home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / graf / dt-hp.zip / TEACH2C.C < prev    next >
C/C++ Source or Header  |  1988-10-13  |  5KB  |  156 lines

  1. /* Program to convert DEAR TEACHER to array initialization data in the       */
  2. /* Microsoft C language                                                      */
  3.  
  4. /* Coded in Microsoft C 5.1 by Daniel Ross, starting 11/2/87                 */
  5. /* Revised 10/13/88    11:15                                                 */
  6.  
  7. /* The input data to this program, DEAR TEACHER, was created by Daniel Ross  */
  8. /* starting 3/20/88, and entered into the public domain by the author at     */
  9. /* that time.                                                                */
  10.  
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <string.h>
  14.  
  15. #define FALSE           0
  16. #define TRUE            1
  17. #define TorF            int
  18.  
  19. #define MaxColsPerChar  32
  20. #define RowsPerChar     35              /* 27 rows above base line, + 8 rows */
  21.                                         /* of descenders                     */
  22.  
  23. FILE   * InputFile, * OutputFile ;
  24. char   InputFileName  []   =   "TEACHER.TXT" ;
  25. char   OutputFileName []   =   "TEACHER.C" ;
  26.  
  27. char   Buf [MaxColsPerChar + 4] ;
  28. char   InputChar ;
  29.  
  30. int    CharIndex, Row, Col, ActualColsThisChar ;
  31. long   Acc ;
  32. TorF   ActualColsKnown ;
  33. char   * pFinalQuote ;
  34.  
  35. void   FormatErr (void)
  36.   {
  37.     printf
  38.       ("\nFormat err, char %02x(hex), row %d up from bottom", CharIndex, Row) ;
  39.     printf ("\nActual line read:  %s", Buf) ;
  40.     exit (1) ;
  41.   }
  42.  
  43. void   main (void)
  44.   {
  45.     if ( ! (InputFile = fopen (InputFileName, "rt")))
  46.       {
  47.         printf ("\nUnable to open input file %s", InputFileName) ;
  48.         exit (1) ;
  49.       } ;
  50.     if ( ! (OutputFile = fopen (OutputFileName, "wt")))
  51.       {
  52.         printf ("\nUnable to open output file %s", OutputFileName) ;
  53.         exit (1) ;
  54.       } ;
  55.     for (CharIndex = 0 ;   CharIndex != '!' ;   ++ CharIndex)
  56.       {
  57.         fprintf (OutputFile, "        {") ;
  58.         for (Row = RowsPerChar - 1 ;   Row ;   -- Row)
  59.           fprintf (OutputFile, "0,") ;
  60.         fprintf (OutputFile, "0},\n") ;
  61.       } ;
  62.     for ( ;   CharIndex != 128 ;   ++ CharIndex)
  63.       {
  64.         if ( ! fgets (Buf, MaxColsPerChar + 4, InputFile))
  65.           {
  66.             printf
  67.               ("\nRead err or early end, at separator before char %02x(hex)",
  68.                 CharIndex) ;
  69.             exit (1) ;
  70.           } ;
  71.         if (strcmp (Buf, "-----------------------\n"))
  72.           {
  73.             printf
  74.             ("\nExpecting separator before char %02x(hex), actually read:  %s",
  75.                 CharIndex, Buf) ;
  76.             exit (1) ;
  77.           } ;
  78.         if ( ! fgets (Buf, MaxColsPerChar + 4, InputFile))
  79.           {
  80.             printf
  81.               ("\nRead err or early end, at blank line before char %02x(hex)",
  82.                 CharIndex) ;
  83.             exit (1) ;
  84.           } ;
  85.         fprintf (OutputFile, "        {") ;
  86.         ActualColsKnown = FALSE ;
  87.         for (Row = RowsPerChar - 1 ;   Row >= 0 ;   -- Row)
  88.           {
  89.             if ((Row % 6)   ==   5)     fprintf (OutputFile, "\n         ") ;
  90.             if ( ! fgets (Buf, MaxColsPerChar + 4, InputFile))
  91.               {
  92.                 printf
  93.    ("\nRead err or early end, char %02x(hex), row %d up from bottom descender",
  94.                     CharIndex, Row) ;
  95.                 exit (1) ;
  96.               } ;
  97.             if ( ! ActualColsKnown)
  98.               {
  99.                 ActualColsKnown = TRUE ;
  100.                 if ( ! (pFinalQuote = strchr ( & Buf [1], '"')))   FormatErr();
  101.                                         /* Assignment, not comparison        */
  102.                 ActualColsThisChar   =   (pFinalQuote - & Buf [1]) ;
  103.                 if (ActualColsThisChar   >   MaxColsPerChar)       FormatErr();
  104.               } ;
  105.             if
  106.               (
  107.                 (Buf [0]   !=   '"')
  108.                   ||
  109.                 (( * pFinalQuote)         !=   '"')
  110.                   ||
  111.                 (( * (pFinalQuote + 1))   !=   '\n')
  112.               )
  113.               FormatErr () ;
  114.             Acc = 0 ;
  115.             for (Col = 1 ;   Col <= ActualColsThisChar ;   ++ Col)
  116.               {
  117.                 InputChar   =   Buf [Col] ;
  118.                 if (InputChar   ==   '*')
  119.                   Acc   |=   (long) (((long) 1) << (32 - Col)) ;
  120.                 else
  121.                   {
  122.                     if (InputChar   !=   ' ')     FormatErr () ;
  123.                   } ;
  124.               } ;
  125.             fprintf (OutputFile, "0x%08lx", Acc) ;
  126.             if (Row)   fprintf (OutputFile, ",") ;
  127.             else
  128.               {
  129.                 fprintf (OutputFile, "}") ;
  130.                 if (CharIndex != 127)   fprintf (OutputFile, ",") ;
  131.                 fprintf (OutputFile, "\n") ;
  132.               } ;
  133.           } ;
  134.         if ( ! fgets (Buf, MaxColsPerChar + 4, InputFile))
  135.           {
  136.             printf
  137.               ("\nRead err or early end, at blank line after char %02x(hex)",
  138.                 CharIndex) ;
  139.             exit (1) ;
  140.           } ;
  141.       } ;
  142.     if (fclose (OutputFile))
  143.       {
  144.         printf ("\nErr closing output file %s", OutputFileName) ;
  145.         exit (1) ;
  146.       } ;
  147.     if (fclose (InputFile))
  148.       {
  149.         printf ("\nErr closing input file %s", InputFileName) ;
  150.         exit (1) ;
  151.       } ;
  152.     exit (0) ;
  153.   }
  154.  
  155. /* End of file                                                               */
  156.