summaryrefslogtreecommitdiff
path: root/extension/rwarray.3am
blob: b10545a3d156937aa45d7a71586ac4937c493d05 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
.TH RWARRAY 3am "Feb 02 2018" "Free Software Foundation" "GNU Awk Extension Modules"
.SH NAME
writea, reada, writeall, readall \- write and read gawk arrays to/from files
.SH SYNOPSIS
.ft CW
@load "rwarray"
.sp
ret = writea(file, array)
.br
ret = reada(file, array)
.br
ret = writeall(file)
.br
ret = readall(file)
.ft R
.SH DESCRIPTION
The
.I rwarray
extension adds functions named
.BR writea() ,
.BR reada() ,
.BR writeaall() ,
and
.BR readaall() ,
as follows.
.TP
.B writea()
This function takes a string argument, which is the name of the
file to which dump the array, and the array itself as the second
argument.
.B writea()
understands multidimensional arrays.
It returns one on success, or zero upon failure.
.TP
.B reada()
is the inverse of
.BR writea() ;
it reads the file named as its first argument, filling in
the array named as the second argument. It clears the array
first.
Here too, the return value is one on success and zero upon failure.
.TP
.B writeall()
This function takes a string argument, which is the name of the
file to which dump the state of all variables. Calling this function
is completely equivalent to calling
.B writea()
with the second argument equal to
.BR SYMTAB .
It returns one on success, or zero upon failure.
.TP
.B readall()
This function takes a string argument, which is the name of the
file from which to read the contents of various global variables.
For each variable in the file, the data is loaded unless the variable
already exists. If the variable already exists, the data for that variable
in the file is ignored.
It returns one on success, or zero upon failure.
.SH NOTES
The array created by
.B reada()
is identical to that written by
.B writea()
in the sense that the contents are the same. However, due
to implementation issues, the array traversal order of the recreated
array will likely be different from that of the original array.
As array traversal order in AWK is by default undefined, this is
not (technically) a problem.  If you need to guarantee a particular
traversal order, use the array sorting features in
.I gawk
to do so.
.PP
The file contains binary data.  All integral values are written
in network byte order.
However, double precision floating-point values are written as
native binary data.  Thus, arrays containing only string data
can theoretically be dumped on systems with one byte order and
restored on systems with a different one, but this has not been tried.
.\" .SH BUGS
.SH EXAMPLE
.ft CW
.nf
@load "rwarray"
\&...
ret = writea("arraydump.bin", array)
\&...
ret = reada("arraydump.bin", array)
\&...
ret = writeall("globalstate.bin")
\&...
ret = readall("globalstate.bin")
.fi
.ft R
.SH "SEE ALSO"
.IR "GAWK: Effective AWK Programming" ,
.IR filefuncs (3am),
.IR fnmatch (3am),
.IR fork (3am),
.IR inplace (3am),
.IR ordchr (3am),
.IR readdir (3am),
.IR readfile (3am),
.IR revoutput (3am),
.IR time (3am).
.SH AUTHOR
Arnold Robbins,
.BR arnold@skeeve.com .
.SH COPYING PERMISSIONS
Copyright \(co 2012, 2013, 2018,
Free Software Foundation, Inc.
.PP
Permission is granted to make and distribute verbatim copies of
this manual page provided the copyright notice and this permission
notice are preserved on all copies.
.ig
Permission is granted to process this file through troff and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual page).
..
.PP
Permission is granted to copy and distribute modified versions of this
manual page under the conditions for verbatim copying, provided that
the entire resulting derived work is distributed under the terms of a
permission notice identical to this one.
.PP
Permission is granted to copy and distribute translations of this
manual page into another language, under the above conditions for
modified versions, except that this permission notice may be stated in
a translation approved by the Foundation.
.\" vim: set filetype=nroff :