excutil.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. /* $XConsortium: excutil.c /main/3 1996/04/08 15:51:03 cde-fuj $ */
  24. /*
  25. * (c) Copyright 1995 FUJITSU LIMITED
  26. * This is source code modified by FUJITSU LIMITED under the Joint
  27. * Development Agreement for the CDEnext PST.
  28. * This is unpublished proprietary source code of FUJITSU LIMITED
  29. */
  30. #include "excutil.h"
  31. extern char *maintitle;
  32. Widget excCreatePushButton(Widget parent, String name, String label,
  33. XtCallbackProc callback_func,
  34. XtPointer client_data)
  35. {
  36. Widget widget;
  37. XmString xms;
  38. Arg args[20];
  39. Cardinal n;
  40. n = 0;
  41. xms = XmStringCreateLocalized(label);
  42. XtSetArg(args[n], XmNlabelString, xms); n++;
  43. widget = XmCreatePushButton(parent, name, args, n);
  44. XmStringFree(xms);
  45. XtAddCallback(widget, XmNactivateCallback,
  46. (XtCallbackProc) callback_func,
  47. (XtPointer) client_data);
  48. XtManageChild(widget);
  49. return (widget);
  50. }
  51. void excerror(Exc_data * ed, int excerrno, char * funcname, char * func)
  52. {
  53. switch (excerrno)
  54. {
  55. case EXCERRMALLOC:
  56. fprintf(stderr, "dtudcexch:memory allocation error\n");
  57. freeExcdata(ed);
  58. exit (-1);
  59. case EXCERRNOUDC:
  60. fprintf(stderr, "dtudcexch:UDC is not defined in current locale\n");
  61. freeExcdata(ed);
  62. exit (-1);
  63. }
  64. }
  65. void dialogokCB(Widget widget, int * ans, XtPointer call_data)
  66. {
  67. /* ok button pushed */
  68. *ans = 1;
  69. }
  70. void dialogcancelCB(Widget widget, int * ans, XtPointer call_data)
  71. {
  72. /* cancel button pushed */
  73. *ans = 2;
  74. }
  75. void AskUser(Widget parent, Exc_data * ed, char *msg, int *r, char * type)
  76. /* If ok button pushed, *r = 1. */
  77. /* If cancel button pushed(if exists), *r = 2. */
  78. {
  79. XmString message;
  80. Widget dialog;
  81. int ans = 0;
  82. Cardinal n;
  83. Arg args[20];
  84. n = 0;
  85. message = XmStringCreateLocalized(msg);
  86. XtSetArg(args[n], XmNmessageString, message); n++;
  87. XtSetArg(args[n], XmNtitle, maintitle); n++;
  88. XtSetArg(args[n], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); n++;
  89. if (strcmp(type, "warning") == 0) {
  90. dialog = XmCreateWarningDialog(parent, type, args, n);
  91. } else if (strcmp(type, "error") == 0) {
  92. dialog = XmCreateErrorDialog(parent, type, args, n);
  93. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  94. } else if (strcmp(type, "information") == 0) {
  95. dialog = XmCreateInformationDialog(parent, type, args, n);
  96. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  97. } else if (strcmp(type, "question") == 0) {
  98. dialog = XmCreateQuestionDialog(parent, type, args, n);
  99. } else {
  100. fprintf(stderr, "error in AskUser\n");
  101. }
  102. XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  103. XmStringFree(message);
  104. XtAddCallback(dialog, XmNokCallback, (XtCallbackProc) dialogokCB,
  105. (XtPointer) &ans);
  106. XtAddCallback(dialog, XmNcancelCallback, (XtCallbackProc) dialogcancelCB,
  107. (XtPointer) &ans);
  108. XtManageChild(dialog);
  109. while (ans == 0) {
  110. XtAppProcessEvent(ed->app, XtIMAll);
  111. XSync(XtDisplay(dialog), 0);
  112. }
  113. *r = ans;
  114. XSync(XtDisplay(dialog), 0);
  115. XmUpdateDisplay(dialog);
  116. }
  117. int beki(int n, int num)
  118. {
  119. int a,i;
  120. a = 1;
  121. for (i=0; i<num; i++)
  122. a = a * n;
  123. return a;
  124. }
  125. int c2h(char * num)
  126. {
  127. int i,n;
  128. char *c;
  129. if ((strlen(num)==6)&&(strncmp(num,"0x",2)==0))
  130. {
  131. c = num;
  132. c=c+2;
  133. n=0;
  134. for (i=3;i>=0;i--)
  135. {
  136. if (('0'<= *c)&&(*c <= '9'))
  137. n = n + ((*c - '0')*beki(16,i));
  138. else if (('a' <= *c)&&(*c <= 'f'))
  139. n = n + ((*c - 'a'+10)*beki(16,i));
  140. else
  141. Ecs("error in c2h.here");
  142. c++;
  143. }
  144. } else
  145. Ecs("error in c2h");
  146. return n;
  147. }
  148. char * renge2num(char * renge)
  149. {
  150. char * num;
  151. num = (char *) calloc(7, sizeof(char));
  152. strncpy(num,renge,6);
  153. return num;
  154. }
  155. void Ecs(char * string)
  156. {
  157. fprintf(stderr,"%s\n",string);
  158. }
  159. void Ecd(int data)
  160. {
  161. fprintf(stderr,"%d\n",data);
  162. }
  163. void freecsrec(UDCcsREC *rec)
  164. {
  165. if (rec->charset != NULL)
  166. free(rec->charset);
  167. if (rec->udcrenge != NULL)
  168. free(rec->udcrenge);
  169. }
  170. void freecslist(int n, UDCcsREC *rec)
  171. {
  172. int i;
  173. UDCcsREC *recp;
  174. recp = rec;
  175. for (i = 0; i < n; i++)
  176. {
  177. if (recp != NULL)
  178. {
  179. freecsrec(recp);
  180. recp++;
  181. } else {
  182. break;
  183. }
  184. }
  185. }
  186. void freeExcdata(Exc_data *ed)
  187. {
  188. if (ed == NULL)
  189. return;
  190. /* Don't free ed->toplevel */
  191. if (ed->locale != NULL)
  192. free(ed->locale);
  193. if (ed->cslist != NULL)
  194. free(ed->cslist);
  195. if (ed->xlfdname != NULL)
  196. free(ed->xlfdname);
  197. if (ed->style != NULL)
  198. free(ed->style);
  199. if (ed->size != NULL)
  200. free(ed->size);
  201. /* Don't free ed->fontfile */
  202. if (ed->bdffile != NULL)
  203. XtFree(ed->bdffile);
  204. if (ed->udcrenge != NULL)
  205. free(ed->udcrenge);
  206. if (ed->gpf_code_list != NULL)
  207. free(ed->gpf_code_list);
  208. if (ed->bdf_code_list != NULL)
  209. free(ed->bdf_code_list);
  210. if (ed->comment_list != NULL)
  211. free(ed->comment_list);
  212. free(ed);
  213. }
  214. void Ecss(char * s1, char * s2)
  215. {
  216. fprintf(stderr,"%s is %s\n", s1, s2);
  217. }
  218. void Ecsd(char * s1, int i)
  219. {
  220. fprintf(stderr,"%s = %d\n", s1, i);
  221. }
  222. void checkdata(Exc_data *ed)
  223. {
  224. if (ed == NULL)
  225. return;
  226. /* Don't free ed->toplevel */
  227. if (ed->locale != NULL)
  228. Ecss("ed->locale", ed->locale);
  229. Ecsd("ed->csnum", ed->csnum);
  230. if (ed->xlfdname != NULL)
  231. Ecss("ed->xlfdname",ed->xlfdname);
  232. if (ed->fontfile != NULL)
  233. Ecss("ed->fontfile",ed->fontfile);
  234. if (ed->bdffile != NULL)
  235. Ecss("ed->bdffile",ed->bdffile);
  236. if (ed->udcrenge != NULL)
  237. Ecss("ed->udcrenge",ed->udcrenge);
  238. Ecsd("ed->code_num", ed->code_num);
  239. }
  240. void excterminate(Exc_data * ed)
  241. {
  242. freeExcdata(ed);
  243. exit(0);
  244. }
  245. void excexit(Exc_data * ed)
  246. {
  247. excterminate(ed);
  248. }
  249. void freeld(ListData *ld)
  250. {
  251. int i;
  252. char **cp;
  253. if (ld != NULL) {
  254. if (ld->allcode != NULL)
  255. free(ld->allcode);
  256. if (ld->existcode != NULL)
  257. free(ld->existcode);
  258. if (ld->existcode_c != NULL) {
  259. cp = ld->existcode_c;
  260. for (i = 0; i < ld->existcode_num; i++) {
  261. if (*cp != NULL)
  262. free(*cp);
  263. cp++;
  264. }
  265. free(ld->existcode_c);
  266. }
  267. free(ld);
  268. }
  269. }
  270. int bigger(int num1, int num2)
  271. {
  272. if (num1 >= num2)
  273. return (num1);
  274. else
  275. return (num2);
  276. }
  277. int smaller(int num1, int num2)
  278. {
  279. if (num1 < num2)
  280. return (num1);
  281. else
  282. return (num2);
  283. }