Mail Archives: djgpp/2000/05/25/05:47:35
> > BTW, to libc mantainer(s): since djgpp libc already
> > contains some functions non-standard functions just
> > for compatibility with Borland or MS compilers,
could
> > it be meaningful to add strrev() to it ?
>
> If you can show that it's a "standard" function in MS
or Borland, and
I have no access to MS compilers, but I verified
that function strrev() appears in Borland C 5,
Watcom C 11.0 and Borland C++Builder, in all cases
it is in file string.h and it has the same
prototype.
> you're willing to write the code *and* documentation
for it, we'll
> probably accept it.
I wrote source (.c) and doc (.txh). It's the first
time I submit some addition to djgpp, so I'm still
figuring out exactly the changes to the various
makefile's, .h files or anything else... :-)
I'm sending you: a diff file for string.h and one
for makefile in src/libc/compat/string; the .c file
and the .txh file. I hope it is all OK.
ciao
Giacomo
---------------------------------------------------
Giacomo Degli Esposti - pad2369 AT iperbole DOT bologna DOT it
------------ string.dif -----------------------
*** include/string.old Sun Jun 28 20:02:34 1998
--- include/string.h Wed May 24 18:22:56 2000
***************
*** 63,68 ****
--- 63,69 ----
int stricmp(const char *_s1, const char *_s2);
int strncasecmp(const char *_s1, const char *_s2,
size_t _n);
int strnicmp(const char *_s1, const char *_s2,
size_t _n);
+ char * strrev(char *_s);
char * strsep(char **_stringp, const char
*_delim);
char * strupr(char *_s);
------------- END of string.dif ---------------
---------- makefile.dif -----------
*** src/libc/compat/string/makefile.old Fri Dec 24
15:47:24 1999
--- src/libc/compat/string/makefile Wed May 24
18:13:34 2000
***************
*** 12,17 ****
--- 12,18 ----
SRC += strlwr.c
SRC += strncase.S
SRC += strnicmp.c
+ SRC += strrev.c
SRC += strsep.c
SRC += strupr.c
--------------- END of makefile.dif
---------- src/libc/compat/string/strrev.c ----
#include <string.h>
char *
strrev( char *s )
{
char *p1, *p2;
char c;
if( s != NULL ) {
p1 = s;
p2 = s + strlen(s) - 1;
while( p1 < p2 )
{
c = *p1;
*p1 = *p2;
*p2 = c;
p1++; p2--;
}
}
return s;
}
----------- END of strrev.c -------------------
---------- src/libc/compat/string/strrev.txh --
@node strrev, string
@subheading Syntax
@example
#include <string.h>
char *strrev( char *s );
@end example
@subheading Description
This function replaces string @var{s} with a string
whose characters are in the reverse order, except
for the ending null characters, which remains last.
@subheading Return Value
The address of the original string @var{s}.
@subheading Portability
@portability !ansi, !posix
@subheading Example
@example
#include <stdio.h>
#include <string.h>
char buf[] = { "Hello, world!" };
int main(void)
{
printf( "%s\n", buf );
printf( "%s\n", strrev( buf ) );
printf( "%s\n", strrev( buf ) );
return 0;
}
produces the following output:
Hello, world!
!dlrow ,olleH
Hello, world!
@end example
--------------- END of strrev.txh -------------
- Raw text -