static int do_cmd(int cmd, int argc, const char *argv[]) { switch (cmd) { case CMD_INTERACTIVE: case CMD_UNKNOWN: return cmd_loop(argc, argv); break; case CMD_CD: return cmd_cd(argv[0]); break; case CMD_PWD: return cmd_pwd(); break; case CMD_LS: return cmd_ls(argc, argv); break; case CMD_MKDIR: return cmd_mkdir(argc, argv); break; case CMD_LN: return cmd_ln(argc, argv); break; case CMD_RM: return cmd_rm(argc, argv); break; case CMD_MV: return cmd_mv(argc, argv); break; case CMD_CP: return cmd_cp(argc, argv); break; case CMD_CAT: return cmd_cat(argc, argv); break; case CMD_STAT: return cmd_stat(argc, argv); break; case CMD_QUIT: exit(EXIT_SUCCESS); break; default: return -1; break; } }
int main(int argc, const char *argv[]) { io_func* io; Volume* volume; TestByteOrder(); if(argc < 3) { printf("usage: %s <image-file> <ls|cat|mv|symlink|mkdir|add|rm|chmod|extract|extractall|rmall|addall|grow|getattr|debug> <arguments>\n", argv[0]); return 0; } io = openFlatFile(argv[1]); if(io == NULL) { fprintf(stderr, "error: Cannot open image-file.\n"); return 1; } volume = openVolume(io); if(volume == NULL) { fprintf(stderr, "error: Cannot open volume.\n"); CLOSE(io); return 1; } if(argc > 1) { if(strcmp(argv[2], "ls") == 0) { cmd_ls(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "cat") == 0) { cmd_cat(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "mv") == 0) { cmd_mv(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "symlink") == 0) { cmd_symlink(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "mkdir") == 0) { cmd_mkdir(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "add") == 0) { cmd_add(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "rm") == 0) { cmd_rm(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "chmod") == 0) { cmd_chmod(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "extract") == 0) { cmd_extract(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "extractall") == 0) { cmd_extractall(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "rmall") == 0) { cmd_rmall(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "addall") == 0) { cmd_addall(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "grow") == 0) { cmd_grow(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "getattr") == 0) { cmd_getattr(volume, argc - 2, argv + 2); } else if(strcmp(argv[2], "debug") == 0) { if(argc > 3 && strcmp(argv[3], "verbose") == 0) { debugBTree(volume->catalogTree, TRUE); } else { debugBTree(volume->catalogTree, FALSE); } } } closeVolume(volume); CLOSE(io); return 0; }
/* execute command */ EXPORT INT exec_cmd(B *cmd) { INT ac; B *av[N_ARGS]; ac = setup_param(cmd, av); if (ac < 1) return 0; if (strcmp(av[0], "date") == 0) { cmd_date(ac, av); } else if (strcmp(av[0], "attach") == 0) { cmd_attach(ac, av); } else if (strcmp(av[0], "detach") == 0) { cmd_detach(ac, av); } else if (strcmp(av[0], "mkdir") == 0) { cmd_mkdir(ac, av); } else if (strcmp(av[0], "rmdir") == 0) { cmd_rmdir(ac, av); } else if (strcmp(av[0], "pwd") == 0) { cmd_pwd(ac, av); } else if (strcmp(av[0], "cd") == 0) { cmd_cd(ac, av); } else if (strcmp(av[0], "rm") == 0) { cmd_rm(ac, av); } else if (strcmp(av[0], "mv") == 0) { cmd_mv(ac, av); } else if (strcmp(av[0], "ls") == 0) { cmd_ls(ac, av); } else if (strcmp(av[0], "tp") == 0 || strcmp(av[0], "tpx") == 0) { cmd_tp(ac, av); } else if (strcmp(av[0], "cp") == 0) { cmd_cp(ac, av); } else if (strcmp(av[0], "trunc") == 0) { cmd_trunc(ac, av); } else if (strcmp(av[0], "df") == 0) { cmd_df(ac, av); } else if (strcmp(av[0], "sync") == 0) { cmd_sync(ac, av); } else if (strcmp(av[0], "chmod") == 0) { cmd_chmod(ac, av); } else if (strcmp(av[0], "ref") == 0) { cmd_ref(ac, av); } else if (strcmp(av[0], "load") == 0) { cmd_load(ac, av); } else if (strcmp(av[0], "loadspg") == 0) { cmd_loadspg(ac, av); } else if (strcmp(av[0], "unload") == 0) { cmd_unload(ac, av); } else if (strcmp(av[0], "call") == 0) { cmd_call(ac, av); } else if (strncmp(av[0], "?", 1) == 0) { P("date [y m d [h m s]]\n"); P("attach devnm connm\n"); P("detach connm\n"); P("cd dir\n"); P("pwd \n"); P("ls [-t][-l][dir]\n"); P("mkdir dir [mode]\n"); P("rmdir dir\n"); P("rm path\n"); P("mv o-path n-path\n"); P("trunc path len\n"); P("df path\n"); P("sync [path [d]]\n"); P("chmod path mode\n"); P("tp path [ofs len]\n"); P("tpx path [ofs len]\n"); P("cp s-path d-path/dir [wofs [wlen]]\n"); P("ref [item]\n"); P("call addr [p1 p2 p3]\n"); P("load path\n"); P("loadspg path [arg ...]\n"); P("unload progid\n"); #ifdef NET_SAMPLE P("net execute network sample\n"); } else if (strcmp(av[0], "net") == 0) { IMPORT void net_test(void); net_test(); #endif } else { return 0; } return 1; }
int main(int argc, const char *argv[]) { io_func* io; Volume* volume; AbstractFile* image; int argOff; TestByteOrder(); if(argc < 3) { printf("usage: %s <image-file> (-k <key>) <ls|cat|mv|mkdir|add|rm|chmod|extract|extractall|rmall|addall|grow|untar> <arguments>\n", argv[0]); return 0; } argOff = 2; if(strstr(argv[1], ".dmg")) { image = createAbstractFileFromFile(fopen(argv[1], "rb")); if(argc > 3) { if(strcmp(argv[2], "-k") == 0) { image = createAbstractFileFromFileVault(image, argv[3]); argOff = 4; } } io = openDmgFilePartition(image, -1); } else { io = openFlatFile(argv[1]); } if(io == NULL) { fprintf(stderr, "error: Cannot open image-file.\n"); return 1; } volume = openVolume(io); if(volume == NULL) { fprintf(stderr, "error: Cannot open volume.\n"); CLOSE(io); return 1; } if(argc > argOff) { if(strcmp(argv[argOff], "ls") == 0) { cmd_ls(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "cat") == 0) { cmd_cat(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "mv") == 0) { cmd_mv(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[2], "symlink") == 0) { cmd_symlink(volume, argc - 2, argv + 2); } else if(strcmp(argv[argOff], "mkdir") == 0) { cmd_mkdir(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "add") == 0) { cmd_add(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "rm") == 0) { cmd_rm(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "chmod") == 0) { cmd_chmod(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "extract") == 0) { cmd_extract(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "extractall") == 0) { cmd_extractall(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "rmall") == 0) { cmd_rmall(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "addall") == 0) { cmd_addall(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "grow") == 0) { cmd_grow(volume, argc - argOff, argv + argOff); } else if(strcmp(argv[argOff], "untar") == 0) { cmd_untar(volume, argc - argOff, argv + argOff); } } closeVolume(volume); CLOSE(io); return 0; }