Rev 6857 | Rev 7802 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6857 | Rev 7024 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | { |
2 | { |
3 | 3 | ||
Line 4... | Line 4... | ||
4 | kol_struct70 k70; |
4 | kol_struct70 k70; |
5 | unsigned *n; |
5 | unsigned *n; |
6 | unsigned num_of_file; |
6 | unsigned num_of_file; // number of files in directory |
7 | unsigned *t; |
7 | unsigned *t; |
8 | unsigned type_of_file; |
8 | unsigned type_of_file; // check is this a file or a folder |
9 | int i, result; |
9 | int i, result; |
Line -... | Line 10... | ||
- | 10 | ||
- | 11 | bool single_column_mode = FALSE; |
|
Line 10... | Line 12... | ||
10 | 12 | ||
11 | 13 | ||
12 | k70.p00 = 1; |
14 | k70.p00 = 1; |
13 | k70.p04 = 0; |
15 | k70.p04 = 0; |
14 | //k70.p08 = 0; |
16 | //k70.p08 = 0; |
15 | k70.p12 = 2; // just for test exist & read number of entries |
17 | k70.p12 = 2; // just for test exist & read number of entries |
Line -... | Line 18... | ||
- | 18 | k70.p16 = (unsigned) malloc(32+k70.p12*560); |
|
- | 19 | k70.p20 = 0; |
|
- | 20 | ||
- | 21 | ||
16 | k70.p16 = (unsigned) malloc(32+k70.p12*560); |
22 | if (!strnicmp(dir,"-1",1)) |
17 | k70.p20 = 0; |
- | |
- | 23 | { |
|
- | 24 | single_column_mode = TRUE; |
|
18 | 25 | dir += 3; |
|
19 | /// !!! |
26 | } |
20 | // ᫨ ls § ¯ã᪠¥âáï ¡¥§ ¯ à ¬¥â஢, ¯à®á¬ âਢ ¥¬ ⥪ã騩 ª â «®£ |
27 | |
21 | if ( !strlen(dir) ) |
28 | if ( !strlen(dir) ) |
Line 22... | Line 29... | ||
22 | k70.p21 = cur_dir; |
29 | k70.p21 = cur_dir; |
23 | else |
30 | else |
24 | k70.p21 = dir; |
31 | k70.p21 = dir; |
25 | 32 | ||
26 | result = kol_file_70(&k70); |
33 | result = kol_file_70(&k70); |
27 | if ( !((result==0) || (result==6)) ) // ¯à®¢¥à塞 áãé¥á⢮¢ ¨¥ ª â «®£ |
34 | if ( !((result==0) || (result==6)) ) // check does the directory exists |
Line 28... | Line 35... | ||
28 | { |
35 | { |
29 | free( (void*) k70.p16); |
36 | free( (void*) k70.p16); |
Line 30... | Line 37... | ||
30 | return FALSE; |
37 | return FALSE; |
31 | } |
38 | } |
32 | 39 | ||
33 | n = (unsigned*) (k70.p16+8); |
40 | n = (unsigned*) (k70.p16+8); |
Line 46... | Line 53... | ||
46 | free( (void*) k70.p16); |
53 | free( (void*) k70.p16); |
47 | return FALSE; |
54 | return FALSE; |
48 | } |
55 | } |
49 | 56 | ||
Line -... | Line 57... | ||
- | 57 | // if there was '-1' param, then show single column mode |
|
- | 58 | // otherwise show files in several columns |
|
- | 59 | if (single_column_mode == TRUE) |
|
- | 60 | { |
|
- | 61 | _SINGLE_COLUMN_MODE: |
|
50 | for (i = 0; i < num_of_file; i++) |
62 | for (i = 0; i < num_of_file; i++) |
51 | { |
63 | { |
52 | printf (" %s", k70.p16+32+40+(264+40)*i); |
64 | printf (" %s", k70.p16+32+40+(264+40)*i); |
53 | t = (unsigned*) (k70.p16+32+(264+40)*i); |
65 | t = (unsigned*) (k70.p16+32+(264+40)*i); |
54 | type_of_file = *t; |
66 | type_of_file = *t; |
55 | if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) ) |
67 | if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) ) |
56 | printf ("/"); |
68 | printf ("/"); |
57 | printf ("\n\r"); |
69 | printf ("\n\r"); |
58 | } |
70 | } |
- | 71 | } |
|
- | 72 | else |
|
- | 73 | { |
|
- | 74 | int longest_name_len = 0; |
|
- | 75 | int console_window_width = 78; //need to get this value from console.obj if it's possible |
|
- | 76 | for (i = 0; i < num_of_file; i++) |
|
- | 77 | { |
|
- | 78 | int current_name_len; |
|
- | 79 | current_name_len = strlen( (char*)k70.p16+32+40+(264+40)*i); |
|
- | 80 | if (current_name_len > longest_name_len) longest_name_len = current_name_len; |
|
- | 81 | } |
|
- | 82 | ||
- | 83 | longest_name_len+=2; //consider space separator and '/' symbol for folders |
|
- | 84 | int columns_max = console_window_width / longest_name_len; |
|
- | 85 | ||
- | 86 | if (longest_name_len >= console_window_width) goto _SINGLE_COLUMN_MODE; //there was too long filename |
|
- | 87 | ||
- | 88 | for (i = 0; i < num_of_file; i++) |
|
- | 89 | { |
|
- | 90 | char cur_file[2048]; |
|
- | 91 | strncpy(cur_file, (char*)k70.p16+32+40+(304)*i, sizeof(cur_file)-2); |
|
- | 92 | ||
- | 93 | t = (unsigned*) (k70.p16+32+(304)*i); |
|
- | 94 | type_of_file = *t; |
|
- | 95 | ||
- | 96 | if ( (0x10 == (type_of_file&0x10)) || (8 == (type_of_file&8)) ) strcat(cur_file, "/"); |
|
- | 97 | ||
- | 98 | printf ("%*s", -longest_name_len, cur_file); |
|
- | 99 | ||
- | 100 | if ((i>0) && ((i+1)%columns_max == 0)) printf ("\n\r"); |
|
- | 101 | } |
|
- | 102 | if ((i)%columns_max != 0) printf("\n\r"); |
|
- | 103 | } |
|
Line 59... | Line 104... | ||
59 | 104 | ||
60 | free((void*)k70.p16); |
105 | free((void*)k70.p16); |
61 | return TRUE; |
106 | return TRUE; |