📄 connect.c
字号:
break;
}
connectDlgOnHostChange(dlg);
}
/* protocol has been changed
*/
void connectDlgOnProtocolChange(HWND dlg)
{
LRESULT res;
char protocol[PROTOCOL_NAME_LEN];
res = SendDlgItemMessage(dlg, IDC_PROTOCOL, CB_GETCURSEL, 0, 0);
if (res == CB_ERR) {
return;
}
SendDlgItemMessage(dlg, IDC_PROTOCOL, CB_GETLBTEXT, (WPARAM)res, (LPARAM)(LPSTR)protocol);
EnableWindow(GetDlgItem(dlg, IDC_USER), stricmp(protocol, protocols[protoRlogin].name) == 0);
}
/* Dialog procedure for the Connect dialog
*/
BOOL CALLBACK connectDlgProc(HWND dlg,
UINT message, WPARAM wparam, LPARAM lparam)
{
switch (message) {
case WM_INITDIALOG:
/* Flag that we have created the dialog and register the
* dialog window handle.
*/
haveDialog = TRUE;
dialogRegister(dlg);
/* Initialise the dialog controls
*/
connectDlgSetVars(dlg, &dlgVars);
return TRUE;
case WM_COMMAND:
switch (LOWORD(wparam)) {
case IDOK:
/* Read all dialog controls into the current session
*/
connectDlgGetVars(dlg, &dlgVars);
/* Add the session to the history
*/
addConnectHistory();
activeHistoryIdx = 0;
/* initiate the connection.
*/
connectOpenHost();
/* Fall through and destroy dialog
*/
case IDCANCEL:
/* Destroy the dialog and unregister the dialog handle.
*/
DestroyWindow(dlg);
dialogUnRegister(dlg);
haveDialog = FALSE;
return TRUE;
case IDC_PROTOCOL:
#ifdef WIN32
if (HIWORD(wparam) != CBN_SELCHANGE)
break;
#else
if (HIWORD(lparam) != CBN_SELCHANGE)
break;
#endif
connectDlgOnProtocolChange(dlg);
break;
case IDC_PORT:
#ifdef WIN32
if (HIWORD(wparam) != EN_CHANGE)
break;
#else
if (HIWORD(lparam) != EN_CHANGE)
break;
#endif
connectDlgOnPortChange(dlg);
break;
case IDC_HOSTNAME:
#ifdef WIN32
if (HIWORD(wparam) != EN_CHANGE)
break;
#else
if (HIWORD(lparam) != EN_CHANGE)
break;
#endif
connectDlgOnHostChange(dlg);
break;
}
break;
}
return FALSE;
}
/* Display the Connect dialog
*/
void showConnectDialog(HINSTANCE instance, HWND wnd)
{
if (!haveDialog)
{
CreateDialog(instance, MAKEINTRESOURCE(IDD_CONNECT_DIALOG),
wnd, connectDlgProc);
}
}
/* Toggle the state of exit-on-disconnect
*/
void connectToggleExitOnDisconnect()
{
exitOnDisconnect = !exitOnDisconnect;
}
/* Set the target host from the command line. Do not use .INI
* settings for connections if driven via command line.
*/
void connectSetHost(const char* host)
{
strncpy(dlgVars.host, host, sizeof(dlgVars.host));
dlgVars.host[sizeof(dlgVars.host) - 1] = '\0';
}
/* Set the target port from the command line. Do not use .INI
* settings for connections if driven via command line.
*/
void connectSetPort(const char* portName)
{
strncpy(dlgVars.port, portName, sizeof(dlgVars.port));
dlgVars.port[sizeof(dlgVars.port) - 1] = '\0';
strncpy(dlgVars.protocol, portName, sizeof(dlgVars.protocol));
dlgVars.protocol[sizeof(dlgVars.protocol) - 1] = '\0';
}
/* Set the port protocol from the command line. Do not use .INI
* settings for connections if driven via command line.
*/
void connectSetProtocol(const char* protocolName)
{
strncpy(dlgVars.protocol, protocolName, sizeof(dlgVars.protocol));
dlgVars.protocol[sizeof(dlgVars.protocol) - 1] = '\0';
}
/* Set the terminal emulation from the command line. Do not use .INI
* settings for connections if driven via command line.
*/
void connectSetTerm(const char* termName)
{
strncpy(dlgVars.term, termName, sizeof(dlgVars.term));
dlgVars.term[sizeof(dlgVars.term) - 1] = '\0';
}
/* Set the remote user for rlogin from the command line. Do not use
* .INI settings for connections if driven via command line.
*/
void connectSetUser(const char* userName)
{
strncpy(dlgVars.user, userName, sizeof(dlgVars.user));
dlgVars.user[sizeof(dlgVars.user) - 1] = '\0';
}
/* Fred. Set the bs2Del option from the command line. Do not use .INI
* settings for connections if driven via command line.
*/
void connectSetBs2Del(BOOL b)
{
dlgVars.bs2Del = b;
}
void connectSetAnswerBack(const char *abackStr)
{
dlgVars.abacklen =
(short)unescape (abackStr, strlen (abackStr),
dlgVars.answerback, sizeof (dlgVars.answerback));
}
/* Use variables loaded from preset file */
void connectLoadVars(Connect *connVars){
memcpy(&dlgVars, connVars, sizeof(dlgVars));
}
/* Copy current connect dialog variables */
void connectGetVars(Connect *connVars) {
memcpy(connVars, &dlgVars, sizeof(dlgVars));
}
/* Copy default connect dialog variables */
void connectGetDefVars(Connect *connVars) {
memcpy(connVars, &defVars, sizeof(dlgVars));
}
/* Load the connection history/parameters from the .INI file
*/
void connectGetProfile()
{
int num; /* Number of sessions in .INI file */
int idx; /* Iterate over sessions */
char tmp [256];
/* if you have to reorder options, change OPTION_**** too */
/* 1 2 3 4 5 67 8 */
static const char options [] = "H:P:S:T:U:DC:(AnswerBack):";
#define OPTION_ANSWERBACK (GETOPT_LONGOPT+8)
/* Get value of exit-on-disconnect
*/
exitOnDisconnect = GetPrivateProfileInt(connectStr, exitStr, 0,
telnetIniFile());
/* Get number of sessions in the .INI file, then load them in
* reverse order.
*/
num = GetPrivateProfileInt(connectStr, numStr, 0, telnetIniFile());
for (idx = num -1; idx >= 0; --idx) {
char id[32]; /* format .INI file session-id */
char value[256]; /* formatted .INI file entry */
char* argv[32]; /* parse entry as argc/argv */
int argc; /* number of session arguments */
int c; /* iterate over argc/argv */
/* Get the next formatted session from the .INI file.
*/
sprintf(id, historyStr, idx);
GetPrivateProfileString(connectStr, id, "", value,
sizeof(value), telnetIniFile());
if (value[0] == '\0')
break;
/* Parse session into current session
*/
memset(&dlgVars, 0, sizeof(dlgVars));
strcpy(dlgVars.charset, "ANSI");
argc = getoptInit(value, argv, 32);
while ((c = getopt(argc, argv, options)) != EOF)
switch (c) {
case 'H':
strcpy(dlgVars.host, opt.optarg);
break;
case 'P':
strcpy(dlgVars.port, opt.optarg);
break;
case 'S':
strcpy(dlgVars.protocol, opt.optarg);
break;
case 'T':
strcpy(dlgVars.term, opt.optarg);
break;
case 'U':
strcpy(dlgVars.user, opt.optarg);
break;
case 'D':
/* Fred */
dlgVars.bs2Del = TRUE;
break;
case 'C':
strcpy(dlgVars.charset, opt.optarg);
break;
case OPTION_ANSWERBACK:
dlgVars.abacklen =
(short)unescape (opt.optarg, strlen (opt.optarg),
dlgVars.answerback, sizeof (dlgVars.answerback));
break;
}
/* Restore session to history
*/
if (dlgVars.host[0] != '\0'
&& dlgVars.port[0] != '\0'
&& dlgVars.term[0] != '\0')
addConnectHistory();
}
/* Get current session parameters
*/
GetPrivateProfileString(connectStr, hostStr, defVars.host, dlgVars.host,
sizeof(dlgVars.host), telnetIniFile());
GetPrivateProfileString(connectStr, portStr, defVars.port, dlgVars.port,
sizeof(dlgVars.port), telnetIniFile());
GetPrivateProfileString(connectStr, protocolStr, defVars.protocol,
dlgVars.protocol, sizeof(dlgVars.port),
telnetIniFile());
GetPrivateProfileString(connectStr, termStr, defVars.term, dlgVars.term,
sizeof(dlgVars.term), telnetIniFile());
GetPrivateProfileString(connectStr, userStr, defVars.user, dlgVars.user,
sizeof(dlgVars.user), telnetIniFile());
/* Fred */
dlgVars.bs2Del = GetPrivateProfileInt(connectStr, bs2DelStr, defVars.bs2Del,
telnetIniFile());
GetPrivateProfileString(connectStr, charsetStr, defVars.charset, dlgVars.charset,
sizeof(dlgVars.charset), telnetIniFile());
GetPrivateProfileString(connectStr, abackStr, defVars.answerback, tmp, sizeof (tmp),
telnetIniFile ());
dlgVars.abacklen = (short)unescape (tmp, strlen (tmp),
dlgVars.answerback, sizeof (dlgVars.answerback));
}
/* Save the connection history/parameters to the .INI file
*/
void connectSaveProfile()
{
char tmp [256];
char str[20]; /* format .INI file entry */
int idx; /* iterate over history */
/* Save number of history sessions
*/
sprintf(str, "%d", historySize);
WritePrivateProfileString(connectStr, numStr, str, telnetIniFile());
/* Format and save all history sessions
*/
for (idx = 0; idx < historySize; ++idx) {
char id[32], value[MAX_HISTORY_SIZE];
connectGetHistory(value, idx, FALSE);
sprintf(id, historyStr, idx);
WritePrivateProfileString(connectStr, id, value, telnetIniFile());
}
/* Save current session parameters
*/
WritePrivateProfileString(connectStr, hostStr,
dlgVars.host, telnetIniFile());
WritePrivateProfileString(connectStr, portStr,
dlgVars.port, telnetIniFile());
WritePrivateProfileString(connectStr, protocolStr,
dlgVars.protocol, telnetIniFile());
WritePrivateProfileString(connectStr, termStr,
dlgVars.term, telnetIniFile());
WritePrivateProfileString(connectStr, userStr,
dlgVars.user, telnetIniFile());
sprintf(str, "%d", exitOnDisconnect);
WritePrivateProfileString(connectStr, exitStr, str, telnetIniFile());
/* Fred */
sprintf(str, "%d", dlgVars.bs2Del);
WritePrivateProfileString(connectStr, bs2DelStr, str, telnetIniFile());
escape (dlgVars.answerback, dlgVars.abacklen, tmp, sizeof (tmp));
WritePrivateProfileString(connectStr, abackStr, tmp,
telnetIniFile());
/* Free history memory
*/
if (history != NULL) {
free(history);
history = NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -