forked from vonj/snippets.org
-
Notifications
You must be signed in to change notification settings - Fork 1
/
asmcnvrt.awk
41 lines (37 loc) · 1.13 KB
/
asmcnvrt.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# awk script to change block asm statments into the single line
# style that versions of Turbo C up to 2.01 can parse.
# asm {
# pushf
# pop flags
# }
# /*START asm { */
# asm pushf
# asm pop flags
# /*END } */
#
# If the asm block start or end lines contain comments you'll end up
# with a nested comment, other than that I believe comments are handled
# correctly. If you fix that or fix or improve anything else send me a
# copy via fidonet 1:140/12.9 or C_ECHO
#
# public domain code written by Ed Kowalski 22 aug 93, use freely.
# The comment code was written by Dan Kozak, check c_lines.awk in
# snippets. (so what's all the fuss about c++ and reusable code<g>)
{
if ($1 ~ /^\/\*/ && $NF ~ /\*\/$/) { print $0; next }
else if ($0 ~ /\/\*/ && $0 !~ /\*\//) { in_comment = 1 }
else if ($0 !~ /\/\*/ && $0 ~ /\*\//) { in_comment = 0 }
else if ($0 ~/[\t ]*}/ && asmblok) {
asmblok = 0
$0 = "/*END" $0 " */"
}
else if ($0 ~ /[\t ]*asm[\t ]+{/ || asmblok > 0 && !in_comment ) {
if( asmblok )
$0 = "asm" $0
else {
asmblok = 1
$0 = $0 = "/*START" $0 " */"
}
}
{ print $0 }
}