home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume28 / sysinfo-2.1.2 / part03 / sysinfo.c < prev   
C/C++ Source or Header  |  1994-06-19  |  18KB  |  782 lines

  1. /*
  2.  * Copyright (c) 1992-1994 Michael A. Cooper.
  3.  * This software may be freely distributed provided it is not sold for 
  4.  * profit and the author is credited appropriately.
  5.  */
  6.  
  7. #ifndef lint
  8. static char *RCSid = "$Id: sysinfo.c,v 1.67 1994/01/12 22:56:08 mcooper Exp mcooper $";
  9. #endif
  10.  
  11. /*
  12.  * Display System Information
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <sys/types.h>
  17. #include <sys/socket.h>
  18. #include <netinet/in.h>
  19. #include <arpa/inet.h>
  20. #include <netdb.h>
  21.  
  22. #include "defs.h"
  23.  
  24. /*
  25.  * Local declarations
  26.  */
  27. int                 DoPrintAll = TRUE;
  28. int                 DoPrintUnknown = FALSE;
  29. int                 DoPrintVersion = FALSE;
  30. int                 Level = L_BRIEF;
  31. int                 Terse = FALSE;
  32. int                 Debug = 0;
  33. int                 UseProm = 0;
  34. int                 OffSetAmt = 4;
  35. char                    *ShowStr = NULL;
  36. char                    *LevelStr = NULL;
  37. char                    *ListStr = NULL;
  38. char                    *UnSupported = NULL;
  39. char                  **Environ = NULL;
  40.  
  41. #if    defined(OPTION_COMPAT)
  42. /*
  43.  * Old options here for backwards compatibility
  44.  */
  45. int                DoPrintCPU = FALSE;
  46. int                DoPrintAppArch = FALSE;
  47. int                DoPrintHostID = FALSE;
  48. int                DoPrintHostName = FALSE;
  49. int                DoPrintHostAlias = FALSE;
  50. int                DoPrintHostAddrs = FALSE;
  51. int                DoPrintKernArch = FALSE;
  52. int                DoPrintKernVer = FALSE;
  53. int                DoPrintMan = FALSE;
  54. int                DoPrintModel = FALSE;
  55. int                DoPrintMemory = FALSE;
  56. int                DoPrintVirtMem = FALSE;
  57. int                DoPrintOSName = FALSE;
  58. int                DoPrintOSVer = FALSE;
  59. int                DoPrintSerialNo = FALSE;
  60. #endif    /* OPTION_COMPAT */
  61.  
  62. /*
  63.  * Command line options table.
  64.  */
  65. OptionDescRec Opts[] = {
  66.     {"+all",     NoArg,        OptBool,     __ &DoPrintAll,        "1",
  67.      NULL,    "Print all information"},
  68.     {"-all",     NoArg,        OptBool,     __ &DoPrintAll,        "0",
  69.      NULL,    "Don't print all information"},
  70.     {"-level",    SepArg,        OptStr,     __ &LevelStr,        NULL,
  71.      "<see \"-list level\">",    "Level names"},
  72.     {"-list",    SepArg,        OptStr,     __ &ListStr,        "-",
  73.      "level,show",    "List information about values"},
  74.     {"-offset",    SepArg,        OptInt,     __ &OffSetAmt,        NULL,
  75.      "<amount>",    "Number of spaces to offset device info"},
  76.     {"-show",    SepArg,        OptStr,     __ &ShowStr,        NULL,
  77.      "<see \"-list show\">",    "Show names"},
  78.     {"+terse",     NoArg,        OptBool,     __ &Terse,        "1",
  79.      NULL,    "Print info in terse format"},
  80.     {"-terse",     NoArg,        OptBool,     __ &Terse,        "0",
  81.      NULL,    "Don't print info in terse format"},
  82.     {"+unknown",NoArg,        OptBool,     __ &DoPrintUnknown,    "1",
  83.      NULL,    "Print unknown devices"},
  84.     {"-unknown",NoArg,        OptBool,     __ &DoPrintUnknown,    "0",
  85.      NULL,    "Don't print unknown devices"},
  86.     {"+useprom",NoArg,        OptBool,     __ &UseProm,        "1",
  87.      NULL,    "Use PROM values"},
  88.     {"-useprom",NoArg,        OptBool,     __ &UseProm,        "0",
  89.      NULL,    "Don't use PROM values"},
  90.     {"-version",NoArg,        OptBool,     __ &DoPrintVersion,    "1",
  91.      NULL,    "Print version of this program" },
  92.     {"-debug",ArgHidden|SepArg,    OptInt,     __ &Debug,        "1",
  93.      NULL,    "Enable debugging"},
  94. #if    defined(OPTION_COMPAT)
  95.     {"+cpu",     NoArg|ArgHidden,OptBool,__ &DoPrintCPU,        "1" },
  96.     {"-cpu",     NoArg|ArgHidden,OptBool,__ &DoPrintCPU,        "0" },
  97.     {"+arch",     NoArg|ArgHidden,OptBool,__ &DoPrintAppArch,    "1" },
  98.     {"-arch",     NoArg|ArgHidden,OptBool,__ &DoPrintAppArch,    "0" },
  99.     {"+hostid",    NoArg|ArgHidden,OptBool,__ &DoPrintHostID,    "1" },
  100.     {"-hostid",    NoArg|ArgHidden,OptBool,__ &DoPrintHostID,    "0" },
  101.     {"+hostname",NoArg|ArgHidden,OptBool,__ &DoPrintHostName,    "1" },
  102.     {"-hostname",NoArg|ArgHidden,OptBool,__ &DoPrintHostName,    "0" },
  103.     {"+hostaliases",NoArg|ArgHidden,OptBool,__ &DoPrintHostAlias,"1" },
  104.     {"-hostaliases",NoArg|ArgHidden,OptBool,__ &DoPrintHostAlias,"0" },
  105.     {"+hostaddrs",NoArg|ArgHidden,OptBool,__ &DoPrintHostAddrs,    "1" },
  106.     {"-hostaddrs",NoArg|ArgHidden,OptBool,__ &DoPrintHostAddrs,    "0" },
  107.     {"+karch",     NoArg|ArgHidden,OptBool,__ &DoPrintKernArch,    "1" },
  108.     {"-karch",     NoArg|ArgHidden,OptBool,__ &DoPrintKernArch,    "0" },
  109.     {"+kernver",NoArg|ArgHidden,OptBool,__ &DoPrintKernVer,    "1" },
  110.     {"-kernver",NoArg|ArgHidden,OptBool,__ &DoPrintKernVer,    "0" },
  111.     {"+man",     NoArg|ArgHidden,OptBool,__ &DoPrintMan,        "1" },
  112.     {"-man",     NoArg|ArgHidden,OptBool,__ &DoPrintMan,        "0" },
  113.     {"+model",     NoArg|ArgHidden,OptBool,__ &DoPrintModel,    "1" },
  114.     {"-model",     NoArg|ArgHidden,OptBool,__ &DoPrintModel,    "0" },
  115.     {"+memory",    NoArg|ArgHidden,OptBool,__ &DoPrintMemory,    "1" },
  116.     {"-memory",    NoArg|ArgHidden,OptBool,__ &DoPrintMemory,    "0" },
  117.     {"+virtmem",NoArg|ArgHidden,OptBool,__ &DoPrintVirtMem,    "1" },
  118.     {"-virtmem",NoArg|ArgHidden,OptBool,__ &DoPrintVirtMem,    "0" },
  119.     {"+osname",    NoArg|ArgHidden,OptBool,__ &DoPrintOSName,    "1" },
  120.     {"-osname",    NoArg|ArgHidden,OptBool,__ &DoPrintOSName,    "0" },
  121.     {"+osvers",    NoArg|ArgHidden,OptBool,__ &DoPrintOSVer,    "1" },
  122.     {"-osvers",    NoArg|ArgHidden,OptBool,__ &DoPrintOSVer,    "0" },
  123.     {"+serial",    NoArg|ArgHidden,OptBool,__ &DoPrintSerialNo,    "1" },
  124.     {"-serial",    NoArg|ArgHidden,OptBool,__ &DoPrintSerialNo,    "0" },
  125. #endif    /* OPTION_COMPAT */
  126. };
  127.  
  128. /*
  129.  * Option compatibility support
  130.  */
  131. #if    defined(OPTION_COMPAT)
  132. static void            SetOptionCompat();
  133. #define OptCom(v) v
  134. #else
  135. #define OptCom(v) 0
  136. #endif
  137.  
  138. SHOWINFO ShowInfo[] = {
  139.     { S_GEN, "general",    "GENERAL INFORMATION",    ShowGeneral },
  140.     { S_GEN, "hostname",    "Host Name",        NULL, GetHostName,
  141.                         OptCom(&DoPrintHostName) },
  142.     { S_GEN, "hostaliases",    "Host Aliases",        NULL, GetHostAliases,
  143.                         OptCom(&DoPrintHostAlias) },
  144.     { S_GEN, "hostaddrs",    "Host Address(es)",    NULL, GetHostAddrs,
  145.                         OptCom(&DoPrintHostAddrs) },
  146.     { S_GEN, "hostid",        "Host ID",        NULL, GetHostID,
  147.                         OptCom(&DoPrintHostID) },
  148.     { S_GEN, "serial",        "Serial Number",    NULL, GetSerialNo,
  149.                         OptCom(&DoPrintSerialNo) },
  150.     { S_GEN, "man",        "Manufacturer",        NULL, GetMan,
  151.                         OptCom(&DoPrintMan) },
  152.     { S_GEN, "model",        "System Model",        NULL, GetModel,
  153.                         OptCom(&DoPrintModel) },
  154.     { S_GEN, "memory",        "Main Memory",        NULL, GetMemory,
  155.                         OptCom(&DoPrintMemory) },
  156.     { S_GEN, "virtmem",        "Virtual Memory",    NULL, GetVirtMem,
  157.                         OptCom(&DoPrintVirtMem) },
  158.     { S_GEN, "romver",        "ROM Version",        NULL, GetRomVer },
  159.     { S_GEN, "cpu",        "CPU Type",        NULL, GetCPU,
  160.                         OptCom(&DoPrintCPU) },
  161.     { S_GEN, "numcpu",        "Number of CPUs",    NULL, GetNumCPU,
  162.                         OptCom(&DoPrintCPU) },
  163.     { S_GEN, "arch",        "App Architecture",    NULL, GetAppArch,
  164.                         OptCom(&DoPrintAppArch) },
  165.     { S_GEN, "karch",        "Kernel Architecture",    NULL, GetKernArch,
  166.                         OptCom(&DoPrintKernArch) },
  167.     { S_GEN, "osname",        "OS Name",        NULL, GetOSName,
  168.                         OptCom(&DoPrintOSName) },
  169.     { S_GEN, "osvers",        "OS Version",        NULL, GetOSVersion,
  170.                         OptCom(&DoPrintOSVer) },
  171.     { S_GEN, "kernver",        "Kernel Version",    NULL, GetKernelVersion,
  172.                         OptCom(&DoPrintKernVer) },
  173.     { S_DEV, "devices",    "DEVICE INFORMATION",    ShowDevices },
  174.     { 0 },
  175. };
  176.  
  177. /*
  178.  * Values and names of levels
  179.  */
  180. NAMETAB LevelNames[] = {
  181.     { L_BRIEF,        "brief" },
  182.     { L_GENERAL,    "general" },
  183.     { L_DESC,        "descriptions" },
  184.     { L_CONFIG,        "config" },
  185.     { L_ALL,        "all" },
  186.     { L_DEBUG,        "debug" },
  187.     { 0 },
  188. };
  189.  
  190. /*
  191.  * List table
  192.  */
  193. struct listtab {
  194.     char               *Name;
  195.     char               *Desc;
  196.     void              (*Func)();
  197. };
  198. typedef struct listtab LISTTAB;
  199.  
  200. static void            List();
  201. static void            ListLevel();
  202. static void            ListShow();
  203.  
  204. LISTTAB ListTab[] = {
  205.     { "level",        "Values for -level option",    ListLevel },
  206.     { "show",        "Values for -show option",    ListShow },
  207.     { 0 },
  208. };
  209.  
  210. /*
  211.  * Print a label and an argument
  212.  */
  213. static void PrintLabel(Lbl, Str)
  214.      char                *Lbl;
  215.      char                *Str;
  216. {
  217.     if (!Terse)
  218.     printf("%-*s: ", 20, Lbl);
  219.     printf("%s\n", (Str && *Str) ? Str : "");
  220. }
  221.  
  222. /*
  223.  * Print general info
  224.  */
  225. extern void ShowGeneral(MyInfo, SpecInfo)
  226.     SHOWINFO               *MyInfo;
  227.     SHOWINFO               *SpecInfo;
  228. {
  229.     register int        i;
  230.     int                ShowAll = TRUE;
  231.  
  232.     /*
  233.      * Do a specific info item
  234.      */
  235.     if (SpecInfo) {
  236.     PrintLabel(SpecInfo->Label, (*SpecInfo->GetFunc)());
  237.     SpecInfo->Enable = FALSE;
  238.     return;
  239.     }
  240.  
  241.     /*
  242.      * See if we are going to show all items
  243.      */
  244.     if (!DoPrintAll)
  245.     for (i = 0; ShowInfo[i].Name; i++)
  246.         if (ShowInfo[i].Type == MyInfo->Type && 
  247.         ShowInfo[i].GetFunc && !ShowInfo[i].Enable) {
  248.         ShowAll = FALSE;
  249.         break;
  250.         }
  251.  
  252.     if (MyInfo && (DoPrintAll || ShowAll || MyInfo->Enable))
  253.     printf("\n\n\t%s\n\n", MyInfo->Label);
  254.  
  255.     /*
  256.      * Print each enabled item of our type
  257.      */
  258.     for (i = 0; ShowInfo[i].Name; i++)
  259.     if ((ShowInfo[i].Type == MyInfo->Type) &&
  260.         (ShowInfo[i].Enable || MyInfo->Enable) && ShowInfo[i].GetFunc) {
  261.         PrintLabel(ShowInfo[i].Label, (*ShowInfo[i].GetFunc)());
  262.         ShowInfo[i].Enable = FALSE;
  263.     }
  264.  
  265.     if (MyInfo)
  266.     MyInfo->Enable = FALSE;
  267. }
  268.  
  269. /*
  270.  * List Show values
  271.  */
  272. static void ListShow()
  273. {
  274.     register int        i;
  275.  
  276.     printf(
  277.     "The following values may be specified with the \"-show\" option:\n");
  278.     printf("\t%-20s %s\n", "VALUE", "DESCRIPTION");
  279.  
  280.     for (i = 0; ShowInfo[i].Name; i++)
  281.     printf("\t%-20s %s%s\n",
  282.            ShowInfo[i].Name,
  283.            (ShowInfo[i].ShowFunc) ? "Show all " : "",
  284.            ShowInfo[i].Label
  285.            );
  286. }
  287.  
  288. /*
  289.  * List Level values
  290.  */
  291. static void ListLevel()
  292. {
  293.     register int        i;
  294.  
  295.     printf(
  296.     "The following values may be specified with the \"-level\" option:\n");
  297.     printf("\t%-20s\n", "VALUE");
  298.  
  299.     for (i = 0; LevelNames[i].name; i++) {
  300.     printf("\t%s\n", LevelNames[i].name);
  301.     }
  302. }
  303.  
  304. /*
  305.  * List list values
  306.  */
  307. static void ListList()
  308. {
  309.     register int        i;
  310.  
  311.     printf(
  312.     "The following values may be specified with the \"-list\" option:\n");
  313.     printf("\t%-20s %s\n", "VALUE", "DESCRIPTION");
  314.  
  315.     for (i = 0; ListTab[i].Name; i++) {
  316.     printf("\t%-20s %s\n",
  317.            ListTab[i].Name,
  318.            ListTab[i].Desc
  319.            );
  320.     }
  321. }
  322.  
  323. /*
  324.  * List information about each word found in Str.
  325.  */
  326. static void List(Str)
  327.     char               *Str;
  328. {
  329.     register int        i;
  330.     char               *Word;
  331.     int                Found;
  332.  
  333.     if (EQ(Str, "-")) {
  334.     ListList();
  335.     return;
  336.     }
  337.  
  338.     for (Word = strtok(Str, ","); Word; Word = strtok((char *)NULL, ",")) {
  339.     for (i = 0, Found = FALSE; ListTab[i].Name && !Found; i++)
  340.         if (EQ(Word, ListTab[i].Name)) {
  341.         Found = TRUE;
  342.         (*ListTab[i].Func)();
  343.         }
  344.  
  345.     if (!Found) {
  346.         Error("The word \"%s\" is invalid.", Word);
  347.         ListList();
  348.         return;
  349.     }
  350.     }
  351. }
  352.  
  353. /*
  354.  * Get argument number "arg" from "str".
  355.  */
  356. static char *GetArg(Str, ArgNum)
  357.     char                *Str;
  358.     int             ArgNum;
  359. {
  360.     register char            *p, *start = NULL;
  361.     register int         c;
  362.  
  363.     for (c = 1, p = Str; p && *p; ++c) {
  364.     /* set start of word */
  365.     start = p; 
  366.  
  367.     /* skip over word */
  368.     while (p && *p && *p != ' ' && *p != '\t' && *p != '\n')
  369.         ++p;
  370.  
  371.     /* is this what we want? */
  372.     if (c == ArgNum) {
  373.         if (p) *p = C_NULL;
  374.         break;
  375.     }
  376.  
  377.     /* skip white space */
  378.     while (*p == ' ' || *p == '\t')
  379.         ++p;
  380.     }
  381.  
  382.     return(start);
  383. }
  384.  
  385. /*
  386.  * Convert integer to ASCII
  387.  */
  388. char *itoa(Num)
  389.     int             Num;
  390. {
  391.     static char         Buf[BUFSIZ];
  392.  
  393.     (void) sprintf(Buf, "%d", Num);
  394.  
  395.     return(Buf);
  396. }
  397.  
  398. /*
  399.  * Get our hostname
  400.  */
  401. extern char *GetHostName()
  402. {
  403.     static char         Buf[MAXHOSTNAMLEN+1];
  404.  
  405.     gethostname(Buf, sizeof(Buf));
  406.  
  407.     return((Buf[0]) ? Buf : (char *) NULL);
  408. }
  409.  
  410. /*
  411.  * Get aliases for this hostname
  412.  *
  413.  * Note that this won't work on most systems if your
  414.  * gethostbyname() call gets its info from DNS since
  415.  * DNS does not provide this funtionality.
  416.  */
  417. extern char *GetHostAliases()
  418. {
  419.     static char         Buf[BUFSIZ];
  420.     struct hostent            *hp;
  421.     register char          **pp;
  422.     char                *HName;
  423.  
  424.     if ((HName = GetHostName()) == NULL)
  425.     return((char *) NULL);
  426.  
  427.     if ((hp = gethostbyname(HName)) == NULL) {
  428.     Error("Cannot find lookup host info for \"%s\": %s", HName, SYSERR);
  429.     return((char *) NULL);
  430.     }
  431.  
  432.     for (pp = hp->h_aliases, Buf[0] = C_NULL; pp && *pp; ++pp) {
  433.     (void) strcat(Buf, *pp);
  434.     (void) strcat(Buf, " ");
  435.     }
  436.  
  437.     return((Buf[0]) ? Buf : (char *) NULL);
  438. }
  439.  
  440. /*
  441.  * Get addresses for this host
  442.  */
  443. extern char *GetHostAddrs()
  444. {
  445.     static char         Buf[BUFSIZ];
  446.     struct hostent            *hp;
  447.     register char          **pp;
  448.     char                *HName;
  449.  
  450.     if ((HName = GetHostName()) == NULL)
  451.     return((char *) NULL);
  452.  
  453.     if ((hp = gethostbyname(HName)) == NULL) {
  454.     Error("Cannot find lookup host info for \"%s\": %s", HName, SYSERR);
  455.     return((char *) NULL);
  456.     }
  457.  
  458.     for (pp = hp->h_addr_list, Buf[0] = C_NULL; pp && *pp; ++pp) {
  459.     if (hp->h_addrtype == AF_INET) {
  460.         (void) strcat(Buf, (char *) inet_ntoa(*(struct in_addr *)*pp));
  461.         (void) strcat(Buf, " ");
  462.     }
  463.     }
  464.  
  465.     return((Buf[0]) ? Buf : (char *) NULL);
  466. }
  467.  
  468. /*
  469.  * Get system model
  470.  */
  471. extern char *GetModel()
  472. {
  473.     int             Len;
  474.     FILE                *fd;
  475.     char             Buf[BUFSIZ];
  476.     char               *GetModelName();
  477. #if    defined(MODEL_COMMAND)
  478.     extern char            *ModelCommand[];
  479. #endif    /* MODEL_COMMAND */
  480.  
  481.     /*
  482.      * Use model file if it exists.
  483.      */
  484.     if ((fd = fopen(MODELFILE, "r")) != NULL) {
  485.     fgets(Buf, sizeof(Buf), fd);
  486.     Len = strlen(Buf);
  487.     if (Buf[Len-1] == '\n') 
  488.         Buf[Len-1] = C_NULL;
  489.     return(Buf);
  490.     }
  491.  
  492.     /*
  493.      * If a command to get model name has been defined, try it.
  494.      */
  495. #if    defined(MODEL_COMMAND)
  496.     if (p = RunCmds(ModelCommand, FALSE))
  497.     return(p);
  498. #endif    /* MODEL_COMMAND */
  499.  
  500.     /*
  501.      * Use a method specific to this OS
  502.      */
  503.     return(GetModelName());
  504. }
  505.  
  506. /*
  507.  * Get host ID
  508.  */
  509. extern char *GetHostID()
  510. {
  511.     static char         Buf[100];
  512.  
  513.     (void) sprintf(Buf, "%08x", gethostid());
  514.  
  515.     return(Buf);
  516. }
  517.  
  518. /*
  519.  * Get system serial number
  520.  */
  521. extern char *GetSerialNo()
  522. {
  523.     return(GetSerialNoStr());
  524. }
  525.  
  526. /*
  527.  * Print error message
  528.  */
  529. #if    defined(HAVE_VARARGS)
  530. #include <varargs.h>
  531. /*
  532.  * Varargs version of Error()
  533.  */
  534. extern void Error(va_alist)
  535.     va_dcl
  536. {
  537.     va_list             args;
  538.     char                *fmt;
  539.     extern char            *ProgramName;
  540.  
  541.     (void) fflush(stdout);
  542.     (void) fprintf(stderr, "%s: ", ProgramName);
  543.     va_start(args);
  544.     fmt = (char *) va_arg(args, char *);
  545.     (void) vfprintf(stderr, fmt, args);
  546.     va_end(args);
  547.     (void) fprintf(stderr, "\n");
  548. }
  549. #else
  550. /*
  551.  * Non-Varargs version of Error()
  552.  */
  553. extern void Error(fmt, a1, a2, a3, a4, a5, a6)
  554.     char                *fmt;
  555. {
  556.     extern char            *ProgramName;
  557.  
  558.     (void) fflush(stdout);
  559.     (void) fprintf(stderr, "%s: ", ProgramName);
  560.     (void) fprintf(stderr, fmt, a1, a2, a3, a4, a5, a6);
  561.     (void) fprintf(stderr, "\n");
  562. }
  563. #endif     /* !HAVE_VARARGS */
  564.  
  565. /*
  566.  * Parse and set the level keyword list
  567.  */
  568. static int ParseLevel(Str)
  569.     char               *Str;
  570. {
  571.     register int        i;
  572.     char               *Word;
  573.     int                Found;
  574.  
  575.     /*
  576.      * Check each word in the LevelNames table
  577.      */
  578.     for (Word = strtok(Str, ","); Word; Word = strtok((char *)NULL, ",")) {
  579.     for (i = 0, Found = FALSE; LevelNames[i].name && !Found; i++) {
  580.         if (strncasecmp(Word, LevelNames[i].name, strlen(Word)) == 0) {
  581.         Level |= LevelNames[i].value;
  582.         Found = TRUE;
  583.         }
  584.     }
  585.     if (!Found) {
  586.         Error("The word \"%s\" is not a valid verbosity level.", Word);
  587.         return(-1);
  588.     }
  589.     }
  590.  
  591.     return(0);
  592. }
  593.  
  594. /*
  595.  * Parse and set the showinfo items
  596.  */
  597. static int ParseShow(Str)
  598.     char               *Str;
  599. {
  600.     register int        x;
  601.     char               *Word;
  602.     int                Found;
  603.  
  604.     /*
  605.      * Check each word.
  606.      */
  607.     for (Word = strtok(Str, ","); Word; Word = strtok((char *)NULL, ",")) {
  608.     /*
  609.      * Search the ShowInfo entries for a match.
  610.      */
  611.     for (x = 0, Found = FALSE; !Found && ShowInfo[x].Name; x++)
  612.         if (EQ(Word, ShowInfo[x].Name)) {
  613.         ShowInfo[x].Enable = TRUE;
  614.         DoPrintAll = FALSE;
  615.         Found = TRUE;
  616.         }
  617.  
  618.     if (!Found) {
  619.         Error("The word \"%s\" is not valid.", Word);
  620.         ListShow();
  621.         return(-1);
  622.     }
  623.     }
  624.  
  625.     return(0);
  626. }
  627.  
  628. /*
  629.  * Front end to calloc()
  630.  */
  631. char *xcalloc(nele, esize)
  632.     int             nele;
  633.     int             esize;
  634. {
  635.     char                *p, *calloc();
  636.  
  637.     if ((p = calloc(nele, esize)) == NULL) {
  638.     Error("calloc(%d, %d) failed.", nele, esize);
  639.     exit(1);
  640.     }
  641.  
  642.     return(p);
  643. }
  644.  
  645. char *xmalloc(size)
  646.     int                size;
  647. {
  648.     char               *newptr, *malloc();
  649.  
  650.     if (!(newptr = malloc(size))) {
  651.     Error("malloc size %d failed: %s", size, SYSERR);
  652.     exit(1);
  653.     }
  654.  
  655.     return(newptr);
  656. }
  657.  
  658. char *xrealloc(ptr, size)
  659.     char               *ptr;
  660.     int                size;
  661. {
  662.     char               *newptr, *realloc();
  663.  
  664.     if (!(newptr = realloc(ptr, size))) {
  665.     Error("realloc 0x%x size %d failed: %s", ptr, size, SYSERR);
  666.     exit(1);
  667.     }
  668.  
  669.     return(newptr);
  670. }
  671.  
  672. #if    defined(OPTION_COMPAT)
  673. /*
  674.  * Set option compatibility
  675.  */
  676. static void SetOptionCompat()
  677. {
  678.     register int        i;
  679.  
  680.     /*
  681.      * For every OptCompat that's TRUE, enable the real value
  682.      */
  683.     for (i = 0; ShowInfo[i].Name; i++) 
  684.     if (ShowInfo[i].OptCompat && *ShowInfo[i].OptCompat) {
  685.         ShowInfo[i].Enable = TRUE;
  686.         /*
  687.          * These is also part of the old behavior
  688.          */
  689.         DoPrintAll = FALSE;
  690.         Terse = TRUE;
  691.     }
  692.  
  693. }
  694. #endif    /* OPTION_COMPAT */
  695.  
  696. /*
  697.  * The beginning
  698.  */
  699. main(Argc, Argv, Envp)
  700.     int             Argc;
  701.     char               **Argv;
  702.     char               **Envp;
  703. {
  704.     register int        i;
  705.  
  706.     Environ = Envp;
  707.  
  708.     if (ParseOptions(Opts, Num_Opts(Opts), Argc, Argv) < 0)
  709.         exit(1);
  710.  
  711.     UnSupported = (Debug) ? "**UNSUPPORTED**" : (char *)NULL;
  712.  
  713.     /*
  714.      * Show version info
  715.      */
  716.     if (DoPrintVersion) {
  717.     if (!Terse)
  718.         printf("Sysinfo version ");
  719.     if (PATCHLEVEL)
  720.         printf("%s.%d\n", VERSION_STR, PATCHLEVEL);
  721.     else
  722.         printf("%s\n", VERSION_STR, PATCHLEVEL);
  723.     exit(0);
  724.     }
  725.  
  726.     /*
  727.      * Do any list commands and exit
  728.      */
  729.     if (ListStr) {
  730.     List(ListStr);
  731.     exit(0);
  732.     }
  733.  
  734. #if    defined(OPTION_COMPAT)
  735.     SetOptionCompat();
  736. #endif
  737.  
  738.     /*
  739.      * Set verbosity strings
  740.      */
  741.     if (LevelStr && ParseLevel(LevelStr))
  742.     exit(1);
  743.  
  744.     if (ShowStr && ParseShow(ShowStr))
  745.     exit(1);
  746.  
  747.     /*
  748.      * Run down the main topics
  749.      */
  750.     for (i = 0; ShowInfo[i].Name; i++) {
  751.     if (!(DoPrintAll || ShowInfo[i].Enable))
  752.         continue;
  753.  
  754.     if (ShowInfo[i].ShowFunc) {
  755.         /*
  756.          * The item has a show function
  757.          */
  758.         (*ShowInfo[i].ShowFunc)(&ShowInfo[i], NULL);
  759.     } else {
  760.         register int    x;
  761.         int            Found;
  762.  
  763.         /*
  764.          * Search for and call a search function for this type of item
  765.          */
  766.         for (x = 0, Found = FALSE; !Found && ShowInfo[x].Name; x++)
  767.         if ((ShowInfo[x].Type == ShowInfo[i].Type) &&
  768.             ShowInfo[x].ShowFunc) {
  769.             Found = TRUE;
  770.             (*ShowInfo[x].ShowFunc)(&ShowInfo[x], &ShowInfo[i]);
  771.         }
  772.         if (!Found) {
  773.         Error("No show function exists for \"%s\".", 
  774.               ShowInfo[i].Name);
  775.         exit(1);
  776.         }
  777.     }
  778.     }
  779.  
  780.     exit(0);
  781. }
  782.