home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume4 / calgen / part1 / pic_m2h.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  2.7 KB  |  114 lines

  1. /*******************************************************
  2.  *
  3.  *          Calendar Generation Program
  4.  *        Copyright 1986 David H. Brierley
  5.  *
  6.  * Permission is granted to anyone to use this software for any
  7.  * purpose on any computer system, and to redistribute it freely,
  8.  * subject to the following restrictions:
  9.  * 1. The author is not responsible for the consequences of use of
  10.  *    this software, no matter how awful, even if they arise
  11.  *    from defects in it.
  12.  * 2. The origin of this software must not be misrepresented, either
  13.  *    by explicit claim or by omission.
  14.  * 3. Altered versions must be plainly marked as such, and must not
  15.  *    be misrepresented as being the original software.
  16.  *
  17.  * David H. Brierley
  18.  * Portsmouth, RI
  19.  * {allegra,ihnp4,linus}!rayssd!dhb
  20.  *
  21.  ********************************************************/
  22.  
  23. /*
  24.  * pic_m2h - calndr program support module
  25.  *
  26.  * This module takes the internal machine format data file and
  27.  * converts it to human readable format.  Carriage returns are
  28.  * added to each line (actually \n) and the picture data is
  29.  * optionally transformed into the compressed format defined
  30.  * by the pic_h2m program.
  31.  *
  32.  */
  33.  
  34. #include <stdio.h>
  35.  
  36. main (argc, argv)
  37. int     argc;
  38. char   *argv[];
  39. {
  40.     char    line[134];
  41.     char   *p1;
  42.     char    moname[81];
  43.     char    nums[6];
  44.     int     points[13];
  45.     int     picdata;
  46.     int     compress;
  47.     int     count;
  48.     int     n;
  49.  
  50.     compress = 0;
  51.     picdata = -1;
  52.     for (n = 1; n < argc; n++) {
  53.     if (strcmp (argv[n], "-c") == 0) {
  54.         compress = 1;
  55.         continue;
  56.     }
  57.     picdata = open (argv[n], 0);
  58.     if (picdata == -1) {
  59.         perror ("calndr");
  60.         fprintf (stderr, "Unable to open file '%s'\n", argv[n]);
  61.         exit (1);
  62.     }
  63.     }
  64.     if (picdata == -1) {
  65.     fprintf (stderr, "No input file specified\n");
  66.     exit (1);
  67.     }
  68.  
  69.     for (n = 0; n < 12 * 7; n++) {
  70.     if (read (picdata, moname, 81) != 81) {
  71.         fprintf (stderr, "I/O error on file\n");
  72.         exit (1);
  73.     }
  74.     printf ("%s\n", moname);
  75.     }
  76.     for (n = 0; n < 10 * 5; n++) {
  77.     if (read (picdata, nums, 6) != 6) {
  78.         fprintf (stderr, "I/O error on file\n");
  79.         exit (1);
  80.     }
  81.     printf ("%s\n", nums);
  82.     }
  83.     if (read (picdata, (char *) points, sizeof points) != sizeof points) {
  84.     fprintf (stderr, "I/O errron file\n");
  85.     exit (1);
  86.     }
  87.     for (n = 0; ; n++) {
  88.     if (read (picdata, line, 134) != 134) {
  89.         break;
  90.     }
  91.     for (p1 = line; *p1 != '\0'; p1++) {
  92.         printf ("%c", *p1);
  93.         if (compress == 1) {
  94.         if (*(p1 + 1) != *p1) continue;
  95.         for (count = 1; *(p1 + count) == *p1; count++) ;
  96.         count--;
  97.         p1 += count;
  98.         if (count > 5) {
  99.             printf ("[%d]", count);
  100.         }
  101.         else {
  102.             while (count-- > 0) {
  103.             printf ("%c", *p1);
  104.             }
  105.         }
  106.         }
  107.     }
  108.     printf ("\n");
  109.     }
  110.  
  111.     (void) close (picdata);
  112.  
  113. }
  114.