Skip to content

Commit

Permalink
Add some missing strXXX() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
agn453 committed Mar 8, 2020
1 parent 2777654 commit 26fcad4
Show file tree
Hide file tree
Showing 29 changed files with 1,554 additions and 28 deletions.
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,116 @@ Extended getenv()


Release v3.09-3b
---------------
----------------

Updated the previous release to adjust the ordering of modules in LIBC.LIB -
programs should now link correctly. Also added the missing documentation for
the debugger in doc/DEBUGMAN.TXT (this was previously available from the
now defunct hitech.com.au web site) and scanned PDFs of the 1989
vintage documentation.


Release v3.09-4
---------------

Some of the string related function prototypes in STRING.H are missing from
the LIBC.LIB library. Most of these are from an update to the MSX flavour
of HI-TECH C by Arnold Metsalaar. I've cherry-picked the following routines
which are applicable to generic CP/M as well as MSX.

```
STRING.H
The header file has been changed to reflect the available
functions in LIBC.LIB. There are still missing routines -
namely strcoll() strcspn() strpbrk() and strspn() and these
have been commented out for now.
strchr() and strrchr()
char *strchr(char *s, int c)
char *strrchr(char *s, int c)
These functions - as well as index() and rindex() (which are identical)
previously returned a NULL for no match. The functions now return
a pointer to the character string's ending NUL character.
stricmp() and strnicmp()
char stricmp(char *s1, char *s2)
char strnicmp(char *s1, char *s2, size_t n)
Case-insensitive versions of strcmp() and strncmp() comparison routines.
Can also be referenced as strcasecmp() and strncasecmp().
strstr(), strnstr(), stristr() and strnistr()
char *strstr(char *t, char *s)
char *strnstr(char *t, char *s, unsigned int n)
char *strcasestr(char *t, char *s)
char *strncasestr(char *t, char *s, unsigned int n)
These extra functions locate the first occurrence of string s in
string t. The functions strnstr() and strcasestr() read at most
n characters from the string t. The functions strcasestr() and
casencasestr() use case insensitive comparisons.
All these functions return a pointer to the first character of
the first occurence ofstring s in string t if found, and NULL
otherwise.
strdup()
char *strdup(char *s)
Allocates a new buffer for and copies the string pointed to
by s to it. Returns a pointer to the copy of the string or NULL
if the memory allocation failed. The memory block can be released
using free().
strtok()
char *strtok(char *s, char *tok, size_t toklen, char *brk)
Copies charactersfrom s to tok until it encounters one of the
characters in brk or until toklen-1 characters have been copied
(whichever comes first). It then adds a NUL character to the
end of the string. This is a non-conforming POSIX function.
TIME.H
Now includes a prototype for strftime() - see below.
strftime()
size_t strftime(char *s, size_t maxs, char *f, struct tm *t)
Converts a time value t to a string using the format string f
into the string s of size maxs (including a terminating NUL).
It acts as a sprintf() function for date/time values. The
following are valid in the format string -
%A full weekday name (Monday)
%a abbreviated weekday name (Mon)
%B full month name (January)
%b abbreviated month name (Jan)
%c standard date and time representation
%d day-of-month (01-31)
%H hour (24 hour clock) (00-23)
%I hour (12 hour clock) (01-12)
%j day-of-year (001-366)
%M minute (00-59)
%m month (01-12)
%p local equivalent of AM or PM
%S second (00-59)
%U week-of-year, first day sunday (00-53)
%W week-of-year, first day monday (00-53)
%w weekday (0-6, sunday is 0)
%X standard time representation
%x standard date representation
%Y year with century
%y year without century (00-99)
%Z timezone name
%% percent sign
the standard date string is equivalent to:
%a %b %d %Y
the standard time string is equivalent to:
%H:%M:%S
the standard date and time string is equivalent to:
%a %b %d %H:%M:%S %Y
strftime() returns the number of characters placed in the
buffer, not including the terminating NUL, or zero if more
than maxs characters were produced.
```
Binary file added dist/LIBC##.LIB
Binary file not shown.
Binary file modified dist/LIBC.LIB
Binary file not shown.
39 changes: 39 additions & 0 deletions dist/STRING##.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* String functions */

#ifndef _STDDEF
typedef int ptrdiff_t; /* result type of pointer difference */
typedef unsigned size_t; /* type yielded by sizeof */
#define _STDDEF
#define offsetof(ty, mem) ((int)&(((ty *)0)->mem))
#endif _STDDEF

#ifndef NULL
#define NULL ((void *)0)
#endif NULL

