The R Project SVN R

Rev

Rev 24283 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24283 Rev 27310
1
/*
1
/*
2
 * GraphApp - Cross-Platform Graphics Programming Library.
2
 * GraphApp - Cross-Platform Graphics Programming Library.
3
 *
3
 *
4
 * File: graphappmain.c (original routines in init.c)
4
 * File: graphappmain.c (original routines in init.c)
5
 * Platform: Windows  Version: 2.40
5
 * Platform: Windows  Version: 2.40
6
 *
6
 *
7
 * Version: 1.00  Changes: Original version by Lachlan Patrick.
7
 * Version: 1.00  Changes: Original version by Lachlan Patrick.
8
 * Version: 1.60  Changes: drawarc/fillarc(r,0,360) now encloses.
8
 * Version: 1.60  Changes: drawarc/fillarc(r,0,360) now encloses.
9
 *    New fillellipse() function replaces Windows Ellipse().
9
 *    New fillellipse() function replaces Windows Ellipse().
10
 * Version: 2.00  Changes: New class system implemented.
10
 * Version: 2.00  Changes: New class system implemented.
11
 * Version: 2.02  Changes: Added support for functions like MoveToEx.
11
 * Version: 2.02  Changes: Added support for functions like MoveToEx.
12
 * Version: 2.15  Changes: Fixed brush origins problem.
12
 * Version: 2.15  Changes: Fixed brush origins problem.
13
 * Version: 2.20  Changes: Moved some arrays from context.c to here.
13
 * Version: 2.20  Changes: Moved some arrays from context.c to here.
14
 * Version: 2.40  Changes: Moved drawimage to this file.
14
 * Version: 2.40  Changes: Moved drawimage to this file.
15
 */
15
 */
16
 
16
 
17
/* Copyright (C) 1993-1998 Lachlan Patrick
17
/* Copyright (C) 1993-1998 Lachlan Patrick
18
 
18
 
19
   This file is part of GraphApp, a cross-platform C graphics library.
19
   This file is part of GraphApp, a cross-platform C graphics library.
20
 
20
 
21
   GraphApp is free software; you can redistribute it and/or modify it
21
   GraphApp is free software; you can redistribute it and/or modify it
22
   under the terms of the GNU Library General Public License.
22
   under the terms of the GNU Library General Public License.
23
   GraphApp is distributed in the hope that it will be useful, but
23
   GraphApp is distributed in the hope that it will be useful, but
24
   WITHOUT ANY WARRANTY.
24
   WITHOUT ANY WARRANTY.
25
 
25
 
26
   See the file COPYLIB.TXT for details.
26
   See the file COPYLIB.TXT for details.
27
*/
27
*/
28
 
28
 
29
#define NONAMELESSUNION
-
 
30
#include "internal.h"
29
#include "internal.h"
31
 
30
 
32
extern void startgraphapp(HINSTANCE Instance, HINSTANCE PrevInstance, int CmdShow);
31
extern void startgraphapp(HINSTANCE Instance, HINSTANCE PrevInstance, int CmdShow);
33
 
32
 
34
 
-
 
35
__declspec(dllimport) extern unsigned int R_reserved_size;
-
 
36
#include <limits.h>
-
 
37
 
-
 
38
static void check_max_mem(int argc, char **argv)
-
 
39
{
-
 
40
    int ac = argc;
-
 
41
    char *p = NULL, **av = argv;
-
 
42
    long v;
-
 
43
 
-
 
44
    while (--ac) {
-
 
45
	++av;
-
 
46
	if(strncmp(*av, "--max-mem-size", 14) == 0) {
-
 
47
	    if(strlen(*av) < 16) {
-
 
48
		ac--; av++; p = *av;
-
 
49
	    } else p = &(*av)[15];
-
 
50
	    v = strtol(p, &p, 10);
-
 
51
	    if(p[0] == 'M') {
-
 
52
		if((1024*1024 * (double)v) > LONG_MAX) return;
-
 
53
		v = 1024*1024*v;
-
 
54
	    } else if(p[0] == 'K') {
-
 
55
		if((1024 * (double)v) > LONG_MAX) return;
-
 
56
		v = 1024*v;
-
 
57
	    } else if(p[0] == 'k') {
-
 
58
		if((1000 * (double)v) > LONG_MAX) return;
-
 
59
		v = 1000*v;
-
 
60
	    }
-
 
61
#ifdef LEA_MALLOC
-
 
62
	    if (v > R_reserved_size) R_reserved_size = v;
-
 
63
#endif
-
 
64
	    return;
-
 
65
	}
-
 
66
    }
-
 
67
}
-
 
