diff options
author | Michele Calgaro <[email protected]> | 2023-04-18 20:47:44 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2023-04-18 20:47:44 +0900 |
commit | 425e16ad894fd23d7c5b061acffba6cd04a1b1db (patch) | |
tree | e1f794e07812bcd59a4b518747bf9dc5c2a5a163 /indenters/__TODO/shellindent.awk | |
parent | 11451cea9db07b2a257297de57d76a8dbb7e3a5e (diff) | |
download | universal-indent-gui-tqt-425e16ad894fd23d7c5b061acffba6cd04a1b1db.tar.gz universal-indent-gui-tqt-425e16ad894fd23d7c5b061acffba6cd04a1b1db.zip |
Added code to load last open file or an example or an untitled file.
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'indenters/__TODO/shellindent.awk')
-rwxr-xr-x | indenters/__TODO/shellindent.awk | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/indenters/__TODO/shellindent.awk b/indenters/__TODO/shellindent.awk new file mode 100755 index 0000000..c02af04 --- /dev/null +++ b/indenters/__TODO/shellindent.awk @@ -0,0 +1,46 @@ +#!/usr/bin/awk -f + +# SOLARIS USERS: Change "awk" to "nawk", above!!! + +# This is part of Phil's AWK tutorial at http://www.bolthole.com/AWK.html +# This program adjusts the indentation level based on which keywords are +# found in each line it encounters. +# +# THIS IS A (relatively) COMPLEX PROGRAM. If you're an AWK rookie, +# go back and read the tutorial before trying to understand this program! +# This program shows off awk functions, variables, and its ability to +# perform multiple actions for the same line + + +function doindent(){ + tmpindent=indent; + if(indent<0){ + print "ERROR; indent level == " indent + } + while(tmpindent >0){ + printf(" "); + tmpindent-=1; + } +} + +$1 == "done" { indent -=1; } +$1 == "fi" { indent -=1; } +$0 ~ /}/ { if(indent!=0) indent-=1; } + +# This is the 'default' action, that actually prints a line out. +# This gets called AS WELL AS any other matching clause, in the +# order they appear in this program. +# An "if" match is run AFTER we run this clause. +# A "done" match is run BEFORE we run this clause. + { + doindent(); + print $0; + } + +$0 ~ /if.*;[ ]*then/ { indent+=1; } +$0 ~ /for.*;[ ]*do/ { indent+=1; } +$0 ~ /while.*;[ ]*do/ { indent+=1; } + +$1 == "then" { indent+=1; } +$1 == "do" { indent+=1; } +$0 ~ /{$/ { indent+=1; } |