sbin/hammer2/cmd_debug.c: Clear errno
[dragonfly.git] / usr.bin / msgs / msgs.c
blobc077fe85e89ca35b4f7d897fd1508edd49a46851
1 /*-
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * @(#) Copyright (c) 1980, 1993 The Regents of the University of California. All rights reserved.
30 * @(#)msgs.c 8.2 (Berkeley) 4/28/95
31 * $FreeBSD: src/usr.bin/msgs/msgs.c,v 1.15.2.2 2003/02/11 21:31:56 mike Exp $
35 * msgs - a user bulletin board program
37 * usage:
38 * msgs [fhlopq] [[-]number] to read messages
39 * msgs -s to place messages
40 * msgs -c [-days] to clean up the bulletin board
42 * prompt commands are:
43 * y print message
44 * n flush message, go to next message
45 * q flush message, quit
46 * p print message, turn on 'pipe thru more' mode
47 * P print message, turn off 'pipe thru more' mode
48 * - reprint last message
49 * s[-][<num>] [<filename>] save message
50 * m[-][<num>] mail with message in temp mbox
51 * x exit without flushing this message
52 * <num> print message number <num>
55 #define V7 /* will look for TERM in the environment */
56 #define OBJECT /* will object to messages without Subjects */
57 /* #define REJECT */ /* will reject messages without Subjects
58 (OBJECT must be defined also) */
59 /* #define UNBUFFERED *//* use unbuffered output */
61 #include <sys/param.h>
62 #include <sys/stat.h>
63 #include <ctype.h>
64 #include <dirent.h>
65 #include <err.h>
66 #include <errno.h>
67 #include <fcntl.h>
68 #include <locale.h>
69 #include <pwd.h>
70 #include <setjmp.h>
71 #include <termcap.h>
72 #include <termios.h>
73 #include <signal.h>
74 #include <stdbool.h>
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <string.h>
78 #include <time.h>
79 #include <unistd.h>
80 #include "pathnames.h"
82 #define CMODE 0644 /* bounds file creation mode */
83 #define NO false
84 #define YES true
85 #define SUPERUSER 0 /* superuser uid */
86 #define DAEMON 1 /* daemon uid */
87 #define NLINES 24 /* default number of lines/crt screen */
88 #define NDAYS 21 /* default keep time for messages */
89 #define DAYS *24*60*60 /* seconds/day */
90 #define MSGSRC ".msgsrc" /* user's rc file */
91 #define BOUNDS "bounds" /* message bounds file */
92 #define NEXT "Next message? [yq]"
93 #define MORE "More? [ynq]"
94 #define NOMORE "(No more) [q] ?"
96 FILE *msgsrc;
97 FILE *newmsg;
98 const char *sep = "-";
99 char inbuf[BUFSIZ];
100 char fname[MAXPATHLEN];
101 char cmdbuf[MAXPATHLEN + MAXPATHLEN];
102 char subj[128];
103 char from[128];
104 char date[128];
105 char *ptr;
106 char *in;
107 bool local;
108 bool ruptible;
109 bool totty;
110 bool seenfrom;
111 bool seensubj;
112 bool blankline;
113 bool printing = NO;
114 bool mailing = NO;
115 bool quitit = NO;
116 bool sending = NO;
117 bool intrpflg = NO;
118 int uid;
119 int msg;
120 int prevmsg;
121 int lct;
122 int nlines;
123 int Lpp = 0;
124 time_t t;
125 time_t keep;
127 /* option initialization */
128 bool hdrs = NO;
129 bool qopt = NO;
130 bool hush = NO;
131 bool send_msg = NO;
132 bool locomode = NO;
133 bool use_pager = NO;
134 bool clean = NO;
135 bool lastcmd = NO;
136 jmp_buf tstpbuf;
139 void ask(const char *);
140 void gfrsub(FILE *);
141 int linecnt(FILE *);
142 int next(char *);
143 char *nxtfld(unsigned char *);
144 void onsusp(int);
145 void onintr(int);
146 void prmesg(int);
147 static void usage(void);
150 main(int argc, char **argv)
152 bool newrc, already;
153 int rcfirst = 0; /* first message to print (from .rc) */
154 int rcback = 0; /* amount to back off of rcfirst */
155 int firstmsg = 0, nextmsg = 0, lastmsg = 0;
156 int blast = 0;
157 struct stat buf; /* stat to check access of bounds */
158 FILE *bounds;
160 #ifdef UNBUFFERED
161 setbuf(stdout, NULL);
162 #endif
163 setlocale(LC_ALL, "");
165 time(&t);
166 setuid(uid = getuid());
167 ruptible = (signal(SIGINT, SIG_IGN) == SIG_DFL);
168 if (ruptible)
169 signal(SIGINT, SIG_DFL);
171 argc--, argv++;
172 while (argc > 0) {
173 if (isdigit(argv[0][0])) { /* starting message # */
174 rcfirst = atoi(argv[0]);
176 else if (isdigit(argv[0][1])) { /* backward offset */
177 rcback = atoi( &( argv[0][1] ) );
179 else {
180 ptr = *argv;
181 while (*ptr) switch (*ptr++) {
183 case '-':
184 break;
186 case 'c':
187 if (uid != SUPERUSER && uid != DAEMON) {
188 fprintf(stderr, "Sorry\n");
189 exit(1);
191 clean = YES;
192 break;
194 case 'f': /* silently */
195 hush = YES;
196 break;
198 case 'h': /* headers only */
199 hdrs = YES;
200 break;
202 case 'l': /* local msgs only */
203 locomode = YES;
204 break;
206 case 'o': /* option to save last message */
207 lastcmd = YES;
208 break;
210 case 'p': /* pipe thru 'more' during long msgs */
211 use_pager = YES;
212 break;
214 case 'q': /* query only */
215 qopt = YES;
216 break;
218 case 's': /* sending TO msgs */
219 send_msg = YES;
220 break;
222 default:
223 usage();
226 argc--, argv++;
230 * determine current message bounds
232 snprintf(fname, sizeof(fname), "%s/%s", _PATH_MSGS, BOUNDS);
235 * Test access rights to the bounds file
236 * This can be a little tricky. if(send_msg), then
237 * we will create it. We assume that if(send_msg),
238 * then you have write permission there.
239 * Else, it better be there, or we bail.
241 if (send_msg != YES) {
242 if (stat(fname, &buf) < 0) {
243 if (hush != YES) {
244 err(errno, "%s", fname);
245 } else {
246 exit(1);
250 bounds = fopen(fname, "r");
252 if (bounds != NULL) {
253 fscanf(bounds, "%d %d\n", &firstmsg, &lastmsg);
254 fclose(bounds);
255 blast = lastmsg; /* save upper bound */
258 if (clean)
259 keep = t - (rcback? rcback : NDAYS) DAYS;
261 if (clean || bounds == NULL) { /* relocate message bounds */
262 struct dirent *dp;
263 struct stat stbuf;
264 bool seenany = NO;
265 DIR *dirp;
267 dirp = opendir(_PATH_MSGS);
268 if (dirp == NULL)
269 err(errno, "%s", _PATH_MSGS);
271 firstmsg = 32767;
272 lastmsg = 0;
274 for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)){
275 char *cp = dp->d_name;
276 int i = 0;
278 if (dp->d_ino == 0)
279 continue;
281 if (clean)
282 snprintf(inbuf, sizeof(inbuf), "%s/%s", _PATH_MSGS, cp);
284 while (isdigit(*cp))
285 i = i * 10 + *cp++ - '0';
286 if (*cp)
287 continue; /* not a message! */
289 if (clean) {
290 if (stat(inbuf, &stbuf) != 0)
291 continue;
292 if (stbuf.st_mtime < keep
293 && stbuf.st_mode&S_IWRITE) {
294 unlink(inbuf);
295 continue;
299 if (i > lastmsg)
300 lastmsg = i;
301 if (i < firstmsg)
302 firstmsg = i;
303 seenany = YES;
305 closedir(dirp);
307 if (!seenany) {
308 if (blast != 0) /* never lower the upper bound! */
309 lastmsg = blast;
310 firstmsg = lastmsg + 1;
312 else if (blast > lastmsg)
313 lastmsg = blast;
315 if (!send_msg) {
316 bounds = fopen(fname, "w");
317 if (bounds == NULL)
318 err(errno, "%s", fname);
319 chmod(fname, CMODE);
320 fprintf(bounds, "%d %d\n", firstmsg, lastmsg);
321 fclose(bounds);
325 if (send_msg) {
327 * Send mode - place msgs in _PATH_MSGS
329 bounds = fopen(fname, "w");
330 if (bounds == NULL)
331 err(errno, "%s", fname);
333 nextmsg = lastmsg + 1;
334 snprintf(fname, sizeof(fname), "%s/%d", _PATH_MSGS, nextmsg);
335 newmsg = fopen(fname, "w");
336 if (newmsg == NULL)
337 err(errno, "%s", fname);
338 chmod(fname, CMODE);
340 fprintf(bounds, "%d %d\n", firstmsg, nextmsg);
341 fclose(bounds);
343 sending = YES;
344 if (ruptible)
345 signal(SIGINT, onintr);
347 if (isatty(fileno(stdin))) {
348 ptr = getpwuid(uid)->pw_name;
349 printf("Message %d:\nFrom %s %sSubject: ",
350 nextmsg, ptr, ctime(&t));
351 fflush(stdout);
352 fgets(inbuf, sizeof inbuf, stdin);
353 putchar('\n');
354 fflush(stdout);
355 fprintf(newmsg, "From %s %sSubject: %s\n",
356 ptr, ctime(&t), inbuf);
357 blankline = seensubj = YES;
359 else
360 blankline = seensubj = NO;
361 for (;;) {
362 fgets(inbuf, sizeof inbuf, stdin);
363 if (feof(stdin) || ferror(stdin))
364 break;
365 blankline = (blankline || (inbuf[0] == '\n'));
366 seensubj = (seensubj || (!blankline && (strncmp(inbuf, "Subj", 4) == 0)));
367 fputs(inbuf, newmsg);
369 #ifdef OBJECT
370 if (!seensubj) {
371 printf("NOTICE: Messages should have a Subject field!\n");
372 #ifdef REJECT
373 unlink(fname);
374 #endif
375 exit(1);
377 #endif
378 exit(ferror(stdin));
380 if (clean)
381 exit(0);
384 * prepare to display messages
386 totty = (isatty(fileno(stdout)) != 0);
387 use_pager = use_pager && totty;
389 snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), MSGSRC);
390 msgsrc = fopen(fname, "r");
391 if (msgsrc) {
392 newrc = NO;
393 fscanf(msgsrc, "%d\n", &nextmsg);
394 fclose(msgsrc);
395 if (nextmsg > lastmsg+1) {
396 printf("Warning: bounds have been reset (%d, %d)\n",
397 firstmsg, lastmsg);
398 truncate(fname, (off_t)0);
399 newrc = YES;
401 else if (!rcfirst)
402 rcfirst = nextmsg - rcback;
404 else
405 newrc = YES;
406 msgsrc = fopen(fname, "r+");
407 if (msgsrc == NULL)
408 msgsrc = fopen(fname, "w");
409 if (msgsrc == NULL)
410 err(errno, "%s", fname);
411 if (rcfirst) {
412 if (rcfirst > lastmsg+1) {
413 printf("Warning: the last message is number %d.\n",
414 lastmsg);
415 rcfirst = nextmsg;
417 if (rcfirst > firstmsg)
418 firstmsg = rcfirst; /* don't set below first msg */
420 if (newrc) {
421 nextmsg = firstmsg;
422 fseek(msgsrc, 0L, 0);
423 fprintf(msgsrc, "%d\n", nextmsg);
424 fflush(msgsrc);
427 #ifdef V7
428 if (totty) {
429 struct winsize win;
430 if (ioctl(fileno(stdout), TIOCGWINSZ, &win) != -1)
431 Lpp = win.ws_row;
432 if (Lpp <= 0) {
433 if (tgetent(inbuf, getenv("TERM")) <= 0
434 || (Lpp = tgetnum("li")) <= 0) {
435 Lpp = NLINES;
439 #endif
440 Lpp -= 6; /* for headers, etc. */
442 already = NO;
443 prevmsg = firstmsg;
444 printing = YES;
445 if (ruptible)
446 signal(SIGINT, onintr);
449 * Main program loop
451 for (msg = firstmsg; msg <= lastmsg; msg++) {
453 snprintf(fname, sizeof(fname), "%s/%d", _PATH_MSGS, msg);
454 newmsg = fopen(fname, "r");
455 if (newmsg == NULL)
456 continue;
458 gfrsub(newmsg); /* get From and Subject fields */
459 if (locomode && !local) {
460 fclose(newmsg);
461 continue;
464 if (qopt) { /* This has to be located here */
465 printf("There are new messages.\n");
466 exit(0);
469 if (already && !hdrs)
470 putchar('\n');
473 * Print header
475 if (totty)
476 signal(SIGTSTP, onsusp);
477 (void) setjmp(tstpbuf);
478 already = YES;
479 nlines = 2;
480 if (seenfrom) {
481 printf("Message %d:\nFrom %s %s", msg, from, date);
482 nlines++;
484 if (seensubj) {
485 printf("Subject: %s", subj);
486 nlines++;
488 else {
489 if (seenfrom) {
490 putchar('\n');
491 nlines++;
493 while (nlines < 6
494 && fgets(inbuf, sizeof inbuf, newmsg)
495 && inbuf[0] != '\n') {
496 fputs(inbuf, stdout);
497 nlines++;
501 lct = linecnt(newmsg);
502 if (lct)
503 printf("(%d%sline%s) ", lct, seensubj? " " : " more ",
504 (lct == 1) ? "" : "s");
506 if (hdrs) {
507 printf("\n-----\n");
508 fclose(newmsg);
509 continue;
513 * Ask user for command
515 if (totty)
516 ask(lct? MORE : (msg==lastmsg? NOMORE : NEXT));
517 else
518 inbuf[0] = 'y';
519 if (totty)
520 signal(SIGTSTP, SIG_DFL);
521 cmnd:
522 in = inbuf;
523 switch (*in) {
524 case 'x':
525 case 'X':
526 exit(0);
528 case 'q':
529 case 'Q':
530 quitit = YES;
531 printf("--Postponed--\n");
532 exit(0);
533 /* intentional fall-thru */
534 case 'n':
535 case 'N':
536 if (msg >= nextmsg) sep = "Flushed";
537 prevmsg = msg;
538 break;
540 case 'p':
541 case 'P':
542 use_pager = (*in++ == 'p');
543 /* intentional fallthru */
544 case '\n':
545 case 'y':
546 default:
547 if (*in == '-') {
548 msg = prevmsg-1;
549 sep = "replay";
550 break;
552 if (isdigit(*in)) {
553 msg = next(in);
554 sep = in;
555 break;
558 prmesg(nlines + lct + (seensubj? 1 : 0));
559 prevmsg = msg;
563 printf("--%s--\n", sep);
564 sep = "-";
565 if (msg >= nextmsg) {
566 nextmsg = msg + 1;
567 fseek(msgsrc, 0L, 0);
568 fprintf(msgsrc, "%d\n", nextmsg);
569 fflush(msgsrc);
571 if (newmsg)
572 fclose(newmsg);
573 if (quitit)
574 break;
578 * Make sure .rc file gets updated
580 if (--msg >= nextmsg) {
581 nextmsg = msg + 1;
582 fseek(msgsrc, 0L, 0);
583 fprintf(msgsrc, "%d\n", nextmsg);
584 fflush(msgsrc);
586 if (already && !quitit && lastcmd && totty) {
588 * save or reply to last message?
590 msg = prevmsg;
591 ask(NOMORE);
592 if (inbuf[0] == '-' || isdigit(inbuf[0]))
593 goto cmnd;
595 if (!(already || hush || qopt))
596 printf("No new messages.\n");
597 exit(0);
600 static void
601 usage(void)
603 fprintf(stderr, "usage: msgs [fhlopq] [[-]number]\n");
604 exit(1);
607 void
608 prmesg(int length)
610 FILE *outf;
611 char *env_pager;
613 if (use_pager && length > Lpp) {
614 signal(SIGPIPE, SIG_IGN);
615 signal(SIGQUIT, SIG_IGN);
616 if ((env_pager = getenv("PAGER")) == NULL) {
617 snprintf(cmdbuf, sizeof(cmdbuf), _PATH_PAGER, Lpp);
618 } else {
619 snprintf(cmdbuf, sizeof(cmdbuf), "%s", env_pager);
621 outf = popen(cmdbuf, "w");
622 if (!outf)
623 outf = stdout;
624 else
625 setbuf(outf, NULL);
627 else
628 outf = stdout;
630 if (seensubj)
631 putc('\n', outf);
633 while (fgets(inbuf, sizeof inbuf, newmsg)) {
634 fputs(inbuf, outf);
635 if (ferror(outf)) {
636 clearerr(outf);
637 break;
641 if (outf != stdout) {
642 pclose(outf);
643 signal(SIGPIPE, SIG_DFL);
644 signal(SIGQUIT, SIG_DFL);
646 else {
647 fflush(stdout);
650 /* force wait on output */
651 tcdrain(fileno(stdout));
654 void
655 onintr(int unused __unused)
657 signal(SIGINT, onintr);
658 if (mailing)
659 unlink(fname);
660 if (sending) {
661 unlink(fname);
662 puts("--Killed--");
663 exit(1);
665 if (printing) {
666 putchar('\n');
667 if (hdrs)
668 exit(0);
669 sep = "Interrupt";
670 if (newmsg)
671 fseek(newmsg, 0L, 2);
672 intrpflg = YES;
677 * We have just gotten a susp. Suspend and prepare to resume.
679 void
680 onsusp(int unused __unused)
682 signal(SIGTSTP, SIG_DFL);
683 sigsetmask(0);
684 kill(0, SIGTSTP);
685 signal(SIGTSTP, onsusp);
686 if (!mailing)
687 longjmp(tstpbuf, 0);
691 linecnt(FILE *f)
693 off_t oldpos = ftell(f);
694 int l = 0;
695 char lbuf[BUFSIZ];
697 while (fgets(lbuf, sizeof lbuf, f))
698 l++;
699 clearerr(f);
700 fseek(f, oldpos, 0);
701 return (l);
705 next(char *buf)
707 int i;
708 sscanf(buf, "%d", &i);
709 sprintf(buf, "Goto %d", i);
710 return(--i);
713 void
714 ask(const char *prompt)
716 char inch;
717 int n, cmsg, fd;
718 off_t oldpos;
719 FILE *cpfrom, *cpto;
721 printf("%s ", prompt);
722 fflush(stdout);
723 intrpflg = NO;
724 (void) fgets(inbuf, sizeof inbuf, stdin);
725 if ((n = strlen(inbuf)) > 0 && inbuf[n - 1] == '\n')
726 inbuf[n - 1] = '\0';
727 if (intrpflg)
728 inbuf[0] = 'x';
731 * Handle 'mail' and 'save' here.
733 if ((inch = inbuf[0]) == 's' || inch == 'm') {
734 if (inbuf[1] == '-')
735 cmsg = prevmsg;
736 else if (isdigit(inbuf[1]))
737 cmsg = atoi(&inbuf[1]);
738 else
739 cmsg = msg;
740 snprintf(fname, sizeof(fname), "%s/%d", _PATH_MSGS, cmsg);
742 oldpos = ftell(newmsg);
744 cpfrom = fopen(fname, "r");
745 if (!cpfrom) {
746 printf("Message %d not found\n", cmsg);
747 ask (prompt);
748 return;
751 if (inch == 's') {
752 in = nxtfld(inbuf);
753 if (*in) {
754 for (n=0; in[n] > ' '; n++) { /* sizeof fname? */
755 fname[n] = in[n];
757 fname[n] = '\0';
759 else
760 strcpy(fname, "Messages");
761 fd = open(fname, O_RDWR|O_EXCL|O_CREAT|O_APPEND);
763 else {
764 strcpy(fname, _PATH_TMP);
765 fd = mkstemp(fname);
766 if (fd != -1) {
767 snprintf(cmdbuf, sizeof(cmdbuf), _PATH_MAIL,
768 fname);
769 mailing = YES;
772 if (fd == -1 || (cpto = fdopen(fd, "a")) == NULL) {
773 if (fd != -1)
774 close(fd);
775 warn("%s", fname);
776 mailing = NO;
777 fseek(newmsg, oldpos, 0);
778 ask(prompt);
779 return;
782 while ((n = fread(inbuf, 1, sizeof inbuf, cpfrom)))
783 fwrite(inbuf, 1, n, cpto);
785 fclose(cpfrom);
786 fclose(cpto);
787 fseek(newmsg, oldpos, 0); /* reposition current message */
788 if (inch == 's')
789 printf("Message %d saved in \"%s\"\n", cmsg, fname);
790 else {
791 system(cmdbuf);
792 unlink(fname);
793 mailing = NO;
795 ask(prompt);
799 void
800 gfrsub(FILE *infile)
802 off_t frompos;
803 int count;
805 seensubj = seenfrom = NO;
806 local = YES;
807 subj[0] = from[0] = date[0] = '\0';
810 * Is this a normal message?
812 if (fgets(inbuf, sizeof inbuf, infile)) {
813 if (strncmp(inbuf, "From", 4)==0) {
815 * expected form starts with From
817 seenfrom = YES;
818 frompos = ftell(infile);
819 ptr = from;
820 in = nxtfld(inbuf);
821 if (*in) {
822 count = sizeof(from) - 1;
823 while (*in && *in > ' ' && count-- > 0) {
824 if (*in == ':' || *in == '@' ||
825 *in == '!')
826 local = NO;
827 *ptr++ = *in++;
830 *ptr = '\0';
831 if (*(in = nxtfld(in)))
832 strncpy(date, in, sizeof date);
833 else {
834 date[0] = '\n';
835 date[1] = '\0';
838 else {
840 * not the expected form
842 fseek(infile, 0L, 0);
843 return;
846 else
848 * empty file ?
850 return;
853 * look for Subject line until EOF or a blank line
855 while (fgets(inbuf, sizeof inbuf, infile)
856 && !(blankline = (inbuf[0] == '\n'))) {
858 * extract Subject line
860 if (!seensubj && strncmp(inbuf, "Subj", 4)==0) {
861 seensubj = YES;
862 frompos = ftell(infile);
863 strncpy(subj, nxtfld(inbuf), sizeof subj);
866 if (!blankline)
868 * ran into EOF
870 fseek(infile, frompos, 0);
872 if (!seensubj)
874 * for possible use with Mail
876 strncpy(subj, "(No Subject)\n", sizeof subj);
879 char *
880 nxtfld(unsigned char *s)
882 if (*s) while (*s && !isspace(*s)) s++; /* skip over this field */
883 if (*s) while (*s && isspace(*s)) s++; /* find start of next field */
884 return (s);