Creative quoting schemes



  • I just came across this little gem of option parsing:

        if (strncmp("-file",token,5)==NULL)		// file
    {
    sscanf( token,"-file%s", szFile );
    // quick hack to allow spaces in path/file names
    // spaces must be given as '*'
    char *tmp;
    for ( tmp=szFile; *tmp; tmp++ )
    {
    if (*tmp=='*')
    *tmp=' ';
    }
    }

    To be fair, it's Windows code where all arguments come in a single string.



  • #define NULL  0xDEADBEEF



  • @Bulb said:

    I just came across this little gem of option parsing:

        if (strncmp("-file",token,5)==NULL)		// file
    {
    sscanf( token,"-file%s", szFile );
    // quick hack to allow spaces in path/file names
    // spaces must be given as '*'
    char *tmp;
    for ( tmp=szFile; *tmp; tmp++ )
    {
    if (*tmp=='*')
    *tmp=' ';
    }
    }

    To be fair, it's Windows code where all arguments come in a single string.

     

    parsing lpCmdLine aye?

     

    for those of our not familiar with raw win32 API this is the equivalent if int main(int argc, char argv*[])

    int WINAPI WinMain(      
        HINSTANCE hInstance,
        HINSTANCE hPrevInstance,
        LPSTR lpCmdLine,
        int nCmdShow
    );

     



  • @Bulb said:

    To be fair,

    'Fair'?  LOL!  Boy did you ever come to the wrong place!

    @Bulb said:

    To be fair, it's Windows code where all arguments come in a single string.
     

    But
    how is that an excuse anyway?  Normally when building a console
    application MSVC supplies you some CRT startup code that parses the
    command line into a standard {argc, argv} and calls your exe at the
    standard 'main()' entrypoint.  It seems as if whoever wrote that
    code decided to deliberately bypass the standard startup solely in
    order to be able to do a worse job of it.

    It's a lose-lose situation.  Cowboy/cargo-cult coder / NIH syndrome at work here?




  •  Yes.



  • @DaveK said:

    But
    how is that an excuse anyway?  Normally when building a console
    application MSVC supplies you some CRT startup code that parses the
    command line into a standard {argc, argv} and calls your exe at the
    standard 'main()' entrypoint.  It seems as if whoever wrote that
    code decided to deliberately bypass the standard startup solely in
    order to be able to do a worse job of it.

    This isn't from console application an CE don't seem to support them anyway. Still bad excuse for such creativity, especially when you spend quite some time trying to pass in a path with spaces (mounting internal flash disk on '/hard disk' in a consumer electronics device where end user is not supposed to access that part of the filesystem anyway is a bit of WTF of it's own).

    By the way, the program didn't work with files that had spaces in paths even after we found this, so there's more sloppiness lurking underneath – and most of it is a 3rd party library we don't have sources for.



  • What happened to using quotes when calling the app?

     app -file"my path name" 

    This works in Win32 - I can't test CE. 



  • @DaveK said:

    @Bulb said:

    To be fair,

    'Fair'?  LOL!  Boy did you ever come to the wrong place!

    @Bulb said:

    To be fair, it's Windows code where all arguments come in a single string.
     

    But
    how is that an excuse anyway?  Normally when building a console
    application MSVC supplies you some CRT startup code that parses the
    command line into a standard {argc, argv} and calls your exe at the
    standard 'main()' entrypoint.  It seems as if whoever wrote that
    code decided to deliberately bypass the standard startup solely in
    order to be able to do a worse job of it.

    It's a lose-lose situation.  Cowboy/cargo-cult coder / NIH syndrome at work here?


    If you're using MSVC.
    I believe there is an API function to automatically parse the command line into argc/argv, but it's difficult to find. I could be wrong though, or it may not exist in CE.


  • I guess I have to flame myself.   I tried the above with a command line app.

    This time I checked everything against a windowed application. Yes, WinMain - and MFC, if you are using that, get called with the entire command line as a single string.  However, Microsoft's WinMainCRTStartup assigns the variables __argc and __argv as expected, with the quoting nicely handled.

    So when your WinMain() is called you have regular parameter handling available.

    * again, the above is checked on Win32 - I don't have a CE setup available* 



  • @lolwtf said:

    If you're using MSVC.
    Actually, it's a msvcrt function, so it works at least with MinGW, too.@lolwtf said:
    I believe there is an API function to automatically parse the command line into argc/argv, but it's difficult to find. I could be wrong though, or it may not exist in CE.
    You mean CommandLineToArgvW?@DogmaBites said:
    However, Microsoft's WinMainCRTStartup assigns the variables __argc and __argv as expected, with the quoting nicely handled.
    I would call Microsoft's quoting anything but nice. You can read the description at the MSDN link above, but that doesn't give you the whole story - specifically, it only describes the behaviour of backslashes. There's some weird stuff going on when you have multiple consucetive quotes.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.