home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Amiga
/
Workbench
/
Archivers
/
mpackWOS.lha
/
mpackppc
/
src
/
amigaunpk.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-04-22
|
7KB
|
189 lines
/* (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>
#ifndef __PPC__
#include <libraries/netsupport.h>
#endif
#ifdef __SASC
#include <proto/exec.h>
#include <proto/dos.h>
#ifndef __PPC__
#include <proto/netsupport.h>
#endif
#else
#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
//#include <clib/netsupport_protos.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "version.h"
extern int didchat;
extern int overwrite_files;
#if defined(__SASC) && (__VERSION__ > 5) && (__REVISION__ > 50)
static const char DOSId[] = "\0$VER: MPack " MPACK_VERSION " " __AMIGADATE__ ;
#else
static const char DOSId[] = "\0$VER: MPack " MPACK_VERSION " (" __DATE__ ")" ;
#endif
int quiet ;
#define TEMPLATE "Files/M,-f=Overwrite/S,-C=Directory/K,-q=Quiet/S,-t=Text/S"
enum { FILES, OVERWRITE, DIRECTORY, QUIET, EXTRACTTEXT, OPT_COUNT } ;
static struct RDArgs *args = NULL, *my_args = NULL ;
BPTR OldDir = NULL ;
#ifndef __PPC__
struct NetSupportLibrary *NetSupportBase;
#endif
#define HS1 "munpack version " MPACK_VERSION "\n"
#define HS2 "Unpack input files. If no files are present, reads from standard in. The\n"
#define HS3 "arguments other than file names are:\n"
#define HS4 "-f=Overwrite/S Causes the unpacked file to overwrite any existing\n"
#define HS5 " files of the same name. Otherwise, an extension\n"
#define HS6 " with a period and a number is added to the file\n"
#define HS7 " name.\n"
#define HS8 "-C=Directory/K Change to the given directory before unpacking.\n"
#define HS9 " Path names will be interpreted relative to the this\n"
#define HS10 " directory, not the current one.\n"
#define HS11 "-q=Quiet/S Supress progress statements.\n"
#define HS12 "-t=Text/S Unpack the Text part fo multipart messages.\n"
char helpstuff[2048];
void warn(char *) ;
void chat(char *) ;
void
FreeSystem(void) {
#ifndef __PPC__
if (NetSupportBase) {
UnLockFiles() ;
CloseLibrary((struct Library *) NetSupportBase) ;
}
#endif
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, extracttext ;
extern struct ExecBase *SysBase ;
#ifndef __PPC__
NetSupportBase = (struct NetSupportLibrary *) OldOpenLibrary(NETSUPPORTNAME) ;
#endif
goodenough = SysBase->LibNode.lib_Version > 36 ;
/* Do the 2.x argument parsing stuff */
if (!goodenough) opts[FILES] = argc ;
else {
memset((char *) opts, 0, sizeof(opts)) ;
if (!(my_args = AllocDosObject(DOS_RDARGS, NULL))) {
PrintFault(IoErr(), *argv) ;
exit(RETURN_FAIL) ;
}
my_args->RDA_ExtHelp=&(helpstuff[0]);
strcpy(my_args->RDA_ExtHelp,HS1);
strcat(my_args->RDA_ExtHelp,HS2);
strcat(my_args->RDA_ExtHelp,HS3);
strcat(my_args->RDA_ExtHelp,HS4);
strcat(my_args->RDA_ExtHelp,HS5);
strcat(my_args->RDA_ExtHelp,HS6);
strcat(my_args->RDA_ExtHelp,HS7);
strcat(my_args->RDA_ExtHelp,HS8);
strcat(my_args->RDA_ExtHelp,HS9);
strcat(my_args->RDA_ExtHelp,HS10);
strcat(my_args->RDA_ExtHelp,HS11);
if (!(args = ReadArgs(TEMPLATE, opts, my_args))) {
PrintFault(IoErr(), *argv) ;
exit(RETURN_FAIL) ;
}
overwrite_files = opts[OVERWRITE] ;
quiet = opts[QUIET] ;
extracttext = opts[EXTRACTTEXT] ;
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 ;
}
#ifndef __PPC__
if (!NetSupportBase)
fprintf(stdout, "Couldn't open NetSupport.Library: Can't parse configfiles.\n");
#endif
if (!opts[FILES]) {
fprintf(stderr, "reading from standard input\n");
didchat = 0;
handleMessage(part_init(stdin), "text/plain", 0, extracttext,
(struct boundary *) NULL) ;
if (!didchat)
fprintf(stdout,
"Did not find anything to unpack from standard input\n");
}
else {
while (*++argv)
if (!(file = fopen(*argv, "r")))
os_perror(*argv) ;
else {
didchat = 0 ;
handleMessage(part_init(file), "text/plain", 0,
extracttext, (struct boundary *) NULL) ;
if (file) fclose(file) ;
if (!didchat)
fprintf(stdout,
"Did not find anything to unpack from %s\n", *argv);
}
}
exit(0) ;
}
void
warn(char *s) {
fprintf(stderr, "munpack: warning: %s\n", s);
}
void
chat(char *s) {
didchat = 1;
if (!quiet) fprintf(stderr, "munpack: %s\n", s);
}