10
20
30 :
40 ON ERROR REPORT:PROCClose_All:PRINT ERL:QUIT
50 SYS "OS_GetEnv" TO A$:A$=MID$(A$,1+INSTR(A$," ",1+INSTR(A$," ",1+INSTR(A$," "))))
60 IF A$="":ERROR 220,"Syntax: RMJoin <infile> <infile> ... <outfile>":QUIT
70 max%=HIMEM-LOMEM-4096:DIM mem% max%,size% 3
80 WHILE RIGHT$(A$)=" ":A$=LEFT$(A$):ENDWHILE
90 A%=0:B%=0:REPEAT:B%=A%:A%=INSTR(A$," ",A%+1):UNTIL A%=0
100 out$=MID$(A$,B%+1):infile$=LEFT$(A$,B%-1)
110 SYS "OS_File",5,infile$ TO ,,load%,exec%,,attr%
120 out%=OPENOUT(out$)
130 REPEAT
140 module%=FALSE
150 A%=INSTR(infile$+" "," "):in$=LEFT$(infile$,A%-1):infile$=MID$(infile$,A%+1)
160 IF LEFT$(in$,2)="-m" THEN
170 A%=INSTR(infile$+" "," "):in$=LEFT$(infile$,A%-1):infile$=MID$(infile$,A%+1)
180 module%=TRUE
190 ENDIF
200 in%=OPENIN(in$)
210 IF in%=0 THEN
220 PRINT "File '"in$"' not found"
230 ELSE
240 len%=EXT#in%:IF len%>max% THEN
250 PRINT "File '"in$"' too long"
260 ELSE
270 SYS "OS_GBPB",3,in%,mem%,len%,0:CLOSE#in%:in%=0
280 IF module%:!size%=len%:SYS "OS_GBPB",1,out%,size%,4,PTR#out%
290 SYS "OS_GBPB",1,out%,mem%,len%,PTR#out%
300 ENDIF
310 ENDIF
320 UNTIL infile$=""
330 IF module%:!size%=0:SYS "OS_GBPB",1,out%,size%,4,PTR#out%
340 CLOSE#out%:out%=0
350 SYS "OS_File",1,out$,load%,exec%,,attr%
360 QUIT
370 :
380 DEF PROCClose_All
390 in%=in%:IF in%:A%=in%:in%=0:CLOSE#A%
400 out%=out%:IF out%:A%=out%:out%=0:CLOSE#A%
410 ENDPROC