home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / windows / help / fptext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-10  |  2.6 KB  |  153 lines

  1. /*
  2. *
  3. *!AU: Michael A. Shiels
  4. *!CD: 1-Jun-86
  5. *!FR: Dr. Dobbs July 1985
  6. */
  7.  
  8. #define LINT_ARGS
  9. #include <stdio.h>
  10. #include    <signal.h>
  11.  
  12. #include "masdos.h"
  13.  
  14. #include    "waitfork.x"
  15.  
  16. #define PTEXT_IBM
  17.  
  18. static    int        ptextctrlchit = 0;
  19. static    int        (*oldsignal)();
  20.  
  21. static    ptextctrlc()
  22. {
  23.     ptextctrlchit = 1;
  24.     signal( SIGINT, ptextctrlc );
  25. }
  26.  
  27. /*    ptext( dirc, dirv, Arg_Num_Cols, 79 / Arg_Num_Cols,
  28.         (dirc/Arg_Num_Cols) + (dirc % Arg_Num_Cols != 0) ); */
  29.  
  30. fptexth( linec, linev, numcols, colwidth, numrows, where )
  31. int         linec, numcols, colwidth;
  32. char        **linev;
  33. int         numrows;
  34. FILE    *where;
  35. {
  36.     register int    j,i;
  37.     register char   **lineend, **line, **nextline;
  38.     register int    linenum = 0;
  39.  
  40.     ptextctrlchit = 0;
  41.     oldsignal = signal( SIGINT, ptextctrlc );
  42.  
  43.     for( j = numrows ; --j >= 0 && !ptextctrlchit ; )
  44.     {
  45. #ifdef PTEXT_IBM
  46.         putc( ' ', where );
  47. #endif
  48.         lineend = &linev[numcols - 1];
  49.      
  50.         for( i = numcols ; --i >= 0 && *linev ; linev++ )
  51.         {
  52.             pr_line( *linev, colwidth,
  53.                 linev < lineend, where );
  54.         }
  55.         mynewline( where );
  56.     }
  57.     fflush( where );
  58.     signal( SIGINT, oldsignal );
  59.     D_OUT("ptexth");
  60. }
  61.  
  62. fptextv( linec, linev, numcols, colwidth, numrows, where )
  63. int         linec, numcols, colwidth;
  64. char        **linev;
  65. int         numrows;
  66. FILE    *where;
  67. {
  68.     register int    j;
  69.     register char   **lineend, **line, **nextline;
  70.     register int    linenum = 0;
  71.  
  72.     lineend = &linev[linec - 1];
  73.      
  74.     for( j = numrows ; --j >= 0 ; )
  75.     {
  76. #ifdef PTEXT_IBM
  77.         putc( ' ', where );
  78. #endif
  79.         for( line = linev++ ; line <= lineend ; line = nextline )
  80.         {
  81.             nextline = line + numrows;
  82.             pr_line( *line, colwidth,
  83.                 nextline <= lineend );
  84.         }
  85.         mynewline( where );
  86.     }
  87.     D_OUT("ptextv");
  88. }
  89.  
  90. static pr_line( str, width, padded, where )
  91. register char  *str;
  92. int        width, padded;
  93. FILE    *where;
  94. {
  95.     int         col = 0;
  96.      
  97.     while( col < width && *str )
  98.     {
  99.         if( *str == '\n' )
  100.             break;
  101.         
  102.         else if( *str == '\r' )
  103.         {
  104.             while( col > 0 )
  105.             {
  106.                 --col;
  107.                 putc( '\b', where );
  108.             }
  109.  
  110.             str++;
  111.         }
  112.         else if( *str == '\t' )
  113.         {
  114.             str++;
  115.             col++;
  116.             putc( ' ', where );
  117.              
  118.             while( ( col % 8 ) && col < width )
  119.             {
  120.                 putc( ' ', where );
  121.                 col++;
  122.             }
  123.         }
  124.         else
  125.         {
  126.             if( *str == Q_ESC )
  127.             {
  128.                 putc( *str++, where );
  129.                 if( !*str )
  130.                     break;
  131.     
  132.                 putc( *str++, where );
  133.                 if( !*str )
  134.                     break;
  135.     
  136.                 putc( *str++, where );
  137.                 if( !*str )
  138.                     break;
  139.             }
  140.             else if( *str == '\b' )
  141.                 --col;
  142.             else if( *str >= ' ' )
  143.                 ++col;
  144.      
  145.         putc( *str++, where );
  146.         }
  147.     }
  148.     if( padded )
  149.         while( col++ < width )
  150.             putc( ' ', where );
  151. }
  152.