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 movecolright(void) /* Moves right one column */ { int col, oldleftcol, oldrightcol; unsigned char oldcolstart[SCREENCOLS]; movmem(colstart, oldcolstart, sizeof(colstart)); oldleftcol = leftcol; oldrightcol = rightcol; displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE); if (curcol < rightcol) curcol++; else if (rightcol < (MAXCOLS - 1)) { curcol++; rightcol++; setleftcol(); setrightcol(); if (oldrightcol >= leftcol) scroll(LEFT, oldcolstart[leftcol - oldleftcol] - LEFTMARGIN, LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE); clearlastcol(); for (col = oldrightcol + 1; col <= rightcol; col++) displaycol(col, NOUPDATE); } } /* movecolright */
void movecolleft(void) /* Moves left one column */ { int col, oldleftcol; unsigned char oldcolstart[SCREENCOLS]; oldleftcol = leftcol; movmem(colstart, oldcolstart, sizeof(colstart)); displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE); if (curcol > leftcol) curcol--; else if (leftcol != 0) { curcol--; leftcol--; setrightcol(); setleftcol(); if (oldleftcol <= rightcol) scroll(RIGHT, colstart[oldleftcol - leftcol] - LEFTMARGIN, LEFTMARGIN + 1, 3, 80, SCREENROWS + 2, WHITE); clearlastcol(); for (col = leftcol; col <= oldleftcol - 1; col++) displaycol(col, NOUPDATE); } } /* movecolleft */
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 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 insertcol(int col) /* Inserts a column */ { int counter, row; if (lastcol == MAXCOLS - 1) { for (counter = 0; counter <= lastrow; counter++) deletecell(lastcol, counter, NOUPDATE); printfreemem(); } if (col != MAXCOLS - 1) { movmem(&cell[col][0], &cell[col + 1][0], MAXROWS * sizeof(CELLPTR) * (MAXCOLS - col - 1)); movmem(&format[col][0], &format[col + 1][0], MAXROWS * (MAXCOLS - col - 1)); movmem(&colwidth[col], &colwidth[col + 1], MAXCOLS - col - 1); } setmem(&cell[col][0], MAXROWS * sizeof(CELLPTR), 0); setmem(&format[col][0], MAXROWS, DEFAULTFORMAT); colwidth[col] = DEFAULTWIDTH; lastcol = MAXCOLS - 1; setlastcol(); setrightcol(); if (curcol > rightcol) { rightcol++; setleftcol(); } for (counter = 0; counter <= lastcol; counter++) { for (row = 0; row <= lastrow; row++) { if ((cell[counter][row] != NULL) && (cell[counter][row]->attrib == FORMULA)) fixformula(counter, row, COLADD, col); updateoflags(col, row, NOUPDATE); } } while (col <= rightcol) displaycol(col++, NOUPDATE); changed = TRUE; recalc(); } /* insertcol */
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 */