📄 dtelnet.c
字号:
}
/* Initialise this process instance
*/
static BOOL initInstance(int cmdShow)
{
fontGetProfile();
logGetProfile();
proxyGetProfile();
printingGetProfile();
telnetWnd = CreateWindow(telnetWinClass,
telnetAppName(),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, instanceHnd, NULL);
if (!telnetWnd)
return FALSE;
if (!statusCreateWnd(instanceHnd, telnetWnd))
return FALSE;
if (!termCreateWnd(instanceHnd, telnetWnd))
return FALSE;
if (!socketInit(instanceHnd))
return FALSE;
makeHelpFileName();
initSetWindowPos(telnetWnd);
fileLoadFavorites(FILETYPE_LOAD_MENU);
ShowWindow(telnetWnd, cmdShow);
UpdateWindow(telnetWnd);
return TRUE;
}
/* Initialise the application when first instance
*/
static BOOL initApplication(void)
{
WNDCLASS wc;
if (!socketInitClass(instanceHnd))
return FALSE;
if (!termInitClass(instanceHnd))
return FALSE;
if (!statusInitClass(instanceHnd))
return FALSE;
wc.style = CS_DBLCLKS;
wc.lpfnWndProc = mainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = instanceHnd;
wc.hIcon = LoadIcon(instanceHnd, MAKEINTRESOURCE(IDR_TELNET));
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = MAKEINTRESOURCE(IDM_TELNET_MENU);
wc.lpszClassName = telnetWinClass;
return RegisterClass(&wc);
}
/* Convert a color name to ANSI color index
*
* Args:
* str - string containing color name
*
* Returns ANSI color number 0 .. 7, or -1 if no color found.
*/
static int parseColor(const char* str)
{
static char* colors[] = {
"Black", "Red", "Green", "Yellow",
"Blue", "Magenta", "Cyan", "White"
};
int idx; /* iterate over possible colors */
for (idx = 0; idx < numElem(colors); idx++)
if (stricmp(str, colors[idx]) == 0)
return idx;
return -1;
}
/* Convert color description from string to byte value for use in
* terminal emulation.
*
* Args:
* desc - color description in form FG[-BG[-bold]]
*
* Returns parsed color, or default if color if parse error.
*/
static int parseAttrib(char* desc)
{
char* fields[4]; /* split parts of color description */
int numFields; /* number of parts in color description */
int fg = GET_FG(NO_ATTRIBS); /* parsed foreground color */
int bg = GET_BG(NO_ATTRIBS); /* parsed background color */
int bold = GET_BOLD(NO_ATTRIBS); /* parsed foreground bold state */
/* Split the color description fields by delimiter '-'
*/
numFields = split(desc, '-', fields, numElem(fields));
if (numFields >= 1) {
/* Get foreground color
*/
int color = parseColor(fields[0]);
if (color >= 0)
fg = color;
}
if (numFields >= 2) {
/* Get background color
*/
int color = parseColor(fields[1]);
if (color >= 0)
bg = color;
}
if (numFields >= 3) {
/* Get foreground bold attribute
*/
if (stricmp(fields[2], "bold") == 0)
bold = BOLD;
}
return FG(fg)|BG(bg)|bold;
}
/* Program entry point
*/
int PASCAL WinMain(HINSTANCE instance, HINSTANCE prevInstance,
LPSTR cmdLine, int cmdShow)
{
MSG msg; /* current message */
char* argv[32]; /* command line arguments */
int argc; /* number of command line arguments */
int c; /* current command line argument */
int errVal; /* error value (0 in 'no error') */
BOOL haveSession = FALSE; /* true if user asks for a preset session */
Connect conn;
char* autoHost = NULL; /* host from command line */
char* autoPort = NULL; /* port from command line */
char* autoTerm = NULL; /* terminal emulation from command line */
char* replayFile = NULL; /* name of replay file from command line */
/* if you have to reorder options, change OPTION_**** too */
/* 11 1 1 */
/* 12 3 4 5 6 7 8 9 01 2 3 */
static const char options [] = "BI:G:H:P:T:U:C:R:DX:(AnswerBack):A:";
#define OPTION_ANSWERBACK (GETOPT_LONGOPT+12)
errVal = 0 ; /* 'no error' now */
/* Standard application initialisation sequence
*/
instanceHnd = instance;
if (!prevInstance)
if (!initApplication())
return FALSE;
/* 20050125.LZS: makeIniFileName moved here to let connectGetProfile work */
makeIniFileName();
/* 20041118.LZS: connect.c now requires us
* to initialize dlgVars from defVars
*/
connectGetDefVars (&conn);
connectLoadVars (&conn);
/* 20050125.LZS: connectGetProfile moved here from initInstance */
connectGetProfile();
/* Set default terminal attributes and default .INI file
*/
termSetBlankAttr(NO_ATTRIBS);
initTermSet();
/* Parse command line
*/
argc = getoptInit(cmdLine, argv, 32);
while (errVal == 0 && ((c = getopt(argc, argv, options)) != EOF) )
switch (c) {
case 'B':
/* Set binary mode
*/
rawEnableBinaryMode();
break;
case 'A':
/* Set color of blank terminal window
*/
termSetBlankAttr(parseAttrib(opt.optarg));
break;
case 'C':
/* Set server character set mode
*/
connectSetServerCharSet (opt.optarg);
break;
case 'G':
/* Set terminal window size (in characters)
*/
termSetGeometry(opt.optarg);
break;
case 'H':
/* Set host to connect to on startup
*/
autoHost = opt.optarg;
break;
case 'P':
/* Set the port to connect to on startup
*/
autoPort = opt.optarg;
break;
case 'T':
/* Set terminal type to emulate
*/
autoTerm = opt.optarg;
break;
case 'U':
/* Set username to specify when connecting to rlogin port
* on startup.
*/
connectSetUser(opt.optarg);
break;
case 'I':
/* Specify the name of the .INI file to use
*/
strncpy(iniFileName, opt.optarg, sizeof(iniFileName) - 1);
iniFileName[sizeof(iniFileName) - 1] = 0;
break;
case 'R':
/* Specify name of the log file to replay on startup
*/
replayFile = opt.optarg;
break;
case 'D':
connectSetBs2Del(TRUE);
break;
case 'X':
haveSession = fileLoadSession(opt.optarg, &conn);
break;
case OPTION_ANSWERBACK:
connectSetAnswerBack (opt.optarg);
break;
/* error */
case '?':
errVal = 1 ;
break;
}
if ( 0 == errVal ) {
if (!haveSession)
{
/* Unix compatible behaviour: telnet host [port]
*/
if (opt.optind < argc)
autoHost = argv[opt.optind++];
if (opt.optind < argc)
autoPort = argv[opt.optind++];
/* If host was specified on command line, set session parameters
*/
if (autoHost != NULL) {
connectSetHost(autoHost);
connectSetPort("telnet");
}
if (autoPort != NULL)
connectSetPort(autoPort);
if (autoTerm != NULL)
connectSetTerm(autoTerm);
}
else /* We got a session file */
{
connectLoadVars(&conn);
}
/* Initialise this application instance
*/
if (!initInstance(cmdShow))
return FALSE;
/* Replay log file if specified
*/
if (replayFile != NULL)
logReplay(replayFile);
/* Show socket status in status bar, then initiate connection if
* host specified on command line.
*/
socketShowStatus();
if ((autoHost != NULL) || haveSession)
connectOpenHost();
/* We have a slightly non-standard message loop. In all cases, we
* want to give user interface processing precedence over the
* network. To achieve this, the socket IO messages are used to
* set status indicators. When the GUI is idle (message queue is
* empty), we go back and check those indicators. It is at this
* point that the actual network IO occurs.
*/
for (;;) {
/* Get a message if one is available. If not return
* immediately so we can service the socket IO messages.
*/
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT)
break;
} else {
/* The message queue is empty. Process any pending socket
* IO. Then wait for the next message - this way we avoid
* spinning on the PeekMessage when there are no messages.
*
* For the sake of user convenience, do not perform socket
* IO when the user is performing a selection with the
* mouse.
*/
if (!termSelectInProgress())
socketProcessPending();
if (!GetMessage(&msg, NULL, 0, 0))
break;
}
/* Handle the message. First try routing the message to a
* registered dialog.
*/
if (!dialogCheckMessage(&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
/* Stop logging to log file
*/
logStop();
/* Cleanup and save profile in the .INI file
*/
socketCleanup();
connectSaveProfile();
fontSaveProfile();
logSaveProfile();
proxySaveProfile();
printingSaveProfile();
telnetDestroyTermProfiles(&emuls);
}
/* Exit the application
*/
return ( 0 == errVal ? msg.wParam : 0 ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -