📄 query.c
字号:
*/ cp = answer + len; break; case LineUp: case LineDown: /* * move through the history */ if (hist != NULL) { do h = (func == LineUp) ? h->prev : h->next; while (strcmp( answer, h->str ) == 0 && h != hist); strcpy( answer, h->str ); dlen = len; len = h->len; DLEN( len ); old_cp = cp = answer + len; col = scol + len; disp = answer; dcol = scol; } break; case Tab: case BackTab: /* * filename completion */ if (hist == &h_file || hist == &h_exec) { if (complete == TRUE + 1) { complete = TRUE + 2; join_strings( answer + stem, cname, "*" ); ftype = my_findfirst( answer, &dta, MATCH_DIRS ); } else if (complete) ftype = my_findnext( &dta ); else { complete = TRUE; for (stem = len - 1; stem >= 0 && answer[stem] != '/'#if !defined( __UNIX__ ) && answer[stem] != '\\' && answer[stem] != ':'#endif ; --stem) ; ++stem; strcpy( cname, answer + stem ); if (!is_pattern( cname )) { *(answer + len) = '*'; *(answer + len + 1) = '\0'; ftype = my_findfirst( answer, &dta, MATCH_DIRS ); if (ftype != NULL) { prefix = strlen( ftype->fname ); strcpy( cname, ftype->fname ); for (; (ftype = my_findnext( &dta )) != NULL; ) { for (i = 0; i < prefix; ++i) {#if defined( __UNIX__ ) if (ftype->fname[i] != cname[i])#else if (bj_tolower( ftype->fname[i] ) != bj_tolower( cname[i] ))#endif break; } complete = TRUE + 1; cname[prefix = i] = '\0'; } } } else ftype = my_findfirst( answer, &dta, MATCH_DIRS ); } if (ftype == NULL) { strcpy( answer + stem, cname ); if (complete != TRUE + 1) --complete; } else strcpy( answer + stem, ftype->fname ); dlen = len; len = strlen( answer ); DLEN( len ); old_cp = cp = answer + len; col = scol + len; disp = answer; dcol = scol; } else if (dlg_tab) { dlg_move = (func == Tab) ? 1 : -1; goto done; } break; case ScrollUpLine: case ScrollDnLine: if (hist != NULL) { /* * Complete the current answer from the history. * Only complete up to the current position, not the * entire string. */ HISTORY *find = search_history( answer, pos, hist, h, (func == ScrollDnLine) ); if (find != NULL) { h = find; strcpy( answer, h->str ); if (mode.search_case == IGNORE) { dlen = len; len = h->len; DLEN( len ); disp = cp - (col - scol); dcol = scol; } else { dlen = len - pos; len = h->len; DLEN( len - pos ); disp = cp; dcol = col; } } } break; default : if (c < 0x100) { /* * insert character at cursor */ if (first) { /* * delete previous answer */ old_cp = cp = answer; *cp = '\0'; dlen = len; len = 0; pos = 0; col = scol; } /* * insert new character */ if (len < max) { if (*cp == '\0') { ++len; *(answer + len) = '\0'; } else if (mode.insert) { for (p = answer+len; p >= cp; p--) *(p+1) = *p; ++len; DLEN( len - pos ); } *cp = (char)c; DLEN( 1 ); disp = cp++; dcol = col; } } break; } if (func != Pause) first = FALSE; if (func != Tab) complete = FALSE; } if (displayed && paused) show_modes( ); if (ftype != NULL) my_findclose( &dta ); return( func == AbortCommand ? ERROR : len );}static unsigned char *sid; /* syntax identifier */static int isnotid( int c ){ return( !(sid[(unsigned char)c] & ID_INWORD) );}/* * Name: copy_word * Purpose: Copy a word from the current window into a buffer * Author: Jason Hood * Date: July 31, 1998 * Passed: window: current window * buffer: buffer to store word * len: length of buffer * str: non-zero to copy a string * Returns: number of characters copied. * Notes: uses the mode.insert flag. * If the current window is not on a word, does nothing. * Expects buffer to be zero-terminated, but does not leave * the new buffer zero-terminated. * jmh 990421: correct beyond eol bug. * jmh 991126: use the line buffer, if appropriate. * jmh 050711: use syntax highlighting's inword if copying a word. */int copy_word( TDE_WIN *window, char *buffer, int len, int str ){text_ptr line = window->ll->line;int llen = window->ll->len;int rcol;int (*space)( int ); /* Function to determine what a word is */int end; if (llen == EOF) return( 0 ); if (g_status.copied && window->ll == g_status.buff_node) { line = g_status.line_buff; llen = g_status.line_buff_len; } rcol = window->rcol; if (window->file_info->inflate_tabs) rcol = entab_adjust_rcol( line, llen, rcol, window->file_info->ptab_size ); if (rcol >= llen) return( 0 ); if (!str && window->syntax) { sid = window->file_info->syntax->info->identifier; space = isnotid; } else space = (str) ? bj_isspc : myiswhitespc; if (space( line[rcol] )) return( 0 ); end = rcol; while (--rcol >= 0 && !space( line[rcol] )) ; ++rcol; while (++end < llen && !space( line[end] )) ; llen = end - rcol; end = (mode.insert) ? strlen( buffer ) : 0; if (llen > len - end) llen = len - end; if (mode.insert) memmove( buffer + llen, buffer, end ); my_memcpy( (text_ptr)buffer, line + rcol, llen ); return( llen );}#if defined( __DJGPP__ ) || defined( __WIN32__ )/* * Name: copy_clipboard * Purpose: Copy the clipboard into a buffer * Author: Jason Hood per David J Hughes * Date: October 21, 2002 * Passed: buffer: buffer to store word * len: length of buffer * Returns: number of characters copied. * Notes: only copies the first line of the clipboard. * Uses the mode.insert flag. * Expects buffer to be zero-terminated, but does not leave * the new buffer zero-terminated. */int copy_clipboard( char *buffer, int len ){char *text = get_clipboard();int clen;char *p;int end; if (text == NULL) return( 0 ); if ((p = strchr( text, '\r' )) != NULL) clen = p - text; else clen = strlen( text ); end = (mode.insert) ? strlen( buffer ) : 0; if (clen > len - end) clen = len - end; if (mode.insert) memmove( buffer + clen, buffer, end ); my_memcpy( (text_ptr)buffer, text, clen ); free( text ); return( clen );}#endif/* * Name: get_number * Purpose: prompt for a numerical value * Author: Jason Hood * Date: November 6, 2002 * Passed: prompt: prompt to offer the user * line: line to display prompt * num: default answer * hist: history to search/add answer to * Returns: num: user's answer * OK if user entered something * ERROR if user aborted the command * Notes: an empty string or invalid number returns ERROR. * if num is -1, no default is used. */int get_number( const char *prompt, int line, long *num, HISTORY *hist ){char answer[MAX_COLS];int rc; if (*num != -1) my_ltoa( *num, answer, 10 ); else *answer = '\0'; rc = get_name( prompt, line, answer, hist ); if (!bj_isdigit( *(answer + (*answer == '-')) )) rc = ERROR; if (rc != ERROR) { *num = atol( answer ); rc = OK; } return( rc );}/* * Name: get_response * Purpose: to prompt the user and wait for a key to be pressed * Date: August 13, 1998 * Author: Jason Hood * Passed: prompt: prompt to offer the user * line: line to display prompt * flag: see below * num: number of responses * let: first response letter * res: first response code * Returns: the appropriate response for the letter * Notes: prompt is displayed using set_prompt. * If prompt is NULL, no prompt is output, line has no meaning and the * R_PROMPT flag is ignored. The cursor remains unchanged. * If the flag contains R_PROMPT, the response letters are displayed * in brackets, in lower-case, separated by slashes, followed by a * colon and space. * If the flag contains R_MACRO, allow the response to be read from, * or recorded to, a macro. * If the flag contains R_DEFAULT, pressing RTURN/Rturn will accept * the first response (ie. res). * If the flag contains R_ABORT, pressing ESC/AbortCommand will cancel * the query and return ERROR. */int get_response( const char* prompt, int line, int flag, int num, int let1, int res1, ... ){long c; /* the user's response */register int rc; /* return code */int let[20]; /* twenty responses should be plenty */int res[20];char buf[MAX_COLS+2];int col = 0;int i;va_list ap;DISPLAY_BUFF; assert( num < 20 ); SAVE_LINE( line ); let[0] = let1; res[0] = res1; va_start( ap, res1 ); for (col = 1; col < num; ++col) { let[col] = bj_toupper( va_arg( ap, int ) ); res[col] = va_arg( ap, int ); } va_end( ap ); if (prompt != NULL) { col = strlen( prompt ); strcpy( buf, prompt ); if (flag & R_PROMPT) { buf[col++] = ' '; buf[col++] = '('; for (i = 0; i < num; ++i) { buf[col++] = bj_tolower( let[i] ); buf[col++] = '/'; } buf[col-1] = ')'; buf[col++] = ':'; buf[col++] = ' '; buf[col++] = '\0'; } set_prompt( buf, line ); } for (;;) { c = (flag & R_MACRO) ? getkey_macro( ) : getkey( ); rc = 0; if (c < 256) { c = bj_toupper( (int)c ); for (i = 0; i < num && let[i] != (int)c; ++i) ; if (i < num) { rc = res[i]; break; } } else { rc = (c == RTURN) ? Rturn : (c == ESC) ? AbortCommand : getfunc( c ); if (rc == Rturn && (flag & R_DEFAULT)) { rc = res1; break; } else if (rc == AbortCommand && (flag & R_ABORT)) { rc = ERROR; break; } } } RESTORE_LINE( line ); return( rc );}/* * Name: prompt_key * Purpose: display a prompt and get a key * Author: Jason Hood * Date: September 22, 2005 * Passed: prompt: the prompt to display * prompt_line: the line to display it * Returns: the key * Notes: works with macros, but will ignore the currently recording key. * doesn't display the prompt when reading from a macro. */long prompt_key( const char *prompt, int prompt_line ){DISPLAY_BUFF;int display;long key; display = (!g_status.macro_executing || (g_status.macro_next < g_status.current_macro->len && getfunc( g_status.current_macro->key.keys[g_status.macro_next] ) == Pause)); if (display) { SAVE_LINE( prompt_line ); set_prompt( prompt, prompt_line ); } for (;;) { key = getkey_macro( ); if (mode.record && key == g_status.recording_key) show_avail_strokes( +1 ); else break; } if (display) RESTORE_LINE( prompt_line );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -