Annotation of researchv10no/cmd/visi/macros.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *      macros.c 1.8
        !             3:  *
        !             4:  *     Screen Handling Functions for Spreadsheet Program `vis'
        !             5:  *
        !             6:  *      A. F. Gettier
        !             7:  *      Bell Laboratories
        !             8:  *      Update made 11/15/82 10:50:58
        !             9:  *      Retrieved 11/15/82 13:22:33
        !            10:  */
        !            11: #include       <math.h>
        !            12: #include       <stdio.h>
        !            13: #include       "curses.h"
        !            14: #include       "vis.h"
        !            15: 
        !            16: extern int     LINES, COLS;
        !            17: extern struct qheader  Fixup;
        !            18: 
        !            19: extern struct colhdr   Col;
        !            20: extern struct rowhdr   Row;
        !            21: 
        !            22: /*
        !            23:  *     duplicate a block of definitions
        !            24:  */
        !            25: duplicate( fr, fc, tr, tc, ar, ac )
        !            26: int    fr, fc, tr, tc, ar, ac;
        !            27: {
        !            28:        char    tbuf[128];
        !            29:        int     i, or, oc, nr, nc;
        !            30:        struct rowlabel **r1;
        !            31:        struct node     *n, *n2;
        !            32:        /*
        !            33:         *      get the row offset
        !            34:         */
        !            35:        or = ar - fr;
        !            36:        oc = ac - fc;
        !            37:        /*
        !            38:         *      Now make all the copies
        !            39:         */
        !            40:        r1 = Row.table;
        !            41:        for ( i=fr; i<=tr && i<Row.size; i++ ) {
        !            42:                n = r1[i]->next;
        !            43:                while ( n != 0 ) {
        !            44:                        if ( n->col > tc )  break;
        !            45:                        if ( n->col >= fc ) {
        !            46:                                nr =  n->row + or;
        !            47:                                nc =  n->col + oc;
        !            48:                                n2 = getnode( nr, nc );
        !            49:                                (void)strcat(strcpy( tbuf, makevar( nr, nc ) ),
        !            50:                                    strchr( n->def, '=' ));
        !            51:                                n2->def = copystr( tbuf );
        !            52:                                qadd( &Fixup, n2 );
        !            53:                        }
        !            54:                        n = n->next;
        !            55:                }
        !            56:        }
        !            57: }
        !            58: 
        !            59: /*
        !            60:  *     replicate a block of definitions
        !            61:  */
        !            62: replicate( ar, ac, fr, fc, tr, tc )
        !            63: int    ar, ac, fr, fc, tr, tc;
        !            64: {
        !            65:        char    tbuf[128], *defin;
        !            66:        int     i, j;
        !            67:        struct node     *n;
        !            68:        /*
        !            69:         *      Is there a def to be copied
        !            70:         */
        !            71:        n = getnode( ar, ac );
        !            72:        if ( n->def == 0 )  {
        !            73:                (void)sprintf( tbuf, "Not previous definition at %s", 
        !            74:                    makevar( ar, ac ) );
        !            75:                yyerror( tbuf );
        !            76:                lexinit();
        !            77:        }
        !            78:        /*
        !            79:         *      get the definition part
        !            80:         */
        !            81:        defin = strchr( n->def, '=' );
        !            82:        if ( defin == 0 )  {
        !            83:                (void)sprintf( tbuf, "Bug in the definition at %s", 
        !            84:                    makevar( ar, ac ) );
        !            85:                yyerror( tbuf );
        !            86:                lexinit();
        !            87:        }
        !            88:        /*
        !            89:         *      Now make all the copies
        !            90:         */
        !            91:        for ( i=fr; i<=tr; i++ ) {
        !            92:                for ( j=fc; j<=tc; j++ ) {
        !            93:                        n = getnode( i, j );
        !            94:                        (void)strcat(strcpy( tbuf, makevar( i, j ) ), defin );
        !            95:                        n->def = copystr( tbuf );
        !            96:                        qadd( &Fixup, n );
        !            97:                }
        !            98:        }
        !            99: }
        !           100: 
        !           101: /*
        !           102:  *     Convert from a row and column format to a character string
        !           103:  */
        !           104: char *
        !           105: makevar( row, col )
        !           106: int    row, col;
        !           107: {
        !           108:        static char     buf[16];
        !           109:        int     i;
        !           110:        /*
        !           111:         *      and the letters on the vertical
        !           112:         */
        !           113:        i = col / 26;
        !           114:        if ( i > 0 )  i += 'A' - 1;
        !           115:        else i = ' ';
        !           116:        col =  col % 26 + 'A';
        !           117:        (void)sprintf( buf, "%c%c%d", i, col, row+1 );
        !           118:        return( buf );
        !           119: }
        !           120: 
        !           121: /*
        !           122:  *     List the HELP to the Terminal
        !           123:  */
        !           124: listhelp()
        !           125: {
        !           126:        int     cnt;
        !           127:        char    tbuf[128];
        !           128:        FILE    *fp;
        !           129:        WINDOW  *listwin;
        !           130: 
        !           131:        if ( (fp=fopen( HELPFILE, "r" )) == 0 ) {
        !           132:                (void)sprintf( tbuf, "Cannot open HELPFILE (%s)", HELPFILE );
        !           133:                yyerror( tbuf );
        !           134:                return;
        !           135:        }
        !           136:        listwin = newwin( LINES, COLS, 0, 0 );
        !           137:        wmove( listwin, 0, 0 );
        !           138:        wclear( listwin );
        !           139:        wrefresh( listwin );
        !           140:        loop {
        !           141:                werase( listwin );
        !           142:                for( cnt=0; cnt<LINES-2; cnt++ ) {
        !           143:                        if ( fgets( tbuf, 80, fp ) == NULL )  break;
        !           144:                        if( tbuf[0] == '\f' )  break;
        !           145:                        wmove( listwin, cnt, 0 );
        !           146:                        (void)wprintw( listwin, "%s", tbuf );
        !           147:                }
        !           148:                if ( cnt == 0 ) break;
        !           149:                wmove( listwin, LINES-2, (COLS-25)/2 );
        !           150:                wstandout( listwin );
        !           151:                (void)wprintw(listwin,"PRESS <RETURN> WHEN READY");
        !           152:                wstandend( listwin );
        !           153:                wrefresh( listwin );
        !           154:                wgetstr(  listwin, tbuf );
        !           155:        }
        !           156:        delwin( listwin );
        !           157:        touchwin( stdscr );
        !           158: }
        !           159: 
        !           160: /*
        !           161:  *     edit the definitions file
        !           162:  */
        !           163: editfile()
        !           164: {
        !           165:        FILE    *fp;
        !           166:        char    *file, bfr[128], *editor;
        !           167: 
        !           168: 
        !           169:        clear();
        !           170:        move( 0, 25 );
        !           171:        standout( );
        !           172:        printw( "Entering Editor, Please Wait" );
        !           173:        standend( );
        !           174:        move( 1, 0 );
        !           175:        refresh();
        !           176:        file = mktemp("/tmp/visXXXXXX");
        !           177: 
        !           178:        /*
        !           179:         *      Write the definitions out
        !           180:         */
        !           181: 
        !           182:        refresh();
        !           183:        if ( (fp=fopen( file, "w" )) == 0 ) {
        !           184:                char    errbuf[64];
        !           185:                (void)sprintf( errbuf, "Cannot open '%s'", file );
        !           186:                yyerror( errbuf );
        !           187:                lexinit();
        !           188:                return;
        !           189:        }
        !           190: 
        !           191:        else dumpfile( fp );
        !           192: 
        !           193:        (void)fclose( fp );
        !           194: 
        !           195:        /*
        !           196:         *      zero out the current definitions
        !           197:         */
        !           198: 
        !           199:        zerodef();
        !           200: 
        !           201:        /*
        !           202:         *      edit the file
        !           203:         */
        !           204: 
        !           205:        editor = getenv( "ED" );
        !           206: 
        !           207:        if ( editor == 0 || *editor == '\0' )
        !           208:                (void)sprintf( bfr, "ed %s", file );
        !           209:        else
        !           210:                (void)sprintf( bfr, "%s %s", editor, file );
        !           211: 
        !           212:        resetty();
        !           213:        (void)system( bfr );
        !           214:        noecho();
        !           215:        crmode();
        !           216: 
        !           217:        /*
        !           218:         *      clean up the screen
        !           219:         */
        !           220: 
        !           221:        clear();
        !           222:        prheading();
        !           223:        refresh();
        !           224: 
        !           225:        /*
        !           226:         *      Read in the new definitions
        !           227:         */
        !           228: 
        !           229:        if ( (fp=fopen( file, "r" )) == 0 ) {
        !           230:                char    errbuf[64];
        !           231:                (void)sprintf( errbuf, "Cannot open '%s'", file );
        !           232:                yyerror( errbuf );
        !           233:                lexinit();
        !           234:        }
        !           235:        else readfile( fp );
        !           236:        (void)unlink( file );
        !           237: }
        !           238: 
        !           239: quit()
        !           240: {
        !           241:        move( LINES-1, 0 );
        !           242:        clrtoeol();
        !           243:        refresh();
        !           244:        endwin();
        !           245:        resetty();
        !           246:        exit( 0 );
        !           247: }

unix.superglobalmegacorp.com

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