home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************
- ** **
- ** TM **
- ** Macify 1.3 **
- ** **
- ** By Donald Burr -- Copyright 1991 **
- ** **
- ** Released to the Public Domain **
- ** **
- ** Version History **
- ** **
- ** Date Version Comments **
- ** ---- ------- -------- **
- ** 10-Mar-91 1.0 Initial release. Written on a Mac **
- ** using LightSpeedC, and later uploaded **
- ** to UNIX, so can't say that it'll work **
- ** **
- ** 14-Mar-91 1.1 Ported to UNIX; discovered bug in usage **
- ** of hex notation. Fixed up screwy tabs. **
- ** **
- ** 14-Mar-91 1.2 Cleaned up some more code oddities, **
- ** split up the code into different files, **
- ** fixed a bug in the character xlation. **
- ** **
- ** 15-Mar-91 1.3 Cleaned up some more code; hacked up a **
- ** real kludgy Mac version; completed work **
- ** on the manpage; added the Mac version **
- ** (with its own documentation) to the **
- ** distribution as a BinHex (.hqx) file **
- ** **
- *************************************************************************/
-
- #include <stdio.h> /* Standard I/O functions */
- #include <string.h> /* BSD uses strings.h */
- #include "macify.h" /* defines for MACIFY */
-
- main(argc, argv) /* main Macify function */
- int argc;
- char *argv[]; /* command line arguments */
- {
- char the_input; /* input gathered from program */
- int thing_to_do; /* tells us what func to perform */
- char do_the_conversion(); /* this function does the stuff */
- FILE *infile, *outfile, *fopen(); /* file handlers */
-
- if (argc != 4) /* are we getting the right # of args? */
- {
- printf("\nMACIFY (tm) v1.3, (c)1991 Donald Burr\n");
- printf("Usage: %s [um or mu] [inputfile or -] ", argv[0]);
- printf("[outputfile or -]\n", argv[0]);
- printf("\tum = UNIX -> Macintosh\n");
- printf("\tmu = Macintosh -> UNIX");
- printf("\n\tinputfile = file to convert FROM, - for stdin\n");
- printf("\toutputfile = file to convert TO, - for stdout\n");
- printf("\nReleased into the Public Domain\n\n");
- exit(1);
- }
-
- /* Okay, we have the right args, so let's check if they're valid */
-
- if (strcmp(argv[1], "um") == 0) /* are we doing unix->mac? */
- thing_to_do = 1; /* 1 = convert unix->mac */
- else if (strcmp(argv[1], "mu") == 0) /* are we doing mac->unix? */
- thing_to_do = 2; /* 2 = convert mac->unix */
- else /* assume invalid arg */
- {
- printf("\nMACIFY: invalid parameter - <%s>\n", argv[1]);
- printf("Was expecting: mu = Mac -> UNIX translation\n");
- printf(" or: um = UNIX -> Mac translation\n\n");
- printf("Halt, cannot proceed.\n\n");
- exit(1);
- }
-
- /* Assign filenames, or stdin/stdout if they are <-> */
-
- if (strcmp(argv[2], "-") == 0) /* is input == stdin? */
- infile = stdin; /* directly assign pointer */
- else /* assume filename */
- infile = fopen(argv[2], "r"); /* open the file specified */
-
- if (strcmp(argv[3], "-") == 0) /* is output == stdout? */
- outfile = stdout; /* directly assign pointer */
- else /* assume filename */
- outfile = fopen(argv[3], "w"); /* open for output */
-
- /* Get input char-by-char */
-
- while ((the_input = fgetc(infile)) != EOF)
- /* while we've still got stuff */
- fputc(do_the_conversion(the_input, thing_to_do), outfile);
- /* Do the conversion */
- }
-