1 /*
2  *      cook - file construction tool
3  *      Copyright (C) 1997, 1999, 2006, 2007 Peter Miller;
4  *      All rights reserved.
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 3 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program. If not, see
18  *      <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <cook/id/nothing.h>
22 #include <cook/id/private.h>
23 #include <cook/opcode/context.h>
24 
25 
26 /*
27  * NAME
28  *      destructor
29  *
30  * SYNOPSIS
31  *      void destructor(id_ty *);
32  *
33  * DESCRIPTION
34  *      The destructor function is used to release the resources held by
35  *      an ID instance.
36  */
37 
38 static void
destructor(id_ty * idp)39 destructor(id_ty *idp)
40 {
41     (void)idp;
42 }
43 
44 
45 /*
46  * NAME
47  *      evaluate
48  *
49  * SYNOPSIS
50  *      int evaluate(id_ty *, const string_list_ty *, string_list_ty *);
51  *
52  * DESCRIPTION
53  *      The evaluate function is used to evaluate an ID instance (there
54  *      are several types).  The arguments to the evaluation are not to
55  *      be changed, the results are only to be appended (not
56  *      constructor'ed first).
57  *
58  * RETURNS
59  *      int; 0 on success, -1 on error.
60  */
61 
62 static int
interpret(id_ty * idp,opcode_context_ty * ocp,const struct expr_position_ty * pp)63 interpret(id_ty *idp, opcode_context_ty *ocp, const struct expr_position_ty *pp)
64 {
65     string_list_ty  *arg;
66 
67     (void)idp;
68     (void)pp;
69     arg = opcode_context_string_list_pop(ocp);
70     string_list_delete(arg);
71     return 0;
72 }
73 
74 
75 /*
76  * NAME
77  *      method
78  *
79  * DESCRIPTION
80  *      The method nothing describes this ID class.
81  *
82  * CAVEAT
83  *      This symbol is not to be exported from this file (its name is
84  *      not unique).
85  */
86 
87 static id_method_ty method =
88 {
89     "nothing",
90     sizeof(id_ty),
91     destructor,
92     interpret,
93     interpret,                  /* script */
94 };
95 
96 
97 /*
98  * NAME
99  *      id_nothing_new
100  *
101  * SYNOPSIS
102  *      void id_nothing_new(void);
103  *
104  * DESCRIPTION
105  *      The id_nothing_new function is used to create a new instance of
106  *      a nothing ID's value.  The given value is copied.
107  *
108  * RETURNS
109  *      id_ty *; a pointer to a ID instance is dynamic memory.
110  *
111  * CAVEAT
112  *      Use id_instance_delete when you are done with it.
113  */
114 
115 id_ty *
id_nothing_new(void)116 id_nothing_new(void)
117 {
118     return id_instance_new(&method);
119 }
120