/* Reads in a cell name that was typed in - Returns FALSE if ESC was pressed */ int getcell(int *col, int *row) { int first = TRUE, good = FALSE, len, numlen = rowwidth(MAXROWS), oldcol = *col, oldrow = *row; char data[10], *input, *start, numstring[6]; data[0] = 0; do { if (!first) errormsg(MSGBADCELL); first = FALSE; input = data; if (!editstring(data, "", numlen + 2)) { *col = oldcol; *row = oldrow; return(FALSE); } *col = toupper(*(input++)) - 'A'; if (isalpha(*input)) { *col *= 26; *col += toupper(*(input++)) - 'A' + 26; } if (*col >= MAXCOLS) continue; start = input; for (len = 0; len < numlen; len++) { if (!isdigit(*(input++))) { input--; break; } } if (len == 0) continue; strncpy(numstring, start, len); numstring[len] = 0; *row = atoi(numstring) - 1; if ((*row >= MAXROWS) || (*row == -1) || (*input != 0)) continue; good = TRUE; } while (!good); return(TRUE); } /* getcell */
int formulastart(char **input, int *col, int *row) /* Returns TRUE if the string is the start of a formula, FALSE otherwise. Also returns the column and row of the formula. */ { int len, maxlen = rowwidth(MAXROWS); char *start, numstring[10]; if (!isalpha(**input)) return(FALSE); *col = *((*input)++) - 'A'; if (isalpha(**input)) { *col *= 26; *col += *((*input)++) - 'A' + 26; } if (*col >= MAXCOLS) return(FALSE); start = *input; for (len = 0; len < maxlen; len++) { if (!isdigit(*((*input)++))) { (*input)--; break; } } if (len == 0) return(FALSE); strncpy(numstring, start, len); numstring[len] = 0; *row = atoi(numstring) - 1; if ((*row >= MAXROWS) || (*row == -1)) return(FALSE); return(TRUE); } /* formulastart */
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 */