changeset 252:dcf78e2c458c

Improve log filename format parsing; Add special casing for handling of function keys for certain terminal types.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 24 Apr 2011 23:35:00 +0300
parents 51319822ae92
children 993fd8eb4271
files nnchat.c
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Thu Apr 21 01:44:05 2011 +0300
+++ b/nnchat.c	Sun Apr 24 23:35:00 2011 +0300
@@ -942,13 +942,14 @@
     return FALSE;
 }
 
-#define VPUTCH(CH)    th_vputch(&bufData, &bufSize, &bufLen, CH)
+#define VPUTCH(CH)  th_vputch(&bufData, &bufSize, &bufLen, CH)
 #define VPUTS(STR)  th_vputs(&bufData, &bufSize, &bufLen, STR)
 
 char *logParseFilename(const char *fmt, int id)
 {
-    size_t bufSize = strlen(fmt) + 32, bufLen = 0;
-    char *bufData = NULL, tmpBuf[32];
+    size_t bufSize = strlen(fmt) + TH_BUFGROW, bufLen = 0;
+    char *bufData = th_malloc(bufSize);
+    char tmpBuf[32];
     const char *s = fmt;
     
     while (*s) {
@@ -959,15 +960,15 @@
                     snprintf(tmpBuf, sizeof(tmpBuf), "%05d", id);
                     VPUTS(tmpBuf);
                     break;
-                
+
+                case 'd':
+                    snprintf(tmpBuf, sizeof(tmpBuf), "%d", id);
+                    VPUTS(tmpBuf);
+                    break;
+
                 case '%':
                     VPUTCH('%');
                     break;
-                
-                default:
-                    VPUTCH('%');
-                    VPUTCH(*s);
-                    break;
             }
             s++;
         } else {
@@ -1291,6 +1292,14 @@
                 if (c == '[') {
                     c = wgetch(stdscr);
                     switch (c) {
+                        case 0x31:
+                            c = wgetch(stdscr);
+                            if (c >= 0x31 && c <= 0x39)
+                                c = KEY_F(c - 0x30);
+                            else
+                                c = ERR;
+                            break;
+                        
                         case 0x32: c = KEY_IC; break;
                         case 0x33: c = KEY_DC; break;