- Timestamp:
- Dec 29, 2008, 11:20:11 PM (17 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/Makefile.am
r2151 r2161 144 144 -DCONFIG_WITH_COMMANDS_FUNC \ 145 145 -DCONFIG_WITH_STRING_FUNCTIONS \ 146 -DCONFIG_WITH_LOOP_FUNCTIONS \ 146 147 -DCONFIG_PRETTY_COMMAND_PRINTING \ 147 148 -DCONFIG_WITH_PRINT_STATS_SWITCH \ -
trunk/src/kmk/Makefile.kmk
r2151 r2161 170 170 CONFIG_WITH_PRINTF \ 171 171 CONFIG_WITH_STRING_FUNCTIONS \ 172 CONFIG_WITH_LOOP_FUNCTIONS \ 172 173 CONFIG_PRETTY_COMMAND_PRINTING \ 173 174 CONFIG_WITH_PRINT_STATS_SWITCH \ -
trunk/src/kmk/expreval.c
r2117 r2161 2073 2073 * Evaluates the given if expression. 2074 2074 * 2075 * @returns -1, 0 or 1. 2075 * @returns -1, 0 or 1. (GNU make conditional check convention, see read.c.) 2076 2076 * @retval -1 if the expression is invalid. 2077 2077 * @retval 0 if the expression is true 2078 2078 * @retval 1 if the expression is false. 2079 2079 * 2080 * @param line The expression. Can modify this as we like.2080 * @param line The expression. 2081 2081 * @param flocp The file location, used for errors. 2082 2082 */ 2083 int expr_eval_if_conditionals(c har *line, const struct floc *flocp)2083 int expr_eval_if_conditionals(const char *line, const struct floc *flocp) 2084 2084 { 2085 2085 /* … … 2115 2115 * @param expr The expression. 2116 2116 */ 2117 char *expr_eval_to_string(char *o, c har *expr)2117 char *expr_eval_to_string(char *o, const char *expr) 2118 2118 { 2119 2119 /* -
trunk/src/kmk/function.c
r2160 r2161 1071 1071 } 1072 1072 1073 #ifdef CONFIG_WITH_LOOP_FUNCTIONS 1074 1075 1076 /* Helper for func_for that evaluates the INIT and NEXT parts. */ 1077 static void 1078 helper_eval (char *text, size_t text_len) 1079 { 1080 unsigned int buf_len; 1081 char *buf; 1082 1083 install_variable_buffer (&buf, &buf_len); 1084 eval_buffer (text, text + text_len); 1085 restore_variable_buffer (buf, buf_len); 1086 } 1087 1088 /* 1089 $(for init,condition,next,body) 1090 */ 1091 static char * 1092 func_for (char *o, char **argv, const char *funcname UNUSED) 1093 { 1094 char *init = argv[0]; 1095 const char *cond = argv[1]; 1096 const char *next = argv[2]; 1097 size_t next_len = strlen (next); 1098 char *next_buf = xmalloc (next_len + 1); 1099 const char *body = argv[3]; 1100 size_t body_len = strlen (body); 1101 unsigned int doneany = 0; 1102 1103 push_new_variable_scope (); 1104 1105 /* Evaluate INIT. */ 1106 1107 helper_eval (init, strlen (init)); 1108 1109 /* Loop till COND is false. */ 1110 1111 while (expr_eval_if_conditionals (cond, NULL) == 0 /* true */) 1112 { 1113 /* Expand BODY. */ 1114 1115 if (!doneany) 1116 doneany = 1; 1117 else 1118 o = variable_buffer_output (o, " ", 1); 1119 variable_expand_string_2 (o, body, body_len, &o); 1120 1121 /* Evaluate NEXT. */ 1122 1123 memcpy (next_buf, next, next_len + 1); 1124 helper_eval (next_buf, next_len); 1125 } 1126 1127 pop_variable_scope (); 1128 free (next_buf); 1129 1130 return o; 1131 } 1132 1133 /* 1134 $(while condition,body) 1135 */ 1136 static char * 1137 func_while (char *o, char **argv, const char *funcname UNUSED) 1138 { 1139 const char *cond = argv[0]; 1140 const char *body = argv[1]; 1141 size_t body_len = strlen (body); 1142 unsigned int doneany = 0; 1143 1144 push_new_variable_scope (); 1145 1146 while (expr_eval_if_conditionals (cond, NULL) == 0 /* true */) 1147 { 1148 if (!doneany) 1149 doneany = 1; 1150 else 1151 o = variable_buffer_output (o, " ", 1); 1152 variable_expand_string_2 (o, body, body_len, &o); 1153 } 1154 1155 pop_variable_scope (); 1156 1157 return o; 1158 } 1159 1160 1161 #endif /* CONFIG_WITH_LOOP_FUNCTIONS */ 1162 1073 1163 struct a_word 1074 1164 { … … 4866 4956 { STRING_SIZE_TUPLE("origin"), 0, 1, 1, func_origin}, 4867 4957 { STRING_SIZE_TUPLE("foreach"), 3, 3, 0, func_foreach}, 4958 #ifdef CONFIG_WITH_LOOP_FUNCTIONS 4959 { STRING_SIZE_TUPLE("for"), 4, 4, 0, func_for}, 4960 { STRING_SIZE_TUPLE("while"), 2, 2, 0, func_while}, 4961 #endif 4868 4962 { STRING_SIZE_TUPLE("call"), 1, 0, 1, func_call}, 4869 4963 { STRING_SIZE_TUPLE("info"), 0, 1, 1, func_error}, -
trunk/src/kmk/make.h
r2121 r2161 911 911 912 912 #ifdef CONFIG_WITH_IF_CONDITIONALS 913 extern int expr_eval_if_conditionals(c har *line, const struct floc *flocp);914 extern char *expr_eval_to_string(char *o, c har *expr);913 extern int expr_eval_if_conditionals(const char *line, const struct floc *flocp); 914 extern char *expr_eval_to_string(char *o, const char *expr); 915 915 #endif 916 916
Note:
See TracChangeset
for help on using the changeset viewer.