makstrdb.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <stdlib.h>
  15. #include "netsite.h"
  16. #ifdef BERKELEY_DB_RESOURCE
  17. #include "mcom_db.h"
  18. #include "nsres.h"
  19. #endif
  20. #define RESOURCE_STR
  21. /********************************************/
  22. /* Begin: Application dependent information */
  23. /********************************************/
  24. #include "gsslapd.h"
  25. #define GSXXX_H_INCLUDED
  26. #ifdef buildAnotherServer
  27. #include "gsanother.h"
  28. #define GSXXX_H_INCLUDED
  29. #endif
  30. /********************************************/
  31. /* End: Application dependent information */
  32. /********************************************/
  33. /**********************************************/
  34. /* Begin: Check that BUILD_MODULE is handled */
  35. /* and a gs*.h file has been included */
  36. /**********************************************/
  37. #ifndef GSXXX_H_INCLUDED
  38. #error Error in makstrdb.c: BUILD_MODULE not handled; gs*.h not included.
  39. #endif
  40. /********************************************/
  41. /* End: Check that BUILD_MODULE is handled */
  42. /* and a gs*.h file has been included */
  43. /********************************************/
  44. /*******************************************************************************/
  45. #ifdef XP_DEBUG
  46. void
  47. XP_PrintStringDatabase(void) /* debug routine */
  48. {
  49. int i;
  50. int j;
  51. char* LibraryName;
  52. RESOURCE_TABLE* table;
  53. j = 0;
  54. while (table=allxpstr[j++].restable) {
  55. LibraryName = table->str;
  56. printf("Library %d: %s\n",j,LibraryName);
  57. i = 1;
  58. table++;
  59. while (table->str) {
  60. printf("%d: %s %d \"%s\"\n",i,LibraryName,table->id,table->str);
  61. i++;
  62. table++;
  63. }
  64. }
  65. }
  66. #endif /* XP_DEBUG */
  67. #ifdef BERKELEY_DB_RESOURCE
  68. /*******************************************************************************/
  69. int
  70. XP_MakeStringDatabase(void)
  71. {
  72. int j;
  73. char* LibraryName;
  74. char* cptr;
  75. RESOURCE_TABLE* table;
  76. NSRESHANDLE hresdb;
  77. /* Creating database */
  78. hresdb = NSResCreateTable(DATABASE_NAME, NULL);
  79. if (hresdb==0) {
  80. printf("Error creating database %s\n",DATABASE_NAME);
  81. return 1;
  82. }
  83. j = 0;
  84. while (table=allxpstr[j++].restable) {
  85. LibraryName = table->str;
  86. printf("Add Library %d: %s\n",j,LibraryName);
  87. table++;
  88. while (table->str) {
  89. if (table->id==-1 && strstr(table->str,"$DBT: ")) {
  90. cptr = strstr(table->str,"referenced");
  91. if (cptr) {
  92. strncpy(cptr,"in DB file",10);
  93. }
  94. }
  95. NSResAddString(hresdb,LibraryName,table->id,table->str,0);
  96. table++;
  97. }
  98. }
  99. NSResCloseTable(hresdb);
  100. return 0;
  101. }
  102. #endif
  103. /*******************************************************************************/
  104. int
  105. XP_MakeStringProperties(void)
  106. {
  107. int j;
  108. char* LibraryName;
  109. RESOURCE_TABLE* table;
  110. FILE *hresfile = NULL;
  111. char buffer[2000];
  112. char *src, *dest;
  113. char *dbfile = NULL;
  114. int rc = 0;
  115. /* Creating database */
  116. dbfile = (char *) malloc (strlen(DATABASE_NAME) + 20);
  117. if (dbfile==NULL) {
  118. printf("Out of memory\n");
  119. rc = 1;
  120. goto done;
  121. }
  122. strcpy(dbfile, DATABASE_NAME);
  123. strcat(dbfile, ".properties");
  124. hresfile = fopen(dbfile, "w");
  125. if (hresfile==NULL) {
  126. printf("Error creating properties file %s\n",DATABASE_NAME);
  127. rc = 1;
  128. goto done;
  129. }
  130. j = 0;
  131. while ((table=allxpstr[j++].restable)) {
  132. LibraryName = table->str;
  133. fprintf(hresfile, "\n");
  134. fprintf(hresfile, "#######################################\n");
  135. fprintf(hresfile, "############### %s ###############\n", LibraryName);
  136. printf("Add Library %d: %s\n",j,LibraryName);
  137. table++;
  138. while (table->str) {
  139. /*
  140. Change special char to \uXXXX
  141. */
  142. src = table->str;
  143. dest = buffer;
  144. while (*src && (sizeof(buffer) > (dest-buffer))) {
  145. if (*src < 0x20) {
  146. strcpy(dest,"\\u00");
  147. dest += 4;
  148. sprintf(dest, "%02x", *src);
  149. dest += 1;
  150. }
  151. else {
  152. *dest = *src;
  153. }
  154. src ++;
  155. dest ++;
  156. }
  157. *dest = '\0';
  158. if (table->id > 0) {
  159. fprintf(hresfile, "%s-%d =%s\n", LibraryName, table->id, buffer);
  160. }
  161. table++;
  162. }
  163. }
  164. done:
  165. if (hresfile) fclose(hresfile);
  166. if (dbfile) free(dbfile);
  167. return rc;
  168. }
  169. /*******************************************************************************/
  170. int main()
  171. {
  172. #if 0
  173. return XP_MakeStringDatabase();
  174. #else
  175. return XP_MakeStringProperties();
  176. #endif
  177. }
  178. /*******************************************************************************/