aboutsummaryrefslogtreecommitdiff
path: root/main/Mac/CoclSystemDependent.icl
blob: 389bd222ffb4bf84ed8cb9df97fba6eaebdf93d4 (plain) (blame)
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
// this is for the PowerMac
implementation module CoclSystemDependent

import StdEnv
import Clean2AppleEventHandler,compile,docommand,cache_variable

from Clean2AppleEventHandler import get_apple_event_string;

PathSeparator
	:==	','
DirectorySeparator
	:==	':'

script_handler :: !{#Char} *Files -> (!Int,!*Files);
script_handler script files
	= case args of
		["cocl":coclArgs]
			# cache = load_state 0;
			# (ok,cache,files) = compile coclArgs cache files;
			->	(if ok 1 0,store_cache_or_clear_cache cache files)
		["clear_cache"]
			| store_state empty_cache>0
				# (r,s) = DoCommandNullTerminated ("clear_cache" +++ "\0") 0
				-> (r,files)
				# (r,s) = DoCommandNullTerminated ("clear_cache" +++ "\0") 0
				-> (r,files)
		_
			// +++ handle errors from docommand
			# (r,s) = DoCommandNullTerminated (script +++ "\0") 0
			-> (r,files)
	where
		args
			=	filter ((<>) "") (map replace scriptArgs)
		scriptArgs
			=	splitArgs script

		store_cache_or_clear_cache cache files
			| isMember "-clear_cache" scriptArgs && store_state empty_cache>0
				# (r,s)=DoCommandNullTerminated "clear_cache\0" 0
				| r==0
					= files
					= files;
			| store_state cache>0
				=	files
				=	files
		replace s
			| s == "\xb3" /* \xb3 == >= ligature */
				=	"-RE"
			| s == ">"
				=	"-RO"
			| s == "-clear_cache"
				=	""
			// otherwise
				=	s

		splitArgs s
			=	split False 0 0 (size s) s
		where
			split quoted frm to n s
				| to >= n
					=	[s % (frm, to)]
				| s.[to] == '\\' && to < n-1
					=	split quoted frm (to+2) n s
				| s.[to] == ' ' && not quoted 
					=	[s % (frm, to-1) : split False (to+1) (to+1) n s]
				| s.[to] == '\'' && quoted
					=	[s % (frm, to-1) : split False (to+1) (to+1) n s]
				| s.[to] == '\''
					=	[s % (frm, to-1) : split True (to+1) (to+1) n s]
				// otherwise
					=	split quoted frm (to+1) n s

//import StdDebug,StdString;

clean2_compiler :: !Int !*Files -> (!Int,!*Files);
clean2_compiler length files
	# string=createArray length ' ';
	# r=get_apple_event_string length string;
//	| trace_t length && trace_t ':' && trace_t r && trace_t '\n'
//		| trace_t string
	= script_handler (string%(6,r-1)) files;
//			= (0,files);
//		= (0,files);

clean2_compile :: !Int -> Int;
clean2_compile length
	# (r,files)=clean2_compiler length create_files;
	= r;

clean2_compile_c_entry :: !Int -> Int;
clean2_compile_c_entry r = code {
	.d 0 1 i
	rtn
	centry clean2_compile e_CoclSystemDependent_sclean2_compile "I:I"
 }

::	* MyFiles = MyFiles;

create_myfiles = MyFiles;

create_files :: *Files;
create_files = cast create_myfiles;

cast :: !*a -> *b;
cast f = code {
	pop_b 0
 }