URI: 
       gramscii.h - gramscii - A simple editor for ASCII box-and-arrow charts
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
       gramscii.h (3758B)
       ---
            1 #ifndef __GRAMSCII_H__
            2 #define __GRAMSCII_H__
            3 
            4 #define _POSIX_C_SOURCE 200112L
            5 
            6 #include <stdio.h>
            7 #include <termios.h>
            8 #include <unistd.h>
            9 
           10 
           11 
           12 /** constants **/
           13 
           14 /* modes */
           15 #define MOVE   0x00
           16 #define BOX    0x01
           17 #define ARROW  0x02
           18 #define TEXT   0x04
           19 #define DEL    0x08
           20 #define VIS    0x10
           21 #define PAR    0x20
           22 #define REM    0x40
           23 #define TRP    0x80
           24 /**/
           25 
           26 /* directions */
           27 #define DIR_N  0x00
           28 #define DIR_R  0x01
           29 #define DIR_U  0x02
           30 #define DIR_D  0x04
           31 #define DIR_L  0x08
           32 
           33 #define DIR_HOR (DIR_R | DIR_L)
           34 #define DIR_VER (DIR_D | DIR_U)
           35 /**/
           36 
           37 /** box style **/
           38 /* rectangular box */
           39 #define BOX_RECT 0x00
           40 /* parallelograms */
           41 #define BOX_PAR  0x10
           42 /* parallelogram (leaning right) */
           43 #define BOX_PARR 0x11
           44 /* parallelogram (leaning left) */
           45 #define BOX_PARL 0x12
           46 /* trapezium */
           47 #define BOX_TRAP    0x20
           48 #define BOX_TRAP_U  0x24
           49 #define BOX_TRAP_D  0x28
           50 #define BOX_TRAP_R  0x21
           51 #define BOX_TRAP_C  0x22
           52 #define BOX_TRAP_L  0x23
           53 #define BOX_TRAP_UR 0x25
           54 #define BOX_TRAP_UC 0x26
           55 #define BOX_TRAP_UL 0x27
           56 #define BOX_TRAP_DL 0x29
           57 #define BOX_TRAP_DC 0x2a
           58 #define BOX_TRAP_DR 0x2b
           59 #define STYLE_IS(x, y) (((x) & (y) ) == y)
           60 /**/
           61 
           62 #define NOFIX 0x0
           63 #define FIX   0x1
           64 
           65 /* markers */
           66 #define BG        ' '
           67 #define PTR       '+'
           68 #define UND       '_'
           69 #define ARR_L     '<'
           70 #define ARR_R     '>'
           71 #define ARR_U     '^'
           72 #define ARR_D     'v'
           73 /**/
           74 
           75 /* global positions */
           76 #define HOME   0x01
           77 #define END    0x02
           78 #define MIDDLE 0x04
           79 /**/
           80 
           81 /* video modes */
           82 #define VIDEO_NRM 0
           83 #define VIDEO_REV 7 
           84 /**/
           85 
           86 /* undo buffer elem types */
           87 #define PRV_STATE 0x01
           88 #define NEW_STATE 0x02
           89 /**/
           90 
           91 /* file types */
           92 #define FFILE 0x01
           93 #define FPIPE 0x02
           94 
           95 /** types **/
           96 
           97 typedef struct{
           98         int sz;/* allocated size */
           99         int n;/* line number */
          100         int lst;/* last visible char (before the first \0) */
          101         char *s;
          102 } line_t;
          103 
          104 typedef struct{
          105         int sz;/* allocated size */
          106         int num;/* number of lines stored */
          107         line_t *l;
          108 } lineset_t;
          109 
          110 typedef struct{
          111         int x;
          112         int y;
          113 } pos_t;
          114 
          115 
          116 /** MACROS **/
          117 
          118 #define MIN(x,y)  (x) < (y) ? (x) : (y)
          119 #define MAX(x,y)  (x) > (y) ? (x) : (y)
          120 
          121 #define progr_x(d) ((d) == DIR_L ? -1 : (d) == DIR_R ? 1 : 0)
          122 #define progr_y(d) ((d) == DIR_U ? -1 : (d) == DIR_D ? 1 : 0)
          123 
          124 
          125 /** screen-related functions **/
          126 void reset_styles();
          127 void redraw();
          128 int move_around(char c, FILE *fc, char global);
          129 void check_bound(int *x, int *y);
          130 void status_bar();
          131 void show_cursor();
          132 void set_cur(char c);
          133 void update_current();
          134 void set_xy(int _x, int _y, char c);
          135 void draw_xy(int x, int y, char c);
          136 char get_mark(char dir);
          137 void set_video(int v);
          138 char get_key(FILE *fc, char *msg);
          139 void get_string(FILE *fc, char *msg, char *s, int sz);
          140 void erase_box(int x1, int y1, char c);
          141 int is_yes(char c);
          142 void init_screen();
          143 void erase_line(int i);
          144 void erase_screen();
          145 void go_to(int where);
          146 void crop_to_nonblank();
          147 void crop_to_rect();
          148 void erase_blank_lines(int y1, int y2);
          149 int _isblank(int c);
          150 void mark_pos(FILE *fc);
          151 /**/
          152 
          153 /** drawing-related functions **/
          154 int change_style(char c);
          155 void get_text(FILE *fc);
          156 void get_box(FILE *fc, char st);
          157 void get_arrow(FILE *fc);
          158 void erase(FILE *fc);
          159 void visual_box(FILE *fc);
          160 void paste();
          161 void undo_change();
          162 void redo_change();
          163 void get_comment(FILE *fc);
          164 /**/
          165 
          166 /** file-related functions **/
          167 void write_file(FILE *fc);
          168 void check_modified(FILE *fc);
          169 void load_file(FILE *fc);
          170 void new_file(FILE *fc);
          171 void read_file_at(FILE *fc, int xl, int yl);
          172 /**/
          173 
          174 /** line-related functions **/
          175 void dump_lines(lineset_t ls, FILE *f);
          176 void alloc_line(line_t *l);
          177 void ensure_line_length(line_t *l, int len);
          178 void ensure_num_lines(lineset_t *ls, int n);
          179 void yank_region(int x1, int y1, int x2, int y2);
          180 void paste_region(int x1, int y1);
          181 void copy_lines_to_ring(int y1, int y2, int which);
          182 void invalidate_undo();
          183 /**/
          184 
          185 void cleanup(int);
          186 
          187 #endif