blob: 3635e888bcdac5fe19221a205bdd9702f02f08c6 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// 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
MG Mud User88f12472016-06-24 23:31:02 +020010#pragma range_check
11
12inherit "/std/util/pager";
13
14#include <pager.h>
15
16#ifdef GERMAN
17# define MSG_WRAPPED " VOM ANFANG"
18# define MSG_NOT_FOUND " NICHTS GEFUNDEN"
19# define MSG_NO_REGX " FEHLENDER REG. AUSDRUCK"
20# define MSG_ILLEGAL " ILLEGALE ZEILENZAHL"
21# define MSG_HELP "\
22Hilfe fuer more:\n\
23\n\
24b,B -- Eine Seite zurueck.\n\
25u,U -- Eine halbe Seite zurueck.\n\
26f,F -- Eine Seite vorwaerts.\n\
27d,D -- Eine halbe Seite vorwaerts.\n\
28<Zeile> -- Springe zu Zeile <Zeile>\n\
29q,x -- Verlassen von more.\n\
30/<RegExp> -- Nach dem regulaeren Ausdruck <RegExp> suchen.\n"
31#else
32# define MSG_WRAPPED " WRAPPED"
33# define MSG_NOT_FOUND " NOTHING FOUND"
34# define MSG_NO_REGX " NO PREV REGULAR EXPR"
35# define MSG_ILLEGAL " ILLEGAL LINE NUMBER"
36# define MSG_HELP "\
37Help for more:\n\
38\n\
39b,B -- One page back.\n\
40u,U -- Half a page back.\n\
41f,F -- One page forward.\n\
42d,D -- Half a page forward.\n\
43<line> -- Jump to line number <line>\n\
44q,x -- Quit or eXit more.\n\
45/<regexp> -- Search for the regular expression <regexp>.\n"
46#endif
47
48private nosave string cprompt = "";
49
50string prompt(mixed pinfo, string add)
51{
52 int line,max; max = 1;
53 if(pointerp(pinfo))
54 {
55 if(pinfo[CURL] + pinfo[PAGE] >= pinfo[MAXL]) line = pinfo[MAXL];
56 else line = pinfo[CURL] + pinfo[PAGE];
57 max = pinfo[MAXL];
58 }
59 if (pinfo[FLAG] & E_ABS)
60 return sprintf("%s (%d/%d)%s %s",
61 ::prompt(pinfo, ""),
62 line-1, pinfo[MAXL],
63 cprompt, stringp(add)?add:"");
64 else
65 return sprintf("%s(%d%%)%s %s",
66 ::prompt(pinfo, ""),
67 line*100/max,
68 cprompt, stringp(add)?add:"");
69}
70
71int search(mixed pinfo)
72{
73 int l, lines;
74 mixed tmp;
75 l = pinfo[CURL];
76 while((tmp = fread(pinfo, l, pinfo[PAGE])) &&
77 !sizeof(regexp(old_explode(tmp, "\n"), pinfo[REGX])))
78 l += pinfo[PAGE];
79 if(!tmp)
80 {
81 cprompt += MSG_WRAPPED;
82 l = 1;
83 while(l < pinfo[CURL] &&
84 (tmp = fread(pinfo, l, pinfo[PAGE])) &&
85 !sizeof(regexp(old_explode(tmp, "\n"), pinfo[REGX])))
86 l += pinfo[PAGE];
87 if(l >= pinfo[CURL]) return 0;
88 }
89 return l;
90}
91
Zesstra29da7472021-04-18 11:16:54 +020092varargs int eval_command(mixed input, mixed pinfo)
MG Mud User88f12472016-06-24 23:31:02 +020093{
94 cprompt = "";
Zesstra29da7472021-04-18 11:16:54 +020095 if(stringp(input))
96 switch(input)
MG Mud User88f12472016-06-24 23:31:02 +020097 {
98 case "?":
99 write(MSG_HELP+"\n");
100 return 0;
101 case "b":
102 case "B":
103 pinfo[CURL] -= pinfo[PAGE];
104 break;
105 case "u":
106 case "U":
107 pinfo[CURL] -= pinfo[PAGE] / 2;
108 break;
109 case "f":
110 case "F":
111 pinfo[CURL] += pinfo[PAGE];
112 break;
113 case "d":
114 case "D":
115 pinfo[CURL] += pinfo[PAGE] / 2;
116 break;
117 default:
118 {
119 int l;
Zesstra29da7472021-04-18 11:16:54 +0200120 if(l = to_int(input))
MG Mud User88f12472016-06-24 23:31:02 +0200121 {
122 if(l > pinfo[MAXL] || l < 1) return (cprompt = MSG_ILLEGAL, 0);
123 pinfo[CURL] = l;
124 break;
125 }
Zesstra29da7472021-04-18 11:16:54 +0200126 if(sizeof(input) && input[0] == '/')
MG Mud User88f12472016-06-24 23:31:02 +0200127 {
Zesstra29da7472021-04-18 11:16:54 +0200128 if(sizeof(input) == 1)
MG Mud User88f12472016-06-24 23:31:02 +0200129 {
130 if(!pinfo[REGX]) return (cprompt = MSG_NO_REGX, 0);
131 }
Zesstra29da7472021-04-18 11:16:54 +0200132 else pinfo[REGX] = input[1..];
MG Mud User88f12472016-06-24 23:31:02 +0200133 if(l = search(pinfo)) pinfo[CURL] = l;
134 else return (cprompt = MSG_NOT_FOUND, 0);
135 }
Zesstra29da7472021-04-18 11:16:54 +0200136 else return ::eval_command(input, pinfo);
MG Mud User88f12472016-06-24 23:31:02 +0200137 break;
138 }
139 }
Zesstra29da7472021-04-18 11:16:54 +0200140 else return ::eval_command(input, pinfo);
MG Mud User88f12472016-06-24 23:31:02 +0200141 return ::eval_command(-1, pinfo);
142}