The Unicode module no longer depends on `cfg', since it gets the
[sgt/putty] / logging.c
index 67b2456..c2c4ff1 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -34,17 +34,27 @@ void logtraffic(void *handle, unsigned char c, int logmode)
 }
 
 /*
- * Log an Event Log entry (used in SSH packet logging mode).
+ * Log an Event Log entry. Used in SSH packet logging mode; this is
+ * also as convenient a place as any to put the output of Event Log
+ * entries to stderr when a command-line tool is in verbose mode.
+ * (In particular, this is a better place to put it than in the
+ * front ends, because it only has to be done once for all
+ * platforms. Platforms which don't have a meaningful stderr can
+ * just avoid defining FLAG_STDERR.
  */
 void log_eventlog(void *handle, char *event)
 {
     struct LogContext *ctx = (struct LogContext *)handle;
+    if ((flags & FLAG_STDERR) && (flags & FLAG_VERBOSE)) {
+       fprintf(stderr, "%s\n", event);
+       fflush(stderr);
+    }
     if (cfg.logtype != LGTYP_PACKETS)
        return;
     if (!ctx->lgfp)
        logfopen(ctx);
     if (ctx->lgfp)
-       fprintf(ctx->lgfp, "Event Log: %s\n", event);
+       fprintf(ctx->lgfp, "Event Log: %s\r\n", event);
 }
 
 /*
@@ -62,11 +72,11 @@ void log_packet(void *handle, int direction, int type,
     if (!ctx->lgfp)
        logfopen(ctx);
     if (ctx->lgfp) {
-       fprintf(ctx->lgfp, "%s packet type %d / 0x%02x (%s)\n",
+       fprintf(ctx->lgfp, "%s packet type %d / 0x%02x (%s)\r\n",
                direction == PKT_INCOMING ? "Incoming" : "Outgoing",
                type, type, texttype);
        for (i = 0; i < len; i += 16) {
-           sprintf(dumpdata, "  %08x%*s\n", i, 1+3*16+2+16, "");
+           sprintf(dumpdata, "  %08x%*s\r\n", i, 1+3*16+2+16, "");
            for (j = 0; j < 16 && i+j < len; j++) {
                int c = ((unsigned char *)data)[i+j];
                sprintf(smalldata, "%02x", c);
@@ -74,7 +84,7 @@ void log_packet(void *handle, int direction, int type,
                dumpdata[10+2+3*j+1] = smalldata[1];
                dumpdata[10+1+3*16+2+j] = (isprint(c) ? c : '.');
            }
-           strcpy(dumpdata + 10+1+3*16+2+j, "\n");
+           strcpy(dumpdata + 10+1+3*16+2+j, "\r\n");
            fputs(dumpdata, ctx->lgfp);
        }
        fflush(ctx->lgfp);
@@ -96,7 +106,7 @@ void logfopen(void *handle)
 
     if (!cfg.logtype)
        return;
-    sprintf(writemod, "w");           /* default to rewrite */
+    sprintf(writemod, "wb");          /* default to rewrite */
 
     time(&t);
     tm = *localtime(&t);
@@ -108,7 +118,10 @@ void logfopen(void *handle)
     if (ctx->lgfp) {
        int i;
        fclose(ctx->lgfp);
-       i = askappend(ctx->frontend, ctx->currlogfilename);
+       if (cfg.logxfovr != LGXF_ASK) {
+           i = ((cfg.logxfovr == LGXF_OVR) ? 2 : 1);
+       } else
+           i = askappend(ctx->frontend, ctx->currlogfilename);
        if (i == 1)
            writemod[0] = 'a';         /* set append mode */
        else if (i == 0) {             /* cancelled */
@@ -124,7 +137,7 @@ void logfopen(void *handle)
        fputs("=~=~=~=~=~=~=~=~=~=~=~= PuTTY log ", ctx->lgfp);
        strftime(buf, 24, "%Y.%m.%d %H:%M:%S", &tm);
        fputs(buf, ctx->lgfp);
-       fputs(" =~=~=~=~=~=~=~=~=~=~=~=\n", ctx->lgfp);
+       fputs(" =~=~=~=~=~=~=~=~=~=~=~=\r\n", ctx->lgfp);
 
        sprintf(buf, "%s session log (%s mode) to file: ",
                (writemod[0] == 'a') ? "Appending" : "Writing new",