110950Srrh #ifndef lint 2*43623Sbostic static char sccsid[] = "@(#)1.form.c 4.2 (Berkeley) 06/24/90"; 310950Srrh #endif not lint 410950Srrh 510950Srrh #include <stdio.h> 610950Srrh #include "1.defs.h" 710950Srrh #include "def.h" 8*43623Sbostic 9*43623Sbostic /* 10*43623Sbostic * The following are used in <stdio.h> but are defines as constants 11*43623Sbostic * in 1.defs.h -- since their values are never used here we simply 12*43623Sbostic * discard them. XXX 13*43623Sbostic */ 14*43623Sbostic #undef _r 15*43623Sbostic #undef _p 16*43623Sbostic 1710950Srrh extern int linechar, errflag, debug; 1810950Srrh extern int (*input)(), (*unput)(); 1910950Srrh 2010950Srrh 2110950Srrh 2210950Srrh uptolow(c) /*translates upper to lower case */ 2310950Srrh int c; 2410950Srrh { 2510950Srrh if ('A' <= c && c <= 'Z') 2610950Srrh return(c+'a'-'A'); 2710950Srrh else 2810950Srrh return(c); 2910950Srrh } 3010950Srrh 3110950Srrh rdfree(func) 3210950Srrh int (*func)(); 3310950Srrh { 3410950Srrh int c; 3510950Srrh while ( (c = (*input)()) != '\n') 3610950Srrh { 3710950Srrh (*func)(c); 3810950Srrh } 3910950Srrh } 4010950Srrh 4110950Srrh rdstand(func) 4210950Srrh int (*func)(); 4310950Srrh { 4410950Srrh int c; 4510950Srrh while ( (c=(*input)()) != '\n') 4610950Srrh { 4710950Srrh (*func)(c); 4810950Srrh } 4910950Srrh } 5010950Srrh 5110950Srrh labfree(func) /* labels in freeform input */ 5210950Srrh int (*func)(); 5310950Srrh { 5410950Srrh int c; 5510950Srrh int temp[6]; 5610950Srrh int j; 5710950Srrh for (j = 0; j < 5; ++j) 5810950Srrh { 5910950Srrh while ( (c = (*input)()) == ' ' || c == '\t' ); 6010950Srrh if (c == '\n') 6110950Srrh { 6210950Srrh if (j != 0) 6310950Srrh { 6410950Srrh temp[j] = '\0'; 6510950Srrh error("label without code - ignored:","",""); 6610950Srrh } 6710950Srrh } 6810950Srrh if (c < '0' || c > '9') 6910950Srrh { 7010950Srrh (*unput)(c); 7110950Srrh break; 7210950Srrh } 7310950Srrh else 7410950Srrh { 7510950Srrh temp[j] = c; 7610950Srrh (*func)(c); 7710950Srrh } 7810950Srrh } 7910950Srrh for ( ; j < 5; ++j) 8010950Srrh (*func)(' '); 8110950Srrh } 8210950Srrh 8310950Srrh labstand(func) /* labels in standard form input */ 8410950Srrh int (*func)(); 8510950Srrh { 8610950Srrh int c; 8710950Srrh int j; 8810950Srrh 8910950Srrh for (j = 0; j < 5; ++j) 9010950Srrh { 9110950Srrh c = (*input)(); 9210950Srrh if (c == '\n') 9310950Srrh { 9410950Srrh error("line shorter than 5 characters","",""); 9510950Srrh errflag = 1; 9610950Srrh (*unput)('\n'); 9710950Srrh } 9810950Srrh if (c == '\t' || c == '\n') 9910950Srrh { 10010950Srrh for ( ;j<5; ++j) 10110950Srrh (*func)(' '); 10210950Srrh return; 10310950Srrh } 10410950Srrh (*func)(c); 10510950Srrh } 10610950Srrh (*input)(); /* throw away continuation char */ 10710950Srrh } 10810950Srrh 10910950Srrh 11010950Srrh 11110950Srrh contfree() /* identify continuation lines in free-form input */ 11210950Srrh { 11310950Srrh return(nonblchar(_diglet,0)); /* any non-alpha non-digit */ 11410950Srrh } 11510950Srrh 11610950Srrh 11710950Srrh nonblchar(class,yesno) 11810950Srrh int class,yesno; 11910950Srrh { 12010950Srrh #define CARDSIZE 121 12110950Srrh int temp[CARDSIZE]; 12210950Srrh int j; 12310950Srrh for (j=0; (temp[j]=(*input)()) == ' ' || temp[j] == '\t'; ++j) 12410950Srrh if (j>=CARDSIZE-1) 12510950Srrh { 12610950Srrh temp[CARDSIZE-1] = '\0'; 12710950Srrh error ("line unexpectedly long","",""); 12810950Srrh break; 12910950Srrh } 13010950Srrh if (temp[j]!=EOF && classmatch(temp[j],class)==yesno) 13110950Srrh return(1); 13210950Srrh else 13310950Srrh { 13410950Srrh for ( ; j >= 0; --j) 13510950Srrh (*unput)(temp[j]); 13610950Srrh return(0); 13710950Srrh } 13810950Srrh } 13910950Srrh 14010950Srrh 14110950Srrh contstand() /* continuation lines in standard form input */ 14210950Srrh { 14310950Srrh int temp[6]; 14410950Srrh int i; 14510950Srrh 14610950Srrh for (i = 0; i < 6; ++i) 14710950Srrh { 14810950Srrh temp[i] = (*input)(); 14910950Srrh if (temp[i] == '\t' || temp[i] == '\n' || temp[i] == '\0' || temp[i] == EOF) 15010950Srrh { 15110950Srrh for ( ;i >= 0; --i) 15210950Srrh (*unput)(temp[i]); 15310950Srrh return(0); 15410950Srrh } 15510950Srrh } 15610950Srrh if (temp[5] != '0' && temp[5] != ' ') 15710950Srrh return(1); 15810950Srrh else 15910950Srrh { 16010950Srrh for ( i = 5 ; i >= 0; --i) 16110950Srrh (*unput)(temp[i]); 16210950Srrh return(0); 16310950Srrh } 16410950Srrh } 16510950Srrh 16610950Srrh 16710950Srrh 16810950Srrh comstand(posafter) /* standard form comments */ 16910950Srrh int posafter; 17010950Srrh { 17110950Srrh int c; 17210950Srrh c = (*input)(); 17310950Srrh if (!posafter) 17410950Srrh (*unput)(c); 17510950Srrh if (c == 'c' || c == '*' || c== '#') 17610950Srrh return(1); 17710950Srrh else 17810950Srrh return(0); 17910950Srrh } 18010950Srrh 18110950Srrh 18210950Srrh comfree(posafter) 18310950Srrh int posafter; 18410950Srrh { 18510950Srrh return(comstand(posafter)); 18610950Srrh } 18710950Srrh int (*rline[])() = {rdfree,rdstand}; 18810950Srrh int (*comment[])() = {comfree,comstand}; 18910950Srrh int (*getlabel[])() = {labfree, labstand}; 19010950Srrh int (*chkcont[])() = {contfree,contstand}; 19110950Srrh 19210950Srrh blankline() 19310950Srrh { 19410950Srrh if ( nonblchar(_nl,1) ) /* first non-blank is nl */ 19510950Srrh { 19610950Srrh (*unput) ('\n'); 19710950Srrh return(1); 19810950Srrh } 19910950Srrh else return(0); 20010950Srrh } 20110950Srrh 20210950Srrh #define maxunbp 80 20310950Srrh char unbuf[maxunbp+1]; 20410950Srrh int unbp; 20510950Srrh 20610950Srrh empseek(linebeg) 20710950Srrh int linebeg; 20810950Srrh { 20910950Srrh unbp = 0; 21010950Srrh if (fseek(infd,(long)(linebeg+rtnbeg),0) == -1) 21110950Srrh faterr("in disk seek","",""); 21210950Srrh } 21310950Srrh 21410950Srrh inchar() 21510950Srrh { 21610950Srrh if (unbp > 0) 21710950Srrh return( unbuf[--unbp] ); 21810950Srrh else 21910950Srrh { 22010950Srrh return( uptolow(getc(infd)) ); 22110950Srrh } 22210950Srrh } 22310950Srrh 22410950Srrh 22510950Srrh unchar(c) 22610950Srrh int c; 22710950Srrh { 22810950Srrh if (unbp >= maxunbp) 22910950Srrh faterr("dec.rat: unbuf size exceeded","",""); 23010950Srrh if(c!=EOF)unbuf[unbp++] = c; 23110950Srrh } 232