From: Mart Lubbers Date: Mon, 25 Jan 2016 17:42:03 +0000 (+0100) Subject: history state added X-Git-Tag: v0.3^2~16 X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=94274704fe7af02aa09174a36a4f9b84501ea738;p=CleanReadLine.git history state added --- diff --git a/Clean System Files/readLine.c b/Clean System Files/readLine.c index b72d31a..c81e7db 100644 --- a/Clean System Files/readLine.c +++ b/Clean System Files/readLine.c @@ -56,6 +56,28 @@ void cleanUsingHistory(){ using_history(); } +void cleanGetState(int *offset, int *num, int *flags){ + *offset = history_get_history_state()->offset; + *num = history_get_history_state()->length; + *flags = history_get_history_state()->flags; +} + +void cleanGetHistoryItem(int num, CleanString *line, CleanString *timestamp){ + ; + char *cs_line = history_get_history_state()->entries[num]->line; + char *cs_stamp = history_get_history_state()->entries[num]->timestamp; + + CleanStringVariable(cleanLine, strlen(cs_line)); + *line = (CleanString) cleanLine; + memcpy(CleanStringCharacters(cleanLine), cs_line, strlen(cs_line)); + CleanStringLength(cleanLine) = strlen(cs_line); + + CleanStringVariable(cleanTimestamp, strlen(cs_stamp)); + *timestamp = (CleanString) cleanTimestamp; + memcpy(CleanStringCharacters(cleanTimestamp), cs_stamp, strlen(cs_stamp)); + CleanStringLength(cleanTimestamp) = strlen(cs_stamp); +} + void cleanAddHistory(CleanString entry){ char *cs_entry = cleanStringToCString(entry); add_history(cs_entry); diff --git a/ReadLine.dcl b/ReadLine.dcl index ecc58bf..5e529c1 100644 --- a/ReadLine.dcl +++ b/ReadLine.dcl @@ -1,5 +1,9 @@ definition module ReadLine +:: HistoryItem = {line :: String, timestamp :: String} + +:: HistoryState = {entries :: [HistoryItem], offset :: Int, flags :: Int} + //Readline readLine :: !String !Bool !*env -> (!String, !*env) setReadLineName :: !String !*env -> !*env @@ -8,6 +12,8 @@ setReadLineName :: !String !*env -> !*env //Note that this HAS to be executed when you want to add entries when the //history has not been used usingHistory :: !*env -> !*env +historyGetHistoryState :: !*env -> (!HistoryState, !*env) +historySetHistoryState :: !HistoryState !*env -> !*env //History List Management addHistory :: !String !*env -> !*env diff --git a/ReadLine.icl b/ReadLine.icl index 4bb84d1..cb4cfbb 100644 --- a/ReadLine.icl +++ b/ReadLine.icl @@ -21,6 +21,32 @@ usingHistory e = code inline { ccall cleanUsingHistory "-" } +historyGetHistoryState :: !*env -> (!HistoryState, !*env) +historyGetHistoryState e +# (offset, num, flags, e) = getState e +# (entries, e) = getItems num e += ({HistoryState | entries=entries, offset=offset, flags=flags}, e) + where + getState :: !*env -> (!Int, !Int, !Int, !*env) + getState e= code inline { + ccall cleanGetState "-III" + } + getItems :: !Int !*env -> (![HistoryItem], !*env) + getItems 0 e = ([], e) + getItems i e + # (line, timestamp, e) = getItem (i-1) e + # (rest, e) = getItems (i-1) e + = ([{line=line,timestamp=timestamp}:rest], e) + + getItem :: !Int !*env -> (!String, !String, !*env) + getItem i e = code inline { + ccall cleanGetHistoryItem "I-SS" + } + + +historySetHistoryState :: !HistoryState !*env -> !*env +historySetHistoryState hs e = abort "Not Implemented" + //History List Management addHistory :: !String !*env -> !*env addHistory s e = code inline { diff --git a/test.icl b/test.icl index 729c126..43f867d 100644 --- a/test.icl +++ b/test.icl @@ -3,7 +3,7 @@ module test import StdEnv import ReadLine -Start :: *World -> (Int, String, *World) +Start :: *World -> (Int, String, HistoryState, *World) Start w # (f, w) = stdio w #! w = setReadLineName "Test program" w @@ -14,5 +14,6 @@ Start w #! (s, w) = readLine "uparrow should word with history: " False w #! (_, w) = writeHistory "readline.history" w #! (i, w) = historySearch "testentry" -1 w -//#! w = clearHistory w -= (i, s, w) +#! (h, w) = historyGetHistoryState w +#! w = clearHistory w += (i, s, h, w)