File: TextPerf.c

package info (click to toggle)
motif 2.3.4-13
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 81,160 kB
  • ctags: 51,769
  • sloc: ansic: 596,938; cpp: 3,951; yacc: 2,854; makefile: 2,070; csh: 1,199; sh: 1,070; lex: 455
file content (183 lines) | stat: -rw-r--r-- 4,424 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* $XConsortium: TextPerf.c /main/5 1995/07/15 21:10:19 drk $ */
/*
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 */
/*
 * HISTORY
 */

/*
 *	file: TextPerf.c
 *
 *	Has a Multi line Scrolled Text widget under Form. 
 *      The XmNcolumns resource is being set to 80 at creation time,
 *      and XmNrows to 24. The wordWrap is off. 
 *	The file TextPerfIn.c from Motif 1.1 is read in and the
 *	memory measured.
 */

/*  Standard C headers  */
#include <stdio.h>
#include <math.h>
#include <sys/types.h>
#include <sys/stat.h>

/*  X headers  */
#include <X11/Xlib.h>
#include <X11/StringDefs.h>
#include <X11/Xatom.h>

#include <testlib.h>

#define	TEXT1_TOPCHAR	1
#define	NUM_COLUMNS	80
#define	NUM_ROWS	24
#define	IN_FILE		"TextPerfIn.c"

#define	TEXT1_X		10
#define	TEXT1_Y		10

#define	MAX_TRIALS	50

static void	fill_text_buf();
static void  	fillTextCB();
static void  	quitCB();
static void  	measureMemoryCB();
static void  	clearTextCB();
static void  	fillSmallTextCB();
static void  	destroyTextCB();
static void  	createTextCB();


/*  Global Variables  */

char *text_string;
char *small_text_string = "SMALL TEXT";

Widget Form1;
Widget Text1;
Widget	fillText;
Widget	measureMemory;
Widget	disableMalloc;
Widget	fillSmallText;
Widget	clearText;
Widget	destroyText, createText;
XmFontList	newfontlist;
XFontStruct	*newfont;

Arg args[MAX_ARGS];
int n;
FILE	*in_fp;
int		in_fd;
int		memory_measured[MAX_TRIALS];
int		num_trials = 0;
int		start_memory, allocated_memory, memory_in_use;


main (argc, argv)
int argc;
char **argv;
{

	Widget	quit;
        XmString string;

	/*  initialize toolkit  */
    CommonTestInit(argc, argv);

    n = 0;
	XtSetArg(args[n], XtNwidth, 800);  n++;
	XtSetArg(args[n], XtNheight, 500);  n++;
    XtSetValues(Shell1, args, n);
    

	/* create main form */
	n = 0;
	Form1 = XmCreateForm (Shell1, "Form1", args, n);
	XtManageChild (Form1);

	/* Read the text file into a buffer */
	fill_text_buf();

	/* create multi line text widget */
	n = 0;
	XtSetArg(args[n], XmNx, TEXT1_X); n++;
	newfont = XLoadQueryFont(XtDisplay(Shell1),"9x15");
	if (newfont != NULL) {
		newfontlist = XmFontListCreate(newfont, XmSTRING_DEFAULT_CHARSET);
		XtSetArg(args[n], XmNfontList, newfontlist);  n++;
	}
	XtSetArg(args[n], XmNcolumns, NUM_COLUMNS);  n++;
	XtSetArg(args[n], XmNrows, NUM_ROWS);  n++;
	XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;
	XtSetArg(args[n], XmNscrollHorizontal, False); n++;
	XtSetArg(args[n], XmNeditable, False); n++;
	Text1 = XmCreateScrolledText(Form1, "Text1", args, n);
	XtManageChild(Text1);

	XmTextSetString( Text1, text_string);

	XtRealizeWidget(Shell1);

        /*  Instruct user to rerun test - timing the display of text widget. */
        CommonPause(); 

        /*  Test scrolling by moving slider. */
        CommonPause();

        /*  Test scrolling my clicking up and down arrows. */
        CommonPause();

        /*  Exit Panel. */
        CommonPause();

	XtAppMainLoop(app_context);
}


static void	fill_text_buf()
{

	struct stat	stat_buf;
	int	filesize, bytes_read;

	/* Read the file into a text buffer */
	if ((in_fp = fopen(IN_FILE, "r")) == NULL) {
		fprintf(stderr, "Can not open %s\n", IN_FILE);
		exit(0);
	}

	in_fd = fileno(in_fp);
	fstat(in_fd, &stat_buf);
	filesize = stat_buf.st_size;

	text_string = (char *)XtMalloc(filesize + 1);
	bytes_read = fread(text_string, sizeof(char ), filesize, in_fp);
	if (bytes_read != filesize) {
		printf("filesize = %d bytes_read = %d\n", filesize, bytes_read);
		fclose(in_fp);
		exit(0);
	}
	*(text_string + filesize) = '\0';
	fclose(in_fp);

}