/[qemacs]/qemacs/qe.c
ViewVC logotype

Diff of /qemacs/qe.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.18 by chqrlie, Mon May 9 03:32:19 2005 UTC revision 1.19 by chqrlie, Mon May 9 06:21:49 2005 UTC
# Line 4011  void edit_close(EditState *s) Line 4011  void edit_close(EditState *s)
4011      free(s);      free(s);
4012  }  }
4013    
4014  /* XXX: buffer overflows */  const char *file_completion_ignore_extensions =
4015        "|bak|bin|dll|exe|o|obj|";
4016    
4017  void file_completion(StringArray *cs, const char *input)  void file_completion(StringArray *cs, const char *input)
4018  {  {
4019      FindFileState *ffs;      FindFileState *ffs;
4020      char path[MAX_FILENAME_SIZE];      char path[MAX_FILENAME_SIZE];
4021      char file[MAX_FILENAME_SIZE];      char file[MAX_FILENAME_SIZE];
4022      char filename[MAX_FILENAME_SIZE];      char filename[MAX_FILENAME_SIZE];
4023      const char *p;      char *base;
4024      int input_path_len;      int len;
4025            
4026      p = strrchr(input, '/');      pstrcpy(path, sizeof(path), input);
4027      if (!p) {      base = path + (basename(path) - path);
4028          input_path_len = 0;      pstrcpy(file, sizeof(file), base);
4029          pstrcpy(file, sizeof(file), input);      pstrcat(file, sizeof(file), "*");
4030          strcpy(path, ".");      *base = '\0';
4031      } else {      ffs = find_file_open(*path ? path : ".", file);
         input_path_len = p - input + 1;  
         memcpy(path, input, input_path_len);  
         if (input_path_len > (int)sizeof(path) - 1)  
             input_path_len = (int)sizeof(path) - 1;  
         path[input_path_len] = '\0';  
         pstrcpy(file, sizeof(file), p + 1);  
     }  
     strcat(file, "*");  
     ffs = find_file_open(path, file);  
4032      while (find_file_next(ffs, filename, sizeof(filename)) == 0) {      while (find_file_next(ffs, filename, sizeof(filename)) == 0) {
4033          struct stat sb;          struct stat sb;
4034          p = basename(filename);  
4035          memcpy(file, input, input_path_len);          base = filename + (basename(filename) - filename);
4036          strcpy(file + input_path_len, p);          /* ignore . and .. to force direct match if
4037             * single entry in directory */
4038            if (!strcmp(base, ".") || !strcmp(base, ".."))
4039                continue;
4040            /* ignore known backup files */
4041            len = strlen(base);
4042            if (!len || base[len - 1] == '~')
4043                continue;
4044            /* ignore known output file extensions */
4045            if (strfind(file_completion_ignore_extensions,
4046                        extension(filename), 1)) {
4047                continue;
4048            }
4049            makepath(file, sizeof(file), path, base);
4050          /* stat the file to find out if it's a directory.          /* stat the file to find out if it's a directory.
4051           * In that case add a slash to speed up typing long paths           * In that case add a slash to speed up typing long paths
4052           */           */
4053          stat(file, &sb);          stat(file, &sb);
4054          if (S_ISDIR(sb.st_mode))          if (S_ISDIR(sb.st_mode))
4055              strcat(file, "/");              pstrcat(path, sizeof(path), "/");
4056          add_string(cs, file);          add_string(cs, file);
4057      }      }
4058    

Legend:
Removed from v.1.18  
changed lines
  Added in v.1.19

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26