Example #1
0
/** Initialize \a pDev. */
void
msLinuxInit(DevicePtr pDev)
{
    GETPRIV;
    const char *names[] = { "/dev/serialmouse", "/dev/mouse", NULL };
    int i;

    if (priv->fd >= 0)
        return;

    for (i = 0; names[i]; i++) {
        if ((priv->fd = open(names[i], O_RDWR | O_NONBLOCK, 0)) >= 0)
            break;
    }
    if (priv->fd < 0)
        FATAL1("msLinuxInit: Cannot open mouse port (%s)\n", strerror(errno));

    if (!isatty(priv->fd))
        FATAL1("msLinuxInit: Mouse port %s is not a tty\n", names[i]);

    if (tcgetattr(priv->fd, &priv->tty) < 0)
        FATAL1("msLinuxInit: tcgetattr failed (%s)\n", strerror(errno));

    i = write(priv->fd, "*n", 2);   /* 1200 baud */
    (void) i;
    usleep(100000);
}
Example #2
0
static void
get_server_info (Window *server_window, Display **display, string identity)
{
    int scr;

    /* Open our own connection to the X server, since sending messages
       through the server's connection hangs.  */
    *display = XOpenDisplay (NULL);
    if (*display == NULL)
        FATAL1 ("limn: Could not open display `%s'", getenv ("DISPLAY"));

    /* Get the identity atom. Create it if it doesn't exist.  */
    foserver_identity_atom
        = XInternAtom (*display, FOSERVER_IDENTITY_ATOM, False);

    /* Ask to be told about most window events.  */
    XSelectInput (*display, DefaultRootWindow (*display),
                  SubstructureNotifyMask);

    /* Remove potential race condition below -- if our server has already
       had its window realized, we wouldn't find it otherwise. Search all
       windows first.  We might just as well search all screens too. */
    *server_window = None;
    for (scr = ScreenCount (*display); scr > 0 && *server_window == None; scr--)
    {
        Window root = RootWindow (*display, scr - 1);
        *server_window = search_children (*display, root, identity);
    }

    while (*server_window == None)
    {
        XEvent event;
        Window w;

        /* Wait for an event that might mean our server is ready.  */
        XIfEvent (*display, &event, window_change_p, NULL);

        /* We look for some property on the window, and rely on our server
           setting that property.  */
        switch (event.type)
        {
        case MapNotify:
            w = event.xmap.window;
            *server_window = search_children (*display, w, identity);
            break;

        default:
            FATAL1 ("limn: Unexpected event (type %d)", event.type);
        }
    }

    /* We don't want to see any events any more.  */
    XSelectInput (*display, DefaultRootWindow (*display),
                  NoEventMask);
}
Example #3
0
/** Turn \a pDev on (i.e., take input from \a pDev). */
int
msLinuxOn(DevicePtr pDev)
{
    GETPRIV;
    struct termios nTty;
    int i;

    if (priv->fd < 0)
        msLinuxInit(pDev);

    nTty = priv->tty;
    nTty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR
                      | IGNCR | ICRNL | IXON | IXOFF);
    nTty.c_oflag &= ~OPOST;
    nTty.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
    nTty.c_cflag &= ~(CSIZE | PARENB);
    nTty.c_cflag |= CS8 | CLOCAL | CSTOPB;
    nTty.c_cc[VTIME] = 0;
    nTty.c_cc[VMIN] = 1;
    cfsetispeed(&nTty, B1200);
    cfsetospeed(&nTty, B1200);
    if (tcsetattr(priv->fd, TCSANOW, &nTty) < 0)
        FATAL1("msLinuxInit: tcsetattr failed (%s)\n", strerror(errno));
    i = write(priv->fd, "*V", 2);   /* 2 button 3 byte protocol */
    (void) i;
    return priv->fd;
}
Example #4
0
unsigned
atou (const_string s)
{
  int i = atoi (s);

  if (i < 0)
    FATAL1 ("I expected a positive number, not %d", i);
  return i;
}
void
xputenv P2C(const_string, var_name,  const_string, value)
{
  static const_string *saved_env_items;
  static unsigned saved_len;
  string old_item = NULL;
  string new_item = concat3 (var_name, "=", value);

#ifndef SMART_PUTENV
  /* Check if we have saved anything yet.  */
  if (!saved_env_items)
    {
      saved_env_items = XTALLOC1 (const_string);
      saved_env_items[0] = var_name;
      saved_len = 1;
    }
  else
    {
      /* Check if we've assigned VAR_NAME before.  */
      unsigned i;
      unsigned len = strlen (var_name);
      for (i = 0; i < saved_len && !old_item; i++)
        {
          if (STREQ (saved_env_items[i], var_name))
            {
              old_item = getenv (var_name);
              assert (old_item);
              old_item -= (len + 1);  /* Back up to the `NAME='.  */
            }
        }
      
      if (!old_item)
        {
          /* If we haven't seen VAR_NAME before, save it.  Assume it is
             in safe storage.  */
          saved_len++;
          XRETALLOC (saved_env_items, saved_len, const_string);
          saved_env_items[saved_len - 1] = var_name;
        }
    }
#endif /* not SMART_PUTENV */

  /* As far as I can see there's no way to distinguish between the
     various errors; putenv doesn't have errno values.  */
  if (putenv (new_item) < 0)
    FATAL1 ("putenv (%s) failed", new_item);
  
#ifndef SMART_PUTENV
  /* Can't free `new_item' because its contained value is now in
     `environ', but we can free `old_item', since it's been replaced.  */
  if (old_item)
    free (old_item);
#endif /* not SMART_PUTENV */
}
Example #6
0
void
x_output_char (char_info_type c, spline_list_array_type splines)
{
    unsigned this_list;

    if (!wants_display) return;

    /* Draw the fitted lines a little thicker, so they'll be easier to see.  */
    XSetLineAttributes (display, gc, 1, LineSolid, CapButt, JoinMiter);

    for (this_list = 0; this_list < SPLINE_LIST_ARRAY_LENGTH (splines);
            this_list++)
    {
        unsigned this_spline;
        spline_list_type list = SPLINE_LIST_ARRAY_ELT (splines, this_list);

        for (this_spline = 0; this_spline < SPLINE_LIST_LENGTH (list);
                this_spline++)
        {
            spline_type s = SPLINE_LIST_ELT (list, this_spline);

            if (SPLINE_DEGREE (s) == LINEAR)
            {
                coordinate_type start
                    = real_cartesian_to_offset_x (START_POINT (s));
                coordinate_type end
                    = real_cartesian_to_offset_x (END_POINT (s));

                XDrawLine (display, pixmap, gc, X_LINE (start, end));
            }

            else if (SPLINE_DEGREE (s) == CUBIC)
                digitize_spline (s);

            else
                FATAL1 ("x_output_char: Spline with degree %d", SPLINE_DEGREE (s));
        }
    }

    /* If desired, make sure everything is visible, then wait for the user
       to hit return, so s/he can look at the results.  */
    if (display_stop)
    {
        char dummy;

        send_event (server_window, foserver_update_pixmap_atom, pixmap);
        XSync (display, False);

        if (verbose) putchar ('\n');
        printf ("RET to continue: " );
        scanf ("%c", &dummy);
    }
}
Example #7
0
static void
send_event (Window w, Atom atom, long data)
{
    XEvent e;

    e.xclient.type = ClientMessage;
    e.xclient.display = display;
    e.xclient.window = w;
    e.xclient.message_type = atom;
    e.xclient.format = 32;
    e.xclient.data.l[0] = data;

    if (XSendEvent (display, w, False, NoEventMask, &e) == 0)
        FATAL1 ("limn: XSendEvent (of %s) failed", XGetAtomName (display, atom));
}
Example #8
0
static void
message_handler (Widget w, XEvent *event, String *params, Cardinal *n_params)
{
  switch (event->type)
    {
    case ClientMessage:
      {
        XClientMessageEvent m = event->xclient;
        message_data_type d;
        
        /* Because two union types are never equivalent, and the X
           library does not define a type for the data part of the
           event, we must copy the data.  */
        memcpy (&d, &(m.data), sizeof (d.b));
        
        dispatch_message (m.message_type, d);
        break;
      }

    default:
      FATAL1 ("foserver: Unexpected event (type %d)", event->type);
    }
}
Example #9
0
string *grep(char *regexp, char *line, int num_vars) 
{
  struct re_pattern_buffer *rc;
  struct re_registers *p;
  const_string ok;
  string *vars = NULL;
  string *lookup;
  int i;

  if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
    fprintf(stderr, "Grep\n\t%s\n\tin\n\t%s\n", regexp, line);
  }

  if (test_file('z', line))
    return NULL;

  /* This will retrieve the precompiled regexp or compile it and
     remember it. vars contains the strings matched, num_vars the number
     of these strings. */
