Commit b83bf25f authored by cvs2snv's avatar cvs2snv

This commit was manufactured by cvs2svn to create tag 'clean-2-0-2'.

parent 6f476ac6
/*
Version 1.0.1
Ronny Wichers Schreur
ronny@cs.kun.nl
*/
definition module ArgEnv
:: EnvironmentVariable
= EnvironmentVariableUndefined
| EnvironmentVariable !.{#Char}
// get the value of an environment variable
getEnvironmentVariable :: !{#Char} -> *EnvironmentVariable
// get the command line, first element is the command name,
// arguments that are interpreted by the run-time system
// (for example to set the heap size) are excluded
// Clean 1.1: getCommandLine :: {{#Char}}
getCommandLine :: {.{#Char}}
implementation module ArgEnv
import StdEnv
:: CString :== Int
NULL :== 0
:: EnvironmentVariable
= EnvironmentVariableUndefined
| EnvironmentVariable !.{#Char}
getEnv :: !{#Char} -> (!Int, !CString)
getEnv _
= code {
.inline getEnv
ccall ArgEnvGetEnvironmentVariableC "S-II"
.end
}
getEnvironmentVariable :: !{#Char} -> *EnvironmentVariable
getEnvironmentVariable name
| cString == NULL
= EnvironmentVariableUndefined
| otherwise
= EnvironmentVariable (copy size cString)
where
(size, cString)
= getEnv (name +++ "\0")
copy :: !Int !CString -> {#.Char}
copy length cString
= code {
.inline copy
| Clean 1.1: use create_array
| pushC '\000'
| push_b 1
| update_b 1 2
| update_b 0 1
| pop_b 1
| create_array CHAR 0 1
| Clean 1.2 and later: use create_array_
create_array_ CHAR 0 1
push_a 0
ccall ArgEnvCopyCStringToCleanStringC "IS-I"
pop_b 1
.end
}
getCommandLineCount :: Int
getCommandLineCount
= code {
.inline getCommandLineCount
ccall ArgEnvGetCommandLineCountC "-I"
.end
}
getCommandLineArgument :: !Int -> (!Int, !Int)
getCommandLineArgument _
= code {
.inline getCommandLineArgument
ccall ArgEnvGetCommandLineArgumentC "I-II"
.end
}
getArg :: !Int -> {#.Char}
getArg i
= copy size cString
where
(size, cString)
= getCommandLineArgument i
// Clean 1.1: getCommandLine :: {{#Char}}
getCommandLine :: {.{#Char}}
getCommandLine
= {getArg i \\ i <- [0 .. getCommandLineCount-1]}
/*
Version 1.0.1
Ronny Wichers Schreur
ronny@cs.kun.nl
*/
# define kVariableSize 1
# ifndef NULL
# define NULL ((void *) 0)
# endif
/* defined by the Clean run-time system */
extern int global_argc;
extern char **global_argv;
# ifndef _WINDOWS_
# include <stdlib.h>
# endif
typedef struct
{
int length;
char characters [kVariableSize];
} *CleanString;
static int
CStringLength (char *s)
{
char *begin;
begin = s;
while (*s != '\0')
s++;
return (s - begin);
} /* CStringLength */
# ifdef _WINDOWS_
/* return size of environment variable's value (including null-terminator)
zero if variable doesn't exist */
int
ArgEnvGetEnvironmentVariableSizeC (CleanString name)
{
char smallBuffer;
/* Assume that name has been null-terminated in Clean */
return (GetEnvironmentVariableA (name->characters, &smallBuffer, 0));
} /* ArgEnvGetEnvironmentVariableSizeC */
/* copy value of environment variable to Clean string
return False if value had to be truncated */
int
ArgEnvGetEnvironmentVariableCharsC (CleanString value, CleanString name)
{
int size, length;
length = value->length;
/* Assume that name has been null-terminated in Clean */
size = GetEnvironmentVariableA (name->characters, value->characters, length);
if (size <= length)
{
size = CStringLength (value->characters);
if (size <= length)
value->length = size;
}
return (size >= value->length);
} /* ArgEnvGetEnvironmentVariableCharsC */
# else /* ifndef _WINDOWS_ */
void
ArgEnvGetEnvironmentVariableC (CleanString name, int *sizeP, char **stringP)
{
char *value;
/* Assume that name has been null-terminated in Clean */
value = getenv (name->characters);
if (value == NULL)
*sizeP = 0;
else
*sizeP = CStringLength (value);
*stringP = value;
} /* ArgEnvGetEnvironmentVariableCharsC */
# endif /* _WINDOWS_ */
int
ArgEnvGetCommandLineCountC (void)
{
return (global_argc);
} /* ArgEnvGetCommandLineCountC */
void
ArgEnvGetCommandLineArgumentC (int i, int *sizeP, char **stringP)
{
char *arg;
/* Assume that i is within bounds */
arg = global_argv [i];
*sizeP = CStringLength (arg);
*stringP = arg;
} /* ArgEnvGetCommandLineArgumentC */
/* copy C string to Clean string
return False if string had to be truncated */
int
ArgEnvCopyCStringToCleanStringC (char *cString, CleanString cleanString)
{
int i, length;
char *to;
length = cleanString->length;
to = cleanString->characters;
i = 0;
while (*cString != '\0' && i < length)
{
i++;
*to++ = *cString++;
}
cleanString->length = i;
return (i <= length);
} /* ArgEnvCopyCStringToCleanStringC */
#
# Version 1.0.1
# Ronny Wichers Schreur
# ronny@cs.kun.nl
#
CLM=clm
CC=gcc
COPTIONS=-Wall -pedantic
printenv : printenv.o ArgEnv.o ArgEnvC.o
$(CLM) -b -nt -l ArgEnvC.o printenv -o printenv
ArgEnvC.o : ArgEnvC.c
$(CC) $(COPTIONS) -c ArgEnvC.c
ArgEnv.o : ArgEnv.icl ArgEnv.dcl
$(CLM) -O ArgEnv
printenv.o : printenv.icl ArgEnv.dcl
$(CLM) -O printenv
cleanup :
$(RM) printenv *.o *.abc
ArgEnv
Version 1.0.1
Ronny Wichers Schreur
ronny@cs.kun.nl
The ArgEnv package provides a Clean interface to the command line
arguments and the environment variables.
This is the README for the Unix version. The Unix version has been
tested on Solaris 5.5 and Clean 1.1 & 1.3, but it should work with all
Unix versions with Clean 1.1 or better. To use the package with Clean
version 1.1 you will have to make a few changes, which are documented
in the source.
FILES
README
This file
ArgEnv.dcl
Definition of the interface
ArgEnv.icl
Implementation of the interface
ArgEnvC.c
Implementation of the C side of the interface
Makefile
Makefile for the ArgEnv interface and the example program
printenv.icl
An example program that prints the value of an environment
variable
USAGE
To use the ArgEnv interface you have to link the object module that
is created from the module ArgEnvC.c.
If you use clm you should specify this extra object file with the -l
option:
% clm -l ArgEnvC.o <your-main-module>
In the CleanIDE you can add this extra object file to the Object
Modules section in the Options->Link Options dialogue.
If you forget this, you will get the link error:
Undefined first referenced
symbol in file
ArgEnvCopyCStringToCleanStringC ArgEnv.o
ArgEnvGetEnvironmentVariableC ArgEnv.o
ArgEnvGetCommandLineArgumentC ArgEnv.o
ArgEnvGetCommandLineCountC ArgEnv.o
BUGS
There is no way to stop the Clean run-time system from interpreting
some of the command-line arguments.
/*
Version 1.0.1
Ronny Wichers Schreur
ronny@cs.kun.nl
*/
module printenv
import StdEnv, ArgEnv
Start
| argc == 1
= format (getEnvironmentVariable argv.[1])
| otherwise
= "usage: " +++ argv.[0] +++ " <variable>\n"
where
argc
= size argv - 1
argv
= getCommandLine
format EnvironmentVariableUndefined
= ""
format (EnvironmentVariable value)
= value +++ "\n"
/*
Version 1.0.1
Ronny Wichers Schreur
ronny@cs.kun.nl
*/
definition module ArgEnv
:: EnvironmentVariable
= EnvironmentVariableUndefined
| EnvironmentVariable !.{#Char}
// get the value of an environment variable
getEnvironmentVariable :: !{#Char} -> *EnvironmentVariable
// get the command line, first element is the command name,
// arguments that are interpreted by the run-time system
// (for example to set the heap size) are excluded
// Clean 1.1: getCommandLine :: {{#Char}}
getCommandLine :: {.{#Char}}
implementation module ArgEnv
import code from "ArgEnvC.obj"
import StdEnv
:: CString :== Int
NULL :== 0
:: EnvironmentVariable
= EnvironmentVariableUndefined
| EnvironmentVariable !.{#Char}
getEnvSize :: !{#Char} -> Int
getEnvSize _
= code {
.inline getEnvSize
ccall ArgEnvGetEnvironmentVariableSizeC "S-I"
.end
}
copyEnv :: !Int !{#Char} -> {#.Char}
copyEnv _ _
= code {
.inline copyEnv
| Clean 1.1: use create_array
| pushC '?'
| push_b 1
| update_b 1 2
| update_b 0 1
| pop_b 1
| create_array CHAR 0 1
| Clean 1.2 and later: use create_array_
create_array_ CHAR 0 1
push_a 1
push_a 1
ccall ArgEnvGetEnvironmentVariableCharsC "SS-I"
pop_b 1
update_a 0 1
pop_a 1
.end
}
getEnvironmentVariable :: !{#Char} -> *EnvironmentVariable
getEnvironmentVariable name
| size == 0
= EnvironmentVariableUndefined
| otherwise
= EnvironmentVariable (copyEnv size name`)
where
size
= getEnvSize name`
name`
= name +++ "\0"
copy :: !Int !CString -> {#.Char}
copy length cString
= code {
.inline copy
| Clean 1.1: use create_array
| pushC '\000'
| push_b 1
| update_b 1 2
| update_b 0 1
| pop_b 1
| create_array CHAR 0 1
| Clean 1.2 and later: use create_array_
create_array_ CHAR 0 1
push_a 0
ccall ArgEnvCopyCStringToCleanStringC "IS-I"
pop_b 1
.end
}
getCommandLineCount :: Int
getCommandLineCount
= code {
.inline getCommandLineCount
ccall ArgEnvGetCommandLineCountC "-I"
.end
}
getCommandLineArgument :: !Int -> (!Int, !Int)
getCommandLineArgument _
= code {
.inline getCommandLineArgument
ccall ArgEnvGetCommandLineArgumentC "I-II"
.end
}
getArg :: !Int -> {#.Char}
getArg i
= copy size cString
where
(size, cString)
= getCommandLineArgument i
// Clean 1.1: getCommandLine :: {{#Char}}
getCommandLine :: {.{#Char}}
getCommandLine
= {getArg i \\ i <- [0 .. getCommandLineCount-1]}
ArgEnv
Version 1.0.1
Ronny Wichers Schreur
ronny@cs.kun.nl
The ArgEnv package provides a Clean interface to the command line
arguments and the environment variables.
This is the README for the Windows version. The Windows version has
been tested on Windows NT client 4.0 with Clean 1.2 & 1.3, but it
should work with all Windows versions with Clean 1.2 or better. To
use the package with Clean version 1.1 you will have to make a few
changes, which are documented in the source.
FILES
README
This file
ArgEnv.dcl
Definition of the interface
ArgEnv.icl
Implementation of the interface
ArgEnvC.c
Implementation of the C side of the interface
(You do not have to compile this file, it is included
in the modified cdebug.obj)
cdebug.obj
A modified version of cdebug.obj that includes the
C side of the ArgEnv interface
kernel_library
A modified version of kernel_library that defines
some extra symbols from kernel32.dll
printenv.icl
An example program that prints the value of an environment
variable
printenv.prj
Project file for the example program
USAGE
To use the ArgEnv interface you have to link the object module that
is created from the module ArgEnvC.c.
There is no easy way to link additional object files with the older
CleanIDEs (version 1.2 and before). Therefore I have made a new
cdebug.obj that contains the object code from ArgEnvC.c. You should
replace cdebug.obj in the Clean System Files of the StdEnv with the
cdebug.obj that comes with this release.
If you use CleanIDE 1.3 or later you can just add this extra object
file to the Object Modules section in the Options->Link Options dialogue.
If you forget this, you will get the link error:
Undefined symbols:
_ArgEnvGetEnvironmentVariableSizeC
_ArgEnvGetEnvironmentVariableCharsC
_ArgEnvCopyCStringToCleanStringC
_ArgEnvGetCommandLineCountC
_ArgEnvGetCommandLineArgumentC
The ArgEnv interface also uses two additional symbols from kernel32.dll.
You should replace kernel_library in the Clean System Files of the StdEnv
with the kernel_library that comes with this release. If you forget this,
you will get the link error:
Undefined symbols:
__imp__GetEnvironmentVariableA@12
BUGS
There is no way to stop the Clean run-time system from interpreting
some of the command-line arguments.
If you start a Clean program from the command-line prompt, you still
have to "press any key" before the program quits.
/*
Version 1.0.1
Ronny Wichers Schreur
ronny@cs.kun.nl
*/
module printenv
import StdEnv, ArgEnv
Start
| argc == 1
= format (getEnvironmentVariable argv.[1])
| otherwise
= "usage: " +++ argv.[0] +++ " <variable>\n"
where
argc
= size argv - 1
argv
= getCommandLine
format EnvironmentVariableUndefined
= ""
format (EnvironmentVariable value)
= value +++ "\n"
This diff is collapsed.
This diff is collapsed.
......@@ -75,7 +75,7 @@ freads :: ! *File !Int -> (!*{#Char},!*File)
If the file doesn't contain n characters the file will be read to the end
of the file. An empty String is returned if no characters can be read. */
//freadsubstring :: !Int !Int !*{#Char} !*File -> (!Int,!*{#Char},!*File)
freadsubstring :: !Int !Int !*{#Char} !*File -> (!Int,!*{#Char},!*File)
/*
Reads n characters from a text or data file, which are returned in the string
arg3 at positions arg1..arg1+arg2-1. If the file doesn't contain arg2 characters
......@@ -105,7 +105,7 @@ fwriter :: !Real !*File -> *File
fwrites :: !{#Char} !*File -> *File
/* Writes a String to a text or data file. */
//fwritesubstring :: !Int !Int !{#Char} !*File -> *File
fwritesubstring :: !Int !Int !{#Char} !*File -> *File
/* Writes the characters at positions arg1..arg1+arg2-1 of string arg3 to
a text or data file. */
......
......@@ -206,7 +206,6 @@ freads f l
.o 1 2 f
}
/*
freadsubstring :: !Int !Int !*{#Char} !*File -> (!Int,!*{#Char},!*File)
/*
Reads n characters from a text or data file, which are returned in the string s
......@@ -223,7 +222,7 @@ freadsubstring i n s f
.o 1 3 i f
.end
}
*/
freadline::!*File -> (!*{#Char},!*File)
/* Reads a line from a textfile. (including a newline character, except for the last
line) freadline cannot be used on data files. */
......@@ -275,7 +274,6 @@ fwrites s f
.o 0 2 f
}
/*
fwritesubstring :: !Int !Int !{#Char} !*File -> *File
/* Writes the characters at positions i..i+n-1 of string s to a text or data file. */
fwritesubstring i n s f
......@@ -286,7 +284,6 @@ fwritesubstring i n s f
.o 0 2 f
.end
}
*/
// Tests
......
......@@ -42,7 +42,6 @@ instance fromInt {#Char}
// Additional functions for integer arithmetic:
instance mod Int // arg1 modulo arg2
instance rem Int // remainder after integer division
instance gcd Int // Greatest common divider
instance lcm Int // Least common multiple
......
......@@ -196,14 +196,7 @@ instance rem Int
where
(rem) a b
= code inline {
push_b 1
push_b 2
push_b 2
divI
mulI
update_b 0 2
pop_b 1
subI
remI
}
instance gcd Int
......@@ -211,7 +204,7 @@ where
gcd x y = gcdnat (abs x) (abs y)
where
gcdnat x 0 = x
gcdnat x y = gcdnat y (x mod y)
gcdnat x y = gcdnat y (x rem y)
instance lcm Int
......
OPENWINHOME=/usr/openwin
DEFAULT_TOOLKIT = xv
# Sun:
# TOOLKITS = olit xv
# Linux:
TOOLKITS = xv
INTERFACE_MODULES = \
xcursor xfileselect xpath xdialog \
xkernel xpicture xwindow xmenu xtimer
CLEAN_MODULES = \
deltaControls deltaFont deltaPicture \
deltaDialog deltaIOState deltaSystem \
deltaEventIO deltaIOSystem deltaTimer \
deltaFileSelect deltaMenu deltaWindow \
commonDef dialogDef menuDef timerDef \
windowDef dialogDevice menuDevice timerDevice \
windowDevice cursorInternal ioState scrollList scrollList sliderBar misc \
picture xevent xtypes
# Link options files
LO_FILES = \
x.lo \
$(TOOLKITS:%=%.lo)
LIBRARY_MODULES = \
libCleanIO \
$(TOOLKITS:%=libClean%)
# Static and Dynamic Libraries
LIBRARIES = \
$(LIBRARY_MODULES:%=%.a)
# $(LIBRARY_MODULES:%=%.so.1.0) \
# Links to versions of shared libraries
# SHARED_LIB_LINKS =
# $(LIBRARY_MODULES:%=%.so)
IOLIB_FILES = \
$(CLEAN_MODULES:%=%.dcl) \
$(INTERFACE_MODULES:%=%.dcl) \
$(CLEAN_MODULES:%=%.icl) \