Beispiel #1
0
int nexttoken(void)
/* Gets the next token from the input stream */
{
 char *start, numstring[80];
 int decimal, len, numlen;

 while (*input == ' ')
  input++;
 if (*input == 0)
  return(EOLN);
 if (strchr("0123456789.", *input))
 {
  start = input;
  len = 0;
  decimal = FALSE;
  while ((isdigit(*input)) ||
   ((*input == '.') && (!decimal)))
  {
   if (*input == '.')
    decimal = TRUE;
   input++;
   len++;
  }
  if ((len == 1) && (start[0] == '.'))
   return(BAD);
  if (*input == 'E')
  {
   input++;
   len++;
   if (strchr("+-", *input) != NULL)
   {
    input++;
    len++;
   }
   numlen = 0;
   while ((isdigit(*input)) && (++numlen <= 3))
   {
    input++;
    len++;
   }
  }
  strncpy(numstring, start, len);
  numstring[len] = 0;
  curtoken.x.value = atof(numstring);
  if (errno == ERANGE)
   return(BAD);
  return(NUM);
 }
 else if (isalpha(*input))
 {
  if
  (isfunc("ABS") ||
   isfunc("ACOS") ||
   isfunc("ASIN") ||
   isfunc("ATAN") ||
   isfunc("COSH") ||
   isfunc("COS") ||
   isfunc("EXP") ||
   isfunc("LOG10") ||
   isfunc("LOG") ||
   isfunc("POW10") ||
   isfunc("ROUND") ||
   isfunc("SINH") ||
   isfunc("SIN") ||
   isfunc("SQRT") ||
   isfunc("SQR") ||
   isfunc("TANH") ||
   isfunc("TAN") ||
   isfunc("TRUNC"))
    return(FUNC);
  if (formulastart(&input, &curtoken.x.c.col, &curtoken.x.c.row))
  {
   isformula = TRUE;
   return(CELL);
  }
  else
   return(BAD);
 }
 else switch(*(input++))
 {
  case '+' : return(PLUS);
  case '-' : return(MINUS);
  case '*' : return(TIMES);
  case '/' : return(DIVIDE);
  case '^' : return(EXP);
  case ':' : return(COLON);
  case '(' : return(OPAREN);
  case ')' : return(CPAREN);
  default  : return(BAD);
 } /* switch */
} /* nexttoken */
Beispiel #2
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 */