Пример #1
0
static char*
getrec(register Sfio_t* sp, register int delimiter, register int flags)
{
	register int	c;
	register char*	glob;

	sfstrseek(sp, 0, SEEK_SET);
	glob = ed.global;
	while ((c = getchr()) != delimiter) {
		if (c == '\n') {
			ed.peekc = c;
			break;
		}
		if (c == EOF) {
			if (glob)
				ed.peekc = (flags & REC_LINE) ? 0 : c;
			else if (delimiter != '\n' || (flags & (REC_LINE|REC_SPLICE)))
				error(2, "unexpected EOF");
			else if (flags & REC_TEXT)
				return 0;
			break;
		}
		if (c == '\\' && ((c = getchr()) != delimiter || (flags & REC_SPLICE) && c != '\n') && c && !(flags & REC_IGNORE))
			sfputc(sp, '\\');
		if (!c)
			error(1, "null character ignored");
		else if (!(flags & REC_IGNORE))
			sfputc(sp, c);
	}
	if (flags & REC_TERMINATE)
		sfputc(sp, c);
	if (!(glob = sfstruse(sp)))
		error(ERROR_SYSTEM|3, "out of space");
	return glob;
}
Пример #2
0
static void
splice(void)
{
	char*	s;
	int	n;

	if (ed.spend) {
		if (!ed.spl && !(ed.spl = sfstropen()))
			error(ERROR_SYSTEM|3, "cannot initialize splice buffer");
		sfwrite(ed.spl, ed.spbeg, ed.spend - ed.spbeg);
		ed.spend = 0;
		sfputc(ed.spl, '\n');
		while (s = sfgetr(sfstdin, '\n', 1)) {
			if ((n = sfvalue(sfstdin) - 1) > 0 && s[n - 1] == '\r')
				n--;
			if (n > 0 && s[n - 1] == '\\') {
				sfwrite(ed.spl, s, n - 1);
				sfputc(ed.spl, '\n');
			}
			else {
				sfwrite(ed.spl, s, n);
				break;
			}
		}
		if (!(s = sfstruse(ed.spl)))
			error(ERROR_SYSTEM|3, "out of space");
		ed.input = s + (ed.input - ed.spbeg);
	}
}
Пример #3
0
void
coquote(register Sfio_t* sp, register const char* s, int type)
{
	register int	c;

	if (type && (!state.type || !*state.type))
		type = 0;
	while (c = *s++)
	{
		sfputc(sp, c);
		if (c == '\'')
		{
			sfputc(sp, '\\');
			sfputc(sp, '\'');
			sfputc(sp, '\'');
		}
		else if (type && c == '/' && *s == *state.type)
		{
			register const char*	x = s;
			register char*		t = state.type;

			while (*t && *t++ == *x) x++;
			if (!*t && *x == '/')
			{
				s = x;
				sfprintf(sp, "'$%s'", CO_ENV_TYPE);
			}
		}
	}
}
Пример #4
0
Файл: deparse.c Проект: att/ast
static_fn void p_arg(const struct argnod *arg, int endchar, int opts) {
    int flag = -1;

    do {
        if (!arg->argnxt.ap) {
            flag = endchar;
        } else if (opts & PRE) {  // case alternation lists in reverse order
            p_arg(arg->argnxt.ap, '|', opts);
            flag = endchar;
        } else if (opts) {
            flag = ' ';
        }
        const char *cp = arg->argval;
        if (*cp == 0 && (arg->argflag & ARG_EXP) && arg->argchn.ap) {
            int c = (arg->argflag & ARG_RAW) ? '>' : '<';
            sfputc(outfile, c);
            sfputc(outfile, '(');
            p_tree((Shnode_t *)arg->argchn.ap, 0);
            sfputc(outfile, ')');
        } else if (*cp == 0 && opts == POST && arg->argchn.ap) {  // compound assignment
            struct fornod *fp = (struct fornod *)arg->argchn.ap;
            sfprintf(outfile, "%s=(\n", fp->fornam);
            sfnputc(outfile, '\t', ++level);
            p_tree(fp->fortre, 0);
            if (--level) sfnputc(outfile, '\t', level);
            sfputc(outfile, ')');
        } else if ((arg->argflag & ARG_RAW) && (cp[1] || (*cp != '[' && *cp != ']'))) {
            cp = sh_fmtq(cp);
        }
        sfputr(outfile, cp, flag);
        if (flag == '\n') begin_line = 1;
        arg = arg->argnxt.ap;
    } while ((opts & POST) && arg);
}
Пример #5
0
/*
 * Handles paste -s, for file <in> to file <out> using delimiters <delim>
 */
