void showcelltype(void) /* Prints the type of cell and what is in it */ { char colstr[3], *s; int color; formdisplay = !formdisplay; s = cellstring(curcol, currow, &color, NOFORMAT); colstring(curcol, colstr); if (curcell == NULL) writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGEMPTY); else switch(curcell->attrib) { case TEXT : writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGTEXT); break; case VALUE : writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGVALUE); break; case FORMULA : writef(1, 23, CELLTYPECOLOR, 80, "%s%d %s", colstr, currow + 1, MSGFORMULA); break; } /* switch */ writef(1, 24, CELLCONTENTSCOLOR, 80, "%s", s); formdisplay = !formdisplay; } /* showcelltype */
void centercolstring(int col, char *colstr) /* Changes a column to a centered string */ { char s[3]; int spaces1, spaces2; colstring(col, s); spaces1 = (colwidth[col] - strlen(s)) >> 1; spaces2 = colwidth[col] - strlen(s) - spaces1; sprintf(colstr, "%*s%s%*s", spaces1, "", s, spaces2, ""); } /* centercolstring */
void fixformula(int col, int row, int action, int place) /* Modifies a formula when its column or row designations need to change. */ { char *colstart, *rowstart, s[6], newformula[MAXINPUT + 1], *curpos = newformula; int fcol, frow; CELLPTR cellptr = cell[col][row]; double value; strcpy(newformula, cellptr->v.f.formula); while (*curpos != 0) { if (formulastart(&curpos, &fcol, &frow)) { rowstart = curpos - rowwidth(frow); colstart = rowstart - ((fcol > 25) ? 2 : 1); switch (action) { case COLADD : if (fcol < place) break; if (fcol == 25) { if (strlen(newformula) == MAXINPUT) { deletecell(col, row, NOUPDATE); alloctext(col, row, newformula); return; } movmem(colstart, colstart + 1, strlen(colstart) + 1); } colstring(fcol + 1, s); movmem(s, colstart, strlen(s)); break; case ROWADD : if (frow < place) break; if (rowwidth(frow + 1) != rowwidth(frow)) { if (strlen(newformula) == MAXINPUT) { deletecell(col, row, NOUPDATE); alloctext(col, row, newformula); return; } movmem(rowstart, rowstart + 1, strlen(rowstart) + 1); } sprintf(s, "%d", frow + 2); movmem(s, rowstart, strlen(s)); break; case COLDEL : if (fcol <= place) break; if (fcol == 26) movmem(colstart + 1, colstart, strlen(colstart) + 1); colstring(fcol - 1, s); movmem(s, colstart, strlen(s)); break; case ROWDEL : if (frow <= place) break; if (rowwidth(frow) != rowwidth(frow - 1)) movmem(rowstart + 1, rowstart, strlen(rowstart) + 1); sprintf(s, "%d", frow); movmem(s, rowstart, strlen(s)); break; } /* switch */ } else curpos++; } if (strlen(newformula) != strlen(cellptr->v.f.formula)) { value = cellptr->v.f.fvalue; deletecell(col, row, NOUPDATE); allocformula(col, row, newformula, value); } else strcpy(cellptr->v.f.formula, newformula); } /* fixformula */