home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / icont / newhdr.c < prev    next >
C/C++ Source or Header  |  1996-03-22  |  1KB  |  76 lines

  1. /*
  2.  * Intermediate program to convert iconx.hdr into a header file for inclusion
  3.  * in icont.  This eliminates a compile-time file search on UNIX systems.
  4.  * Definition of Header (without ShellHeader) activates the inclusion.
  5.  */
  6.  
  7. #include "::h:gsupport.h"
  8.  
  9. /*
  10.  * Prototype
  11.  */
  12.  
  13. novalue    putbyte    Params((int b));
  14.  
  15. #ifdef Header
  16. main(argc, argv) 
  17. int argc;
  18. unsigned char *argv[];
  19.    {
  20.    int b, n;
  21.  
  22.    /*
  23.     * Create an array large enough to hold iconx.hdr (+1 for luck)
  24.     * This array shall be included by link.c (and is nominally called
  25.     * hdr.h)
  26.     */ 
  27.    printf("static unsigned char iconxhdr[MaxHdr+1] = {\n");
  28.  
  29.    /*
  30.     * Recreate iconx.hdr as a series of hex constants, padded with zero bytes.
  31.     */
  32.  
  33.    for (n = 0; (b = getchar()) != EOF; n++)
  34.       putbyte(b);
  35.  
  36. #ifndef ShellHeader
  37.    /*
  38.     * If header is to be used, make sure it fits.
  39.     */
  40.    if (n > MaxHdr) {
  41.       fprintf(stderr, "%s: file size is %d bytes but MaxHdr is only %d\n",
  42.          argv[0], n, MaxHdr);
  43.       unlink("hdr.h");
  44.       exit(ErrorExit);
  45.       }
  46. #endif                    /* ShellHeader */
  47.  
  48.    while (n++ < MaxHdr)
  49.       putbyte(0);
  50.  
  51.    printf("0x00};\n");            /* one more, sans comma, and finish */
  52.    exit(NormalExit);
  53.    }
  54.  
  55. /* putbyte(b) - output byte b as two hex digits */
  56. novalue putbyte(b)
  57. int b;
  58.    {
  59.    static int n = 0;
  60.  
  61.    printf("0x%02x,", b & 0xFF);
  62.    if (++n == 16) {
  63.       printf("\n");
  64.       n = 0;
  65.       }
  66.    }
  67.  
  68. #else                    /* Header */
  69.  
  70. main()
  71.    {
  72.    exit(0);
  73.    }
  74.  
  75. #endif                    /* Header */
  76.