PennMUSH Community

root/1.8.3/trunk/hdrs/ansi.h

Revision 1167, 6.7 kB (checked in by shawnw, 10 months ago)

Merge devel into trunk for p6 release

Line 
1 /* ansi.h */
2
3 /* ANSI control codes for various neat-o terminal effects
4
5  * Some older versions of Ultrix don't appear to be able to
6  * handle these escape sequences. If lowercase 'a's are being
7  * stripped from @doings, and/or the output of the ANSI flag
8  * is screwed up, you have the Ultrix problem.
9  *
10  * To fix the ANSI problem, try replacing the '\x1B' with '\033'.
11  * To fix the problem with 'a's, replace all occurrences of '\a'
12  * in the code with '\07'.
13  *
14  */
15
16 #ifndef __ANSI_H
17 #define __ANSI_H
18
19 #include "mushtype.h"
20 #include "mypcre.h"
21
22 #define BEEP_CHAR     '\a'
23 #define ESC_CHAR      '\x1B'
24
25 #define ANSI_RAW_NORMAL "\x1B[0m"
26
27 #define TAG_START     '\002'
28 #define TAG_END       '\003'
29 #define MARKUP_START     "\002"
30 #define MARKUP_END       "\003"
31
32 #define ANSI_HILITE      MARKUP_START "ch" MARKUP_END
33 #define ANSI_INVERSE     MARKUP_START "ci" MARKUP_END
34 #define ANSI_BLINK       MARKUP_START "cf" MARKUP_END
35 #define ANSI_UNDERSCORE  MARKUP_START "cu" MARKUP_END
36
37 #define ANSI_INV_BLINK         MARKUP_START "cfi" MARKUP_END
38 #define ANSI_INV_HILITE        MARKUP_START "chi" MARKUP_END
39 #define ANSI_BLINK_HILITE      MARKUP_START "cfh" MARKUP_END
40 #define ANSI_INV_BLINK_HILITE  MARKUP_START "cifh" MARKUP_END
41
42 /* Foreground colors */
43
44 #define ANSI_PLAIN      MARKUP_START "n" MARKUP_END
45 #define ANSI_BLACK      MARKUP_START "cx" MARKUP_END
46 #define ANSI_RED        MARKUP_START "cr" MARKUP_END
47 #define ANSI_GREEN      MARKUP_START "cg" MARKUP_END
48 #define ANSI_YELLOW     MARKUP_START "cy" MARKUP_END
49 #define ANSI_BLUE       MARKUP_START "cb" MARKUP_END
50 #define ANSI_MAGENTA    MARKUP_START "cm" MARKUP_END
51 #define ANSI_CYAN       MARKUP_START "cc" MARKUP_END
52 #define ANSI_WHITE      MARKUP_START "cw" MARKUP_END
53
54 #define ANSI_HIBLACK      MARKUP_START "chx" MARKUP_END
55 #define ANSI_HIRED        MARKUP_START "chr" MARKUP_END
56 #define ANSI_HIGREEN      MARKUP_START "chg" MARKUP_END
57 #define ANSI_HIYELLOW     MARKUP_START "chy" MARKUP_END
58 #define ANSI_HIBLUE       MARKUP_START "chb" MARKUP_END
59 #define ANSI_HIMAGENTA    MARKUP_START "chm" MARKUP_END
60 #define ANSI_HICYAN       MARKUP_START "chc" MARKUP_END
61 #define ANSI_HIWHITE      MARKUP_START "chw" MARKUP_END
62
63 /* Background colors */
64
65 #define ANSI_BBLACK     MARKUP_START "cX" MARKUP_END
66 #define ANSI_BRED       MARKUP_START "cR" MARKUP_END
67 #define ANSI_BGREEN     MARKUP_START "cG" MARKUP_END
68 #define ANSI_BYELLOW    MARKUP_START "cY" MARKUP_END
69 #define ANSI_BBLUE      MARKUP_START "cB" MARKUP_END
70 #define ANSI_BMAGENTA   MARKUP_START "cM" MARKUP_END
71 #define ANSI_BCYAN      MARKUP_START "cC" MARKUP_END
72 #define ANSI_BWHITE     MARKUP_START "cW" MARKUP_END
73
74 #define ANSI_END        MARKUP_START "c/" MARKUP_END
75 #define ANSI_ENDALL     MARKUP_START "c/a" MARKUP_END
76
77 #define ANSI_NORMAL     ANSI_ENDALL
78
79 void init_ansi_codes(void);
80
81 #ifdef HAVE_STDINT_H
82 #include <stdint.h>
83 #endif
84
85 typedef struct _ansi_data {
86   uint8_t bits;
87   uint8_t offbits;
88   char fore;
89   char back;
90 } ansi_data;
91
92 int read_raw_ansi_data(ansi_data *store, const char *codes);
93 int write_raw_ansi_data(ansi_data *old, ansi_data *cur, char *buff, char **bp);
94
95 void define_ansi_data(ansi_data *store, const char *str);
96 int write_ansi_data(ansi_data *cur, char *buff, char **bp);
97
98
99 void nest_ansi_data(ansi_data *old, ansi_data *cur);
100
101 #define MARKUP_COLOR 'c'
102 #define MARKUP_COLOR_STR "c"
103 #define MARKUP_COLOR_OLD 'a'
104 #define MARKUP_HTML 'p'
105 #define MARKUP_HTML_STR "p"
106
107 /* Markup information necessary for ansi_string */
108
109 /* Miscellaneous notes on markup_information:
110  * If "start" is negative, there are two cases:
111  * end >= 0  :: A stand-alone tag, starting at "end".
112  * end <  0  :: A tag set for removal.
113  * If start is non-negative while end is negative, something's broken.
114  *
115  * Markup surrounding a character ends to the right of that character:
116  * In the string "abc", if 'b' has a markup assigned to only itself,
117  * start = 1, end = 2. (Instead of end = 1)
118  */
119
120 typedef struct _markup_information {
121   char *start_code;
122   char *stop_code;
123   char type;
124   int start;
125   int end;
126   int priority;
127 } markup_information;
128
129 /** A string, with ansi attributes broken out from the text */
130 typedef struct _ansi_string {
131   char text[BUFFER_LEN];        /**< Text of the string */
132   ansi_data ansi[BUFFER_LEN];   /**< ANSI of the string */
133   markup_information markup[BUFFER_LEN]; /**< The markup_information list */
134   int nmarkups;         /**< Number of Pueblo markups */
135   int len;              /**< Length of text */
136   int optimized;              /**< Has this ansi_string been optimized? */
137 } ansi_string;
138
139 int ansi_strcmp(const char *astr, const char *bstr);
140 extern char *remove_markup(const char *orig, size_t * stripped_len);
141 extern char *skip_leading_ansi(const char *p);
142
143 extern ansi_string *
144 parse_ansi_string(const char *src)
145   __attribute_malloc__;
146     extern void flip_ansi_string(ansi_string *as);
147     extern void free_ansi_string(ansi_string *as);
148
149 /* Append X characters to the end of a string, taking ansi and html codes into
150    account. */
151     extern int safe_ansi_string(ansi_string *as, int start, int len,
152                                 char *buff, char **bp);
153
154 /* Modifying ansi strings */
155     ansi_string *real_parse_ansi_string(const char *src)
156  __attribute_malloc__;
157     int ansi_string_delete(ansi_string *as, int start, int count);
158     int ansi_string_insert(ansi_string *dst, int loc, ansi_string *src);
159     int ansi_string_replace(ansi_string *dst, int loc, int size,
160                             ansi_string *src);
161     ansi_string *scramble_ansi_string(ansi_string *as);
162     void optimize_ansi_string(ansi_string *as);
163
164 /* Dump the penn code required to recreate the ansi_string */
165     extern int dump_ansi_string(ansi_string *as, char *buff, char **bp);
166
167     int ansi_pcre_copy_substring(ansi_string *as, int *ovector, int stringcount,
168                                  int stringnumber, int nonempty, char *buffer,
169                                  char **bp);
170
171     int ansi_pcre_copy_named_substring(const pcre * code, ansi_string *as,
172                                        int *ovector, int stringcount,
173                                        const char *stringname, int nonempty,
174                                        char *buffer, char **bp);
175
176 /* Pueblo stuff */
177 #define open_tag(x) tprintf("%c%c%s%c",TAG_START,MARKUP_HTML,x,TAG_END)
178 #define close_tag(x) tprintf("%c%c/%s%c",TAG_START,MARKUP_HTML,x,TAG_END)
179 #define wrap_tag(x,y) tprintf("%c%c%s%c%s%c%c/%s%c", \
180                               TAG_START,MARKUP_HTML,x,TAG_END, \
181                               y, TAG_START,MARKUP_HTML,x,TAG_END)
182     int safe_tag(char const *a_tag, char *buf, char **bp);
183     int safe_tag_cancel(char const *a_tag, char *buf, char **bp);
184     int safe_tag_wrap(char const *a_tag, char const *params,
185                       char const *data, char *buf, char **bp, dbref player);
186
187 #endif                          /* __ANSI_H */
Note: See TracBrowser for help on using the browser.