File: shell.cpp

package info (click to toggle)
slic3r 1.3.0%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 8,572 kB
  • sloc: cpp: 63,126; perl: 21,512; ansic: 6,312; sh: 591; xml: 201; makefile: 37; python: 11
file content (116 lines) | stat: -rw-r--r-- 3,403 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
#include <EXTERN.h> // from the Perl distribution
#include <perl.h> // from the Perl distribution

#ifdef WIN32
// Perl win32 specific includes, found in perl\\lib\\CORE\\win32.h
// Defines the windows specific convenience RunPerl() function,
// which is not available on other operating systems.
#include <win32.h>
#include <wchar.h>
#endif

#include <cstdio>
#include <cstdlib>

#ifdef WIN32
int main(int argc, char **argv, char **env)
{
	
	// If the Slic3r is installed in a localized directory (containing non-iso
	// characters), spaces or semicolons, use short file names.
	char    exe_path[MAX_PATH] = {0};
	char    script_path[MAX_PATH];
	char    gui_flag[6] = {"--gui"};
#ifdef FORCE_GUI
	char**  command_line = (char**)malloc(sizeof(char*) * ((++ argc) + 2));
#else
	char**  command_line = (char**)malloc(sizeof(char*) * ((++ argc) + 1));
#endif
	{
		// Unicode path. This will not be used directly, but to test, whether
		// there are any non-ISO characters, in which case the path is converted to a
		// short path (using 8.3 directory names).

		wchar_t exe_path_w[MAX_PATH] = {0};
		char    drive[_MAX_DRIVE];
		char    dir[_MAX_DIR];
		char    fname[_MAX_FNAME];
		char    ext[_MAX_EXT];
		bool    needs_short_paths = false;
		int     len;
		int     i;
		GetModuleFileNameA(NULL, exe_path, MAX_PATH-1);
		GetModuleFileNameW(NULL, exe_path_w, MAX_PATH-1);
		len = strlen(exe_path);

		if (len != wcslen(exe_path_w)) {
			needs_short_paths = true;
		} else {
			for (i = 0; i < len; ++ i)
				if ((wchar_t)exe_path[i] != exe_path_w[i] || exe_path[i] == ' ' ||
						exe_path[i] == ';') {
					needs_short_paths = true;
					break;
				}
		}
		if (needs_short_paths) {
			wchar_t exe_path_short[MAX_PATH] = {0};
			GetShortPathNameW(exe_path_w, exe_path_short, MAX_PATH);
			len = wcslen(exe_path_short);
			for (i = 0; i <= len; ++ i)
				exe_path[i] = (char)exe_path_short[i];
		}
		_splitpath(exe_path, drive, dir, fname, ext);
		_makepath(script_path, drive, dir, NULL, NULL);
		if (needs_short_paths)
			printf("Slic3r installed in a loclized path. Using an 8.3 path: \"%s\"\n",
					script_path);
		SetDllDirectoryA(script_path);
		_makepath(script_path, drive, dir, "slic3r", "pl");
		command_line[0] = exe_path;
		command_line[1] = script_path;
		memcpy(command_line + 2, argv + 1, sizeof(char*) * (argc - 2));
#ifdef FORCE_GUI
		command_line[argc] = gui_flag;
		command_line[argc+1] = NULL;
#else
		command_line[argc] = NULL;
#endif
		// Unset the PERL5LIB and PERLLIB environment variables.
		SetEnvironmentVariable("PERL5LIB", NULL);
		SetEnvironmentVariable("PERLLIB", NULL);
#if 0
		printf("Arguments: \r\n");
		for (size_t i = 0; i < argc + 1; ++ i)
			printf(" %d: %s\r\n", i, command_line[i]);
#endif
	}
#ifdef FORCE_GUI
	RunPerl(argc+1, command_line, NULL);
#else
	RunPerl(argc, command_line, NULL);
#endif
	free(command_line);
}
#else

int main(int argc, char **argv, char **env)
{
    PerlInterpreter *my_perl = perl_alloc();
    if (my_perl == NULL) {
        fprintf(stderr, "Cannot start perl interpreter. Exiting.\n");
        return -1;
    }
    perl_construct(my_perl);

#ifdef FORCE_GUI
    char* command_line[] = { "slic3r", "slic3r.pl", "--gui" };
#else
    char* command_line[] = { "slic3r", "slic3r.pl" };
#endif
    perl_parse(my_perl, NULL, 3, command_line, (char **)NULL);
    perl_run(my_perl);
    perl_destruct(my_perl);
    perl_free(my_perl);
}
#endif