ANSI C conversion of code, rename some parameters to better names and adapt man page accordingly.

This commit is contained in:
carl 2019-05-11 00:57:58 +08:00
parent add131b6f9
commit 8b290cf68a
12 changed files with 43 additions and 98 deletions

View file

@ -13,9 +13,9 @@ char *strzero(char *s);
char *str2bts(char *s, char *b, int *n);
char *long2str(long l, int b);
long str2long(char *s, int b);
char *btscpy(char *s1, char *s2, int n);
char *btscat(char *s1, int n1, char *s2, int n2);
int btscmp(char *s1, int n1, char *s2, int n2);
char *btscpy(char *b1, char *b2, int n);
char *btscat(char *b1, int n1, char *b2, int n2);
int btscmp(char *b1, int n1, char *b2, int n2);
char *btszero(char *b, int n);
char *bts2str(char *b, int n, char *s);

View file

@ -8,12 +8,7 @@
#include "ack_string.h"
char *
btscat(b1, n1, b2, n2)
char *b1;
int n1;
register char *b2;
register int n2;
char *btscat(char* b1, int n1, register char *b2, register int n2)
{
register char *b = b1 + n1;

View file

@ -8,12 +8,9 @@
#include "ack_string.h"
int
btscmp(b1, n1, b2, n2)
register char *b1, *b2;
int n1, n2;
int btscmp(register char *b1, int n1, register char *b2, int n2)
{
register n = (n1 <= n2) ? n1 : n2;
register int n = (n1 <= n2) ? n1 : n2;
while (n-- > 0) {
if (*b1++ != *b2++)

View file

@ -8,10 +8,7 @@
#include "ack_string.h"
char *
btscpy(b1, b2, n)
register char *b1, *b2;
register int n;
char *btscpy(register char *b1, register char *b2, register int n)
{
char *b1s = b1;

View file

@ -8,10 +8,7 @@
#include "ack_string.h"
char *
btszero(b, n)
char *b;
register int n;
char *btszero(char *b, register int n)
{
register char *s = b;

View file

@ -14,10 +14,7 @@
#define MAXWIDTH 32
char *
long2str(val, base)
register long val;
register base;
char *long2str(register long val, register int base)
{
static char numbuf[MAXWIDTH];
static char vec[] = "0123456789ABCDEF";
@ -40,10 +37,10 @@ long2str(val, base)
if (base < 0) { /* unsigned */
base = -base;
if (val < 0L) { /* taken from Amoeba src */
register mod, i;
register int mod, i;
overflow:
mod = 0;
for (i = 0; i < 8 * sizeof val; i++) {
for (i = 0; i < 8 * (int)sizeof(val); i++) {
mod <<= 1;
if (val < 0)
mod++;

View file

@ -8,9 +8,7 @@
#include "ack_string.h"
static
is_oct(c)
char c;
static int is_oct(char c)
{
return ((unsigned int)(c-'0') <= ('7'-'0'));
}
@ -20,11 +18,7 @@ is_oct(c)
The ascii length of the resulting string is returned, including the
terminating null-character.
*/
char *
str2bts(str, bts, pn)
register char *str;
char *bts;
int *pn;
char *str2bts(register char *str, char *bts, int *pn)
{
register char *t = bts;
@ -53,7 +47,7 @@ str2bts(str, bts, pn)
break;
default:
if (is_oct(*str)) {
register cnt = 0, oct = 0;
register int cnt = 0, oct = 0;
do
oct = oct * 8 + *str - '0';

View file

@ -8,9 +8,7 @@
#include "ack_string.h"
value(c, b)
char c;
int b;
static int value(char c, int b)
{
register int ch;
@ -23,10 +21,7 @@ value(c, b)
return b;
}
long
str2long(str, base)
register char *str;
int base;
long str2long(register char *str, int base)
{
int minus = 0, d;
long l = 0;

View file

@ -8,10 +8,7 @@
#include "ack_string.h"
char *
strindex(s, c)
register char *s;
int c;
char *strindex(register char *s, int c)
{
while (*s)
if (*s++ == c)

View file

@ -9,46 +9,27 @@ conversions between strings and row of bytes
.nf
.B #include <ack_string.h>
.PP
.B char *strindex(s, c)
.B char *s, c;
.B char *strindex(char *s, int c)
.PP
.B char *strrindex(s, c)
.B char *s, c;
.B char *strrindex(char *s, int c)
.PP
.B char *strzero(s)
.B char *s;
.B char *strzero(char *s)
.PP
.B char *str2bts(s, b, pn)
.B char *s, *b;
.B int *pn;
.B char *str2bts(char *s, char *b, int *n)
.PP
.B char *long2str(l, base)
.B long l;
.B int base;
.B char *long2str(long l, int b)
.PP
.B long str2long(s, base)
.B char *s;
.B int base;
.B long str2long(char *s, int b)
.PP
.B char *btscpy(b1, b2, n)
.B char *b1, *b2;
.B int n;
.B char *btscpy(char *b1, char *b2, int n)
.PP
.B char *btscat(b1, n1, b2, n2)
.B char *b1, *b2;
.B int n1, n2;
.B char *btscat(char *b1, int n1, char *b2, int n2)
.PP
.B int btscmp(b1, n1, b2, n2)
.B char *b1, *b2;
.B int n1, n2;
.B int btscmp(char *b1, int n1, char *b2, int n2)
.PP
.B char *btszero(b, n)
.B char *b;
.B int n;
.B char *btszero(char *b, int n)
.PP
.B char *bts2str(b, n, s)
.B char *b, *s;
.B int n;
.B char *bts2str(char *b, int n, char *s)
.fi
.SH DESCRIPTION
The
@ -60,7 +41,7 @@ functions operate on variable-length rows of bytes,
regardless of null bytes.
Neither of these functions check for overflow of any receiving area.
.PP
.I Strindex
.I strindex
.RI ( strrindex )
returns a pointer to the first (last)
occurrence of character
@ -72,12 +53,12 @@ or zero if
does not occur in
.IR s .
.PP
.I Strzero
.I strzero
turns
.I s
into a null string.
.PP
.I Bts2str
.I bts2str
turns a row of
.I n
consecutive bytes, the first of which is pointed by
@ -100,7 +81,7 @@ is turned into the string consisting of the following characters
.RE
The latter string could be represented in C as "\e\e000\e\en".
.PP
.I Str2bts
.I str2bts
turns string
.I s
into a sequence of bytes pointed by
@ -108,7 +89,7 @@ into a sequence of bytes pointed by
It has the inverse effect to
.IR bts2str .
The length of the resulting byte sequence is returned in
.RI * pn .
.RI *n .
.br
Both the functions
.I bts2str
@ -116,7 +97,7 @@ and
.I str2bts
return a pointer to the result.
.PP
.I Long2str
.I long2str
converts a long value
.I l
into a null-terminated string according to
@ -126,13 +107,13 @@ This base may be any of 2..16.
A negative base (in the range -16..-2) indicates that the long must be
seen as unsigned.
A pointer to the string is returned.
.I Str2long
.I str2long
returns the value that is represented in
.IR s ,
according to
.IR base .
.PP
.I Btscpy
.I btscpy
copies
.I n
bytes from the string of bytes
@ -142,7 +123,7 @@ to
and returns
.IR b1 .
.PP
.I Btscat
.I btscat
appends a copy of
.I n2
bytes from
@ -152,10 +133,10 @@ to the end of
consisting of
.I n1
bytes.
.I B1
.I b1
is returned.
.PP
.I Btscmp
.I btscmp
compares row of bytes
.I b1
with length
@ -170,12 +151,12 @@ is lexicographically greater then, equal to, or less than
.IR b2 ,
respectively.
.PP
.I Btszero
.I btszero
places
.I n
null bytes in the string
.IR b .
.I B
.I b
is returned.
.SH FILES
~em/modules/lib/libstring.a

View file

@ -6,10 +6,7 @@
#include "ack_string.h"
char *
strrindex(str, chr)
register char *str;
int chr;
char *strrindex(register char *str, int chr)
{
register char *retptr = 0;

View file

@ -8,9 +8,7 @@
#include "ack_string.h"
char *
strzero(s)
char *s;
char *strzero(char *s)
{
*s = '\0';
return s;