Просмотр исходного кода

Fix bolds being backwards due to race between DCC and STDOUT.

Now use a per-dcc cflags rather than 1 global value.

Fixes #86
Bryan Drewery 11 лет назад
Родитель
Сommit
f705855a42
3 измененных файлов с 20 добавлено и 10 удалено
  1. 2 0
      doc/UPDATES
  2. 1 0
      src/dcc.h
  3. 17 10
      src/dccutil.cc

+ 2 - 0
doc/UPDATES

@@ -6,6 +6,8 @@ maint
   * Fix broken startup with GCC from ports on FreeBSD.
   * Fix broken startup with GCC from ports on FreeBSD.
   * Fix simulated terminal mode (-nt) defaulting to all console flags.
   * Fix simulated terminal mode (-nt) defaulting to all console flags.
   * Fix simulated terminal mode (-nt) not having color supported.
   * Fix simulated terminal mode (-nt) not having color supported.
+  * Fix race between DCC and terminal output which could result in
+    bolds being backwards (#86).
 
 
 1.4.5
 1.4.5
   * Remove ahbl as it now positively identifies all hosts as abusive
   * Remove ahbl as it now positively identifies all hosts as abusive

+ 1 - 0
src/dcc.h

@@ -71,6 +71,7 @@ struct dcc_t {
 #ifdef USE_IPV6
 #ifdef USE_IPV6
   char host6[121];              /* easier.. ipv6 address in regular notation (3ffe:80c0:225::) */
   char host6[121];              /* easier.. ipv6 address in regular notation (3ffe:80c0:225::) */
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
+  int8_t cflags;	 	/* Color status flags. */
 };
 };
 
 
 struct dns_info {
 struct dns_info {

+ 17 - 10
src/dccutil.cc

@@ -96,9 +96,16 @@ colorbuf(char *buf, size_t len, int idx, size_t bufsiz)
 {
 {
 //  char *buf = *bufp;
 //  char *buf = *bufp;
   int cidx = coloridx(idx);
   int cidx = coloridx(idx);
-  static int cflags;
   int schar = 0;
   int schar = 0;
   char buf3[1024] = "", buf2[15] = "", c = 0;
   char buf3[1024] = "", buf2[15] = "", c = 0;
+  static int8_t stdout_cflags = 0;
+  int8_t *cflags;
+
+  if (idx == -1) {
+    cflags = &stdout_cflags;
+  } else {
+    cflags = &dcc[idx].cflags;
+  }
 
 
   for (size_t i = 0; i < len; i++) {
   for (size_t i = 0; i < len; i++) {
     c = buf[i];
     c = buf[i];
@@ -120,30 +127,30 @@ colorbuf(char *buf, size_t len, int idx, size_t bufsiz)
         schar--;                  /* Unset identifier int */
         schar--;                  /* Unset identifier int */
         switch (c) {
         switch (c) {
           case 'b':
           case 'b':
-            if (cflags & CFLGS_BOLD) {
+            if (*cflags & CFLGS_BOLD) {
               strlcpy(buf2, BOLD_END(idx), sizeof(buf2));
               strlcpy(buf2, BOLD_END(idx), sizeof(buf2));
-              cflags &= ~CFLGS_BOLD;
+              *cflags &= ~CFLGS_BOLD;
             } else {
             } else {
-              cflags |= CFLGS_BOLD;
+              *cflags |= CFLGS_BOLD;
               strlcpy(buf2, BOLD(idx), sizeof(buf2));
               strlcpy(buf2, BOLD(idx), sizeof(buf2));
             }
             }
             break;
             break;
           case 'u':
           case 'u':
-            if (cflags & CFLGS_UNDERLINE) {
+            if (*cflags & CFLGS_UNDERLINE) {
               strlcpy(buf2, UNDERLINE_END(idx), sizeof(buf2));
               strlcpy(buf2, UNDERLINE_END(idx), sizeof(buf2));
-              cflags &= ~CFLGS_UNDERLINE;
+              *cflags &= ~CFLGS_UNDERLINE;
             } else {
             } else {
               strlcpy(buf2, UNDERLINE(idx), sizeof(buf2));
               strlcpy(buf2, UNDERLINE(idx), sizeof(buf2));
-              cflags |= CFLGS_UNDERLINE;
+              *cflags |= CFLGS_UNDERLINE;
             }
             }
             break;
             break;
           case 'f':
           case 'f':
-            if (cflags & CFLGS_FLASH) {
+            if (*cflags & CFLGS_FLASH) {
               strlcpy(buf2, FLASH_END(idx), sizeof(buf2));
               strlcpy(buf2, FLASH_END(idx), sizeof(buf2));
-              cflags &= ~CFLGS_FLASH;
+              *cflags &= ~CFLGS_FLASH;
             } else {
             } else {
               strlcpy(buf2, FLASH(idx), sizeof(buf2));
               strlcpy(buf2, FLASH(idx), sizeof(buf2));
-              cflags |= CFLGS_FLASH;
+              *cflags |= CFLGS_FLASH;
             }
             }
             break;
             break;
           default:
           default: