/* Some example code and prototype - contains many, many problems: should check for return values (especially system calls), handle errors, not use fixed paths, handle parameters, put comments, watch out for buffer overflows, security problems, use environment variables, etc. */ #include #include #include #include #include #include int main(void) { pid_t child; DIR * d; struct dirent * de; int i, c; char s[256], cmd[256]; time_t t; while (1) { getcwd(s, 200); printf( "\nCurrent Directory: %s \n", s); d = opendir( "." ); c = 0; while ((de = readdir(d))){ printf( " ( %d %s %s ) ", c++, de->d_name, ((de->d_type) & DT_DIR) ? "Directory": "File" ) ; } closedir( d ); printf( "\n" ); c = getchar( ); switch (c) { case 'q': exit(0); /* quit */ case 'e': printf( "Edit what?:" ); scanf( "%s", s ); strcpy( cmd, "pico "); strcat( cmd, s ); system( cmd ); break; case 'r': printf( "Run what?:" ); scanf( "%s", cmd ); system( cmd ); break; case 'c': printf( "Change To?:" ); scanf( "%s", cmd ); chdir( cmd ); break; case 't': t = time( NULL ); printf( "Time: %s\n", ctime( &t )); break; } } }