1# Written by Aleksey Cheusov <vle@gmx.net>, public domain
2#
3# This awk module is a part of RunAWK distribution,
4#        http://sourceforge.net/projects/runawk
5#
6############################################################
7
8#use "xgetline.awk"
9#use "xclose.awk"
10
11# =head2 readfile.awk
12#
13# =over 2
14#
15# =item I<readfile(FILENAME)>
16#
17# read entire file and return its content as a string
18#
19# =back
20#
21# See example/demo_readfile for the sample of usage
22#
23
24function readfile (fn,                      ret){
25	# Unfortunately there is no way portable accross all awk flavours
26	# to read an entire file content by single 'getline' command.
27	# This is why I use loop here.
28	ret = ""
29
30	while (xgetline(fn)){
31		if (ret == "")
32			ret = __input
33		else
34			ret = ret "\n" __input
35	}
36	xclose(fn)
37
38	return ret
39}
40