Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
DocBin.txt144 linesDownload Raw Back to DolDoc
1 2#help_index "DolDoc/Bin"3 4CDocBin *DocBinFindNum(CDoc *haystack_doc,I64 needle_num)5{6  CDocBin *b=haystack_doc->bin_head.next;7  while (b!=&haystack_doc->bin_head) {8    if (b->num==needle_num)9      return b;10    b=b->next;11  }12  return NULL;13}14 15CDocBin *DocBinFindTag(CDoc *haystack_doc,U8 *needle_tag)16{17  CDocBin *b;18  if (needle_tag) {19    b=haystack_doc->bin_head.next;20    while (b!=&haystack_doc->bin_head) {21      if (b->tag && !StrCmp(b->tag,needle_tag))22        return b;23      b=b->next;24    }25  }26  return NULL;27}28 29U0 DocBinsValidate(CDoc *doc)30{31  Bool unlock=DocLock(doc);32  CDocBin *b,*b1;33  CDocEntry *doc_e,*doc_e2;34  I64 renum_num=0;35  b=doc->bin_head.next;36  while (b!=&doc->bin_head) {37    b->use_cnt=0;38    b->tmp_use_cnt=0;39    b->renum_num=-1;40    Free(b->tag);41    b->tag=NULL;42    b=b->next;43  }44  doc_e=doc->head.next;45  while (doc_e!=doc) {46    doc_e2=doc_e->next;47    if (doc_e->de_flags & DOCEF_HAS_BIN) {48      if (b=doc_e->bin_data=DocBinFindNum(doc,doc_e->bin_num)) {49        if (doc_e->de_flags & DOCEF_BIN_PTR_LINK)50          b->tmp_use_cnt=I32_MAX;51        if (!b->use_cnt++)52          b->renum_num=++renum_num;53        doc_e->bin_num=b->renum_num;54        if (!b->tag && doc_e->de_flags&DOCEF_TAG && doc_e->tag && *doc_e->tag)55          b->tag=StrNew(doc_e->tag,doc->mem_task);56      } else {57        RawPrint(3000,"Bin Not Found");58        doc_e->type=doc_e->de_flags=0;59        doc_e->type_u8=DOCT_ERROR;60      }61    }62    doc_e=doc_e2;63  }64 65  b=doc->bin_head.next;66  doc->cur_bin_num=1;67  while (b!=&doc->bin_head) {68    b1=b->next;69    if (!b->use_cnt) {70      QueRem(b);71      Free(b->data);72      Free(b);73    } else {74      b->num=b->renum_num;75      if (b->num>=doc->cur_bin_num)76        doc->cur_bin_num=b->num+1;77    }78    b=b1;79  }80  if (unlock)81    DocUnlock(doc);82}83 84U0 DocBinDel(CDoc *doc,CDocBin *b)85{86  if (doc && b && b->use_cnt) {87    b->use_cnt--;88    if (!b->use_cnt) {89      QueRem(b);90      Free(b->tag);91      Free(b->data);92      Free(b);93    }94  } else95    RawPrint(3000,"DocBinDel");96}97 98I64 DocBinPtrRst(CDoc *doc,CDocEntry *doc_e)99{100  U8 *st,*st2;101  CDoc *doc2;102  CDocBin *tmpb,*tmpb2;103  I64 i,bin_num=0;104  if (doc_e->de_flags&DOCEF_HAS_BIN &&105        doc_e->bin_ptr_link && StrLen(doc_e->bin_ptr_link)) {106    bin_num=doc_e->bin_num;107    st=StrNew(doc_e->bin_ptr_link);108    st2=StrNew(st);109    StrLastRem(st,",",st2);110    i=Str2I64(st2);111    if (i>0||*st2) {112      doc2=DocRead(st);113      if (i>0  && (tmpb2=DocBinFindNum(doc2,i)) ||114            i==0 && (tmpb2=DocBinFindTag(doc2,st2))) {115        i=1;116        if (bin_num>0) {117          if (tmpb=DocBinFindNum(doc,bin_num)) {118            i=tmpb->use_cnt;119            DocBinDel(doc,tmpb);120          }121        } else122          bin_num=doc->cur_bin_num++;123        tmpb=MAllocIdent(tmpb2,doc->mem_task);124        tmpb->use_cnt=i;125        tmpb->data=MAllocIdent(tmpb2->data,doc->mem_task);126        tmpb->num=bin_num;127        doc_e->bin_data=tmpb;128        if (doc_e->de_flags&DOCEF_TAG && doc_e->tag && *doc_e->tag)129          tmpb->tag=StrNew(doc_e->tag,doc->mem_task);130        else131          tmpb->tag=NULL;132        QueIns(tmpb,doc->bin_head.last);133      } else134        bin_num=0;135      DocDel(doc2);136    } else137      bin_num=0;138    Free(st2);139    Free(st);140    doc_e->bin_num=bin_num;141  }142  return bin_num;143}144