makstrdb.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. #include <stdio.h>
  42. #include <string.h>
  43. #include <stdlib.h>
  44. #include "netsite.h"
  45. #ifdef BERKELEY_DB_RESOURCE
  46. #include "mcom_db.h"
  47. #include "nsres.h"
  48. #endif
  49. #define RESOURCE_STR
  50. /********************************************/
  51. /* Begin: Application dependent information */
  52. /********************************************/
  53. #include "gsslapd.h"
  54. #define GSXXX_H_INCLUDED
  55. #ifdef buildAnotherServer
  56. #include "gsanother.h"
  57. #define GSXXX_H_INCLUDED
  58. #endif
  59. /********************************************/
  60. /* End: Application dependent information */
  61. /********************************************/
  62. /**********************************************/
  63. /* Begin: Check that BUILD_MODULE is handled */
  64. /* and a gs*.h file has been included */
  65. /**********************************************/
  66. #ifndef GSXXX_H_INCLUDED
  67. #error Error in makstrdb.c: BUILD_MODULE not handled; gs*.h not included.
  68. #endif
  69. /********************************************/
  70. /* End: Check that BUILD_MODULE is handled */
  71. /* and a gs*.h file has been included */
  72. /********************************************/
  73. /*******************************************************************************/
  74. #ifdef XP_DEBUG
  75. void
  76. XP_PrintStringDatabase(void) /* debug routine */
  77. {
  78. int i;
  79. int j;
  80. char* LibraryName;
  81. RESOURCE_TABLE* table;
  82. j = 0;
  83. while (table=allxpstr[j++].restable) {
  84. LibraryName = table->str;
  85. printf("Library %d: %s\n",j,LibraryName);
  86. i = 1;
  87. table++;
  88. while (table->str) {
  89. printf("%d: %s %d \"%s\"\n",i,LibraryName,table->id,table->str);
  90. i++;
  91. table++;
  92. }
  93. }
  94. }
  95. #endif /* XP_DEBUG */
  96. #ifdef BERKELEY_DB_RESOURCE
  97. /*******************************************************************************/
  98. int
  99. XP_MakeStringDatabase(void)
  100. {
  101. int j;
  102. char* LibraryName;
  103. char* cptr;
  104. RESOURCE_TABLE* table;
  105. NSRESHANDLE hresdb;
  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 = NULL;
  140. char buffer[2000];
  141. char *src, *dest;
  142. char *dbfile = NULL;
  143. int rc = 0;
  144. /* Creating database */
  145. dbfile = (char *) malloc (strlen(DATABASE_NAME) + 20);
  146. if (dbfile==NULL) {
  147. printf("Out of memory\n");
  148. rc = 1;
  149. goto done;
  150. }
  151. strcpy(dbfile, DATABASE_NAME);
  152. strcat(dbfile, ".properties");
  153. hresfile = fopen(dbfile, "w");
  154. if (hresfile==NULL) {
  155. printf("Error creating properties file %s\n",DATABASE_NAME);
  156. rc = 1;
  157. goto done;
  158. }
  159. j = 0;
  160. while ((table=allxpstr[j++].restable)) {
  161. LibraryName = table->str;
  162. fprintf(hresfile, "\n");
  163. fprintf(hresfile, "#######################################\n");
  164. fprintf(hresfile, "############### %s ###############\n", LibraryName);
  165. printf("Add Library %d: %s\n",j,LibraryName);
  166. table++;
  167. while (table->str) {
  168. /*
  169. Change special char to \uXXXX
  170. */
  171. src = table->str;
  172. dest = buffer;
  173. while (*src && (sizeof(buffer) > (dest-buffer))) {
  174. if (*src < 0x20) {
  175. strcpy(dest,"\\u00");
  176. dest += 4;
  177. sprintf(dest, "%02x", *src);
  178. dest += 1;
  179. }
  180. else {
  181. *dest = *src;
  182. }
  183. src ++;
  184. dest ++;
  185. }
  186. *dest = '\0';
  187. if (table->id > 0) {
  188. fprintf(hresfile, "%s-%d =%s\n", LibraryName, table->id, buffer);
  189. }
  190. table++;
  191. }
  192. }
  193. done:
  194. if (hresfile) fclose(hresfile);
  195. if (dbfile) free(dbfile);
  196. return rc;
  197. }
  198. /*******************************************************************************/
  199. int main()
  200. {
  201. #if 0
  202. return XP_MakeStringDatabase();
  203. #else
  204. return XP_MakeStringProperties();
  205. #endif
  206. }
  207. /*******************************************************************************/