1 /* Copyright (C) 1998 by Marc Olzheim
2  *
3  * alias expp "runfeed /usr/local/lib/eif/ex ${1} ${2} ${3}"
4  */
5 
6 #include	"../config.h"
7 
8 #include	<stdio.h>
9 #include	<stdlib.h>
10 #ifdef	HAVE_STRING_H
11 #include	<string.h>
12 #endif	/* HAVE_STRING_H */
13 #ifdef	HAVE_STRINGS_H
14 #include	<strings.h>
15 #endif	/* HAVE_STRINGS_H */
16 
17 char		*prog_name;
18 
usage(void)19 static void usage(void)
20 {
21 		fprintf(stderr, "Usage: %s <from> <base_path> <expl_path>\n",
22 			prog_name);
23 		fprintf(stderr, "where: from      - the sector to explore from\n");
24 		fprintf(stderr, "       base_path - the path to move by before exploring\n");
25 		fprintf(stderr, "       expl_path - the path to explore\n");
26 		exit(1);
27 }
28 
chng_loc(int * x,int * y,char c)29 static void	chng_loc(int *x, int *y, char c)
30 {
31 	switch(c)
32 	{
33 	case 'b':
34 		(*x)--; (*y)++;
35 		break;
36 	case 'g':
37 		(*x) -= 2;
38 		break;
39 	case 'y':
40 		(*x)--; (*y)--;
41 		break;
42 	case 'u':
43 		(*x)++; (*y)--;
44 		break;
45 	case 'j':
46 		(*x) += 2;
47 		break;
48 	case 'n':
49 		(*x)++; (*y)++;
50 		break;
51 	default:
52 		fprintf(stderr, "Illegal path character `%c'\n", c);
53 		usage();
54 	}
55 }
56 
57 int
main(int argc,char * const argv[])58 main(int argc, char * const argv[])
59 {
60 	int		x_base, y_base, x, y;
61 	char		*base, *explore, *temp, *walk;
62 	unsigned int	i, len, max;
63 
64 	prog_name = argv[0];
65 
66 	if (argc != 4)
67 		usage();
68 
69 	base = strdup(argv[2]);
70 	if (!base)
71 	{
72 		perror("Not enough mem (base)");
73 		return(1);
74 	}
75 	len = strlen(base);
76 	while (base[len - 1] == 'h')
77 		base[--len] = 0;
78 
79 	explore = strdup(argv[3]);
80 	if (!explore)
81 	{
82 		perror("Not enough mem (explore)");
83 		return(1);
84 	}
85 	len = strlen(explore);
86 	while (explore[len - 1] == 'h')
87 		explore[--len] = 0;
88 
89 	temp = strdup(argv[1]);
90 	if (!temp)
91 	{
92 		perror("Not enough mem (temp)");
93 		return(1);
94 	}
95 	walk = temp;
96 	while (*walk && *walk != ',')
97 		walk++;
98 	if (*walk)
99 		*walk++ = 0;
100 
101 	x_base = atoi(temp);
102 	y_base = atoi(walk);
103 	if ((!x_base && (*temp != '0')) || (!y_base && (*walk != '0')))
104 	{
105 		fprintf(stderr, "Illegal 'from'\n");
106 		usage();
107 	}
108 
109 	walk = base;
110 	while (*walk)
111 		chng_loc(&x_base, &y_base, *walk++);
112 
113 	x = x_base; y = y_base;
114 	for (max = 1; max <= len; max++)
115 	{
116 		printf("explore civ %s 1 %s", argv[1], base);
117 		for (i = 0; i < max; i++)
118 			(void) putchar(explore[i]);
119 
120 		chng_loc(&x, &y, explore[i - 1]);
121 
122 		printf("h\ndesignate %d,%d +\n", x, y);
123 	}
124 
125 	return(0);
126 }
127 
128 /* vim:ts=8:ai:syntax=c
129  */
130