00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "config.h"
00027 #include "system.h"
00028
00029 #undef PATH_SEPARATOR
00030 #undef PATH_SEPARATOR_STR
00031 #define PATH_SEPARATOR ','
00032 #define PATH_SEPARATOR_STR ","
00033
00034
00035 int verbose = 0;
00036 int save_temps = 0;
00037
00038 int comp_arg_max = -1;
00039 const char **comp_args = 0;
00040 int comp_arg_index = -1;
00041 char *objfilename = 0;
00042
00043 char *system_search_dirs = (char *) "";
00044 char *search_dirs;
00045
00046 char *default_defines = (char *) "";
00047 char *defines;
00048
00049
00050
00051 static char *to_host_dir_spec PARAMS ((char *));
00052
00053
00054
00055 static char *to_host_file_spec PARAMS ((char *));
00056
00057
00058 static void addarg PARAMS ((const char *));
00059
00060
00061
00062 static void preprocess_args PARAMS ((int *, char **));
00063
00064
00065
00066 static void process_args PARAMS ((int *, char **));
00067
00068
00069 static int translate_unix PARAMS ((char *, int));
00070
00071 int main PARAMS ((int, char **));
00072
00073
00074
00075
00076 static void
00077 addarg (str)
00078 const char *str;
00079 {
00080 int i;
00081
00082 if (++comp_arg_index >= comp_arg_max)
00083 {
00084 const char **new_comp_args
00085 = (const char **) xcalloc (comp_arg_max + 1000, sizeof (char *));
00086
00087 for (i = 0; i <= comp_arg_max; i++)
00088 new_comp_args [i] = comp_args [i];
00089
00090 if (comp_args)
00091 free (comp_args);
00092
00093 comp_arg_max += 1000;
00094 comp_args = new_comp_args;
00095 }
00096
00097 comp_args [comp_arg_index] = str;
00098 }
00099
00100 static void
00101 preprocess_args (p_argc, argv)
00102 int *p_argc;
00103 char *argv[];
00104 {
00105 int i;
00106
00107 for (i = 1; i < *p_argc; i++)
00108 {
00109 if (strcmp (argv[i], "-o") == 0)
00110 {
00111 char *buff, *ptr;
00112 int out_len;
00113
00114 i++;
00115 ptr = to_host_file_spec (argv[i]);
00116 objfilename = xstrdup (ptr);
00117 out_len = strlen (ptr);
00118 buff = xmalloc (out_len + 6);
00119
00120 strcpy (buff, "/obj=");
00121 strcat (buff, ptr);
00122 addarg (buff);
00123 }
00124 }
00125 }
00126
00127 static void
00128 process_args (p_argc, argv)
00129 int *p_argc;
00130 char *argv[];
00131 {
00132 int i;
00133
00134 for (i = 1; i < *p_argc; i++)
00135 {
00136 if (strlen (argv[i]) < 2)
00137 continue;
00138
00139 if (strncmp (argv[i], "-I", 2) == 0)
00140 {
00141 char *ptr;
00142 int new_len, search_dirs_len;
00143
00144 ptr = to_host_dir_spec (&argv[i][2]);
00145 new_len = strlen (ptr);
00146 search_dirs_len = strlen (search_dirs);
00147
00148 search_dirs = xrealloc (search_dirs, search_dirs_len + new_len + 2);
00149 if (search_dirs_len > 0)
00150 strcat (search_dirs, PATH_SEPARATOR_STR);
00151 strcat (search_dirs, ptr);
00152 }
00153 else if (strncmp (argv[i], "-D", 2) == 0)
00154 {
00155 char *ptr;
00156 int new_len, defines_len;
00157
00158 ptr = &argv[i][2];
00159 new_len = strlen (ptr);
00160 defines_len = strlen (defines);
00161
00162 defines = xrealloc (defines, defines_len + new_len + 4);
00163 if (defines_len > 0)
00164 strcat (defines, ",");
00165
00166 strcat (defines, "\"");
00167 strcat (defines, ptr);
00168 strcat (defines, "\"");
00169 }
00170 else if (strcmp (argv[i], "-v") == 0)
00171 verbose = 1;
00172 else if (strcmp (argv[i], "-g0") == 0)
00173 addarg ("/nodebug");
00174 else if (strcmp (argv[i], "-O0") == 0)
00175 addarg ("/noopt");
00176 else if (strncmp (argv[i], "-g", 2) == 0)
00177 addarg ("/debug");
00178 else if (strcmp (argv[i], "-E") == 0)
00179 addarg ("/preprocess");
00180 else if (strcmp (argv[i], "-save-temps") == 0)
00181 save_temps = 1;
00182 }
00183 }
00184
00185
00186
00187
00188 typedef struct dsc {unsigned short len, mbz; char *adr; } Descr;
00189
00190 int
00191 main (argc, argv)
00192 int argc;
00193 char **argv;
00194 {
00195 int i;
00196 char cwdev [128], *devptr;
00197 int devlen;
00198 char *cwd = getcwd (0, 1024);
00199
00200 devptr = strchr (cwd, ':');
00201 devlen = (devptr - cwd) + 1;
00202 strncpy (cwdev, cwd, devlen);
00203 cwdev [devlen] = '\0';
00204
00205 search_dirs = xmalloc (strlen (system_search_dirs) + 1);
00206 strcpy (search_dirs, system_search_dirs);
00207
00208 defines = xmalloc (strlen (default_defines) + 1);
00209 strcpy (defines, default_defines);
00210
00211 addarg ("cc");
00212 preprocess_args (&argc , argv);
00213 process_args (&argc , argv);
00214
00215 if (strlen (search_dirs) > 0)
00216 {
00217 addarg ("/include=(");
00218 addarg (search_dirs);
00219 addarg (")");
00220 }
00221
00222 if (strlen (defines) > 0)
00223 {
00224 addarg ("/define=(");
00225 addarg (defines);
00226 addarg (")");
00227 }
00228
00229 for (i = 1; i < argc; i++)
00230 {
00231 int arg_len = strlen (argv[i]);
00232
00233 if (strcmp (argv[i], "-o") == 0)
00234 i++;
00235 else if (strcmp (argv[i], "-v" ) == 0
00236 || strcmp (argv[i], "-E") == 0
00237 || strcmp (argv[i], "-c") == 0
00238 || strncmp (argv[i], "-g", 2 ) == 0
00239 || strncmp (argv[i], "-O", 2 ) == 0
00240 || strcmp (argv[i], "-save-temps") == 0
00241 || (arg_len > 2 && strncmp (argv[i], "-I", 2) == 0)
00242 || (arg_len > 2 && strncmp (argv[i], "-D", 2) == 0))
00243 ;
00244
00245
00246
00247
00248 else if ((argv[i][0] == '/') && (strchr (&argv[i][1], '/') == 0))
00249 addarg (argv[i]);
00250 else
00251 {
00252
00253 char buff [256], *ptr;
00254 int buff_len;
00255
00256 ptr = to_host_file_spec (argv[i]);
00257 arg_len = strlen (ptr);
00258
00259 if (ptr[0] == '[')
00260 sprintf (buff, "%s%s", cwdev, ptr);
00261 else if (strchr (ptr, ':'))
00262 sprintf (buff, "%s", ptr);
00263 else
00264 sprintf (buff, "%s%s", cwd, ptr);
00265
00266 buff_len = strlen (buff);
00267 ptr = xmalloc (buff_len + 1);
00268
00269 strcpy (ptr, buff);
00270 addarg (ptr);
00271 }
00272 }
00273
00274 addarg (NULL);
00275
00276 if (verbose)
00277 {
00278 int i;
00279
00280 for (i = 0; i < comp_arg_index; i++)
00281 printf ("%s ", comp_args [i]);
00282
00283 putchar ('\n');
00284 }
00285
00286 {
00287 int i;
00288 int len = 0;
00289
00290 for (i = 0; comp_args[i]; i++)
00291 len = len + strlen (comp_args[i]) + 1;
00292
00293 {
00294 char *allargs = (char *) alloca (len + 1);
00295 Descr cmd;
00296 int status;
00297 int status1 = 1;
00298
00299 for (i = 0; i < len + 1; i++)
00300 allargs [i] = 0;
00301
00302 for (i = 0; comp_args [i]; i++)
00303 {
00304 strcat (allargs, comp_args [i]);
00305 strcat (allargs, " ");
00306 }
00307
00308 cmd.adr = allargs;
00309 cmd.len = len;
00310 cmd.mbz = 0;
00311
00312 i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status);
00313
00314 if ((i & 1) != 1)
00315 {
00316 LIB$SIGNAL (i);
00317 exit (1);
00318 }
00319
00320 if ((status & 1) == 1 && (status1 & 1) == 1)
00321 exit (0);
00322
00323 exit (1);
00324 }
00325 }
00326 }
00327
00328 static char new_host_filespec [255];
00329 static char new_host_dirspec [255];
00330 static char filename_buff [256];
00331
00332 static int
00333 translate_unix (name, type)
00334 char *name;
00335 int type ATTRIBUTE_UNUSED;
00336 {
00337 strcpy (filename_buff, name);
00338 return 0;
00339 }
00340
00341 static char *
00342 to_host_dir_spec (dirspec)
00343 char *dirspec;
00344 {
00345 int len = strlen (dirspec);
00346
00347 strcpy (new_host_dirspec, dirspec);
00348
00349 if (strchr (new_host_dirspec, ']') || strchr (new_host_dirspec, ':'))
00350 return new_host_dirspec;
00351
00352 while (len > 1 && new_host_dirspec [len-1] == '/')
00353 {
00354 new_host_dirspec [len-1] = 0;
00355 len--;
00356 }
00357
00358 decc$to_vms (new_host_dirspec, translate_unix, 1, 2);
00359 strcpy (new_host_dirspec, filename_buff);
00360
00361 return new_host_dirspec;
00362
00363 }
00364
00365 static char *
00366 to_host_file_spec (filespec)
00367 char *filespec;
00368 {
00369 strcpy (new_host_filespec, "");
00370 if (strchr (filespec, ']') || strchr (filespec, ':'))
00371 strcpy (new_host_filespec, filespec);
00372 else
00373 {
00374 decc$to_vms (filespec, translate_unix, 1, 1);
00375 strcpy (new_host_filespec, filename_buff);
00376 }
00377
00378 return new_host_filespec;
00379 }