1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-22 06:38:37 -05:00

Clean up scp client - re-indent to my coding style and remove

compiler warnings

[originally from svn r280]
This commit is contained in:
Simon Tatham 1999-11-08 11:22:45 +00:00
parent 7809b519d5
commit 3c9b8bff57
2 changed files with 592 additions and 610 deletions

34
scp.c
View File

@ -6,7 +6,6 @@
* They, in turn, used stuff from BSD rcp. * They, in turn, used stuff from BSD rcp.
*/ */
#include <windows.h> #include <windows.h>
#include <winsock.h> #include <winsock.h>
#include <stdlib.h> #include <stdlib.h>
@ -18,13 +17,11 @@
#include "putty.h" #include "putty.h"
#include "scp.h" #include "scp.h"
#define TIME_POSIX_TO_WIN(t, ft) (*(LONGLONG*)&(ft) = \ #define TIME_POSIX_TO_WIN(t, ft) (*(LONGLONG*)&(ft) = \
((LONGLONG) (t) + (LONGLONG) 11644473600) * (LONGLONG) 10000000) ((LONGLONG) (t) + (LONGLONG) 11644473600) * (LONGLONG) 10000000)
#define TIME_WIN_TO_POSIX(ft, t) ((t) = (unsigned long) \ #define TIME_WIN_TO_POSIX(ft, t) ((t) = (unsigned long) \
((*(LONGLONG*)&(ft)) / (LONGLONG) 10000000 - (LONGLONG) 11644473600)) ((*(LONGLONG*)&(ft)) / (LONGLONG) 10000000 - (LONGLONG) 11644473600))
int verbose = 0; int verbose = 0;
static int recursive = 0; static int recursive = 0;
static int preserve = 0; static int preserve = 0;
@ -37,7 +34,6 @@ static void source(char *src);
static void rsource(char *src); static void rsource(char *src);
static void sink(char *targ); static void sink(char *targ);
/* /*
* Print an error message and perform a fatal exit. * Print an error message and perform a fatal exit.
*/ */
@ -52,7 +48,6 @@ void fatalbox(char *fmt, ...)
exit(1); exit(1);
} }
/* /*
* Print an error message and exit after closing the SSH link. * Print an error message and exit after closing the SSH link.
*/ */
@ -72,11 +67,11 @@ static void bump(char *fmt, ...)
exit(1); exit(1);
} }
void ssh_get_password(char *prompt, char *str, int maxlen) void ssh_get_password(char *prompt, char *str, int maxlen)
{ {
HANDLE hin, hout; HANDLE hin, hout;
DWORD savemode, i; DWORD savemode;
int i;
hin = GetStdHandle(STD_INPUT_HANDLE); hin = GetStdHandle(STD_INPUT_HANDLE);
hout = GetStdHandle(STD_OUTPUT_HANDLE); hout = GetStdHandle(STD_OUTPUT_HANDLE);
@ -98,7 +93,6 @@ void ssh_get_password(char *prompt, char *str, int maxlen)
WriteFile(hout, "\r\n", 2, &i, NULL); WriteFile(hout, "\r\n", 2, &i, NULL);
} }
/* /*
* Open an SSH connection to user@host and execute cmd. * Open an SSH connection to user@host and execute cmd.
*/ */
@ -139,12 +133,11 @@ static void do_cmd(char *host, char *user, char *cmd)
connection_open = 1; connection_open = 1;
} }
/* /*
* Update statistic information about current file. * Update statistic information about current file.
*/ */
static void print_stats(char *name, unsigned long size, unsigned long done, static void print_stats(char *name, unsigned long size, unsigned long done,
unsigned long start, unsigned long now) time_t start, time_t now)
{ {
float ratebs; float ratebs;
unsigned long eta; unsigned long eta;
@ -159,11 +152,11 @@ static void print_stats(char *name, unsigned long size, unsigned long done,
if (ratebs < 1.0) if (ratebs < 1.0)
eta = size - done; eta = size - done;
else else
eta = (size - done) / ratebs; eta = (unsigned long) ((size - done) / ratebs);
sprintf(etastr, "%02d:%02d:%02d", sprintf(etastr, "%02d:%02d:%02d",
eta / 3600, (eta % 3600) / 60, eta % 60); eta / 3600, (eta % 3600) / 60, eta % 60);
pct = 100.0 * (float) done / size; pct = (int) (100.0 * (float) done / size);
printf("\r%-25.25s | %10ld kB | %5.1f kB/s | ETA: %8s | %3d%%", printf("\r%-25.25s | %10ld kB | %5.1f kB/s | ETA: %8s | %3d%%",
name, done / 1024, ratebs / 1024.0, name, done / 1024, ratebs / 1024.0,
@ -173,7 +166,6 @@ static void print_stats(char *name, unsigned long size, unsigned long done,
printf("\n"); printf("\n");
} }
/* /*
* Find a colon in str and return a pointer to the colon. * Find a colon in str and return a pointer to the colon.
* This is used to seperate hostname from filename. * This is used to seperate hostname from filename.
@ -198,7 +190,6 @@ static char * colon(char *str)
return (NULL); return (NULL);
} }
/* /*
* Wait for a response from the other side. * Wait for a response from the other side.
* Return 0 if ok, -1 if error. * Return 0 if ok, -1 if error.
@ -235,7 +226,6 @@ static int response(void)
} }
} }
/* /*
* Send an error message to the other side and to the screen. * Send an error message to the other side and to the screen.
* Increment error counter. * Increment error counter.
@ -255,7 +245,6 @@ static void run_err(const char *fmt, ...)
va_end(ap); va_end(ap);
} }
/* /*
* Execute the source part of the SCP protocol. * Execute the source part of the SCP protocol.
*/ */
@ -268,7 +257,7 @@ static void source(char *src)
DWORD attr; DWORD attr;
unsigned long i; unsigned long i;
unsigned long stat_bytes; unsigned long stat_bytes;
unsigned long stat_starttime, stat_lasttime; time_t stat_starttime, stat_lasttime;
attr = GetFileAttributes(src); attr = GetFileAttributes(src);
if (attr == -1) { if (attr == -1) {
@ -351,7 +340,6 @@ static void source(char *src)
(void) response(); (void) response();
} }
/* /*
* Recursively send the contents of a directory. * Recursively send the contents of a directory.
*/ */
@ -403,7 +391,6 @@ static void rsource(char *src)
(void) response(); (void) response();
} }
/* /*
* Execute the sink part of the SCP protocol. * Execute the sink part of the SCP protocol.
*/ */
@ -422,7 +409,7 @@ static void sink(char *targ)
unsigned long size, i; unsigned long size, i;
int wrerror = 0; int wrerror = 0;
unsigned long stat_bytes; unsigned long stat_bytes;
unsigned long stat_starttime, stat_lasttime; time_t stat_starttime, stat_lasttime;
char *stat_name; char *stat_name;
attr = GetFileAttributes(targ); attr = GetFileAttributes(targ);
@ -435,7 +422,7 @@ static void sink(char *targ)
ssh_send("", 1); ssh_send("", 1);
while (1) { while (1) {
settime = 0; settime = 0;
gottime: gottime:
if (ssh_recv(&ch, 1) <= 0) if (ssh_recv(&ch, 1) <= 0)
return; return;
if (ch == '\n') if (ch == '\n')
@ -569,7 +556,6 @@ gottime:
} }
} }
/* /*
* We will copy local files to a remote server. * We will copy local files to a remote server.
*/ */
@ -669,7 +655,6 @@ static void toremote(int argc, char *argv[])
} }
} }
/* /*
* We will copy files from a remote server to the local machine. * We will copy files from a remote server to the local machine.
*/ */
@ -719,7 +704,6 @@ static void tolocal(int argc, char *argv[])
sink(targ); sink(targ);
} }
/* /*
* Initialize the Win$ock driver. * Initialize the Win$ock driver.
*/ */
@ -736,7 +720,6 @@ static void init_winsock()
bump("WinSock version is incompatible with 1.1"); bump("WinSock version is incompatible with 1.1");
} }
/* /*
* Short description of parameters. * Short description of parameters.
*/ */
@ -750,7 +733,6 @@ static void usage()
exit(1); exit(1);
} }
/* /*
* Main program (no, really?) * Main program (no, really?)
*/ */

View File

@ -37,10 +37,10 @@
((unsigned long)(unsigned char)(cp)[3])) ((unsigned long)(unsigned char)(cp)[3]))
#define PUT_32BIT(cp, value) { \ #define PUT_32BIT(cp, value) { \
(cp)[0] = (value) >> 24; \ (cp)[0] = (unsigned char)((value) >> 24); \
(cp)[1] = (value) >> 16; \ (cp)[1] = (unsigned char)((value) >> 16); \
(cp)[2] = (value) >> 8; \ (cp)[2] = (unsigned char)((value) >> 8); \
(cp)[3] = (value); } (cp)[3] = (unsigned char)(value); }
static SOCKET s = INVALID_SOCKET; static SOCKET s = INVALID_SOCKET;