home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_05 / 9n05122a < prev    next >
Text File  |  1991-03-20  |  6KB  |  172 lines

  1. /*******************************************************
  2. *  file d:\cips\pi.c
  3. *
  4. *  Purpose - These functions print an image out to the 
  5. *      line printer.  The parameters in this function
  6. *      are defined differently than in most other CIPS
  7. *      functions.  The parameters il, ie, ll, le are
  8. *      coordinates inside the 100x100 image array.
  9. *      The parameters first_line and first_element
  10. *      are coordinates for the entire image file.
  11. *      So, if you want to start printing at row 10
  12. *      and column 10 of the image file you would call:
  13. *         read_tiff_image(name, the_image, 10, 10, 
  14. *                         110, 110);
  15. *         print_image(the_image, name, 1, 1, 1, 100, 18,
  16. *                     10, 10);
  17. *      In normal print mode you can only print 17 
  18. *      columns: le - ie = 17.
  19. *
  20. *  External Calls: fwrite.c -  my_frwiteln
  21. *                              my_fwrite
  22. *                  rstring.c - read_string
  23. *                              long_clear_buffer
  24. *******************************************************/
  25.  
  26. #include "d:\cips\cips.h"
  27. #define  FORMFEED  '\014'
  28.  
  29. print_image(the_image, name, channel, il, ie, ll, le,
  30.             first_line, first_element)
  31.    char  name[];
  32.    int   channel, il, ie, ll, le, first_line, first_element;
  33.    short the_image[ROWS][COLS];
  34. {
  35.    char printer_name[MAX_NAME_LENGTH];
  36.    FILE *printer;
  37.  
  38.    strcpy(printer_name, "prn");
  39.    if( (printer = fopen(printer_name, "w")) == NULL)
  40.       printf("\nPI> Could not open printer");
  41.    else{
  42.       printf("\nPI> The print file is opened");
  43.      /*****************************************
  44.      *   If your printer has some form of 
  45.      *   condensed printing, you can send those
  46.      *   commands via software using the fputc
  47.      *   function.  For example, if your printer
  48.      *   needs to sequence X Y Z to start 
  49.      *   condensed printing, insert the following
  50.      *   three calls right here:
  51.      *   fputc('X', printer);
  52.      *   fputc('Y', printer);
  53.      *   fputc('Z', printer);
  54.      ********************************************/
  55.       perform_printing(printer, the_image, name, channel,
  56.                        il, ll, ie, le, first_line, first_element);
  57.       fclose(printer);
  58.    }  /* ends else print  */
  59. }     /* ends print_image  */
  60.  
  61. perform_printing(printer, the_image, name, channel,
  62.                  il, ll, ie, le, first_line, first_element)
  63.    char  name[];
  64.    FILE  *printer;
  65.    int         channel, il, ie, ll, le, first_line, first_element;
  66.    short the_image[ROWS][COLS];
  67. {
  68.    char output[300],
  69.         response[80],
  70.         string[300];
  71.    int  i,
  72.         j,
  73.         k,
  74.         line_counter;
  75.  
  76.    printf("\nPI> Print header");
  77.    line_counter = 0;
  78.    long_clear_buffer(string);
  79.    sprintf(string, "     This image is -- %s --", name);
  80.    my_fwriteln(printer, string);
  81.    ++line_counter;
  82.  
  83.    long_clear_buffer(string);
  84.    sprintf(string, "     The parameters are:");
  85.    my_fwriteln(printer, string);
  86.    ++line_counter;
  87.  
  88.    long_clear_buffer(string);
  89.    sprintf(string, "     channel=%d il=%d ll=%d ie=%d le=%d",
  90.            channel, first_line, first_line+ll-2,
  91.            first_element, first_element+le-2);
  92.    my_fwriteln(printer, string);
  93.    ++line_counter;
  94.  
  95.    long_clear_buffer(string);
  96.    sprintf(string, " ");
  97.    my_fwriteln(printer, string);
  98.    ++line_counter;
  99.  
  100.    print_column_header(&line_counter, first_element, ie, le, 
  101.                        output, string, printer);
  102.  
  103.    for(i=il; i<ll; i++){
  104.       long_clear_buffer(string);
  105.    /* now print the image  */
  106.       sprintf(string, "      ");
  107.       long_clear_buffer(output);
  108.       sprintf(output, "%3d-", i+first_line-1);
  109.       append_string(output, string);
  110.       for(j=ie; j<le; j++){
  111.          long_clear_buffer(output);
  112.          sprintf(output,"%4d",the_image[i][j]);
  113.          append_string(output, string);
  114.       }  /* ends loop over j columns */
  115.  
  116.       my_fwriteln(printer, string);
  117.       line_counter = line_counter + 1;
  118.       if(line_counter >= 53){
  119.          line_counter = 0;
  120.          putc(FORMFEED, printer);
  121.          print_column_header(&line_counter, first_element, ie,
  122.                              le, output, string, printer);
  123.       }  /* ends if line_counter >=65  */
  124.    }  /* ends loop over i rows */
  125.  
  126.    for(i=line_counter; i<66; i++){
  127.       long_clear_buffer(string);
  128.       sprintf(string, " ");
  129.       my_fwriteln(printer, string);
  130.    }
  131. }     /* ends perform_printing  */
  132.  
  133. print_column_header(line_counter, first_element, ie, le, output,
  134.                     string, printer)
  135.    char string[], output[];
  136.    FILE *printer;
  137.    int  first_element, ie, le, *line_counter;
  138. {
  139.    int k;
  140.  
  141.    long_clear_buffer(string);
  142.    sprintf(string, "          ");
  143.  
  144.    for(k=first_element; k<(first_element + (le-ie)); k++){
  145.       long_clear_buffer(output);
  146.       sprintf(output, "-%3d", k);
  147.       append_string(output, string);
  148.    }  /* ends loop over k  */
  149.    my_fwriteln(printer, string);
  150.    *line_counter = *line_counter + 1;
  151. }  /* ends print_column_header  */
  152.  
  153. /*********************************************
  154. *  print_image_array(...
  155. *  This function prints a 100x100 image array.
  156. **********************************************/
  157. print_image_array(the_image)
  158.    short the_image[ROWS][COLS];
  159. {
  160.    char response[80];
  161.    printf("\nPIA> Enter a comment line\n--");
  162.    clear_buffer(response);
  163.    read_string(response);
  164.                                 /*     il  ie  ll    le    */
  165.    print_image(the_image, response, 0,  1,  1, 100,  17, 0, 0);
  166.    print_image(the_image, response, 0,  1, 18, 100,  35, 0, 0);
  167.    print_image(the_image, response, 0,  1, 36, 100,  53, 0, 0);
  168.    print_image(the_image, response, 0,  1, 54, 100,  71, 0, 0);
  169.    print_image(the_image, response, 0,  1, 72, 100,  89, 0, 0);
  170.    print_image(the_image, response, 0,  1, 90, 100, 100, 0, 0);
  171. }  /* ends print_image_array  */
  172.