1 | /*
2 | ** $Log: delgame.c,v $
3 | ** Revision 1.5 2003/09/09 18:51:27 jaldhar
4 | ** Got rid of port.h and replaced with some extra configure checks. The
5 | ** include strings.h was not carried over because it is commented out and
6 | ** likely wouldn't work anyway.
7 | **
8 | ** Revision 1.4 2002/08/27 22:27:48 millis
9 | ** Updated for automake/autoconf functionality
10 | **
11 | ** Revision 1.3 2001/10/20 12:11:11 miller
12 | ** Merged in changes from DEMA and USTV CVS: ----------------------------------------------------------------------
13 | **
14 | ** Revision 1.2.2.1 2001/10/20 00:51:31 dedo
15 | ** Removed warnings
16 | **
17 | ** Revision 1.2 2001/07/15 09:13:16 greg
18 | ** added support for game directories in a sub directory
19 | **
20 | ** Revision 1.1 1998/02/28 17:49:42 david
21 | ** Initial revision
22 | **
23 | ** Revision 1.1 1996/10/20 12:29:45 rpaar
24 | ** Morrolan v9.0
25 | **
26 | */
27 |
28 |
29 | #include <stdio.h>
30 | #include <stdlib.h>
31 | #include <string.h>
32 | #include "config.h"
33 | #include "dip.h"
34 |
35 | int main(int argc, char *argv[])
36 | {
37 | FILE *ifd, *ofd;
38 | char line[255], name[255];
39 | int nameline, delthis, found;
40 |
41 | if (argc != 2) {
42 | printf("Usage: delgame <game>\n");
43 | exit(1);
44 | }
45 | ++argv;
46 | nameline = 0;
47 | delthis = 0;
48 | found = 0;
49 | ifd = fopen("dip.master", "r");
50 | ofd = fopen("dip.master.admin", "w");
51 | printf("Deleting game : %s\n", *argv);
52 | while (!feof(ifd)) {
53 | fscanf(ifd, "%[^\n]%*[\n]", line);
54 | strcpy(name, "\0");
55 | if (nameline) {
56 | sscanf(line, "%s", name);
57 | }
58 | if (strcmp(line, "-") == 0) {
59 | nameline = 1;
60 | }
61 | if (nameline && (strcmp(name, *argv) == 0)) {
62 | delthis = 1;
63 | found = 1;
64 | }
65 | if (strcmp(line, "-") != 0)
66 | nameline = 0;
67 | if (!delthis)
68 | fprintf(ofd, "%s\n", line);
69 | if (strcmp(line, "-") == 0) {
70 | delthis = 0;
71 | }
72 | }
73 | fclose(ifd);
74 | fclose(ofd);
75 | if (found) {
76 | rename("dip.master", "dip.master.old");
77 | rename("dip.master.admin", "dip.master");
78 | printf("Game: %s removed.\n", *argv);
79 | printf(" To make the removal complete, please type :\n");
80 | printf(" rm -rf D%s\n", *argv);
81 | printf(" (Change the directory as appropriate - \n");
82 | printf(" see dip.conf for the current setting.)\n\n");
83 | } else
84 | printf("Game: %s not found.\n", *argv);
85 |
86 | return 0;
87 | }