Use set_icon and set_title rather than SetWindowText. Should fix
[u/mdw/putty] / psftp.c
diff --git a/psftp.c b/psftp.c
index e585732..2dc6e4c 100644 (file)
--- a/psftp.c
+++ b/psftp.c
@@ -34,6 +34,7 @@ static int do_sftp_init(void);
 char *pwd, *homedir;
 static Backend *back;
 static void *backhandle;
+static Config cfg;
 
 /* ----------------------------------------------------------------------
  * Higher-level helper functions used in commands.
@@ -832,7 +833,7 @@ int sftp_cmd_chmod(struct sftp_command *cmd)
            if (!(subset & 06777) && (perms &~ subset)) {
                printf("chmod: file mode '%.*s' contains no user/group/other"
                       " specifier and permissions other than 't' \n",
-                      strcspn(modebegin, ","), modebegin, *mode);
+                      strcspn(modebegin, ","), modebegin);
                return 0;
            }
            perms &= subset;
@@ -1448,40 +1449,43 @@ static int verbose = 0;
  */
 void fatalbox(char *fmt, ...)
 {
-    char str[0x100];                  /* Make the size big enough */
+    char *str, *str2;
     va_list ap;
     va_start(ap, fmt);
-    strcpy(str, "Fatal:");
-    vsprintf(str + strlen(str), fmt, ap);
+    str = dupvprintf(fmt, ap);
+    str2 = dupcat("Fatal: ", str, "\n", NULL);
+    sfree(str);
     va_end(ap);
-    strcat(str, "\n");
-    fputs(str, stderr);
+    fputs(str2, stderr);
+    sfree(str2);
 
     cleanup_exit(1);
 }
 void modalfatalbox(char *fmt, ...)
 {
-    char str[0x100];                  /* Make the size big enough */
+    char *str, *str2;
     va_list ap;
     va_start(ap, fmt);
-    strcpy(str, "Fatal:");
-    vsprintf(str + strlen(str), fmt, ap);
+    str = dupvprintf(fmt, ap);
+    str2 = dupcat("Fatal: ", str, "\n", NULL);
+    sfree(str);
     va_end(ap);
-    strcat(str, "\n");
-    fputs(str, stderr);
+    fputs(str2, stderr);
+    sfree(str2);
 
     cleanup_exit(1);
 }
 void connection_fatal(void *frontend, char *fmt, ...)
 {
-    char str[0x100];                  /* Make the size big enough */
+    char *str, *str2;
     va_list ap;
     va_start(ap, fmt);
-    strcpy(str, "Fatal:");
-    vsprintf(str + strlen(str), fmt, ap);
+    str = dupvprintf(fmt, ap);
+    str2 = dupcat("Fatal: ", str, "\n", NULL);
+    sfree(str);
     va_end(ap);
-    strcat(str, "\n");
-    fputs(str, stderr);
+    fputs(str2, stderr);
+    sfree(str2);
 
     cleanup_exit(1);
 }
@@ -1719,7 +1723,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
     /*
      * Enact command-line overrides.
      */
-    cmdline_run_saved();
+    cmdline_run_saved(&cfg);
 
     /*
      * Trim leading whitespace off the hostname if it's there.
@@ -1769,6 +1773,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
     }
     if (!cfg.username[0]) {
        printf("login as: ");
+       fflush(stdout);
        if (!fgets(cfg.username, sizeof(cfg.username), stdin)) {
            fprintf(stderr, "psftp: aborting\n");
            cleanup_exit(1);
@@ -1824,12 +1829,12 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
 
     back = &ssh_backend;
 
-    err = back->init(NULL, &backhandle, cfg.host, cfg.port, &realhost, 0);
+    err = back->init(NULL, &backhandle, &cfg, cfg.host, cfg.port, &realhost,0);
     if (err != NULL) {
        fprintf(stderr, "ssh_init: %s\n", err);
        return 1;
     }
-    logctx = log_init(NULL);
+    logctx = log_init(NULL, &cfg);
     back->provide_logctx(backhandle, logctx);
     ssh_sftp_init();
     if (verbose && realhost != NULL)
@@ -1840,11 +1845,11 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
 void cmdline_error(char *p, ...)
 {
     va_list ap;
-    fprintf(stderr, "pscp: ");
+    fprintf(stderr, "psftp: ");
     va_start(ap, p);
     vfprintf(stderr, p, ap);
     va_end(ap);
-    fputc('\n', stderr);
+    fprintf(stderr, "\n       try typing \"psftp -h\" for help\n");
     exit(1);
 }
 
@@ -1859,6 +1864,7 @@ int main(int argc, char *argv[])
     int mode = 0;
     int modeflags = 0;
     char *batchfile = NULL;
+    int errors = 0;
 
     flags = FLAG_STDERR | FLAG_INTERACTIVE;
     cmdline_tooltype = TOOLTYPE_FILETRANSFER;
@@ -1868,6 +1874,7 @@ int main(int argc, char *argv[])
 
     userhost = user = NULL;
 
+    errors = 0;
     for (i = 1; i < argc; i++) {
        int ret;
        if (argv[i][0] != '-') {
@@ -1877,7 +1884,7 @@ int main(int argc, char *argv[])
                 userhost = dupstr(argv[i]);
            continue;
        }
-       ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1);
+       ret = cmdline_process_param(argv[i], i+1<argc?argv[i+1]:NULL, 1, &cfg);
        if (ret == -2) {
            cmdline_error("option \"%s\" requires an argument", argv[i]);
        } else if (ret == 2) {
@@ -1902,7 +1909,7 @@ int main(int argc, char *argv[])
            i++;
            break;
        } else {
-           usage();
+           cmdline_error("unknown option \"%s\"", argv[i]);
        }
     }
     argc -= i;