bool ResourceManagerImpl::searchUpwards( std::string const &base, std::string const &subpath, std::string &dest ) { bool exists = false; // TODO debug g_message("............"); std::vector<std::string> parts = splitPath(subpath); std::vector<std::string> baseParts = splitPath(base); while ( !exists && !baseParts.empty() ) { std::vector<std::string> current; current.insert(current.begin(), parts.begin(), parts.end()); // TODO debug g_message(" ---{%s}", Glib::build_filename( baseParts ).c_str()); while ( !exists && !current.empty() ) { std::vector<std::string> combined; combined.insert( combined.end(), baseParts.begin(), baseParts.end() ); combined.insert( combined.end(), current.begin(), current.end() ); std::string filepath = Glib::build_filename( combined ); exists = Glib::file_test(filepath, Glib::FILE_TEST_EXISTS); // TODO debug g_message(" ...[%s] %s", filepath.c_str(), (exists ? "XXX" : "")); if ( exists ) { dest = filepath; } current.erase( current.begin() ); } baseParts.pop_back(); } return exists; }
void bigWigCorrelateList(char *listFile) /* Correlate all files in list to each other */ { char **fileNames = NULL; int fileCount = 0; char *buf = NULL; readAllWords(listFile, &fileNames, &fileCount, &buf); int i; for (i=0; i<fileCount; ++i) { char *aPath = fileNames[i]; char aName[FILENAME_LEN]; if (rootNames) splitPath(aPath, NULL, aName, NULL); else safef(aName, sizeof(aName), "%s", aPath); int j; for (j=i+1; j<fileCount; ++j) { char *bPath = fileNames[j]; char bName[FILENAME_LEN]; if (rootNames) splitPath(bPath, NULL, bName, NULL); else safef(bName, sizeof(bName), "%s", bPath); struct correlate *c = bigWigCorrelate(aPath, bPath); printf("%s\t%s\t%g\n", aName, bName, correlateResult(c)); correlateFree(&c); } } }
static std::string convertPathToRelative( std::string const &path, std::string const &docbase ) { std::string result = path; if ( !path.empty() && Glib::path_is_absolute(path) ) { // Whack the parts into pieces std::vector<std::string> parts = splitPath(path); std::vector<std::string> baseParts = splitPath(docbase); // TODO debug g_message("+++++++++++++++++++++++++"); for ( std::vector<std::string>::iterator it = parts.begin(); it != parts.end(); ++it ) { // TODO debug g_message(" [%s]", it->c_str()); } // TODO debug g_message(" - - - - - - - - - - - - - - - "); for ( std::vector<std::string>::iterator it = baseParts.begin(); it != baseParts.end(); ++it ) { // TODO debug g_message(" [%s]", it->c_str()); } // TODO debug g_message("+++++++++++++++++++++++++"); if ( !parts.empty() && !baseParts.empty() && (parts[0] == baseParts[0]) ) { // Both paths have the same root. We can proceed. while ( !parts.empty() && !baseParts.empty() && (parts[0] == baseParts[0]) ) { parts.erase( parts.begin() ); baseParts.erase( baseParts.begin() ); } // TODO debug g_message("+++++++++++++++++++++++++"); for ( std::vector<std::string>::iterator it = parts.begin(); it != parts.end(); ++it ) { // TODO debug g_message(" [%s]", it->c_str()); } // TODO debug g_message(" - - - - - - - - - - - - - - - "); for ( std::vector<std::string>::iterator it = baseParts.begin(); it != baseParts.end(); ++it ) { // TODO debug g_message(" [%s]", it->c_str()); } // TODO debug g_message("+++++++++++++++++++++++++"); if ( !parts.empty() ) { result.clear(); for ( size_t i = 0; i < baseParts.size(); ++i ) { parts.insert(parts.begin(), ".."); } result = Glib::build_filename( parts ); // TODO debug g_message("----> [%s]", result.c_str()); } } } return result; }
void loadPslTable(char *database, struct sqlConnection *conn, char *pslFile) /* load one psl table */ { char table[128]; char *tabFile; boolean indirectLoad = FALSE; verbose(1, "Processing %s\n", pslFile); /* determine table name to use */ if (clTableName != NULL) safef(table, sizeof(table), "%s", clTableName); else { if (endsWith(pslFile, ".gz")) { char *stripGz; stripGz = cloneString(pslFile); chopSuffix(stripGz); splitPath(stripGz, NULL, table, NULL); freeMem(stripGz); } else splitPath(pslFile, NULL, table, NULL); } setupTable(database, conn, table); /* if a bin column is being added or if the input file is * compressed, we must copy to an intermediate tab file */ indirectLoad = ((pslCreateOpts & PSL_WITH_BIN) != 0) || endsWith(pslFile, ".gz") || !noSort; if (indirectLoad) { tabFile = "psl.tab"; if (pslCreateOpts & PSL_XA_FORMAT) copyPslXaToTab(pslFile, tabFile); else copyPslToTab(pslFile, tabFile); } else tabFile = pslFile; sqlLoadTabFile(conn, tabFile, table, pslLoadOpts); if (!noHistory) hgHistoryComment(conn, "Add psl alignments to %s table", table); if (indirectLoad && !keep) unlink(tabFile); }
void makeC(struct dtdElement *elList, char *fileName, char *incName) /* Produce C code file. */ { FILE *f = mustOpen(fileName, "w"); struct dtdElement *el; char incFile[128], incExt[64]; splitPath(incName, NULL, incFile, incExt); fprintf(f, "/* %s.c %s */\n", prefix, fileComment); fprintf(f, "\n"); fprintf(f, "#include \"common.h\"\n"); fprintf(f, "#include \"xap.h\"\n"); fprintf(f, "#include \"%s%s\"\n", incFile, incExt); fprintf(f, "\n"); fprintf(f, "\n"); for (el = elList; el != NULL; el = el->next) { freeFunctionPrototype(el, f, ""); freeFunctionBody(el, f); freeListFunctionPrototype(el, f, ""); freeListFunctionBody(el, f); saveFunctionPrototype(el, f, ""); saveFunctionBody(el, f); loadFunctionPrototype(el, f, ""); loadFunctionBody(el, f); loadNextFunctionPrototype(el, f, ""); loadNextFunctionBody(el, f); } makeStartHandler(elList, f); makeEndHandler(elList, f); if (makeMain) makeTestDriver(elList, f); }
static std::string getFileName(const std::string &path) { std::string directory; std::string file; splitPath(path, directory, file); return file; }
static std::string getDirectory(const std::string &path) { std::string directory; std::string file; splitPath(path, directory, file); return directory; }
void splitByNamePrefix(char *inName, char *outRoot, int preFixCount) /* Split into chunks using prefix of sequence names. */ { struct dnaSeq seq; struct lineFile *lf = lineFileOpen(inName, TRUE); FILE *f = NULL; char outDir[256], outFile[128], ext[64], outPath[512], preFix[512]; ZeroVar(&seq); splitPath(outRoot, outDir, outFile, ext); assert(preFixCount < sizeof(preFix)); while (faMixedSpeedReadNext(lf, &seq.dna, &seq.size, &seq.name)) { carefulClose(&f); strncpy(preFix, seq.name, preFixCount); preFix[preFixCount] = '\0'; sprintf(outPath, "%s%s.fa", outDir, preFix); verbose(2, "writing %s\n", outPath); f = mustOpen(outPath, "a"); faWriteNext(f, seq.name, seq.dna, seq.size); } carefulClose(&f); lineFileClose(&lf); }
void DrawingAnchor::loadXmlObjectPicture(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("pic")); while (!reader.atEnd()) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("blip")) { QString rId = reader.attributes().value(QLatin1String("r:embed")).toString(); QString name = m_drawing->relationships()->getRelationshipById(rId).target; QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name); bool exist = false; QList<QSharedPointer<MediaFile> > mfs = m_drawing->workbook->mediaFiles(); for (int i=0; i<mfs.size(); ++i) { if (mfs[i]->fileName() == path) { //already exist exist = true; m_pictureFile = mfs[i]; } } if (!exist) { m_pictureFile = QSharedPointer<MediaFile> (new MediaFile(path)); m_drawing->workbook->addMediaFile(m_pictureFile, true); } } } else if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("pic")) { break; } } return; }
//--------------------------------------------------------------------- // remove a file of the dir content - if present fxp_name * Server::removeFile(bstring const & remotePath) { bstring path, file; file = splitPath(path, remotePath); DirCache::iterator i = dirCache.find(path); if (i == dirCache.end()) return 0; my_fxp_names * dir = i->second; int count = dir->nnames; for (int i = 0; i < count; ++i) { fxp_name * fn = dir->names[i]; if (file == fn->filename) { // not last -> replace current with last if (i + 1 < count) { dir->names[i] = dir->names[count - 1]; } // and one less now --dir->nnames; return fn; // done } } return 0; }
void writeRelevantSplits(char *ctgDir, struct hash *splitCloneHash) /* Write out splits if there are any. */ { char fileName[512], dir[256], name[128], ext[64]; char *cnBuf, **cloneNames, *clonePath; int i, cloneCount; FILE *f; struct clone *clone; struct frag *frag; sprintf(fileName, "%s/geno.lst", ctgDir); readAllWords(fileName, &cloneNames, &cloneCount, &cnBuf); sprintf(fileName, "%s/splitFin", ctgDir); f = mustOpen(fileName, "w"); for (i=0; i<cloneCount; ++i) { clonePath = cloneNames[i]; splitPath(clonePath, dir, name, ext); if ((clone = hashFindVal(splitCloneHash, name)) != NULL) { printf(" Split %s in %s\n", name, ctgDir); for (frag = clone->fragList; frag != NULL; frag = frag->next) { fprintf(f, "%s\t%s\t%d\t%d\n", frag->name, clone->name, frag->start, frag->end); } } } fclose(f); freeMem(cloneNames); freeMem(cnBuf); }
void writeRelevantChains(char *ctgDir, struct hash *cloneHash) /* Read in geno.lst and write chains on relevant clones to * fragChains. */ { char inName[512]; char outName[512]; char *wordBuf, **faNames; int faCount; int i; char dir[256], cloneName[128], ext[64]; FILE *f; struct clone *clone; sprintf(inName, "%s/geno.lst", ctgDir); sprintf(outName, "%s/fragChains", ctgDir); readAllWords(inName, &faNames, &faCount, &wordBuf); f = mustOpen(outName, "w"); for (i=0; i<faCount; ++i) { splitPath(faNames[i], dir, cloneName, ext); if (!startsWith("NT_", cloneName)) { clone = hashMustFindVal(cloneHash, cloneName); writeChains(clone, f); } } freeMem(wordBuf); fclose(f); }
struct slName *getFileList(char *listFile, char *bulkDir) /* Get list of files to work on from listFile. */ { char **faFiles; char *faBuf; int faCount; int i; char path[512], dir[256], name[128], extension[64]; struct slName *list = NULL, *el; readAllWords(listFile, &faFiles, &faCount, &faBuf); for (i = 0; i<faCount; ++i) { splitPath(faFiles[i], dir, name, extension); sprintf(path, "%s/%s.%s", bulkDir, name, "psl"); if (fileExists(path)) { el = newSlName(path); slAddHead(&list, el); } } slReverse(&list); return list; }
void ModelLoader::loadModel(std::string path, ModelData* modelData) { std::string basename, directory; splitPath(path, &basename, &directory); std::vector<tinyobj::shape_t> shapes; std::vector<tinyobj::material_t> materials; std::string err = tinyobj::LoadObj(shapes, materials, path.c_str(), directory.c_str()); modelData->vertices.clear(); modelData->indices.clear(); modelData->material.reset(); modelData->diffuseTex.reset(); modelData->alphaTex.reset(); if (materials.size() > 0) { modelData->material.reset(createMaterialFromMtl(*materials.begin())); if (!materials.begin()->diffuse_texname.empty()) modelData->diffuseTex.reset(loadImage(directory, materials.begin()->diffuse_texname)); else modelData->diffuseTex.reset(); if (!materials.begin()->alpha_texname.empty()) modelData->alphaTex.reset(loadImage(directory, materials.begin()->alpha_texname)); else modelData->alphaTex.reset(); } if (!err.empty()) throw Exception(err); loadShapes(shapes, &modelData->vertices, &modelData->indices); }
static void recurseThroughIncludes(char *fileName, struct lm *lm, struct hash *circularHash, struct raLevel *level, struct raFile **pFileList) /* Recurse through include files. */ { struct raFile *raFile = raFileRead(fileName, level, lm); slAddHead(pFileList, raFile); struct raRecord *r; for (r = raFile->recordList; r != NULL; r = r->next) { struct raTag *tag = r->tagList; if (sameString(tag->name, "include")) { for (; tag != NULL; tag = tag->next) { if (!sameString(tag->name, "include")) recordAbort(r, "Non-include tag %s in an include stanza", tag->name); char *relPath = tag->val; char dir[PATH_LEN]; splitPath(fileName, dir, NULL, NULL); char includeName[PATH_LEN]; safef(includeName, sizeof(includeName), "%s%s", dir, relPath); if (hashLookup(circularHash, includeName)) recordAbort(r, "Including file %s in an infinite loop", includeName); recurseThroughIncludes(includeName, lm, circularHash, level, pFileList); } } } }
string getDirname(const string &path) { string dir; string file; splitPath(path, dir, file); return dir; }
void DrawingAnchor::loadXmlObjectGraphicFrame(QXmlStreamReader &reader) { Q_ASSERT(reader.name() == QLatin1String("graphicFrame")); while (!reader.atEnd()) { reader.readNextStartElement(); if (reader.tokenType() == QXmlStreamReader::StartElement) { if (reader.name() == QLatin1String("chart")) { QString rId = reader.attributes().value(QLatin1String("r:id")).toString(); QString name = m_drawing->relationships()->getRelationshipById(rId).target; QString path = QDir::cleanPath(splitPath(m_drawing->filePath())[0] + QLatin1String("/") + name); bool exist = false; QList<QSharedPointer<Chart> > cfs = m_drawing->workbook->chartFiles(); for (int i=0; i<cfs.size(); ++i) { if (cfs[i]->filePath() == path) { //already exist exist = true; m_chartFile = cfs[i]; } } if (!exist) { m_chartFile = QSharedPointer<Chart> (new Chart(m_drawing->sheet, Chart::F_LoadFromExists)); m_chartFile->setFilePath(path); m_drawing->workbook->addChartFile(m_chartFile); } } } else if (reader.tokenType() == QXmlStreamReader::EndElement && reader.name() == QLatin1String("graphicFrame")) { break; } } return; }
void ccdsGetTblFileNames(char *tblFile, char *table, char *tabFile) /* Get table and tab file name from a single input name. If specified names * looks like a file name, use it as-is, otherwise generate a file name. * Output buffers should be PATH_LEN bytes long. Either output argument maybe * be NULL. */ { if ((strchr(tblFile, '/') != NULL) || (strchr(tblFile, '.') != NULL)) { if (tabFile != NULL) safef(tabFile, PATH_LEN, "%s", tblFile); if (table != NULL) splitPath(tblFile, NULL, table, NULL); } else { if (tabFile != NULL) { char *tmpDir = getenv("TMPDIR"); if (tmpDir != NULL) safef(tabFile, PATH_LEN, "%s/%s.tab", tmpDir, tblFile); else safef(tabFile, PATH_LEN, "%s.tab", tblFile); } if (table != NULL) safef(table, PATH_LEN, "%s", tblFile); } }
void apacheSendX(char *format, char *filePath, char *suggestFileName) /* send pseudo-HTTP header to tell Apache to transfer filePath with suggestFileName on user's disk * format is one of "fastq", "fasta", defined in cdw.as. if format is NULL, use file extension. */ { if (format==NULL) { char ext[FILEEXT_LEN]; splitPath(filePath, NULL, NULL, ext); if (strlen(ext)>1) { format = cloneString(ext); format++; // skip over . character } } // html files are shown directly in the internet browser, not downloaded if (sameWord(format, "html")) printf("Content-Type: text/html\n"); else if (sameWord(format, "json")) printf("Content-Type: application/json\n"); else if (sameWord(format, "text")) printf("Content-Type: application/json\n"); else { printf("Content-Disposition: attachment;filename=%s\n", suggestFileName); printf("Content-Type: application/octet-stream\n"); } printf("X-Sendfile: %s\n\n", filePath); }
void gfiGetSeqName(char *spec, char *name, char *file) /* Extract sequence name and optionally file name from spec, * which includes nib and 2bit files. (The file may be NULL * if you don't care.) */ { if (nibIsFile(spec)) { splitPath(spec, NULL, name, NULL); if (file != NULL) strcpy(file, spec); } else { char *s = strchr(spec, ':'); if (s == NULL) errAbort("Expecting colon in %s", spec); strcpy(name, s+1); if (file != NULL) { int fileNameSize = s - spec; memcpy(file, spec, fileNameSize); file[fileNameSize] = 0; } } }
void mkOutPath(char *outPath, char* outRoot, int digits, int fileCount) /* generate output file name */ { char dir[PATH_LEN], fname[PATH_LEN]; splitPath(outRoot, dir, fname, NULL); strcpy(outPath, dir); if (outDirDepth > 0) { /* add directory levels, using training digits for names */ char fcntStr[64], dirBuf[3]; int i, iDir; safef(fcntStr, sizeof(fcntStr), "%0*d", outDirDepth, fileCount); iDir = strlen(fcntStr)-outDirDepth; strcpy(dirBuf, "X/"); for (i = 0; i < outDirDepth; i++, iDir++) { dirBuf[0] = fcntStr[iDir]; strcat(outPath, dirBuf); makeDir(outPath); } } if (digits) sprintf(outPath+strlen(outPath), "%s%0*d.fa", fname, digits, fileCount); }
string getBasename(const string &path) { string dir; string file; splitPath(path, dir, file); return file; }
char *chromFileName(char *track, char *chrom, char fileName[512]) /* Return chromosome specific version of file if it exists. */ { if (fileExists(track)) { strncpy(fileName, track, 512); } else { char dir[256], root[128], ext[65]; int len; splitPath(track, dir, root, ext); /* Chop trailing / off of dir. */ len = strlen(dir); if (len > 0 && dir[len-1] == '/') dir[len-1] = 0; safef(fileName, 512, "%s/%s%s%s", dir, chrom, root, ext); if (!fileExists(fileName)) { warn("Couldn't find %s or %s", track, fileName); strncpy(fileName, track, 512); } } return fileName; }
void ZProfile::openRoot (ZBoolean aCreate) { ZFUNCTRACE_DEVELOP ("ZProfile::openRoot(ZBoolean aCreate)"); if (iRootHandle == 0 || (aCreate && iRootReadOnly)) { closeRoot (); HKEY parentKey (0); ZString path; while (!parentKey) { path = iRoot; ZString token (splitPath (path)); for (unsigned i = 0; i < sizeof (sysHandles) / sizeof (SystemHandle); i++) if (token == sysHandles[i].iName) { parentKey = sysHandles[i].iHandle; break; } // if if (!parentKey) iRoot = ZString (sysHandles[0].iName) + (char) ZC_PATHSEPARATOR + iRoot; } // while if (path.length ()) iRootHandle = openHandle (parentKey, path, aCreate); else iRootHandle = parentKey; iRootReadOnly = !aCreate; } // if } // openRoot
void oneContig(char *dir, char *chrom, char *contig) /* Write out clone ends information to one contig. */ { char *wordsBuf, **faFiles, *faFile; int i, faCount; char path[512], sDir[256], sFile[128], sExt[64]; FILE *f; struct clone *clone; sprintf(path, "%s/geno.lst", dir); readAllWords(path, &faFiles, &faCount, &wordsBuf); sprintf(path, "%s/cloneEnds", dir); f = mustOpen(path, "w"); fprintf(f, "#accession\tversion\tphase\tGS ends\tSP ends\taFrag\taSide\tzFrag\tzSide\n"); for (i=0; i<faCount; ++i) { faFile = faFiles[i]; splitPath(faFile, sDir, sFile, sExt); if ((clone = hashFindVal(cloneHash, sFile)) != NULL) { printCloneEndInfo(clone, f); } } freez(&wordsBuf); fclose(f); }
int filterByQual(char *faFileName, FILE *f, int minQual, int minQualRun, struct hash *uniqHash) /* Write out parts of sequence that meet quality standards to fa file in out. * Returns untrimmed size. */ { char qaFileName[512], dir[256], name[128], ext[64]; struct qaSeq *qa; int start, size; int initialSize; splitPath(faFileName, dir, name, ext); sprintf(qaFileName, "%s%s.qual", dir, name); qa = qaMustReadBoth(qaFileName, faFileName); if (hashLookup(uniqHash, qa->name)) warn("%s duplicated, ignoring all but first occurence", qa->name); else { hashAdd(uniqHash, qa->name, NULL); if (trimQa(qa, minQual, minQualRun, &start, &size)) { faWriteNext(f, qa->name, qa->dna + start, size); } } initialSize = qa->size; qaSeqFree(&qa); return initialSize; }
Common::InSaveFile *Ps2SaveFileManager::openForLoading(const char *filename) { _screen->wantAnim(true); char dir[256], name[256]; splitPath(filename, dir, name); if (mcReadyForDir(dir)) { bool fileExists = false; for (int i = 0; i < _mcEntries; i++) if (strcmp(name, (char*)_mcDirList[i].name) == 0) fileExists = true; if (fileExists) { char fullName[256]; sprintf(fullName, "/ScummVM-%s/%s", dir, name); UclInSaveFile *file = new UclInSaveFile(fullName, _screen, _mc); if (file) { if (!file->ioFailed()) return file; else delete file; } } else printf("file %s (%s) doesn't exist\n", filename, name); } _screen->wantAnim(false); return NULL; }
QList<QImage> split(const QImage& img) { QVector<bool> emptyLines(img.height(), true); for (int y = 0; y < img.height(); ++y) { const uchar* it = img.constScanLine(y); const uchar* end = it + img.width(); while (it < end) { if (*it++ > 10) { emptyLines[y] = false; break; } } } QList<QImage> lines; for (int y = 0; y < img.height();) { if (emptyLines[y]) { ++y; continue; } QRect r(0, y, img.width(), 1); int height = 0; for (; y < img.height() && !emptyLines[y]; ++y) ++height; r.setHeight(height); if (height > 60 && height < 80) { lines += splitPath(img.copy(r)); } else { lines << img.copy(r); } } return lines; }
//--------------------------------------------------------------------- // add a file to the dir content - if not already there void Server::insertFile(bstring const & remotePath, FILETIME * ft, unsigned long szLo, unsigned long szHi, char kind, bstring const & chmod) { bstring path, file; file = splitPath(path, remotePath); DirCache::iterator i = dirCache.find(path); if (i == dirCache.end()) return; my_fxp_names * dir = i->second; int count = dir->nnames; for (int i = 0; i < count; ++i) { fxp_name * fn = dir->names[i]; if (file == fn->filename) { // already there return; } } // create a new structure and fill it my_fxp_names * ndir = (my_fxp_names *) malloc(sizeof(my_fxp_names)); ndir->names = (fxp_name **)malloc(sizeof(fxp_name*) * (count + 1)); fxp_name * n = ndir->names[0] = (fxp_name *)malloc(sizeof(fxp_name)); RtlZeroMemory(n, sizeof(fxp_name)); FILETIME ft2; SYSTEMTIME st; if (ft) { FileTimeToSystemTime(ft, &st); } else { GetSystemTime(&st); SystemTimeToFileTime(&st, &ft2); ft = &ft2; } char buffer[32]; sprintf(buffer, "%d ", szLo); #ifdef UNICODE char * chmod2; BCONVERT(char, 32, chmod2, chmod.c_str()); char * file2; BCONVERT(char, 256, file2, file.c_str()); std::string ln = kind + chmod2 + std::string(" 1 ? ? ") + buffer + " Jan 1 1990 " + file2; #else std::string ln = kind + chmod + std::string(" 1 ? ? ") + buffer + " Jan 1 1990 " + file; #endif n->longname = strdup(ln.c_str()); n->filename = bstrdup(file.c_str()); n->attrs.size.hi = szHi; n->attrs.size.lo = szLo; n->attrs.mtime = FileTimeToUnixTime(ft); for (int i = 0; i < count; ++i) { ndir->names[i + 1] = dir->names[i]; } ndir->nnames = count + 1; i->second = ndir; }
int env(int argc, char **argv) { char epath[PATH_MAX + 1]; char *oldpath = getenv("PATH"); assert(oldpath); if (!getExecutablePath(epath, sizeof(epath))) exit(EXIT_FAILURE); if (argc <= 1) { const std::string &pname = getParentProcessName(); if (pname == "csh" || pname == "tcsh") { std::cerr << std::endl << "you are invoking this program from a C shell, " << std::endl << "please use " << std::endl << std::endl << "setenv PATH `" << epath << "/osxcross-env -v=PATH`" << std::endl << std::endl << "instead." << std::endl << std::endl; } } std::vector<std::string> path; std::map<std::string, std::string> vars; splitPath(oldpath, path); if (!hasPath(path, epath)) path.push_back(epath); vars["PATH"] = joinPath(path); auto printVariable = [&](const std::string & var)->bool { auto it = vars.find(var); if (it == vars.end()) { std::cerr << "unknown variable '" << var << "'" << std::endl; return false; } std::cout << it->second << std::endl; return true; }; if (argc <= 1) { std::cout << std::endl; for (auto &v : vars) { std::cout << "export " << v.first << "="; if (!printVariable(v.first)) return 1; std::cout << std::endl; } } else { if (strncmp(argv[1], "-v=", 3)) return 1; const char *var = argv[1] + 3; return static_cast<int>(printVariable(var)); } return 0; }