home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / util / dowhatever.c < prev    next >
C/C++ Source or Header  |  1994-11-30  |  1KB  |  67 lines

  1. /*
  2.  * the main program for do(statfs, ustat, ultrix, ...)
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <stdlib.h>
  9.  
  10. long bperi = 1000000000L;    /* how many bytes per inode? */
  11.  
  12. int debug = 0;
  13. char *progname;
  14.  
  15. /*
  16.  - main - parse arguments and handle options
  17.  */
  18. main(argc, argv)
  19. int argc;
  20. char *argv[];
  21. {
  22.     int c;
  23.     int errflg = 0;
  24.     extern int optind;
  25.     extern char *optarg;
  26.     long spacefor();
  27.     register long n;
  28.  
  29.     progname = argv[0];
  30.  
  31.     while ((c = getopt(argc, argv, "e:d")) != EOF)
  32.         switch (c) {
  33.         case 'e':    /* Estimated bytes/inode. */
  34.             bperi = atol(optarg);
  35.             break;
  36.         case 'd':    /* Debugging. */
  37.             debug++;
  38.             break;
  39.         case '?':
  40.         default:
  41.             errflg++;
  42.             break;
  43.         }
  44.     if (errflg || optind != argc-4 || !num(argv[optind]) ||
  45.                         !num(argv[optind+2]) ||
  46.                         !num(argv[optind+3])) {
  47.         fprintf(stderr, "usage: %s [-e estsize]", progname);
  48.         fprintf(stderr, "filesize fileonfs wantspace wantinodes\n");
  49.         exit(2);
  50.     }
  51.  
  52.     n = spacefor((long)atof(argv[optind]), argv[optind+1],
  53.             atol(argv[optind+2]), atol(argv[optind+3]), bperi);
  54.     printf("%ld\n", n);
  55.     exit(0);
  56. }
  57.  
  58. /*
  59.  - num - is a string numeric?
  60.  */
  61. int                /* predicate */
  62. num(s)
  63. char *s;
  64. {
  65.     return(strspn(s, "0123456789.eE+-") == strlen(s));
  66. }
  67.