File: embed_str.awk

package info (click to toggle)
runawk 1.6.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 712 kB
  • sloc: awk: 1,127; ansic: 736; sh: 420; makefile: 103
file content (48 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download | duplicates (4)
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
42
43
44
45
46
47
48
# Written by Aleksey Cheusov <vle@gmx.net>, public domain
#
# This awk module is a part of RunAWK distribution,
#        http://sourceforge.net/projects/runawk
#
############################################################

# =head2 embed_str.awk
#
# This module reads a program's file, find .begin-str/.end-str pairs
# and reads lines between them.
#
# I<EMBED_STR> - Associative array with string index
#
# Example:
#  Input:
#   .begin-str mymsg
#    Line1
#    Line2
#   .end-str
#  Output (result)
#   EMBED_STR ["mymsg"]="Line1\nLine2"
#
# See example/demo_embed_str for the sample of usage
#

#use "xgetline.awk"
#use "modinfo.awk"
#use "xclose.awk"

BEGIN {
	_embed_str_id = ""
	while (xgetline0(MODMAIN)){
		if ($0 ~ /^#[.]begin-str/){
			_embed_str_id = $2
		}else if ($0 ~ /^#[.]end-str/){
			_embed_str_id = ""
		}else if (_embed_str_id != ""){
			if (EMBED_STR [_embed_str_id] != "")
				_nl = "\n"
			else
				_nl = ""

			EMBED_STR [_embed_str_id] = EMBED_STR [_embed_str_id] _nl substr($0, 3)
		}
	}
	xclose(MODMAIN)
}