📄 utils.c
字号:
if (quote) { if (pos > answer && (pos[-1] == '\"' || pos[-1] == '\'')) quote = FALSE; else quote = (strpbrk( name, " +;,=%" ) != NULL); } if (quote) *pos++ = '\"'; do {#if !defined( __UNIX__ ) if (*name == '/') *pos++ = '\\'; else#endif *pos++ = *name; } while (*++name); if (quote) *pos++ = '\"'; break; case 'w' : case 'W' : *pos = '\0'; rc = copy_word( window, pos, sizeof(answer) - (int)(pos - answer), (*cmd == 'W') ); if (rc == 0) case 'p' : { /* * Enter parameter for command : */ strcpy( pos, h_parm.prev->str ); rc = get_name( utils20, g_display.end_line, pos, &h_parm ); if (rc <= 0) return( ERROR ); } pos += rc; break; } } ++cmd; } *pos = '\0'; cmd = answer; capture = CB_Capture; save = !CB_Original; auto_reload = CB_Reload; } else { capture = save = FALSE; cmd = ""; } if (*cmd == '\0') { quiet = TRUE; pause = FALSE;#if defined( __UNIX__ ) if ((cmd = getenv( "SHELL" )) == NULL) cmd = "/bin/sh";#elif defined( __MSC__ ) cmd = getenv( "COMSPEC" );#elif defined( __WIN32__ ) cmd = NULL;#endif } else { quiet = CB_NEcho; pause = !CB_NPause; } if (un_copy_line( window->ll, window, TRUE, TRUE ) == ERROR) return( ERROR ); if (save) { if (save_all( window ) == ERROR) return( ERROR ); } console_suspend( ); if (!quiet) { putchar( '[' ); if (capture) putchar( OUTPUT ); fputs( "tde] ", stdout ); puts( cmd ); } if (capture) { fh1 = dup( 1 ); /* standard output */ fh2 = dup( 2 ); /* standard error */ name = tmpnam( NULL ); /* unique temporary filename */ fh = creat( name, 0200 ); /* S_IWUSR - don't make read-only */ dup2( fh, 1 ); dup2( fh, 2 ); }#if defined( __GNUC__ ) /* prevent warnings */ else { fh = fh1 = fh2 = 0; name = NULL; } out_win = NULL;#endif#if defined( __WIN32__ ) if (cmd == NULL) { /* * running "cmd /c cmd" disables history for some reason, so use spawn, * but spawn won't work with redirected input, so use CreateProcess, * which disables history if it's not redirected, so now the input handle * is always created. Weird. */ STARTUPINFO si; PROCESS_INFORMATION pi; memset( &si, 0, sizeof(si) ); si.cb = sizeof(si); if (CreateProcess( NULL, getenv( "COMSPEC" ), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) WaitForSingleObject( pi.hProcess, INFINITE ); } else#endif system( cmd ); if (capture) { close( fh ); dup2( fh1, 1 ); dup2( fh2, 2 ); close( fh1 ); close( fh2 ); } console_resume( pause ); if (g_display.adapter != MDA) set_overscan_color( Color( Overscan ) ); redraw_screen( window );#if defined( __MSDOS__ ) /* * Restore the correct cwd, since DOS maintains it globally (UNIX and * Win32 maintain it per-process, so it's not needed there). */ set_path( window );#endif output_reloaded = FALSE; old_reload = auto_reload; for (fp = g_status.file_list; fp != NULL; fp = fp->next) { if (*fp->file_name == '\0') { rc = FALSE; if (capture && !output_reloaded) { if (strcmp( fp->file_name + 2, cmd ) == 0) { output_reloaded = rc = TRUE; strcpy( fp->file_name, name ); old_reload = auto_reload; auto_reload = TRUE; } } } else if (get_ftime( fp->file_name, &ftime ) == OK) {#if defined( __WIN32__ ) rc = (CompareFileTime( &ftime, &fp->ftime ) != 0);#else rc = (ftime != fp->ftime);#endif } else rc = FALSE; if (rc) { win = find_file_window( fp ); rc = reload_file( win ); if (output_reloaded == TRUE) { ++output_reloaded; auto_reload = old_reload; fp->file_attrib = 0; fp->file_name[0] = '\0'; fp->file_name[1] = OUTPUT; strcpy( fp->file_name + 2, cmd ); out_win = win; if (rc == OK) unlink( name ); } } } auto_reload = FALSE; if (capture) { if (output_reloaded) change_window( window, out_win ); else if (attempt_edit_display( name, LOCAL ) == OK) { unlink( name ); g_status.current_file->scratch = -1; g_status.current_file->file_attrib = 0; g_status.current_file->file_name[0] = '\0'; g_status.current_file->file_name[1] = OUTPUT; strcpy( g_status.current_file->file_name + 2, cmd ); show_window_fname( g_status.current_window ); } } return( OK );}/* * Name: exec_proc * Purpose: dialog callback for Execute * Author: Jason Hood * Date: November 30, 2003 * Notes: turning on Capture will turn on and disable No pause; * a blank command will turn on and disable No echo and No pause. */int exec_proc( int id, char *text ){static int necho = ERROR; /* remember the old echo state */static int npause = ERROR; /* remember the old pause state */ if (id == -IDE_COMMAND) { if (*text == '\0') { if (necho == ERROR) { necho = CB_NEcho; if (!necho) check_box( IDC_NECHO ); check_box_enabled( IDC_NECHO, FALSE ); } if (npause == ERROR) { npause = CB_NPause; if (!npause) check_box( IDC_NPAUSE ); check_box_enabled( IDC_NPAUSE, FALSE ); } } else { check_box_enabled( IDC_NECHO, TRUE ); if (necho == FALSE) check_box( IDC_NECHO ); necho = ERROR; if (!CB_Capture) { check_box_enabled( IDC_NPAUSE, TRUE ); if (npause == FALSE) check_box( IDC_NPAUSE ); npause = ERROR; } } } else if (id == IDC_CAPTURE) { if (necho == ERROR) { /* empty command will have already done pause */ if (CB_Capture) { npause = CB_NPause; if (!npause) check_box( IDC_NPAUSE ); check_box_enabled( IDC_NPAUSE, FALSE ); } else if (npause != ERROR) { check_box_enabled( IDC_NPAUSE, TRUE ); if (!npause) check_box( IDC_NPAUSE ); npause = ERROR; } } } return( OK );}/* Name: user_screen * Purpose: to display the screen prior to running TDE, or from the shell * Author: Jason Hood * Date: December 28, 1996 * Passed: window: pointer to current window * Notes: DOS only * jmh 990418: added Linux version * jmh 031125: restore overscan color */int user_screen( TDE_WIN *window ){ page( 0 ); if (g_display.adapter != MDA) set_overscan_color( g_display.old_overscan ); getkey( );#if defined( __UNIX__ ) redraw_screen( window );#else page( 1 );# if defined( __WIN32__ ) show_window_fname( window );# endif#endif if (g_display.adapter != MDA) set_overscan_color( Color( Overscan ) ); return( OK );}static void create_stat( const char *, char *, char [][STAT_WIDTH+1], char [], int );/* * Name: show_status * Purpose: display markers, block and break point settings * Author: Jason Hood * Date: April 10, 1999 * Passed: window: pointer to current window * Notes: write to a temporary buffer first to find the largest string, * then write them centered in the status_screen. * * 990425: display filename. * 990503: display file size and size in memory (not including window or * syntax info, but including file info). * 991021: create the screen in memory, using frame style. * Assumes no line will be greater than STAT_WIDTH (other than the * filename). * 991028: Corrected errors I introduced above. * 991111: Display line ending in brackets after file size. * 991120: Display "(pipe)" when appropriate. * 991126: Include window info. * 010605: Moved sizes to show_statistics(); * added syntax highlighting info. * 030226: Display "(scratch)" when appropriate. * 030320: Added file time and current time, using a different format. */int show_status( TDE_WIN *window ){char buf[STAT_COUNT+1][STAT_WIDTH+1];char blen[STAT_COUNT+1];int len;file_infos *file = window->file_info;int j;int o = 0;long lines; memset( blen, 0, sizeof(blen) ); blen[STAT_PREV] = sprintf( buf[STAT_PREV], status1b[file->marker[0].marked], file->marker[0].rline, file->marker[0].rcol+1 ); for (j = 1; j < NO_MARKERS; ++j) { blen[STAT_MARK+j] = sprintf( buf[STAT_MARK+j], status1a[file->marker[j].marked], j, file->marker[j].rline, file->marker[j].rcol+1 ); } if (!g_status.marked) blen[STAT_BLOCK] = sprintf( buf[STAT_BLOCK], status2[0] ); else if (g_status.marked_file != file) blen[STAT_BLOCK] = sprintf( buf[STAT_BLOCK], status2[5], status_block[g_status.marked_file->block_type] ); else { if (file->block_type == LINE) len = sprintf( buf[STAT_BLOCK], status2[LINE], file->block_br, file->block_er ); else /* file->block_type == BOX or STREAM */ len = sprintf( buf[STAT_BLOCK], status2[file->block_type + (file->block_ec == -1)], status_block[file->block_type], file->block_br, file->block_bc+1, file->block_er, file->block_ec+1 ); blen[STAT_BLOCK] = len; len = 0; lines = file->block_er - file->block_br + (file->block_type != STREAM); if (file->block_type == BOX) { j = file->block_ec - file->block_bc + 1; if (j != 1 || lines != 1) len = sprintf( buf[STAT_BLOCK+1], status2b[0], lines, status2a[lines == 1], j, status2a[2 + (j == 1)] ); } else if (lines > 1) /* && file->block_type == LINE or STREAM */ len = sprintf( buf[STAT_BLOCK+1], status2b[1], lines ); if (len) { blen[STAT_BLOCK+1] = len; o = 1; } else buf[STAT_BLOCK][(int)blen[STAT_BLOCK]++] = '.'; } blen[STAT_BREAK+o] = sprintf( buf[STAT_BREAK+o], status3[file->break_point != 0], file->break_point ); blen[STAT_LANG+o] = sprintf( buf[STAT_LANG+o], status4[file->syntax != NULL], file->syntax->name ); blen[STAT_REF+o] = sprintf( buf[STAT_REF+o], status5[file->ref_count != 1], file->ref_count ); if (*file->file_name == '\0') *buf[0] = '\0'; else format_time( stat_time, buf[0], ftime_to_tm( &file->ftime ) ); blen[STAT_FTIME+o] = sprintf( buf[STAT_FTIME+o], status6, buf[0] ); format_time( stat_time, buf[0], NULL ); blen[STAT_TIME+o] = sprintf( buf[STAT_TIME+o], status7, buf[0] ); create_stat( status0, file->file_name, buf, blen, STAT_COUNT+o ); return( OK );}/* * Name: show_statistics * Purpose: display certain statistics about the current file * Author: Jason Hood * Date: June 5, 2001 * Passed: window: pointer to current window * Notes: write to a temporary buffer first to find the largest string, * then write them centered in the stat_screen. * Include the EOF char in file size, if relevant. * * jmh 011128: modified memory calculation due to new management. * jmh 021102: fix display bug when max line length exceeds number of lines. * jmh 030329: fixed bug using wrong strings/counts. */int show_statistics( TDE_WIN *window ){char buf[STATS_COUNT][STAT_WIDTH+1];char blen[STATS_COUNT];int len;file_infos *file = window->file_info;line_list_ptr ll;text_ptr line;long llen, flen, mlen; /* line, file and memory lengths */long lines, blank; /* non-blank & blank lines */long chars, spaces, strings;long alnum, symbols, words;int line_len[3], word_len[3], string_len[3];int in_word, in_string;int sa[3], na[3];int pct[2];int j, k; if (un_copy_line( window->ll, window, TRUE, TRUE ) == ERROR) return( ERROR ); show_search_message( TALLYING ); #define STAT_LEN( stat ) \ if (stat##_len[0] < stat##_len[1])\ stat##_len[1] = stat##_len[0];\ if (stat##_len[0] > stat##_len[2])\ stat##_len[2] = stat##_len[0];\ /* * For memory size, add all the line_list_struc's and the file info. The +2 * is for the top and end of file markers; the 2+ is for length markers. */ mlen = 2+sizeof(file_infos) + 2+sizeof(TDE_WIN) + (file->length+2) * (2+sizeof(line_list_struc)); /* * Calculate the overall length of lines.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -