//-------------------------------------------------------------------------------------------------- bool IsLibrary ( const std::string& path ) //-------------------------------------------------------------------------------------------------- { // If it ends in ".a" or a ".so" then it's a library. static const std::list<std::string> suffixes = { ".a", ".so" }; return HasSuffix(path, suffixes); }
//-------------------------------------------------------------------------------------------------- bool IsCSource ( const std::string& path ) //-------------------------------------------------------------------------------------------------- { // If it ends in ".c" or ".C", then it's a C source code file. static const std::list<std::string> suffixes = { ".c", ".C" }; return HasSuffix(path, suffixes); }
void InitializeLibrary () { char *p; gchar **dirs; GDir *dir; gchar *fname, *path, *docname, *dirname, *homedir; int i, fp; DocInfo *docinfo; if (PluckerDocs != NULL) return; homedir = (char *) g_getenv ("HOME"); PluckerDocs = g_tree_new ((GCompareFunc) strcmp); p = (char *) g_getenv ("PLUCKERPATH"); if (p == NULL) p = plkr_GetConfigString (NULL, "pluckerpath", NULL); if (p == NULL) p = "."; if (p != NULL) { dirs = g_strsplit (p, ":", 0); for (i = 0; dirs[i] != NULL; i++) { dirname = dirs[i]; /* handle ~ characters */ if (dirname[0] == '~' && dirname[1] == G_DIR_SEPARATOR && homedir) { dirname = g_strjoin (G_DIR_SEPARATOR_S, homedir, dirs[i] + 2, NULL); } if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { fprintf (stderr, "Non-existent path/file on PLUCKERPATH: %s\n", dirname); continue; } else if (g_file_test (dirname, G_FILE_TEST_IS_DIR)) { if (dir = g_dir_open (dirname, 0, NULL)) { /* fprintf (stderr, "Looking in directory %s...\n", dirname); */ while ((fname = (char *) g_dir_read_name (dir)) != NULL) { if (HasSuffix (fname, ".plkr") || HasSuffix (fname, ".pdb")) { path = g_strjoin (G_DIR_SEPARATOR_S, dirname, fname, NULL); fp = open (path, O_RDONLY); if ((docname = IsPlucker (fp)) != NULL) { /* OK, it's a plucker document, index it by document name */ /* fprintf (stderr, " adding '%s' (%s)\n", filebuf, fname); */ docinfo = (DocInfo *) malloc (sizeof (DocInfo)); docinfo->name = docname; docinfo->path = path; GetMetadata (fp, &docinfo->nrecords, &docinfo->categories, &docinfo->charset, &docinfo->title, &docinfo->author, &docinfo->pubtime); g_tree_insert (PluckerDocs, docinfo->name, docinfo); path = NULL; } close (fp); if (path) free (path); } } g_dir_close (dir); } } else if (g_file_test (dirname, G_FILE_TEST_EXISTS)) { fp = open (dirname, O_RDONLY); if ((docname = IsPlucker (fp)) != NULL) { /* OK, it's a plucker document, index it by document name */ /* fprintf (stderr, " adding '%s' (%s)\n", filebuf, fname); */ docinfo = (DocInfo *) malloc (sizeof (DocInfo)); docinfo->name = docname; docinfo->path = g_strdup (dirname); GetMetadata (fp, &docinfo->nrecords, &docinfo->categories, &docinfo->charset, &docinfo->title, &docinfo->author, &docinfo->pubtime); g_tree_insert (PluckerDocs, docinfo->name, docinfo); } close (fp); } else { fprintf (stderr, "Non-Plucker, non-directory element on PLUCKERPATH: %s\n", dirname); } if (dirname != dirs[i]) free (dirname); } g_strfreev (dirs); } }