extern int errno; /* system error number */

extern void *memcpy(void *, void *, size_t);
extern void *memmove(void *, void *, size_t);
extern char *strcpy(char *, char *);
extern char *strncpy(char *, char *, size_t);
extern char *strcat(char *, char *);
extern char *strncat(char *, char *, size_t);
extern int memcmp(void *, void *, size_t);
extern int strcmp(char *, char *);
extern int strcasecmp(char *, char *);
extern int strncmp(char *, char *, size_t);
extern int strnicmp(char *, char *, size_t);
#define strncasecmp strnicmp
extern size_t strcoll(char *, size_t, char *);
extern void *memchr(void *, int, size_t);
extern size_t strcspn(char *, char *);
extern char *strpbrk(char *, char *);
extern size_t strspn(char *, char *);
extern char *strstr(char *, char *);
extern char *strtok(char *, char *);
extern void *memset(void *, int, size_t);
extern char *strerror(int);
extern size_t strlen(char *);
extern char *strchr(char *, int);
extern char *strrchr(char *, int);
22 changes: 15 additions & 7 deletions dist/STRING.H
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* String functions */
/* String functions v3.09-4 */

#ifndef _STDDEF
typedef int ptrdiff_t; /* result type of pointer difference */
Expand All @@ -23,17 +23,25 @@ extern int memcmp(void *, void *, size_t);
extern int strcmp(char *, char *);
extern int strcasecmp(char *, char *);
extern int strncmp(char *, char *, size_t);
extern int strnicmp(char *, char *, size_t);
#define strncasecmp strnicmp
extern size_t strcoll(char *, size_t, char *);
extern int strncasecmp(char *, char *, size_t);
#define strnicmp strncasecmp
/* extern size_t strcoll(char *, size_t, char *); */ /* missing */
extern void *memchr(void *, int, size_t);
extern size_t strcspn(char *, char *);
extern char *strpbrk(char *, char *);
extern size_t strspn(char *, char *);
/* extern size_t strcspn(char *, char *); */ /* missing */
/* extern char *strpbrk(char *, char *); */ /* missing */
/* extern size_t strspn(char *, char *); *//* missing */
extern char *strstr(char *, char *);
extern char *strtok(char *, char *);
extern void *memset(void *, int, size_t);
extern char *strerror(int);
extern size_t strlen(char *);
extern char *strchr(char *, int);
/* #define index strchr */ /* these are equivalent */
extern char *index(char *, int);
extern char *strrchr(char *, int);
/* #define rindex *strrchr */ /* these are equivalent */
extern char *rindex(char *, int);
extern char *strcasestr(char *, char *);
#define stristr strcasestr
extern char *strncasestr(char *, char *, size_t);
#define strnistr strncasestr
27 changes: 27 additions & 0 deletions dist/TIME#.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef _TIME

typedef long time_t; /* for representing times in seconds */
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
#define _TIME
#endif _TIME

extern int time_zone; /* minutes WESTWARD of Greenwich */
/* this value defaults to 0 since with
operating systems like MS-DOS there is
no time zone information available */

extern time_t time(time_t *); /* seconds since 00:00:00 Jan 1 1970 */
extern char * asctime(struct tm *); /* converts struct tm to ascii time */
extern char * ctime(); /* current local time in ascii form */
extern struct tm * gmtime(); /* Universal time */
extern struct tm * localtime(); /* local time */
10 changes: 10 additions & 0 deletions dist/TIME.H
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* time.h for HI-TECH C Z80 v3.09-4*/

#ifndef _TIME

typedef long time_t; /* for representing times in seconds */
Expand All @@ -15,6 +17,13 @@ struct tm {
#define _TIME
#endif _TIME

#ifndef _STDDEF
typedef int ptrdiff_t; /* result type of pointer difference */
typedef unsigned size_t; /* type yielded by sizeof */
#define _STDDEF
#define offsetof(ty, mem) ((int)&(((ty *)0)->mem))
#endif

extern int time_zone; /* minutes WESTWARD of Greenwich */
/* this value defaults to 0 since with
operating systems like MS-DOS there is
Expand All @@ -25,3 +34,4 @@ extern char * asctime(struct tm *); /* converts struct tm to ascii time */
extern char * ctime(); /* current local time in ascii form */
extern struct tm * gmtime(); /* Universal time */
extern struct tm * localtime(); /* local time */
extern size_t strftime(char *s, size_t maxs, char *f, struct tm *t);
Loading

0 comments on commit 26fcad4

Please sign in to comment.