Jacob's fixes for the Event Log
[u/mdw/putty] / windlg.c
index b7e878d..6d3b0f4 100644 (file)
--- a/windlg.c
+++ b/windlg.c
@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <ctype.h>
+#include <time.h>
 
 #include "ssh.h"
 #include "putty.h"
@@ -48,6 +49,11 @@ static int CALLBACK LogProc (HWND hwnd, UINT msg,
 
     switch (msg) {
       case WM_INITDIALOG:
+        {
+            static int tabs[4] = {78, 108};
+            SendDlgItemMessage (hwnd, IDN_LIST, LB_SETTABSTOPS, 2,
+                                (LPARAM) tabs);
+        }
        for (i=0; i<nevents; i++)
            SendDlgItemMessage (hwnd, IDN_LIST, LB_ADDSTRING,
                                0, (LPARAM)events[i]);
@@ -205,8 +211,8 @@ enum { IDCX_ABOUT = IDC_ABOUT, IDCX_TVSTATIC, IDCX_TREEVIEW, controlstartvalue,
     IDC_SESSDEL,
     IDC_CLOSEEXIT,
     IDC_COEALWAYS,
-    IDC_COENORMAL,
     IDC_COENEVER,
+    IDC_COENORMAL,
     sessionpanelend,
 
     loggingpanelstart,
@@ -540,9 +546,9 @@ static void init_dlg_ctrls(HWND hwnd) {
     CheckDlgButton (hwnd, IDC_BLINKCUR, cfg.blink_cur);
     CheckDlgButton (hwnd, IDC_SCROLLBAR, cfg.scrollbar);
     CheckDlgButton (hwnd, IDC_LOCKSIZE, cfg.locksize);
-    CheckRadioButton (hwnd, IDC_COEALWAYS, IDC_COENEVER,
-                      cfg.close_on_exit==COE_NEVER ? IDC_COENEVER :
-                      cfg.close_on_exit==COE_NORMAL ? IDC_COENORMAL : IDC_COEALWAYS);
+    CheckRadioButton (hwnd, IDC_COEALWAYS, IDC_COENORMAL,
+                      cfg.close_on_exit==COE_NORMAL ? IDC_COENORMAL :
+                      cfg.close_on_exit==COE_NEVER ? IDC_COENEVER : IDC_COEALWAYS);
     CheckDlgButton (hwnd, IDC_CLOSEWARN, cfg.warn_on_close);
 
     SetDlgItemText (hwnd, IDC_TTEDIT, cfg.termtype);
@@ -704,10 +710,10 @@ static void create_controls(HWND hwnd, int dlgtype, int panel) {
             endbox(&cp);
         }
         beginbox(&cp, NULL, IDC_BOX_SESSION3);
-        radioline(&cp, "At session end, close &window:", IDC_CLOSEEXIT, 3,
+        radioline(&cp, "Close &window on exit:", IDC_CLOSEEXIT, 4,
                   "Always", IDC_COEALWAYS,
-                  "On clean exit", IDC_COENORMAL,
-                  "Never", IDC_COENEVER, NULL);
+                  "Never", IDC_COENEVER,
+                  "Only on clean exit", IDC_COENORMAL, NULL);
         endbox(&cp);
     }
 
@@ -1605,13 +1611,13 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
                                sizeof(cfg.wintitle)-1);
            break;
           case IDC_COEALWAYS:
-          case IDC_COENORMAL:
           case IDC_COENEVER:
+          case IDC_COENORMAL:
             if (HIWORD(wParam) == BN_CLICKED ||
                 HIWORD(wParam) == BN_DOUBLECLICKED) {
                 cfg.close_on_exit = IsDlgButtonChecked (hwnd, IDC_COEALWAYS) ? COE_ALWAYS :
-                                    IsDlgButtonChecked (hwnd, IDC_COENORMAL) ? COE_NORMAL :
-                                    COE_NEVER;
+                                    IsDlgButtonChecked (hwnd, IDC_COENEVER) ? COE_NEVER :
+                                    COE_NORMAL;
             }
             break;
          case IDC_CLOSEWARN:
@@ -2038,20 +2044,28 @@ int do_reconfig (HWND hwnd) {
 }
 
 void logevent (char *string) {
+    char timebuf[40];
+    time_t t;
+
     if (nevents >= negsize) {
        negsize += 64;
        events = srealloc (events, negsize * sizeof(*events));
     }
-    events[nevents] = smalloc(1+strlen(string));
-    strcpy (events[nevents], string);
-    nevents++;
+
+    time(&t);
+    strftime(timebuf, sizeof(timebuf), "%Y-%m-%d %H:%M:%S\t", localtime(&t));
+
+    events[nevents] = smalloc(strlen(timebuf)+strlen(string)+1);
+    strcpy(events[nevents], timebuf);
+    strcat(events[nevents], string);
     if (logbox) {
         int count;
        SendDlgItemMessage (logbox, IDN_LIST, LB_ADDSTRING,
-                           0, (LPARAM)string);
+                           0, (LPARAM)events[nevents]);
        count = SendDlgItemMessage (logbox, IDN_LIST, LB_GETCOUNT, 0, 0);
        SendDlgItemMessage (logbox, IDN_LIST, LB_SETTOPINDEX, count-1, 0);
     }
+    nevents++;
 }
 
 void showeventlog (HWND hwnd) {