jac@paul.rutgers.edu (Jonathan A. Chandross) (11/19/90)
Submitted-by: jac@paul.rutgers.edu
Posting-number: Volume 1, Source:2
Archive-name: archive/aaf_jac
Architecture: ANY_2
Version-number: 1.00
Enclosed is my version of the AAF tools. These include the pack and
unpack programs as well as documentation and a Makefile.
The upaaf program I posted earlier should be used to unpack this archive.
******************************
=Read.Me
-
-Apple Archive Format
-Version 1.00
-
-COPYRIGHT 1990 by Jonathan A. Chandross.
-All Rights Reserved.
-
-The AAF is a simple archive format designed for shipping around Apple
-source code. An archive consists of a series of lines. Each line is
-interpreted according to the first character of the line. The
-interpretations are:
-
- = the name of the unpacked file starting here
- - a source line to be unpacked into the current file
- + end of archive.
-
-Lines beginning with any other character are simply output to the console.
-
-A simple example of this format:
- From: random@foobar.com
- To: freeworld
- Subject: First program.
- R.
- =helloworld.c
- -main()
- -{
- - printf("Hello World\n");
- -}
- =Read.Me
- -Test out a C compiler; just compile and execute.
- + All done.
- J. Random Hacker
- random@foobar.com
-
-This file would create the files "helloworld.c" and "Read.Me". When
-the archive was unpacked, all of the non-source and non-file-name
-lines would be output to the console until the '+' was encountered.
-
-Using '=' to specify a file name and '-' to specify a line of source
-allows a standard USENET or email file to be unpacked without removing
-any preamble or trailing information.
-
-The '+' at the end of the file indicates the end of an archive. Lines
-occurring past this point will not be processed at all.
-
-The '=' and "+" sentinels are due to Doug Gwyn.
-
-
-Jonathan A. Chandross
-jac@paul.rutgers.edu
-November 1990
-
=Makefile
-
-FLAGS = -g
-DEFINES = -D SHELL
-
-all: paaf.c upaaf.c
-
-paaf: paaf.c
- cc ${DEFINES} ${FLAGS} -o paaf paaf.c
-
-upaaf: upaaf.c
- cc ${DEFINES} ${FLAGS} -o upaaf upaaf.c
-
-lint:
- lint paaf.c
- lint upaaf.c
-
-clean:
- rm -f paaf upaaf
-
=paaf.c
-
-/*
- *******************************************************************************
- *
- * paaf.c
- *
- * Pack an archive in Apple Archive Format.
- *
- * Another quality product handcrafted with loving care by:
- * Jonathan A. Chandross
- * jac@paul.rutgers.edu
- * November 1990
- *
- * COPYRIGHT 1990 by Jonathan A. Chandross
- * All rights reserved.
- *
- * Use "cc -D SHELL" to compile for use with a shell.
- *
- *******************************************************************************
- */
-
-#include <stdio.h>
-
-/*
- *******************************************************************************
- *
- * Defines
- *
- * EXPORT function is visible outside this module
- * IMPORT function is defined outside this module
- * STATIC function is invisible outside this module
- *
- * LENGTH length of strings
- *
- *******************************************************************************
- */
-#define EXPORT
-#define IMPORT extern
-#define LOCAL static
-
-#define LENGTH 255
-
-/*
- *******************************************************************************
- *
- * main
- *
- * Packs a series of files in Apple Archive Format
- *
- * Parameters:
- * argc number of command line arguments if compiled
- * for a shell
- * argv command line argument vector
- * Locals:
- * archive_name name of archive to pack if not using a shell
- * Returns:
- *
- * If this program is compiled for use with a shell, the first command line
- * argument is considered to contain a list of file names to archive. If
- * this program is compiled stand-alone, i.e. not for use with a shell, it
- * prompts for the files to pack.
- *
- * The SHELL define is an unsightly way to do things, but there is little
- * choice if this program is to be used on an Apple lacking some sort of
- * shell.
- *
- *******************************************************************************
- */
-#ifdef SHELL
-EXPORT int main(argc, argv)
-int argc;
-char *argv[];
-#else
-EXPORT int main()
-#endif
-{
-IMPORT void pack();
-IMPORT int fclose();
-#ifdef SHELL
-IMPORT void usage();
-#else
-char archive_file_name[LENGTH];
-FILE *archive_file;
-#endif
-
-#ifdef SHELL
- /*
- * If we are using a shell, then argv[] will contain the names of the
- * files to pack into an archive.
- */
- if(argc == 1) {
- usage(argv[0]);
- exit(1);
- }
- else {
- /*
- * argc is always 1 more than the number of arguments since
- * argv[0] contains the name of the program. This means we
- * have to correct for the array basing whenever we use an
- * argument.
- */
- int arg_num;
-
- for(arg_num = 2; arg_num <= argc; arg_num++) {
- (void) fprintf(stderr,
- "Packing file: '%s'\n",
- argv[arg_num - 1]);
- pack(argv[arg_num - 1], stdout);
- }
- (void) fputs("+ END OF ARCHIVE\n\n", stdout);
- }
-#else
- (void) fputs("Archive name:", stdout);
- if(scanf("%s", archive_file_name) == EOF)
- exit(1);
-
- if((archive_file = fopen(archive_file_name, "w")) == (FILE *)EOF) {
- (void) fprintf(stderr,
- "Error: could not open archive file '%s'\n",
- archive_file_name);
- exit(1);
- }
-
- for(;;) {
- char buffer[LENGTH];
-
- (void) fputs("File name to archive:", stdout);
- if(scanf("%s", buffer) == EOF)
- break;
- else
- pack(buffer, archive_file);
- }
- (void) fputs("+ END OF ARCHIVE\n\n", archive_file);
- (void) fclose(archive_file);
-#endif
-
- return(0);
-}
-
-/*
- *******************************************************************************
- *
- * usage
- *
- * Print out a message on how to use this program
- *
- * Parameters:
- * object_name name of object file storing this program
- * Locals:
- * Returns:
- *
- *******************************************************************************
- */
-#ifdef SHELL
-LOCAL void usage(object_name)
-char *object_name;
-{
- (void) fprintf(stderr,
- "Usage: %s file_1 [file_2] [file_3] [...]\n",
- object_name);
-}
-#endif
-
-/*
- *******************************************************************************
- *
- * pack
- *
- * pack an archive
- *
- * Parameters:
- * file_name name of file to add to archive
- * output_file archive file (appended to)
- * Locals:
- * buffer holds each line as it is read out of archive
- * file file to archive
- * Returns:
- *
- *******************************************************************************
- */
-LOCAL void pack(file_name, output_file)
-char *file_name;
-FILE *output_file;
-{
-IMPORT char *fgets();
-IMPORT int fputs();
-IMPORT int fclose();
-IMPORT FILE *fopen();
-char buffer[LENGTH];
-FILE *file;
-
- /*
- * Open the file to archive and make sure it exists.
- */
- if((file = fopen(file_name, "r")) == (FILE *)NULL) {
- (void) fprintf(stderr,
- "Error: could not open file '%s'\n",
- file_name);
- exit(1);
- }
-
- /*
- * Put the file name in the output
- */
- (void) fprintf(output_file, "=%s\n", file_name);
-
- /*
- * As long as the file is not empty, process lines. Each line
- * to be output has a leading '-'.
- */
- buffer[0] = '-';
- while(fgets(&buffer[1], LENGTH, file) != (char *)NULL) {
- /*
- * Add the line to the output file with a leading '-'.
- */
- (void) fputs(buffer, output_file);
- }
-
- /*
- * Done with this file.
- */
- (void) fclose(file);
-}
-
=upaaf.c
-
-/*
- *******************************************************************************
- *
- * upaaf.c
- *
- * Unpack an archive in apple format.
- *
- * Another quality product handcrafted with loving care by:
- * Jonathan A. Chandross
- * jac@paul.rutgers.edu
- * November 1990
- *
- * COPYRIGHT 1990 by Jonathan A. Chandross
- * All rights reserved.
- *
- * Use "cc -D SHELL" to compile for use with a shell.
- *
- *******************************************************************************
- */
-
-#include <stdio.h>
-
-/*
- *******************************************************************************
- *
- * Defines
- *
- * EXPORT function is visible outside this module
- * IMPORT function is defined outside this module
- * STATIC function is invisible outside this module
- *
- * LENGTH length of strings
- *
- *******************************************************************************
- */
-#define EXPORT
-#define IMPORT extern
-#define LOCAL static
-
-#define LENGTH 255
-
-/*
- *******************************************************************************
- *
- * main
- *
- * Unpacks a file in Apple Archive Format
- *
- * Parameters:
- * argc number of command line arguments if compiled
- * for a shell
- * argv command line argument vector
- * Locals:
- * archive_name name of archive to unpack if not using a
- * shell
- * Returns:
- *
- * If this program is compiled for use with a shell, the first command line
- * argument is considered to contain the name of the archive to unpack. If
- * this program is compiled stand-alone, i.e. not for use with a shell, it
- * prompts for the archive to unpack.
- *
- * The SHELL define is an unsightly way to do things, but there is little
- * choice if this program is to be used on an Apple lacking some sort of
- * shell.
- *
- *******************************************************************************
- */
-#ifdef SHELL
-EXPORT int main(argc, argv)
-int argc;
-char *argv[];
-#else
-EXPORT int main()
-#endif
-{
-IMPORT void unpack();
-#ifdef SHELL
-IMPORT void usage();
-#else
-char archive_name[LENGTH];
-#endif
-
-#ifdef SHELL
- /*
- * If we are using a shell, then argv[1] will be the name of the
- * archive to unpack.
- */
- if(argc == 2)
- unpack(argv[1]);
- else {
- usage(argv[0]);
- exit(1);
- }
-#else
- (void) fputs("Enter name of archive to unpack:", stdout);
- (void) scanf("%s", archive_name);
- unpack(archive_name);
-#endif
-
- return(0);
-}
-
-/*
- *******************************************************************************
- *
- * usage
- *
- * Print out a message on how to use this program
- *
- * Parameters:
- * object_name name of object file storing this program
- * Locals:
- * Returns:
- *
- *******************************************************************************
- */
-#ifdef SHELL
-LOCAL void usage(object_name)
-char *object_name;
-{
- (void) fprintf(stderr, "Usage: %s archive-name\n", object_name);
-}
-#endif
-
-/*
- *******************************************************************************
- *
- * unpack
- *
- * Unpack an archive
- *
- * Parameters:
- * archive_file_name name of archive file to unpack
- * Locals:
- * buffer holds each line as it is read out of archive
- * archive_file archive file
- * output_file current file being unpacked from archive
- * Returns:
- *
- *******************************************************************************
- */
-LOCAL void unpack(archive_file_name)
-char *archive_file_name;
-{
-IMPORT char *fgets();
-IMPORT int fput();
-IMPORT int strlen();
-IMPORT int fclose();
-IMPORT FILE *fopen();
-char buffer[LENGTH];
-FILE *archive_file;
-FILE *output_file = (FILE *)NULL;
-
- /*
- * Open the archive file and make sure it exists.
- */
- if((archive_file = fopen(archive_file_name, "r")) == (FILE *)NULL) {
- (void) fprintf(stderr, "Error: could not open archive '%s'\n",
- archive_file_name);
- exit(1);
- }
-
- /*
- * As long as the file is not empty, process lines
- */
- while(fgets(buffer, LENGTH, archive_file) != (char *)NULL) {
- /*
- * What kind of line do we have?
- */
- switch(buffer[0]) {
- case '=':
- /*
- * Have a file name. Remove the trailing newline
- * from the file-name (left by fgets) by overwriting
- * with a Null. Then open the file and verify that
- * we can write to it. Skip over the first character
- * in the file-name (it is an '=')
- */
- buffer[strlen(buffer) - 1] = '\0';
- (void) fprintf(stdout, "Unpacking '%s'\n", &buffer[1]);
-
- /*
- * If we have an open output file, close it.
- */
- if(output_file != (FILE *)NULL)
- (void) fclose(output_file);
-
- if((output_file = fopen(&buffer[1], "w")) ==
- (FILE *)EOF) {
- (void) fprintf(stderr,
- "Error: could not open '%s'\n", buffer);
- exit(1);
- }
- break;
- case '-':
- /*
- * Have a line of source. Add the line to the output
- * file without the leading "-".
- */
- if(output_file == (FILE *)NULL) {
- fputs("Error: no file specified.\n", stderr);
- exit(1);
- }
- else
- (void) fputs(&buffer[1], output_file);
- break;
- case '+':
- /*
- * End of archive. Exit.
- */
- exit(0);
- break;
- default:
- /*
- * Have some other type of line (mail header,
- * signature, comment, etc.) Output it.
- */
- (void) fputs(&buffer[0], stdout);
- break;
- }
- }
-}
-
+ END OF ARCHIVE