comparison lib/csharpcomp.c @ 8948:a162347a0232

Update after allocsa -> malloca renaming.
author Bruno Haible <bruno@clisp.org>
date Sat, 09 Jun 2007 11:11:14 +0000
parents 4a8b5467d8b2
children c5cedfcd0db0
comparison
equal deleted inserted replaced
8947:fffd4f371557 8948:a162347a0232
1 /* Compile a C# program. 1 /* Compile a C# program.
2 Copyright (C) 2003-2006 Free Software Foundation, Inc. 2 Copyright (C) 2003-2007 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2003. 3 Written by Bruno Haible <bruno@clisp.org>, 2003.
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option) 7 the Free Software Foundation; either version 2, or (at your option)
31 #include "pipe.h" 31 #include "pipe.h"
32 #include "wait-process.h" 32 #include "wait-process.h"
33 #include "getline.h" 33 #include "getline.h"
34 #include "sh-quote.h" 34 #include "sh-quote.h"
35 #include "safe-read.h" 35 #include "safe-read.h"
36 #include "xallocsa.h" 36 #include "xmalloca.h"
37 #include "error.h" 37 #include "error.h"
38 #include "gettext.h" 38 #include "gettext.h"
39 39
40 #define _(str) gettext (str) 40 #define _(str) gettext (str)
41 41
100 100
101 argc = 101 argc =
102 1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count 102 1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count
103 + 2 * libraries_count + (optimize ? 1 : 0) + (debug ? 1 : 0) 103 + 2 * libraries_count + (optimize ? 1 : 0) + (debug ? 1 : 0)
104 + sources_count; 104 + sources_count;
105 argv = (char **) xallocsa ((argc + 1) * sizeof (char *)); 105 argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
106 106
107 argp = argv; 107 argp = argv;
108 *argp++ = "cscc"; 108 *argp++ = "cscc";
109 if (output_is_library) 109 if (output_is_library)
110 *argp++ = "-shared"; 110 *argp++ = "-shared";
129 const char *source_file = sources[i]; 129 const char *source_file = sources[i];
130 if (strlen (source_file) >= 10 130 if (strlen (source_file) >= 10
131 && memcmp (source_file + strlen (source_file) - 10, ".resources", 131 && memcmp (source_file + strlen (source_file) - 10, ".resources",
132 10) == 0) 132 10) == 0)
133 { 133 {
134 char *option = (char *) xallocsa (12 + strlen (source_file) + 1); 134 char *option = (char *) xmalloca (12 + strlen (source_file) + 1);
135 135
136 memcpy (option, "-fresources=", 12); 136 memcpy (option, "-fresources=", 12);
137 strcpy (option + 12, source_file); 137 strcpy (option + 12, source_file);
138 *argp++ = option; 138 *argp++ = option;
139 } 139 }
155 exitstatus = execute ("cscc", "cscc", argv, false, false, false, false, 155 exitstatus = execute ("cscc", "cscc", argv, false, false, false, false,
156 true, true); 156 true, true);
157 157
158 for (i = 0; i < sources_count; i++) 158 for (i = 0; i < sources_count; i++)
159 if (argv[argc - sources_count + i] != sources[i]) 159 if (argv[argc - sources_count + i] != sources[i])
160 freesa (argv[argc - sources_count + i]); 160 freea (argv[argc - sources_count + i]);
161 freesa (argv); 161 freea (argv);
162 162
163 return (exitstatus != 0); 163 return (exitstatus != 0);
164 } 164 }
165 else 165 else
166 return -1; 166 return -1;
212 unsigned int i; 212 unsigned int i;
213 213
214 argc = 214 argc =
215 1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count 215 1 + (output_is_library ? 1 : 0) + 1 + libdirs_count + libraries_count
216 + (debug ? 1 : 0) + sources_count; 216 + (debug ? 1 : 0) + sources_count;
217 argv = (char **) xallocsa ((argc + 1) * sizeof (char *)); 217 argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
218 218
219 argp = argv; 219 argp = argv;
220 *argp++ = "mcs"; 220 *argp++ = "mcs";
221 if (output_is_library) 221 if (output_is_library)
222 *argp++ = "-target:library"; 222 *argp++ = "-target:library";
223 { 223 {
224 char *option = (char *) xallocsa (5 + strlen (output_file) + 1); 224 char *option = (char *) xmalloca (5 + strlen (output_file) + 1);
225 memcpy (option, "-out:", 5); 225 memcpy (option, "-out:", 5);
226 strcpy (option + 5, output_file); 226 strcpy (option + 5, output_file);
227 *argp++ = option; 227 *argp++ = option;
228 } 228 }
229 for (i = 0; i < libdirs_count; i++) 229 for (i = 0; i < libdirs_count; i++)
230 { 230 {
231 char *option = (char *) xallocsa (5 + strlen (libdirs[i]) + 1); 231 char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1);
232 memcpy (option, "-lib:", 5); 232 memcpy (option, "-lib:", 5);
233 strcpy (option + 5, libdirs[i]); 233 strcpy (option + 5, libdirs[i]);
234 *argp++ = option; 234 *argp++ = option;
235 } 235 }
236 for (i = 0; i < libraries_count; i++) 236 for (i = 0; i < libraries_count; i++)
237 { 237 {
238 char *option = (char *) xallocsa (11 + strlen (libraries[i]) + 4 + 1); 238 char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
239 memcpy (option, "-reference:", 11); 239 memcpy (option, "-reference:", 11);
240 memcpy (option + 11, libraries[i], strlen (libraries[i])); 240 memcpy (option + 11, libraries[i], strlen (libraries[i]));
241 strcpy (option + 11 + strlen (libraries[i]), ".dll"); 241 strcpy (option + 11 + strlen (libraries[i]), ".dll");
242 *argp++ = option; 242 *argp++ = option;
243 } 243 }
248 const char *source_file = sources[i]; 248 const char *source_file = sources[i];
249 if (strlen (source_file) >= 10 249 if (strlen (source_file) >= 10
250 && memcmp (source_file + strlen (source_file) - 10, ".resources", 250 && memcmp (source_file + strlen (source_file) - 10, ".resources",
251 10) == 0) 251 10) == 0)
252 { 252 {
253 char *option = (char *) xallocsa (10 + strlen (source_file) + 1); 253 char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
254 254
255 memcpy (option, "-resource:", 10); 255 memcpy (option, "-resource:", 10);
256 strcpy (option + 10, source_file); 256 strcpy (option + 10, source_file);
257 *argp++ = option; 257 *argp++ = option;
258 } 258 }
306 306
307 for (i = 1 + (output_is_library ? 1 : 0); 307 for (i = 1 + (output_is_library ? 1 : 0);
308 i < 1 + (output_is_library ? 1 : 0) 308 i < 1 + (output_is_library ? 1 : 0)
309 + 1 + libdirs_count + libraries_count; 309 + 1 + libdirs_count + libraries_count;
310 i++) 310 i++)
311 freesa (argv[i]); 311 freea (argv[i]);
312 for (i = 0; i < sources_count; i++) 312 for (i = 0; i < sources_count; i++)
313 if (argv[argc - sources_count + i] != sources[i]) 313 if (argv[argc - sources_count + i] != sources[i])
314 freesa (argv[argc - sources_count + i]); 314 freea (argv[argc - sources_count + i]);
315 freesa (argv); 315 freea (argv);
316 316
317 return (exitstatus != 0); 317 return (exitstatus != 0);
318 } 318 }
319 else 319 else
320 return -1; 320 return -1;
394 unsigned int i; 394 unsigned int i;
395 395
396 argc = 396 argc =
397 1 + 1 + 1 + libdirs_count + libraries_count 397 1 + 1 + 1 + libdirs_count + libraries_count
398 + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count; 398 + (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
399 argv = (char **) xallocsa ((argc + 1) * sizeof (char *)); 399 argv = (char **) xmalloca ((argc + 1) * sizeof (char *));
400 400
401 argp = argv; 401 argp = argv;
402 *argp++ = "csc"; 402 *argp++ = "csc";
403 *argp++ = 403 *argp++ =
404 (char *) (output_is_library ? "-target:library" : "-target:exe"); 404 (char *) (output_is_library ? "-target:library" : "-target:exe");
405 { 405 {
406 char *option = (char *) xallocsa (5 + strlen (output_file) + 1); 406 char *option = (char *) xmalloca (5 + strlen (output_file) + 1);
407 memcpy (option, "-out:", 5); 407 memcpy (option, "-out:", 5);
408 strcpy (option + 5, output_file); 408 strcpy (option + 5, output_file);
409 *argp++ = option; 409 *argp++ = option;
410 } 410 }
411 for (i = 0; i < libdirs_count; i++) 411 for (i = 0; i < libdirs_count; i++)
412 { 412 {
413 char *option = (char *) xallocsa (5 + strlen (libdirs[i]) + 1); 413 char *option = (char *) xmalloca (5 + strlen (libdirs[i]) + 1);
414 memcpy (option, "-lib:", 5); 414 memcpy (option, "-lib:", 5);
415 strcpy (option + 5, libdirs[i]); 415 strcpy (option + 5, libdirs[i]);
416 *argp++ = option; 416 *argp++ = option;
417 } 417 }
418 for (i = 0; i < libraries_count; i++) 418 for (i = 0; i < libraries_count; i++)
419 { 419 {
420 char *option = (char *) xallocsa (11 + strlen (libraries[i]) + 4 + 1); 420 char *option = (char *) xmalloca (11 + strlen (libraries[i]) + 4 + 1);
421 memcpy (option, "-reference:", 11); 421 memcpy (option, "-reference:", 11);
422 memcpy (option + 11, libraries[i], strlen (libraries[i])); 422 memcpy (option + 11, libraries[i], strlen (libraries[i]));
423 strcpy (option + 11 + strlen (libraries[i]), ".dll"); 423 strcpy (option + 11 + strlen (libraries[i]), ".dll");
424 *argp++ = option; 424 *argp++ = option;
425 } 425 }
432 const char *source_file = sources[i]; 432 const char *source_file = sources[i];
433 if (strlen (source_file) >= 10 433 if (strlen (source_file) >= 10
434 && memcmp (source_file + strlen (source_file) - 10, ".resources", 434 && memcmp (source_file + strlen (source_file) - 10, ".resources",
435 10) == 0) 435 10) == 0)
436 { 436 {
437 char *option = (char *) xallocsa (10 + strlen (source_file) + 1); 437 char *option = (char *) xmalloca (10 + strlen (source_file) + 1);
438 438
439 memcpy (option, "-resource:", 10); 439 memcpy (option, "-resource:", 10);
440 strcpy (option + 10, source_file); 440 strcpy (option + 10, source_file);
441 *argp++ = option; 441 *argp++ = option;
442 } 442 }
457 457
458 exitstatus = execute ("csc", "csc", argv, false, false, false, false, 458 exitstatus = execute ("csc", "csc", argv, false, false, false, false,
459 true, true); 459 true, true);
460 460
461 for (i = 2; i < 3 + libdirs_count + libraries_count; i++) 461 for (i = 2; i < 3 + libdirs_count + libraries_count; i++)
462 freesa (argv[i]); 462 freea (argv[i]);
463 for (i = 0; i < sources_count; i++) 463 for (i = 0; i < sources_count; i++)
464 if (argv[argc - sources_count + i] != sources[i]) 464 if (argv[argc - sources_count + i] != sources[i])
465 freesa (argv[argc - sources_count + i]); 465 freea (argv[argc - sources_count + i]);
466 freesa (argv); 466 freea (argv);
467 467
468 return (exitstatus != 0); 468 return (exitstatus != 0);
469 } 469 }
470 else 470 else
471 return -1; 471 return -1;