Changeset 1727 for trunk/src/kmk/function.c
- Timestamp:
- Sep 5, 2008, 3:45:52 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/function.c
r1716 r1727 2724 2724 if (e1 - s1 != e2 - s2) 2725 2725 return comp_vars_ne (o, s1, e1, s2, e2, argv[2], funcname); 2726 l_simple_compare:2727 2726 if (!memcmp (s1, s2, e1 - s1)) 2728 2727 return variable_buffer_output (o, "", 0); /* eq */ … … 3089 3088 return variable_buffer_output (o, "", 0); 3090 3089 } 3091 #endif 3090 #endif /* CONFIG_WITH_WHICH */ 3091 3092 #ifdef CONFIG_WITH_IF_CONDITIONALS 3093 3094 /* Evaluates the expression given in the argument using the 3095 same evaluator as for the new 'if' statements, except now 3096 we don't force the result into a boolean like for 'if' and 3097 '$(if-expr ,,)'. */ 3098 static char * 3099 func_expr (char *o, char **argv, const char *funcname UNUSED) 3100 { 3101 o = expr_eval_to_string (o, argv[0]); 3102 return o; 3103 } 3104 3105 /* Same as '$(if ,,)' except the first argument is evaluated 3106 using the same evaluator as for the new 'if' statements. */ 3107 static char * 3108 func_if_expr (char *o, char **argv, const char *funcname UNUSED) 3109 { 3110 int rc; 3111 char *to_expand; 3112 3113 /* Evaluate the condition in argv[0] and expand the 2nd or 3114 3rd argument according to the result. */ 3115 rc = expr_eval_if_conditionals (argv[0], NULL); 3116 to_expand = rc == 0 ? argv[1] : argv[2]; 3117 if (*to_expand) 3118 { 3119 char *expansion = expand_argument (to_expand, NULL); 3120 3121 o = variable_buffer_output (o, expansion, strlen (expansion)); 3122 3123 free (expansion); 3124 } 3125 3126 return o; 3127 } 3128 3129 #endif /* CONFIG_WITH_IF_CONDITIONALS */ 3092 3130 3093 3131 #ifdef CONFIG_WITH_STACK … … 3108 3146 struct variable *stack_var; 3109 3147 const char *stack = argv[0]; 3110 const int return_item = argv[0][sizeof("stack-pop") - 1] == '\0';3111 3148 3112 3149 stack_var = lookup_variable (stack, strlen (stack) ); … … 3959 3996 { STRING_SIZE_TUPLE("which"), 0, 0, 1, func_which}, 3960 3997 #endif 3998 #ifdef CONFIG_WITH_IF_CONDITIONALS 3999 { STRING_SIZE_TUPLE("expr"), 1, 1, 0, func_expr}, 4000 { STRING_SIZE_TUPLE("if-expr"), 2, 3, 0, func_if_expr}, 4001 #endif 3961 4002 #ifdef CONFIG_WITH_STACK 3962 4003 { STRING_SIZE_TUPLE("stack-push"), 2, 2, 1, func_stack_push},
Note:
See TracChangeset
for help on using the changeset viewer.