Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
AHash.txt433 linesDownload Raw Back to Adam
1 2#help_index "Info;Hash/System;Cmd Line (Typically)"3class CWho4{5  CHashGeneric *h;6  U8 *idx;7};8 9I64 HashEntriesCompare(CWho *h1,CWho *h2)10{11  I64 i1,i2;12  if (i1=StrCmp(h1->h->str,h2->h->str))13    return i1;14  i1=HashTypeNum(h1->h);15  i2=HashTypeNum(h2->h);16  return i1-i2;17}18 19I64 HashEntriesCompare2(CWho *h1,CWho *h2)20{21  CHashFun *tmpf1=h1->h,*tmpf2=h2->h;22  I64 i1=HashVal(tmpf1),i2=HashVal(tmpf2);23  if (i1==i2) {24    i1=HashTypeNum(tmpf1);25    i2=HashTypeNum(tmpf2);26    if (i1==i2)27      return StrCmp(tmpf1->str,tmpf2->str);28  }29  return i1-i2;30}31 32I64 HelpIndexCnt(U8 *ptr,U8 *idx)33{34  I64 cnt=0,ch,idx_len=StrLen(idx);35  while (*ptr) {36    if (!StrNCmp(ptr,idx,idx_len))37      cnt++;38    while (ch=*ptr++)39      if (ch==';')40        break;41    if (!ch)42      ptr--;43  }44  return cnt;45}46 47U8 *HelpIndexStr(U8 **_ptr,U8 *idx)48{49  U8 *ptr=*_ptr,*ptr2,*res;50  I64 ch,idx_len=StrLen(idx);51  while (*ptr) {52    ptr2=ptr;53    while (ch=*ptr++)54      if (ch==';')55        break;56    if (!ch)57      ptr--;58    *_ptr=ptr;59    if (!StrNCmp(ptr2,idx,idx_len)) {60      if (ch==';')61        ptr--;62      *ptr=0;63      res=StrNew(ptr2);64      *ptr=ch;65      return res;66    }67  }68  return NULL;69}70 71U8 *HelpComment(CTask *task,CHash *tmph,U8 *_src_link)72{73  CDoc *doc;74  CDocEntry *doc_e;75  U8 *res=NULL,*ptr,*ptr2,*src_link=StrNew(_src_link);76 77  if (*src_link=='F' && src_link[2]==':')78    *src_link='P';79  XTalkWait(task,"Ed(0x%X,DOF_DONT_WINMGR_SYNC|DOF_DONT_SHOW);\n",src_link);80  Free(src_link);81 82  doc=DocPut(task);83  doc_e=doc->cur_entry;84  if (tmph->type&HTT_FUN) {85    if (Bt(&tmph(CHashFun *)->flags,Ff__EXTERN) ||86          Bt(&tmph(CHashFun *)->flags,Ff_INTERNAL))87      while (doc_e!=doc &&88            (!(doc_e->de_flags&DOCEF_TAG)||!StrOcc(doc_e->tag,';')))89        doc_e=doc_e->next;90    else91      while (doc_e!=doc &&92            (!(doc_e->de_flags&DOCEF_TAG)||!StrOcc(doc_e->tag,'{')))93        doc_e=doc_e->next;94  }95  if (doc_e!=doc) {96    if (doc_e->de_flags&DOCEF_TAG) {97      ptr=doc_e->tag;98      if (ptr2=StrMatch("//",ptr))99        ptr=ptr2+2;100      else if (ptr2=StrMatch("/*",ptr))101        ptr=ptr2+2;102      else if (!StrNCmp(ptr,"public",6))103        ptr+=6;104      while (*ptr==CH_SPACE)105        ptr++;106      res=StrNew(ptr);107      doc_e=doc_e->next;108    }109    while (doc_e!=doc && doc_e->type_u8!=DOCT_NEW_LINE) {110      if (doc_e->type_u8==DOCT_TAB) {111        ptr=MStrPrint("%s ",res);112        Free(res);113        res=ptr;114      } else if (doc_e->de_flags&DOCEF_TAG) {115        ptr=MStrPrint("%s%s",res,doc_e->tag);116        Free(res);117        res=ptr;118      }119      doc_e=doc_e->next;120    }121  }122  XTalkWait(task,"%c",CH_SHIFT_ESC);123  if (res) {124    ptr=MStrUtil(res,SUF_REM_TRAILING|SUF_REM_LEADING|SUF_SINGLE_SPACE);125    Free(res);126    res=ptr;127  }128  return res;129}130 131I64 HashEntriesCompare3(CWho *h1,CWho *h2)132{133  I64 i,i1=0,i2=0;134  i=StrCmp(h1->idx,h2->idx);135  if (i)136    return i;137  else {138    if (h1->h->type&HTT_HELP_FILE)139      i1=1;140    if (h2->h->type&HTT_HELP_FILE)141      i2=1;142    i=i2-i1;143    if (i)144      return i;145    else146      return StrCmp(h1->h->str,h2->h->str);147  }148}149 150public U0 Who(U8 *fu_flags=NULL,CHashTable *h=NULL,151U8 *idx=NULL,CDoc *doc=NULL)152{//Dump hash symbol table.153// "+p" for only public symbols154  // "+m" to order by number (normally alphabetical)155  // "-r" just local hash table156  CHashTable *table;157  CHashSrcSym *tmph;158  CHashGeneric *ptr;159  CWho *lst;160  I64 cnt,i,j,k,f=0;161  U8 buf[512],*last_idx=StrNew(""),*cur_idx,*comment;162  Bool recurse,publics,map;163  CTask *task;164 165  ScanFlags(&f,Define("ST_FILE_UTIL_FLAGS"),"+r");166  ScanFlags(&f,Define("ST_FILE_UTIL_FLAGS"),fu_flags);167  if (f&~(FUF_RECURSE|FUF_PUBLIC|FUF_MAP))168    throw('FUF');169  recurse=Bt(&f,FUf_RECURSE);170  publics=Bt(&f,FUf_PUBLIC);171  map    =Bt(&f,FUf_MAP);172 173  if (!h) h=Fs->hash_table;174 175  if (idx) {176    task=User;177    TaskWait(task);178    LBtr(&task->display_flags,DISPLAYf_SHOW);179  } else180    task=NULL;181 182  cnt=0;183  table=h;184  while (table) {185    for (i=0;i<=table->mask;i++) {186      tmph=table->body[i];187      while (tmph) {188        if (!(tmph->type & (HTF_IMPORT | HTF_PRIVATE)) &&189              (tmph->type & HTF_PUBLIC || !publics)) {190          if (!idx)191            cnt++;192          else if (tmph->type&HTG_SRC_SYM && (cur_idx=tmph->idx))193            cnt+=HelpIndexCnt(cur_idx,idx);194        }195        tmph=tmph->next;196      }197    }198    if (recurse)199      table=table->next;200    else201      break;202  }203  if (!cnt) goto wh_done;204 205  lst=CAlloc(cnt*sizeof(CWho));206  j=0;207  table=h;208  while (table) {209    for (i=0;i<=table->mask;i++) {210      tmph=table->body[i];211      while (tmph) {212        if (!(tmph->type & (HTF_IMPORT | HTF_PRIVATE)) &&213              (tmph->type & HTF_PUBLIC || !publics))214          if (!idx)215            lst[j++].h=tmph;216          else if (tmph->type&HTG_SRC_SYM && (cur_idx=tmph->idx) &&217                (k=HelpIndexCnt(cur_idx,idx)))218            while (k--) {219              lst[j].idx=HelpIndexStr(&cur_idx,idx);220              lst[j++].h=tmph;221            }222        tmph=tmph->next;223      }224    }225    if (recurse)226      table=table->next;227    else228      break;229  }230 231  if (map)232    QSort(lst,cnt,sizeof(CWho),&HashEntriesCompare2);233  else if (idx)234    QSort(lst,cnt,sizeof(CWho),&HashEntriesCompare3);235  else236    QSort(lst,cnt,sizeof(CWho),&HashEntriesCompare);237 238  if (idx) {239    progress1_max=cnt;240    progress1=0;241  }242  for (i=0;i<cnt;i++) {243    comment=NULL;244    ptr=lst[i].h;245    if (idx)246      if (cur_idx=lst[i].idx) {247        if (StrCmp(cur_idx,last_idx)) {248          Free(last_idx);249          last_idx=StrNew(cur_idx);250          if (i)251            DocPrint(doc,"\n\n");252          DocPrint(doc,"$WW,0$$PURPLE$$TX+CX,\"%$Q\"$$FG$\n",cur_idx);253        }254      }255 256    if (idx && ptr->type & HTT_HELP_FILE) {257      DocPrint(doc,"$WW,1$");258      DocType(doc,ptr->str);259      DocPrint(doc,"$WW,0$");260    } else {261      if (ptr->type&HTG_SRC_SYM && ptr(CHashSrcSym *)->src_link) {262        DocPrint(doc,"$LK,\"%-20s\",A=\"%s\"$",263              ptr->str,ptr(CHashSrcSym *)->src_link);264        if (idx)265          comment=HelpComment(task,ptr,ptr(CHashSrcSym *)->src_link);266      } else267        DocPrint(doc,"%-20s",ptr->str);268 269      if (!idx) {270        if (ptr->type & HTT_DEFINE_STR) {271          j=ptr(CHashDefineStr *)->cnt;272          if (j==-1)273            StrPrint(buf,"%-10t$Q   ",ptr(CHashDefineStr *)->data);274          else275            StrPrint(buf,"%-10t$Q %02X",ptr(CHashDefineStr *)->data,j);276        } else if (ptr->type & HTT_GLBL_VAR)277          StrPrint(buf,"%010X   ",ptr(CHashGlblVar *)->data_addr);278        else279          StrPrint(buf,"%010X   ",HashVal(ptr));280        j=HashEntrySize(ptr);281        if (j==-1)282          CatPrint(buf," %04X            ",ptr->use_cnt);283        else284          CatPrint(buf," %04X %010X ",ptr->use_cnt,j);285      } else286        *buf=0;287 288      k=ptr->type;289      if (publics)290        k&=~HTF_PUBLIC;291      if (!(k&HTG_TYPE_MASK))292        CatPrint(buf,"NULL ");293      while (k) {294        j=Bsf(k);295        if (j<0)296          break;297        Btr(&k,j);298        CatPrint(buf,"%Z ",j,"ST_HTT_TYPES");299      }300      DocPrint(doc,"%s",buf);301      if (comment) {302        DocPrint(doc,"$GREEN$%s$FG$",comment);303        Free(comment);304      }305      DocPrint(doc,"\n");306    }307    Free(lst[i].idx);308    if (idx)309      progress1++;310  }311  Free(lst);312  if (idx)313    progress1=progress1_max=0;314 315wh_done:316  if (doc) {317    if (doc->head.next==doc)318      DocPrint(doc,"No Match");319    else320      DocRecalc(doc);321  }322  Free(last_idx);323  Kill(task);324}325 326#help_index "Info;Hash;Cmd Line (Typically)"327 328#define HDR_NUM 16329public I64 HashDepthRep(CHashTable *table=NULL)330{//Hash table linked-list chain depth report.331//Histogram of collision count.332  I64 i,j,longest=0,cnt=0,a[HDR_NUM];333  CHash *tmph;334  if (!table) table=Fs->hash_table;335  MemSet(a,0,sizeof(a));336  for (i=0;i<=table->mask;i++) {337    tmph=table->body[i];338    if (tmph) {339      j=LinkedLstCnt(tmph);340      if (j<HDR_NUM)341        a[j]++;342      cnt+=j;343      if (j>longest)344        longest=j;345    }346  }347  "Histogram\n";348  for (i=0;i<HDR_NUM;i++)349    if (a[i])350      "%02d:%d\n",i,a[i];351  "Size:%d Count:%d Longest:%d\n",352        table->mask+1,cnt,longest;353  return longest;354}355 356#help_index "Help System"357#help_file "::/Doc/HelpSystem"358 359public U0 DocHelpIdx(CDoc *doc,U8 *idx)360{//Put to doc report for given help idx.361  Who("+p",,idx,doc);362}363 364public U0 PopUpHelpIndex(U8 *idx,CTask *parent=NULL)365{//PopUp win report for given help idx.366  U8 *buf;367  buf=MStrPrint("DocHelpIdx(DocPut,\"%s\");View;",idx);368  PopUp(buf,parent);369  Free(buf);370}371 372#help_index "Hash/System"373public U0 MapFileLoad(U8 *filename)374{//Load map file so we have src line info.375  U8 *st,*ptr,*name=ExtDft(filename,"MAP.Z"),376        *absname=FileNameAbs(name);377  CDoc *doc=DocRead(name);378  CDocEntry *doc_e;379  CHashSrcSym *tmph;380  I64 i,j,base=0;381  CDbgInfo *dbg_info;382 383  FileExtRem(absname);384  if (absname[1]==':' && StrLen(absname)>2 &&385        (tmph=HashSingleTableFind(absname+2,Fs->hash_table,HTT_MODULE)))386    base=tmph(CHashGeneric *)->user_data0+sizeof(CBinFile);387 388  if (!doc) return;389  doc_e=doc->head.next;390  while (doc_e!=doc) {391    if (doc_e->type_u8==DOCT_LINK) {392      if (*doc_e->tag)393        st=MStrUtil(doc_e->tag,SUF_REM_TRAILING);394      else395        st=MStrUtil(doc_e->aux_str,SUF_REM_TRAILING);396      if (tmph=HashSingleTableFind(st,Fs->hash_table,HTG_SRC_SYM)) {397        if (*doc_e->tag) {398          Free(tmph->src_link);399          tmph->src_link=doc_e->aux_str;400          ptr=tmph->src_link;401          if (ptr[0] && ptr[1] && ptr[2]==':') {402            if (ptr[3]==':')403              ptr[3]=blkdev.boot_drv_let;404            else if (ptr[3]=='~')405              ptr[3]=*blkdev.home_dir;406          }407          doc_e->aux_str=NULL;408        }409        if (tmph->type&(HTT_FUN|HTT_EXPORT_SYS_SYM) &&410              !(dbg_info=tmph->dbg_info) && doc_e->bin_data &&411              (dbg_info=doc_e->bin_data->data)) {412          if (doc_e->bin_data->size>MSize(dbg_info))413            "Corrupt Map Entry\n";414          else {415            doc_e->bin_data->data=NULL;416            tmph->dbg_info=dbg_info;417            for (i=dbg_info->min_line;i<=dbg_info->max_line+1;i++) {418              j=i-dbg_info->min_line;419              if (dbg_info->body[j])420                dbg_info->body[j]=dbg_info->body[j]+base;421            }422          }423        }424      }425      Free(st);426    }427    doc_e=doc_e->next;428  }429  DocDel(doc);430  Free(name);431  Free(absname);432}433