Changeset 337

Show
Ignore:
Timestamp:
07/13/07 19:39:56 (1 year ago)
Author:
takkaria
Message:

Make show_file() a little bit nicer, and make do_cmd_messages() much nicer. (closes #104)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/cmd4.c

    r293 r337  
    19581958        int wid, hgt; 
    19591959 
    1960         char shower[80]; 
    1961         char finder[80]; 
    1962  
    1963  
    1964         /* Wipe finder */ 
    1965         my_strcpy(finder, "", sizeof(shower)); 
    1966  
    1967         /* Wipe shower */ 
    1968         my_strcpy(shower, "", sizeof(finder)); 
     1960        char shower[80] = ""; 
     1961 
    19691962 
    19701963 
     
    20082001 
    20092002                                /* Display matches */ 
    2010                                 while ((str = strstr(str, shower)) != NULL) 
     2003                                while ((str = my_stristr(str, shower)) != NULL) 
    20112004                                { 
    20122005                                        int len = strlen(shower); 
    20132006 
    20142007                                        /* Display the match */ 
    2015                                         Term_putstr(str-msg, hgt - 3 - j, len, TERM_YELLOW, shower); 
     2008                                        Term_putstr(str-msg, hgt - 3 - j, len, TERM_YELLOW, str); 
    20162009 
    20172010                                        /* Advance */ 
     
    20212014                } 
    20222015 
    2023                 /* Display header XXX XXX XXX */ 
    2024                 prt(format("Message Recall (%d-%d of %d), Offset %d", 
    2025                            i, i + j - 1, n, q), 0, 0); 
     2016                /* Display header */ 
     2017                prt(format("Message recall (%d-%d of %d), offset %d", i, i + j - 1, n, q), 0, 0); 
    20262018 
    20272019                /* Display prompt (not very informative) */ 
    2028                 prt("[Press 'p' for older, 'n' for newer, ..., or ESCAPE]", hgt - 1, 0); 
     2020                if (shower[0]) 
     2021                    prt("[Movement keys to navigate, '-' for next, '=' to find]", hgt - 1, 0); 
     2022                else 
     2023                        prt("[Movement keys to navigate, '=' to find, or ESCAPE to exit]", hgt - 1, 0); 
     2024                         
    20292025 
    20302026                /* Get a command */ 
    20312027                ke = inkey_ex(); 
    20322028 
     2029 
    20332030                /* Exit on Escape */ 
    2034                 if (ke.key == ESCAPE) break; 
    2035  
    2036                 /* Hack -- Save the old index */ 
    2037                 j = i; 
     2031                if (ke.key == ESCAPE) 
     2032                { 
     2033                        break; 
     2034                } 
     2035 
     2036                /* Find text */ 
     2037                else if (ke.key == '=') 
     2038                { 
     2039                        /* Get the string to find */ 
     2040                        prt("Find: ", hgt - 1, 0); 
     2041                        if (!askfor_aux(shower, sizeof shower, NULL)) continue; 
     2042 
     2043                        /* Set to find */ 
     2044                        ke.key = '-'; 
     2045                } 
    20382046 
    20392047                /* Horizontal scroll */ 
    2040                 if (ke.key == '4'
     2048                else if (ke.key == '4' || ke.key == ARROW_LEFT
    20412049                { 
    20422050                        /* Scroll left */ 
     
    20482056 
    20492057                /* Horizontal scroll */ 
    2050                 if (ke.key == '6'
     2058                else if (ke.key == '6'|| ke.key == ARROW_RIGHT
    20512059                { 
    20522060                        /* Scroll right */ 
     
    20572065                } 
    20582066 
    2059                 /* Hack -- handle show */ 
    2060                 if (ke.key == '=') 
    2061                 { 
    2062                         /* Prompt */ 
    2063                         prt("Show: ", hgt - 1, 0); 
    2064  
    2065                         /* Get a "shower" string, or continue */ 
    2066                         if (!askfor_aux(shower, sizeof shower, NULL)) continue; 
    2067  
    2068                         /* Okay */ 
    2069                         continue; 
    2070                 } 
    2071  
    2072                 /* Hack -- handle find */ 
    2073                 if (ke.key == '/') 
    2074                 { 
    2075                         s16b z; 
    2076  
    2077                         /* Prompt */ 
    2078                         prt("Find: ", hgt - 1, 0); 
    2079  
    2080                         /* Get a "finder" string, or continue */ 
    2081                         if (!askfor_aux(finder, sizeof finder, NULL)) continue; 
    2082  
    2083                         /* Show it */ 
    2084                         my_strcpy(shower, finder, sizeof(shower)); 
    2085  
    2086                         /* Scan messages */ 
    2087                         for (z = i + 1; z < n; z++) 
    2088                         { 
    2089                                 cptr msg = message_str(z); 
    2090  
    2091                                 /* Search for it */ 
    2092                                 if (strstr(msg, finder)) 
    2093                                 { 
    2094                                         /* New location */ 
    2095                                         i = z; 
    2096  
    2097                                         /* Done */ 
    2098                                         break; 
    2099                                 } 
    2100                         } 
     2067                /* Recall 1 older message */ 
     2068                else if (ke.key == '8' || ke.key == ARROW_UP) 
     2069                { 
     2070                        /* Go older if legal */ 
     2071                        if (i + 1 < n) i += 1; 
     2072                } 
     2073 
     2074                /* Recall 1 newer messages */ 
     2075                else if (ke.key == '2' || ke.key == ARROW_DOWN || ke.key == '\r' || ke.key == '\n') 
     2076                { 
     2077                        /* Go newer (if able) */ 
     2078                        i = (i >= 1) ? (i - 1) : 0; 
    21012079                } 
    21022080 
    21032081                /* Recall 20 older messages */ 
    2104                 if ((ke.key == 'p') || (ke.key == KTRL('P')) || (ke.key == ' ')) 
     2082                else if ((ke.key == 'p') || (ke.key == KTRL('P')) || (ke.key == ' ')) 
    21052083                { 
    21062084                        /* Go older if legal */ 
     
    21082086                } 
    21092087 
    2110                 /* Recall 10 older messages */ 
    2111                 if (ke.key == '+') 
    2112                 { 
    2113                         /* Go older if legal */ 
    2114                         if (i + 10 < n) i += 10; 
    2115                 } 
    2116  
    2117                 /* Recall 1 older message */ 
    2118                 if ((ke.key == '8') || (ke.key == '\n') || (ke.key == '\r')) 
    2119                 { 
    2120                         /* Go older if legal */ 
    2121                         if (i + 1 < n) i += 1; 
    2122                 } 
    2123  
    21242088                /* Recall 20 newer messages */ 
    2125                 if ((ke.key == 'n') || (ke.key == KTRL('N'))) 
     2089                else if ((ke.key == 'n') || (ke.key == KTRL('N'))) 
    21262090                { 
    21272091                        /* Go newer (if able) */ 
     
    21292093                } 
    21302094 
    2131                 /* Recall 10 newer messages */ 
    2132                 if (ke.key == '-') 
    2133                 { 
    2134                         /* Go newer (if able) */ 
    2135                         i = (i >= 10) ? (i - 10) : 0; 
    2136                 } 
    2137  
    2138                 /* Recall 1 newer messages */ 
    2139                 if (ke.key == '2') 
    2140                 { 
    2141                         /* Go newer (if able) */ 
    2142                         i = (i >= 1) ? (i - 1) : 0; 
    2143                 } 
    2144  
    21452095                /* Scroll forwards or backwards using mouse clicks */ 
    2146                 if (ke.key == '\xff') 
     2096                else if (ke.key == '\xff') 
    21472097                { 
    21482098                        if (ke.index) 
     
    21612111                } 
    21622112 
    2163                 /* Hack -- Error of some kind */ 
    2164                 if (i == j) bell(NULL); 
     2113                /* Error time */ 
     2114                else 
     2115                { 
     2116                        bell(NULL); 
     2117                } 
     2118 
     2119 
     2120                /* Find the next item */ 
     2121                if (ke.key == '-' && shower[0]) 
     2122                { 
     2123                        s16b z; 
     2124 
     2125                        /* Scan messages */ 
     2126                        for (z = i + 1; z < n; z++) 
     2127                        { 
     2128                                /* Search for it */ 
     2129                                if (my_stristr(message_str(z), shower)) 
     2130                                { 
     2131                                        /* New location */ 
     2132                                        i = z; 
     2133 
     2134                                        /* Done */ 
     2135                                        break; 
     2136                                } 
     2137                        } 
     2138                } 
    21652139        } 
    21662140 
  • trunk/src/files.c

    r288 r337  
    23752375 
    23762376                /* Back up one line */ 
    2377                 if ((ch == '8') || (ch == '=')
     2377                if (ch == ARROW_UP || ch == '8'
    23782378                { 
    23792379                        line = line - 1; 
    2380                 } 
    2381  
    2382                 /* Back up one half page */ 
    2383                 if (ch == '_') 
    2384                 { 
    2385                         line = line - ((hgt - 4) / 2); 
    23862380                } 
    23872381 
     
    23992393 
    24002394                /* Advance one line */ 
    2401                 if ((ch == '2') || (ch == '\n') || (ch == '\r')) 
     2395                if ((ch == ARROW_DOWN) || (ch == '2') || (ch == '\n') || (ch == '\r')) 
    24022396                { 
    24032397                        line = line + 1; 
    2404                 } 
    2405  
    2406                 /* Advance one half page */ 
    2407                 if (ch == '+') 
    2408                 { 
    2409                         line = line + ((hgt - 4) / 2); 
    24102398                } 
    24112399 
  • trunk/src/z-util.c

    r155 r337  
    8282} 
    8383 
     84/* 
     85 * An ANSI version of strstr() with case insensitivity. 
     86 * 
     87 * In the public domain; found at: 
     88 *    http://c.snippets.org/code/stristr.c 
     89 */ 
     90char *my_stristr(const char *string, const char *pattern) 
     91{ 
     92      char *pptr, *sptr, *start; 
     93 
     94      for (start = (char *)string; *start != 0; start++) 
     95      { 
     96            /* find start of pattern in string */ 
     97            for ( ; ((*start != 0) && 
     98                                (toupper((unsigned char)*start) != toupper((unsigned char)*pattern))); start++) 
     99                  ; 
     100            if (*start == 0) 
     101                  return NULL; 
     102 
     103            pptr = (char *)pattern; 
     104            sptr = (char *)start; 
     105 
     106            while (toupper((unsigned char)*sptr) == toupper((unsigned char)*pptr)) 
     107            { 
     108                  sptr++; 
     109                  pptr++; 
     110 
     111                  /* if end of pattern then pattern was found */ 
     112                  if (*pptr == 0) 
     113                        return (start); 
     114            } 
     115      } 
     116 
     117      return NULL; 
     118} 
     119 
    84120 
    85121/* 
  • trunk/src/z-util.h

    r155 r337  
    3939extern int my_strnicmp(cptr a, cptr b, int n); 
    4040 
     41/* Case-insensitive strstr */ 
     42extern char *my_stristr(const char *string, const char *pattern); 
     43 
    4144/* Copy a string */ 
    4245extern size_t my_strcpy(char *buf, const char *src, size_t bufsize);