Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions TermiC.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ echo -e $initSource > $sourceFile
trap "echo -e '\nKeyboardInterrupt'" SIGINT
while true;do
[[ $inlineCounter -gt 0 ]] && promptPS1=" " || promptPS1=">> "
prompt=$(read -rep "$promptPS1"$(echo $(yes ... | head -n $inlineCounter) | sed 's/ //g') prompt || { [[ $inlineCounter -gt 0 ]] || prompt="exit"; } ; echo $prompt)
read -rep "$promptPS1"$(yes ... | head -n $inlineCounter | tr -d '\n') prompt || { [[ $inlineCounter -gt 0 ]] || prompt="exit"; }
[[ $prompt == "" ]] && continue
history -s "$prompt"
[[ $prompt == "exit" ]] && break
Expand All @@ -78,9 +78,7 @@ while true;do
inlineOpen=`echo $fullPrompt | grep -o '{\|#ifdef' | wc -l`
inlineClose=`echo $fullPrompt | grep -o '}\|#endif' | wc -l`
inlineCounter=$((inlineOpen-inlineClose))
if [[ $inlineOpen -gt $inlineClose ]];then
:
else
if [[ $inlineCounter -le 0 ]];then
addOutsideMain=false
addToBeginning=false
addSemicolon=";"
Expand All @@ -95,12 +93,11 @@ while true;do
# If namespace/class/struct declaration
[[ $fullPrompt =~ ^.?[[:alnum:]\*:]*[[:blank:]]*(namespace|class|struct)[[:blank:]]*[[:alnum:]\*:]*[[:blank:]]*.*\{ ]] && addOutsideMain=true
# If if/else if/else/switch/while/do while/for/try/catch

[[ $fullPrompt =~ ^.?[[:blank:]]*(if|else if|else|switch|while|do|for|try|catch).*\{ ]] && addOutsideMain=false && addToBeginning=false && addSemicolon=""
[[ $fullPrompt == *";" ]] && addSemicolon=""
[[ $fullPrompt == *";" ]] && addSemicolon=""
if $addToBeginning;then
echo "$fullPrompt"$addSemicolon > $sourceFile.tmp
echo "`cat $sourceFile`" >> $sourceFile.tmp
cat $sourceFile >> $sourceFile.tmp
elif $addOutsideMain;then
fullPrompt=`printf "%s" "$fullPrompt" | sed -e 's/[&\\]/\\\&/g'`
fullPrompt=`echo $fullPrompt`
Expand All @@ -110,10 +107,8 @@ while true;do
echo "$fullPrompt$addSemicolon" >> $sourceFile.tmp
fi
fullPrompt=""
compiledSuccessfully=false
$compiler -w -x$lang <(echo "`cat $sourceFile.tmp`}") -o $binaryFile && compiledSuccessfully=true

if $compiledSuccessfully;then
if $compiler -w -x$lang <(cat $sourceFile.tmp; echo "}") -o $binaryFile
then
retval=`./$binaryFile 2>&1`
[[ $retval == "" ]] && mv $sourceFile.tmp $sourceFile || echo "$retval"
fi
Expand Down