std::string Maker::GetFileTime(const std::string &goal, const std::string &preferredPath, Time &timeval) { std::string rv; if (goal.find_first_of(CmdFiles::DIR_SEP) != std::string::npos) { std::fstream fil(goal.c_str(), std::ios::in); if (fil != NULL) { fil.close(); timeval = OS::GetFileTime(goal); } } else { std::string vpath = preferredPath + std::string(" .\\ ") + Eval::GetVPATH(goal); std::string sep = std::string(" ") + CmdFiles::PATH_SEP; while (vpath.size()) { std::string cur = Eval::ExtractFirst(vpath, sep); if (cur[cur.size() -1] != CmdFiles::DIR_SEP[0]) cur += CmdFiles::DIR_SEP; std::string name ; if (goal[0] != CmdFiles::DIR_SEP[0] && goal[1] != ':') name = cur + goal; else name = goal; if (cur != ".\\") filePaths[goal] = cur; // tentatively enter this as the goal path // this will collide if there are multiple paths and no file exists // and choose the last one std::fstream fil(name.c_str(), std::ios::in); if (fil != NULL) { fil.close(); rv = cur; // return value is the path, with a slash on the end timeval = OS::GetFileTime(name); filePaths[goal] = cur; break; } } } if (ScanList(newFiles, goal) || ScanList(newFiles, rv + goal)) { timeval = OS::GetCurrentTime(); } else if (ScanList(oldFiles, goal) || ScanList(oldFiles, rv + goal)) { timeval.Clear(); } return rv; }
void Search(CarNode *headPointer) { int vehicleID; CarNode *searchNode; /* Points to node to delete to follow */ CarNode *prevNode; /* Points to car before one to delete */ printf("Enter the vehicle ID number of the car to search for:\n"); scanf("%d", &vehicleID); prevNode = ScanList(headPointer, vehicleID); searchNode = prevNode->next; /* Either there is the car does not exist in the list or */ /* searchNode points to the car we are looking for. */ if (searchNode != NULL && searchNode->vehicleID == vehicleID) { printf("vehicle ID : %d\n", searchNode->vehicleID); printf("make : %s\n", searchNode->make); printf("model : %s\n", searchNode->model); printf("year : %d\n", searchNode->year); printf("mileage : %d\n", searchNode->mileage); /* The following printf has a field width specification on */ /* %f specification. The 10.2 indicates that the floating */ /* point number should be printed in a 10 character field */ /* with two units after the decimal displayed. */ printf("cost : $%10.2f\n\n", searchNode->cost); } else { printf("The vehicle id %d was not found in the database.\n\n", vehicleID); } }
void Maker::CancelOne(Depends *depend) { for (Depends::iterator it = depend->begin(); it != depend->end(); ++it) { CancelOne(*it); } std::string path = filePaths[depend->GetGoal()]; if (path.size() != 0) { Variable *v = VariableContainer::Instance()->Lookup("GPATH"); if (v) { std::string t = v->GetValue(); if (v->GetFlavor() == Variable::f_recursive) { Eval e(t, false); t = e.Evaluate(); } if (!ScanList(t, path)) filePaths[depend->GetGoal()] = ""; } // else // filePaths[depend->GetGoal()] = ""; } }
bool Maker::OnList(const std::string &goal, char *what) { bool rv = false; RuleList *rl = RuleContainer::Instance()->Lookup(what); if (rl) { for (RuleList::iterator it = rl->begin(); !rv && it != rl->end(); ++it) { std::string value = (*it)->GetPrerequisites(); rv = ScanList(value, goal); } } return rv; }
void DeleteEntry(Car *headPointer) { int vehicleID; Car *delNode; // 要删除的Node指针 Car *prevNode; // 要删除的的Node之前的Node的指针 printf("Enter the vehicle ID of the car to delete:\n"); scanf("%d", &vehicleID); prevNode = ScanList(headPointer, vehicleID); delNode = prevNode->next; // 可以删除的情况 if (delNode != NULL && delNode->vehicleID == vehicleID) { prevNode->next = delNode->next; printf("vehicle with ID %d deleted.\n\n", vehicleID); free(delNode); } // 不能删除的情况 else { printf("The vehicle was not found in the database\n"); } }
void AddEntry(Car *headPointer) { Car *newNode; // 指向新车 Car *nextNode; // 这个新车的下一个Car节点 Car *prevNode; // 这个新车的前一个节点 // 动态申请新的内存 newNode = (Car *) malloc(sizeof(Car)); // 它返回了申请到的内存地址的首地址指针. if(newNode == NULL) { printf("Error: could not allocate a new node\n"); exit(1); } printf("Enter the following info about the car.\n"); printf("Seperate each field by white space:\nA"); printf("vehicle_id make model year mileage cost\n"); scanf("%d %s %s %d %d %lf, &newNode->vehicleID, newNode->make, newNode->model, &newNode->year, &newNode->mileage, &newNode->cost"); prevNode = ScanList(headPointer, newNode->vehicleID); nextNode = prevNode->next; // 可以插入的情况 if((nextNode == NULL) || (nextNode->vehicleID != newNode->vehicleID)) { prevNode->next = newNode; newNode->next = nextNode; printf("Entry added.\n"); } // 不能插入的情况 else { printf("That car already exists in the database!\n"); printf("Entry not added.\n\n"); free(newNode); } }
void Search(Car *headPointer) { int vehicleID; Car *searchNode; // 要搜索的Node的指针` Car *prevNode; // 要搜索的Node之前的Node的指针 printf("Enter the vehicle ID number of the car to search for:\n"); scanf("%d", &vehicleID); prevNode = ScanList(headPointer, vehicleID); searchNode = prevNode->next; if (searchNode != NULL && serachNode->vehicleID == vehicleID) { printf("vehicle ID : %d\n", searchNode->vehicleID); printf("make : %s\n", searchNode->make); printf("model : %s\n", searchNode->model); printf("year : %d\n", searchNode->year); printf("mileage : %d\n", searchNode->mileage); printf("cost : $%10.2f\n\n", searchNode->cost); } else { printf("The vehicle ID %d was not found in the database.\n\n", vehicleID); } }
void AddEntry(Car *headPointer) { Car *newNode; /* Points to the new car info */ Car *nextNode; /* Points to car to follow new one */ Car *prevNode; /* Points to car before this one */ /* Dynamically allocate memory for this new entry. */ newNode = (Car *) malloc(sizeof(Car)); if (newNode == NULL) { printf("Error: could not allocate a new node\n"); exit(1); } printf("Enter the following info about the car.\n"); printf("Separate each field by whitespace:\n"); printf("vehicle_id make model year mileage cost\n"); scanf("%d %s %s %d %d %lf", &newNode->vehicleID, newNode->make, newNode->model, &newNode->year, &newNode->mileage, &newNode->cost); prevNode = ScanList(headPointer, newNode->vehicleID); nextNode = prevNode->next; if ((nextNode == NULL) || (nextNode->vehicleID != newNode->vehicleID)) { prevNode->next = newNode; newNode->next = nextNode; printf("Entry added.\n\n"); } else { printf("That car already exists in the Database!\n"); printf("Entry not added.\n\n"); free(newNode); } }
/*** doreplace - perform search-replace * * Performs the actual search and replace argument verification, set up and * high level control. * * Input: * fQuery = TRUE if a query replace * pArg = pArg of parent function * fMeta = fMeta of parent function * fFiles = TRUE is multiple file search and replace. * * Output: * Returns ..... * * Exceptions: * * Notes: * *************************************************************************/ flagType doreplace ( flagType fQuery, ARG * pArg, flagType fMeta, flagType fFiles ) { buffer bufFn; /* filename buffer */ fl flStart; char *p; PCMD pCmd; PFILE pFileSave; /* file to save as top of heap */ p = "Query Search string: "; if (!fQuery) { p += 6; } fQrpl = fQuery; fSrchCasePrev = fMeta ? (flagType)!fSrchCaseSwit : fSrchCaseSwit; Display (); cRepl = 0; /* * If not menu-driven, ask the user for a search string. If none is entered, * we're done. */ if ((pCmd = getstring (srcbuf, sizeof(srcbuf), p, NULL, GS_NEWLINE | GS_INITIAL)) == NULL || (PVOID)pCmd->func == (PVOID)cancel) { return FALSE; } if (srcbuf[0] == '\0') { return FALSE; } /* * If RE search to take place, the compile the expression. */ if (pArg->arg.nullarg.cArg == 2) { if (patBuf != NULL) { FREE ((char *) patBuf); patBuf = NULL; } patBuf = RECompile (srcbuf, fSrchCaseSwit, (flagType)!fUnixRE); if (patBuf == NULL) { printerror ((RESize == -1) ? "Invalid pattern" : "Not enough memory for pattern"); return FALSE; } fRplRePrev = TRUE; } else { fRplRePrev = FALSE; } /* * If not menu driven, ask the user for a replacement string. Confirm the * entry of a null string. Error check the replacement if an RE search. */ if ((pCmd = getstring (rplbuf, sizeof(rplbuf), "Replace string: ", NULL, GS_NEWLINE | GS_INITIAL)) == NULL || (PVOID)pCmd->func == (PVOID)cancel) { return FALSE; } if (rplbuf[0] == 0) { if (!confirm ("Empty replacement string, confirm: ", NULL)) { return FALSE; } } if (fRplRePrev && !RETranslate (patBuf, rplbuf, scanreal)) { printerror ("Invalid replacement pattern"); return FALSE; } srchlen = strlen (srcbuf); switch (pArg->argType) { case NOARG: case NULLARG: setAllScan (TRUE); break; case LINEARG: rnScan.flFirst.col = 0; rnScan.flLast.col = sizeof(linebuf)-1; rnScan.flFirst.lin = pArg->arg.linearg.yStart; rnScan.flLast.lin = pArg->arg.linearg.yEnd; break; case BOXARG: rnScan.flFirst.col = pArg->arg.boxarg.xLeft; rnScan.flLast.col = pArg->arg.boxarg.xRight; rnScan.flFirst.lin = pArg->arg.boxarg.yTop; rnScan.flLast.lin = pArg->arg.boxarg.yBottom; break; case STREAMARG: if (pArg->arg.streamarg.yStart == pArg->arg.streamarg.yEnd) { rnScan.flFirst.col = pArg->arg.streamarg.xStart; rnScan.flLast.col = pArg->arg.streamarg.xEnd; rnScan.flFirst.lin = pArg->arg.streamarg.yStart; rnScan.flLast.lin = pArg->arg.streamarg.yEnd; } else { rnScan.flFirst.col = 0; /* Do all but last line first */ rnScan.flLast.col = sizeof(linebuf)-1; rnScan.flFirst.lin = pArg->arg.streamarg.yStart; rnScan.flLast.lin = pArg->arg.streamarg.yEnd - 1; flStart.col = pArg->arg.streamarg.xStart - 1; flStart.lin = rnScan.flFirst.lin; fScan (flStart, fDoReplace , TRUE, fSrchWrapSwit); rnScan.flLast.col = pArg->arg.streamarg.xEnd; rnScan.flFirst.lin = ++rnScan.flLast.lin; } } flStart.col = rnScan.flFirst.col-1; flStart.lin = rnScan.flFirst.lin; if (fRplRePrev) { MaxREStack = 512; REStack = (RE_OPCODE **)ZEROMALLOC (MaxREStack * sizeof(*REStack)); } if (fFiles) { /* * Get the list handle, and initialize to start at the head of the list. * Attempt to read each file. */ if (pCmd = GetListHandle ("mgreplist", TRUE)) { pFileSave = pFileHead; p = ScanList (pCmd, TRUE); while (p) { CanonFilename (p, bufFn); forfile (bufFn, A_ALL, mrepl1file, &p); p = ScanList (NULL, TRUE); if (fCtrlc) { return FALSE; } } pFileToTop (pFileSave); dispmsg (0); } } else { fScan (flStart, fDoReplace , TRUE, fSrchWrapSwit); } if (fRplRePrev) { FREE (REStack); } domessage ("%d occurrences replaced", cRepl); return (flagType)(cRepl != 0); }