1 | /* |
---|
2 | * Copyright (c) 1992-1998 Michael A. Cooper. |
---|
3 | * This software may be freely used and distributed provided it is not |
---|
4 | * sold for profit or used in part or in whole for commercial gain |
---|
5 | * without prior written agreement, and the author is credited |
---|
6 | * appropriately. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef lint |
---|
10 | static char *RCSid = "$Revision: 1.1.1.3 $"; |
---|
11 | #endif |
---|
12 | |
---|
13 | /* |
---|
14 | * General Information routines |
---|
15 | */ |
---|
16 | |
---|
17 | #include "defs.h" |
---|
18 | |
---|
19 | /* |
---|
20 | * Option compatibility support |
---|
21 | */ |
---|
22 | #if defined(OLD_OPTION_COMPAT) |
---|
23 | #define OptCom(v) v |
---|
24 | #else |
---|
25 | #define OptCom(v) 0 |
---|
26 | #endif |
---|
27 | |
---|
28 | static ShowInfo_t ShowInfo[] = { |
---|
29 | { "hostname", "Host Name", GetHostName }, |
---|
30 | { "hostaliases", "Host Aliases", GetHostAliases }, |
---|
31 | { "hostaddrs", "Host Address(es)", GetHostAddrs }, |
---|
32 | { "hostid", "Host ID", GetHostID }, |
---|
33 | { "serial", "Serial Number", GetSerial }, |
---|
34 | { "man", "Manufacturer", GetMan }, |
---|
35 | { "model", "System Model", GetModel }, |
---|
36 | { "memory", "Main Memory", GetMemory }, |
---|
37 | { "virtmem", "Virtual Memory", GetVirtMem }, |
---|
38 | { "romver", "ROM Version", GetRomVer }, |
---|
39 | { "numcpu", "Number of CPUs", GetNumCpu }, |
---|
40 | { "cpu", "CPU Type", GetCpuType }, |
---|
41 | { "arch", "App Architecture", GetAppArch }, |
---|
42 | { "karch", "Kernel Architecture", GetKernArch }, |
---|
43 | { "osname", "OS Name", GetOSName }, |
---|
44 | { "osvers", "OS Version", GetOSVer }, |
---|
45 | { "osdist", "OS Distribution", GetOSDist }, |
---|
46 | { "kernver", "Kernel Version", GetKernVer }, |
---|
47 | { "boottime", "Boot Time", GetBootTime }, |
---|
48 | { 0 }, |
---|
49 | }; |
---|
50 | |
---|
51 | /* |
---|
52 | * List valid arguments for the General class. |
---|
53 | */ |
---|
54 | extern void GeneralList() |
---|
55 | { |
---|
56 | register ShowInfo_t *ShowPtr; |
---|
57 | |
---|
58 | SImsg(SIM_INFO, "\n\nThe following are valid arguments for `-class General -show Name1,Name2,...':\n\n"); |
---|
59 | SImsg(SIM_INFO, "%-25s %s\n", "NAME", "DESCRIPTION"); |
---|
60 | |
---|
61 | for (ShowPtr = &ShowInfo[0]; ShowPtr->Name; ++ShowPtr) |
---|
62 | SImsg(SIM_INFO, "%-25s %s\n", ShowPtr->Name, ShowPtr->Label); |
---|
63 | } |
---|
64 | |
---|
65 | /* |
---|
66 | * Show General class information. |
---|
67 | */ |
---|
68 | extern void GeneralShow(MyClass, Names) |
---|
69 | ClassInfo_t *MyClass; |
---|
70 | char **Names; |
---|
71 | { |
---|
72 | static char *RptData[3]; |
---|
73 | register char **cpp; |
---|
74 | char *Value; |
---|
75 | register ShowInfo_t *ShowPtr; |
---|
76 | int Found = 0; |
---|
77 | register int Len = 0; |
---|
78 | register int MaxLen = 0; |
---|
79 | |
---|
80 | if (Names) { |
---|
81 | /* |
---|
82 | * Enable only the specific items specified by user |
---|
83 | */ |
---|
84 | for (cpp = Names; cpp && *cpp; ++cpp) { |
---|
85 | for (ShowPtr = ShowInfo; ShowPtr->Name; ++ShowPtr) |
---|
86 | if (EQ(*cpp, ShowPtr->Name)) |
---|
87 | break; |
---|
88 | if (ShowPtr->Name && ShowPtr->Get) { |
---|
89 | ShowPtr->Enabled = TRUE; |
---|
90 | Found = TRUE; |
---|
91 | } |
---|
92 | } |
---|
93 | } else { |
---|
94 | Found = TRUE; |
---|
95 | /* |
---|
96 | * No items specified so enable everything |
---|
97 | */ |
---|
98 | for (ShowPtr = ShowInfo; ShowPtr->Name; ++ShowPtr) |
---|
99 | ShowPtr->Enabled = TRUE; |
---|
100 | } |
---|
101 | |
---|
102 | if (Found) |
---|
103 | ClassShowBanner(MyClass); |
---|
104 | |
---|
105 | for (ShowPtr = ShowInfo; ShowPtr->Name; ++ShowPtr) { |
---|
106 | Len = strlen(ShowPtr->Label); |
---|
107 | if (VL_ALL) |
---|
108 | Len += strlen(ShowPtr->Name) + 2; |
---|
109 | if (Len > MaxLen) |
---|
110 | MaxLen = Len; |
---|
111 | } |
---|
112 | |
---|
113 | for (ShowPtr = ShowInfo; ShowPtr->Name; ++ShowPtr) |
---|
114 | if (ShowPtr->Enabled) |
---|
115 | switch (FormatType) { |
---|
116 | case FT_PRETTY: |
---|
117 | Value = (*ShowPtr->Get)(); |
---|
118 | if (!Value) |
---|
119 | Value = UnSupported; |
---|
120 | ClassShowValue(ShowPtr->Label, ShowPtr->Name, |
---|
121 | Value, MaxLen); |
---|
122 | break; |
---|
123 | case FT_REPORT: |
---|
124 | RptData[0] = PRTS(ShowPtr->Label); |
---|
125 | RptData[1] = PRTS((*ShowPtr->Get)()); |
---|
126 | Report(CN_GENERAL, NULL, ShowPtr->Name, RptData, 2); |
---|
127 | break; |
---|
128 | } |
---|
129 | } |
---|