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