Make dual functions: _new (which allocates) and _init (which just copies) to

make C conversion elsewhere easier.

svn path=/trunk/yasm/; revision=580
0.3
Peter Johnson 23 years ago
parent bfe432b582
commit 05224a9fd9
  1. 17
      tools/re2c/substr.c
  2. 40
      tools/re2c/substr.h

@ -13,6 +13,13 @@ SubStr_eq(const SubStr *s1, const SubStr *s2)
return (s1->len == s2->len && memcmp(s1->str, s2->str, s1->len) == 0);
}
void
Str_init(Str *r, const SubStr* s)
{
SubStr_init(r, malloc(sizeof(char)*s->len), s->len);
memcpy(r->str, s->str, s->len);
}
Str *
Str_new(const SubStr* s)
{
@ -21,8 +28,16 @@ Str_new(const SubStr* s)
return r;
}
void
Str_copy(Str *r, Str* s)
{
SubStr_init(r, s->str, s->len);
s->str = NULL;
s->len = 0;
}
Str *
Str_copy(Str* s)
Str_new_copy(Str* s)
{
Str *r = SubStr_new(s->str, s->len);
s->str = NULL;

@ -13,19 +13,37 @@ struct SubStr {
typedef struct SubStr SubStr;
int SubStr_eq(const SubStr *, const SubStr *);
static inline void SubStr_init_u(SubStr*, uchar*, uint);
static inline SubStr *SubStr_new_u(uchar*, uint);
static inline void SubStr_init(SubStr*, char*, uint);
static inline SubStr *SubStr_new(char*, uint);
static inline SubStr *SubStr_copy(const SubStr*);
void SubStr_out(const SubStr *, FILE *);
static inline void SubStr_copy(SubStr*, const SubStr*);
static inline SubStr *SubStr_new_copy(const SubStr*);
void SubStr_out(const SubStr*, FILE *);
#define SubStr_delete(x) free(x)
typedef struct SubStr Str;
void Str_init(Str*, const SubStr*);
Str *Str_new(const SubStr*);
Str *Str_copy(Str*);
void Str_copy(Str*, Str*);
Str *Str_new_copy(Str*);
Str *Str_new_empty(void);
void Str_delete(Str *);
static inline void
SubStr_init_u(SubStr *r, uchar *s, uint l)
{
r->str = (char*)s;
r->len = l;
}
static inline SubStr *
SubStr_new_u(uchar *s, uint l)
{
@ -35,6 +53,13 @@ SubStr_new_u(uchar *s, uint l)
return r;
}
static inline void
SubStr_init(SubStr *r, char *s, uint l)
{
r->str = s;
r->len = l;
}
static inline SubStr *
SubStr_new(char *s, uint l)
{
@ -44,8 +69,15 @@ SubStr_new(char *s, uint l)
return r;
}
static inline void
SubStr_copy(SubStr *r, const SubStr *s)
{
r->str = s->str;
r->len = s->len;
}
static inline SubStr *
SubStr_copy(const SubStr *s)
SubStr_new_copy(const SubStr *s)
{
SubStr *r = malloc(sizeof(SubStr));
r->str = s->str;

Loading…
Cancel
Save