comparison src/pst2ldif.cpp @ 128:7f747c8c9d02

cleanup installed headers
author Carl Byington <carl@five-ten-sg.com>
date Thu, 05 Feb 2009 09:22:22 -0800
parents bdb38b434c0a
children fc11b1d1ad34
comparison
equal deleted inserted replaced
127:c2482d0cd84e 128:7f747c8c9d02
102 static const char* unique_string(const char *name) { 102 static const char* unique_string(const char *name) {
103 int unique = 2; 103 int unique = 2;
104 string_set::iterator i = all_strings.find(name); 104 string_set::iterator i = all_strings.find(name);
105 if (i == all_strings.end()) return register_string(name); 105 if (i == all_strings.end()) return register_string(name);
106 while (true) { 106 while (true) {
107 char n[strlen(name)+10]; 107 vector<char> n(strlen(name)+10);
108 snprintf(n, sizeof(n), "%s %d", name, unique++); 108 snprintf(&n[0], n.size(), "%s %d", name, unique++);
109 string_set::iterator i = all_strings.find(n); 109 string_set::iterator i = all_strings.find(&n[0]);
110 if (i == all_strings.end()) return register_string(n); 110 if (i == all_strings.end()) return register_string(&n[0]);
111 } 111 }
112 } 112 }
113 113
114 114
115 static void process(pst_desc_ll *d_ptr); 115 static void process(pst_desc_ll *d_ptr);
325 bool space_flag = false; 325 bool space_flag = false;
326 326
327 // Strip leading spaces 327 // Strip leading spaces
328 while (*value == ' ') value++; 328 while (*value == ' ') value++;
329 len = strlen(value) + 1; 329 len = strlen(value) + 1;
330 char buffer[len]; 330 vector<char> buffer(len);
331 char *p = buffer; 331 char *p = &buffer[0];
332 332
333 // See if "value" is a "SAFE STRING" 333 // See if "value" is a "SAFE STRING"
334 // First check characters that are safe but not safe as initial characters 334 // First check characters that are safe but not safe as initial characters
335 if (*value == ':' || *value == '<') 335 if (*value == ':' || *value == '<')
336 is_safe_string = false; 336 is_safe_string = false;
357 *p++ = ch; 357 *p++ = ch;
358 } 358 }
359 } 359 }
360 *p = 0; 360 *p = 0;
361 if (is_safe_string) { 361 if (is_safe_string) {
362 printf("%s: %s\n", attr, buffer); 362 printf("%s: %s\n", attr, &buffer[0]);
363 return; 363 return;
364 } 364 }
365 365
366 if (needs_code_conversion && cd != 0) { 366 if (needs_code_conversion && cd != 0) {
367 size_t inlen = p - buffer; 367 size_t inlen = p - &buffer[0];
368 size_t utf8_len = 2 * inlen + 1; 368 size_t utf8_len = 2 * inlen + 1;
369 char utf8_buffer[utf8_len]; 369 vector<char> utf8_buffer(utf8_len);
370 char *utf8_p = utf8_buffer; 370 char *utf8_p = &utf8_buffer[0];
371 371
372 iconv(cd, NULL, NULL, NULL, NULL); 372 iconv(cd, NULL, NULL, NULL, NULL);
373 p = buffer; 373 p = &buffer[0];
374 int ret = iconv(cd, (ICONV_CONST char**)&p, &inlen, &utf8_p, &utf8_len); 374 int ret = iconv(cd, (ICONV_CONST char**)&p, &inlen, &utf8_p, &utf8_len);
375 375
376 if (ret >= 0) { 376 if (ret >= 0) {
377 *utf8_p = 0; 377 *utf8_p = 0;
378 p = base64_encode(utf8_buffer, utf8_p - utf8_buffer); 378 p = base64_encode(&utf8_buffer[0], utf8_p - &utf8_buffer[0]);
379 } 379 }
380 else 380 else
381 p = base64_encode(buffer, strlen(buffer)); 381 p = base64_encode(&buffer[0], buffer.size());
382 } 382 }
383 else 383 else
384 p = base64_encode(buffer, strlen(buffer)); 384 p = base64_encode(&buffer[0], buffer.size());
385 printf("%s:: %s\n", attr, p); 385 printf("%s:: %s\n", attr, p);
386 free(p); 386 free(p);
387 } 387 }
388 388
389 389
484 else { 484 else {
485 print_ldif_single(attr, value1); 485 print_ldif_single(attr, value1);
486 return; 486 return;
487 } 487 }
488 488
489 char value[len1 + len2 + 2]; 489 vector<char> value(len1 + len2 + 2);
490 memcpy(value, value1, len1); 490 memcpy(&value[0], value1, len1);
491 value[len1] = ' '; 491 value[len1] = ' ';
492 memcpy(value + len1 + 1, value2, len2 + 1); 492 memcpy(&value[0] + len1 + 1, value2, len2 + 1);
493 print_ldif_single(attr, value); 493 print_ldif_single(attr, &value[0]);
494 } 494 }
495 495
496 496
497 void build_cn(char *cn, size_t len, int nvalues, char *value, ...) 497 void build_cn(char *cn, size_t len, int nvalues, char *value, ...)
498 { 498 {