1 implementation module ReadLine
6 import code from "readLine.o"
8 instance toString HistoryItem where
9 toString {line,timestamp} = line +++ " (" +++ timestamp +++ ")"
10 instance toString HistoryState where
11 toString {entries,offset,flags} = "[" +++ toS entries +++ "]\n" +++
12 "offset: " +++ toString offset +++ "\nflags: " +++ toString flags
14 toS :: [HistoryItem] -> String
17 toS [x:xs] = toString x +++ ","
20 readLine :: !String !Bool !*env -> (!Maybe String, !*env)
22 # (s, eof, e) = readLineEof s h e
23 = (if eof Nothing (Just s), e)
25 readLineEof :: !String !Bool !*env -> (!String, !Bool, !*env)
26 readLineEof s h e = code {
27 ccall cleanReadLine "SI:VSI:A"
30 setReadLineName :: !String !*env -> *env
31 setReadLineName s e = code {
32 ccall cleanSetReadLineName "S:V:A"
35 //Initializing History and State Management
36 usingHistory :: !*env -> *env
37 usingHistory e = code {
38 ccall cleanUsingHistory ":V:A"
41 historyGetHistoryState :: !*env -> (!HistoryState, !*env)
42 historyGetHistoryState e
43 # (offset, num, flags, e) = getState e
44 # (entries, e) = getItems num e
45 = ({HistoryState | entries=entries, offset=offset, flags=flags}, e)
47 getState :: !*env -> (!Int, !Int, !Int, !*env)
49 ccall cleanGetState ":VIII:A"
51 getItems :: !Int !*env -> (![HistoryItem], !*env)
52 getItems 0 e = ([], e)
54 # (line, timestamp, e) = getItem (i-1) e
55 # (rest, e) = getItems (i-1) e
56 = ([{line=line,timestamp=timestamp}:rest], e)
58 getItem :: !Int !*env -> (!String, !String, !*env)
60 ccall cleanGetHistoryItem "I:VSS:A"
64 historySetHistoryState :: !HistoryState !*env -> *env
65 historySetHistoryState {entries,offset,flags} e
66 # e = initNewHistoryState offset flags (length entries) e
67 # e = setItems entries 0 e
70 initNewHistoryState :: !Int !Int !Int !*env -> *env
71 initNewHistoryState o f l e = code {
72 ccall cleanInitNewHistoryState "III:V:A"
74 setItems :: ![HistoryItem] !Int !*env -> *env
77 # e = setItem i x.line x.timestamp e
80 setItem :: !Int !String !String !*env -> *env
81 setItem i l t e = code {
82 ccall cleanSetNewHistoryEntry "ISS:V:A"
85 commit :: !*env -> *env
87 ccall cleanCommitSetHistory ":V:A"
90 //History List Management
91 addHistory :: !String !*env -> *env
92 addHistory s e = code {
93 ccall cleanAddHistory "S:V:A"
96 addHistoryTime :: !String !*env -> *env
97 addHistoryTime s e = code {
98 ccall cleanAddHistoryTime "S:V:A"
101 removeHistory :: !Int !*env -> (!HistoryItem, !*env)
103 # (line, timestamp, e) = removeHistoryItem i e
104 = ({HistoryItem | line=line, timestamp=timestamp}, e)
106 removeHistoryItem :: !Int !*env -> (!String, !String, !*env)
107 removeHistoryItem i e = code {
108 ccall cleanRemoveHistory "I:VSS:A"
111 replaceHistoryEntry :: !Int !String !*env -> (!HistoryItem, !*env)
112 replaceHistoryEntry i s e
113 # (line, timestamp, e) = replaceItem i s e
114 = ({HistoryItem | line=line, timestamp=timestamp}, e)
116 replaceItem :: !Int !String !*env -> (!String, !String, !*env)
117 replaceItem i s e = code {
118 ccall cleanReplaceHistoryEntry "IS:VSS:A"
121 clearHistory :: !*env -> *env
122 clearHistory e = code {
123 ccall cleanClearHistory ":V:A"
126 stifleHistory :: !Int !*env -> *env
127 stifleHistory i e = code {
128 ccall cleanStifleHistory "I:V:A"
131 unstifleHistory :: !*env -> *env
132 unstifleHistory e = code {
133 ccall cleanUnstifleHistory ":V:A"
136 historyIsStifled :: !*env -> (!Int, !*env)
137 historyIsStifled e = code {
138 ccall cleanHistoryIsStifled ":I:A"
141 //Information About the History List
142 historyList :: !*env -> (![HistoryItem], !*env)
144 # ({entries,offset,flags}, e) = historyGetHistoryState e
147 whereHistory :: !*env -> (!Int, !*env)
149 # ({entries,offset,flags}, e) = historyGetHistoryState e
152 currentHistory :: !*env -> (!Maybe HistoryItem, !*env)
154 # ({entries,offset,flags}, e) = historyGetHistoryState e
155 = (if (isEmpty entries) Nothing (Just (entries!!offset)), e)
157 historyGet :: !Int !*env -> (!Maybe HistoryItem, !*env)
159 # ({entries,offset,flags}, e) = historyGetHistoryState e
160 = (if (isEmpty entries) Nothing (Just (entries!!i)), e)
162 historyGetTime :: HistoryItem -> String
163 historyGetTime {line,timestamp} = timestamp
165 historyTotalBytes :: !*env -> (!Int, !*env)
166 historyTotalBytes e = code {
167 ccall cleanHistoryTotalBytes ":I:A"
170 //Moving Around the History List
171 historySetPos :: !Int !*env -> (!Int, !*env)
172 historySetPos i e = code {
173 ccall cleanHistorySetPos "I:I:A"
176 previousHistory :: !*env -> (!Maybe HistoryItem, !*env)
178 # (line, timestamp, null, e) = previousHistoryItem e
179 = (if null Nothing (Just {HistoryItem | line=line, timestamp=timestamp}), e)
181 previousHistoryItem :: !*env -> (!String, !String, !Bool, !*env)
182 previousHistoryItem e = code {
183 ccall cleanPreviousHistory ":VSSI:A"
186 nextHistory :: !*env -> (!Maybe HistoryItem, !*env)
188 # (line, timestamp, null, e) = nextHistoryItem e
189 = (if null Nothing (Just {HistoryItem | line=line, timestamp=timestamp}), e)
191 nextHistoryItem :: !*env -> (!String, !String, !Bool, !*env)
192 nextHistoryItem e = code {
193 ccall cleanNextHistory ":VSSI:A"
196 //Searching the History List
197 historySearch :: !String !Int !*env-> (!Int, !*env)
198 historySearch s i e = code {
199 ccall cleanHistorySearch "SI:I:A"
202 historySearchPrefix :: !String !Int !*env-> (!Int, !*env)
203 historySearchPrefix s i e = code {
204 ccall cleanHistorySearchPrefix "SI:I:A"
207 historySearchPos :: !String !Int !Int !*env-> (!Int, !*env)
208 historySearchPos s i1 i2 e = code {
209 ccall cleanHistorySearchPos "SI:I:A"
213 //Managing the History File
214 readHistory :: !String !*env -> (!Bool, !*env)
215 readHistory s e = code {
216 ccall cleanReadHistory "S:I:A"
219 readHistoryRange :: !String !Int !Int !*env -> (!Bool, !*env)
220 readHistoryRange s i1 i2 e = code {
221 ccall cleanReadHistoryRange "SII:I:A"
224 writeHistory :: !String !*env -> (!Bool, !*env)
225 writeHistory s e = code {
226 ccall cleanWriteHistory "S:I:A"
229 appendHistory :: !Int !String !*env -> (!Bool, !*env)
230 appendHistory i s e = code {
231 ccall cleanWriteHistory "IS:I:A"
234 historyTruncateFile :: !String !Int !*env -> (!Bool, !*env)
235 historyTruncateFile i s e = code {
236 ccall cleanWriteHistory "SI:I:A"
239 historyExpand :: !String !*env -> (!String, !Int, !*env)
240 historyExpand s e = code {
241 ccall cleanHistoryExpand "S:VSI:A"
244 getHistoryEvent :: !String !Int !Int !*env -> (!Maybe String, !Int, !*env)
245 getHistoryEvent s i1 i2 e
246 # (string, cindex, null, e) = getHistoryEventItem s i1 i2 e
247 = (if null Nothing (Just string), cindex, e)
249 getHistoryEventItem :: !String !Int !Int !*env -> (!String, !Int, !Bool, !*env)
250 getHistoryEventItem s i1 i2 e = code {
251 ccall cleanGetHistoryEvent "SII:VSII:A"
254 historyTokenize :: !String !*env -> ([String], !*env)
256 # (i, e) = historyTokenizeInit s e
257 = historyTokenizeItems i e
260 historyTokenizeInit :: !String !*env -> (!Int, !*env)
261 historyTokenizeInit s e = code {
262 ccall cleanHistoryTokenizeInit "S:I:A"
265 historyTokenizeItems :: !Int !*env -> (![String], !*env)
266 historyTokenizeItems 0 e = ([], e)
267 historyTokenizeItems i e
268 # (token, e) = historyTokenizeItem (i-1) e
269 # (rest, e) = historyTokenizeItems (i-1) e
272 historyTokenizeItem :: !Int !*env -> (!String, !*env)
273 historyTokenizeItem i e = code {
274 ccall cleanHistoryTokenizeItem "I:S:A"
277 historyArgExtract :: !Int !Int !String !*env -> (!Maybe String, !*env)
278 historyArgExtract i1 i2 s e
279 # (string, null, e) = historyArgExtractItem i1 i2 s e
280 = (if null Nothing (Just string), e)
282 historyArgExtractItem :: !Int !Int !String !*env -> (!String, !Bool, !*env)
283 historyArgExtractItem i1 i2 s e = code {
284 ccall cleanHistoryArgExtract "IIS:VSI:A"