home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume2 / pbm / Part2 / pbmtoptx.c < prev    next >
C/C++ Source or Header  |  1991-08-07  |  2KB  |  101 lines

  1. /* pbmtoptx.c - read a portable bitmap and produce a Printronix printer file
  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    OS_SYSV
  15. #include <string.h>
  16. #else    OS_SYSV
  17. #include <strings.h>
  18. #endif    OS_SYSV
  19. #include "pbm.h"
  20.  
  21. main( argc, argv )
  22. int argc;
  23. char *argv[];
  24.     {
  25.     FILE *ifd;
  26.     bit **bits;
  27.     int rows, cols, row, col;
  28.     char *usage = "usage:  %s [pbmfile]\n";
  29.  
  30.     if ( argc > 2 )
  31.     {
  32.     fprintf( stderr, usage, argv[0] );
  33.     exit( 1 );
  34.     }
  35.  
  36.     if ( argc == 2 )
  37.     {
  38.         ifd = fopen( argv[1], "r" );
  39.         if ( ifd == NULL )
  40.         {
  41.         fprintf( stderr, "%s: can't open.\n", argv[1] );
  42.         exit( 1 );
  43.         }
  44.     }
  45.     else
  46.     ifd = stdin;
  47.  
  48.     bits = pbm_readpbm( ifd, &cols, &rows );
  49.  
  50.     if ( ifd != stdin )
  51.     fclose( ifd );
  52.     
  53.     putinit( );
  54.     for ( row = 0; row < rows; row++ )
  55.     {
  56.     putchar( 5 );
  57.         for ( col = 0; col < cols; col++ )
  58.         putbit( bits[row][col] );
  59.     putrest( );
  60.     putchar( '\n' );
  61.         }
  62.  
  63.     exit( 0 );
  64.     }
  65.  
  66.  
  67. char item;
  68. int bitsperitem, bitshift;
  69.  
  70. putinit( )
  71.     {
  72.     bitsperitem = 0;
  73.     item = 64;
  74.     bitshift = 0;
  75.     }
  76.  
  77. putbit( b )
  78. bit b;
  79.     {
  80.     if ( bitsperitem == 6 )
  81.     putitem( );
  82.     if ( b )
  83.     item += 1 << bitshift;
  84.     bitsperitem++;
  85.     bitshift++;
  86.     }
  87.  
  88. putrest( )
  89.     {
  90.     if ( bitsperitem > 0 )
  91.     putitem( );
  92.     }
  93.  
  94. putitem( )
  95.     {
  96.     putchar( item );
  97.     bitsperitem = 0;
  98.     item = 64;
  99.     bitshift = 0;
  100.     }
  101.