#if 0
  if ((lookup = hash_lookup(symtab, regexp)))
    rc = (struct re_pattern_buffer *)lookup[0];
  else
    rc = NULL;
  if (rc == NULL) {
#endif
    /* Compile the regexp and stores the result */

    if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
      fprintf(stderr, "\tCompiling the regexp\n");
    }

    re_syntax_options = RE_SYNTAX_POSIX_EGREP;
    rc = (struct re_pattern_buffer *) calloc(1, sizeof(struct re_pattern_buffer));
    rc->regs_allocated = REGS_UNALLOCATED;
    if ((ok = re_compile_pattern(regexp, strlen(regexp), rc)) != 0)
      FATAL1("Can't compile regex %s\n", regexp);
#if 0
    hash_remove_all(symtab, regexp);
    hash_insert(symtab, regexp, (char *)rc);
  }
  else   if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
    fprintf(stderr, "\tAlready compiled\n");
  }
#endif

  p = (struct re_registers *) calloc(1, sizeof(struct re_registers));
  p->num_regs = num_vars;
  if ((re_match(rc, line, strlen(line), 0, p)) > 0) {
    vars = (char **) xmalloc ((num_vars+1) * sizeof(char *));
    for (i = 0; i <= num_vars; i++) {
      vars[i] = malloc((p->end[i] - p->start[i] + 1)*sizeof(char));
      strncpy(vars[i], line+p->start[i], p->end[i] - p->start[i]);
      vars[i][p->end[i] - p->start[i]] = '\0';
    }
  }
  free (p);
  if (KPSE_DEBUG_P(MKTEX_FINE_DEBUG)) {
    if (vars)
      for(i = 0; i <= num_vars; i++)
	fprintf(stderr, "String %d matches %s\n", i, vars[i]);
  }
  return vars;
}
Example #10
0
void
xputenv P2C(const_string, var_name,  const_string, value)
{
  string old_item = NULL;
  string new_item = concat3 (var_name, "=", value);
  unsigned name_len = strlen (var_name);

#ifndef SMART_PUTENV

  static const_string *saved_env_items = NULL;
  static unsigned saved_len;
  boolean found = false;

  /* Check if we have saved anything yet.  */
  if (!saved_env_items)
    {
      saved_env_items = XTALLOC1 (const_string);
      saved_env_items[0] = var_name;
      saved_len = 1;
    }
  else
    {
      /* Check if we've assigned VAR_NAME before.  */
      unsigned i;
      for (i = 0; i < saved_len && !found; i++)
        {
          if (STREQ (saved_env_items[i], var_name))
            {
              found = true;
              old_item = getenv (var_name);
#ifdef WIN32
	      /* win32 putenv() removes the variable if called with
		 "VAR=". So we have to cope with this case. Distinction
		 is not made between the value being "" or the variable
		 not set. */
	      if (old_item)
		old_item -= (name_len + 1);
#else
              assert (old_item);
              /* Back up to the `NAME=' in the environment before the
                 value that getenv returns.  */
              old_item -= (name_len + 1);
#endif
            }
        }

      if (!found)
        {
          /* If we haven't seen VAR_NAME before, save it.  Assume it is
             in safe storage.  */
          saved_len++;
          XRETALLOC (saved_env_items, saved_len, const_string);
          saved_env_items[saved_len - 1] = var_name;
        }
    }
#endif /* not SMART_PUTENV */

  /* If the old and the new values are identical, don't do anything.
     This is both more memory-efficient and safer as far as our
     assumptions (about how putenv is implemented in libc) go.  */
  if (!old_item || !STREQ (old_item, new_item))
    {
      char *new_val;
      /* As far as I can see there's no way to distinguish between the
         various errors; putenv doesn't have errno values.  */
      if (putenv (new_item) < 0)
        FATAL1 ("putenv (%s) failed", new_item);

      /* If their putenv copied `new_item', we can free it.  */
      new_val = getenv (var_name);
      if (new_val && new_val - name_len - 1 != new_item)
        free (new_item);

#ifndef SMART_PUTENV
      /* Can't free `new_item' because its contained value is now in
         `environ', but we can free `old_item', since it's been replaced.  */
#ifndef WIN32
      /* ... except on Win32, where old_item points to garbage.
         Or at least non free-able memory. Or at least, that's what
         BoundsChecker says... FP, 06/10/98) */
      if (old_item)
        free (old_item);
#endif
#endif /* not SMART_PUTENV */
    }
}
Example #11
0
static string
maketex P2C(kpse_file_format_type, format, string*, args)
{
  /* New implementation, use fork/exec pair instead of popen, since
   * the latter is virtually impossible to make safe.
   */
  unsigned len;
  string *s;
  string ret;
  string fn;
  
  if (!kpse_make_tex_discard_errors) {
    fprintf (stderr, "kpathsea: Running");
    for (s = &args[0]; *s != NULL; s++)
      fprintf (stderr, " %s", *s);
    fputc('\n', stderr);
  }

#if defined (AMIGA)
  /* Amiga has a different interface. */
  {
    string cmd;
    string newcmd;
    cmd = xstrdup(args[0]);
    for (s = &args[1];  *s != NULL; s++) {
      newcmd = concat(cmd, *s);
      free (cmd);
      cmd = newcmd;
    }
    ret = system(cmd) == 0 ? getenv ("LAST_FONT_CREATED"): NULL;
    free (cmd);
  }
#elif defined (MSDOS)
#error Implement new MSDOS mktex call interface here
#elif defined (WIN32)
  /* We would vastly prefer to link directly with mktex.c here.
     Unfortunately, it is not quite possible because kpathsea
     is not reentrant. The progname is expected to be set in mktex.c
     and various initialisations occur. So to be safe, we implement
     a call sequence equivalent to the Unix one. */
  {
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    HANDLE child_in, child_out, child_err;
    HANDLE father_in, father_out_dup;
    HANDLE current_pid;
    SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};
    string new_cmd = NULL, app_name = NULL;

    char buf[1024+1];
    int num;
    extern char *quote_args(char **argv);

    if (look_for_cmd(args[0], &app_name) == FALSE) {
      ret = NULL;
      goto error_exit;
    }

    /* Compute the command line */
    new_cmd = quote_args(args);

    /* We need this handle to duplicate other handles */
    current_pid = GetCurrentProcess();

    ZeroMemory( &si, sizeof(STARTUPINFO) );
    si.cb = sizeof(STARTUPINFO);
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW ;
    si.wShowWindow = /* 0 */ SW_HIDE ;

    /* Child stdin */
    child_in = CreateFile("nul",
                          GENERIC_READ,
                          FILE_SHARE_READ | FILE_SHARE_WRITE,
                          &sa,  /* non inheritable */
                          OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL,
                          NULL);
    si.hStdInput = child_in;

    if (CreatePipe(&father_in, &child_out, NULL, 0) == FALSE) {
      fprintf(stderr, "popen: error CreatePipe\n");
      goto error_exit;
    }
    if (DuplicateHandle(current_pid, child_out,
                        current_pid, &father_out_dup,
                        0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE) {
      fprintf(stderr, "popen: error DuplicateHandle father_in\n");
      CloseHandle(father_in);
      CloseHandle(child_out);
      goto error_exit;
    }
    CloseHandle(child_out);
    si.hStdOutput = father_out_dup;

    /* Child stderr */
    if (kpse_make_tex_discard_errors) {
      child_err = CreateFile("nul",
                             GENERIC_WRITE,
                             FILE_SHARE_READ | FILE_SHARE_WRITE,
                             &sa,       /* non inheritable */
                             OPEN_EXISTING,
                             FILE_ATTRIBUTE_NORMAL,
                             NULL);
    }
    else {
      DuplicateHandle(current_pid, GetStdHandle(STD_ERROR_HANDLE),
                      current_pid, &child_err,
                      0, TRUE,
                      DUPLICATE_SAME_ACCESS);
    }
    si.hStdError = child_err;

    /* creating child process */
    if (CreateProcess(app_name, /* pointer to name of executable module */
                      new_cmd,  /* pointer to command line string */
                      NULL,     /* pointer to process security attributes */
                      NULL,     /* pointer to thread security attributes */
                      TRUE,     /* handle inheritance flag */
                      0,                /* creation flags */
                      NULL,     /* pointer to environment */
                      NULL,     /* pointer to current directory */
                      &si,      /* pointer to STARTUPINFO */
                      &pi               /* pointer to PROCESS_INFORMATION */
                      ) == 0) {
      FATAL2("kpathsea: CreateProcess() failed for `%s' (Error %x)\n", new_cmd, GetLastError());
    }

    CloseHandle(child_in);
    CloseHandle(father_out_dup);
    CloseHandle(child_err);

    /* Only the process handle is needed */
    CloseHandle(pi.hThread);

    /* Get stdout of child from the pipe. */
    fn = xstrdup("");
    while (ReadFile(father_in,buf,sizeof(buf)-1, &num, NULL) != 0
           && num > 0) {
      if (num <= 0) {
        if (GetLastError() != ERROR_BROKEN_PIPE) {
          FATAL1("kpathsea: read() error code for `%s' (Error %d)", GetLastError());
          break;
        }
      } else {
        string newfn;
        buf[num] = '\0';
        newfn = concat(fn, buf);
        free(fn);
        fn = newfn;
      }
    }
    /* End of file on pipe, child should have exited at this point. */
    CloseHandle(father_in);

    if (WaitForSingleObject(pi.hProcess, INFINITE) != WAIT_OBJECT_0) {
      WARNING2("kpathsea: failed to wait for process termination: %s (Error %d)\n",
               new_cmd, GetLastError());
    }

    CloseHandle(pi.hProcess);

    if (new_cmd) free(new_cmd);
    if (app_name) free(app_name);

    if (fn) {
      len = strlen(fn);

      /* Remove trailing newlines and returns.  */
      while (len && (fn[len - 1] == '\n' || fn[len - 1] == '\r')) {
        fn[len - 1] = '\0';
        len--;
      }

      ret = len == 0 ? NULL : kpse_readable_file (fn);
      if (!ret && len > 1) {
        WARNING1 ("kpathsea: mktexpk output `%s' instead of a filename", fn);
      }

      /* Free the name if we're not returning it.  */
      if (fn != ret)
        free (fn);
    }
  error_exit:
    ;
  }
#else
  {
    /* Standard input for the child.  Set to /dev/null */
    int childin;
    /* Standard output for the child, what we're interested in. */
    int childout[2];
    /* Standard error for the child, same as parent or /dev/null */
    int childerr;
    /* Child pid. */
    pid_t childpid;

    /* Open the channels that the child will use. */
    /* A fairly horrible uses of gotos for here for the error case. */
    if ((childin = open("/dev/null", O_RDONLY)) < 0) {
      perror("kpathsea: open(\"/dev/null\", O_RDONLY)");
      goto error_childin;
    }
    if (pipe(childout) < 0) {
      perror("kpathsea: pipe()");
      goto error_childout;
    }
    if ((childerr = open("/dev/null", O_WRONLY)) < 0) {
      perror("kpathsea: open(\"/dev/null\", O_WRONLY)");
      goto error_childerr;
    }
    if ((childpid = fork()) < 0) {
      perror("kpathsea: fork()");
      close(childerr);
     error_childerr:
      close(childout[0]);
      close(childout[1]);
     error_childout:
      close(childin);
     error_childin:
      fn = NULL;
    } else if (childpid == 0) {
      /* Child
       *
       * We can use vfork, provided we're careful about what we
       * do here: do not return from this function, do not modify
       * variables, call _exit if there is a problem.
       *
       * Complete setting up the file descriptors.
       * We use dup(2) so the order in which we do this matters.
       */
      close(childout[0]);
      /* stdin -- the child will not receive input from this */
      if (childin != 0) {
        close(0);
        dup(childin);
        close(childin);
      }
      /* stdout -- the output of the child's action */
      if (childout[1] != 1) {
        close(1);
        dup(childout[1]);
        close(childout[1]);
      }
      /* stderr -- use /dev/null if we discard errors */
      if (childerr != 2) {
        if (kpse_make_tex_discard_errors) {
          close(2);
          dup(childerr);
        }
        close(childerr);
      }
      /* FIXME: We could/should close all other file descriptors as well. */
      /* exec -- on failure a call of _exit(2) it is the only option */
      if (execvp(args[0], args))
        perror(args[0]);
      _exit(1);
    } else {
      /* Parent */
      char buf[1024+1];
      int num;
      int status;

      /* Clean up child file descriptors that we won't use anyway. */
      close(childin);
      close(childout[1]);
      close(childerr);
      /* Get stdout of child from the pipe. */
      fn = xstrdup("");
      while ((num = read(childout[0],buf,sizeof(buf)-1)) != 0) {
        if (num == -1) {
          if (errno != EINTR) {
            perror("kpathsea: read()");
            break;
          }
        } else {
          string newfn;
          buf[num] = '\0';
          newfn = concat(fn, buf);
          free(fn);
          fn = newfn;
        }
      }
      /* End of file on pipe, child should have exited at this point. */
      close(childout[0]);
      /* We don't really care about the exit status at this point. */
      wait(NULL);
    }

    if (fn) {
      len = strlen(fn);

      /* Remove trailing newlines and returns.  */
      while (len && (fn[len - 1] == '\n' || fn[len - 1] == '\r')) {
        fn[len - 1] = '\0';
        len--;
      }

      ret = len == 0 ? NULL : kpse_readable_file (fn);
      if (!ret && len > 1) {
        WARNING1 ("kpathsea: mktexpk output `%s' instead of a filename", fn);
      }

      /* Free the name if we're not returning it.  */
      if (fn != ret)
        free (fn);
    } else {
      ret = NULL;
    }
  }
#endif

  if (ret == NULL)
    misstex (format, args);
  else
    kpse_db_insert (ret);
  
  return ret;
}
int coveragescanner(int argc,char **argv)
{
#ifdef __COVERAGESCANNER__
  __coveragescanner_install(argv[0]);
#endif
#if LOG
  signal(SIGABRT,sighandler);
  signal(SIGTERM,sighandler);
  signal(SIGFPE,sighandler);
  signal(SIGILL,sighandler);
  signal(SIGINT,sighandler);
  signal(SIGSEGV,sighandler);
  signal(SIGTERM,sighandler);
#endif
#ifdef SEFLTEST
  setenv("EF_PROTECT_FREE","1",0);
  setenv("EF_FREE_WIPE","1",0);
#endif
#if 0
  if (strcmp(argv[0],"link.exe")==0)
    DebugBreak();
#endif
#if LOG
  OPEN_LOG();
  DEBUG5("TestCocoon v%i.%i.%i date:%s\n",(TESTCOCOON_VERSION>>16),(TESTCOCOON_VERSION>>8)&0xFF, TESTCOCOON_VERSION&0xFF ,__DATE__);
  std::string cmd;
  for (int i=0;i<argc;i++)
  {
    cmd+=" ";
    cmd+=System::quoteArgument(argv[i]);
  }
  DEBUG2("cmd=%s\n",cmd.c_str());
  for (int ilog=0;ilog<argc;ilog++)
  {
    DEBUG3("Argv[%i]=%s\n",ilog,argv[ilog]);
  }
#endif

  bool coveragescanner_disable_env=CompilerInterface::isCoverageScannerDisabledPerEnvironmentVariable();
  if (coveragescanner_disable_env)
  {
    DEBUG1("COVERAGESCANNER_DISABLE is set\n");
  }

  Option option(argc,argv);
  CompilerInterface::disableCoverageScannerPerEnvironmentVariable();
  if (coveragescanner_disable_env || option.isInactive())
  {
    DEBUG1("Do not instrument source file, call the native tool.\n");
    DEBUG3("call_native_tool(%s,%s)\n",option.profileToolName().c_str(),option.param_args()[0]);
    CompilerInterface  *compiler_p=CompilerFactory::create(option);
    if (compiler_p==NULL)
    {
      FATAL1("Could not find CoverageScanner profile!");
    }
    int ret = compiler_p->callNativeTool();
    TmpFile::object().deleteFiles();
    return ret;
  }
  //DebugBreak();
#if defined(LOG) || !defined(NO_DEBUG)
  fprintf(stderr,"CoverageScanner (\"%s\") is build in debug mode.\n",argv[0]);
#endif

  DEBUG1("Instrument source file, not calling the native tool.\n");
  Compiler compiler(option);


  if (!compiler.generate())
  {
    FATAL2("Error:%s\n",compiler.error());
  }
  MEMORY_REPORT;
  return (0);
}
Example #13
0
void
kpse_set_program_name P2C(const_string, argv0, const_string, progname)
{
  string ext, sdir, sdir_parent, sdir_grandparent;
  string s = getenv ("KPATHSEA_DEBUG");
#ifdef WIN32
  string debug_output = getenv("KPATHSEA_DEBUG_OUTPUT");
  string append_debug_output = getenv("KPATHSEA_DEBUG_APPEND");
  int err, olderr;
#endif
  
  /* Set debugging stuff first, in case we end up doing debuggable stuff
     during this initialization.  */
  if (s) {
    kpathsea_debug |= atoi (s);
  }

#ifndef HAVE_PROGRAM_INVOCATION_NAME
#if defined(WIN32)
  /* Set various info about user. Among many things,
     ensure that HOME is set. If debug_paths is on, 
     turn on some message if $HOME is not found. */
  if (KPSE_DEBUG_P(KPSE_DEBUG_PATHS)) {
    set_home_warning();
  }
  init_user_info();

  /* redirect stderr to debug_output. Easier to send logfiles. */
  if (debug_output) {
    int flags =  _O_CREAT | _O_TRUNC | _O_RDWR;
    err = -1;
    if (_stricmp(debug_output, "con") == 0
       || _stricmp(debug_output, "con:") == 0) {
      err = _fileno(stdout);
    } else {
      if (append_debug_output) {
        flags =  _O_CREAT | _O_APPEND | _O_WRONLY;
      } else {
        flags =  _O_CREAT | _O_TRUNC | _O_WRONLY;
        xputenv("KPATHSEA_DEBUG_APPEND", "yes");
      }
    }

    if ((err < 0)
        && (err = _open(debug_output, flags, _S_IREAD | _S_IWRITE)) == -1)
    {
      WARNING1("Can't open %s for stderr redirection!\n", debug_output);
      perror(debug_output);
    } else if ((olderr = _dup(fileno(stderr))) == -1) {
      WARNING("Can't dup() stderr!\n");
      close(err);
    } else if (_dup2(err, fileno(stderr)) == -1) {
      WARNING1("Can't redirect stderr to %s!\n", debug_output);
      close(olderr);
      close(err);
    } else {
      close(err);
    }
  }
  /* Win95 always gives the short filename for argv0, not the long one.
     There is only this way to catch it. It makes all the selfdir stuff
     useless for win32. */
  {
    char short_path[PATH_MAX], path[PATH_MAX], *fp;
      
    /* SearchPath() always gives back an absolute directory */
    if (SearchPath(NULL, argv0, ".exe", PATH_MAX, short_path, &fp) == 0)
        FATAL1("Can't determine where the executable %s is.\n", argv0);
    if (!win32_get_long_filename(short_path, path, sizeof(path))) {
        FATAL1("This path points to an invalid file : %s\n", short_path);
    }
    /* slashify the dirname */
    for (fp = path; fp && *fp; fp++)
        if (IS_DIR_SEP(*fp)) *fp = DIR_SEP;
    /* sdir will be the directory of the executable, ie: c:/TeX/bin */
    sdir = xdirname(path);
    program_invocation_name = xstrdup(xbasename(path));
  }

#elif defined(__DJGPP__)

  /* DJGPP programs support long filenames on Windows 95, but ARGV0 there
     is always made with the short 8+3 aliases of all the pathname elements.
     If long names are supported, we need to convert that to a long name.

     All we really need is to call `_truename', but most of the code
     below is required to deal with the special case of networked drives.  */
  if (pathconf (argv0, _PC_NAME_MAX) > 12) {
    char long_progname[PATH_MAX];

    if (_truename (argv0, long_progname)) {
      char *fp;

      if (long_progname[1] != ':') {
	/* A complication: `_truename' returns network-specific string at
	   the beginning of `long_progname' when the program resides on a
	   networked drive, and DOS calls cannot grok such pathnames.  We
	   need to convert the filesystem name back to a drive letter.  */
	char rootname[PATH_MAX], rootdir[4];

	if (argv0[0] && argv0[1] == ':')
	  rootdir[0] = argv0[0]; /* explicit drive in `argv0' */
	else
	  rootdir[0] = getdisk () + 'A';
	rootdir[1] = ':';
	rootdir[2] = '\\';
	rootdir[3] = '\0';
	if (_truename (rootdir, rootname)) {
	  /* Find out where `rootname' ends in `long_progname' and replace
	     it with the drive letter.  */
	  int root_len = strlen (rootname);

 	  if (IS_DIR_SEP (rootname[root_len - 1]))
            root_len--;	/* keep the trailing slash */
	  long_progname[0] = rootdir[0];
	  long_progname[1] = ':';
	  memmove (long_progname + 2, long_progname + root_len,
		   strlen (long_progname + root_len) + 1);
	}
      }

      /* Convert everything to canonical form.  */
      if (long_progname[0] >= 'A' && long_progname[0] <= 'Z')
	long_progname[0] += 'a' - 'A'; /* make drive lower case, for beauty */
      for (fp = long_progname; *fp; fp++)
	if (IS_DIR_SEP (*fp))
	  *fp = DIR_SEP;

      program_invocation_name = xstrdup (long_progname);
    }
    else
      /* If `_truename' failed, God help them, because we won't...  */
      program_invocation_name = xstrdup (argv0);
  }
  else
    program_invocation_name = xstrdup (argv0);

#else /* !WIN32 && !__DJGPP__ */

  program_invocation_name = xstrdup (argv0);

#endif
#endif /* not HAVE_PROGRAM_INVOCATION_NAME */

  /* We need to find SELFAUTOLOC *before* removing the ".exe" suffix from
     the program_name, otherwise the PATH search inside selfdir will fail,
     since `prog' doesn't exists as a file, there's `prog.exe' instead.  */
#ifndef WIN32
  sdir = selfdir (program_invocation_name);
#endif
  /* SELFAUTODIR is actually the parent of the invocation directory,
     and SELFAUTOPARENT the grandparent.  This is how teTeX did it.  */
  xputenv ("SELFAUTOLOC", sdir);
  sdir_parent = xdirname (sdir);
  xputenv ("SELFAUTODIR", sdir_parent);
  sdir_grandparent = xdirname (sdir_parent);
  xputenv ("SELFAUTOPARENT", sdir_grandparent);

  free (sdir);
  free (sdir_parent);
  free (sdir_grandparent);

#ifndef HAVE_PROGRAM_INVOCATION_NAME
  program_invocation_short_name = (string)xbasename (program_invocation_name);
#endif

  if (progname) {
    kpse_program_name = xstrdup (progname);
  } else {
    /* If configured --enable-shared and running from the build directory
       with the wrapper scripts (e.g., for make check), the binaries will
       be named foo.exe instead of foo.  Or possibly if we're running on a
       DOSISH system.  */
    ext = find_suffix (program_invocation_short_name);
    if (ext && FILESTRCASEEQ (ext, "exe")) {
      kpse_program_name = remove_suffix (program_invocation_short_name);
    } else {
      kpse_program_name = xstrdup (program_invocation_short_name);
    }
  }
  xputenv("progname", kpse_program_name);
}
Example #14
0
std::string  CompilerFactory::application_path(const std::string &exec_param)
{
  FUNCTION_TRACE;

  std::string exe_param=System::appendExecSuffix(std::string(exec_param));
  std::string  file_path;

  int slash_count=0;
  int i;
  int lg=exe_param.length();
  for (i=0;i<lg;i++)
    if (exe_param[i]==FILE_SEPARATOR_CHAR || exe_param[i]==FILE_SEPARATOR_CHAR_BIS) 
      slash_count++;

  if ( slash_count>0 )
  { /* absolute of relative path */
    file_path=exe_param; 
  }
  else 
  {
    struct stat info;
#if defined(OS_WIN32)
    if (stat(exe_param.c_str(),&info)==0)
    { /* file exists */
      file_path=exe_param; 
    }
    else
#endif
    {
      char *path = getenv( "PATH" );
      if (!path)
      {
        FATAL1("System variable PATH not defined");
      }
      int path_lg=strlen(path);
      int pos1,pos2;
      DEBUG2("getenv(PATH)=%s\n", path);
      for (pos1=0,pos2=0;pos2<path_lg;pos2++)
      {
        if ( (path[pos2]==PATH_SEPARATOR_CHAR) || (pos2==path_lg-1) )
        {
          char *p;

          p=(char*)MALLOC((pos2-pos1+1+1+lg)*sizeof(char));
          memcpy(p,&path[pos1],pos2-pos1);
          if (p[pos2-pos1-1]!=FILE_SEPARATOR_CHAR && p[pos2-pos1-1]!=FILE_SEPARATOR_CHAR_BIS)
          {
            p[pos2-pos1]=FILE_SEPARATOR_CHAR ;
            p[pos2-pos1+1]='\0';
          }
          else
            p[pos2-pos1]='\0';
          strcat(p,exe_param.c_str());
          pos1=pos2+1;
          if (stat(p,&info)==0)
          { /* file exists */
            file_path=std::string(p); 
            break;
          }
          FREE(p);
        }
      }
    }
  }

  if (file_path.empty())
    file_path=exe_param;

  char resolved_file_path[MAX_PATH];
  realPath(file_path.c_str(),resolved_file_path);

  return std::string(resolved_file_path);
}
Example #15
0
std::string CompilerFactory::findFileInPath(const std::string& name,int index)
{
  FUNCTION_TRACE;
  int found_id=0;
  const char *path_env=getenv("PATH");
  if (!path_env)
  {
    FATAL1("System variable PATH not defined");
  }
  DEBUG2("getenv(PATH)=%s\n", path_env);

  /* extract the file name */
  bool inactive=false;
  int name_lg=name.length();
  std::string filename;
  CompilerFactory::extract_tool_name(name,filename,false,inactive);

  int path_lg=strlen(path_env)+name_lg+2;
  char *path=(char*)MALLOC(path_lg);
  std::string file;

  const char *pos1=path_env;
  char sep[2];
  sep[0]=PATH_SEPARATOR_CHAR;
  sep[1]='\0';
  const char *pos2=strstr(path_env,sep );
  for (;pos2!=NULL;pos2=strstr(pos2,sep ))
  {
    /* extract the path */
    size_t plg=(size_t)(pos2)-(size_t)(pos1);
    if (plg>0)
      memcpy(path,pos1,plg);
    path[plg]='\0';

    /* calculate the filename */
    file = std::string(path);
    file+=FILE_SEPARATOR_CHAR ;
    file+=filename;
    file=System::appendExecSuffix(file);

    /* check if existing */
    struct stat info;
    bool found=false;
    if (stat(file.c_str(),&info)==0)
    {
      if (index==found_id)
      {
        FREE(path);
        DEBUG4("findFileInPath(%s,%i)->%s\n",name.c_str(),index,file.c_str());
        return file;
      }
      found_id++;
      found=true;
    }
    pos2++;
    pos1=pos2;
  }
  FREE(path);
  DEBUG3("findFileInPath(%s,%i)->not found\n",name.c_str(),index);
  return std::string();
}
Example #16
0
void
main (unsigned argc, string argv[])
{
  bzr_preamble_type preamble;
  bzr_postamble_type postamble;
  tfm_char_type *tfm_chars;
  tfm_global_info_type tfm_info;
  string tfm_name;
  unsigned this_char;
  unsigned char_count = 0;
  string font_name = read_command_line (argc, argv);
  string font_basename = basename (font_name);
  string bzr_name = concat (font_name, ".bzr");

  if (!bzr_open_input_file (bzr_name))
    FATAL1 ("%s: Could not find BZR file", font_name);

  tfm_name = find_tfm_filename (font_name);
  if (tfm_name == NULL || !tfm_open_input_file (tfm_name))
    FATAL1 ("%s: Could not find TFM file", font_name);
  
  preamble = bzr_get_preamble ();
  postamble = bzr_get_postamble ();
  
  tfm_info = tfm_get_global_info ();
  tfm_chars = tfm_get_chars ();

  if (output_name == NULL)
    output_name = strtok (xstrdup (font_basename), "0123456789");
  else 
    if (find_suffix (output_name) != NULL
	&& ((output[metafont] && output[pstype1])
	    || (output[metafont] && output[pstype3])
	    || (output[pstype1] && output[pstype3])))
     FATAL ("You can't specify all the output files' suffices to be the same");

  
  if (output[metafont])
    metafont_start_output (output_name, preamble, tfm_info);
    
  if (output[pstype1])
    pstype1_start_output (font_basename, output_name, preamble, postamble,
    			  tfm_info); 
  if (output[pstype3])
    pstype3_start_output (font_basename, output_name, preamble, postamble, 
			  tfm_info); 
  if (output[text])
    text_start_output (font_basename, preamble);
  
  for (this_char = 0; this_char <= MAX_CHARCODE; this_char++)
    {
      bzr_char_type *c = bzr_get_char (this_char);
      
      if (c != NULL)
        {
          REPORT1 ("[%u", this_char);
          
          BZR_SHAPE (*c) = oblique_splines (BZR_SHAPE (*c));
          
          if (output[metafont])
            metafont_output_char (*c);
  
          if (output[pstype1])
            pstype1_output_char (*c);

          if (output[pstype3])
            pstype3_output_char (*c);
  
          if (output[text])
            text_output_char (*c);
  
          REPORT1 ("]%c", ++char_count % 8 ? ' ' : '\n');
        }
    }
  
  if (output[metafont]) metafont_finish_output (tfm_chars);
  if (output[pstype1]) pstype1_finish_output ();
  if (output[pstype3]) pstype3_finish_output ();
  if (output[text]) text_finish_output (postamble);

  if (char_count % 8 != 0)
    REPORT ("\n");
    
  bzr_close_input_file ();
  tfm_close_input_file ();
  exit (0);
}
Example #17
0
int
main (int argc, string *argv)
{
  const_string coerce;
  unsigned coerce_len;
  int option;

#ifdef WIN32
  setmode(fileno(stdout), _O_BINARY);
#endif

  while ((option = getopt(argc, argv, "il:")) != -1) {
    switch (option) {
    case 'i':
      do_ini = true;
      break;
    case 'l':
      max_lines = atoi(optarg);
      if (max_lines <= 0)
        FATAL("[-i] [-l lines] name");
      break;
    default:
      FATAL("[-i] [-l lines] name");
      break;
    }
  }
  if (optind + 1 != argc)
    FATAL("[-i] [-l lines] name");
  output_name = argv[optind];

  sprintf (filename, "%sd.h", output_name);
  sprintf (tempfile, "%s.tmp", output_name);
  out = xfopen (filename, FOPEN_W_MODE);
  fputs ("#undef TRIP\n#undef TRAP\n", out);
  /* We have only one binary that can do both ini stuff and vir stuff.  */
  fputs ("#define STAT\n#define INI\n", out);
  
  if (STREQ (output_name, "mf")) {
    fputs ("#define INIMF\n#define MF\n", out);
    coerce = "mfcoerce.h";
  } else if (STREQ (output_name, "tex")) {
    fputs ("#define INITEX\n#define TeX\n#define onlyTeX\n", out);
    coerce = "texcoerce.h";
  } else if (STREQ (output_name, "aleph")) {
    fputs ("#define INITEX\n#define TeX\n#define Aleph\n", out);
    coerce = "alephcoerce.h";
  } else if (STREQ (output_name, "etex")) {
    fputs ("#define INITEX\n#define TeX\n#define eTeX\n", out);
    coerce = "etexcoerce.h";
  } else if (STREQ (output_name, "pdftex")) {
    fputs ("#define INITEX\n#define TeX\n#define pdfTeX\n", out);
    coerce = "pdftexcoerce.h";
  } else if (STREQ (output_name, "ptex")) {
    fputs ("#define INITEX\n#define TeX\n#define pTeX\n", out);
    coerce = "ptexcoerce.h";
  } else if (STREQ (output_name, "eptex")) {
    fputs ("#define INITEX\n#define TeX\n#define epTeX\n", out);
    coerce = "eptexcoerce.h";
  } else if (STREQ (output_name, "euptex")) {
    fputs ("#define INITEX\n#define TeX\n#define eupTeX\n", out);
    coerce = "euptexcoerce.h";
  } else if (STREQ (output_name, "uptex")) {
    fputs ("#define INITEX\n#define TeX\n#define upTeX\n", out);
    coerce = "uptexcoerce.h";
  } else if (STREQ (output_name, "xetex")) {
    fputs ("#define INITEX\n#define TeX\n#define XeTeX\n", out);
    coerce = "xetexcoerce.h";
  } else
    FATAL1 ("Can only split mf, tex, aleph, eptex, euptex, etex, pdftex, ptex, uptex, or xetex,\n not %s", output_name);
  
  coerce_len = strlen (coerce);
  
  /* Read everything up to coerce.h.  */
  while (fgets (buffer, sizeof (buffer), stdin))
    {
      if (strncmp (&buffer[10], coerce, coerce_len) == 0)
	break;

      if (buffer[0] == '#' || buffer[0] == '\n' || buffer[0] == '}'
	  || buffer[0] == '/' || buffer[0] == ' '
	  || strncmp (buffer, "typedef", 7) == 0)
	/*nothing */ ;
      else
	fputs ("EXTERN ", out);

      fputs (buffer, out);
    }

  if (strncmp (&buffer[10], coerce, coerce_len) != 0)
    FATAL1 ("No #include %s line", coerce);

  fputs (buffer, out);
  xfclose (out, filename);

  if (do_ini) {
    sprintf (ini_name, "%sini.c", output_name);
    ini = xfopen (ini_name, FOPEN_W_MODE);
    fputs ("#define EXTERN extern\n", ini);
    fprintf (ini, "#include \"%sd.h\"\n\n", output_name);
  }

  sprintf (filename, "%s0.c", output_name);
  out = xfopen (filename, FOPEN_W_MODE);
  fputs ("#define EXTERN extern\n", out);
  fprintf (out, "#include \"%sd.h\"\n\n", output_name);

  do
    {
      /* Read one routine into a temp file */
      has_ini = false;
      temp = xfopen (tempfile, "wb+");

      while (read_line ())
	{
	  fputs (buffer, temp);
	  if (buffer[0] == '}')
	    break;		/* End of procedure */
	}
      while (ifdef_nesting > 0 && read_line ())
	fputs (buffer, temp);
      rewind (temp);

      if (do_ini && has_ini)
	{			/* Contained "#ifdef INI..." */
	  while (fgets (buffer, sizeof (buffer), temp))
	    fputs (buffer, ini);
	}
      else
	{			/* Doesn't contain "#ifdef INI..." */
	  while (fgets (buffer, sizeof (buffer), temp))
	    {
	      fputs (buffer, out);
	      lines_in_file++;
	    }
	}
      xfclose (temp, tempfile);

      /* Switch to new output file.  */
      if (max_lines && lines_in_file > max_lines)
	{
	  xfclose (out, filename);
	  sprintf (filename, "%s%d.c", output_name, ++filenumber);
	  out = xfopen (filename, FOPEN_W_MODE);
	  fputs ("#define EXTERN extern\n", out);
	  fprintf (out, "#include \"%sd.h\"\n\n", output_name);
	  lines_in_file = 0;
	}
    }
  while (!feof (stdin));

  xfclose (out, filename);
  if (lines_in_file == 0)
    unlink (filename);

  if (do_ini)
    xfclose (ini, ini_name);

  if (unlink (tempfile)) {
      perror (tempfile);
      exit (EXIT_FAILURE);
  }

  return EXIT_SUCCESS;
}