Annotation of researchv10no/cmd/pico/other.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <signal.h>
        !             3: #include "pico.h"
        !             4: 
        !             5: extern short   CUROLD, CURSCRATCH;
        !             6: extern struct  SRC src[MANY];
        !             7: extern char    linenumber;
        !             8: extern FILE    *INPUT;
        !             9: extern int     nsrc;
        !            10: extern int     DEF_LL, DEF_NL;
        !            11: 
        !            12: Usage(s)
        !            13:        char *s;
        !            14: {
        !            15:        if (strlen(s) > 0)
        !            16:        fprintf(stderr, "pico: %s\n", s);
        !            17:        fprintf(stderr, "usage: pico -fto -m[0-9] -wN -hN [filenames]\n");
        !            18:        fprintf(stderr, "\t-f   open framebuffer display (kwee)\n");
        !            19:        fprintf(stderr, "\t-m[012..]    open metheus display /dev/om[012..]\n");
        !            20:        fprintf(stderr, "\t-t   show parse trees\n");
        !            21:        fprintf(stderr, "\t-o   turn off optimizer\n");
        !            22:        fprintf(stderr, "\t-wN  set width work buffer to N pel\n");
        !            23:        fprintf(stderr, "\t-hN  set depth work buffer to N pel\n");
        !            24:        exit(1);
        !            25: }
        !            26: 
        !            27: whatarray(inname)
        !            28:        char *inname;
        !            29: {
        !            30:        int i, j, k;
        !            31: 
        !            32:        j = findbase(inname);
        !            33:        for (i = 2; i < nsrc; i++)
        !            34:        {       k = findbase(src[i].fname);
        !            35:                if (strcmp(&inname[j], &src[i].fname[k]) == 0)
        !            36:                        return i;
        !            37:        }
        !            38:        return -1;
        !            39: }
        !            40: 
        !            41: findbase(inname)
        !            42:        char *inname;
        !            43: {
        !            44:        int i = strlen(inname)+1;
        !            45: 
        !            46:        while (--i > 0)
        !            47:                if (inname[i] == '/')
        !            48:                        return i+1;
        !            49:        return 0;
        !            50: }
        !            51: 
        !            52: wsize(a,b,c,d) { fprintf(stderr, "(%d,%d,%d,%d)\n", a,b,c,d); }
        !            53: 
        !            54: files()
        !            55: {      int i;
        !            56: 
        !            57:        fprintf(stderr, "$0:\told\t");
        !            58:        fprintf(stderr, "%s\t\t", (src[CUROLD].nchan >= 3)?"color" : "b&w  ");
        !            59:        fprintf(stderr, "%s\t",  (src[CUROLD].incore==2)?"resident" : "absent  ");
        !            60:        wsize(src[CUROLD].sx, src[CUROLD].sy, src[CUROLD].ex, src[CUROLD].ey);
        !            61:        if (nsrc==2) fprintf(stderr, "no files open\n");
        !            62:        for (i = 2; i < nsrc; i++)
        !            63:        {       fprintf(stderr, "$%d:\t%s\t", i-1, src[i].fname);
        !            64:                if (strcmp(src[i].fname, " empty") == 0)
        !            65:                {       fprintf(stderr, "\n");
        !            66:                        continue;
        !            67:                }
        !            68:                fprintf(stderr, "%s  ",  (src[i].nchan >= 3)?"color":"b&w  ");
        !            69:                fprintf(stderr, "%s ",  (src[i].incore==2)? "resident":"absent  ");
        !            70:                fprintf(stderr, "xo %d yo %d ", src[i].ox, src[i].oy);
        !            71:                fprintf(stderr, "ll %d nl %d ", src[i].ll, src[i].nl);
        !            72:                wsize(src[i].sx, src[i].sy, src[i].ex, src[i].ey);
        !            73:        }
        !            74: }
        !            75: 
        !            76: char *
        !            77: Emalloc(N)
        !            78:        unsigned N;
        !            79: {
        !            80:        char *try, *malloc();
        !            81:        if ((try = malloc(N)) == NULL)
        !            82:                whoops("out of memory");
        !            83:        return try;
        !            84: }
        !            85: 
        !            86: whoops(s)
        !            87:        char *s;
        !            88: {
        !            89:        fprintf(stderr, "pico: fatal error `%s'\n", s);
        !            90:        exit(1);
        !            91: }
        !            92: 
        !            93: append(n, m, k, l, s)
        !            94:        char *s;
        !            95: {      int i, reopened=0;
        !            96: 
        !            97:        if ((i = whatarray(s)) >= 2 && strcmp(s, src[i].fname) == 0)
        !            98:        {       lseek(src[i].fd, src[i].sop, 0);
        !            99:                reopened = 1;
        !           100:        } else
        !           101:                i = prepare(s);
        !           102: 
        !           103:        if (i < 2) return 0;
        !           104: 
        !           105:        src[i].ox = src[i].oy = 0;
        !           106:        if (n > 0)
        !           107:        {       src[i].sx = src[i].sx - n;
        !           108:                if (src[i].sx < 0)
        !           109:                {       src[i].ox = min(src[i].ll, -src[i].sx);
        !           110:                        src[i].sx = 0;
        !           111:                }
        !           112:        } else  src[i].sx = min(DEF_LL, src[i].sx - n);
        !           113: 
        !           114:        if (m > 0)
        !           115:        {       src[i].sy = src[i].sy - m;
        !           116:                if (src[i].sy < 0)
        !           117:                {       src[i].oy = min(src[i].nl, -src[i].sy);
        !           118:                        src[i].sy = 0;
        !           119:                }
        !           120:        } else  src[i].sy = min(DEF_LL, src[i].sy - m);
        !           121: 
        !           122:        if (k > 0) src[i].ll = k;
        !           123:        if (l > 0) src[i].nl = l;
        !           124: 
        !           125:        src[i].ex = min(DEF_LL, src[i].sx + src[i].ll - src[i].ox);
        !           126:        src[i].ey = min(DEF_NL, src[i].sy + src[i].nl - src[i].oy);
        !           127: 
        !           128:        if (reopened && src[i].incore==2)
        !           129:                src[i].incore = 1;
        !           130: 
        !           131:        return i;
        !           132: }
        !           133: 
        !           134: setwindow(a, b, c, d)
        !           135: {
        !           136:        int e = min(DEF_LL, a+c);
        !           137:        int f = min(DEF_NL, b+d);
        !           138: 
        !           139:        (Old)->sx = (Scratch)->sx = a;
        !           140:        (Old)->sy = (Scratch)->sy = b;
        !           141:        (Old)->ex = (Scratch)->ex = e;
        !           142:        (Old)->ey = (Scratch)->ey = f;
        !           143:        setmid();
        !           144: }

unix.superglobalmegacorp.com

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