Browse Source

Fixed clang warnings.

Steve Thielemann 4 years ago
parent
commit
fdb6107df3
5 changed files with 155 additions and 146 deletions
  1. 5 4
      hharry.cpp
  2. 1 1
      images.cpp
  3. 2 0
      terminal.cpp
  4. 144 140
      try-re.c
  5. 3 1
      wordplay.cpp

+ 5 - 4
hharry.cpp

@@ -7,8 +7,8 @@
 #include <termios.h>
 #include <unistd.h>
 
-#include <string>
 #include <sstream>
+#include <string>
 
 using namespace std;
 
@@ -253,7 +253,7 @@ int main(int argc, char *argv[]) {
   // -U<username>
   for (int x = 0; x < argc; x++) {
     if (strncmp("-U", argv[x], 2) == 0) {
-      username.assign( argv[x] + 2);
+      username.assign(argv[x] + 2);
     }
     if (strncmp("-SL", argv[x], 3) == 0) {
       node = atoi(argv[x] + 3) + 1;
@@ -278,9 +278,10 @@ int main(int argc, char *argv[]) {
     return 2;
 
   ZF_LOGI("Node: %d", node);
-  if (!username.empty() ) {
+  if (!username.empty()) {
     locate_user(username.c_str());
-    ZF_LOGD("Username: [%s] A.K.A. [%s]", (const char *)username.c_str(), (const char *)fullname.c_str());
+    ZF_LOGD("Username: [%s] A.K.A. [%s]", (const char *)username.c_str(),
+            (const char *)fullname.c_str());
   }
 
   pid = forkpty(&master, NULL, NULL, NULL);

+ 1 - 1
images.cpp

@@ -24,7 +24,7 @@ public:
 
 IConv converter("UTF-8", "CP437");
 
-char display_line(const char *line) {
+void display_line(const char *line) {
   char input[1024];
   char output[1024];
   int len;

+ 2 - 0
terminal.cpp

@@ -290,6 +290,8 @@ ANSI_TYPE console_ansi(struct console_details *cdp, const char *ansi) {
       }
     }
   }
+  ZF_LOGD("console_ansi( %s ) : ???", repr(ansi));
+  return OTHER;
 }
 
 /*

+ 144 - 140
try-re.c

@@ -1,160 +1,164 @@
+#include <regex.h>
 #include <stdio.h>
 #include <string.h>
-#include <regex.h>
 
 regex_t regex;
 #define MAX_MATCH 5
 // This is the number of capture groups + 1
 #define RESET "\x1b[0m"
 
-int regmatch( regex_t *preg, const char * string, size_t nmatch, regmatch_t pmatch[], int eflags) {
-    // returns number of matches found.  (Max nmatch)
-    int matches = 0;
-    int offset = 0;
-    int ret;
-
-    while (matches < nmatch) {
-        ret = regexec( preg, string + offset, nmatch - matches, pmatch + matches, eflags);
-        if (!ret) {
-            int current = offset;
-            offset += pmatch[matches].rm_eo;
-            pmatch[matches].rm_so += current;
-            pmatch[matches].rm_eo += current;
-            matches++;
-        } else if (ret == REG_NOMATCH ) {
-            break;
-        } else {
-            break;
-        }
+int regmatch(regex_t *preg, const char *string, size_t nmatch,
+             regmatch_t pmatch[], int eflags) {
+  // returns number of matches found.  (Max nmatch)
+  int matches = 0;
+  int offset = 0;
+  int ret;
+
+  while (matches < nmatch) {
+    ret = regexec(preg, string + offset, nmatch - matches, pmatch + matches,
+                  eflags);
+    if (!ret) {
+      int current = offset;
+      offset += pmatch[matches].rm_eo;
+      pmatch[matches].rm_so += current;
+      pmatch[matches].rm_eo += current;
+      matches++;
+    } else if (ret == REG_NOMATCH) {
+      break;
+    } else {
+      break;
     }
-    return matches;
-} 
-
-const char * clean_string(const char * badansi) {
-    static char buffer[1024];
-    char * cp;
-
-    strcpy(buffer, badansi);
-    cp = buffer;
-    while ( (cp = strstr(cp, "\x1b")) != NULL )
-    {
-        *cp = '~';
-    };
-    return buffer;
+  }
+  return matches;
 }
 
-void test(const char * trythis) {
-    regmatch_t regmatches[MAX_MATCH];
-    int matches, x;
-    const char * clean = clean_string(trythis);
-    printf("TEST (%s)\n", clean);
+const char *clean_string(const char *badansi) {
+  static char buffer[1024];
+  char *cp;
 
-    matches = regmatch(&regex, trythis, MAX_MATCH, regmatches, 0);
-    if (matches == 0) {
-        printf("No matches.\n");
-    } else {
-        printf("%d matches:\n", matches);
-        for( x = 0; x < matches; x++) {
-            printf("%d (%d - %d)\n", x, regmatches[x].rm_so, regmatches[x].rm_eo);
-            printf("    %*s [%.*s]\n", regmatches[x].rm_so, "", regmatches[x].rm_eo - regmatches[x].rm_so, clean + regmatches[x].rm_so);
-        }
-    }
+  strcpy(buffer, badansi);
+  cp = buffer;
+  while ((cp = strstr(cp, "\x1b")) != NULL) {
+    *cp = '~';
+  };
+  return buffer;
 }
 
-void test_( const char * trythis) {
-    int ret;
-    char msgbuf[100];
-    const char * p = trythis;
-
-    // safe printing (maybe)
-    strcpy(msgbuf, trythis);
-    char * fixup = msgbuf;
-    while ( ( fixup = strstr(fixup, "\x1b") ) != NULL ) {
-        *fixup = '^';
-    };
-
-    printf("Test: [%s]%s\n", msgbuf, RESET);
-
-    regmatch_t matches[ MAX_MATCH ];
-    while (1) {
-        ret = regexec( &regex, p, MAX_MATCH, matches, 0 );
-
-        if (!ret) {
-            printf("MATCH!\n");
-            for (int i = 0; i < MAX_MATCH; i++) {
-                int start, finish;
-                if (matches[i].rm_so == -1 )
-                    break;
-
-                start = matches[i].rm_so;
-                finish = matches[i].rm_eo;
-		// %.*s  = length to print, char * to use
-                strncpy(msgbuf, p+start, (finish-start));
-                msgbuf[finish-start] = 0;
-                fixup = msgbuf;
-                while ( ( fixup = strstr(fixup, "\x1b") ) != NULL ) {
-                    *fixup = '^';
-                };
-
-                // printf("'%.*s'%s %d : %d - %d\n", (finish - start), p + start, RESET, i, start, finish);
-                printf("'%s' %d : %d - %d\n", msgbuf, i, start, finish);
-            };
-            p += matches[0].rm_eo;
-        }
-        else if (ret == REG_NOMATCH) {
-            printf("Sorry, no matches.\n");
-            break;
-        }
-        else {
-            regerror( ret, &regex, msgbuf, sizeof(msgbuf));
-            fprintf(stderr, "Regex match failed: %s\n", msgbuf);
-        }
+void test(const char *trythis) {
+  regmatch_t regmatches[MAX_MATCH];
+  int matches, x;
+  const char *clean = clean_string(trythis);
+  printf("TEST (%s)\n", clean);
+
+  matches = regmatch(&regex, trythis, MAX_MATCH, regmatches, 0);
+  if (matches == 0) {
+    printf("No matches.\n");
+  } else {
+    printf("%d matches:\n", matches);
+    for (x = 0; x < matches; x++) {
+      printf("%d (%d - %d)\n", x, regmatches[x].rm_so, regmatches[x].rm_eo);
+      printf("    %*s [%.*s]\n", regmatches[x].rm_so, "",
+             regmatches[x].rm_eo - regmatches[x].rm_so,
+             clean + regmatches[x].rm_so);
     }
-    return;
+  }
 }
 
-int main(int argc, char * argv[]) {
-    // char RX[] = "(\x1b\[(?:\\d+|;)+[a-zA-Z])";
-    //char RX[] = "([a-z][a-z]([0-9]+))";
-    char RX[] = "([a-z][a-z]([0-9]+))";
-    char msgbuf[100];
-    int ret;
-
-    if ( ret = regcomp( &regex, RX, REG_EXTENDED|REG_NEWLINE ) ) {
-        regerror( ret, &regex, msgbuf, sizeof(msgbuf));
-        fprintf(stderr, "Regex compile failed: %s\n", msgbuf);
-        return 1;
+void test_(const char *trythis) {
+  int ret;
+  char msgbuf[100];
+  const char *p = trythis;
+
+  // safe printing (maybe)
+  strcpy(msgbuf, trythis);
+  char *fixup = msgbuf;
+  while ((fixup = strstr(fixup, "\x1b")) != NULL) {
+    *fixup = '^';
+  };
+
+  printf("Test: [%s]%s\n", msgbuf, RESET);
+
+  regmatch_t matches[MAX_MATCH];
+  while (1) {
+    ret = regexec(&regex, p, MAX_MATCH, matches, 0);
+
+    if (!ret) {
+      printf("MATCH!\n");
+      for (int i = 0; i < MAX_MATCH; i++) {
+        int start, finish;
+        if (matches[i].rm_so == -1)
+          break;
+
+        start = matches[i].rm_so;
+        finish = matches[i].rm_eo;
+        // %.*s  = length to print, char * to use
+        strncpy(msgbuf, p + start, (finish - start));
+        msgbuf[finish - start] = 0;
+        fixup = msgbuf;
+        while ((fixup = strstr(fixup, "\x1b")) != NULL) {
+          *fixup = '^';
+        };
+
+        // printf("'%.*s'%s %d : %d - %d\n", (finish - start), p + start, RESET,
+        // i, start, finish);
+        printf("'%s' %d : %d - %d\n", msgbuf, i, start, finish);
+      };
+      p += matches[0].rm_eo;
+    } else if (ret == REG_NOMATCH) {
+      printf("Sorry, no matches.\n");
+      break;
+    } else {
+      regerror(ret, &regex, msgbuf, sizeof(msgbuf));
+      fprintf(stderr, "Regex match failed: %s\n", msgbuf);
     }
+  }
+  return;
+}
 
-    test("this will fail.");
-    test("this has ab5 ab55 zd3 three matches.");
-
-    regfree(&regex);
-    // if ( regcomp( &regex, "(\x1b\[(?:[0-9]|;)+[a-zA-Z])", REG_EXTENDED|REG_NEWLINE ) ) {
-    // if ( regcomp( &regex, "(\x1b\[([0-9]+|;)+[a-zA-Z])", REG_EXTENDED|REG_NEWLINE ) ) {
-    // if ( regcomp( &regex, "\x1b\[[0-9]+(;[0-9]+)+?[a-zA-Z]", REG_EXTENDED|REG_NEWLINE ) ) {
-    if ( regcomp( &regex, "\x1b\[[0-9]+(;[0-9]+)*?[a-zA-Z]", REG_EXTENDED|REG_NEWLINE ) ) {
-        regerror( ret, &regex, msgbuf, sizeof(msgbuf));
-        fprintf(stderr, "Regex compile failed: %s\n", msgbuf);
-        return 1;
-    };
-
-    test("\x1b[1;1H\x1b[2J\x0cMystic BBS\x1b[6n");
-    test("\x1b[5;1HMEEP.");
-    test("\x1b[0;1;34;47mHello");
-    regfree(&regex);
-
-    //   \s matches space, FORM FEED.  Ouch!  NO!
-
-    if ( regcomp( &regex, "[a-zA-Z]+( [a-zA-Z]+)+", REG_EXTENDED|REG_NEWLINE ) ) {
-        regerror( ret, &regex, msgbuf, sizeof(msgbuf));
-        fprintf(stderr, "Regex compile failed: %s\n", msgbuf);
-        return 1;
-    };
-
-    test("\x1b[1;1H\x1b[2J\x0cMystic BBS\x1b[6n");
-    test("\x1b[5;1HMEEP is cool for cats.");
-     
-    regfree(&regex);
-    return 0;
+int main(int argc, char *argv[]) {
+  // char RX[] = "(\x1b\[(?:\\d+|;)+[a-zA-Z])";
+  // char RX[] = "([a-z][a-z]([0-9]+))";
+  char RX[] = "([a-z][a-z]([0-9]+))";
+  char msgbuf[100];
+  int ret;
+
+  if ((ret = regcomp(&regex, RX, REG_EXTENDED | REG_NEWLINE))) {
+    regerror(ret, &regex, msgbuf, sizeof(msgbuf));
+    fprintf(stderr, "Regex compile failed: %s\n", msgbuf);
+    return 1;
+  }
+
+  test("this will fail.");
+  test("this has ab5 ab55 zd3 three matches.");
+
+  regfree(&regex);
+  // if ( regcomp( &regex, "(\x1b\[(?:[0-9]|;)+[a-zA-Z])",
+  // REG_EXTENDED|REG_NEWLINE ) ) { if ( regcomp( &regex,
+  // "(\x1b\[([0-9]+|;)+[a-zA-Z])", REG_EXTENDED|REG_NEWLINE ) ) { if ( regcomp(
+  // &regex, "\x1b\[[0-9]+(;[0-9]+)+?[a-zA-Z]", REG_EXTENDED|REG_NEWLINE ) ) {
+  if (regcomp(&regex, "\x1b\[[0-9]+(;[0-9]+)*?[a-zA-Z]",
+              REG_EXTENDED | REG_NEWLINE)) {
+    regerror(ret, &regex, msgbuf, sizeof(msgbuf));
+    fprintf(stderr, "Regex compile failed: %s\n", msgbuf);
+    return 1;
+  };
+
+  test("\x1b[1;1H\x1b[2J\x0cMystic BBS\x1b[6n");
+  test("\x1b[5;1HMEEP.");
+  test("\x1b[0;1;34;47mHello");
+  regfree(&regex);
+
+  //   \s matches space, FORM FEED.  Ouch!  NO!
+
+  if (regcomp(&regex, "[a-zA-Z]+( [a-zA-Z]+)+", REG_EXTENDED | REG_NEWLINE)) {
+    regerror(ret, &regex, msgbuf, sizeof(msgbuf));
+    fprintf(stderr, "Regex compile failed: %s\n", msgbuf);
+    return 1;
+  };
+
+  test("\x1b[1;1H\x1b[2J\x0cMystic BBS\x1b[6n");
+  test("\x1b[5;1HMEEP is cool for cats.");
+
+  regfree(&regex);
+  return 0;
 }

+ 3 - 1
wordplay.cpp

@@ -41,7 +41,7 @@ void harry_idle_event(int fd) {
     r = randint((sizeof(phrases) / sizeof(char *)));
   } while (last_seen_harry_event.seen_before(r));
 
-  int color = random() % 15 + 1;
+  int color = randint(15) + 1;
   // %02d = std::setfill('0') << std::setw(2) << (int)
 
   buffer << "^S2^C" << std::setfill('0') << std::setw(2) << color << phrases[r]
@@ -230,6 +230,7 @@ int mangle_clrscr(std::string &buffer, std::string &work, size_t pos) {
       }
     }
   }
+  return 0;
 }
 
 int mangle(int fd, std::string &buffer) {
@@ -284,6 +285,7 @@ int mangle(int fd, std::string &buffer) {
           text.append(1, '.');
           text_offsets.push_back(-1);
           break;
+        case START:
         case COLOR:
           // text.append(1, ' ');
           // text_offsets.push_back(-1);