1
1
/* 12AM COmmander, a Midnight Commander Lookalike for Agon Light.
2
2
11/05/2024
3
3
23/06/2024: added mode/font/video mode config
4
+ 21/07/2024: do case-insensitive compare. do not add path to filename in
5
+ commands.
4
6
*/
5
7
#include <stdio.h>
6
8
#include <string.h>
13
15
#include "mc.h"
14
16
15
17
18
+ int my_strcasecmp (char * p ,char * q )
19
+ {
20
+ char c1 ,c2 ;
21
+ for (;;) {
22
+ c1 = * p ++ ;
23
+ c2 = * q ++ ;
24
+ if (c1 >= 'a' && c1 <= 'z' ) c1 -= 0x20 ;
25
+ if (c2 >= 'a' && c2 <= 'z' ) c2 -= 0x20 ;
26
+ if (c1 != c2 ) return c1 - c2 ;
27
+ if ((c1 | c2 ) == 0 ) return 0 ;
28
+ }
29
+ }
30
+
16
31
char dirname_left [256 ];
17
32
char dirname_right [256 ];
18
33
struct dirlist * dirlist_left ;
@@ -94,11 +109,15 @@ void execute_command(char *cmdline,bool fWait)
94
109
char cmdbuf [256 ];
95
110
char pathbuf [256 ];
96
111
97
- void set_pathbuf (void )
112
+ void set_pathbuf (bool fFullPath )
98
113
{
99
- strcpy (pathbuf ,which_dir == 1 ?dirname_left :dirname_right );
100
- if (strcmp (pathbuf ,"/" )!= 0 ) {
101
- strcat (pathbuf ,"/" );
114
+ if (fFullPath ) {
115
+ strcpy (pathbuf ,which_dir == 1 ?dirname_left :dirname_right );
116
+ if (strcmp (pathbuf ,"/" )!= 0 ) {
117
+ strcat (pathbuf ,"/" );
118
+ }
119
+ } else {
120
+ pathbuf [0 ]= 0 ;
102
121
}
103
122
strcat (pathbuf ,dirlist_get_name (which_dir == 1 ?dirlist_left :dirlist_right ));
104
123
}
@@ -183,7 +202,6 @@ char * scan_word(char*dest, char *src)
183
202
return p ;
184
203
}
185
204
186
-
187
205
/* Replacement for fgets as the one in AgDev appears to be broken,
188
206
does not detect EOF on real machine */
189
207
static char * my_fgets (char * s , unsigned int maxlen , FILE * f )
@@ -215,12 +233,12 @@ void read_cfg_file(void)
215
233
cmdbuf [strlen (cmdbuf )- 1 ] = 0 ; /* Get rid of trailing newline */
216
234
p = cmdbuf ;
217
235
p = scan_word (pathbuf ,p );
218
- if (strcmp (pathbuf ,"view" ) == 0 ) {
236
+ if (my_strcasecmp (pathbuf ,"view" ) == 0 ) {
219
237
strcpy (viewer_cmd ,p );
220
- } else if (strcmp (pathbuf ,"edit" ) == 0 ) {
238
+ } else if (my_strcasecmp (pathbuf ,"edit" ) == 0 ) {
221
239
strcpy (editor_cmd ,p );
222
- } else if (strcmp (pathbuf ,"exec" ) == 0 || strcmp (pathbuf ,"execp" ) == 0 ) {
223
- do_pause = strcmp (pathbuf ,"execp" ) == 0 ;
240
+ } else if (my_strcasecmp (pathbuf ,"exec" ) == 0 || my_strcasecmp (pathbuf ,"execp" ) == 0 ) {
241
+ do_pause = my_strcasecmp (pathbuf ,"execp" ) == 0 ;
224
242
p = scan_word (pathbuf ,p );
225
243
while (* p ++ == ' ' )
226
244
;
@@ -232,9 +250,9 @@ void read_cfg_file(void)
232
250
233
251
n_extensions ++ ;
234
252
}
235
- } else if (strcmp (pathbuf ,"mode" ) == 0 ) {
253
+ } else if (my_strcasecmp (pathbuf ,"mode" ) == 0 ) {
236
254
video_mode = strtol (p ,& p ,10 );
237
- } else if (strcmp (pathbuf ,"font" ) == 0 ) {
255
+ } else if (my_strcasecmp (pathbuf ,"font" ) == 0 ) {
238
256
while (* p ++ == ' ' )
239
257
;
240
258
p -- ;
@@ -243,7 +261,7 @@ void read_cfg_file(void)
243
261
}else {
244
262
font_nr = strtol (p ,& p ,10 );
245
263
}
246
- } else if (strcmp (pathbuf ,"color" ) == 0 || strcmp (pathbuf ,"colour" ) == 0 ) {
264
+ } else if (my_strcasecmp (pathbuf ,"color" ) == 0 || my_strcasecmp (pathbuf ,"colour" ) == 0 ) {
247
265
fgcol = strtol (p ,& p ,10 );
248
266
bgcol = strtol (p ,& p ,10 );
249
267
hlcol = strtol (p ,& p ,10 );
@@ -335,8 +353,9 @@ main(int argc, char *argv[])
335
353
which_dir == 1 ?dirname_left :dirname_right );
336
354
} else {
337
355
mos_cd (which_dir == 1 ?dirname_left :dirname_right );
338
- set_pathbuf ();
356
+ set_pathbuf (false );
339
357
if (has_ext (pathbuf ,"bin" )) {
358
+ set_pathbuf (true);
340
359
execute_command (pathbuf ,false);
341
360
} else {
342
361
unsigned int i ;
@@ -362,12 +381,14 @@ main(int argc, char *argv[])
362
381
execute_command (cmdbuf ,true);
363
382
break ;
364
383
case 161 : /* F3 view */
365
- set_pathbuf ();
384
+ set_pathbuf (false);
385
+ mos_cd (which_dir == 1 ?dirname_left :dirname_right );
366
386
sprintf (cmdbuf ,viewer_cmd ,pathbuf );
367
387
execute_command (cmdbuf ,false);
368
388
break ;
369
389
case 162 : /* F4 Edit */
370
- set_pathbuf ();
390
+ set_pathbuf (false);
391
+ mos_cd (which_dir == 1 ?dirname_left :dirname_right );
371
392
sprintf (cmdbuf ,editor_cmd ,pathbuf );
372
393
execute_command (cmdbuf ,false);
373
394
break ;
@@ -384,10 +405,12 @@ main(int argc, char *argv[])
384
405
vdp_cursor_enable (true);
385
406
mos_editline (pathbuf ,256 ,true);
386
407
vdp_cursor_enable (false);
408
+ putch (12 );
387
409
mos_copy (cmdbuf ,pathbuf );
388
410
} else {
389
411
printf ("Copy %d selected files to %s? (Y/N)\n" ,n_selected ,which_dir == 1 ?dirname_right :dirname_left );
390
412
ch = getch ();
413
+ putch (12 );
391
414
if (ch == 'y' || ch == 'Y' ) {
392
415
nm = dirlist_first_selected (which_dir == 1 ?dirlist_left :dirlist_right );
393
416
while (nm != NULL ) {
@@ -416,10 +439,12 @@ main(int argc, char *argv[])
416
439
vdp_cursor_enable (true);
417
440
mos_editline (pathbuf ,256 ,true);
418
441
vdp_cursor_enable (false);
442
+ putch (12 );
419
443
mos_ren (cmdbuf ,pathbuf );
420
444
} else {
421
445
printf ("Move %d selected files to %s? (Y/N)\n" ,n_selected ,which_dir == 1 ?dirname_right :dirname_left );
422
446
ch = getch ();
447
+ putch (12 );
423
448
if (ch == 'y' || ch == 'Y' ) {
424
449
nm = dirlist_first_selected (which_dir == 1 ?dirlist_left :dirlist_right );
425
450
while (nm != NULL ) {
@@ -443,6 +468,7 @@ main(int argc, char *argv[])
443
468
vdp_cursor_enable (true);
444
469
mos_editline (cmdbuf ,256 ,true);
445
470
vdp_cursor_enable (false);
471
+ putch (12 );
446
472
mos_mkdir (cmdbuf );
447
473
cmd_reload_dir ();
448
474
break ;
@@ -457,12 +483,14 @@ main(int argc, char *argv[])
457
483
strcpy (cmdbuf ,dirlist_get_name (which_dir == 1 ?dirlist_left :dirlist_right ));
458
484
printf ("Delete file: %s? (Y/N)\n" ,cmdbuf );
459
485
ch = getch ();
486
+ putch (12 );
460
487
if (ch == 'y' || ch == 'Y' ) {
461
488
mos_del (cmdbuf );
462
489
}
463
490
} else {
464
491
printf ("Delete %d selected files? (Y/N)\n" ,n_selected );
465
492
ch = getch ();
493
+ putch (12 );
466
494
if (ch == 'y' || ch == 'Y' ) {
467
495
nm = dirlist_first_selected (which_dir == 1 ?dirlist_left :dirlist_right );
468
496
while (nm != NULL ) {
@@ -503,6 +531,7 @@ main(int argc, char *argv[])
503
531
vdp_cursor_enable (true);
504
532
mos_editline (cmdbuf ,256 ,true);
505
533
vdp_cursor_enable (false);
534
+ putch (12 );
506
535
dirlist_select_pattern (which_dir ,which_dir == 1 ?dirlist_left :dirlist_right ,cmdbuf );
507
536
break ;
508
537
case '\\' :
@@ -513,6 +542,7 @@ main(int argc, char *argv[])
513
542
vdp_cursor_enable (true);
514
543
mos_editline (cmdbuf ,256 ,true);
515
544
vdp_cursor_enable (false);
545
+ putch (12 );
516
546
dirlist_deselect_pattern (which_dir ,which_dir == 1 ?dirlist_left :dirlist_right ,cmdbuf );
517
547
break ;
518
548
case 12 : /* Ctrl-L, reload directories */
0 commit comments