📄 mal_module.mx
字号:
Symbol t; str ps, lnk, hlp=0, op=0, endtag=0; InstrPtr sig; Module list[256]; int k, top=0; if(s==NULL || f==NULL){ return; } list[top++]=s; while(s->outer && recursive){ list[top++]= s->outer;s=s->outer;} if(top>1) qsort(list, top, sizeof(Module), (int(*)(const void *, const void *))cmpModName); for(k=0;k<top;k++){ s= list[k]; stream_printf(f,"<%smodule name=\"%s\">\n", (s->isAtomModule?"atom":""),xmlChr(s->name)); if(s->help) stream_printf(f,"%s\n",s->help); if( s->subscope) for(j=0;j<MAXSCOPE;j++) if(s->subscope[j]){ for(t= s->subscope[j];t!=NULL;t=t->peer) { sig= getSignature(t); if(op==0 || strcmp(op,t->name)){ if(endtag) stream_printf(f," </%s>\n",endtag); stream_printf(f," <%s",fcnClass(sig)); op = t->name; stream_printf(f," name=\"%s\">\n",xmlChr(op)); if(t->def->help) stream_printf(f," <comment>%s</comment>\n", xmlChr(t->def->help)); op= t->name; endtag= fcnClass(sig); } ps= instruction2str(t->def,sig,0); lnk= strrchr(ps,'='); if(lnk && *(lnk+1)!='(') *lnk=0; stream_printf(f," <instantiation>\n"); stream_printf(f," <signature>%s</signature>\n", xmlChr(strchr(ps,'('))); if(lnk) stream_printf(f," <implementation>%s</implementation>\n",xmlChr(lnk+1)); GDKfree(ps); if(t->def->help){ if(hlp && strcmp(hlp,t->def->help)) stream_printf(f," <comment>%s</comment>\n", xmlChr(t->def->help)); } stream_printf(f," </instantiation>\n"); } } if(endtag) stream_printf(f," </%s>\n",endtag); stream_printf(f,"</%smodule>\n", (s->isAtomModule?"atom":"")); endtag=0; }}void dumpManualSection(stream *f, Module s){ int j; Symbol t; InstrPtr sig; str ps; char *pt; if(s==NULL || f==NULL || s->subscope== NULL) return; stream_printf(f,"@table\n"); for(j=0;j<MAXSCOPE;j++) if(s->subscope[j]){ for(t= s->subscope[j];t!=NULL;t=t->peer) { sig= getSignature(t); ps= instruction2str(t->def,sig,0); pt= strchr(ps,')'); if(pt){ pt++; *pt=0; stream_printf(f,"@tab %s\n",ps+1); } else stream_printf(f,"@tab %s\n",t->name); if( t->def->help) stream_printf(f," %s\n",t->def->help); } } stream_printf(f,"@end table\n");}@-The manual overview merely lists the mod.function namesin texi format for inclusion in the documetation.@cvoid dumpManualOverview(stream *f, Module s, int recursive){ int j,z,rows; Symbol t; InstrPtr sig; Module list[256]; int k, top=0, ftop, fnd; InstrPtr fcn[5000]; if(s==NULL || f==NULL){ return; } list[top++]=s; while(s->outer && recursive){ list[top++]= s->outer;s=s->outer;} if(top>1) qsort(list, top, sizeof(Module), (int(*)(const void *, const void *))cmpModName); stream_printf(f,"@multitable @columnfractions .24 .24 .24 .24\n"); for(k=0;k<top;k++){ s= list[k]; ftop = 0; if( s->subscope) for(j=0;j<MAXSCOPE;j++) if(s->subscope[j]){ for(t= s->subscope[j];t!=NULL;t=t->peer) { sig= getSignature(t); fnd = 0; fnd= *getFunctionId(sig) == '#'; for(z=0; z<ftop; z++) if( strcmp(getFunctionId(fcn[z]),getFunctionId(sig))==0){ fnd++; break; } if( fnd == 0 && ftop<5000) fcn[ftop++] = sig; } } for(j=0; j<ftop; j++) for(z=j+1; z<ftop; z++) if( strcmp(getFunctionId(fcn[j]),getFunctionId(fcn[z])) >0) { sig= fcn[j]; fcn[j]=fcn[z]; fcn[z]= sig; } stream_printf(f,"@" "item\n"); rows = ftop/4; rows += (ftop %4) ?1:0; for(z=0; z<rows; z++){ stream_printf(f,"@" "item\n%s.%s\n", getModuleId(fcn[z]), getFunctionId(fcn[z])); if( z+rows <ftop) stream_printf(f,"@" "tab\n%s.%s\n", getModuleId(fcn[z+rows]), getFunctionId(fcn[z+rows])); if(z+rows*2 <ftop) stream_printf(f,"@" "tab\n%s.%s\n", getModuleId(fcn[z+rows*2]), getFunctionId(fcn[z+rows*2])); if(z+rows*3 <ftop) stream_printf(f,"@" "tab\n%s.%s\n", getModuleId(fcn[z+rows*3]), getFunctionId(fcn[z+rows*3])); } } stream_printf(f,"@end multitable\n");}@-The manual help overview merely lists the mod.function namestogether with the help oneliner in texi format for inclusion in the documentation.@cvoid dumpManualHelp(stream *f, Module s, int recursive){ int j,z; Symbol t; InstrPtr sig; Module list[256]; int k, ftop, fnd,top=0; InstrPtr fcn[5000]; str hlp[5000],msg; if(s==NULL || f==NULL){ return; } list[top++]=s; while(s->outer && recursive){ list[top++]= s->outer;s=s->outer;} if(top>1) qsort(list, top, sizeof(Module), (int(*)(const void *, const void *))cmpModName); stream_printf(f,"@multitable @columnfractions .2 .8 \n"); for(k=0;k<top;k++){ s= list[k]; ftop = 0; if( s->subscope) for(j=0;j<MAXSCOPE;j++) if(s->subscope[j]){ for(t= s->subscope[j];t!=NULL;t=t->peer) { sig= getSignature(t); fnd = 0; fnd= *getFunctionId(sig) == '#'; for(z=0; z<ftop; z++) if( strcmp(getFunctionId(fcn[z]),getFunctionId(sig))==0){ if( hlp[z] == 0) hlp[z]= t->def->help; fnd++; break; } if( fnd == 0 && ftop<5000){ hlp[ftop]= t->def->help; fcn[ftop++] = sig; } } } for(j=0; j<ftop; j++) for(z=j+1; z<ftop; z++) if( strcmp(getFunctionId(fcn[j]),getFunctionId(fcn[z])) >0) { msg= hlp[j]; hlp[j]=hlp[z]; hlp[z]= msg; sig= fcn[j]; fcn[j]=fcn[z]; fcn[z]= sig; } stream_printf(f,"@" "item\n"); for(z=0; z<ftop; z++){ stream_printf(f,"@" "item %s.%s\n", getModuleId(fcn[z]), getFunctionId(fcn[z])); if( hlp[z] ) stream_printf(f,"@" "tab %s\n", hlp[z]); } } stream_printf(f,"@end multitable\n");}@-Summarize the type resolution table.@cvoid showModuleStat(stream *f, Module v,int cnt[256]){ int sigs=0,i,max=0,m; Symbol s; int c[256]; for(i=0;i<256;i++) c[i]=0; for(i=0;i<256;i++){ m=0; s= v->subscope[i]; while(s!=NULL){ m++; sigs++; cnt[i]++; c[i]++; s= s->peer; } if(m>max)max=m; } m=0; for(i=0;i<256;i++) if(v->subscope[i]){ stream_printf(f,"%20s",(m++ ==0?v->name:"")); stream_printf(f,"[%c] %5d %5d\n",i,c[i],(cnt[i]-c[i]/2)); } if(v->outer) showModuleStat(f,v->outer,cnt);}void showModuleStatistics(stream *f,Module s){ int i,cnt[256]; stream_printf(f,"%20s%5s%5s\n","module","#sig","avg chk"); for(i=0;i<256;i++) cnt[i]=0; showModuleStat(f,s,cnt);}@-Some primitives to aid online help and completions.@cint tstDuplicate(char **msg, char *s){ int i; size_t len; len= strlen(s); for(i=0; msg[i]; i++) if( strncmp(s, msg[i], MAX(len,strlen(msg[i]))) == 0) return 1; return 0;}char **getHelp(Module m, str pat, int completion){ str modnme, fcnnme = 0; Module m1; Symbol s; int len1 = 0,len2 = 0,fnd,f; char *t, **msg, buf[BUFSIZ]; int top=0, i,j,k, sig = 0, doc = 0;#ifdef MAL_SCOPE_DEBUG printf("showHelp: %s",pat);#endif msg= (char **) GDKmalloc( 1000 * sizeof(str)); msg[top]=0; t= strchr(pat,'\n'); if( t) *t=0; t = strchr(pat,')'); if( t) { doc++; *t=0; completion=0; } t= strchr(pat,'('); if( t) { sig++; *t=0; completion=0; } modnme= pat; if( (fcnnme = strchr(pat,'.')) ){ *fcnnme++ = 0; } t = modnme; while((isalpha((int) *t) || *t == '_' || *t=='*') && *t) t++; if(t) *t = 0; t = fcnnme; while(t && (isalpha((int) *t) || *t == '_' || *t=='*') && *t) t++; if(t) *t = 0; if( fcnnme){ len2 = strlen(fcnnme); } len1 = strlen(modnme); /* display module information if there is no function */ if( fcnnme == NULL){ for(i=0; i< MAXSCOPE; i++) for(j=0; j< MAXSCOPE; j++){ m= scopeJump[i][j]; while(m != NULL){ if( strncmp(modnme,m->name,len1) ==0 || *modnme=='*'){ msg[top++] = GDKstrdup(m->name); msg[top] =0; if( top == 999) return msg; } m= m->sibling; } } return msg; } /* display module.function */ m1 = findModule(m,modnme); if( m1 == 0 && *modnme != '*') return msg; if( m1 ) m = m1; #ifdef MAL_SCOPE_DEBUG printf("showHelp: %s %s [%d] %s %s\n", modnme,fcnnme,len2, (doc?"doc":""), (sig?"sig":""));#endif for(i=0; i< MAXSCOPE; i++) for(k=0; k< MAXSCOPE; k++){ m= scopeJump[i][k]; while( m){ if( strncmp(modnme,m->name,len1) && *modnme!='*' ) { m= m->sibling; continue; } for(j=0;j<MAXSCOPE;j++) for(s= m->subscope[j]; s; s= s->peer) if( strncmp(fcnnme,s->name,len2)==0 || *fcnnme=='*') { if( completion ) { snprintf(buf,BUFSIZ," %s.%s", ((*modnme=='*' || *modnme==0)? m->name:modnme),s->name); if( tstDuplicate(msg,buf) ) continue; } else if( doc) { fcnDefinition(s->def,s->def->stmt[0],buf,FALSE); buf[0]=' '; if( s->def->help) { char *v,*w; v= strchr(buf,0); *v++ = '\\'; *v++ = 'n'; for( w= s->def->help; *w && v <buf+BUFSIZ-1; w++) if( *w == '\n'){ *v++ = '\\'; *v++ = 'n'; w++; if( isspace((int) *w)) { for(; *w && isspace((int) *w); w++); w--; } } else *v++ = *w; *v++ = '\\'; *v++ = 'n'; *v = 0; } if( tstDuplicate(msg,buf) ) continue; } else if( strcmp(fcnnme,s->name)==0 || *fcnnme=='*' ) { fcnDefinition(s->def,s->def->stmt[0],buf,FALSE); buf[0]=' '; t= strstr(buf,"address"); if( t) *t= 0; } fnd=0; for(f=0;f<top;f++) if( msg[f] && strcmp(buf+1, msg[f]) == 0 ) fnd++; if( fnd == 0 && buf[1]){ msg[top++] = GDKstrdup(buf+1); msg[top] = 0; if( top ==999) return msg; } } m= m->sibling; } } return msg;}@-The second primitive of relevance is to find documentation matchinga keyword. Since we can not assume pcre to be everywhere, we keepit simple.@cchar **getHelpMatch(char *pat){ char **msg, buf[BUFSIZ]; Module m; Symbol s; int top = 0, i,j,k; msg= (char **) GDKmalloc( 2000 * sizeof(str)); msg[top]=0; for(i=0; i< MAXSCOPE; i++) for(k=0; k< MAXSCOPE; k++){ m= scopeJump[i][k]; while( m){ for(j=0;j<MAXSCOPE;j++) if( m->subscope[j]) for(s= m->subscope[j]; s; s= s->peer) if( strstr(m->name,pat) || strstr(s->name,pat) || (s->def->help && strstr(s->def->help,pat))) { fcnDefinition(s->def,s->def->stmt[0],buf,FALSE); buf[0]=' '; if( s->def->help) { char *v,*w; v= strchr(buf,0); *v++ = '\\'; *v++ = 'n'; *v++ = '#'; for( w= s->def->help; *w && v <buf+BUFSIZ-1; w++) if( *w == '\n'){ *v++ = '\\'; *v++ = 'n'; *v++ = '#'; w++; if( isspace((int) *w)) { for(; *w && isspace((int) *w); w++); w--; } } else *v++ = *w; *v++ = '\\'; *v++ = 'n'; *v = 0; } msg[top++] = GDKstrdup(buf); msg[top] = 0; if( top == 1999) return msg; } m= m->sibling; } } return msg;}voidshowHelp(Module m, str txt, stream *fs){ int i; char **msg = getHelp(m,txt,TRUE); for(i=0; msg[i]; i++) stream_printf(fs,"%s\n",msg[i]); if( i == 0){ msg = getHelp(m,txt,0); for(i=0; msg[i]; i++) stream_printf(fs,"%s\n",msg[i]); }}@-The tags file is used by the MapiClient frontend toenable language specific word completion.@cvoid dumpHelpTable(stream *f, Module s, str text, int flag){ str *msg; int j,m; msg= getHelp(s,text,flag); for(m=0; msg[m]; m++ ) ; stream_printf(f,"&1 0 %d 1 %d\n",m,m); stream_printf(f,"# help # table_name\n"); stream_printf(f,"# name # name\n"); stream_printf(f,"# varchar # type\n"); stream_printf(f,"# 0 # length\n"); for(j=0; j<m; j++) { stream_printf(f,"[ \"%s\" ]\n",msg[j]); GDKfree(msg[j]); } GDKfree(msg);}void dumpSearchTable(stream *f, str text){ str *msg; int j,m; msg= getHelpMatch(text); for(m=0; msg[m]; m++ ) ; stream_printf(f,"&1 0 %d 1 %d\n",m,m); stream_printf(f,"# help # table_name\n"); stream_printf(f,"# name # name\n"); stream_printf(f,"# varchar # type\n"); stream_printf(f,"# 0 # length\n"); for(j=0; j<m; j++) { stream_printf(f,"[ \"%s\" ]\n",msg[j]); GDKfree(msg[j]); } GDKfree(msg);}@}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -