]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - sys-utils/cytune.c
Imported from util-linux-2.11o tarball.
[thirdparty/util-linux.git] / sys-utils / cytune.c
index f7fe1ee382ac315b269907cd4a0a06d788826575..295e63bb73a35f6af0d0dd8be17de1735708713a 100644 (file)
  *
  */
 
+ /*
+  * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
+  * - added Native Language Support
+  * Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
+  * - fixed strerr(errno) in gettext calls
+  */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <string.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <signal.h>
 #include <linux/tty.h>
 #include <termios.h>
-#include <linux/tqueue.h>
+
+#include "../defines.h"                /* for NEED_tqueue_h */
+#ifdef NEED_tqueue_h
+#include <linux/tqueue.h>      /* required for old kernels (for struct tq_struct) */
+                               /* compilation errors on other kernels */
+#endif
 #include <linux/cyclades.h>
-#include <signal.h>
 
 #if 0
 #ifndef XMIT
@@ -56,6 +68,8 @@
 # endif
 #endif
 #endif
+
+#include "nls.h"
                                /* Until it gets put in the kernel,
                                   toggle by hand. */
 #undef XMIT
@@ -75,7 +89,8 @@ int cmon_index;
 #define mvtime(tvpto, tvpfrom)  (((tvpto)->tv_sec = (tvpfrom)->tv_sec),(tvpto)->tv_usec = (tvpfrom)->tv_usec)
 
 
