1 /* 2 * $LynxId: LYStrings.h,v 1.117 2018/05/04 22:47:10 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 masked, 57 unsigned bufsize, 58 RecallType recall); 59 #define LYGetStr(input,masked,bufsize,recall) \ 60 LYgetstr(input,masked,(unsigned)(bufsize),recall) 61 extern int LYgetBString(bstring **inputline, 62 int masked, 63 unsigned 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 size_t n); 117 extern char *SNACat(char **dest, 118 const char *src, 119 size_t 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. 144 * These are "extra" keys which do not fit into a single byte. 145 */ 146 typedef enum { 147 UNKNOWN_KEY = -1 148 ,DEL_KEY = 127 149 ,UPARROW_KEY = 256 150 ,DNARROW_KEY 151 ,RTARROW_KEY 152 ,LTARROW_KEY 153 ,PGDOWN_KEY 154 ,PGUP_KEY 155 ,HOME_KEY 156 ,END_KEY 157 ,F1_KEY 158 ,DO_KEY 159 ,FIND_KEY 160 ,SELECT_KEY 161 ,INSERT_KEY 162 ,REMOVE_KEY 163 ,DO_NOTHING 164 ,BACKTAB_KEY 165 /* these should be referenced by name in keymap, e.g., "f2" */ 166 ,F2_KEY 167 ,F3_KEY 168 ,F4_KEY 169 ,F5_KEY 170 ,F6_KEY 171 ,F7_KEY 172 ,F8_KEY 173 ,F9_KEY 174 ,F10_KEY 175 ,F11_KEY 176 ,F12_KEY 177 /* this has known value */ 178 ,MOUSE_KEY = 285 /* 0x11D */ 179 } LYExtraKeys; 180 181 /* ***** NOTES: ***** 182 If you add definitions for new lynxkeycodes to the above list that need to 183 be mapped to LYK_* lynxactioncodes - 184 185 - AT LEAST the tables keymap[] and key_override[] in LYKeymap.c have to be 186 changed/reviewed, AS WELL AS the lineedit binding tables in LYEditmap.c ! 187 188 - KEYMAP_SIZE, defined in LYKeymap.h, may need to be changed ! 189 190 - See also table named_keys[] in LYKeymap.c for 'pretty' strings for the 191 keys with codes >= 256 (to appear on the 'K'eymap page). New keycodes 192 should probably be assigned consecutively, so their key names can be 193 easily added to named_keys[] (but see next point). They should also be 194 documented in lynx.cfg. 195 196 - The DOS port uses its own native codes for some keys, unless they are 197 remapped by the code in LYgetch(). See *.key files in docs/ directory. 198 Adding new keys here may conflict with those codes (affecting DOS users), 199 unless/until remapping is added or changed in LYgetch(). (N)curses 200 keypad codes (KEY_* from curses.h) can also directly appear as 201 lynxkeycodes and conflict with our assignments, although that shouldn't 202 happen - the useful ones should be recognized in LYgetch(). 203 204 - The actual recognition of raw input keys or escape sequences, and mapping 205 to our lynxkeycodes, take place in LYgetch() and/or its subsidiary 206 functions and/or the curses/slang/etc. libraries. 207 208 The basic lynxkeycodes can appear combined with various flags in 209 higher-order bits as extended lynxkeycodes; see macros in LYKeymap.h. The 210 range of possible basic values is therefore limited, they have to be less 211 than LKC_ISLKC (even if KEYMAP_SIZE is increased). 212 */ 213 214 # define FOR_PANEL 0 /* normal screen, also LYgetch default */ 215 # define FOR_CHOICE 1 /* mouse menu */ 216 # define FOR_INPUT 2 /* form input and textarea field */ 217 # define FOR_PROMPT 3 /* string prompt editing */ 218 # define FOR_SINGLEKEY 4 /* single key prompt, confirmation */ 219 220 #ifdef USE_ALT_BINDINGS 221 /* Enable code implementing additional, mostly emacs-like, line-editing 222 functions. - kw */ 223 #define ENHANCED_LINEEDIT 224 #endif 225 226 /* FieldEditor preserves state between calls to LYDoEdit 227 */ 228 typedef struct { 229 230 int efStartX; /* Origin of edit-field */ 231 int efStartY; 232 int efWidth; /* Screen real estate for editing */ 233 234 char *efBuffer; /* the buffer which is being edited */ 235 size_t efBufInUse; /* current size of string. */ 236 size_t efBufAlloc; /* current buffer-size, excluding nul at end */ 237 size_t efBufLimit; /* buffer size limit, zero if indefinite */ 238 239 char efPadChar; /* Right padding typically ' ' or '_' */ 240 BOOL efIsMasked; /* Masked password entry flag */ 241 242 BOOL efIsDirty; /* accumulate refresh requests */ 243 BOOL efIsPanned; /* Need horizontal scroll indicator */ 244 int efDpyStart; /* Horizontal scroll offset */ 245 int efEditAt; /* Insertion point in string */ 246 int efPanMargin; /* Number of columns look-ahead/look-back */ 247 int efInputMods; /* Modifiers for next input lynxkeycode */ 248 #ifdef ENHANCED_LINEEDIT 249 int efEditMark; /* position of emacs-like mark, or -1-pos to denote 250 unactive mark. */ 251 #endif 252 253 int *efOffs2Col; /* fixups for multibyte characters */ 254 255 } FieldEditor; 256 257 /* line-edit action encoding */ 258 259 typedef enum { 260 LYE_UNKNOWN = -1 /* no binding */ 261 ,LYE_NOP = 0 /* Do Nothing */ 262 ,LYE_CHAR /* Insert printable char */ 263 ,LYE_ENTER /* Input complete, return char/lynxkeycode */ 264 ,LYE_TAB /* Input complete, return TAB */ 265 ,LYE_STOP /* Input complete, deactivate */ 266 ,LYE_ABORT /* Input cancelled */ 267 268 ,LYE_FORM_PASS /* In form fields: input complete, 269 return char / lynxkeycode; 270 Elsewhere: Do Nothing */ 271 272 ,LYE_DELN /* Delete next/curr char */ 273 ,LYE_DELC /* Obsolete (DELC case was equiv to DELN) */ 274 ,LYE_DELP /* Delete prev char */ 275 ,LYE_DELNW /* Delete next word */ 276 ,LYE_DELPW /* Delete prev word */ 277 278 ,LYE_ERASE /* Erase the line */ 279 280 ,LYE_BOL /* Go to begin of line */ 281 ,LYE_EOL /* Go to end of line */ 282 ,LYE_FORW /* Cursor forwards */ 283 ,LYE_FORW_RL /* Cursor forwards or right link */ 284 ,LYE_BACK /* Cursor backwards */ 285 ,LYE_BACK_LL /* Cursor backwards or left link */ 286 ,LYE_FORWW /* Word forward */ 287 ,LYE_BACKW /* Word back */ 288 289 ,LYE_LOWER /* Lower case the line */ 290 ,LYE_UPPER /* Upper case the line */ 291 292 ,LYE_LKCMD /* Invoke command prompt */ 293 294 ,LYE_AIX /* Hex 97 */ 295 296 ,LYE_DELBL /* Delete back to BOL */ 297 ,LYE_DELEL /* Delete thru EOL */ 298 299 ,LYE_SWMAP /* Switch input keymap */ 300 301 ,LYE_TPOS /* Transpose characters */ 302 303 ,LYE_SETM1 /* Set modifier 1 flag */ 304 ,LYE_SETM2 /* Set modifier 2 flag */ 305 ,LYE_UNMOD /* Fall back to no-modifier command */ 306 307 ,LYE_C1CHAR /* Insert C1 char if printable */ 308 309 ,LYE_SETMARK /* emacs-like set-mark-command */ 310 ,LYE_XPMARK /* emacs-like exchange-point-and-mark */ 311 ,LYE_KILLREG /* emacs-like kill-region */ 312 ,LYE_YANK /* emacs-like yank */ 313 #ifdef CAN_CUT_AND_PASTE 314 ,LYE_PASTE /* ClipBoard to Lynx */ 315 #endif 316 } LYEditCodes; 317 318 /* All preceding values must be within 0x00..0x7f - kw */ 319 320 /* The following are meant to be bitwise or-ed: */ 321 #define LYE_DF 0x80 /* Flag to set modifier 3 AND do other 322 action */ 323 #define LYE_FORM_LAC 0x1000 /* Flag to pass lynxactioncode given by 324 lower bits. Doesn't fit in a char! */ 325 326 #if defined(USE_KEYMAPS) 327 extern int lynx_initialize_keymaps(void); 328 extern int map_string_to_keysym(const char *src, int *lec, int internal); 329 #endif 330 331 extern BOOL LYRemapEditBinding(int xlkc, int lec, int select_edi); /* in LYEditmap.c */ 332 extern BOOLEAN LYRemoveNewlines(char *buffer); 333 extern BOOLEAN LYTrimStartfile(char *buffer); 334 extern LYExtraKeys LYnameToExtraKeys(const char *name); 335 extern char *LYElideString(char *str, int cut_pos); 336 extern char *LYReduceBlanks(char *buffer); 337 extern char *LYRemoveBlanks(char *buffer); 338 extern char *LYSkipBlanks(char *buffer); 339 extern char *LYSkipNonBlanks(char *buffer); 340 extern char *LYTrimNewline(char *buffer); 341 extern const char *LYSkipCBlanks(const char *buffer); 342 extern const char *LYSkipCNonBlanks(const char *buffer); 343 extern const char *LYextraKeysToName(LYExtraKeys code); 344 extern int EditBinding(int ch); /* in LYEditmap.c */ 345 extern int LYDoEdit(FieldEditor * edit, int ch, int action, int maxMessage); 346 extern int LYEditKeyForAction(int lac, int *pmodkey); /* LYEditmap.c */ 347 extern int LYKeyForEditAction(int lec); /* in LYEditmap.c */ 348 extern int LYhandlePopupList(int cur_choice, int ly, int lx, 349 STRING2PTR choices, 350 int width, 351 int i_length, 352 int disabled, 353 int for_mouse); 354 extern void LYCloseCloset(RecallType recall); 355 extern void LYEscapeStartfile(char **buffer); 356 extern void LYFinishEdit(FieldEditor * edit); 357 extern void LYLowerCase(char *buffer); 358 extern void LYRefreshEdit(FieldEditor * edit); 359 extern void LYSetupEdit(FieldEditor * edit, char *old, 360 unsigned buffer_limit, 361 int display_limit); 362 extern void LYTrimAllStartfile(char *buffer); 363 extern void LYTrimLeading(char *buffer); 364 extern void LYTrimTrailing(char *buffer); 365 extern void LYUpperCase(char *buffer); 366 367 typedef short LYEditCode; 368 369 typedef struct { 370 int code; 371 LYEditCode edit; 372 } LYEditInit; 373 374 typedef struct { 375 const char *name; 376 const LYEditInit *init; 377 LYEditCode *used; 378 } LYEditConfig; 379 380 extern int current_lineedit; 381 extern const char *LYEditorNames[]; 382 extern LYEditConfig LYLineEditors[]; 383 extern const char *LYLineeditHelpURLs[]; 384 385 #define CurrentLineEditor() LYLineEditors[current_lineedit].used 386 387 extern void LYinitEditmap(void); 388 extern void LYinitKeymap(void); 389 extern const char *LYLineeditHelpURL(void); 390 391 extern int escape_bound; 392 393 #define LYLineEdit(e,c,m) LYDoEdit(e, c, EditBinding(c) & ~LYE_DF, m) 394 395 extern int LYEditInsert(FieldEditor * edit, unsigned const char *s, 396 int len, int map_active, 397 int maxMessage); 398 399 #ifdef __cplusplus 400 } 401 #endif 402 #endif /* LYSTRINGS_H */ 403