Changeset 730 in kBuild for trunk/src/gmake/function.c
- Timestamp:
- Dec 17, 2006 3:59:33 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/function.c
r729 r730 1905 1905 */ 1906 1906 static char * 1907 func_eq (char *o, char **argv, c har *funcname)1907 func_eq (char *o, char **argv, const char *funcname) 1908 1908 { 1909 1909 int result = ! strcmp (argv[0], argv[1]); … … 1917 1917 */ 1918 1918 static char * 1919 func_not (char *o, char **argv, c har *funcname)1919 func_not (char *o, char **argv, const char *funcname) 1920 1920 { 1921 1921 char *s = argv[0]; … … 2208 2208 2209 2209 #if defined(CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE) 2210 /* Returns empty string if equal, returns the third arg if not equal. */ 2210 2211 /* Strip leading spaces and other things off a command. */ 2212 static const char * 2213 comp_cmds_strip_leading (const char *s, const char *e) 2214 { 2215 while (s < e) 2216 { 2217 const char ch = *s; 2218 if (!isblank (ch) 2219 && ch != '@' 2220 && ch != '+' 2221 && ch != '-') 2222 break; 2223 s++; 2224 } 2225 return s; 2226 } 2227 2228 /* Worker for func_comp_vars() which is called if the comparision failed. 2229 It will do the slow command by command comparision of the commands 2230 when there invoked as comp-cmds. */ 2231 static char * 2232 comp_vars_ne (char *o, const char *s1, const char *e1, const char *s2, const char *e2, 2233 char *ne_retval, const char *funcname) 2234 { 2235 /* give up at once if not comp-cmds. */ 2236 if (strcmp (funcname, "comp-cmds") != 0) 2237 o = variable_buffer_output (o, ne_retval, strlen (ne_retval)); 2238 else 2239 { 2240 const char * const s1_start = s1; 2241 int new_cmd = 1; 2242 int diff; 2243 for (;;) 2244 { 2245 /* if it's a new command, strip leading stuff. */ 2246 if (new_cmd) 2247 { 2248 s1 = comp_cmds_strip_leading (s1, e1); 2249 s2 = comp_cmds_strip_leading (s2, e2); 2250 new_cmd = 0; 2251 } 2252 if (s1 >= e1 || s2 >= e2) 2253 break; 2254 2255 /* 2256 * Inner compare loop which compares one line. 2257 * FIXME: parse quoting! 2258 */ 2259 for (;;) 2260 { 2261 const char ch1 = *s1; 2262 const char ch2 = *s2; 2263 diff = ch1 - ch2; 2264 if (diff) 2265 break; 2266 if (ch1 == '\n') 2267 break; 2268 assert (ch1 != '\r'); 2269 2270 /* next */ 2271 s1++; 2272 s2++; 2273 if (s1 >= e1 || s2 >= e2) 2274 break; 2275 } 2276 2277 /* 2278 * If we exited because of a difference try to end-of-command 2279 * comparision, e.g. ignore trailing spaces. 2280 */ 2281 if (diff) 2282 { 2283 /* strip */ 2284 while (s1 < e1 && isblank (*s1)) 2285 s1++; 2286 while (s2 < e2 && isblank (*s2)) 2287 s2++; 2288 if (s1 >= e1 || s2 >= e2) 2289 break; 2290 2291 /* compare again and check that it's a newline. */ 2292 if (*s2 != '\n' || *s1 != '\n') 2293 break; 2294 } 2295 /* Break out if we exited because of EOS. */ 2296 else if (s1 >= e1 || s2 >= e2) 2297 break; 2298 2299 /* 2300 * Detect the end of command lines. 2301 */ 2302 if (*s1 == '\n') 2303 new_cmd = s1 == s1_start || s1[-1] != '\\'; 2304 s1++; 2305 s2++; 2306 } 2307 2308 /* 2309 * Ignore trailing empty lines. 2310 */ 2311 if (s1 < e1 || s2 < e2) 2312 { 2313 while (s1 < e1 && (isblank (*s1) || *s1 == '\n')) 2314 if (*s1++ == '\n') 2315 s1 = comp_cmds_strip_leading (s1, e1); 2316 while (s2 < e2 && (isblank (*s2) || *s2 == '\n')) 2317 if (*s2++ == '\n') 2318 s2 = comp_cmds_strip_leading (s2, e2); 2319 } 2320 2321 /* emit the result. */ 2322 if (s1 == e1 && s2 == e2) 2323 o = variable_buffer_output (o, "", 1); 2324 else 2325 o = variable_buffer_output (o, ne_retval, strlen (ne_retval)); 2326 } 2327 return o; 2328 } 2329 2330 /* 2331 $(comp-vars var1,var2,not-equal-return) 2332 or 2333 $(comp-cmds cmd-var1,cmd-var2,not-equal-return) 2334 2335 Compares the two variables (that's given by name to avoid unnecessary 2336 expanding) and return the string in the third argument if not equal. 2337 If equal, nothing is returned. 2338 2339 comp-vars will to an exact comparision only stripping leading and 2340 trailing spaces. 2341 2342 comp-cmds will compare command by command, ignoring not only leading 2343 and trailing spaces on each line but also leading one leading '@' and '-'. 2344 */ 2211 2345 static char * 2212 2346 func_comp_vars (char *o, char **argv, const char *funcname) … … 2247 2381 2248 2382 if (e1 - s1 != e2 - s2) 2249 return variable_buffer_output (o, argv[2], strlen(argv[2]));2383 return comp_vars_ne (o, s1, e1, s2, e2, argv[2], funcname); 2250 2384 l_simple_compare: 2251 2385 if (!memcmp (s1, s2, e1 - s1)) 2252 2386 return variable_buffer_output (o, "", 1); /* eq */ 2253 return variable_buffer_output (o, argv[2], strlen(argv[2]));2387 return comp_vars_ne (o, s1, e1, s2, e2, argv[2], funcname); 2254 2388 } 2255 2389 … … 2282 2416 x2 = var2->recursive ? memchr (s2, '$', e2 - s2) : NULL; 2283 2417 if (!x1 && !x2) 2284 return variable_buffer_output (o, argv[2], strlen (argv[2]));2418 return comp_vars_ne (o, s1, e1, s2, e2, argv[2], funcname); 2285 2419 2286 2420 l1 = x1 ? x1 - s1 : e1 - s1; … … 2288 2422 l = l1 <= l2 ? l1 : l2; 2289 2423 if (l && memcmp (s1, s2, l)) 2290 return variable_buffer_output (o, argv[2], strlen (argv[2]));2424 return comp_vars_ne (o, s1, e1, s2, e2, argv[2], funcname); 2291 2425 2292 2426 /* one or both buffers now require expanding. */ … … 2299 2433 while (isblank ((unsigned char) *s1)) 2300 2434 s1++; 2301 e1 = strchr (s1, '\0'); /*hmm*/2435 e1 = strchr (s1, '\0'); 2302 2436 while (e1 > s1 && isblank ((unsigned char) e1[-1])) 2303 2437 e1--; … … 2312 2446 while (isblank ((unsigned char) *s2)) 2313 2447 s2++; 2314 e2 = strchr (s2, '\0'); /*hmm*/2448 e2 = strchr (s2, '\0'); 2315 2449 while (e2 > s2 && isblank ((unsigned char) e2[-1])) 2316 2450 e2--; … … 2318 2452 2319 2453 /* the final compare */ 2320 l = ( e1 - s1 != e2 - s2 2321 || memcmp (s1, s2, e1 - s1)); 2454 if ( e1 - s1 != e2 - s2 2455 || memcmp (s1, s2, e1 - s1)) 2456 o = comp_vars_ne (o, s1, e1, s2, e2, argv[2], funcname); 2457 else 2458 o = variable_buffer_output (o, "", 1); /* eq */ 2322 2459 if (a1) 2323 2460 free (a1); 2324 2461 if (a2) 2325 2462 free (a2); 2326 if (l) 2327 return variable_buffer_output (o, argv[2], strlen (argv[2])); 2328 return variable_buffer_output (o, "", 1); /* eq */ 2463 return o; 2329 2464 } 2330 2465 #endif … … 2446 2581 #if defined(CONFIG_WITH_VALUE_LENGTH) && defined(CONFIG_WITH_COMPARE) 2447 2582 { STRING_SIZE_TUPLE("comp-vars"), 3, 3, 1, func_comp_vars}, 2583 { STRING_SIZE_TUPLE("comp-cmds"), 3, 3, 1, func_comp_vars}, 2448 2584 #endif 2449 2585 #ifdef CONFIG_WITH_STACK
Note:
See TracChangeset
for help on using the changeset viewer.