Ejemplo n.º 1
0
// osdir_list_start -- prepare to list a directory
int osdir_list_start(char *path)
{
   if (strlen(path) >= OSDIR_MAX_PATH - 2) {
      xlcerror("LISTDIR path too big", "return nil", NULL);
      return FALSE;
   }
   strcpy(osdir_path, path);
   strcat(osdir_path, "/*"); // make a pattern to match all files

   if (osdir_list_status != OSDIR_LIST_READY) {
      osdir_list_finish(); // close previously interrupted listing
   }

   hFind = FindFirstFile(osdir_path, &FindFileData); // get the "."
   if (hFind == INVALID_HANDLE_VALUE) {
      return FALSE;
   }
   if (FindNextFile(hFind, &FindFileData) == 0) {
      return FALSE; // get the ".."
   }

   osdir_list_status = OSDIR_LIST_STARTED;

   return TRUE;
}
Ejemplo n.º 2
0
/* osdir_list_start -- open a directory listing */
int osdir_list_start(char *path)
{
   if (osdir_list_status != OSDIR_LIST_READY) {
      osdir_list_finish(); /* close current listing */
   }
   osdir_dir = opendir(path);
   if (!osdir_dir) {
      return FALSE;
   }
   osdir_list_status = OSDIR_LIST_STARTED;
   return TRUE;
}
Ejemplo n.º 3
0
LVAL xlistdir(void)
{
    const char *path;
    LVAL result = NULL;
    LVAL *tail;
    /* get the path, converting unsigned char * to char * */
    path = (char *)getstring(xlgetfname());
    /* try to start listing */
    if (osdir_list_start(path)) {
        const char *filename;
        xlsave1(result);
        tail = &result;
        while ((filename = osdir_list_next())) {
            *tail = cons(NIL, NIL);
            rplaca(*tail, cvstring(filename));
            tail = &cdr(*tail);
        }
        osdir_list_finish();
        xlpop();
    }
    return result;
}