summaryrefslogtreecommitdiffstats
path: root/mbbsd/lovepaper.c
blob: dffdee6937dc210122eb26ebe807bb144e5e7ebc (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* $Id: lovepaper.c,v 1.3 2002/05/13 03:20:04 ptt Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include "config.h"
#include "pttstruct.h"
#include "modes.h"
#include "common.h"
#include "proto.h"

#define DATA "etc/lovepaper.dat"

extern userec_t cuser;
extern time_t now;

int x_love() {
    char buf1[200], save_title[TTLEN + 1];
    char receiver[61], path[STRLEN] = "home/";
    int x, y = 0, tline = 0, poem = 0;
    FILE *fp, *fpo;
    struct tm *gtime;
    fileheader_t mhdr;
    
    setutmpmode(LOVE);
    gtime = localtime(&now);
    sprintf(buf1,"%c/%s/love%d%d",
        cuser.userid[0], cuser.userid,gtime->tm_sec,gtime->tm_min);
    strcat(path,buf1);
    move(1,0);
    clrtobot();
    
    outs("\n歡迎使用情書產生器 v0.00 版 \n");
    outs("有何難以啟齒的話,交由系統幫你說吧.\n爸爸說 : 濫情不犯法.\n");
    
    if(!getdata(7, 0, "收信人:", receiver, sizeof(receiver), DOECHO))
    return 0;
    if(receiver[0] && !(searchuser(receiver) &&
            getdata(8, 0, "主  題:", save_title,
                sizeof(save_title), DOECHO))) {
    move(10, 0);
    outs("收信人或主題不正確, 情書無法傳遞. ");
    pressanykey();
    return 0;
    }
    
    fpo = fopen(path, "w");
    fprintf(fpo, "\n");
    if((fp = fopen(DATA, "r"))) {
    while(fgets(buf1,100, fp)) {
        switch(buf1[0]) {
        case '#':
        break;
        case '@':
        if(!strncmp(buf1, "@begin", 6) || !strncmp(buf1, "@end", 4))
            tline=3;
        else if(!strncmp(buf1,"@poem",5)) {
            poem = 1;
            tline = 1;
            fprintf(fpo, "\n\n");
        } else
            tline=2;
        break;
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
        sscanf(buf1,"%d",&x);
        y = (rand() % (x - 1)) * tline; 
        break;
        default:
        if(!poem) {
            if(y > 0)
            y = y - 1;
            else {
            if(tline > 0) {
                fprintf(fpo, "%s", buf1);
                tline--;
            }
            }
        } else {
            if(buf1[0] == '$')
            y--;
            else if(y == 0)
            fprintf(fpo,"%s",buf1);
        }
        } 

    }
    
    fclose(fp);
    fclose(fpo);
    if(vedit(path, YEA, NULL) == -1) {
        unlink(path);
        clear();
        outs("\n\n 放棄寄情書\n");
        pressanykey();
        return -2;
    }
    sethomepath(buf1, receiver);
    stampfile(buf1, &mhdr);
    Rename(path, buf1);
    strncpy(mhdr.title, save_title, TTLEN);
    strcpy(mhdr.owner, cuser.userid);
    mhdr.savemode = '\0';
    sethomedir(path, receiver );
    if(append_record(path, &mhdr, sizeof(mhdr)) == -1)
        return -1;
    hold_mail(buf1, receiver);
    return 1;
    }
    return 0;
}