📄 macro.c
字号:
branch = search_tree( key, key_tree.left ); if (branch != NULL) mac = branch->macro; } return( mac );}/* * Name: add_branch * Purpose: add a branch to the tree * Author: Jason Hood * Date: July 29, 1998 * Passed: branch: pointer to branch to be added * tree: pointer to tree to add it * Notes: assumes tree is not NULL. */void add_branch( TREE *branch, TREE *tree ){TREE **new_branch = &tree; do new_branch = (branch->key < (*new_branch)->key) ? &(*new_branch)->left : &(*new_branch)->right; while (*new_branch != NULL); *new_branch = branch;}/* * Name: record_key * Purpose: save keystrokes in keystroke buffer * Date: April 1, 1992 * Passed: key: key to record * func: function of key * Notes: rewritten by Jason Hood, July 17, 1998. * jmh 980722: add a bit of "intelligence" - don't record a null function key * and test for backspacing over a character. * jmh 980726: use the bottom line of current window to display an error. * jmh 980809: don't record the Help function. * jmh 980826: when possible, store the function rather than the key. * don't record the PullDown function. */void record_key( long key, int func ){MACRO *mac; if (mode.record == TRUE && (func != 0 || key < 256) && func != RecordMacro && func != SaveMacro && func != ClearAllMacros && func != LoadMacro && func != Help && func != PullDown) { mac = g_status.rec_macro; if (func == BackSpace && mac->len > 0 && mac->key.keys[mac->len-1] < 256) show_avail_strokes( +1 ); else if (g_status.stroke_count == 0) /* * no more room in recording buffer */ error( WARNING, g_status.current_window->bottom_line, main13 ); else { mac->key.keys[mac->len] = (func == 0 || func == PlayBack) ? key : (func | _FUNCTION); show_avail_strokes( -1 ); } }}/* * Name: show_avail_strokes * Purpose: show available free key strokes in lite bar at bottom of screen * Date: April 1, 1992 * jmh 980722: update the macro length and stroke count according to update. * jmh 981129: moved it back one position. */void show_avail_strokes( int update ){ g_status.rec_macro->len -= update; g_status.stroke_count += update; s_output( main16, g_display.mode_line, 32, Color( Mode ) ); n_output( g_status.stroke_count, 0, 50, g_display.mode_line, Color( Mode ) );}/* * Name: save_strokes * Purpose: save strokes to a file * Date: November 13, 1993 * Passed: window: pointer to current window * Notes: rewritten by Jason Hood, July 17, 1998 * This is just basically a config file. Search the config defs * for the appropriate string. * If syntax highlighting is on just write the language macros, * otherwise write the global macros. * jmh 980723: provide a default filename. * jmh 980821: create an array of key strings and function names. * jmh 020904: the key strings have been defined in cfgfile.c. * jmh 020923: likewise the function strings. */int save_strokes( TDE_WIN *window ){FILE *fp; /* file to be written */register int rc;int prompt_line;char answer[PATH_MAX+2];int key;TREE *tree;int i, j; prompt_line = window->bottom_line; /* * Supply a default name - either the language or "global". */ if (window->syntax) {#if defined( __UNIX__ ) || defined( __WIN32__ ) join_strings( answer, window->file_info->syntax->name, ".tdm" );#else key = strlen( window->file_info->syntax->name );#if defined( __DJGPP__ ) if (!_USE_LFN)#endif if (key > 8) key = 8; memcpy( answer, window->file_info->syntax->name, key ); strcpy( answer+key, ".tdm" );#endif } else strcpy( answer, "global.tdm" ); /* * name for macro file */ if ((rc = get_name( main19, prompt_line, answer, &h_file )) > 0) { /* * make sure it is OK to overwrite any existing file */ rc = file_exists( answer ); if (rc == SUBDIRECTORY) rc = ERROR; else if (rc == OK || rc == READ_ONLY) { /* * overwrite existing file? */ if (get_yn( utils10, prompt_line, R_PROMPT | R_ABORT ) != A_YES || change_mode( answer, prompt_line ) == ERROR) rc = ERROR; } else /* * file name does not exist. take a chance on a valid file name. */ rc = OK; if (rc != ERROR) { if ((fp = fopen( answer, "w" )) != NULL) { format_time( main20c, answer, NULL ); if (!window->syntax) { fprintf( fp, main20a, answer ); for (j = 0; j < MODIFIERS; ++j) { key = 256 | (j << 9); for (i = 0; i < MAX_KEYS; ++i) { if (macro[j][i] != NULL) { fprintf( fp, "%s %s", key_name( i | key, answer ), func_str[PlayBack] ); write_macro( fp, macro[j][i], i | key ); } } } tree = &key_tree; } else { fprintf( fp, main20b, window->file_info->syntax->name, answer ); tree = &window->file_info->syntax->key_tree; } write_pseudomacro( fp, tree->left ); write_twokeymacro( fp, tree->right ); fclose( fp ); } } } return( OK );}/* * Name: write_macro * Purpose: write a macro structure to a file (helper function) * Author: Jason Hood * Date: July 17, 1998 * Passed: file: pointer to file structure * macro: pointer to macro to be written * mkey: key of macro * Notes: if the macro is only one character, write it on the same line; * otherwise use separate lines with two-space indentation. * * 050709: recognise recursive definitions. * 051222: write a literal on the same line as its presumed function; * split literals at "\n". */void write_macro( FILE *file, MACRO *macro, long mkey ){int j;long key;int func;int literal = FALSE;int function = FALSE;char str[KEY_STR_MAX];char ch; if (macro->len == 1) { key = macro->key.key; if (key < 256) { fprintf( file, " \"%c\"\n\n", (int)key ); return; } } if (macro->mode[0] == FALSE) fputs( " Overwrite", file ); if (macro->mode[1] == FALSE) fputs( " FixedTabs", file ); if (macro->mode[2] == FALSE) fputs( " NoIndent", file ); if (macro->flag & WRAP) fputs( " Wrap", file ); if (macro->flag & NOWRAP) fputs( " NoWrap", file ); if (macro->flag & NOWARN) fputs( " NoWarn", file ); if ((macro->flag & NEEDBLOCK) == NEEDBLOCK) fputs( " NeedBlock", file ); else { if (macro->flag & NEEDBOX) fputs( " NeedBox", file ); if (macro->flag & NEEDLINE) fputs( " NeedLine", file ); if (macro->flag & NEEDSTREAM) fputs( " NeedStream", file ); } if (macro->flag & USESBLOCK) fputs( " UsesBlock", file ); if (macro->flag & USESDIALOG) fputs( " UsesDialog", file ); for (j = 0; j < macro->len; ++j) { key = (macro->len == 1) ? macro->key.key : macro->key.keys[j]; if (key == mkey && !literal) { /* why a recursive pseudomacro? */ fputs( "\nPlayBack\n\n", file ); /* func_str is Macro */ return; /* must be last */ } if (key < 256) { if (!literal) { if (function) fputc( ' ', file ); else fputs( "\n ", file ); fputc( '\"', file ); literal = TRUE; function = FALSE; } fputc( (int)key, file ); if ((int)key == '\\' || (int)key == '\"') fputc( (int)key, file ); } else { func = getfunc( key ); if (literal) { ch = '\"'; switch (func) { case BackSpace : ch = MAC_BackSpace; break; case CharLeft : ch = MAC_CharLeft; break; case CharRight : ch = MAC_CharRight; break; case Rturn : ch = MAC_Rturn; break; case PseudoMacro : ch = MAC_Pseudo; break; case Tab : ch = MAC_Tab; break; case MacroMark : ch = '0'; break; case SetMark1 : ch = '1'; break; case SetMark2 : ch = '2'; break; case SetMark3 : ch = '3'; break; } if (ch != '\"') fputc( '\\', file ); else literal = FALSE; fputc( ch, file ); if (ch == MAC_Rturn) { fputc( '\"', file ); literal = FALSE; function = FALSE; continue; } if (literal) continue; } fputs( "\n ", file ); if (key & _FUNCTION) fputs( func_str[func], file ); else fputs( key_name( key, str ), file ); function = TRUE; } } if (literal) fputc( '\"', file ); fprintf( file, "\n%s\n\n", func_str[RecordMacro] );}/* * Name: write_pseudomacro * Purpose: write the list of pseudo-macros to file * Author: Jason Hood * Date: July 17, 1998 * Passed: file: pointer to file being written * pmacro: pointer to pseudo-macro being written * Notes: recursive function traverses the tree, writing macros * in order, smallest first. * 020819: remove tail recursion. * 050709: recognise semicolon and quote. */void write_pseudomacro( FILE *file, TREE *pmacro ){int t1, t2; while (pmacro != NULL) { write_pseudomacro( file, pmacro->left ); if (pmacro->macro != NULL) { fputs( func_str[PseudoMacro], file ); fputc( ' ', file ); t1 = (int)pmacro->key >> 8; t2 = (int)pmacro->key & 0xff; if (t1 == '\"' || t2 == '\"') { fputc( '\"', file ); if (t1 == '\"') fputs( "\"\"", file ); else fputc( t1, file ); if (t2 == '\"') fputs( "\"\"", file ); else fputc( t2, file ); fputc( '\"', file ); } else if (t1 == ';' || t2 == ';') fprintf( file, "\"%c%c\"", t1, t2 ); else fprintf( file, "%c%c", t1, t2 ); write_macro( file, pmacro->macro, pmacro->key ); } pmacro = pmacro->right; }}/* * Name: write_twokeymacro * Purpose: write the list of two-key macros to file * Author: Jason Hood * Date: July 29, 1998 * Passed: file: pointer to file being written * twokey: pointer to two-key macro being written * Notes: recursive function traverses the tree, writing macros * in order, smallest first. * 020819: remove tail recursion. */void write_twokeymacro( FILE *file, TREE *twokey ){char buf[KEY_STR_MAX];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -