// // simple directory listing // to run with SD card, define USE_SD // to run with host files, define USE_HOST; // in that case make sure -9. is given to the loadp2 program #define USE_SD //#define USE_HOST #include #include #include #include typedef struct Line Line; struct Line { char* s; /* string content */ size_t l; /* length excluding \0 */ size_t v; /* visual length */ size_t m; /* multiples of LINSIZ? */ Line* p; /* previous line */ Line* n; /* next line */ }; typedef struct { Line* l; size_t o; /* offset */ } Position; Position insertstr(Position p, char* src) { printf("#\n"); return; } int main() { //RJA: Testing Position p; char* s; p = insertstr(p, s); DIR *d; struct dirent *ent; struct stat sbuf; int r; #if defined(USE_SD) mount("/files", _vfs_open_sdcard()); chdir("/files"); #elif defined(USE_HOST) mount("/files", _vfs_open_host()); chdir("/files"); #else #warning no file system specified, I hope you are compiling for PC #endif d = opendir("."); if (!d) { printf("Unable to open directory\n"); return 1; } printf("Files in current directory:\n"); for(;;) { ent = readdir(d); if (!ent) break; r = stat(ent->d_name, &sbuf); if (r) { printf("??? error in stat of %s\n", ent->d_name); } else if ((sbuf.st_mode & S_IFMT) == S_IFDIR) { printf("%8s %s\n", "", ent->d_name); } else { printf("%8u %s\n", sbuf.st_size, ent->d_name); } } closedir(d); return 0; }