home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / rvi / part1 / rv_column.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  1.4 KB  |  82 lines

  1. #include "rv.h"
  2.  
  3. /*
  4.  * Logical to/from physical column conversion functions
  5.  */
  6.  
  7. INT
  8. file_column(s, maxscreen_col)
  9. /*
  10.  * Convert a screen column number to a file column number.
  11.  */
  12. register char    *s;
  13. register INT maxscreen_col;
  14. {
  15.     register INT    c;
  16.     register INT    file_col, screen_col;
  17.  
  18.     if (s == NULL) {
  19.         errflag = 1;
  20.         botprint(TRUE, "file_column - text is null.\n");
  21.         return 0;
  22.     }
  23.  
  24.     file_col = 0;
  25.     screen_col = 0;
  26.     while (c = *s++) {
  27.         if (c < ' ' || c > '~') /* control character */
  28.             if (c == '\t' && !set_list) {
  29.                 screen_col += set_tabstops -
  30.                     (screen_col % set_tabstops) - 1;
  31.             } else
  32.                 ++screen_col;
  33.         ++file_col;
  34.         ++screen_col;
  35.         if (screen_col > maxscreen_col)
  36.             break;
  37.     }
  38.  
  39.     return file_col <= 0 ? 0 : file_col-1;
  40. }
  41.  
  42.  
  43.  
  44. INT
  45. screen_column(s, maxfile_col)
  46. /*
  47.  * Convert a file column number to a screen column number.
  48.  */
  49. register char    *s;
  50. register INT maxfile_col;
  51. {
  52.     register INT    c;
  53.     register INT    file_col, screen_col;
  54.  
  55.     if (s == NULL) {
  56.         errflag = 1;
  57.         botprint(TRUE, "screen_column - text is null.\n");
  58.         return 0;
  59.     }
  60.  
  61.     file_col = 0;
  62.     screen_col = 0;
  63.     while (c = *s++) {
  64.         if (c < ' ' || c > '~') /* control character */
  65.             if (c == '\t' && !set_list) {
  66.                 if (input_mode && file_col >= maxfile_col) {
  67.                     ++screen_col;
  68.                     break;
  69.                 }
  70.                 screen_col += set_tabstops - 
  71.                     (screen_col % set_tabstops) - 1;
  72.             } else
  73.                 ++screen_col;
  74.         ++file_col;
  75.         ++screen_col;
  76.         if (file_col > maxfile_col)
  77.             break;
  78.     }
  79.  
  80.     return screen_col <= 0 ? 0 : screen_col-1;
  81. }
  82.