static int spaste(Sfio_t *in,register Sfio_t* out,register const char *delim,int dsiz,int dlen,Delim_t* mp)
{
	register const char *cp;
	register int d=0;
	if((cp = sfgetr(in,'\n',0)) && sfwrite(out,cp,sfvalue(in)-1) < 0)
		return(-1);
	while(cp=sfgetr(in, '\n',0)) 
	{
		if(dlen)
		{
			register int c;
			if(d >= dlen)
				d = 0;
			if(mp)
				sfwrite(out,mp[d].chr,mp[d].len);
			else if(c=delim[d])
				sfputc(out,c);
			d++;
		}
		if(sfwrite(out,cp,sfvalue(in)-1) < 0)
			return(-1);
	}
	sfputc(out,'\n');
	return(0);
}
Пример #6
0
static int
post(Css_t* css, Cssdisc_t* disc, Connection_t* from, register Connection_t* to, int channel, const char* format, ...)
{
	State_t*		state = (State_t*)disc;
	char*			s;
	ssize_t			n;
	Sfulong_t		m;
	va_list			ap;

	sfprintf(state->tmp, "%d", channel);
	if (from)
		sfprintf(state->tmp, ".%d", from->fp->fd);
	sfputc(state->tmp, ' ');
	va_start(ap, format);
	sfvprintf(state->tmp, format, ap);
	va_end(ap);
	sfputc(state->tmp, '\n');
	n = sfstrtell(state->tmp);
	if (!(s = sfstruse(state->tmp)))
		error(ERROR_SYSTEM|3, "out of space");
	m = CHAN_MASK(channel);
	state->logged = 0;
	if (!to)
	{
		for (to = state->all; to; to = to->next)
			if ((to->mask & m) && to != from)
				note(css, to, state->log, s, n, 0, disc);
	}
	else if (to->mask & m)
		note(css, to, state->log, s, n, 0, disc);
	return 0;
}
Пример #7
0
static int paste(int nstream,Sfio_t* streams[],Sfio_t *out, register const char *delim, int dsiz, int dlen, Delim_t* mp)
{
	register const char *cp;
	register int d, n, i, z, more=1;
	register Sfio_t *fp;
	do
	{
		d = (dlen>0?0:-1);
		for(n=more-1,more=0; n < nstream;)
		{
			if(fp=streams[n])
			{
				if(cp = sfgetr(fp,'\n',0))
				{
					if(n==0)
						more = 1;
					else if(!more) /* first stream with output */
					{
						if(dsiz == 1)
							sfnputc(out, *delim, n);
						else if(dlen>0)
						{
							for(d=n; d>dlen; d-=dlen)
								sfwrite(out,delim,dsiz);
							if(d)
							{
								if(mp)
									for (i = z = 0; i < d; i++)
										z += mp[i].len;
								else
									z = d;
								sfwrite(out,delim,z);
							}
						}
						more = n+1;
					}
					if(sfwrite(out,cp,sfvalue(fp)-((n+1)<nstream)) < 0)
						return(-1);
				}
				else
					streams[n] = 0;
			}
			if(++n<nstream && more && d>=0)
			{
				register int c;
				if(d >= dlen)
					d = 0;
				if(mp)
					sfwrite(out,mp[d].chr,mp[d].len);
				else if(c=delim[d])
					sfputc(out,c);
				d++;
			}
			else if(n==nstream && !streams[n-1] && more)
				sfputc(out,'\n');
		}
	} while(more);
	return(0);
}
Пример #8
0
Файл: history.c Проект: att/ast
//
// This routine will cause the previous command to be cancelled.
//
void hist_cancel(History_t *hp) {
    int c;
    if (!hp) return;
    sfputc(hp->histfp, HIST_UNDO);
    sfputc(hp->histfp, 0);
    sfsync(hp->histfp);
    hp->histcnt += 2;
    c = hist_ind(hp, --hp->histind);
    hp->histcmds[c] = hp->histcnt;
}
Пример #9
0
static int
cc_options(Codexmeth_t* meth, Sfio_t* sp)
{
	register iconv_list_t*	ic;
	register const char*	p;
	register int		c;

	for (ic = iconv_list(NiL); ic; ic = iconv_list(ic))
	{
		sfputc(sp, '[');
		sfputc(sp, '+');
		sfputc(sp, '\b');
		p = ic->match;
		if (*p == '(')
			p++;
		while (c = *p++)
		{
			if (c == ')' && !*p)
				break;
			if (c == '?' || c == ']')
				sfputc(sp, c);
			sfputc(sp, c);
		}
		sfputc(sp, '?');
		p = ic->desc;
		while (c = *p++)
		{
			if (c == ']')
				sfputc(sp, c);
			sfputc(sp, c);
		}
		sfputc(sp, ']');
	}
	return 0;
}
Пример #10
0
int
pzheadprint(register Pz_t* pz, register Sfio_t* op, int parts)
{
	register Pzpart_t*	pp;
	char			t;

	if (pz->flags & PZ_FORCE)
		sfprintf(op, "# fixed record input\n");
	else
	{
		sfprintf(op, "# pzip %d.%d partition\n", pz->major, pz->minor);
		if (pz->disc->comment)
			sfprintf(op, "# %s\n", pz->disc->comment);
		sfprintf(op, "# window %I*u\n", sizeof(pz->win), pz->win);
		if (pz->prefix.count)
		{
			sfprintf(op, "\nprefix=%I*u", sizeof(pz->prefix.count), pz->prefix.count);
			if (pz->prefix.terminator >= 0)
			{
				t = pz->prefix.terminator;
				sfprintf(op, "*%s\n", fmtquote(&t, "'", "'", 1, FMT_ALWAYS));
			}
			else
				sfputc(op, '\n');
		}
		if (pz->headoptions || pz->det)
		{
			sfputc(op, '\n');
			if (pz->headoptions)
				sfputr(op, pz->headoptions, '\n');
			if (pz->det)
			{
				sfwrite(op, sfstrbase(pz->det), sfstrtell(pz->det));
				sfputc(op, '\n');
			}
		}
	}
	if (parts)
	{
		pp = pz->partdict ? (Pzpart_t*)dtfirst(pz->partdict) : pz->part;
		while (pp)
		{
			if (pzpartprint(pz, pp, op))
				return -1;
			if (!pz->partdict)
				break;
			pp = (Pzpart_t*)dtnext(pz->partdict, pp);
		}
	}
	return sferror(op) ? -1 : 0;
}
Пример #11
0
static char*
str_xor(Expr_t* ex, register char* l, register char* r)
{
	register int	c;
	register char*	s = l;

	while (c = *s++)
		if (!strchr(r, c) && !strchr(s, c))
			sfputc(ex->tmp, c);
	while (c = *r++)
		if (!strchr(l, c) && !strchr(r, c))
			sfputc(ex->tmp, c);
	return exstash(ex->tmp, ex->ve);
}
Пример #12
0
int huffputhdr(register Huff_t *hp,Sfio_t *outfile)
{
	register int		i, c;
	register Sfio_t	*fp = outfile;
	/* output magic number */
	sfputc(fp,HUFFMAG1);
	sfputc(fp,HUFFMAG2);
	if(sizeof(Sfoff_t)>4 && hp->insize >= ((Sfoff_t)1)<<(4*CHAR_BIT))
	{
		sfputc(fp,hp->insize>>(7*CHAR_BIT));
		sfputc(fp,hp->insize>>(6*CHAR_BIT));
		sfputc(fp,hp->insize>>(5*CHAR_BIT));
		sfputc(fp,hp->insize>>(4*CHAR_BIT));
		sfputc(fp,0);
	}
Пример #13
0
static int
tablewrite(Dssfile_t* file, Dssrecord_t* record, Dssdisc_t* disc)
{
	register Bgproute_t* rp	= (Bgproute_t*)record->data;

	switch (rp->attr & (BGP_best|BGP_damped|BGP_internal|BGP_suppressed|BGP_valid))
	{
	case BGP_best|BGP_valid:
	case BGP_internal|BGP_valid:
		break;
	default:
		return 0;
	}
	sfprintf(file->io, "%-16s ", fmtip4(rp->addr.v4, rp->bits));
	if (rp->hop.v4 < 256)
		sfprintf(file->io, "%-19u", rp->hop.v4);
	else
		sfprintf(file->io, "%-19s", fmtip4(rp->hop.v4, -1));
	if (sfputc(file->io, '\n') == EOF)
	{
		if (disc->errorf)
			(*disc->errorf)(NiL, disc, ERROR_SYSTEM|2, "write error");
		return -1;
	}
	return 0;
}
Пример #14
0
MAIN()
{
	char		buf[1024], *s;
	Sfio_t*	f;

	f = sfnew(NIL(Sfio_t*),NIL(Void_t*),(size_t)SF_UNBOUND,-1,SF_WRITE|SF_STRING);
	sfsetbuf(sfstdout,buf,sizeof(buf));
	sfsetbuf(sfstderr,buf,sizeof(buf));
	sfset(sfstdout,SF_SHARE,0);
	sfset(sfstderr,SF_SHARE,0);

	if(!sfpool(sfstdout,f,SF_SHARE) || !sfpool(sfstderr,f,SF_SHARE) )
		terror("Pooling\n");

	if(sfputr(sfstdout,"01234",-1) != 5)
		terror("Writing to stderr\n");
	if(sfputr(sfstderr,"56789",-1) != 5)
		terror("Writing to stdout\n");

	if(sfputc(f,'\0') < 0)
		terror("Writing to string stream\n");

	sfseek(f,(Sfoff_t)0,0);
	if(!(s = sfreserve(f,SF_UNBOUND,1)) )
		terror("Peeking\n");
	sfwrite(f,s,0);
	if(strcmp(s,"0123456789") != 0)
		terror("Data is wrong\n");

	TSTEXIT(0);
}
Пример #15
0
static void l_dirname(register Sfio_t *outfile, register const char *pathname)
{
	register const char  *last;
	/* go to end of path */
	for(last=pathname; *last; last++);
	/* back over trailing '/' */
	while(last>pathname && *--last=='/');
	/* back over non-slash chars */
	for(;last>pathname && *last!='/';last--);
	if(last==pathname)
	{
		/* all '/' or "" */
		if(*pathname!='/')
			last = pathname = ".";
	}
	else
	{
		/* back over trailing '/' */
		for(;*last=='/' && last > pathname; last--);
	}
	/* preserve // */
	if(last!=pathname && pathname[0]=='/' && pathname[1]=='/')
	{
		while(pathname[2]=='/' && pathname<last)
			pathname++;
		if(last!=pathname && pathname[0]=='/' && pathname[1]=='/' && *astconf("PATH_LEADING_SLASHES",NiL,NiL)!='1')
			pathname++;
	}
	sfwrite(outfile,pathname,last+1-pathname);
	sfputc(outfile,'\n');
}
Пример #16
0
extern char*	getpass(const char *prompt)
{
	struct termios told,tnew;
	Sfio_t *iop;
	static char *cp, passwd[32];
	void (*savesig)(int);
	if(!(iop = sfopen((Sfio_t*)0, "/dev/tty", "r")))
		return(0);
	if(tcgetattr(sffileno(iop),&told) < 0)
		return(0);
	interrupt = 0;
	tnew = told;
	tnew.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL);
	if(tcsetattr(sffileno(iop),TCSANOW,&tnew) < 0)
		return(0);
	savesig = signal(SIGINT, handler);
	sfputr(sfstderr,prompt,-1);
	if(cp = sfgetr(iop,'\n',1))
		strncpy(passwd,cp,sizeof(passwd)-1);
	tcsetattr(sffileno(iop),TCSANOW,&told);
	sfputc(sfstderr,'\n');
	sfclose(iop);
	signal(SIGINT, savesig);
	if(interrupt)
		kill(getpid(),SIGINT);
	return(cp?passwd:0);
}
Пример #17
0
static void
init(void)
{
	register Sfio_t**	ss;
	register int		c;

	ed.interactive = -1;
	ed.msg = sfstdout;
	ed.all = BLOCK_LINE;
	ed.page.size = BREAK_PAGE;
	ed.redisc.re_version = REG_VERSION;
	ed.redisc.re_errorf = errorf;
	ed.re.re_disc = &ed.redisc;
	ed.reflags = REG_DISCIPLINE|REG_DELIMITED;
	if (!conformance(0, 0))
		ed.reflags |= REG_LENIENT;
	ed.verbose = 1;
	for (c = 0; c < elementsof(signals); c++)
		if (signal(signals[c], interrupt) == SIG_IGN)
			signal(signals[c], SIG_IGN);
	for (ss = (Sfio_t**)&ed.buffer; ss < (Sfio_t**)(((char*)&ed.buffer) + sizeof(ed.buffer)); ss++) {
		if (!(*ss = sfstropen()))
			error(ERROR_SYSTEM|3, "cannot initialize internal buffer");
		sfputc(*ss, 0);
		sfstrseek(*ss, 0, SEEK_SET);
	}
	sfputr(ed.buffer.help, "?", 0);
	if (!(ed.zero = newof(NiL, Line_t, ed.all, 0)))
		error(ERROR_SYSTEM|3, "out of space [zero]");
}
Пример #18
0
static void namebase(Sfio_t *outfile, register char *pathname, char *suffix)
{
	register char *first, *last;
	register int n=0;
	for(first=last=pathname; *last; last++);
	/* back over trailing '/' */
	if(last>first)
		while(*--last=='/' && last > first);
	if(last==first && *last=='/')
	{
		/* all '/' or "" */
		if(*first=='/')
			if(*++last=='/')	/* keep leading // */
				last++;
	}
	else
	{
		for(first=last++;first>pathname && *first!='/';first--);
		if(*first=='/')
			first++;
		/* check for trailing suffix */
		if(suffix && (n=strlen(suffix)) && n<(last-first))
		{
			if(memcmp(last-n,suffix,n)==0)
				last -=n;
		}
	}
	if(last>first)
		sfwrite(outfile,first,last-first);
	sfputc(outfile,'\n');
}
Пример #19
0
MAIN()
{
	Sfio_t*	f;
	char	buf[1024], *s;
	int	n;
#ifdef DEBUG
	Sfio_t*	logf = sfopen(0,"LOG","a"); sfsetbuf(logf,NIL(Void_t*),0);
#endif

	alarm(10);
	if(argc > 1)
	{	/* coprocess only */
		while((s = sfreserve(sfstdin,-1,0)) )
		{
#ifdef DEBUG
			sfwrite(logf, s, sfvalue(sfstdin));
#endif
			sfwrite(sfstdout, s, sfvalue(sfstdin));
		}
		return 0;
	}

	/* make coprocess */
	if(!(f = sfpopen(NIL(Sfio_t*), sfprints("%s -p",argv[0]), "r+")))
		terror("Opening for read/write\n");
	for(n = 0; n < 10; ++n)
	{	sfsprintf(buf,sizeof(buf),"Line %d",n);
		sfputr(f,buf,'\n');
		if(!(s = sfgetr(f,'\n',1)))
			terror("Did not read back line\n");
		if(strcmp(s,buf) != 0)
			terror("Input=%s, Expect=%s\n",s,buf);
	}

	if(sfputr(f,"123456789",'\n') != 10)
		terror("Bad write");

	if(sfread(f,buf,3) != 3)
		terror("Did not get data back\n");
	if(strncmp(s,"123",3) != 0)
		terror("Wrong data\n");

	if(sfwrite(f,"aaa",3) != 3 || sfputc(f,'\n') != '\n')
		terror("Fail on write\n");

	if(!(s = sfgetr(f,'\n',1)) )
		terror("Should have gotten 456789\n"); 
	if(strcmp(s,"456789") != 0)
		terror("Wrong data2\n");

	if(!(s = sfgetr(f,'\n',1)) )
		terror("Should have gotten aaa\n"); 
	if(strcmp(s,"aaa") != 0)
		terror("Wrong data3\n");

	sfclose(f);
	
	TSTEXIT(0);
}
Пример #20
0
/* toUpper:
 * Convert characters to uppercase
 */
