home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fed0217s.zip / include / line.h < prev    next >
C/C++ Source or Header  |  2000-12-13  |  3KB  |  105 lines

  1. /*
  2. ** Module   :LINE.H
  3. ** Abstract :Class Line handles one line of editor
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. **
  7. ** Log: Wed  05/03/1997       Updated to V0.5
  8. */
  9.  
  10. #include <collect.h>
  11. #include <common.h>
  12. #include <parser.h>
  13.  
  14. #ifndef  __LINE_H
  15. #define  __LINE_H
  16.  
  17. #define BC_STEP     16
  18.  
  19. class ByteCache
  20. {
  21.         char* buf;      //Buffer of pairs color/len
  22.         int   len;      //Buffer len
  23.         int   pos;      //Last requested position rounded down to token len
  24.         int   bpos;     //Last position in buffer for 'pos'
  25.  
  26.         int   enc;      //Current encoding position
  27.         int   last_pos; //Last encoded position
  28.  
  29. #define q_len(p)    ((buf[p] & 0x0F) + 1)
  30.  
  31.         void expand_buffer();
  32.         int unwind(int qry);
  33.         int unwind2(int qry)
  34.         {
  35.             if(qry > last_pos || !len)
  36.                 return 0;
  37.  
  38.             if(qry >= pos && qry < (pos + q_len(bpos)))
  39.                 return buf[bpos];
  40.  
  41.             pos += q_len(bpos);
  42.             bpos++;
  43.  
  44.             if(qry >= pos && qry < (pos + q_len(bpos)))
  45.                 return buf[bpos];
  46.  
  47.             return unwind(qry);
  48.         }
  49.  
  50.     public:
  51.  
  52.         ByteCache():buf(0),len(0)       { reset();}
  53.         ~ByteCache()                    { delete buf;}
  54.  
  55.         //Direct access (ReadOnly)
  56.         int get_color(int pos)  { return unwind2(pos) >> 4;}
  57.         int get_len  (int pos)  { return (unwind2(pos) & 0x0F) + 1;}
  58.  
  59.         //Stream encoding (WroteOnly)
  60.         void reset()                     { pos = bpos = enc = last_pos = 0;}
  61.         void encode(int color, int len);
  62. };
  63.  
  64. class Line;
  65. typedef Line* PLine;
  66.  
  67. class Line
  68. {
  69.         int buf_len;
  70.         int known_len;
  71.         int hl_state;
  72.  
  73.         void expand_by(int len);
  74.         void check_size(int sz) { if(sz >= buf_len) expand_by(sz - buf_len); }
  75.  
  76.     public:
  77.         char *str;
  78. //        ByteCache bc;
  79.  
  80.         Line();
  81.         Line(char *);
  82.         Line(PLine);
  83.         Line(PLine master, int start, int width);
  84.  
  85.         ~Line();
  86.         void set(char *str);
  87.         char * get_print(int start, char *buffer, int width);
  88.         int ins_char(int chr, int pos);
  89.         int ins_char(int pos, PLine src);
  90.         int del_char(int pos, int num = 1);
  91.         int len();
  92.         void touch();
  93.         int char_at(int pos);
  94.         int fchar_at(char *tmp, int pos) { return (pos < len()) ? tmp[pos]:0;}
  95.         void build_print(char*);
  96.         void xlat(char *cvt_tbl);
  97.  
  98.         int state() { return hl_state;}
  99.  
  100.         void set_hiliting(Parser*, int& initial_state);
  101. };
  102.  
  103. #endif //__LINE_H
  104.  
  105.