Porting DOS source to GNU C - Backslashes

Posted on 2000-03-30
Last Modified: 2010-04-15
I am trying to port a DOS program to Linux using the GNU C compiler.  I am stuck on the problem of directory slashes.  In our source we frequently have includes that are in a subdirectory of the main header directory.  For example:

#include <proto\lib\util.h>

Naturally, as the software was developed in the DOS/WIN world, we have used the backslash as our directory separator.

Now, when we try to compile with the GNU C compiler, it complains that it cannot find any of the include files that contain the backslashes (No such file or directory).   It can find include files that are in the top-level include directory (and therefore have no backslashes), so it's looking in the right place.

Is there a setting, switch or whatever that will allow GNU see to recognize these backslashes and find the files we are trying to include?  I tried usind the DIR_SEPARATOR define, but that didn't seem to help anything.
Question by:robworley
LVL 16

Accepted Solution

imladris earned 210 total points
ID: 2670847
I think all would be well if you change them all to forward slashes. DOS will internally recognize a forward slash as a dir_separator. It's certainly not a legal character for a file name in DOS.

Author Comment

ID: 2670889
Adjusted points from 200 to 210

Author Comment

ID: 2670890
Well, that's a possibility.  Ultimately I'm talking about hundreds of files though and I'm trying to avoid a massive and tedious set of changes.  Is there any way to make the compiler recognize and honor the backslash?
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

LVL 84

Expert Comment

ID: 2671139
You could write a script to change all the slashes in the #include directives.
Or you could copy /usr/include/proto/lib/util.h to /usr/include/proto\lib\util.h

Expert Comment

ID: 2671745
You can create soft links for all include paths in one common directory and include this directory in your compile time options using -I option.

e.g proto\lib\util.h can be a soft link as

proto\\lib\\util.h  -> actual path where util.h is stored in linux.
This can give you excellent abstraction to emulate the directoy env on linux machine without changing single line in your code.
May be you can put all this as a install shell script and run it on each new machine before you compile your programs on new machine.

Hope this helps.


Expert Comment

ID: 2671841
A suggestions:

In the main program, or some file that all file '#include', add this line:

#define \ /

That will replace all '\' with '/', and won't even screw up any math you might be doing.  I'm not sure that all cases are accounted for here, though.


Expert Comment

ID: 2672646
An ASCII game of warships might not like it...

Author Comment

ID: 2674428
Ufolk and bikeman: I could not get your solution/suggestion to work

ozo/imladris: I ended up writing a perl script to fix the files, so i guess I used a combination of your suggestions.  I don't know what's the best way to divide up the points.  

Maybe, one of you can post your answer as an answer here and I'll accept it.  And then I can open a dummy question so the other can get the points too?  Let me know how you want to work it out.
LVL 84

Expert Comment

ID: 2674443
macro name shall be an identifier
\ is not a legal macro name
LVL 12

Expert Comment

ID: 2676510
robworley: You can accept a comment as an answer--you should have a button which lets you do this.

Author Comment

ID: 2676818
This turned out to be the right answer, although a helpful suggestion from ozo was also implemented.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question