From: Peter Johnson <peter@tortall.net> Date: Sun, 7 Apr 2002 23:51:09 +0000 (-0000) Subject: Convert to C. X-Git-Tag: v0.2.0~261 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c71097348c05e7f7a9e83e2301171e38e1d82ebd;p=yasm Convert to C. svn path=/trunk/yasm/; revision=578 --- diff --git a/tools/re2c/substr.c b/tools/re2c/substr.c index 3275660e..26529bc4 100644 --- a/tools/re2c/substr.c +++ b/tools/re2c/substr.c @@ -1,30 +1,45 @@ #include <string.h> #include "substr.h" -void SubStr::out(ostream& o) const { - o.write(str, len); +void +SubStr_out(const SubStr *s, FILE *o) +{ + fwrite(s->str, s->len, 1, o); } -bool operator==(const SubStr &s1, const SubStr &s2){ - return (bool) (s1.len == s2.len && memcmp(s1.str, s2.str, s1.len) == 0); +int +SubStr_eq(const SubStr *s1, const SubStr *s2) +{ + return (s1->len == s2->len && memcmp(s1->str, s2->str, s1->len) == 0); } -Str::Str(const SubStr& s) : SubStr(new char[s.len], s.len) { - memcpy(str, s.str, s.len); +Str * +Str_new(const SubStr* s) +{ + Str *r = SubStr_new(malloc(sizeof(char)*s->len), s->len); + memcpy(r->str, s->str, s->len); + return r; } -Str::Str(Str& s) : SubStr(s.str, s.len) { - s.str = NULL; - s.len = 0; +Str * +Str_copy(Str* s) +{ + Str *r = SubStr_new(s->str, s->len); + s->str = NULL; + s->len = 0; + return r; } -Str::Str() : SubStr((char*) NULL, 0) { - ; +Str * +Str_new_empty(void) +{ + return SubStr_new(NULL, 0); } -Str::~Str() { - delete str; - str = (char*)-1; - len = (uint)-1; +void Str_delete(Str *s) { + free(s->str); + s->str = (char*)-1; + s->len = (uint)-1; + free(s); } diff --git a/tools/re2c/substr.h b/tools/re2c/substr.h index fb5e2cc2..c1db6fa5 100644 --- a/tools/re2c/substr.h +++ b/tools/re2c/substr.h @@ -1,45 +1,56 @@ -#ifndef _substr_h -#define _substr_h +#ifndef re2c_substr_h +#define re2c_substr_h -#include <iostream.h> +#include <stdio.h> +#include <stdlib.h> #include "basics.h" -class SubStr { -public: +struct SubStr { char *str; uint len; -public: - friend bool operator==(const SubStr &, const SubStr &); - SubStr(uchar*, uint); - SubStr(char*, uint); - SubStr(const SubStr&); - void out(ostream&) const; }; -class Str: public SubStr { -public: - Str(const SubStr&); - Str(Str&); - Str(); - ~Str(); -}; - -inline ostream& operator<<(ostream& o, const SubStr &s){ - s.out(o); - return o; +typedef struct SubStr SubStr; + +int SubStr_eq(const SubStr *, const SubStr *); +static inline SubStr *SubStr_new_u(uchar*, uint); +static inline SubStr *SubStr_new(char*, uint); +static inline SubStr *SubStr_copy(const SubStr*); +void SubStr_out(const SubStr *, FILE *); +#define SubStr_delete(x) free(x) + +typedef struct SubStr Str; + +Str *Str_new(const SubStr*); +Str *Str_copy(Str*); +Str *Str_new_empty(void); +void Str_delete(Str *); + +static inline SubStr * +SubStr_new_u(uchar *s, uint l) +{ + SubStr *r = malloc(sizeof(SubStr)); + r->str = (char*)s; + r->len = l; + return r; } -inline ostream& operator<<(ostream& o, const SubStr* s){ - return o << *s; +static inline SubStr * +SubStr_new(char *s, uint l) +{ + SubStr *r = malloc(sizeof(SubStr)); + r->str = s; + r->len = l; + return r; } -inline SubStr::SubStr(uchar *s, uint l) - : str((char*) s), len(l) { } - -inline SubStr::SubStr(char *s, uint l) - : str(s), len(l) { } - -inline SubStr::SubStr(const SubStr &s) - : str(s.str), len(s.len) { } +static inline SubStr * +SubStr_copy(const SubStr *s) +{ + SubStr *r = malloc(sizeof(SubStr)); + r->str = s->str; + r->len = s->len; + return r; +} #endif