[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

crtinit.c vs. quoted filenames



Hi all!
 
The code in crtinit.c for extracting the argv from the environment
doesn't handle quoted filenames correctly. Modern desktops (Thing,
Gemini) use ' for filenames that containing special characters, e.g. a
blank. If you doubleclick the file <i:\with blank> it would be send as
'i:\with blank' to the program. 
The code in crtinit.c (PL46, PL47) split this name into two args:
    argv[1] = 'i:\with
    argv[2] = blank'

I've implemented a simple parser that looks for ' in the cmdline. It
create a correct argv:
    argv[1] = i:\with blank

Please test it out and integrate it into the next PL. I've test it only
with PL46 for PureC.

 Chris.
 
--- mintlib.47\crtinit.c    Fri Jun 27 06:55:30 1997
+++ mintlib\crtinit.c   Sun Jan 11 12:16:44 1998
@@ -410,6 +410,10 @@
    while(i > 0 && isspace(*cmdln) )
        cmdln++,--i;
 
+#if 0
+/* 
+ * This code doesn't handle quoted file names correctly!
+*/ 
    while (i > 0) {
        if (isspace(*cmdln)) {
            --i; cmdln++;
@@ -422,6 +426,46 @@
            --i;
        }
    }
+#else
+{
+   int in_quote = 0;
+   
+   while (i > 0) 
+   {
+       if (*cmdln == '\'')
+       {
+           i--; cmdln++;
+           if (in_quote)
+           {
+               if (*cmdln == '\'')     /* double ': file name contains
' */
+               {
+                   *to++ = *cmdln++;
+                   i--;
+               }
+               else
+                   in_quote = 0;
+           }
+           else
+               in_quote = 1;
+       }
+       if ((*cmdln != ' ') || ((*cmdln == ' ' && in_quote)))
+       {
+           *to++ = *cmdln++;
+           i--;
+       }
+       else
+       {
+           --i; cmdln++;
+           while (i > 0 && isspace(*cmdln))
+               --i,cmdln++;
+           *to++ = 0;
+       }
+   }
+}
+#endif
+
+
    *to++ = '\0';
    *to = '\0'; /* bug fix example:cmdln == '\3' 'a' ' ' 'b' '\0' */
    /* the loop below expects \0\0 at end to terminate! */
 
------------------------------------------------------------------------
 Christian Felsch   email: felsch@tu-harburg.d400.de    (Big mails, uue)
 Bevenser Weg 18           christian_felsch@hh.maus.de  (Mails < 16K)
 21079 Hamburg
 Germany            WWW  : http://www.tu-harburg.de/~smcf1605/   
------------------------------------------------------------------------