-
Notifications
You must be signed in to change notification settings - Fork 3
/
MOVE.FILES
199 lines (197 loc) · 4.38 KB
/
MOVE.FILES
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
SUBROUTINE MOVE.FILES(ARGS,DELETE.FLAG)
*
GIT.FILENAME = 'MOVE.FILES'
GIT.REPO = 'https://github.com/Krowemoh/TCL-Utilities.git'
*
* COMPILER DIRECTIVES
*
$DEFINE DATABASE.UV
$DEFINE PLATFORM.LINUX
*
* VERSION
*
VERSION = '1'
*
@USER1 = 'MOVE.FILES'
@USER2 = 'MOVE.FILES'
*
$IFDEF DATABASE.UV
USER.NAME = @ACCOUNT
PORT.NUMBER = @USERNO
ACCOUNT.NAME = @WHO
$ENDIF
*
$IFDEF DATABASE.D3
USER.NAME = @USER
PORT.NUMBER = @USERNO
ACCOUNT.NAME = @ACCOUNT
$ENDIF
*
EQU TRUE TO 1
EQU FALSE TO 0
*
OPEN '','VOC' TO VOC.FILE ELSE
OPEN '','MD' TO VOC.FILE ELSE
PRINT 'Unable to open file: VOC'
STOP
END
END
*
OS.DEST = FALSE
*
SOURCE.IS.DICT = FALSE
DEST.IS.DICT = FALSE
*
IF ARGS<2> = 'DICT' THEN
SOURCE.IS.DICT = TRUE
ARGS = DELETE(ARGS,2)
END
*
LOCATE('DICT',ARGS;ANYPOS) THEN
DEST.IS.DICT = TRUE
ARGS = DELETE(ARGS,ANYPOS)
END
*
SOURCE.DICT = ''
DEST.DICT = ''
*
IF SOURCE.IS.DICT THEN
SOURCE.DICT = 'DICT'
END
*
IF DEST.IS.DICT THEN
DEST.DICT = 'DICT'
END
*
ARGS.LEN = DCOUNT(ARGS,@AM)
*
IF ARGS.LEN = 2 THEN
PRINT 'Invalid option.'
STOP
*
END ELSE IF ARGS.LEN = 3 THEN
SOURCE = ARGS<2>
DEST = ARGS<3>
DEST.RECORD.ID = ''
*
END ELSE IF ARGS.LEN = 4 THEN
SOURCE = ARGS<2>
SOURCE.RECORD.ID = ARGS<3>
DEST = ARGS<4>
DEST.RECORD.ID = ''
*
CLEARSELECT
SELECT SOURCE.RECORD.ID
*
END ELSE IF ARGS.LEN = 5 THEN
SOURCE = ARGS<2>
SOURCE.RECORD.ID = ARGS<3>
DEST = ARGS<4>
DEST.RECORD.ID = ARGS<5>
*
CLEARSELECT
SELECT SOURCE.RECORD.ID
END
*
OPEN SOURCE.DICT,SOURCE TO SOURCE.FILE ELSE
PRINT 'Unable to open source: ' : SOURCE
STOP
END
*
OPEN DEST.DICT,DEST TO DEST.FILE ELSE
IF DEST[1,1] # '/' THEN
PRINT 'Failed to open destination: ' : DEST
STOP
END
*
DEST.ENTRY.ID = USER.NAME : '.' : PORT.NUMBER : '.MOVE.DEST'
*
DEST.ENTRY = ''
DEST.ENTRY<1> = 'F'
DEST.ENTRY<2> = DEST
DEST.ENTRY<3> = DEST
*
WRITEU DEST.ENTRY ON VOC.FILE,DEST.ENTRY.ID LOCKED
PRINT 'Failed to get lock on destination VOC: ' : DEST
STOP
*
END THEN
OPEN '',DEST.ENTRY.ID TO DEST.FILE ELSE
PRINT 'Failed top open destination: ' : DEST
END
*
END ELSE
PRINT 'Failed to write destination VOC for: ' : DEST
STOP
END
END
*
CTR = 0
TOTAL.CTR = 0
*
LOOP
READNEXT ITEM.ID ELSE ITEM.ID = ''
UNTIL ITEM.ID = '' DO
TOTAL.CTR = TOTAL.CTR + 1
*
IF DEST.RECORD.ID = '' THEN
DEST.RECORD.ID = ITEM.ID
END
*
PRINT TOTAL.CTR, ITEM.ID, DEST.RECORD.ID
*
READU ITEM FROM SOURCE.FILE,ITEM.ID LOCKED
PRINT 'Failed to get a lock for: ' : SOURCE : ' ' : ITEM.ID
DEST.RECORD.ID = ''
CONTINUE
*
END ELSE
PRINT 'Failed to read: ' : SOURCE : ' ' : ITEM.ID
DEST.RECORD.ID = ''
CONTINUE
END
*
READ DEST.ITEM FROM DEST.FILE,DEST.RECORD.ID THEN
READU DEST.ITEM FROM DEST.FILE,DEST.RECORD.ID LOCKED
PRINT 'Failed to get a lock: ' : DEST : ' ' : DEST.RECORD.ID
DEST.RECORD.ID = ''
CONTINUE
*
END ELSE
PRINT 'Failed to read: ' : DEST : ' ' : DEST.RECORD.ID
DEST.RECORD.ID = ''
CONTINUE
END
END
*
WRITE ITEM ON DEST.FILE,DEST.RECORD.ID THEN
IF DELETE.FLAG THEN
DELETE SOURCE.FILE,ITEM.ID ELSE
PRINT 'Failed to delete: ' : SOURCE : ' ' : ITEM.ID
END
END
*
END ELSE
PRINT 'Failed to write: ' : DEST : ' ' : DEST.RECORD.ID
DEST.RECORD.ID = ''
CONTINUE
END
*
CTR = CTR + 1
*
DEST.RECORD.ID = ''
REPEAT
*
IF OS.DEST THEN
DELETE VOC.FILE,DEST.ENTRY.ID ELSE
PRINT 'Failed to delete: ' : DEST.ENTRY.ID
END
END
*
PRINT
PRINT 'Moved ' : CTR : '/' : TOTAL.CTR : ' from ' : SOURCE : ' to ' : DEST
*
* END OF PROGRAM
*
END
*