[Toybox] [patch] add sed

Strake strake888 at gmail.com
Thu Aug 8 19:30:30 PDT 2013


On 05/08/2013, Rob Landley <rob at landley.net> wrote:
> I put a partial version in pending to indicate that I've got this one,

Ah, sorry; I just noted that it wasn't working and started to write
it. I'll leave it to you if you wish.

>> -// Digested version of what sed commands can actually tell use to do.
>> +static wint_t xfgetwc (FILE *f) {
>> +  wint_t x = fgetwc (f);
>> +  if (x < 0) error_exit ("failed to read");
>> +  return x;
>> +}
>
> Some sort of wide character support, but not based on TOYBOX_I18N...

Is this to build in environments lacking the wc functions?

> So xafgetswde() calls afgetswde() which calls afgetwswde() and wcstoambs().

Should these be in another file?

> And the non-wide character version is implemented as a wrapper around the wide character version.

This seemed simpler and easier. Could be wrong.

>> +typedef struct {
>> +  char type;
>> +  union {
>> +    regex_t re;
>> +    long n;
>> +  };
>> +} Address;
>> +
>> +typedef struct Function {
>> +  char x;
>> +  union {
>> +    struct {
>> +      char *writ;
>> +      regex_t re;
>> +      int flags, fd;
>> +      long n, nMatch /* for s function, to pass to regexec */;
>> +    };
>> +    struct Function *fns;
>> +  };
>> +} Function;
>
> So this is a named struct _and_ a typedef?

Yes, to have pointers to own type.

> I haven't got any typedefs in the code. When it's a struct I say struct.
> I don't currently have a single enum in the cleaned up codebase:
> When I need a constant, I #define it. I try fairly hard not to need
> them.

Why?

> Not extending the code that was there, just zapping it all and
> replacing it with something completely unrelated.

Sorry, the longest-common-subsequence algorithm found this. It's
tedious to make diffs myself...

>> +static Command *cs;
>> +
>> +static long      parseNumber    (FILE *);
>> +static Address   parseAddress   (FILE *);
>> +static Function  parseFunction  (FILE *);
>> +static Function *parseFunctions (FILE *);
>> +static Command   parseCommand   (FILE *);
>
> Globals outside GLOBALS()

I get build failure if they are in GLOBALS:

unknown type name 'Command'
field X declared as a function

>> +/* parse natural number */
>> +static long parseNumber (FILE *f) {
>> +  ...
>> +}

> Sed reads a line of data into a buffer and operates on it. The posix
> "getline()" can do this, and in posix 2008 can even allocate the buffer
> for you
> ...
> In a buffer, you can use strtoul() which tells you where the number ended.

This is to parse the script, not the input.

 1376015430.0


More information about the Toybox mailing list