void setcolwidth(int col) /* Sets the new column width for a selected column */ { int width, row; writeprompt(MSGCOLWIDTH); if (!getint(&width, MINCOLWIDTH, MAXCOLWIDTH)) return; colwidth[col] = width; setrightcol(); if (rightcol < col) { rightcol = col; setleftcol(); setrightcol(); } for (row = 0; row <= lastrow; row++) { if ((cell[col][row] != NULL) && (cell[col][row]->attrib == TEXT)) clearoflags(col + 1, row, NOUPDATE); else clearoflags(col, row, NOUPDATE); updateoflags(col, row, NOUPDATE); } displayscreen(NOUPDATE); changed = TRUE; } /* setcolwidth */
void redrawscreen(void) /* Displays the entire screen */ { setrightcol(); setbottomrow(); writef(1, 1, MSGMEMORYCOLOR, strlen(MSGMEMORY), MSGMEMORY); writef(29, 1, PROMPTCOLOR, strlen(MSGCOMMAND), MSGCOMMAND); changeautocalc(autocalc); changeformdisplay(formdisplay); printfreemem(); displayscreen(NOUPDATE); } /* redrawscreen */
void gotocell() /* Moves to a selected cell */ { writeprompt(MSGGOTO); if (!getcell(&curcol, &currow)) return; leftcol = curcol; toprow = currow; setbottomrow(); setrightcol(); setleftcol(); displayscreen(NOUPDATE); } /* gotocell */
void umenu(void) /* Executes the commands in the utility menu */ { switch(getcommand(UMENU, UCOMMAND)) { case 0 : recalc(); break; case 1 : changeformdisplay(!formdisplay); displayscreen(UPDATE); break; } /* switch */ } /* umenu */
void recalc(void) /* Recalculates all of the numbers in the speadsheet */ { int col, row, dummy; for (col = 0; col <= lastcol; col++) { for (row = 0; row <= lastrow; row++) { if ((cell[col][row] != NULL) && (cell[col][row]->attrib == FORMULA)) cell[col][row]->v.f.fvalue = parse(cell[col][row]->v.f.formula, &dummy); } } displayscreen(UPDATE); } /* recalc */
void clearsheet(void) /* Clears the current spreadsheet */ { int col, row; for (row = 0; row <= lastrow; row++) { for (col = 0; col <= lastcol; col++) deletecell(col, row, NOUPDATE); } initvars(); setrightcol(); setbottomrow(); displayscreen(NOUPDATE); printfreemem(); changed = FALSE; } /* clearsheet */
void loadsheet(char *filename) /* Loads a new spreadsheet */ { int size, allocated, reallastcol = 0, reallastrow = 0, file; char check[81]; if (filename[0] == 0) { writeprompt(MSGFILENAME); if (!editstring(filename, "", MAXINPUT)) return; } if (access(filename, 0)) { errormsg(MSGNOEXIST); return; } if ((file = open(filename, O_RDWR | O_BINARY)) == -1) { errormsg(MSGNOOPEN); return; } read(file, check, strlen(name) + 1); if (strcmp(check, name) != 0) { errormsg(MSGNOTURBOCALC); close(file); return; } writef(1, 25, PROMPTCOLOR, 79, MSGLOADING); gotoxy(strlen(MSGLOADING) + 1, 25); clearsheet(); read(file, (char *)&size, 1); read(file, (char *)&lastcol, 2); read(file, (char *)&lastrow, 2); read(file, (char *)&size, 2); read(file, colwidth, sizeof(colwidth)); do { if (read(file, (char *)&curcol, 2) <= 0) break; read(file, (char *)&currow, 2); read(file, &format[curcol][currow], 1); read(file, (char *)&size, 2); read(file, (char *)&rec, size); switch (rec.attrib) { case TEXT : if ((allocated = alloctext(curcol, currow, rec.v.text)) == TRUE) setoflags(curcol, currow, NOUPDATE); break; case VALUE : allocated = allocvalue(curcol, currow, rec.v.value); break; case FORMULA : allocated = allocformula(curcol, currow, rec.v.f.formula, rec.v.f.fvalue); break; } /* switch */ if (!allocated) { errormsg(MSGFILELOMEM); lastrow = reallastrow; lastcol = reallastcol; format[curcol][currow] = DEFAULTFORMAT; break; } else { if (curcol > reallastcol) reallastcol = curcol; if (currow > reallastrow) reallastrow = currow; } } while (TRUE); writef(1, 25, WHITE, strlen(MSGLOADING), ""); gotoxy(1, 25); printfreemem(); close(file); curcol = currow = 0; setrightcol(); displayscreen(NOUPDATE); changed = FALSE; } /* loadsheet */