Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to replace a forward slash with 2 backslashes ?

Posted on 2003-02-20
11
Medium Priority
?
3,278 Views
Last Modified: 2013-12-26
I have a Makefile that compiles Java files.
Because Sun JDK 1.1.8 on Windows requires backward slashes
in the file name, I need to replace each forward slash
in the filename with 2 backslashes.

Here is the rule I am using to compile:

bin/%.class: src/%.java  
     @mkdir -p $(dir $@)
     $(JAVAC) -classpath "src;$(CLASSPATH)" -d \
              $(dir $@) src/$*.java


So, what I want is in the last line to change src/$*.java
so that it contains doubled backslashes instead of forward slashes.

0
Comment
Question by:seva
11 Comments
 
LVL 1

Author Comment

by:seva
ID: 7990981
Actually, I found one solution involving "sed" and
"xargs", but still would be great to learn if it is possible just with Make functions.
0
 
LVL 1

Author Comment

by:seva
ID: 7991086
Actually, I found one solution involving "sed" and
"xargs", but still would be great to learn if it is possible just with Make functions.
0
 
LVL 2

Accepted Solution

by:
ellesd earned 150 total points
ID: 7991324
If this is your only makefile, which it seems like it is with the use of your macros, just change it.  If not, then sed is probably your best way.  Are you wanting to have a forward slash sometimes and double backslashes sometimes, or double backslashes all the time.  If you always want double backslashes, again edit the file or use sed.  If you want to alternate, try using macro definitions; they can be declared on the command line.  Other than that, I'm not quite sure what you are referring to by make functions.  Please give some additional description.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 150 total points
ID: 7993357
DOS-SEP         = \\\\
UNIX-SEP        = /
SEP             = $($(P)-SEP)
PATH=           = path$(SEP)file

# keep in mind that you probably need
simple-SEP      = \\
# when $(simple-SEP) is to be substituted by Makefile only, and not (as in your example) by an additional shell command in the target
0
 
LVL 1

Author Comment

by:seva
ID: 8030453
Sorry for delay.

DOS-SEP         = \\\\
UNIX-SEP        = /
SEP             = $($(P)-SEP)
PATH=           = path$(SEP)file

didn't work for me, probably because I am running make inside Cygwin.
Just curious, are SEP and PATH make special variables?
How is PATH=     = path$(SEP)file
supposed to work?
Thanks.

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8037380
example:
   make P=UNIX any-target
evaluates SEP to / and PATH to path/file
   make P=DOS any-target
evaluates SEP to \\ and PATH to path\\file

BTW, keep in mind that the macro-name PATH (in my example) might be a bad choice,'cause it overwrides the shell's PATH variable
0
 
LVL 4

Expert Comment

by:Vinit Kain
ID: 8041940
try this

cat filename|sed "s/\//\\\\\\\\/g"
0
 
LVL 1

Author Comment

by:seva
ID: 8060992
OK, I'll try to formulate my problem more precisely.

I have a rule in my Makefile:

bin/%.class: src/%.java
     javac -classpath \
"src;bin;d:/opt/jdk1.1.8/lib/classes.zip" \
       -d bin src/$*.java

and the following target:

mytest: bin/Test.class

If I run make with JDK1.2 or later in my PATH,
it works fine.
However, JDK 1.1 doesn't like forward slashes in
the rule's command.

I can't just replace forward slash with a backslash
in the command because the JAVA file name (which substitutes $*) contains
potentially many directories in it, like

com/company/utility/model/SomeClass.java.

At the same time, I can't replace other forward slashes
in the rule with backslashes (I'm talking about
  bin/%.class: src/%.java )
because then make won't find any files because
make doesn't like backslashes.

The problem that I am trying to solve is how to keep
forward slashes in the rule pattern, but replace
forward slashes with double back slashes
in the command.

I've managed this with the following:

bin/%.class: src/%.java
     echo src/$*.java | sed 's/\//\\\\/g' | xargs \  
       javac  -classpath "src;classes.zip" -d bin

Another way would be to use cygwin special command
"cygpath -w <filename>"

I guess at this point I am purely interested
if someone knows of any other way to do that,
preferably with just "make" facilities.

Thanks everyone for your input!




0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 8061219
STOP
where do you think is your problem now?

> If I run make with JDK1.2 or later in my PATH, it works fine.
and
> However, JDK 1.1 doesn't like forward slashes in the rule's command

what has JDK x.y to do with your make (except the arguments passed to J*)

> I can't replace other forward slashes in the rule with backslashes ..
true, you cannot on UNIX (probably with some M$ make)


> .. but replace forward slashes with double back slashes in the command
see my very first suggestion

Do you want to run this Makefilewith different JDK versions?
If so, and JDK is the culprit (not make!), then I's suggest to Makefiles
0
 
LVL 18

Expert Comment

by:liddler
ID: 9826992
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Delete and refund

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

liddler
EE Cleanup Volunteer
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9827088
ahoffmann gave an answer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

571 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