GList *filename_complete(const char *path) { GList *list; DIR *dirp; struct dirent *dp; char *realpath, *dir, *basename, *name; int len; g_return_val_if_fail(path != NULL, NULL); list = NULL; /* get directory part of the path - expand ~/ */ realpath = convert_home(path); dir = g_dirname(realpath); g_free(realpath); /* open directory for reading */ dirp = opendir(dir); g_free(dir); if (dirp == NULL) return NULL; dir = g_dirname(path); if (*dir == G_DIR_SEPARATOR && dir[1] == '\0') *dir = '\0'; /* completing file in root directory */ basename = g_basename(path); len = strlen(basename); /* add all files in directory to completion list */ while ((dp = readdir(dirp)) != NULL) { if (dp->d_name[0] == '.') { if (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' && dp->d_name[2] == '\0')) continue; /* skip . and .. */ if (basename[0] != '.') continue; } if (len == 0 || strncmp(dp->d_name, basename, len) == 0) { name = g_strdup_printf("%s"G_DIR_SEPARATOR_S"%s", dir, dp->d_name); list = list_add_file(list, name); g_free(name); } } closedir(dirp); g_free(dir); return list; }
GList *filename_complete(const char *path, const char *default_path) { GList *list; DIR *dirp; struct dirent *dp; const char *basename; char *realpath, *dir, *name; int len; g_return_val_if_fail(path != NULL, NULL); list = NULL; /* get directory part of the path - expand ~/ */ realpath = convert_home(path); if (USE_DEFAULT_PATH(realpath, default_path)) { g_free(realpath); realpath = g_strconcat(default_path, G_DIR_SEPARATOR_S, path, NULL); } /* open directory for reading */ dir = g_dirname(realpath); dirp = opendir(dir); g_free(dir); g_free(realpath); if (dirp == NULL) return NULL; dir = g_dirname(path); if (*dir == G_DIR_SEPARATOR && dir[1] == '\0') { /* completing file in root directory */ *dir = '\0'; } else if (IS_CURRENT_DIR(dir) && !IS_CURRENT_DIR(path)) { /* completing file in default_path (path not set, and leave it that way) */ g_free_and_null(dir); } basename = g_basename(path); len = strlen(basename); /* add all files in directory to completion list */ while ((dp = readdir(dirp)) != NULL) { if (dp->d_name[0] == '.') { if (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' && dp->d_name[2] == '\0')) continue; /* skip . and .. */ if (basename[0] != '.') continue; } if (len == 0 || strncmp(dp->d_name, basename, len) == 0) { name = dir == NULL ? g_strdup(dp->d_name) : g_strdup_printf("%s"G_DIR_SEPARATOR_S"%s", dir, dp->d_name); list = list_add_file(list, name, default_path); g_free(name); } } closedir(dirp); g_free_not_null(dir); return list; }
GList *filename_complete(const char *path, const char *default_path) { GList *list; DIR *dirp; struct dirent *dp; char *basename; char *realpath, *dir, *name; size_t len; g_return_val_if_fail(path != NULL, NULL); if (path[0] == '\0') { return NULL; } list = NULL; /* get directory part of the path - expand ~/ */ realpath = convert_home(path); if (USE_DEFAULT_PATH(realpath, default_path)) { g_free(realpath); realpath = g_strconcat(default_path, G_DIR_SEPARATOR_S, path, NULL); } /* open directory for reading */ dir = g_path_get_dirname(realpath); dirp = opendir(dir); g_free(dir); g_free(realpath); if (dirp == NULL) return NULL; dir = g_path_get_dirname(path); if (*dir == G_DIR_SEPARATOR && dir[1] == '\0') { /* completing file in root directory */ *dir = '\0'; } else if (IS_CURRENT_DIR(dir) && !IS_CURRENT_DIR(path)) { /* completing file in default_path (path not set, and leave it that way) */ g_free_and_null(dir); } len = strlen(path); /* g_path_get_basename() returns the component before the last slash if * the path ends with a directory separator, that's not what we want */ if (len > 0 && path[len - 1] == G_DIR_SEPARATOR) { basename = g_strdup(""); } else { basename = g_path_get_basename(path); } len = strlen(basename); /* add all files in directory to completion list */ while ((dp = readdir(dirp)) != NULL) { if (dp->d_name[0] == '.') { if (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' && dp->d_name[2] == '\0')) continue; /* skip . and .. */ /* Skip the dotfiles unless the user explicitly asked us * to do so. Basename might be './', beware of that */ if (basename[0] != '.' || basename[1] == '\0') continue; } if (len == 0 || strncmp(dp->d_name, basename, len) == 0) { name = dir == NULL ? g_strdup(dp->d_name) : g_strdup_printf("%s"G_DIR_SEPARATOR_S"%s", dir, dp->d_name); list = list_add_file(list, name, default_path); g_free(name); } } closedir(dirp); g_free(basename); g_free_not_null(dir); return list; }
static int asm_exec(const char *infile, const char *outfile) { list_t *l; const char *file; int rv; if (opt.prog_asm == NULL) error("No assembler is defined"); l = list_alloc(); list_add_file(l, opt.prog_asm, &progdirs, X_OK); Wflag_add(l, W_ASM); list_add_list(l, opt.Wa); { -p gnu -f <type> #if defined(USE_YASM) av[na++] = "-p"; av[na++] = "gnu"; av[na++] = "-f"; #if defined(os_win32) av[na++] = "win32"; #elif defined(os_darwin) av[na++] = "macho"; #else av[na++] = "elf"; #endif #endif #if defined(os_sunos) && defined(mach_sparc64) av[na++] = "-m64"; #endif #if defined(os_darwin) if (Bstatic) av[na++] = "-static"; #endif #if !defined(USE_YASM) if (vflag) av[na++] = "-v"; #endif if (kflag) av[na++] = "-k"; #ifdef os_darwin av[na++] = "-arch"; #if mach_amd64 av[na++] = amd64_i386 ? "i386" : "x86_64"; #else av[na++] = "i386"; #endif #else #ifdef mach_amd64 if (amd64_i386) av[na++] = "--32"; #endif #endif av[na++] = "-o"; if (outfile && cflag) ermfile = av[na++] = outfile; else if (cflag) ermfile = av[na++] = olist[i] = setsuf(clist[i], 'o'); else ermfile = av[na++] = olist[i] = gettmp(); av[na++] = assource; av[na++] = 0; if (callsys(as, av)) { cflag++; eflag++; cunlink(tmp4); continue; } } if (infile != NULL) list_add(l, infile); else if (outfile != NULL) list_add(l, "-"); if (outfile != NULL) { list_add(l, "-o"); list_add(l, outfile); } rv = list_exec(l); list_free(l); return rv; }