Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any tool/script available to convert c99 style comments // into c style comments /* ..*/ into whole projects?

Any tool/script available to convert c99 style comments // into c style comments /* ..*/ into whole projects?

if i have code like this

// printf("stcakoverflow");

then it would be converted like

 /* printf("stcakoverflow"); */

and also

int temp // this is temp varialbe

converted into

int temp /* this is temp varialbe */
like image 448
Jeegar Patel Avatar asked Dec 03 '22 02:12

Jeegar Patel


1 Answers

For a command-line example, try e.g. something like this:

echo "int temp; // this is temp variable" | sed 's@//\(.*\)$@/*\1 */@'

The above results in

int temp; /* this is temp variable */

For a real file you could use e.g. cat instead of echo, it's the piping to sed and the sed command that does the "magic".

Edit: How to do it for lots of files

Something like this maybe:

cd /your/source/directory
mkdir converted-files
for f in *.cpp; do
    cat $f | sed 's@//\(.*\)$@/*\1 */@' > converted-files/$f
done

Now all converted source files will be in a folder converted-files.

like image 72
Some programmer dude Avatar answered May 22 '23 05:05

Some programmer dude