-inline double dtime(struct timeval * tvpnew, struct timeval * tvpold) {
+static inline double
+dtime(struct timeval * tvpnew, struct timeval * tvpold) {
   double diff;
   diff = (double)tvpnew->tv_sec - (double)tvpold->tv_sec;
   diff += ((double)tvpnew->tv_usec - (double)tvpold->tv_usec)/1000000;
@@ -85,25 +100,24 @@ inline double dtime(struct timeval * tvpnew, struct timeval * tvpold) {
 static int global_argc, global_optind;
 static char ***global_argv;
 
-void summary(int signal) {
+static void
+summary(int sig) {
   struct cyclades_control *cc;
 
-  int argc, optind;
+  int argc, local_optind;
   char **argv;
 
   int i,j;
 
   argc = global_argc;
   argv = *global_argv;
-  optind = global_optind;
+  local_optind = global_optind;
 
-  if (signal > 0) {
-    for(i = optind; i < argc; i ++) {
-      j = i - optind;
+  if (sig > 0) {
+    for(i = local_optind; i < argc; i ++) {
+      j = i - local_optind;
       cc = &cmon[cmon_index];
-      fprintf(stderr, "File %s, For threshold value %lu, Maximum characters "
-             "in fifo were %d,\nand the maximum transfer rate in "
-             "characters/second was %f\n", 
+      fprintf(stderr, _("File %s, For threshold value %lu, Maximum characters in fifo were %d,\nand the maximum transfer rate in characters/second was %f\n"), 
              argv[i],
              cc->threshold_value,
              cc->maxmax,
@@ -113,12 +127,9 @@ void summary(int signal) {
     exit(0);
   }
   cc = &cmon[cmon_index];
-  if (cc->threshold_value > 0 && signal != -1) {
-    fprintf(stderr, "File %s, For threshold value %lu and timrout value %lu,"
-           " Maximum characters "
-           "in fifo were %d,\nand the maximum transfer rate in "
-           "characters/second was %f\n", 
-           argv[cmon_index+optind],
+  if (cc->threshold_value > 0 && sig != -1) {
+    fprintf(stderr, _("File %s, For threshold value %lu and timrout value %lu, Maximum characters in fifo were %d,\nand the maximum transfer rate in characters/second was %f\n"),
+           argv[cmon_index+local_optind],
            cc->threshold_value,
            cc->timeout_value,
            cc->maxmax,
@@ -159,8 +170,6 @@ int main(int argc, char *argv[]) {
   struct cyclades_monitor cywork;
   
   int i;
-  extern char *optarg;
-  extern int optind;
   unsigned long threshold_value;
   unsigned long timeout_value;
   double xfer_rate;
@@ -171,8 +180,11 @@ int main(int argc, char *argv[]) {
   global_argc = argc;          /* For signal routine. */
   global_argv = &argv;         /* For signal routine. */
 
-  while (EOF != (i = getopt(argc, argv, 
-                           "qs:S:t:T:gGi:"))) {
+  setlocale(LC_ALL, "");
+  bindtextdomain(PACKAGE, LOCALEDIR);
+  textdomain(PACKAGE);
+
+  while ((i = getopt(argc, argv, "qs:S:t:T:gGi:")) != -1) {
     switch (i) {
     case 'q':
       query = 1;
@@ -180,7 +192,7 @@ int main(int argc, char *argv[]) {
     case 'i':
       interval = atoi(optarg);
       if(interval <= 0) {
-       fprintf(stderr, "Invalid interval value: %s\n",optarg);
+       fprintf(stderr, _("Invalid interval value: %s\n"),optarg);
        errflg ++;
       }
       break;
@@ -188,7 +200,7 @@ int main(int argc, char *argv[]) {
       ++set;
       set_val = atoi(optarg);
       if(set_val <= 0 || set_val > 12) {
-       fprintf(stderr, "Invalid set value: %s\n",optarg);
+       fprintf(stderr, _("Invalid set value: %s\n"),optarg);
        errflg ++;
       }
       break;
@@ -196,7 +208,7 @@ int main(int argc, char *argv[]) {
        ++set_def;
       set_def_val = atoi(optarg);
       if(set_def_val < 0 || set_def_val > 12) {
-       fprintf(stderr, "Invalid default value: %s\n",optarg);
+       fprintf(stderr, _("Invalid default value: %s\n"),optarg);
        errflg ++;
       }
       break;
@@ -204,7 +216,7 @@ int main(int argc, char *argv[]) {
       ++set_time;
       set_time_val = atoi(optarg);
       if(set_time_val <= 0 || set_time_val > 255) {
-       fprintf(stderr, "Invalid set time value: %s\n",optarg);
+       fprintf(stderr, _("Invalid set time value: %s\n"),optarg);
        errflg ++;
       }
       break;
@@ -212,7 +224,7 @@ int main(int argc, char *argv[]) {
        ++set_def_time;
       set_def_time_val = atoi(optarg);
       if(set_def_time_val < 0 || set_def_time_val > 255) {
-       fprintf(stderr, "Invalid default time value: %s\n",optarg);
+       fprintf(stderr, _("Invalid default time value: %s\n"),optarg);
        errflg ++;
       }
       break;
@@ -229,9 +241,7 @@ int main(int argc, char *argv[]) {
      (set && set_def) || (set_time && set_def_time) || 
      (get && get_def)) {
     fprintf(stderr, 
-           "Usage: %s [-q [-i interval]]"
-           " ([-s value]|[-S value]) ([-t value]|[-T value])"
-           " [-g|-G] file [file...]\n",
+           _("Usage: %s [-q [-i interval]] ([-s value]|[-S value]) ([-t value]|[-T value]) [-g|-G] file [file...]\n"),
            argv[0]);
     exit(1);
   }
@@ -239,60 +249,71 @@ int main(int argc, char *argv[]) {
   global_optind = optind;      /* For signal routine. */
 
   if (set || set_def) {
-    for(i = optind;i < argc;i ++) {
+    for(i = optind; i < argc; i++) {
       file = open(argv[i],O_RDONLY);
       if(file == -1) {
-       fprintf(stderr, "Can't open %s: %s\n",argv[i],strerror(errno));
+        int errsv = errno;
+       fprintf(stderr, _("Can't open %s: %s\n"),argv[i],strerror(errsv));
        exit(1);
       }
       if(ioctl(file,
               set ? CYSETTHRESH : CYSETDEFTHRESH,
               set ? set_val : set_def_val)) {
-       fprintf(stderr, "Can't set %s to threshold %d: %s\n",
-               argv[i],set?set_val:set_def_val,strerror(errno));
+       int errsv = errno;
+       fprintf(stderr, _("Can't set %s to threshold %d: %s\n"),
+               argv[i],set?set_val:set_def_val,strerror(errsv));
        exit(1);
       }
+      close(file);
     }
   }
   if (set_time || set_def_time) {
-    for(i = optind;i < argc;i ++) {
+    for(i = optind; i < argc; i++) {
       file = open(argv[i],O_RDONLY);
       if(file == -1) {
-       fprintf(stderr, "Can't open %s: %s\n",argv[i],strerror(errno));
+        int errsv = errno;
+       fprintf(stderr, _("Can't open %s: %s\n"),argv[i],strerror(errsv));
        exit(1);
       }
       if(ioctl(file,
               set_time ? CYSETTIMEOUT : CYSETDEFTIMEOUT,
               set_time ? set_time_val : set_def_time_val)) {
-       fprintf(stderr, "Can't set %s to time threshold %d: %s\n",
-               argv[i],set_time?set_time_val:set_def_time_val,strerror(errno));
+       int errsv = errno;
+       fprintf(stderr, _("Can't set %s to time threshold %d: %s\n"),
+               argv[i],set_time?set_time_val:set_def_time_val,strerror(errsv));
        exit(1);
       }
+      close(file);
     }
   }
 
   if (get || get_def) {
-    for(i = optind;i < argc;i ++) {
+    for(i = optind; i < argc; i++) {
       file = open(argv[i],O_RDONLY);
       if(file == -1) {
-       fprintf(stderr, "Can't open %s: %s\n",argv[i],strerror(errno));
+        int errsv = errno;
+       fprintf(stderr, _("Can't open %s: %s\n"),argv[i],strerror(errsv));
        exit(1);
       }
       if(ioctl(file, get ? CYGETTHRESH : CYGETDEFTHRESH, &threshold_value)) {
-       fprintf(stderr, "Can't get threshold for %s: %s\n",
-               argv[i],strerror(errno));
+        int errsv = errno;
+       fprintf(stderr, _("Can't get threshold for %s: %s\n"),
+               argv[i],strerror(errsv));
        exit(1);
       }
       if(ioctl(file, get ? CYGETTIMEOUT : CYGETDEFTIMEOUT, &timeout_value)) {
-       fprintf(stderr, "Can't get timeout for %s: %s\n",
-               argv[i],strerror(errno));
+       int errsv = errno;
+       fprintf(stderr, _("Can't get timeout for %s: %s\n"),
+               argv[i],strerror(errsv));
        exit(1);
       }
-      printf("%s: %ld %s threshold and %ld %s timeout\n",
-            argv[i], threshold_value, 
-            get?"current":"default",
-            timeout_value,
-            get?"current":"default");
+      close(file);
+      if (get)
+             printf(_("%s: %ld current threshold and %ld current timeout\n"),
+                    argv[i], threshold_value, timeout_value);
+      else
+             printf(_("%s: %ld default threshold and %ld default timeout\n"),
+                    argv[i], threshold_value, timeout_value);
     }
   }
 
@@ -303,40 +324,44 @@ int main(int argc, char *argv[]) {
   cmon = (struct cyclades_control *) malloc(sizeof (struct cyclades_control)
                                            * numfiles);
   if(!cmon) {
-    perror("malloc failed");
+    perror(_("malloc failed"));
     exit(1);
   }
   if(signal(SIGINT, summary)||
      signal(SIGQUIT, summary)||
      signal(SIGTERM, summary)) {
-    perror("Can't set signal handler");
+    perror(_("Can't set signal handler"));
     exit(1);
   }
   if(gettimeofday(&lasttime,&tz)) {
-    perror("gettimeofday failed");
+    perror(_("gettimeofday failed"));
     exit(1);
   }
   for(i = optind; i < argc; i ++) {
     cmon_index = i - optind;
     cmon[cmon_index].cfile = open(argv[i], O_RDONLY);
     if(-1 == cmon[cmon_index].cfile) {
-      fprintf(stderr, "Can't open %s: %s\n",argv[i],strerror(errno));
+      int errsv = errno;
+      fprintf(stderr, _("Can't open %s: %s\n"),argv[i],strerror(errsv));
       exit(1);
     }
     if(ioctl(cmon[cmon_index].cfile, CYGETMON, &cmon[cmon_index].c)) {
-      fprintf(stderr, "Can't issue CYGETMON on %s: %s\n",
-             argv[i],strerror(errno));
+      int errsv = errno;
+      fprintf(stderr, _("Can't issue CYGETMON on %s: %s\n"),
+             argv[i],strerror(errsv));
       exit(1);
     }
     summary(-1);
     if(ioctl(cmon[cmon_index].cfile, CYGETTHRESH, &threshold_value)) {
-      fprintf(stderr, "Can't get threshold for %s: %s\n",
-             argv[i],strerror(errno));
+      int errsv = errno;
+      fprintf(stderr, _("Can't get threshold for %s: %s\n"),
+             argv[i],strerror(errsv));
       exit(1);
     }
     if(ioctl(cmon[cmon_index].cfile, CYGETTIMEOUT, &timeout_value)) {
-      fprintf(stderr, "Can't get timeout for %s: %s\n",
-             argv[i],strerror(errno));
+      int errsv = errno;
+      fprintf(stderr, _("Can't get timeout for %s: %s\n"),
+             argv[i],strerror(errsv));
       exit(1);
     }
   }
@@ -344,7 +369,7 @@ int main(int argc, char *argv[]) {
     sleep(interval);
     
     if(gettimeofday(&thistime,&tz)) {
-      perror("gettimeofday failed");
+      perror(_("gettimeofday failed"));
       exit(1);
     }
     diff = dtime(&thistime, &lasttime);
@@ -353,18 +378,21 @@ int main(int argc, char *argv[]) {
     for(i = optind; i < argc; i ++) {
       cmon_index = i - optind;
       if(ioctl(cmon[cmon_index].cfile, CYGETMON, &cywork)) {
-       fprintf(stderr, "Can't issue CYGETMON on %s: %s\n",
-               argv[i],strerror(errno));
+        int errsv = errno;
+       fprintf(stderr, _("Can't issue CYGETMON on %s: %s\n"),
+               argv[i],strerror(errsv));
        exit(1);
       }
       if(ioctl(cmon[cmon_index].cfile, CYGETTHRESH, &threshold_value)) {
-       fprintf(stderr, "Can't get threshold for %s: %s\n",
-               argv[i],strerror(errno));
+        int errsv = errno;
+       fprintf(stderr, _("Can't get threshold for %s: %s\n"),
+               argv[i],strerror(errsv));
        exit(1);
       }
       if(ioctl(cmon[cmon_index].cfile, CYGETTIMEOUT, &timeout_value)) {
-       fprintf(stderr, "Can't get timeout for %s: %s\n",
-               argv[i],strerror(errno));
+        int errsv = errno;
+       fprintf(stderr, _("Can't get timeout for %s: %s\n"),
+               argv[i],strerror(errsv));
        exit(1);
       }
 
@@ -393,26 +421,24 @@ int main(int argc, char *argv[]) {
       }
 
 #ifdef XMIT
-      printf("%s: %lu ints, %lu/%lu chars; "
-            "fifo: %lu thresh, %lu tmout, "
-            "%lu max, %lu now\n",
+      printf(_("%s: %lu ints, %lu/%lu chars; fifo: %lu thresh, %lu tmout, "
+              "%lu max, %lu now\n"),
             argv[i],
             cywork.int_count,cywork.char_count,cywork.send_count,
             threshold_value,timeout_value,
             cywork.char_max,cywork.char_last);
-      printf("   %f int/sec; %f rec, %f send (char/sec)\n",
+      printf(_("   %f int/sec; %f rec, %f send (char/sec)\n"),
             cywork.int_count/diff,
             xfer_rate,
             xmit_rate);
 #else
-      printf("%s: %lu ints, %lu chars; "
-            "fifo: %lu thresh, %lu tmout, "
-            "%lu max, %lu now\n",
+      printf(_("%s: %lu ints, %lu chars; fifo: %lu thresh, %lu tmout, "
+              "%lu max, %lu now\n"),
             argv[i],
             cywork.int_count,cywork.char_count,
             threshold_value,timeout_value,
             cywork.char_max,cywork.char_last);
-      printf("   %f int/sec; %f rec (char/sec)\n",
+      printf(_("   %f int/sec; %f rec (char/sec)\n"),
             cywork.int_count/diff,
             xfer_rate);
 #endif