Changeset 775 for trunk/src/gmake/kmkbuiltin/printf.c
- Timestamp:
- Jan 19, 2007, 6:57:42 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gmake/kmkbuiltin/printf.c
r774 r775 30 30 */ 31 31 32 #include <sys/cdefs.h>32 /*#include <sys/cdefs.h> 33 33 #ifndef lint 34 34 #if !defined(BUILTIN) && !defined(SHELL) … … 44 44 __RCSID("$NetBSD: printf.c,v 1.31 2005/03/22 23:55:46 dsl Exp $"); 45 45 #endif 46 #endif /* not lint */46 #endif*/ /* not lint */ 47 47 48 48 #include <sys/types.h> 49 49 50 50 #include <ctype.h> 51 #include <err.h>51 #include "err.h" 52 52 #include <errno.h> 53 #ifndef _MSC_VER 53 54 #include <inttypes.h> 55 #endif 54 56 #include <limits.h> 55 57 #include <locale.h> … … 58 60 #include <stdlib.h> 59 61 #include <string.h> 62 #ifndef _MSC_VER 60 63 #include <unistd.h> 64 #else 65 #include "mscfakes.h" 66 #endif 61 67 62 68 #ifdef __GNUC__ … … 77 83 static char *mklong(const char *, int); 78 84 static void check_conversion(const char *, const char *); 79 static void usage(void); 85 static void usage(void); 80 86 81 87 static void b_count(int); … … 88 94 89 95 #ifdef BUILTIN /* csh builtin */ 90 #define mainprogprintf96 #define kmk_builtin_printf progprintf 91 97 #endif 92 98 93 99 #ifdef SHELL /* sh (aka ash) builtin */ 94 #define mainprintfcmd100 #define kmk_builtin_printf printfcmd 95 101 #include "../../bin/sh/bltin/bltin.h" 96 102 #endif /* SHELL */ … … 120 126 } 121 127 122 int main(int, char **); 123 int main(int argc, char *argv[]) 128 int kmk_builtin_printf(int argc, char *argv[]) 124 129 { 125 130 char *fmt, *start; … … 129 134 int ch; 130 135 131 #if !defined(SHELL) && !defined(BUILTIN) 136 /* kmk: reinitialize globals */ 137 b_length = 0; 138 b_fmt = NULL; 139 rval = 0; 140 gargv = NULL; 141 142 /* kmk: reset getopt and set progname */ 143 g_progname = argv[0]; 144 opterr = 1; 145 optarg = NULL; 146 optopt = 0; 147 #if defined(__FreeBSD__) || defined(__EMX__) || defined(__APPLE__) 148 optreset = 1; 149 optind = 1; 150 #else 151 optind = 0; /* init */ 152 #endif 153 154 #if !defined(SHELL) && !defined(BUILTIN) && !defined(kmk_builtin_printf) /* kmk did this already. */ 132 155 (void)setlocale (LC_ALL, ""); 133 156 #endif … … 158 181 * Basic algorithm is to scan the format string for conversion 159 182 * specifications -- once one is found, find out if the field 160 * width or precision is a '*'; if it is, gather up value. 183 * width or precision is a '*'; if it is, gather up value. 161 184 * Note, format strings are reused as necessary to use up the 162 * provided arguments, arguments of zero/null string are 185 * provided arguments, arguments of zero/null string are 163 186 * provided to use up the format string. 164 187 */ … … 322 345 323 346 /* 324 * Print SysV echo(1) style escape string 347 * Print SysV echo(1) style escape string 325 348 * Halts processing string if a \c escape is encountered. 326 349 */ … … 345 368 } 346 369 347 /* 370 /* 348 371 * %b string octal constants are not like those in C. 349 * They start with a \0, and are followed by 0, 1, 2, 350 * or 3 octal digits. 372 * They start with a \0, and are followed by 0, 1, 2, 373 * or 3 octal digits. 351 374 */ 352 375 if (ch == '0') { … … 390 413 391 414 /* 392 * Print "standard" escape characters 415 * Print "standard" escape characters 393 416 */ 394 417 static char * … … 519 542 { 520 543 static char copy[64]; 521 size_t len; 544 size_t len; 522 545 523 546 len = strlen(str) + 2; … … 530 553 copy[len - 2] = ch; 531 554 copy[len - 1] = '\0'; 532 return copy; 555 return copy; 533 556 } 534 557 … … 659 682 usage(void) 660 683 { 661 (void)fprintf(stderr, "Usage: %s format [arg ...]\n", g etprogname());662 } 684 (void)fprintf(stderr, "Usage: %s format [arg ...]\n", g_progname); 685 }
Note:
See TracChangeset
for help on using the changeset viewer.