makstrdb.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <stdlib.h>
  41. #include "netsite.h"
  42. #ifdef BERKELEY_DB_RESOURCE
  43. #include "mcom_db.h"
  44. #include "nsres.h"
  45. #endif
  46. #define RESOURCE_STR
  47. /********************************************/
  48. /* Begin: Application dependent information */
  49. /********************************************/
  50. #ifdef NS_DS
  51. #include "gsslapd.h"
  52. #define GSXXX_H_INCLUDED
  53. #endif
  54. #ifdef buildAnotherServer
  55. #include "gsanother.h"
  56. #define GSXXX_H_INCLUDED
  57. #endif
  58. /********************************************/
  59. /* End: Application dependent information */
  60. /********************************************/
  61. /**********************************************/
  62. /* Begin: Check that BUILD_MODULE is handled */
  63. /* and a gs*.h file has been included */
  64. /**********************************************/
  65. #ifndef GSXXX_H_INCLUDED
  66. #error Error in makstrdb.c: BUILD_MODULE not handled; gs*.h not included.
  67. #endif
  68. /********************************************/
  69. /* End: Check that BUILD_MODULE is handled */
  70. /* and a gs*.h file has been included */
  71. /********************************************/
  72. /*******************************************************************************/
  73. #ifdef XP_DEBUG
  74. void
  75. XP_PrintStringDatabase(void) /* debug routine */
  76. {
  77. int i;
  78. int j;
  79. char* LibraryName;
  80. RESOURCE_TABLE* table;
  81. j = 0;
  82. while (table=allxpstr[j++].restable) {
  83. LibraryName = table->str;
  84. printf("Library %d: %s\n",j,LibraryName);
  85. i = 1;
  86. table++;
  87. while (table->str) {
  88. printf("%d: %s %d \"%s\"\n",i,LibraryName,table->id,table->str);
  89. i++;
  90. table++;
  91. }
  92. }
  93. }
  94. #endif /* XP_DEBUG */
  95. #ifdef BERKELEY_DB_RESOURCE
  96. /*******************************************************************************/
  97. int
  98. XP_MakeStringDatabase(void)
  99. {
  100. int j;
  101. char* LibraryName;
  102. char* cptr;
  103. RESOURCE_TABLE* table;
  104. NSRESHANDLE hresdb;
  105. char DBTlibraryName[128];
  106. /* Creating database */
  107. hresdb = NSResCreateTable(DATABASE_NAME, NULL);
  108. if (hresdb==0) {
  109. printf("Error creating database %s\n",DATABASE_NAME);
  110. return 1;
  111. }
  112. j = 0;
  113. while (table=allxpstr[j++].restable) {
  114. LibraryName = table->str;
  115. printf("Add Library %d: %s\n",j,LibraryName);
  116. table++;
  117. while (table->str) {
  118. if (table->id==-1 && strstr(table->str,"$DBT: ")) {
  119. cptr = strstr(table->str,"referenced");
  120. if (cptr) {
  121. strncpy(cptr,"in DB file",10);
  122. }
  123. }
  124. NSResAddString(hresdb,LibraryName,table->id,table->str,0);
  125. table++;
  126. }
  127. }
  128. NSResCloseTable(hresdb);
  129. return 0;
  130. }
  131. #endif
  132. /*******************************************************************************/
  133. int
  134. XP_MakeStringProperties(void)
  135. {
  136. int j;
  137. char* LibraryName;
  138. RESOURCE_TABLE* table;
  139. FILE *hresfile;
  140. char buffer[2000];
  141. char *src, *dest;
  142. char *dbfile;
  143. /* Creating database */
  144. dbfile = (char *) malloc (strlen(DATABASE_NAME) + 20);
  145. strcpy(dbfile, DATABASE_NAME);
  146. strcat(dbfile, ".properties");
  147. hresfile = fopen(dbfile, "w");
  148. if (hresfile==NULL) {
  149. printf("Error creating properties file %s\n",DATABASE_NAME);
  150. return 1;
  151. }
  152. j = 0;
  153. while ((table=allxpstr[j++].restable)) {
  154. LibraryName = table->str;
  155. fprintf(hresfile, "\n");
  156. fprintf(hresfile, "#######################################\n");
  157. fprintf(hresfile, "############### %s ###############\n", LibraryName);
  158. printf("Add Library %d: %s\n",j,LibraryName);
  159. table++;
  160. while (table->str) {
  161. /*
  162. Change special char to \uXXXX
  163. */
  164. src = table->str;
  165. dest = buffer;
  166. while (*src) {
  167. if (*src < 0x20) {
  168. strcpy(dest,"\\u00");
  169. dest += 4;
  170. sprintf(dest, "%02x", *src);
  171. dest += 1;
  172. }
  173. else {
  174. *dest = *src;
  175. }
  176. src ++;
  177. dest ++;
  178. }
  179. *dest = '\0';
  180. if (table->id > 0) {
  181. fprintf(hresfile, "%s-%d =%s\n", LibraryName, table->id, buffer);
  182. }
  183. table++;
  184. }
  185. }
  186. fclose(hresfile);
  187. return 0;
  188. }
  189. /*******************************************************************************/
  190. int main()
  191. {
  192. #if 0
  193. return XP_MakeStringDatabase();
  194. #else
  195. return XP_MakeStringProperties();
  196. #endif
  197. }
  198. /*******************************************************************************/