⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkhlpfiles.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
*! version 1.0.5  09mar2005
program checkhlpfiles
	version 8

	if `c(SE)' != 1 { 
		di as err "checkhelpfiles:  requires Stata/SE"
		exit 198
	}

	gettoken cmd 0 : 0, parse(" ,")
	syntax [, PATH(string) System]

	if "`system'" != "" {
		if `"`path'"'!="" {
			di as err ///
			"may not combine options -path()- and -system-"
			exit 198
		}
		local path "UPDATES;BASE"
	}
	else if `"`path'"'=="" {
		local path `"`c(adopath)'"'
	}

	preserve

	if "`cmd'"=="help" {
		DoHelp "`path'"
	}
	else if "`cmd'"=="stata" {
		DoStata "`path'"
	}
	else if "`cmd'"=="dialog" {
		DoDialog "`path'"
	}
	else if "`cmd'"=="manual" {
		DoManual "`path'"
	}
	else if "`cmd'"=="doublebang" {
		DoDoublebang "`path'"
	}
	else	error 198
end


program DoDoublebang
	args path

	GetFiles hlpfiles : *.hlp `"`path'"'
	GetFiles ihlpfiles : *.ihlp `"`path'"'
	GetFiles mfiles : *.maint `"`path'"'

	local n 0
	local h 0
	foreach el of local hlpfiles {
		DoublebangFile "`el'" "`path'"
		local h = `h' + r(has)
		local ++n
	}

	foreach el of local ihlpfiles {
		DoublebangFile "`el'" "`path'"
		local h = `h' + r(has)
		local ++n
	}

	foreach el of local mfiles {
		DoublebangFile "`el'" "`path'"
		local h = `h' + r(has)
		local ++n
	}
	di _n "(`h'/`n' have doublebangs)"
end


program DoublebangFile, rclass
	args hfn path

	GetFFN ffn : `"`path'"' "`hfn'"
	ReadHlpFile `"`path'"' "`hfn'"

	local dbang = "!" + "!" 
	quietly count if strpos(contents, "`dbang'")
	if r(N) {
		di as txt "`ffn'"
		ret scalar has = 1
	}
	else	ret scalar has = 0
end


program DoDialog
	args path
	tempfile dlg dlgs

	quietly {
		drop _all
		set obs 1
		gen str1 ref=""
		gen found = 0
		save "`dlgs'"
	}

	GetFiles hlpfiles : *.hlp `"`path'"'
	if r(n)==0 {
		exit
	}
	GetFiles ihlpfiles : *.ihlp `"`path'"'

	GetFiles dlgfiles : *.dlg `"`path'"'
	MakeDlgFileDataset `dlgfiles'
	qui save "`dlg'"

	foreach el of local hlpfiles {
		DialogHlpFile "`el'" "`dlg'" "`path'" "`dlgs'"
		if r(leaf) {
			local leaves `leaves' `el'
		}
	}

	foreach el of local ihlpfiles {
		DialogHlpFile "`el'" "`dlg'" "`path'" "`dlgs'"
		if r(leaf) {
			local leaves `leaves' `el'
		}
	}

	qui use `dlgs', clear
	qui count if found==0
	if r(N) {
		di as txt _n "{hline}"
		di as txt "{title:Dialogs referred to but which do not exist}"
		qui keep if found==0
		list ref
	}

	quietly {
		use "`dlgs'", clear
		keep if found
		drop found
		capture drop _merge
		save "`dlgs'", replace
		use "`dlg'", clear
		capture drop _merge
		rename dfn ref
		merge ref using `dlgs', nokeep
		keep if _merge==1
	}
	if _N {
		di as txt _n "{hline}"
		di as txt "{title:Dialogs not referred to}"
		list ref
	}
end

program DialogHlpFile
	args hfn dlgdta path dlgs

	GetFFN ffn : `"`path'"' "`hfn'"

	ReadHlpFile `"`path'"' "`hfn'"
	Extract `"`ffn'"' "dialog"
	if _N==0 { 
		exit
	}
	quietly { 
		replace ref = word(ref, 1) 
		sort ref 
		by ref: keep if _n==1

		rename ref dfn
		merge dfn using "`dlgdta'", nokeep
		rename dfn ref
		gen byte found = _merge==3
	}
	qui count if found==0
	if r(N) {
		preserve
		qui keep if found==0
		di as txt _n as res `"`ffn':  "' ///
			as txt "unmatched dialog:"
		list ref
		restore
	}

	quietly {
		append using "`dlgs'"
		sort ref
		by ref: keep if _n==1
		drop if ref==""
		save "`dlgs'", replace
	}
end


