home *** CD-ROM | disk | FTP | other *** search
- /* (C) Copyright 1993 by Mike W. Meyer
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose is hereby granted without
- * fee, provided that the above copyright notice appear in all copies
- * and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of Mike W.
- * Meyer not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior
- * permission. Mike W. Meyer makes no representations about the
- * suitability of this software for any purpose. It is provided "as
- * is" without express or implied warranty.
- *
- * MIKE W. MEYER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
- * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS, IN NO EVENT SHALL MIKE W. MEYER BE LIABLE FOR ANY SPECIAL,
- * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
- * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
- * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
- * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
- #include <exec/types.h>
- #include <exec/execbase.h>
- #include <dos/dos.h>
- #include <libraries/netsupport.h>
-
- #ifdef __SASC
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/netsupport.h>
- #else
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/netsupport_protos.h>
- #endif
-
- #include <stdio.h>
- #include <errno.h>
- #include "version.h"
-
- #ifdef __SASC_60
- #if (__REVISION__ - 50)
- static const char DOSId[] = "\0$VER: MUnpack " MPACK_VERSION " " __AMIGADATE__ ;
- #else
- static const char DOSId[] = "\0$VER: MUnpack " MPACK_VERSION " (" __DATE__ ")" ;
- #endif
- #endif
-
-
- extern char *myGetConfig(char *, char *);
- extern int optind;
- extern char *optarg;
-
- extern int overwrite_files ;
-
- #define TEMPLATE "Files/M,-f=Overwrite/S,-C=Directory/K"
- enum { FILES, OVERWRITE, DIRECTORY, OPT_COUNT } ;
- struct RDArgs *args = NULL, *my_args = NULL ;
- BPTR OldDir = NULL ;
- struct NetSupportLibrary *NetSupportBase;
-
- #define HELPSTRING "munpack version " MPACK_VERSION "\n\
- Unpack input files. If no files are present, reads from standard in. The\n\
- arguments other than file names are:\n\
- -f=Overwrite/S Causes the unpacked file to overwrite any existing\n\
- files of the same name. Otherwise, an extension\n\
- with a period and a number is added to the file\n\
- name.\n\
- -C=Directory/K Change to the given directory before unpacking.\n\
- Path names will be interpreted relative to the this\n\
- directory, not the current one.\n"
-
- void warn(char *) ;
-
- void
- FreeSystem(void) {
-
- if (NetSupportBase) {
- UnLockFiles() ;
- CloseLibrary((struct Library *) NetSupportBase) ;
- }
- if (args) FreeArgs(args) ;
- if (my_args) FreeDosObject(DOS_RDARGS, args) ;
- if (OldDir) UnLock(CurrentDir(OldDir)) ;
- }
-
- main(int argc, char **argv) {
- long opts[OPT_COUNT] ;
- FILE *file ;
- int goodenough ;
- extern struct ExecBase *SysBase ;
-
- if (!(NetSupportBase = (struct NetSupportLibrary *) OldOpenLibrary(NETSUPPORTNAME)))
- warn("Couldn't open NetSupport.Library: Can't parse configfiles.");
- goodenough = SysBase->LibNode.lib_Version > 36 ;
-
- /* Do the 2.x argument parsing stuff */
- if (!goodenough) opts[FILES] = argc ;
- else {
- onexit(FreeSystem) ;
- memset((char *) opts, 0, sizeof(opts)) ;
- if (!(my_args = AllocDosObject(DOS_RDARGS, NULL))) {
- PrintFault(IoErr(), *argv) ;
- exit(RETURN_FAIL) ;
- }
- my_args->RDA_ExtHelp = HELPSTRING ;
- if (!(args = ReadArgs(TEMPLATE, opts, my_args))) {
- PrintFault(IoErr(), *argv) ;
- exit(RETURN_FAIL) ;
- }
- overwrite_files = opts[OVERWRITE] ;
-
- if (opts[DIRECTORY])
- if (OldDir = Lock((char *) opts[DIRECTORY], SHARED_LOCK))
- OldDir = CurrentDir(OldDir) ;
- else PrintFault(IoErr(), (char *) opts[DIRECTORY]) ;
-
- argv = ((char **) opts[FILES]) - 1 ;
- }
-
- if (!opts[FILES]) {
- fprintf(stderr, "munpack: reading from standard input\n");
- handleMessage(stdin, "text/plain", 0) ;
- }
- else {
- while (*++argv)
- if (!(file = fopen(*argv, "r")))
- os_perror(*argv) ;
- else {
- handleMessage(file, "text/plain", 0) ;
- fclose(file) ;
- }
- }
-
- exit(0) ;
- }
-
- void
- warn(char *s) {
- fprintf(stderr, "munpack: warning: %s\n", s);
- }
-