1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2011 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Eclipse Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.eclipse.org/org/documents/epl-v10.html *
11 * (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24 * standalone mini ast+sfio implementation
25 */
26
27 #include <ast.h>
28
29 #define CHUNK 1024
30
31 _Ast_info_t ast;
32
33 int
astwinsize(int fd,int * lines,int * columns)34 astwinsize(int fd, int* lines, int* columns)
35 {
36 if (lines)
37 *lines = 24;
38 if (columns)
39 *columns = 80;
40 return 0;
41 }
42
43 char*
sfgetr(Sfio_t * sp,int c,int z)44 sfgetr(Sfio_t* sp, int c, int z)
45 {
46 register char* s;
47 register char* e;
48
49 static char* buf;
50 static unsigned long siz;
51
52 if (!buf)
53 {
54 siz = CHUNK;
55 if (!(buf = newof(0, char, siz, 0)))
56 return 0;
57 }
58 if (z < 0)
59 return *buf ? buf : (char*)0;
60 s = buf;
61 e = s + siz;
62 for (;;)
63 {
64 if (s >= e)
65 {
66 siz += CHUNK;
67 if (!(buf = newof(buf, char, siz, 0)))
68 return 0;
69 s = buf + (siz - CHUNK);
70 e = s + siz;
71 }
72 if ((c = sfgetc(sp)) == EOF)
73 {
74 *s = 0;
75 return 0;
76 }
77 if (c == '\n')
78 {
79 *s = z ? 0 : c;
80 break;
81 }
82 *s++ = c;
83 }
84 return buf;
85 }
86