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