View difference between Paste ID: NLLZ660h and nf3WcyGb
SHOW: | | - or go back to the newest paste.
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;
11+
	pid_t child;
12
    DIR* d;
13
    struct dirent* de;
14
    int i, c, k, number;
15-
    char s[256], cmd[256];
15+
    char s[256], cmd[256], dirNames[256][256], regNames[256][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-
       
24+
		d = opendir( "." );
25
		c = 0;
26
		while( (de = readdir(d)) )
27-
                char** dirNames = (char**)malloc(sizeof(char*)*256);
27+
		{
28-
                for( i = 0; i < 256; i++ )
28+
			if( ((de->d_type) & DT_DIR) )
29-
                        dirNames[i] = (char*)malloc(sizeof(char)*256);
29+
			{
30
				strcpy(dirNames[c], (de->d_name));
31-
                while( (de = readdir(d)) )
31+
				printf("%d Directory: %s\n", c, de->d_name);
32-
                {
32+
				c++;
33-
					if( ((de->d_type) & DT_REG) )
33+
			}
34
		}
35-
						strcpy(dirNames[c], de->d_name);
35+
		closedir(d);
36-
						c++;
36+
		
37
        d = opendir( "." );
38-
                }
38+
39-
                int n = 0;
39+
		while( (de = readdir(d)) )
40-
                while( n < c )
40+
		{
41-
                {
41+
			if( ((de->d_type) & DT_REG) )
42-
                        printf( "%d. %s\n", n, dirNames[n] );
42+
			{
43-
						if( n%9 == 0 && n!= 0 )
43+
				strcpy(regNames[c], (de->d_name));
44
				c++;
45-
							printf( "Hit N for Next\nHit P for Previous\nHit Q to choose\n" );
45+
			}
46-
							k = getchar();
46+
		}
47-
							if( k == 'N' || k == 'n' )
47+
		int n = 0;
48-
							{
48+
		while( n < c )
49-
								n++;
49+
		{
50-
								continue;
50+
				printf( "Files %d: %s\n", n, regNames[n] );
51-
							}
51+
				if( n%9 == 0 && n!= 0 )
52-
							else if ( k == 'P' || k == 'p' )
52+
				{
53-
							{
53+
					printf( "Hit N for Next\nHit P for Previous\nHit Q to choose\n" );
54-
								if( n >= 9 )
54+
					k = getchar();
55-
								{
55+
					if( k == 'N' || k == 'n' )
56-
									n = n - 9;
56+
57-
									continue;
57+
58-
								}
58+
						continue;
59-
								else
59+
60-
									printf("Can't go previous\n");
60+
					else if ( k == 'P' || k == 'p' )
61-
							}
61+
62-
							else
62+
						if( n >= 9 )
63-
							{
63+
64-
								break;
64+
							n = n - 9;
65-
							}
65+
							continue;
66
						}
67
						else
68-
                }
68+
							printf("Can't go previous\n");
69
					}
70
					else
71
					{
72
						break;
73
					}
74
				}
75
				n++;
76
		}
77
        closedir(d);
78-
                            strcpy(dirNames[n], s);
78+
79
                printf("Press:\ne for Edit\nr for Run\nc for Change directory\nq for Quit\n");
80
        c = getchar(); getchar();
81
        switch( c )
82
        {
83
            case 'q':   exit(0);
84
            case 'e':   printf( "Edit what? (input number): " );
85
							scanf("%d", &number);
86
                            strcpy(regNames[n], s);
87
                            strcpy(cmd, "pico ");
88
                            strcat(cmd, s);
89
                            system(cmd);
90
                            break;
91
            case 'r':   printf ( "Run what?: ");
92
                        scanf("%s", cmd);
93
                        system(cmd);
94
                        break;
95
            case 'c':   printf( "Change to? ");
96
                        scanf("%s", cmd);
97
                        chdir(cmd);
98
                        break;
99
        }
100
    }
101
}