Upgraded to follow CVS-20040525 - upgraded psmisc to 21.5
[automated_linux_from_scratch.git] / nALFS / src / handlers / stamp.c
blob2799662e835e980acebe75ac13ceb6787be35efe
1 /*
2 * stamp.c - Handler.
3 *
4 * Copyright (C) 2001, 2002, 2004
6 * Vassili Dzuba <vassilidzuba@nerim.net>
7 * Neven Has <haski@sezampro.yu>
8 * Kevin P. Fleming <kpfleming@linuxfromscratch.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
29 #define MODULE_NAME stamp
30 #include <nALFS.h>
32 #include "handlers.h"
33 #include "utility.h"
34 #include "nprint.h"
35 #include "parser.h"
36 #include "backend.h"
38 enum {
39 STAMP_NAME,
40 STAMP_VERSION,
43 struct stamp_data {
44 char *name;
45 char *version;
48 static const struct handler_attribute stamp_attributes[] = {
49 { .name = "name", .private = STAMP_NAME },
50 { .name = "version", .private = STAMP_VERSION },
51 { .name = NULL }
54 static int stamp_setup(element_s * const element)
56 struct stamp_data *data;
58 if ((data = xmalloc(sizeof(struct stamp_data))) == NULL)
59 return 1;
61 data->name = NULL;
62 data->version = NULL;
63 element->handler_data = data;
65 return 0;
68 static void stamp_free(const element_s * const element)
70 struct stamp_data *data = (struct stamp_data *) element->handler_data;
72 xfree(data->name);
73 xfree(data->version);
74 xfree(data);
77 static int stamp_attribute(const element_s * const element,
78 const struct handler_attribute * const attr,
79 const char * const value)
81 struct stamp_data *data = (struct stamp_data *) element->handler_data;
83 switch (attr->private) {
84 case STAMP_NAME:
85 if (data->name) {
86 Nprint_err("<%s>: cannot specify \"name\" more than once.", element->handler->name);
87 return 1;
89 data->name = xstrdup(value);
90 return 0;
91 case STAMP_VERSION:
92 if (data->version) {
93 Nprint_err("<%s>: cannot specify \"version\" more than once.", element->handler->name);
94 return 1;
96 data->version = xstrdup(value);
97 return 0;
98 default:
99 return 1;
103 static int stamp_valid_data(const element_s * const element)
105 struct stamp_data *data = (struct stamp_data *) element->handler_data;
107 if (!data->name) {
108 Nprint_err("<%s>: \"name\" cannot be empty.", element->handler->name);
109 return 0;
112 if (!data->version) {
113 Nprint_err("<%s>: \"version\" cannot be empty.", element->handler->name);
114 return 0;
117 return 1;
120 static int stamp_main(const element_s * const element)
122 struct stamp_data *data = (struct stamp_data *) element->handler_data;
124 return stamp_package_installed(1, data->name, data->version);
128 * Handlers' information.
131 handler_info_s HANDLER_SYMBOL(info)[] = {
132 #if HANDLER_SYNTAX_2_0
134 .name = "stamp",
135 .description = "Produce a stamp",
136 .syntax_version = "2.0",
137 .main = stamp_main,
138 .type = HTYPE_NORMAL,
139 .setup = stamp_setup,
140 .free = stamp_free,
141 .attributes = stamp_attributes,
142 .attribute = stamp_attribute,
143 .valid_data = stamp_valid_data,
145 #endif
147 .name = NULL