1 /* write_l - simple functions to write into a label widget or gadget;
2 procedures write_ll (writing long) & write_ls (writing string)
3 replace write_lw printf function that accepts variable
4 number of arguments (but the latter causes some compatibility
5 problems on different systems so we do not use it if possible)
6
7 A widget into which something will be written must belongs
8 to a label widget class or to a label gadget class.
9 The output will be written using appropriate character set.
10 (C) A. Stochniol 1991 - 1993
11 All rights reserved
12 Last revision: 17.11.1993
13 */
14
15
16 #include <stdio.h>
17 #include <X11/Intrinsic.h>
18 #include <X11/StringDefs.h>
19 #include <Xm/Xm.h>
20 #include <Xm/Label.h>
21 #include <Xm/LabelG.h>
22
23
24
25
26
27 #ifdef _NO_PROTO
write_ll(label,charset,format,n)28 void write_ll(label, charset, format, n)
29 Widget label;
30 XmStringCharSet charset;
31 char *format;
32 long n;
33
34 #else /* _NO_PROTO */
35 void write_ll(Widget label, XmStringCharSet charset, char *format, long n)
36 #endif
37 {
38 char output[512]; /* watch out not to use longer output !!!! */
39 Arg al[1];
40 XmString xmstr;
41
42 if(!label) return; /* safety test .... */
43
44 /* format the string to be displayed in the widget */
45 sprintf(output, format, n);
46
47 /* Make sure that the destination widget is a subclass of XmLabel. */
48 if(!XmIsLabel(label) && !XmIsLabelGadget(label))
49 {
50 fprintf(stderr, "Error: write_ll requires a Label Widget or Gadget. The following output not written:\n %s \n",
51 output);
52 return;
53 }
54
55 /* convert the string to an appropriate compound string and set it */
56 xmstr = XmStringLtoRCreate(output, charset);
57 XtSetArg(al[0], XmNlabelString, xmstr);
58 XtSetValues(label, al, 1);
59
60 XmStringFree(xmstr);
61
62 } /* write_ll */
63
64
65 #ifdef _NO_PROTO
write_ls(label,charset,format,s)66 void write_ls(label, charset, format, s)
67 Widget label;
68 XmStringCharSet charset;
69 char *format;
70 char *s;
71
72 #else /* _NO_PROTO */
73 void write_ls(Widget label, XmStringCharSet charset, char *format, char *s)
74 #endif
75 {
76 char output[512]; /* watch out not to use longer output !!!! */
77 Arg al[1];
78 XmString xmstr;
79
80 if(!label) return; /* safety test .... */
81
82 /* format the string to be displayed in the widget */
83 sprintf(output, format, s);
84
85 /* Make sure that the destination widget is a subclass of XmLabel. */
86 if(!XmIsLabel(label) && !XmIsLabelGadget(label))
87 {
88 fprintf(stderr, "Error: write_ls requires a Label Widget or Gadget. The following output not written:\n %s \n",
89 output);
90 return;
91 }
92
93 /* convert the string to an appropriate compound string and set it */
94 xmstr = XmStringLtoRCreate(output, charset);
95 XtSetArg(al[0], XmNlabelString, xmstr);
96 XtSetValues(label, al, 1);
97
98 XmStringFree(xmstr);
99
100 } /* write_ls */
101
102
103
104