1 /* $Header: /home/cvs/wavplay/xmsprint.c,v 1.1.1.1 1999/11/21 19:50:56 wwg Exp $
2 * Warren W. Gay VE3WWG Sat Mar 1 14:04:46 1997
3 *
4 * Format a string: XmString XmSprintf(format,...)
5 *
6 * X LessTif WAV Play :
7 *
8 * Copyright (C) 1997 Warren W. Gay VE3WWG
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation version 2 of the License.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 * Public License for more details (see enclosed file COPYING).
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * Send correspondance to:
24 *
25 * Warren W. Gay VE3WWG
26 *
27 * Email:
28 * ve3wwg@yahoo.com
29 * wgay@mackenziefinancial.com
30 *
31 * $Log: xmsprint.c,v $
32 * Revision 1.1.1.1 1999/11/21 19:50:56 wwg
33 * Import wavplay-1.3 into CVS
34 *
35 * Revision 1.7 1997/04/14 00:08:49 wwg
36 * Added GNU license info.
37 *
38 * Revision 1.6 1997/04/14 00:02:46 wwg
39 * Hopefully the final revision for the 1.0 release
40 *
41 * Revision 1.5 1997/03/04 03:08:53 wwg
42 * Added function XmSprintfText()
43 *
44 * Revision 1.4 1997/03/01 21:50:27 wwg
45 * Put StrDate() function in here
46 *
47 * Revision 1.3 1997/03/01 19:44:14 wwg
48 * Added missing rcsid[]
49 *
50 * Revision 1.2 1997/03/01 19:28:44 wwg
51 * Added XmSprintfLabel() function
52 *
53 * Revision 1.1 1997/03/01 19:13:36 wwg
54 * Initial revision
55 */
56 static const char rcsid[] = "@(#)xmsprint.c $Revision: 1.1.1.1 $";
57
58 #include <stdio.h>
59 #include <stdlib.h>
60 #include <unistd.h>
61 #include <stdarg.h>
62 #include <string.h>
63 #include <time.h>
64 #include <Xm/Xm.h>
65 #include <Xm/Text.h>
66 #include "xmsprint.h"
67
68 /*
69 * This function returns a formatted XmString
70 */
71 XmString
XmSprintf(const char * format,...)72 XmSprintf(const char *format,...) {
73 char buf[2048];
74 va_list ap;
75
76 /*
77 * First format the message:
78 */
79 va_start(ap,format);
80 vsprintf(buf,format,ap);
81 va_end(ap);
82
83 /*
84 * Now create the XmString to return:
85 */
86 return XmStringCreateLtoR(buf,XmSTRING_DEFAULT_CHARSET);
87 }
88
89 /*
90 * This function does a sprintf() into a label widget:
91 */
92 void
XmSprintfLabel(Widget w,const char * format,...)93 XmSprintfLabel(Widget w,const char *format,...) {
94 char buf[2048];
95 va_list ap;
96 XmString s;
97
98 /*
99 * First format the message:
100 */
101 va_start(ap,format);
102 vsprintf(buf,format,ap);
103 va_end(ap);
104
105 /*
106 * Now create the XmString to return:
107 */
108 s = XmStringCreateLtoR(buf,XmSTRING_DEFAULT_CHARSET);
109 XtVaSetValues(w,XmNlabelString,s,NULL);
110 XmStringFree(s);
111 }
112
113 /*
114 * This function does a sprintf() into a text widget:
115 */
116 void
XmSprintfText(Widget w,const char * format,...)117 XmSprintfText(Widget w,const char *format,...) {
118 char buf[2048];
119 va_list ap;
120
121 /*
122 * First format the message:
123 */
124 va_start(ap,format);
125 vsprintf(buf,format,ap);
126 va_end(ap);
127
128 XmTextSetString(w,buf); /* Set text in widget now */
129 XmTextSetInsertionPosition(w,0); /* Put cursor at start of field */
130 }
131
132 /*
133 * Return an ascii string date, without the newline:
134 */
135 char *
StrDate(time_t td)136 StrDate(time_t td) {
137 char *cp;
138 static char stbuf[64];
139
140 strcpy(stbuf,ctime(&td));
141 if ( (cp = strchr(stbuf,'\n')) != NULL )
142 *cp = 0; /* Stomp on the newline */
143 return stbuf;
144 }
145
146 /* $Source: /home/cvs/wavplay/xmsprint.c,v $ */
147