annotate buddytrans.c @ 458:4f09ffbd2a78

[gaim-migrate @ 468] A true genius never sleeps. committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Sat, 01 Jul 2000 09:04:33 +0000
parents 05077cb276d4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
75
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 #include <fcntl.h>
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 #include <sys/types.h>
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 #include <sys/stat.h>
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 #include <stdio.h>
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 #include <stdlib.h>
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 #include <string.h>
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 void do_trans(int, int);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 int main(int argc, char **argv) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 char *srcn;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 char *destn;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 int src;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 int dest;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 char *resp;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 printf("Gaim - Buddy List Translator\n");
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 printf("----------------------------\n");
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21 if (argc != 3) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 printf("Syntax: %s buddy.lst gaimlist\n", argv[0]);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23 exit(0);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 }
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26 srcn = argv[1];
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 destn = argv[2];
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 if ((src = open(srcn, O_RDONLY)) != -1) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30 printf("Source=%s, Dest=%s\n", srcn, destn);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 if ((dest = open(destn, O_WRONLY | O_CREAT | O_EXCL)) == -1) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33 printf("%s exists! Should I continue? ", destn);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 scanf("%s", resp);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 if (strchr(resp, 'y') || strchr(resp, 'Y')) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36 dest = open(destn, O_WRONLY | O_CREAT |
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
37 O_TRUNC);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
38 do_trans(src, dest);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
39 } else
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
40 exit(0);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
41 } else
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
42 do_trans(src, dest);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
43 printf("Conversion Complete.\n");
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
44 } else {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
45 printf("Source file must exist!\n\nSyntax: %s buddy.lst gaimlist\n", argv[0]);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
46 exit(0);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 }
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 return 0;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 }
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 void do_trans(int source, int destin) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52 FILE *src;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 FILE *dest;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 char line[1024];
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 umask(644);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 src = fdopen(source, "r");
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 dest = fdopen(destin, "w");
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 fprintf(dest, "toc_set_config {m 1\n");
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 while (fgets(line, sizeof line, src)) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 line[strlen(line) - 1] = 0;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 if (strpbrk(line, "abcdefghijklmnopqrstuvwxyz"
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64 "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 char *field, *name;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66 if (line[0] == ' ' || line[0] == '\t' ||
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 line[0] == '\n' || line[0] == '\r' ||
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68 line[0] == '\f')
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 field = strdup(line + 1);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 else
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 field = strdup(line);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 name = strpbrk(field, " \t\n\r\f");
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 name[0] = 0;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 name += 2;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 name[strlen(name) - 1] = 0;
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 printf("%s, %s\n", field, name);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 if (!strcmp("group", field)) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 fprintf(dest, "g %s\n", name);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79 } else if (!strcmp("buddy", field)) {
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 fprintf(dest, "b %s\n", name);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 }
82
05077cb276d4 [gaim-migrate @ 92]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 75
diff changeset
82 free(field);
75
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 }
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 }
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 fprintf(dest, "}");
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 fclose(src);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87 fclose(dest);
6419cd5286ae [gaim-migrate @ 85]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 }