char *toUpper(Expr_t * pgm, char *s, Sfio_t* tmps)
{
    int c;

    while ((c = *s++))
	sfputc (tmps, toupper (c));

    return exstring(pgm, sfstruse(tmps));
}
Пример #21
0
static void
outline(Fmt_t* fp)
{
	register char*	cp = fp->outbuf;
	int		n = 0;
	int		c;
	int		d;

	if (!fp->outp)
		return;
	while (fp->outp[-1] == ' ')
		fp->outp--;
	*fp->outp = 0;
	while (*cp++ == ' ')
		n++;
	if (n >= TABSZ)
	{
		n /= TABSZ;
		cp = &fp->outbuf[TABSZ*n];
		while (n--)
			*--cp = '\t';
	}
	else
		cp = fp->outbuf;
	fp->nwords = 0;
	if (!isoption(fp, 'o'))
		sfputr(fp->out, cp, '\n');
	else if (*cp)
	{
		n = fp->indent;
		if (*cp != '[')
		{
			if (*cp == ' ')
				cp++;
			n += INDENT;
		}
		while (n--)
			sfputc(fp->out, ' ');
		if (fp->quote)
		{
			if ((d = (fp->outp - cp)) <= 0)
				c = 0;
			else if ((c = fp->outp[-1]) == 'n' && d > 1 && fp->outp[-2] == '\\')
				c = '}';
			sfprintf(fp->out, "\"%s%s\"\n", cp, c == ']' || c == '{' || c == '}' ? "" : " ");
		}
		else
			sfputr(fp->out, cp, '\n');
		if (fp->nextdent)
		{
			fp->indent += fp->nextdent;
			fp->endbuf -= fp->nextdent;
			fp->nextdent = 0;
		}
	}
	fp->outp = 0;
}
Пример #22
0
static int nocrnl(Sfio_t *in, Sfio_t *out)
{
	register char *cp, *first, *cpmax;
	register int lastc=0, defer=0,n;
	while(cp = sfreserve(in,SF_UNBOUND,0))
	{
		if(defer)
			sfputc(out,lastc);
		defer = 0;
		cpmax = cp + sfvalue(in)-1;
		lastc= *(unsigned char*)(cpmax);
		*(unsigned char*)(cpmax) = '\r';
		while(1)
		{
			first = cp;
		again:
			while(*cp++ != '\r');
			if(cp>=cpmax)
			{
				*cpmax = lastc;
				if(cp==cpmax)
				{
					if(lastc!='\n')
						cp += 2;
					else
						defer = 1;
				}
				else if(lastc!='\r')
					cp++;
				else
					defer = 1;
			}
			else if(*cp !='\n')
				goto again;
			if((n=cp-1-first)>0)
				sfwrite(out,first,n);
			if(cp>=cpmax)
				break;
		}
	}
	if(defer)
		sfputc(out,lastc);
	return(1);
}
Пример #23
0
static char*
str_mod(Expr_t* ex, register char* l, register char* r)
{
	register int	c;

	while (c = *l++)
		if (!strchr(r, c) && !strchr(l, c))
			sfputc(ex->tmp, c);
	return exstash(ex->tmp, ex->ve);
}
Пример #24
0
static char*
str_mpy(Expr_t* ex, register char* l, register char* r)
{
	register int	lc;
	register int	rc;

	while ((lc = *l++) && (rc = *r++))
		sfputc(ex->tmp, lc == rc ? lc : ' ');
	return exstash(ex->tmp, ex->ve);
}
Пример #25
0
/*
 * Read single line from stream.
 * Return "" on EOF.
 */
