- Timestamp:
- Dec 25, 2008 8:21:22 PM (16 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/Makefile.am
r2101 r2141 139 139 -DCONFIG_WITH_FILE_SIZE \ 140 140 -DCONFIG_WITH_WHICH \ 141 -DCONFIG_WITH_PRINTF \ 141 142 -DCONFIG_WITH_EVALPLUS \ 142 143 -DCONFIG_WITH_MINIMAL_STATS \ -
trunk/src/kmk/Makefile.kmk
r2108 r2141 165 165 CONFIG_WITH_FILE_SIZE \ 166 166 CONFIG_WITH_WHICH \ 167 CONFIG_WITH_PRINTF \ 167 168 CONFIG_WITH_EVALPLUS \ 168 169 CONFIG_WITH_MINIMAL_STATS \ -
trunk/src/kmk/function.c
r2118 r2141 35 35 #ifdef KMK_HELPERS 36 36 # include "kbuild.h" 37 #endif 38 #ifdef CONFIG_WITH_PRINTF 39 # include "kmkbuiltin.h" 37 40 #endif 38 41 #ifdef CONFIG_WITH_XARGS /* bird */ … … 4545 4548 { STRING_SIZE_TUPLE("not"), 0, 1, 1, func_not}, 4546 4549 #endif 4550 #ifdef CONFIG_WITH_PRINTF 4551 { STRING_SIZE_TUPLE("printf"), 1, 0, 1, kmk_builtin_func_printf}, 4552 #endif 4547 4553 #ifdef CONFIG_WITH_LAZY_DEPS_VARS 4548 4554 { STRING_SIZE_TUPLE("deps"), 1, 2, 1, func_deps}, -
trunk/src/kmk/kmkbuiltin.h
r2127 r2141 54 54 extern int kmk_builtin_kDepIDB(int argc, char **argv, char **envp); 55 55 56 extern char *kmk_builtin_func_printf(char *o, char **argv, const char *funcname); 57 56 58 extern int kbuild_version(const char *); 57 59 -
trunk/src/kmk/kmkbuiltin/printf.c
r2132 r2141 46 46 #endif*/ /* not lint */ 47 47 48 #include "config.h" 48 #if !defined(kmk_builtin_printf) && !defined(BUILTIN) && !defined(SHELL) 49 # include "../make.h" 50 # include "../filedef.h" 51 # include "../variable.h" 52 #else 53 # include "config.h" 54 #endif 49 55 #include <sys/types.h> 50 56 … … 68 74 #endif 69 75 70 #include " kmkbuiltin.h"76 #include "../kmkbuiltin.h" 71 77 72 78 … … 82 88 static int rval; 83 89 static char **gargv; 90 #if !defined(kmk_builtin_printf) && !defined(BUILTIN) && !defined(SHELL) 91 static char *g_o = NULL; 92 #endif 84 93 static struct option long_options[] = 85 94 { … … 90 99 91 100 101 static int common_printf(int argc, char *argv[]); 92 102 static void conv_escape_str(char *, void (*)(int)); 93 103 static char *conv_escape(char *, char *); … … 105 115 static void b_count(int); 106 116 static void b_output(int); 117 static int wrap_putchar(int ch); 118 static int wrap_printf(const char *, ...); 107 119 108 120 #ifdef BUILTIN /* csh builtin */ … … 118 130 if (fieldwidth != -1) { \ 119 131 if (precision != -1) \ 120 (void) printf(f, fieldwidth, precision, func); \132 (void)wrap_printf(f, fieldwidth, precision, func); \ 121 133 else \ 122 (void) printf(f, fieldwidth, func); \134 (void)wrap_printf(f, fieldwidth, func); \ 123 135 } else if (precision != -1) \ 124 (void) printf(f, precision, func); \136 (void)wrap_printf(f, precision, func); \ 125 137 else \ 126 (void) printf(f, func); \138 (void)wrap_printf(f, func); \ 127 139 } 128 140 … … 141 153 int kmk_builtin_printf(int argc, char *argv[], char **envp) 142 154 { 143 char *fmt, *start; 144 int fieldwidth, precision; 145 char nextch; 146 char *format; 155 int rc; 147 156 int ch; 148 149 /* kmk: reinitialize globals */150 b_length = 0;151 b_fmt = NULL;152 rval = 0;153 gargv = NULL;154 157 155 158 /* kmk: reset getopt and set progname */ … … 182 185 return usage(stderr); 183 186 } 187 188 rc = common_printf(argc, argv); 189 return rc; 190 } 191 192 #ifndef kmk_builtin_printf 193 /* entry point used by function.c $(printf ..,..). */ 194 char *kmk_builtin_func_printf(char *o, char **argv, const char *funcname) 195 { 196 int rc; 197 int argc; 198 199 for (argc = 0; argv[argc] != NULL; argc++) 200 /* nothing */; 201 202 g_o = o; 203 rc = common_printf(argc, argv); 204 o = g_o; 205 g_o = NULL; 206 207 (void)funcname; 208 if (rc != 0) 209 fatal (NILF, _("$(%s): failure rc=%d\n"), rc); 210 return o; 211 } 212 #endif 213 214 static int common_printf(int argc, char *argv[]) 215 { 216 char *fmt, *start; 217 int fieldwidth, precision; 218 char nextch; 219 char *format; 220 int ch; 221 222 /* kmk: reinitialize globals */ 223 b_length = 0; 224 b_fmt = NULL; 225 rval = 0; 226 gargv = NULL; 184 227 185 228 format = *argv; … … 203 246 char c_ch; 204 247 fmt = conv_escape(fmt, &c_ch); 205 putchar(c_ch);248 wrap_putchar(c_ch); 206 249 continue; 207 250 } 208 251 if (ch != '%' || (*fmt == '%' && ++fmt)) { 209 (void) putchar(ch);252 (void)wrap_putchar(ch); 210 253 continue; 211 254 } … … 272 315 conv_escape_str(cp, b_output); 273 316 /* Add any trailing spaces */ 274 printf("%s", b_fmt);317 wrap_printf("%s", b_fmt); 275 318 break; 276 319 } … … 346 389 return; 347 390 case ' ': 348 putchar(' ');391 wrap_putchar(' '); 349 392 break; 350 393 default: 351 putchar(ch);394 wrap_putchar(ch); 352 395 return; 353 396 } 354 397 } 398 } 399 400 static int wrap_putchar(int ch) 401 { 402 #ifndef kmk_builtin_printf 403 if (g_o) { 404 char sz[2]; 405 sz[0] = ch; sz[1] = '\0'; 406 g_o = variable_buffer_output(g_o, sz, 1); 407 return ch; 408 } 409 #endif 410 return putchar(ch); 411 } 412 413 static int wrap_printf(const char * fmt, ...) 414 { 415 int rc; 416 va_list va; 417 418 #ifndef kmk_builtin_printf 419 if (g_o) { 420 char *str; 421 422 va_start(va, fmt); 423 rc = vasprintf(&str, fmt, va); 424 va_end(va); 425 if (rc >= 0) { 426 g_o = variable_buffer_output(g_o, str, rc); 427 free(str); 428 } 429 return rc; 430 } 431 #endif 432 433 va_start(va, fmt); 434 rc = vprintf(fmt, va); 435 va_end(va); 436 return rc; 355 437 } 356 438
Note:
See TracChangeset
for help on using the changeset viewer.