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 *str2bts(char *s, char *b, int *n);
char *long2str(long l, int b); char *long2str(long l, int b);
long str2long(char *s, int b); long str2long(char *s, int b);
char *btscpy(char *s1, char *s2, int n); char *btscpy(char *b1, char *b2, int n);
char *btscat(char *s1, int n1, char *s2, int n2); char *btscat(char *b1, int n1, char *b2, int n2);
int btscmp(char *s1, int n1, char *s2, int n2); int btscmp(char *b1, int n1, char *b2, int n2);
char *btszero(char *b, int n); char *btszero(char *b, int n);
char *bts2str(char *b, int n, char *s); char *bts2str(char *b, int n, char *s);

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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