char *readLine(Expr_t * ex, int fd)
{
    Sfio_t *sp;
    int c;
    Sfio_t *tmps;
    char *line;

    if (fd < 0 || fd >= elementsof(ex->file) || !((sp = ex->file[fd]))) {
	exerror("readL: %d: invalid descriptor", fd);
	return "";
    }
    tmps = sfstropen();
    while (((c = sfgetc(sp)) > 0) && (c != '\n'))
	sfputc(tmps, c);
    if (c == '\n')
	sfputc(tmps, c);
    line = exstring(ex, sfstruse(tmps));
    sfclose(tmps);
    return line;
}
Пример #26
0
static int myputc (Sfio_t *fp, char c) {
    if (count2 < 2) {
        buf2[count2++] = c;
        return 0;
    }
    wrotenl = (buf2[0] == '\n') ? 1 : 0;
    sfputc (fp, buf2[0]), buf2[0] = buf2[1], buf2[1] = c;
    if (!binmode && buf2[1] == '\n' && buf2[0] == '\r')
        buf2[0] = buf2[1], count2 = 1;
    return 0;
}
Пример #27
0
Файл: tmode.c Проект: att/ast
tmain() {
    Sfio_t *f;

    if (argc > 1) {
        if (sfopen(sfstdin, argv[1], "r") != sfstdin) terror("Can't reopen stdin");
        sfmove(sfstdin, sfstdout, (Sfoff_t)(-1), -1);
        return 0;
    }

    if (!(f = sfopen(NULL, tstfile("sf", 0), "w"))) terror("Opening to write");
    if (sfputc(f, 'a') != 'a') terror("sfputc");
    if (sfgetc(f) >= 0) terror("sfgetc");

    if (!(f = sfopen(f, tstfile("sf", 0), "r"))) terror("Opening to read");
    if (sfgetc(f) != 'a') terror("sfgetc2");
    if (sfputc(f, 'b') >= 0) terror("sfputc2");

    if (!(f = sfopen(f, tstfile("sf", 0), "r+"))) terror("Opening to read/write");

    if (sfgetc(f) != 'a') terror("sfgetc3");
    if (sfputc(f, 'b') != 'b') terror("sfputc3");
    if (sfclose(f) < 0) terror("sfclose");

    if (!(f = sfpopen(NULL, sfprints("%s %s", argv[0], tstfile("sf", 0)), "r"))) terror("sfpopen");
    if (sfgetc(f) != 'a') terror("sfgetc4");
    if (sfgetc(f) != 'b') terror("sfgetc5");
    if (sfgetc(f) >= 0) terror("sfgetc6");

    if (!(f = sfopen(f, tstfile("sf", 0), "w"))) terror("sfopen");
    if (sfputc(f, 'a') != 'a') terror("sfputc1");
    sfsetfd(f, -1);
    if (sfputc(f, 'b') >= 0) terror("sfputc2");
    if (sfclose(f) < 0) terror("sfclose");

    if (!(f = sfopen(NULL, tstfile("sf", 0), "a+"))) terror("sfopen2");
    sfset(f, SF_READ, 0);
    if (!sfreserve(f, 0, -1)) terror("Failed on buffer getting");
    if (sfvalue(f) <= 0) terror("There is no buffer?");

    texit(0);
}
Пример #28
0
P_NOGEN

