-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite.c
83 lines (67 loc) · 1.6 KB
/
write.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <time.h>
#include <assert.h>
#include "ii-functions.c"
char template[100];
char full_msgfile[200];
char msgfile[40];
char subj2[250];
char* frmSubj(char* subj) {
if (strncmp("Re: ", subj, 4)==0) {
return subj;
} else {
strcat(subj2, "Re: ");
strcat(subj2, subj);
return &subj2[0];
}
}
void edit (char* text) {
time_t rawtime;
struct tm * mytime;
time(&rawtime);
mytime=localtime(&rawtime);
strcat(full_msgfile, tossesdir);
strftime(msgfile, 60, "%G%m%d%H%M%S.toss", mytime);
strcat(full_msgfile, msgfile);
FILE *f=fopen(full_msgfile, "w");
if (!f) {
printf("Не могу открыть файл %s для записи\n", full_msgfile);
exit(1);
}
fputs(text, f);
fclose(f);
execl("/usr/bin/vim", "vim", full_msgfile, (char*)0);
}
void writeNew (char* echoarea) {
strcat(template, echoarea);
strcat(template, "\nAll\n...\n\n");
edit(&template[0]);
}
void answer (char* msgid) {
struct message msg=parseMessage(getRawMsg(msgid));
strcat(template, msg.echoarea);
strcat(template, "\n");
strcat(template, msg.msgfrom);
strcat(template, "\n");
strcat(template, frmSubj(msg.subj));
strcat(template, "\n\n@repto:");
strcat(template, msgid);
strcat(template, "\n");
edit(template);
}
int main (int argc, char** argv) {
if (argc==1) {
printf("Usage: write <echoarea> <msg number>\n");
return 1;
}
ii_base_init();
char* echoarea=argv[1];
if (argc==2) {
writeNew(echoarea);
} else {
int number=0;
struct list msgids=getLocalEcho(echoarea);
sscanf(argv[2], "%d", &number);
assert(number>=0 && number<=((msgids.length)-1));
answer(msgids.index[number]);
}
}