I am using Awk inside a bash shell script to search header files for c++ functions so I can add these functions to another file. All of the functions I need will have form:
type getName()
or
type setName(type value)
Right now I get all the functions listed in between two points in the file (between "public:" and "private:"). This works fine:
variable=$(awk '/public:/ {flag=1;next}/private:/ {flag=0} flag {print}' $file) ;
But when I search the resulting string, I only get everything separated by spaces (i.e. bool getSilenceDetection()
would return as bool, getSilenceDetection() and void setSilenceDetection(bool detection)
would return as void, setSilenceDetection(bool, detection). Here is the code I am using for this:
for word in $variable; do
function=$(awk '/[A-Za-z]* (set|get)[A-Za-z]*\((.*|.* .*)\)/' $word)
echo
done
Unfortunately, this then says "awk: cannot open \<whatever the contents of the string were> (No such file or directory). Why is it not picking up them when they're separated by spaces and why is it thinking they're files? Here is the example file fragment I use:
public:
AudioSettings();
double getVolume() { return volume_; }
void setVolume(double volume) { volume_ = volume < 1.00 ? volume : 1.00; }
bool getEchoCancellation() { return echoCancellation_; }
void setEchoCancellation(bool cancelation) { echoCancellation_ = cancelation; }
bool getSilenceDetection() {return silenceDetection_; }
void setSilenceDetection(bool detection) { silenceDetection_ = detection; }
string getAudioSettingsASCIIString();
bool saveConfiguration();
private:
And here is what I would want to get out of that:
double getVolume()
void setVolume(double volume)
bool getEchoCancellation()
void setEchoCancellation(bool cancelation)
bool getSilenceDetection()
void setSilenceDetection(bool detection)
string getAudioSettingsASCIIString()
bool saveConfiguration()
Can someone help me with this? Thanks