program DoStata
	args path

	tempfile cmds

	quietly { 
		drop _all
		set obs 1 
		gen str1 ref = ""
		gen found = 0 
		save "`cmds'"
	}

	GetFiles hlpfiles : *.hlp `"`path'"'
	if r(n)==0 { 
		exit
	}
	GetFiles ihlpfiles : *.ihlp `"`path'"'

	foreach el of local hlpfiles {
		StataHlpfile "`el'" "`path'" "`cmds'"
	}

	foreach el of local ihlpfiles {
		StataHlpfile "`el'" "`path'" "`cmds'"
	}

	quietly use "`cmds'", clear
	drop if ref==""
	if _N==0 { 
		exit
	}

	quietly keep if !found
	if _N {
		di as txt _n "{hline}"
		di as txt "{title:Commands used but that do not exist}"
		list ref
	}

	quietly use "`cmds'", clear
	quietly keep if found
	if _N {
		di as txt _n "{hline}"
		di as txt _n "{title:Commands used that exist}"
		list ref
	}
end

program StataHlpfile 
	args hfn path cmds

	GetFFN ffn : `"`path'"' "`hfn'"

	ReadHlpFile `"`path'"' "`hfn'"
	Extract `"`ffn'"' "stata"
	if _N==0 { 
		exit
	}
	quietly { 
		replace ref = word(ref, 1) 
		sort ref 
		by ref: keep if _n==1
		gen byte found = 1 
	}

	forvalues i=1(1)`=_N' {
		local cmd = ref[`i']
		capture which `cmd'
		if _rc {
			qui replace found = 0 in `i'
		}
	}

	capture assert found==1
	if _rc {
		preserve
		qui keep if found==0
		di as txt _n as res `"`ffn':  "' ///
			as txt "unmatched command:"
		list ref
		restore
	}

	quietly {
		append using "`cmds'"
		sort ref
		by ref: keep if _n==1
		drop if ref==""
		save "`cmds'", replace
	}
end


program DoManual
	args path
	tempfile manfi ok

	quietly {
		drop _all
		set obs 1 
		gen str1 ref = ""
		save "`manfi'"
	}

	GetFiles hlpfiles : *.hlp `"`path'"'
	if r(n)==0 { 
		exit
	}
	GetFiles ihlpfiles : *.ihlp `"`path'"'

	foreach el of local hlpfiles {
		ManualHlpfile "`el'" "`path'" "`manfi'" "hi"
		ManualHlpfile "`el'" "`path'" "`manfi'" "bf"
	}

	foreach el of local ihlpfiles {
		ManualHlpfile "`el'" "`path'" "`manfi'" "hi"
		ManualHlpfile "`el'" "`path'" "`manfi'" "bf"
	}

	Read_ManrefMaint_File "`path'" "
	if _N==0 { 
		qui use "`manfi'", clear
		qui compress
		list
		exit
	}
	quietly {
		save "`ok'"

		use "`manfi'", clear
		merge ref using "`ok'"
		drop if _merge==3
		compress
		sort ref
	}
	di as txt _n "{hline}"
	di as txt "{title:Referenced but not in manref.maint}
	quietly count if _merge==1
	if r(N) {
		preserve
		qui keep if _merge==1
		list ref
		restore
	}
	else	di as txt _n "    (none)"

	di as txt _n "{hline}"
	di as txt "{title:Not referenced but in manref.maint}
	quietly count if _merge==2
	if r(N) {
		preserve
		qui keep if _merge==2
		list ref
	}
	else	di as txt _n "    (none)"
end


program Read_ManrefMaint_File
	args path
	ReadMaintFile "`path'" manref.maint
	if _N {
		quietly {
			sort ref
			by ref: keep if _n==1
		}
	}
end

program Read_HlpnotusedMaint_File
	args path f_o f_y

	quietly { 
		drop _all
		set obs 1
		gen str1 hfn = ""
		drop in 1
		save "`f_o'"
		save "`f_y'"
	}

	ReadMaintFile "`path'" hlpnotused.maint
	if _N==0 { 
		exit
	}

	qui gen bad = word(ref,3)!=""
	InvalidLines
	if _N==0 { 
		exit
	}

	quietly {
		gen str word1 = word(ref, 1)
		gen str word2 = word(ref, 2)
		gen bad = !( ///
		word2=="" | word2=="both" | word2=="contents" | word2=="base" ///
		)
	}

	InvalidLines
	if _N==0 { 
		exit
	}

	quietly {
		gen str1 type = "b" if word2=="base"
		replace type = "y" if word2=="contents"
		sort word1
		by word1: gen bad = (type!=type[1])
	}
	InvalidLines
	if _N==0 { 
		exit
	}
	quietly { 
		by word1: keep if _n==1
		keep word1 type
		rename word1 hfn
		sort hfn

		preserve
		keep if type=="b" || type==""
		keep hfn
		save "`f_o'", replace
		restore

		keep if type=="y" || type==""
		keep hfn
		save "`f_y'", replace
	}