68
 
-
 
69
/*
33
/*
70
 *  If PASS_ARGS is zero, the main function will be passed zero
34
 *  If PASS_ARGS is zero, the main function will be passed zero
71
 *  and NULL instead of argc and argv.
35
 *  and NULL instead of argc and argv.
72
 *  If it is one, the argc and argv parameters will be passed.
36
 *  If it is one, the argc and argv parameters will be passed.
73
 *  If it is two, the environ parameter will also be passed.
37
 *  If it is two, the environ parameter will also be passed.
74
 *  We define the main function as returning void, so this
38
 *  We define the main function as returning void, so this
75
 *  method ignores any value returned from main.
39
 *  method ignores any value returned from main.
76
 */
40
 */
77
 
41
 
78
int PASCAL
42
int PASCAL
79
WinMain (HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CmdLine,
43
WinMain (HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CmdLine,
80
	 int CmdShow)
44
	 int CmdShow)
81
{
45
{
82
#if (PASS_ARGS > 1) /* define argc, argv, environ */
46
#if (PASS_ARGS > 1) /* define argc, argv, environ */
83
	extern int _argc;
47
	extern int _argc;
84
	extern char **_argv;
48
	extern char **_argv;
85
	extern char **environ;
49
	extern char **environ;
86
	extern void AppMain(int argc, char **argv, char **envp);
50
	extern void AppMain(int argc, char **argv, char **envp);
87
#elif (PASS_ARGS > 0) /* only define argc and argv */
51
#elif (PASS_ARGS > 0) /* only define argc and argv */
88
	extern int _argc;
52
	extern int _argc;
89
	extern char **_argv;
53
	extern char **_argv;
90
	extern void AppMain(int argc, char **argv);
54
	extern void AppMain(int argc, char **argv);
91
#else /* else pass zero and NULL to main */
55
#else /* else pass zero and NULL to main */
92
	extern void AppMain(int argc, char **argv);
56
	extern void AppMain(int argc, char **argv);
93
#endif /* end arg declarations */
57
#endif /* end arg declarations */
94
 
58
 
95
	/* do this here, before ANY used of malloc + friends */
-
 
96
	check_max_mem(_argc, _argv);
-
 
97
        startgraphapp(Instance, PrevInstance, CmdShow);
59
        startgraphapp(Instance, PrevInstance, CmdShow);
98
	/*
60
	/*
99
	 *  Call the main function now.
61
	 *  Call the main function now.
100
	*/
62
	*/
101
#if (PASS_ARGS > 1)		/* pass argc, argv, environ */
63
#if (PASS_ARGS > 1)		/* pass argc, argv, environ */
102
	AppMain(_argc, _argv, environ);
64
	AppMain(_argc, _argv, environ);
103
#elif (PASS_ARGS > 0)	/* only pass argc and argv */
65
#elif (PASS_ARGS > 0)	/* only pass argc and argv */
104
	AppMain(_argc, _argv);
66
	AppMain(_argc, _argv);
105
#else			/* pass zero and NULL */
67
#else			/* pass zero and NULL */
106
	AppMain(0, NULL);
68
	AppMain(0, NULL);
107
#endif
69
#endif
108
 
70
 
109
	/*
71
	/*
110
	 *  Call the mainloop function to handle events.
72
	 *  Call the mainloop function to handle events.
111
	 */
73
	 */
112
 
74
 
113
 
75
 
114
	return 0;
76
	return 0;
115
}
77
}