Headers Index Help Within this page: Functions Constants Variables
FIXNAME.C - Force a string to conform to a correct
local filename as regards length, default
extension, and numbers of dots.
NOTE: The function allocates storage for the
modified name in a safe place. If it is
called repeatedly this space should be
released as soon as possible by calling
free().
Include files defined in the header, environ.h, are shown in italics.
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int argval(char *s, int d);
Convert a string to an integer, using the second parameter as the default if the string is empty. This is intended to be used in conjunction with getopt() to handle options with optional integer values which default to zero if the option is omitted or to some known value if the option is present in the command line but without a specified value:
See also: getopt(), getarg()
In: argval.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
CHARDATE autodate(struct tm *tbp, int fmt, int code) ;
Exerpted from the function prototype
In: Autodate.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
CHARTIME autotime(struct tm *tbp) ;
Exerpted from the function prototype
In: Autodate.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char *capitalise(char *s) ;
Exerpted from the function prototype
In: capitals.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int chopinsert(void **Table, int *Items, int Tablimit, void *NewItem, int InsertPoint) ;
chopinsert() adds a entry to the search table in the place indicated by
InsertPoint. It returns Tablimit if the table is full,
zero if the insert was OK.
In: chopins.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void *chopsearch(void *Target, void **Table, int Items, int *InsertHere, int (*Compare)(const void*, const void*)) ;
chopsearch() returns a pointer to the target item if it was found
and NULL if it wasn't found.
In: chopsrch.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
struct COUNTRY *country(int xcode, struct COUNTRY *cp) ;
country() provides a degree of international independance to a
program. It started as an attempt to implement the Borland DOS
country() function for OS/9. The result was subsequently
ported to Linux. This explains the interface and omissions from the
information returned, as these exactly match the Borland definition.
The implementation is derived from the termcap system.
If country() is called with xcode=0 the default country
will be processed. If it is called with cp set to -1 the
contents of xcode becomes the default for the rest of the
program run. Calls with a pointer to the struct and a non-zero country
code access details for the requested country.
Information from the database is returned in the following structure:
struct COUNTRY {
int co_date; 0 - US format: MM.DD.CCYY
1 - European: DD.MM.CCYY
2 - Japanese: CCYY.MM.DD
char co_curr[5]; The currency symbol. Up to 4 characters.
char co_thsep[2]; The symbol used to delimit thousands.
char co_desep[2]; The symbol used for a decimal point.
char co_dtsep[2]; The separator used within dates.
char co_tmsep[2]; The separator used within times.
char co_currstyle; 0 - symbol preceeds value w/o gap.
1 - symbol follows value w/o gap.
2 - symbol preceeds value w/space between.
3 - symbol follows value w/space between.
char co_digits; 1-3 Number of decimal places
char co_time; 0 = 12 hour time format: HH.MM.SS am
1 = 24 hour time format: HH.MM.SS
long co_case; not used - conformity with Borland C
char co_dasep[2]; The character used in delimited data files
to separate fields. Usually a comma.
char co_fill[10];
};
National information is held in a database file.
This is /dd/sys/country in the OS-9 implementation,
/usr/local/etc/country in the Linux implementation,
and C:\etc\country in the Windows version/
If the database cannot be found country() returns values for
the UK and will do so regardless of the country code input.
If the database file does exist it must be correctly formatted and the
first line in the file that is not blank or a comment must be the
default country definition, e.g.
default=44
Any line starting with an asterisk is treated as a comment.
The order of other entries is not important; a country data
definition block must be correctly formatted. A missed default
definition, a reference to a missing country, or a malformed
country definition block will all cause errors. A country data
block has the following format:
dialcode:[keyword=value:]...
where dialcode is the international dialing code for the country.
Each data block must be contiguous, must not contain comments or
blank lines, and must be separated from the next data block by at
least one blank line or comment. The minimum UK/US database is:
default=44
*UK
44:datefmt=1:datesep=/:currsym=x9c:currdec=2:currsty=0:thousep=,:\
decpt=.:timefmt=1:timesep=::casemap=18222325:datasep=,:
*USA
01:datefmt=0:datesep=/:currsym=$:currdec=2:currsty=0:thousep=,:\
decpt=.:timefmt=0:timesep=::datasep=,:
The parameters describing the country are all of the form
keyword=value
and may not contain spaces. If necessary, values may be supplied as
hexadecimal strings, which will be converted to the equivalent
character string before validation and length checking. A hex string
is made of the repeating group 'xhh', e.g. x30x31x32 is '012'.
The parameters are:
casemap - Exists for conformity with DOS. Not used by OS/9.
currdec - 1 - 3 Number of decimal places in the currency.
currsty - 0 - Currency symbol preceeds value without a gap.
1 - Currency symbol follows value without a gap.
2 - Currency symbol preceeds value with a space between.
3 - Currency symbol follows value with a space between.
currsym - The currency symbol. Up to 4 characters.
datasep - The character used in delimited data files to separate
fields. Usually a comma.
datefmt - 0 - US format: MM.DD.CCYY
1 - European: DD.MM.CCYY
2 - Japanese: CCYY.MM.DD
datesep - The separator used within dates (shown above as '.').
decpt - The symbol used for a decimal point
thousep - The symbol used to delimit thousands.
timefmt - 0 - 12 hour time format: HH.MM.SS xx (xx = am or pm))
1 - 24 hour time format: HH.MM.SS
timesep - The separator used within times (shown above as '.').
OS9: /dd/sys/country
Linux: /usr/local/etc/country
Windows: c:\etc\country
In: country.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int dirclose(dp) DIRPATH *dp; ;
Exerpted from the function prototype
In: diracc.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
DIRPATH *diropen(p) char *p; ;
MS-DOS-specific versions of diropen, dirclose, dirread, dirsize.
In: diracc.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int dirread(dp,name) DIRPATH *dp; char *name; ;
Exerpted from the function prototype
In: diracc.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void dumphex(FILE *f, char *buff, int lth) ;
Exerpted from the function prototype
In: dumphex.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
void error(char *f, char *e, char *p);
Exerpted from the function prototype
In: environ.h
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void *expand_space(void *pp, size_t n) ;
This is a convenience wrapper for realloc(). It
expands the area pointed to by pp to n bytes
and returns a pointer to the new area.
If it fails to get the requested space it abandons with
a suitable error message by calling error().
In: getspace.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
long filesize(name) char* name; ;
Exerpted from the function prototype
In: filesize.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char* fixext(char *name, char *ext) ;
Exerpted from the function prototype
In: fixext.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char *fixname(char *name, char *ext, char *type) ;
Exerpted from the function prototype
In: fixname.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char *fixpath(char *path, char *ext, char *type) ;
Exerpted from the function prototype
In: fixpath.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void *get_space(size_t n) ;
This is a convenience wrapper for malloc(). It
allocates n bytes and returns a pointer to it.
If this fails to get the requested space it abandons
with a suitable error message by calling error().
In: getspace.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int getarg(int nargc, char **nargv) ;
getarg
Harlow,
U.K.
getarg returns command line parameters ignored by getopt().
It must only be called after getopt() has completely scanned
the command parameters. optind should be reset to 1 before the
first call.
getarg Should be called repeatedly until it returne EOF.
Each call returns one of the following values:
option value by getopt(). Ignore it.
NOTE:
This version can ONLY be compiled under Linux, as the tell()
function uses writeln() to force a newline onto the terminal;
writeln() is not a standard UNIX function.
See also: getopt(), argval()
In: argparse.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char getdelcode(void) ;
Exerpted from the function prototype
In: getdelcd.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int getopt(int nargc, char * const nargv[], const char *ostr) ;
getopt - extended version.
Masterbyte Software
Los Gatos, CA
Harlow,
U.K.
getopt is used to parse options on the command
line. The extension to OS/9 standards adds these facilities:
Defaults to case sensitive.
been processed as options and/or option values
getopt is called repeatedly with the same parameters to process
all the arguments on the command line.
Each call returns NULL if the command line argument is not an option:
it should be called again to skip this argument. It returns EOF when all
arguments have been processed. It returns each option character as
it is found: if the option has an associated value then optarg
points to a string containing the option value.
After getopt has completely processed the command line
getarg() should be used to retrieve the other argument(s).
NOTE:
This version can ONLY be compiled under Linux, as the tell()
function uses writeln() to force a newline onto the terminal;
writeln() is not a standard UNIX function.
See also: getarg(), argval()
In: argparse.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char* getpath(int argc, char *argv[], FILE *pathlist, int listflag);
A general purpose file name handler. It retrieves filenames from the command line arguments argc and argv if listflag is FALSE. The filenames are read from the pathlist file if listflag is TRUE. getpath() is used in conjunction with the command line parsing functions getopt() and getarg().
getpath() is called repeatedly until it returns null. Each call returns a pointer to the next filename or null when the end of the list is reached.
Assumptions are that when it is called:
A convention observed by all OS-9 command line utilities is the use of the -z option to provide an alternative to passing filenames as command line arguments. If the option is absent the filename(s) are passed as command line arguments. If the -z option is present they will be taken from a file. If the option takes the form -z=filename then the list of filenames will be read from from the filename supplied as the option value. If option takes the form -z then the list of files is read from stdin.
getpath() was originally written to implement this convention. When getopt() encounters a -z option, listflag is set TRUE. If optarg contains a filename this is opened for reading. If optarg is blank stdin is cloned. The result is passed to getpath() as pathlist.
In: getpath.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char *getwd(char *buff) ;
Exerpted from the function prototype
In: getwd.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char *itoa(int i, char *a, int r);
Transform the integer i into an ASCII string and store the result in the buffer a, which must be long enough to hold the resulting string. The numeric string is encoded in the base given in r. The base must be in the range 2 to 36. If it is outside this range it is defaulted to base 10. This is a recursive function that occupies a stack level for every digit in the output string.
The function returns a pointer to a.
- written by Lew Pitcher
In: itoa.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void logdump(void) ;
logdump() - prints the buffer set up by logmsg().
If the debugging flag DIRECT_LOG is on this function does nothing.
If it is off all unprinted messages in the buffer are printed.
In: logmsg.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void logmsg(char* fmt, ...) ;
logmsg() - handles message logging.
If the debugging flag DIRECT_LOG is on this call is equivalent
to 'fprintf(stderr, format, ....)'. If it is off each message
is timestamped and written to a circular buffer, from where it
is printed by logdump().
In: logmsg.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void logsetup(int r, int f) ;
logsetup() - selects operational mode and output file no
In: logmsg.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char *ltoa(long i, char *a, int r) ;
Transform the long integer i into an ASCII string
and store the result in the buffer a, which must be long enough
to hold the resulting string. The numeric string is encoded in the base
given in r. The base must be in the range 2 to 36. If it is
outside this range it is defaulted to base 10. This is a recursive
function that occupies a stack level for every digit in the output string.
The function returns a pointer to a.
- written by Lew Pitcher
In: ltoa.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char *progname(void) ;
Exerpted from the function prototype
In: progname.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int question(char *prompt) ;
Exerpted from the function prototype
In: question.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void *release_space(void *p) ;
This is a convenience wrapper for free(). It
releases the space pointed to by p and returns null.
If p is null it abandons with a suitable error
message by calling error().
In: getspace.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int setpause(int action, int pathno) ;
Exerpted from the function prototype
In: setpause.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void setprog(char *name) ;
Exerpted from the function prototype
In: progname.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
char *strmfe(char *fullname, char *name, char *ext) ;
Exerpted from the function prototype
In: strmfe.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int swapdir(char *path) ;
Exerpted from the function prototype
In: swapdir.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void tabclear(char *tabstops) ;
Exerpted from the function prototype
In: tabclear.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int tabdefault() ;
Exerpted from the function prototype
In: tabdefau.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int tabexpand(char dest[], int i, char *tabstops, char fill) ;
Exerpted from the function prototype
In: tabexpan.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void tabnormal(char *tabstops) ;
Exerpted from the function prototype
In: tabnorma.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int tabout(FILE *fn, int i, char *tabstops) ;
Exerpted from the function prototype
In: tabout.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int tabpos(int col, char *tabstops) ;
Exerpted from the function prototype
In: tabpos.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void tabset(int col, char state, char *tabstops) ;
Exerpted from the function prototype
In: tabset.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
void tabspread(int gap, char *tabstops) ;
Exerpted from the function prototype
In: tabsprea.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
tempstore* tsclose(tempstore *ptr) ;
close the storage system
In: tempstor.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int tsgetc(tempstore *ptr) ;
get a character from storage
In: tempstor.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int tsgetstr(tempstore *ptr, char *str, int n) ;
get a string from storage
In: tempstor.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
tempstore* tsopen(long s, int d) ;
initialise the storage system
In: tempstor.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int tsputc(tempstore *ptr, int c) ;
store a character
In: tempstor.c
Return to the top
#include <stdio.h>
#include <dirent.h>
#include <time.h>
#include <environ.h>
int tsputstr(tempstore *ptr, char *str) ;
store a string
In: tempstor.c
Return to the topATTRIBUTE | #define ATTRIBUTE 11 |
AUTOFMT | #define AUTOFMT 0 |
BLANK | #define BLANK ' ' |
BUFFLIM | #define BUFFLIM 21 |
DDMMMYY | #define DDMMMYY 1 |
DIRECT_LOG | #define DIRECT_LOG 1 |
DIRENT | #define DIRENT 32 |
DIR_EOF | #define DIR_EOF 0 |
DIR_FILE | #define DIR_FILE 2 |
DIR_NULL | #define DIR_NULL 1 |
DIR_SUBDIR | #define DIR_SUBDIR 3 |
DOT | #define DOT '.' |
EOF | #define EOF (-1) |
FALSE | #define FALSE 0 |
FIRSTCALL | #define FIRSTCALL 1 |
FORM_FEED | #define FORM_FEED 0x0c |
FOUND | #define FOUND 1 |
INDIRECT_LOG | #define INDIRECT_LOG 0 |
MANUAL | #define MANUAL 2 |
MAXEXT | #define MAXEXT 5 |
MAXFILE | #define MAXFILE 9 |
MAXLINE | #define MAXLINE 161 |
MAXNAME | #define MAXNAME 12 |
MAXPATH | #define MAXPATH 80 |
MSDOS | #define MSDOS "MS-DOS" |
NAMELTH | #define NAMELTH 256 |
NAMESIZE | #define NAMESIZE 12 |
NEXTCALL | #define NEXTCALL 2 |
NOTHING | #define NOTHING 0 |
NULL | #define NULL (0) |
PATHSEP | #define PATHSEP "\\" |
PRINTER | #define PRINTER "lpt2:" |
P_NOPAUSE | #define P_NOPAUSE 3 |
P_PAUSE | #define P_PAUSE 2 |
P_RECORD | #define P_RECORD 1 |
P_RESTORE | #define P_RESTORE 4 |
SEPARATOR | #define SEPARATOR '\\' |
SEPCHAR | #define SEPCHAR '\\' |
STDERR_LOG | #define STDERR_LOG 2 |
STDOUT_LOG | #define STDOUT_LOG 1 |
TABSPACE | #define TABSPACE 8 |
TRUE | #define TRUE 1 |
TSLIM | #define TSLIM 16384 |
UNDERSCORE | #define UNDERSCORE '_' |
max | #define max(a,b) ( a>b ? a : b ) |
min | #define min(a,b) ( a<b ? a : b ) |
BYTE | typedef unsigned char BYTE; |
CHARDATE | typedef char* CHARDATE; |
CHARTIME | typedef char* CHARTIME; |
COUNTRY | struct COUNTRY { int co_date; char co_curr[5]; char co_thsep[2]; char co_desep[2]; char co_dtsep[2]; char co_tmsep[2]; char co_currstyle; char co_digits; char co_time; long co_case; char co_dasep[2]; char co_fill[10]; }; |
DIRPATH | typedef struct { struct ffblk *p; int status; char path[NAMELTH]; } DIRPATH; |
tempstore | typedef struct { char *buffer; int fileused; char *filename; FILE* fil; int inptr; int outptr; int size; } tempstore; |
optarg | extern char *optarg; |
optbad | extern int optbad; |
optcase | extern int optcase; |
optchar | extern int optchar; |
opterr | extern int opterr; |
opterrfd | extern int opterrfd; |
optind | extern int optind; |
optmaybe | extern int optmaybe; |
optneed | extern int optneed; |
optopt | extern int optopt; |
optstart | extern char *optstart; |