75
|
1 #include <fcntl.h>
|
|
2 #include <sys/types.h>
|
|
3 #include <sys/stat.h>
|
|
4 #include <stdio.h>
|
|
5 #include <stdlib.h>
|
|
6 #include <string.h>
|
|
7
|
|
8 void do_trans(int, int);
|
|
9
|
|
10 int main(int argc, char **argv) {
|
|
11 char *srcn;
|
|
12 char *destn;
|
|
13 int src;
|
|
14 int dest;
|
|
15 char *resp;
|
|
16
|
|
17
|
|
18 printf("Gaim - Buddy List Translator\n");
|
|
19 printf("----------------------------\n");
|
|
20
|
|
21 if (argc != 3) {
|
|
22 printf("Syntax: %s buddy.lst gaimlist\n", argv[0]);
|
|
23 exit(0);
|
|
24 }
|
|
25
|
|
26 srcn = argv[1];
|
|
27 destn = argv[2];
|
|
28
|
|
29 if ((src = open(srcn, O_RDONLY)) != -1) {
|
|
30 printf("Source=%s, Dest=%s\n", srcn, destn);
|
|
31
|
|
32 if ((dest = open(destn, O_WRONLY | O_CREAT | O_EXCL)) == -1) {
|
|
33 printf("%s exists! Should I continue? ", destn);
|
|
34 scanf("%s", resp);
|
|
35 if (strchr(resp, 'y') || strchr(resp, 'Y')) {
|
|
36 dest = open(destn, O_WRONLY | O_CREAT |
|
|
37 O_TRUNC);
|
|
38 do_trans(src, dest);
|
|
39 } else
|
|
40 exit(0);
|
|
41 } else
|
|
42 do_trans(src, dest);
|
|
43 printf("Conversion Complete.\n");
|
|
44 } else {
|
|
45 printf("Source file must exist!\n\nSyntax: %s buddy.lst gaimlist\n", argv[0]);
|
|
46 exit(0);
|
|
47 }
|
|
48 return 0;
|
|
49 }
|
|
50
|
|
51 void do_trans(int source, int destin) {
|
|
52 FILE *src;
|
|
53 FILE *dest;
|
|
54 char line[1024];
|
|
55
|
|
56 umask(644);
|
|
57 src = fdopen(source, "r");
|
|
58 dest = fdopen(destin, "w");
|
|
59
|
|
60 fprintf(dest, "toc_set_config {m 1\n");
|
|
61 while (fgets(line, sizeof line, src)) {
|
|
62 line[strlen(line) - 1] = 0;
|
|
63 if (strpbrk(line, "abcdefghijklmnopqrstuvwxyz"
|
|
64 "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
|
|
65 char *field, *name;
|
|
66 if (line[0] == ' ' || line[0] == '\t' ||
|
|
67 line[0] == '\n' || line[0] == '\r' ||
|
|
68 line[0] == '\f')
|
|
69 field = strdup(line + 1);
|
|
70 else
|
|
71 field = strdup(line);
|
|
72 name = strpbrk(field, " \t\n\r\f");
|
|
73 name[0] = 0;
|
|
74 name += 2;
|
|
75 name[strlen(name) - 1] = 0;
|
|
76 printf("%s, %s\n", field, name);
|
|
77 if (!strcmp("group", field)) {
|
|
78 fprintf(dest, "g %s\n", name);
|
|
79 } else if (!strcmp("buddy", field)) {
|
|
80 fprintf(dest, "b %s\n", name);
|
|
81 }
|
82
|
82 free(field);
|
75
|
83 }
|
|
84 }
|
|
85 fprintf(dest, "}");
|
|
86 fclose(src);
|
|
87 fclose(dest);
|
|
88 }
|