/* * commands.cpp * * Created on: Aug 31, 2011 * Author: Tiberiu */ #include #include "app.h" RomDisk* disk = NULL; char* remove_quotes (char* str) { if (*str == '"') str = str + 1; int temp = strlen (str); if (str[temp-1] == '"') str[temp-1] = 0; return str; } int cmd_create (char** argv, int argc) { // Check number of parameters if (argc < 2) return 0; // Create a new disk disk = new RomDisk(); // Set path argv[1] = remove_quotes(argv[1]); disk->SetOutFile(argv[1]); printf("Created ramdisk '%s'.", argv[1]); return 1; } int cmd_close (char** argv, int argc) { if (!disk) fprintf(stderr, "Error: no romdisk opened!"); disk->Close(); delete disk; printf("Closed ramdisk '%s'.", argv[1]); return 1; } int cmd_mkdir (char** argv, int argc) { if (!disk) fprintf(stderr, "Error: no romdisk opened!"); if (argc < 2) return 0; argv[1] = remove_quotes(argv[1]); disk->AddDirectory(argv[1]); printf("Created directory '%s'.", argv[1]); return 1; } int cmd_cd (char** argv, int argc) { if (!disk) fprintf(stderr, "Error: no romdisk opened!"); if (argc < 2) return 0; argv[1] = remove_quotes(argv[1]); if (disk->ChangeCurrentDirectory(argv[1]) == -1) fprintf(stderr, "Error: invalid path."); printf("Changed directory to '%s'.", argv[1]); return 1; } int cmd_add (char** argv, int argc) { if (!disk) fprintf(stderr, "Error: no romdisk opened!"); if (argc < 2) return 0; argv[1] = remove_quotes(argv[1]); disk->AddFile(argv[1]); printf("Added file '%s'.", argv[1]); return 1; } int cmd_setflags (char** argv, int argc) { if (!disk) fprintf(stderr, "Error: no romdisk opened!"); if (argc < 2) return 0; argv[1] = remove_quotes(argv[1]); unsigned flags = strtoul(argv[1], 0, 16); disk->SetFlags(flags); printf("Changed flags to 0x%x.", flags); return 1; }