34 const char *fulldir =
".";
35 char *file = strrchr(path,
'/');
41 const char *oldstyle =
".arb.quick";
43 int oldstylelen = strlen(oldstyle);
54 memset((
char*)sd, 0,
sizeof(*sd));
60 dirp = opendir(fulldir);
66 filelen = strlen(file);
67 for (dp = readdir(dirp); dp; dp = readdir(dirp)) {
68 if (strncmp(dp->d_name, file, filelen))
continue;
69 suffix = dp->d_name + filelen;
70 if (suffix[0] !=
'.')
continue;
71 if (!strncmp(suffix, oldstyle, oldstylelen)) {
73 printf(
"Warning: Found new and old changes files, using new\n");
77 curindex = atoi(suffix+oldstylelen);
78 goto check_time_and_date;
80 if (strlen(suffix) == 4 &&
86 printf(
"Warning: Found new and old changes files, using new\n");
89 curindex = atoi(suffix+2);
90 goto check_time_and_date;
95 sprintf(buffer,
"%s/%s", fulldir, dp->d_name);
129 for (dirent *dp = readdir(dirp); dp; dp = readdir(dirp)) {
132 sprintf(buffer,
"%s/%s", dir, dp->d_name);
133 if (stat(buffer, &st) == 0 && S_ISREG(st.st_mode)) {
134 if (filename_only) strcpy(buffer, dp->d_name);
169 for (dirent *dp = readdir(dirp); dp; dp = readdir(dirp)) {
172 sprintf(buffer,
"%s/%s", dir, dp->d_name);
173 if (stat(buffer, &st) == 0 &&
174 S_ISREG(st.st_mode) &&
176 newest = st.st_mtime;
177 freedup(result, dp->d_name);
194 if (warn_when_not_found)
GB_warningf(
"Could not find '%s'", file);
198 char *
GB_lib_file(
bool warn_when_not_found,
const char *libprefix,
const char *filename) {
209 if (!result) result =
GB_lib_file(warn_when_not_found,
"arb_default", filename);
233 DIR *dirstream = opendir(fulldir);
243 char *lslash = strrchr(fulldir,
'/');
246 char *name = lslash+1;
248 for (
int smartMethod = 1; smartMethod<=2 && names.empty(); ++smartMethod) {
249 if (smartMethod == 1) {
252 else if (smartMethod == 2) {
271 if (!mask) mask =
"*";
276 while ((entry = readdir(dirstream))) {
277 const char *name = entry->d_name;
279 if (name[0] ==
'.' && (name[1] == 0 || (name[1] ==
'.' && name[2] == 0))) {
308 static SmartCharPtr tag;
314 char *
nl = strchr(&*tag,
'\n');
329 static char *remove_path(
const char *fullname,
void *cl_path) {
330 const char *path = (
const char *)cl_path;
334 static void GBT_transform_names(StrArray& dest,
const StrArray& source,
char *transform(
const char *,
void *),
void *client_data) {
335 for (
int i = 0; source[i]; ++i) dest.put(transform(source[i], client_data));
338 #define TEST_JOINED_FULLDIR_CONTENT_EQUALS(fulldir,mask,expected) do { \
340 GBS_read_dir(contents, fulldir, mask); \
341 StrArray contents_no_path; \
342 GBT_transform_names(contents_no_path, contents, remove_path, (void*)fulldir); \
343 TEST_EXPECT_STRARRAY_CONTAINS(contents_no_path, '!', expected); \
346 #define TEST_JOINED_DIR_CONTENT_EQUALS(subdir,mask,expected) do { \
347 char *fulldir = ARB_strdup(GB_path_in_ARBHOME(subdir)); \
348 TEST_JOINED_FULLDIR_CONTENT_EQUALS(fulldir,mask,expected); \
352 void TEST_GBS_read_dir() {
356 TEST_JOINED_DIR_CONTENT_EQUALS(
"GDE/CLUSTAL",
"*.c",
"/amenu.c!/clustalv.c!/gcgcheck.c!/myers.c!/sequence.c!/showpair.c!/trees.c!/upgma.c!/util.c");
357 TEST_JOINED_DIR_CONTENT_EQUALS(
"GDE/CLUSTAL",
"?????*.c",
"/amenu.c!/clustalv.c!/gcgcheck.c!/myers.c!/sequence.c!/showpair.c!/trees.c!/upgma.c");
358 TEST_JOINED_DIR_CONTENT_EQUALS(
"GDE/CLUSTAL",
"??????*.c",
"/clustalv.c!/gcgcheck.c" "!/sequence.c!/showpair.c");
359 TEST_JOINED_DIR_CONTENT_EQUALS(
"GDE/CLUSTAL",
"/s.*\\.c/",
"/clustalv.c!/myers.c!/sequence.c!/showpair.c!/trees.c");
362 TEST_JOINED_DIR_CONTENT_EQUALS(
"SL",
NULp,
"/Makefile!/README");
363 TEST_JOINED_DIR_CONTENT_EQUALS(
"SL",
"*",
"/Makefile!/README");
365 TEST_JOINED_FULLDIR_CONTENT_EQUALS(
"",
"",
"");
368 void TEST_find_file() {
374 char *tcporg =
GB_lib_file(
false,
"",
"arb_tcp_org.dat");
GBS_string_matcher * GBS_compile_matcher(const char *search_expr, GB_CASE case_flag)
GB_CSTR GB_path_in_arbprop(const char *relative_path)
char * GB_lib_file(bool warn_when_not_found, const char *libprefix, const char *filename)
unsigned long date_of_quick_file
char * GB_find_all_files(const char *dir, const char *mask, bool filename_only)
void GBS_free_matcher(GBS_string_matcher *matcher)
char * ARB_strdup(const char *str)
const char * GBS_global_string(const char *templat,...)
char * GB_property_file(bool warn_when_not_found, const char *filename)
NOT4PERL gb_getenv_hook GB_install_getenv_hook(gb_getenv_hook hook)
char buffer[MESSAGE_BUFFERSIZE]
GB_CSTR GB_canonical_path(const char *anypath)
int GB_string_comparator(const void *v0, const void *v1, void *)
#define TEST_PUBLISH(testfunction)
const char * GB_get_arb_revision_tag()
#define TEST_EXPECT(cond)
void GB_warningf(const char *templat,...)
gb_scan_quicks_types type
#define TEST_REJECT(cond)
static void error(const char *msg)
GB_ERROR gb_scan_directory(char *basename, gb_scandir *sd)
void GBS_read_dir(StrArray &names, const char *dir, const char *mask)
GB_CSTR GB_path_in_ARBHOME(const char *relative_path)
#define RETURN_ONETIME_ALLOC(allocated)
const char *(* gb_getenv_hook)(const char *varname)
static BasicStatus status
char * GB_find_latest_file(const char *dir, const char *mask)
GB_CSTR GB_concat_path(GB_CSTR anypath_left, GB_CSTR anypath_right)
GB_ERROR GB_export_errorf(const char *templat,...)
#define TEST_EXPECT_NULL(n)
bool GB_is_directory(const char *path)
GB_CSTR GB_concat_path_in_ARBLIB(const char *relative_path_left, const char *anypath_right)
bool GB_is_readablefile(const char *filename)
bool ARB_strBeginsWith(const char *str, const char *with)
bool GBS_string_matches_regexp(const char *str, const GBS_string_matcher *expr)
static const char * GB_existing_file(const char *file, bool warn_when_not_found)
bool GBS_string_matches(const char *str, const char *expr, GB_CASE case_sens)
#define TEST_EXPECT_EQUAL(expr, want)
char * GBS_global_string_copy(const char *templat,...)
char * GB_read_file(const char *path)