]> skyeroc.xyz Git - dgamelaunch/commitdiff
Dynamically alloc is_nhext array in watching menu.
authorPasi Kallinen <paxed@alt.org>
Sun, 18 Oct 2009 08:29:33 +0000 (08:29 +0000)
committerPasi Kallinen <paxed@alt.org>
Sun, 18 Oct 2009 08:29:33 +0000 (08:29 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@475 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

dgamelaunch.c

index 640b0b214a97e38a64bb2ef5ad65f35456ae3050..5f9f9ff6ce6e1aac63703b040e582e7e8a6cfa18 100644 (file)
@@ -371,27 +371,31 @@ drawbanner (struct dg_banner *ban, unsigned int start_line, unsigned int howmany
 void
 inprogressmenu (int gameid)
 {
-    char selectorchars[('z'-'a') + ('Z'-'A')+2];
+    const char *selectorchars = "abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ";
   int i, menuchoice, len = 20, offset = 0, doresizewin = 0;
   static dg_sortmode sortmode = NUM_SORTMODES;
   time_t ctime;
   struct dg_game **games;
   char ttyrecname[130], *replacestr = NULL, gametype[10];
-  int is_nhext[('z'-'a') + ('Z'-'A')+2];
+  int *is_nhext;
   sigset_t oldmask, toblock;
   int idx = -1;
   int max_height = -1;
   int selected = -1;
 
-
-  for (i = 'a'; i <= 'z'; i++) {
-      selectorchars[i-'a'] = i;
-      selectorchars[(i-'a')+('z'-'a')+1] = (i - 'a' + 'A');
-  }
+  int abs_max_height;
 
   if (sortmode == NUM_SORTMODES)
       sortmode = globalconfig.sortmode;
 
+  abs_max_height = strlen(selectorchars);
+  is_nhext = (int *)calloc(abs_max_height+1, sizeof(int));
+
+  if (!is_nhext) {
+      debug_write("could not calloc is_nhext");
+      graceful_exit(70);
+  }
+
   games = populate_games (gameid, &len, me);
   games = sort_games (games, len, sortmode);
 
@@ -399,8 +403,12 @@ inprogressmenu (int gameid)
     {
        term_resize_check();
        max_height = local_LINES - 10;
-       if (max_height < 2) return;
-       if (max_height > ('z'-'a') + ('Z'-'A')) max_height = ('z'-'a') + ('Z'-'A');
+       if (max_height < 2) {
+           free(is_nhext);
+           /* TODO: free games[] */
+           return;
+       }
+       if (max_height > abs_max_height) max_height = abs_max_height;
 
       if (len == 0)
         offset = 0;
@@ -498,6 +506,7 @@ inprogressmenu (int gameid)
 
        case ERR:
        case 'q': case 'Q':
+           if (is_nhext) free(is_nhext);
           return;
 
        case '.':
@@ -552,8 +561,6 @@ watchgame:
                 graceful_exit (145);
              }
 
-              /*replacestr[0] = '/';*/
-
               clear ();
               refresh ();
               endwin ();
@@ -589,6 +596,7 @@ watchgame:
       games = populate_games (gameid, &len, me);
       games = sort_games (games, len, sortmode);
     }
+  if (is_nhext) free(is_nhext);
 }
 
 /* ************************************************************* */