~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/cull/cull_parse.c

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
Import upstream version 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*___INFO__MARK_BEGIN__*/
 
2
/*************************************************************************
 
3
 * 
 
4
 *  The Contents of this file are made available subject to the terms of
 
5
 *  the Sun Industry Standards Source License Version 1.2
 
6
 * 
 
7
 *  Sun Microsystems Inc., March, 2001
 
8
 * 
 
9
 * 
 
10
 *  Sun Industry Standards Source License Version 1.2
 
11
 *  =================================================
 
12
 *  The contents of this file are subject to the Sun Industry Standards
 
13
 *  Source License Version 1.2 (the "License"); You may not use this file
 
14
 *  except in compliance with the License. You may obtain a copy of the
 
15
 *  License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
 
16
 * 
 
17
 *  Software provided under this License is provided on an "AS IS" basis,
 
18
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 
19
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 
20
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 
21
 *  See the License for the specific provisions governing your rights and
 
22
 *  obligations concerning the Software.
 
23
 * 
 
24
 *   The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 
25
 * 
 
26
 *   Copyright: 2001 by Sun Microsystems, Inc.
 
27
 * 
 
28
 *   All Rights Reserved.
 
29
 * 
 
30
 ************************************************************************/
 
31
/*___INFO__MARK_END__*/
 
32
#include <stdio.h>
 
33
#include <string.h>
 
34
#include <ctype.h>
 
35
 
 
36
/* do not compile in monitoring code */
 
37
#ifndef NO_SGE_COMPILE_DEBUG
 
38
#define NO_SGE_COMPILE_DEBUG
 
39
#endif
 
40
 
 
41
#include "sgermon.h"
 
42
#include "cull_listP.h"
 
43
#include "cull_parse.h"
 
44
#include "cull_lerrnoP.h"
 
45
 
 
46
/* ---------- static funcs --------------------------------- */
 
47
static const char *eatws(const char *s);
 
48
/* ---------- global variable --------------------------------- */
 
49
 
 
50
/* =========== implementation ================================= */
 
51
 
 
52
/* ------------------------------------------------------------ 
 
53
 
 
54
   sets pointer s to next character after
 
55
   white space character 
 
56
 
 
57
   returns NULL if there is '\0'
 
58
 
 
59
 */
 
60
static const char *eatws(
 
61
const char *s 
 
62
) {
 
63
   while (*s && isspace((int) *s))
 
64
      s++;
 
65
   return *s ? s : NULL;
 
66
}
 
67
 
 
68
/* ------------------------------------------------------------ 
 
69
 
 
70
   eat_token() informs parsing system that the current token 
 
71
   is proceed
 
72
 
 
73
 */
 
74
void eat_token(cull_parse_state *state) {
 
75
   state->token_is_valid = 0;
 
76
}
 
77
 
 
78
/* ------------------------------------------------------------ 
 
79
 
 
80
   scan() scans a string s for valid tokens 
 
81
 
 
82
   for getting the first token call scan with s = &string
 
83
   s != �NULL initializes scan()
 
84
   s == NULL uses the previous string for scanning
 
85
   if scan is called once again it gets the same token as before if there
 
86
   was no call to eat_token() otherwise a new token is delivered
 
87
 
 
88
 */
 
89
int scan(
 
90
const char *s,
 
91
cull_parse_state *state
 
92
) {
 
93
   static char *opv[] =
 
94
   {
 
95
      "%T",                     /* DESCRIPTOR TYPE OF LIST */
 
96
      "%I",                     /* FIELD                   */
 
97
 
 
98
      "->",                     /* SUBSCOPE                */
 
99
      "+",                      /* PLUS                    */
 
100
      "-",                      /* MINUS                   */
 
101
      "%d",                     /* INT                     */
 
102
      "%s",                     /* STRING                  */
 
103
      "%u",                     /* ULONG                   */
 
104
      "%l",                     /* SUBLIST                 */
 
105
      "%f",                     /* FLOAT                   */
 
106
      "%g",                     /* DOUBLE                  */
 
107
      "%o",                     /* LONG                    */
 
108
      "%c",                     /* CHAR                    */
 
109
      "%b",                     /* BOOL                    */
 
110
      "%p",                     /* REF                     */
 
111
 
 
112
      "ALL",                    /* CULL_ALL                */
 
113
      "NONE",                   /* CULL_NONE               */
 
114
      "==",                     /* EQUAL                   */
 
115
      "!=",                     /* NOT_EQUAL               */
 
116
      "<=",                     /* LOWER_EQUAL             */
 
117
      "<",                      /* LOWER                   */
 
118
      ">=",                     /* GREATER_EQUAL           */
 
119
      ">",                      /* GREATER                 */
 
120
      "m=",                     /* BITMASK                 */
 
121
      "c=",                     /* STRCASECMP              */
 
122
      "p=",                     /* PATTERNCMP              */
 
123
      "h=",                     /* HOSTNAMECMP             */
 
124
 
 
125
      "&&",                     /* AND */
 
126
      "||",                     /* OR  */
 
127
      "!",                      /* NEG */
 
128
      "(",                      /* BRA */
 
129
      ")"                       /* KET */
 
130
   };
 
131
 
 
132
   int i, j, len;
 
133
   int n = sizeof(opv) / sizeof(char *);
 
134
   int found;
 
135
 
 
136
   DENTER(CULL_LAYER, "scan");
 
137
 
 
138
   if (s) {                     /* initialize scan() with a new string to parse */
 
139
      state->t = s;
 
140
      state->token_is_valid = 0;
 
141
   }
 
142
 
 
143
   if (state->token_is_valid) {        /* no need for a new token to parse */
 
144
      DEXIT;
 
145
      return state->token;
 
146
   }
 
147
 
 
148
   state->t = eatws(state->t);
 
149
   if (state->t == NULL) {       /* end of the string to parse */
 
150
      state->token_is_valid = 1;
 
151
      state->token = NO_TOKEN;
 
152
      DEXIT;
 
153
      return state->token;
 
154
   }
 
155
 
 
156
   /* try every possible token */
 
157
   for (i = 0; i < n; i++) {
 
158
      found = 1;
 
159
      len = strlen(opv[i]);
 
160
      for (j = 0; j < len; j++)
 
161
         if (state->t[j] == '\0' || state->t[j] != opv[i][j]) {
 
162
            found = 0;
 
163
            break;
 
164
         }
 
165
      if (found) {
 
166
         state->t += len;
 
167
         state->token_is_valid = 1;
 
168
         state->token = i + 1;
 
169
 
 
170
         DEXIT;
 
171
         return (state->token);
 
172
      }
 
173
   }
 
174
 
 
175
   state->token_is_valid = 1;
 
176
   state->token = NO_TOKEN;
 
177
 
 
178
   DEXIT;
 
179
   return state->token;
 
180
}