Advertisement
marvk

Untitled

Dec 19th, 2013
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. void processInput(char *input, int row, int column) {
  2.     printf("\n**process input**\n");
  3.     Cell *cell = cells[row][column];
  4.     free(cell->input); // free old input
  5.     cell->input = strdup(input); // copy input string
  6.     printf("cell->input: %s (row %d, column %d) (strlen = %d)\n",
  7.     cell->input, row, column, (int)strlen(input));
  8.    
  9.     guiSetInput(input, row, column);
  10.    
  11.    
  12.     //Remove current cell from the listeners list in all cells in the listeningTo list of the current cell
  13.     Node *node = cell->listeningTo->first;
  14. //    printf("\t%d\t%d listening to %s will be removed\n", row, column, toCString(cell->listeningTo)); Debug
  15.     for (; node != NULL; node = node->next) {
  16.         Cell *curCell = (Cell*)node->value;
  17.         removeObject(cell->listeners, curCell);
  18.     }
  19.    
  20.     removeAll(cell->listeningTo);
  21.    
  22.     //Set new references
  23.     references(cell->listeningTo, parse(newString(cell->input)));
  24.     printf("\(%d\t%d) listening to %s\n", row, column, toCString(cell->listeningTo));
  25.     node = cell->listeningTo->first;
  26.     for (; node != NULL; node = node->next) {
  27.         Cell *curCell = (Cell*)node->value;
  28.         if (contains(curCell->listeners, cell) == 0) {
  29.             append(curCell->listeners, cell);
  30.         }
  31.         printf("\t(%d\t%d) has listeners  %s\n", curCell->row, curCell->column, toCString(curCell->listeners));
  32.     }
  33.    
  34.     //Evaluate
  35.     Object *evalResult = evaluate(parse(newString(cell->input)));
  36.     cell->value = evalResult;
  37.     char *result = "";
  38.     if (evalResult != NULL) {
  39.         result = toCString(evalResult);
  40.     } else {
  41.         result = "Could not Evaluate Input";
  42.     }
  43.    
  44.     guiSetOutput(result, row, column);
  45.    
  46.     updateReferencedCells(cell);
  47.    
  48.     saveFile(currentFileName);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement