Split one argument into multiple args

266 views Asked by At

I am launching a c program from a Custom uRL Protocol.

Custom URL Protocols urlencode all args and combine them into one string. No way around this.

This is my Windows only attempt but it crashes. getopt_long doesn't like my newly created argv.

    bool main_init(int argc, char *argv[])
    {
        // if url protocol
        if (strstr(argv[1], "protocol:") != NULL)
        {
            //decode and remove protocol.
            char *decoded = url_decode(argv[1])+9;
            // wrap " around original argv[0] and prepend to argv[1]
            LPSTR buf[1024];
            strcpy(buf, "\"");
            strcat(buf, argv[0]);
            strcat(buf, "\" ");
            strcat(buf, decoded);
            // ANSi version of CommandLineToArgvW: http://alter.org.ua/docs/win/args/
            argv = CommandLineToArgvA(buf, &argc);
            // argv appears correct at this point
        }
// protocol causes crash here
        int c = getopt_long(argc, argv, optstring, opts, NULL);
    }

Thanks.

0

There are 0 answers