/* $Id: progname 3.2.0.3 1998/07/26 10:52:00 stoklund Exp stoklund $ */
/* progname.c: the executable name we were invoked as; general initialization.

   Copyright (C) 1994, 96, 97 Karl Berry.
   Copyright (C) 1998 Jakob Stoklund Olesen.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with this library; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */

#include "kpathsea:config.h"
#include "kpathsea:c-pathch.h"
/* For kpse_reset_progname */
#include "kpathsea:tex-file.h"
#include "kpathsea:envnames.h"
#include "kpathsea:riscos.h"

/* Some really serious cleaning-out for RISC OS */

#ifndef HAVE_PROGRAM_INVOCATION_NAME
/* Don't redefine the variables if glibc already has.  */
string program_invocation_name = NULL;
string program_invocation_short_name = NULL;
#endif
/* And the variable for the program we pretend to be. */
string kpse_program_name = NULL;

void
kpse_set_program_name (const_string argv0, const_string progname)
{
  string s = getenv (ENV_KPATHSEA_DEBUG);

  /* 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
  program_invocation_name = riscos_canonicalise (argv0, getenv ("Run$Path"));
  /* We can't use basename(), it would give two directories */
  s = strrchr (program_invocation_name, DIR_SEP);
  program_invocation_short_name = s ? s + 1 : program_invocation_name;
#endif

  if (progname)
    kpse_program_name = xstrdup (progname);
  else
    kpse_program_name = xstrdup (program_invocation_short_name);
}

/* This function is deprecated, because when we pretend to have a different
   name it will look for _that_ name in the PATH if program_invocation_name
   is not defined.  */
void
kpse_set_progname (const_string argv0)
{
  kpse_set_program_name (argv0, NULL);
}
