home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / MPack1_2_1.lha / MPack / src / amigaunpk.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-31  |  5.0 KB  |  142 lines

  1. /* (C) Copyright 1993 by Mike W. Meyer
  2.  *
  3.  * Permission to use, copy, modify, distribute, and sell this software
  4.  * and its documentation for any purpose is hereby granted without
  5.  * fee, provided that the above copyright notice appear in all copies
  6.  * and that both that copyright notice and this permission notice
  7.  * appear in supporting documentation, and that the name of Mike W.
  8.  * Meyer not be used in advertising or publicity pertaining to
  9.  * distribution of the software without specific, written prior
  10.  * permission.  Mike W. Meyer makes no representations about the
  11.  * suitability of this software for any purpose.  It is provided "as
  12.  * is" without express or implied warranty.
  13.  *
  14.  * MIKE W. MEYER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  15.  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  16.  * FITNESS, IN NO EVENT SHALL MIKE W. MEYER BE LIABLE FOR ANY SPECIAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  18.  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  19.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  20.  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22. #include <exec/types.h>
  23. #include <exec/execbase.h>
  24. #include <dos/dos.h>
  25. #include <libraries/netsupport.h>
  26.  
  27. #ifdef __SASC
  28. #include <proto/exec.h>
  29. #include <proto/dos.h>
  30. #include <proto/netsupport.h>
  31. #else
  32. #include <clib/exec_protos.h>
  33. #include <clib/dos_protos.h>
  34. #include <clib/netsupport_protos.h>
  35. #endif
  36.  
  37. #include <stdio.h>
  38. #include <errno.h>
  39. #include "version.h"
  40.  
  41. #ifdef __SASC_60
  42. #if (__REVISION__ - 50)
  43. static const char DOSId[] = "\0$VER: MUnpack " MPACK_VERSION " " __AMIGADATE__ ;
  44. #else
  45. static const char DOSId[] = "\0$VER: MUnpack " MPACK_VERSION " (" __DATE__ ")" ;
  46. #endif
  47. #endif
  48.  
  49.  
  50. extern char *myGetConfig(char *, char *);
  51. extern int optind;
  52. extern char *optarg;
  53.  
  54. extern int overwrite_files ;
  55.  
  56. #define TEMPLATE        "Files/M,-f=Overwrite/S,-C=Directory/K"
  57. enum { FILES, OVERWRITE, DIRECTORY, OPT_COUNT } ;
  58. struct RDArgs *args = NULL, *my_args = NULL ;
  59. BPTR    OldDir = NULL ;
  60. struct NetSupportLibrary *NetSupportBase;
  61.  
  62. #define HELPSTRING "munpack version " MPACK_VERSION "\n\
  63. Unpack input files. If no files are present, reads from standard in. The\n\
  64. arguments other than file names are:\n\
  65. -f=Overwrite/S          Causes the unpacked file to overwrite any existing\n\
  66.                         files of the same name. Otherwise, an extension\n\
  67.                         with a period and a number is added to the file\n\
  68.                         name.\n\
  69. -C=Directory/K          Change to the given directory before unpacking.\n\
  70.                         Path names will be interpreted relative to the this\n\
  71.                         directory, not the current one.\n"
  72.  
  73. void warn(char *) ;
  74.  
  75. void
  76. FreeSystem(void) {
  77.  
  78.         if (NetSupportBase) {
  79.                 UnLockFiles() ;
  80.                 CloseLibrary((struct Library *) NetSupportBase) ;
  81.                 }
  82.         if (args) FreeArgs(args) ;
  83.         if (my_args) FreeDosObject(DOS_RDARGS, args) ;
  84.         if (OldDir) UnLock(CurrentDir(OldDir)) ;
  85.         }
  86.  
  87. main(int argc, char **argv) {
  88.         long opts[OPT_COUNT] ;
  89.         FILE *file ;
  90.         int goodenough ;
  91.         extern struct ExecBase *SysBase ;
  92.  
  93.         if (!(NetSupportBase = (struct NetSupportLibrary *) OldOpenLibrary(NETSUPPORTNAME)))
  94.                 warn("Couldn't open NetSupport.Library: Can't parse configfiles.");
  95.         goodenough = SysBase->LibNode.lib_Version > 36 ;
  96.  
  97.         /* Do the 2.x argument parsing stuff */
  98.         if (!goodenough) opts[FILES] = argc ;
  99.         else {
  100.                 onexit(FreeSystem) ;
  101.                 memset((char *) opts, 0, sizeof(opts)) ;
  102.                 if (!(my_args = AllocDosObject(DOS_RDARGS, NULL))) {
  103.                         PrintFault(IoErr(), *argv) ;
  104.                         exit(RETURN_FAIL) ;
  105.                         }
  106.                 my_args->RDA_ExtHelp = HELPSTRING ;
  107.                 if (!(args = ReadArgs(TEMPLATE, opts, my_args))) {
  108.                         PrintFault(IoErr(), *argv) ;
  109.                         exit(RETURN_FAIL) ;
  110.                         }
  111.                 overwrite_files = opts[OVERWRITE] ;
  112.  
  113.                 if (opts[DIRECTORY])
  114.                         if (OldDir = Lock((char *) opts[DIRECTORY], SHARED_LOCK))
  115.                                 OldDir = CurrentDir(OldDir) ;
  116.                         else PrintFault(IoErr(), (char *) opts[DIRECTORY]) ;
  117.  
  118.                 argv = ((char **) opts[FILES]) - 1 ;
  119.                 }
  120.  
  121.         if (!opts[FILES]) {
  122.                 fprintf(stderr, "munpack: reading from standard input\n");
  123.                 handleMessage(stdin, "text/plain", 0) ;
  124.                 }
  125.         else {
  126.                 while (*++argv)
  127.                         if (!(file = fopen(*argv, "r")))
  128.                                 os_perror(*argv) ;
  129.                         else {
  130.                                 handleMessage(file, "text/plain", 0) ;
  131.                                 fclose(file) ;
  132.                                 }
  133.                         }
  134.  
  135.         exit(0) ;
  136.         }
  137.  
  138. void
  139. warn(char *s) {
  140.         fprintf(stderr, "munpack: warning: %s\n", s);
  141.         }
  142.