-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfms.c
More file actions
816 lines (735 loc) · 22.5 KB
/
fms.c
File metadata and controls
816 lines (735 loc) · 22.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <limits.h>
#include <errno.h>
#include <time.h>
#include <dirent.h>
#include "terminal_gui.h"
#include "platform.h"
#include "terminal_gui.h"
#ifdef _WIN32
#include <windows.h> // For Windows API
#include <lmcons.h> // For UNLEN (username length)
#include <direct.h> // For _mkdir
#else
#include <sys/statvfs.h>
#include <unistd.h>
#include <sys/stat.h> // For mkdir
#include <sys/resource.h> // For resource limits
#include <unistd.h> // For gethostname()
#include <sys/utsname.h> // For uname()
#include <pwd.h>
#endif
#ifndef PATH_MAX
#define PATH_MAX 4096 // A common default value for maximum path length
#endif
#define MAX_CONTENT_LENGTH 2048
#define MAX_CMD_LENGTH 256
// Function prototypes
void list_current_directory();
void create_file(const char *filename);
void write_file(const char *filename);
void overwrite_file(const char *filename);
void read_file(const char *filename);
void delete_file(const char *filename);
void display_file_metadata(const char *filename);
void copy_file(const char *source_filename, const char *dest_filename);
void rename_file(const char *old_filename, const char *new_filename);
void search_within_file(const char *filename, const char *search_term);
void create_directory(const char *dirname);
void delete_directory_recursive(const char *dirname);
void list_directory_recursive(const char *dirname, int depth);
void list_directory(const char *dirname);
void enter_directory(const char *dirname);
void exit_directory();
void display_system_info();
void current_directory();
void print_usage();
void process_command(char *cmd);
// Function to handle command input with GUI
void process_command(char *cmd)
{
char original_cmd[MAX_CMD_LENGTH];
strcpy(original_cmd, cmd);
char *token = strtok(cmd, " ");
if (token == NULL)
{
return;
}
int color_code = 4; // Default to "other" color
if (strcmp(token, "create-file") == 0)
{
color_code = 0; // File operations
char *filename = strtok(NULL, " ");
if (filename == NULL)
{
printf("Error: Missing filename argument.\n");
}
else
{
create_file(filename);
}
}
else if (strcmp(token, "write-file") == 0)
{
color_code = 0; // File operations
char *filename = strtok(NULL, " ");
if (filename == NULL)
{
printf("Error: Missing filename argument.\n");
}
else
{
write_file(filename);
}
}
else if (strcmp(token, "overwrite-file") == 0)
{
color_code = 0; // File operations
char *filename = strtok(NULL, " ");
if (filename == NULL)
{
printf("Error: Missing filename argument.\n");
}
else
{
overwrite_file(filename);
}
}
else if (strcmp(token, "read-file") == 0)
{
color_code = 0; // File operations
char *filename = strtok(NULL, " ");
if (filename == NULL)
{
printf("Error: Missing filename argument.\n");
}
else
{
read_file(filename);
}
}
else if (strcmp(token, "delete-file") == 0)
{
color_code = 0; // File operations
char *filename = strtok(NULL, " ");
if (filename == NULL)
{
printf("Error: Missing filename argument.\n");
}
else
{
delete_file(filename);
}
}
else if (strcmp(token, "copy-file") == 0)
{
color_code = 0; // File operations
char *source = strtok(NULL, " ");
char *dest = strtok(NULL, " ");
if (source == NULL || dest == NULL)
{
printf("Error: Missing source or destination argument.\n");
}
else
{
copy_file(source, dest);
}
}
else if (strcmp(token, "rename-file") == 0)
{
color_code = 0; // File operations
char *old_filename = strtok(NULL, " ");
char *new_filename = strtok(NULL, " ");
if (old_filename == NULL || new_filename == NULL)
{
printf("Error: Missing old or new filename argument.\n");
}
else
{
rename_file(old_filename, new_filename);
}
}
else if (strcmp(token, "search-file") == 0)
{
color_code = 0; // File operations
char *filename = strtok(NULL, " ");
char *term = strtok(NULL, "");
if (filename == NULL || term == NULL)
{
printf("Error: Missing filename or search term argument.\n");
}
else
{
search_within_file(filename, term);
}
}
else if (strcmp(token, "create-dir") == 0)
{
color_code = 1; // Directory operations
char *dirname = strtok(NULL, " ");
if (dirname == NULL)
{
printf("Error: Missing directory name argument.\n");
}
else
{
create_directory(dirname);
}
}
else if (strcmp(token, "delete-dir") == 0)
{
color_code = 1; // Directory operations
char *dirname = strtok(NULL, " ");
if (dirname == NULL)
{
printf("Error: Missing directory name argument.\n");
}
else
{
delete_directory_recursive(dirname);
}
}
else if (strcmp(token, "list-dir") == 0)
{
color_code = 1; // Directory operations
char *dirname = strtok(NULL, " ");
if (dirname == NULL)
{
printf("Error: Missing directory name argument.\n");
}
else
{
list_directory(dirname);
}
}
else if (strcmp(token, "enter-dir") == 0)
{
color_code = 3; // Navigation
char *dirname = strtok(NULL, " ");
if (dirname == NULL)
{
printf("Error: Missing directory name argument.\n");
}
else
{
enter_directory(dirname);
}
}
else if (strcmp(token, "exit-dir") == 0)
{
color_code = 3; // Navigation
exit_directory();
}
else if (strcmp(token, "metadata") == 0)
{
color_code = 0; // File operations
char *filename = strtok(NULL, " ");
if (filename == NULL)
{
printf("Error: Missing filename argument.\n");
}
else
{
display_file_metadata(filename);
}
}
else if (strcmp(token, "system-info") == 0)
{
color_code = 2; // System operations
display_system_info();
}
else if (strcmp(token, "show-path") == 0)
{
color_code = 3; // Navigation
current_directory(); // Reuse the existing function
}
else if (strcmp(token, "list-current") == 0)
{
color_code = 1; // Directory operations
list_current_directory();
}
else if (strcmp(token, "-h") == 0 || strcmp(token, "--help") == 0)
{
color_code = 4; // Other operations
print_usage();
}
else if (strcmp(token, "exit") == 0)
{
color_code = 4; // Other operations
printf("Exiting the program.\n");
exit(0);
}
else
{
printf("Invalid command. Type 'exit' to quit or '-h' for help.\n");
return; // Don't add invalid commands to history
}
// Add command to history
add_to_history(original_cmd, color_code);
// Show popup message
char popup_msg[100];
sprintf(popup_msg, "Command '%s' executed successfully", token);
show_popup_message(popup_msg);
}
// Below are the existing functions from your code, slightly modified to work with the GUI
void list_current_directory()
{
DIR *dir = opendir(".");
if (!dir)
{
perror("Error opening current directory");
return;
}
struct dirent *entry;
printf("%sContents of the current directory:%s\n", COLOR_CYAN, COLOR_RESET);
while ((entry = readdir(dir)) != NULL)
{
if (entry->d_type == DT_DIR)
{
printf("%s%s/%s\n", COLOR_BLUE, entry->d_name, COLOR_RESET);
}
else
{
printf("%s\n", entry->d_name);
}
}
closedir(dir);
}
void create_file(const char *filename)
{
if (filename == NULL || strlen(filename) == 0)
{
printf("%sError: Filename cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
FILE *file = fopen(filename, "w");
if (file == NULL)
{
perror("Error creating file");
return;
}
printf("%sFile '%s' created successfully.%s\n", COLOR_GREEN, filename, COLOR_RESET);
fclose(file);
}
void write_file(const char *filename)
{
if (filename == NULL || strlen(filename) == 0)
{
printf("%sError: Filename cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
FILE *file = fopen(filename, "a");
if (file == NULL)
{
perror("Error opening file");
return;
}
char content[MAX_CONTENT_LENGTH];
printf("%sEnter content to write. Type 'STOP' on a new line to finish.%s\n", COLOR_YELLOW, COLOR_RESET);
while (1)
{
printf("Enter line: ");
fgets(content, MAX_CONTENT_LENGTH, stdin);
if (strncmp(content, "STOP", 4) == 0 && content[4] == '\n')
{
break;
}
fprintf(file, "%s", content);
}
fclose(file);
printf("%sContent written to '%s'.%s\n", COLOR_GREEN, filename, COLOR_RESET);
}
void overwrite_file(const char *filename)
{
if (filename == NULL || strlen(filename) == 0)
{
printf("%sError: Filename cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
FILE *file = fopen(filename, "w");
if (file == NULL)
{
perror("Error opening file");
return;
}
char content[MAX_CONTENT_LENGTH];
printf("%sEnter new content to overwrite:%s ", COLOR_YELLOW, COLOR_RESET);
fgets(content, MAX_CONTENT_LENGTH, stdin);
fprintf(file, "%s", content);
fclose(file);
printf("%sFile '%s' overwritten successfully.%s\n", COLOR_GREEN, filename, COLOR_RESET);
}
void read_file(const char *filename)
{
if (filename == NULL || strlen(filename) == 0)
{
printf("%sError: Filename cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
FILE *file = fopen(filename, "r");
if (file == NULL)
{
perror("Error opening file");
return;
}
char content[MAX_CONTENT_LENGTH];
printf("%sContent of '%s':%s\n", COLOR_CYAN, filename, COLOR_RESET);
while (fgets(content, MAX_CONTENT_LENGTH, file) != NULL)
{
printf("%s", content);
}
fclose(file);
}
void delete_file(const char *filename)
{
if (filename == NULL || strlen(filename) == 0)
{
printf("%sError: Filename cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
if (remove(filename) == 0)
{
printf("%sFile '%s' deleted successfully.%s\n", COLOR_GREEN, filename, COLOR_RESET);
}
else
{
perror("Error deleting file");
}
}
void display_file_metadata(const char *filename)
{
if (filename == NULL || strlen(filename) == 0)
{
printf("%sError: Filename cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
struct stat fileStat;
if (stat(filename, &fileStat) < 0)
{
perror("Error retrieving file metadata");
return;
}
printf("\n%sFile Metadata for '%s':%s\n", COLOR_CYAN, filename, COLOR_RESET);
printf("File Size: %ld bytes\n", fileStat.st_size);
printf("File Permissions: %o\n", fileStat.st_mode & 0777);
printf("Last Access Time: %s", ctime(&fileStat.st_atime));
printf("Last Modification Time: %s", ctime(&fileStat.st_mtime));
}
void copy_file(const char *source_filename, const char *dest_filename)
{
if (source_filename == NULL || dest_filename == NULL || strlen(source_filename) == 0 || strlen(dest_filename) == 0)
{
printf("%sError: Source and destination filenames cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
FILE *source = fopen(source_filename, "r");
if (source == NULL)
{
perror("Error opening source file");
return;
}
FILE *dest = fopen(dest_filename, "w");
if (dest == NULL)
{
perror("Error opening destination file");
fclose(source);
return;
}
char content[MAX_CONTENT_LENGTH];
while (fgets(content, MAX_CONTENT_LENGTH, source) != NULL)
{
fputs(content, dest);
}
fclose(source);
fclose(dest);
printf("%sFile copied successfully from '%s' to '%s'.%s\n", COLOR_GREEN, source_filename, dest_filename, COLOR_RESET);
}
void rename_file(const char *old_filename, const char *new_filename) {
if (old_filename == NULL || new_filename == NULL || strlen(old_filename) == 0 || strlen(new_filename) == 0) {
printf("%sError: Old and new filenames cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
if (rename(old_filename, new_filename) == 0) {
printf("%sFile renamed successfully from '%s' to '%s'.%s\n", COLOR_GREEN, old_filename, new_filename, COLOR_RESET);
} else {
perror("Error renaming file");
}
}
void search_within_file(const char *filename, const char *search_term) {
if (filename == NULL || search_term == NULL || strlen(filename) == 0 || strlen(search_term) == 0) {
printf("%sError: Filename and search term cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
FILE *file = fopen(filename, "r");
if (file == NULL) {
perror("Error opening file");
return;
}
char line[MAX_CONTENT_LENGTH];
int line_number = 0;
int found = 0;
printf("%sSearching for '%s' in file '%s':%s\n", COLOR_CYAN, search_term, filename, COLOR_RESET);
while (fgets(line, sizeof(line), file) != NULL) {
line_number++;
if (strstr(line, search_term) != NULL) {
printf("Line %d: %s", line_number, line);
found = 1;
}
}
if (!found) {
printf("%sNo matches found for '%s'.%s\n", COLOR_YELLOW, search_term, COLOR_RESET);
}
fclose(file);
}
void create_directory(const char *dirname) {
if (dirname == NULL || strlen(dirname) == 0) {
printf("%sError: Directory name cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
#ifdef _WIN32
if (_mkdir(dirname) == 0) {
#else
if (mkdir(dirname, 0755) == 0) {
#endif
printf("%sDirectory '%s' created successfully.%s\n", COLOR_GREEN, dirname, COLOR_RESET);
} else {
perror("Error creating directory");
}
}
void delete_directory_recursive(const char *dirname) {
if (dirname == NULL || strlen(dirname) == 0) {
printf("%sError: Directory name cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
DIR *dir = opendir(dirname);
if (!dir) {
perror("Error opening directory");
return;
}
struct dirent *entry;
char path[PATH_MAX];
while ((entry = readdir(dir)) != NULL) {
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
snprintf(path, PATH_MAX, "%s/%s", dirname, entry->d_name);
if (entry->d_type == DT_DIR) {
delete_directory_recursive(path);
} else {
if (remove(path) != 0) {
printf("%sError removing file '%s'.%s\n", COLOR_RED, path, COLOR_RESET);
}
}
}
closedir(dir);
if (rmdir(dirname) == 0) {
printf("%sDirectory '%s' and its contents deleted successfully.%s\n", COLOR_GREEN, dirname, COLOR_RESET);
} else {
perror("Error deleting directory");
}
}
void list_directory_recursive(const char *dirname, int depth) {
if (dirname == NULL || strlen(dirname) == 0) {
printf("%sError: Directory name cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
DIR *dir = opendir(dirname);
if (!dir) {
perror("Error opening directory");
return;
}
struct dirent *entry;
char path[PATH_MAX];
while ((entry = readdir(dir)) != NULL) {
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
continue;
}
for (int i = 0; i < depth; i++) {
printf(" ");
}
snprintf(path, PATH_MAX, "%s/%s", dirname, entry->d_name);
if (entry->d_type == DT_DIR) {
printf("%s%s/%s\n", COLOR_BLUE, entry->d_name, COLOR_RESET);
list_directory_recursive(path, depth + 1);
} else {
printf("%s\n", entry->d_name);
}
}
closedir(dir);
}
void list_directory(const char *dirname) {
if (dirname == NULL || strlen(dirname) == 0) {
printf("%sError: Directory name cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
DIR *dir = opendir(dirname);
if (!dir) {
perror("Error opening directory");
return;
}
struct dirent *entry;
printf("%sContents of directory '%s':%s\n", COLOR_CYAN, dirname, COLOR_RESET);
while ((entry = readdir(dir)) != NULL) {
if (entry->d_type == DT_DIR) {
printf("%s%s/%s\n", COLOR_BLUE, entry->d_name, COLOR_RESET);
} else {
printf("%s\n", entry->d_name);
}
}
closedir(dir);
}
void enter_directory(const char *dirname) {
if (dirname == NULL || strlen(dirname) == 0) {
printf("%sError: Directory name cannot be empty.%s\n", COLOR_RED, COLOR_RESET);
return;
}
if (chdir(dirname) == 0) {
printf("%sEntered directory '%s'.%s\n", COLOR_GREEN, dirname, COLOR_RESET);
} else {
perror("Error changing directory");
}
}
void exit_directory() {
if (chdir("..") == 0) {
printf("%sExited to parent directory.%s\n", COLOR_GREEN, COLOR_RESET);
} else {
perror("Error changing to parent directory");
}
}
void display_system_info() {
printf("\n%s=== System Information ===%s\n", COLOR_CYAN, COLOR_RESET);
#ifdef _WIN32
// Windows specific code
TCHAR hostname[MAX_COMPUTERNAME_LENGTH + 1];
DWORD size = sizeof(hostname) / sizeof(hostname[0]);
if (GetComputerName(hostname, &size)) {
printf("Hostname: %s\n", hostname);
}
TCHAR username[UNLEN + 1];
size = sizeof(username) / sizeof(username[0]);
if (GetUserName(username, &size)) {
printf("User: %s\n", username);
}
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
if (GlobalMemoryStatusEx(&statex)) {
printf("Total RAM: %.2f GB\n", (float)statex.ullTotalPhys / (1024 * 1024 * 1024));
printf("Available RAM: %.2f GB\n", (float)statex.ullAvailPhys / (1024 * 1024 * 1024));
}
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
printf("Number of Processors: %u\n", sysInfo.dwNumberOfProcessors);
// Get Windows version
printf("Operating System: Windows\n");
#else
// Unix/Linux specific code
char hostname[1024];
if (gethostname(hostname, sizeof(hostname)) == 0) {
printf("Hostname: %s\n", hostname);
}
struct passwd *pw = getpwuid(getuid());
if (pw) {
printf("User: %s\n", pw->pw_name);
}
struct utsname uname_data;
if (uname(&uname_data) == 0) {
printf("Operating System: %s %s\n", uname_data.sysname, uname_data.release);
printf("Machine: %s\n", uname_data.machine);
}
// Get memory information
long pages = sysconf(_SC_PHYS_PAGES);
long page_size = sysconf(_SC_PAGE_SIZE);
if (pages > 0 && page_size > 0) {
float total_ram = (float)(pages * page_size) / (1024 * 1024 * 1024);
printf("Total RAM: %.2f GB\n", total_ram);
}
// Get CPU information
long num_procs = sysconf(_SC_NPROCESSORS_ONLN);
printf("Number of Processors: %ld\n", num_procs);
#endif
// Get disk space information
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
#ifdef _WIN32
ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
if (GetDiskFreeSpaceEx(cwd, &free_bytes, &total_bytes, &total_free_bytes)) {
printf("Disk Total Space: %.2f GB\n", (float)total_bytes.QuadPart / (1024 * 1024 * 1024));
printf("Disk Free Space: %.2f GB\n", (float)free_bytes.QuadPart / (1024 * 1024 * 1024));
}
#else
struct statvfs stat;
if (statvfs(cwd, &stat) == 0) {
printf("Disk Total Space: %.2f GB\n", (float)(stat.f_blocks * stat.f_frsize) / (1024 * 1024 * 1024));
printf("Disk Free Space: %.2f GB\n", (float)(stat.f_bfree * stat.f_frsize) / (1024 * 1024 * 1024));
}
#endif
}
// Current time
time_t now = time(NULL);
printf("Current Time: %s", ctime(&now));
}
void current_directory() {
char cwd[PATH_MAX];
if (getcwd(cwd, sizeof(cwd)) != NULL) {
printf("%sCurrent directory: %s%s\n", COLOR_CYAN, cwd, COLOR_RESET);
} else {
perror("Error getting current directory");
}
}
void print_usage() {
printf("\n%s=== File Management System Help ===%s\n", COLOR_CYAN, COLOR_RESET);
printf("%sFile Operations:%s\n", COLOR_YELLOW, COLOR_RESET);
printf(" create-file <filename> - Create a new file\n");
printf(" write-file <filename> - Append content to a file\n");
printf(" overwrite-file <filename> - Overwrite content of a file\n");
printf(" read-file <filename> - Display content of a file\n");
printf(" delete-file <filename> - Delete a file\n");
printf(" copy-file <source> <dest> - Copy a file\n");
printf(" rename-file <old> <new> - Rename a file\n");
printf(" search-file <filename> <term> - Search within a file\n");
printf(" metadata <filename> - Display file metadata\n");
printf("\n%sDirectory Operations:%s\n", COLOR_YELLOW, COLOR_RESET);
printf(" create-dir <dirname> - Create a new directory\n");
printf(" delete-dir <dirname> - Delete a directory recursively\n");
printf(" list-dir <dirname> - List contents of a directory\n");
printf(" list-current - List contents of current directory\n");
printf("\n%sNavigation:%s\n", COLOR_YELLOW, COLOR_RESET);
printf(" show-path - Display current directory path\n");
printf(" enter-dir <dirname> - Change to a directory\n");
printf(" exit-dir - Go to parent directory\n");
printf("\n%sSystem Operations:%s\n", COLOR_YELLOW, COLOR_RESET);
printf(" system-info - Display system information\n");
printf("\n%sOther Commands:%s\n", COLOR_YELLOW, COLOR_RESET);
printf(" -h, --help - Display this help information\n");
printf(" exit - Exit the program\n");
}
int main() {
// Initialize the terminal GUI
init_terminal_gui();
char cmd[MAX_CMD_LENGTH];
printf("\n%s=== File Management System ===%s\n", COLOR_CYAN, COLOR_RESET);
printf("Type '-h' for help, 'exit' to quit.\n\n");
while (1) {
printf("%s> %s", COLOR_GREEN, COLOR_RESET);
if (fgets(cmd, MAX_CMD_LENGTH, stdin) == NULL) {
break;
}
// Remove trailing newline
size_t len = strlen(cmd);
if (len > 0 && cmd[len-1] == '\n') {
cmd[len-1] = '\0';
}
if (strlen(cmd) > 0) {
process_command(cmd);
}
}
// Clean up the terminal GUI
cleanup_terminal_gui();
return 0;
}