# Copyright for the Uniform Repository Service (c) 1995 - 2023,
# by Gerald Banon. All rights reserved.
# Version 2.1
# getWordOccurrence.tcl
# used in PerformCheck only
# similar code em post

if 0 {
# for testing
	set rep dpi.inpe.br/banon/1999/06.19.17.00
	set homePath c:/usuario/gerald/URLib
	set URLibServiceRepository dpi.inpe.br/banon/1998/08.02.08.56
	set loCoInRep dpi.inpe.br/banon/1999/01.09.22.14
}

set rep [lindex $argv 0]
set homePath [lindex $argv 1]
set URLibServiceRepository [lindex $argv 2]
set loCoInRep [lindex $argv 3]	;# used by MultipleSubmit (see GetWordOccurrenceList)
# set serverAddress [lindex $argv 4]	;# used by MultipleSubmit (see GetWordOccurrenceList)
# set serverAddressWithIP [lindex $argv 5]	;# used by MultipleSubmit (see GetWordOccurrenceList)

source $homePath/col/$URLibServiceRepository/doc/utilities1.tcl
source $homePath/col/$URLibServiceRepository/doc/cgi/mirrorfind-.tcl
source $homePath/col/$URLibServiceRepository/doc/utilitiesStart.tcl

LoadGlobalVariables	;# set serverAddress and serverAddressWithIP

# maximumNumberOfWords
# empty maximumNumberOfWords means to return all the keywords
if ![file exists $homePath/col/$rep/doc/@maximumNumberOfWords] {
	set fileContent {# empty maximumNumberOfWords means to return all the keywords
# set maximumNumberOfWords 30
set maximumNumberOfWord {}}
	Store fileContent $homePath/col/$rep/doc/@maximumNumberOfWords
}
source $homePath/col/$rep/doc/@maximumNumberOfWords	;# set maximumNumberOfWords

if [catch {GetWordOccurrenceList $rep $maximumNumberOfWords} wordOccurrenceList] {
	set message $errorInfo
	Store message $homePath/col/$rep/doc/@log auto 0 a
	return
}
if [catch {GetWordOccurrenceList $rep $maximumNumberOfWords} wordOccurrenceList] {
	set message $errorInfo
	Store message $homePath/col/$rep/doc/@log auto 0 a
	set message {warning: the word ocurrence list has not been updated}
	Store message $homePath/col/$rep/doc/@log auto 0 a
} else {	;# else added by GJFB in 2023-02-08 - otherwise 'Store wordOccurrenceList' below might store an error message like 'invalid bareword "rep"' and result to an error while executing GetWordOccurrenceList the next day
	if ![string equal {} $wordOccurrenceList] {
#		Store wordOccurrenceList $homePath/col/$rep/doc/@wordOccurrence	;# commented by GJFB in 2016-08-06
		Store wordOccurrenceList $homePath/col/$rep/doc/@wordOccurrence auto 0 w 0 iso8859-1	;# solves the accent problem at mtc-m12 (with utf-8 encoding system) - added by GJFB in 2016-08-06
	} else {
		set message {$wordOccurrenceList is empty}
		Store message $homePath/col/$rep/doc/@log auto 0 a
		set message {warning: the word ocurrence list has not been updated}
		Store message $homePath/col/$rep/doc/@log auto 0 a
	}
}
