SaC Standard Library Interface
1 Utrace
1.1 UTrace.sac
/*-----------------------------------------------*/
module UTrace;
export all except { PrintSeparator, PrintHeader, Indent};
use StdIO : all;
use Structures : all;
use ArrayFormat : all;
use Indent : all;
/*
* global objects
*/
Indent offset = newIndent( 0) ;
/*
* function definitions (FUNDEFS)
*/
/****************************************************************************
* PrintSeparator(...) [ body ]
****************************************************************************/
void PrintSeparator( string pattern)
/****************************************************************************
* PrintHeader(...) [ body ]
****************************************************************************/
void PrintHeader( string modName, int line)
/****************************************************************************
* PrintFunEnter(...) [ body ]
****************************************************************************/
void PrintFunEnter( string modName, int line, string funName)
/****************************************************************************
* PrintFunLeave(...) [ body ]
****************************************************************************/
void PrintFunLeave( string modName, int line, string funName)
/****************************************************************************
* PrintArgsDone(...) [ body ]
****************************************************************************/
void PrintArgsDone( string modName, int line, string funName)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( int[+] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( int[.,.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( int[.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( int arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( float[+] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( float[.,.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( float[.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( float arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( double[+] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( double[.,.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( double[.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( double arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( bool[+] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( bool[.,.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( bool[.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( bool arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( char[+] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( char[.,.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( char[.] arr)
/****************************************************************************
* indentedShow(...) [ body ]
****************************************************************************/
void indentedShow( char arr)
/****************************************************************************
* PrintArg(...) [ body ]
****************************************************************************/
void PrintArg( string modName, int line, string var, int[*] x)
/****************************************************************************
* PrintArg(...) [ body ]
****************************************************************************/
void PrintArg( string modName, int line, string var, float[*] x)
/****************************************************************************
* PrintArg(...) [ body ]
****************************************************************************/
void PrintArg( string modName, int line, string var, double[*] x)
/****************************************************************************
* PrintArg(...) [ body ]
****************************************************************************/
void PrintArg( string modName, int line, string var, bool[*] x)
/****************************************************************************
* PrintArg(...) [ body ]
****************************************************************************/
void PrintArg( string modName, int line, string var, char[*] x)
/****************************************************************************
* PrintAssign(...) [ body ]
****************************************************************************/
void PrintAssign( string modName, int line, string var, int[*] x)
/****************************************************************************
* PrintAssign(...) [ body ]
****************************************************************************/
void PrintAssign( string modName, int line, string var, float[*] x)
/****************************************************************************
* PrintAssign(...) [ body ]
****************************************************************************/
void PrintAssign( string modName, int line, string var, double[*] x)
/****************************************************************************
* PrintAssign(...) [ body ]
****************************************************************************/
void PrintAssign( string modName, int line, string var, bool[*] x)
/****************************************************************************
* PrintAssign(...) [ body ]
****************************************************************************/
void PrintAssign( string modName, int line, string var, char[*] x)
/****************************************************************************
* PrintReturn(...) [ body ]
****************************************************************************/
void PrintReturn( string modName, int line, int[*] x)
/****************************************************************************
* PrintReturn(...) [ body ]
****************************************************************************/
void PrintReturn( string modName, int line, float[*] x)
/****************************************************************************
* PrintReturn(...) [ body ]
****************************************************************************/
void PrintReturn( string modName, int line, double[*] x)
/****************************************************************************
* PrintReturn(...) [ body ]
****************************************************************************/
void PrintReturn( string modName, int line, bool[*] x)
/****************************************************************************
* PrintReturn(...) [ body ]
****************************************************************************/
void PrintReturn( string modName, int line, char[*] x)
/*-----------------------------------------------*/
1.2 Indent.sac
/*-----------------------------------------------*/
class Indent;
export all;
use StdIO : all;
use Structures : all;
/*
* type definitions
*/
classtype int Indent::Indent;
/*
* global objects
*/
Indent indent = to_Indent( 0) ;
/*
* function definitions (FUNDEFS)
*/
/****************************************************************************
* newIndent(...) [ body ]
****************************************************************************/
Indent newIndent( int value)
/****************************************************************************
* getIndent(...) [ body ]
****************************************************************************/
int getIndent()
/****************************************************************************
* getIndent(...) [ body ]
****************************************************************************/
int getIndent( Indent &i)
/****************************************************************************
* setIndent(...) [ body ]
****************************************************************************/
void setIndent( Indent &i, int val)
/****************************************************************************
* doIndent(...) [ body ]
****************************************************************************/
void doIndent( string pattern)
/****************************************************************************
* doIndent(...) [ body ]
****************************************************************************/
void doIndent( Indent &i, string pattern)
/****************************************************************************
* incIndent(...) [ body ]
****************************************************************************/
void incIndent( Indent &i)
/****************************************************************************
* incIndent(...) [ body ]
****************************************************************************/
void incIndent( Indent &i, int offset)
/****************************************************************************
* incIndent(...) [ body ]
****************************************************************************/
void incIndent()
/****************************************************************************
* decIndent(...) [ body ]
****************************************************************************/
void decIndent( Indent &i)
/****************************************************************************
* decIndent(...) [ body ]
****************************************************************************/
void decIndent( Indent &i, int offset)
/****************************************************************************
* decIndent(...) [ body ]
****************************************************************************/
void decIndent()
/*-----------------------------------------------*/
2 System
2.1 World.sac
/*-----------------------------------------------*/
class World;
export all except { create_TheWorld};
/*
* type definitions
*/
external classtype World::World;
/*
* prototypes for externals (FUNDECS)
*/
/*\n * The global object TheWorld of class World serves as a representation of the\n * execution environment. It provides access to resources residing\n * outside the functional framework of a SAC program.\n *\n * In order to allow concurrent access to unrelated parts of the\n * execution environment, some other predefined global objects are \n * derived from world upon program start. These represent disjoint\n * partitions of the execution environment or outside world.\n *\n * These are: - TheTerminal\n * - TheFileSys\n * - TheEnvironment\n * - TheCommandLine\n * - TheClock\n */external World create_TheWorld();
/*
* global objects
*/
World TheWorld = create_TheWorld() ;
/*-----------------------------------------------*/
2.2 TimeStamp.sac
/*-----------------------------------------------*/
module TimeStamp;
export all;
/*
* prototypes for externals (FUNDECS)
*/
external void timeStamp();
#pragma effect World::TheWorld
/*-----------------------------------------------*/
2.3 Terminal.sac
/*-----------------------------------------------*/
class Terminal;
export all except { create_TheTerminal};
/*
* type definitions
*/
external classtype Terminal::Terminal;
/*
* prototypes for externals (FUNDECS)
*/
/*\n * The global object TheTerminal of class Terminal serves as a representation\n * for a terminal screen. It is derived from the global object TheWorld in\n * order to represent this part or sub-world of the execution environment.\n * It is also used to synchronise the standard I/O streams stdin, stdout,\n * and stderr.\n */external Terminal create_TheTerminal();
#pragma effect World::TheWorld
/*
* global objects
*/
Terminal TheTerminal = create_TheTerminal() ;
/*-----------------------------------------------*/
2.4 System.sac
/*-----------------------------------------------*/
module System;
import World : all;
import Terminal : all;
import FileSystem : all;
import CommandLine : all;
import Environment : all;
import Clock : all;
import SysErr : all;
import RuntimeError : all;
export all;
/*-----------------------------------------------*/
2.5 SysErr.sac
/*-----------------------------------------------*/
module SysErr;
use String : { string};
export all;
/*
* type definitions
*/
typedef int syserr;
/*
* prototypes for externals (FUNDECS)
*/
external bool fail( syserr ERROR);
external bool clear( syserr ERROR);
/*\n * Check if the error condition produced by a call to a system function\n * signals success or failure.\n */external string strerror( syserr ERROR);
/* file system errors */external syserr Eperm();
external syserr Enoent();
external syserr Esrch();
external syserr Eintr();
external syserr Eio();
external syserr Enxio();
external syserr E2big();
external syserr Enoexec();
external syserr Ebadf();
external syserr Echild();
external syserr Eagain();
external syserr Enomem();
external syserr Eacces();
external syserr Efault();
external syserr Enotblk();
external syserr Ebusy();
external syserr Eexist();
external syserr Exdev();
external syserr Enodev();
external syserr Enotdir();
external syserr Eisdir();
external syserr Einval();
external syserr Enfile();
external syserr Emfile();
external syserr Enotty();
external syserr Etxtbsy();
external syserr Efbig();
external syserr Enospc();
external syserr Espipe();
external syserr Erofs();
external syserr Emlink();
external syserr Epipe();
external syserr Eloop();
external syserr Enametoolong();
/* operational errors */external syserr Enetdown();
external syserr Enetunreach();
external syserr Enetreset();
external syserr Econnaborted();
external syserr Econnreset();
external syserr Enobufs();
external syserr Eisconn();
external syserr Enotconn();
external syserr Eshutdown();
external syserr Etoomanyrefs();
external syserr Etimedout();
external syserr Econnrefused();
/* should be rearranged */external syserr Ehostdown();
external syserr Ehostunreach();
external syserr Enotempty();
/* quotas & mush */external syserr Eusers();
external syserr Edquot();
/* Network File System */external syserr Estale();
external syserr Eremote();
/*-----------------------------------------------*/
2.6 RuntimeError.sac
/*-----------------------------------------------*/
module RuntimeError;
export all;
/*
* prototypes for externals (FUNDECS)
*/
external void error( int result, String::string message, ...);
#pragma effect Terminal::TheTerminal
/*-----------------------------------------------*/
2.7 RTimer.sac
/*-----------------------------------------------*/
class RTimer;
use RTClock : all;
export all;
/*
* type definitions
*/
external classtype RTimer::RTimer;
/*
* prototypes for externals (FUNDECS)
*/
external RTimer createRTimer();
#pragma effect RTClock::TheRTClock
external void destroyRTimer( RTimer rtimer);
#pragma effect RTClock::TheRTClock
external void startRTimer( RTimer &rtimer);
#pragma effect RTClock::TheRTClock
external void stopRTimer( RTimer &rtimer);
#pragma effect RTClock::TheRTClock
external void resetRTimer( RTimer &rtimer);
external int, int getRTimerInts( RTimer &rtimer);
external double getRTimerDbl( RTimer &rtimer);
/*-----------------------------------------------*/
2.8 RTClock.sac
/*-----------------------------------------------*/
class RTClock;
export { TheRTClock, touch, gettime};
/*
* type definitions
*/
external classtype RTClock::RTClock;
/*
* prototypes for externals (FUNDECS)
*/
external RTClock createTheRTClock();
#pragma effect World::TheWorld
external void touch( RTClock &rtclock);
external long, long gettime();
#pragma effect RTClock::TheRTClock
/*
* global objects
*/
RTClock TheRTClock = createTheRTClock() ;
/*-----------------------------------------------*/
2.9 Process.sac
/*-----------------------------------------------*/
module Process;
use FileSystem : { TheFileSystem};
use File : { File};
use String : { string};
use SysErr : { syserr};
export all;
/*
* prototypes for externals (FUNDECS)
*/
/*\n * Functions to open and close processes.\n */external syserr, File popen( string COMMAND, string MODE);
#pragma effect TheFileSystem
/*\n * Open the process COMMAND in mode MODE. The modes supported are identical\n * to the C version of this function. An error condition and a process\n * handle are returned. You should inspect the error condition before\n * using the process handle. The process handle must be closed by pclose.\n */external void pclose( File STREAM);
#pragma effect TheFileSystem
external int system( string COMMAND);
#pragma effect TheFileSystem
/*-----------------------------------------------*/
2.10 MTClock.sac
/*-----------------------------------------------*/
class MTClock;
export { TheMTClock, touch, gettime};
/*
* type definitions
*/
external classtype MTClock::MTClock;
/*
* prototypes for externals (FUNDECS)
*/
external MTClock createTheMTClock();
#pragma effect World::TheWorld
external void touch( MTClock &mtclock);
external long, long gettime();
#pragma effect MTClock::TheMTClock
/*
* global objects
*/
MTClock TheMTClock = createTheMTClock() ;
/*-----------------------------------------------*/
2.11 GetOpt.sac
/*-----------------------------------------------*/
module GetOpt;
use String : { string};
use CommandLine : { TheCommandLine};
export all;
/*
* prototypes for externals (FUNDECS)
*/
external char getopt( string opts);
#pragma effect TheCommandLine
/*\n * Return the next command line option using the options given in \’opts\’.\n * If the option requires an argument then this is available by optarg().\n * If no more options are available then getopt returns optEND().\n * See the manual page for getopt(3) for more details.\n */external char optEND();
/*\n * Return the option character that is used to signal end-of-options.\n */external string optarg();
#pragma effect TheCommandLine
/*\n * Retrieve the argument to the current option.\n * If the option doesn\’t require an argument then this is empty.\n */external char optopt();
#pragma effect TheCommandLine
/*\n * Retrieve the last option value.\n */external int optind();
#pragma effect TheCommandLine
/*\n * Return the current index into argv.\n */external void optind( int set);
#pragma effect TheCommandLine
/*\n * Set or reset the current option index into argv.\n */external bool opterr();
#pragma effect TheCommandLine
/*\n * Query if option error reporting is enabled.\n */external void opterr( bool set);
#pragma effect TheCommandLine
/*-----------------------------------------------*/
2.12 FileSystem.sac
/*-----------------------------------------------*/
class FileSystem;
use SysErr : { syserr};
use String : { string};
export all;
/*
* type definitions
*/
external classtype FileSystem::FileSystem;
/*
* prototypes for externals (FUNDECS)
*/
/*\n * The global object TheFileSys of class FileSys serves as a representation\n * for a file system. It is derived from the global object world in\n * order to represent this part or sub-world of the execution environment.\n */external FileSystem create_TheFileSystem();
#pragma effect World::TheWorld
external syserr rename( string OLDNAME, string NEWNAME);
#pragma effect TheFileSystem
/*\n * Rename file OLDNAME to NEWNAME. \n */external syserr remove( string PATHNAME);
#pragma effect TheFileSystem
/*\n * Remove the file given by PATHNAME from the file system. \n */external syserr symlink( string PATHNAME, string LINKNAME);
#pragma effect TheFileSystem
/*\n * Create a symbolic link to file PATHNAME which is called LINKNAME. \n */external bool, syserr access( string PATHNAME, int HOW);
#pragma effect TheFileSystem
/*\n * Test if access to file PATHNAME is granted.\n * HOW specifies the type of access tested:\n * 0: existence\n * 1: read access\n * 2: write access\n * 3: execution access \n *\n * In contrast to C, the result is true iff access is granted.\n */external bool, syserr isdir( string PATHNAME);
#pragma effect TheFileSystem
/*\n * Test PATHNAME for being a directory. \n */external bool, syserr isreg( string PATHNAME);
#pragma effect TheFileSystem
/*\n * Test PATHNAME for being a regular file. \n */external bool, syserr islnk( string PATHNAME);
#pragma effect TheFileSystem
/*\n * Test PATHNAME for being a symbolic link. \n */external ulonglong, syserr filesize( string PATHNAME);
#pragma effect TheFileSystem
/* \n * Functions for dealing with directories.\n */external string getcwd();
#pragma effect TheFileSystem
/*\n * Get the current working directory. \n */external syserr chdir( string PATHNAME);
#pragma effect TheFileSystem
/*\n * Change the current working directory to PATHNAME. \n */external syserr mkdir( string PATHNAME);
#pragma effect TheFileSystem
/*\n * Create the directory PATHNAME. \n */external syserr rmdir( string PATHNAME);
#pragma effect TheFileSystem
/*\n * Functions for dealing with temporary files and directories.\n */external string P_tmpdir();
/*\n * Path-prefix for storing temporary files on the specific system,\n * e.g. \"/usr/tmp/\".\n */external int L_tmpnam();
/*\n * Maximum length of file names generated by tmpnam() or tempnam().\n */external string mktemp( string TEMPLATE);
#pragma effect TheFileSystem
/*\n * Create a unique file name, typically in a temporary\n * file system. The string TEMPLATE\n * should contain a file name with six trailing Xs.\n * These Xs are replaced by a letter and the current process ID.\n * The letter will be chosen so that the resulting\n * name does not duplicate an existing file.\n */external string tmpnam();
#pragma effect TheFileSystem
/*\n * Generate a unique file name using the path-prefix\n * defined by P_tmpdir().\n */external string tmpnam( string DIR, string PREFIX);
#pragma effect TheFileSystem
/*
* global objects
*/
FileSystem TheFileSystem = create_TheFileSystem() ;
/*-----------------------------------------------*/
2.13 Environment.sac
/*-----------------------------------------------*/
class Environment;
use String : { string};
export all;
/*
* type definitions
*/
external classtype Environment::Environment;
/*
* prototypes for externals (FUNDECS)
*/
/*\n * The global object TheEnvironment of class Environment serves as\n * a representation of the environment.\n * It is derived from the global object TheWorld in\n * order to represent this part or sub-world of the execution environment.\n */external Environment create_TheEnvironment();
#pragma effect World::TheWorld
external string GetEnv( string ENVVAR);
#pragma effect TheEnvironment
external bool ExistEnv( string ENVVAR);
#pragma effect TheEnvironment
external bool SetEnv( string ENVVAR, string VALUE, bool OVERWRITE);
#pragma effect TheEnvironment
external void UnsetEnv( string ENVVAR);
#pragma effect TheEnvironment
external int EnvCount();
#pragma effect TheEnvironment
external string IndexEnv( int N);
#pragma effect TheEnvironment
/*
* global objects
*/
Environment TheEnvironment = create_TheEnvironment() ;
/*-----------------------------------------------*/
2.14 Dir.sac
/*-----------------------------------------------*/
class Dir;
use SysErr : { syserr};
use String : { string};
use FileSystem : { TheFileSystem};
export all;
/*
* type definitions
*/
external classtype Dir::Dir;
/*
* prototypes for externals (FUNDECS)
*/
external syserr, Dir opendir( string NAME);
#pragma effect TheFileSystem
external void closedir( Dir &DIR);
#pragma effect TheFileSystem
external string readdir( Dir &DIR);
#pragma effect TheFileSystem
external void rewinddir( Dir &DIR);
#pragma effect TheFileSystem
external long telldir( Dir &DIR);
#pragma effect TheFileSystem
external void seekdir( Dir &DIR, long POS);
#pragma effect TheFileSystem
/*-----------------------------------------------*/
2.15 CommandLine.sac
/*-----------------------------------------------*/
class CommandLine;
use String : { string};
export all;
/*
* type definitions
*/
external classtype CommandLine::CommandLine;
/*
* prototypes for externals (FUNDECS)
*/
/*\n * The global object TheCommandLine of class CommandLine serves as a \n * representation of the shell command used for starting program execution.\n * It is derived from the global object TheWorld in\n * order to represent this part or sub-world of the execution environment.\n */external CommandLine create_TheCommandLine();
#pragma effect World::TheWorld
external int argc();
#pragma effect TheCommandLine
external string argv();
#pragma effect TheCommandLine
external string argv( int N);
#pragma effect TheCommandLine
/*
* global objects
*/
CommandLine TheCommandLine = create_TheCommandLine() ;
/*-----------------------------------------------*/
2.16 Clock.sac
/*-----------------------------------------------*/
class Clock;
use String : { string};
export all;
/*
* type definitions
*/
external classtype Clock::Clock;
external typedef time;
/*
* prototypes for externals (FUNDECS)
*/
external Clock create_TheClock();
#pragma effect World::TheWorld
external time to_time( int secs);
/* \n * Convert seconds since the Epoch into a time value\n */external time gettime();
#pragma effect TheClock
/* Get the current system time.\n *\n * Note: Although the system clock of course is not effected by a call\n * to this function, the pragma effect is used instead of touch.\n * This is done to achieve a sequentialization which is necessary\n * since the state of the clock is not constant although it may\n * not be modified from within a SAC program.\n */external time, bool mktime( int YEAR, int MON, int DAY, int HOUR, int MIN, int SEC);
/*\n * Functions for decomposing time values.\n */external int sec( time T);
/*\n * The number of seconds after the minute, normally in\n * the range 0 to 59, but can be up to 61 to allow for\n * leap seconds.\n */external int min( time T);
/*\n * The number of minutes after the hour, in the range 0 to 59.\n */external int hour( time T);
/*\n * The number of hours past midnight, in the range 0 to 23. \n */external int mday( time T);
/*\n * The day of the month, in the range 1 to 31. \n */external int mon( time T);
/*\n * The number of months since January, in the range 0 to 11. \n */external int year( time T);
/*\n * The year, starting with 0=1900. \n */external int wday( time T);
/*\n * The number of days since Sunday, in the range 0 to 6 \n */external int yday( time T);
/*\n * The number of days since January 1, in the range 0 to 365. \n */external int, int, int clock( time T);
/*\n * Extract hours, minutes, and seconds from time value T. \n */external int, int, int date( time T);
/*\n * Functions for getting additional information about the time.\n */external int isdst( time T);
/*\n * A flag that indicates whether daylight saving time\n * is in effect at the time described. The value is\n * positive if daylight saving time is in effect, zero\n * if it is not, and negative if the information is\n * not available.\n */external bool isleap( int YEAR);
external bool isleap( time T);
/*\n * Test the given year YEAR or the time value T respectively \n * for being a leap year.\n */external double difftime( time T1, time T0);
/*\n * Functions for converting time values and string representations.\n */external string ctime( time T);
/*\n * The ctime() function converts the time T into\n * a string of the form\n *\n * \"Wed Jun 30 21:49:08 1993\n\"\n *\n * The abbreviations for the days of the week are ‘Sun\’,\n * ‘Mon\’, ‘Tue\’, ‘Wed\’, ‘Thu\’, ‘Fri\’, and ‘Sat\’. \n * The abbreviations for the months are ‘Jan\’, ‘Feb\’, ‘Mar\’, ‘Apr\’,\n * ‘May\’, ‘Jun\’, ‘Jul\’, ‘Aug\’, ‘Sep\’, ‘Oct\’, ‘Nov\’, and ‘Dec\’\n * \n */external string strftime( int LEN, string FORMAT, time T);
/*\n * Convert the time T into a string of maximum length LEN\n * concerning the format string FORMAT. Special time oriented\n * conversion specifiers may be used (see C documentation).\n * If an error occurs the returned string is empty.\n */external time, string strptime( string S, string FORMAT);
/*\n * Complementary function to strftime(),\n * convert the string S into a time value concerning the format\n * string FORMAT. Similar conversion specifiers may be applied as\n * with the strftime() function (see C documentation for details).\n * The resulting string contains the remainder of S not scanned\n * by strptime(). If strptime() fails to match all of the format\n * string an error occurs, the returned remainder string is empty,\n * and the returned time is 0.\n */external void sleep( int SECONDS);
#pragma effect World::TheWorld
/*
* global objects
*/
Clock TheClock = create_TheClock() ;
/*-----------------------------------------------*/
3 Structures
3.1 Structures.sac
/*-----------------------------------------------*/
module Structures;
import Array : all;
import Char : all;
import Bits : all;
import String : all;
export all;
/*-----------------------------------------------*/
3.2 StringArray.sac
/*-----------------------------------------------*/
module StringArray;
use String : { string};
use Array : { *, all, -, abs, <, >=, +, zero, ++};
export all except { eq_SxS, eq_SxA, eq_AxS, eq_AxA, getIndicies, modarray_AxVxS, sel_VxA, stringArrayCreator, drop};
/*
* type definitions
*/
external typedef stringArray;
/*
* prototypes for externals (FUNDECS)
*/
external stringArray modarray_AxVxS( stringArray labs, int[.] idx, string str);
external string sel_VxA( int[.] idx, stringArray labs);
external int dim( stringArray s);
external int[.] shape( stringArray s);
external stringArray stringArrayCreator( int[.] shp, string s);
/*
* function definitions (FUNDEFS)
*/
/****************************************************************************
* drop(...) [ body ]
****************************************************************************/
stringArray drop( int[.] v, stringArray array)
/****************************************************************************
* where(...) [ body ]
****************************************************************************/
inline
int[+] where( bool[+] p, int A, int[+] B)
/****************************************************************************
* modarray(...) [ body ]
****************************************************************************/
stringArray modarray( stringArray array, int[.] idx, stringArray val)
/****************************************************************************
* sel(...) [ body ]
****************************************************************************/
stringArray sel( int[.] idx, stringArray array)
/****************************************************************************
* to_string(...) [ body ]
****************************************************************************/
string to_string( stringArray a)
/****************************************************************************
* to_stringArray(...) [ body ]
****************************************************************************/
stringArray to_stringArray( string s)
/****************************************************************************
* genarray(...) [ body ]
****************************************************************************/
stringArray genarray( int[.] shp, stringArray s)
/****************************************************************************
* eq_SxS(...) [ body ]
****************************************************************************/
inline
bool eq_SxS( stringArray a, stringArray b)
/****************************************************************************
* eq_SxA(...) [ body ]
****************************************************************************/
inline
bool[*] eq_SxA( stringArray a, stringArray b)
/****************************************************************************
* eq_AxS(...) [ body ]
****************************************************************************/
inline
bool[*] eq_AxS( stringArray a, stringArray b)
/****************************************************************************
* eq_AxA(...) [ body ]
****************************************************************************/
inline
bool[*] eq_AxA( stringArray a, stringArray b)
/****************************************************************************
* ==(...) [ body ]
****************************************************************************/
inline
bool[*] ==( stringArray a, stringArray b)
/****************************************************************************
* getIndicies(...) [ body ]
****************************************************************************/
int[.,.] getIndicies( int[.] shp)
/* I\’d love to name this funcion ++ but if I do then when I use Structures,\n * ++ on integers can no longer be found.\n * N.b. The specific error is:\n * No definition found for a function \"Structures::++\" that accepts an\n * argument of type \"int[0]{}\" as parameter no 1. Full argument types\n * are \"( int[0]{}, int[.])\".\n */
/****************************************************************************
* concatStringArrays(...) [ body ]
****************************************************************************/
stringArray concatStringArrays( stringArray m1, stringArray m2)
/*\n * Returns true if needle exists in haystack\n */
/****************************************************************************
* in(...) [ body ]
****************************************************************************/
bool in( string needle, stringArray haystack)
/*\n * Returns the index into haystack for the string needle.\n * N.b. before calling this function call in to ensure that the needle you are\n * searching for really is in the haystack!\n */
/****************************************************************************
* indexOf(...) [ body ]
****************************************************************************/
int[.] indexOf( string needle, stringArray haystack)
/*-----------------------------------------------*/
3.3 String.sac
/*-----------------------------------------------*/
module String;
import Char : all;
import ScalarArith : { &, !=, ==, +, >=, >, <=, <, ++};
import ArrayBasics : { shape, sel};
export all except { indent};
/*
* type definitions
*/
external typedef string;
/*
* prototypes for externals (FUNDECS)
*/
external string to_string( char[.] A, int LENGTH);
external string strmod( string S, int P, char C);
external string strins( string S1, int P, string S2);
/* Insert string S2 into string S1 starting at position P. */external string strovwt( string S1, int P, string S2);
external char strsel( string S, int P);
external string strcat( string S1, string S2);
external string +( string S1, string S2);
external string strncat( string S1, string S2, int N);
external int strcmp( string S1, string S2);
external int strncmp( string S1, string S2, int N);
external int strcasecmp( string S1, string S2);
external int strncasecmp( string S1, string S2, int N);
external int strlen( string S);
external string strtake( string S, int N);
external string strdrop( string S, int N);
external string strext( string S, int FIRST, int LEN);
external string sprintf( string FORMAT, ...);
external int, ... sscanf( string S, string FORMAT);
external string sscanf_str( string S, string FORMAT);
external int strchr( string S, char C);
external int strrchr( string S, char C);
external int strcspn( string S, string REJECT);
external int strspn( string S, string ACCEPT);
external int strstr( string HAYSTACK, string NEEDLE);
external string, string strtok( string S, string SEP);
external string chomp( string S);
external string rtrim( string S);
external string ltrim( string S);
external string trim( string S);
external int, string strtoi( string S, int BASE);
external float, string strtof( string S);
external double, string strtod( string S);
external int toi( string S);
external float tof( string S);
external double tod( string S);
external string tos( int N);
external string tos( float N);
external string tos( double N);
external string tos( bool B);
/*
* function definitions (FUNDEFS)
*/
/****************************************************************************
* indent(...) [ body ]
****************************************************************************/
inline
string indent( int indent, string str)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( int[+] in)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( int in, int indent)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( int[+] in, int indent)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( float[+] in)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( float in, int indent)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( float[+] in, int indent)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( double[+] in)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( double in, int indent)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( double[+] in, int indent)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( bool[+] in)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( bool in, int indent)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
string tos( bool[+] in, int indent)
/****************************************************************************
* to_string(...) [ body ]
****************************************************************************/
inline
string to_string( char[.] arr)
/****************************************************************************
* tochar(...) [ body ]
****************************************************************************/
inline
char[.] tochar( string s)
/****************************************************************************
* sel(...) [ body ]
****************************************************************************/
inline
char sel( int[.] index, string s)
/****************************************************************************
* modarray(...) [ body ]
****************************************************************************/
inline
string modarray( string s, int[1] index, char c)
/****************************************************************************
* modarray(...) [ body ]
****************************************************************************/
inline
string modarray( string s1, int[1] index, string s2)
/****************************************************************************
* ==(...) [ body ]
****************************************************************************/
inline
bool ==( string A, string B)
/****************************************************************************
* !=(...) [ body ]
****************************************************************************/
inline
bool !=( string A, string B)
/****************************************************************************
* <(...) [ body ]
****************************************************************************/
inline
bool <( string A, string B)
/****************************************************************************
* <=(...) [ body ]
****************************************************************************/
inline
bool <=( string A, string B)
/****************************************************************************
* >(...) [ body ]
****************************************************************************/
inline
bool >( string A, string B)
/****************************************************************************
* >=(...) [ body ]
****************************************************************************/
inline
bool >=( string A, string B)
/****************************************************************************
* isalpha(...) [ body ]
****************************************************************************/
inline
bool isalpha( string S)
/****************************************************************************
* isupper(...) [ body ]
****************************************************************************/
inline
bool isupper( string S)
/****************************************************************************
* islower(...) [ body ]
****************************************************************************/
inline
bool islower( string S)
/****************************************************************************
* isdigit(...) [ body ]
****************************************************************************/
inline
bool isdigit( string S)
/****************************************************************************
* isxdigit(...) [ body ]
****************************************************************************/
inline
bool isxdigit( string S)
/****************************************************************************
* isspace(...) [ body ]
****************************************************************************/
inline
bool isspace( string S)
/****************************************************************************
* ispunct(...) [ body ]
****************************************************************************/
inline
bool ispunct( string S)
/****************************************************************************
* isalnum(...) [ body ]
****************************************************************************/
inline
bool isalnum( string S)
/****************************************************************************
* isprint(...) [ body ]
****************************************************************************/
inline
bool isprint( string S)
/****************************************************************************
* isgraph(...) [ body ]
****************************************************************************/
inline
bool isgraph( string S)
/****************************************************************************
* iscntrl(...) [ body ]
****************************************************************************/
inline
bool iscntrl( string S)
/****************************************************************************
* tolower(...) [ body ]
****************************************************************************/
inline
string tolower( string S)
/****************************************************************************
* toupper(...) [ body ]
****************************************************************************/
inline
string toupper( string S)
/*-----------------------------------------------*/
3.4 List.sac
/*-----------------------------------------------*/
module List;
export all;
/*
* type definitions
*/
external typedef list;
/*
* prototypes for externals (FUNDECS)
*/
external list nil();
external list cons( int ELEM, list LIST);
external int hd( list LIST);
external list tl( list LIST);
external bool empty( list LIST);
external list append( list LIST1, list LIST2);
external int nth( int N, list LIST);
external int length( list LIST);
external list drop( int N, list LIST);
external list take( int N, list LIST);
/*-----------------------------------------------*/
3.5 Grey.sac
/*-----------------------------------------------*/
module Grey;
use Array : { min, max};
import ScalarArith : { tod, toi};
export all;
/*
* type definitions
*/
typedef int grey;
/*
* function definitions (FUNDEFS)
*/
/****************************************************************************
* newGrey(...) [ body ]
****************************************************************************/
inline
grey newGrey( int g)
/****************************************************************************
* newGrey(...) [ body ]
****************************************************************************/
inline
grey newGrey( double g)
/****************************************************************************
* toi(...) [ body ]
****************************************************************************/
inline
int[*] toi( grey g)
/****************************************************************************
* tod(...) [ body ]
****************************************************************************/
inline
double[*] tod( grey g)
/****************************************************************************
* sel(...) [ body ]
****************************************************************************/
inline
grey[*] sel( int[.] idx, grey[*] a)
/****************************************************************************
* dim(...) [ body ]
****************************************************************************/
inline
int dim( grey[*] a)
/****************************************************************************
* shape(...) [ body ]
****************************************************************************/
inline
int[.] shape( grey[*] a)
/****************************************************************************
* reshape(...) [ body ]
****************************************************************************/
inline
grey[*] reshape( int[.] shp, grey[*] a)
/****************************************************************************
* +(...) [ body ]
****************************************************************************/
inline
grey +( grey g1, grey g2)
/****************************************************************************
* -(...) [ body ]
****************************************************************************/
inline
grey -( grey g1, grey g2)
/*-----------------------------------------------*/
3.6 Constants.sac
/*-----------------------------------------------*/
module Constants;
export all;
/*
* prototypes for externals (FUNDECS)
*/
external byte minbyte();
external byte maxbyte();
external short minshort();
external short maxshort();
external int minint();
external int maxint();
external long minlong();
external long maxlong();
external longlong minlonglong();
external longlong maxlonglong();
external ubyte minubyte();
external ubyte maxubyte();
external ushort minushort();
external ushort maxushort();
external uint minuint();
external uint maxuint();
external ulong minulong();
external ulong maxulong();
external ulonglong minulonglong();
external ulonglong maxulonglong();
external float minfloat();
external float maxfloat();
external double mindouble();
external double tinydouble();
external double maxdouble();
external double epidouble();
/*-----------------------------------------------*/
3.7 ComplexScalarArith.sac
/*-----------------------------------------------*/
module ComplexScalarArith;
export all;
use ArrayBasics : { sel};
use ScalarArith : { &, |};
use ComplexBasics : all;
/*
* function definitions (FUNDEFS)
*/
/* Binary operations on complex numbers. */
/****************************************************************************
* +(...) [ body ]
****************************************************************************/
inline
complex +( complex X1, complex X2)
/****************************************************************************
* -(...) [ body ]
****************************************************************************/
inline
complex -( complex X1, complex X2)
/****************************************************************************
* -(...) [ body ]
****************************************************************************/
inline
complex -( complex X1)
/****************************************************************************
* *(...) [ body ]
****************************************************************************/
inline
complex *( complex X1, complex X2)
/****************************************************************************
* /(...) [ body ]
****************************************************************************/
inline
complex /( complex X1, complex X2)
/* Functions for specific complex manipulations. */
/****************************************************************************
* conj(...) [ body ]
****************************************************************************/
inline
complex conj( complex X)
/****************************************************************************
* abs(...) [ body ]
****************************************************************************/
inline
complex abs( complex X)
/* relational operations */
/****************************************************************************
* ==(...) [ body ]
****************************************************************************/
inline
bool ==( complex X1, complex X2)
/****************************************************************************
* !=(...) [ body ]
****************************************************************************/
inline
bool !=( complex X1, complex X2)
/****************************************************************************
* <(...) [ body ]
****************************************************************************/
inline
bool <( complex X1, complex X2)
/****************************************************************************
* <=(...) [ body ]
****************************************************************************/
inline
bool <=( complex X1, complex X2)
/****************************************************************************
* >(...) [ body ]
****************************************************************************/
inline
bool >( complex X1, complex X2)
/****************************************************************************
* >=(...) [ body ]
****************************************************************************/
inline
bool >=( complex X1, complex X2)
/****************************************************************************
* min(...) [ body ]
****************************************************************************/
inline
complex min( complex X1, complex X2)
/****************************************************************************
* max(...) [ body ]
****************************************************************************/
inline
complex max( complex X1, complex X2)
/*-----------------------------------------------*/
3.8 ComplexBasics.sac
/*-----------------------------------------------*/
module ComplexBasics;
export all;
use ArrayBasics : { sel};
use Math : { atan2};
/*
* type definitions
*/
typedef double[2] complex;
/*
* function definitions (FUNDEFS)
*/
/* Functions for composing and decomposing of complex numbers. */
/****************************************************************************
* real(...) [ body ]
****************************************************************************/
inline
double real( complex CPX)
/****************************************************************************
* imag(...) [ body ]
****************************************************************************/
inline
double imag( complex CPX)
/* \n * Simple conversion functions between complex, real and integer\n * numbers.\n */
/****************************************************************************
* toc(...) [ body ]
****************************************************************************/
inline
complex toc( int REAL, int IMAG)
/****************************************************************************
* toc(...) [ body ]
****************************************************************************/
inline
complex toc( float REAL, float IMAG)
/****************************************************************************
* toc(...) [ body ]
****************************************************************************/
inline
complex toc( double REAL, double IMAG)
/****************************************************************************
* toc(...) [ body ]
****************************************************************************/
inline
complex toc( double[2] COMP)
/****************************************************************************
* toc(...) [ body ]
****************************************************************************/
inline
complex toc( int REAL)
/****************************************************************************
* toc(...) [ body ]
****************************************************************************/
inline
complex toc( float REAL)
/****************************************************************************
* toc(...) [ body ]
****************************************************************************/
inline
complex toc( double REAL)
/* Extract real and imag part from a complex number. */
/****************************************************************************
* toi(...) [ body ]
****************************************************************************/
inline
int, int toi( complex C)
/****************************************************************************
* tof(...) [ body ]
****************************************************************************/
inline
float, float tof( complex C)
/****************************************************************************
* tod(...) [ body ]
****************************************************************************/
inline
double, double tod( complex C)
/****************************************************************************
* todv(...) [ body ]
****************************************************************************/
inline
double[2] todv( complex C)
/****************************************************************************
* tos(...) [ body ]
****************************************************************************/
inline
String::string tos( complex c)
/****************************************************************************
* ptoi(...) [ body ]
****************************************************************************/
inline
int, int ptoi( complex C)
/****************************************************************************
* ptof(...) [ body ]
****************************************************************************/
inline
float, float ptof( complex C)
/****************************************************************************
* ptod(...) [ body ]
****************************************************************************/
inline
double, double ptod( complex C)
/* Functions for composing and decomposing of complex numbers\n using polar coordinates. */
/****************************************************************************
* polar(...) [ body ]
****************************************************************************/
inline
complex polar( double MAG, double ANGLE)
/****************************************************************************
* polar(...) [ body ]
****************************************************************************/
inline
complex polar( double MAG)
/****************************************************************************
* normSq(...) [ body ]
****************************************************************************/
inline
double normSq( complex CPX)
/****************************************************************************
* norm(...) [ body ]
****************************************************************************/
inline
double norm( complex CPX)
/****************************************************************************
* arg(...) [ body ]
****************************************************************************/
inline
double arg( complex CPX)
/* Complex constants. */
/****************************************************************************
* i(...) [ body ]
****************************************************************************/
inline
complex i()
/****************************************************************************
* zero(...) [ body ]
****************************************************************************/
inline
complex zero()
/****************************************************************************
* zero(...) [ body ]
****************************************************************************/
inline
complex zero( complex[*] a)
/****************************************************************************
* one(...) [ body ]
****************************************************************************/
inline
complex one()
/****************************************************************************
* one(...) [ body ]
****************************************************************************/
inline
complex one( complex[*] a)
/*-----------------------------------------------*/
3.9 Complex.sac
/*-----------------------------------------------*/
module Complex;
import ComplexBasics : all;
import ComplexScalarArith : all;
import ComplexArrayBasics : all;
import ComplexArrayArith : all;
import ComplexArrayTransform : all;
export all;
/*-----------------------------------------------*/
3.10 Color8.sac
/*-----------------------------------------------*/
module Color8;
use Array : all except { *, -, +, reshape, dim, shape, sel, tod, toi};
import Array : { *, -, +, reshape, dim, shape, sel, tod, toi};
use MathArray : all;
export all except { Weights2Clut, genSteps};
/*
* type definitions
*/
typedef int[3] color;
/*
* function definitions (FUNDEFS)
*/
/****************************************************************************
* black(...) [ body ]
****************************************************************************/
inline
color black()
/****************************************************************************
* white(...) [ body ]
****************************************************************************/
inline
color white()
/****************************************************************************
* red(...) [ body ]
****************************************************************************/
inline
color red()
/****************************************************************************
* green(...) [ body ]
****************************************************************************/
inline
color green()
/****************************************************************************
* blue(...) [ body ]
****************************************************************************/
inline
color blue()
/****************************************************************************
* red(...) [ body ]
****************************************************************************/
inline
int red( color col)
/****************************************************************************
* green(...) [ body ]
****************************************************************************/
inline
int green( color col)
/****************************************************************************
* blue(...) [ body ]
****************************************************************************/
inline
int blue( color col)
/****************************************************************************
* newColor(...) [ body ]
****************************************************************************/
inline
color newColor( int[3] col)
/****************************************************************************
* newColor(...) [ body ]
****************************************************************************/
inline
color newColor( int x, int y, int z)
/****************************************************************************
* toi(...) [ body ]
****************************************************************************/
inline
int[3] toi( color c)
/****************************************************************************
* toi(...) [ body ]
****************************************************************************/
inline
int[*] toi( color[*] c)
/****************************************************************************
* tod(...) [ body ]
****************************************************************************/
inline
double[3] tod( color c)
/****************************************************************************
* tod(...) [ body ]
****************************************************************************/
inline
double[*] tod( color[*] c)
/****************************************************************************
* Weights2Clut(...) [ body ]
****************************************************************************/
inline
color[256] Weights2Clut( double[256] w, color c1, color c2)
/****************************************************************************
* genSteps(...) [ body ]
****************************************************************************/
inline
double[256] genSteps( double from, double to)
/****************************************************************************
* genLinearClut(...) [ body ]
****************************************************************************/
inline
color[256] genLinearClut( color c1, color c2)
/****************************************************************************
* genLogarithmicClut(...) [ body ]
****************************************************************************/
inline
color[256] genLogarithmicClut( double from, double to, color c1, color c2)
/****************************************************************************
* genExponentialClut(...) [ body ]
****************************************************************************/
inline
color[256] genExponentialClut( double from, double to, color c1, color c2)
/****************************************************************************
* genAlternatingClut(...) [ body ]
****************************************************************************/
inline
color[256] genAlternatingClut( color c1, color c2)
/*\n * h_in is the hue in degrees [0:360]\n * s_in is the saturation in % [0:100]\n * b_in is the brightness in % [0:100]\n */
/****************************************************************************
* Hsb2Rgb(...) [ body ]
****************************************************************************/
inline
color Hsb2Rgb( int h_in, int s_in, int b_in)
/****************************************************************************
* Hsb2Rgb(...) [ body ]
****************************************************************************/
inline
color[*] Hsb2Rgb( int[*] h_in, int s_in, int b_in)
/****************************************************************************
* Hsb2Rgb(...) [ body ]
****************************************************************************/
inline
color[*] Hsb2Rgb( int[*] h_in, int[*] s_in, int[*] b_in)
/****************************************************************************
* sel(...) [ body ]
****************************************************************************/
inline
color[*] sel( int idx, color[*] clut)
/****************************************************************************
* sel(...) [ body ]
****************************************************************************/
inline
color[*] sel( int[.] idx, color[*] a)
/****************************************************************************
* dim(...) [ body ]
****************************************************************************/
inline
int dim( color[*] a)
/****************************************************************************
* shape(...) [ body ]
****************************************************************************/
inline
int[.] shape( color[*] a)
/****************************************************************************
* reshape(...) [ body ]
****************************************************************************/
inline
color[*] reshape( int[.] shp, color[*] a)
/****************************************************************************
* +(...) [ body ]
****************************************************************************/
inline
color +( color a, color b)
/****************************************************************************
* +(...) [ body ]
****************************************************************************/
inline
color[*] +( color[*] a, color[*]