]> granicus.if.org Git - yasm/commitdiff
Make dual functions: _new (which allocates) and _init (which just copies) to
authorPeter Johnson <peter@tortall.net>
Mon, 8 Apr 2002 00:30:39 +0000 (00:30 -0000)
committerPeter Johnson <peter@tortall.net>
Mon, 8 Apr 2002 00:30:39 +0000 (00:30 -0000)
make C conversion elsewhere easier.

svn path=/trunk/yasm/; revision=580

tools/re2c/substr.c
tools/re2c/substr.h

index 26529bc4c8d8d3df2b4cf7fc750de8a3ad60a9b6..de18f0d16f00c093136d89ea388ee94f7c2d1b12 100644 (file)
@@ -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;
index c1db6fa50a5711a12a02443eecc7ec5ac5877ee1..9ee849d7f2904534b8f38913fa8790d3e5d1a8b6 100644 (file)
@@ -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;