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 | * System Configuration |
---|
15 | * |
---|
16 | * Use the sysconf() routine to show system configuration info. |
---|
17 | * This routine is available on POSIX complient systems. |
---|
18 | */ |
---|
19 | #include "defs.h" |
---|
20 | |
---|
21 | /* |
---|
22 | * List valid arguments for the SysConf class. |
---|
23 | */ |
---|
24 | extern void SysConfList() |
---|
25 | { |
---|
26 | #if defined(HAVE_SYSCONF) |
---|
27 | register Define_t *DefPtr; |
---|
28 | |
---|
29 | DefPtr = DefGetList(DL_SYSCONF); |
---|
30 | if (!DefPtr) { |
---|
31 | SImsg(SIM_WARN, "No sysconf variables are defined."); |
---|
32 | return; |
---|
33 | } |
---|
34 | |
---|
35 | SImsg(SIM_INFO, "\n\nThe following are valid arguments for `-class SysConf -show Name1,Name2,...':\n\n"); |
---|
36 | SImsg(SIM_INFO, "%-25s %s\n", "NAME", "DESCRIPTION"); |
---|
37 | |
---|
38 | for ( ; DefPtr; DefPtr = DefPtr->Next) |
---|
39 | if (sysconf(DefPtr->KeyNum) > 0) |
---|
40 | SImsg(SIM_INFO, "%-25s %s\n", DefPtr->KeyStr, DefPtr->ValStr2); |
---|
41 | #endif /* HAVE_SYSCONF */ |
---|
42 | } |
---|
43 | |
---|
44 | /* |
---|
45 | * Check to see if a symbol named String appears |
---|
46 | * in Argv. |
---|
47 | * Return 1 if found. |
---|
48 | * Return 0 if not found. |
---|
49 | */ |
---|
50 | static int HasName(String, Argv) |
---|
51 | char *String; |
---|
52 | char **Argv; |
---|
53 | { |
---|
54 | register char **cpp; |
---|
55 | |
---|
56 | for (cpp = Argv; cpp && *cpp; ++cpp) |
---|
57 | if (EQ(String, *cpp)) |
---|
58 | return(1); |
---|
59 | |
---|
60 | return(0); |
---|
61 | } |
---|
62 | |
---|
63 | /* |
---|
64 | * Show System Configuration information utilizing the sysconf() |
---|
65 | * system call. |
---|
66 | */ |
---|
67 | extern void SysConfShow(MyInfo, Names) |
---|
68 | ClassInfo_t *MyInfo; |
---|
69 | char **Names; |
---|
70 | { |
---|
71 | #if defined(HAVE_SYSCONF) |
---|
72 | static char Buff[BUFSIZ]; |
---|
73 | static char *RptData[3]; |
---|
74 | int MaxDesc = 0; |
---|
75 | register int Len; |
---|
76 | long Value; |
---|
77 | char *ValuePtr; |
---|
78 | Define_t *SysConfDef; |
---|
79 | register Define_t *DefPtr; |
---|
80 | |
---|
81 | SysConfDef = DefGetList(DL_SYSCONF); |
---|
82 | if (!SysConfDef) |
---|
83 | return; |
---|
84 | |
---|
85 | for (DefPtr = SysConfDef; DefPtr; DefPtr = DefPtr->Next) { |
---|
86 | if (Names && !HasName(DefPtr->KeyStr, Names)) |
---|
87 | continue; |
---|
88 | |
---|
89 | /* |
---|
90 | * Call sysconf(). If it succeeds, then store the return value |
---|
91 | * in KeyNum. If it fails, set KeyNum to -1 and continue on. |
---|
92 | */ |
---|
93 | Value = sysconf(DefPtr->KeyNum); |
---|
94 | if (Value < 0) { |
---|
95 | SImsg(SIM_GERR, "sysconf(%s) failed: %s", DefPtr->KeyStr, SYSERR); |
---|
96 | DefPtr->KeyNum = -1; |
---|
97 | continue; |
---|
98 | } |
---|
99 | DefPtr->KeyNum = Value; |
---|
100 | |
---|
101 | Len = strlen(DefPtr->ValStr2); |
---|
102 | if (VL_ALL) |
---|
103 | Len += strlen(DefPtr->KeyStr) + 2; |
---|
104 | if (Len > MaxDesc) |
---|
105 | MaxDesc = Len; |
---|
106 | } |
---|
107 | |
---|
108 | ClassShowBanner(MyInfo); |
---|
109 | |
---|
110 | for (DefPtr = SysConfDef; DefPtr; DefPtr = DefPtr->Next) { |
---|
111 | if (Names && !HasName(DefPtr->KeyStr, Names)) |
---|
112 | continue; |
---|
113 | |
---|
114 | /* Skip entries that are not available */ |
---|
115 | if (DefPtr->KeyNum < 0) |
---|
116 | continue; |
---|
117 | Value = DefPtr->KeyNum; |
---|
118 | |
---|
119 | if (strlen(DefPtr->ValStr2) + strlen(DefPtr->KeyStr) + 7 >= |
---|
120 | sizeof(Buff)) |
---|
121 | continue; |
---|
122 | |
---|
123 | if (EQ(DefPtr->ValStr1, "bool")) { |
---|
124 | if (Value) |
---|
125 | ValuePtr = "TRUE"; |
---|
126 | else |
---|
127 | ValuePtr = "FALSE"; |
---|
128 | } else |
---|
129 | ValuePtr = itoa(Value); |
---|
130 | |
---|
131 | if (FormatType == FT_PRETTY) { |
---|
132 | ClassShowValue(DefPtr->ValStr2, DefPtr->KeyStr, ValuePtr, MaxDesc); |
---|
133 | } else if (FormatType == FT_REPORT) { |
---|
134 | RptData[0] = DefPtr->ValStr2; |
---|
135 | RptData[1] = ValuePtr; |
---|
136 | Report(CN_SYSCONF, NULL, DefPtr->KeyStr, RptData, 2); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | #endif /* HAVE_SYSCONF */ |
---|
141 | } |
---|