Mercurial > libpst
annotate nick2ldif.cpp @ 10:a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
author | carl |
---|---|
date | Fri, 17 Feb 2006 15:48:38 -0800 |
parents | 8dd68d722fa8 |
children |
rev | line source |
---|---|
2 | 1 /* |
2 | |
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under | |
4 the GPL version 2 or any later version at your choice available at | |
5 http://www.fsf.org/licenses/gpl.txt | |
6 | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 #include <iostream> | |
11 //#include <fstream> | |
12 #include <unistd.h> | |
13 | |
14 char *ldap_base = NULL; | |
10
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
15 char *ldap_org = NULL; |
2 | 16 char *ldap_class = NULL; |
17 | |
18 using namespace std; | |
19 | |
20 int main(int argc, char** argv) { | |
10
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
21 char c; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
22 char *temp; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
23 while ((c = getopt(argc, argv, "b:c:"))!= -1) { |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
24 switch (c) { |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
25 case 'b': |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
26 ldap_base = optarg; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
27 temp = strchr(ldap_base, ','); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
28 if (temp) { |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
29 *temp = '\0'; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
30 ldap_org = strdup(ldap_base); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
31 *temp = ','; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
32 } |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
33 break; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
34 case 'c': |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
35 ldap_class = optarg; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
36 break; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
37 default: |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
38 break; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
39 } |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
40 } |
2 | 41 |
10
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
42 const int LINE_SIZE = 2000; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
43 char line[LINE_SIZE]; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
44 while (!cin.eof()) { |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
45 cin.getline(line, LINE_SIZE); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
46 int n = strlen(line); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
47 if (!n) continue; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
48 char *f = line + 6; // skip alias keyword |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
49 char *e; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
50 if (*f == '"') { |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
51 f++; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
52 e = strchr(f, '"'); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
53 } |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
54 else { |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
55 e = strchr(f, ' '); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
56 } |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
57 if (!e) continue; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
58 *e = '\0'; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
59 char *m = e+1; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
60 while (*m == ' ') m++; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
61 if (*m != '\0') { |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
62 char cn[1000]; |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
63 snprintf(cn, sizeof(cn), "email %s", f); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
64 printf("dn: cn=%s, %s\n", cn, ldap_base); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
65 printf("cn: %s\n", cn); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
66 printf("sn: %s\n", f); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
67 printf("mail: %s\n", m); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
68 printf("objectClass: %s\n\n", ldap_class); |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
69 } |
a818f3c2e589
fix tree walk, we now use the item counts in the node blocks
carl
parents:
2
diff
changeset
|
70 } |
2 | 71 } |