/* Import a text in a box */
/* $VER: ImportText 1.01e (© R.Florac, 9 août 1998) */
/* Bug: don't handle the quotes ("), the current scale and placement mode */
/* Only use the left and top borders of the selected box */

options results

signal on error
signal on syntax

'FIRSTSEL'; obj=result
if obj>0 then do
    'TYPE('obj')'
    if result=22 then do
	'NEXTSEL('obj')'
	if result=0 then do
	    'COORDS('obj')';
	    PARSE VAR result x0 ',' y0 ',' x1 ',' y1
	    xg=minima(x0,x1); xd=maxima(x0,x1)
	    yh=minima(y0,y1); yb=maxima(y0,y1)
	    'REQFILE("Name of the text file?", "Work:text/ASCII")'; fichier=result
	    if fichier ~= "" then do
		if open(file, fichier, 'R') then do
		    y0=y0+10
		    'SAVEALL(-1)'
		    do while y0 < y1
			ligne=readln(file)
			if ligne ~= "" then do
			    ligne=translate(ligne,"        ",'09'x)
			    'WRITE("'ligne'",'x0','y0')'; e=result
			    if e=0 then do
				'REQUEST("Text placement in line"+CHR(10)+"'ligne'"+CHR(10)+"impossible."+CHR(10)+"Do you want to continue?")'
				if result=0 then leave
			    end
			    y0=y0+10
			end
			if eof(file) then leave
		    end
		    close(file)
		end
	    end
	    exit
	end
    end
end

'MESSAGE("Draw and select a box"+CHR(10)+"where you want to"+CHR(10)+"put the text")'

exit

minima: procedure
    parse arg v1,v2
    if v1<v2 then return v1
    return v2
end

maxima: procedure
    parse arg v1,v2
    if v1>v2 then return v1
    return v2
end

syntax:
erreur=RC
'MESSAGE("Script ImportText.AmiCAD"+CHR(10)+"Syntax error"+CHR(10)+"in line 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
exit

error:
'MESSAGE("Script ImportText.AmiCAD"+CHR(10)+"Error in line 'SIGL'")'
exit
