source: trunk/third/sysinfo/class.c @ 12269

Revision 12269, 3.9 KB checked in by ghudson, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12268, which included commits to RCS files with non-trunk default branches.
Line 
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
10static char *RCSid = "$Revision: 1.1.1.3 $";
11#endif
12
13/*
14 * Class Info
15 */
16#include "defs.h"
17
18/*
19 * Class information
20 */
21ClassInfo_t ClassInfo[] = {
22    { CN_GENERAL,       GeneralShow,    GeneralList,
23      "General Information", "G E N E R A L   I N F O R M A T I O N" },
24    { CN_KERNEL,        KernelShow,     KernelList,
25      "Kernel Information", "K E R N E L   I N F O R M A T I O N" },
26    { CN_SYSCONF,       SysConfShow,    SysConfList,
27      "SysConf Information", "S Y S C O N F   I N F O R M A T I O N" },
28    { CN_DEVICE,        DeviceShow,     DeviceList,
29      "Device Information", "D E V I C E   I N F O R M A T I O N" },
30    { 0 },
31};
32
33/*
34 * List class names.
35 */
36extern void ClassList()
37{
38    register ClassInfo_t       *ClassPtr;
39
40    SImsg(SIM_INFO,
41"The following values may be specified with the `-class' option:\n");
42    SImsg(SIM_INFO, "%-20s %s\n", "VALUE", "DESCRIPTION");
43
44    for (ClassPtr = &ClassInfo[0]; ClassPtr->Name; ++ClassPtr)
45        SImsg(SIM_INFO, "%-20s %s\n", ClassPtr->Name, ClassPtr->Label);
46}
47
48/*
49 * Lookup a class named Name.
50 */
51static ClassInfo_t *ClassGetName(Name)
52    char                       *Name;
53{
54    register ClassInfo_t       *ClassPtr;
55
56    for (ClassPtr = &ClassInfo[0]; ClassPtr->Name; ++ClassPtr)
57        if (EQ(Name, ClassPtr->Name))
58            return(ClassPtr);
59
60    return((ClassInfo_t *) NULL);
61}
62
63/*
64 * Set class information
65 */
66extern void ClassSetInfo(Names)
67    char                       *Names;
68{
69    register ClassInfo_t       *ClassPtr;
70    register char              *cp;
71    char                       *String;
72
73    if (Names) {
74        /*
75         * Enable a specific list of classes.
76         * The Names variable is a `,' seperated list
77         * of class names.
78         */
79        String = Names;         /* XXX Names param is altered */
80        for (cp = strtok(Names, ","); cp; cp = strtok((char *)NULL, ",")) {
81            ClassPtr = ClassGetName(cp);
82            if (!ClassPtr) {
83                SImsg(SIM_GERR, "The class name `%s' is invalid.", cp);
84                ClassList();
85                exit(1);
86            }
87            ClassPtr->Enabled = TRUE;
88        }
89    } else
90        /*
91         * No specific class names were specified so enabled all of them.
92         */
93        for (ClassPtr = ClassInfo; ClassPtr->Name; ++ClassPtr)
94            ClassPtr->Enabled = TRUE;
95}
96
97/*
98 * Show a class Banner
99 */
100extern void ClassShowBanner(MyClass)
101    ClassInfo_t                *MyClass;
102{
103    if ((!VL_TERSE && !VL_BRIEF) && FormatType == FT_PRETTY)
104        SImsg(SIM_INFO, "\n\n\t%s\n\n", MyClass->Banner);
105}
106
107/*
108 * Show a Class Value
109 */
110extern void ClassShowValue(Lbl, Key, Value, MaxLen)
111    char                       *Lbl;
112    char                       *Key;
113    char                       *Value;
114    int                         MaxLen;
115{
116    char                        Buff[256];
117    int                         Len;
118
119    if (!Value || !*Value)
120        return;
121
122    if (VL_TERSE) {
123        SImsg(SIM_INFO, "%s", Value);
124    } else if (VL_BRIEF) {
125        SImsg(SIM_INFO, "%s is %s", Key, Value);
126    } else {
127        if (Lbl) {
128            (void) strcpy(Buff, Lbl);
129            if (VL_ALL) {
130                Len = strlen(Lbl);
131                (void) snprintf(Buff + Len, sizeof(Buff)-Len, " (%s)", Key);
132            }
133        } else
134            (void) strcpy(Buff, Key);
135        (void) strcat(Buff, " is ");
136        SImsg(SIM_INFO, "%-*s %s", MaxLen + 5, Buff, Value);
137    }
138
139    if (Value[strlen(Value) - 1] != '\n')
140        SImsg(SIM_INFO, "\n");
141}
142
143/*
144 * Call each enabled show function
145 */
146extern int ClassCall(NameStr)
147    char                       *NameStr;
148{
149    ClassInfo_t                *ClassPtr;
150    char                      **Argv;
151    int                         Argc;
152
153    Argc = StrToArgv(NameStr, ",", &Argv, NULL, 0);
154
155    for (ClassPtr = &ClassInfo[0]; ClassPtr->Name; ++ClassPtr)
156        if (ClassPtr->Enabled && ClassPtr->Show)
157            (*ClassPtr->Show)(ClassPtr,(Argc > 0) ? Argv : (char **) NULL);
158
159    return(0);
160}
161
162/*
163 * Call each Class List function
164 */
165extern void ClassCallList()
166{
167    register ClassInfo_t       *ClassPtr;
168
169    for (ClassPtr = &ClassInfo[0]; ClassPtr->Name; ++ClassPtr)
170        if (ClassPtr->List)
171            (*ClassPtr->List)();
172}
Note: See TracBrowser for help on using the repository browser.