Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 2 | /* printf - format and print data |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 3 | |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 4 | Copyright 1999 Dave Cinege |
| 5 | Portions copyright (C) 1990-1996 Free Software Foundation, Inc. |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 6 | |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 7 | Licensed under GPL v2 or later, see file LICENSE in this tarball for details. |
| 8 | */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 9 | |
| 10 | /* Usage: printf format [argument...] |
| 11 | |
| 12 | A front end to the printf function that lets it be used from the shell. |
| 13 | |
| 14 | Backslash escapes: |
| 15 | |
| 16 | \" = double quote |
| 17 | \\ = backslash |
| 18 | \a = alert (bell) |
| 19 | \b = backspace |
| 20 | \c = produce no further output |
| 21 | \f = form feed |
| 22 | \n = new line |
| 23 | \r = carriage return |
| 24 | \t = horizontal tab |
| 25 | \v = vertical tab |
| 26 | \0ooo = octal number (ooo is 0 to 3 digits) |
| 27 | \xhhh = hexadecimal number (hhh is 1 to 3 digits) |
| 28 | |
| 29 | Additional directive: |
| 30 | |
| 31 | %b = print an argument string, interpreting backslash escapes |
| 32 | |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 33 | The 'format' argument is re-used as many times as necessary |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 34 | to convert all of the given arguments. |
| 35 | |
| 36 | David MacKenzie <djm@gnu.ai.mit.edu> */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 37 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 38 | |
| 39 | // 19990508 Busy Boxed! Dave Cinege |
| 40 | |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 41 | #include "busybox.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 42 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 43 | static int print_formatted(char *format, int argc, char **argv); |
| 44 | static void print_direc(char *start, size_t length, |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 45 | int field_width, int precision, const char *argument); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 46 | |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 47 | typedef void (*converter)(const char *arg, void *result); |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 48 | |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 49 | static void multiconvert(const char *arg, void *result, converter convert) |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 50 | { |
| 51 | char s[16]; |
| 52 | if (*arg == '"' || *arg == '\'') { |
Denis Vlasenko | d686a04 | 2006-11-27 14:43:21 +0000 | [diff] [blame] | 53 | sprintf(s, "%d", (unsigned char)arg[1]); |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 54 | arg = s; |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 55 | } |
Denis Vlasenko | d686a04 | 2006-11-27 14:43:21 +0000 | [diff] [blame] | 56 | convert(arg, result); |
| 57 | if (errno) /* Huh, looks strange... bug? */ |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 58 | fputs(arg, stderr); |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 59 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 60 | |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 61 | static void conv_strtoul(const char *arg, void *result) |
Denis Vlasenko | d686a04 | 2006-11-27 14:43:21 +0000 | [diff] [blame] | 62 | { |
| 63 | *(unsigned long*)result = bb_strtoul(arg, NULL, 10); |
| 64 | } |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 65 | static void conv_strtol(const char *arg, void *result) |
Denis Vlasenko | d686a04 | 2006-11-27 14:43:21 +0000 | [diff] [blame] | 66 | { |
| 67 | *(long*)result = bb_strtol(arg, NULL, 10); |
| 68 | } |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 69 | static void conv_strtod(const char *arg, void *result) |
Denis Vlasenko | d686a04 | 2006-11-27 14:43:21 +0000 | [diff] [blame] | 70 | { |
| 71 | char *end; |
| 72 | /* Well, this one allows leading whitespace... so what */ |
| 73 | /* What I like much less is that "-" is accepted too! :( */ |
| 74 | *(double*)result = strtod(arg, &end); |
| 75 | if (end[0]) errno = ERANGE; |
| 76 | } |
| 77 | |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 78 | static unsigned long my_xstrtoul(const char *arg) |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 79 | { |
| 80 | unsigned long result; |
Denis Vlasenko | d686a04 | 2006-11-27 14:43:21 +0000 | [diff] [blame] | 81 | multiconvert(arg, &result, conv_strtoul); |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 82 | return result; |
| 83 | } |
| 84 | |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 85 | static long my_xstrtol(const char *arg) |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 86 | { |
| 87 | long result; |
Denis Vlasenko | d686a04 | 2006-11-27 14:43:21 +0000 | [diff] [blame] | 88 | multiconvert(arg, &result, conv_strtol); |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 89 | return result; |
| 90 | } |
| 91 | |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 92 | static double my_xstrtod(const char *arg) |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 93 | { |
| 94 | double result; |
Denis Vlasenko | d686a04 | 2006-11-27 14:43:21 +0000 | [diff] [blame] | 95 | multiconvert(arg, &result, conv_strtod); |
Rob Landley | 251161f | 2006-01-06 20:28:05 +0000 | [diff] [blame] | 96 | return result; |
| 97 | } |
| 98 | |
| 99 | static void print_esc_string(char *str) |
| 100 | { |
| 101 | for (; *str; str++) { |
| 102 | if (*str == '\\') { |
| 103 | str++; |
| 104 | putchar(bb_process_escape_sequence((const char **)&str)); |
| 105 | } else { |
| 106 | putchar(*str); |
| 107 | } |
| 108 | |
| 109 | } |
| 110 | } |
| 111 | |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame] | 112 | int printf_main(int argc, char **argv); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 113 | int printf_main(int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 114 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 115 | char *format; |
| 116 | int args_used; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 117 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 118 | if (argc <= 1 || argv[1][0] == '-') { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 119 | bb_show_usage(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 120 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 121 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 122 | format = argv[1]; |
| 123 | argc -= 2; |
| 124 | argv += 2; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 125 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 126 | do { |
| 127 | args_used = print_formatted(format, argc, argv); |
| 128 | argc -= args_used; |
| 129 | argv += args_used; |
| 130 | } |
| 131 | while (args_used > 0 && argc > 0); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 132 | |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 133 | /* if (argc > 0) |
| 134 | fprintf(stderr, "excess args ignored"); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 135 | */ |
| 136 | |
Glenn L McGrath | 240a91d | 2004-09-15 02:05:23 +0000 | [diff] [blame] | 137 | return EXIT_SUCCESS; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* Print the text in FORMAT, using ARGV (with ARGC elements) for |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 141 | arguments to any '%' directives. |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 142 | Return the number of elements of ARGV used. */ |
| 143 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 144 | static int print_formatted(char *format, int argc, char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 145 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 146 | int save_argc = argc; /* Preserve original value. */ |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 147 | char *f; /* Pointer into 'format'. */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 148 | char *direc_start; /* Start of % directive. */ |
| 149 | size_t direc_length; /* Length of % directive. */ |
| 150 | int field_width; /* Arg to first '*', or -1 if none. */ |
| 151 | int precision; /* Arg to second '*', or -1 if none. */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 152 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 153 | for (f = format; *f; ++f) { |
| 154 | switch (*f) { |
| 155 | case '%': |
| 156 | direc_start = f++; |
| 157 | direc_length = 1; |
| 158 | field_width = precision = -1; |
| 159 | if (*f == '%') { |
| 160 | putchar('%'); |
| 161 | break; |
| 162 | } |
| 163 | if (*f == 'b') { |
| 164 | if (argc > 0) { |
| 165 | print_esc_string(*argv); |
| 166 | ++argv; |
| 167 | --argc; |
| 168 | } |
| 169 | break; |
| 170 | } |
| 171 | if (strchr("-+ #", *f)) { |
| 172 | ++f; |
| 173 | ++direc_length; |
| 174 | } |
| 175 | if (*f == '*') { |
| 176 | ++f; |
| 177 | ++direc_length; |
| 178 | if (argc > 0) { |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 179 | field_width = my_xstrtoul(*argv); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 180 | ++argv; |
| 181 | --argc; |
| 182 | } else |
| 183 | field_width = 0; |
| 184 | } else |
Glenn L McGrath | 240a91d | 2004-09-15 02:05:23 +0000 | [diff] [blame] | 185 | while (isdigit(*f)) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 186 | ++f; |
| 187 | ++direc_length; |
| 188 | } |
| 189 | if (*f == '.') { |
| 190 | ++f; |
| 191 | ++direc_length; |
| 192 | if (*f == '*') { |
| 193 | ++f; |
| 194 | ++direc_length; |
| 195 | if (argc > 0) { |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 196 | precision = my_xstrtoul(*argv); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 197 | ++argv; |
| 198 | --argc; |
| 199 | } else |
| 200 | precision = 0; |
| 201 | } else |
Glenn L McGrath | 240a91d | 2004-09-15 02:05:23 +0000 | [diff] [blame] | 202 | while (isdigit(*f)) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 203 | ++f; |
| 204 | ++direc_length; |
| 205 | } |
| 206 | } |
| 207 | if (*f == 'l' || *f == 'L' || *f == 'h') { |
| 208 | ++f; |
| 209 | ++direc_length; |
| 210 | } |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 211 | /* |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 212 | if (!strchr ("diouxXfeEgGcs", *f)) |
| 213 | fprintf(stderr, "%%%c: invalid directive", *f); |
| 214 | */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 215 | ++direc_length; |
| 216 | if (argc > 0) { |
| 217 | print_direc(direc_start, direc_length, field_width, |
| 218 | precision, *argv); |
| 219 | ++argv; |
| 220 | --argc; |
| 221 | } else |
| 222 | print_direc(direc_start, direc_length, field_width, |
| 223 | precision, ""); |
| 224 | break; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 225 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 226 | case '\\': |
Glenn L McGrath | 240a91d | 2004-09-15 02:05:23 +0000 | [diff] [blame] | 227 | if (*++f == 'c') |
| 228 | exit(0); |
| 229 | putchar(bb_process_escape_sequence((const char **)&f)); |
| 230 | f--; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 231 | break; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 232 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 233 | default: |
| 234 | putchar(*f); |
| 235 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 236 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 237 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 238 | return save_argc - argc; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 241 | static void |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 242 | print_direc(char *start, size_t length, int field_width, int precision, |
Denis Vlasenko | a41fdf3 | 2007-01-29 22:51:00 +0000 | [diff] [blame] | 243 | const char *argument) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 244 | { |
Denis Vlasenko | c290563 | 2006-09-23 16:01:09 +0000 | [diff] [blame] | 245 | char *p; /* Null-terminated copy of % directive. */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 246 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 247 | p = xmalloc((unsigned) (length + 1)); |
| 248 | strncpy(p, start, length); |
| 249 | p[length] = 0; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 250 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 251 | switch (p[length - 1]) { |
| 252 | case 'd': |
| 253 | case 'i': |
| 254 | if (field_width < 0) { |
| 255 | if (precision < 0) |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 256 | printf(p, my_xstrtol(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 257 | else |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 258 | printf(p, precision, my_xstrtol(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 259 | } else { |
| 260 | if (precision < 0) |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 261 | printf(p, field_width, my_xstrtol(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 262 | else |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 263 | printf(p, field_width, precision, my_xstrtol(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 264 | } |
| 265 | break; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 266 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 267 | case 'o': |
| 268 | case 'u': |
| 269 | case 'x': |
| 270 | case 'X': |
| 271 | if (field_width < 0) { |
| 272 | if (precision < 0) |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 273 | printf(p, my_xstrtoul(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 274 | else |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 275 | printf(p, precision, my_xstrtoul(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 276 | } else { |
| 277 | if (precision < 0) |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 278 | printf(p, field_width, my_xstrtoul(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 279 | else |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 280 | printf(p, field_width, precision, my_xstrtoul(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 281 | } |
| 282 | break; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 283 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 284 | case 'f': |
| 285 | case 'e': |
| 286 | case 'E': |
| 287 | case 'g': |
| 288 | case 'G': |
| 289 | if (field_width < 0) { |
| 290 | if (precision < 0) |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 291 | printf(p, my_xstrtod(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 292 | else |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 293 | printf(p, precision, my_xstrtod(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 294 | } else { |
| 295 | if (precision < 0) |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 296 | printf(p, field_width, my_xstrtod(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 297 | else |
Denis Vlasenko | 1385899 | 2006-10-08 12:49:22 +0000 | [diff] [blame] | 298 | printf(p, field_width, precision, my_xstrtod(argument)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 299 | } |
| 300 | break; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 301 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 302 | case 'c': |
| 303 | printf(p, *argument); |
| 304 | break; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 305 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 306 | case 's': |
| 307 | if (field_width < 0) { |
| 308 | if (precision < 0) |
| 309 | printf(p, argument); |
| 310 | else |
| 311 | printf(p, precision, argument); |
| 312 | } else { |
| 313 | if (precision < 0) |
| 314 | printf(p, field_width, argument); |
| 315 | else |
| 316 | printf(p, field_width, precision, argument); |
| 317 | } |
| 318 | break; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 319 | } |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 320 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 321 | free(p); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 322 | } |