next up previous
Next: UnixUtil Up: simlib Previous: FileUtil

UnixCmdLineClass


     NAME
	  unixcmdlineclass - contains routines to read the raw Unix
	  commandline and Env-vars.

     DESCRIPTION
	  Routines to read the arguments from the commandline in
	  primitive, space separated form. It also returns the
	  environment variables	in raw form.

     EXAMPLE
	  Unix Commandline: prog -b -i=123 -t=Donald abc def
	  will be seens	as having 6 arguments:
	  1:"prog", 2:"-b", 3:"-i=123",	4:"-t=Donald", 5:"abc",
	  6:"def"
	  The following	example	program	lists all  arguments  and  all
	  environment variables	it can see:

	   begin
	     external class UnixCmdlineClass;
	     ref(UnixCmdlineClass) ux;
	     integer  ix,i;
	     ux:-new UnixCmdlineClass;
	     ix:=ux.MaxCmd;
	     outtext( Arg count:"); outint(ix,0); outimage;"
	     for i:=1 step 1 until ix do
	     begin
	       outtext(ux.CmdArg(i)); outimage;
	     end;
	     ix:=ux.MaxEnv;
	     outtext( Env count:"); outint(ix,0); outimage;"
	     for i:=1 step 1 until ix do
	     begin
	       outtext(ux.EnvArg(i)); outimage;
	     end;
	   end;

     AUTHOR
	  Boris	Magnusson, Lund	University.

     SEE ALSO
	  CmdLineClass - portable Simula  interface  to	 command  line
	  arguments.

     DETAILED INTERFACE
	     class UnixCmdlineClass;
	  Basic	interface  to  Unix  program  'parameters'  (from  the
	  command  line	 and from environment variables). Command line
	  arguments are	returned in uniterpreted Unix form.

	  Use this class if you	want to	write  Simula  programs	 which
	  look	like  standard Unix applications. If you want to write
	  portable Simula programs use the  routines  in  CmdLineClass
	  instead   which   exists   for   several   non  Unix	Simula
	  implementations.

	  Supers: -
	  Kind:	Instantiable
	  Init:	-
	  Sequencing: (MaxCmd/CmdArg/MaxEnv/EnvArg/GetEnv)*

     OPERATIONS
     MaxCmd
	     integer procedure MaxCmd;
	  Return the number of arguments on the	command	line, numbered
	  1,2 ...

     CmdArg
	     text procedure CmdArg(ix);
	     integer ix;
	  Return the command line argument number index	 as  a	Simula
	  text.	  If  index  is	 out  of  range	(1..MaxCmd) it returns
	  notext.  With	ix=1 it	returns	the name of the	program/script
	  used to start	this process.

     MaxEnv
	     integer procedure MaxEnv;
	  Return the number of environment variables numbered 1,2 ...

     EnvArg
	     text procedure EnvArg(ix);
	     integer ix;
	  Return the environment variable number  index	 as  a	Simula
	  text	in the same format as when listed with 'printenv'.  If
	  index	is out of range	(1..MaxEnv) it returns notext.

     GetEnv
	     Text procedure GetEnv(Arg,Defined);
	     name Defined; text	Arg; Boolean Defined;
	  Returns True and the 'value'	of  Arg	 if  defined  as  env-
	  variable.  Ex: given:	'EDITOR=vi' will make GetEnv("EDITOR")
	  return: "vi" and Defined=True.  Returns  Defined=False  (and
	  Notext)   if	 'Arg'	 is  not  defined.   Notice  that  the
	  combination Notext and True means that the 'Arg' is  defined
	  as the empty string.