home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / advos2 / ch16 / proto.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-12  |  1.8 KB  |  61 lines

  1. /*
  2.     PROTO.C
  3.  
  4.     A filter template for OS/2.
  5.  
  6.     Compile with:  C> cl proto.c
  7.  
  8.     Usage is:  C> proto <source >destination
  9.  
  10.     Copyright (C) 1988 Ray Duncan
  11. */
  12.  
  13. #include <stdio.h>
  14.  
  15. #define STDIN   0                   /* standard input handle */
  16. #define STDOUT  1                   /* standard output handle */
  17. #define BUFSIZE 256                 /* I/O buffer size */
  18.  
  19. #define API unsigned extern far pascal 
  20.  
  21. API DosRead(unsigned, void far *, unsigned, unsigned far *);
  22. API DosWrite(unsigned, void far *, unsigned, unsigned far *);
  23.  
  24. static char input[BUFSIZE];         /* buffer for input line */
  25. static char output[BUFSIZE];        /* buffer for output line */
  26.  
  27. main(int argc,char *argv[])
  28. {       
  29.     int rlen, wlen;                 /* scratch variables */
  30.  
  31.     while(1)                        /* do until end of file */
  32.     {       
  33.                                     /* get line from standard
  34.                                        input stream */
  35.         if(DosRead(STDIN, input, BUFSIZE, &rlen)) 
  36.         exit(1);            /* exit if read error */
  37.  
  38.         if(rlen == 0) exit(0);      /* exit if end of stream */
  39.  
  40.                                     /* write translated line to 
  41.                                        standard output stream */
  42.         if(DosWrite(STDOUT, output, translate(rlen), &wlen)) 
  43.             exit(1);                /* exit if write error */
  44.     }
  45. }
  46.  
  47. /*
  48.     Perform any necessary translation on input line, 
  49.     leaving the resulting text in output buffer.  
  50.     Returns length of translated line (may be zero).
  51. */
  52.  
  53. int translate(int length)
  54. {       
  55.     memcpy(output,input,length);    /* template action is */
  56.                                     /* to copy input line */
  57.     return(length);                 /* and return its length */
  58. }
  59.  
  60. 
  61.