Exemplo n.º 1
0
static int
execute_csharp_using_sscli (const char *assembly_path,
			    const char * const *libdirs,
			    unsigned int libdirs_count,
			    const char * const *args, unsigned int nargs,
			    bool verbose, bool quiet,
			    execute_fn *executer, void *private_data)
{
  static bool clix_tested;
  static bool clix_present;

  if (!clix_tested)
    {
      /* Test for presence of clix:
	 "clix >/dev/null 2>/dev/null ; test $? = 1"  */
      char *argv[2];
      int exitstatus;

      argv[0] = "clix";
      argv[1] = NULL;
      exitstatus = execute ("clix", "clix", argv, false, false, true, true,
			    true, false);
      clix_present = (exitstatus == 0 || exitstatus == 1);
      clix_tested = true;
    }

  if (clix_present)
    {
      char *old_clixpath;
      char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
      unsigned int i;
      bool err;

      /* Set clix' PATH variable.  */
      old_clixpath = set_clixpath (libdirs, libdirs_count, false, verbose);

      argv[0] = "clix";
      argv[1] = (char *) assembly_path;
      for (i = 0; i <= nargs; i++)
	argv[2 + i] = (char *) args[i];

      if (verbose)
	{
	  char *command = shell_quote_argv (argv);
	  printf ("%s\n", command);
	  free (command);
	}

      err = executer ("clix", "clix", argv, private_data);

      /* Reset clix' PATH variable.  */
      reset_clixpath (old_clixpath);

      freesa (argv);

      return err;
    }
  else
    return -1;
}
Exemplo n.º 2
0
char *
__realpath (const char *name, char *resolved)
{
  char *rpath, *dest, *extra_buf = NULL;
  const char *start, *end, *rpath_limit;
  long int path_max;
#ifdef S_ISLNK
  int num_links = 0;
#endif

  if (name == NULL)
    {
      /* As per Single Unix Specification V2 we must return an error if
	 either parameter is a null pointer.  We extend this to allow
	 the RESOLVED parameter to be NULL in case the we are expected to
	 allocate the room for the return value.  */
      __set_errno (EINVAL);
      return NULL;
    }

  if (name[0] == '\0')
    {
      /* As per Single Unix Specification V2 we must return an error if
	 the name argument points to an empty string.  */
      __set_errno (ENOENT);
      return NULL;
    }

#ifdef PATH_MAX
  path_max = PATH_MAX;
#else
  path_max = pathconf (name, _PC_PATH_MAX);
  if (path_max <= 0)
    path_max = 1024;
#endif

  if (resolved == NULL)
    {
      rpath = malloc (path_max);
      if (rpath == NULL)
	return NULL;
    }
  else
    rpath = resolved;
  rpath_limit = rpath + path_max;

  if (name[0] != '/')
    {
      if (!__getcwd (rpath, path_max))
	{
	  rpath[0] = '\0';
	  goto error;
	}
      dest = strchr (rpath, '\0');
    }
  else
    {
      rpath[0] = '/';
      dest = rpath + 1;
    }

  for (start = end = name; *start; start = end)
    {
#ifdef _LIBC
      struct stat64 st;
#else
      struct stat st;
#endif

      /* Skip sequence of multiple path-separators.  */
      while (*start == '/')
	++start;

      /* Find end of path component.  */
      for (end = start; *end && *end != '/'; ++end)
	/* Nothing.  */;

      if (end - start == 0)
	break;
      else if (end - start == 1 && start[0] == '.')
	/* nothing */;
      else if (end - start == 2 && start[0] == '.' && start[1] == '.')
	{
	  /* Back up to previous component, ignore if at root already.  */
	  if (dest > rpath + 1)
	    while ((--dest)[-1] != '/');
	}
      else
	{
	  size_t new_size;

	  if (dest[-1] != '/')
	    *dest++ = '/';

	  if (dest + (end - start) >= rpath_limit)
	    {
	      ptrdiff_t dest_offset = dest - rpath;
	      char *new_rpath;

	      if (resolved)
		{
		  __set_errno (ENAMETOOLONG);
		  if (dest > rpath + 1)
		    dest--;
		  *dest = '\0';
		  goto error;
		}
	      new_size = rpath_limit - rpath;
	      if (end - start + 1 > path_max)
		new_size += end - start + 1;
	      else
		new_size += path_max;
	      new_rpath = (char *) realloc (rpath, new_size);
	      if (new_rpath == NULL)
		goto error;
	      rpath = new_rpath;
	      rpath_limit = rpath + new_size;

	      dest = rpath + dest_offset;
	    }

#ifdef _LIBC
	  dest = __mempcpy (dest, start, end - start);
#else
	  memcpy (dest, start, end - start);
	  dest += end - start;
#endif
	  *dest = '\0';

#ifdef _LIBC
	  if (__lxstat64 (_STAT_VER, rpath, &st) < 0)
#else
	  if (lstat (rpath, &st) < 0)
#endif
	    goto error;

#ifdef S_ISLNK
	  if (S_ISLNK (st.st_mode))
	    {
	      char *buf;
	      size_t len;
	      int n;

	      if (++num_links > MAXSYMLINKS)
		{
		  __set_errno (ELOOP);
		  goto error;
		}

	      buf = allocsa (path_max);
	      if (!buf)
		{
		  errno = ENOMEM;
		  goto error;
		}

	      n = __readlink (rpath, buf, path_max);
	      if (n < 0)
		{
		  int saved_errno = errno;
		  freesa (buf);
		  errno = saved_errno;
		  goto error;
		}
	      buf[n] = '\0';

	      if (!extra_buf)
		{
		  extra_buf = allocsa (path_max);
		  if (!extra_buf)
		    {
		      freesa (buf);
		      errno = ENOMEM;
		      goto error;
		    }
		}

	      len = strlen (end);
	      if ((long int) (n + len) >= path_max)
		{
		  freesa (buf);
		  __set_errno (ENAMETOOLONG);
		  goto error;
		}

	      /* Careful here, end may be a pointer into extra_buf... */
	      memmove (&extra_buf[n], end, len + 1);
	      name = end = memcpy (extra_buf, buf, n);

	      if (buf[0] == '/')
		dest = rpath + 1;	/* It's an absolute symlink */
	      else
		/* Back up to previous component, ignore if at root already: */
		if (dest > rpath + 1)
		  while ((--dest)[-1] != '/');
	    }
#endif
	}
    }
  if (dest > rpath + 1 && dest[-1] == '/')
    --dest;
  *dest = '\0';

  if (extra_buf)
    freesa (extra_buf);

  return resolved ? memcpy (resolved, rpath, dest - rpath + 1) : rpath;

error:
  {
    int saved_errno = errno;
    if (extra_buf)
      freesa (extra_buf);
    if (resolved)
      strcpy (resolved, rpath);
    else
      free (rpath);
    errno = saved_errno;
  }
  return NULL;
}
Exemplo n.º 3
0
msgdomain_list_ty *
msgdomain_read_tcl (const char *locale_name, const char *directory)
{
  const char *gettextdatadir;
  char *tclscript;
  size_t len;
  char *frobbed_locale_name;
  char *p;
  char *file_name;
  char *argv[4];
  pid_t child;
  int fd[1];
  FILE *fp;
  msgdomain_list_ty *mdlp;
  int exitstatus;
  size_t k;

  /* Make it possible to override the msgunfmt.tcl location.  This is
     necessary for running the testsuite before "make install".  */
  gettextdatadir = getenv ("GETTEXTDATADIR");
  if (gettextdatadir == NULL || gettextdatadir[0] == '\0')
    gettextdatadir = relocate (GETTEXTDATADIR);

  tclscript = concatenated_pathname (gettextdatadir, "msgunfmt.tcl", NULL);

  /* Convert the locale name to lowercase and remove any encoding.  */
  len = strlen (locale_name);
  frobbed_locale_name = (char *) xallocsa (len + 1);
  memcpy (frobbed_locale_name, locale_name, len + 1);
  for (p = frobbed_locale_name; *p != '\0'; p++)
    if (*p >= 'A' && *p <= 'Z')
      *p = *p - 'A' + 'a';
    else if (*p == '.')
      {
	*p = '\0';
	break;
      }

  file_name = concatenated_pathname (directory, frobbed_locale_name, ".msg");

  freesa (frobbed_locale_name);

  /* Prepare arguments.  */
  argv[0] = "tclsh";
  argv[1] = tclscript;
  argv[2] = file_name;
  argv[3] = NULL;

  if (verbose)
    {
      char *command = shell_quote_argv (argv);
      printf ("%s\n", command);
      free (command);
    }

  /* Open a pipe to the Tcl interpreter.  */
  child = create_pipe_in ("tclsh", "tclsh", argv, DEV_NULL, false, true, true,
			  fd);

  fp = fdopen (fd[0], "r");
  if (fp == NULL)
    error (EXIT_FAILURE, errno, _("fdopen() failed"));

  /* Read the message list.  */
  mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po);

  fclose (fp);

  /* Remove zombie process from process list, and retrieve exit status.  */
  exitstatus = wait_subprocess (child, "tclsh", false, false, true, true);
  if (exitstatus != 0)
    {
      if (exitstatus == 2)
	/* Special exitcode provided by msgunfmt.tcl.  */
	error (EXIT_FAILURE, ENOENT,
	       _("error while opening \"%s\" for reading"), file_name);
      else
	error (EXIT_FAILURE, 0, _("%s subprocess failed with exit code %d"),
	       "tclsh", exitstatus);
    }

  free (tclscript);

  /* Move the header entry to the beginning.  */
  for (k = 0; k < mdlp->nitems; k++)
    {
      message_list_ty *mlp = mdlp->item[k]->messages;
      size_t j;

      for (j = 0; j < mlp->nitems; j++)
	if (is_header (mlp->item[j]))
	  {
	    /* Found the header entry.  */
	    if (j > 0)
	      {
		message_ty *header = mlp->item[j];
		size_t i;

		for (i = j; i > 0; i--)
		  mlp->item[i] = mlp->item[i - 1];
		mlp->item[0] = header;
	      }
	    break;
	  }
    }

  return mdlp;
}
Exemplo n.º 4
0
/* This function is used by `setenv' and `putenv'.  The difference between
   the two functions is that for the former must create a new string which
   is then placed in the environment, while the argument of `putenv'
   must be used directly.  This is all complicated by the fact that we try
   to reuse values once generated for a `setenv' call since we can never
   free the strings.  */
