4
|
1 /*--------------------------------------------------------------------------
|
|
2 NETREK II -- Paradise
|
|
3
|
|
4 Permission to use, copy, modify, and distribute this software and its
|
|
5 documentation, or any derivative works thereof, for any NON-COMMERCIAL
|
|
6 purpose and without fee is hereby granted, provided that this copyright
|
|
7 notice appear in all copies. No representations are made about the
|
|
8 suitability of this software for any purpose. This software is provided
|
|
9 "as is" without express or implied warranty.
|
|
10
|
|
11 Xtrek Copyright 1986 Chris Guthrie
|
|
12 Netrek (Xtrek II) Copyright 1989 Kevin P. Smith
|
|
13 Scott Silvey
|
|
14 Paradise II (Netrek II) Copyright 1993 Larry Denys
|
|
15 Kurt Olsen
|
|
16 Brandon Gillespie
|
|
17 --------------------------------------------------------------------------*/
|
|
18
|
|
19 #include "config.h"
|
|
20 #include <stdio.h>
|
|
21 #include <string.h>
|
|
22 #include <stdlib.h>
|
|
23
|
|
24 /*
|
|
25 * This is the default path, you don't have to change this as long as you set
|
|
26 * the NETREKDIR env
|
|
27 */
|
|
28 char netrekpath[256] = "/local/lib/paradise";
|
|
29
|
|
30
|
|
31 static char buf[512];
|
|
32 static int initted = 0;
|
|
33
|
|
34 char *
|
|
35 build_path(suffix)
|
|
36 char *suffix;
|
|
37 {
|
|
38 int len;
|
|
39 if (!initted)
|
|
40 {
|
|
41 char *ptr;
|
|
42 initted = 1;
|
|
43 ptr = (char *) getenv("NETREKDIR");
|
|
44 if (ptr == NULL)
|
|
45 {
|
|
46 fprintf(stderr, "Warning, no NETREKDIR envariable. Using default of %s\n", netrekpath);
|
|
47 }
|
|
48 else
|
|
49 {
|
|
50 strncpy(netrekpath, ptr, 255);
|
|
51 netrekpath[255] = '\0';
|
|
52 }
|
|
53 len = strlen(netrekpath);
|
|
54 if (len > 230)
|
|
55 {
|
|
56 fprintf(stderr, "NETREKDIR enviroment variable too long.\n");
|
|
57 fprintf(stderr, "Please change it.\n");
|
|
58 exit(1);
|
|
59 }
|
|
60 if (netrekpath[len - 1] != '/')
|
|
61 {
|
|
62 netrekpath[len] = '/';
|
|
63 netrekpath[len + 1] = '\0';
|
|
64 }
|
|
65 }
|
|
66 if (*suffix == '/')
|
|
67 { /* absolute path... don't prepend anything */
|
|
68 strcpy(buf, suffix);
|
|
69 }
|
|
70 else
|
|
71 {
|
|
72 strcpy(buf, netrekpath);
|
|
73 strcat(buf, suffix);
|
|
74 }
|
|
75
|
|
76 return buf;
|
|
77 }
|