/* Recherche d'un texte
Version 1.00: 3 juin 1999
Version 1.01: 13 avril 2000 (modif fonctions OBJECTS, LOCK, UNLOCK)
Version 1.02: 4 novembre 2000 (localisation anglais/français)
$VER: 1.01 (© R.Florac, 13 avril 2000) */

options results     /* indispensable pour récupérer le résultat des macros */

signal on error     /* pour l'interception des erreurs */
signal on syntax

'LANGUAGE'
if result='français.language' then fr=1
else fr=0

texte=""
'LOCK:FIRSTSEL'; i=result
if i>0 then do
    'IF(TYPE('i')==TEXTE,READTEXT('i'),"")'; texte=result
    if result="" then do
	'IF(TYPE('i')==REFERENCE,READTEXT('i'),"")'; texte=result
	if result="" then do
	    'IF(TYPE('i')==VALEUR,READTEXT('i'),"")'; texte=result
	end
    end
end

if texte="" then do
    if fr=1 then 'ASKTEXT("Texte à chercher ?","")'
    else 'ASKTEXT("Text to search ?","")'
    texte=result
end
if texte='' then do
    'UNLOCK'
    exit
end

call 'Travail:AmiCAD/Arexx/InitObjets.AmiCAD'

nf=0
if fr=1 then 'TITLE("Recherche en cours..."):OBJECTS'
else 'TITLE("Searching..."):OBJECTS'
o=result
do i=1 to o
    'IF(TYPE('i')==TEXTE,READTEXT('i'),"")'
    t=result
    if t ~= "" then do
	if t=texte then do
	    'MARK('i')'
	    nf=nf+1
	end
    end
end

i=1
do while i>0
    'FINDREF('i',"'texte'")'; i=result
    if i>0 then do
	'MARK('i'):MARK(GETREF('i'))'
	nf=nf+1
	i=i+1
	if i>o then leave
    end
end

i=1
do while i>0
    'FINDVAL('i',"'texte'")'; i=result
    if i>0 then do
	'MARK('i'):MARK(GETVAL('i'))'
	nf=nf+1
	i=i+1
	if i>o then leave
    end
end

if fr=1 then do
    if nf > 0 then 'TITLE(""):MESSAGE("Texte «'texte'»"+CHR(10)+"trouvé 'nf' fois"):UNLOCK'
    else 'TITLE(""):MESSAGE("'texte'"+CHR(10)+"non trouvé"):UNLOCK'
end
else do
    if nf > 0 then 'TITLE(""):MESSAGE("'texte'"+CHR(10)+"found 'nf' times"):UNLOCK'
    else 'TITLE(""):MESSAGE("'texte'"+CHR(10)+"not found"):UNLOCK'
end
exit

/* Traitement des erreurs, interruption du programme */
syntax:
erreur=RC
if fr=1 then 'MESSAGE("Erreur de syntaxe"+CHR(10)+"en ligne 'SIGL'"+CHR(10)+"'errortext(erreur)'"):UNLOCK'
else 'MESSAGE("Syntax error"+CHR(10)+"in line 'SIGL'"+CHR(10)+"'errortext(erreur)'"):UNLOCK'
exit

error:
if fr=1 then 'MESSAGE("Erreur en ligne 'SIGL'"):UNLOCK'
else 'MESSAGE("Error in line 'SIGL'"):UNLOCK'
exit
