Commit c2a7fad2 authored by Steffen Michels's avatar Steffen Michels

- add tasks for OS operations like reading/writing text-files, calling...

- add tasks for OS operations like reading/writing text-files, calling external processes and creating directories
- remove superfluous imports from iTasks.icl
- small improvements to formatted text

git-svn-id: https://svn.cs.ru.nl/repos/iTask-system/trunk@979 63da3aa8-80fd-4f01-9db8-e6ea747a3da2
parent ed955bf8
......@@ -147,8 +147,8 @@ formattedText =
where
tasks sid =
[ updateShared "WYSIWYG Editor" [] sid [idEditor]
, updateShared "HTML-Source Editor" [] sid [editor { editorFrom = \(FormattedText src _) -> Note src
, editorTo = \(Note src) (FormattedText _ ctrls) -> FormattedText src ctrls
, updateShared "HTML-Source Editor" [] sid [editor { editorFrom = \ft -> Note (getFormattedTextSrc ft)
, editorTo = \(Note src) ft -> setFormattedTextSrc src ft
}]
, updateShared "Formatted Preview" [] sid [idListener]
, updateShared "Unformatted Preview" [] sid [listener {listenerFrom = \ft -> Note (toUnformattedString ft)}]
......
This diff was suppressed by a .gitattributes entry.
definition module OSTasks
import iTasks
:: Path :== String
// Exceptions
:: FileException = FileException !Path !FileProblem
:: FileProblem = CannotOpen | CannotClose | IOError
:: CallException = CallFailed !Path
:: DirectoryException = CannotCreate
derive gPrint FileException, FileProblem, CallException
derive gParse FileException, FileProblem, CallException
derive gVisualize FileException, FileProblem, CallException
derive gUpdate FileException, FileProblem, CallException
/**
* Calls an external executable. The call is blocking and should only
* be used for executables terminating within a very short time.
*
* @param path to the executable
* @return return-code of the process
* @throws CallException
*/
callProcess :: !Path -> Task Int
/**
* Reads a textfile from disc.
*
* @param path to the file
* @return content of the file
* @throws FileException
*/
readTextFile :: !Path -> Task String
/**
* Writes string to a textfile.
*
* @param path to the file
* @param string written to file
* @throws FileException
*/
writeTextFile :: !String !Path -> Task Void
/**
* Checks if a file exists.
*
* @param path to the file
* @return True if file exists
*/
fileExists :: !Path -> Task Bool
/**
* Checks if a file is a directory.
*
* @param path to the file
* @return True if file exists and is a directory
*/
isDirectory :: !Path -> Task Bool
/**
* Creates a directory.
*
* @param path of directory to create; only final dir in path is created, intermediate ones have to exist
* @throws DirectoryException
*/
createDirectory :: !Path -> Task Void
/**
* Returns the path of the iTasks-server executable.
*
* @return path of the iTasks-server executable
*/
getAppPath :: Task String
implementation module OSTasks
import iTasks, TSt, ostoolbox, clCCall_12, StdFile, Text
import code from "OSTasksC."
derive gPrint FileException, FileProblem, CallException
derive gParse FileException, FileProblem, CallException
derive gVisualize FileException, FileProblem, CallException
derive gUpdate FileException, FileProblem, CallException
derive bimap Maybe, (,)
callProcess :: !Path -> Task Int
callProcess cmd = mkInstantTask "callProcess" callProcess`
where
callProcess` tst=:{TSt|world}
# (os,world) = worldGetToolbox world
# (ccmd,os) = winMakeCString cmd os
# (succ,ret,os) = winCallProcess ccmd 0 0 0 0 0 os
# os = winReleaseCString ccmd os
# world = worldSetToolbox os world
# tst = {TSt|tst & world = world}
| not succ = (TaskException (dynamic (CallFailed cmd)), tst)
| otherwise = (TaskFinished ret, tst)
readTextFile :: !Path -> Task String
readTextFile path = mkInstantTask "readTextFile" readTextFile`
where
readTextFile` tst=:{TSt|world}
# (ok,file,world) = fopen path FReadText world
| not ok = (TaskException (fileException CannotOpen),{TSt | tst & world = world})
# (mbStrAcc,file) = readFile file []
# (ok,world) = fclose file world
# tst = {TSt | tst & world = world}
= case mbStrAcc of
Nothing = (TaskException (fileException IOError),tst)
Just strAcc
| not ok = (TaskException (fileException CannotClose),tst)
| otherwise = (TaskFinished (foldr (+++) "" (reverse strAcc)),tst)
fileException prob = (dynamic (FileException path prob))
readFile file acc
# (str,file) = freads file 1024
# (err,file) = ferror file
| err = (Nothing,file)
# (eof,file) = fend file
| eof = (Just [str:acc],file)
| otherwise = readFile file [str:acc]
writeTextFile :: !String !Path -> Task Void
writeTextFile path text = mkInstantTask "writeTextFile" writeTextFile`
where
writeTextFile` tst=:{TSt|world}
# (ok,file,world) = fopen path FWriteText world
| not ok = (TaskException (fileException CannotOpen),{TSt | tst & world = world})
# file = fwrites text file
# (err,file) = ferror file
# (ok,world) = fclose file world
# tst = {TSt | tst & world = world}
| err = (TaskException (fileException IOError),tst)
| not ok = (TaskException (fileException CannotClose),tst)
| otherwise = (TaskFinished Void,tst)
fileException prob = (dynamic (FileException path prob))
fileExists :: !Path -> Task Bool
fileExists path = mkInstantTask "fileExists" (\tst -> (TaskFinished (winFileExists path), tst))
isDirectory :: !Path -> Task Bool
isDirectory path = return (winIsDirectory path)
where
winIsDirectory :: !{#Char} -> Bool
winIsDirectory _ = code
{
.inline WinIsDirectory
ccall WinIsDirectory "S-I"
.end
}
createDirectory :: !Path -> Task Void
createDirectory path = if (winCreateDirectory path) stop (throw CannotCreate)
where
winCreateDirectory :: !{#Char} -> Bool
winCreateDirectory _ = code
{
.inline WinCreateDirectory
ccall WinCreateDirectory "S-I"
.end
}
getAppPath :: Task String
getAppPath = mkInstantTask "getAppPath" getAppPath`
where
getAppPath` tst=:{TSt|world}
# (os,world) = worldGetToolbox world
# cstr = winGetAppPath
# (path,os) = winGetCStringAndFree cstr os
# world = worldSetToolbox os world
= (TaskFinished path, {TSt|tst & world = world})
#include "..\..\..\..\..\..\Libraries\ObjectIO\OS Windows\Windows_C_12\util_121.h"
Bool WinIsDirectory(CLEAN_STRING name) {
WIN32_FIND_DATA find_data;
HANDLE handle = FindFirstFile(cstring(name), &find_data);
if (handle != INVALID_HANDLE_VALUE) {
FindClose(handle);
return find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
}
else
return FALSE;
}
Bool WinCreateDirectory (CLEAN_STRING name) {
return CreateDirectory(cstring (name), NULL);
}
......@@ -31,6 +31,8 @@ import GenCopy
}
mkEmptyFormattedText :: FormattedTextControls -> FormattedText
setFormattedTextSrc :: !String !FormattedText -> FormattedText
getFormattedTextSrc :: !FormattedText -> String
allControls :: FormattedTextControls
noControls :: FormattedTextControls
toUnformattedString :: FormattedText -> String
......
......@@ -258,7 +258,9 @@ where
toUnformattedString :: FormattedText -> String
toUnformattedString (FormattedText s _)
# s = replaceSubString "<br>" "\n" s
# s = replaceSubString "<BR>" "\n" s
# s = replaceSubString "</li>" "\n" s
# s = replaceSubString "&nbsp;" " " s
# s = stripHtmlTags s
= s
where
......@@ -354,6 +356,12 @@ decFormat x = toString (x / 100) +++ "." +++ pad 2 (x rem 100)
mkEmptyFormattedText :: FormattedTextControls -> FormattedText
mkEmptyFormattedText controls = FormattedText "" controls
setFormattedTextSrc :: !String !FormattedText -> FormattedText
setFormattedTextSrc cont (FormattedText _ controls) = FormattedText cont controls
getFormattedTextSrc :: !FormattedText -> String
getFormattedTextSrc (FormattedText src _) = src
allControls :: FormattedTextControls
allControls = { alignmentControls = True
, colorControls = True
......
......@@ -18,7 +18,8 @@ import Engine // basic iTask system creator
, DateTimeTasks // tasks triggered by date and time
, ChangeTasks // Tasks for changing existing workflows
, MenuTasks
, MenuTasks // tasks for setting/changing the menu structure of a process
, OSTasks // tasks for OS operations like reading/writing files or calling external processes
// Task combinators
, CoreCombinators // The core iTask combinators
......
implementation module iTasks
import Engine // basic iTask system creator
, EngineWrapperStandalone // standalone wrapper
//, EngineWrapperCGI // CGI wrapper
// Basic tasks
, InteractionTasks // tasks for interaction with users
, SystemTasks // tasks for interaction with the iTasks system itself
, StoreTasks // tasks for accessing the generic store
, UserDBTasks // tasks for accessing the user database
, SessionDBTasks // tasks for accessing the session database
, ProcessDBTasks // tasks for accessing the process database
, DateTimeTasks // tasks triggered by date and time
, ChangeTasks // Tasks for changing existing workflows
// Task combinators
, CoreCombinators // The core iTask combinators
, CommonCombinators // Set of additional useful iTask combinators
, LiftingCombinators // Lifting of other domains (e.g. World) to the iTask domain
, ExceptionCombinators // Handling exceptional situations
, TuningCombinators // Fine tuning of tasks
// Miscellaneous machinery
, Util
, GenVisualize // Functions for generating GUIs
, GenUpdate // Functions for updating arbitrary values
//StdEnv modules
, StdInt
, StdBool
, StdString
, StdList
, StdOrdList
, StdTuple
, StdEnum
, StdOverloaded
, StdArray
, StdGeneric
, StdDynamic
//Generic modules
, GenPrint
, GenParse
\ No newline at end of file
import GenPrint, GenParse, GenUpdate, GenVisualize
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment