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 $ */
7 vsprintf(s, format, arg)
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;
20 _doprnt(format, arg, &tmp_stream);
21 putc('\0',&tmp_stream);
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 $ */
31 vfprintf(stream, format, arg)
36 return _doprnt (format, arg, stream);
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 $ */
48 return _doprnt(format, arg, stdout);
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
53 * Copyright Joypace Ltd, London, UK, 1987. All rights reserved.
54 * This file may be freely distributed provided that this notice
57 * A public domain implementation of the termcap(3) routines.
59 * Made fully functional by Ceriel J.H. Jacobs.
62 * - does not check termcap entry sizes
69 #define ISSPACE(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
70 #define ISDIGIT(x) ((x) >= '0' && (x) <= '9')
72 short ospeed; /* output speed */
73 char PC; /* padding character */
74 char *BC; /* back cursor movement */
75 char *UP; /* up cursor movement */
77 static char *capab; /* the capability itself */
78 static int check_for_tc();
79 static int match_name();
81 extern char *getenv(); /* new, improved getenv */
82 extern FILE *fopen(); /* old fopen */
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.
97 short len = strlen(name);
101 if ((file = getenv("TERMCAP")) != (char *) NULL) {
103 (cp = getenv("TERM")) != NULL && strcmp(name, cp) == 0) {
104 (void) strcpy(bp, file);
107 else file = "/etc/termcap";
109 file = "/etc/termcap";
110 if ((fp = fopen(file, "r")) == (FILE *) NULL)
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)
117 if (match_name(buf, name)) {
120 return(check_for_tc());
128 * Compare the terminal name with each termcap entry name; Return 1 if a
132 match_name(buf, name)
136 register char *tp = buf;
140 for (np = name; *np && *tp == *np; np++, tp++) { }
141 if (*np == 0 && (*tp == '|' || *tp == ':' || *tp == 0))
143 while (*tp != 0 && *tp != '|' && *tp != ':') tp++;
144 if (*tp++ != '|') return (0);
149 * Handle tc= definitions recursively.
154 static int count = 0;
155 char *savcapab = capab;
157 char terminalname[128];
158 register char *p = capab + strlen(capab) - 2, *q;
162 return(0); /* no : in termcap entry */
163 if (p[1] != 't' || p[2] != 'c')
165 if (count > 16) return(0); /* recursion in tc= definitions */
167 strcpy(terminalname, &p[4]);
169 while (*q && *q != ':') q++;
171 if (tgetent(buf, terminalname) != 1) {
176 for (q = buf; *q && *q != ':'; q++) { }
183 * tgetnum - get the numeric terminal capability corresponding
184 * to id. Returns the value, -1 if invalid.
193 if ((cp = capab) == NULL || id == NULL)
201 if (strncmp(cp, id, CAPABLEN) == 0) {
202 while (*cp && *cp != ':' && *cp != '#')
206 for (ret = 0, cp++ ; *cp && ISDIGIT(*cp) ; cp++)
207 ret = ret * 10 + *cp - '0';
210 while (*cp && *cp != ':')
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
227 if ((cp = capab) == NULL || id == NULL)
235 if (strncmp(cp, id, CAPABLEN) == 0)
237 while (*cp && *cp != ':')
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.
257 if ((cp = capab) == NULL || id == NULL)
265 if (strncmp(cp, id, CAPABLEN) == 0) {
266 while (*cp && *cp != ':' && *cp != '=')
270 for (ret = *area, cp++; *cp && *cp != ':' ; (*area)++, cp++)
273 **area = *++cp - 'A' + 1;
299 for (i=0 ; *cp && ISDIGIT(*cp) ; cp++)
300 i = i * 8 + *cp - '0';
316 while (*cp && *cp != ':')
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.
328 tgoto(cm, destcol, destline)
341 for (rp = ret ; *cm ; cm++) {
356 if (*cm == '+') *dp = *dp + *++cm;
363 /* filter these out */
364 if (dp == &destcol || swapped || UP) {
365 strcat(added, dp == &destcol || swapped ?
375 dp = (dp == &destline) ? &destcol : NULL;
383 swapped = 1 - swapped;
403 *dp = 16 * (*dp / 10) + *dp % 10;
409 *dp = *dp - 2 * (*dp % 16);
418 dp = (dp == &destline) ? &destcol : NULL;
420 *rp++ = '0' + numval / 100;
422 else if (*cm == '3') {
426 *rp++ = '0' + ((numval%100)/10);
428 else if (*cm == '3' || *cm == '2') {
431 *rp++ = '0' + (numval%10);
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
449 * tputs - put the string cp out onto the terminal, using the function
450 * outc. Also handle padding.
453 tputs(cp, affcnt, outc)
461 while (ISDIGIT(*cp)) {
462 delay = delay * 10 + (*cp++ - '0');
468 delay += *cp++ - '0';
470 while (ISDIGIT(*cp)) cp++;
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);
489 * That's all, folks...
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 $ */
493 #define ERR(s, c) if(opterr){\
494 fputs(argv[0], stderr);\
497 fputc('\n', stderr);}
506 getopt (argc, argv, opts)
514 if (optind >= argc ||
515 argv[optind][0] != '-' || argv[optind][1] == '\0')
517 else if (strcmp(argv[optind], "--") == NULL) {
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') {
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);
538 optarg = argv[optind++];
541 if (argv[optind][++sp] == '\0') {
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 $ */
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".
561 iop->_flags &= ~(IO_ERR|IO_EOF);
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 $ */
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 $ */
574 char *fgets(str, n, file)
583 while ( --n > 0 && (ch = getc(file)) != EOF){
588 if (ch == EOF && ptr==str)
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 $ */
604 FILE *file = va_arg(ap, FILE *);
605 char *fmt = va_arg(ap, char *);
607 _doprnt (fmt, ap, file);
608 if ( io_testflag(file,IO_PERPRINTF) )
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 $ */
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 $ */
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 $ */
634 fread(ptr, size, count, file)
636 unsigned size, count;
640 unsigned ndone = 0, s;
644 while ( ndone < count ) {
647 if ((c = getc(file)) != EOF)
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 $ */
663 FILE *freopen(name,mode,fp)
668 flags = fp->_flags & ~(IO_WRITEMODE|IO_READMODE|IO_ERR|IO_EOF|IO_PERPRINTF);
676 flags |= IO_WRITEMODE;
677 fd = creat (name,PMODE);
681 flags |= IO_WRITEMODE;
682 if (( fd = open(name, 1)) < 0 )
683 fd = creat(name, PMODE);
684 if (fd >= 0) lseek(fd,0L,2);
688 flags |= IO_READMODE;
699 for (i = 0; i < _NFILES; i++) {
700 if (fp == _io_table[i]) {
705 if (fp != &_stdin && fp != &_stdout && fp != &_stderr) free(fp);
709 if (fp->_buf && !(flags & IO_UNBUFF) && (flags & IO_WRITEMODE))
710 fp->_count = fp->_bufsiz;
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 $ */
727 FILE *fp = va_arg(ap, FILE *);
728 char *format = va_arg(ap, char *);
730 retval = _doscanf (fp, format, ap);
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 $ */
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;
753 result = lseek(fileno(iop), 0L, 1);
758 result += (long) adjust;
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 $ */
764 fwrite(ptr, size, count, file)
765 unsigned size, count;
773 while ( ndone < count ) {
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 $ */
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 $ */
797 * get entry from group file
799 * By: Patrick van Kleef
804 #define PRIVATE static
806 PRIVATE char _gr_file[] = "/etc/group";
807 PRIVATE char _grbuf[256];
808 PRIVATE char _buffer[1024];
811 PRIVATE int _gfd = -1;
813 PRIVATE struct group grp;
820 _gfd = open (_gr_file, 0);
839 if (_gfd < 0 && setgrent () < 0)
845 if ((_bufcnt = read (_gfd, _buffer, 1024)) <= 0)
851 } while (*_pnt != '\n');
859 static skip_period ()
861 while (*_buf && *_buf != ':')
866 struct group *getgrent ()
873 grp.gr_passwd = _buf;
875 grp.gr_gid = atoi (_buf);
880 struct group *getgrnam (name)
886 while ((grp = getgrent ()) != 0)
887 if (!strcmp (grp -> gr_name, name))
896 struct group *getgrgid (gid)
902 while ((grp = getgrent ()) != 0)
903 if (grp -> gr_gid == gid)
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 $ */
915 char * getpass(prompt)
919 struct sgttyb tty, ttysave;
920 static char pwdbuf[9];
924 if ((fd = open("/dev/tty", 0)) < 0) fd = 0;
925 savesig = signal(SIGINT, SIG_IGN);
926 write(2, prompt, strlen(prompt));
929 tty.sg_flags &= ~ECHO;
931 i = read(fd, pwdbuf, 9);
932 while (pwdbuf[i - 1] != '\n')
933 read(fd, &pwdbuf[i - 1], 1);
934 pwdbuf[i - 1] = '\0';
937 if (fd != 0) close(fd);
938 signal(SIGINT, savesig);
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 $ */
952 pwf = fopen("/etc/passwd", "r");
953 if (pwf == NULL) return(1);
957 while ((ch = getc(pwf)) != '\n') {
958 if (ch == EOF) return 1;
963 for (i = 2; i; i--) {
964 while ((ch = *bp++) != ':') {
965 if(ch = '\0') return 1;
969 while ((ch = *bp++) != ':') {
970 if (ch < '0' || ch > '9') return 1;
971 i = i * 10 + (ch - '0');
973 if (i == uid) return(0);
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 $ */
983 FILE *fopen(name,mode)
992 for (i = 0; _io_table[i] != 0 ; i++)
999 flags |= IO_WRITEMODE;
1000 fd = creat (name,PMODE);
1004 flags |= IO_WRITEMODE;
1005 if (( fd = open(name, 1)) < 0 )
1006 fd = creat(name, PMODE);
1007 if (fd >= 0) lseek(fd,0L,2);
1011 flags |= IO_READMODE;
1012 if (( fd = open (name, 0)) < 0 )
1021 if (fd < 0) return NULL;
1023 if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) {
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 $ */
1037 * get entry from password file
1039 * By Patrick van Kleef
1046 #define PRIVATE static
1049 PRIVATE char _pw_file[] = "/etc/passwd";
1050 PRIVATE char _pwbuf[256];
1051 PRIVATE char _buffer[1024];
1054 PRIVATE int _pw = -1;
1055 PRIVATE int _bufcnt;
1056 PRIVATE struct passwd pwd;
1063 _pw = open (_pw_file, 0);
1081 if (_pw < 0 && setpwent () < 0)
1085 if (--_bufcnt <= 0){
1086 if ((_bufcnt = read (_pw, _buffer, 1024)) <= 0)
1092 } while (*_pnt != '\n');
1100 static skip_period ()
1102 while (*_buf && *_buf != ':')
1108 struct passwd *getpwent ()
1110 if (getline () == 0)
1115 pwd.pw_passwd = _buf;
1117 pwd.pw_uid = atoi (_buf);
1119 pwd.pw_gid = atoi (_buf);
1121 pwd.pw_gecos = _buf;
1125 pwd.pw_shell = _buf;
1130 struct passwd *getpwnam (name)
1136 while ((pwd = getpwent ()) != 0)
1137 if (!strcmp (pwd -> pw_name, name))
1146 struct passwd *getpwuid (uid)
1152 while ((pwd = getpwent ()) != 0)
1153 if (pwd -> pw_uid == uid)
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 $ */
1171 while ((ch = getc(stdin)) != EOF && ch != '\n')
1174 if (ch == EOF && ptr==str)
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 $ */
1185 register int cnt = sizeof(int);
1187 register char *p = (char *) &w;
1192 if (feof(iop) || ferror(iop)) return EOF;
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 $ */
1199 static int pids[20];
1202 popen(command, type)
1203 char *command, *type;
1206 int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2;
1211 (pid = fork()) < 0) return 0;
1217 for (p = pids; p < &pids[20]; p++) {
1218 if (*p) close(p - pids);
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() ??? */
1227 pids[piped[Xtype]] = pid;
1228 close(piped[!Xtype]);
1229 return fdopen(piped[Xtype], type);
1235 int fd = fileno(iop);
1237 void (*intsave)() = signal(SIGINT, SIG_IGN);
1238 void (*quitsave)() = signal(SIGQUIT, SIG_IGN);
1241 while ((wret = wait(&status)) != -1) {
1242 if (wret == pids[fd]) break;
1244 if (wret == -1) status = -1;
1245 signal(SIGINT, intsave);
1246 signal(SIGQUIT, quitsave);
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 $ */
1253 FILE *fdopen(fd,mode)
1261 if (fd < 0) return NULL;
1262 for (i = 0; _io_table[i] != 0 ; i++)
1268 flags |= IO_READMODE;
1273 flags |= IO_WRITEMODE;
1279 if (( fp = (FILE *) malloc (sizeof( FILE))) == NULL ) {
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 $ */
1292 #include <varargs.h>
1301 char *fmt = va_arg(ap, char *);
1303 _doprnt (fmt, ap, stdout);
1304 if ( io_testflag(stdout,IO_PERPRINTF) )
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 $ */
1317 return putc(c, stdout);
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 $ */
1325 register FILE *file = stdout;
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 $ */
1338 register int cnt = sizeof(int);
1339 register char *p = (char *) &w;
1344 if (ferror(iop)) return EOF;
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 $ */
1353 return fseek(iop, 0L, 0);
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 $ */
1359 fseek(iop, offset, where)
1367 iop->_flags &= ~(IO_EOF | IO_ERR);
1368 /* Clear both the end of file and error flags */
1370 if ( io_testflag(iop,IO_READMODE) ) {
1371 if ( where < 2 && iop->_buf && !io_testflag(iop,IO_UNBUFF) ) {
1372 count = iop->_count;
1376 pos += count - lseek(fileno(iop), 0L,1);
1380 if ( count > 0 && pos <= count
1381 && pos >= iop->_buf - iop->_ptr ) {
1382 iop->_ptr += (int) pos;
1383 iop->_count -= (int) pos;
1387 pos = lseek(fileno(iop), offset, where);
1389 } else if ( io_testflag(iop,IO_WRITEMODE) ) {
1391 pos = lseek(fileno(iop), offset, where);
1393 return((pos == -1) ? -1 : 0 );
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 $ */
1397 #include <varargs.h>
1407 char *format = va_arg(ap, char *);
1409 retval = _doscanf (stdin, format, ap);
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 $ */
1424 if ( iop->_buf && io_testflag(iop,IO_MYBUF) )
1427 iop->_flags &= ~(IO_MYBUF | IO_UNBUFF | IO_PERPRINTF);
1429 iop->_buf = (unsigned char *) buffer;
1432 if ( iop->_buf == NULL ) {
1433 iop->_flags |= IO_UNBUFF;
1436 if (io_testflag(iop, IO_WRITEMODE)) iop->_count = BUFSIZ;
1437 iop->_bufsiz = BUFSIZ;
1439 iop->_ptr = iop->_buf;
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 $ */
1443 #include <varargs.h>
1445 char *sprintf(va_alist)
1453 char *buf = va_arg(ap, char *);
1454 char *format = va_arg(ap, char *);
1459 _tempfile._flags = IO_WRITEMODE + IO_UNBUFF;
1460 _tempfile._buf = (unsigned char *) buf;
1461 _tempfile._ptr = (unsigned char *) buf;
1462 _tempfile._count = 32767;
1464 _doprnt(format, ap, &_tempfile);
1465 putc('\0',&_tempfile);
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 $ */
1473 #include <varargs.h>
1476 extern char *_pfloat();
1477 extern char *_pscien();
1478 extern char *gcvt();
1481 # define wsize(par) ( (sizeof par) / sizeof (int) )
1484 static char *gnum(f,ip,app) register char *f; int *ip; va_list *app; {
1488 *ip = va_arg((*app), int);
1492 while ((c = *f - '0') >= 0 && c <= 9) {
1501 #define signbit(par) (1L<<(sizeof par*8 -1))
1503 static char *i_compute(val,base,s) unsigned val; char *s; {
1509 s = i_compute(val,base,s);
1510 *s++ = (c>9 ? c-10+'a' : c+'0');
1515 static char *l_compute(l1,d,s) long l1; char *s; {
1520 /* assumption: d is a multiple of 2 */
1522 l2= ( (l1>>1) & ~signbit(l1) );
1524 c += (l2%(d>>1))<<1 ;
1530 s = l_compute(l1,d,s);
1531 *s++ = (c>9 ? c-10+'a' : c+'0');
1536 _doprnt(fmt,ap,stream)
1537 register char *fmt; va_list ap ; FILE *stream;
1553 int i,c,rjust,width,ndigit,ndfnd,zfill;
1554 char *oldfmt,*s1,buf[1025];
1556 while (c = *fmt++) {
1559 if (c == '\n') putc('\r',stream);
1578 fmt = gnum(fmt,&width,&ap);
1579 ndigit = 0; ndfnd = 0;
1581 fmt++; oldfmt = fmt;
1582 fmt = gnum(fmt,&ndigit,&ap);
1583 ndfnd = (fmt != oldfmt);
1587 if ( *fmt == 'l' || *fmt == 'L' ) {
1591 switch (c = *fmt++) {
1594 if (c == '\n') putc('\r',stream);
1599 s1 = va_arg(ap, char *);
1614 inte = va_arg(ap, int);
1620 l = va_arg(ap, long);
1633 l = va_arg(ap, long);
1639 s = l_compute(l,j,s);
1650 if ( lflag ) goto l_signed; ;
1651 inte = va_arg(ap, int);
1657 s = i_compute(inte,j,s);
1660 uint = va_arg(ap, unsigned int);
1661 for ( i= sizeof uint -1 ; i>=0 ; i-- ) {
1662 if ( *s = uint%256 ) s++;
1671 if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
1672 dbl = va_arg(ap, double);
1673 s = _pscien(dbl,s,ndigit,ndfnd);
1676 if (ndigit >= sizeof(buf)) ndigit = sizeof(buf) - 1;
1677 dbl = va_arg(ap, double);
1678 s = _pfloat(dbl,s,ndigit,ndfnd);
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);
1690 ap = va_arg(ap, va_list);
1691 fmt = va_arg(ap, char *);
1696 register char *p = buf;
1698 while (*p && *p != 'e') p++;
1699 if (*p == 'e') *p = 'E';
1703 if ((c = width - j) > 0)
1705 do putc(zfill,stream);
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 $ */
1715 extern char *fcvt();
1716 extern char *ecvt();
1729 s1 = fcvt(r,n,&dp,&sign);
1734 for (i=dp; i>0; i--)
1735 if (*s1) *s++ = *s1++;
1745 if (*s1) *s++ = *s1++;
1750 char *_pscien(r,s,n,b) float r; register char *s; {
1757 s1 = ecvt(r,n,&dp,&sign);
1763 if (*s1) *s++ = *s1++;
1768 *s++ = '-' ; dp= -dp ;
1773 *s++ = '0' + (dp / 100);
1776 *s++ = '0' + (dp/10);
1777 *s++ = '0' + (dp%10);
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 $ */
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;
1795 extern char *malloc();
1797 if (!(iop->_buf = (unsigned char *) malloc(_BUFSIZ))) {
1798 iop->_flags |= IO_UNBUFF;
1801 iop->_flags |= IO_MYBUF;
1802 iop->_bufsiz = _BUFSIZ;
1803 iop->_count = _BUFSIZ-1;
1806 iop->_ptr = iop->_buf;
1810 if (io_testflag(iop, IO_UNBUFF)) {
1814 if (write(fileno(iop), &c1, 1) != 1) {
1815 iop->_flags |= IO_ERR;
1821 int count = iop->_ptr - iop->_buf;
1823 iop->_count = iop->_bufsiz - 1;
1824 iop->_ptr = iop->_buf + 1;
1827 if (write(fileno(iop), iop->_buf, count) != count) {
1829 iop->_flags |= IO_ERR;
1842 for ( i = 0 ; i < _NFILES ; i++ )
1843 if ( _io_table[i] != NULL )
1844 fclose(_io_table[i]);
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 $ */
1854 for (i=0; i<_NFILES; i++)
1855 if (fp == _io_table[i]) {
1863 if ( io_testflag(fp,IO_MYBUF) && fp->_buf )
1865 if (fp != &_stdin && fp != &_stdout && fp != &_stderr) free(fp);
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 $ */
1872 struct _io_buf _stdin = {
1873 0, IO_READMODE , 0, 0, 0, 0
1876 struct _io_buf _stdout = {
1877 0, IO_WRITEMODE, 0, 0, 0, 1
1880 struct _io_buf _stderr = {
1881 0, IO_WRITEMODE + IO_UNBUFF, 0, 0, 0, 2
1884 struct _io_buf *_io_table[_NFILES] = {
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 $ */
1900 io_testflag(iop,IO_UNBUFF) ||
1901 !io_testflag(iop,IO_WRITEMODE) )
1904 count = iop->_bufsiz - iop->_count;
1908 c1 = write(iop->_fd,iop->_buf,count);
1910 if ( count == c1 ) {
1911 iop->_count = iop->_bufsiz;
1912 iop->_ptr = iop->_buf;
1916 iop->_flags |= IO_ERR;
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 $ */
1921 #include <varargs.h>
1923 int sscanf(va_alist)
1931 char *string = va_arg(ap, char *);
1932 char *format = va_arg(ap, char *);
1936 _tempfile._flags = IO_READMODE + IO_UNBUFF;
1937 _tempfile._buf = (unsigned char *) string;
1938 _tempfile._ptr = (unsigned char *) string;
1939 _tempfile._count = strlen(string);
1941 retval = _doscanf (&_tempfile, format, ap);
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 $ */
1950 #include <varargs.h>
1954 unsigned short *ushort_p;
1955 unsigned int *uint_p;
1956 unsigned long *ulong_p;
1963 static char Xtable[128];
1966 * the routine that does the job
1969 _doscanf (iop, format, ap)
1971 char *format; /* the format control string */
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 [...] */
1988 extern double atof();
2001 if (isspace(*format)) {
2002 while (isspace (*format))
2003 ++format; /* skip whitespace */
2004 while (isspace (ic)) ic = getc(iop);
2007 goto all_done; /* end of format */
2009 goto quit; /* seen an error */
2010 if (*format != '%') {
2019 if (*format == '*') {
2023 if (isdigit (*format)) {
2025 for (width = 0; isdigit (*format);)
2026 width = width * 10 + *format++ - '0';
2028 widflag = 0; /* no width spec */
2029 if (longflag = (*format == 'L' || *format == 'l'))
2031 else if (shortflag = (*format == 'H' || *format == 'h'))
2033 if (isupper(*format)) {
2034 kind = tolower(*format);
2037 else kind = *format;
2038 if (kind != 'c' && kind != '[')
2039 while (isspace (ic))
2041 done_some = 0; /* nothing yet */
2052 if (((!widflag) || width >= 2) && ic == '0') {
2054 if (tolower (ic) == 'x') {
2064 val = 0L; /* our result value */
2065 sign = 0; /* assume positive */
2067 width = 0xffff; /* very wide */
2068 if (width && ic == '+')
2070 else if (width && ic == '-') {
2075 if (isdigit (ic) && ic - '0' < base)
2077 else if (base == 16 && tolower (ic) >= 'a' && tolower (ic) <= 'f')
2078 ic = 10 + tolower (ic) - 'a';
2081 val = val * base + ic;
2089 *va_arg(ap, unsigned long *) = (unsigned long) val;
2091 *va_arg(ap, unsigned short *) = (unsigned short) val;
2093 *va_arg(ap, unsigned *) = (unsigned) val;
2096 if (do_assign) ++done;
2106 p = va_arg(ap, char *);
2107 while (width-- && ic >= 0) {
2124 p = va_arg(ap, char *);
2125 while (width-- && !isspace (ic) && ic > 0) {
2131 if (do_assign) /* terminate the string */
2145 if ( *(++format) == '^' ) {
2152 for (c = Xtable; c < &Xtable[128]; c++) *c = 0;
2154 while (*format && *format != ']') {
2155 Xtable[*format++] = 1;
2162 p = va_arg(ap, char *);
2163 while (width-- && ic > 0 &&
2164 (Xtable[ic] ^ reverse)) {
2170 if (do_assign) /* terminate the string */
2183 register char *c = buffer;
2185 if (!widflag) width = 127;
2186 if (width >= 128) width = 127;
2187 if (width && (ic == '+' || ic == '-')) {
2192 while (isdigit(ic) && width) {
2197 if (ic == '.' && width) {
2202 while (isdigit(ic) && width) {
2207 if (width && (ic == 'e' || ic == 'E')) {
2211 if (width && (ic == '+' || ic == '-')) {
2217 while (isdigit(ic) && width) {
2222 if (c == buffer) goto all_done;
2228 *va_arg(ap, double *) = atof(buffer);
2230 *va_arg(ap, float *) = atof(buffer);
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 $ */
2252 static unsigned char ch[_NFILES];
2255 if (fileno(iop) < 0) return EOF;
2256 if ( io_testflag(iop, (IO_EOF | IO_ERR )))
2259 if ( !io_testflag(iop, IO_READMODE) )
2262 if (! io_testflag(iop, IO_UNBUFF) && ! iop->_buf) {
2263 iop->_buf = (unsigned char *) malloc(_BUFSIZ);
2265 iop->_flags |= IO_UNBUFF;
2268 iop->_flags |= IO_MYBUF;
2269 iop->_bufsiz = _BUFSIZ;
2273 iop->_buf = &ch[fileno(iop)];
2276 iop->_ptr = iop->_buf;
2277 iop->_count = read(iop->_fd, iop->_buf, iop->_bufsiz);
2279 if (iop->_count <= 0){
2280 if (iop->_count == 0) {
2281 iop->_flags |= IO_EOF;
2284 iop->_flags |= IO_ERR;
2290 return *iop->_ptr++;
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 $ */
2298 int pid, exitstatus, waitval;
2299 void (*sigint)(), (*sigquit)();
2302 if ((pid = fork()) < 0) return -1; /* How do we distinguish this
2303 from exit status -1?
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 */
2312 sigint = signal( SIGINT, SIG_IGN );
2313 sigquit = signal( SIGQUIT, SIG_IGN );
2315 while ((waitval = wait(&exitstatus)) != pid) {
2316 if (waitval == -1) break;
2318 if (waitval == -1) {
2319 /* no child ??? or maybe interrupted ??? */
2323 signal( SIGINT, sigint );
2324 signal( SIGQUIT, sigquit );
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 $ */
2330 static struct 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 ??? */
2358 register struct zonetable *p = zonetable;
2359 static char buf[16];
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;
2378 i = (zone / 60) % 24;
2380 *c++ = i / 10 + '0';
2382 *c++ = i % 10 + '0';
2384 *c++ = i / 10 + '0';
2385 *c++ = i % 10 + '0';
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 $ */
2399 if ( ch < 0 || !io_testflag(iop,IO_READMODE))
2401 if (iop->_ptr == iop->_buf) {
2402 if (iop->_count != 0) return EOF;
2406 p = --(iop->_ptr); /* ??? Bloody vax assembler !!! */