MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // more.c -- more files |
| 4 | // |
| 5 | // $Id: more.c 9142 2015-02-04 22:17:29Z Zesstra $ |
| 6 | |
| 7 | #pragma strict_types |
| 8 | #pragma save_types |
| 9 | #pragma no_clone |
| 10 | #pragma pedantic |
| 11 | #pragma range_check |
| 12 | |
| 13 | inherit "/std/util/pager"; |
| 14 | |
| 15 | #include <pager.h> |
| 16 | |
| 17 | #ifdef GERMAN |
| 18 | # define MSG_WRAPPED " VOM ANFANG" |
| 19 | # define MSG_NOT_FOUND " NICHTS GEFUNDEN" |
| 20 | # define MSG_NO_REGX " FEHLENDER REG. AUSDRUCK" |
| 21 | # define MSG_ILLEGAL " ILLEGALE ZEILENZAHL" |
| 22 | # define MSG_HELP "\ |
| 23 | Hilfe fuer more:\n\ |
| 24 | \n\ |
| 25 | b,B -- Eine Seite zurueck.\n\ |
| 26 | u,U -- Eine halbe Seite zurueck.\n\ |
| 27 | f,F -- Eine Seite vorwaerts.\n\ |
| 28 | d,D -- Eine halbe Seite vorwaerts.\n\ |
| 29 | <Zeile> -- Springe zu Zeile <Zeile>\n\ |
| 30 | q,x -- Verlassen von more.\n\ |
| 31 | /<RegExp> -- Nach dem regulaeren Ausdruck <RegExp> suchen.\n" |
| 32 | #else |
| 33 | # define MSG_WRAPPED " WRAPPED" |
| 34 | # define MSG_NOT_FOUND " NOTHING FOUND" |
| 35 | # define MSG_NO_REGX " NO PREV REGULAR EXPR" |
| 36 | # define MSG_ILLEGAL " ILLEGAL LINE NUMBER" |
| 37 | # define MSG_HELP "\ |
| 38 | Help for more:\n\ |
| 39 | \n\ |
| 40 | b,B -- One page back.\n\ |
| 41 | u,U -- Half a page back.\n\ |
| 42 | f,F -- One page forward.\n\ |
| 43 | d,D -- Half a page forward.\n\ |
| 44 | <line> -- Jump to line number <line>\n\ |
| 45 | q,x -- Quit or eXit more.\n\ |
| 46 | /<regexp> -- Search for the regular expression <regexp>.\n" |
| 47 | #endif |
| 48 | |
| 49 | private nosave string cprompt = ""; |
| 50 | |
| 51 | string prompt(mixed pinfo, string add) |
| 52 | { |
| 53 | int line,max; max = 1; |
| 54 | if(pointerp(pinfo)) |
| 55 | { |
| 56 | if(pinfo[CURL] + pinfo[PAGE] >= pinfo[MAXL]) line = pinfo[MAXL]; |
| 57 | else line = pinfo[CURL] + pinfo[PAGE]; |
| 58 | max = pinfo[MAXL]; |
| 59 | } |
| 60 | if (pinfo[FLAG] & E_ABS) |
| 61 | return sprintf("%s (%d/%d)%s %s", |
| 62 | ::prompt(pinfo, ""), |
| 63 | line-1, pinfo[MAXL], |
| 64 | cprompt, stringp(add)?add:""); |
| 65 | else |
| 66 | return sprintf("%s(%d%%)%s %s", |
| 67 | ::prompt(pinfo, ""), |
| 68 | line*100/max, |
| 69 | cprompt, stringp(add)?add:""); |
| 70 | } |
| 71 | |
| 72 | int search(mixed pinfo) |
| 73 | { |
| 74 | int l, lines; |
| 75 | mixed tmp; |
| 76 | l = pinfo[CURL]; |
| 77 | while((tmp = fread(pinfo, l, pinfo[PAGE])) && |
| 78 | !sizeof(regexp(old_explode(tmp, "\n"), pinfo[REGX]))) |
| 79 | l += pinfo[PAGE]; |
| 80 | if(!tmp) |
| 81 | { |
| 82 | cprompt += MSG_WRAPPED; |
| 83 | l = 1; |
| 84 | while(l < pinfo[CURL] && |
| 85 | (tmp = fread(pinfo, l, pinfo[PAGE])) && |
| 86 | !sizeof(regexp(old_explode(tmp, "\n"), pinfo[REGX]))) |
| 87 | l += pinfo[PAGE]; |
| 88 | if(l >= pinfo[CURL]) return 0; |
| 89 | } |
| 90 | return l; |
| 91 | } |
| 92 | |
| 93 | varargs int eval_command(mixed in, mixed pinfo) |
| 94 | { |
| 95 | cprompt = ""; |
| 96 | if(stringp(in)) |
| 97 | switch(in) |
| 98 | { |
| 99 | case "?": |
| 100 | write(MSG_HELP+"\n"); |
| 101 | return 0; |
| 102 | case "b": |
| 103 | case "B": |
| 104 | pinfo[CURL] -= pinfo[PAGE]; |
| 105 | break; |
| 106 | case "u": |
| 107 | case "U": |
| 108 | pinfo[CURL] -= pinfo[PAGE] / 2; |
| 109 | break; |
| 110 | case "f": |
| 111 | case "F": |
| 112 | pinfo[CURL] += pinfo[PAGE]; |
| 113 | break; |
| 114 | case "d": |
| 115 | case "D": |
| 116 | pinfo[CURL] += pinfo[PAGE] / 2; |
| 117 | break; |
| 118 | default: |
| 119 | { |
| 120 | int l; |
| 121 | if(l = to_int(in)) |
| 122 | { |
| 123 | if(l > pinfo[MAXL] || l < 1) return (cprompt = MSG_ILLEGAL, 0); |
| 124 | pinfo[CURL] = l; |
| 125 | break; |
| 126 | } |
| 127 | if(sizeof(in) && in[0] == '/') |
| 128 | { |
| 129 | if(sizeof(in) == 1) |
| 130 | { |
| 131 | if(!pinfo[REGX]) return (cprompt = MSG_NO_REGX, 0); |
| 132 | } |
| 133 | else pinfo[REGX] = in[1..]; |
| 134 | if(l = search(pinfo)) pinfo[CURL] = l; |
| 135 | else return (cprompt = MSG_NOT_FOUND, 0); |
| 136 | } |
| 137 | else return ::eval_command(in, pinfo); |
| 138 | break; |
| 139 | } |
| 140 | } |
| 141 | else return ::eval_command(in, pinfo); |
| 142 | return ::eval_command(-1, pinfo); |
| 143 | } |