Pristine Ack-5.5
[Ack-5.5.git] / lang / cem / libcc / stdio / tail_cc.1s.a
1 eÿvsprintf.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Ì\ 1/* $Id: vsprintf.c,v 1.2 1994/06/24 12:21:41 ceriel Exp $ */
2
3 #include        <stdio.h>
4 #include        <varargs.h>
5
6 char *
7 vsprintf(s, format, arg)
8         char *s;
9         char *format;
10         va_list arg;
11 {
12         FILE tmp_stream;
13
14         tmp_stream._fd     = -1;
15         tmp_stream._flags  = IO_WRITEMODE + IO_UNBUFF;
16         tmp_stream._buf    = (unsigned char *) s;
17         tmp_stream._ptr    = (unsigned char *) s;
18         tmp_stream._count  = 32767;
19
20         _doprnt(format, arg, &tmp_stream);
21         putc('\0',&tmp_stream);
22
23         return s;
24 }
25 vfprintf.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0à\0/* $Id: vfprintf.c,v 1.2 1994/06/24 12:21:35 ceriel Exp $ */
26
27 #include        <stdio.h>
28 #include        <varargs.h>
29
30 int
31 vfprintf(stream, format, arg)
32         FILE *stream;
33         char *format;
34         va_list arg;
35 {
36         return _doprnt (format, arg, stream);
37 }
38 vprintf.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Æ\0/* $Id: vprintf.c,v 1.2 1994/06/24 12:21:38 ceriel Exp $ */
39
40 #include        <stdio.h>
41 #include        <varargs.h>
42
43 int
44 vprintf(format, arg)
45         char *format;
46         va_list arg;
47 {
48         return _doprnt(format, arg, stdout);
49 }
50 termcap.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0`!/*
51  *      termcap.c       1.1     20/7/87         agc     Joypace Ltd
52  *
53  *      Copyright Joypace Ltd, London, UK, 1987. All rights reserved.
54  *      This file may be freely distributed provided that this notice
55  *      remains attached.
56  *
57  *      A public domain implementation of the termcap(3) routines.
58  *
59  *      Made fully functional by Ceriel J.H. Jacobs.
60  *
61  * BUGS:
62  *      - does not check termcap entry sizes
63  *      - not fully tested
64  */
65 #include <stdio.h>
66
67 #define CAPABLEN        2
68
69 #define ISSPACE(c)      ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
70 #define ISDIGIT(x)      ((x) >= '0' && (x) <= '9')
71
72 short   ospeed;         /* output speed */
73 char    PC;             /* padding character */
74 char    *BC;            /* back cursor movement */
75 char    *UP;            /* up cursor movement */
76
77 static char     *capab;         /* the capability itself */
78 static int      check_for_tc();
79 static int      match_name();
80
81 extern char     *getenv();      /* new, improved getenv */
82 extern FILE     *fopen();       /* old fopen */
83
84 /*
85  *      tgetent - get the termcap entry for terminal name, and put it
86  *      in bp (which must be an array of 1024 chars). Returns 1 if
87  *      termcap entry found, 0 if not found, and -1 if file not found.
88  */
89 int
90 tgetent(bp, name)
91 char    *bp;
92 char    *name;
93 {
94         FILE    *fp;
95         char    *file;
96         char    *cp;
97         short   len = strlen(name);
98         char    buf[1024];
99
100         capab = bp;
101         if ((file = getenv("TERMCAP")) != (char *) NULL) {
102                 if (*file != '/' &&
103                     (cp = getenv("TERM")) != NULL && strcmp(name, cp) == 0) {
104                         (void) strcpy(bp, file);
105                         return(1);
106                 }
107                 else file = "/etc/termcap";
108         } else
109                 file = "/etc/termcap";
110         if ((fp = fopen(file, "r")) == (FILE *) NULL)
111                 return(-1); 
112         while (fgets(buf, 1024, fp) != NULL) {
113                 if (buf[0] == '#') continue;
114                 while (*(cp = &buf[strlen(buf) - 2]) == '\\')
115                         if (fgets(cp, 1024, fp) == NULL)
116                                 return (0);
117                 if (match_name(buf, name)) {
118                         strcpy(bp, buf);
119                         fclose(fp);
120                         return(check_for_tc());
121                 }
122         }
123         fclose(fp);
124         return(0);
125 }
126
127 /*
128  *      Compare the terminal name with each termcap entry name; Return 1 if a
129  *      match is found.
130  */
131 static int
132 match_name(buf, name)
133         char    *buf;
134         char    *name;
135 {
136         register char   *tp = buf;
137         register char   *np;
138
139         for (;;) {
140                 for (np = name; *np && *tp == *np; np++, tp++) { }
141                 if (*np == 0 && (*tp == '|' || *tp == ':' || *tp == 0))
142                         return(1);
143                 while (*tp != 0 && *tp != '|' && *tp != ':') tp++;
144                 if (*tp++ != '|') return (0);
145         }
146 }
147
148 /*
149  *      Handle tc= definitions recursively.
150  */
151 static int
152 check_for_tc()
153 {
154         static int      count = 0;
155         char            *savcapab = capab;
156         char            buf[1024];
157         char            terminalname[128];
158         register char   *p = capab + strlen(capab) - 2, *q;
159
160         while (*p != ':')
161                 if (--p < capab)
162                         return(0);      /* no : in termcap entry */
163         if (p[1] != 't' || p[2] != 'c')
164                 return(1);
165         if (count > 16) return(0);      /* recursion in tc= definitions */
166         count++;
167         strcpy(terminalname, &p[4]);
168         q = terminalname;
169         while (*q && *q != ':') q++;
170         *q = 0;
171         if (tgetent(buf, terminalname) != 1) {
172                 --count;
173                 return(0);
174         }
175         --count;
176         for (q = buf; *q && *q != ':'; q++) { }
177         strcpy(p, q);
178         capab = savcapab;
179         return(1);
180 }
181
182 /*
183  *      tgetnum - get the numeric terminal capability corresponding
184  *      to id. Returns the value, -1 if invalid.
185  */
186 int
187 tgetnum(id)
188 char    *id;
189 {
190         char    *cp;
191         int     ret;
192
193         if ((cp = capab) == NULL || id == NULL)
194                 return(-1);
195         while (*++cp != ':')
196                 ;
197         while (*cp) {
198                 cp++;
199                 while (ISSPACE(*cp))
200                         cp++;
201                 if (strncmp(cp, id, CAPABLEN) == 0) {
202                         while (*cp && *cp != ':' && *cp != '#')
203                                 cp++;
204                         if (*cp != '#')
205                                 return(-1);
206                         for (ret = 0, cp++ ; *cp && ISDIGIT(*cp) ; cp++)
207                                 ret = ret * 10 + *cp - '0';
208                         return(ret);
209                 }
210                 while (*cp && *cp != ':')
211                         cp++;
212         }
213         return(-1);
214 }
215
216 /*
217  *      tgetflag - get the boolean flag corresponding to id. Returns -1
218  *      if invalid, 0 if the flag is not in termcap entry, or 1 if it is
219  *      present.
220  */
221 int
222 tgetflag(id)
223 char    *id;
224 {
225         char    *cp;
226
227         if ((cp = capab) == NULL || id == NULL)
228                 return(-1);
229         while (*++cp != ':')
230                 ;
231         while (*cp) {
232                 cp++;
233                 while (ISSPACE(*cp))
234                         cp++;
235                 if (strncmp(cp, id, CAPABLEN) == 0)
236                         return(1);
237                 while (*cp && *cp != ':')
238                         cp++;
239         }
240         return(0);
241 }
242
243 /*
244  *      tgetstr - get the string capability corresponding to id and place
245  *      it in area (advancing area at same time). Expand escape sequences
246  *      etc. Returns the string, or NULL if it can't do it.
247  */
248 char *
249 tgetstr(id, area)
250 char    *id;
251 char    **area;
252 {
253         char    *cp;
254         char    *ret;
255         int     i;
256
257         if ((cp = capab) == NULL || id == NULL)
258                 return(NULL);
259         while (*++cp != ':')
260                 ;
261         while (*cp) {
262                 cp++;
263                 while (ISSPACE(*cp))
264                         cp++;
265                 if (strncmp(cp, id, CAPABLEN) == 0) {
266                         while (*cp && *cp != ':' && *cp != '=')
267                                 cp++;
268                         if (*cp != '=')
269                                 return(NULL);
270                         for (ret = *area, cp++; *cp && *cp != ':' ; (*area)++, cp++)
271                                 switch(*cp) {
272                                 case '^' :
273                                         **area = *++cp - 'A' + 1;
274                                         break;
275                                 case '\\' :
276                                         switch(*++cp) {
277                                         case 'E' :
278                                                 **area = '\033';
279                                                 break;
280                                         case 'n' :
281                                                 **area = '\n';
282                                                 break;
283                                         case 'r' :
284                                                 **area = '\r';
285                                                 break;
286                                         case 't' :
287                                                 **area = '\t';
288                                                 break;
289                                         case 'b' :
290                                                 **area = '\b';
291                                                 break;
292                                         case 'f' :
293                                                 **area = '\f';
294                                                 break;
295                                         case '0' :
296                                         case '1' :
297                                         case '2' :
298                                         case '3' :
299                                                 for (i=0 ; *cp && ISDIGIT(*cp) ; cp++)
300                                                         i = i * 8 + *cp - '0';
301                                                 **area = i;
302                                                 cp--;
303                                                 break;
304                                         case '^' :
305                                         case '\\' :
306                                                 **area = *cp;
307                                                 break;
308                                         }
309                                         break;
310                                 default :
311                                         **area = *cp;
312                                 }
313                         *(*area)++ = '\0';
314                         return(ret);
315                 }
316                 while (*cp && *cp != ':')
317                         cp++;
318         }
319         return(NULL);
320 }
321
322 /*
323  *      tgoto - given the cursor motion string cm, make up the string
324  *      for the cursor to go to (destcol, destline), and return the string.
325  *      Returns "OOPS" if something's gone wrong, or the string otherwise.
326  */
327 char *
328 tgoto(cm, destcol, destline)
329 char    *cm;
330 int     destcol;
331 int     destline;
332 {
333         register char   *rp;
334         static char     ret[24];
335         char            added[16];
336         int             *dp = &destline;
337         int             numval;
338         int             swapped = 0;
339
340         added[0] = 0;
341         for (rp = ret ; *cm ; cm++) {
342                 if (*cm == '%') {
343                         switch(*++cm) {
344                         case '>' :
345                                 if (dp == NULL)
346                                         return("OOPS");
347                                 cm++;
348                                 if (*dp > *cm++) {
349                                         *dp += *cm;
350                                 }
351                                 break;
352                         case '+' :
353                         case '.' :
354                                 if (dp == NULL)
355                                         return("OOPS");
356                                 if (*cm == '+') *dp = *dp + *++cm;
357                                 for (;;) {
358                                     switch(*dp) {
359                                     case 0:
360                                     case 04:
361                                     case '\t':
362                                     case '\n':
363                                         /* filter these out */
364                                         if (dp == &destcol || swapped || UP) {
365                                                 strcat(added, dp == &destcol || swapped ?
366                                                         (BC ? BC : "\b") :
367                                                         UP);
368                                                 (*dp)++;
369                                                 continue;
370                                         }
371                                     }
372                                     break;
373                                 }
374                                 *rp++ = *dp;
375                                 dp = (dp == &destline) ? &destcol : NULL;
376                                 break;
377
378                         case 'r' : {
379                                 int tmp = destline;
380
381                                 destline = destcol;
382                                 destcol = tmp;
383                                 swapped = 1 - swapped;
384                                 break;
385                         }
386                         case 'n' :
387                                 destcol ^= 0140;
388                                 destline ^= 0140;
389                                 break;
390
391                         case '%' :
392                                 *rp++ = '%';
393                                 break;
394
395                         case 'i' :
396                                 destcol++;
397                                 destline++;
398                                 break;
399
400                         case 'B' :
401                                 if (dp == NULL)
402                                         return("OOPS");
403                                 *dp = 16 * (*dp / 10) + *dp % 10;
404                                 break;
405
406                         case 'D' :
407                                 if (dp == NULL)
408                                         return("OOPS");
409                                 *dp = *dp - 2 * (*dp % 16);
410                                 break;
411
412                         case 'd' :
413                         case '2' :
414                         case '3' :
415                                 if (dp == NULL)
416                                         return("OOPS");
417                                 numval = *dp;
418                                 dp = (dp == &destline) ? &destcol : NULL;
419                                 if (numval >= 100) {
420                                         *rp++ = '0' + numval / 100;
421                                 }
422                                 else if (*cm == '3') {
423                                         *rp++ = ' ';
424                                 }
425                                 if (numval >= 10) {
426                                         *rp++ = '0' + ((numval%100)/10);
427                                 }
428                                 else if (*cm == '3' || *cm == '2') {
429                                         *rp++ = ' ';
430                                 }
431                                 *rp++ = '0' + (numval%10);
432                                 break;
433                         default :
434                                 return("OOPS");
435                         }
436                 }
437                 else *rp++ = *cm;
438         }
439         *rp = '\0';
440         strcpy(rp, added);
441         return(ret);
442 }
443
444 static int tens_of_ms_p_char[] = {      /* index as returned by gtty */
445                                         /* assume 10 bits per char */
446         0, 2000, 1333, 909, 743, 666, 500, 333, 166, 83, 55, 41, 20, 10, 5, 2
447 };
448 /*
449  *      tputs - put the string cp out onto the terminal, using the function
450  *      outc. Also handle padding.
451  */
452 int
453 tputs(cp, affcnt, outc)
454 register char   *cp;
455 int             affcnt;
456 int             (*outc)();
457 {
458         int delay = 0;
459         if (cp == NULL)
460                 return(1);
461         while (ISDIGIT(*cp)) {
462                 delay = delay * 10 + (*cp++ - '0');
463         }
464         delay *= 10;
465         if (*cp == '.') {
466                 cp++;
467                 if (ISDIGIT(*cp)) {
468                         delay += *cp++ - '0';
469                 }
470                 while (ISDIGIT(*cp)) cp++;
471         }
472         if (*cp == '*') {
473                 delay *= affcnt;
474                 cp++;
475         }
476         while (*cp)
477                 (*outc)(*cp++);
478         if (delay != 0 &&
479             ospeed > 0 &&
480             ospeed < (sizeof tens_of_ms_p_char / sizeof tens_of_ms_p_char[0])) {
481                 delay = (delay + tens_of_ms_p_char[ospeed] - 1) / 
482                                   tens_of_ms_p_char[ospeed];
483                 while (delay--) (*outc)(PC);
484         }
485         return(1);
486 }
487
488 /*
489  *      That's all, folks...
490  */
491 getopt.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0o\ 4/* $Id: getopt.c,v 1.2 1994/06/24 12:20:37 ceriel Exp $ */
492 #include        <stdio.h>
493 #define ERR(s, c)       if(opterr){\
494         fputs(argv[0], stderr);\
495         fputs(s, stderr);\
496         fputc(c, stderr);\
497         fputc('\n', stderr);}
498
499 int     opterr = 1;
500 int     optind = 1;
501 int     optopt;
502 char    *optarg;
503 char    *index();
504
505 int
506 getopt (argc, argv, opts)
507 char **argv, *opts;
508 {
509         static int sp = 1;
510         register c;
511         register char *cp;
512
513         if (sp == 1)
514                 if (optind >= argc ||
515                    argv[optind][0] != '-' || argv[optind][1] == '\0')
516                         return EOF;
517                 else if (strcmp(argv[optind], "--") == NULL) {
518                         optind++;
519                         return EOF;
520                 }
521         optopt = c = argv[optind][sp];
522         if (c == ':' || (cp=index(opts, c)) == NULL) {
523                 ERR (": illegal option -- ", c);
524                 if (argv[optind][++sp] == '\0') {
525                         optind++;
526                         sp = 1;
527                 }
528                 return '?';
529         }
530         if (*++cp == ':') {
531                 if (argv[optind][sp+1] != '\0')
532                         optarg = &argv[optind++][sp+1];
533                 else if (++optind >= argc) {
534                         ERR (": option requires an argument -- ", c);
535                         sp = 1;
536                         return '?';
537                 } else
538                         optarg = argv[optind++];
539                 sp = 1;
540         } else {
541                 if (argv[optind][++sp] == '\0') {
542                         sp = 1;
543                         optind++;
544                 }
545                 optarg = NULL;
546         }
547         return c;
548 }
549 {clearerr.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\07\ 1/* $Id: clearerr.c,v 1.4 1994/06/24 12:19:25 ceriel Exp $ */
550
551 /*
552  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
553  * See the copyright notice in the ACK home directory, in the file "Copyright".
554  */
555
556 #include <stdio.h>
557
558 clearerr(iop)
559         FILE *iop;
560 {
561         iop->_flags &= ~(IO_ERR|IO_EOF);
562 }
563 afgetc.c\0.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\7f\0/* $Id: fgetc.c,v 1.3 1994/06/24 12:19:46 ceriel Exp $ */
564 #include <stdio.h>
565
566 fgetc(f)
567         register FILE *f;
568 {
569         return getc(f);
570 }
571 efgets.c\0.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0i\ 1/* $Id: fgets.c,v 1.3 1994/06/24 12:19:48 ceriel Exp $ */
572 #include <stdio.h>
573
574 char *fgets(str, n, file)
575 char *str;
576 unsigned n;
577 FILE *file;
578 {
579         register int ch;
580         register char *ptr;
581
582         ptr = str;
583         while ( --n > 0 && (ch = getc(file)) != EOF){
584                 *ptr++ = ch;
585                 if ( ch == '\n')
586                         break;
587         }
588         if (ch == EOF && ptr==str)
589                 return(NULL);
590         *ptr = '\0';
591         return(str);
592 }
593  fprintf.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0T\ 1/* $Id: fprintf.c,v 1.5 1994/06/24 12:20:04 ceriel Exp $ */
594 #include <stdio.h>
595 #include <varargs.h>
596
597 fprintf(va_alist)
598         va_dcl
599 {
600         va_list ap;
601
602         va_start(ap);
603         {
604                 FILE *file = va_arg(ap, FILE *);
605                 char *fmt = va_arg(ap, char *);
606
607                 _doprnt (fmt, ap, file);
608                 if ( io_testflag(file,IO_PERPRINTF) )
609                         fflush(file);
610         }
611         va_end(ap);
612 }
613 fputc.c\0c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\8b\0/* $Id: fputc.c,v 1.3 1994/06/24 12:20:07 ceriel Exp $ */
614 #include <stdio.h>
615
616 fputc(c, iop)
617         register FILE *iop;
618 {
619         return putc(c, iop);
620 }
621 pfputs.c\0c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0©\0/* $Id: fputs.c,v 1.3 1994/06/24 12:20:10 ceriel Exp $ */
622 #include <stdio.h>
623
624 fputs(s,file)
625 register char *s;
626 register FILE *file;
627 {
628         while ( *s ) 
629                 putc(*s++,file);
630 }
631 ffread.c\0c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\9a\ 1/* $Id: fread.c,v 1.3 1994/06/24 12:20:13 ceriel Exp $ */
632 #include <stdio.h>
633
634 fread(ptr, size, count, file)
635 register char *ptr;
636 unsigned size, count;
637 register FILE *file;
638 {
639         int c;
640         unsigned ndone = 0, s;
641
642         ndone = 0;
643         if (size)
644                 while ( ndone < count ) {
645                         s = size;
646                         do {
647                                 if ((c = getc(file)) != EOF)
648                                         *ptr++ = c;
649                                 else
650                                         return(ndone);
651                         } while (--s);
652                         ndone++;
653                 }
654         return(ndone);
655 }
656
657 freopen.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0ö\ 3/* $Id: freopen.c,v 1.9 1994/06/24 12:20:15 ceriel Exp $ */
658 #include <stdio.h>
659
660 #define  PMODE    0666
661
662
663 FILE *freopen(name,mode,fp)
664 char *name , *mode;
665 register FILE *fp;
666 {
667         int fd,
668         flags = fp->_flags & ~(IO_WRITEMODE|IO_READMODE|IO_ERR|IO_EOF|IO_PERPRINTF);
669
670         fflush(fp);
671         close(fileno(fp));
672
673         switch(*mode){
674
675         case 'w':
676                 flags |= IO_WRITEMODE;
677                 fd = creat (name,PMODE);
678                 break;
679
680         case 'a': 
681                 flags |= IO_WRITEMODE;
682                 if (( fd = open(name, 1)) < 0 )
683                         fd = creat(name, PMODE);
684                 if (fd >= 0) lseek(fd,0L,2);
685                 break;         
686
687         case 'r':
688                 flags |= IO_READMODE;   
689                 fd = open(name, 0);
690                 break;
691
692         default:
693                 fd = -1;
694         }
695
696         if (fd < 0) {
697                 register int i;
698
699                 for (i = 0; i < _NFILES; i++) {
700                         if (fp == _io_table[i]) {
701                                 _io_table[i] = 0;
702                                 break;
703                         }
704                 }
705                 if (fp != &_stdin && fp != &_stdout && fp != &_stderr) free(fp);
706                 return NULL;
707         }
708         fp->_count = 0;
709         if (fp->_buf && !(flags & IO_UNBUFF) && (flags & IO_WRITEMODE)) 
710                 fp->_count = fp->_bufsiz;
711         fp->_fd = fd;
712         fp->_flags = flags;
713         return(fp);
714 }
715 fscanf.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0A\ 1/* $Id: fscanf.c,v 1.5 1994/06/24 12:20:18 ceriel Exp $ */
716 #include <stdio.h>
717 #include <varargs.h>
718
719 int fscanf(va_alist)
720         va_dcl
721 {
722         va_list ap;
723         int retval;
724
725         va_start(ap);
726         {
727                 FILE *fp = va_arg(ap, FILE *);
728                 char *format = va_arg(ap, char *);
729
730                 retval = _doscanf (fp, format, ap);
731         }
732         va_end(ap);
733
734         return retval;
735 }
736
737 'ftell.c\0\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0Ï\ 1/* $Id: ftell.c,v 1.4 1994/06/24 12:20:25 ceriel Exp $ */
738 #include <stdio.h>
739
740
741 long ftell(iop)
742 FILE *iop;
743 {
744         long result;
745         long lseek();
746         int adjust = 0;
747
748         if ( io_testflag(iop,IO_READMODE) )
749                 adjust -= iop->_count;
750         else if ( io_testflag(iop,IO_WRITEMODE) && iop->_buf && !io_testflag(iop,IO_UNBUFF))
751                 adjust = iop->_ptr - iop->_buf;
752         
753         result = lseek(fileno(iop), 0L, 1);
754
755         if ( result < 0 )
756                 return ( result );
757
758         result += (long) adjust;
759         return(result);
760 }
761 =fwrite.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\88\ 1/* $Id: fwrite.c,v 1.3 1994/06/24 12:20:28 ceriel Exp $ */
762 #include <stdio.h>
763
764 fwrite(ptr, size, count, file)
765 unsigned size, count;
766 register char *ptr;
767 register FILE *file;
768 {
769         unsigned s;
770         unsigned ndone = 0;
771
772         if (size)
773                 while ( ndone < count ) {
774                         s = size;
775                         do {
776                                 putc(*ptr++, file);
777                                 if (ferror(file))
778                                         return(ndone);
779                         } 
780                         while (--s);
781                         ndone++;
782                 }
783         return(ndone);
784 }
785 getchar.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\83\0/* $Id: getchar.c,v 1.3 1994/06/24 12:20:31 ceriel Exp $ */
786 #include <stdio.h>
787
788 #undef getchar
789
790 getchar()
791 {
792         return getc(stdin);
793 }
794
795 getgrent.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0<\b/* $Id: getgrent.c,v 1.4 1994/06/24 12:20:34 ceriel Exp $ */
796 /*
797  * get entry from group file
798  * 
799  * By: Patrick van Kleef
800  */
801
802 #include <grp.h>
803
804 #define PRIVATE static
805
806 PRIVATE char _gr_file[] = "/etc/group";
807 PRIVATE char _grbuf[256];
808 PRIVATE char _buffer[1024];
809 PRIVATE char *_pnt;
810 PRIVATE char *_buf;
811 PRIVATE int  _gfd = -1;
812 PRIVATE int  _bufcnt;
813 PRIVATE struct group grp;
814
815 setgrent ()
816 {
817         if (_gfd >= 0)
818                 lseek (_gfd, 0L, 0);
819         else
820                 _gfd = open (_gr_file, 0);
821
822         _bufcnt = 0;
823         return (_gfd);
824 }
825
826
827 endgrent () 
828 {
829         if (_gfd >= 0)
830                 close (_gfd);
831
832         _gfd = -1;
833         _bufcnt = 0;
834 }
835
836
837 static getline () 
838 {
839         if (_gfd < 0 && setgrent () < 0)
840                 return (0);
841
842         _buf = _grbuf;
843         do {
844                 if (--_bufcnt <= 0){
845                         if ((_bufcnt = read (_gfd, _buffer, 1024)) <= 0)
846                                 return (0);
847                         else
848                                 _pnt = _buffer;
849                 }
850                 *_buf++ = *_pnt++;
851         } while (*_pnt != '\n');
852         _pnt++;
853         _bufcnt--;
854         *_buf = 0;
855         _buf = _grbuf;
856         return (1);
857 }
858
859 static skip_period () 
860 {
861         while (*_buf && *_buf != ':')
862                 _buf++;
863         *_buf++ = '\0';
864 }
865
866 struct group   *getgrent () 
867 {
868         if (getline () == 0)
869                return (0);
870
871         grp.gr_name = _buf;
872         skip_period ();
873         grp.gr_passwd = _buf;
874         skip_period ();
875         grp.gr_gid = atoi (_buf);
876         skip_period ();
877         return (&grp);
878 }
879
880 struct group   *getgrnam (name)
881 char   *name;
882 {
883         struct group *grp;
884
885         setgrent ();
886         while ((grp = getgrent ()) != 0)
887                 if (!strcmp (grp -> gr_name, name))
888                         break;
889         endgrent ();
890         if (grp != 0)
891                 return (grp);
892         else
893                 return (0);
894 }
895
896 struct group   *getgrgid (gid)
897 int     gid;
898 {
899         struct group   *grp;
900
901         setgrent ();
902         while ((grp = getgrent ()) != 0)
903                 if (grp -> gr_gid == gid)
904                         break;
905         endgrent ();
906         if (grp != 0)
907                 return (grp);
908         else
909                 return (0);
910 }
911 getpass.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\86\ 2/* $Id: getpass.c,v 1.4 1994/06/24 12:20:40 ceriel Exp $ */
912 #include <signal.h>
913 #include <sgtty.h>
914
915 char * getpass(prompt)
916 char *prompt;
917 {
918         int i = 0;
919         struct sgttyb tty, ttysave;
920         static char pwdbuf[9];
921         int fd;
922         void (*savesig)();
923
924         if ((fd = open("/dev/tty", 0)) < 0) fd = 0;
925         savesig = signal(SIGINT, SIG_IGN);
926         write(2, prompt, strlen(prompt));
927         gtty(fd, &tty);
928         ttysave = tty;
929         tty.sg_flags &= ~ECHO;
930         stty(fd, &tty);
931         i = read(fd, pwdbuf, 9);
932         while (pwdbuf[i - 1] != '\n')
933                 read(fd, &pwdbuf[i - 1], 1);
934         pwdbuf[i - 1] = '\0';
935         stty(fd, &ttysave);
936         write(2, "\n", 1);
937         if (fd != 0) close(fd);
938         signal(SIGINT, savesig);
939         return(pwdbuf);
940 }
941 getpw.c\0c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0|\ 2/* $Id: getpw.c,v 1.3 1994/06/24 12:20:43 ceriel Exp $ */
942 #include        <stdio.h>
943
944 getpw(uid, buf)
945         int uid;
946         char buf[];
947 {
948         register FILE *pwf;
949         register int ch, i;
950         register char *bp;
951
952         pwf = fopen("/etc/passwd", "r");
953         if (pwf == NULL) return(1);
954
955         for (;;) {
956                 bp = buf;
957                 while ((ch = getc(pwf)) != '\n') {
958                         if (ch == EOF) return 1;
959                         *bp++ = ch;
960                 }
961                 *bp++ = '\0';
962                 bp = buf;
963                 for (i = 2; i; i--) {
964                         while ((ch = *bp++) != ':') {
965                                 if(ch = '\0') return 1;
966                         }
967                 }
968                 i = 0;
969                 while ((ch = *bp++) != ':') {
970                         if (ch < '0' || ch > '9') return 1;
971                         i = i * 10 + (ch - '0');
972                 }
973                 if (i == uid) return(0);
974         }
975         /*NOTREACHED*/
976 }
977 fopen.c\0c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0r\ 3/* $Id: fopen.c,v 1.4 1994/06/24 12:20:01 ceriel Exp $ */
978 #include <stdio.h>
979
980 #define  PMODE    0666
981
982
983 FILE *fopen(name,mode)
984 char *name , *mode;
985 {
986         register int i;
987         FILE *fp;
988         char *malloc();
989         int fd,
990         flags = 0;
991
992         for (i = 0; _io_table[i] != 0 ; i++) 
993                 if ( i >= _NFILES )
994                         return(NULL);
995
996         switch(*mode){
997
998         case 'w':
999                 flags |= IO_WRITEMODE;
1000                 fd = creat (name,PMODE);
1001                 break;
1002
1003         case 'a': 
1004                 flags |= IO_WRITEMODE;
1005                 if (( fd = open(name, 1)) < 0 )
1006                         fd = creat(name, PMODE);
1007                 if (fd >= 0) lseek(fd,0L,2);
1008                 break;         
1009
1010         case 'r':
1011                 flags |= IO_READMODE;   
1012                 if (( fd = open (name, 0)) < 0 )
1013                         return(NULL);
1014                 break;
1015
1016         default:
1017                 return(NULL);
1018         }
1019
1020
1021         if (fd < 0) return NULL;
1022
1023         if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) {
1024                 close(fd);
1025                 return(NULL);
1026         }
1027
1028         fp->_count = 0;
1029         fp->_fd = fd;
1030         fp->_flags = flags;
1031         fp->_buf = 0;
1032         _io_table[i] = fp;
1033         return(fp);
1034 }
1035 getpwent.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\f\a/* $Id: getpwent.c,v 1.4 1994/06/24 12:20:46 ceriel Exp $ */
1036 /*
1037  * get entry from password file
1038  *
1039  * By Patrick van Kleef
1040  *
1041  */
1042
1043
1044 #include <pwd.h>
1045
1046 #define PRIVATE static
1047
1048
1049 PRIVATE char  _pw_file[] = "/etc/passwd";
1050 PRIVATE char  _pwbuf[256];
1051 PRIVATE char  _buffer[1024];
1052 PRIVATE char *_pnt;
1053 PRIVATE char *_buf;
1054 PRIVATE int   _pw = -1;
1055 PRIVATE int   _bufcnt;
1056 PRIVATE struct passwd    pwd;
1057
1058 setpwent() 
1059 {
1060         if (_pw >= 0)
1061                 lseek (_pw, 0L, 0);
1062         else
1063                 _pw = open (_pw_file, 0);
1064
1065         _bufcnt = 0;
1066         return (_pw);
1067 }
1068
1069
1070 endpwent () 
1071 {
1072         if (_pw >= 0)
1073                 close (_pw);
1074
1075         _pw = -1;
1076         _bufcnt = 0;
1077 }
1078
1079 static getline () 
1080 {
1081         if (_pw < 0 && setpwent () < 0)
1082                 return (0);
1083         _buf = _pwbuf;
1084         do {
1085                 if (--_bufcnt <= 0){
1086                         if ((_bufcnt = read (_pw, _buffer, 1024)) <= 0)
1087                                 return (0);
1088                         else
1089                                 _pnt = _buffer;
1090                 }
1091                 *_buf++ = *_pnt++;
1092         } while (*_pnt != '\n');
1093         _pnt++;
1094         _bufcnt--;
1095         *_buf = 0;
1096         _buf = _pwbuf;
1097         return (1);
1098 }
1099
1100 static skip_period () 
1101 {
1102         while (*_buf && *_buf != ':')
1103                 _buf++;
1104
1105         *_buf++ = '\0';
1106 }
1107
1108 struct passwd  *getpwent () 
1109 {
1110         if (getline () == 0)
1111                 return (0);
1112
1113         pwd.pw_name = _buf;
1114         skip_period ();
1115         pwd.pw_passwd = _buf;
1116         skip_period ();
1117         pwd.pw_uid = atoi (_buf);
1118         skip_period ();
1119         pwd.pw_gid = atoi (_buf);
1120         skip_period ();
1121         pwd.pw_gecos = _buf;
1122         skip_period ();
1123         pwd.pw_dir = _buf;
1124         skip_period ();
1125         pwd.pw_shell = _buf;
1126
1127         return (&pwd);
1128 }
1129
1130 struct passwd  *getpwnam (name)
1131 char   *name;
1132 {
1133         struct passwd  *pwd;
1134
1135         setpwent ();
1136         while ((pwd = getpwent ()) != 0)
1137                 if (!strcmp (pwd -> pw_name, name))
1138                         break;
1139         endpwent ();
1140         if (pwd != 0)
1141                 return (pwd);
1142         else
1143                 return (0);
1144 }
1145
1146 struct passwd  *getpwuid (uid)
1147 int     uid;
1148 {
1149         struct passwd  *pwd;
1150
1151         setpwent ();
1152         while ((pwd = getpwent ()) != 0)
1153                 if (pwd -> pw_uid == uid)
1154                         break;
1155         endpwent ();
1156         if (pwd != 0)
1157                 return (pwd);
1158         else
1159                 return (0);
1160 }
1161 gets.c\0t.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0)\ 1/* $Id: gets.c,v 1.3 1994/06/24 12:20:49 ceriel Exp $ */
1162 #include <stdio.h>
1163
1164 char *gets(str)
1165 char *str;
1166 {
1167         register int ch;
1168         register char *ptr;
1169
1170         ptr = str;
1171         while ((ch = getc(stdin)) != EOF && ch != '\n')
1172                 *ptr++ = ch;
1173
1174         if (ch == EOF && ptr==str)
1175                 return(NULL);
1176         *ptr = '\0';
1177         return(str);
1178 }
1179 Agetw.c\0t.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\1d\ 1/* $Id: getw.c,v 1.4 1994/06/24 12:20:52 ceriel Exp $ */
1180 #include <stdio.h>
1181
1182 int getw(iop)
1183         register FILE *iop;
1184 {
1185         register int cnt = sizeof(int);
1186         int w;
1187         register char *p = (char *) &w;
1188
1189         while (cnt--) {
1190                 *p++ = getc(iop);
1191         }
1192         if (feof(iop) || ferror(iop)) return EOF;
1193         return w;
1194 }
1195 upopen.c\0.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0=\ 4/* $Id: popen.c,v 1.4 1994/06/24 12:20:55 ceriel Exp $ */
1196 #include <stdio.h>
1197 #include <signal.h>
1198
1199 static int pids[20];
1200
1201 FILE *
1202 popen(command, type)
1203         char *command, *type;
1204 {
1205         int piped[2];
1206         int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2;
1207         int pid;
1208
1209         if (Xtype == 2 ||
1210             pipe(piped) < 0 ||
1211             (pid = fork()) < 0) return 0;
1212         
1213         if (pid == 0) {
1214                 /* child */
1215                 register int *p;
1216
1217                 for (p = pids; p < &pids[20]; p++) {
1218                         if (*p) close(p - pids);
1219                 }
1220                 close(piped[Xtype]);
1221                 dup2(piped[!Xtype], !Xtype);
1222                 close(piped[!Xtype]);
1223                 execl("/bin/sh", "sh", "-c", command, (char *) 0);
1224                 _exit(127);     /* like system() ??? */
1225         }
1226
1227         pids[piped[Xtype]] = pid;
1228         close(piped[!Xtype]);
1229         return fdopen(piped[Xtype], type);
1230 }
1231
1232 pclose(iop)
1233         FILE *iop;
1234 {
1235         int fd = fileno(iop);
1236         int status, wret;
1237         void (*intsave)() = signal(SIGINT, SIG_IGN);
1238         void (*quitsave)() = signal(SIGQUIT, SIG_IGN);
1239
1240         fclose(iop);
1241         while ((wret = wait(&status)) != -1) {
1242                 if (wret == pids[fd]) break;
1243         }
1244         if (wret == -1) status = -1;
1245         signal(SIGINT, intsave);
1246         signal(SIGQUIT, quitsave);
1247         pids[fd] = 0;
1248         return status;
1249 }
1250 sfdopen.c\0c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0t\ 2/* $Id: fdopen.c,v 1.4 1994/06/24 12:19:40 ceriel Exp $ */
1251 #include <stdio.h>
1252
1253 FILE *fdopen(fd,mode)
1254 char *mode;
1255 {
1256         register int i;
1257         FILE *fp;
1258         char *malloc();
1259         int flags = 0;
1260
1261         if (fd < 0) return NULL;
1262         for (i = 0; _io_table[i] != 0 ; i++) 
1263                 if ( i >= _NFILES )
1264                         return(NULL);
1265
1266         switch(*mode) {
1267         case 'r':
1268                 flags |= IO_READMODE;
1269                 break;
1270         case 'a':
1271                 lseek(fd, 0L, 2);
1272         case 'w':
1273                 flags |= IO_WRITEMODE;
1274                 break;
1275         default:
1276                 return NULL;
1277         }
1278
1279         if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) {
1280                 return(NULL);
1281         }
1282
1283         fp->_count = 0;
1284         fp->_fd = fd;
1285         fp->_flags = flags;
1286         fp->_buf = 0;
1287         _io_table[i] = fp;
1288         return(fp);
1289 }
1290 printf.c\0c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\05\ 1/* $Id: printf.c,v 1.6 1994/06/24 12:20:58 ceriel Exp $ */
1291 #include <stdio.h>
1292 #include <varargs.h>
1293
1294 printf(va_alist)
1295         va_dcl
1296 {
1297         va_list ap;
1298
1299         va_start(ap);
1300         {
1301                 char *fmt = va_arg(ap, char *);
1302
1303                 _doprnt (fmt, ap, stdout);
1304                 if ( io_testflag(stdout,IO_PERPRINTF) )
1305                         fflush(stdout);
1306         }
1307         va_end(ap);
1308 }
1309
1310 putchar.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\88\0/* $Id: putchar.c,v 1.3 1994/06/24 12:21:00 ceriel Exp $ */
1311 #include <stdio.h>
1312
1313 #undef putchar
1314
1315 putchar(c)
1316 {
1317         return putc(c, stdout);
1318 }
1319 puts.c\0.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0¿\0/* $Id: puts.c,v 1.3 1994/06/24 12:21:03 ceriel Exp $ */
1320 #include <stdio.h>
1321
1322 puts(s)
1323 register char *s;
1324 {
1325         register FILE *file = stdout;
1326         while ( *s ) 
1327                 putc(*s++,file);
1328         putc('\n', file);
1329 }
1330 ;putw.c\0.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0
1331 \ 1/* $Id: putw.c,v 1.3 1994/06/24 12:21:06 ceriel Exp $ */
1332 #include <stdio.h>
1333
1334 int
1335 putw(w, iop)
1336         register FILE *iop;
1337 {
1338         register int cnt = sizeof(int);
1339         register char *p = (char *) &w;
1340
1341         while (cnt--) {
1342                 putc(*p++, iop);
1343         }
1344         if (ferror(iop)) return EOF;
1345         return w;
1346 }
1347 rewind.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\86\0/* $Id: rewind.c,v 1.3 1994/06/24 12:21:09 ceriel Exp $ */
1348 #include <stdio.h>
1349
1350 rewind(iop)
1351         FILE *iop;
1352 {
1353         return fseek(iop, 0L, 0);
1354 }
1355 fseek.c\0\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0h\ 3/* $Id: fseek.c,v 1.3 1994/06/24 12:20:22 ceriel Exp $ */
1356 #include <stdio.h>
1357
1358
1359 fseek(iop, offset, where)
1360 FILE *iop;
1361 long offset;
1362 {
1363         int  count;
1364         long lseek();
1365         long pos;
1366
1367         iop->_flags &= ~(IO_EOF | IO_ERR);
1368         /* Clear both the end of file and error flags */
1369
1370         if ( io_testflag(iop,IO_READMODE) ) {
1371                 if ( where < 2 && iop->_buf && !io_testflag(iop,IO_UNBUFF) ) {
1372                         count = iop->_count;
1373                         pos = offset;
1374
1375                         if ( where == 0 )
1376                                 pos += count - lseek(fileno(iop), 0L,1);
1377                         else
1378                                 offset -= count;
1379
1380                         if ( count > 0 && pos <= count 
1381                              && pos >= iop->_buf - iop->_ptr ) {
1382                                 iop->_ptr += (int) pos;
1383                                 iop->_count -= (int) pos;
1384                                 return(0);
1385                         }
1386                 }
1387                 pos = lseek(fileno(iop), offset, where);
1388                 iop->_count = 0;
1389         } else if ( io_testflag(iop,IO_WRITEMODE) ) {
1390                 fflush(iop);
1391                 pos = lseek(fileno(iop), offset, where);
1392         }
1393         return((pos == -1) ? -1 : 0 );
1394 }
1395 scanf.c\0\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0"\ 1/* $Id: scanf.c,v 1.5 1994/06/24 12:21:12 ceriel Exp $ */
1396 #include <stdio.h>
1397 #include <varargs.h>
1398
1399 int scanf(va_alist)
1400         va_dcl
1401 {
1402         va_list ap;
1403         int retval;
1404
1405         va_start(ap);
1406         {
1407                 char *format = va_arg(ap, char *);
1408
1409                 retval = _doscanf (stdin, format, ap);
1410         }
1411         va_end(ap);
1412
1413         return retval;
1414 }
1415
1416
1417 setbuf.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\ 5\ 2/* $Id: setbuf.c,v 1.5 1994/06/24 12:21:15 ceriel Exp $ */
1418 #include        <stdio.h>
1419
1420 setbuf(iop, buffer)
1421 register FILE *iop;
1422 char *buffer;
1423 {
1424         if ( iop->_buf && io_testflag(iop,IO_MYBUF) )
1425                 free(iop->_buf);
1426
1427         iop->_flags &= ~(IO_MYBUF | IO_UNBUFF | IO_PERPRINTF);
1428
1429         iop->_buf = (unsigned char *) buffer;
1430
1431         iop->_count = 0;
1432         if ( iop->_buf == NULL ) {
1433                 iop->_flags |= IO_UNBUFF;
1434                 iop->_bufsiz = 1;
1435         } else {
1436                 if (io_testflag(iop, IO_WRITEMODE)) iop->_count = BUFSIZ;
1437                 iop->_bufsiz = BUFSIZ;
1438         }
1439         iop->_ptr = iop->_buf;
1440 }
1441  sprintf.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0A\ 2/* $Id: sprintf.c,v 1.6 1994/06/24 12:21:18 ceriel Exp $ */
1442 #include <stdio.h>
1443 #include <varargs.h>
1444
1445 char *sprintf(va_alist)
1446         va_dcl
1447 {
1448         va_list ap;
1449         char *retval;
1450
1451         va_start(ap);
1452         {
1453                 char *buf = va_arg(ap, char *);
1454                 char *format = va_arg(ap, char *);
1455                 FILE _tempfile;
1456
1457                 retval = buf;
1458                 _tempfile._fd     = -1;
1459                 _tempfile._flags  = IO_WRITEMODE + IO_UNBUFF;
1460                 _tempfile._buf    = (unsigned char *) buf;
1461                 _tempfile._ptr    = (unsigned char *) buf;
1462                 _tempfile._count  = 32767;
1463
1464                 _doprnt(format, ap, &_tempfile);
1465                 putc('\0',&_tempfile);
1466         }
1467         va_end(ap);
1468
1469         return retval;
1470 }
1471 {doprnt.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0¸\10/* $Id: doprnt.c,v 1.11 1994/06/24 12:19:31 ceriel Exp $ */
1472 #include <stdio.h>
1473 #include <varargs.h>
1474
1475 #ifndef NOFLOAT
1476 extern char     *_pfloat();
1477 extern char     *_pscien();
1478 extern char     *gcvt();
1479 #endif
1480
1481 # define wsize(par) ( (sizeof par) / sizeof (int) )
1482
1483
1484 static char *gnum(f,ip,app) register char *f; int *ip; va_list *app; {
1485         register int    i,c;
1486
1487         if (*f == '*') {
1488                 *ip = va_arg((*app), int);
1489                 f++;
1490         } else {
1491                 i = 0;
1492                 while ((c = *f - '0') >= 0 && c <= 9) {
1493                         i = i*10 + c;
1494                         f++;
1495                 }
1496                 *ip = i;
1497         }
1498         return(f);
1499 }
1500
1501 #define signbit(par) (1L<<(sizeof par*8 -1))
1502
1503 static char *i_compute(val,base,s) unsigned val; char *s; {
1504         int c;
1505
1506         c= val % base ;
1507         val/= base ;
1508         if (val)
1509                 s = i_compute(val,base,s);
1510         *s++ = (c>9 ? c-10+'a' : c+'0');
1511         return(s);
1512 }
1513
1514 #ifndef NOLONG
1515 static char *l_compute(l1,d,s) long l1; char *s; {
1516         int c;
1517         long l2;
1518
1519         if ( l1<0 ) {
1520                 /* assumption: d is a multiple of 2 */
1521                 c= l1&1 ;
1522                 l2= ( (l1>>1) & ~signbit(l1) );
1523                 l1= l2/(d>>1) ;
1524                 c += (l2%(d>>1))<<1 ;
1525         } else {
1526                 c= l1 % d ;
1527                 l1= l1 / d ;
1528         }
1529         if (l1)
1530                 s = l_compute(l1,d,s);
1531         *s++ = (c>9 ? c-10+'a' : c+'0');
1532         return(s);
1533 }
1534 #endif
1535
1536 _doprnt(fmt,ap,stream)
1537         register char *fmt; va_list ap ; FILE *stream;
1538 {
1539         register char   *s;
1540 #ifndef NOLONG
1541         long            l;
1542         int             lflag ;
1543 #else
1544 #define lflag 0
1545 #endif
1546 #ifndef NOFLOAT
1547         double          dbl ;
1548         int             capitalE = 0;
1549 #endif
1550         int             inte ;
1551         unsigned int    uint ;
1552         register int    j ;
1553         int             i,c,rjust,width,ndigit,ndfnd,zfill;
1554         char            *oldfmt,*s1,buf[1025];
1555
1556         while (c = *fmt++) {
1557                 if (c != '%') {
1558 #ifdef  CPM
1559                         if (c == '\n') putc('\r',stream);
1560 #endif
1561                         putc(c,stream);
1562                         continue;
1563                 }
1564 #ifndef NOLONG
1565                 lflag = 0 ;
1566 #endif
1567                 j = 10 ;
1568                 rjust = 0;
1569                 if (*fmt == '-') {
1570                         fmt++;
1571                         rjust++;
1572                 }
1573                 zfill = ' ';
1574                 if (*fmt == '0') {
1575                         fmt++;
1576                         zfill = '0';
1577                 }
1578                 fmt = gnum(fmt,&width,&ap);
1579                 ndigit = 0; ndfnd = 0;
1580                 if (*fmt == '.') {
1581                         fmt++; oldfmt = fmt;
1582                         fmt = gnum(fmt,&ndigit,&ap);
1583                         ndfnd = (fmt != oldfmt);
1584                 }
1585                 s = s1 = buf;
1586 #ifndef NOLONG
1587                 if ( *fmt == 'l' || *fmt == 'L' ) {
1588                         fmt++ ; lflag++ ;
1589                 }
1590 #endif
1591                 switch (c = *fmt++) {
1592                 default:
1593 #ifdef  CPM
1594                         if (c == '\n') putc('\r',stream);
1595 #endif
1596                         putc(c,stream);
1597                         continue;
1598                 case 's':
1599                         s1 = va_arg(ap, char *);
1600                         if (s1 == 0)
1601                                 s1 = "(null)";
1602                         s = s1;
1603                         do {
1604                                 if (*s == 0)
1605                                         break;
1606                                 s++;
1607                         } while (--ndigit);
1608                         break;
1609                 case 'b':
1610                         j = 2;
1611                 case 'u':
1612                 getu:
1613                         if ( !lflag ) {
1614                                 inte = va_arg(ap, int);
1615                                 goto i_unsignd ;
1616                         }
1617 #ifndef NOLONG
1618                 case 'U':
1619                 getlu:
1620                         l = va_arg(ap, long);
1621                         goto l_unsignd ;
1622                 case 'B':
1623                         j = 2 ;
1624                         goto getlu ;
1625                 case 'X':
1626                         j = 16;
1627                         goto getlu ;
1628                 case 'O':
1629                         j = 8;
1630                         goto getlu ;
1631                 case 'D':
1632                     l_signed:
1633                         l = va_arg(ap, long);
1634                         if (l < 0) {
1635                                 *s++ = '-';
1636                                 l = -l;
1637                         }
1638                     l_unsignd:
1639                         s = l_compute(l,j,s);
1640                         break;
1641 #endif
1642
1643                 case 'x':
1644                         j = 16;
1645                         goto getu ;
1646                 case 'o':
1647                         j = 8;
1648                         goto getu ;
1649                 case 'd':
1650                         if ( lflag ) goto l_signed; ;
1651                         inte = va_arg(ap, int);
1652                         if ( inte<0 ) {
1653                                 *s++ = '-';
1654                                 inte= -inte ;
1655                         }
1656                     i_unsignd:
1657                         s = i_compute(inte,j,s);
1658                         break;
1659                 case 'c':
1660                         uint = va_arg(ap, unsigned int);
1661                         for ( i= sizeof uint -1  ; i>=0 ; i-- ) {
1662                                 if ( *s = uint%256 ) s++;
1663                                 uint/= 256 ;
1664                         }
1665                         break;
1666 #ifndef NOFLOAT
1667                 case 'E':
1668                         capitalE = 1;
1669                         /* fall through */
1670                 case 'e':
1671                         if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
1672                         dbl = va_arg(ap, double);
1673                         s = _pscien(dbl,s,ndigit,ndfnd);
1674                         break;
1675                 case 'f':
1676                         if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
1677                         dbl = va_arg(ap, double);
1678                         s = _pfloat(dbl,s,ndigit,ndfnd);
1679                         break;
1680                 case 'G':
1681                         capitalE = 1;
1682                         /* fall through */
1683                 case 'g':
1684                         if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
1685                         dbl = va_arg(ap, double);
1686                         s = gcvt(dbl, ndigit ? ndigit : 6, s) + strlen(s);
1687                         break;
1688 #endif
1689                 case 'r':
1690                         ap = va_arg(ap, va_list);
1691                         fmt = va_arg(ap, char *);
1692                         continue;
1693                 }
1694 #ifndef NOFLOAT
1695                 if (capitalE) {
1696                         register char *p = buf;
1697                         capitalE=0;
1698                         while (*p && *p != 'e') p++;
1699                         if (*p == 'e') *p = 'E';
1700                 }
1701 #endif
1702                 j = s - s1;
1703                 if ((c = width - j) > 0)
1704                         if (rjust == 0)
1705                                 do putc(zfill,stream);
1706                                 while (--c);
1707                 while (--j >= 0)
1708                         putc(*s1++,stream);
1709                 while (--c >= 0)
1710                         putc(zfill,stream);
1711         }
1712 }
1713 fltpr.c\0\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0#\ 4/* $Id: fltpr.c,v 1.6 1994/06/24 12:19:55 ceriel Exp $ */
1714 #ifndef NOFLOAT
1715 extern char     *fcvt();
1716 extern char     *ecvt();
1717
1718 char *
1719 _pfloat(r,s,n,b)
1720         double r;
1721         register char *s;
1722 {
1723         register char *s1;
1724         int sign,dp;
1725         register int i;
1726
1727         if (b == 0)
1728                 n = 6;
1729         s1 = fcvt(r,n,&dp,&sign);
1730         if (sign)
1731                 *s++ = '-';
1732         if (dp<=0)
1733                 *s++ = '0';
1734         for (i=dp; i>0; i--)
1735                 if (*s1) *s++ = *s1++;
1736                 else *s++ = '0';
1737         if ((i=n) > 0)
1738                 *s++ = '.';
1739         while (++dp <= 0) {
1740                 if (--i<0)
1741                         break;
1742                 *s++ = '0';
1743         }
1744         while (--i >= 0)
1745                 if (*s1) *s++ = *s1++;
1746                 else *s++ = '0';
1747         return(s);
1748 }
1749
1750 char *_pscien(r,s,n,b) float r; register char *s; {
1751         int sign,dp; 
1752         register char *s1;
1753
1754         if (b == 0)
1755                 n = 7;
1756         else    n += 1;
1757         s1 = ecvt(r,n,&dp,&sign);
1758         if (sign)
1759                 *s++ = '-';
1760         *s++ = *s1++;
1761         *s++ = '.';
1762         while (--n>0)
1763                 if (*s1) *s++ = *s1++;
1764                 else *s++ = '0';
1765         *s++ = 'e';
1766         if ( r ) --dp ;
1767         if ( dp<0 ) {
1768                 *s++ = '-' ; dp= -dp ;
1769         } else {
1770                 *s++ = '+' ;
1771         }
1772         if (dp >= 100) {
1773                 *s++ = '0' + (dp / 100);
1774                 dp %= 100;
1775         }
1776         *s++ = '0' + (dp/10);
1777         *s++ = '0' + (dp%10);
1778         return(s);
1779 }
1780 #endif
1781 ,flushbuf.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\9b\ 4/* $Id: flushbuf.c,v 1.6 1994/06/24 12:19:58 ceriel Exp $ */
1782 #include <stdio.h>
1783
1784 int
1785 _flushbuf(c, iop)
1786         register FILE *iop;
1787 {
1788         if (fileno(iop) < 0) return EOF;
1789         if (! io_testflag(iop, IO_UNBUFF)) {
1790                 if (iop->_buf == 0) {
1791                         if (iop == stdout && isatty(fileno(stdout))) {
1792                                 iop->_flags |= IO_UNBUFF;
1793                         }
1794                         else {
1795                                 extern char *malloc();
1796         
1797                                 if (!(iop->_buf = (unsigned char *) malloc(_BUFSIZ))) {
1798                                         iop->_flags |= IO_UNBUFF;
1799                                 }
1800                                 else {
1801                                         iop->_flags |= IO_MYBUF;
1802                                         iop->_bufsiz = _BUFSIZ;
1803                                         iop->_count = _BUFSIZ-1;
1804                                 }
1805                         }
1806                         iop->_ptr = iop->_buf;
1807                 }
1808         }
1809
1810         if (io_testflag(iop, IO_UNBUFF)) {
1811                 char c1 = c;
1812
1813                 iop->_count = 0;
1814                 if (write(fileno(iop), &c1, 1) != 1) {
1815                         iop->_flags |= IO_ERR;
1816                         return EOF;
1817                 }
1818                 return c;
1819         }
1820         else {
1821                 int count = iop->_ptr - iop->_buf;
1822
1823                 iop->_count = iop->_bufsiz - 1;
1824                 iop->_ptr = iop->_buf + 1;
1825
1826                 if (count > 0) {
1827                         if (write(fileno(iop), iop->_buf, count) != count) {
1828                                 *(iop->_buf) = c;
1829                                 iop->_flags |= IO_ERR;
1830                                 return EOF;
1831                         }
1832                 }
1833                 *(iop->_buf) = c;
1834         }
1835         return c;
1836 }
1837
1838 _cleanup()
1839 {
1840         register int i;
1841
1842         for ( i = 0 ; i < _NFILES ; i++ )
1843                 if ( _io_table[i] != NULL )
1844                         fclose(_io_table[i]);
1845 }
1846 Ffclose.c\0c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0ª\ 1/* $Id: fclose.c,v 1.4 1994/06/24 12:19:37 ceriel Exp $ */
1847 #include <stdio.h>
1848
1849 fclose(fp)
1850 FILE *fp;
1851 {
1852         register int i;
1853
1854         for (i=0; i<_NFILES; i++)
1855                 if (fp == _io_table[i]) {
1856                         _io_table[i] = 0;
1857                         break;
1858                 }
1859         if (i >= _NFILES)
1860                 return(EOF);
1861         fflush(fp);
1862         close(fileno(fp));
1863         if ( io_testflag(fp,IO_MYBUF) && fp->_buf )
1864                 free( fp->_buf );
1865         if (fp != &_stdin && fp != &_stdout && fp != &_stderr) free(fp);
1866         return(NULL);
1867 }
1868
1869 data.c\0c\0c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0[\ 1/* $Id: data.c,v 1.6 1994/06/24 12:19:28 ceriel Exp $ */
1870 #include <stdio.h>
1871
1872 struct _io_buf _stdin = {
1873         0, IO_READMODE , 0, 0, 0, 0
1874 };
1875
1876 struct _io_buf _stdout = {
1877         0, IO_WRITEMODE, 0, 0, 0, 1
1878 };
1879
1880 struct _io_buf _stderr = {
1881         0, IO_WRITEMODE + IO_UNBUFF, 0, 0, 0, 2
1882 };
1883
1884 struct  _io_buf  *_io_table[_NFILES] = {
1885         &_stdin,
1886         &_stdout,
1887         &_stderr,
1888         0
1889 };
1890 ffflush.c\0c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0à\ 1/* $Id: fflush.c,v 1.5 1994/06/24 12:19:43 ceriel Exp $ */
1891 #include <stdio.h>
1892
1893
1894 fflush(iop)
1895 FILE *iop;
1896 {
1897         int count, c1;
1898
1899         if (!iop->_buf ||
1900             io_testflag(iop,IO_UNBUFF) ||
1901             !io_testflag(iop,IO_WRITEMODE) ) 
1902                 return(0);
1903
1904         count = iop->_bufsiz - iop->_count;
1905         if ( count <= 0 )
1906                 return(0);
1907
1908         c1 = write(iop->_fd,iop->_buf,count);
1909
1910         if ( count == c1 ) {
1911                 iop->_count = iop->_bufsiz;
1912                 iop->_ptr   = iop->_buf;
1913                 return(count);
1914         }
1915
1916         iop->_flags |= IO_ERR;
1917         return(EOF); 
1918 }
1919 sscanf.c\0c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0.\ 2/* $Id: sscanf.c,v 1.6 1994/06/24 12:21:21 ceriel Exp $ */
1920 #include <stdio.h>
1921 #include <varargs.h>
1922
1923 int sscanf(va_alist)
1924         va_dcl
1925 {
1926         va_list ap;
1927         int retval;
1928
1929         va_start(ap);
1930         {
1931                 char *string = va_arg(ap, char *);
1932                 char *format = va_arg(ap, char *);
1933                 FILE _tempfile;
1934
1935                 _tempfile._fd     = -1;
1936                 _tempfile._flags  = IO_READMODE + IO_UNBUFF;
1937                 _tempfile._buf    = (unsigned char *) string;
1938                 _tempfile._ptr    = (unsigned char *) string;
1939                 _tempfile._count  = strlen(string);
1940
1941                 retval = _doscanf (&_tempfile, format, ap);
1942         }
1943         va_end(ap);
1944
1945         return retval;
1946 }
1947 doscan.c\0c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0e\17/* $Id: doscan.c,v 1.9 1995/09/25 08:09:55 ceriel Exp $ */
1948 #include <stdio.h>
1949 #include <ctype.h>
1950 #include <varargs.h>
1951
1952 union ptr_union {
1953         char           *chr_p;
1954         unsigned short *ushort_p;
1955         unsigned int   *uint_p;
1956         unsigned long  *ulong_p;
1957 #ifndef NOFLOAT
1958         float           *float_p;
1959         double          *double_p;
1960 #endif
1961 };
1962
1963 static char     Xtable[128];
1964
1965 /*
1966  * the routine that does the job 
1967  */
1968
1969 _doscanf (iop, format, ap)
1970 register FILE   *iop;
1971 char           *format;         /* the format control string */
1972 va_list ap;
1973 {
1974         int             done = 0;       /* number of items done */
1975         int             base;           /* conversion base */
1976         long            val;            /* an integer value */
1977         int             sign;           /* sign flag */
1978         int             do_assign;      /* assignment suppression flag */
1979         unsigned        width;          /* width of field */
1980         int             widflag;        /* width was specified */
1981         int             longflag;       /* true if long */
1982         int             shortflag;      /* true if short */
1983         int             done_some;      /* true if we have seen some data */
1984         int             reverse;        /* reverse the checking in [...] */
1985         int             kind;
1986         register int    ic;
1987 #ifndef NOFLOAT
1988         extern double   atof();
1989         int             dotseen;
1990         int             expseen;
1991         char            buffer[128];
1992 #endif
1993
1994         ic = getc(iop);
1995         if (ic == EOF) {
1996                 done = EOF;
1997                 goto quit;
1998         }
1999
2000         while (1) {
2001                 if (isspace(*format)) {
2002                         while (isspace (*format))
2003                                 ++format;       /* skip whitespace */
2004                         while (isspace (ic)) ic = getc(iop);
2005                 }
2006                 if (!*format)
2007                         goto all_done;  /* end of format */
2008                 if (ic < 0)
2009                         goto quit;      /* seen an error */
2010                 if (*format != '%') {
2011                         if (ic != *format)
2012                                 goto all_done;
2013                         ++format;
2014                         ic = getc(iop);
2015                         continue;
2016                 }
2017                 ++format;
2018                 do_assign = 1;
2019                 if (*format == '*') {
2020                         ++format;
2021                         do_assign = 0;
2022                 }
2023                 if (isdigit (*format)) {
2024                         widflag = 1;
2025                         for (width = 0; isdigit (*format);)
2026                                 width = width * 10 + *format++ - '0';
2027                 } else
2028                         widflag = 0;    /* no width spec */
2029                 if (longflag = (*format == 'L' || *format == 'l'))
2030                         ++format;
2031                 else if (shortflag = (*format == 'H' || *format == 'h'))
2032                         ++format;
2033                 if (isupper(*format)) {
2034                         kind = tolower(*format);
2035                         longflag = 1;
2036                 }
2037                 else    kind = *format;
2038                 if (kind != 'c' && kind != '[')
2039                         while (isspace (ic))
2040                                 ic = getc(iop);
2041                 done_some = 0;  /* nothing yet */
2042                 switch (kind) {
2043                 case 'o':
2044                         base = 8;
2045                         goto decimal;
2046                 case 'u':
2047                 case 'd':
2048                         base = 10;
2049                         goto decimal;
2050                 case 'x':
2051                         base = 16;
2052                         if (((!widflag) || width >= 2) && ic == '0') {
2053                                 ic = getc(iop);
2054                                 if (tolower (ic) == 'x') {
2055                                         width -= 2;
2056                                         done_some = 1;
2057                                         ic = getc(iop);
2058                                 } else {
2059                                         ungetc(ic, iop);
2060                                         ic = '0';
2061                                 }
2062                         }
2063         decimal:
2064                         val = 0L;       /* our result value */
2065                         sign = 0;       /* assume positive */
2066                         if (!widflag)
2067                                 width = 0xffff; /* very wide */
2068                         if (width && ic == '+')
2069                                 ic = getc(iop);
2070                         else if (width && ic == '-') {
2071                                 sign = 1;
2072                                 ic = getc(iop);
2073                         }
2074                         while (width--) {
2075                                 if (isdigit (ic) && ic - '0' < base)
2076                                         ic -= '0';
2077                                 else if (base == 16 && tolower (ic) >= 'a' && tolower (ic) <= 'f')
2078                                         ic = 10 + tolower (ic) - 'a';
2079                                 else
2080                                         break;
2081                                 val = val * base + ic;
2082                                 ic = getc(iop);
2083                                 done_some = 1;
2084                         }
2085                         if (do_assign) {
2086                                 if (sign)
2087                                         val = -val;
2088                                 if (longflag)
2089                                         *va_arg(ap, unsigned long *) = (unsigned long) val;
2090                                 else if (shortflag)
2091                                         *va_arg(ap, unsigned short *) = (unsigned short) val;
2092                                 else
2093                                         *va_arg(ap, unsigned *) = (unsigned) val;
2094                         }
2095                         if (done_some) {
2096                                 if (do_assign) ++done;
2097                         }
2098                         else
2099                                 goto all_done;
2100                         break;
2101                 case 'c':
2102                         if (!widflag)
2103                                 width = 1;
2104                         { register char *p;
2105                           if (do_assign)
2106                                 p = va_arg(ap, char *);
2107                           while (width-- && ic >= 0) {
2108                                 if (do_assign)
2109                                         *p++ = (char) ic;
2110                                 ic = getc(iop);
2111                                 done_some = 1;
2112                           }
2113                         }
2114                         if (do_assign) {
2115                                 if (done_some)
2116                                         ++done;
2117                         }
2118                         break;
2119                 case 's':
2120                         if (!widflag)
2121                                 width = 0xffff;
2122                         { register char *p;
2123                           if (do_assign)
2124                                 p = va_arg(ap, char *);
2125                           while (width-- && !isspace (ic) && ic > 0) {
2126                                 if (do_assign)
2127                                         *p++ = (char) ic;
2128                                 ic = getc(iop);
2129                                 done_some = 1;
2130                           }
2131                           if (do_assign)        /* terminate the string */
2132                                 *p = '\0';      
2133                         }
2134                         if (done_some) {
2135                                 if (do_assign)
2136                                         ++done;
2137                         }
2138                         else
2139                                 goto all_done;
2140                         break;
2141                 case '[':
2142                         if (!widflag)
2143                                 width = 0xffff;
2144
2145                         if ( *(++format) == '^' ) {
2146                                 reverse = 1;
2147                                 format++;
2148                         } else
2149                                 reverse = 0;
2150                         
2151                         { register char *c;
2152                           for (c = Xtable; c < &Xtable[128]; c++) *c = 0;
2153                         }
2154                         while (*format && *format != ']') {
2155                                 Xtable[*format++] = 1;
2156                         }
2157                         if (!*format)
2158                                 goto quit;
2159                         
2160                         { register char *p;
2161                           if (do_assign)
2162                                 p = va_arg(ap, char *);
2163                           while (width-- && ic > 0 &&
2164                                 (Xtable[ic] ^ reverse)) {
2165                                 if (do_assign)
2166                                         *p++ = (char) ic;
2167                                 ic = getc(iop);
2168                                 done_some = 1;
2169                           }
2170                           if (do_assign)        /* terminate the string */
2171                                 *p = '\0';      
2172                         }
2173                         if (done_some) {
2174                                 if (do_assign)
2175                                         ++done;
2176                         }
2177                         else
2178                                 goto all_done;
2179                         break;
2180 #ifndef NOFLOAT:
2181                 case 'e':
2182                 case 'f': {
2183                         register char *c = buffer;
2184
2185                         if (!widflag) width = 127;
2186                         if (width >= 128) width = 127;
2187                         if (width && (ic == '+' || ic == '-')) {
2188                                 *c++ = ic;
2189                                 width--;
2190                                 ic = getc(iop);
2191                         }
2192                         while (isdigit(ic) && width) {
2193                                 width--;
2194                                 *c++ = ic;
2195                                 ic = getc(iop);
2196                         }
2197                         if (ic == '.' && width) {
2198                                 width--;
2199                                 *c++ = ic;
2200                                 ic = getc(iop);
2201                         }
2202                         while (isdigit(ic) && width) {
2203                                 width--;
2204                                 *c++ = ic;
2205                                 ic = getc(iop);
2206                         }
2207                         if (width && (ic == 'e' || ic == 'E')) {
2208                                 width--;
2209                                 *c++ = ic;
2210                                 ic = getc(iop);
2211                                 if (width && (ic == '+' || ic == '-')) {
2212                                         width--;
2213                                         *c++ = ic;
2214                                         ic = getc(iop);
2215                                 }
2216                         }
2217                         while (isdigit(ic) && width) {
2218                                 width--;
2219                                 *c++ = ic;
2220                                 ic = getc(iop);
2221                         }
2222                         if (c == buffer) goto all_done;
2223                         *c = 0;
2224
2225                         if (do_assign) {
2226                                 done++;
2227                                 if (longflag)
2228                                         *va_arg(ap, double *) = atof(buffer);
2229                                 else
2230                                         *va_arg(ap, float *) = atof(buffer);
2231                         }
2232                         }
2233                         break;
2234 #endif
2235                 }               /* end switch */
2236                 ++format;
2237         }
2238 all_done:
2239         if (ic >= 0)
2240                 ungetc(ic, iop);
2241 quit:
2242         return done;
2243 }
2244         fillbuf.c\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\82\ 3/* $Id: fillbuf.c,v 1.6 1994/06/24 12:19:52 ceriel Exp $ */
2245 #include <stdio.h>
2246
2247 char *malloc();
2248
2249 _fillbuf(iop)
2250 register FILE *iop;
2251 {
2252         static unsigned char ch[_NFILES];
2253
2254         iop->_count = 0;
2255         if (fileno(iop) < 0) return EOF;
2256         if ( io_testflag(iop, (IO_EOF | IO_ERR )))
2257                 return (EOF); 
2258
2259         if ( !io_testflag(iop, IO_READMODE) ) 
2260                 return (EOF);
2261
2262         if (! io_testflag(iop, IO_UNBUFF) && ! iop->_buf) {
2263                 iop->_buf = (unsigned char *) malloc(_BUFSIZ);
2264                 if (! iop->_buf) {
2265                         iop->_flags |= IO_UNBUFF;
2266                 }
2267                 else {
2268                         iop->_flags |= IO_MYBUF;
2269                         iop->_bufsiz = _BUFSIZ;
2270                 }
2271         }
2272         if (! iop->_buf) {
2273                 iop->_buf = &ch[fileno(iop)];
2274                 iop->_bufsiz = 1;
2275         }
2276         iop->_ptr = iop->_buf;
2277         iop->_count = read(iop->_fd, iop->_buf, iop->_bufsiz);
2278
2279         if (iop->_count <= 0){
2280                 if (iop->_count == 0) {
2281                         iop->_flags |= IO_EOF;
2282                 }
2283                 else 
2284                         iop->_flags |= IO_ERR;
2285
2286                 return (EOF);
2287         }
2288         iop->_count--;
2289
2290         return *iop->_ptr++;
2291 }
2292 system.c\0\0\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\19\ 3/* $Id: system.c,v 1.5 1994/06/24 12:21:24 ceriel Exp $ */
2293 #include <signal.h>
2294
2295 system(str)
2296         char *str;
2297 {
2298         int pid, exitstatus, waitval;
2299         void (*sigint)(), (*sigquit)();
2300         int i;
2301
2302         if ((pid = fork()) < 0) return -1;      /* How do we distinguish this
2303                                                    from exit status -1?
2304                                                 */
2305         if (pid == 0) {
2306                 for (i = 3; i <= 20; i++) close(i);
2307                 execl("/bin/sh", "sh", "-c", str, (char *) 0);
2308                 /* get here if execl fails ... */
2309                 _exit(127);     /* see manual page */
2310         }
2311
2312         sigint  = signal( SIGINT,  SIG_IGN );
2313         sigquit = signal( SIGQUIT, SIG_IGN );
2314
2315         while ((waitval = wait(&exitstatus)) != pid) {
2316                 if (waitval == -1) break;
2317         }
2318         if (waitval == -1) {
2319                 /* no child ??? or maybe interrupted ??? */
2320                 exitstatus = -1;
2321         }
2322
2323         signal( SIGINT,  sigint );
2324         signal( SIGQUIT, sigquit );
2325
2326         return exitstatus;
2327 }
2328 _timezone.c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\84\ 5/* $Id: timezone.c,v 1.4 1994/06/24 12:21:27 ceriel Exp $ */
2329 #ifndef __USG
2330 static struct zonetable {
2331         int     offset;
2332         char    *stdzone;
2333         char    *dstzone;
2334 } zonetable[] = {
2335         -3*60-30, "NST", 0,     /* new foundland ??? */
2336         -4*60, "AST", "ADT",    /* atlanic */
2337         -5*60, "EST", "EDT",    /* eastern */
2338         -6*60, "CST", "CDT",    /* central */
2339         -7*60, "MST", "MDT",    /* mountain */
2340         -8*60, "PST", "PDT",    /* pacific */
2341         -9*60, "YST", "YDT",    /* yukon */
2342         -10*60, "AST", "ADT",   /* aleutian */
2343         -10*60, "HST", "HDT",   /* hawai, never found */
2344         0, "GMT", 0,            /* Greenwich */
2345         0, "WET", "WDT",        /* west european, never found */
2346         1*60,"MET", "MDT",      /* middle european */
2347         2*60, "EET", "EDT",     /* east european */
2348         8*60, "WST", 0, /* west australia */
2349         9*60, "JST", 0, /* japan */
2350         9*60+30, "CST", 0,      /* also australia ??? */
2351         10*60, "EST", 0,        /* also australia ??? */
2352         -1                      
2353 };
2354
2355 char *
2356 timezone(zone, dst)
2357 {
2358         register struct zonetable *p = zonetable;
2359         static char buf[16];
2360         register char *c;
2361         int i;
2362
2363         while (p->offset != -1) {
2364                 if (zone == -p->offset) {
2365                         if (dst && p->dstzone) return p->dstzone;
2366                         if (!dst && p->stdzone) return p->stdzone;
2367                 }
2368                 p++;
2369         }
2370         *c++ = 'G';
2371         *c++ = 'M';
2372         *c++ = 'T';
2373         if (zone < 0) {
2374                 zone = - zone;
2375                 *c++ = '+';
2376         }
2377         else    *c++ = '-';
2378         i = (zone / 60) % 24;
2379         if (i >= 10) {
2380                 *c++ = i / 10 + '0';
2381         }
2382         *c++ = i % 10 + '0';
2383         i = zone % 60;
2384         *c++ = i / 10 + '0';
2385         *c++ = i % 10 + '0';
2386         *c = '\0';
2387         return buf;
2388 }
2389 #endif
2390 ungetc.c\0c\0\0\0\0\0\0\0\0\ 2\ 2¤\ 1\0\0\84\ 1/* $Id: ungetc.c,v 1.4 1994/06/24 12:21:31 ceriel Exp $ */
2391 #include <stdio.h>
2392
2393 ungetc(ch, iop)
2394 int ch;
2395 register FILE *iop;
2396 {
2397         unsigned char *p;
2398
2399         if ( ch < 0  || !io_testflag(iop,IO_READMODE))
2400                 return EOF;
2401         if (iop->_ptr == iop->_buf) {
2402                 if (iop->_count != 0) return EOF;
2403                 iop->_ptr++;
2404         }
2405         iop->_count++;
2406         p = --(iop->_ptr);      /* ??? Bloody vax assembler !!! */
2407         *p = ch;
2408         return(ch);
2409 }