]> skyeroc.xyz Git - dgamelaunch/commitdiff
Formatting workzone -- sorry
authorsbkelley <sb24kelley@gmail.com>
Wed, 10 Jun 2026 05:13:17 +0000 (01:13 -0400)
committersbkelley <sb24kelley@gmail.com>
Mon, 15 Jun 2026 22:55:29 +0000 (18:55 -0400)
dgamelaunch.c

index c9d7df8eccb6216449a06417c60c95432b4dfd2f..69ccd1bad3590c07be93ea715d9fe905087894b3 100644 (file)
@@ -640,74 +640,107 @@ loadbanner (char *fname, struct dg_banner *ban) {
   fclose (bannerfile);
 }
 
-void
-drawbanner (struct dg_banner *ban)
+void drawbanner(struct dg_banner *ban)
 {
   unsigned int i;
-  char *tmpch, *tmpch2, *splch;
+  char *edit_cursor, *special_end, *next_delimiter;
   int attr = 0, oattr = 0;
 
-  if (!ban) return;
-
-  for (i = 0; i < ban->len; i++) {
-      char *tmpbuf = strdup(ban->lines[i]);
-      char *tmpbuf2 = tmpbuf;
-      int ok = 0;
-      int x = 1;
-      do {
-         ok = 0;
-         if ((tmpch = strstr(tmpbuf2, "$ATTR("))) {
-             if ((tmpch2 = strstr(tmpch, ")"))) {
-                 int spl = 0;
-                 char *nxttmpch;
-                 ok = 1;
-                 oattr = attr;
-                 attr = A_NORMAL;
-                 *tmpch = *tmpch2 = '\0';
-                 tmpch += 6;
-                 nxttmpch = tmpch;
-                 do {
-                     spl = 0;
-                     splch = strchr(tmpch, ';');
-                     if (splch && *splch) {
-                         spl = 1;
-                         nxttmpch = splch;
-                         *nxttmpch = '\0';
-                         nxttmpch++;
-                     }
-                     if (tmpch && *tmpch) {
-                         switch (*tmpch) {
-                         default: break;
-                         case '0': case '1': case '2': case '3': case '4':
-                         case '5': case '6': case '7': case '8': case '9':
-                             {
-                                 int num = atoi(tmpch);
-                                 if (num >= 0 && num <= 15)
-                                     attr |= color_remap[num];
-                             }
-                             break;
-                         case 'b': attr |= A_BOLD; break;
-                         case 's': attr |= A_STANDOUT; break;
-                         case 'u': attr |= A_UNDERLINE; break;
-                         case 'r': attr |= A_REVERSE; break;
-                         case 'd': attr |= A_DIM; break;
-                         }
-                     } else attr = A_NORMAL;
-                     tmpch = nxttmpch;
-                 } while (spl);
-
-                 mvaddstr(1 + i, x, tmpbuf2);
-                 if (oattr) attroff(oattr);
-                 if (attr) attron(attr);
-                 x += strlen(tmpbuf2);
-                 tmpch2++;
-                 tmpbuf2 = tmpch2;
-             } else
-                 mvaddstr (1 + i, x, tmpbuf2);
-         } else
-             mvaddstr (1 + i, x, tmpbuf2);
-      } while (ok);
-      free(tmpbuf);
+  if (!ban)
+    return;
+
+  for (i = 0; i < ban->len; i++)
+  {
+    char *banner_line = strdup(ban->lines[i]);
+    char *output_cursor = banner_line;
+    int line_incomplete = 0;
+    int x = 1;
+    do
+    { // while (line_incomplete)
+      line_incomplete = 0;
+      if ((edit_cursor = strstr(output_cursor, "$ATTR(")))
+      {
+        if ((special_end = strstr(edit_cursor, ")")))
+        {
+          int delimited = 0;
+          char *next_attr_char;
+          line_incomplete = 1;
+          oattr = attr;
+          attr = A_NORMAL;
+          *edit_cursor = *special_end = '\0';
+          edit_cursor += 6;
+          next_attr_char = edit_cursor;
+          do // while(delimited)
+          {
+            delimited = 0;
+            next_delimiter = strchr(edit_cursor, ';');
+            if (next_delimiter && *next_delimiter)
+            {
+              delimited = 1;
+              next_attr_char = next_delimiter;
+              *next_attr_char = '\0';
+              next_attr_char++;
+            }
+            if (edit_cursor && *edit_cursor)
+            {
+              switch (*edit_cursor)
+              {
+              default:
+                break;
+              case '0':
+              case '1':
+              case '2':
+              case '3':
+              case '4':
+              case '5':
+              case '6':
+              case '7':
+              case '8':
+              case '9':
+              {
+                int num = atoi(edit_cursor);
+                if (num >= 0 && num <= 15)
+                  attr |= color_remap[num];
+              }
+              break;
+              case 'b':
+                attr |= A_BOLD;
+                break;
+              case 's':
+                attr |= A_STANDOUT;
+                break;
+              case 'u':
+                attr |= A_UNDERLINE;
+                break;
+              case 'r':
+                attr |= A_REVERSE;
+                break;
+              case 'd':
+                attr |= A_DIM;
+                break;
+              }
+            }
+            else
+              attr = A_NORMAL;
+            edit_cursor = next_attr_char;
+          } while (delimited);
+
+          mvaddstr(1 + i, x, output_cursor);
+          if (oattr)
+            attroff(oattr);
+          if (attr)
+            attron(attr);
+          x += strlen(output_cursor);
+          special_end++;
+          output_cursor = special_end;
+        }
+        else
+          mvaddstr(1 + i, x, output_cursor);
+      }
+      else
+        mvaddstr(1 + i, x, output_cursor);
+    } while (line_incomplete);
+    free(banner_line);
   }
 }