"Fossies" - the Fresh Open Source Software Archive

Member "di-4.47.2/C/options.c" (30 Oct 2019, 26149 Bytes) of package /linux/privat/di-4.47.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "options.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 4.46_vs_4.47.

    1 /*
    2  * Copyright 1994-2018 Brad Lanam, Walnut Creek, CA
    3  */
    4 
    5 #include "config.h"
    6 #include "di.h"
    7 #include "getoptn.h"
    8 #include "options.h"
    9 #include "version.h"
   10 
   11 #if _hdr_stdio
   12 # include <stdio.h>
   13 #endif
   14 #if _hdr_stdlib
   15 # include <stdlib.h>
   16 #endif
   17 #if _sys_types \
   18     && ! defined (DI_INC_SYS_TYPES_H) /* xenix */
   19 # define DI_INC_SYS_TYPES_H
   20 # include <sys/types.h>
   21 #endif
   22 #if _hdr_ctype
   23 # include <ctype.h>
   24 #endif
   25 #if _hdr_errno
   26 # include <errno.h>
   27 #endif
   28 #if _hdr_string
   29 # include <string.h>
   30 #endif
   31 #if _hdr_strings
   32 # include <strings.h>
   33 #endif
   34 #if _hdr_libintl
   35 # include <libintl.h>
   36 #endif
   37 #if _use_mcheck
   38 # include <mcheck.h>
   39 #endif
   40 
   41 struct pa_tmp {
   42   diData_t        *diData;
   43   diOptions_t     *diopts;
   44   diOutput_t      *diout;
   45   char            *dbsstr;
   46   Size_t          dbsstr_sz;
   47 };
   48 
   49 typedef struct
   50 {
   51     _print_size_t   size;
   52     const char      *disp[2];
   53 } dispTable_t;
   54 
   55 static dispTable_t dispTable [] =
   56 {
   57     { (_print_size_t) 0.0, { "KBytes", "KBytes" } },
   58     { (_print_size_t) 0.0, { "Megs", "Mebis" } },
   59     { (_print_size_t) 0.0, { "Gigs", "Gibis" } },
   60     { (_print_size_t) 0.0, { "Teras", "Tebis" } },
   61     { (_print_size_t) 0.0, { "Petas", "Pebis" } },
   62     { (_print_size_t) 0.0, { "Exas", "Exbis" } },
   63     { (_print_size_t) 0.0, { "Zettas", "Zebis" } },
   64     { (_print_size_t) 0.0, { "Yottas", "Yobis" } }
   65 };
   66 #define DI_DISPTAB_SIZE (sizeof (dispTable) / sizeof (dispTable_t))
   67 
   68 #define DI_ARGV_SEP             "   "  /* space, tab */
   69 #define DI_MAX_ARGV             50
   70 #define DI_LIST_SEP             ","
   71 
   72 #define DI_POSIX_FORMAT         "SbuvpM"
   73 #define DI_DEF_MOUNT_FORMAT     "MST\n\tO"
   74 #define DI_ALL_FORMAT           "MTS\n\tO\n\tbuf13\n\tbcvpa\n\tBuv2\n\tiUFP"
   75 
   76 # if defined (__cplusplus) || defined (c_plusplus)
   77    extern "C" {
   78 # endif
   79 
   80 extern int debug;
   81 
   82 static void processStringArgs   _((char *, diData_t *, char *));
   83 static int  processArgs         _((int, const char * const [], diData_t *, char *, Size_t));
   84 static int  parseList           _((iList_t *, char *));
   85 static void processOptions      _((const char *, char *));
   86 static void processOptionsVal   _((const char *, char *, char *));
   87 static void usage               _((void));
   88 static void setDispBlockSize    _((char *, diOptions_t *, diOutput_t *));
   89 static void initDisplayTable    _((diOptions_t *));
   90 static void setExitFlag         _((diOptions_t *, unsigned int));
   91 
   92 # if defined (__cplusplus) || defined (c_plusplus)
   93    }
   94 # endif
   95 
   96 static void
   97 #if _proto_stdc
   98 processStringArgs (char *ptr, diData_t *diData, char *dbsstr)
   99 #else
  100 processStringArgs (ptr, diData, dbsstr)
  101   char      *ptr;
  102   diData_t  *diData;
  103   char      *dbsstr;
  104 #endif
  105 {
  106   char        *dptr;
  107   char        *tptr;
  108   int         nargc;
  109   const char  *nargv [DI_MAX_ARGV];
  110   diOptions_t *diopts;
  111 
  112   if (ptr == (char *) NULL || strcmp (ptr, "") == 0) {
  113     return;
  114   }
  115 
  116   diopts = &diData->options;
  117 
  118   dptr = (char *) NULL;
  119   dptr = strdup (ptr);
  120   if (dptr == (char *) NULL)
  121   {
  122       fprintf (stderr, "strdup failed in main() (1).  errno %d\n", errno);
  123       setExitFlag (diopts, DI_EXIT_FAIL);
  124       return;
  125   }
  126   if (dptr != (char *) NULL)
  127   {
  128     tptr = strtok (dptr, DI_ARGV_SEP);
  129     nargc = 1;
  130     nargv[0] = "";
  131     while (tptr != (char *) NULL)
  132     {
  133         if (nargc >= DI_MAX_ARGV)
  134         {
  135             break;
  136         }
  137         nargv[nargc++] = tptr;
  138         tptr = strtok ((char *) NULL, DI_ARGV_SEP);
  139     }
  140     processArgs (nargc, nargv, diData, dbsstr, sizeof (dbsstr) - 1);
  141     free ((char *) dptr);
  142   }
  143 }
  144 
  145 int
  146 #if _proto_stdc
  147 getDIOptions (int argc, const char * const argv[], diData_t *diData)
  148 #else
  149 getDIOptions (argc, argv, diData)
  150   int           argc;
  151   const char    * const argv[];
  152   diData_t      *diData;
  153 #endif
  154 {
  155   const char *      argvptr;
  156   char *            ptr;
  157   char              dbsstr [30];
  158   int               optidx;
  159   int               ec;
  160   diOptions_t       *diopts;
  161   diOutput_t        *diout;
  162 
  163   diopts = &diData->options;
  164   diout = &diData->output;
  165   strncpy (dbsstr, DI_DEFAULT_DISP_SIZE, sizeof (dbsstr)); /* default */
  166   ec = 0;
  167 
  168   argvptr = argv [0] + strlen (argv [0]) - 2;
  169   if (memcmp (argvptr, "mi", (Size_t) 2) == 0) {
  170     diopts->formatString = DI_DEF_MOUNT_FORMAT;
  171   }
  172   else    /* don't use DIFMT env var if running mi. */
  173   {
  174     if ((ptr = getenv ("DIFMT")) != (char *) NULL) {
  175       diopts->formatString = ptr;
  176     }
  177   }
  178 
  179       /* gnu df */
  180   if ((ptr = getenv ("POSIXLY_CORRECT")) != (char *) NULL) {
  181     strncpy (dbsstr, "512", sizeof (dbsstr));
  182     diopts->formatString = DI_POSIX_FORMAT;
  183     diopts->posix_compat = TRUE;
  184     diopts->csv_output = FALSE;
  185   }
  186 
  187       /* bsd df */
  188   if ((ptr = getenv ("BLOCKSIZE")) != (char *) NULL) {
  189     strncpy (dbsstr, ptr, sizeof (dbsstr)-1);
  190   }
  191 
  192       /* gnu df */
  193   if ((ptr = getenv ("DF_BLOCK_SIZE")) != (char *) NULL) {
  194     strncpy (dbsstr, ptr, sizeof (dbsstr)-1);
  195   }
  196 
  197   if ((ptr = getenv ("DI_ARGS")) != (char *) NULL) {
  198     if (debug > 0) {
  199       printf ("# DI_ARGS:%s\n", ptr);
  200     }
  201     processStringArgs (ptr, diData, dbsstr);
  202   }
  203 
  204   if (debug > 0) {
  205     int j;
  206     printf ("# ARGS:");
  207     for (j = 0; j < argc; ++j)
  208     {
  209       printf (" %s", argv[j]);
  210     }
  211     printf ("\n");
  212     printf ("# blocksize: %s\n", dbsstr);
  213   }
  214   optidx = processArgs (argc, argv, diData, dbsstr,
  215       sizeof (dbsstr) - 1);
  216 
  217   initDisplayTable (diopts);
  218   setDispBlockSize (dbsstr, diopts, diout);
  219 
  220   return optidx;
  221 }
  222 
  223 static int
  224 #if _proto_stdc
  225 processArgs (int argc,
  226              const char * const argv [],
  227              diData_t *diData,
  228              char *dbsstr,
  229              Size_t dbsstr_sz)
  230 #else
  231 processArgs (argc, argv, diData, dbsstr, dbsstr_sz)
  232     int             argc;
  233     const char      * const argv [];
  234     diData_t        *diData;
  235     char            *dbsstr;
  236     Size_t          dbsstr_sz;
  237 #endif
  238 {
  239   int           i;
  240   int           optidx;
  241   int           errorCount;
  242   diOptions_t   *diopts;
  243   diOutput_t    *diout;
  244   struct pa_tmp padata;
  245 
  246     /* the really old compilers don't have automatic initialization */
  247   static getoptn_opt_t opts[] = {
  248     { "-A",     GETOPTN_STRPTR,            /* 0 */
  249         NULL  /*&diopts->formatString*/,
  250         0,
  251         (void *) DI_ALL_FORMAT },
  252     { "-a",     GETOPTN_FUNC_BOOL,
  253         NULL  /*&padata*/,
  254         0,
  255         NULL  /*processOptions*/ },
  256     { "--all",  GETOPTN_ALIAS,
  257         (void *) "-a",
  258         0,
  259         NULL },
  260     { "-B",     GETOPTN_FUNC_VALUE,
  261         NULL  /*&padata*/,
  262         0,
  263         NULL  /*processOptionsVal*/ },
  264     { "-b",     GETOPTN_ALIAS,
  265         (void *) "-B",
  266         0,
  267         NULL },
  268     { "--block-size",   GETOPTN_ALIAS,      /* 5 */
  269         (void *) "-B",
  270         0,
  271         NULL },
  272     { "-c",     GETOPTN_BOOL,
  273         NULL  /*&diopts->csv_output*/,
  274         0     /*sizeof(diopts->csv_output)*/,
  275         NULL },
  276     { "-C",     GETOPTN_BOOL,
  277         NULL  /*&diopts->csv_tabs*/,
  278         0     /*sizeof(diopts->csv_tabs)*/,
  279         NULL },
  280     { "--csv-output", GETOPTN_ALIAS,
  281         (void *) "-c",
  282         0,
  283         NULL },
  284     { "--csv-tabs", GETOPTN_ALIAS,
  285         (void *) "-C",
  286         0,
  287         NULL },
  288     { "-d",     GETOPTN_STRING,                 /* 10 */
  289         NULL  /*dbsstr*/,
  290         0  /*dbsstr_sz*/,
  291         NULL },
  292     { "--display-size",     GETOPTN_ALIAS,
  293         (void *) "-d",
  294         0,
  295         NULL },
  296     { "--dont-resolve-symlink",     GETOPTN_ALIAS,  /* 12 */
  297         (void *) "-R",
  298         0,
  299         NULL },
  300     { "-f",     GETOPTN_STRPTR,             /* 13 */
  301         NULL  /*&diopts->formatString*/,
  302         0,
  303         NULL },
  304     { "--format-string",    GETOPTN_ALIAS,
  305         (void *) "-f",
  306         0,
  307         NULL },
  308     { "-F",     GETOPTN_ALIAS,
  309         (void *) "-I",
  310         0,
  311         NULL },
  312     { "-g",     GETOPTN_STRING,
  313         NULL  /*dbsstr*/,
  314         0  /*dbsstr_sz*/,
  315         (void *) "g" },
  316     { "-h",     GETOPTN_STRING,            /* 17 */
  317         NULL  /*dbsstr*/,
  318         0  /*dbsstr_sz*/,
  319         (void *) "h" },
  320     { "-H",     GETOPTN_STRING,             /* 18 */
  321         NULL  /*dbsstr*/,
  322         0  /*dbsstr_sz*/,
  323         (void *) "H" },
  324     { "--help", GETOPTN_FUNC_BOOL,
  325         NULL,
  326         0,
  327         NULL  /*processOptions*/ },
  328     { "--human-readable",   GETOPTN_ALIAS,
  329         (void *) "-H",
  330         0,
  331         NULL },
  332     { "-?",     GETOPTN_FUNC_BOOL,
  333         NULL,
  334         0,
  335         NULL  /*processOptions*/ },
  336     { "-i",     GETOPTN_ALIAS,              /* 22 */
  337         (void *) "-x",
  338         0,
  339         NULL },
  340     { "-I",     GETOPTN_FUNC_VALUE,         /* 23 */
  341         NULL  /*&padata*/,
  342         0,
  343         NULL  /*processOptionsVal*/ },
  344     { "--inodes",GETOPTN_IGNORE,
  345         NULL,
  346         0,
  347         NULL },
  348     { "-k",     GETOPTN_STRING,
  349         NULL  /*dbsstr*/,
  350         0  /*dbsstr_sz*/,
  351         (void *) "k" },
  352     { "-l",     GETOPTN_BOOL,
  353         NULL  /*&diopts->localOnly*/,
  354         0  /*sizeof (diopts->localOnly)*/,
  355         NULL },
  356     { "--local",GETOPTN_ALIAS,              /* 27 */
  357         (void *) "-l",
  358         0,
  359         NULL },
  360     { "-L",     GETOPTN_BOOL,               /* 28 */
  361         NULL  /*&diopts->excludeLoopback*/,
  362         0  /*sizeof (diopts->excludeLoopback)*/,
  363         NULL },
  364     { "-m",     GETOPTN_STRING,
  365         NULL  /*dbsstr*/,
  366         0  /*dbsstr_sz*/,
  367         (void *) "m" },
  368     { "-n",     GETOPTN_BOOL,
  369         NULL  /*&diopts->printHeader*/,
  370         0  /*sizeof (diopts->printHeader)*/,
  371         NULL },
  372     { "--no-sync",  GETOPTN_IGNORE,
  373         NULL,
  374         0,
  375         NULL },
  376     { "-P",     GETOPTN_FUNC_BOOL,          /* 32 */
  377         NULL  /*&padata*/,
  378         0,
  379         NULL  /*processOptions*/ },
  380     { "--portability",  GETOPTN_ALIAS,      /* 33 */
  381         (void *) "-P",
  382         0,
  383         NULL },
  384     { "--print-type",   GETOPTN_IGNORE,
  385         NULL,
  386         0,
  387         NULL },
  388     { "-q",     GETOPTN_BOOL,
  389         NULL  /*&diopts->quota_check*/,
  390         0  /*sizeof (diopts->quota_check)*/,
  391         NULL },
  392     { "-R",     GETOPTN_BOOL,
  393         NULL  /*&diopts->dontResolveSymlink*/,
  394         0  /*sizeof (diopts->dontResolveSymlink)*/,
  395         NULL },
  396     { "-s",     GETOPTN_FUNC_VALUE,         /* 37 */
  397         NULL  /*&padata*/,
  398         0,
  399         NULL  /*processOptionsVal*/ },
  400     { "--si",   GETOPTN_FUNC_BOOL,          /* 38 */
  401         NULL  /*&padata*/,
  402         0,
  403         NULL  /*processOptions*/ },
  404     { "--sync", GETOPTN_IGNORE,             /* 39 */
  405         NULL,
  406         0,
  407         NULL },
  408     { "-t",     GETOPTN_BOOL,
  409         NULL  /*&diopts->printTotals*/,
  410         0  /*sizeof (diopts->printTotals)*/,
  411         NULL },
  412     { "--total",GETOPTN_ALIAS,
  413         (void *) "-t",
  414         0,
  415         NULL },
  416     { "--type", GETOPTN_ALIAS,              /* 42 */
  417         (void *) "-I",
  418         0,
  419         NULL },
  420     { "-v",     GETOPTN_IGNORE,             /* 43 */
  421         NULL,
  422         0,
  423         NULL },
  424     { "--version", GETOPTN_FUNC_BOOL,       /* 44 */
  425         NULL,
  426         0,
  427         NULL  /*processOptions*/ },
  428     { "-w",     GETOPTN_SIZET,
  429         NULL  /*&diout->width*/,
  430         0  /*sizeof (diout->width)*/,
  431         NULL },
  432     { "-W",     GETOPTN_SIZET,
  433         NULL  /*&diout->inodeWidth*/,
  434         0  /*sizeof (diout->inodeWidth)*/,
  435         NULL },
  436     { "-x",     GETOPTN_FUNC_VALUE,
  437         NULL  /*&padata*/,
  438         0,
  439         NULL  /*processOptionsVal*/ },
  440     { "--exclude-type",     GETOPTN_ALIAS,  /* 48 */
  441         (void *) "-x",
  442         0,
  443         NULL },
  444     { "-X",     GETOPTN_FUNC_VALUE,
  445         NULL  /*&padata*/,
  446         0,
  447         NULL  /*processOptionsVal*/ },
  448     { "-z",     GETOPTN_STRING,             /* 50 */
  449         NULL  /*&diData->zoneInfo.zoneDisplay*/,
  450         0  /*sizeof (diData->zoneInfo.zoneDisplay)*/,
  451         NULL },
  452     { "-Z",     GETOPTN_STRING,
  453         NULL  /*&diData->zoneInfo.zoneDisplay*/,
  454         0  /*sizeof (diData->zoneInfo.zoneDisplay)*/,
  455         (void *) "all" }
  456   };
  457   static int dbsids[] = { 10, 16, 17, 18, 25, 29 };
  458   static int paidb[] = { 1, 19, 21, 32, 38, 44, };
  459   static int paidv[] = { 3, 23, 37, 47, 49 };
  460 
  461   diopts = &diData->options;
  462   diout = &diData->output;
  463 
  464     /* this is seriously gross, but the old compilers don't have    */
  465     /* automatic aggregate initialization                           */
  466     /* don't forget to change dbsids, paidb and paidv above also    */
  467   opts[0].valptr = (void *) &diopts->formatString;   /* -A */
  468   opts[6].valptr = (void *) &diopts->csv_output;     /* -c */
  469   opts[6].valsiz = sizeof (diopts->csv_output);
  470   opts[7].valptr = (void *) &diopts->csv_tabs;     /* -C */
  471   opts[7].valsiz = sizeof (diopts->csv_tabs);
  472   opts[13].valptr = (void *) &diopts->formatString;  /* -f */
  473   opts[26].valptr = (void *) &diopts->localOnly;     /* -l */
  474   opts[26].valsiz = sizeof (diopts->localOnly);
  475   opts[28].valptr = (void *) &diopts->excludeLoopback; /* -L */
  476   opts[28].valsiz = sizeof (diopts->excludeLoopback);
  477   opts[30].valptr = (void *) &diopts->printHeader;   /* -n */
  478   opts[30].valsiz = sizeof (diopts->printHeader);
  479   opts[35].valptr = (void *) &diopts->quota_check;    /* -q */
  480   opts[35].valsiz = sizeof (diopts->quota_check);
  481   opts[36].valptr = (void *) &diopts->dontResolveSymlink;    /* -R */
  482   opts[36].valsiz = sizeof (diopts->dontResolveSymlink);
  483   opts[40].valptr = (void *) &diopts->printTotals;    /* -t */
  484   opts[40].valsiz = sizeof (diopts->printTotals);
  485   opts[45].valptr = (void *) &diout->width;          /* -w */
  486   opts[45].valsiz = sizeof (diout->width);
  487   opts[46].valptr = (void *) &diout->inodeWidth;     /* -W */
  488   opts[46].valsiz = sizeof (diout->inodeWidth);
  489   opts[50].valptr = (void *) diData->zoneInfo.zoneDisplay;  /* -z */
  490   opts[50].valsiz = sizeof (diData->zoneInfo.zoneDisplay);
  491   opts[51].valptr = (void *) diData->zoneInfo.zoneDisplay;  /* -Z */
  492   opts[51].valsiz = sizeof (diData->zoneInfo.zoneDisplay);
  493 
  494   for (i = 0; i < (int) (sizeof (dbsids) / sizeof (int)); ++i) {
  495     opts[dbsids[i]].valptr = (void *) dbsstr;
  496     opts[dbsids[i]].valsiz = dbsstr_sz;
  497   }
  498   for (i = 0; i < (int) (sizeof (paidb) / sizeof (int)); ++i) {
  499     opts[paidb[i]].valptr = (void *) &padata;
  500     opts[paidb[i]].value2 = (void *) processOptions;
  501     if (diopts->exitFlag != DI_EXIT_NORM) {
  502       break;
  503     }
  504   }
  505   for (i = 0; i < (int) (sizeof (paidv) / sizeof (int)); ++i) {
  506     opts[paidv[i]].valptr = (void *) &padata;
  507     opts[paidv[i]].value2 = (void *) processOptionsVal;
  508     if (diopts->exitFlag != DI_EXIT_NORM) {
  509       break;
  510     }
  511   }
  512 
  513   optidx = -1;
  514   if (diopts->exitFlag != DI_EXIT_NORM) {
  515     return optidx;
  516   }
  517 
  518   padata.diData = diData;
  519   padata.diopts = diopts;
  520   padata.diout = diout;
  521   padata.dbsstr = dbsstr;
  522   padata.dbsstr_sz = dbsstr_sz;
  523 
  524   optidx = getoptn (GETOPTN_LEGACY, argc, argv,
  525        sizeof (opts) / sizeof (getoptn_opt_t), opts, &errorCount);
  526   diopts->errorCount += errorCount;
  527   if (diopts->errorCount > 0) {
  528     setExitFlag (diopts, DI_EXIT_WARN);
  529   }
  530 
  531   if (diopts->csv_tabs) {
  532     diopts->csv_output = TRUE;
  533   }
  534   if (diopts->csv_output) {
  535     diopts->printTotals = FALSE;
  536   }
  537 
  538   return optidx;
  539 }
  540 
  541 static void
  542 #if _proto_stdc
  543 processOptions (const char *arg, char *valptr)
  544 #else
  545 processOptions (arg, valptr)
  546     const char *arg;
  547     char *valptr;
  548 #endif
  549 {
  550   struct pa_tmp     *padata;
  551 
  552   padata = (struct pa_tmp *) valptr;
  553   if (strcmp (arg, "-a") == 0) {
  554     padata->diopts->displayAll = TRUE;
  555     strncpy (padata->diData->zoneInfo.zoneDisplay, "all", MAXPATHLEN);
  556   } else if (strcmp (arg, "--help") == 0 || strcmp (arg, "-?") == 0) {
  557     usage();
  558     setExitFlag (padata->diopts, DI_EXIT_OK);
  559   } else if (strcmp (arg, "-P") == 0) {
  560     if (strcmp (padata->dbsstr, "k") != 0) /* don't override -k option */
  561     {
  562       strncpy (padata->dbsstr, "512", padata->dbsstr_sz);
  563     }
  564     padata->diopts->formatString = DI_POSIX_FORMAT;
  565     padata->diopts->posix_compat = TRUE;
  566     padata->diopts->csv_output = FALSE;
  567   } else if (strcmp (arg, "--si") == 0) {
  568     padata->diopts->baseDispSize = (_print_size_t) DI_VAL_1000;
  569     padata->diopts->baseDispIdx = DI_DISP_1000_IDX;
  570     strncpy (padata->dbsstr, "H", padata->dbsstr_sz);
  571   } else if (strcmp (arg, "--version") == 0) {
  572     printf (DI_GT("di version %s    Default Format: %s\n"), DI_VERSION, DI_DEFAULT_FORMAT);
  573     setExitFlag (padata->diopts, DI_EXIT_OK);
  574   } else {
  575     fprintf (stderr, "di_panic: bad option setup\n");
  576   }
  577 
  578   return;
  579 }
  580 
  581 static void
  582 #if _proto_stdc
  583 processOptionsVal (const char *arg, char *valptr, char *value)
  584 #else
  585 processOptionsVal (arg, valptr, value)
  586     const char  *arg;
  587     char        *valptr;
  588     char        *value;
  589 #endif
  590 {
  591   struct pa_tmp     *padata;
  592   int               rc;
  593 
  594   padata = (struct pa_tmp *) valptr;
  595 
  596   if (strcmp (arg, "-B") == 0) {
  597     if (isdigit ((int) (*value)))
  598     {
  599       padata->diopts->baseDispSize = (_print_size_t) atof (value);
  600       padata->diopts->baseDispIdx = DI_DISP_1000_IDX; /* unknown, really */
  601       if (padata->diopts->baseDispSize == (_print_size_t) DI_VAL_1024)
  602       {
  603         padata->diopts->baseDispIdx = DI_DISP_1024_IDX;
  604       }
  605     }
  606     else if (strcmp (value, "k") == 0)
  607     {
  608       padata->diopts->baseDispSize = (_print_size_t) DI_VAL_1024;
  609       padata->diopts->baseDispIdx = DI_DISP_1024_IDX;
  610     }
  611     else if (strcmp (value, "d") == 0 ||
  612         strcmp (value, "si") == 0)
  613     {
  614       padata->diopts->baseDispSize = (_print_size_t) DI_VAL_1000;
  615       padata->diopts->baseDispIdx = DI_DISP_1000_IDX;
  616     }
  617   } else if (strcmp (arg, "-I") == 0) {
  618     rc = parseList (&padata->diData->includeList, value);
  619     if (rc != 0) {
  620       setExitFlag (padata->diopts, DI_EXIT_FAIL);
  621       return;
  622     }
  623   } else if (strcmp (arg, "-s") == 0) {
  624     strncpy (padata->diopts->sortType, value, DI_SORT_MAX);
  625       /* for backwards compatibility                       */
  626       /* reverse by itself - change to reverse mount point */
  627     if (strcmp (padata->diopts->sortType, "r") == 0)
  628     {
  629         strncpy (padata->diopts->sortType, "rm", DI_SORT_MAX);
  630     }
  631         /* add some sense to the sort order */
  632     if (strcmp (padata->diopts->sortType, "t") == 0)
  633     {
  634         strncpy (padata->diopts->sortType, "tm", DI_SORT_MAX);
  635     }
  636   } else if (strcmp (arg, "-x") == 0) {
  637     parseList (&padata->diData->ignoreList, value);
  638   } else if (strcmp (arg, "-X") == 0) {
  639     debug = atoi (value);
  640     padata->diopts->printDebugHeader = TRUE;
  641     padata->diopts->printTotals = TRUE;
  642     padata->diopts->printHeader = TRUE;
  643     padata->diout->width = 10;
  644     padata->diout->inodeWidth = 10;
  645   } else {
  646     fprintf (stderr, "di_panic: bad option setup\n");
  647   }
  648 
  649   return;
  650 }
  651 
  652 static int
  653 #if _proto_stdc
  654 parseList (iList_t *list, char *str)
  655 #else
  656 parseList (list, str)
  657     iList_t       *list;
  658     char        *str;
  659 #endif
  660 {
  661     char        *dstr;
  662     char        *ptr;
  663     char        *lptr;
  664     int         count;
  665     int         ocount;
  666     int         ncount;
  667     int         i;
  668     unsigned int len;
  669 
  670     dstr = strdup (str);
  671     if (dstr == (char *) NULL)
  672     {
  673       fprintf (stderr, "strdup failed in parseList() (1).  errno %d\n", errno);
  674       return 1;
  675     }
  676 
  677     ptr = strtok (dstr, DI_LIST_SEP);
  678     count = 0;
  679     while (ptr != (char *) NULL)
  680     {
  681         ++count;
  682         ptr = strtok ((char *) NULL, DI_LIST_SEP);
  683     }
  684 
  685     ocount = list->count;
  686     list->count += count;
  687     ncount = list->count;
  688     list->list = (char **) di_realloc ((char *) list->list,
  689             (Size_t) list->count * sizeof (char *));
  690     if (list->list == (char **) NULL)
  691     {
  692       fprintf (stderr, "malloc failed in parseList() (2).  errno %d\n", errno);
  693       free ((char *) dstr);
  694       return 1;
  695     }
  696 
  697     ptr = dstr;
  698     for (i = ocount; i < ncount; ++i)
  699     {
  700         len = (unsigned int) strlen (ptr);
  701         lptr = (char *) malloc ((Size_t) len + 1);
  702         if (lptr == (char *) NULL)
  703         {
  704           fprintf (stderr, "malloc failed in parseList() (3).  errno %d\n", errno);
  705           free ((char *) dstr);
  706           return 1;
  707         }
  708         strncpy (lptr, ptr, (Size_t) len);
  709         lptr[len] = '\0';
  710         list->list [i] = lptr;
  711         ptr += len + 1;
  712     }
  713 
  714     free ((char *) dstr);
  715     return 0;
  716 }
  717 
  718 
  719 /*
  720  * usage
  721  */
  722 
  723 static void
  724 #if _proto_stdc
  725 usage (void)
  726 #else
  727 usage ()
  728 #endif
  729 {
  730     printf (DI_GT("di version %s    Default Format: %s\n"), DI_VERSION, DI_DEFAULT_FORMAT);
  731             /*  12345678901234567890123456789012345678901234567890123456789012345678901234567890 */
  732     printf (DI_GT("Usage: di [-ant] [-d display-size] [-f format] [-x exclude-fstyp-list]\n"));
  733     printf (DI_GT("       [-I include-fstyp-list] [file [...]]\n"));
  734     printf (DI_GT("   -a   : print all mounted devices\n"));
  735     printf (DI_GT("   -d x : size to print blocks in (512 - POSIX, k - kbytes,\n"));
  736     printf (DI_GT("          m - megabytes, g - gigabytes, t - terabytes, h - human readable).\n"));
  737     printf (DI_GT("   -f x : use format string <x>\n"));
  738     printf (DI_GT("   -I x : include only file system types in <x>\n"));
  739     printf (DI_GT("   -x x : exclude file system types in <x>\n"));
  740     printf (DI_GT("   -l   : display local filesystems only\n"));
  741     printf (DI_GT("   -n   : don't print header\n"));
  742     printf (DI_GT("   -t   : print totals\n"));
  743     printf (DI_GT(" Format string values:\n"));
  744     printf (DI_GT("    m - mount point                     M - mount point, full length\n"));
  745     printf (DI_GT("    b - total kbytes                    B - kbytes available for use\n"));
  746     printf (DI_GT("    u - used kbytes                     c - calculated kbytes in use\n"));
  747     printf (DI_GT("    f - kbytes free                     v - kbytes available\n"));
  748     printf (DI_GT("    p - percentage not avail. for use   1 - percentage used\n"));
  749     printf (DI_GT("    2 - percentage of user-available space in use.\n"));
  750     printf (DI_GT("    i - total file slots (i-nodes)      U - used file slots\n"));
  751     printf (DI_GT("    F - free file slots                 P - percentage file slots used\n"));
  752     printf (DI_GT("    s - filesystem name                 S - filesystem name, full length\n"));
  753     printf (DI_GT("    t - disk partition type             T - partition type, full length\n"));
  754     printf (DI_GT("See manual page for more options.\n"));
  755 }
  756 
  757 static void
  758 #if _proto_stdc
  759 setDispBlockSize (char *ptr, diOptions_t *diopts, diOutput_t *diout)
  760 #else
  761 setDispBlockSize (ptr, diopts, diout)
  762     char            *ptr;
  763     diOptions_t     *diopts;
  764     diOutput_t      *diout;
  765 #endif
  766 {
  767   unsigned int    len;
  768   _print_size_t   val;
  769   char            *tptr;
  770   static char     tempbl [15];
  771   char            ttempbl [15];
  772 
  773   if (isdigit ((int) (*ptr)))
  774   {
  775       val = (_print_size_t) atof (ptr);
  776   }
  777   else
  778   {
  779       val = (_print_size_t) 1.0;
  780   }
  781 
  782   tptr = ptr;
  783   len = (unsigned int) strlen (ptr);
  784   if (! isdigit ((int) *tptr))
  785   {
  786     int             idx;
  787 
  788     idx = -1;
  789     switch (*tptr)
  790     {
  791       case 'k':
  792       case 'K':
  793       {
  794           idx = DI_ONE_K;
  795           break;
  796       }
  797 
  798       case 'm':
  799       case 'M':
  800       {
  801           idx = DI_ONE_MEG;
  802           break;
  803       }
  804 
  805       case 'g':
  806       case 'G':
  807       {
  808           idx = DI_ONE_GIG;
  809           break;
  810       }
  811 
  812       case 't':
  813       case 'T':
  814       {
  815           idx = DI_ONE_TERA;
  816           break;
  817       }
  818 
  819       case 'p':
  820       case 'P':
  821       {
  822           idx = DI_ONE_PETA;
  823           break;
  824       }
  825 
  826       case 'e':
  827       case 'E':
  828       {
  829           idx = DI_ONE_EXA;
  830           break;
  831       }
  832 
  833       case 'z':
  834       case 'Z':
  835       {
  836           idx = DI_ONE_ZETTA;
  837           break;
  838       }
  839 
  840       case 'y':
  841       case 'Y':
  842       {
  843           idx = DI_ONE_YOTTA;
  844           break;
  845       }
  846 
  847       case 'h':
  848       {
  849           val = (_print_size_t) DI_DISP_HR;
  850           diout->dispBlockLabel = "Size";
  851           break;
  852       }
  853 
  854       case 'H':
  855       {
  856           val = (_print_size_t) DI_DISP_HR_2;
  857           diout->dispBlockLabel = "Size";
  858           break;
  859       }
  860 
  861       default:
  862       {
  863           if (strncmp (ptr, "HUMAN", (Size_t) 5) == 0)
  864           {
  865               val = (_print_size_t) DI_DISP_HR;
  866           }
  867           else
  868           {
  869               /* some unknown string value */
  870             idx = DI_ONE_MEG;
  871           }
  872           break;
  873       }
  874     }
  875 
  876     if (idx >= 0)
  877     {
  878       if (len > 1)
  879       {
  880         ++tptr;
  881         if (*tptr == 'B')
  882         {
  883            diopts->baseDispSize = (_print_size_t) DI_VAL_1000;
  884            diopts->baseDispIdx = DI_DISP_1000_IDX;
  885         }
  886       }
  887 
  888       if (val == (_print_size_t) 1.0)
  889       {
  890         diout->dispBlockLabel = dispTable [idx].disp [diopts->baseDispIdx];
  891       }
  892       else
  893       {
  894         Snprintf1 (ttempbl, sizeof (tempbl), "%%.0%s %%s", DI_Lf);
  895         Snprintf2 (tempbl, sizeof (tempbl), ttempbl,
  896             val, DI_GT (dispTable [idx].disp [diopts->baseDispIdx]));
  897         diout->dispBlockLabel = tempbl;
  898       }
  899       val *= dispTable [idx].size;
  900     } /* known size multiplier */
  901   }
  902   else
  903   {
  904     int         i;
  905     int         ok;
  906 
  907     ok = 0;
  908     for (i = 0; i < (int) DI_DISPTAB_SIZE; ++i)
  909     {
  910       if (val == dispTable [i].size)
  911       {
  912         diout->dispBlockLabel = dispTable [i].disp [diopts->baseDispIdx];
  913         ok = 1;
  914         break;
  915       }
  916     }
  917 
  918     if (ok == 0)
  919     {
  920       Snprintf1 (ttempbl, sizeof (ttempbl), "%%.0%sb", DI_Lf);
  921       Snprintf1 (tempbl, sizeof (tempbl), ttempbl, val);
  922       diout->dispBlockLabel = tempbl;
  923     }
  924   }  /* some oddball block size */
  925 
  926   if (diopts->posix_compat && val == (_print_size_t) DI_VAL_512)
  927   {
  928     diout->dispBlockLabel = "512-blocks";
  929   }
  930   if (diopts->posix_compat && val == (_print_size_t) DI_VAL_1024)
  931   {
  932     diout->dispBlockLabel = "1024-blocks";
  933   }
  934 
  935   diopts->dispBlockSize = val;
  936 }
  937 
  938 
  939 static void
  940 #if _proto_stdc
  941 initDisplayTable (diOptions_t *diopts)
  942 #else
  943 initDisplayTable (diopts)
  944   diOptions_t *diopts;
  945 #endif
  946 {
  947   int       i;
  948 
  949       /* initialize dispTable array */
  950   dispTable [0].size = diopts->baseDispSize;
  951   for (i = 1; i < (int) DI_DISPTAB_SIZE; ++i)
  952   {
  953     dispTable [i].size = dispTable [i - 1].size *
  954         diopts->baseDispSize;
  955   }
  956 }
  957 
  958 static void
  959 #if _proto_stdc
  960 setExitFlag (diOptions_t *diopts, unsigned int exitFlag)
  961 #else
  962 setExitFlag (diopts, exitFlag)
  963   diOptions_t   *diopts;
  964   unsigned int  exitFlag;
  965 #endif
  966 {
  967   if (exitFlag > diopts->exitFlag) {
  968     diopts->exitFlag = exitFlag;
  969   }
  970 }