On Mon, 30 Jul 2001, after playing in traffic, Jeff Raven yelped:
> 
> Well, the menu parser is currently line-based and rather
> nasty... some easier solutions would be to either
>    -- put the long command in a script, and just use the
>       script as the command instead
>    -- set up some X resources and use "aterm -name whatever"
>       (at least rxvt uses -name, so aterm probably does)
> 

Here's my 'quick' way of implementing the ability to break lines...

-----
char * get_file_ent (FILE * fd)
{
        char * ret;
        char * buf;
        char * tmp;
        int cnt;
        cnt = 0;
        buf = malloc(16384);
        fgets(buf, 16384, fd);
        while (buf[strlen(buf) - 1] == '\\')
        {
                if (cnt == 0)
                {
                        tmp = malloc(strlen(buf) + 1);
                } else {
                        tmp = realloc(ret, cnt + strlen(buf) + 1);
                }
                if (tmp == NULL)
                {
                        fprintf(stderr, "Memory allocation error.\n");
                        return NULL;
                }
                ret = tmp;
                if (cnt == 0)
                {
                        strcpy(ret, buf);
                } else {
                        strcat(ret, buf);
                }
                cnt += strlen(buf);
                free(buf);
                buf = malloc(16384);
                fgets(buf, 16384, fd);
        }
        if (cnt == 0)
        {
                tmp = malloc(strlen(buf) + 1);
        } else {
                tmp = realloc(ret, cnt + strlen(buf) + 1);
        }
        if (tmp == NULL)
        {
                fprintf(stderr, "Memory allocation error.\n");
                return NULL;
        }
        ret = tmp;
        if (cnt == 0)
        {
                strcpy(ret, buf);
        } else {
                strcat(ret, buf);
        }
        cnt += strlen(buf);
        free(buf);
        return ret;
}
-----

There are a few problems with this code snippet: 1) a large amount of code
repetition, 2) nether the \ nor the \n are removed. (note on #2: it seems
that most implementations of SH (including BASH) will not care about that,
and will just process it anyway...)

Now if I can only come up with a cryptic implementation for TITS
(http://www.pointlessmovement.net/hacks/oxsh)...

--gile
-- 
"i think when somebody goes to a software site and sees TITS, they are
obligated to click" -dingo

Reply via email to