Subversion Repositories Kolibri OS

Rev

Rev 7802 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1665 Nasarus 1
 
8827 rgimad 2
1665 Nasarus 3
 
8827 rgimad 4
	unsigned	*n;
5
	unsigned	num_of_file; // number of files in directory
6
	unsigned	*t;
7
	unsigned	type_of_file; // check is this a file or a folder
8
	int		i, result;
9
	char tmp[FILENAME_MAX];
10
1665 Nasarus 11
 
8827 rgimad 12
2617 Albom 13
 
7024 leency 14
 
8827 rgimad 15
	k70.p04 = 0;
16
	//k70.p08 = 0;
17
	k70.p12 = 2;  // just for test exist & read number of entries
18
	k70.p16 =  (unsigned) malloc(32+k70.p12*560);
19
	k70.p20 = 0;
20
1665 Nasarus 21
 
7024 leency 22
 
8827 rgimad 23
		{
24
		single_column_mode = TRUE;
25
		dir += 3;
26
		}
27
7024 leency 28
 
8827 rgimad 29
		k70.p21 = cur_dir;
30
	else
31
	{
7802 rgimad 32
		if (dir[0] != '/') // if given directory is relative path, then append cur_dir on left side
8827 rgimad 33
		{
34
			strcpy(tmp, cur_dir);
35
			if (tmp[strlen(tmp)-1] != '/')
36
			{
37
				strcat(tmp, "/"); // add slash
38
			}
39
			strcat(tmp, dir);
40
			k70.p21 = tmp;
41
		} else // if given directory is an absolute path
42
		{
43
			k70.p21 = dir;
44
		}
45
	}
7802 rgimad 46
2617 Albom 47
 
8827 rgimad 48
	if ( !((result==0) || (result==6)) ) // check does the directory exists
49
		{
50
		free( (void*) k70.p16);
51
		return FALSE;
52
		}
53
1665 Nasarus 54
 
8827 rgimad 55
	num_of_file = *n;
56
1665 Nasarus 57
 
8827 rgimad 58
	k70.p12 = num_of_file;
59
	free( (void*) k70.p16);
6857 siemargl 60
	k70.p16 =  (unsigned) malloc(32+k70.p12*560);
8827 rgimad 61
	if ( !k70.p16 )
62
		return FALSE;
63
64
 
65
	if ( !((result==0) || (result==6)) )
66
		{
67
		free( (void*) k70.p16);
68
		return FALSE;
69
		}
70
6857 siemargl 71
 
8827 rgimad 72
	// otherwise show files in several columns
73
	if (single_column_mode == TRUE)
74
	{
1665 Nasarus 75
	_SINGLE_COLUMN_MODE:
8827 rgimad 76
		for (i = 0; i < num_of_file; i++)
77
		{
7024 leency 78
		printf ("  %s", k70.p16+32+40+(264+40)*i);
8827 rgimad 79
		t =  (unsigned*) (k70.p16+32+(264+40)*i);
80
		type_of_file = *t;
81
		if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) )
82
			printf ("/");
83
		printf ("\n\r");
84
		}
7024 leency 85
	}
8827 rgimad 86
	else
87
	{
88
		int longest_name_len = 0;
89
		int console_window_width = 78; //need to get this value from console.obj if it's possible
90
		for (i = 0; i < num_of_file; i++)
91
			{
92
			int current_name_len;
93
			current_name_len = strlen( (char*)k70.p16+32+40+(264+40)*i);
94
			if (current_name_len > longest_name_len) longest_name_len = current_name_len;
95
			}
96
1665 Nasarus 97
 
8827 rgimad 98
		int columns_max = console_window_width / longest_name_len;
99
7024 leency 100
 
8827 rgimad 101
7024 leency 102
 
8827 rgimad 103
			{
104
			char cur_file[2048];
105
			strncpy(cur_file, (char*)k70.p16+32+40+(304)*i, sizeof(cur_file)-2);
106
7024 leency 107
 
8827 rgimad 108
			type_of_file = *t;
109
110
 
111
			if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) ) { is_folder = 1; strcat(cur_file, "/"); }
112
7024 leency 113
 
8827 rgimad 114
			printf ("%*s", -longest_name_len, cur_file);
115
			if (is_folder) { printf("\033[0m"); } // is had been set, reset
116
7024 leency 117
 
8827 rgimad 118
			}
119
		if ((i)%columns_max != 0) printf("\n\r");
120
	}
121
7024 leency 122
 
8827 rgimad 123
	return TRUE;
124
}
1665 Nasarus 125