/*  Last edited: Feb 13 13:49 1996 (rmott) */
/* CL.H is the header file for the command-line parsing functions in CL.C */
/* (C) Richard Mott, ICRF */

FILE *OpenFile( char *filename, char *mode );
     
     /* attempts to open filename, using mode to determine function
	(read/write/append), and stops the program on failure */

FILE *OpenFileInSearchPath(char *base, char *mode, char *searchpath, char *fullname );
FILE *OpenFileInEnvPath(char *base, char *mode, char *env, char *fullname );

int GetFloat( char *format, float *variable, int argc, char **argv ); /* gets a float from command line */
int GetInt( char *format, int *variable, int argc, char **argv ); /* gets an int from the command line */
int ClCheck( char *format, int argc, char **argv ); /* checks if a string is on the command line*/
int GetBool( char *format, int *bool, int argc, char **argv );
     
     /* checks for boolean switch, eg
	
	-gap=yes  -gap=y -gap=1 -gap=true -gap=t -gap	TRUE
	-gap=no -gap=n -gap=0 -gap=false -gap=f		FALSE
	
	format should be the string "-gap" 
	
	*/
int GetBoolean( char *format, int *bool, int argc, char **argv ); /* similar to GetBool(), except that function returns 1 and sets *bool = 1 if ClCheck is true also . Therefore the switch

-switch

is equivalent to

-switch=y

*/
int GetArg( char *format, char *arg, int argc, char **argv ); /* gets a string argument*/

FILE *NextFile( char *filename, int argc, char **argv );
     
     /* searches the command line for arguments not beginning with "-", and tries
	to open the first one it finds for reading. The corresponding argument in the command-line list is then blanked
	out so that on the next call a different file is opened. The name of the
	file opened is returned in filename. On failure the function returns NULL */

char *Extension ( char *filename, char *ext);
     
     /* changes the Extension of filename to ext.
	
	e.g.
	Extension( "file.dat", "out" );
	
	produces file.out
	
	Extension( "file", "out");
	
	produces file.out
	
	Extension( "file", ".out");
	
	produces file.out
	
	Extension( "file.out", "");
	
	produces file
	
	Note: filename MUST be long enough to cope ! 

        Returns the modified string */


char *BaseName (char *filename);
     
     /* strips any Directory from filename
	
	e.g.
	BaseName("/gea/users/rmott/.cshrc");
	
	produces .cshrc
	
	BaseName("/usr");
	
	produces usr
	
	*/
     
char *DirName( char *pathname );

/* strips off the filename from the path, leaving the Directory */

char *Directory( char *filename, char *dir );
     
     /* changes the Directory part of filename to dir.
	
	e.g.
	Directory( "/home/gea/fred/file.dat", "/usr/local/" );
	
	produces /usr/local/file.dat
	
	Directory("/usr/lib", "var");
	
	produces var/lib, i.e. a Directory slash is inserted if necessary.
	
	*/
     
char *RootName( char *filename );
     
     /* trims off the Directory and the Extension from filename */
     
char *MakeLegal( char *filename );

FILE *ArgFile( char *format, char *mode, int argc, char **argv, char *filename );
     
     /* parses the command-line using format, attempts to get a filename and open
	it. If format does not match any argument then NULL is returned. If format
	matchs an argument but the file will not open then the program stops*/
     
FILE *ArgFileForce( char *format, char *mode, int argc, char **argv, char *filename );
     
     /* parses the command-line using format, attempts to get a filename and open
	it. If format does not match any argument or if format matchs an argument
	but the file will not open then the program stops*/

int FileTime( char *filename );
     
     /* returns the time that filename was last modified, or 0 if filename
	cannot be opened for reading or if the call to stat fails */
     
char *FileDate( char *filename );
     
     /* similar to FileTime() execpt that a pointer to the date (in English) */

int LegalString( char *string, char **strings, int size, int *value );

/* checks if string is a member os strings, and sets value to the index in the array strings
returns 1 on success and 0 on failure */

char *NextArg( char *format, int argc, char **argv );
char *ClStub( char *format );

int AddCommandsFromFile( int argc, char **argv, int *nargc, char ***nargv );
void PrintUsage( int argc, char **argv, int stop );
void AppendUsage( char *format, char *text, char *def, int overide );
void GetHelp( int argc, char **argv );
void AddHelp( char *string );


char 
**SplitOnSeparator( char *string, char separator, int *items);

char *Now(void);
int GetSeed( int *seed, int argc, char **argv );

int GetRestrictedArg( char *format, char *arg, int argc, char ** argv, int stringc, char **strings, int *value );
int EndsWith( char *text, char *suffix );

