static void Enumerate(struct Strbuf *buf, const XmapNode *ptr) { size_t old_len; if (ptr == NULL) { #ifdef DEBUG_EDIT xprintf(CGETS(9, 6, "Enumerate: BUG!! Null ptr passed\n!")); #endif return; } old_len = buf->len; unparsech(buf, ptr->ch); /* put this char at end of string */ if (ptr->next == NULL) { /* print this Xkey and function */ Strbuf_append1(buf, '"'); Strbuf_terminate(buf); printOne(buf->s, &ptr->val, ptr->type); } else Enumerate(buf, ptr->next); /* go to sibling if there is one */ if (ptr->sibling) { buf->len = old_len; Enumerate(buf, ptr->sibling); } }
/* Lookup(): * look for the string starting at node ptr. * Print if last node */ static int Lookup(struct Strbuf *buf, const CStr *str, const XmapNode *ptr) { if (ptr == NULL) return (-1); /* cannot have null ptr */ if (str->len == 0) { /* no more chars in string. Enumerate from here. */ Enumerate(buf, ptr); return (0); } else { /* If match put this char into buf. Recurse */ if (ptr->ch == *(str->buf)) { /* match found */ unparsech(buf, ptr->ch); if (ptr->next != NULL) { /* not yet at leaf */ CStr tstr; tstr.buf = str->buf + 1; tstr.len = str->len - 1; return (Lookup(buf, &tstr, ptr->next)); } else { /* next node is null so key should be complete */ if (str->len == 1) { Strbuf_append1(buf, '"'); Strbuf_terminate(buf); printOne(buf->s, &ptr->val, ptr->type); return (0); } else return (-1);/* mismatch -- string still has chars */ } } else { /* no match found try sibling */ if (ptr->sibling) return (Lookup(buf, str, ptr->sibling)); else return (-1); } } }
void Stack::pop(){ printOne(0); deleteNode(0); }
/********************************* processCommand ******************************* void processCommand(Tree tree, QuoteSelection quoteSelection, char *pszInput) Purpose: to read input file and Parameters: Returns: ********************************************************************************/ void processCommand(Tree tree, QuoteSelection quoteSelection, char *pszInput) { char szToken[MAX_TOKEN_SIZE+1]; char szSubordinateToId[MAX_ID_SIZE]; char szOptionId[MAX_ID_SIZE]; NodeT *p; Element element; //Gets first word in input pszInput = getToken(pszInput,szToken,MAX_TOKEN_SIZE); //Set of if statmenets to check the command if (strcmp(szToken,"DEFINE")==0) { //checks the next word after the command pszInput = getToken(pszInput,szToken,MAX_TOKEN_SIZE); //check to see if it is OPTION or VALUE if (strcmp(szToken,"OPTION")==0) { element.cNodeType = 'O'; sscanf(pszInput, "%s %s %[^\t\n]" ,element.szId ,szSubordinateToId ,element.szTitle); //check to see if it is root node if (strcmp(szSubordinateToId,"ROOT")==0) { if (tree->pRoot == NULL) tree->pRoot = allocateNodeT(element); else tree->pRoot->pSibling = allocateNodeT(element); } else { insertPriceMenu(tree,element,szSubordinateToId); } } else if (strcmp(szToken,"VALUE")==0) { element.cNodeType = 'V'; sscanf(pszInput, "%s %s %s %lf %[^\t\n]" ,element.szId ,szOptionId ,&element.cCostInd ,&element.dCost ,element.szTitle); if (strcmp(szOptionId,"ROOT")==0) printf("DEFINE ERROR: ROOT is not option\n"); else insertPriceMenu(tree,element,szOptionId); } } else if (strcmp(szToken,"PRINT")==0) { pszInput = getToken(pszInput,szToken,MAX_TOKEN_SIZE); //if the command is to print all if (strcmp(szToken,"ALL")==0) { //Pretty print printPriceMenu(tree); } //if the command is print one else { pszInput = getToken(pszInput,szToken,MAX_TOKEN_SIZE); printOne(tree, szToken); } } else if (strcmp(szToken,"QUOTE")==0) { //3 cases, BEGIN, OPTION,END pszInput = getToken(pszInput,szToken,MAX_TOKEN_SIZE); if (strcmp(szToken,"BEGIN")==0) { quoteSelection->iQuoteItemCnt = 0; } if (strcmp(szToken,"OPTION")==0) { sscanf(pszInput," %d %s %d" ,"eSelection->quoteItemM[quoteSelection->iQuoteItemCnt].iLevel ,quoteSelection->quoteItemM[quoteSelection->iQuoteItemCnt].szOptionId ,"eSelection->quoteItemM[quoteSelection->iQuoteItemCnt].iSelection); quoteSelection->iQuoteItemCnt++; } if (strcmp(szToken,"END")==0) { QuoteResult result; result = determineQuote(tree,quoteSelection); switch (result.returnCode) { case 0: printf("\t\tTotal Cost \t\t\t\t$%.2lf\n",result.dTotalCost); break; case 1: printf("\tPartial Total is \t\t\t\t$%.2lf\n",result.dTotalCost); printf("PARTIAL QUOTE: missing %s", result.error.szOptionId); break; case 2: printf("Bad option value: %s\n" ,result.error.szOptionId); break; case 3: printf("Bad Selection value: %s %d\n" ,result.error.szOptionId ,result.error.iSelection); break; } } } else if (strcmp(szToken,"DELETE")==0) { pszInput = getToken(pszInput,szToken,MAX_TOKEN_SIZE); p = findId(tree->pRoot,szToken); if (p == NULL) printf("DELETE ERROR: Id %s not found\n",szToken); else { deleteItem(tree,szToken); } } }