1 package io.jawk.jrt;
2
3 /*-
4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5 * Jawk
6 * ჻჻჻჻჻჻
7 * Copyright (C) 2006 - 2026 MetricsHub
8 * ჻჻჻჻჻჻
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23 */
24
25 /**
26 * The AWK Variable Manager.
27 * It provides getter/setter methods for global AWK variables.
28 * Its purpose is to expose a variable management interface to
29 * the JRT, even though the implementation is provided by
30 * the AWK script at script compile-time.
31 * <p>
32 * The getters/setters here do not access <strong>all</strong>
33 * special AWK variables, such as <code>RSTART</code>
34 * and <code>ENVIRON</code>. That's because these variables
35 * are not referred to within the JRT.
36 *
37 * @see JRT
38 * @author Danny Daglas
39 */
40 public interface VariableManager {
41 /**
42 * <p>
43 * getARGC.
44 * </p>
45 *
46 * @return the contents of the ARGC variable.
47 */
48 Object getARGC();
49
50 /**
51 * <p>
52 * getARGV.
53 * </p>
54 *
55 * @return the contents of the ARGV variable.
56 */
57 Object getARGV();
58
59 /**
60 * <p>
61 * getCONVFMT.
62 * </p>
63 *
64 * @return the contents of the CONVFMT variable.
65 */
66 Object getCONVFMT();
67
68 /**
69 * <p>
70 * getFS.
71 * </p>
72 *
73 * @return the contents of the FS variable.
74 */
75 Object getFS();
76
77 /**
78 * <p>
79 * getRS.
80 * </p>
81 *
82 * @return the contents of the RS variable.
83 */
84 Object getRS();
85
86 /**
87 * <p>
88 * getOFS.
89 * </p>
90 *
91 * @return the contents of the OFS variable.
92 */
93 Object getOFS();
94
95 /**
96 * <p>
97 * getORS.
98 * </p>
99 *
100 * @return the contents of the ORS variable.
101 */
102 Object getORS();
103
104 /**
105 * <p>
106 * getSUBSEP.
107 * </p>
108 *
109 * @return the contents of the SUBSEP variable.
110 */
111 Object getSUBSEP();
112
113 /**
114 * Returns the current value of a named global variable or JRT-managed special
115 * variable.
116 * <p>
117 * The default implementation returns {@code null} so that
118 * {@code VariableManager} implementations written before this lookup hook
119 * existed remain source and binary compatible; interpreters should override
120 * it.
121 * </p>
122 *
123 * @param name variable name
124 * @return the variable value, or {@code null} when it is unknown or untyped
125 */
126 default Object getVariable(String name) {
127 return null;
128 }
129
130 /**
131 * Set the contents of the FILENAME variable.
132 *
133 * @param fileName File name
134 */
135 void setFILENAME(String fileName);
136
137 /**
138 * Set the contents of the NF variable.
139 *
140 * @param newNf Value for NF
141 */
142 void setNF(Integer newNf);
143
144 /**
145 * Increases the NR variable by 1.
146 */
147 void incNR();
148
149 /**
150 * Increases the FNR variable by 1.
151 */
152 void incFNR();
153
154 /**
155 * Resets the FNR variable to 0.
156 */
157 void resetFNR();
158
159 /**
160 * Set the contents of a user-defined AWK
161 * variable. Used when processing
162 * <em>name=value</em> command-line arguments
163 * (either via -v or via ARGV).
164 *
165 * @param name The AWK variable name.
166 * @param value The new contents of the variable.
167 */
168 void assignVariable(String name, Object value);
169 }