1*10950Srrh #ifndef lint 2*10950Srrh static char sccsid[] = "@(#)1.form.c 4.1 (Berkeley) 02/11/83"; 3*10950Srrh #endif not lint 4*10950Srrh 5*10950Srrh #include <stdio.h> 6*10950Srrh #include "1.defs.h" 7*10950Srrh #include "def.h" 8*10950Srrh extern int linechar, errflag, debug; 9*10950Srrh extern int (*input)(), (*unput)(); 10*10950Srrh 11*10950Srrh 12*10950Srrh 13*10950Srrh uptolow(c) /*translates upper to lower case */ 14*10950Srrh int c; 15*10950Srrh { 16*10950Srrh if ('A' <= c && c <= 'Z') 17*10950Srrh return(c+'a'-'A'); 18*10950Srrh else 19*10950Srrh return(c); 20*10950Srrh } 21*10950Srrh 22*10950Srrh rdfree(func) 23*10950Srrh int (*func)(); 24*10950Srrh { 25*10950Srrh int c; 26*10950Srrh while ( (c = (*input)()) != '\n') 27*10950Srrh { 28*10950Srrh (*func)(c); 29*10950Srrh } 30*10950Srrh } 31*10950Srrh 32*10950Srrh rdstand(func) 33*10950Srrh int (*func)(); 34*10950Srrh { 35*10950Srrh int c; 36*10950Srrh while ( (c=(*input)()) != '\n') 37*10950Srrh { 38*10950Srrh (*func)(c); 39*10950Srrh } 40*10950Srrh } 41*10950Srrh 42*10950Srrh labfree(func) /* labels in freeform input */ 43*10950Srrh int (*func)(); 44*10950Srrh { 45*10950Srrh int c; 46*10950Srrh int temp[6]; 47*10950Srrh int j; 48*10950Srrh for (j = 0; j < 5; ++j) 49*10950Srrh { 50*10950Srrh while ( (c = (*input)()) == ' ' || c == '\t' ); 51*10950Srrh if (c == '\n') 52*10950Srrh { 53*10950Srrh if (j != 0) 54*10950Srrh { 55*10950Srrh temp[j] = '\0'; 56*10950Srrh error("label without code - ignored:","",""); 57*10950Srrh } 58*10950Srrh } 59*10950Srrh if (c < '0' || c > '9') 60*10950Srrh { 61*10950Srrh (*unput)(c); 62*10950Srrh break; 63*10950Srrh } 64*10950Srrh else 65*10950Srrh { 66*10950Srrh temp[j] = c; 67*10950Srrh (*func)(c); 68*10950Srrh } 69*10950Srrh } 70*10950Srrh for ( ; j < 5; ++j) 71*10950Srrh (*func)(' '); 72*10950Srrh } 73*10950Srrh 74*10950Srrh labstand(func) /* labels in standard form input */ 75*10950Srrh int (*func)(); 76*10950Srrh { 77*10950Srrh int c; 78*10950Srrh int j; 79*10950Srrh 80*10950Srrh for (j = 0; j < 5; ++j) 81*10950Srrh { 82*10950Srrh c = (*input)(); 83*10950Srrh if (c == '\n') 84*10950Srrh { 85*10950Srrh error("line shorter than 5 characters","",""); 86*10950Srrh errflag = 1; 87*10950Srrh (*unput)('\n'); 88*10950Srrh } 89*10950Srrh if (c == '\t' || c == '\n') 90*10950Srrh { 91*10950Srrh for ( ;j<5; ++j) 92*10950Srrh (*func)(' '); 93*10950Srrh return; 94*10950Srrh } 95*10950Srrh (*func)(c); 96*10950Srrh } 97*10950Srrh (*input)(); /* throw away continuation char */ 98*10950Srrh } 99*10950Srrh 100*10950Srrh 101*10950Srrh 102*10950Srrh contfree() /* identify continuation lines in free-form input */ 103*10950Srrh { 104*10950Srrh return(nonblchar(_diglet,0)); /* any non-alpha non-digit */ 105*10950Srrh } 106*10950Srrh 107*10950Srrh 108*10950Srrh nonblchar(class,yesno) 109*10950Srrh int class,yesno; 110*10950Srrh { 111*10950Srrh #define CARDSIZE 121 112*10950Srrh int temp[CARDSIZE]; 113*10950Srrh int j; 114*10950Srrh for (j=0; (temp[j]=(*input)()) == ' ' || temp[j] == '\t'; ++j) 115*10950Srrh if (j>=CARDSIZE-1) 116*10950Srrh { 117*10950Srrh temp[CARDSIZE-1] = '\0'; 118*10950Srrh error ("line unexpectedly long","",""); 119*10950Srrh break; 120*10950Srrh } 121*10950Srrh if (temp[j]!=EOF && classmatch(temp[j],class)==yesno) 122*10950Srrh return(1); 123*10950Srrh else 124*10950Srrh { 125*10950Srrh for ( ; j >= 0; --j) 126*10950Srrh (*unput)(temp[j]); 127*10950Srrh return(0); 128*10950Srrh } 129*10950Srrh } 130*10950Srrh 131*10950Srrh 132*10950Srrh contstand() /* continuation lines in standard form input */ 133*10950Srrh { 134*10950Srrh int temp[6]; 135*10950Srrh int i; 136*10950Srrh 137*10950Srrh for (i = 0; i < 6; ++i) 138*10950Srrh { 139*10950Srrh temp[i] = (*input)(); 140*10950Srrh if (temp[i] == '\t' || temp[i] == '\n' || temp[i] == '\0' || temp[i] == EOF) 141*10950Srrh { 142*10950Srrh for ( ;i >= 0; --i) 143*10950Srrh (*unput)(temp[i]); 144*10950Srrh return(0); 145*10950Srrh } 146*10950Srrh } 147*10950Srrh if (temp[5] != '0' && temp[5] != ' ') 148*10950Srrh return(1); 149*10950Srrh else 150*10950Srrh { 151*10950Srrh for ( i = 5 ; i >= 0; --i) 152*10950Srrh (*unput)(temp[i]); 153*10950Srrh return(0); 154*10950Srrh } 155*10950Srrh } 156*10950Srrh 157*10950Srrh 158*10950Srrh 159*10950Srrh comstand(posafter) /* standard form comments */ 160*10950Srrh int posafter; 161*10950Srrh { 162*10950Srrh int c; 163*10950Srrh c = (*input)(); 164*10950Srrh if (!posafter) 165*10950Srrh (*unput)(c); 166*10950Srrh if (c == 'c' || c == '*' || c== '#') 167*10950Srrh return(1); 168*10950Srrh else 169*10950Srrh return(0); 170*10950Srrh } 171*10950Srrh 172*10950Srrh 173*10950Srrh comfree(posafter) 174*10950Srrh int posafter; 175*10950Srrh { 176*10950Srrh return(comstand(posafter)); 177*10950Srrh } 178*10950Srrh int (*rline[])() = {rdfree,rdstand}; 179*10950Srrh int (*comment[])() = {comfree,comstand}; 180*10950Srrh int (*getlabel[])() = {labfree, labstand}; 181*10950Srrh int (*chkcont[])() = {contfree,contstand}; 182*10950Srrh 183*10950Srrh blankline() 184*10950Srrh { 185*10950Srrh if ( nonblchar(_nl,1) ) /* first non-blank is nl */ 186*10950Srrh { 187*10950Srrh (*unput) ('\n'); 188*10950Srrh return(1); 189*10950Srrh } 190*10950Srrh else return(0); 191*10950Srrh } 192*10950Srrh 193*10950Srrh #define maxunbp 80 194*10950Srrh char unbuf[maxunbp+1]; 195*10950Srrh int unbp; 196*10950Srrh 197*10950Srrh empseek(linebeg) 198*10950Srrh int linebeg; 199*10950Srrh { 200*10950Srrh unbp = 0; 201*10950Srrh if (fseek(infd,(long)(linebeg+rtnbeg),0) == -1) 202*10950Srrh faterr("in disk seek","",""); 203*10950Srrh } 204*10950Srrh 205*10950Srrh inchar() 206*10950Srrh { 207*10950Srrh if (unbp > 0) 208*10950Srrh return( unbuf[--unbp] ); 209*10950Srrh else 210*10950Srrh { 211*10950Srrh return( uptolow(getc(infd)) ); 212*10950Srrh } 213*10950Srrh } 214*10950Srrh 215*10950Srrh 216*10950Srrh unchar(c) 217*10950Srrh int c; 218*10950Srrh { 219*10950Srrh if (unbp >= maxunbp) 220*10950Srrh faterr("dec.rat: unbuf size exceeded","",""); 221*10950Srrh if(c!=EOF)unbuf[unbp++] = c; 222*10950Srrh } 223