Jump to content

Shellscript For Replacing Postincrements With Preincrements

Guest balrok

Recommended Posts

cause i often hear pre-increment is faster than postincrement, so i thought about a shellscript/regular expression to automaticly replace those on places where it's not important if there is a pre or postincrement

cause i don't know how i can make multiple matches with find you also should execute it a 2nd time with "-name *.h" (and *.c)

find all in for-loops:

find -name *.cpp -exec sh -c "sed -r 's/(.*for *\\(.*; *)([a-zA-Z0-9_]+) ?((\\+\\+)|(\\-\\-))( *\\).*)/\\1 \\3\\2 \\6/' {} > /tmp/lalala && cp /tmp/lalala {}" \\; && rm /tmp/lalala

find all in plain code:

find -name *.cpp -exec sh -c "sed -r 's/^(( *)([a-zA-Z0-9_]*) *((\\+\\+)|(\\-\\-))+ *$/\\2\\4\\3;/g' {} > /tmp/lalala && cp /tmp/lalala {}" \\; && rm /tmp/lalala

to find out if the script works right you can do:

ack -h "for *\\(.*((\\+\\+)|(\\-\\-)) *\\)" > test

and then run the sed-script over test

sed -r 's/(.*for *\\(.*; *)([a-zA-Z0-9_]+) ?((\\+\\+)|(\\-\\-))( *\\).*)/\\1 \\3\\2 \\6/' test

for the 2nd script it is:

ack -h "^( *[a-zA-Z0-9_]+ *((\\+\\+)|(\\-\\-)) *+ *$"

(if you don't have ack you can replace "ack -h" with grep , the result is the same (but grep is realy slow on the whole mangos-source, thats why i prefer ack)

i post it in this section, cause i don't realy know if this will help and cause i'm not 100% sure if the server will work after this (i already tested the script with the for-loop without any crash.. but i can't test much things alone)

Link to comment
Share on other sites

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use