/* Supplimentary functions that get compiled and linked to cpp on an
   Amiga host.
   Copyright (C) 1996 Free Software Foundation, Inc.

This file is part of GNU CC.

GNU CC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU CC 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>

#if HAVE_STDLIB_H
# include <stdlib.h>
#else
char *getenv ();
#endif

#if STDC_HEADERS
# include <string.h>
#else
char *strrchr();
#endif

static int amiga_priority = -21; /* Flag indicating process priority */

/* This function returns whether the LEN characters long filename FNAME 
   is an absolute path specification. */

int
amiga_abs_filename (fname, len)
     char *fname;
     int len;
{
  /* we're using ixemul.library, which treats `/foo' as `foo:', so 
     fname[0] is to be considered absolute as well */

  if (fname[0] == '/')
    {
      return (1);
    }

  /* else do an index() on fname, but one which is limited to len characters */

  while (*fname && *fname != ':' && len) 
    {
      fname++;
      len--;
    }

  return (*fname == ':');
}

void
amiga_get_default_priority ()
{
  char *envstr;

  if (envstr = getenv ("GCCPRIORITY"))
    amiga_priority = atoi (envstr);
}

/* Set the priority to whatever is currently in the amiga_priority variable. */

void
amiga_set_priority ()
{
  if (amiga_priority != -21)
    setpriority (0, 0, -amiga_priority);
}

/* Parse the --priority option and stash the value away for future use. */

int
amiga_parse_priority (argc, argv, ip)
     int argc;
     char **argv;
     int *ip;
{
  if (strcmp (argv[*ip], "-priority") != 0)
    {
      return (0);
    }
  else
    {
      if (*ip + 1 == argc)
	{
	  fatal ("Priority missing after -P option");
	}
      (*ip)++;
      amiga_priority = atoi (argv[*ip]);
      return (1);
    }
}
