📄 query.c
字号:
return( key );}/* * Name: get_sort_order * Purpose: To prompt the user and get sort direction * Date: June 5, 1992 * Modified: November 13, 1993, Frank Davis per Byrial Jensen * Passed: window * Returns: OK if user entered something * ERROR if user aborted the command * * jmh 980813: moved from utils.c */int get_sort_order( TDE_WIN *window ){register int c; /* * sort ascending or descending */ c = get_response( utils4, window->bottom_line, R_ALL, 2, L_ASCENDING, ASCENDING, L_DESCENDING, DESCENDING ); if (c != ERROR) { sort.direction = c; c = OK; } return( c );}/* * Name: add_to_history * Purpose: add a string to a history list * Author: Jason Hood * Date: April 24, 1999 * Passed: str: string to add * hist: history to add it to * Returns: nothing * Notes: if the string already exists, move it to the end. The comparison * is case sensitive. * Silently fail if there's no memory. * 991028: don't add "=" to file history. */void add_to_history( char *str, HISTORY *hist ){HISTORY* h;int len;int rc = OK; if (hist == NULL || str == NULL || *str == '\0') return; len = strlen( str ); if (hist == &h_file && *str == '=' && len == 1) return; for (h = hist->prev; h != hist; h = h->prev) { if (h->len == len && strcmp( h->str, str ) == 0) break; } if (h == hist) { h = my_malloc( sizeof(HISTORY) + len, &rc ); if (rc == ERROR) return; strcpy( h->str, str ); h->len = len; } else { h->prev->next = h->next; h->next->prev = h->prev; } h->prev = hist->prev; h->next = hist; hist->prev->next = h; hist->prev = h;}/* * Name: search_history * Purpose: search the history for a matching prefix * Author: Jason Hood * Date: October 29, 2002 * Passed: prefix: the prefix to match * len: the length of the prefix * hist: the history to search * h: the current position within history * dir: TRUE to search forwards * Returns: pointer to history line, or NULL if no match * Notes: uses the current search case to perform the comparison * * 031213: fixed not matching the start item if it's the only. */static HISTORY *search_history( char *prefix, int len, HISTORY *hist, HISTORY *h, int dir ){HISTORY *start = h;int rc = 1; do { h = (dir) ? h->next : h->prev; rc = my_memcmp( (text_ptr)prefix, (text_ptr)h->str, len ); } while (rc != 0 && h != start); if (rc == 0) return( h ); return( NULL );}/* * Name: do_dialog * Purpose: process a dialog box * Author: Jason Hood * Date: November 15, 2003 * Passed: dlg: the dialog to process * Returns: OK: accept values * ERROR: ignore values * Notes: cancelling the dialog does NOT restore the original values. */int do_dialog( DIALOG* dlg, DLG_PROC proc ){char answer[PATH_MAX];Char *buffer;int rc; dlg_active = TRUE; init_dialog( dlg ); dlg_proc = proc; dlg_tab = (first_edit != last_edit); dlg_id = dlg->n; if (dlg_id < first_edit || dlg_id > last_edit) dlg_id = first_edit; g_display.output_space = g_display.frame_space; buffer = malloc( (dlg->x + 4) * (dlg->y + 1) * sizeof(Char) ); if (buffer != NULL) save_area( buffer, dlg->x, dlg->y, dlg_row, dlg_col ); g_display.output_space = FALSE; while (TRUE) { if (dlg[dlg_id].text != NULL) strcpy( answer, dlg[dlg_id].text ); else *answer = '\0'; hlight_label( dlg_id, TRUE ); rc = get_string( dlg_col + dlg[dlg_id].x, dlg_row + dlg[dlg_id].y, dlg[dlg_id].n, Color( Dialog ), '_', answer, dlg[dlg_id].hist ); if (rc == ERROR) break; rc = set_dlg_text( dlg + dlg_id, answer ); if (rc == ERROR) { error( WARNING, g_display.end_line, main4 ); break; } if (dlg_move == 0) { if (dlg_proc) { rc = dlg_proc( 0, NULL ); if (rc != OK) { if (rc != ERROR) dlg_id = rc; continue; } } break; } hlight_label( dlg_id, FALSE ); dlg_id += dlg_move; if (dlg_id > last_edit) dlg_id = first_edit; else if (dlg_id < first_edit) dlg_id = last_edit; dlg->n = dlg_id; } dlg_tab = FALSE; dlg_move = 0; dlg_proc = NULL; if (buffer != NULL) { g_display.output_space = g_display.frame_space; restore_area( buffer, dlg->x, dlg->y, dlg_row, dlg_col ); g_display.output_space = FALSE; free( buffer ); } else { if (g_status.current_window != NULL) redraw_screen( g_status.current_window ); } dlg_active = FALSE; return( rc );}/* * Name: check_box * Purpose: process a check box in the current dialog * Author: Jason Hood * Date: November 15, 2003 * Passed: id: number of the check box to process * Returns: FALSE if check box is disabled, TRUE otherwise. */int check_box( int id ){DIALOG *cb; cb = current_dlg + id; if (cb->hist == NULL) { cb->n = !cb->n; if (dlg_drawn) c_output( (cb->n) ? CHECK : ' ', dlg_col + cb->x + 4, dlg_row + cb->y, Color( Dialog ) ); } return( cb->hist == NULL );}/* * Name: check_box_enabled * Purpose: enable or disable a check box * Author: Jason Hood * Date: November 30, 2003 * Passed: id: number of the check box * state: TRUE to enable, FALSE to disable */void check_box_enabled( int id, int state ){DIALOG *cb; cb = current_dlg + id; cb->hist = (state) ? NULL : (HISTORY*)ERROR; if (dlg_drawn) hlight_line( dlg_col + cb->x, dlg_row + cb->y, 7 + strlen( cb->text ), (state) ? Color( Dialog ) : Color( Disabled ) );}/* * Name: init_dialog * Purpose: initialise local global dialog variables * Author: Jason Hood * Date: November 15, 2003 * Passed: dlg: dialog to initialise * Notes: in a macro, reset all check boxes and set focus to the first edit * field, to ensure consistency, unless UsesDialog flag is used. */static void init_dialog( DIALOG *dlg ){int macro;int j; current_dlg = dlg; macro = (mode.record || (g_status.macro_executing && (!(g_status.current_macro->flag & USESDIALOG) && g_status.current_macro->len != 1))); if (macro) dlg->n = 0; first_edit = last_edit = 0; first_cbox = num_cbox = 0; for (j = 1; dlg[j].x != 0; ++j) { /* * count the number of check boxes and * set the index of the first */ if (dlg[j].n == FALSE || dlg[j].n == TRUE) { if (++num_cbox == 1) first_cbox = j; if (macro) dlg[j].n = FALSE; /* * set the index of the first and last edit fields. */ } else if (dlg[j].n != ERROR) { if (first_edit == 0) first_edit = j; last_edit = j; } } dlg->n = first_edit; dlg_col = (g_display.ncols - dlg->x) / 2; dlg_row = (g_display.mode_line - dlg->y) / 2; if (dlg_col < 0) dlg_col = 0; if (dlg_row < 0) dlg_row = 0; dlg_drawn = FALSE;}/* * Name: display_dialog * Purpose: display the current dialog * Author: Jason Hood * Date: November 15, 2003 * Passed: nothing, but uses local globals */static void display_dialog( void ){int x, y, n;char *t;int w, c;int j, sel;char line[MAX_COLS]; if (dlg_drawn) return; create_frame( current_dlg->x, current_dlg->y, 0, NULL, dlg_col, dlg_row ); sel = (first_edit == last_edit) ? 0 : current_dlg->n + first_edit - last_edit - 1; for (j = 1; current_dlg[j].x != 0; ++j) { x = dlg_col + current_dlg[j].x; y = dlg_row + current_dlg[j].y; t = current_dlg[j].text; n = current_dlg[j].n; if (n == ERROR) s_output( t, y, x, (j == sel) ? Color( EditLabel ) : Color( Dialog ) ); else if (n == FALSE || n == TRUE) { sprintf( line, "F%d [%c] %s", j-first_cbox+1, (n) ? CHECK : ' ', t ); s_output( line, y, x, (current_dlg[j].hist == NULL) ? Color( Dialog ) : Color( Disabled ) ); } else { if (t != NULL) { w = strlen( t ); if (w > n) { w = n; c = t[w]; t[w] = '\0'; } else c = '\0'; s_output( t, y, x, Color( Message ) ); t[w] = c; x += w; w = n - w; } else w = n; c_repeat( '_', w, x, y, Color( Dialog ) ); } } dlg_drawn = TRUE;}/* * Name: hlight_label * Purpose: change the color of a dialog's label * Author: Jason Hood * Date: August 17, 2005 * Passed: id: number of the edit field * sel: TRUE if id is the selected edit field * Notes: init_dialog should have been called first. * don't highlight if there's only one edit field. */static void hlight_label( int id, int sel ){ if (dlg_drawn && first_edit != last_edit) { id += first_edit - last_edit - 1; if (current_dlg[id].n == ERROR) hlight_line( dlg_col + current_dlg[id].x, dlg_row + current_dlg[id].y, strlen( current_dlg[id].text ), (sel) ? Color( EditLabel ) : Color( Dialog ) ); }}/* * Name: set_dlg_text * Purpose: set the text of a dialog's edit field * Author: Jason Hood * Date: November 15, 2003 * Passed: edit: the field to set * text: the text * Returns: OK if set, ERROR if out of memory */int set_dlg_text( DIALOG *edit, const char *text ){char *temp;int len;int rc = OK; len = strlen( text ); if (len == 0) { if (edit->text != NULL) *edit->text = '\0'; } else { temp = my_realloc( edit->text, len + 1, &rc ); if (len != ERROR) { strcpy( temp, text ); edit->text = temp; } } return( rc );}/* * Name: get_dlg_text * Purpose: retrieve the text of an edit field * Author: Jason Hood * Date: November 15, 2003 * Passed: edit: the field to get * Returns: the text */char *get_dlg_text( DIALOG *edit ){ return( (edit->text == NULL) ? "" : edit->text );}/* * Name: set_dlg_num * Purpose: set a dialog's edit field to a number * Author: Jason Hood * Date: November 15, 2003 * Passed: edit: the field to set * num: the number * Returns: OK if set, ERROR if out of memory */int set_dlg_num( DIALOG *edit, long num ){char str[12]; return( set_dlg_text( edit, my_ltoa( num, str, 10 ) ) );}/* * Name: get_dlg_num * Purpose: get a dialog's edit field as a number * Author: Jason Hood * Date: November 15, 2003 * Passed: edit: the field to get * Returns: the number * Notes: invalid numbers will return 0 */long get_dlg_num( DIALOG *edit ){ return( (edit->text == NULL) ? 0 : atol( edit->text ) );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -