void print_usage(char* progname, int argc, char* argv[]) { progname = basename(progname); if (!plugins) return; if (argc >= 1) { CFStringRef name = cfstr(argv[0]); const DBPlugin* plugin = DBGetPluginWithName(name); if (plugin) { _DBPluginSetCurrentPlugin(plugin); CFStringRef usage = plugin->usage(); cfprintf(stderr, "usage: %s [-f db] [-b build] %@ %@\n", progname, name, usage); CFRelease(usage); return; } else { cfprintf(stderr, "%s: no such command: %@\n", progname, name); } } cfprintf(stderr, "usage: %s [-f db] [-b build] <command> ...\n", progname); cfprintf(stderr, "commands:\n"); CFArrayRef pluginNames = dictionaryGetSortedKeys(plugins); CFIndex i, count = CFArrayGetCount(pluginNames); for (i = 0; i < count; ++i) { CFStringRef name = CFArrayGetValueAtIndex(pluginNames, i); const DBPlugin* plugin = DBGetPluginWithName(name); _DBPluginSetCurrentPlugin(plugin); CFStringRef usage = plugin->usage(); cfprintf(stderr, "\t%@ %@\n", name, usage); CFRelease(usage); } }
void CHXCFURL::SetToString(const char *pCString) { const CFURLRef kNoBaseURL = NULL; ReleaseCFURL(); // make a CFString then a CFURL from which we can get an FSRef CHXCFString cfstr(pCString, kCFStringEncodingUTF8); require(cfstr.IsSet(), CantMakeCFString); mCFURLRef = ::CFURLCreateWithString(kCFAllocatorDefault, cfstr, kNoBaseURL); if (mCFURLRef == NULL) { // failed; CFURL seems unable to deal with parameters, so try // stripping those and trying again CHXString strURL = pCString; int paramOffset = strURL.Find('?'); if (paramOffset != -1) { CHXCFString cfstr2((const char *) strURL.Left(paramOffset), kCFStringEncodingUTF8); mCFURLRef = ::CFURLCreateWithString(kCFAllocatorDefault, cfstr2, kNoBaseURL); } } UpdateDebugOnlyString(); CantMakeCFString: return; }
int run_plugin(int argc, char* argv[]) { int res = -1; int i; if (argc < 1) return -1; CFStringRef name = cfstr(argv[0]); CFMutableArrayRef args = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); for (i = 1; i < argc; ++i) { CFArrayAppendValue(args, cfstr(argv[i])); } const DBPlugin* plugin = DBGetPluginWithName(name); if (plugin) { _DBPluginSetCurrentPlugin(plugin); res = plugin->run(args); } CFRelease(name); return res; }
void DBSetCurrentBuild(char* build) { if (currentBuild) CFRelease(currentBuild); currentBuild = cfstr(build); }
////// // // DBPluginLoadPlugins // returns -1 if the plugin dictionary cannot be // created, otherwise returns 0 // ///// int DBPluginLoadPlugins(const char* plugin_path) { if (plugins == NULL) { plugins = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &cfDictionaryPluginValueCallBacks); } if (plugins == NULL) return -1; // // If the path contains colons, split the path and // search each path component. If there are no // colons, CFStringCreateArrayBySeparatingStrings() // will return an array with one element being the // entire path. // CFStringRef str = cfstr(plugin_path); CFArrayRef array = CFStringCreateArrayBySeparatingStrings(NULL, str, CFSTR(":")); CFRelease(str); CFIndex i, path_argc = CFArrayGetCount(array); char** path_argv = malloc(sizeof(char*)*(path_argc+1)); for (i = 0; i < path_argc; ++i) { path_argv[i] = strdup_cfstr(CFArrayGetValueAtIndex(array, i)); } path_argv[i] = NULL; CFRelease(array); // // Search the directories for plugins // FTSENT* ent; FTS* dir = fts_open((char * const *)path_argv, FTS_LOGICAL, NULL); while ((ent = fts_read(dir)) != NULL) { DBPlugin* plugin = NULL; if (strstr(ent->fts_name, ".so")) { //fprintf(stderr, "plugin: loading %s\n", ent->fts_accpath); void* handle = dlopen(ent->fts_accpath, RTLD_LAZY | RTLD_LOCAL); if (handle) { DBPluginInitializeFunc func = dlsym(handle, "initialize"); if (!func) { fprintf(stderr, "plugin: cannot find initialize for: %s\n%s\n", ent->fts_accpath, dlerror()); return -1; } plugin = _DBPluginInitialize(); if (!plugin) { fprintf(stderr, "plugin: failed to initialize %s\n", ent->fts_accpath); return -1; } _DBPluginSetCurrentPlugin(plugin); (*func)(kDBPluginCurrentVersion); // Call out to C plugin // XXX: check for error? } else { fprintf(stderr, "Could not dlopen plugin: %s\n", ent->fts_name); } #if HAVE_TCL_PLUGINS } else if (strstr(ent->fts_name, ".tcl")) { plugin = _DBPluginInitialize(); _DBPluginSetCurrentPlugin(plugin); load_tcl_plugin(plugin, ent->fts_accpath); // Calls out to Tcl plugin #endif } if (plugin) { if (plugin->name == NULL) { fprintf(stderr, "warning: plugin has no name (skipping): %s\n", ent->fts_name); } else if (plugin->type == kDBPluginNullType) { fprintf(stderr, "warning: plugin has no type (skipping): %s\n", ent->fts_name); } else { if (CFDictionaryContainsKey(plugins, plugin->name)) { fprintf(stderr, "Error: already have a plugin loaded with name '%s' when " "trying to load %s\n", strdup_cfstr(plugin->name), ent->fts_accpath); return -1; } CFDictionarySetValue(plugins, plugin->name, plugin); } } ent = ent->fts_link; } fts_close(dir); // // Release the path array // for (i = 0; i < path_argc; ++i) { free(path_argv[i]); } free(path_argv); return 0; }
int LoadBCP(char *fn) { int i, f; uint numfiles, root = 1, id; HTREEITEM pti = TVI_ROOT; int ver, rp; if(file) CloseBCP(); file = fopen(fn, "rb"); if(!file) fErr(-1, "File not found."); idti.hParent = TVI_ROOT; idti.hInsertAfter = TVI_LAST; idti.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE; idti.item.pszText = abuf; idti.item.cchTextMax = 3; fseek(file, 9, SEEK_SET); ver = fgetc(file) - '0'; fseek(file, 0x30, SEEK_SET); fseek(file, fentof = _getw(file), SEEK_SET); nfiles = _getw(file); fent = (fileentry*)malloc(nfiles*20); if(!fent) fErr(-2, "Failed to allocate memory for the file position/size table."); fread(fent, nfiles*20, 1, file); fetime = (FILETIME*)malloc(nfiles*sizeof(FILETIME)); if(!fetime) fErr(-2092016, "Failed to allocate fetime."); fseek(file, fentof+4+nfiles*20, SEEK_SET); dirsp = dirstack; htisp = htistack; *dirsp = 1000; *htisp = TVI_ROOT; while(!feof(file)) { // Directories if(root) {root = 0;} else { i = _getw(file); if(i) { // Next level dirsp++; // Push htisp++; dirlev++; if(dirlev >= MAX_DIR_LEV) fErr(-209161825, "Maximum directory level reached."); *dirsp = i+1; } while(!(--(*dirsp))) { dirsp--; // Pop htisp--; dirlev--; } if(ver == 2) {cfstr(); bufwtoa();} else afstr(); if(feof(file)) goto flend; idti.hParent = *(htisp-1); idti.item.cchTextMax = strlen(abuf); idti.item.lParam = -1; idti.item.iImage = idti.item.iSelectedImage = 0; *htisp = TreeView_InsertItem(htree, &idti); } numfiles = _getw(file); // Files in directory listing. for(f = 0; f < numfiles; f++) { if(feof(file)) goto flend; id = _getw(file); fetime[id].dwLowDateTime = _getw(file); fetime[id].dwHighDateTime = _getw(file); if(ver == 2) {cfstr(); bufwtoa();} else afstr(); idti.hParent = *htisp; idti.item.cchTextMax = strlen(abuf); idti.item.lParam = id; idti.item.iImage = idti.item.iSelectedImage = fent[id].form + 1; TreeView_InsertItem(htree, &idti); } } flend: return 0; }
//static QFileSystemEntry QFileSystemEngine::getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data) { #if defined(__GLIBC__) && !defined(PATH_MAX) #define PATH_CHUNK_SIZE 256 char *s = 0; int len = -1; int size = PATH_CHUNK_SIZE; while (1) { s = (char *) ::realloc(s, size); Q_CHECK_PTR(s); len = ::readlink(link.nativeFilePath().constData(), s, size); if (len < 0) { ::free(s); break; } if (len < size) { break; } size *= 2; } #else char s[PATH_MAX+1]; int len = readlink(link.nativeFilePath().constData(), s, PATH_MAX); #endif if (len > 0) { QString ret; if (!data.hasFlags(QFileSystemMetaData::DirectoryType)) fillMetaData(link, data, QFileSystemMetaData::DirectoryType); if (data.isDirectory() && s[0] != '/') { QDir parent(link.filePath()); parent.cdUp(); ret = parent.path(); if (!ret.isEmpty() && !ret.endsWith(QLatin1Char('/'))) ret += QLatin1Char('/'); } s[len] = '\0'; ret += QFile::decodeName(QByteArray(s)); #if defined(__GLIBC__) && !defined(PATH_MAX) ::free(s); #endif if (!ret.startsWith(QLatin1Char('/'))) { if (link.filePath().startsWith(QLatin1Char('/'))) { ret.prepend(link.filePath().left(link.filePath().lastIndexOf(QLatin1Char('/'))) + QLatin1Char('/')); } else { ret.prepend(QDir::currentPath() + QLatin1Char('/')); } } ret = QDir::cleanPath(ret); if (ret.size() > 1 && ret.endsWith(QLatin1Char('/'))) ret.chop(1); return QFileSystemEntry(ret); } #if defined(Q_OS_DARWIN) { QCFString path = CFStringCreateWithFileSystemRepresentation(0, QFile::encodeName(QDir::cleanPath(link.filePath())).data()); if (!path) return QFileSystemEntry(); QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, data.hasFlags(QFileSystemMetaData::DirectoryType)); if (!url) return QFileSystemEntry(); QCFType<CFDataRef> bookmarkData = CFURLCreateBookmarkDataFromFile(0, url, NULL); if (!bookmarkData) return QFileSystemEntry(); QCFType<CFURLRef> resolvedUrl = CFURLCreateByResolvingBookmarkData(0, bookmarkData, (CFURLBookmarkResolutionOptions)(kCFBookmarkResolutionWithoutUIMask | kCFBookmarkResolutionWithoutMountingMask), NULL, NULL, NULL, NULL); if (!resolvedUrl) return QFileSystemEntry(); QCFString cfstr(CFURLCopyFileSystemPath(resolvedUrl, kCFURLPOSIXPathStyle)); if (!cfstr) return QFileSystemEntry(); return QFileSystemEntry(QCFString::toQString(cfstr)); } #endif return QFileSystemEntry(); }