Updated PCI IDs to latest snapshot.
[tangerine.git] / rom / dos / findvar.c
blob0b6b9e99367738ff6bef6f8b3bf6b70d2e4433fd
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Find a local variable.
6 Lang: English
7 */
8 #include "dos_intern.h"
9 #include <proto/exec.h>
10 #include <proto/utility.h>
11 #include <string.h>
13 /*****************************************************************************
15 NAME */
17 #include <proto/dos.h>
18 #include <dos/var.h>
20 AROS_LH2(struct LocalVar *, FindVar,
22 /* SYNOPSIS */
23 AROS_LHA(CONST_STRPTR, name, D1),
24 AROS_LHA(ULONG , type, D2),
26 /* LOCATION */
27 struct DosLibrary *, DOSBase, 153, Dos)
29 /* FUNCTION
30 Finds a local variable structure.
32 INPUTS
33 name -- the name of the variable you wish to find. Note that
34 variable names follow the same syntax and semantics
35 as filesystem names.
36 type -- The type of variable to be found (see <dos/var.h>).
37 Actually, only the lower 8 bits of "type" are used
38 by FindVar().
40 RESULT
41 A pointer to the LocalVar structure for that variable if it was
42 found. If the variable wasn't found, or was of the wrong type,
43 NULL will be returned.
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 DeleteVar(), GetVar(), SetVar()
54 INTERNALS
55 For every local variable, a structure of type LocalVar exists:
56 struct LocalVar {
57 struct Node lv_Node;
58 UWORD lv_Flags;
59 UBYTE *lv_Value;
60 ULONG lv_Len;
63 lv_Node.ln_Type
64 holds the variable type, either LV_VAR for regular local environment
65 variables or LV_ALIAS for shell aliases. dos/var.h also defines
66 LVF_IGNORE (for private usage by the shell)
68 lv_Node.ln_Name
69 holds the variable name (NUL terminated string)
71 lv_Flags
72 stores GVF_BINARY_VAR and GVF_DONT_NULL_TERM if given as flags to
73 SetVar(). It is only used by GetVar().
75 lv_Value
76 holds the variable's value
78 lv_Len
79 is the length of lv_Value
81 *****************************************************************************/
83 AROS_LIBFUNC_INIT
85 /* Only the lowest 8 bits are valid here */
86 type &= 0xFF;
88 if (name != NULL)
90 /* We scan through the process->pr_LocalVars list */
91 struct Process *pr;
92 struct LocalVar *var;
94 pr = (struct Process *)FindTask(NULL);
95 var = (struct LocalVar *)pr->pr_LocalVars.mlh_Head;
97 ForeachNode(&pr->pr_LocalVars, var)
99 LONG res;
101 if (var->lv_Node.ln_Type == type)
103 /* The list is alphabetically sorted. */
104 res = Stricmp(name, var->lv_Node.ln_Name);
106 /* Found it */
107 if (res == 0)
109 return var;
112 /* We have gone too far through the sorted list. */
113 else if (res < 0)
115 break;
121 return NULL;
123 AROS_LIBFUNC_EXIT
124 } /* FindVar */