Commit 15d91d15 authored by Bas Lijnse's avatar Bas Lijnse

Added a simple module for accessing the command line arguments.


git-svn-id: https://svn.cs.ru.nl/repos/clean-platform/trunk@44 2afc29ad-3112-4e41-907a-9359c7e6e986
parent 7102a285
module IPLookup
import IP, Maybe
import StdEnv
import IP, Maybe, CommandLine
Start :: *World -> (String, *World)
Start world = case lookupIPAddress "clean.cs.ru.nl" world of
(Just addr, world) = (toString addr, world)
(Nothing, world) = ("Could not lookup IP address", world)
\ No newline at end of file
Start world
# (cmd,world) = getCommandLine world
| length cmd <> 2 = ("Usage: " +++ cmd !! 0 +++ " hostname",world)
= case lookupIPAddress (cmd !! 1) world of
(Just addr, world) = (toString addr, world)
(Nothing, world) = ("Could not lookup IP address", world)
definition module CommandLine
/**
* This module provides access to the commandline arguments of
* the program.
*/
/**
* Read the command line arguments from the world.
*
* @param The world
* @return The command line arguments
* @return The world
*/
getCommandLine :: *World -> ([String],*World)
implementation module CommandLine
import StdInt, StdList, StdEnum
import Pointer
getCommandLine :: *World -> ([String],*World)
getCommandLine world
# argc = derefInt global_argc
# argv = derefInt global_argv
= ([derefString (readInt argv (i << 2) ) \\ i <- [0..argc - 1]], world)
where
//Global argc pointer
global_argc :: Pointer
global_argc = code {
pushLc global_argc
}
//Global argv pointer
global_argv :: Pointer
global_argv = code {
pushLc global_argv
}
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