int main(int argc, char** argv) {
  char fname[1000];
  char* h;
  Sfio_t* io;
  Pint8    data1 = -2;
  Puint8   data2 = 2;
  Pint16   data3 = -2;
  Puint16  data4 = 2;
  Pint32   data5 = -2;
  Puint32  data6 = 2;
  Pint64   data7 = -2;
  Puint64  data8 = 2;

  h = getenv("HOSTSHORT");
  sprintf(fname, "../../data/ex_data.libtest2.%s", h);
  printf("fname = %s\n", fname);
  io = sfopen(0, fname, "w");
  sfwrite(io, (void*)&data1, sizeof(data1));
  sfwrite(io, (void*)&data2, sizeof(data2));
  sfwrite(io, (void*)&data3, sizeof(data3));
  sfwrite(io, (void*)&data4, sizeof(data4));
  sfwrite(io, (void*)&data5, sizeof(data5));
  sfwrite(io, (void*)&data6, sizeof(data6));
  sfwrite(io, (void*)&data7, sizeof(data7));
  sfwrite(io, (void*)&data8, sizeof(data8));
  sfputc(io, '\n');
  sfwrite(io, (void*)&data1, sizeof(data1));
  sfwrite(io, (void*)&data2, sizeof(data2));
  sfwrite(io, (void*)&data3, sizeof(data3));
  sfwrite(io, (void*)&data4, sizeof(data4));
  sfwrite(io, (void*)&data5, sizeof(data5));
  sfwrite(io, (void*)&data6, sizeof(data6));
  sfwrite(io, (void*)&data7, sizeof(data7));
  /*  sfwrite(io, (void*)&data8, sizeof(data8)); */
  sfwrite(io, (void*)&data4, sizeof(data4));
  sfputc(io, '\n');
  sfclose(io);
  return 0;
}
Пример #29
0
static ssize_t
helpwrite(int fd, const void* buf, size_t len)
{
	ssize_t	n;

	NoP(fd);
	n = ed.help ? sfwrite(sfstderr, buf, len) : ed.verbose ? sfputr(ed.msg, "?", '\n') : 0;
	sfstrseek(ed.buffer.help, 0, SEEK_SET);
	sfwrite(ed.buffer.help, buf, len - 1);
	sfputc(ed.buffer.help, 0);
	return n;
}
Пример #30
0
char*
_re_putc(int c)
{
	static Sfio_t*	sp;

	if (!sp && !(sp = sfstropen()))
		return 0;
	if (!c)
		return sfstruse(sp);
	sfputc(sp, c);
	return 0;
}