|
|
1.1 ! root 1: /* ! 2: * nodes.c 1.5 ! 3: * ! 4: * Node Handling Functions for Spreadsheet Program `vis' ! 5: * ! 6: * A. F. Gettier ! 7: * Bell Laboratories ! 8: * Update made 11/3/82 02:08:13 ! 9: * Retrieved 11/15/82 13:22:35 ! 10: */ ! 11: #include <stdio.h> ! 12: #include <math.h> ! 13: #include "curses.h" ! 14: #include "vis.h" ! 15: ! 16: static struct node BLANKNODE={-1,-1,UNRES,0,0,0,0,0,0}; ! 17: ! 18: extern int Width; ! 19: extern int Scale; ! 20: extern struct rowhdr Row; ! 21: extern struct colhdr Col; ! 22: extern struct qheader Fixup; ! 23: ! 24: /* ! 25: * get a node for reading - returns undef ! 26: * if not present ! 27: */ ! 28: struct node * ! 29: getnode( row, col ) ! 30: int row, col; ! 31: { ! 32: struct rowlabel **r1; ! 33: struct node *n1, *n2, *n3; ! 34: /* ! 35: * Is the row for the new node there? ! 36: */ ! 37: if ( Row.size <= row ) rowexpand( row ); ! 38: /* ! 39: * Is the col for the new node there? ! 40: */ ! 41: if ( Col.size <= col ) colexpand( col ); ! 42: /* ! 43: * Get the table addresses ! 44: */ ! 45: r1 = Row.table; ! 46: /* ! 47: * Is the node present at the first ! 48: * location? ! 49: */ ! 50: n1 = r1[row]->next; ! 51: if ( n1 == 0 || n1->col > col ) { ! 52: r1[row]->next = n2 = newnode( row, col ); ! 53: n2->next = n1; ! 54: n2->type = UNDEF; ! 55: n2->def = 0; ! 56: return( n2 ); ! 57: } ! 58: /* ! 59: * Look Harder!! ! 60: */ ! 61: while ( n1 != 0 && n1->col <= col ) { ! 62: if ( n1->col == col ) return( n1 ); ! 63: n2 = n1; ! 64: n1 = n1->next; ! 65: } ! 66: n3 = newnode( row, col ); ! 67: n3->next = n1; ! 68: n2->next = n3; ! 69: n3->type = UNDEF; ! 70: n3->def = 0; ! 71: return( n3 ); ! 72: } ! 73: /* ! 74: * Make a new unresolved node ! 75: */ ! 76: struct node * ! 77: newnode( row, col ) ! 78: int row, col; ! 79: { ! 80: struct node *n; ! 81: n = NODE( node ); ! 82: n->row = row; ! 83: n->col = col; ! 84: n->type = UNRES; ! 85: n->value = 0; ! 86: n->def = 0; ! 87: n->svalue = 0; ! 88: n->next = 0; ! 89: qinit( &(n->depend) ); ! 90: return( n ); ! 91: } ! 92: /* ! 93: * mathop - do the math operation type checking, and return a ! 94: * blank node ! 95: */ ! 96: struct node ! 97: mathop( n1, n2 ) ! 98: struct node *n1, *n2; ! 99: { ! 100: struct node n; ! 101: n = BLANKNODE; ! 102: if ( n1->type == NUM && n2->type == NUM ) { ! 103: n.type = NUM; ! 104: } ! 105: else { ! 106: if ( n1->row == -1 && n1->type == STRING ) ! 107: free( n1->svalue ); ! 108: if ( n2->row == -1 && n2->type == STRING ) ! 109: free( n2->svalue ); ! 110: } ! 111: return( n ); ! 112: } ! 113: ! 114: /* ! 115: * List the definitions to the Terminal ! 116: */ ! 117: listfile() ! 118: { ! 119: int i, cnt; ! 120: char tbuf[128]; ! 121: struct node *x; ! 122: struct rowlabel **r1; ! 123: WINDOW *listwin; ! 124: listwin = newwin( LINES, COLS, 0, 0 ); ! 125: wmove( listwin, 0, 0 ); ! 126: wclear( listwin ); ! 127: wrefresh( listwin ); ! 128: cnt = 2; ! 129: r1 = Row.table; ! 130: for ( i=0; i<Row.size; i++ ) { ! 131: x = r1[i]->next; ! 132: while ( x != 0 ) { ! 133: if ( x->def == 0 ) { ! 134: x = x->next; ! 135: continue; ! 136: } ! 137: (void)wprintw( listwin, "%s\n", x->def ); ! 138: x = x->next; ! 139: if ( ++cnt < LINES ) continue; ! 140: cnt = 2; ! 141: wmove( listwin, LINES-2, (COLS-25)/2 ); ! 142: wstandout( listwin ); ! 143: (void)wprintw(listwin,"PRESS <RETURN> WHEN READY"); ! 144: wstandend(listwin); ! 145: wrefresh( listwin ); ! 146: wgetstr( listwin, tbuf ); ! 147: werase( listwin ); ! 148: wmove( listwin, 0, 0 ); ! 149: } ! 150: } ! 151: if ( cnt > 0 ) { ! 152: wmove( listwin, LINES-2, (COLS-25)/2 ); ! 153: wstandout( listwin ); ! 154: (void)wprintw(listwin,"PRESS <RETURN> WHEN READY"); ! 155: wstandend(listwin); ! 156: wrefresh( listwin ); ! 157: wgetstr( listwin, tbuf ); ! 158: } ! 159: delwin( listwin ); ! 160: touchwin( stdscr ); ! 161: } ! 162: ! 163: /* ! 164: * Dump the definitions to a file ! 165: */ ! 166: dumpfile( fp ) ! 167: FILE *fp; ! 168: { ! 169: int i; ! 170: struct node *x; ! 171: struct rowlabel **r1; ! 172: r1 = Row.table; ! 173: for ( i=0; i<Row.size; i++ ) { ! 174: x = r1[i]->next; ! 175: while ( x != 0 ) { ! 176: if ( x->def != 0 ) ! 177: (void)fprintf( fp, "%s\n", x->def ); ! 178: x = x->next; ! 179: } ! 180: } ! 181: } ! 182: ! 183: /* ! 184: * Zero all current the definitions ! 185: */ ! 186: zerodef() ! 187: { ! 188: int i; ! 189: struct node *x, *y; ! 190: struct rowlabel **r1; ! 191: r1 = Row.table; ! 192: for ( i=0; i<Row.size; i++ ) { ! 193: x = r1[i]->next; ! 194: while ( x != 0 ) { ! 195: if ( x->def != 0 ) ! 196: free( x->def ); ! 197: if ( x->type == STRING && x->svalue != 0 ) ! 198: free( x->svalue ); ! 199: y = x; ! 200: x = x->next; ! 201: free( (char *)y ); ! 202: } ! 203: r1[i]->next = 0; ! 204: } ! 205: } ! 206: ! 207: /* ! 208: * Expand the number of defined Rows ! 209: */ ! 210: rowexpand( amt ) ! 211: int amt; ! 212: { ! 213: int i,j; ! 214: struct rowlabel **r1, **r2; ! 215: /* ! 216: * check for validity ! 217: */ ! 218: if ( Row.size > amt ) return; ! 219: /* ! 220: * Allocate a new Header ! 221: */ ! 222: r1 = Row.table; ! 223: i = amt + 1; ! 224: r2 = (struct rowlabel **)malloc((unsigned)(i*sizeof(struct rowlabel **))); ! 225: for ( j=0; j<Row.size; j++ ) ! 226: r2[j] = r1[j]; ! 227: for ( j=Row.size; j<i; j++ ) { ! 228: r2[j] = NODE( rowlabel ); ! 229: r2[j]->rownum = j; ! 230: r2[j]->position = 0; ! 231: r2[j]->next = 0; ! 232: } ! 233: free( (char *)r1 ); ! 234: Row.size = i; ! 235: Row.table = r2; ! 236: } ! 237: /* ! 238: * Expand the number of defined Cols ! 239: */ ! 240: colexpand( amt ) ! 241: int amt; ! 242: { ! 243: int i, j; ! 244: struct collabel **c1, **c2; ! 245: /* ! 246: * check for validity ! 247: */ ! 248: if ( Col.size > amt ) return; ! 249: /* ! 250: * Allocate a new Header ! 251: */ ! 252: c1 = Col.table; ! 253: i = amt + 1; ! 254: c2 = (struct collabel **)malloc((unsigned)(i*sizeof(struct collabel **))); ! 255: for ( j=0; j<Col.size; j++ ) ! 256: c2[j] = c1[j]; ! 257: for ( j=Col.size; j<i; j++ ) { ! 258: c2[j] = NODE( collabel ); ! 259: c2[j]->position = 0; ! 260: c2[j]->cell = -1; ! 261: c2[j]->colnum = j; ! 262: c2[j]->width = Width; ! 263: c2[j]->scale = Scale; ! 264: } ! 265: free( (char *)c1 ); ! 266: Col.size = i; ! 267: Col.table = c2; ! 268: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.