void showDir(int i) { DIR *dirP; struct dirent *direntP; struct stat buf; if((dirP = opendir(".")) == NULL) sys_err("opendir()"); while((direntP = readdir(dirP)) != NULL) { if(direntP->d_name[0] == '.') continue; if(lstat(direntP->d_name, &buf) < 0) sys_err("lstat()"); int j = 0; for(; j < i; j++) printf(" "); printf("%s",direntP->d_name); if(S_ISDIR(buf.st_mode)) { printf("/\n"); if(chdir(direntP->d_name) < 0) sys_err("chdir()"); showDir(i + 1); } else printf("\n"); } chdir(".."); closedir(dirP); }
int main(int argc, char *argv[]) { if(argc != 2) { printf("argc not equal 2.\n"); exit(-1); } if(access(argv[1], F_OK) < 0) sys_err("access()"); if(chdir(argv[1]) < 0) sys_err("chdir()"); showDir(0); return 0; }
void control( void ) { while (1) { if ( isWait() ) waiting(); eleStat.dir = newDirection( eleStat.dir, eleStat.floor ); if ( isStop( eleStat.dir, eleStat.floor ) ) stop( eleStat.dir, eleStat.floor ); showDir( eleStat.dir ); if ( eleStat.dir != 0 && !isStop( eleStat.dir, eleStat.floor ) ) move( eleStat.dir, &eleStat.floor ); } }