Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

windows to linux path delimeters and case substitution in cpp code

Posted on 2010-11-11
9
Medium Priority
?
418 Views
Last Modified: 2012-05-10
Hi,

I have received a significant amount of cpp that was developed on windows and now needs to be compiled on Linux. My main focus for the time being is to modify paths and case in file names within paths.

The paths are easy with the sharp end of the stick doing the following sed within a series of loops in my bash script:

sed -i 's#\\#/#' <path/filename>

Could anyone ease my frustration with substituting uppercase but only in string matches where windows path delimiters can be found? Fortunately I have been unable  to find whitespace in paths...yet.

eg
SYSTEMINCLUDE \root\subdir_A\Component\Include\stdapis
subs to:
SYSTEMINCLUDE /root/subdir_a/component/include/stdapis

Cheers,
ddd
0
Comment
Question by:dingdangdo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
9 Comments
 
LVL 3

Expert Comment

by:Vryali
ID: 34120527
Something simple like this would work fine, I imagine?

grep "SYSTEMINCLUDE" file.c | tr '[:upper:]' '[:lower:]'

Just run your inital sed script to convert slashes and run that after.  I imagine you have an if statement already that checks if the given header file is in windows format vs *nux format, so you could alternatively just tack on the tr command after the sed statement:

sed -i 's#\\#/#' <path/filename> | tr '[:upper:]' '[:lower:]'

Unsure if that's entirely what you're looking for, but given what you said that's my initial take.
0
 

Accepted Solution

by:
dingdangdo earned 0 total points
ID: 34140144
Hi Vryali,

Many thanks for the contrib. It's just the path strings I wanted to do the substitution in. I ended up with it in python. The key line is:
repattern-re.compile(r"^(?P<head>.*?)(?P<path>[^/]/[^/][/|a-z|A-Z|_|\-|0-9|\.]+)(?P<tail>.*)$");

It could have ben done in shell using sed. 'Just the way it went on the day :-)

Cheers,
ddd

#! /usr/bin/python

import os
import re
import sys
import datetime
import time
import shutil
import inspect
import glob
import traceback
import copy

verboseOutput = False
doOutFileCopy = True

modified = False
shownFilename = False

# --------------------------------------------------------------

def recurseReplace( line ):
    global shownFilename
    reRes = repattern.match(line.replace('\\', '/'));      
    if( reRes ):

        if verboseOutput:
            print " *** regex match *** "

        line = reRes.group('head') + reRes.group('path').lower() + recurseReplace( reRes.group('tail') )

    return line

# --------------------------------------------------------------

fileName = None
if (len(sys.argv) < 2):
    sys.exit(-1)
else:
    fileName = sys.argv[1]
    fileOut = fileName + '.out'

repattern = re.compile(r"^(?P<head>.*?)(?P<path>[^/]/[^/][/|a-z|A-Z|_|\-|0-9|\.]+)(?P<tail>.*)$");
# print "=== Opening file: " + fileName
fIn = open( fileName )
fOut= open( fileOut, "w" )

for line in fIn:
    lineEnd = "\n\r"
    if( line.find("\n\r") >= 0 ):
        lineEnd = "\n\r"
    elif( line.find("\r\n") >= 0 ):
        lineEnd = "\r\n"
    elif( line.find("\r") >= 0 ):
        lineEnd = "\r"
    elif( line.find("\n") >= 0 ):
        lineEnd = "\n"

    line = line.replace("\n", "").replace("\r", "")
    if verboseOutput:
        print line

    newLine = recurseReplace( line )
   
    fOut.write( newLine + lineEnd )
   
    if newLine != line:
        if shownFilename == False:
            print "=== Opening file: " + fileName
            shownFilename = True
        print ' Changed "' + line + '" to "' + newLine + '"'
        modified = True

fIn.close()
fOut.close()

if( modified == False ):
    os.remove( fileOut )
elif doOutFileCopy:
    try:
        os.remove( fileOut + ".orig"  )
    except:
        fukit = True
    os.rename( fileName, fileName + ".orig" )
    os.rename( fileOut, fileName )
0
 
LVL 3

Expert Comment

by:Vryali
ID: 34140280
He found the solution himself and worked it out as a Rube Goldberg-esque solution, and it apparently works (Didn't go through his code).  His closing comment bit though is:

"Hope I don't get these points. I've only asked 2 questions. Wasn't expecting to find the solution ot this one myself."

I'm objecting because it looks like he's stating that I should have gotten the points (since he hopes he doesn't get them and I'm the other response/simpler response.

I'm not really sure, he got the right answer in another fashion, but it looks like he wanted me to get the points?  I don't mind not getting the points... Just sayin'.  Happily would withdraw my objection (If you can even do that?) if he was intending to give out zero points since he found the correct answer on his own...?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:Vryali
ID: 34140296
Ah, I didn't realize it would post that publicly, I feel like an ass now; Damn you Experts-Exchange  for not giving me an edit or delete button that I can find...
0
 

Author Comment

by:dingdangdo
ID: 34140482
Hi Vryali,

I am sorry you didn't receive points but your solution wasn't what I was after. I must only substitute case in the <path>/<filename> portions of each line as stated in the example I submitted:

eg
SYSTEMINCLUDE \root\subdir_A\Component\Include\stdapis
subs to:
SYSTEMINCLUDE /root/subdir_a/component/include/stdapis

Your solution would have yielded:
systeminclude /root/subdir_a/component/include/stdapis

Many thanks though for taking the time on it. BTW as I hoped I didn't get the points. It wouldn't be right to be rewarded for answering my own question.

Cheers,
ddd

0
 
LVL 3

Expert Comment

by:Vryali
ID: 34140873
Ah cheers,i was just confused by the wording, my apologies
0
 
LVL 3

Expert Comment

by:Vryali
ID: 34140884
Ah cheers,i was just confused by the wording, my apologies
0
 

Expert Comment

by:_alias99
ID: 34179136
All,
 
Following an 'Objection' by Vryali (at http://www.experts-exchange.com/Q_26616568.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as originally requested by the author.
 
Thank you,
 
_alias99
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background Still having to process all these year-end "csv" files received from all these sources (including Government entities), sometimes we have the need to examine the contents due to data error, etc... As a "Unix" shop, our only readily …
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

722 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