int
__add_to_environ (const char *name, const char *value, const char *combined,
		  int replace)
{
  register char **ep;
  register size_t size;
  const size_t namelen = strlen (name);
  const size_t vallen = value != NULL ? strlen (value) + 1 : 0;

  LOCK;

  /* We have to get the pointer now that we have the lock and not earlier
     since another thread might have created a new environment.  */
  ep = __environ;

  size = 0;
  if (ep != NULL)
    {
      for (; *ep != NULL; ++ep)
	if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=')
	  break;
	else
	  ++size;
    }

  if (ep == NULL || *ep == NULL)
    {
      char **new_environ;
#ifdef USE_TSEARCH
      char *new_value;
#endif

      /* We allocated this space; we can extend it.  */
      new_environ =
	(char **) (last_environ == NULL
		   ? malloc ((size + 2) * sizeof (char *))
		   : realloc (last_environ, (size + 2) * sizeof (char *)));
      if (new_environ == NULL)
	{
	  UNLOCK;
	  return -1;
	}

      /* If the whole entry is given add it.  */
      if (combined != NULL)
	/* We must not add the string to the search tree since it belongs
	   to the user.  */
	new_environ[size] = (char *) combined;
      else
	{
	  /* See whether the value is already known.  */
#ifdef USE_TSEARCH
# ifdef _LIBC
	  new_value = (char *) alloca (namelen + 1 + vallen);
	  __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1),
		     value, vallen);
# else
	  new_value = (char *) allocsa (namelen + 1 + vallen);
	  if (new_value == NULL)
	    {
	      __set_errno (ENOMEM);
	      UNLOCK;
	      return -1;
	    }
	  memcpy (new_value, name, namelen);
	  new_value[namelen] = '=';
	  memcpy (&new_value[namelen + 1], value, vallen);
# endif

	  new_environ[size] = KNOWN_VALUE (new_value);
	  if (new_environ[size] == NULL)
#endif
	    {
	      new_environ[size] = (char *) malloc (namelen + 1 + vallen);
	      if (new_environ[size] == NULL)
		{
#if defined USE_TSEARCH && !defined _LIBC
		  freesa (new_value);
#endif
		  __set_errno (ENOMEM);
		  UNLOCK;
		  return -1;
		}

#ifdef USE_TSEARCH
	      memcpy (new_environ[size], new_value, namelen + 1 + vallen);
#else
	      memcpy (new_environ[size], name, namelen);
	      new_environ[size][namelen] = '=';
	      memcpy (&new_environ[size][namelen + 1], value, vallen);
#endif
	      /* And save the value now.  We cannot do this when we remove
		 the string since then we cannot decide whether it is a
		 user string or not.  */
	      STORE_VALUE (new_environ[size]);
	    }
#if defined USE_TSEARCH && !defined _LIBC
	  freesa (new_value);
#endif
	}

      if (__environ != last_environ)
	memcpy ((char *) new_environ, (char *) __environ,
		size * sizeof (char *));

      new_environ[size + 1] = NULL;

      last_environ = __environ = new_environ;
    }
  else if (replace)
    {
      char *np;

      /* Use the user string if given.  */
      if (combined != NULL)
	np = (char *) combined;
      else
	{
#ifdef USE_TSEARCH
	  char *new_value;
# ifdef _LIBC
	  new_value = alloca (namelen + 1 + vallen);
	  __mempcpy (__mempcpy (__mempcpy (new_value, name, namelen), "=", 1),
		     value, vallen);
# else
	  new_value = allocsa (namelen + 1 + vallen);
	  if (new_value == NULL)
	    {
	      __set_errno (ENOMEM);
	      UNLOCK;
	      return -1;
	    }
	  memcpy (new_value, name, namelen);
	  new_value[namelen] = '=';
	  memcpy (&new_value[namelen + 1], value, vallen);
# endif

	  np = KNOWN_VALUE (new_value);
	  if (np == NULL)
#endif
	    {
	      np = malloc (namelen + 1 + vallen);
	      if (np == NULL)
		{
#if defined USE_TSEARCH && !defined _LIBC
		  freesa (new_value);
#endif
		  __set_errno (ENOMEM);
		  UNLOCK;
		  return -1;
		}

#ifdef USE_TSEARCH
	      memcpy (np, new_value, namelen + 1 + vallen);
#else
	      memcpy (np, name, namelen);
	      np[namelen] = '=';
	      memcpy (&np[namelen + 1], value, vallen);
#endif
	      /* And remember the value.  */
	      STORE_VALUE (np);
	    }
#if defined USE_TSEARCH && !defined _LIBC
	  freesa (new_value);
#endif
	}

      *ep = np;
    }

  UNLOCK;

  return 0;
}
Exemplo n.º 5
0
bool
execute_java_class (const char *class_name,
		    const char * const *classpaths,
		    unsigned int classpaths_count,
		    bool use_minimal_classpath,
		    const char *exe_dir,
		    const char * const *args,
		    bool verbose, bool quiet,
		    execute_fn *executer, void *private_data)
{
  bool err = false;
  unsigned int nargs;
  char *old_JAVA_HOME;

  /* Count args.  */
  {
    const char * const *arg;

    for (nargs = 0, arg = args; *arg != NULL; nargs++, arg++)
     ;
  }

  /* First, try a class compiled to a native code executable.  */
  if (exe_dir != NULL)
    {
      char *exe_pathname = concatenated_pathname (exe_dir, class_name, EXEEXT);
      char *old_classpath;
      char **argv = (char **) xallocsa ((1 + nargs + 1) * sizeof (char *));
      unsigned int i;

      /* Set CLASSPATH.  */
      old_classpath =
	set_classpath (classpaths, classpaths_count, use_minimal_classpath,
		       verbose);

      argv[0] = exe_pathname;
      for (i = 0; i <= nargs; i++)
	argv[1 + i] = (char *) args[i];

      if (verbose)
	{
	  char *command = shell_quote_argv (argv);
	  printf ("%s\n", command);
	  free (command);
	}

      err = executer (class_name, exe_pathname, argv, private_data);

      /* Reset CLASSPATH.  */
      reset_classpath (old_classpath);

      freesa (argv);

      goto done1;
    }

  {
    const char *java = getenv ("JAVA");
    if (java != NULL && java[0] != '\0')
      {
	/* Because $JAVA may consist of a command and options, we use the
	   shell.  Because $JAVA has been set by the user, we leave all
	   all environment variables in place, including JAVA_HOME, and
	   we don't erase the user's CLASSPATH.  */
	char *old_classpath;
	unsigned int command_length;
	char *command;
	char *argv[4];
	const char * const *arg;
	char *p;

	/* Set CLASSPATH.  */
	old_classpath =
	  set_classpath (classpaths, classpaths_count, false,
			 verbose);

	command_length = strlen (java);
	command_length += 1 + shell_quote_length (class_name);
	for (arg = args; *arg != NULL; arg++)
	  command_length += 1 + shell_quote_length (*arg);
	command_length += 1;

	command = (char *) xallocsa (command_length);
	p = command;
	/* Don't shell_quote $JAVA, because it may consist of a command
	   and options.  */
	memcpy (p, java, strlen (java));
	p += strlen (java);
	*p++ = ' ';
	p = shell_quote_copy (p, class_name);
	for (arg = args; *arg != NULL; arg++)
	  {
	    *p++ = ' ';
	    p = shell_quote_copy (p, *arg);
	  }
	*p++ = '\0';
	/* Ensure command_length was correctly calculated.  */
	if (p - command > command_length)
	  abort ();

	if (verbose)
	  printf ("%s\n", command);

	argv[0] = "/bin/sh";
	argv[1] = "-c";
	argv[2] = command;
	argv[3] = NULL;
	err = executer (java, "/bin/sh", argv, private_data);

	freesa (command);

	/* Reset CLASSPATH.  */
	reset_classpath (old_classpath);

	goto done1;
      }
  }

  /* Unset the JAVA_HOME environment variable.  */
  old_JAVA_HOME = getenv ("JAVA_HOME");
  if (old_JAVA_HOME != NULL)
    {
      old_JAVA_HOME = xstrdup (old_JAVA_HOME);
      unsetenv ("JAVA_HOME");
    }

  {
    static bool gij_tested;
    static bool gij_present;

    if (!gij_tested)
      {
	/* Test for presence of gij: "gij --version > /dev/null"  */
	char *argv[3];
	int exitstatus;

	argv[0] = "gij";
	argv[1] = "--version";
	argv[2] = NULL;
	exitstatus = execute ("gij", "gij", argv, false, false, true, true,
			      true, false);
	gij_present = (exitstatus == 0);
	gij_tested = true;
      }

    if (gij_present)
      {
	char *old_classpath;
	char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
	unsigned int i;

	/* Set CLASSPATH.  */
	old_classpath =
	  set_classpath (classpaths, classpaths_count, use_minimal_classpath,
			 verbose);

	argv[0] = "gij";
	argv[1] = (char *) class_name;
	for (i = 0; i <= nargs; i++)
	  argv[2 + i] = (char *) args[i];

	if (verbose)
	  {
	    char *command = shell_quote_argv (argv);
	    printf ("%s\n", command);
	    free (command);
	  }

	err = executer ("gij", "gij", argv, private_data);

	/* Reset CLASSPATH.  */
	reset_classpath (old_classpath);

	freesa (argv);

	goto done2;
      }
  }

  {
    static bool java_tested;
    static bool java_present;

    if (!java_tested)
      {
	/* Test for presence of java: "java -version 2> /dev/null"  */
	char *argv[3];
	int exitstatus;

	argv[0] = "java";
	argv[1] = "-version";
	argv[2] = NULL;
	exitstatus = execute ("java", "java", argv, false, false, true, true,
			      true, false);
	java_present = (exitstatus == 0);
	java_tested = true;
      }

    if (java_present)
      {
	char *old_classpath;
	char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
	unsigned int i;

	/* Set CLASSPATH.  We don't use the "-classpath ..." option because
	   in JDK 1.1.x its argument should also contain the JDK's classes.zip,
	   but we don't know its location.  (In JDK 1.3.0 it would work.)  */
	old_classpath =
	  set_classpath (classpaths, classpaths_count, use_minimal_classpath,
			 verbose);

	argv[0] = "java";
	argv[1] = (char *) class_name;
	for (i = 0; i <= nargs; i++)
	  argv[2 + i] = (char *) args[i];

	if (verbose)
	  {
	    char *command = shell_quote_argv (argv);
	    printf ("%s\n", command);
	    free (command);
	  }

	err = executer ("java", "java", argv, private_data);

	/* Reset CLASSPATH.  */
	reset_classpath (old_classpath);

	freesa (argv);

	goto done2;
      }
  }

  {
    static bool jre_tested;
    static bool jre_present;

    if (!jre_tested)
      {
	/* Test for presence of jre: "jre 2> /dev/null ; test $? = 1"  */
	char *argv[2];
	int exitstatus;

	argv[0] = "jre";
	argv[1] = NULL;
	exitstatus = execute ("jre", "jre", argv, false, false, true, true,
			      true, false);
	jre_present = (exitstatus == 0 || exitstatus == 1);
	jre_tested = true;
      }

    if (jre_present)
      {
	char *old_classpath;
	char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
	unsigned int i;

	/* Set CLASSPATH.  We don't use the "-classpath ..." option because
	   in JDK 1.1.x its argument should also contain the JDK's classes.zip,
	   but we don't know its location.  */
	old_classpath =
	  set_classpath (classpaths, classpaths_count, use_minimal_classpath,
			 verbose);

	argv[0] = "jre";
	argv[1] = (char *) class_name;
	for (i = 0; i <= nargs; i++)
	  argv[2 + i] = (char *) args[i];

	if (verbose)
	  {
	    char *command = shell_quote_argv (argv);
	    printf ("%s\n", command);
	    free (command);
	  }

	err = executer ("jre", "jre", argv, private_data);

	/* Reset CLASSPATH.  */
	reset_classpath (old_classpath);

	freesa (argv);

	goto done2;
      }
  }

#if defined _WIN32 || defined __WIN32__
  /* Win32 */
  {
    static bool jview_tested;
    static bool jview_present;

    if (!jview_tested)
      {
	/* Test for presence of jview: "jview -? >nul ; test $? = 1"  */
	char *argv[3];
	int exitstatus;

	argv[0] = "jview";
	argv[1] = "-?";
	argv[2] = NULL;
	exitstatus = execute ("jview", "jview", argv, false, false, true, true,
			      true, false);
	jview_present = (exitstatus == 0 || exitstatus == 1);
	jview_tested = true;
      }

    if (jview_present)
      {
	char *old_classpath;
	char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
	unsigned int i;

	/* Set CLASSPATH.  */
	old_classpath =
	  set_classpath (classpaths, classpaths_count, use_minimal_classpath,
			 verbose);

	argv[0] = "jview";
	argv[1] = (char *) class_name;
	for (i = 0; i <= nargs; i++)
	  argv[2 + i] = (char *) args[i];

	if (verbose)
	  {
	    char *command = shell_quote_argv (argv);
	    printf ("%s\n", command);
	    free (command);
	  }

	err = executer ("jview", "jview", argv, private_data);

	/* Reset CLASSPATH.  */
	reset_classpath (old_classpath);

	freesa (argv);

	goto done2;
      }
  }
#endif

  if (!quiet)
    error (0, 0, _("Java virtual machine not found, try installing gij or set $JAVA"));
  err = true;

 done2:
  if (old_JAVA_HOME != NULL)
    {
      xsetenv ("JAVA_HOME", old_JAVA_HOME, 1);
      free (old_JAVA_HOME);
    }

 done1:
  return err;
}
Exemplo n.º 6
0
static int
compile_csharp_using_pnet (const char * const *sources,
			   unsigned int sources_count,
			   const char * const *libdirs,
			   unsigned int libdirs_count,
			   const char * const *libraries,
			   unsigned int libraries_count,
			   const char *output_file, bool output_is_library,
			   bool optimize, bool debug,
			   bool verbose)
{
  static bool cscc_tested;
  static bool cscc_present;

  if (!cscc_tested)
    {
      /* Test for presence of cscc:
	 "cscc --version >/dev/null 2>/dev/null"  */
      char *argv[3];
      int exitstatus;

      argv[0] = "cscc";
      argv[1] = "--version";
      argv[2] = NULL;
      exitstatus = execute ("cscc", "cscc", argv, false, false, true, true,
			    true, false);
      cscc_present = (exitstatus == 0);
      cscc_tested = true;
    }

  if (cscc_present)
    {
      unsigned int argc;
      char **argv;
      char **argp;
      int exitstatus;
      unsigned int i;

      argc =
	1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count
	+ 2 * libraries_count + (optimize ? 1 : 0) + (debug ? 1 : 0)
	+ sources_count;
      argv = (char **) xallocsa ((argc + 1) * sizeof (char *));

      argp = argv;
      *argp++ = "cscc";
      if (output_is_library)
	*argp++ = "-shared";
      *argp++ = "-o";
      *argp++ = (char *) output_file;
      for (i = 0; i < libdirs_count; i++)
	{
	  *argp++ = "-L";
	  *argp++ = (char *) libdirs[i];
	}
      for (i = 0; i < libraries_count; i++)
	{
	  *argp++ = "-l";
	  *argp++ = (char *) libraries[i];
	}
      if (optimize)
	*argp++ = "-O";
      if (debug)
	*argp++ = "-g";
      for (i = 0; i < sources_count; i++)
	{
	  const char *source_file = sources[i];
	  if (strlen (source_file) >= 9
	      && memcmp (source_file + strlen (source_file) - 9, ".resource",
			 9) == 0)
	    {
	      char *option = (char *) xallocsa (12 + strlen (source_file) + 1);

	      memcpy (option, "-fresources=", 12);
	      strcpy (option + 12, source_file);
	      *argp++ = option;
	    }
	  else
	    *argp++ = (char *) source_file;
	}
      *argp = NULL;
      /* Ensure argv length was correctly calculated.  */
      if (argp - argv != argc)
	abort ();

      if (verbose)
	{
	  char *command = shell_quote_argv (argv);
	  printf ("%s\n", command);
	  free (command);
	}

      exitstatus = execute ("cscc", "cscc", argv, false, false, false, false,
			    true, true);

      for (i = 0; i < sources_count; i++)
	if (argv[argc - sources_count + i] != sources[i])
	  freesa (argv[argc - sources_count + i]);
      freesa (argv);

      return (exitstatus != 0);
    }
  else
    return -1;
}
Exemplo n.º 7
0
static int
compile_csharp_using_sscli (const char * const *sources,
			    unsigned int sources_count,
			    const char * const *libdirs,
			    unsigned int libdirs_count,
			    const char * const *libraries,
			    unsigned int libraries_count,
			    const char *output_file, bool output_is_library,
			    bool optimize, bool debug,
			    bool verbose)
{
  static bool csc_tested;
  static bool csc_present;

  if (!csc_tested)
    {
      /* Test for presence of csc:
	 "csc -help >/dev/null 2>/dev/null \
	  && ! { csc -help 2>/dev/null | grep -i chicken > /dev/null; }"  */
      char *argv[3];
      pid_t child;
      int fd[1];
      int exitstatus;

      argv[0] = "csc";
      argv[1] = "-help";
      argv[2] = NULL;
      child = create_pipe_in ("csc", "csc", argv, DEV_NULL, true, true, false,
			      fd);
      csc_present = false;
      if (child != -1)
	{
	  /* Read the subprocess output, and test whether it contains the
	     string "chicken".  */
	  char c[7];
	  size_t count = 0;

	  csc_present = true;
	  while (safe_read (fd[0], &c[count], 1) > 0)
	    {
	      if (c[count] >= 'A' && c[count] <= 'Z')
		c[count] += 'a' - 'A';
	      count++;
	      if (count == 7)
		{
		  if (memcmp (c, "chicken", 7) == 0)
		    csc_present = false;
		  c[0] = c[1]; c[1] = c[2]; c[2] = c[3];
		  c[3] = c[4]; c[4] = c[5]; c[5] = c[6];
		  count--;
		}
	    }

	  close (fd[0]);

	  /* Remove zombie process from process list, and retrieve exit
	     status.  */
	  exitstatus =
	    wait_subprocess (child, "csc", false, true, true, false);
	  if (exitstatus != 0)
	    csc_present = false;
	}
      csc_tested = true;
    }

  if (csc_present)
    {
      unsigned int argc;
      char **argv;
      char **argp;
      int exitstatus;
      unsigned int i;

      argc =
	1 + 1 + 1 + libdirs_count + libraries_count
	+ (optimize ? 1 : 0) + (debug ? 1 : 0) + sources_count;
      argv = (char **) xallocsa ((argc + 1) * sizeof (char *));

      argp = argv;
      *argp++ = "csc";
      *argp++ = (output_is_library ? "-target:library" : "-target:exe");
      {
	char *option = (char *) xallocsa (5 + strlen (output_file) + 1);
	memcpy (option, "-out:", 5);
	strcpy (option + 5, output_file);
	*argp++ = option;
      }
      for (i = 0; i < libdirs_count; i++)
	{
	  char *option = (char *) xallocsa (5 + strlen (libdirs[i]) + 1);
	  memcpy (option, "-lib:", 5);
	  strcpy (option + 5, libdirs[i]);
	  *argp++ = option;
	}
      for (i = 0; i < libraries_count; i++)
	{
	  char *option = (char *) xallocsa (11 + strlen (libraries[i]) + 1);
	  memcpy (option, "-reference:", 11);
	  strcpy (option + 11, libraries[i]);
	  *argp++ = option;
	}
      if (optimize)
	*argp++ = "-optimize+";
      if (debug)
	*argp++ = "-debug+";
      for (i = 0; i < sources_count; i++)
	{
	  const char *source_file = sources[i];
	  if (strlen (source_file) >= 9
	      && memcmp (source_file + strlen (source_file) - 9, ".resource",
			 9) == 0)
	    {
	      char *option = (char *) xallocsa (10 + strlen (source_file) + 1);

	      memcpy (option, "-resource:", 10);
	      strcpy (option + 10, source_file);
	      *argp++ = option;
	    }
	  else
	    *argp++ = (char *) source_file;
	}
      *argp = NULL;
      /* Ensure argv length was correctly calculated.  */
      if (argp - argv != argc)
	abort ();

      if (verbose)
	{
	  char *command = shell_quote_argv (argv);
	  printf ("%s\n", command);
	  free (command);
	}

      exitstatus = execute ("csc", "csc", argv, false, false, false, false,
			    true, true);

      for (i = 2; i < 3 + libdirs_count + libraries_count; i++)
	freesa (argv[i]);
      for (i = 0; i < sources_count; i++)
	if (argv[argc - sources_count + i] != sources[i])
	  freesa (argv[argc - sources_count + i]);
      freesa (argv);

      return (exitstatus != 0);
    }
  else
    return -1;
}
Exemplo n.º 8
0
static int
compile_csharp_using_mono (const char * const *sources,
			   unsigned int sources_count,
			   const char * const *libdirs,
			   unsigned int libdirs_count,
			   const char * const *libraries,
			   unsigned int libraries_count,
			   const char *output_file, bool output_is_library,
			   bool optimize, bool debug,
			   bool verbose)
{
  static bool mcs_tested;
  static bool mcs_present;

  if (!mcs_tested)
    {
      /* Test for presence of mcs:
	 "mcs --version >/dev/null 2>/dev/null"  */
      char *argv[3];
      int exitstatus;

      argv[0] = "mcs";
      argv[1] = "--version";
      argv[2] = NULL;
      exitstatus = execute ("mcs", "mcs", argv, false, false, true, true, true,
			    false);
      mcs_present = (exitstatus == 0);
      mcs_tested = true;
    }

  if (mcs_present)
    {
      unsigned int argc;
      char **argv;
      char **argp;
      pid_t child;
      int fd[1];
      FILE *fp;
      char *line[2];
      size_t linesize[2];
      size_t linelen[2];
      unsigned int l;
      int exitstatus;
      unsigned int i;

      argc =
	1 + (output_is_library ? 1 : 0) + 2 + 2 * libdirs_count
	+ 2 * libraries_count + (debug ? 1 : 0) + sources_count;
      argv = (char **) xallocsa ((argc + 1) * sizeof (char *));

      argp = argv;
      *argp++ = "mcs";
      if (output_is_library)
	*argp++ = "-target:library";
      *argp++ = "-o";
      *argp++ = (char *) output_file;
      for (i = 0; i < libdirs_count; i++)
	{
	  *argp++ = "-L";
	  *argp++ = (char *) libdirs[i];
	}
      for (i = 0; i < libraries_count; i++)
	{
	  *argp++ = "-r";
	  *argp++ = (char *) libraries[i];
	}
      if (debug)
	*argp++ = "-g";
      for (i = 0; i < sources_count; i++)
	{
	  const char *source_file = sources[i];
	  if (strlen (source_file) >= 9
	      && memcmp (source_file + strlen (source_file) - 9, ".resource",
			 9) == 0)
	    {
	      char *option = (char *) xallocsa (10 + strlen (source_file) + 1);

	      memcpy (option, "-resource:", 10);
	      strcpy (option + 10, source_file);
	      *argp++ = option;
	    }
	  else
	    *argp++ = (char *) source_file;
	}
      *argp = NULL;
      /* Ensure argv length was correctly calculated.  */
      if (argp - argv != argc)
	abort ();

      if (verbose)
	{
	  char *command = shell_quote_argv (argv);
	  printf ("%s\n", command);
	  free (command);
	}

      child = create_pipe_in ("mcs", "mcs", argv, NULL, false, true, true, fd);

      /* Read the subprocess output, copying it to stderr.  Drop the last
	 line if it starts with "Compilation succeeded".  */
      fp = fdopen (fd[0], "r");
      if (fp == NULL)
	error (EXIT_FAILURE, errno, _("fdopen() failed"));
      line[0] = NULL; linesize[0] = 0;
      line[1] = NULL; linesize[1] = 0;
      l = 0;
      for (;;)
	{
	  linelen[l] = getline (&line[l], &linesize[l], fp);
	  if (linelen[l] == (size_t)(-1))
	    break;
	  l = (l + 1) % 2;
	  if (line[l] != NULL)
	    fwrite (line[l], 1, linelen[l], stderr);
	}
      l = (l + 1) % 2;
      if (line[l] != NULL
	  && !(linelen[l] >= 21
	       && memcmp (line[l], "Compilation succeeded", 21) == 0))
	fwrite (line[l], 1, linelen[l], stderr);
      if (line[0] != NULL)
	free (line[0]);
      if (line[1] != NULL)
	free (line[1]);
      fclose (fp);

      /* Remove zombie process from process list, and retrieve exit status.  */
      exitstatus = wait_subprocess (child, "mcs", false, false, true, true);

      for (i = 0; i < sources_count; i++)
	if (argv[argc - sources_count + i] != sources[i])
	  freesa (argv[argc - sources_count + i]);
      freesa (argv);

      return (exitstatus != 0);
    }
  else
    return -1;
}
Exemplo n.º 9
0
static int
execute_csharp_using_pnet (const char *assembly_path,
			   const char * const *libdirs,
			   unsigned int libdirs_count,
			   const char * const *args, unsigned int nargs,
			   bool verbose, bool quiet,
			   execute_fn *executer, void *private_data)
{
  static bool ilrun_tested;
  static bool ilrun_present;

  if (!ilrun_tested)
    {
      /* Test for presence of ilrun:
	 "ilrun --version >/dev/null 2>/dev/null"  */
      char *argv[3];
      int exitstatus;

      argv[0] = "ilrun";
      argv[1] = "--version";
      argv[2] = NULL;
      exitstatus = execute ("ilrun", "ilrun", argv, false, false, true, true,
			    true, false);
      ilrun_present = (exitstatus == 0);
      ilrun_tested = true;
    }

  if (ilrun_present)
    {
      unsigned int argc;
      char **argv;
      char **argp;
      unsigned int i;
      bool err;

      argc = 1 + 2 * libdirs_count + 1 + nargs;
      argv = (char **) xallocsa ((argc + 1) * sizeof (char *));

      argp = argv;
      *argp++ = "ilrun";
      for (i = 0; i < libdirs_count; i++)
	{
	  *argp++ = "-L";
	  *argp++ = (char *) libdirs[i];
	}
      *argp++ = (char *) assembly_path;
      for (i = 0; i < nargs; i++)
	*argp++ = (char *) args[i];
      *argp = NULL;
      /* Ensure argv length was correctly calculated.  */
      if (argp - argv != argc)
	abort ();

      if (verbose)
	{
	  char *command = shell_quote_argv (argv);
	  printf ("%s\n", command);
	  free (command);
	}

      err = executer ("ilrun", "ilrun", argv, private_data);

      freesa (argv);

      return err;
    }
  else
    return -1;
}
Exemplo n.º 10
0
static int
execute_csharp_using_mono (const char *assembly_path,
			   const char * const *libdirs,
			   unsigned int libdirs_count,
			   const char * const *args, unsigned int nargs,
			   bool verbose, bool quiet,
			   execute_fn *executer, void *private_data)
{
  static bool mono_tested;
  static bool mono_present;

  if (!mono_tested)
    {
      /* Test for presence of mono:
	 "mono --version >/dev/null 2>/dev/null"  */
      char *argv[3];
      int exitstatus;

      argv[0] = "mono";
      argv[1] = "--version";
      argv[2] = NULL;
      exitstatus = execute ("mono", "mono", argv, false, false, true, true,
			    true, false);
      mono_present = (exitstatus == 0);
      mono_tested = true;
    }

  if (mono_present)
    {
      char *old_monopath;
      char **argv = (char **) xallocsa ((2 + nargs + 1) * sizeof (char *));
      unsigned int i;
      bool err;

      /* Set MONO_PATH.  */
      old_monopath = set_monopath (libdirs, libdirs_count, false, verbose);

      argv[0] = "mono";
      argv[1] = (char *) assembly_path;
      for (i = 0; i <= nargs; i++)
	argv[2 + i] = (char *) args[i];

      if (verbose)
	{
	  char *command = shell_quote_argv (argv);
	  printf ("%s\n", command);
	  free (command);
	}

      err = executer ("mono", "mono", argv, private_data);

      /* Reset MONO_PATH.  */
      reset_monopath (old_monopath);

      freesa (argv);

      return err;
    }
  else
    return -1;
}