/* Screen editor: general utilities * BDS C version * * Source: ed9.cc * Version: May 15, 1981. */ /* define global constants and variables */ #include ed.h #include bdscio.h #include ed1.ccc #include edext.cc /* return: is first token in args a number ? */ /* return value of number in *val */ number(args,val) char *args; int *val; { char c; c=*args++; if ((c<'0')||(c>'9')) { return(NO); } *val=c-'0'; while (c=*args++) { if ((c<'0')||(c>'9')) { break; } *val=(*val*10)+c-'0'; } return(YES); } /* convert character buffer to numeric */ ctoi(buf,index) char *buf; int index; { int k; while ( (buf[index]==' ')|| (buf[index]==TAB) ) { index++; } k=0; while ((buf[index]>='0')&&(buf[index]<='9')) { k=(k*10)+buf[index]-'0'; index++; } return(k); } /* put decimal integer n in field width >= w. * left justify the number in the field. */ putdec(n,w) int n,w; { char chars[10]; int i,nd; nd=itoc(n,chars,10); i=0; while (i0) { if (syspshch(*p++,file)==ERR) { return(ERR); } } /* write trailing CR */ return(syspshch(CR,file)); } /* pop a line from the back of the file. * the line should have been pushed using pushline(). */ popline(file,p,n) int file; char *p; int n; { int c; int k, kmax, t; /* first char must be CR */ c=syspopch(file); if (c==EOF) { /* at START of file */ return(EOF); } if (c==CR) { /* put into buffer */ *p++=CR; k=1; } else { syserr("popline: missing CR"); return(ERR); } /* pop line into buffer in reverse order */ while (1) { c=syspopch(file); if (c==ERR) { return(ERR); } if (c==EOF) { break; } if (c==CR) { /* this ends ANOTHER line */ /* push it back */ if (syspshch(CR,file)==ERR) { return(ERR); } break; } /* non-special case */ if (kt) { /* swap p[t], p[k] */ c=p[k]; p[k]=p[t]; p[t]=c; k--; t++; } return(kmax); }