summaryrefslogtreecommitdiffstats
path: root/pttbbs/upgrade/r4848_watermode.c
blob: b0310e1abdf6ba8508fbde2ae4d889b95caadd64 (plain) (blame)
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
#define _UTIL_C_
#include "bbs.h"
#include <time.h>

int transform(userec_t *new, userec_t *old, int i)
{
    userec_t *u = new;

    memcpy(new, old, sizeof(userec_t));

    if (!u->userid[0])
    return 0;

    u->pager_ui_type = (u->uflag2 & 3) % PAGER_UI_TYPES;

    printf("%-13s: wateremode: %d -> %d\n", 
        u->userid, u->uflag2 & 3, u->pager_ui_type);

    // force convert!
    // passwd_update(n+1, u);

    return 0;
}

int main(void)
{
    int fd, fdw;
    userec_t new;
    userec_t old;
    int i = 0;

    printf("sizeof(userec_t)=%u\n", (unsigned int)sizeof(userec_t));
    printf("You're going to convert your .PASSWDS\n");
    printf("The new file will be named .PASSWDS.trans.tmp\n");

    if (chdir(BBSHOME) < 0) {
    perror("chdir");
    exit(-1);
    }

    if ((fd = open(FN_PASSWD, O_RDONLY)) < 0 ||
     (fdw = open(FN_PASSWD".trans.tmp", O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0 ) {
    perror("open");
    exit(-1);
    }

    while (read(fd, &old, sizeof(old)) > 0) {
    transform(&new, &old, ++i);
    write(fdw, &new, sizeof(new));
    }

    close(fd);
    close(fdw);

    // printf("total %d records converted.\n", accs);
    return 0;
}