/* MapMatch.amirx
Based on MATCHDemo by Ariel Magnum
Like Match.amirx but displays result with WorldMap.
*/


Options Results  /* Enable rc/result return codes */
signal on syntax /* Enables syntax checking       */
prefix='MapMatch'  /* Prefix for echos              */
colour=3         /* Colour fo echos               */

NL='0a'x ;ib=0 ;mi=0 ;ai=0;st=0
"GETCHANNEL"
channel=RESULT
	IF WORDS(channel)=0 THEN DO
		cecho("MapMatch ERROR: you are not on a channel!")
		exit
	END

/* Begin */
	IF SHOW('Ports','WORLD.1') THEN ADDRESS 'WORLD.1' 'CLEAR' 
	IF ~SHOW('Ports','WORLD.1') THEN DO
		ADDRESS 'COMMAND' 'Run >NIL: c:worldmap'
		ADDRESS 'COMMAND' 'SYS:RexxC/WaitForPort MIAMI.1'
	END
	IF ~SHOW('Ports','WORLD.1') THEN DO
		cecho("MapMatch ERROR: could not find c:worldmap")
		exit
	END
	

ADDRESS 'WORLD.1' 'WRITE Matching ' channel
"GETUSERS"
users=compress(result,'@+') /* Remove the status markers */
de=0;il=0;uk=0;se=0;fi=0;no=0;au=0
do until users=''
	parse var users user users
	"USERHOST" user
	host=result
	"MATCHUSERHOST" user"!"host "*!*@*.fi"
	if rc=1 then fi=fi+1
	"MATCHUSERHOST" user"!"host "*!*@*.de"
	if rc=1 then de=de+1
	"MATCHUSERHOST" user"!"host "*!*@*.il"
	if rc=1 then il=il+1
	"MATCHUSERHOST" user"!"host "*!*@*.uk"
	if rc=1 then uk=uk+1
	"MATCHUSERHOST" user"!"host "*!*@*.se"
	if rc=1 then se=se+1
	"MATCHUSERHOST" user"!"host "*!*@*.no"
	if rc=1 then no=no+1
	"MATCHUSERHOST" user"!"host "*!*@*.au"
	if rc=1 then au=au+1

end
max=0

IF il~=0 THEN DO
	IF il>max THEN DO
		max=il
		most="Mostly Israelis, " il "users."
	END
	dot_it(30,35,il)
END
IF fi~=0 THEN DO
	IF fi>max THEN DO
		max=fi
		most="Mostly Finnish, " fi "users."
	END
	dot_it(25,65,fi)
END
IF de~=0 THEN DO
	IF de>max THEN DO
		max=de
		most="Mostly German, " de "users."
	END
	dot_it(13,50,de)
END
IF uk~=0 THEN DO
	IF uk>max THEN DO
		max=uk
		most="Mostly British, " uk "users."
	END
	dot_it(0,40,uk)
END
IF se~=0 THEN DO
	IF se>max THEN DO
		max=se
		most="Mostly Swedish, " se "users."
	END
	dot_it(18,60,se)
END
IF no~=0 THEN DO
	IF no>max THEN DO
		max=no
		most="Mostly Norweigian, " no "users."
	END
	dot_it(13,65,no)
END
IF au~=0 THEN DO
	IF au>max THEN DO
		max=au
		most="Mostly Australian, " au "users."
	END
	dot_it(140,-30,au)
END
IF max~=0 THEN ADDRESS 'WORLD.1' 'WRITE ' most
IF max=0 THEN ADDRESS 'WORLD.1' 'WRITE No matches.' 

/* End   */
exit

dot_it:
	ADDRESS 'WORLD.1' 'DOT ' arg(1) arg(2) 
	ADDRESS 'WORLD.1' 'MOVE ' arg(1) (arg(2)+1) 
	ADDRESS 'WORLD.1' 'DRAW ' arg(1) (arg(2)+arg(3))	
return 0

/* Shared Functions */
bold:      /* This function bolds text*/
return '02'x||arg(1)||'02'x

underline: /* This function underlines text*/
return '1F'x||arg(1)||'1F'x

inverse:   /* This function inverses text*/
return '16'x||arg(1)||'16'x

cecho:     /* This function echo's text to listview*/
"ECHO P="d2c(27)"b«"prefix"» C="colour arg(1)
return 0

syntax:   /* This function returns where you made a syntax error */
prefix="Syntax"
cecho("Command on line" SIGL "returned" RC ":" errortext(rc) sourceline(SIGL))
exit


