Main.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: Main.c /main/5 1999/09/20 14:08:17 mgreess $ */
  24. /*
  25. cc -g -o Main Main.c -I/usr/dt/include -I/usr/openwin/include -R/export2/build/SunOS/lib1/DtSvc:/usr/dt/lib:/usr/openwin/lib -L/export2/build/SunOS/lib1/DtSvc -L/usr/dt/lib -L/usr/openwin/lib -lDtSvc -lXt
  26. */
  27. #include <locale.h>
  28. #include <Tt/tt_c.h>
  29. #include <X11/Intrinsic.h>
  30. #include <Xm/MessageB.h>
  31. #include <Xm/Form.h>
  32. #include <Xm/Text.h>
  33. #include <Dt/Dts.h>
  34. #include <Dt/UserMsg.h>
  35. #include <Dt/EnvControlP.h>
  36. static void DbCacheCreateError(Widget toplevel);
  37. static void DbCacheCreateErrorCallback(Widget, XtPointer, XtPointer);
  38. static void DieFromToolTalkError(char*, Tt_status);
  39. #define ApplicationClass "dtdtscache"
  40. #define RebuildMsg "DtDtsCache"
  41. int build_db = 1;
  42. int
  43. main(int argc, char **argv)
  44. {
  45. XtAppContext appContext;
  46. Widget toplevel, form;
  47. char *tmp;
  48. int c;
  49. int more = 1;
  50. Tt_message msg;
  51. Tt_status status;
  52. int count = 0;
  53. int slp = 0;
  54. int init_flag;
  55. int i;
  56. char *locale = setlocale(LC_ALL, "");
  57. if(!locale)
  58. {
  59. perror("setlocale");
  60. }
  61. _DtEnvControl(DT_ENV_SET);
  62. if(strcmp(argv[1], "-init") == 0)
  63. {
  64. init_flag = 1;
  65. }
  66. else
  67. {
  68. init_flag = 0;
  69. }
  70. if(!init_flag)
  71. {
  72. status = tt_ptr_error(tt_open());
  73. DieFromToolTalkError(
  74. "Could not connect to ToolTalk:\n%s\nExiting",
  75. status);
  76. }
  77. if(!init_flag)
  78. {
  79. status = tt_ptype_declare("SDTDTSCACHE");
  80. DieFromToolTalkError(
  81. "Could not declare SDTDTSCACHE ptype:\n%s\nExiting",
  82. status);
  83. }
  84. toplevel = XtAppInitialize(&appContext, ApplicationClass, NULL, 0,
  85. &argc, argv, NULL, NULL, 0);
  86. if (DtAppInitialize(appContext, XtDisplay(toplevel), toplevel, argv[0],
  87. ApplicationClass) == False)
  88. {
  89. _DtSimpleError(ApplicationClass,
  90. DtFatalError,
  91. NULL ,
  92. "%s: Couldn't initialize Dt\n",
  93. argv[0]);
  94. }
  95. while(!init_flag && more)
  96. {
  97. msg = tt_message_receive();
  98. if(msg != 0)
  99. {
  100. char *op = tt_message_op(msg);
  101. if(strcmp(op, RebuildMsg) != 0)
  102. {
  103. tt_message_reject(msg);
  104. }
  105. else
  106. {
  107. Tt_message m;
  108. if (!_DtDtsMMInit(1))
  109. {
  110. tt_message_reply(msg);
  111. DbCacheCreateError(toplevel);
  112. /* NOTREACHED */
  113. }
  114. count = 0;
  115. slp = 0;
  116. tt_message_reply(msg);
  117. /*
  118. m = tt_message_create();
  119. tt_message_scope_set(m, TT_SESSION);
  120. tt_message_class_set(m, TT_NOTICE);
  121. tt_message_op_set(m, "DtTypes_Reloaded");
  122. tt_message_address_set(m, TT_PROCEDURE);
  123. tt_message_send(m);
  124. */
  125. }
  126. }
  127. else
  128. {
  129. count++;
  130. }
  131. if(count >= 10)
  132. {
  133. if(slp)
  134. {
  135. more = 0;
  136. continue;
  137. }
  138. sleep(30);
  139. slp = 1;
  140. }
  141. }
  142. if(init_flag)
  143. {
  144. if (!_DtDtsMMInit(1))
  145. {
  146. /*
  147. * Log an error message. Cannot post a dialog because
  148. * there is a good chance system is starting up.
  149. */
  150. _DtSimpleError(ApplicationClass, DtFatalError, NULL,
  151. "Couldn't create the Desktop Action/DataTypes Database.\n\
  152. Check disk space and/or permissions.\n");
  153. }
  154. }
  155. exit(0);
  156. }
  157. static void
  158. DbCacheCreateErrorCallback(Widget w, XtPointer userData, XtPointer callData)
  159. {
  160. XtUnmanageChild(w);
  161. XFlush(XtDisplay(w));
  162. XmUpdateDisplay(w);
  163. _DtSimpleError(ApplicationClass, DtFatalError, NULL,
  164. "Couldn't recreate the Desktop Action/DataTypes Database.\n\
  165. Check disk space and/or permissions.\n");
  166. }
  167. /*
  168. * This function posts an error dialog informing the user that creation
  169. * of the Actions/DataTypes Database failed.
  170. * Wait for the user to acknowledge the error, log a message, and then exit.
  171. */
  172. static void
  173. DbCacheCreateError(Widget toplevel)
  174. {
  175. Widget err;
  176. int n;
  177. Arg args[10];
  178. XmString okLabel;
  179. XmString message;
  180. char * messagein;
  181. char * title;
  182. Dimension dialogWd, dialogHt;
  183. title = "dtdbcache failure";
  184. messagein = "Couldn't recreate the Desktop Actions/DataTypes Database.\n\
  185. Check disk space and/or permissions.";
  186. message = XmStringCreateLocalized(messagein);
  187. okLabel = XmStringCreateLocalized("OK");
  188. /* Post an error dialog */
  189. n = 0;
  190. XtSetArg(args[n], XmNtitle, title); n++;
  191. XtSetArg(args[n], XmNmessageString, message); n++;
  192. XtSetArg(args[n], XmNokLabelString, okLabel); n++;
  193. XtSetArg(args[n], XmNdefaultPosition, False); n++;
  194. XtSetArg(args[n], XmNmappedWhenManaged, False); n++;
  195. err = XmCreateErrorDialog(toplevel, "err", args, n);
  196. XmStringFree(okLabel);
  197. XmStringFree(message);
  198. XtUnmanageChild(XmMessageBoxGetChild(err, XmDIALOG_CANCEL_BUTTON));
  199. XtUnmanageChild(XmMessageBoxGetChild(err, XmDIALOG_HELP_BUTTON));
  200. /* Center the dialog */
  201. XtRealizeWidget(err);
  202. XtVaGetValues(err, XmNwidth, &dialogWd, XmNheight, &dialogHt, NULL);
  203. XtSetArg(args[0], XmNx,
  204. (WidthOfScreen(XtScreen(err)) - dialogWd) / 2);
  205. XtSetArg(args[1], XmNy,
  206. (HeightOfScreen(XtScreen(err)) - dialogHt) / 2);
  207. XtSetValues (err, args, 2);
  208. XtManageChild(err);
  209. XtSetMappedWhenManaged(err, True);
  210. XtAddCallback(err, XmNokCallback, DbCacheCreateErrorCallback,
  211. (XtPointer)NULL);
  212. XtAppMainLoop(XtWidgetToApplicationContext(err));
  213. }
  214. static void
  215. DieFromToolTalkError(char *errfmt, Tt_status status)
  216. {
  217. char *statmsg;
  218. if (! tt_is_err(status)) return;
  219. statmsg = tt_status_message(status);
  220. _DtSimpleError(ApplicationClass, DtFatalError, NULL, errfmt, statmsg);
  221. exit(status);
  222. }