|
|
@ -5,30 +5,49 @@ |
|
|
|
|
|
|
|
|
|
|
|
char formulaBuffer[1000]; |
|
|
|
calc_op* mainCalc = NULL; |
|
|
|
calc_op* resultCalc = NULL; |
|
|
|
calc_op* currentCalc = NULL; |
|
|
|
|
|
|
|
void processInput(char* formStr, int len) { |
|
|
|
deleteWhitespace(formStr, len); |
|
|
|
if (mainCalc!=NULL){ |
|
|
|
free(mainCalc); |
|
|
|
if (resultCalc != NULL){ |
|
|
|
free(resultCalc); |
|
|
|
} |
|
|
|
mainCalc = malloc(sizeof(calc_op)); |
|
|
|
resultCalc = malloc(sizeof(calc_op)); |
|
|
|
memset(resultCalc, 0, sizeof(calc_op)); |
|
|
|
resultCalc->functionsType = opResult; |
|
|
|
memcpy(formulaBuffer, formStr, len); |
|
|
|
mainCalc->formular = formStr; |
|
|
|
mainCalc->functionsType = detectFunctionOperator(formulaBuffer, 10); |
|
|
|
if (getNumbers(formulaBuffer, len, mainCalc) == NULL){ |
|
|
|
showStruct(mainCalc); |
|
|
|
calc_op * nextCalc = NULL; |
|
|
|
nextCalc= malloc(sizeof(calc_op)); |
|
|
|
memset(nextCalc, 0, sizeof(calc_op)); |
|
|
|
nextCalc->formular = formStr; |
|
|
|
nextCalc->parent = (void*) resultCalc; |
|
|
|
nextCalc->functionsType = detectFunctionOperator(formulaBuffer, 10); |
|
|
|
if (getNumbers(formulaBuffer, len, nextCalc) == NULL){ |
|
|
|
resultCalc->children[0] = (void*) nextCalc; |
|
|
|
showStruct(nextCalc); |
|
|
|
} else { |
|
|
|
printf("Formular %s not supported", mainCalc->formular); |
|
|
|
printf("Formular %s not supported", resultCalc->formular); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
calc_op* getNextCalc(){ |
|
|
|
calc_op* newCalc = NULL; |
|
|
|
if (currentCalc != NULL){ |
|
|
|
newCalc = (calc_op*) currentCalc->parent; |
|
|
|
if (newCalc == NULL) { |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
newCalc->inputNumbers[0]= currentCalc->result; |
|
|
|
free(currentCalc); |
|
|
|
} else { |
|
|
|
newCalc = (calc_op*) resultCalc->children[0]; |
|
|
|
} |
|
|
|
if (newCalc==NULL){ |
|
|
|
return NULL; |
|
|
|
} |
|
|
|
currentCalc = mainCalc; // get ext calculation |
|
|
|
currentCalc = newCalc; // get ext calculation |
|
|
|
showStruct(currentCalc); |
|
|
|
return currentCalc; |
|
|
|
} |
|
|
|
|
|
|
|