#include "config.h" /* directory functions-- mainly unix stuff, needs work for VMS */ #ifndef VMS #include #include #ifndef NO_UNISTD_H #include #endif #endif #ifndef NO_STDLIB_H # include #endif #include "most.h" #include "buffer.h" #include "window.h" #include "file.h" void most_get_cdir(char *dir) { getcwd(dir, MAX_PATHLEN); #ifndef VMS { int i; i = strlen(dir); if (i && (dir[i - 1] != '/')) dir[i++] = '/'; dir[i] = 0; } #endif } #ifndef VMS /* This is a cheap routine-- should be replaced!!!! */ void bubble_sort (void) { unsigned char *this, *next, *save; char tmp[MAX_PATHLEN], *t; int change; change = 1; while(change) { next = this = Most_Beg; while((next < Most_Eob) && (*next++ != 0)); if (next == Most_Eob) return; change = 0; while(next < Most_Eob) { if (strcmp((char *)this,(char *) next) > 0) { change = 1; strcpy(tmp,(char *) this); t = tmp; while(*next != 0) *this++ = *next++; *this++ = 0; save = this; /* now next points at a null */ next++; while(*t != 0) *this++ = *t++; *this = 0; this = save; } else { this = next; while(next < Most_Eob && *next++ != 0); } } } } int most_get_dir(char *dir) { DIR *dirp; struct direct *dp; char *p; unsigned char *pos; int dsize, len, size = 4096, i; if (*dir == 0) dirp = opendir("."); else dirp = opendir(dir); if (dirp == NULL) { most_message("Unable to open directory.",1); return(0); } Most_Beg = (unsigned char *) MOSTMALLOC(size); strcpy(Most_Buf->file,dir); pos = Most_Beg; dsize = size; Most_Eob = Most_Beg + size; for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { p = dp->d_name; len = dp->d_namlen; if (pos + len >= Most_Eob - 1) { size += dsize; Most_Beg = (unsigned char *) MOSTREALLOC(Most_Beg,size); Most_Eob = Most_Beg + size; pos = Most_Eob - dsize; } strcpy(pos,p); pos += len; /* *pos++ = '\n'; */ *pos++ = '\0'; } Most_Buf->end = Most_Eob = pos; Most_Buf->beg = Most_Beg; closedir(dirp); bubble_sort(); i = 0; for (pos = Most_Beg; pos < Most_Eob; pos++) if (*pos == '\0') { if (i = !i, i) *pos = '\t'; else *pos = '\n'; } Most_Num_Lines = most_count_lines(Most_Beg,Most_Eob); Most_Buf->fd = -1; return(1); } #endif