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

Revision 12269, 3.7 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 * Definetion functions
15 */
16#include "defs.h"
17
18/*
19 * Master list of definetions
20 */
21DefineList_t                   *Definetions = NULL;
22
23/*
24 * Valid list of definetions
25 * XXX  It would be nice if only those names that are valid for
26 *      the OS we're run on are defined.
27 */
28static char *ValidDefineList[] = {
29    DL_SYSMODEL, DL_KARCH, DL_CPU, DL_OBP, DL_VPD,
30    DL_NETTYPE, DL_CATEGORY, DL_PART, DL_TAPEINFO,
31    DL_KERNEL, DL_SYSCONF, DL_SCSI_DTYPE, DL_CDSPEED,
32    NULL
33};
34
35/*
36 * Make sure Name is valid.
37 */
38int DefValid(Name)
39    char                       *Name;
40{
41    register char             **cpp;
42    int                         Valid = FALSE;
43
44    for (cpp = ValidDefineList; !Valid && cpp && *cpp; ++cpp)
45        if (EQ(Name, *cpp))
46            Valid = TRUE;
47
48    return(Valid);
49}
50
51/*
52 * Add a definetion to the master list.
53 */
54extern void DefAdd(Define, ListName)
55    Define_t                   *Define;
56    char                       *ListName;
57{
58    register DefineList_t      *ListPtr;
59    register DefineList_t      *NewList = NULL;
60    register Define_t          *DefPtr;
61
62    /*
63     * Find the requested list
64     */
65    for (ListPtr = Definetions; ListPtr; ListPtr = ListPtr->Next)
66        if (EQ(ListPtr->Name, ListName))
67            break;
68
69    /*
70     * Create a new list entry if the list doesn't exist already.
71     */
72    if (!ListPtr) {
73        ListPtr = NewList = (DefineList_t *) xcalloc(1, sizeof(DefineList_t));
74        NewList->Name = strdup(ListName);
75    }
76
77    /*
78     * Add NewList to Definetions
79     */
80    if (!Definetions)
81        Definetions = NewList;
82    else if (NewList) {
83        for (ListPtr = Definetions; ListPtr && ListPtr->Next;
84             ListPtr = ListPtr->Next);
85        ListPtr->Next = NewList;
86        ListPtr = NewList;
87    }
88
89    /*
90     * Add Define to the requested list
91     */
92    if (!ListPtr->Defines)
93        ListPtr->Defines = Define;
94    else {
95        for (DefPtr = ListPtr->Defines; DefPtr && DefPtr->Next;
96             DefPtr = DefPtr->Next);
97        DefPtr->Next = Define;
98    }
99}
100
101/*
102 * Get the Define list for ListName.
103 */
104extern Define_t *DefGetList(ListName)
105    char                       *ListName;
106{
107    register DefineList_t      *Ptr;
108
109    for (Ptr = Definetions; Ptr; Ptr = Ptr->Next)
110        if (EQ(Ptr->Name, ListName))
111            return(Ptr->Defines);
112
113    return((Define_t *) NULL);
114}
115
116/*
117 * Find definetion with key KeyStr and/or KeyNum in list ListName.
118 */
119extern Define_t *DefGet(ListName, KeyStr, KeyNum, Opts)
120    char                       *ListName;
121    char                       *KeyStr;
122    long                        KeyNum;
123    int                         Opts;
124{
125    Define_t                   *List;
126    register Define_t          *Ptr;
127    int                         StrMatch = FALSE;
128    int                         NumMatch = FALSE;
129
130    List = DefGetList(ListName);
131    if (!List) {
132        SImsg(SIM_DBG, "Invalid list name `%s'.", ListName);
133        return((Define_t *) NULL);
134    }
135
136    for (Ptr = List; Ptr; Ptr = Ptr->Next) {
137        if (KeyStr && Ptr->KeyStr)
138            if (FLAGS_ON(Opts, DO_REGEX)) {
139                strtolower(KeyStr);
140                strtolower(Ptr->KeyStr);
141                if (REmatch(KeyStr, Ptr->KeyStr, NULL) > 0)
142                    StrMatch = TRUE;
143            } else {
144                if (EQ(KeyStr, Ptr->KeyStr))
145                    StrMatch = TRUE;
146            }
147        /*
148         * If KeyStr is NULL and the entry key is "-" this implies
149         * that we want to match againt none (NULL).
150         */
151        if (!StrMatch)
152            if (!KeyStr && Ptr->KeyStr && EQ(Ptr->KeyStr, "-"))
153                StrMatch = TRUE;
154        if ((KeyNum >= 0) && (Ptr->KeyNum >= 0) && KeyNum == Ptr->KeyNum)
155            NumMatch = TRUE;
156        if (KeyStr && (KeyNum >= 0) && StrMatch && NumMatch)
157            return(Ptr);
158        if (KeyStr && StrMatch)
159            return(Ptr);
160        if ((KeyNum >= 0) && NumMatch)
161            return(Ptr);
162    }
163
164    return((Define_t *) NULL);
165}
Note: See TracBrowser for help on using the repository browser.