📄 main.c
字号:
/******************* start of original comments ********************//* * Written by Douglas Thomson (1989/1990) * * This source code is released into the public domain. *//* * Name: dte - Doug's Text Editor program - hardware dependent module * Purpose: This file contains all the code that needs to be different on * different hardware. * File: hwibm.c * Author: Douglas Thomson * System: This particular version is for the IBM PC and close compatibles. * It write directly to video RAM, so it is faster than other * techniques, but will cause "snow" on most CGA cards. See the * file "hwibmcga.c" for a version that avoids snow. * The compiler is Turbo C 2.0, using one of the large data memory * models. * Date: October 10, 1989 * Notes: This module has been kept as small as possible, to facilitate * porting between different systems. *//********************* end of original comments ********************//* * These routines were rewritten for Microsoft C. They are pretty much system * dependent and pretty much Microsoft C dependent. I also renamed this file * "main.c" - easier to find the main function. * * New editor name: TDE, the Thomson-Davis Editor. * Author: Frank Davis * Date: June 5, 1991, version 1.0 * Date: July 29, 1991, version 1.1 * Date: October 5, 1991, version 1.2 * Date: January 20, 1992, version 1.3 * Date: February 17, 1992, version 1.4 * Date: April 1, 1992, version 1.5 * Date: June 5, 1992, version 2.0 * Date: October 31, 1992, version 2.1 * Date: April 1, 1993, version 2.2 * Date: June 5, 1993, version 3.0 * Date: August 29, 1993, version 3.1 * Date: November 13, 1993, version 3.2 * Date: June 5, 1994, version 4.0 * Date: December 5, 1998, version 5.0 (jmh) * * This modification of Douglas Thomson's code is released into the * public domain, Frank Davis. You may distribute it freely. */char *greatest_composer_ever = "W. A. Mozart, 1756-1791";#include "tdestr.h" /* tde types */#include "common.h"#include "define.h"#include "tdefunc.h"#if !defined( __DOS16__ ) #include <signal.h> /* unix critical errors */ #if defined( __DJGPP__ ) #define __dj_include_pc_h_ /* prevent inclusion of pc.h & it's getkey() */ #include <dos.h> #endif#else #include <dos.h> /* for renaming files */#endifvoid default_twokeys( void ); /* defined in default.c *//* * Disable globbing. Unfortunately, can't automatically do this for UNIX, so * wildcards which include directory names will bring up the file list for * each directory (TDE's globber will ignore directories). */#if defined( __DJGPP__ )#include <crt0.h>char** __crt0_glob_function( char *unused ){ return( NULL );}#elif defined( __MINGW32__ )int _CRT_glob = 0;#endif#if defined( __TURBOC__ )extern unsigned _stklen = 10240; /* 10K stack (jmh 020821) */#endifextern char *cmd_config; /* defined in config.c */extern char wksp_file[]; /* defined in file.c */extern int wksp_loaded; /* defined in file.c */char init_wd[PATH_MAX]; /* directory TDE started in (jmh 021021) *//* * Name: main * Purpose: To do any system dependent command line argument processing, * and then call the main editor function. * Date: October 10, 1989 * Passed: argc: number of command line arguments * argv: text of command line arguments * * jmh 980807: translate argv[0] to the HOME/executable directory. * jmh 010528: recognize "tdv" as "tde -v"; * test for "-?" and "--help"; * added g_status.errmsg to explain why the editor didn't start. * jmh 010605: process -v and -i directly here; * added "-i config_file" option. * jmh 020802: added "-w workspace" option. * jmh 021023: moved some stuff into the portable console_init() functions. * jmh 021024: recognise "-G?" as regx help. * jmh 040715: use TDEHOME environment variable for default file location; * have DOS also HOME, and UNIX also use executable (in the * unlikely event HOME is not defined). * jmh 050819: recognise "-??" as wildcard help and "--version". * jmh 051018: DOS/Win: assume if last arg ends in '"' it should really be '\'. */int main( int argc, char *argv[] ){char *argv0;char *home;static char path[PATH_MAX];int i;int viewer; /* * See if we were asked to display help. */ if (argc == 2) { if (strcmp( argv[1], "/?" ) == 0 || strcmp( argv[1], "-?" ) == 0 || strcmp( argv[1], "--help" ) == 0) { puts( tde_help ); return( 0 ); } if (strcmp( argv[1], "--version" ) == 0) { printf( "%.*s", (int)(strchr( tde_help, '\n') - (char *)tde_help ) + 1, tde_help ); return( 0 ); } if (stricmp( argv[1], "-g?" ) == 0 || strcmp( argv[1], "-??" ) == 0) { const char * const *help = (argv[1][1] == '?') ? wildcard_help : regx_help; for (i = 0; help[i] != NULL; ++i) puts( help[i] ); return( 0 ); } }#if defined( __WIN32__ ) /* * As recommended by the Win32 documentation. */ SetFileApisToOEM( ); GetModuleFileName( NULL, path, sizeof(path) ); argv0 = path;#else argv0 = argv[0];#endif /* * determine the name of the binary. If it starts with tdv, place the * editor in viewer mode. */ for (i = strlen( argv0 ); --i >= 0;) if (argv0[i] == '/'#if !defined( __UNIX__ ) || argv0[i] == '\\' || argv0[i] == ':'#endif ) break; ++i;#if defined( __UNIX__ ) viewer = (strncmp( argv0+i, "tdv", 3 ) == 0);#else viewer = (strnicmp( argv0+i, "tdv", 3 ) == 0);#endif home = getenv( "TDEHOME" ); if (home == NULL) home = getenv( "HOME" ); if (home != NULL) {#if !defined( __UNIX__ ) /* * check the existence of tde.cfg before using HOME in DOS/Windows. */ char cfg[PATH_MAX]; join_strings( cfg, home, "/"CONFIGFILE ); if (file_exists( cfg ) == ERROR) home = NULL; else#endif argv0 = home; } if (home == NULL) { if (i == 0) argv0[i++] = '.'; argv0[i] = '\0'; } get_full_path( argv0, path ); i = strlen( path ); if (path[i-1] != '/') { path[i] = '/'; path[i+1] = '\0'; }#if !defined( __UNIX__ ) i = strlen( argv[argc-1] ) - 1; if (argv[argc-1][i] == '"') argv[argc-1][i] = '\\';#endif g_status.arg = 1; g_status.argc = argc; g_status.argv = argv; g_status.argv[0] = path; /* * jmh 010605: process -v and -i. * jmh 020802: and -w; initialise the workspace to the directory TDE was * started in, not whatever the current dir. happens to be. * jmh 020817: fix problem with missing -w argument (just ignore it). * jmh 021024: specifying a workspace with files will auto-save it. * jmh 021031: "-w" (without a filename) will use the global workspace. */ get_full_path( WORKSPACEFILE, wksp_file ); while (g_status.arg < g_status.argc && *g_status.argv[g_status.arg] == '-') { i = g_status.argv[g_status.arg][1]; if (i != 'v' && i != 'i' && i != 'w') break; if (i == 'v') viewer = TRUE; else /* i == 'i' || i == 'w' */ { if (g_status.argv[g_status.arg][2] == 0) cmd_config = g_status.argv[++g_status.arg]; else cmd_config = g_status.argv[g_status.arg] + 2; if (i == 'w') { if (cmd_config != NULL) { get_full_path( cmd_config, wksp_file ); cmd_config = NULL; } else join_strings( wksp_file, g_status.argv[0], WORKSPACEFILE ); wksp_loaded = TRUE; } } ++g_status.arg; }#if !defined( __DOS16__ ) /* * unix signals are kinda analagous to DOS critical errors. */ signal( SIGABRT, crit_err_handler ); signal( SIGFPE, crit_err_handler ); signal( SIGILL, crit_err_handler ); signal( SIGINT, crit_err_handler ); signal( SIGSEGV, crit_err_handler );# if defined( __UNIX__ ) signal( SIGALRM, crit_err_handler ); signal( SIGCONT, crit_err_handler ); signal( SIGHUP, crit_err_handler ); signal( SIGIO, crit_err_handler ); signal( SIGPIPE, crit_err_handler ); signal( SIGPWR, crit_err_handler ); signal( SIGQUIT, crit_err_handler ); signal( SIGTERM, crit_err_handler ); signal( SIGTRAP, crit_err_handler ); signal( SIGTSTP, crit_err_handler ); signal( SIGTTIN, crit_err_handler ); signal( SIGTTOU, crit_err_handler ); signal( SIGURG, crit_err_handler ); signal( SIGUSR1, crit_err_handler ); signal( SIGUSR2, crit_err_handler ); signal( SIGVTALRM, crit_err_handler ); signal( SIGWINCH, crit_err_handler ); signal( SIGXCPU, crit_err_handler ); signal( SIGXFSZ, crit_err_handler );# elif defined( __DJGPP__ ) _go32_dpmi_lock_code( crit_err_handler, (unsigned long)crit_err_handler_end - (unsigned long)crit_err_handler );# endif#else /* defined( __DOS16__ ) */ /* * install and initialize our simple Critical Error Handler. */ install_ceh( &ceh ); CEH_OK;#endif if (initialize( ) != ERROR) { g_status.viewer_mode = viewer; editor( ); } terminate( ); if (g_status.errmsg != NULL) fprintf( stderr, "%s.\n", g_status.errmsg ); return( 0 );}/* * Name: error * Purpose: To report an error, and wait for a keypress before continuing. * Date: June 5, 1991 * Passed: kind: an indication of how serious the error was: * INFO: continue after pressing a key * WARNING: as INFO, but prefix message with "Warning: " * line: line to display message * message: string to be printed * Notes: Show user the message and wait for a key. * * jmh 980813: added INFO capability. * jmh 021031: removed FATAL. * jmh 021106: if message is too long, drop the warning/any key parts. */void error( int kind, int line, const char *message ){char buff[MAX_COLS+2]; /* somewhere to store error before printing */int len;DISPLAY_BUFF; if (g_status.macro_executing && kind == WARNING && (g_status.current_macro->flag & NOWARN)) return; len = strlen( message ) + strlen( main3 ); if (len <= g_display.ncols) { if (kind == WARNING && len + strlen( main2 ) < (size_t)g_display.ncols) /* * WARNING: message : press any key */ combine_strings( buff, main2, message, main3 ); else /* * message : press any key */ join_strings( buff, message, main3 );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -