home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / netpbm_src.lzh / NETPBM / PBM / pbmupc.c < prev    next >
C/C++ Source or Header  |  1996-11-18  |  17KB  |  532 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 "pbm.h"
  14.  
  15. #define MARGIN 20
  16. #define DIGIT_WIDTH 14
  17. #define DIGIT_HEIGHT 23
  18. #define LINE1_WIDTH 2
  19.  
  20. #define LINE2_WIDTH ( 2 * LINE1_WIDTH )
  21. #define LINE3_WIDTH ( 3 * LINE1_WIDTH )
  22. #define LINE4_WIDTH ( 4 * LINE1_WIDTH )
  23. #define LINES_WIDTH ( 7 * LINE1_WIDTH )
  24. #define SHORT_HEIGHT ( 8 * LINES_WIDTH )
  25. #define TALL_HEIGHT ( SHORT_HEIGHT + DIGIT_HEIGHT / 2 )
  26.  
  27. static int alldig ARGS(( char* cp ));
  28. static void putdigit ARGS(( int d, bit** bits, int row0, int col0 ));
  29. static int addlines ARGS(( int d, bit** bits, int row0, int col0, int height, bit color ));
  30. static int rect ARGS(( bit** bits, int row0, int col0, int height, int width, bit color ));
  31.  
  32. int
  33. main( argc, argv )
  34.     int argc;
  35.     char* argv[];
  36.     {
  37.     register bit** bits;
  38.     int argn, style, rows, cols, row, digrow, col, digcolofs;
  39.     char* typecode;
  40.     char* manufcode;
  41.     char* prodcode;
  42.     int sum, p, lc0, lc1, lc2, lc3, lc4, rc0, rc1, rc2, rc3, rc4;
  43.     char* usage = "[-s1|-s2] <type> <manufac> <product>";
  44.  
  45.  
  46.     pbm_init( &argc, argv );
  47.  
  48.     argn = 1;
  49.     style = 1;
  50.  
  51.     /* Check for flags. */
  52.     while ( argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0' )
  53.     {
  54.     if ( pm_keymatch( argv[argn], "-s1", 3 ) )
  55.         style = 1;
  56.     else if ( pm_keymatch( argv[argn], "-s2", 3 ) )
  57.         style = 2;
  58.     else
  59.         pm_usage( usage );
  60.     argn++;
  61.     }
  62.  
  63.     if ( argn + 3 < argc )
  64.     pm_usage( usage );
  65.     typecode = argv[argn];
  66.     manufcode = argv[argn + 1];
  67.     prodcode = argv[argn + 2];
  68.     argn += 3;
  69.  
  70.     if ( argn != argc )
  71.     pm_usage( usage );
  72.  
  73.     if ( strlen( typecode ) != 1 || ( ! alldig( typecode ) ) ||
  74.      strlen( manufcode ) != 5 || ( ! alldig ( manufcode ) ) ||
  75.      strlen( prodcode ) != 5 || ( ! alldig ( prodcode ) ) )
  76.     pm_error(
  77.         "type code must be one digit, and\n    manufacturer and product codes must be five digits" );
  78.     p = typecode[0] - '0';
  79.     lc0 = manufcode[0] - '0';
  80.     lc1 = manufcode[1] - '0';
  81.     lc2 = manufcode[2] - '0';
  82.     lc3 = manufcode[3] - '0';
  83.     lc4 = manufcode[4] - '0';
  84.     rc0 = prodcode[0] - '0';
  85.     rc1 = prodcode[1] - '0';
  86.     rc2 = prodcode[2] - '0';
  87.     rc3 = prodcode[3] - '0';
  88.     rc4 = prodcode[4] - '0';
  89.     sum = ( 10 - ( ( ( p + lc1 + lc3 + rc0 + rc2 + rc4 ) * 3 + lc0 + lc2 + lc4 + rc1 + rc3 ) % 10 ) ) % 10;
  90.  
  91.     rows = 2 * MARGIN + SHORT_HEIGHT + DIGIT_HEIGHT;
  92.     cols = 2 * MARGIN + 12 * LINES_WIDTH + 11 * LINE1_WIDTH;
  93.     bits = pbm_allocarray( cols, rows );
  94.  
  95.     (void) rect( bits, 0, 0, rows, cols, PBM_WHITE );
  96.     
  97.     row = MARGIN;
  98.     digrow = row + SHORT_HEIGHT;
  99.     col = MARGIN;
  100.     digcolofs = ( LINES_WIDTH - DIGIT_WIDTH ) / 2;
  101.  
  102.     if ( style == 1 )
  103.     putdigit( p, bits, digrow, col - DIGIT_WIDTH - LINE1_WIDTH );
  104.     else if ( style == 2 )
  105.     putdigit(
  106.         p, bits, row + SHORT_HEIGHT / 2, col - DIGIT_WIDTH - LINE1_WIDTH );
  107.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  108.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  109.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  110.     col = addlines( p, bits, row, col, TALL_HEIGHT, PBM_WHITE );
  111.     putdigit( lc0, bits, digrow, col + digcolofs );
  112.     col = addlines( lc0, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  113.     putdigit( lc1, bits, digrow, col + digcolofs );
  114.     col = addlines( lc1, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  115.     putdigit( lc2, bits, digrow, col + digcolofs );
  116.     col = addlines( lc2, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  117.     putdigit( lc3, bits, digrow, col + digcolofs );
  118.     col = addlines( lc3, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  119.     putdigit( lc4, bits, digrow, col + digcolofs );
  120.     col = addlines( lc4, bits, row, col, SHORT_HEIGHT, PBM_WHITE );
  121.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  122.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  123.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  124.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  125.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  126.     putdigit( rc0, bits, digrow, col + digcolofs );
  127.     col = addlines( rc0, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  128.     putdigit( rc1, bits, digrow, col + digcolofs );
  129.     col = addlines( rc1, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  130.     putdigit( rc2, bits, digrow, col + digcolofs );
  131.     col = addlines( rc2, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  132.     putdigit( rc3, bits, digrow, col + digcolofs );
  133.     col = addlines( rc3, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  134.     putdigit( rc4, bits, digrow, col + digcolofs );
  135.     col = addlines( rc4, bits, row, col, SHORT_HEIGHT, PBM_BLACK );
  136.     col = addlines( sum, bits, row, col, TALL_HEIGHT, PBM_BLACK );
  137.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  138.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_WHITE );
  139.     col = rect( bits, row, col, TALL_HEIGHT, LINE1_WIDTH, PBM_BLACK );
  140.     if ( style == 1 )
  141.     putdigit( sum, bits, digrow, col + LINE1_WIDTH );
  142.  
  143.     pbm_writepbm( stdout, bits, cols, rows, 0 );
  144.     pm_close( stdout );
  145.  
  146.     exit( 0 );
  147.     }
  148.  
  149. static int
  150. alldig( cp )
  151.     char* cp;
  152.     {
  153.     for ( ; *cp != '\0'; cp++ )
  154.     if ( *cp < '0' || *cp > '9' )
  155.         return 0;
  156.     return 1;
  157.     }
  158.  
  159. static void
  160. putdigit( d, bits, row0, col0 )
  161.     int d;
  162.     bit** bits;
  163.     int row0, col0;
  164.     {
  165.     int row, col;
  166.     static bit digits[10][DIGIT_HEIGHT][DIGIT_WIDTH] = {
  167.     /* 0 */
  168.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  169.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  170.     0,0,0,0,1,1,1,1,1,1,0,0,0,0,
  171.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  172.     0,0,1,1,1,0,0,0,0,1,1,1,0,0,
  173.     0,0,1,1,0,0,0,0,0,0,1,1,0,0,
  174.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  175.     0,1,1,0,0,0,0,0,0,0,0,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,1,0,0,0,0,0,0,1,1,1,0,
  185.     0,0,1,1,0,0,0,0,0,0,1,1,0,0,
  186.     0,0,1,1,1,0,0,0,0,1,1,1,0,0,
  187.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  188.     0,0,0,0,1,1,1,1,1,1,0,0,0,0,
  189.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  190.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  191.  
  192.     /* 1 */
  193.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  194.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  195.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  196.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  197.     0,0,0,0,1,1,1,1,0,0,0,0,0,0,
  198.     0,0,0,1,1,1,1,1,0,0,0,0,0,0,
  199.     0,0,1,1,1,0,1,1,0,0,0,0,0,0,
  200.     0,0,1,1,0,0,1,1,0,0,0,0,0,0,
  201.     0,0,0,0,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,0,0,0,0,0,0,0,0,
  215.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  216.  
  217.     /* 2 */
  218.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  219.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  220.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  221.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  222.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  223.     0,1,1,1,0,0,0,0,0,0,1,1,0,0,
  224.     0,1,1,0,0,0,0,0,0,0,1,1,1,0,
  225.     0,0,0,0,0,0,0,0,0,0,0,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,1,1,1,0,
  228.     0,0,0,0,0,0,0,0,0,1,1,1,0,0,
  229.     0,0,0,0,0,0,0,0,1,1,1,0,0,0,
  230.     0,0,0,0,0,0,0,1,1,1,0,0,0,0,
  231.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  232.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  233.     0,0,0,0,1,1,1,0,0,0,0,0,0,0,
  234.     0,0,0,1,1,1,0,0,0,0,0,0,0,0,
  235.     0,0,1,1,1,0,0,0,0,0,0,0,0,0,
  236.     0,1,1,1,0,0,0,0,0,0,0,0,0,0,
  237.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  238.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  239.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  240.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  241.  
  242.     /* 3 */
  243.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  244.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  245.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  246.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  247.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  248.     0,0,0,0,0,0,0,0,0,1,1,1,0,0,
  249.     0,0,0,0,0,0,0,0,1,1,1,0,0,0,
  250.     0,0,0,0,0,0,0,1,1,1,0,0,0,0,
  251.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  252.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  253.     0,0,0,0,0,1,1,1,1,1,1,0,0,0,
  254.     0,0,0,0,0,0,0,0,1,1,1,1,0,0,
  255.     0,0,0,0,0,0,0,0,0,0,1,1,0,0,
  256.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  257.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  258.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  259.     0,1,1,0,0,0,0,0,0,0,1,1,1,0,
  260.     0,1,1,1,0,0,0,0,0,0,1,1,0,0,
  261.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  262.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  263.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  264.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  265.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  266.  
  267.     /* 4 */
  268.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  269.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  270.     0,0,0,0,0,0,1,1,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,1,1,1,0,0,0,0,0,0,
  273.     0,0,0,0,0,1,1,0,0,0,0,0,0,0,
  274.     0,0,0,0,1,1,1,0,0,0,0,0,0,0,
  275.     0,0,0,0,1,1,0,0,0,0,0,0,0,0,
  276.     0,0,0,1,1,1,0,0,0,0,0,0,0,0,
  277.     0,0,0,1,1,0,0,0,1,1,0,0,0,0,
  278.     0,0,1,1,1,0,0,0,1,1,0,0,0,0,
  279.     0,0,1,1,0,0,0,0,1,1,0,0,0,0,
  280.     0,1,1,1,0,0,0,0,1,1,0,0,0,0,
  281.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  282.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  283.     0,0,0,0,0,0,0,0,1,1,0,0,0,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,0,0,0,0,0,0,
  290.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  291.  
  292.     /* 5 */
  293.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  294.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  295.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  296.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  297.     0,1,1,0,0,0,0,0,0,0,0,0,0,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,1,1,1,1,1,1,0,0,0,0,0,
  303.     0,1,1,1,1,1,1,1,1,1,1,0,0,0,
  304.     0,0,0,0,0,0,0,0,1,1,1,1,0,0,
  305.     0,0,0,0,0,0,0,0,0,0,1,1,0,0,
  306.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  307.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  308.     0,0,0,0,0,0,0,0,0,0,0,1,1,0,
  309.     0,1,1,0,0,0,0,0,0,0,1,1,1,0,
  310.     0,1,1,1,0,0,0,0,0,0,1,1,0,0,
  311.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  312.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  313.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  314.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  315.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  316.  
  317.     /* 6 */
  318.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  319.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  320.     0,0,0,0,0,0,0,1,1,0,0,0,0,0,
  321.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  322.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  323.     0,0,0,0,1,1,1,0,0,0,0,0,0,0,
  324.     0,0,0,1,1,1,0,0,0,0,0,0,0,0,
  325.     0,0,0,1,1,0,0,0,0,0,0,0,0,0,
  326.     0,0,1,1,1,0,0,0,0,0,0,0,0,0,
  327.     0,0,1,1,0,1,1,1,1,0,0,0,0,0,
  328.     0,0,1,1,1,1,1,1,1,1,1,0,0,0,
  329.     0,1,1,1,1,1,0,0,1,1,1,1,0,0,
  330.     0,1,1,1,0,0,0,0,0,0,1,1,0,0,
  331.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  332.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  333.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  334.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  335.     0,0,1,1,0,0,0,0,0,0,1,1,0,0,
  336.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  337.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  338.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  339.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  340.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  341.  
  342.     /* 7 */
  343.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  344.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  345.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  346.     0,1,1,1,1,1,1,1,1,1,1,1,1,0,
  347.     0,0,0,0,0,0,0,0,0,0,1,1,1,0,
  348.     0,0,0,0,0,0,0,0,0,0,1,1,0,0,
  349.     0,0,0,0,0,0,0,0,0,1,1,1,0,0,
  350.     0,0,0,0,0,0,0,0,0,1,1,0,0,0,
  351.     0,0,0,0,0,0,0,0,1,1,1,0,0,0,
  352.     0,0,0,0,0,0,0,0,1,1,0,0,0,0,
  353.     0,0,0,0,0,0,0,1,1,1,0,0,0,0,
  354.     0,0,0,0,0,0,0,1,1,0,0,0,0,0,
  355.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  356.     0,0,0,0,0,0,1,1,0,0,0,0,0,0,
  357.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  358.     0,0,0,0,0,1,1,0,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,1,1,1,0,0,0,0,0,0,0,
  361.     0,0,0,0,1,1,0,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,0,0,0,0,0,0,0,0,0,0,
  365.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  366.  
  367.     /* 8 */
  368.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  369.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  370.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  371.     0,0,1,1,1,1,1,1,1,1,1,1,0,0,
  372.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  373.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  374.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  375.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  376.     0,0,1,1,1,0,0,0,0,1,1,1,0,0,
  377.     0,0,0,1,1,1,0,0,1,1,1,0,0,0,
  378.     0,0,0,0,1,1,1,1,1,1,0,0,0,0,
  379.     0,0,0,0,1,1,1,1,1,1,0,0,0,0,
  380.     0,0,0,1,1,1,0,0,1,1,1,0,0,0,
  381.     0,0,1,1,1,0,0,0,0,1,1,1,0,0,
  382.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  383.     0,1,1,0,0,0,0,0,0,0,0,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,1,0,0,0,0,0,0,1,1,1,0,
  387.     0,0,1,1,1,1,1,1,1,1,1,1,0,0,
  388.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  389.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  390.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  391.  
  392.     /* 9 */
  393.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  394.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  395.     0,0,0,0,0,1,1,1,1,0,0,0,0,0,
  396.     0,0,0,1,1,1,1,1,1,1,1,0,0,0,
  397.     0,0,1,1,1,1,0,0,1,1,1,1,0,0,
  398.     0,0,1,1,0,0,0,0,0,0,1,1,0,0,
  399.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  400.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  401.     0,1,1,0,0,0,0,0,0,0,0,1,1,0,
  402.     0,1,1,1,0,0,0,0,0,0,1,1,1,0,
  403.     0,0,1,1,0,0,0,0,0,0,1,1,1,0,
  404.     0,0,1,1,1,1,0,0,1,1,1,1,1,0,
  405.     0,0,0,1,1,1,1,1,1,1,1,1,0,0,
  406.     0,0,0,0,0,1,1,1,1,0,1,1,0,0,
  407.     0,0,0,0,0,0,0,0,0,1,1,1,0,0,
  408.     0,0,0,0,0,0,0,0,0,1,1,0,0,0,
  409.     0,0,0,0,0,0,0,0,1,1,1,0,0,0,
  410.     0,0,0,0,0,0,0,1,1,1,0,0,0,0,
  411.     0,0,0,0,0,0,1,1,1,0,0,0,0,0,
  412.     0,0,0,0,0,1,1,1,0,0,0,0,0,0,
  413.     0,0,0,0,0,1,1,0,0,0,0,0,0,0,
  414.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  415.     0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  416.     };
  417.  
  418.     for ( row = 0; row < DIGIT_HEIGHT; row++ )
  419.     for ( col = 0; col < DIGIT_WIDTH; col++ )
  420.         bits[row0 + row][col0 + col] = digits[d][row][col];
  421.     }
  422.  
  423. #if __STDC__
  424. static int
  425. addlines( int d, bit** bits, int row0, int col0, int height, bit color )
  426. #else /*__STDC__*/
  427. static int
  428. addlines( d, bits, row0, col0, height, color )
  429.     int d;
  430.     bit** bits;
  431.     int row0, col0, height;
  432.     bit color;
  433. #endif /*__STDC__*/
  434.     {
  435.     switch ( d )
  436.     {
  437.     case 0:
  438.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
  439.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  440.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  441.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  442.     break;
  443.  
  444.     case 1:
  445.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
  446.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  447.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
  448.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  449.     break;
  450.  
  451.     case 2:
  452.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
  453.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  454.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, color );
  455.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  456.     break;
  457.  
  458.     case 3:
  459.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  460.     col0 = rect( bits, row0, col0, height, LINE4_WIDTH, 1 - color );
  461.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  462.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  463.     break;
  464.  
  465.     case 4:
  466.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  467.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  468.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
  469.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  470.     break;
  471.  
  472.     case 5:
  473.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  474.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  475.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
  476.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  477.     break;
  478.  
  479.     case 6:
  480.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  481.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  482.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  483.     col0 = rect( bits, row0, col0, height, LINE4_WIDTH, 1 - color );
  484.     break;
  485.  
  486.     case 7:
  487.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  488.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, 1 - color );
  489.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  490.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  491.     break;
  492.  
  493.     case 8:
  494.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  495.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  496.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  497.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, 1 - color );
  498.     break;
  499.  
  500.     case 9:
  501.     col0 = rect( bits, row0, col0, height, LINE3_WIDTH, color );
  502.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, 1 - color );
  503.     col0 = rect( bits, row0, col0, height, LINE1_WIDTH, color );
  504.     col0 = rect( bits, row0, col0, height, LINE2_WIDTH, 1 - color );
  505.     break;
  506.  
  507.     default:
  508.     pm_error( "can't happen" );
  509.     }
  510.  
  511.     return col0;
  512.     }
  513.  
  514. #if __STDC__
  515. static int
  516. rect( bit** bits, int row0, int col0, int height, int width, bit color )
  517. #else /*__STDC__*/
  518. static int
  519. rect( bits, row0, col0, height, width, color )
  520.     bit** bits;
  521.     int row0, col0, height, width;
  522.     bit color;
  523. #endif /*__STDC__*/
  524.     {
  525.     int row, col;
  526.  
  527.     for ( row = row0; row < row0 + height; row++ )
  528.     for ( col = col0; col < col0 + width; col++ )
  529.         bits[row][col] = color;
  530.     return col0 + width;
  531.     }
  532.