1 implementation module ReadLine
5 import code from "readLine.o"
7 instance toString HistoryItem where
8 toString {line,timestamp} = line +++ " (" +++ timestamp +++ ")"
9 instance toString HistoryState where
10 toString {entries,offset,flags} = "[" +++ toS entries +++ "]\n" +++
11 "offset: " +++ toString offset +++ "\nflags: " +++ toString flags
13 toS :: [HistoryItem] -> String
16 toS [x:xs] = toString x +++ ","
19 readLine :: !String !Bool !*env -> (!Maybe String, !*env)
21 # (s, eof, e) = readLineEof s h e
22 = (if eof Nothing (Just s), e)
24 readLineEof :: !String !Bool !*env -> (!String, !Bool, !*env)
25 readLineEof s h e = code {
26 ccall cleanReadLine "SI:VSI:A"
29 setReadLineName :: !String !*env -> *env
30 setReadLineName s e = code {
31 ccall cleanSetReadLineName "S:V:A"
34 //Initializing History and State Management
35 usingHistory :: !*env -> *env
36 usingHistory e = code {
37 ccall cleanUsingHistory ":V:A"
40 historyGetHistoryState :: !*env -> (!HistoryState, !*env)
41 historyGetHistoryState e
42 # (offset, num, flags, e) = getState e
43 # (entries, e) = getItems num e
44 = ({HistoryState | entries=entries, offset=offset, flags=flags}, e)
46 getState :: !*env -> (!Int, !Int, !Int, !*env)
48 ccall cleanGetState ":VIII:A"
50 getItems :: !Int !*env -> (![HistoryItem], !*env)
51 getItems 0 e = ([], e)
53 # (line, timestamp, e) = getItem (i-1) e
54 # (rest, e) = getItems (i-1) e
55 = ([{line=line,timestamp=timestamp}:rest], e)
57 getItem :: !Int !*env -> (!String, !String, !*env)
59 ccall cleanGetHistoryItem "I:VSS:A"
63 historySetHistoryState :: !HistoryState !*env -> *env
64 historySetHistoryState {entries,offset,flags} e
65 # e = initNewHistoryState offset flags (length entries) e
66 # e = setItems entries 0 e
69 initNewHistoryState :: !Int !Int !Int !*env -> *env
70 initNewHistoryState o f l e = code {
71 ccall cleanInitNewHistoryState "III:V:A"
73 setItems :: ![HistoryItem] !Int !*env -> *env
76 # e = setItem i x.line x.timestamp e
79 setItem :: !Int !String !String !*env -> *env
80 setItem i l t e = code {
81 ccall cleanSetNewHistoryEntry "ISS:V:A"
84 commit :: !*env -> *env
86 ccall cleanCommitSetHistory ":V:A"
89 //History List Management
90 addHistory :: !String !*env -> *env
91 addHistory s e = code {
92 ccall cleanAddHistory "S:V:A"
95 addHistoryTime :: !String !*env -> *env
96 addHistoryTime s e = code {
97 ccall cleanAddHistoryTime "S:V:A"
100 removeHistory :: !Int !*env -> (!HistoryItem, !*env)
102 # (line, timestamp, e) = removeHistoryItem i e
103 = ({HistoryItem | line=line, timestamp=timestamp}, e)
105 removeHistoryItem :: !Int !*env -> (!String, !String, !*env)
106 removeHistoryItem i e = code {
107 ccall cleanRemoveHistory "I:VSS:A"
110 replaceHistoryEntry :: !Int !String !*env -> (!HistoryItem, !*env)
111 replaceHistoryEntry i s e
112 # (line, timestamp, e) = replaceItem i s e
113 = ({HistoryItem | line=line, timestamp=timestamp}, e)
115 replaceItem :: !Int !String !*env -> (!String, !String, !*env)
116 replaceItem i s e = code {
117 ccall cleanReplaceHistoryEntry "IS:VSS:A"
120 clearHistory :: !*env -> *env
121 clearHistory e = code {
122 ccall cleanClearHistory ":V:A"
125 stifleHistory :: !Int !*env -> *env
126 stifleHistory i e = code {
127 ccall cleanStifleHistory "I:V:A"
130 unstifleHistory :: !*env -> *env
131 unstifleHistory e = code {
132 ccall cleanUnstifleHistory ":V:A"
135 historyIsStifled :: !*env -> (!Int, !*env)
136 historyIsStifled e = code {
137 ccall cleanHistoryIsStifled ":I:A"
140 //Information About the History List
141 historyList :: !*env -> (![HistoryItem], !*env)
143 # ({entries,offset,flags}, e) = historyGetHistoryState e
146 whereHistory :: !*env -> (!Int, !*env)
148 # ({entries,offset,flags}, e) = historyGetHistoryState e
151 currentHistory :: !*env -> (!Maybe HistoryItem, !*env)
153 # ({entries,offset,flags}, e) = historyGetHistoryState e
154 = (if (isEmpty entries) Nothing (Just (entries!!offset)), e)
156 historyGet :: !Int !*env -> (!Maybe HistoryItem, !*env)
158 # ({entries,offset,flags}, e) = historyGetHistoryState e
159 = (if (isEmpty entries) Nothing (Just (entries!!i)), e)
161 historyGetTime :: HistoryItem -> String
162 historyGetTime {line,timestamp} = timestamp
164 historyTotalBytes :: !*env -> (!Int, !*env)
165 historyTotalBytes e = code {
166 ccall cleanHistoryTotalBytes ":I:A"
169 //Moving Around the History List
171 //Searching the History List
172 historySearch :: !String !Int !*env-> (!Int, !*env)
173 historySearch s i e = code {
174 ccall cleanHistorySearch "SI:I:A"
177 historySearchPrefix :: !String !Int !*env-> (!Int, !*env)
178 historySearchPrefix s i e = code {
179 ccall cleanHistorySearchPrefix "SI:I:A"
182 historySearchPos :: !String !Int !Int !*env-> (!Int, !*env)
183 historySearchPos s i1 i2 e = code {
184 ccall cleanHistorySearchPos "SI:I:A"
188 //Managing the History File
189 readHistory :: !String !*env -> (!Bool, !*env)
190 readHistory s e = code {
191 ccall cleanReadHistory "S:I:A"
194 readHistoryRange :: !String !Int !Int !*env -> (!Bool, !*env)
195 readHistoryRange s i1 i2 e = code {
196 ccall cleanReadHistoryRange "SII:I:A"
199 writeHistory :: !String !*env -> (!Bool, !*env)
200 writeHistory s e = code {
201 ccall cleanWriteHistory "S:I:A"
204 appendHistory :: !Int !String !*env -> (!Bool, !*env)
205 appendHistory i s e = code {
206 ccall cleanWriteHistory "IS:I:A"
209 historyTruncateFile :: !String !Int !*env -> (!Bool, !*env)
210 historyTruncateFile i s e = code {
211 ccall cleanWriteHistory "SI:I:A"