home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 309.lha / PBM_PLUS / pbm / pbmupc.c < prev    next >
C/C++ Source or Header  |  1980-12-04  |  16KB  |  522 lines

  1. /* pbmupc.c - create a Universal Product Code bitmap
  2. **
  3. ** Copyright (C) 1988 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include <stdio.h>
  14. #ifdef    SYSV
  15. #include <string.h>
  16. #else    SYSV
  17. #include <strings.h>
  18. #endif    SYSV
  19. #include "pbm.h"
  20.  
  21. #define max(a,b) ((a) > (b) ? (a) : (b))
  22.  
  23. #define MARGIN 20
  24. #define DIGIT_WIDTH 14
  25. #define DIGIT_HEIGHT 23
  26. #define LINE1_WIDTH 2
  27.  
  28. #define LINE2_WIDTH ( 2 * LINE1_WIDTH )
  29. #define LINE3_WIDTH ( 3 * LINE1_WIDTH )
  30. #define LINE4_WIDTH ( 4 * LINE1_WIDTH )
  31. #define LINES_WIDTH ( 7 * LINE1_WIDTH )
  32. #define SHORT_HEIGHT ( 8 * LINES_WIDTH )
  33. #define TALL_HEIGHT ( SHORT_HEIGHT + DIGIT_HEIGHT / 2 )
  34.  
  35.  
  36. main( argc, argv )
  37. int argc;
  38. char *argv[];
  39.     {
  40.     register bit **bits;
  41.     int argn, style, rows, cols, row, digrow, col, digcolofs;
  42.     char *prod, *leftcode, *rightcode;
  43.     int sum, p, lc0, lc1, lc2, lc3, lc4, rc0, rc1, rc2, rc3, rc4;
  44.     int rect( ), alldig( ), addlines( );
  45.     void putdigit( );
  46.     char *usage = "[-s1|-s2] <type> <manufac> <product>";
  47.  
  48.     pm_progname = argv[0];
  49.  
  50.     argn = 1;
  51.     style = 1;
  52.  
  53.     /* Check for flags. */
  54.     while ( argn < argc && argv[argn][0] == '-' )
  55.     {
  56.     if ( strncmp(argv[argn],"-s1",max(strlen(argv[argn]),3)) == 0 )
  57.         style = 1;
  58.     else if ( strncmp(argv[argn],"-s2",max(strlen(argv[argn]),3)) == 0 )
  59.         style = 2;
  60.     else
  61.         pm_usage( usage );
  62.     argn++;
  63.     }
  64.  
  65.     if ( argn + 3 < argc )
  66.     pm_usage( usage );
  67.     prod = argv[argn];
  68.     leftcode = argv[argn + 1];
  69.     rightcode = argv[argn + 2];
  70.     argn += 3;
  71.  
  72.     if ( argn != argc )
  73.     pm_usage( usage );
  74.  
  75.     if ( strlen( prod ) != 1 || ( ! alldig( prod ) ) ||
  76.      strlen( leftcode ) != 5 || ( ! alldig ( leftcode ) ) ||
  77.      strlen( rightcode ) != 5 || ( ! alldig ( rightcode ) ) )
  78.     pm_error(
  79.         "product code must be one digit, and\n    left and right codes must be five digits",
  80.         0,0,0,0,0 );
  81.     p = prod[0] - '0';
  82.     lc0 = leftcode[0] - '0';
  83.     lc1 = leftcode[1] - '0';
  84.     lc2 = leftcode[2] - '0';
  85.     lc3 = leftcode[3] - '0';
  86.     lc4 = leftcode[4] - '0';
  87.     rc0 = rightcode[0] - '0';
  88.     rc1 = rightcode[1] - '0';
  89.     rc2 = rightcode[2] - '0';
  90.     rc3 = rightcode[3] - '0';
  91.     rc4 = rightcode[4] - '0';
  92.     sum = ( 10 - ( ( ( p + lc1 + lc3 + rc0 + rc2 + rc4 ) * 3 + lc0 + lc2 + lc4 + rc1 + rc3 ) % 10 ) ) % 10;
  93.  
  94.     rows = 2 * MARGIN + SHORT_HEIGHT + DIGIT_HEIGHT;
  95.     cols = 2 * MARGIN + 12 * LINES_WIDTH + 11 * LINE1_WIDTH;
  96.     bits = pbm_allocarray( cols, rows );
  97.  
  98.     (void) rect( bits, 0, 0, rows, cols, PBM_WHITE );
  99.     
  100.     row = MARGIN;
  101.     digrow = row + SHORT_HEIGHT;
  102.     col = MARGIN;
  103.     digcolofs = ( LINES_WIDTH - DIGIT_WIDTH ) / 2;
  104.  
  105.     if ( style == 1 )
  106.     putdigit( p, bits, digrow, col - DIGIT_WIDTH - LINE1_WIDTH );
  107.     else if ( style == 2 )
  108.     putdigit(
  109.         p, bits, row + SHORT_HEIGHT / 2, col - DIGIT_WIDTH - LINE1_WIDTH );
  110.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  111.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  112.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  113.     col = addlines( p, bits, row, col, TALL_HEIGHT, PBM_WHITE );
  114.     putdigit( lc0, bits, digrow, col + digcolofs );
  115.     col = addlines( lc0, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  116.     putdigit( lc1, bits, digrow, col + digcolofs );
  117.     col = addlines( lc1, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  118.     putdigit( lc2, bits, digrow, col + digcolofs );
  119.     col = addlines( lc2, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  120.     putdigit( lc3, bits, digrow, col + digcolofs );
  121.     col = addlines( lc3, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  122.     putdigit( lc4, bits, digrow, col + digcolofs );
  123.     col = addlines( lc4, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  124.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  125.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  126.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  127.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  128.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  129.     putdigit( rc0, bits, digrow, col + digcolofs );
  130.     col = addlines( rc0, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  131.     putdigit( rc1, bits, digrow, col + digcolofs );
  132.     col = addlines( rc1, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  133.     putdigit( rc2, bits, digrow, col + digcolofs );
  134.     col = addlines( rc2, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  135.     putdigit( rc3, bits, digrow, col + digcolofs );
  136.     col = addlines( rc3, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  137.     putdigit( rc4, bits, digrow, col + digcolofs );
  138.     col = addlines( rc4, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  139.     col = addlines( sum, bits, row, col, TALL_HEIGHT, PBM_BLACK );
  140.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  141.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  142.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  143.     if ( style == 1 )
  144.     putdigit( sum, bits, digrow, col + LINE1_WIDTH );
  145.  
  146.     pbm_writepbm( stdout, bits, cols, rows );
  147.  
  148.     exit( 0 );
  149.     }
  150.  
  151. int
  152. alldig( cp )
  153. char *cp;
  154.     {
  155.     for ( ; *cp != '\0'; cp++ )
  156.     if ( *cp < '0' || *cp > '9' )
  157.         return 0;
  158.     return 1;
  159.     }
  160.  
  161. void
  162. putdigit( d, bits, row0, col0 )
  163. int d, row0, col0;
  164. bit **bits;
  165.     {
  166.     int row, col;
  167.     static bit digits[10][DIGIT_HEIGHT][DIGIT_WIDTH] = {
  168.     /* 0 */
  169.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  170.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  171.     0,0,0,0,1,1,1,1,1,1,0,0,0,0,
  172.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  173.     0,0,1,1,1,0,0,0,0,1,1,1,0,0,
  174.     0,0,1,1,0,0,0,0,0,0,1,1,0,0,
  175.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  176.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  177.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  178.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  179.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  180.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  181.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  182.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  183.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  184.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  185.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  186.     0,0,1,1,0,0,0,0,0,0,1,1,0,0,
  187.     0,0,1,1,1,0,0,0,0,1,1,1,0,0,
  188.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  189.     0,0,0,0,1,1,1,1,1,1,0,0,0,0,
  190.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  191.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  192.  
  193.     /* 1 */
  194.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  195.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  196.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  197.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  198.     0,0,0,0,1,1,1,1,0,0,0,0,0,0,
  199.     0,0,0,1,1,1,1,1,0,0,0,0,0,0,
  200.     0,0,1,1,1,0,1,1,0,0,0,0,0,0,
  201.     0,0,1,1,0,0,1,1,0,0,0,0,0,0,
  202.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  203.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  204.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  205.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  206.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  207.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  208.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  209.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  210.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  211.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  212.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  213.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  214.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  215.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  216.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  217.  
  218.     /* 2 */
  219.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  220.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  221.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  222.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  223.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  224.     0,1,1,1,0,0,0,0,0,0,1,1,0,0,
  225.     0,1,1,0,0,0,0,0,0,0,1,1,1,0,
  226.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  227.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  228.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  229.     0,0,0,0,0,0,0,0,0,1,1,1,0,0,
  230.     0,0,0,0,0,0,0,0,1,1,1,0,0,0,
  231.     0,0,0,0,0,0,0,1,1,1,0,0,0,0,
  232.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  233.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  234.     0,0,0,0,1,1,1,0,0,0,0,0,0,0,
  235.     0,0,0,1,1,1,0,0,0,0,0,0,0,0,
  236.     0,0,1,1,1,0,0,0,0,0,0,0,0,0,
  237.     0,1,1,1,0,0,0,0,0,0,0,0,0,0,
  238.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  239.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  240.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  241.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  242.  
  243.     /* 3 */
  244.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  245.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  246.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  247.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  248.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  249.     0,0,0,0,0,0,0,0,0,1,1,1,0,0,
  250.     0,0,0,0,0,0,0,0,1,1,1,0,0,0,
  251.     0,0,0,0,0,0,0,1,1,1,0,0,0,0,
  252.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  253.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  254.     0,0,0,0,0,1,1,1,1,1,1,0,0,0,
  255.     0,0,0,0,0,0,0,0,1,1,1,1,0,0,
  256.     0,0,0,0,0,0,0,0,0,0,1,1,0,0,
  257.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  258.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  259.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  260.     0,1,1,0,0,0,0,0,0,0,1,1,1,0,
  261.     0,1,1,1,0,0,0,0,0,0,1,1,0,0,
  262.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  263.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  264.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  265.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  266.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  267.  
  268.     /* 4 */
  269.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  270.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  271.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  272.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  273.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  274.     0,0,0,0,0,1,1,0,0,0,0,0,0,0,
  275.     0,0,0,0,1,1,1,0,0,0,0,0,0,0,
  276.     0,0,0,0,1,1,0,0,0,0,0,0,0,0,
  277.     0,0,0,1,1,1,0,0,0,0,0,0,0,0,
  278.     0,0,0,1,1,0,0,0,1,1,0,0,0,0,
  279.     0,0,1,1,1,0,0,0,1,1,0,0,0,0,
  280.     0,0,1,1,0,0,0,0,1,1,0,0,0,0,
  281.     0,1,1,1,0,0,0,0,1,1,0,0,0,0,
  282.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  283.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  284.     0,0,0,0,0,0,0,0,1,1,0,0,0,0,
  285.     0,0,0,0,0,0,0,0,1,1,0,0,0,0,
  286.     0,0,0,0,0,0,0,0,1,1,0,0,0,0,
  287.     0,0,0,0,0,0,0,0,1,1,0,0,0,0,
  288.     0,0,0,0,0,0,0,0,1,1,0,0,0,0,
  289.     0,0,0,0,0,0,0,0,1,1,0,0,0,0,
  290.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  291.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  292.  
  293.     /* 5 */
  294.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  295.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  296.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  297.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  298.     0,1,1,0,0,0,0,0,0,0,0,0,0,0,
  299.     0,1,1,0,0,0,0,0,0,0,0,0,0,0,
  300.     0,1,1,0,0,0,0,0,0,0,0,0,0,0,
  301.     0,1,1,0,0,0,0,0,0,0,0,0,0,0,
  302.     0,1,1,0,0,0,0,0,0,0,0,0,0,0,
  303.     0,1,1,1,1,1,1,1,1,0,0,0,0,0,
  304.     0,1,1,1,1,1,1,1,1,1,1,0,0,0,
  305.     0,0,0,0,0,0,0,0,1,1,1,1,0,0,
  306.     0,0,0,0,0,0,0,0,0,0,1,1,0,0,
  307.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  308.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  309.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  310.     0,1,1,0,0,0,0,0,0,0,1,1,1,0,
  311.     0,1,1,1,0,0,0,0,0,0,1,1,0,0,
  312.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  313.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  314.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  315.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  316.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  317.  
  318.     /* 6 */
  319.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  320.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  321.     0,0,0,0,0,0,0,1,1,0,0,0,0,0,
  322.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  323.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  324.     0,0,0,0,1,1,1,0,0,0,0,0,0,0,
  325.     0,0,0,1,1,1,0,0,0,0,0,0,0,0,
  326.     0,0,0,1,1,0,0,0,0,0,0,0,0,0,
  327.     0,0,1,1,1,0,0,0,0,0,0,0,0,0,
  328.     0,0,1,1,0,1,1,1,1,0,0,0,0,0,
  329.     0,0,1,1,1,1,1,1,1,1,1,0,0,0,
  330.     0,1,1,1,1,1,0,0,1,1,1,1,0,0,
  331.     0,1,1,1,0,0,0,0,0,0,1,1,0,0,
  332.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  333.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  334.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  335.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  336.     0,0,1,1,0,0,0,0,0,0,1,1,0,0,
  337.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  338.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  339.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  340.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  341.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  342.  
  343.     /* 7 */
  344.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  345.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  346.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  347.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  348.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  349.     0,0,0,0,0,0,0,0,0,0,1,1,0,0,
  350.     0,0,0,0,0,0,0,0,0,1,1,1,0,0,
  351.     0,0,0,0,0,0,0,0,0,1,1,0,0,0,
  352.     0,0,0,0,0,0,0,0,1,1,1,0,0,0,
  353.     0,0,0,0,0,0,0,0,1,1,0,0,0,0,
  354.     0,0,0,0,0,0,0,1,1,1,0,0,0,0,
  355.     0,0,0,0,0,0,0,1,1,0,0,0,0,0,
  356.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  357.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  358.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  359.     0,0,0,0,0,1,1,0,0,0,0,0,0,0,
  360.     0,0,0,0,0,1,1,0,0,0,0,0,0,0,
  361.     0,0,0,0,1,1,1,0,0,0,0,0,0,0,
  362.     0,0,0,0,1,1,0,0,0,0,0,0,0,0,
  363.     0,0,0,0,1,1,0,0,0,0,0,0,0,0,
  364.     0,0,0,0,1,1,0,0,0,0,0,0,0,0,
  365.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  366.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  367.  
  368.     /* 8 */
  369.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  370.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  371.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  372.     0,0,1,1,1,1,1,1,1,1,1,1,0,0,
  373.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  374.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  375.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  376.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  377.     0,0,1,1,1,0,0,0,0,1,1,1,0,0,
  378.     0,0,0,1,1,1,0,0,1,1,1,0,0,0,
  379.     0,0,0,0,1,1,1,1,1,1,0,0,0,0,
  380.     0,0,0,0,1,1,1,1,1,1,0,0,0,0,
  381.     0,0,0,1,1,1,0,0,1,1,1,0,0,0,
  382.     0,0,1,1,1,0,0,0,0,1,1,1,0,0,
  383.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  384.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  385.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  386.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  387.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  388.     0,0,1,1,1,1,1,1,1,1,1,1,0,0,
  389.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  390.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  391.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  392.  
  393.     /* 9 */
  394.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  395.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  396.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  397.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  398.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  399.     0,0,1,1,0,0,0,0,0,0,1,1,0,0,
  400.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  401.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  402.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  403.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  404.     0,0,1,1,0,0,0,0,0,0,1,1,1,0,
  405.     0,0,1,1,1,1,0,0,1,1,1,1,1,0,
  406.     0,0,0,1,1,1,1,1,1,1,1,1,0,0,
  407.     0,0,0,0,0,1,1,1,1,0,1,1,0,0,
  408.     0,0,0,0,0,0,0,0,0,1,1,1,0,0,
  409.     0,0,0,0,0,0,0,0,0,1,1,0,0,0,
  410.     0,0,0,0,0,0,0,0,1,1,1,0,0,0,
  411.     0,0,0,0,0,0,0,1,1,1,0,0,0,0,
  412.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  413.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  414.     0,0,0,0,0,1,1,0,0,0,0,0,0,0,
  415.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  416.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  417.     };
  418.  
  419.     for ( row = 0; row < DIGIT_HEIGHT; row++ )
  420.     for ( col = 0; col < DIGIT_WIDTH; col++ )
  421.         bits[row0 + row][col0 + col] = digits[d][row][col];
  422.     }
  423.  
  424. int
  425. addlines( d, bits, row0, col0, height, color )
  426. int d, row0, col0, height;
  427. bit **bits, color;
  428.     {
  429.     int rect( );
  430.  
  431.     switch ( d )
  432.     {
  433.     case 0:
  434.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
  435.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  436.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  437.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  438.     break;
  439.  
  440.     case 1:
  441.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
  442.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  443.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
  444.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  445.     break;
  446.  
  447.     case 2:
  448.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
  449.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  450.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
  451.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  452.     break;
  453.  
  454.     case 3:
  455.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  456.     col0 = rect( bits, row0, col0, height, LINE4_WIDTH, 1 - color );
  457.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  458.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  459.     break;
  460.  
  461.     case 4:
  462.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  463.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  464.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
  465.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  466.     break;
  467.  
  468.     case 5:
  469.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  470.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  471.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
  472.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  473.     break;
  474.  
  475.     case 6:
  476.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  477.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  478.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  479.     col0 = rect( bits, row0, col0, height, LINE4_WIDTH, 1 - color );
  480.     break;
  481.  
  482.     case 7:
  483.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  484.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, 1 - color );
  485.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  486.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  487.     break;
  488.  
  489.     case 8:
  490.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  491.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  492.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  493.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, 1 - color );
  494.     break;
  495.  
  496.     case 9:
  497.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
  498.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  499.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  500.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  501.     break;
  502.  
  503.     default:
  504.     pm_error( "can't happen", 0,0,0,0,0 );
  505.     }
  506.  
  507.     return col0;
  508.     }
  509.  
  510. int
  511. rect( bits, row0, col0, height, width, color )
  512. bit **bits, color;
  513. int row0, col0, height, width;
  514.     {
  515.     int row, col;
  516.  
  517.     for ( row = row0; row < row0 + height; row++ )
  518.     for ( col = col0; col < col0 + width; col++ )
  519.         bits[row][col] = color;
  520.     return col0 + width;
  521.     }
  522.