home *** CD-ROM | disk | FTP | other *** search
- /*
- PPDecrunch Version 1.0
-
- Pipeable PowerPacker Decruncher
-
- Created on June 30, 1991
- Last revised July 22, 1991
-
- Copyright (C) 1991 by Darren Ewaniuk
- Freely distributable with conditions
- (See "distribution" section of the documentation file for more information)
-
- Builds on example public domain code from PPLib file name "example.c"
- by Nico François.
- (Thanks Nico for the excellent PowerPacker library!)
-
- Compiled using the Freely distributable DICE C compiler version 2.06.16
- (Thanks to Matt Dillon for DICE - as soon as it includes the 2.0
- specific files, I'm sending in the registration for it)
-
- Compile using "DCC PPDecrunch.c /PPLib/PPSCGlue.o -o PPDecrunch"
-
- Library functions used:
-
- Exec
- OpenLibrary To open PowerPacker library
- CloseLibrary To close PowerPacker library
- FreeMem To free allocated memory
-
- PowerPacker.library V33
- ppLoadData Load PowerPacked file
- */
-
- /* Pretend DICE is Aztec C so that ppbase.h does not try to use #pragmas */
-
- #define AZTEC_C 1
-
- /* Include the necessary files */
-
- #include <exec/types.h>
- #include <exec/memory.h>
- #include <libraries/dos.h>
- #include <libraries/ppbase.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- /* Set up library base */
-
- struct PPBase *PPBase = NULL;
-
- /* Kill DICE's break handling */
-
- void chkabort()
- {
- }
-
- /* Checks for break and returns TRUE if pressed */
-
- int taskbreak(FILE *stderrfile)
- {
- /* Check and clear break signal */
-
- if ((SetSignal(0L, SIGBREAKF_CTRL_C)) & SIGBREAKF_CTRL_C)
- {
- fputs ("\n***PPDecrunch BREAK\n", stderrfile);
- return (TRUE);
- }
- else
- {
- return (FALSE);
- }
- }
-
- /* Start of the main program */
-
- void main (int argc, char *argv[])
- {
- UBYTE *filestart = NULL; /* Memory address of decrunched file */
- ULONG filelen; /* Length of decrunched file */
- ULONG bytecount = 0; /* Counter for outputting the file */
- int err; /* PowerPacker error number */
- int warncode = 0; /* Exit code for return when finished */
- FILE *stderrfile; /* File handle for error messages */
-
- /* Gimme an error channel back to the calling window */
- /* so errors don't get redirected or go to the pipe */
-
- /* Get out of here if you can't even get a handle */
- /* to the calling window */
-
- if (!(stderrfile = fopen ("*", "w")))
- {
- exit (11);
- }
- /* DICE leaves before 0 args are passed because there's no WBMain() */
- /* but I thought I'd leave it in for people with other compilers */
-
- if (argc == 0) /* Too bad, cannot run from Workbench. */
- {
- exit (0);
- }
- else if (argc !=2) /* User doesn't know what he's doing! */
- {
- fputs ("\n\033[33mPPDecrunch 1.0\033[31m (July 22, 1991) Pipeable PowerPacker Decruncher\n", stderrfile);
- fputs ("Copyright \251 1991 by Darren Ewaniuk, freely distributable with conditions\n", stderrfile);
- fputs ("Usage: PPDecrunch <filename>\n", stderrfile);
- fputs (" Output is sent to STDOUT, useful for piping into text readers\n", stderrfile);
- fputs (" or redirecting to other files or devices\n", stderrfile);
- fputs (" Example: 'PPDecrunch <filename> | more'\n\n", stderrfile);
- warncode = 1;
- }
- else /* Right number of arguments. Lets go! */
- {
- /* Open PowerPacker.library */
-
- if (!(PPBase = (struct PPBase *)OpenLibrary ("powerpacker.library", 0L)))
- {
- fputs ("\n\033[33mPPDecrunch Error: PowerPacker library V33+ required\033[31m\n\n", stderrfile);
- warncode = 11;
- }
- else
- {
- if (err = ppLoadData (argv[1], DECR_NONE, 0L, &filestart, &filelen, -1))
- {
- fputs ("\n\033[33mPPDecrunch Error: ", stderrfile);
- switch (err)
- {
- case PP_READERR:
- fputs ("Error loading text file", stderrfile);
- break;
- case PP_NOMEMORY:
- fputs ("No memory to decrunch file", stderrfile);
- break;
- case PP_PASSERR:
- fputs ("Password protected, loading aborted", stderrfile);
- break;
- case PP_OPENERR:
- fputs ("Cannot open file", stderrfile);
- break;
- case PP_UNKNOWNPP:
- fputs ("Crunched with unknown PP", stderrfile);
- break;
- default:
- fputs ("Unknown error", stderrfile);
- break;
- }
- fputs ("!\033[31m\n\n", stderrfile);
- warncode = 10;
- }
- else
- {
- while ((bytecount < filelen) && (!taskbreak(stderrfile)))
- {
- fputc (filestart[bytecount++], stdout);
- }
- /* Free all resources */
-
- FreeMem (filestart, filelen);
- }
- CloseLibrary ((struct Library *)PPBase);
- }
- }
- fclose (stderrfile);
- exit (warncode);
- }
-