|
| 1 | +#!/bin/bash |
| 2 | +echo "Compiling the helper file to extract the raw list of parameters from cbmc" |
| 3 | +g++ -c -MMD -MP -std=c++11 -Wall -I ../../src/ -ftrack-macro-expansion=0 -fno-diagnostics-show-caret switch_extractor_helper.c -o tmp.o 2> pragma.txt |
| 4 | + |
| 5 | +retval=$? |
| 6 | + |
| 7 | +#clean up compiled files, we don't need them. |
| 8 | +rm tmp.o 2> /dev/null |
| 9 | +rm tmp.d 2> /dev/null |
| 10 | + |
| 11 | +#check if compilation went fine |
| 12 | +if [ $retval -ne 0 ]; then |
| 13 | + echo "Problem compiling the helper file, parameter list not extracted." |
| 14 | + exit 1; |
| 15 | +fi |
| 16 | + |
| 17 | +echo "Converting the raw parameter list to the format required by autocomplete scripts" |
| 18 | +rawstring=`sed "s/^.*pragma message: \(.*\)/\1/" pragma.txt` |
| 19 | +#delete pragma file, we won't need it |
| 20 | +rm pragma.txt 2> /dev/null |
| 21 | + |
| 22 | +#now the main bit, convert from raw format to a proper list of switches |
| 23 | +cleanstring=`( |
| 24 | + #extract 2-hyphen switches, such as --foo |
| 25 | + #grep for '(foo)' expressions, and then use sed to remove parantheses and put '--' at the start |
| 26 | + (echo $rawstring | grep -o "([^)]*)" | sed "s/^.\(.*\).$/--\1/") ; |
| 27 | + #extract 1-hyphen switches, such as -F |
| 28 | + #use sed to remove all (foo) expressions, then you're left with switches and ':', so grep the colons out and then use sed to include the '-' |
| 29 | + (echo $rawstring | sed "s/([^)]*)//g" | grep -o "[a-zA-Z0-9]" | sed "s/\(.*\)/-\1/") |
| 30 | + ) | tr '\n' ' '` |
| 31 | + |
| 32 | +#sanity check that there is only one line of output |
| 33 | +if [ `echo $cleanstring | wc -l | awk '{print $1}'` -ne 1 ]; then |
| 34 | + echo "Problem converting the parameter list to the correct format, I was expecting one line but either got 0 or >2. This is likely to be an error in this conversion script." |
| 35 | + exit 1; |
| 36 | +fi |
| 37 | + |
| 38 | +#sanity check that there are no dangerous characters |
| 39 | +echo $cleanstring | grep -q "[^a-zA-Z0-9 -]" |
| 40 | +if [ $? -eq 0 ]; then |
| 41 | + echo "Problem converting the parameter list to the correct format, illegal characters detected. This is likely to be an error in this conversion script." |
| 42 | + exit 1; |
| 43 | +fi |
| 44 | + |
| 45 | +echo "Injecting the parameter list to the autocomplete file." |
| 46 | +sed "5 s/.*/ local switches=\"$cleanstring\"/" cbmc.sh.template > cbmc.sh |
| 47 | + |
| 48 | +rm pragma.txt 2> /dev/null |
0 commit comments