1 /* 2 * $LynxId: LYStrings.h,v 1.88 2013/05/03 09:37:02 tom Exp $ 3 */ 4 #ifndef LYSTRINGS_H 5 #define LYSTRINGS_H 6 7 #include <LYCurses.h> 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 #define SQUOTE '\'' 14 #define DQUOTE '"' 15 #define ESCAPE '\\' 16 #define LPAREN '(' 17 #define RPAREN ')' 18 19 typedef const char *const Const2CharPtr; 20 typedef enum { 21 NORECALL = 0 22 ,RECALL_URL 23 ,RECALL_CMD 24 ,RECALL_MAIL 25 } RecallType; 26 27 #define IS_UTF8_TTY (BOOLEAN) (LYCharSet_UC[current_char_set].enc == UCT_ENC_UTF8) 28 #define IS_CJK_TTY (BOOLEAN) (HTCJK != NOCJK) 29 30 #define is8bits(ch) (BOOLEAN) (UCH(ch) >= 128) /* isascii(ch) is not POSIX */ 31 32 /* UPPER8(ch1,ch2) is an extension of (TOUPPER(ch1) - TOUPPER(ch2)) */ 33 extern int UPPER8(int ch1, 34 int ch2); 35 36 extern int get_mouse_link(void); 37 extern int peek_mouse_link(void); 38 extern int peek_mouse_levent(void); 39 extern int fancy_mouse(WINDOW * win, int row, int *position); 40 41 extern char *LYstrncpy(char *dst, 42 const char *src, 43 int n); 44 #define LYStrNCpy(dst,src,n) LYstrncpy(dst,src,(int)(n)) 45 extern void ena_csi(int flag); 46 extern int get_popup_number(const char *msg, 47 int *c, 48 int *rel); 49 extern int LYarrayLength(STRING2PTR list); 50 extern int LYarrayWidth(STRING2PTR list); 51 extern int LYgetch(void); 52 extern int LYgetch_choice(void); 53 extern int LYgetch_input(void); 54 extern int LYgetch_single(void); 55 extern int LYgetstr(char *inputline, 56 int hidden, 57 size_t bufsize, 58 RecallType recall); 59 #define LYGetStr(input,hidden,bufsize,recall) \ 60 LYgetstr(input,hidden,(size_t)(bufsize),recall) 61 extern int LYgetBString(bstring **inputline, 62 int hidden, 63 size_t max_cols, 64 RecallType recall); 65 extern int LYscanFloat(const char *source, float *result); 66 extern int LYscanFloat2(const char **source, float *result); 67 extern char *LYstrsep(char **stringp, 68 const char *delim); 69 extern char *LYstrstr(char *chptr, 70 const char *tarptr); 71 extern char *LYmbcsstrncpy(char *dst, 72 const char *src, 73 int n_bytes, 74 int n_glyphs, 75 int utf_flag); 76 extern const char *LYmbcs_skip_cells(const char *data, 77 int n_cells, 78 int utf_flag); 79 extern const char *LYmbcs_skip_glyphs(const char *data, 80 int n_glyphs, 81 int utf_flag); 82 extern int LYmbcsstrlen(const char *str, 83 int utf_flag, 84 int count_gcells); 85 86 extern const char *LYno_attr_mbcs_strstr(const char *chptr, 87 const char *tarptr, 88 int utf_flag, 89 int count_gcells, 90 int *nstartp, 91 int *nendp); 92 extern const char *LYno_attr_mbcs_case_strstr(const char *chptr, 93 const char *tarptr, 94 int utf_flag, 95 int count_gcells, 96 int *nstartp, 97 int *nendp); 98 99 #define LYno_attr_mb_strstr(chptr, tarptr, utf_flag, count_gcells, nstartp, nendp) \ 100 (LYcase_sensitive \ 101 ? LYno_attr_mbcs_strstr(chptr, tarptr, utf_flag, count_gcells, nstartp, nendp) \ 102 : LYno_attr_mbcs_case_strstr(chptr, tarptr, utf_flag, count_gcells, nstartp, nendp)) 103 104 extern const char *LYno_attr_char_strstr(const char *chptr, 105 const char *tarptr); 106 extern const char *LYno_attr_char_case_strstr(const char *chptr, 107 const char *tarptr); 108 109 #define LYno_attr_strstr(chptr, tarptr) \ 110 (LYcase_sensitive \ 111 ? LYno_attr_char_strstr(chptr, tarptr) \ 112 : LYno_attr_char_case_strstr(chptr, tarptr)) 113 114 extern char *SNACopy(char **dest, 115 const char *src, 116 int n); 117 extern char *SNACat(char **dest, 118 const char *src, 119 int n); 120 121 #define StrnAllocCopy(dest, src, n) SNACopy (&(dest), src, n) 122 #define StrnAllocCat(dest, src, n) SNACat (&(dest), src, n) 123 124 extern char *LYSafeGets(char **src, FILE *fp); 125 126 #ifdef USE_CMD_LOGGING 127 extern BOOL LYHaveCmdScript(void); 128 extern int LYReadCmdKey(int mode); 129 extern void LYCloseCmdLogfile(void); 130 extern void LYOpenCmdLogfile(int argc, char **argv); 131 extern void LYOpenCmdScript(void); 132 extern void LYWriteCmdKey(int ch); 133 134 #else 135 #define LYHaveCmdScript() FALSE 136 #define LYReadCmdKey(mode) LYgetch_for(mode) 137 #define LYCloseCmdLogfile() /* nothing */ 138 #endif 139 140 /* values for LYgetch */ 141 /* The following are lynxkeycodes, not to be confused with 142 lynxactioncodes (LYK_*) to which they are often mapped. 143 The lynxkeycodes include all single-byte keys as a subset. - kw 144 */ 145 #define UPARROW 256 /* 0x100 */ 146 #define DNARROW 257 /* 0x101 */ 147 #define RTARROW 258 /* 0x102 */ 148 #define LTARROW 259 /* 0x103 */ 149 #define PGDOWN 260 /* 0x104 */ 150 #define PGUP 261 /* 0x105 */ 151 #define HOME 262 /* 0x106 */ 152 #define END_KEY 263 /* 0x107 */ 153 #define F1 264 /* 0x108 */ 154 #define DO_KEY 265 /* 0x109 */ 155 #define FIND_KEY 266 /* 0x10A */ 156 #define SELECT_KEY 267 /* 0x10B */ 157 #define INSERT_KEY 268 /* 0x10C */ 158 #define REMOVE_KEY 269 /* 0x10D */ 159 #define DO_NOTHING 270 /* 0x10E */ 160 #define BACKTAB_KEY 271 /* 0x10F */ 161 #define MOUSE_KEY 285 /* 0x11D */ 162 /* ***** NOTES: ***** 163 If you add definitions for new lynxkeycodes to the above list that need to 164 be mapped to LYK_* lynxactioncodes - 165 166 - AT LEAST the tables keymap[] and key_override[] in LYKeymap.c have to be 167 changed/reviewed, AS WELL AS the lineedit binding tables in LYEditmap.c ! 168 169 - KEYMAP_SIZE, defined in LYKeymap.h, may need to be changed ! 170 171 - See also table named_keys[] in LYKeymap.c for 'pretty' strings for the 172 keys with codes >= 256 (to appear on the 'K'eymap page). New keycodes 173 should probably be assigned consecutively, so their key names can be 174 easily added to named_keys[] (but see next point). They should also be 175 documented in lynx.cfg. 176 177 - The DOS port uses its own native codes for some keys, unless they are 178 remapped by the code in LYgetch(). See *.key files in docs/ directory. 179 Adding new keys here may conflict with those codes (affecting DOS users), 180 unless/until remapping is added or changed in LYgetch(). (N)curses 181 keypad codes (KEY_* from curses.h) can also directly appear as 182 lynxkeycodes and conflict with our assignments, although that shouldn't 183 happen - the useful ones should be recognized in LYgetch(). 184 185 - The actual recognition of raw input keys or escape sequences, and mapping 186 to our lynxkeycodes, take place in LYgetch() and/or its subsidiary 187 functions and/or the curses/slang/etc. libraries. 188 189 The basic lynxkeycodes can appear combined with various flags in 190 higher-order bits as extended lynxkeycodes; see macros in LYKeymap.h. The 191 range of possible basic values is therefore limited, they have to be less 192 than LKC_ISLKC (even if KEYMAP_SIZE is increased). 193 */ 194 195 # define FOR_PANEL 0 /* normal screen, also LYgetch default */ 196 # define FOR_CHOICE 1 /* mouse menu */ 197 # define FOR_INPUT 2 /* form input and textarea field */ 198 # define FOR_PROMPT 3 /* string prompt editing */ 199 # define FOR_SINGLEKEY 4 /* single key prompt, confirmation */ 200 201 #define VISIBLE 0 202 #define HIDDEN 1 203 204 #ifdef USE_ALT_BINDINGS 205 /* Enable code implementing additional, mostly emacs-like, line-editing 206 functions. - kw */ 207 #define ENHANCED_LINEEDIT 208 #endif 209 210 /* EditFieldData preserves state between calls to LYEdit1 211 */ 212 typedef struct _EditFieldData { 213 214 int sx; /* Origin of editfield */ 215 int sy; 216 int dspwdth; /* Screen real estate for editing */ 217 218 size_t buffer_used; /* current size of string. */ 219 size_t buffer_size; /* current buffer-size, excluding nul at end */ 220 size_t buffer_limit; /* buffer size limit, zero if indefinite */ 221 char pad; /* Right padding typically ' ' or '_' */ 222 BOOL hidden; /* Masked password entry flag */ 223 224 BOOL dirty; /* accumulate refresh requests */ 225 BOOL panon; /* Need horizontal scroll indicator */ 226 int xpan; /* Horizontal scroll offset */ 227 int pos; /* Insertion point in string */ 228 int margin; /* Number of columns look-ahead/look-back */ 229 int current_modifiers; /* Modifiers for next input lynxkeycode */ 230 #ifdef ENHANCED_LINEEDIT 231 int mark; /* position of emacs-like mark, or -1-pos to denote 232 unactive mark. */ 233 #endif 234 235 char *buffer; /* the buffer which is being edited */ 236 int *offset2col; /* fixups for multibyte characters */ 237 238 } EditFieldData; 239 240 /* line-edit action encoding */ 241 242 typedef enum { 243 LYE_NOP = 0 /* Do Nothing */ 244 ,LYE_CHAR /* Insert printable char */ 245 ,LYE_ENTER /* Input complete, return char/lynxkeycode */ 246 ,LYE_TAB /* Input complete, return TAB */ 247 ,LYE_STOP /* Input complete, deactivate */ 248 ,LYE_ABORT /* Input cancelled */ 249 250 ,LYE_FORM_PASS /* In form fields: input complete, 251 return char / lynxkeycode; 252 Elsewhere: Do Nothing */ 253 254 ,LYE_DELN /* Delete next/curr char */ 255 ,LYE_DELC /* Obsolete (DELC case was equiv to DELN) */ 256 ,LYE_DELP /* Delete prev char */ 257 ,LYE_DELNW /* Delete next word */ 258 ,LYE_DELPW /* Delete prev word */ 259 260 ,LYE_ERASE /* Erase the line */ 261 262 ,LYE_BOL /* Go to begin of line */ 263 ,LYE_EOL /* Go to end of line */ 264 ,LYE_FORW /* Cursor forwards */ 265 ,LYE_FORW_RL /* Cursor forwards or right link */ 266 ,LYE_BACK /* Cursor backwards */ 267 ,LYE_BACK_LL /* Cursor backwards or left link */ 268 ,LYE_FORWW /* Word forward */ 269 ,LYE_BACKW /* Word back */ 270 271 ,LYE_LOWER /* Lower case the line */ 272 ,LYE_UPPER /* Upper case the line */ 273 274 ,LYE_LKCMD /* Invoke command prompt */ 275 276 ,LYE_AIX /* Hex 97 */ 277 278 ,LYE_DELBL /* Delete back to BOL */ 279 ,LYE_DELEL /* Delete thru EOL */ 280 281 ,LYE_SWMAP /* Switch input keymap */ 282 283 ,LYE_TPOS /* Transpose characters */ 284 285 ,LYE_SETM1 /* Set modifier 1 flag */ 286 ,LYE_SETM2 /* Set modifier 2 flag */ 287 ,LYE_UNMOD /* Fall back to no-modifier command */ 288 289 ,LYE_C1CHAR /* Insert C1 char if printable */ 290 291 ,LYE_SETMARK /* emacs-like set-mark-command */ 292 ,LYE_XPMARK /* emacs-like exchange-point-and-mark */ 293 ,LYE_KILLREG /* emacs-like kill-region */ 294 ,LYE_YANK /* emacs-like yank */ 295 #ifdef CAN_CUT_AND_PASTE 296 ,LYE_PASTE /* ClipBoard to Lynx */ 297 #endif 298 } LYEditCodes; 299 300 /* All preceding values must be within 0x00..0x7f - kw */ 301 302 /* The following are meant to be bitwise or-ed: */ 303 #define LYE_DF 0x80 /* Flag to set modifier 3 AND do other 304 action */ 305 #define LYE_FORM_LAC 0x1000 /* Flag to pass lynxactioncode given by 306 lower bits. Doesn't fit in a char! */ 307 308 #if defined(USE_KEYMAPS) 309 extern int lynx_initialize_keymaps(void); 310 extern int map_string_to_keysym(const char *src, int *lec); 311 #endif 312 313 extern char *LYElideString(char *str, 314 int cut_pos); 315 extern void LYEscapeStartfile(char **buffer); 316 extern void LYLowerCase(char *buffer); 317 extern void LYUpperCase(char *buffer); 318 extern BOOLEAN LYRemoveNewlines(char *buffer); 319 extern char *LYReduceBlanks(char *buffer); 320 extern char *LYRemoveBlanks(char *buffer); 321 extern char *LYSkipBlanks(char *buffer); 322 extern char *LYSkipNonBlanks(char *buffer); 323 extern const char *LYSkipCBlanks(const char *buffer); 324 extern const char *LYSkipCNonBlanks(const char *buffer); 325 extern void LYTrimLeading(char *buffer); 326 extern char *LYTrimNewline(char *buffer); 327 extern void LYTrimTrailing(char *buffer); 328 extern void LYTrimAllStartfile(char *buffer); 329 extern BOOLEAN LYTrimStartfile(char *buffer); 330 extern void LYFinishEdit(EditFieldData *edit); 331 extern void LYSetupEdit(EditFieldData *edit, char *old, 332 size_t buffer_limit, 333 int display_limit); 334 extern void LYRefreshEdit(EditFieldData *edit); 335 extern int EditBinding(int ch); /* in LYEditmap.c */ 336 extern BOOL LYRemapEditBinding(int xlkc, 337 int lec, 338 int select_edi); /* in LYEditmap.c */ 339 extern int LYKeyForEditAction(int lec); /* in LYEditmap.c */ 340 extern int LYEditKeyForAction(int lac, int *pmodkey); /* LYEditmap.c */ 341 extern int LYEdit1(EditFieldData *edit, int ch, 342 int action, 343 int maxMessage); 344 extern void LYCloseCloset(RecallType recall); 345 extern int LYhandlePopupList(int cur_choice, 346 int ly, 347 int lx, 348 STRING2PTR choices, 349 int width, 350 int i_length, 351 int disabled, 352 int for_mouse); 353 354 typedef unsigned char LYEditCode; 355 356 extern int current_lineedit; 357 extern const char *LYLineeditNames[]; 358 extern LYEditCode *LYLineEditors[]; 359 extern const char *LYLineeditHelpURLs[]; 360 361 #define CurrentLineEditor() LYLineEditors[current_lineedit] 362 363 extern const char *LYLineeditHelpURL(void); 364 365 extern int escape_bound; 366 367 #define LYLineEdit(e,c,m) LYEdit1(e, c, EditBinding(c) & ~LYE_DF, m) 368 369 /* Dummy initializer for LYEditmap.c */ 370 extern int LYEditmapDeclared(void); 371 372 extern int LYEditInsert(EditFieldData *edit, 373 unsigned const char *s, 374 int len, int map_active, 375 int maxMessage); 376 377 #ifdef __cplusplus 378 } 379 #endif 380 #endif /* LYSTRINGS_H */ 381