Changeset 720 for trunk/src


Ignore:
Timestamp:
Dec 15, 2006, 3:41:46 AM (19 years ago)
Author:
bird
Message:

stack functions and enabled the 'eq' and 'not' functions.

Location:
trunk/src/gmake
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/Makefile.kmk

    r613 r720  
    3838        CONFIG_WITH_VALUE_LENGTH \
    3939        CONFIG_WITH_COMPARE \
     40        CONFIG_WITH_STACK \
     41        EXPERIMENTAL \
    4042        \
    4143        BUILD_PLATFORM=\"$(BUILD_TARGET)\" \
     
    285287        HAVE_CONFIG_H \
    286288        NO_ARCHIVES \
    287         CONFIG_WITH_TOUPPER_TOLOWER
     289        CONFIG_WITH_TOUPPER_TOLOWER \
     290        EXPERIMENTAL
    288291       
    289292kmk_gmake_SOURCES = \
     
    400403                -e 's/foo/\!/'
    401404
     405
     406test_stack:
     407        $(MAKE) -f testcase-stack.kmk
  • trunk/src/gmake/function.c

    r567 r720  
    22662266}
    22672267#endif
     2268
     2269
     2270#ifdef CONFIG_WITH_STACK
     2271
     2272/* Push an item (string without spaces). */
     2273static char *
     2274func_stack_push (char *o, char **argv, const char *funcname)
     2275{
     2276    do_variable_definition(NILF, argv[0], argv[1], o_file, f_append, 0 /* !target_var */);
     2277    return o;
     2278}
     2279
     2280/* Pops an item off the stack / get the top stack element.
     2281   (This is what's tricky to do in pure GNU make syntax.) */
     2282static char *
     2283func_stack_pop_top (char *o, char **argv, const char *funcname)
     2284{
     2285    struct variable *stack_var;
     2286    const char *stack = argv[0];
     2287    const int return_item = argv[0][sizeof("stack-pop") - 1] == '\0';
     2288
     2289    stack_var = lookup_variable (stack, strlen (stack) );
     2290    if (stack_var)
     2291      {
     2292        unsigned int len;
     2293        char *iterator = stack_var->value;
     2294        char *lastitem = NULL;
     2295        char *cur;
     2296
     2297        while ((cur = find_next_token (&iterator, &len)))
     2298          lastitem = cur;
     2299
     2300        if (lastitem != NULL)
     2301          {
     2302            if (strcmp (funcname, "stack-popv") != 0)
     2303              o = variable_buffer_output (o, lastitem, len);
     2304            if (strcmp (funcname, "stack-top") != 0)
     2305              {
     2306                *lastitem = '\0';
     2307                while (lastitem > stack_var->value && isspace (lastitem[-1]))
     2308                  *--lastitem = '\0';
     2309#ifdef CONFIG_WITH_VALUE_LENGTH
     2310                stack_var->value_length = lastitem - stack_var->value;
     2311#endif
     2312              }
     2313          }
     2314      }
     2315    return o;
     2316}
     2317#endif /* CONFIG_WITH_STACK */
    22682318
    22692319/* Lookup table for builtin functions.
     
    23312381  { STRING_SIZE_TUPLE("comp-vars"),     3,  3,  1,  func_comp_vars},
    23322382#endif
     2383#ifdef CONFIG_WITH_STACK
     2384  { STRING_SIZE_TUPLE("stack-push"),    2,  2,  1,  func_stack_push},
     2385  { STRING_SIZE_TUPLE("stack-pop"),     1,  1,  1,  func_stack_pop_top},
     2386  { STRING_SIZE_TUPLE("stack-popv"),    1,  1,  1,  func_stack_pop_top},
     2387  { STRING_SIZE_TUPLE("stack-top"),     1,  1,  1,  func_stack_pop_top},
     2388#endif
    23332389#ifdef KMK_HELPERS
    23342390  { STRING_SIZE_TUPLE("kb-src-tool"),   1,  1,  0,  func_kbuild_source_tool},
Note: See TracChangeset for help on using the changeset viewer.