/*---------------------------------------------------------------------------* Project: archiver for Revolution dvd File: darch.c Copyright (C) 2001-2006 Nintendo All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: darch.c,v $ Revision 1.3.4.1 2008/09/09 11:42:52 nakano_yoshinobu Update version number. Revision 1.4 2008/08/08 02:15:34 nakano_yoshinobu Updated its version number to 1.03. Revision 1.3 2007/11/16 05:08:53 nakano_yoshinobu Removed #include Windows.h. Revision 1.2 2006/04/27 05:27:01 yasuh-to Modified error handling when any arguments are not there. Revision 1.1 2006/04/20 01:41:22 hiratsu Initial check-in. 4 03/05/01 14:56 Hashida Updated its version number to 1.02. 3 7/31/01 11:29a Hashida Removed a redundant options from major option list, and sorted alphabetically. 2 7/09/01 7:01p Hashida Modified to mention -V option in usage(). 1 7/02/01 11:34p Hashida Initial revision. $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include #include #include #include #include #include "darch.h" #define VERSION "1.03" char fstFile[FILENAME_MAX]; char userFile[FILENAME_MAX]; static char arcFile[FILENAME_MAX]; char arcRoot[FILENAME_MAX]; char* progName; int debugMode = 0; diskMap map; void* BigBuffer; static unsigned int MajorMode = 0; #define MAJOR_MODE_CREATE 0x0001 #define MAJOR_MODE_LIST 0x0002 #define MAJOR_MODE_EXTRACT 0x0004 #define MAJOR_MODE_DIFF 0x0008 #define MAJOR_MODE_DELETE 0x0010 #define MAJOR_MODE_REPLACE 0x0020 #define MAJOR_MODE_LIST_IN_DISC_ORDER 0x0040 static char* MajorOptions = "`-cdeltx'"; int verbose = 0; #define ARGUMENTS_MAX 256 static Arg_s Arg[ARGUMENTS_MAX]; static int ArgCount = 0; static void usage(void) { fprintf(stderr, "\n"); fprintf(stderr, "Usage: %s [-c files/directories ...] [-d directory] [-x directory] [-e files/directories...] [-htlvV] file\n", progName); fprintf(stderr, "\n"); fprintf(stderr, " -c Creates a new archive\n"); fprintf(stderr, " -t Lists the contents of an archive in tar-like order\n"); fprintf(stderr, " -l Lists the contents of an archive in the order in disc\n"); fprintf(stderr, " -x Extracts files from an archive\n"); fprintf(stderr, " -d Finds differences between archive and file system\n"); fprintf(stderr, " -e Erases files/directories from an archive\n"); fprintf(stderr, " -v Turns on verbose mode\n"); fprintf(stderr, " -V Shows version number\n"); fprintf(stderr, " -h Prints this message and exit\n"); fprintf(stderr, " file Archive file\n"); } int main(int argc, char *argv[]) { char* p; char* currDir = "."; char** argStartMinus1; if ( (progName = strrchr(argv[0], '/')) != NULL ) { progName++; } else { progName = argv[0]; } while (--argc > 0) { if (**(++argv) == '-') { p = *argv; while (*++p) { switch (*p) { case 'h': usage(); exit(0); break; case 'C': currDir = *++argv; argc--; break; case 'c': argStartMinus1 = argv; if (argc == 1) { fprintf(stderr, "%s: You need to specify at least one" " directory/file\n", progName); exit(1); } while ( (*argv[1] != '-') && (argv[2] != NULL) ) { argv++; argc--; } Arg[ArgCount].currDir = currDir; Arg[ArgCount].argStart = argStartMinus1 + 1; Arg[ArgCount].argNum = argv - argStartMinus1; if(++ArgCount >= ARGUMENTS_MAX) { fprintf(stderr, "%s: Too many arguments\n", progName); exit(1); } MajorMode |= MAJOR_MODE_CREATE; break; case 'e': argStartMinus1 = argv; if (argc == 1) { fprintf(stderr, "%s: You need to specify at least one" " directory/file to erase\n", progName); exit(1); } while ( (*argv[1] != '-') && (argv[2] != NULL) ) { argv++; argc--; } Arg[ArgCount].currDir = currDir; Arg[ArgCount].argStart = argStartMinus1 + 1; Arg[ArgCount].argNum = argv - argStartMinus1; if(++ArgCount >= ARGUMENTS_MAX) { fprintf(stderr, "%s: Too many arguments\n", progName); exit(1); } MajorMode |= MAJOR_MODE_DELETE; break; case 'd': if (argc == 1) { fprintf(stderr, "%s: You need to specify " " a directory to see the difference\n", progName); exit(1); } strcpy(arcRoot, *++argv); argc--; MajorMode |= MAJOR_MODE_DIFF; break; case 't': MajorMode |= MAJOR_MODE_LIST; break; case 'l': MajorMode |= MAJOR_MODE_LIST_IN_DISC_ORDER; break; case 'x': if (argc == 1) { fprintf(stderr, "%s: You need to specify a" " directory name to extract\n", progName); exit(1); } strcpy(arcRoot, *++argv); argc--; MajorMode |= MAJOR_MODE_EXTRACT; break; case 'v': verbose = 1; break; case 'V': fprintf(stderr, "Revolution archiver v.%s\n", VERSION); exit(0); break; default: fprintf(stderr, "%s: Unknown option -- %c\n", progName, *p); usage(); exit(1); break; } } } else break; } if (debugMode) { int i, j; for (i = 0; i < ArgCount; i++) { fprintf(stderr, "curr dir is %s\n", Arg[i].currDir); fprintf(stderr, "directories to erase is "); for(j = 0; j < Arg[i].argNum; j++) { fprintf(stderr, "%s ", (Arg[i].argStart)[j]); } fprintf(stderr, "\n"); fprintf(stderr, "\n"); } } if (argc == 0) { fprintf(stderr, "%s: You need to specify archive file name\n", progName); usage(); exit(1); } if (argc > 1) { fprintf(stderr, "%s: You may not specify more than one archive file name\n", progName); usage(); exit(1); } strcpy(arcFile, *argv); // Check if only one major mode was specified if ( ((MajorMode - 1) & MajorMode) != 0 ) { fprintf(stderr, "%s: You may not specify more than one %s option\n", progName, MajorOptions); usage(); exit(1); } if (MajorMode == 0) { fprintf(stderr, "%s: You must specify one of the %s options\n", progName, MajorOptions); usage(); exit(1); } if (debugMode) { fprintf(stdout, "output file name is %s\n", arcFile); fprintf(stdout, "root is %s\n", arcRoot); } if ( NULL == (BigBuffer = malloc(ALLOC_MEMSIZE)) ) { fprintf(stderr, "%s: malloc failed\n", progName); exit(1); } switch (MajorMode) { case MAJOR_MODE_CREATE: CreateArc(arcFile, Arg, ArgCount); break; case MAJOR_MODE_LIST: ListArc(arcFile); break; case MAJOR_MODE_LIST_IN_DISC_ORDER: ListArcInDiscOrder(arcFile); break; case MAJOR_MODE_EXTRACT: ExtractArc(arcFile, arcRoot); break; case MAJOR_MODE_DIFF: DiffArc(arcFile, arcRoot); break; case MAJOR_MODE_DELETE: DeleteArc(arcFile, Arg, ArgCount); break; } free(BigBuffer); return 0; }