2 * Chat -- a program for automatic session establishment (i.e. dial
3 * the phone and log in).
5 * Standard termination codes:
6 * 0 - successful completion of the script
7 * 1 - invalid argument, expect string too large, etc.
8 * 2 - error on an I/O operation or fatal error condition.
9 * 3 - timeout waiting for a simple string.
10 * 4 - the first string declared as "ABORT"
11 * 5 - the second string declared as "ABORT"
12 * 6 - ... and so on for successive ABORT strings.
14 * This software is in the public domain.
17 * added -T and -U option and \T and \U substitution to pass a phone
18 * number into chat script. Two are needed for some ISDN TA applications.
19 * Keith Dart <kdart@cisco.com>
22 * Added SAY keyword to send output to stderr.
23 * This allows to turn ECHO OFF and to output specific, user selected,
24 * text to give progress messages. This best works when stderr
25 * exists (i.e.: pppd in nodetach mode).
27 * Added HANGUP directives to allow for us to be called
28 * back. When HANGUP is set to NO, chat will not hangup at HUP signal.
29 * We rely on timeouts in that case.
31 * Added CLR_ABORT to clear previously set ABORT string. This has been
32 * dictated by the HANGUP above as "NO CARRIER" (for example) must be
33 * an ABORT condition until we know the other host is going to close
34 * the connection for call back. As soon as we have completed the
35 * first stage of the call back sequence, "NO CARRIER" is a valid, non
36 * fatal string. As soon as we got called back (probably get "CONNECT"),
37 * we should re-arm the ABORT "NO CARRIER". Hence the CLR_ABORT command.
38 * Note that CLR_ABORT packs the abort_strings[] array so that we do not
39 * have unused entries not being reclaimed.
41 * In the same vein as above, added CLR_REPORT keyword.
43 * Allow for comments. Line starting with '#' are comments and are
44 * ignored. If a '#' is to be expected as the first character, the
45 * expect string must be quoted.
48 * Francis Demierre <Francis@SwissMail.Com>
49 * Thu May 15 17:15:40 MET DST 1997
52 * Added -r "report file" switch & REPORT keyword.
53 * Robert Geer <bgeer@xmission.com>
55 * Added -s "use stderr" and -S "don't use syslog" switches.
57 * Karl O. Pinc <kop@meme.com>
60 * Added -e "echo" switch & ECHO keyword
61 * Dick Streefland <dicks@tasking.nl>
64 * Considerable updates and modifications by
65 * Al Longyear <longyear@pobox.com>
66 * Paul Mackerras <paulus@cs.anu.edu.au>
69 * The original author is:
71 * Karl Fox <karl@MorningStar.Com>
72 * Morning Star Technologies, Inc.
81 static char rcsid[] = "$Id: chat.c,v 1.19 1998/03/24 23:57:48 paulus Exp $";
93 #include <sys/types.h>
124 #define __V(x) (va_alist) va_dcl
130 #define O_NONBLOCK O_NDELAY
135 extern char *sys_errlist[];
136 #define memmove(to, from, n) bcopy(from, to, n)
137 #define strerror(n) ((unsigned)(n) < sys_nerr? sys_errlist[(n)] :\
141 /*************** Micro getopt() *********************************************/
142 #define OPTION(c,v) (_O&2&&**v?*(*v)++:!c||_O&4?0:(!(_O&1)&& \
143 (--c,++v),_O=4,c&&**v=='-'&&v[0][1]?*++*v=='-'\
144 &&!v[0][1]?(--c,++v,0):(_O=2,*(*v)++):0))
145 #define OPTARG(c,v) (_O&2?**v||(++v,--c)?(_O=1,--c,*v++): \
146 (_O=4,(char*)0):(char*)0)
147 #define OPTONLYARG(c,v) (_O&2&&**v?(_O=1,--c,*v++):(char*)0)
148 #define ARG(c,v) (c?(--c,*v++):(char*)0)
150 static int _O = 0; /* Internal state */
151 /*************** Micro getopt() *********************************************/
155 #define MAX_ABORTS 50
156 #define MAX_REPORTS 50
157 #define DEFAULT_CHAT_TIMEOUT 45
167 FILE* report_fp = (FILE *) 0;
168 char *report_file = (char *) 0;
169 char *chat_file = (char *) 0;
170 char *phone_num = (char *) 0;
171 char *phone_num2 = (char *) 0;
172 int timeout = DEFAULT_CHAT_TIMEOUT;
174 int have_tty_parameters = 0;
177 #define term_parms struct termio
178 #define get_term_param(param) ioctl(0, TCGETA, param)
179 #define set_term_param(param) ioctl(0, TCSETA, param)
180 struct termio saved_tty_parameters;
184 #define term_parms struct termios
185 #define get_term_param(param) tcgetattr(0, param)
186 #define set_term_param(param) tcsetattr(0, TCSANOW, param)
187 struct termios saved_tty_parameters;
190 char *abort_string[MAX_ABORTS], *fail_reason = (char *)0,
192 int n_aborts = 0, abort_next = 0, timeout_next = 0, echo_next = 0;
193 int clear_abort_next = 0;
195 char *report_string[MAX_REPORTS] ;
196 char report_buffer[50] ;
197 int n_reports = 0, report_next = 0, report_gathering = 0 ;
198 int clear_report_next = 0;
200 int say_next = 0, hup_next = 0;
202 void *dup_mem __P((void *b, size_t c));
203 void *copy_of __P((char *s));
204 void usage __P((void));
205 void logf __P((const char *fmt, ...));
206 void fatal __P((int code, const char *fmt, ...));
207 SIGTYPE sigalrm __P((int signo));
208 SIGTYPE sigint __P((int signo));
209 SIGTYPE sigterm __P((int signo));
210 SIGTYPE sighup __P((int signo));
211 void unalarm __P((void));
212 void init __P((void));
213 void set_tty_parameters __P((void));
214 void echo_stderr __P((int));
215 void break_sequence __P((void));
216 void terminate __P((int status));
217 void do_file __P((char *chat_file));
218 int get_string __P((register char *string));
219 int put_string __P((register char *s));
220 int write_char __P((int c));
221 int put_char __P((int c));
222 int get_char __P((void));
223 void chat_send __P((register char *s));
224 char *character __P((int c));
225 void chat_expect __P((register char *s));
226 char *clean __P((register char *s, int sending));
227 void break_sequence __P((void));
228 void terminate __P((int status));
229 void pack_array __P((char **array, int end));
230 char *expect_strtok __P((char *, char *));
231 int vfmtmsg __P((char *, int, const char *, va_list)); /* vsprintf++ */
233 int main __P((int, char *[]));
239 void *ans = malloc (c);
241 fatal(2, "memory error!");
250 return dup_mem (s, strlen (s) + 1);
254 * chat [ -v ] [-T number] [-U number] [ -t timeout ] [ -f chat-file ] \
255 * [ -r report-file ] \
256 * [...[[expect[-say[-expect...]] say expect[-say[-expect]] ...]]]
258 * Perform a UUCP-dialer-like chat script on stdin and stdout.
268 program_name = *argv;
271 while ((option = OPTION(argc, argv)) != 0) {
294 if ((arg = OPTARG(argc, argv)) != NULL)
295 chat_file = copy_of(arg);
301 if ((arg = OPTARG(argc, argv)) != NULL)
308 arg = OPTARG (argc, argv);
310 if (report_fp != NULL)
312 report_file = copy_of (arg);
313 report_fp = fopen (report_file, "a");
314 if (report_fp != NULL) {
316 fprintf (report_fp, "Opening \"%s\"...\n",
324 if ((arg = OPTARG(argc, argv)) != NULL)
325 phone_num = copy_of(arg);
331 if ((arg = OPTARG(argc, argv)) != NULL)
332 phone_num2 = copy_of(arg);
343 * Default the report file to the stderr location
345 if (report_fp == NULL)
350 openlog("chat", LOG_PID);
352 openlog("chat", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
355 setlogmask(LOG_UPTO(LOG_INFO));
357 setlogmask(LOG_UPTO(LOG_WARNING));
363 if (chat_file != NULL) {
364 arg = ARG(argc, argv);
370 while ((arg = ARG(argc, argv)) != NULL) {
373 if ((arg = ARG(argc, argv)) != NULL)
383 * Process a chat script when read from a file.
386 void do_file (chat_file)
390 char *sp, *arg, quote;
394 cfp = fopen (chat_file, "r");
396 fatal(1, "%s -- open failed: %m", chat_file);
401 while (fgets(buf, STR_LEN, cfp) != NULL) {
402 sp = strchr (buf, '\n');
409 /* lines starting with '#' are comments. If a real '#'
410 is to be expected, it should be quoted .... */
414 while (*sp != '\0') {
415 if (*sp == ' ' || *sp == '\t') {
420 if (*sp == '"' || *sp == '\'') {
423 while (*sp != quote) {
425 fatal(1, "unterminated quote (line %d)", linect);
435 while (*sp != '\0' && *sp != ' ' && *sp != '\t')
453 * We got an error parsing the command line.
458 Usage: %s [-e] [-v] [-t timeout] [-r report-file] [-T phone-number]\n\
459 [-U phone-number2] {-f chat-file | chat-script}\n", program_name);
466 * Send a message to syslog and/or stderr.
468 void logf __V((const char *fmt, ...))
477 fmt = va_arg(args, char *);
480 vfmtmsg(line, sizeof(line), fmt, args);
482 syslog(LOG_INFO, "%s", line);
484 fprintf(stderr, "%s\n", line);
488 * Print an error message and terminate.
491 void fatal __V((int code, const char *fmt, ...))
501 code = va_arg(args, int);
502 fmt = va_arg(args, char *);
505 vfmtmsg(line, sizeof(line), fmt, args);
507 syslog(LOG_ERR, "%s", line);
509 fprintf(stderr, "%s\n", line);
515 SIGTYPE sigalrm(signo)
521 alarmed = 1; /* Reset alarm to avoid race window */
522 signal(SIGALRM, sigalrm); /* that can cause hanging in read() */
524 if ((flags = fcntl(0, F_GETFL, 0)) == -1)
525 fatal(2, "Can't get file mode flags on stdin: %m");
527 if (fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
528 fatal(2, "Can't set file mode flags on stdin: %m");
538 if ((flags = fcntl(0, F_GETFL, 0)) == -1)
539 fatal(2, "Can't get file mode flags on stdin: %m");
541 if (fcntl(0, F_SETFL, flags & ~O_NONBLOCK) == -1)
542 fatal(2, "Can't set file mode flags on stdin: %m");
545 SIGTYPE sigint(signo)
551 SIGTYPE sigterm(signo)
557 SIGTYPE sighup(signo)
565 signal(SIGINT, sigint);
566 signal(SIGTERM, sigterm);
567 signal(SIGHUP, sighup);
569 set_tty_parameters();
570 signal(SIGALRM, sigalrm);
575 void set_tty_parameters()
577 #if defined(get_term_param)
580 if (get_term_param (&t) < 0)
581 fatal(2, "Can't get terminal parameters: %m");
583 saved_tty_parameters = t;
584 have_tty_parameters = 1;
586 t.c_iflag |= IGNBRK | ISTRIP | IGNPAR;
594 if (set_term_param (&t) < 0)
595 fatal(2, "Can't set terminal parameters: %m");
599 void break_sequence()
606 void terminate(status)
610 if (report_file != (char *) 0 && report_fp != (FILE *) NULL) {
612 * Allow the last of the report string to be gathered before we terminate.
614 if (report_gathering) {
617 rep_len = strlen(report_buffer);
618 while (rep_len + 1 <= sizeof(report_buffer)) {
622 if (c < 0 || iscntrl(c))
624 report_buffer[rep_len] = c;
627 report_buffer[rep_len] = 0;
628 fprintf (report_fp, "chat: %s\n", report_buffer);
631 fprintf (report_fp, "Closing \"%s\".\n", report_file);
633 report_fp = (FILE *) NULL;
636 #if defined(get_term_param)
637 if (have_tty_parameters) {
638 if (set_term_param (&saved_tty_parameters) < 0)
639 fatal(2, "Can't restore terminal parameters: %m");
647 * 'Clean up' this string.
649 char *clean(s, sending)
651 int sending; /* set to 1 when sending (putting) this string. */
653 char temp[STR_LEN], cur_chr;
654 register char *s1, *phchar;
655 int add_return = sending;
656 #define isoctal(chr) (((chr) >= '0') && ((chr) <= '7'))
661 if (cur_chr == '^') {
663 if (cur_chr == '\0') {
674 if (cur_chr != '\\') {
680 if (cur_chr == '\0') {
694 if (sending && *s == '\0')
711 if (sending && phone_num) {
712 for ( phchar = phone_num; *phchar != '\0'; phchar++)
722 if (sending && phone_num2) {
723 for ( phchar = phone_num2; *phchar != '\0'; phchar++)
762 if (isoctal (cur_chr)) {
766 cur_chr |= *s++ - '0';
769 cur_chr |= *s++ - '0';
773 if (cur_chr != 0 || sending) {
774 if (sending && (cur_chr == '\\' || cur_chr == 0))
791 *s1++ = '\0'; /* guarantee closure */
792 *s1++ = '\0'; /* terminate the string */
793 return dup_mem (temp, (size_t) (s1 - temp)); /* may have embedded nuls */
797 * A modified version of 'strtok'. This version skips \ sequences.
800 char *expect_strtok (s, term)
803 static char *str = "";
808 * If a string was specified then do initial processing.
814 * If this is the escape flag then reset it and ignore the character.
835 * If this is not in the termination string, continue.
837 if (strchr (term, *str) == (char *) 0) {
843 * This is the terminator. Mark the end of the string and stop.
852 * Process the expect string
861 if (strcmp(s, "HANGUP") == 0) {
866 if (strcmp(s, "ABORT") == 0) {
871 if (strcmp(s, "CLR_ABORT") == 0) {
876 if (strcmp(s, "REPORT") == 0) {
881 if (strcmp(s, "CLR_REPORT") == 0) {
886 if (strcmp(s, "TIMEOUT") == 0) {
891 if (strcmp(s, "ECHO") == 0) {
896 if (strcmp(s, "SAY") == 0) {
902 * Fetch the expect and reply string.
905 expect = expect_strtok (s, "-");
908 if (expect == (char *) 0)
911 reply = expect_strtok (s, "-");
914 * Handle the expect string. If successful then exit.
916 if (get_string (expect))
920 * If there is a sub-reply string then send it. Otherwise any condition
923 if (reply == (char *) 0 || exit_code != 3)
930 * The expectation did not occur. This is terminal.
933 logf("Failed (%s)", fail_reason);
936 terminate(exit_code);
940 * Translate the input character to the appropriate string for printing
947 static char string[10];
950 meta = (c & 0x80) ? "M-" : "";
954 sprintf(string, "%s^%c", meta, (int)c + '@');
956 sprintf(string, "%s^?", meta);
958 sprintf(string, "%s%c", meta, c);
964 * process the reply string
972 write(2, s, strlen(s));
979 if (strcmp(s, "OFF") == 0)
980 signal(SIGHUP, SIG_IGN);
982 signal(SIGHUP, sighup);
988 echo = (strcmp(s, "ON") == 0);
997 if (n_aborts >= MAX_ABORTS)
998 fatal(2, "Too many ABORT strings");
1002 if (strlen(s1) > strlen(s)
1003 || strlen(s1) + 1 > sizeof(fail_buffer))
1004 fatal(1, "Illegal or too-long ABORT string ('%v')", s);
1006 abort_string[n_aborts++] = s1;
1009 logf("abort on (%v)", s);
1013 if (clear_abort_next) {
1019 clear_abort_next = 0;
1023 if (strlen(s1) > strlen(s)
1024 || strlen(s1) + 1 > sizeof(fail_buffer))
1025 fatal(1, "Illegal or too-long CLR_ABORT string ('%v')", s);
1028 for (i=0; i < n_aborts; i++) {
1029 if ( strcmp(s1,abort_string[i]) == 0 ) {
1030 free(abort_string[i]);
1031 abort_string[i] = NULL;
1035 logf("clear abort on (%v)", s);
1040 pack_array(abort_string,old_max);
1048 if (n_reports >= MAX_REPORTS)
1049 fatal(2, "Too many REPORT strings");
1053 if (strlen(s1) > strlen(s) || strlen(s1) > sizeof fail_buffer - 1)
1054 fatal(1, "Illegal or too-long REPORT string ('%v')", s);
1056 report_string[n_reports++] = s1;
1059 logf("report (%v)", s);
1063 if (clear_report_next) {
1069 clear_report_next = 0;
1073 if (strlen(s1) > strlen(s) || strlen(s1) > sizeof fail_buffer - 1)
1074 fatal(1, "Illegal or too-long REPORT string ('%v')", s);
1076 old_max = n_reports;
1077 for (i=0; i < n_reports; i++) {
1078 if ( strcmp(s1,report_string[i]) == 0 ) {
1079 free(report_string[i]);
1080 report_string[i] = NULL;
1084 logf("clear report (%v)", s);
1089 pack_array(report_string,old_max);
1099 timeout = DEFAULT_CHAT_TIMEOUT;
1102 logf("timeout set to %d seconds", timeout);
1107 if (strcmp(s, "EOT") == 0)
1109 else if (strcmp(s, "BREAK") == 0)
1121 status = read(0, &c, 1);
1125 return ((int)c & 0x7F);
1128 logf("warning: read() on stdin returned %d", status);
1131 if ((status = fcntl(0, F_GETFL, 0)) == -1)
1132 fatal(2, "Can't get file mode flags on stdin: %m");
1134 if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
1135 fatal(2, "Can't set file mode flags on stdin: %m");
1147 usleep(10000); /* inter-character typing delay (?) */
1149 status = write(1, &ch, 1);
1156 logf("warning: write() on stdout returned %d", status);
1159 if ((status = fcntl(0, F_GETFL, 0)) == -1)
1160 fatal(2, "Can't get file mode flags on stdin, %m");
1162 if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
1163 fatal(2, "Can't set file mode flags on stdin: %m");
1172 if (alarmed || put_char(c) < 0) {
1177 if (errno == EINTR || errno == EWOULDBLOCK)
1178 logf(" -- write timed out");
1180 logf(" -- write failed: %m");
1195 logf("send (??????)");
1197 logf("send (%v)", s);
1200 alarm(timeout); alarmed = 0;
1203 register char c = *s++;
1206 if (!write_char (c))
1222 usleep(10000); /* 1/100th of a second (arg is microseconds) */
1226 if (!write_char (c))
1238 * Echo a character to stderr.
1239 * When called with -1, a '\n' character is generated when
1240 * the cursor is not at the beginning of a line.
1249 case '\r': /* ignore '\r' */
1261 write(2, s, strlen(s));
1268 * 'Wait for' this string to appear on this file descriptor.
1270 int get_string(string)
1271 register char *string;
1274 int c, printed = 0, len, minlen;
1275 register char *s = temp, *end = s + STR_LEN;
1276 char *logged = temp;
1278 fail_reason = (char *)0;
1279 string = clean(string, 0);
1280 len = strlen(string);
1281 minlen = (len > sizeof(fail_buffer)? len: sizeof(fail_buffer)) - 1;
1284 logf("expect (%v)", string);
1286 if (len > STR_LEN) {
1287 logf("expect string is too long");
1301 while ( ! alarmed && (c = get_char()) >= 0) {
1302 int n, abort_len, report_len;
1306 if (verbose && c == '\n') {
1308 logf(""); /* blank line */
1310 logf("%0.*v", s - logged, logged);
1316 if (verbose && s >= logged + 80) {
1317 logf("%0.*v", s - logged, logged);
1323 fputc( '\n', stderr );
1325 fprintf( stderr, "%s", character(c) );
1328 if (!report_gathering) {
1329 for (n = 0; n < n_reports; ++n) {
1330 if ((report_string[n] != (char*) NULL) &&
1331 s - temp >= (report_len = strlen(report_string[n])) &&
1332 strncmp(s - report_len, report_string[n], report_len) == 0) {
1333 time_t time_now = time ((time_t*) NULL);
1334 struct tm* tm_now = localtime (&time_now);
1336 strftime (report_buffer, 20, "%b %d %H:%M:%S ", tm_now);
1337 strcat (report_buffer, report_string[n]);
1339 report_string[n] = (char *) NULL;
1340 report_gathering = 1;
1347 int rep_len = strlen (report_buffer);
1348 report_buffer[rep_len] = c;
1349 report_buffer[rep_len + 1] = '\0';
1352 report_gathering = 0;
1353 fprintf (report_fp, "chat: %s\n", report_buffer);
1357 if (s - temp >= len &&
1358 c == string[len - 1] &&
1359 strncmp(s - len, string, len) == 0) {
1362 logf("%0.*v", s - logged, logged);
1363 logf(" -- got it\n");
1371 for (n = 0; n < n_aborts; ++n) {
1372 if (s - temp >= (abort_len = strlen(abort_string[n])) &&
1373 strncmp(s - abort_len, abort_string[n], abort_len) == 0) {
1376 logf("%0.*v", s - logged, logged);
1383 strcpy(fail_reason = fail_buffer, abort_string[n]);
1389 if (logged < s - minlen) {
1390 logf("%0.*v", s - logged, logged);
1394 memmove(temp, s, minlen);
1395 logged = temp + (logged - s);
1399 if (alarmed && verbose)
1400 logf("warning: alarm synchronization problem");
1405 if (verbose && printed) {
1407 logf(" -- read timed out");
1409 logf(" -- read failed: %m");
1418 * Gross kludge to handle Solaris versions >= 2.6 having usleep.
1421 #include <sys/param.h>
1422 #if MAXUID > 65536 /* then this is Solaris 2.6 or later */
1428 #include <sys/types.h>
1429 #include <sys/time.h>
1432 usleep -- support routine for 4.2BSD system call emulations
1433 last edit: 29-Oct-1984 D A Gwyn
1436 extern int select();
1439 usleep( usec ) /* returns 0 if ok, else -1 */
1440 long usec; /* delay in microseconds */
1442 static struct { /* `timeval' */
1443 long tv_sec; /* seconds */
1444 long tv_usec; /* microsecs */
1445 } delay; /* _select() timeout */
1447 delay.tv_sec = usec / 1000000L;
1448 delay.tv_usec = usec % 1000000L;
1450 return select(0, (long *)0, (long *)0, (long *)0, &delay);
1455 pack_array (array, end)
1456 char **array; /* The address of the array of string pointers */
1457 int end; /* The index of the next free entry before CLR_ */
1461 for (i = 0; i < end; i++) {
1462 if (array[i] == NULL) {
1463 for (j = i+1; j < end; ++j)
1464 if (array[j] != NULL)
1465 array[i++] = array[j];
1466 for (; i < end; ++i)
1474 * vfmtmsg - format a message into a buffer. Like vsprintf except we
1475 * also specify the length of the output buffer, and we handle the
1476 * %m (error message) format.
1477 * Doesn't do floating-point formats.
1478 * Returns the number of chars put into buf.
1480 #define OUTCHAR(c) (buflen > 0? (--buflen, *buf++ = (c)): 0)
1483 vfmtmsg(buf, buflen, fmt, args)
1490 int width, prec, fillch;
1491 int base, len, neg, quoted;
1492 unsigned long val = 0;
1497 static char hexchars[] = "0123456789abcdef";
1501 while (buflen > 0) {
1502 for (f = fmt; *f != '%' && *f != 0; ++f)
1508 memcpy(buf, fmt, len);
1523 width = va_arg(args, int);
1526 while (isdigit(c)) {
1527 width = width * 10 + c - '0';
1534 prec = va_arg(args, int);
1537 while (isdigit(c)) {
1538 prec = prec * 10 + c - '0';
1549 i = va_arg(args, int);
1558 val = va_arg(args, unsigned int);
1562 val = va_arg(args, unsigned int);
1566 val = (unsigned long) va_arg(args, void *);
1571 str = va_arg(args, char *);
1574 num[0] = va_arg(args, int);
1579 str = strerror(errno);
1581 case 'v': /* "visible" string */
1582 case 'q': /* quoted string */
1584 p = va_arg(args, unsigned char *);
1585 if (fillch == '0' && prec > 0) {
1588 n = strlen((char *)p);
1589 if (prec > 0 && prec < n)
1592 while (n > 0 && buflen > 0) {
1595 if (!quoted && c >= 0x80) {
1600 if (quoted && (c == '"' || c == '\\'))
1602 if (c < 0x20 || (0x7f <= c && c < 0xa0)) {
1606 case '\t': OUTCHAR('t'); break;
1607 case '\n': OUTCHAR('n'); break;
1608 case '\b': OUTCHAR('b'); break;
1609 case '\f': OUTCHAR('f'); break;
1612 OUTCHAR(hexchars[c >> 4]);
1613 OUTCHAR(hexchars[c & 0xf]);
1630 --fmt; /* so %z outputs %z etc. */
1635 str = num + sizeof(num);
1637 while (str > num + neg) {
1638 *--str = hexchars[val % base];
1640 if (--prec <= 0 && val == 0)
1652 len = num + sizeof(num) - 1 - str;
1655 if (prec > 0 && len > prec)
1661 if ((n = width - len) > 0) {
1669 memcpy(buf, str, len);