Annotation of researchv10no/cmd/ideal/idfilt/idsort.c, revision 1.1

1.1     ! root        1: #include "idfilt.h"
        !             2: 
        !             3: FILE *infile;
        !             4: FILE *tempfile;
        !             5: char *filename;
        !             6: int lineno = 0;
        !             7: 
        !             8: float maxx, maxy;
        !             9: float minx, miny;
        !            10: float width = 4.0;
        !            11: float colwid = 6.0;
        !            12: float xscale;
        !            13: 
        !            14: boolean maxxset, maxyset;
        !            15: boolean minxset, minyset;
        !            16: boolean widset, colset;
        !            17: boolean boundset;
        !            18: 
        !            19: boolean veryfirst = TRUE;
        !            20: 
        !            21: main (argc, argv)
        !            22: int argc;
        !            23: char *argv[];
        !            24: {
        !            25:        while (argc > 1 && argv[1][0] == '-') {
        !            26:                fprintf (stderr, "ideal filter: unknown flag %c\n", argv[1][1]);
        !            27:                argc--;
        !            28:                argv++;
        !            29:        }
        !            30:        if (argc < 2) {
        !            31:                infile = stdin;
        !            32:                lineno = 0;
        !            33:                interpret (infile);
        !            34:        } else {
        !            35:                while (argc-- > 1) {
        !            36:                        if (!(infile = fopen (*++argv, "r"))) {
        !            37:                                fprintf (stderr, "ideal sorter: can't open %s\n", *argv);
        !            38:                                exit (1);
        !            39:                        }
        !            40:                        filename = *argv;
        !            41:                        lineno = 0;
        !            42:                        interpret (infile);
        !            43:                        fclose (infile);
        !            44:                }
        !            45:        }
        !            46:        exit (0);
        !            47: }
        !            48: 
        !            49: interpret (infile)
        !            50: register FILE *infile;
        !            51: {
        !            52:        char buf[250];
        !            53: 
        !            54:        int numitems;
        !            55:        char cmd[10];
        !            56:        int i[10];
        !            57:        float f[30];
        !            58:        char *string;
        !            59:        boolean indots;
        !            60: 
        !            61: 
        !            62:        indots = FALSE;
        !            63:        while (fgets (buf, sizeof buf, infile)) {
        !            64:                if (!indots) {
        !            65:                        fputs (buf, stdout);
        !            66:                        if (strncmp(buf,".IS",3) == 0) {
        !            67:                                indots = TRUE;
        !            68:                                maxxset = minxset = maxyset = minyset = FALSE;
        !            69:                                colset = boundset = widset = FALSE;
        !            70:                                boundset = FALSE;
        !            71:                                tempfile = fopen ("jUnKfOo", "w");
        !            72:                        }
        !            73:                } else {
        !            74:                        if (strncmp(buf,"...line",7)) {
        !            75:                                if (!strncmp(buf,".IE",3) || !strncmp(buf,".IF",3)) {
        !            76:                                        idendE ();
        !            77:                                        indots = FALSE;
        !            78:                                }
        !            79:                                fputs (buf, stdout);
        !            80:                                if (!boundset) {
        !            81:                                        if (strcmp (cmd, "...maxx") == 0) {
        !            82:                                                sscanf (buf, "%s %f", cmd, &f[0]);
        !            83:                                                idmaxx (f[0]);
        !            84:                                        } else if (strcmp (cmd, "...maxy") == 0) {
        !            85:                                                sscanf (buf, "%s %f", cmd, &f[0]);
        !            86:                                                idmaxy (f[0]);
        !            87:                                        } else if (strcmp (cmd, "...minx") == 0) {
        !            88:                                                sscanf (buf, "%s %f", cmd, &f[0]);
        !            89:                                                idminx (f[0]);
        !            90:                                        } else if (strcmp (cmd, "...miny") == 0) {
        !            91:                                                sscanf (buf, "%s %f", cmd, &f[0]);
        !            92:                                                idminy (f[0]);
        !            93:                                        } else if (strcmp (cmd, "...width") == 0) {
        !            94:                                                sscanf (buf, "%s %f", cmd, &f[0]);
        !            95:                                                idwidth (f[0]);
        !            96:                                        } else if (strcmp (cmd, "...colwid") == 0) {
        !            97:                                                sscanf (buf, "%s %f", cmd, &f[0]);
        !            98:                                                idcolwid (f[0]);
        !            99:                                        } else if (strcmp (cmd, "...obbox") == 0) {
        !           100:                                                if (!veryfirst) {
        !           101:                                                        maxxset = maxyset = TRUE;
        !           102:                                                        minxset = minyset = TRUE;
        !           103:                                                        boundset = TRUE;
        !           104:                                                }
        !           105:                                        } else {
        !           106:                                                idendbound ();
        !           107:                                                veryfirst = FALSE;
        !           108:                                        }
        !           109:                                }
        !           110:                        } else {
        !           111:                                if (!boundset)
        !           112:                                        idendbound();
        !           113:                                sscanf (buf, "%s %f %f %f %f", cmd, &f[0], &f[1], &f[2], &f[3]);
        !           114:                                idline (f[0], f[1], f[2], f[3]);
        !           115:                        }
        !           116:                }
        !           117:        }
        !           118: }
        !           119: 
        !           120: void idmaxx (x)
        !           121: float x;
        !           122: {
        !           123:        if (!maxxset) {
        !           124:                maxx = x;
        !           125:                maxxset = TRUE;
        !           126:        }
        !           127: }
        !           128: 
        !           129: void idmaxy (y)
        !           130: float y;
        !           131: {
        !           132:        if (!maxyset) {
        !           133:                maxy = y;
        !           134:                maxyset = TRUE;
        !           135:        }
        !           136: }
        !           137: 
        !           138: void idminx (x)
        !           139: float x;
        !           140: {
        !           141:        if (!minxset) {
        !           142:                minx = x;
        !           143:                minxset = TRUE;
        !           144:        }
        !           145: }
        !           146: 
        !           147: void idminy (y)
        !           148: float y;
        !           149: {
        !           150:        if (!minyset) {
        !           151:                miny = y;
        !           152:                minyset = TRUE;
        !           153:        }
        !           154: }
        !           155: 
        !           156: void idwidth (wid)
        !           157: float wid;
        !           158: {
        !           159:        if (!widset) {
        !           160:                width = wid;
        !           161:                widset = TRUE;
        !           162:        }
        !           163: }
        !           164: 
        !           165: void idcolwid (wid)
        !           166: float wid;
        !           167: {
        !           168:        if (!colset) {
        !           169:                colwid = wid;
        !           170:                colset = TRUE;
        !           171:        }
        !           172: }
        !           173: 
        !           174: void idendbound ()
        !           175: {
        !           176:        if (boundset)
        !           177:                return;
        !           178:        idminx (-6.0);
        !           179:        idmaxy (6.0);
        !           180:        idmaxx (6.0);
        !           181:        idminy (-6.0);
        !           182:        if (maxx - minx < 0.2) {
        !           183:                maxx += 1;
        !           184:                minx -= 1;
        !           185:        }
        !           186:        if (maxy - miny < 0.2) {
        !           187:                maxy += 1;
        !           188:                miny -= 1;
        !           189:        }
        !           190:        xscale = width*972.0/(maxx - minx);
        !           191:        boundset = TRUE;
        !           192: }
        !           193: 
        !           194: void idendE ()
        !           195: {
        !           196:        char c;
        !           197:        fclose (tempfile);
        !           198:        system ("sort +2 -r -n -o jUnKfOo jUnKfOo");
        !           199:        tempfile = fopen ("jUnKfOo", "r");
        !           200:        while ((c = getc(tempfile)) != EOF)
        !           201:                putchar(c);
        !           202:        fclose (tempfile);
        !           203:        system ("rm jUnKfOo");
        !           204: }
        !           205: 
        !           206: 
        !           207: void idline (x1, y1, x2, y2)
        !           208: float x1, y1, x2, y2;
        !           209: {
        !           210:        double t;
        !           211:        int numsegs, i;
        !           212:        if (y1 < y2 ) {
        !           213:                t = x1;
        !           214:                x1 = x2;
        !           215:                x2 = t;
        !           216:                t = y1;
        !           217:                y1 = y2;
        !           218:                y2 = t;
        !           219:        }
        !           220:        numsegs = xscale*abs(y2-y1)/250;
        !           221:        if (numsegs <= 0) numsegs = 1;
        !           222:        for (i = 0; i < numsegs; i ++)
        !           223:                fprintf (tempfile, "...line %f %f %f %f\n",
        !           224:                        x1 + i*(x2-x1)/numsegs,
        !           225:                        y1 + i*(y2-y1)/numsegs,
        !           226:                        x1 + (i+1)*(x2-x1)/numsegs,
        !           227:                        y1 + (i+1)*(y2-y1)/numsegs
        !           228:                );
        !           229: }

unix.superglobalmegacorp.com

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