Annotation of 43BSD/usr.bin/ratfor/r2.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char sccsid[] = "@(#)r2.c       1.2 (Berkeley) 8/11/83";
        !             3: #endif
        !             4: 
        !             5: #include "r.h"
        !             6: 
        !             7: extern int hollerith;
        !             8: 
        !             9: char   outbuf[80];
        !            10: int    outp    = 0;
        !            11: int    cont    = 0;
        !            12: int    contchar        = '&';
        !            13: 
        !            14: char   comment[320];
        !            15: int    comptr  = 0;
        !            16: int    indent  = 0;
        !            17: 
        !            18: outdon() {
        !            19:        outbuf[outp] = '\0';
        !            20:        if (outp > 0)
        !            21:                fprintf(outfil, "%s\n", outbuf);
        !            22:        outp = cont = 0;
        !            23: }
        !            24: 
        !            25: putcom(s) char *s; {
        !            26:        if (printcom) {
        !            27:                ptc('c');
        !            28:                outtab();
        !            29:                pts(s);
        !            30:                outdon();
        !            31:        }
        !            32: }
        !            33: 
        !            34: outcode(xp) char *xp; {
        !            35:        register c, c1, j;
        !            36:        char *q, *p;
        !            37: 
        !            38:        p = (char *) xp;        /* shut lint up */
        !            39:        if (cont == 0 && comptr > 0)    /* flush comment if not on continuation */
        !            40:                flushcom();
        !            41:        while( (c = *p++) ){
        !            42:                c1 = *p;
        !            43:                if (type[c] == LET || type[c] == DIG) {
        !            44:                        pts(p-1);
        !            45:                        break;
        !            46:                }
        !            47:                switch(c){
        !            48: 
        !            49:                case '"': case '\'':
        !            50:                        j = 0;
        !            51:                        for (q=p; *q; q++) {
        !            52:                                if (*q == '\\')
        !            53:                                        q++;
        !            54:                                j++;
        !            55:                        }
        !            56:                        if (outp+j+2 > 71)
        !            57:                                contcard();
        !            58:                        if (hollerith) {
        !            59:                                outnum(--j);
        !            60:                                ptc('h');
        !            61:                        } else
        !            62:                                ptc(c);
        !            63:                        while (*p != c) {
        !            64:                                if (*p == '\\')
        !            65:                                        p++;
        !            66:                                ptc(*p++);
        !            67:                        }
        !            68:                        if (!hollerith)
        !            69:                                ptc(c);
        !            70:                        p++;
        !            71:                        break;
        !            72:                case '$': case '\\':
        !            73:                        if (strlen(p-1)+outp > 71)
        !            74:                                contcard();
        !            75:                        if (c1 == '"' || c1 == '\'') {
        !            76:                                ptc(c1);
        !            77:                                p++;
        !            78:                        } else
        !            79:                                for (p--; *p; p++)
        !            80:                                        ptc(*p);
        !            81:                        break;
        !            82:                case '%':
        !            83:                        outp = 0;
        !            84:                        while (*p)
        !            85:                                ptc(*p++);
        !            86:                        break;
        !            87:                case '>':
        !            88:                        if( c1=='=' ){
        !            89:                                pts(".ge."); p++;
        !            90:                        } else
        !            91:                                pts(".gt.");
        !            92:                        break;
        !            93:                case '<':
        !            94:                        if( c1=='=' ){
        !            95:                                pts(".le."); p++;
        !            96:                        } else if( c1=='>' ){
        !            97:                                pts(".ne."); p++;
        !            98:                        } else
        !            99:                                pts(".lt.");
        !           100:                        break;
        !           101:                case '=':
        !           102:                        if( c1=='=' ){
        !           103:                                pts(".eq."); p++;
        !           104:                        } else
        !           105:                                ptc('=');
        !           106:                        break;
        !           107:                case '!': case '^':
        !           108:                        if( c1=='=' ){
        !           109:                                pts(".ne."); p++;
        !           110:                        } else
        !           111:                                pts(".not.");
        !           112:                        break;
        !           113:                case '&':
        !           114:                        if( c1=='&' )
        !           115:                                p++;
        !           116:                        pts(".and.");
        !           117:                        break;
        !           118:                case '|':
        !           119:                        if( c1=='|' )
        !           120:                                p++;
        !           121:                        pts(".or.");
        !           122:                        break;
        !           123:                case '\t':
        !           124:                        outtab();
        !           125:                        break;
        !           126:                case '\n':
        !           127:                        ptc(' ');
        !           128:                        break;
        !           129:                default:
        !           130:                        ptc(c);
        !           131:                        break;
        !           132:                }
        !           133:        }
        !           134: }
        !           135: 
        !           136: ptc(c) char c; {
        !           137:        if( outp > 71 )
        !           138:                contcard();
        !           139:        outbuf[outp++] = c;
        !           140: }
        !           141: 
        !           142: pts(s) char *s; {
        !           143:        if (strlen(s)+outp > 71)
        !           144:                contcard();
        !           145:        while(*s)
        !           146:                ptc(*s++);
        !           147: }
        !           148: 
        !           149: contcard(){
        !           150:        int n;
        !           151:        outbuf[outp] = '\0';
        !           152:        fprintf(outfil, "%s\n", outbuf);
        !           153:        n = 6;
        !           154:        if (printcom) {
        !           155:                n += INDENT * indent + 1;
        !           156:                if (n > 35) n = 35;
        !           157:        }
        !           158:        for( outp=0; outp<n; outbuf[outp++] = ' ' );
        !           159:        outbuf[contfld-1] = contchar;
        !           160:        cont++;
        !           161:        if (cont > 19)
        !           162:                error("more than 19 continuation cards");
        !           163: }
        !           164: 
        !           165: outtab(){
        !           166:        int n;
        !           167:        n = 6;
        !           168:        if (printcom) {
        !           169:                n += INDENT * indent;
        !           170:                if (n > 35) n = 35;
        !           171:        }
        !           172:        while (outp < n)
        !           173:                ptc(' ');
        !           174: }
        !           175: 
        !           176: outnum(n) int n; {
        !           177:        int a;
        !           178:        if( a = n/10 )
        !           179:                outnum(a);
        !           180:        ptc(n%10 + '0');
        !           181: }
        !           182: 
        !           183: outcont(n) int n; {
        !           184:        transfer = 0;
        !           185:        if (n == 0 && outp == 0)
        !           186:                return;
        !           187:        if( n > 0 )
        !           188:                outnum(n);
        !           189:        outcode("\tcontinue");
        !           190:        outdon();
        !           191: }
        !           192: 
        !           193: outgoto(n) int n; {
        !           194:        if (transfer != 0)
        !           195:                return;
        !           196:        outcode("\tgoto ");
        !           197:        outnum(n);
        !           198:        outdon();
        !           199: }
        !           200: 
        !           201: flushcom() {
        !           202:        int i, j;
        !           203:        if (printcom == 0)
        !           204:                comptr = 0;
        !           205:        else if (cont == 0 && comptr > 0) {
        !           206:                for (i=j=0; i < comptr; i++)
        !           207:                        if (comment[i] == '\n') {
        !           208:                                comment[i] = '\0';
        !           209:                                fprintf(outfil, "%s\n", &comment[j]);
        !           210:                                j = i + 1;
        !           211:                        }
        !           212:                comptr = 0;
        !           213:        }
        !           214: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.