-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetboard.c
68 lines (56 loc) · 1.57 KB
/
setboard.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*-------------------------------------------------------*/
/* util/setboard.c ( NTHU CS MapleBBS Ver 2.36 ) */
/*-------------------------------------------------------*/
/* target : ³]©w¬ÝªO§ë²¼ÄÝ©Ê */
/* create : 95/03/29 */
/* update : 95/12/15 */
/*-------------------------------------------------------*/
/* usage : setboard VoteLfag[012] board1 [board2...] */
/*-------------------------------------------------------*/
#include <stdio.h>
#include "bbs.h"
#define DOTPASSWDS BBSHOME"/.BOARDS"
#define PASSWDSBAK BBSHOME"/BOARDS"
#define TMPFILE BBSHOME"/tmpfile"
boardheader board;
main(argc, argv)
int argc;
char **argv;
{
FILE *foo1, *foo2;
int cnum, i, match;
int VF;
if (argc < 3 || !(*argv[1] == '0' || *argv[1] == '1' || *argv[1] == '2'))
{
puts("Usage: setboard VoteFlag[012] board1 [board2...]");
exit(1);
}
if (((foo1 = fopen(DOTPASSWDS, "r")) == NULL)
|| ((foo2 = fopen(TMPFILE, "w")) == NULL))
{
puts("file opening error");
exit(1);
}
while ((cnum = fread(&board, sizeof(board), 1, foo1)) > 0)
{
for (match = 0, i = 2; i < argc; i++)
if (!strcmp(board.brdname, argv[i]))
{
match = 1;
break;
}
if (match)
board.bvote = *argv[1] - '0';
fwrite (&board, sizeof(board), 1, foo2);
}
fclose(foo1);
fclose(foo2);
if (f_mv(DOTPASSWDS, PASSWDSBAK) == -1)
{
puts("replace fails");
exit(1);
}
unlink(DOTPASSWDS);
f_mv(TMPFILE, DOTPASSWDS);
exit(0);
}