mainGNU M4 - Support: sr #110912, Backslash followed by quote...

 
 

sr #110912: Backslash followed by quote treated as escape sequence on Windows.

Submitter:  Marek Knápek <marekknapek>
Submitted:  Sat 29 Jul 2023 11:36:06 PM UTC
   
 
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  Microsoft Windows
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 31 Jul 2023 06:22:13 PM UTC, comment #1: 

As you pointed out, it is the responsibility of the calling program to pass in argv[] with expected contents.  Most ports of GNU programs to Windows environments have their own idioms in place to either alter the shell to have normal Unix parsing, or to have the CRT normalize the incoming arguments prior to reaching main() (examples of these environments being Cygwin and MSYS).  In which case, the problem is in your environment, and not in m4 proper, as the normalization still happens before main() (whether it happens in the parent process as with Unix sh, or in the child process).  I don't see how upstream m4 can do anything about your problem.  What's more, if it is the CRT not normalizing arguments the way you want, then every other application you compile with the same CRT will have the same problem.

Eric Blake <ericb>
Group administrator
Sat 29 Jul 2023 11:36:06 PM UTC, original submission:  

Backslash followed by quote treated as escape sequence on Windows. Hi all, recently I started using the m4 template processor on MS Windows OS. I found one problem with invoking it when using the -I option to specify the include path. Everything works fine, except when the path ends with directory separator (backslash) and at the same time it is enclosed inside double quotes. Please see examples below. Every example works fine, except example number 5. I suspect the problem is that there is backslash followed by double quote. There are multiple things happening at the same time:

 - On Windows, the directory separator is backslash, but forward slash works also in most cases as a compatibility shim.
 - Directory names could contain space, and space is also parameter separator. Thus it is good practice to enclose user-provided paths in double quotes, so it could be treated as single parameter.
 - Some people and some software have habit of appending directory separator (backslash) to the end of directory path name, so it is clear to the user that the string specifies directory path name as opposed to file path name.

I'm using the Visual Studio / MSBuild software as my build environment, this program uses an combination of points above, resulting in invoking the m4 template processor the way as in example number 5. I could work-around the problem by appending dot at the end of the include path. But this is no generic solution and similar problem might arise in different places where the user could not work-around this like me.

On Windows, the invoked program (m4 in this case) receives the complete command line as single long string and it is its responsibility to parse it into argc+argv before passing it to the C main function. This is different from Linux where it is shell's responsibility to create argc+argv, pass it into kernel and kernel passing it to the invoked program. On Windows most programs are using the CRT to do the parsing from command line to argc+argv. CRT is shortcut for C run-time, basically equivalent to libc/glibc. CRT could be linked to programs statically or dynamically, dynamic CRT are the msvcrt.dll, msvcp140.dll and similar DLLs. I suspect the problem might be there, but I have no idea.

It is unfortunate that m4 sometimes works fine, sometimes gets stuck. It is based on format of the command line. Please fix this problem. Best regards, Marek.

[1] m4 -I c:\dev\tmp\templates some_template.m4 > some_output.txt
[2] m4 -I c:\dev\tmp\templates\ some_template.m4 > some_output.txt
[3] m4 -I c:/dev/tmp/templates/ some_template.m4 > some_output.txt
[4] m4 -I "c:\dev\tmp\templates" some_template.m4 > some_output.txt
[5] m4 -I "c:\dev\tmp\templates\" some_template.m4 > some_output.txt
[6] m4 -I "c:/dev/tmp/templates/" some_template.m4 > some_output.txt

Marek Knápek <marekknapek>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ericb (Posted a comment)
  • -email is unavailable- added by marekknapek (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-bb6a.
    Corresponding source code