*! 7nov2008 program docs version 11.1 syntax [anything], [none sxs search(string) noMEMory *] if ("`0'"=="dir") { qui findfile "docs.ado" mata: pathback("`r(fn)'") *pathutil `r(fn)', p(dir) qui collect `pbpath'docs_*.lmat, hold q foreach f in `r(files)' { mata: pathback("`f'") * pathutil `f',p(path) f(name) local short=substr("`pbfile'",strpos("`pbfile'","_")+1,strlen("`pbfile'")-strpos("`pbfile'","_")) capture confirm file "`pbpath'docs_`short'.hlp" if (~_rc) mata: st_local("desc",cat("`path'docs_`short'.hlp",3,3)) local desc=substr("`desc'",strpos("`desc'","{* DIR:")+7,.) local desc=substr("`desc'",1,strpos("`desc'","}")-1) di "{ralign 10:{help docs_`short':`short'}} {txt:`desc'}" } } else mata: docs_display("`anything'","`options'") end version 11.1 mata: struct docsmap { //>>def struct>> string colvector who pointer colvector at string rowvector keys, meta, formats real rowvector spacing } void docs_display(string scalar command, string scalar inOpt) { //>>def func>> pointer (struct docsmap scalar) map class prefs scalar pr //*****************parse command comvec=columnize(command) if (!length(comvec)) { name=""; inDS=""; inVars="" } else { if (sum(isat=strpos(comvec,"@"):>0)) name=subinstr(comvec[toindices(isat)],"@","") else name="" comvec=columnize(columnize(" "+concat(select(comvec',!isat')," ")+" ","("),")") if (length(comvec)==3) { inDS=comvec[2] inVars=strtrim(comvec[1]+comvec[3]) } else { inDS="" inVars=strtrim(concat(comvec," ")) } } //*********************reconcile with prefs, etc. pr.make("docs",("docs","dsets","vars","meta")) if (name=="") name=pr.c("docs") //here need to handle clearing others or not if ((map=findexternal("docs_"+name))==NULL) { path=findfile("docs_"+name+".lmat") if (!strlen(path)) errel("Specified Docs not found ("+name+")") (void) lmat_read(path) map=findexternal("docs_"+name) } pr.rowof("docs",name,("*","1",map->meta[1])) if (st_local("ne")!="none") inOpt=concat(select(map->meta,listmatch(map->meta,inOpt))," ") else inOpt="none" pr.updaterow((name,inDS,inVars,inOpt)) if (st_local("memory")=="") pr.write() tables=toindices(listmatch(map->who,pr.c("dsets"))) vars=J(rows(tables),1,NULL) keyvec=tokens(pr.c("vars"),":") if (length(keyvec)>1) { vcol=2+toindices(map->keys:==keyvec[1]) for (i=1;i<=rows(vars);i++) vars[i]= &toindices(rowmax(vmatch(columnize((*map->at[tables[i]])[,vcol]),keyvec[3]))) } else { vcol=2-(regexm(pr.c("vars"),"^[0-9]+[-<> ]?")) //digits followed by space or range operator indicates index for (i=1;i<=rows(vars);i++) vars[i]= &toindices(listmatch((*map->at[tables[i]])[,vcol],pr.c("vars"))) } tcols=(1,2) if (length(keyvec)>1) tcols=tcols,vcol if (pr.c("meta")!="none") tcols=tcols,toindices(listmatch(map->meta,pr.c("meta"))):+2+cols(map->keys) if (st_local("sxs")=="") { //***********Begin Display paragraph******************************************* printf("{p2colset 0 %f %f 1}",map->spacing[3],map->spacing[3]+3) for (i=1;i<=rows(tables);i++) { for (j=1;j<=rows(*vars[i]);j++) { therow=(*map->at[tables[i]])[(*vars[i])[j],tcols] rdup=therow if (strlen(search=st_local("search"))) { searches=(searches=strlower(tokens(search))),strupper(searches),strproper(searches) for (s=1;s<=length(searches);s++) { therow=subinstr(therow,searches[s],"{hi:"+searches[s]+"}") } } if (!strlen(search) | rdup!=therow) { if (rows(map->who)>1) printf("{txt}{p2col:{space %f}%s{space %f}%s{space %f}{res:%s}}", map->spacing[1]-strlen(map->who[tables[i]]), map->who[tables[i]], map->spacing[2]-strlen(therow[1]), therow[1], map->spacing[3]-map->spacing[1]-map->spacing[2]-strlen(therow[2])-2,therow[2]) else printf("{txt}{p2col:{space %f}%s{space %f}{res:%s}}", map->spacing[2]-strlen(therow[1]), therow[1], map->spacing[3]-map->spacing[2]-strlen(therow[2])-2,therow[2]) if (cols(therow)<3) printf("{p_end}") else { if (map->formats[tcols[3]]=="line") /*printf("{p_end}%s",therow[3])*/ printf("{p_end}{col %f}%s",map->spacing[3], subinstr(therow[3],"{break}","{break}{col "+strofreal(map->spacing[3])+"}")) else printf("%s{p_end}",therow[3]) for (k=4;k<=cols(therow);k++) { if (map->formats[tcols[k]]=="line") //section mark literals causing problems here for some reason printf("{col %f}{res:%s} %s",map->spacing[3]-2,char(167), subinstr(therow[k],"{break}","{break}{col "+strofreal(map->spacing[3])+"}")) else printf("{p2col:{space %f}{res:%s}}%s{p_end}",map->spacing[3]-3,char(167),therow[k]) } } } } } printf("{txt}{hline %f}\n",line=sum(strlen(map->meta))+sum(strlen(pr.body[pr.r,1..3]))+10) printf("@{cmd:%s} ({cmd:%s}) {cmd:%s}, ",pr.c("docs"),pr.c("dsets"),pr.c("vars")) for (i=1;i<=length(map->meta);i++) { printf("{%s:%s} ",anyof(tokens(pr.c("meta")),map->meta[i])?"cmd":"txt",map->meta[i]) } printf("\n{hline %f}\n",line) } else { //****************Begin Display sxs******************************************** first=(*map->at[tables[1]])[*vars[1],2] farrow=J(rows(first),1,"") c=max(strlen(first)) for (span=2;span<=rows(tables);span++) { next=(*map->at[tables[span]])[*vars[span],2] farrow=farrow,J(rows(farrow),1,"") narrow=J(rows(next),1,"") for (i=1;i<=rows(next);i++) { maxindex(strmatch(first[,span-1],next[i]),1,idx,w) if (length(idx)>1) { first=insert(first,"r",i,1) farrow=insert(farrow,"r",i,1) } else if (idx>i) { next=insert(next,"r",i,idx-i) narrow=insert(narrow,"r",i,idx-i) i=idx } else if (idxwho[tables[j]]) printf("\n") for (j=1;j<=cols(first);j++) printf("{hline "+c[j]+"}{hline 2}"+(j==cols(first)?"{c RT}":"{c +}")) printf("\n") for (i=1;i<=rows(first);i++) { for (j=1;j<=cols(first);j++) { printf("{res:%1s}%-"+c[j]+"s{res:%1s}{c |}",farrow[i,2*j-1],first[i,j],farrow[i,2*j]) } printf("\n") } } } transmorphic matrix insert(transmorphic matrix body, string scalar rc, real scalar at, real scalar amt, | transmorphic scalar blank) { if (args()<5) blank=missingof(body) begin= (rc=="r"?body:body') out=J(0,cols(begin),missingof(begin)) if (at>1) out=begin[1..at-1,] out=out\J(amt,cols(begin),blank) if (at<=rows(begin)) out=out\begin[at..rows(begin),] return(rc=="r"?out:out') } end