Advertisement
Guest User

pate

a guest
Sep 15th, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <dirent.h>
  5. #include <string.h>
  6. #include <time.h>
  7. //#include <curses.h>
  8.  
  9. int main(void)
  10. {
  11. pid_t child;
  12. DIR* d;
  13. struct dirent* de;
  14. int i, c, k, number;
  15. char s[256], cmd[256];
  16. time_t t;
  17.  
  18. while(1)
  19. {
  20. t = time( NULL );
  21. printf( "\nTime: %s\n", ctime( &t ));
  22. getcwd(s, 200);
  23. printf( "Current Directory: %s\n", s );
  24.  
  25. d = opendir( "." );
  26. c = 0;
  27. char** dirNames = (char**)malloc(sizeof(char*)*256);
  28. for( i = 0; i < 256; i++ )
  29. dirNames[i] = (char*)malloc(sizeof(char)*256);
  30.  
  31. while( (de = readdir(d)) )
  32. {
  33. if( ((de->d_type) & DT_REG) )
  34. {
  35. strcpy(dirNames[c], de->d_name);
  36. c++;
  37. }
  38. }
  39. int n = 0;
  40. while( n < c )
  41. {
  42. printf( "%d. %s\n", n, dirNames[n] );
  43. if( n%9 == 0 && n!= 0 )
  44. {
  45. printf( "Hit N for Next\nHit P for Previous\nHit Q to choose\n" );
  46. k = getchar();
  47. if( k == 'N' || k == 'n' )
  48. {
  49. n++;
  50. continue;
  51. }
  52. else if ( k == 'P' || k == 'p' )
  53. {
  54. if( n >= 9 )
  55. {
  56. n = n - 9;
  57. continue;
  58. }
  59. else
  60. printf("Can't go previous\n");
  61. }
  62. else
  63. {
  64. break;
  65. }
  66. }
  67. n++;
  68. }
  69. closedir(d);
  70. printf("---------------------------------------------------------\n\n");
  71. printf("Press:\ne for Edit\nr for Run\nc for Change directory\nq for Quit\n");
  72. c = getchar(); getchar();
  73. switch( c )
  74. {
  75. case 'q': exit(0);
  76. case 'e': printf( "Edit what? (input number): " );
  77. scanf("%d", &number);
  78. strcpy(dirNames[n], s);
  79. strcpy(cmd, "pico ");
  80. strcat(cmd, s);
  81. system(cmd);
  82. break;
  83. case 'r': printf ( "Run what?: ");
  84. scanf("%s", cmd);
  85. system(cmd);
  86. break;
  87. case 'c': printf( "Change to? ");
  88. scanf("%s", cmd);
  89. chdir(cmd);
  90. break;
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement