With your last submission, it works fine!
But without the extra filter to get the space out, there is that problem.
The comment cut off line leave a space when there is comment ( // or /* )
With my test code ( see further below ), you will see that the comment out line isn't working the way it should.
The first * in
+line="${line%*([[:space:]])/[/*]*}"+
means if I understands zero or more of the matching pattern.
I did expect the same as you, it should remove all the spaces in front of the comment together with the comment.
It leaves ( creates?!) one space when there was a comment, no matter if there where many spaces or tabs in front of the comment.
A second weird thing for me is that when using /* is shows al the folders from root.
So some where it is transformed. I believe this is only because of echo and the real line string contains the /*, because it remove the 'comments' correctly, even echo show my folders.
To show you how I get to this idea, I got this in my .h file.
#import <Cocoa/Cocoa.h>
#import <Example/Example.h>
#define kPL_KEYTAG 'TAG_value' // comment about KeyTag
#define kPL_KEYGROUP "GROUPvalue" /* tekst */
#define kPL_KEYVERSION "2010 feb 10 V1.2 " /* tekst */
#define kPL_KEYINFO 'INFO_Value Txt Max 120 Char width'
#define kPL_KEYNAME ExamplePluginName // bnb
#define kPL_KEYORDER 14// dfd
#define kPL_KEYDESC "Example Plugins"
My Test code with your lines for testing, I did leave the 'if' line out.
shopt -s extglob # enable extended globs +(...), *(...), etc...
cat ${sourceFile} | while read line
do
echo
echo 'before :'${line}--
line="${line%*([[:space:]])/[/*]*}"
echo 'comment out :'${line}--
line="${line##*([[:space:]])define*([[:space:]])*([[:alnum:]])PL_KEY}"
echo 'Tear off beginning:'${line}--
key=${line%%+([[:space:]])*}
echo 'key :'$key--
value=${line##${key}+([[:space:]])}
echo 'Value :'$value--
done
the result ( see bolded text )
{quote}
*before :#define kPL_KEYTAG 'TAG_value' // comment about KeyTag--*
*comment out :#define kPL_KEYTAG 'TAG_value' --*
*Tear off beginning:TAG 'TAG_value' --*
*key :TAG--*
*Value :'TAG_value' --*
before :#define kPL_KEYGROUP "GROUPvalue" /Applications /Developer /Extra /Groups /Library /Logs.sh /Mac OS X Install Data /Network /Shared Items /System /Users /Volumes /bin /boot /cores /dev /etc /home /mach_kernel /net /pfix.log /private /sbin /sw /tmp /usr /var tekst /--
*comment out :#define kPL_KEYGROUP "GROUPvalue" --*
*Tear off beginning:GROUP "GROUPvalue" --*
*key :GROUP--*
*Value :"GROUPvalue" --*
*before :#define kPL_KEYVERSION "2010 feb 10 V1.2 " /Applications /Developer /Extra /Groups /Library /Logs.sh /Mac OS X Install Data /Network /Shared Items /System /Users /Volumes /bin /boot /cores /dev /etc /home /mach_kernel /net /pfix.log /private /sbin /sw /tmp /usr /var tekst */--*
*comment out :#define kPL_KEYVERSION "2010 feb 10 V1.2 " --*
*Tear off beginning:VERSION "2010 feb 10 V1.2 " --*
*key :VERSION--*
*Value :"2010 feb 10 V1.2 " --*
before :#define kPL_KEYINFO 'INFO_Value Txt Max 120 Char width'--
comment out :#define kPL_KEYINFO 'INFO_Value Txt Max 120 Char width'--
Tear off beginning:INFO 'INFO_Value Txt Max 120 Char width'--
key :INFO--
Value :'INFO_Value Txt Max 120 Char width'--
before :#define kPL_KEYNAME ExamplePluginName // bnb--
comment out :#define kPL_KEYNAME ExamplePluginName --
Tear off beginning:NAME ExamplePluginName --
key :NAME--
Value :ExamplePluginName --
before :#define kPL_KEYORDER 14// dfd--
comment out :#define kPL_KEYORDER 14--
Tear off beginning:ORDER 14--
key :ORDER--
Value :14--
before :#define kPL_KEYDESC "Example Plugins"--
comment out :#define kPL_KEYDESC "Example Plugins"--
Tear off beginning:DESC "Example Plugins"--
key :DESC--
Value :"Example Plugins"--
{quote}