Example #1
0
void act(char *s)
/* Acts on a particular input */
{
 int attrib, allocated;
 double value;

 deletecell(curcol, currow, UPDATE);
 value = parse(s, &attrib);
 switch(attrib)
 {
  case TEXT :
   allocated = alloctext(curcol, currow, s);
   if (allocated)
    displaycell(curcol, currow, NOHIGHLIGHT, NOUPDATE);
   break;
  case VALUE :
   allocated = allocvalue(curcol, currow, value);
   break;
  case FORMULA :
   allocated = allocformula(curcol, currow, s, value);
   break;
 } /* switch */
 if (allocated)
 {
  format[curcol][currow] &= ~OVERWRITE;
  clearoflags(curcol + 1, currow, UPDATE);
  if (attrib == TEXT)
    setoflags(curcol, currow, UPDATE);
  if (curcol > lastcol)
   lastcol = curcol;
  if (currow > lastrow)
   lastrow = currow;
  if (autocalc)
   recalc();
 }
 else
  errormsg(MSGLOMEM);
 printfreemem();
} /* act */
Example #2
0
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 */
Example #3
0
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 */