home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / macify13.shr / macify.c < prev    next >
C/C++ Source or Header  |  1991-05-20  |  4KB  |  93 lines

  1. /*************************************************************************
  2.  **                                    **
  3.  **                    TM                **
  4.  **                  Macify    1.3                **
  5.  **                                    **
  6.  **            By Donald Burr  --  Copyright 1991        **
  7.  **                                    **
  8.  **              Released to the Public Domain            **
  9.  **                                    **
  10.  ** Version History                            **
  11.  **                                    **
  12.  ** Date    Version        Comments                **
  13.  ** ----    -------        --------                **
  14.  ** 10-Mar-91    1.0        Initial release.  Written on a Mac    **
  15.  **                using LightSpeedC, and later uploaded    **
  16.  **                to UNIX, so can't say that it'll work    **
  17.  **                                    **
  18.  ** 14-Mar-91    1.1        Ported to UNIX; discovered bug in usage **
  19.  **                of hex notation.  Fixed up screwy tabs. **
  20.  **                                                                     **
  21.  ** 14-Mar-91    1.2        Cleaned up some more code oddities,     **
  22.  **                split up the code into different files, **
  23.  **                fixed a bug in the character xlation.   **
  24.  **                                                                     **
  25.  ** 15-Mar-91    1.3        Cleaned up some more code; hacked up a  **
  26.  **                real kludgy Mac version; completed work **
  27.  **                on the manpage; added the Mac version   **
  28.  **                (with its own documentation) to the    **
  29.  **                distribution as a BinHex (.hqx) file    **
  30.  **                                    **
  31.  *************************************************************************/
  32.  
  33. #include     <stdio.h>        /* Standard I/O functions */
  34. #include    <string.h>        /* BSD uses strings.h */
  35. #include    "macify.h"        /* defines for MACIFY */
  36.  
  37. main(argc, argv)        /* main Macify function */
  38. int    argc;
  39. char    *argv[];        /* command line arguments */
  40. {
  41.     char    the_input;    /* input gathered from program */
  42.     int    thing_to_do;    /* tells us what func to perform */
  43.     char    do_the_conversion();    /* this function does the stuff */
  44.     FILE    *infile, *outfile, *fopen();    /* file handlers */
  45.  
  46.     if (argc != 4)        /* are we getting the right # of args? */
  47.     {
  48.         printf("\nMACIFY (tm) v1.3, (c)1991 Donald Burr\n");
  49.         printf("Usage: %s [um or mu] [inputfile or -] ", argv[0]);
  50.         printf("[outputfile or -]\n", argv[0]);
  51.         printf("\tum = UNIX -> Macintosh\n");
  52.         printf("\tmu = Macintosh -> UNIX");
  53.         printf("\n\tinputfile = file to convert FROM, - for stdin\n");
  54.         printf("\toutputfile = file to convert TO, - for stdout\n");
  55.         printf("\nReleased into the Public Domain\n\n");
  56.         exit(1);
  57.     }
  58.  
  59.     /* Okay, we have the right args, so let's check if they're valid */
  60.  
  61.     if (strcmp(argv[1], "um") == 0)        /* are we doing unix->mac? */
  62.         thing_to_do = 1;        /* 1 = convert unix->mac */
  63.     else if (strcmp(argv[1], "mu") == 0)    /* are we doing mac->unix? */
  64.         thing_to_do = 2;        /* 2 = convert mac->unix */
  65.     else                    /* assume invalid arg */
  66.         {
  67.         printf("\nMACIFY: invalid parameter - <%s>\n", argv[1]);
  68.         printf("Was expecting:  mu = Mac -> UNIX translation\n");
  69.         printf("           or:  um = UNIX -> Mac translation\n\n");
  70.         printf("Halt, cannot proceed.\n\n");
  71.         exit(1);
  72.         }
  73.  
  74.     /* Assign filenames, or stdin/stdout if they are <-> */
  75.  
  76.     if (strcmp(argv[2], "-") == 0)        /* is input == stdin? */
  77.         infile = stdin;            /* directly assign pointer */
  78.     else                    /* assume filename */
  79.         infile = fopen(argv[2], "r");    /* open the file specified */
  80.  
  81.     if (strcmp(argv[3], "-") == 0)        /* is output == stdout? */
  82.         outfile = stdout;        /* directly assign pointer */
  83.     else                    /* assume filename */
  84.         outfile = fopen(argv[3], "w");    /* open for output */
  85.  
  86.     /* Get input char-by-char */
  87.  
  88.     while ((the_input = fgetc(infile)) != EOF)
  89.                     /* while we've still got stuff */
  90.         fputc(do_the_conversion(the_input, thing_to_do), outfile);
  91.                         /* Do the conversion */
  92. }
  93.