home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / DCFVBA.ZIP / DCFSUBR.C < prev    next >
Text File  |  1990-05-07  |  5KB  |  195 lines

  1. /**
  2. ***  This is a part of the PCL2VBA project.   This set of functions handle
  3. ***  misc data handling.
  4. **/
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include "dcfvba.h"
  10.  
  11. /* -------------------------------------------------------------------------- */
  12.  
  13. void normal_char(void)
  14.    {
  15.    if (strlen(line) < (size_t)line_length)
  16.       strcat(line,current);
  17.    return;
  18.    }
  19.  
  20. /* -------------------------------------------------------------------------- */
  21.  
  22. void next_char(void)
  23.    {
  24.    if (!feof(pcl_file))
  25.       *current = (char)fgetc(pcl_file);
  26.  
  27.       /* Convert null bytes to blanks so they do not indicate end of string */
  28.  
  29.       if (*current == '\0')
  30.          *current = ' ';
  31.    column++;
  32.    }
  33.  
  34. /* -------------------------------------------------------------------------- */
  35.  
  36. double get_pcl_arg(void)
  37.    {
  38.    STRING real = "";  /* holder for the real number */
  39.  
  40.    while (strchr("+-.0123456789",*current) != NULL)
  41.       {
  42.       strcat(real,current);
  43.       next_char();
  44.       }
  45.    return(atof(real));
  46.    }
  47.  
  48. /* -------------------------------------------------------------------------- */
  49.  
  50. void translate_pcl(void)
  51.    {
  52.    char pcl_command;
  53.    do
  54.       {
  55.       next_char();
  56.       pcl_command = (char)toupper(*current);
  57.       switch(pcl_command)
  58.          {
  59.          case '(':
  60.          case ')':
  61.             {
  62.             pcl_paren();
  63.             break;
  64.             }
  65.          case '&':
  66.             {
  67.             pcl_ampersand();
  68.             break;
  69.             }
  70.          case '*':
  71.             {
  72.             pcl_asterisk();
  73.             break;
  74.             }
  75.          case 'E':  /* Reset */
  76.             break;
  77.          case '9':  /* Clear margins */
  78.             {
  79.             lmargin = 0;
  80.             rmargin = 0;
  81.             break;
  82.             }
  83.          default:
  84.             {
  85.             char error_message[255];
  86.  
  87.             sprintf(error_message,"Unsupported PCL command: <Esc>(%c",*current);
  88.             error(error_message,8);
  89.  
  90.             /* Skip over remaining characters in the PCL datastream */
  91.  
  92.             while(strchr(PCL_END_SET,*current) == NULL)
  93.                {
  94.                next_char();
  95.                strcat(error_message,current);
  96.                }
  97.             } /* default */
  98.          } /* switch */
  99.       } /* do */
  100.    while(strchr(PCL_END_SET,*current) == NULL);
  101.    return;
  102.    }
  103.  
  104. /* -------------------------------------------------------------------------- */
  105.  
  106. void strpad(int col)
  107.    {
  108.    int i;      /* loop index */
  109.    int length; /* length of the line */
  110.  
  111.    /* Pad out the string */
  112.  
  113.    length = strlen(line);
  114.    if (length <= col)
  115.       for (i = length;i < col;i++)
  116.          strcat(line," ");
  117.    else /* Truncate the line */
  118.       {
  119.       if (col > 1)
  120.          line[col-1] = '\0';
  121.       else
  122.          *line = '\0';
  123.       }
  124.    }  /* strpad */
  125.  
  126. /* -------------------------------------------------------------------------- */
  127.  
  128. void position_vertical(int target_row)
  129.    {
  130.    int  length;            /* length of the line */
  131.    int  skip_lines;        /* Number of lines to skip */
  132.  
  133.    /* Save the current column number */
  134.  
  135.    length = strlen(line);
  136.  
  137.    /* Dump the current line so far */
  138.  
  139.    new_line();
  140.  
  141.    /* Skip blank lines */
  142.  
  143.    /* Adjust the logical and actual line numbers.  If there hasn't been any */
  144.    /* negative positioning, they will be the same.   If there has been      */
  145.    /* movement up the page, this will adjust for that as best it can.       */
  146.  
  147.    logical_vpos = target_row;
  148.  
  149.    if ((skip_lines = target_row - actual_vpos) > 0)
  150.       fprintf(vba_file,".sk %d\n",skip_lines);
  151.  
  152.    /* Move the "cursor" back to the original column */
  153.  
  154.    strpad(length);
  155.  
  156.    }  /* position_vertical */
  157.  
  158. /* -------------------------------------------------------------------------- */
  159.  
  160. int column_by_decipoint(double number)
  161.    {
  162.    return((int)(number / (720.0 / pitch)));
  163.    }
  164.  
  165. /* -------------------------------------------------------------------------- */
  166.  
  167. int column_by_dot(double number)
  168.    {
  169.    return((int)(number / (DPI / pitch)));
  170.    }
  171.  
  172. /* -------------------------------------------------------------------------- */
  173.  
  174. int row_by_decipoint(double number)
  175.    {
  176.    return((int)(number / (720.0 / lpi)));
  177.    }
  178.  
  179. /* -------------------------------------------------------------------------- */
  180.  
  181. int row_by_dot(double number)
  182.    {
  183.    return((int)(number / (DPI / lpi)));
  184.    }
  185.  
  186. /* -------------------------------------------------------------------------- */
  187.  
  188. void error(char *message, int rcode)
  189.    {
  190.    fprintf(stderr,"%s at (%lu:%u): %s\n",(rcode) ? "Error" : "Warning",row,column,message);
  191.  
  192.    if (rcode)
  193.       exit(rcode);
  194.    }
  195.