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 const char rcsid[] =
82 "$FreeBSD: src/usr.bin/chat/chat.c,v 1.15 1999/11/25 07:28:54 kris Exp $";
94 #include <sys/types.h>
125 #define __V(x) (va_alist) va_dcl
131 #define O_NONBLOCK O_NDELAY
136 extern char *sys_errlist[];
137 #define memmove(to, from, n) bcopy(from, to, n)
138 #define strerror(n) ((unsigned)(n) < sys_nerr? sys_errlist[(n)] :\
142 /*************** Micro getopt() *********************************************/
143 #define OPTION(c,v) (_O&2&&**v?*(*v)++:!c||_O&4?0:(!(_O&1)&& \
144 (--c,++v),_O=4,c&&**v=='-'&&v[0][1]?*++*v=='-'\
145 &&!v[0][1]?(--c,++v,0):(_O=2,*(*v)++):0))
146 #define OPTARG(c,v) (_O&2?**v||(++v,--c)?(_O=1,--c,*v++): \
147 (_O=4,(char*)0):(char*)0)
148 #define OPTONLYARG(c,v) (_O&2&&**v?(_O=1,--c,*v++):(char*)0)
149 #define ARG(c,v) (c?(--c,*v++):(char*)0)
151 static int _O = 0; /* Internal state */
152 /*************** Micro getopt() *********************************************/
154 #define MAX_ABORTS 50
155 #define MAX_REPORTS 50
156 #define DEFAULT_CHAT_TIMEOUT 45
166 FILE* report_fp = (FILE *) 0;
167 char *report_file = (char *) 0;
168 char *chat_file = (char *) 0;
169 char *phone_num = (char *) 0;
170 char *phone_num2 = (char *) 0;
171 int timeout = DEFAULT_CHAT_TIMEOUT;
173 int have_tty_parameters = 0;
176 #define term_parms struct termio
177 #define get_term_param(param) ioctl(0, TCGETA, param)
178 #define set_term_param(param) ioctl(0, TCSETA, param)
179 struct termio saved_tty_parameters;
183 #define term_parms struct termios
184 #define get_term_param(param) tcgetattr(0, param)
185 #define set_term_param(param) tcsetattr(0, TCSANOW, param)
186 struct termios saved_tty_parameters;
189 char *abort_string[MAX_ABORTS], *fail_reason = (char *)0,
191 int n_aborts = 0, abort_next = 0, timeout_next = 0, echo_next = 0;
192 int clear_abort_next = 0;
194 char *report_string[MAX_REPORTS] ;
195 char report_buffer[50] ;
196 int n_reports = 0, report_next = 0, report_gathering = 0 ;
197 int clear_report_next = 0;
199 int say_next = 0, hup_next = 0;
201 void *dup_mem __P((void *b, size_t c));
202 void *copy_of __P((char *s));
203 static void usage __P((void));
204 void logf __P((const char *fmt, ...));
205 void fatal __P((int code, const char *fmt, ...));
206 SIGTYPE sigalrm __P((int signo));
207 SIGTYPE sigint __P((int signo));
208 SIGTYPE sigterm __P((int signo));
209 SIGTYPE sighup __P((int signo));
210 void unalarm __P((void));
211 void init __P((void));
212 void set_tty_parameters __P((void));
213 void echo_stderr __P((int));
214 void break_sequence __P((void));
215 void terminate __P((int status));
216 void do_file __P((char *chat_file));
217 int get_string __P((register char *string));
218 int put_string __P((register char *s));
219 int write_char __P((int c));
220 int put_char __P((int c));
221 int get_char __P((void));
222 void chat_send __P((register char *s));
223 char *character __P((int c));
224 void chat_expect __P((register char *s));
225 char *clean __P((register char *s, int sending));
226 void break_sequence __P((void));
227 void terminate __P((int status));
228 void pack_array __P((char **array, int end));
229 char *expect_strtok __P((char *, char *));
230 int vfmtmsg __P((char *, int, const char *, va_list)); /* vsprintf++ */
232 int main __P((int, char *[]));
238 void *ans = malloc (c);
240 fatal(2, "memory error!");
249 return dup_mem (s, strlen (s) + 1);
253 * chat [ -v ] [-T number] [-U number] [ -t timeout ] [ -f chat-file ] \
254 * [ -r report-file ] \
255 * [...[[expect[-say[-expect...]] say expect[-say[-expect]] ...]]]
257 * Perform a UUCP-dialer-like chat script on stdin and stdout.
269 while ((option = OPTION(argc, argv)) != 0) {
292 if ((arg = OPTARG(argc, argv)) != NULL)
293 chat_file = copy_of(arg);
299 if ((arg = OPTARG(argc, argv)) != NULL)
306 arg = OPTARG (argc, argv);
308 if (report_fp != NULL)
310 report_file = copy_of (arg);
311 report_fp = fopen (report_file, "a");
312 if (report_fp != NULL) {
314 fprintf (report_fp, "Opening \"%s\"...\n",
322 if ((arg = OPTARG(argc, argv)) != NULL)
323 phone_num = copy_of(arg);
329 if ((arg = OPTARG(argc, argv)) != NULL)
330 phone_num2 = copy_of(arg);
341 * Default the report file to the stderr location
343 if (report_fp == NULL)
348 openlog("chat", LOG_PID);
350 openlog("chat", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
353 setlogmask(LOG_UPTO(LOG_INFO));
355 setlogmask(LOG_UPTO(LOG_WARNING));
361 if (chat_file != NULL) {
362 arg = ARG(argc, argv);
368 while ((arg = ARG(argc, argv)) != NULL) {
371 if ((arg = ARG(argc, argv)) != NULL)
381 * Process a chat script when read from a file.
384 void do_file (chat_file)
388 char *sp, *arg, quote;
392 cfp = fopen (chat_file, "r");
394 fatal(1, "%s -- open failed: %m", chat_file);
399 while (fgets(buf, STR_LEN, cfp) != NULL) {
400 sp = strchr (buf, '\n');
407 /* lines starting with '#' are comments. If a real '#'
408 is to be expected, it should be quoted .... */
412 while (*sp != '\0') {
413 if (*sp == ' ' || *sp == '\t') {
418 if (*sp == '"' || *sp == '\'') {
421 while (*sp != quote) {
423 fatal(1, "unterminated quote (line %d)", linect);
433 while (*sp != '\0' && *sp != ' ' && *sp != '\t')
451 * We got an error parsing the command line.
457 Usage: chat [-e] [-v] [-V] [-t timeout] [-r report-file] [-T phone-number]\n\
458 [-U phone-number2] {-f chat-file | chat-script}\n");
465 * Send a message to syslog and/or stderr.
467 void logf __V((const char *fmt, ...))
476 fmt = va_arg(args, char *);
479 vfmtmsg(line, sizeof(line), fmt, args);
481 syslog(LOG_INFO, "%s", line);
483 fprintf(stderr, "%s\n", line);
487 * Print an error message and terminate.
490 void fatal __V((int code, const char *fmt, ...))
500 code = va_arg(args, int);
501 fmt = va_arg(args, char *);
504 vfmtmsg(line, sizeof(line), fmt, args);
506 syslog(LOG_ERR, "%s", line);
508 fprintf(stderr, "%s\n", line);
514 SIGTYPE sigalrm(signo)
520 alarmed = 1; /* Reset alarm to avoid race window */
521 signal(SIGALRM, sigalrm); /* that can cause hanging in read() */
523 if ((flags = fcntl(0, F_GETFL, 0)) == -1)
524 fatal(2, "Can't get file mode flags on stdin: %m");
526 if (fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
527 fatal(2, "Can't set file mode flags on stdin: %m");
537 if ((flags = fcntl(0, F_GETFL, 0)) == -1)
538 fatal(2, "Can't get file mode flags on stdin: %m");
540 if (fcntl(0, F_SETFL, flags & ~O_NONBLOCK) == -1)
541 fatal(2, "Can't set file mode flags on stdin: %m");
544 SIGTYPE sigint(signo)
550 SIGTYPE sigterm(signo)
556 SIGTYPE sighup(signo)
564 signal(SIGINT, sigint);
565 signal(SIGTERM, sigterm);
566 signal(SIGHUP, sighup);
568 set_tty_parameters();
569 signal(SIGALRM, sigalrm);
574 void set_tty_parameters()
576 #if defined(get_term_param)
579 if (get_term_param (&t) < 0)
580 fatal(2, "Can't get terminal parameters: %m");
582 saved_tty_parameters = t;
583 have_tty_parameters = 1;
585 t.c_iflag |= IGNBRK | ISTRIP | IGNPAR;
593 if (set_term_param (&t) < 0)
594 fatal(2, "Can't set terminal parameters: %m");
598 void break_sequence()
605 void terminate(status)
609 if (report_file != (char *) 0 && report_fp != (FILE *) NULL) {
611 * Allow the last of the report string to be gathered before we terminate.
613 if (report_gathering) {
616 rep_len = strlen(report_buffer);
617 while (rep_len + 1 <= sizeof(report_buffer)) {
621 if (c < 0 || iscntrl(c))
623 report_buffer[rep_len] = c;
626 report_buffer[rep_len] = 0;
627 fprintf (report_fp, "chat: %s\n", report_buffer);
630 fprintf (report_fp, "Closing \"%s\".\n", report_file);
632 report_fp = (FILE *) NULL;
635 #if defined(get_term_param)
636 if (have_tty_parameters) {
637 if (set_term_param (&saved_tty_parameters) < 0)
638 fatal(2, "Can't restore terminal parameters: %m");
646 * 'Clean up' this string.
648 char *clean(s, sending)
650 int sending; /* set to 1 when sending (putting) this string. */
652 char temp[STR_LEN], cur_chr;
653 register char *s1, *phchar;
654 int add_return = sending;
655 #define isoctal(chr) (((chr) >= '0') && ((chr) <= '7'))
658 /* Don't overflow buffer, leave room for chars we append later */
659 while (*s && s1 - temp < sizeof(temp) - 2 - add_return) {
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;
1280 if (strlen(string) > STR_LEN) {
1281 logf("expect string is too long");
1286 string = clean(string, 0);
1287 len = strlen(string);
1288 minlen = (len > sizeof(fail_buffer)? len: sizeof(fail_buffer)) - 1;
1291 logf("expect (%v)", string);
1302 while ( ! alarmed && (c = get_char()) >= 0) {
1303 int n, abort_len, report_len;
1307 if (verbose && c == '\n') {
1309 logf(""); /* blank line */
1311 logf("%0.*v", s - logged, logged);
1317 if (verbose && s >= logged + 80) {
1318 logf("%0.*v", s - logged, logged);
1324 fputc( '\n', stderr );
1326 fprintf( stderr, "%s", character(c) );
1329 if (!report_gathering) {
1330 for (n = 0; n < n_reports; ++n) {
1331 if ((report_string[n] != (char*) NULL) &&
1332 s - temp >= (report_len = strlen(report_string[n])) &&
1333 strncmp(s - report_len, report_string[n], report_len) == 0) {
1334 time_t time_now = time ((time_t*) NULL);
1335 struct tm* tm_now = localtime (&time_now);
1337 strftime (report_buffer, 20, "%b %d %H:%M:%S ", tm_now);
1338 strcat (report_buffer, report_string[n]);
1340 report_string[n] = (char *) NULL;
1341 report_gathering = 1;
1348 int rep_len = strlen (report_buffer);
1349 report_buffer[rep_len] = c;
1350 report_buffer[rep_len + 1] = '\0';
1353 report_gathering = 0;
1354 fprintf (report_fp, "chat: %s\n", report_buffer);
1358 if (s - temp >= len &&
1359 c == string[len - 1] &&
1360 strncmp(s - len, string, len) == 0) {
1363 logf("%0.*v", s - logged, logged);
1364 logf(" -- got it\n");
1372 for (n = 0; n < n_aborts; ++n) {
1373 if (s - temp >= (abort_len = strlen(abort_string[n])) &&
1374 strncmp(s - abort_len, abort_string[n], abort_len) == 0) {
1377 logf("%0.*v", s - logged, logged);
1384 strcpy(fail_reason = fail_buffer, abort_string[n]);
1390 if (logged < s - minlen) {
1391 logf("%0.*v", s - logged, logged);
1395 memmove(temp, s, minlen);
1396 logged = temp + (logged - s);
1400 if (alarmed && verbose)
1401 logf("warning: alarm synchronization problem");
1406 if (verbose && printed) {
1408 logf(" -- read timed out");
1410 logf(" -- read failed: %m");
1419 * Gross kludge to handle Solaris versions >= 2.6 having usleep.
1422 #include <sys/param.h>
1423 #if MAXUID > 65536 /* then this is Solaris 2.6 or later */
1429 #include <sys/types.h>
1430 #include <sys/time.h>
1433 usleep -- support routine for 4.2BSD system call emulations
1434 last edit: 29-Oct-1984 D A Gwyn
1437 extern int select();
1440 usleep( usec ) /* returns 0 if ok, else -1 */
1441 long usec; /* delay in microseconds */
1443 static struct { /* `timeval' */
1444 long tv_sec; /* seconds */
1445 long tv_usec; /* microsecs */
1446 } delay; /* _select() timeout */
1448 delay.tv_sec = usec / 1000000L;
1449 delay.tv_usec = usec % 1000000L;
1451 return select(0, (long *)0, (long *)0, (long *)0, &delay);
1456 pack_array (array, end)
1457 char **array; /* The address of the array of string pointers */
1458 int end; /* The index of the next free entry before CLR_ */
1462 for (i = 0; i < end; i++) {
1463 if (array[i] == NULL) {
1464 for (j = i+1; j < end; ++j)
1465 if (array[j] != NULL)
1466 array[i++] = array[j];
1467 for (; i < end; ++i)
1475 * vfmtmsg - format a message into a buffer. Like vsprintf except we
1476 * also specify the length of the output buffer, and we handle the
1477 * %m (error message) format.
1478 * Doesn't do floating-point formats.
1479 * Returns the number of chars put into buf.
1481 #define OUTCHAR(c) (buflen > 0? (--buflen, *buf++ = (c)): 0)
1484 vfmtmsg(buf, buflen, fmt, args)
1491 int width, prec, fillch;
1492 int base, len, neg, quoted;
1493 unsigned long val = 0;
1498 static char hexchars[] = "0123456789abcdef";
1502 while (buflen > 0) {
1503 for (f = fmt; *f != '%' && *f != 0; ++f)
1509 memcpy(buf, fmt, len);
1524 width = va_arg(args, int);
1527 while (isdigit(c)) {
1528 width = width * 10 + c - '0';
1535 prec = va_arg(args, int);
1538 while (isdigit(c)) {
1539 prec = prec * 10 + c - '0';
1550 i = va_arg(args, int);
1559 val = va_arg(args, unsigned int);
1563 val = va_arg(args, unsigned int);
1567 val = (unsigned long) va_arg(args, void *);
1572 str = va_arg(args, char *);
1575 num[0] = va_arg(args, int);
1580 str = strerror(errno);
1582 case 'v': /* "visible" string */
1583 case 'q': /* quoted string */
1585 p = va_arg(args, unsigned char *);
1586 if (fillch == '0' && prec > 0) {
1589 n = strlen((char *)p);
1590 if (prec > 0 && prec < n)
1593 while (n > 0 && buflen > 0) {
1596 if (!quoted && c >= 0x80) {
1601 if (quoted && (c == '"' || c == '\\'))
1603 if (c < 0x20 || (0x7f <= c && c < 0xa0)) {
1607 case '\t': OUTCHAR('t'); break;
1608 case '\n': OUTCHAR('n'); break;
1609 case '\b': OUTCHAR('b'); break;
1610 case '\f': OUTCHAR('f'); break;
1613 OUTCHAR(hexchars[c >> 4]);
1614 OUTCHAR(hexchars[c & 0xf]);
1631 --fmt; /* so %z outputs %z etc. */
1636 str = num + sizeof(num);
1638 while (str > num + neg) {
1639 *--str = hexchars[val % base];
1641 if (--prec <= 0 && val == 0)
1653 len = num + sizeof(num) - 1 - str;
1656 if (prec > 0 && len > prec)
1662 if ((n = width - len) > 0) {
1670 memcpy(buf, str, len);