home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / unix / textmstr.shr / tm.c < prev    next >
C/C++ Source or Header  |  1991-06-26  |  4KB  |  105 lines

  1. /*************************************************************************
  2.  **                                    **
  3.  **                    TM                **
  4.  **                  TextMaster    1.4                **
  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.  ** 09-May-91    1.4        Sent error messages to stderr.        **
  32.  **                Unified version numbers between both    **
  33.  **                Mac and UNIX versions.  Changed name    **
  34.  **                of program to TextMaster.        **
  35.  **                                    **
  36.  *************************************************************************/
  37.  
  38. #include     <stdio.h>        /* Standard I/O functions */
  39.  
  40. #include    "tm.h"            /* defines for TextMaster */
  41.  
  42. main(argc, argv)        /* main program */
  43. int    argc;
  44. char    *argv[];        /* command line arguments */
  45. {
  46.     char    the_input;    /* input gathered from program */
  47.     int    thing_to_do;    /* tells us what func to perform */
  48.     char    do_the_conversion();    /* this function does the stuff */
  49.     FILE    *infile, *outfile, *fopen();    /* file handlers */
  50.  
  51.     if (argc != 4)        /* are we getting the right # of args? */
  52.     {
  53.         fprintf(stderr,
  54.             "\nTextMaster (tm) v1.4, (c)1991 Donald Burr\n");
  55.         fprintf(stderr,
  56.             "Usage: %s [um or mu] [inputfile or -] ", argv[0]);
  57.         fprintf(stderr, "[outputfile or -]\n", argv[0]);
  58.         fprintf(stderr, "\tum = UNIX -> Macintosh\n");
  59.         fprintf(stderr, "\tmu = Macintosh -> UNIX");
  60.         fprintf(stderr,
  61.             "\n\tinputfile = file to convert FROM, - for stdin\n");
  62.         fprintf(stderr,
  63.             "\toutputfile = file to convert TO, - for stdout\n");
  64.         fprintf(stderr, "\nReleased into the Public Domain\n\n");
  65.         exit(1);
  66.     }
  67.  
  68.     /* Okay, we have the right args, so let's check if they're valid */
  69.  
  70.     if (strcmp(argv[1], "um") == 0)        /* are we doing unix->mac? */
  71.         thing_to_do = 1;        /* 1 = convert unix->mac */
  72.     else if (strcmp(argv[1], "mu") == 0)    /* are we doing mac->unix? */
  73.         thing_to_do = 2;        /* 2 = convert mac->unix */
  74.     else                    /* assume invalid arg */
  75.         {
  76.         fprintf(stderr,
  77.             "\n%s: invalid parameter - <%s>\n", argv[0], argv[1]);
  78.         fprintf(stderr,
  79.             "Was expecting:  mu = Mac -> UNIX translation\n");
  80.         fprintf(stderr,
  81.             "           or:  um = UNIX -> Mac translation\n\n");
  82.         fprintf(stderr, "Halt, cannot proceed.\n\n");
  83.         exit(1);
  84.         }
  85.  
  86.     /* Assign filenames, or stdin/stdout if they are <-> */
  87.  
  88.     if (strcmp(argv[2], "-") == 0)        /* is input == stdin? */
  89.         infile = stdin;            /* directly assign pointer */
  90.     else                    /* assume filename */
  91.         infile = fopen(argv[2], "r");    /* open the file specified */
  92.  
  93.     if (strcmp(argv[3], "-") == 0)        /* is output == stdout? */
  94.         outfile = stdout;        /* directly assign pointer */
  95.     else                    /* assume filename */
  96.         outfile = fopen(argv[3], "w");    /* open for output */
  97.  
  98.     /* Get input char-by-char */
  99.  
  100.     while ((the_input = fgetc(infile)) != EOF)
  101.                     /* while we've still got stuff */
  102.         fputc(do_the_conversion(the_input, thing_to_do), outfile);
  103.                         /* Do the conversion */
  104. }
  105.