end

	

program InvalidLines
	capture assert bad==0
	if _rc==0 { 
		drop bad
		exit 
	}
	di as txt _n
	di as txt "manref.maint:  contains invalid lines:"
	list ref if bad
	di "manref.maint:  lines ignored
	qui drop if bad
	drop bad
end
	

	
program ReadMaintFile 
	args path fn 
	qui drop _all
	capture findfile "`fn'", path("`path'")
	if _rc { 
		di as txt "(note:  file `fn' not found)"
		exit
	}
	local input "`r(fn)'"
	quietly {
		infix str ref 1-240 using `"`input'"'
		replace ref = trim(ref)
		drop if ref=="" | substr(ref,1,1)=="*"
		compress
	}
end



program ManualHlpfile 
	args hfn path manfi hiorbf

	GetFFN ffn : `"`path'"' "`hfn'"

	ReadHlpFile `"`path'"' "`hfn'"
	ExtractColon `"`ffn'"' "`hiorbf'"
	if _N==0 { 
		exit
	}
	quietly {
		keep if substr(ref,1,1)=="["
		if _N==0 { 
			exit
		}
		sort ref
		by ref: keep if _n==1
		append using "`manfi'"
		drop if ref==""
		sort ref
		by ref: keep if _n==1
		save "`manfi'", replace
	}
end
	

program DoHelp
	args path
	tempfile hlpdta refed_o refed_y realhlpfiles
	tempfile noref_o noref_y

	Read_HlpnotusedMaint_File "`path'" "`noref_o'" "`noref_y'"

	GetFiles hlpfiles : *.hlp `"`path'"'
	if r(n)==0 { 
		exit
	}
	GetFiles ihlpfiles : *.ihlp `"`path'"'

	GetAliases aliases : `"`path'"'

	MakeHlpFileDataset `hlpfiles'
	qui save `"`realhlpfiles'"'

	MakeHlpFileDataset `hlpfiles' `aliases'
	rename hfn ref
	qui save `"`hlpdta'"'

	quietly {
		drop _all
		set obs 1 
		gen str1 ref = ""
		save "`refed_o'"
		save "`refed_y'"
	}

	di as txt _n "{hline}"
	di as txt "{title:Errors}"
	foreach el of local hlpfiles {
		CheckHlpFile "`el'" "`hlpdta'" "`path'" "`refed_o'" "`refed_y'"
		if r(leaf) {
			local leaves `leaves' `el'
		}
	}
	foreach el of local ihlpfiles {
		CheckHlpFile "`el'" "`hlpdta'" "`path'" "`refed_o'" "`refed_y'"
		/* don't report .ihlps as leaves */
	}

	di as txt _n "{hline}"
	di as txt "{title:Leaves}"
	ReportLeaves `leaves'

/*
	use "`refed_o'", clear
	save refed_o, replace
	use "`refed_y'", clear
	save refed_y, replace
	use "`hlpdta'", clear
	save hlpdta, replace
*/

	di as txt _n "{hline}"
	Xref "`refed_o'" "`hlpdta'" "`realhlpfiles'" ///
		"From base help files" 1 "`noref_o'"
	di as txt _n "{hline}"
	Xref "`refed_y'" "`hlpdta'" "`realhlpfiles'" ///
		"From contents help files" 0 "`noref_y'"
end

program ReportLeaves
	if `"`0'"'=="" {
		exit
	}
	MakeHlpFileDataset `0'
	sort hfn
	list
end


program Xref
	args refed hlpdta realhlpfiles title isbase noref

	quietly { 
		use "`refed'", clear 
		drop if ref==""
		if _N==0 { 
			exit
		}
		sort ref
		merge ref using "`hlpdta'"
		drop if _merge==3
		if _N==0 { 
			exit
		}
		sort ref 
	}
		
	preserve
	qui count if _merge==1
	if r(N) {
		qui keep if _merge==1
		di as txt "{title:`title':  referenced but do not exist}"
		list ref
		di
		restore, preserve
	}
	if `isbase' { // contents.hlp and y_*.hlp are not part of "base"
		qui drop if substr(ref,1,2)=="y_"
		qui drop if ref=="contents.hlp"
	}
	qui count if _merge==2
	if r(N) {
		quietly {
			keep if _merge==2
			drop _merge
			sort ref 
			rename ref hfn

			merge hfn using `"`realhlpfiles'"'
			keep if _merge==3

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -