4 * Copyright (C) 2001-2003
6 * Neven Has <haski@sezampro.yu>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #define MODULE_NAME link
42 #define El_link_target(el) alloc_trimmed_param_value("target", el)
43 #define El_link_name(el) alloc_trimmed_param_value("name", el)
46 #if HANDLER_SYNTAX_2_0
48 static const char *link_parameters_ver2
[] =
49 { "options", "base", "target", "name", NULL
};
50 // char *HANDLER_SYMBOL(attributes)[] = { "type", NULL };
52 static int link_main_ver2(element_s
*el
)
55 int force
= option_exists("force", el
);
56 char *type
= attr_value("type", el
);
64 if ((target
= El_link_target(el
)) == NULL
) {
65 Nprint_h_err("No source files specified.");
69 link_name
= El_link_name(el
);
71 base
= alloc_base_dir(el
);
73 if (change_current_dir(base
)) {
80 if (type
== NULL
|| strcmp(type
, "symbolic") == 0) {
81 append_str(&command
, "ln -s");
82 append_str(&message
, "Creating symbolic link in ");
84 } else if (strcmp(type
, "hard") == 0) {
85 append_str(&command
, "ln");
86 append_str(&message
, "Creating hard link in ");
89 Nprint_h_warn("Unknown link type (%s), using symbolic.", type
);
90 append_str(&command
, "ln -s");
91 append_str(&message
, "Creating symbolic link in ");
94 append_str(&message
, base
);
97 append_str(&command
, " -f");
98 append_str(&message
, " (force):");
101 append_str(&message
, ":");
104 Nprint_h("%s", message
);
107 Nprint_h(" %s -> %s", link_name
, target
);
109 Nprint_h(" %s", target
);
112 append_str(&command
, " ");
113 append_str(&command
, target
);
116 append_str(&command
, " ");
117 append_str(&command
, link_name
);
120 if ((status
= execute_command("%s", command
))) {
121 Nprint_h_err("Executing \"%s\" in \"%s\" failed.",
134 #endif /* HANDLER_SYNTAX_2_0 */
137 #if HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2
139 static const char *link_parameters_ver3
[] =
140 { "option", "target", "name", NULL
};
141 // char *HANDLER_SYMBOL(attributes)[] = { "type", "base", NULL };
143 static int link_main_ver3(element_s
*el
)
145 int options
[2], force
, no_dereference
;
149 char *targets
= NULL
;
151 char *command
= NULL
;
152 char *message
= NULL
;
156 /* Read all <option>s. */
157 check_options(2, options
, "force no-dereference", el
);
159 no_dereference
= options
[1];
161 link_name
= alloc_trimmed_param_value("name", el
);
163 base
= alloc_base_dir_new(el
);
164 if (change_current_dir(base
)) {
170 type
= attr_value("type", el
);
172 if (type
== NULL
|| strcmp(type
, "symbolic") == 0) {
173 append_str(&message
, "Creating symbolic link in ");
174 append_str(&command
, "ln -s");
176 } else if (strcmp(type
, "hard") == 0) {
177 append_str(&message
, "Creating hard link in ");
178 append_str(&command
, "ln");
181 Nprint_h_warn("Unknown link type (%s), using symbolic.", type
);
182 append_str(&message
, "Creating symbolic link in ");
183 append_str(&command
, "ln -s");
186 append_str(&message
, base
);
189 append_str(&message
, " (force)");
190 append_str(&command
, " -f");
193 if (no_dereference
) {
194 append_str(&message
, " (no_dereference)");
195 append_str(&command
, " -n");
198 append_str(&message
, ": ");
201 append_str(&message
, link_name
);
204 /* Concatenate all targets in "targets". */
205 for (p
= first_param("target", el
); p
; p
= next_param(p
)) {
209 if ((target
= alloc_trimmed_str(p
->content
)) == NULL
) {
210 Nprint_h_warn("No target specified.");
214 if (targets
!= NULL
) {
215 append_str(&targets
, " ");
218 append_str(&targets
, target
);
224 append_str(&command
, " ");
225 append_str(&command
, targets
);
228 append_str(&command
, " ");
229 append_str(&command
, link_name
);
232 Nprint_h("%s", message
);
233 Nprint_h(" %s", targets
);
235 if ((status
= execute_command("%s", command
))) {
236 Nprint_h_err("Executing \"%s\" in %s failed.",
241 Nprint_h_err("No target for link specified.");
253 #endif /* HANDLER_SYNTAX_3_0 || HANDLER_SYNTAX_3_1 || HANDLER_SYNTAX_3_2 */
257 * Handlers' information.
260 handler_info_s
HANDLER_SYMBOL(info
)[] = {
261 #if HANDLER_SYNTAX_2_0
264 .description
= "Link",
265 .syntax_version
= "2.0",
266 .parameters
= link_parameters_ver2
,
267 .main
= link_main_ver2
,
274 #if HANDLER_SYNTAX_3_0
277 .description
= "Link",
278 .syntax_version
= "3.0",
279 .parameters
= link_parameters_ver3
,
280 .main
= link_main_ver3
,
287 #if HANDLER_SYNTAX_3_1
290 .description
= "Link",
291 .syntax_version
= "3.1",
292 .parameters
= link_parameters_ver3
,
293 .main
= link_main_ver3
,
300 #if HANDLER_SYNTAX_3_2
303 .description
= "Link",
304 .syntax_version
= "3.2",
305 .parameters
= link_parameters_ver3
,
306 .main
= link_main_ver3
,
314 NULL
, NULL
, NULL
, NULL
, NULL
, 0, NULL
, 0, 0