void processFileArgument(char* name) { if (!table.lookup(name)) { fprintf(stderr, "File %s is not present in baseline.\n", name); return; } File localfile(name); if (localfile.exists()) { processFile(name); } else { if (forced_revision()) { File tempfile("forced_mergefile.tmp"); File rcsfile(dirs.baseline, dirs.subdir->path, "RCS", localfile.path); char line[LINE_LENGTH]; char* version = forced_revision_number ? forced_revision_number : rcsfile.getRevisionFromDate(forced_revision_date); sprintf(line, "co -q -p%s %s,v > %s", version, rcsfile.path, tempfile.path); if (execute(line)) { tempfile.un_link(); exit(-1); } localfile.become(tempfile, save); tempfile.un_link(); } else { File basefile(dirs.baseline, dirs.subdir->path, localfile.path); localfile.become(basefile, save); } } }
nsresult GenerateBaselineFile(const char* aSourceFilename,const char* aBaselineFilename) { if (!aSourceFilename || !aBaselineFilename) return NS_ERROR_INVALID_ARG; nsresult rv; // Create a parser nsCOMPtr<nsIParser> parser(do_CreateInstance(kParserCID, &rv)); if (NS_FAILED(rv)) { cout << "Unable to create a parser (" << rv << ")" <<endl; return rv; } // Create a sink nsCOMPtr<nsILoggingSink> sink(do_CreateInstance(kLoggingSinkCID, &rv)); if (NS_FAILED(rv)) { cout << "Unable to create a sink (" << rv << ")" <<endl; return rv; } nsCOMPtr<nsILocalFile> localfile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; localfile->InitWithNativePath(nsDependentCString(aSourceFilename)); nsCOMPtr<nsIURI> inputURI; { nsCOMPtr<nsIIOService> ioService(do_GetService(NS_IOSERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; rv = ioService->NewFileURI(localfile, getter_AddRefs(inputURI)); if (NS_FAILED(rv)) return rv; } localfile->InitWithNativePath(nsDependentCString(aBaselineFilename)); PRFileDesc *outputfile; localfile->OpenNSPRFileDesc(0660, PR_WRONLY | PR_CREATE_FILE, &outputfile); sink->SetOutputStream(outputfile); // Parse the document, having the sink write the data to fp parser->SetContentSink(sink); rv = parser->Parse(inputURI, 0, PR_FALSE, eDTDMode_unknown); return rv; }
int handlenode(stringNode* node) { if (node->version != remove_keyword) { if (!node->isMarked()) { if (verbose) { fprintf(stderr, "Updating %s since not removed nor marked\n", node->string); } File localfile(node->string); File baseline (dirs.baseline, dirs.subdir->path, node->string); localfile.become(baseline, save); } else { if (verbose) { fprintf(stderr, "File %s is marked; ignoring\n", node->string); } } } else { if (verbose) { fprintf(stderr, "File %s should be removed; ignoring\n", node->string); } } return 1; }
void processFile(char* name) { stringNode* node; if (node = table.lookup(name)) { if (!node->isMarked()) { node->mark(); File localfile(name); if (node->version == remove_keyword) { if (verbose) { fprintf(stderr, "File %s keyword is %s; removing\n", name, node->version); } localfile.remove(); } else { File basefile(dirs.baseline, dirs.subdir->path, localfile.path); if (node->version == copy_keyword) { if (verbose) { fprintf(stderr, "File %s keyword is %s; copying if outdated\n", name, node->version); } localfile.becomeIfOutdated(basefile, save); } else { // The file must have a revision char* revision; switch (getRevision(localfile.path, &revision)) { case GOT_REVISION: if (verbose) { fprintf(stderr, "Testing revisions of %s:\n" " local: \"%s\"; baseline: \"%s\"...", localfile.path, revision, node->version); } char* version; if (forced_revision()) { version = forced_revision_number ? forced_revision_number : basefile.getRevisionFromDate(forced_revision_date); } else version = node->version; switch (cmpRevisions(revision, version)) { case EQUAL: if (verbose) { fprintf(stderr, "same; no action.\n"); } break; case LESS_THAN: { if (verbose) { fprintf(stderr, "revision is behind; merge.\n"); } File rcsfile(dirs.baseline, dirs.subdir->path, "RCS", localfile.path); if (forced_revision()) { File tempfile("forced_mergefile.tmp"); char line[LINE_LENGTH]; sprintf(line, "co -q -p%s %s,v > %s", version, rcsfile.path, tempfile.path); if (execute(line)) { tempfile.un_link(); exit(-1); } localfile.merge(tempfile, rcsfile, revision, version); tempfile.un_link(); } else { localfile.merge(basefile, rcsfile, revision, version); } } break; case GREATER_THAN: if (verbose) { fprintf(stderr, "\n"); } fprintf(stderr, "%s has a newer revision number than baseline.\n", localfile.path); localfile.becomeIfConfirmed(basefile, 1); break; case FAILED: if (verbose) { fprintf(stderr, "\n"); } fprintf(stderr, "%s has a conflicting revision number with baseline.\n", localfile.path); localfile.becomeIfConfirmed(basefile, 1); break; default: fprintf(stderr, "unexpected cmpRevisions result"); exit(-1); } break; case NO_REVISION: if (strcmp(node->version, "none") == 0) { // baseline has no revision; copy if outdated if (verbose) { fprintf(stderr, "%s has no revision number; copying if outdated\n", localfile.path); } localfile.becomeIfOutdated(basefile, 1); } else { // baseline does have a revision num, but local file doesn't; // ask! fprintf(stderr, "%s has no revision number (baseline's is %s).\n", localfile.path, node->version); localfile.becomeIfConfirmed(basefile, 1); } break; default: fprintf(stderr, "getRevision failed on %s\n", name); localfile.becomeIfConfirmed(basefile, 1); break; } } } } else { if (verbose) { fprintf(stderr, "File %s is marked; ignoring\n", name); } } } else { if (verbose) { fprintf(stderr, "File %s not found in table; ignoring\n", name); } } }