bagajjal 2017-01-24 10:18:42 -08:00 committed by Manoj Ampalam
parent d10d8a8f36
commit e4da8db4d2
4 changed files with 43 additions and 35 deletions

View File

@ -74,6 +74,7 @@ typedef struct _SCREEN_RECORD{
}SCREEN_RECORD,*PSCREEN_RECORD;
PSCREEN_RECORD pSavedScreenRec = NULL;
int in_raw_mode = 0;
/* ************************************************************ */
/* Function: ConInit */
@ -135,6 +136,7 @@ int ConInit( DWORD OutputHandle, BOOL fSmartInit )
if (GetConsoleScreenBufferInfo(hOutputConsole, &csbi))
SavedViewRect = csbi.srWindow;
in_raw_mode = 1;
return 0;
}
@ -147,6 +149,7 @@ int ConUnInit( void )
{
CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo;
in_raw_mode = 0;
if ( hOutputConsole == NULL )
return 0;

View File

@ -1069,15 +1069,15 @@ int start_with_pty(int ac, wchar_t **av) {
/*TODO - pick this up from system32*/
cmd[0] = L'\0';
if (ac)
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L"cmd.exe"));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L"cmd.exe"));
ac--;
av++;
if (ac)
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L" /c"));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" /c"));
while (ac) {
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L" "));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, *av));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" "));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, *av));
ac--;
av++;
}
@ -1183,14 +1183,14 @@ int start_withno_pty(int ac, wchar_t **av) {
/*TODO - pick this up from system32*/
cmd[0] = L'\0';
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L"cmd.exe"));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L"cmd.exe"));
ac -= 2;
av += 2;
if (ac)
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L" /c"));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" /c"));
while (ac) {
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, L" "));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, PATH_MAX, *av));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, L" "));
GOTO_CLEANUP_ON_ERR(wcscat_s(cmd, MAX_CMD_LEN, *av));
ac--;
av++;
}

View File

@ -6,6 +6,8 @@
#define TERM_IO_BUF_SIZE 2048
extern int in_raw_mode;
struct io_status {
DWORD to_transfer;
DWORD transferred;
@ -129,25 +131,19 @@ static DWORD WINAPI WriteThread(
DWORD dwSavedAttributes = ENABLE_PROCESSED_INPUT;
debug3("TermWrite thread, io:%p", pio);
/* decide to call parsing engine or directly write to console
* doing the following trick to decide -
* if console in handle is set to process Ctrl+C, then it is likely
* serving a PTY enabled session
*/
GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &dwSavedAttributes);
if (dwSavedAttributes & ENABLE_PROCESSED_INPUT) {
if (in_raw_mode == 0) {
/* convert stream to utf16 and dump on console */
pio->write_details.buf[write_status.to_transfer] = '\0';
wchar_t* t = utf8_to_utf16(pio->write_details.buf);
WriteConsoleW(WINHANDLE(pio), t, wcslen(t), 0, 0);
free(t);
write_status.transferred = write_status.to_transfer;
} else {
telProcessNetwork(pio->write_details.buf, write_status.to_transfer, &respbuf, &resplen);
/*TODO - respbuf is not null in some cases, this needs to be returned back via read stream*/
write_status.transferred = write_status.to_transfer;
}
} else {
/* console mode */
telProcessNetwork(pio->write_details.buf, write_status.to_transfer, &respbuf, &resplen);
/*TODO - respbuf is not null in some cases, this needs to be returned back via read stream*/
write_status.transferred = write_status.to_transfer;
}
if (0 == QueueUserAPC(WriteAPCProc, main_thread, (ULONG_PTR)pio)) {
debug("TermWrite thread - ERROR QueueUserAPC failed %d, io:%p", GetLastError(), pio);

35
sftp.c
View File

@ -296,19 +296,16 @@ help(void)
/* printf version to account for utf-8 input */
/* TODO - merge this with vfmprint */
static void printf_utf8(char *fmt, ... ) {
/* TODO - is 1024 sufficient */
char buf[1024];
wchar_t* wtmp;
va_list valist;
va_start(valist, fmt);
/* TODO - is 1024 sufficient */
char buf[1024];
int length = 0;
vsnprintf(buf, 1024, fmt, valist);
va_end(valist);
va_list valist;
va_start(valist, fmt);
length = vsnprintf(buf, 1024, fmt, valist);
va_end(valist);
if ((wtmp = utf8_to_utf16(buf)) == NULL)
fatal("unable to allocate memory");
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wtmp, wcslen(wtmp), 0, 0);
free(wtmp);
write(STDOUT_FILENO, buf, length);
}
/* override mprintf */
@ -931,11 +928,17 @@ do_ls_dir(struct sftp_conn *conn, const char *path,
#ifdef WINDOWS
/* cannot use printf_utf8 becuase of width specification */
/* printf_utf8 does not account for utf-16 based argument widths */
char *p = NULL;
wchar_t buf[1024];
wchar_t* wtmp = utf8_to_utf16(fname);
swprintf(buf, 1024, L"%-*s", colspace, wtmp);
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), buf, wcslen(buf), 0, 0);
if ((p = utf16_to_utf8(buf)) == NULL)
continue;
write(STDOUT_FILENO, p, strlen(p));
free(wtmp);
free(p);
#else
mprintf("%-*s", colspace, fname);
#endif
@ -1025,11 +1028,17 @@ do_globbed_ls(struct sftp_conn *conn, const char *path,
#ifdef WINDOWS
/* cannot use printf_utf8 becuase of width specification */
/* printf_utf8 does not account for utf-16 based argument widths */
char *p = NULL;
wchar_t buf[1024];
wchar_t* wtmp = utf8_to_utf16(fname);
swprintf(buf, 1024, L"%-*s", colspace, wtmp);
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), buf, wcslen(buf), 0, 0);
if ((p = utf16_to_utf8(buf)) == NULL)
continue;
write(STDOUT_FILENO, p, strlen(p));
free(wtmp);
free(p);
#else
mprintf("%-*s", colspace, fname);
#endif