summaryrefslogtreecommitdiff
path: root/fonts/utilities/mff-29/searchpath.c
blob: b9939d14236da3e03021cddcc828ef366b7b67cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* searchpath.c 2.9.0 92/07/06 - wrapper around library thingie
 *  - Damian Cugley <pdc@oxford.prg> Thu 15 Feb 1990
 */

#include <sys/param.h>		/* for MAXPATHLEN */
#include "xstdio.h"		/* <stdio.h> plus prototypes */
#include "searchpath.h"
#include "stdc.h"

#ifndef MAXPATHLEN
#  define MAXPATHLEN 1024
#endif

void NONRETURNING exit ARGS((int));

int
main (ac, av)
     int	ac;
     char     **av;
{
  char scratch[MAXPATHLEN];

  if (ac < 3)
    {
      fprintf(stderr, "%s: Not enough arguments\n\
Usage: %s FILENAME PATH [ SUFFIX ]\n",
	      av[0], av[0]);
      if (ac == 2)
	puts(av[1]);		/* The best we can do */
      exit(2);
    }

  if (!findfile(scratch, av[1], av[2], (ac > 3 ? av[3] : (char *)NULL)))
    {
      if (ac > 3)
	fprintf(stderr, "%s: Couldn't find \"%s\" or \"%s%s\" in path\n\
\t\"%s\"\n",
		av[0], av[1], av[1], av[3], av[2]);
      else
	fprintf(stderr, "%s: Couldn't find \"%s\" in path\n\
\t\"%s\"\n",
		av[0], av[1], av[2]);
      puts(av[1]);
      exit(1);
    }

  puts(scratch);
  return(0);
}