1 /* Copyright (C) 1999 by Marc Olzheim
2 *
3 * alias room "dump ${5} ${6:-?des#.} >!tmp/tmp_dump ; runfeed /usr/local/lib/eif/mov ${1} ${2} ${3} ${4}"
4 */
5
6 #include "config.h"
7
8 #include <ctype.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #ifdef HAVE_STRING_H
12 #include <string.h>
13 #endif /* HAVE_STRING_H */
14 #ifdef HAVE_STRINGS_H
15 #include <strings.h>
16 #endif /* HAVE_STRINGS_H */
17
18 int
main(int argc,char * const argv[])19 main(int argc, char * const argv[])
20 {
21 char *walk0, *walk1, *sect_x = NULL, *sect_y = NULL;
22 char buffer[4096], bufje[32];
23 FILE *fp;
24 int column, number, diff, i, max;
25
26 if (argc != 5 || ((number = atoi(argv[3])) < 0) ||
27 ((max = atoi(argv[4])) < 0))
28 {
29 fprintf(stderr, "Usage: %s <commodity> <to_sector> <thresh_from> <max_mov>\n", argv[0]);
30 fprintf(stderr, "where: commodity - the commodity to be moved\n");
31 fprintf(stderr, " to_sector - the sector to be moved to\n");
32 fprintf(stderr, " thresh_from - the per sector threshold\n");
33 fprintf(stderr, " max_mov - the per sector maximum to be moved out\n");
34 return(1);
35 }
36
37 if (!(fp = fopen("tmp/tmp_dump", "r")))
38 {
39 perror("tmp/tmp_dump");
40 exit(1);
41 }
42
43 (void) fgets(buffer, sizeof(buffer), fp);
44 (void) fgets(buffer, sizeof(buffer), fp);
45 (void) fgets(buffer, sizeof(buffer), fp);
46 buffer[0] = 0;
47 (void) fgets(buffer, sizeof(buffer), fp);
48 if (!strlen(buffer))
49 {
50 perror("tmp/tmp_dump");
51 exit(1);
52 }
53
54 column = 0;
55 walk0 = walk1 = buffer;
56 while (*walk0)
57 {
58 column++;
59
60 while (*walk1 && !isspace(*walk1))
61 walk1++;
62 if (*walk1)
63 *walk1++ = 0;
64
65 if (!strcmp(walk0, argv[1]))
66 break;
67
68 walk0 = walk1;
69 }
70 if (!*walk0)
71 {
72 fprintf(stderr, "Unknown commodity `%s'\n", argv[1]);
73 exit(0);
74 }
75
76 column--;
77
78 while (fgets(buffer, sizeof(buffer), fp))
79 {
80 walk1 = walk0 = buffer;
81 for (i = 0; i < column; i++)
82 {
83 while (*walk1 && !isspace(*walk1))
84 walk1++;
85 if (*walk1)
86 *walk1++ = 0;
87 if (i == 0)
88 sect_x = walk0;
89 else if (i == 1)
90 sect_y = walk0;
91
92 walk0 = walk1;
93 }
94 if (i < 3)
95 break;
96 while (*walk1 && !isspace(*walk1))
97 walk1++;
98 if (*walk1)
99 *walk1 = 0;
100
101 sprintf(bufje, "%s,%s", sect_x, sect_y);
102
103 /* If over threshold and not to_sector, move */
104 if (((diff = atoi(walk0) - number) > 0) &&
105 strcmp(bufje, argv[2]))
106 printf("move %s %s,%s %d %s\n",
107 argv[1], sect_x, sect_y,
108 (!max || (diff <= max)) ? diff : max,
109 argv[2]);
110 }
111
112 fclose(fp);
113
114 return(0);
115 }
116
117 /* vim:ts=8:ai:syntax=c
118 */
119