// Source: D:\TempleOS-Projects\html\Define-Demo.html
// Date: unknown-date
// Language: HolyC

//See Define.

//These might be in the Adam task.
DefineLoad("ST_YES_NO","(Yes or No)");
DefineLoad("ST_EXIT","Exit");
DefineLstLoad("ST_NO_YES_LST","No\0Yes\0");

//New strings might be loaded for each user
//to override.

"Spanish";
if (YorN) {
  DefineLoad("ST_YES_NO","(Si or No)");
  DefineLoad("ST_EXIT","Salida");
  DefineLstLoad("ST_NO_YES_LST","No\0Si\0");
}

Bool Quit()
{
  Bool res;
  U8 *st;
  I64 i;
  while (TRUE) {
    "%S %S?","ST_EXIT","ST_YES_NO";
    st=GetStr;
    i=DefineMatch(st,"ST_NO_YES_LST",LMF_IGNORE_CASE);
    if (i>=0) {
      res=i;
      break;
    }
    Free(st);
  }
  return res;
}

Quit;

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\Define-Demo.html
// Date: unknown-date
// Language: HolyC

//See Define.

//These might be in the Adam task.
DefineLoad("ST_YES_NO","(Yes or No)");
DefineLoad("ST_EXIT","Exit");
DefineLstLoad("ST_NO_YES_LST","No\0Yes\0");

//New strings might be loaded for each user
//to override.

"Spanish";
if (YorN) {
  DefineLoad("ST_YES_NO","(Si or No)");
  DefineLoad("ST_EXIT","Salida");
  DefineLstLoad("ST_NO_YES_LST","No\0Si\0");
}

Bool Quit()
{
  Bool res;
  U8 *st;
  I64 i;
  while (TRUE) {
    "%S %S?","ST_EXIT","ST_YES_NO";
    st=GetStr;
    i=DefineMatch(st,"ST_NO_YES_LST",LMF_IGNORE_CASE);
    if (i>=0) {
      res=i;
      break;
    }
    Free(st);
  }
  return res;
}

Quit;


// Source: D:\TempleOS-Projects\html\DskRaw-Dsk-Demo.html
// Date: unknown-date
// Language: HolyC

U0 RawAccess(I64 drv_let=0)
{
  CDrv *dv=Let2Drv(drv_let);
  CBlkDev *bd=Let2BlkDev(drv_let);
  I64 blk,old_offset,old_size;
  U8 *buf=MAlloc(BLK_SIZE);

  DrvRep;
  PressAKey;

  ClassRep(dv);
  PressAKey;

  ClassRep(bd);
  PressAKey;

  //Temporarily change partition range to full device.
  //Normally, you are limited to just your partition.
  //This is obviously dangerous!
  old_offset=dv->drv_offset;
  old_size  =dv->size;
  dv->drv_offset=0;
  dv->size=bd->max_blk+1;

  try {
    blk=GetI64("Blk to Read: ",old_offset,0,bd->max_blk);
    BlkRead(dv,buf,blk,1);
    D(buf,BLK_SIZE);
  } catch
    PutExcept;

  dv->drv_offset=old_offset;
  dv->size  =old_size;

  Free(buf);
}

RawAccess;

//See BlkRead(), BlkWrite(), DrvLock(), DrvUnlock()
//DBlk(), DClus(), BlkDevLock() and BlkDevUnlock().

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\DskRaw-Dsk-Demo.html
// Date: unknown-date
// Language: HolyC

U0 RawAccess(I64 drv_let=0)
{
  CDrv *dv=Let2Drv(drv_let);
  CBlkDev *bd=Let2BlkDev(drv_let);
  I64 blk,old_offset,old_size;
  U8 *buf=MAlloc(BLK_SIZE);

  DrvRep;
  PressAKey;

  ClassRep(dv);
  PressAKey;

  ClassRep(bd);
  PressAKey;

  //Temporarily change partition range to full device.
  //Normally, you are limited to just your partition.
  //This is obviously dangerous!
  old_offset=dv->drv_offset;
  old_size  =dv->size;
  dv->drv_offset=0;
  dv->size=bd->max_blk+1;

  try {
    blk=GetI64("Blk to Read: ",old_offset,0,bd->max_blk);
    BlkRead(dv,buf,blk,1);
    D(buf,BLK_SIZE);
  } catch
    PutExcept;

  dv->drv_offset=old_offset;
  dv->size  =old_size;

  Free(buf);
}

RawAccess;

//See BlkRead(), BlkWrite(), DrvLock(), DrvUnlock()
//DBlk(), DClus(), BlkDevLock() and BlkDevUnlock().


// Source: D:\TempleOS-Projects\html\ToHtml-ToHtmlToTXTDemo-Demo.html
// Date: unknown-date
// Language: HolyC

#help_index "DolDoc/Conversion"

//See ::/Doc/Credits.DD.

#define DOCET_UNDEF_COLOR       0x100000000
#define DOCET_LINK_UNDERLINE    0x200000000
U0 HtmlPutS(CDoc *doc,I64 u32_attr,I64 *_old_u32_attr,Bool underline_update,
        U8 *st,I64 *_col,U8 *style_bitmap=NULL)
{
  U8 *ch,*ptr;
  u32_attr&=0xFFFFFF00;
  if (u32_attr&DOCET_INVERT)
    u32_attr.u8[1]=(u32_attr.u8[1]&15)<<4|u32_attr.u8[1]>>4;
  if (underline_update &&
        !(u32_attr&DOCET_UNDERLINE) && *_old_u32_attr&DOCET_UNDERLINE) {
    if (!(*_old_u32_attr&DOCET_LINK_UNDERLINE))
      DocPrint(doc,"");
    *_old_u32_attr&=~DOCET_LINK_UNDERLINE;
  }
  if (!(u32_attr&DOCET_BLINK) && *_old_u32_attr&DOCET_BLINK)
    DocPrint(doc,"</blink>");
  if (u32_attr&0xFF00!=*_old_u32_attr&0xFF00) {
    if (!(*_old_u32_attr&DOCET_UNDEF_COLOR))
      DocPrint(doc,"");
    DocPrint(doc,"",u32_attr.u8[1]);
    if (style_bitmap)
      LBts(style_bitmap,u32_attr.u8[1]);
  }
  if (u32_attr&DOCET_BLINK && !(*_old_u32_attr&DOCET_BLINK))
    DocPrint(doc,"<blink>");
  if (underline_update) {
    if (u32_attr&DOCET_UNDERLINE && !(*_old_u32_attr&DOCET_UNDERLINE))
      DocPrint(doc,"");
  } else //Keep same underline status.
    u32_attr=u32_attr&~DOCET_UNDERLINE | *_old_u32_attr&DOCET_UNDERLINE;

  *_old_u32_attr=u32_attr | *_old_u32_attr&DOCET_LINK_UNDERLINE;

  while (ch=*st++) {
    switch (ch) {
      case '\t':
        do {
          DocPutKey(doc,CH_SPACE,0);
          *_col=*_col+1;
        } while (*_col&7);
        break;

      start:
        case 'pi':      ptr="pi";       break;
        case 'theta':   ptr="theta";    break;
        case 'phi':     ptr="phi";      break;
        case 'omega':   ptr="omega";    break;
        case 'inf':     ptr="inf";      break;
        case 'u':       ptr="u";        break;
      end:
        DocPrint(doc,ptr);
        *_col=*_col+StrLen(ptr);
        break;

      start:
        case CH_SHIFT_SPACE: ptr=" ";   break;
        case '&':       ptr="&";    break;
        case '<':       ptr="<";     break;
        case '>':       ptr=">";     break;
        case '"':       ptr=""";   break;
      end:
        DocPrint(doc,ptr);
        *_col=*_col+1;
        break;

      default:
        if (CH_SPACE<=ch<0x7F || ch=='\n')
          DocPutKey(doc,ch,0);
        else
          DocPrint(doc,".");
        *_col=*_col+1;
    }
  }
}

U8 *TOSLinkCvt2(U8 *filename,I64 line_num)
{// ::/  --> /Wb/
//Make your own LinkCvt routine
  U8 *res=NULL,*st;
  if (filename) {
    st=ExtChg(filename,"html");
    if (st && StrLen(st)>3 && !StrNCmp(st+1,":/",2))
      res=MStrPrint("/Wb/%s#l%d",st+3,line_num);
    Free(st);
  }
  return res;
}

U8 *URLBibleGateway(U8 *src)
{
  U8 buf[STR_LEN],*dst=buf;
  if (!MemCmp(src,"BF:",3))
    src+=3;
  while (*src) {
    if (*src==CH_SPACE || *src==',')
      *dst++='+';
    else
      *dst++=*src;
    src++;
  }
  *dst=0;
  if (StrOcc(buf,'-'))
    return MStrPrint(
          "http://www.biblegateway.com/passage/?search=%s&version=NIV",buf);
  else
    return MStrPrint(
          "http://www.biblegateway.com/verse/en/%s",buf);
}

U8 *TOSLinkCvt1(U8 *link_st)
{
  static CDoc *bible=NULL;
  static I64 locks=0;
  U8 *res=NULL,*filename,*needle;
  I64 i,num;
  if (link_st) {
    switch (i=EdLinkCvt(link_st,&filename,&needle,&num)) {
      case LK_FILE_LINE:
      case LK_PLAIN_LINE:
      case LK_FILE:
        res=TOSLinkCvt2(filename,num);
        break;
      case -1:
      case LK_DEF:
      case LK_HELP_INDEX:
      case LK_DOC:
      case LK_DOC_ANCHOR:
      case LK_DOC_FIND:
      case LK_DOC_LINE:
        break;
      case LK_BIBLE_FIND:
        while (LBts(&locks,0))
          Yield;
        if (!bible)
          bible=Adam("DocRead(\"%s\");",filename);
        if (DocFind(bible,num,needle))
          res=URLBibleGateway(link_st);
        LBtr(&locks,0);
        break;
      default:
        if (DocFileEd(i,filename,needle,&num,EDF_UNCOLLAPSE|EDF_BAIL))
          res=TOSLinkCvt2(filename,num);
    }
    Free(filename);
    Free(needle);
  }
  return res;
}

public CDoc *Doc2Html(CDoc *doc_in,U8 *html_header=NULL,U8 *body_header=NULL,
        U8 *body_footer=NULL,U8 *html_footer=NULL,Bool line_anchors=TRUE,
        U8 (*link_cvt)(U8 *link_st)=&TOSLinkCvt1,Bool line_nums=FALSE)
{//Cvt DolDocdoc to HTML file.
  CDocEntry *doc_e,*style,*doc_e2;
  I64 i,y,old_y=I64_MIN,col,old_u32_attr=DOCET_UNDEF_COLOR,old_attr,digits;
  U32 *hl,*src;
  U8 *st,st_2[2],*link_st,*style_bitmap=CAlloc(256/8);
  CBGR48 p[COLORS_NUM];
  GrPaletteGet(p);
  CDoc *doc_out=DocNew;
  Bool unlock_doc_in=DocLock(doc_in),no_bwd;

  old_attr=doc_in->win_task->text_attr;
  doc_in->win_task->text_attr=DOC_ATTR_DFT_TEXT;

  for (i=0xF0;i<=0xFF;i++)
    LBts(style_bitmap,i);

  DocRecalc(doc_in,RECALCt_NORMAL|RECALCF_TO_HTML);

  digits=Log10(doc_in->head.last->y+1)+1;

  st_2[0]=0; st_2[1]=0;
  doc_out->flags|=DOCF_PLAIN_TEXT|DOCF_NO_CURSOR;

  if (!html_header) html_header=
          "<!DOCTYPE HTML>\n"
          "\n"
          "\n"
          "<meta http-equiv=\"Content-Type\" "
          "content=\"text/html;charset=US-ASCII\">\n"
          "<meta name=\"generator\" content=\"TempleOS V5.03\">\n";
  if (!body_header) body_header=
          "\n"
          "
\n";
  if (!body_footer) body_footer=
          "
\n\n";
  if (!html_footer) html_footer=
          "\n";

  DocPrint(doc_out,"%s",html_header);

  DocPrint(doc_out,"\n"
        "\n");
  DocPrint(doc_out,"%s",body_header);

  doc_e=doc_in->head.next;
  col=doc_e->x;
  y=doc_e->y;
  while (doc_e!=doc_in) {
    if (!(doc_e->de_flags&DOCEF_SKIP)) {
      if (y!=old_y) {
        if (line_anchors)
          DocPrint(doc_out,"",y+1);
        if (line_nums)
          DocPrint(doc_out,"%0*d ",digits,y+1);
        old_y=y;
      }

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\ToHtml-ToHtmlToTXTDemo-Demo.html
// Date: unknown-date
// Language: HolyC

#help_index "DolDoc/Conversion"

//See ::/Doc/Credits.DD.

#define DOCET_UNDEF_COLOR       0x100000000
#define DOCET_LINK_UNDERLINE    0x200000000
U0 HtmlPutS(CDoc *doc,I64 u32_attr,I64 *_old_u32_attr,Bool underline_update,
        U8 *st,I64 *_col,U8 *style_bitmap=NULL)
{
  U8 *ch,*ptr;
  u32_attr&=0xFFFFFF00;
  if (u32_attr&DOCET_INVERT)
    u32_attr.u8[1]=(u32_attr.u8[1]&15)<<4|u32_attr.u8[1]>>4;
  if (underline_update &&
        !(u32_attr&DOCET_UNDERLINE) && *_old_u32_attr&DOCET_UNDERLINE) {
    if (!(*_old_u32_attr&DOCET_LINK_UNDERLINE))
      DocPrint(doc,"");
    *_old_u32_attr&=~DOCET_LINK_UNDERLINE;
  }
  if (!(u32_attr&DOCET_BLINK) && *_old_u32_attr&DOCET_BLINK)
    DocPrint(doc,"</blink>");
  if (u32_attr&0xFF00!=*_old_u32_attr&0xFF00) {
    if (!(*_old_u32_attr&DOCET_UNDEF_COLOR))
      DocPrint(doc,"");
    DocPrint(doc,"",u32_attr.u8[1]);
    if (style_bitmap)
      LBts(style_bitmap,u32_attr.u8[1]);
  }
  if (u32_attr&DOCET_BLINK && !(*_old_u32_attr&DOCET_BLINK))
    DocPrint(doc,"<blink>");
  if (underline_update) {
    if (u32_attr&DOCET_UNDERLINE && !(*_old_u32_attr&DOCET_UNDERLINE))
      DocPrint(doc,"");
  } else //Keep same underline status.
    u32_attr=u32_attr&~DOCET_UNDERLINE | *_old_u32_attr&DOCET_UNDERLINE;

  *_old_u32_attr=u32_attr | *_old_u32_attr&DOCET_LINK_UNDERLINE;

  while (ch=*st++) {
    switch (ch) {
      case '\t':
        do {
          DocPutKey(doc,CH_SPACE,0);
          *_col=*_col+1;
        } while (*_col&7);
        break;

      start:
        case 'pi':      ptr="pi";       break;
        case 'theta':   ptr="theta";    break;
        case 'phi':     ptr="phi";      break;
        case 'omega':   ptr="omega";    break;
        case 'inf':     ptr="inf";      break;
        case 'u':       ptr="u";        break;
      end:
        DocPrint(doc,ptr);
        *_col=*_col+StrLen(ptr);
        break;

      start:
        case CH_SHIFT_SPACE: ptr=" ";   break;
        case '&':       ptr="&";    break;
        case '<':       ptr="<";     break;
        case '>':       ptr=">";     break;
        case '"':       ptr=""";   break;
      end:
        DocPrint(doc,ptr);
        *_col=*_col+1;
        break;

      default:
        if (CH_SPACE<=ch<0x7F || ch=='\n')
          DocPutKey(doc,ch,0);
        else
          DocPrint(doc,".");
        *_col=*_col+1;
    }
  }
}

U8 *TOSLinkCvt2(U8 *filename,I64 line_num)
{// ::/  --> /Wb/
//Make your own LinkCvt routine
  U8 *res=NULL,*st;
  if (filename) {
    st=ExtChg(filename,"html");
    if (st && StrLen(st)>3 && !StrNCmp(st+1,":/",2))
      res=MStrPrint("/Wb/%s#l%d",st+3,line_num);
    Free(st);
  }
  return res;
}

U8 *URLBibleGateway(U8 *src)
{
  U8 buf[STR_LEN],*dst=buf;
  if (!MemCmp(src,"BF:",3))
    src+=3;
  while (*src) {
    if (*src==CH_SPACE || *src==',')
      *dst++='+';
    else
      *dst++=*src;
    src++;
  }
  *dst=0;
  if (StrOcc(buf,'-'))
    return MStrPrint(
          "http://www.biblegateway.com/passage/?search=%s&version=NIV",buf);
  else
    return MStrPrint(
          "http://www.biblegateway.com/verse/en/%s",buf);
}

U8 *TOSLinkCvt1(U8 *link_st)
{
  static CDoc *bible=NULL;
  static I64 locks=0;
  U8 *res=NULL,*filename,*needle;
  I64 i,num;
  if (link_st) {
    switch (i=EdLinkCvt(link_st,&filename,&needle,&num)) {
      case LK_FILE_LINE:
      case LK_PLAIN_LINE:
      case LK_FILE:
        res=TOSLinkCvt2(filename,num);
        break;
      case -1:
      case LK_DEF:
      case LK_HELP_INDEX:
      case LK_DOC:
      case LK_DOC_ANCHOR:
      case LK_DOC_FIND:
      case LK_DOC_LINE:
        break;
      case LK_BIBLE_FIND:
        while (LBts(&locks,0))
          Yield;
        if (!bible)
          bible=Adam("DocRead(\"%s\");",filename);
        if (DocFind(bible,num,needle))
          res=URLBibleGateway(link_st);
        LBtr(&locks,0);
        break;
      default:
        if (DocFileEd(i,filename,needle,&num,EDF_UNCOLLAPSE|EDF_BAIL))
          res=TOSLinkCvt2(filename,num);
    }
    Free(filename);
    Free(needle);
  }
  return res;
}

public CDoc *Doc2Html(CDoc *doc_in,U8 *html_header=NULL,U8 *body_header=NULL,
        U8 *body_footer=NULL,U8 *html_footer=NULL,Bool line_anchors=TRUE,
        U8 (*link_cvt)(U8 *link_st)=&TOSLinkCvt1,Bool line_nums=FALSE)
{//Cvt DolDocdoc to HTML file.
  CDocEntry *doc_e,*style,*doc_e2;
  I64 i,y,old_y=I64_MIN,col,old_u32_attr=DOCET_UNDEF_COLOR,old_attr,digits;
  U32 *hl,*src;
  U8 *st,st_2[2],*link_st,*style_bitmap=CAlloc(256/8);
  CBGR48 p[COLORS_NUM];
  GrPaletteGet(p);
  CDoc *doc_out=DocNew;
  Bool unlock_doc_in=DocLock(doc_in),no_bwd;

  old_attr=doc_in->win_task->text_attr;
  doc_in->win_task->text_attr=DOC_ATTR_DFT_TEXT;

  for (i=0xF0;i<=0xFF;i++)
    LBts(style_bitmap,i);

  DocRecalc(doc_in,RECALCt_NORMAL|RECALCF_TO_HTML);

  digits=Log10(doc_in->head.last->y+1)+1;

  st_2[0]=0; st_2[1]=0;
  doc_out->flags|=DOCF_PLAIN_TEXT|DOCF_NO_CURSOR;

  if (!html_header) html_header=
          "<!DOCTYPE HTML>\n"
          "\n"
          "\n"
          "<meta http-equiv=\"Content-Type\" "
          "content=\"text/html;charset=US-ASCII\">\n"
          "<meta name=\"generator\" content=\"TempleOS V5.03\">\n";
  if (!body_header) body_header=
          "\n"
          "
\n";
  if (!body_footer) body_footer=
          "
\n\n";
  if (!html_footer) html_footer=
          "\n";

  DocPrint(doc_out,"%s",html_header);

  DocPrint(doc_out,"\n"
        "\n");
  DocPrint(doc_out,"%s",body_header);

  doc_e=doc_in->head.next;
  col=doc_e->x;
  y=doc_e->y;
  while (doc_e!=doc_in) {
    if (!(doc_e->de_flags&DOCEF_SKIP)) {
      if (y!=old_y) {
        if (line_anchors)
          DocPrint(doc_out,"",y+1);
        if (line_nums)
          DocPrint(doc_out,"%0*d ",digits,y+1);
        old_y=y;
      }


// Source: D:\TempleOS-Projects\html\ACInit-AutoComplete-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "AutoComplete/Dictionary"
acd.has_words=FileFind(ACD_WORD_FILENAME);
acd.has_defs =FileFind(ACD_DEF_FILENAME)||FileFind(ACD_DEF_FILENAME_Z);

public U0 ACDWordsLoad()
{//Put words from word list into hash table.
  I64 size;
  CHashGeneric *tmph;
  U8 *in_ptr,*in_start,*st2;
  U16 *d;
  acd.num_words=0;
  if (in_ptr=FileRead(ACD_WORD_FILENAME,&size)) {
    in_start=in_ptr;
    Free(acd.word_lst);
    acd.word_lst=AMAlloc(size);
    MemCpy(acd.word_lst,in_start,size);
    acd.word_lst_size=size;

    while (in_ptr<in_start+size) {
      if (*in_ptr==ACD_WORD_CHAR)
        in_ptr++;
      if (*in_ptr) {
        st2=MStrUtil(in_ptr,SUF_TO_UPPER);
        tmph=ACAlloc(sizeof(CHashGeneric)+StrLen(st2)+1);
        StrCpy(tmph+1,st2);
        Free(st2);
        in_ptr+=StrLen(in_ptr)+1;
        tmph->str=tmph+1;
        tmph->use_cnt=1;
        tmph->type=HTT_DICT_WORD;
        d=in_ptr;
        tmph->user_data0=*d;
        in_ptr+=2;
        HashAdd(tmph,ac.hash_table);
        acd.num_words++;
      } else
        in_ptr+=3;
    }
    Free(in_start);
  }
}

#help_index "AutoComplete"
CHashAC *ACHashAdd(U8 *w)
{
  CHashAC *tmpw=HashFind(w,ac.hash_table,HTT_WORD);
  if (tmpw) {
    tmpw->hits++;
    return tmpw;
  }
  tmpw=ACAlloc(sizeof(CHashAC));
  tmpw->str=AStrNew(w);
  tmpw->type=HTT_WORD;
  tmpw->use_cnt=1;
  tmpw->hits=1;
  HashAdd(tmpw,ac.hash_table);
  ac.num_words++;
  return tmpw;
}

U0 ACSingleFileAdd(U8 *buf)
{
  I64 ch;
  U8 *ptr=buf,*ptr2,*ptr3;
  while (TRUE) {
    while (TRUE) {
      if (ch=*ptr++) {
        if (Bt(char_bmp_alpha_numeric,ch))
          break;
      } else
        return;
    }
    ptr3=ptr;
    ptr2=ptr;
    ptr--;
    while (TRUE) {
      if (ch=*ptr2++) {
        if (Bt(char_bmp_alpha_numeric,ch))
          *ptr3++=ch;
        else if (ch!=CH_CURSOR)
          break;
      } else {
        ptr2--;
        break;
      }
    }
    *ptr3=0;
    ACHashAdd(ptr);
    ptr=ptr2;
  }
}

U0 ACMainFileLstTraverse(U8 *files_find_mask)
{
  U8 *buf;
  CDirEntry *tmpde,*tmpde1;
  try {
    tmpde=tmpde1=FilesFind(files_find_mask,
          FUF_RECURSE|FUF_JUST_TXT|FUF_JUST_FILES|FUF_CLUS_ORDER);
    while (tmpde) {
      "%s\n",tmpde->full_name;
      buf=FileRead(tmpde->full_name);
      ACSingleFileAdd(buf);
      Free(buf);
      tmpde=tmpde->next;
    }
  } catch
    Fs->catch_except=TRUE;
  DirTreeDel(tmpde1);
}

U0 ACProgressTask(Bool *_start_flag)
{
  I64 start=blkdev.write_cnt;
  progress1=0;
  progress1_max=(Size(ACD_DEF_FILENAME_Z,"+x+s")+BLK_SIZE-1)>>BLK_SIZE_BITS;
  StrCpy(progress1_desc,"Uncompressing Dictionary");
  start=blkdev.write_cnt;
  *_start_flag=TRUE;
  while (progress1<progress1_max) {
    progress1=blkdev.write_cnt-start;
    Sleep(10);
  }
  *progress1_desc=progress1=progress1_max=0;
}

public U0 ACInit(U8 *mask=NULL)
{//Read files and build AutoComplete statistics.
  Bool start_flag;
  CBlkDev *bd=Let2BlkDev;

  LBtr(&sys_run_level,RLf_AUTO_COMPLETE);
  AutoComplete;
  while (LBts(&ac.flags,ACf_INIT_IN_PROGRESS))
    Yield;
  if (DrvIsWritable && FileFind(ACD_DEF_FILENAME_Z) &&
        !FileFind(ACD_DEF_FILENAME)) {
    if (bd->type!=BDT_RAM) {
      start_flag=FALSE;
      Spawn(&ACProgressTask,&start_flag);
      while (!start_flag)
        Yield;
    }
    Move(ACD_DEF_FILENAME_Z,ACD_DEF_FILENAME);
  }

  HashTableDel(ac.hash_table);
  ac.hash_table=HashTableNew(2048,adam_task);

  ac.num_words=0;
  Free(ac.cur_word);
  ac.cur_word=NULL;

  if (mask)
    ACMainFileLstTraverse(mask);

  ACDWordsLoad;
  LBtr(&ac.flags,ACf_INIT_IN_PROGRESS);
  LBts(&sys_run_level,RLf_AUTO_COMPLETE);
  AutoComplete(ON);
}

I64 AutoCompleteSize()
{
  if (ac.hash_table)
    return HashTableSize2(ac.hash_table)+MSize2(acd.word_lst);
  else
    return 0;
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\ACInit-AutoComplete-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "AutoComplete/Dictionary"
acd.has_words=FileFind(ACD_WORD_FILENAME);
acd.has_defs =FileFind(ACD_DEF_FILENAME)||FileFind(ACD_DEF_FILENAME_Z);

public U0 ACDWordsLoad()
{//Put words from word list into hash table.
  I64 size;
  CHashGeneric *tmph;
  U8 *in_ptr,*in_start,*st2;
  U16 *d;
  acd.num_words=0;
  if (in_ptr=FileRead(ACD_WORD_FILENAME,&size)) {
    in_start=in_ptr;
    Free(acd.word_lst);
    acd.word_lst=AMAlloc(size);
    MemCpy(acd.word_lst,in_start,size);
    acd.word_lst_size=size;

    while (in_ptr<in_start+size) {
      if (*in_ptr==ACD_WORD_CHAR)
        in_ptr++;
      if (*in_ptr) {
        st2=MStrUtil(in_ptr,SUF_TO_UPPER);
        tmph=ACAlloc(sizeof(CHashGeneric)+StrLen(st2)+1);
        StrCpy(tmph+1,st2);
        Free(st2);
        in_ptr+=StrLen(in_ptr)+1;
        tmph->str=tmph+1;
        tmph->use_cnt=1;
        tmph->type=HTT_DICT_WORD;
        d=in_ptr;
        tmph->user_data0=*d;
        in_ptr+=2;
        HashAdd(tmph,ac.hash_table);
        acd.num_words++;
      } else
        in_ptr+=3;
    }
    Free(in_start);
  }
}

#help_index "AutoComplete"
CHashAC *ACHashAdd(U8 *w)
{
  CHashAC *tmpw=HashFind(w,ac.hash_table,HTT_WORD);
  if (tmpw) {
    tmpw->hits++;
    return tmpw;
  }
  tmpw=ACAlloc(sizeof(CHashAC));
  tmpw->str=AStrNew(w);
  tmpw->type=HTT_WORD;
  tmpw->use_cnt=1;
  tmpw->hits=1;
  HashAdd(tmpw,ac.hash_table);
  ac.num_words++;
  return tmpw;
}

U0 ACSingleFileAdd(U8 *buf)
{
  I64 ch;
  U8 *ptr=buf,*ptr2,*ptr3;
  while (TRUE) {
    while (TRUE) {
      if (ch=*ptr++) {
        if (Bt(char_bmp_alpha_numeric,ch))
          break;
      } else
        return;
    }
    ptr3=ptr;
    ptr2=ptr;
    ptr--;
    while (TRUE) {
      if (ch=*ptr2++) {
        if (Bt(char_bmp_alpha_numeric,ch))
          *ptr3++=ch;
        else if (ch!=CH_CURSOR)
          break;
      } else {
        ptr2--;
        break;
      }
    }
    *ptr3=0;
    ACHashAdd(ptr);
    ptr=ptr2;
  }
}

U0 ACMainFileLstTraverse(U8 *files_find_mask)
{
  U8 *buf;
  CDirEntry *tmpde,*tmpde1;
  try {
    tmpde=tmpde1=FilesFind(files_find_mask,
          FUF_RECURSE|FUF_JUST_TXT|FUF_JUST_FILES|FUF_CLUS_ORDER);
    while (tmpde) {
      "%s\n",tmpde->full_name;
      buf=FileRead(tmpde->full_name);
      ACSingleFileAdd(buf);
      Free(buf);
      tmpde=tmpde->next;
    }
  } catch
    Fs->catch_except=TRUE;
  DirTreeDel(tmpde1);
}

U0 ACProgressTask(Bool *_start_flag)
{
  I64 start=blkdev.write_cnt;
  progress1=0;
  progress1_max=(Size(ACD_DEF_FILENAME_Z,"+x+s")+BLK_SIZE-1)>>BLK_SIZE_BITS;
  StrCpy(progress1_desc,"Uncompressing Dictionary");
  start=blkdev.write_cnt;
  *_start_flag=TRUE;
  while (progress1<progress1_max) {
    progress1=blkdev.write_cnt-start;
    Sleep(10);
  }
  *progress1_desc=progress1=progress1_max=0;
}

public U0 ACInit(U8 *mask=NULL)
{//Read files and build AutoComplete statistics.
  Bool start_flag;
  CBlkDev *bd=Let2BlkDev;

  LBtr(&sys_run_level,RLf_AUTO_COMPLETE);
  AutoComplete;
  while (LBts(&ac.flags,ACf_INIT_IN_PROGRESS))
    Yield;
  if (DrvIsWritable && FileFind(ACD_DEF_FILENAME_Z) &&
        !FileFind(ACD_DEF_FILENAME)) {
    if (bd->type!=BDT_RAM) {
      start_flag=FALSE;
      Spawn(&ACProgressTask,&start_flag);
      while (!start_flag)
        Yield;
    }
    Move(ACD_DEF_FILENAME_Z,ACD_DEF_FILENAME);
  }

  HashTableDel(ac.hash_table);
  ac.hash_table=HashTableNew(2048,adam_task);

  ac.num_words=0;
  Free(ac.cur_word);
  ac.cur_word=NULL;

  if (mask)
    ACMainFileLstTraverse(mask);

  ACDWordsLoad;
  LBtr(&ac.flags,ACf_INIT_IN_PROGRESS);
  LBts(&sys_run_level,RLf_AUTO_COMPLETE);
  AutoComplete(ON);
}

I64 AutoCompleteSize()
{
  if (ac.hash_table)
    return HashTableSize2(ac.hash_table)+MSize2(acd.word_lst);
  else
    return 0;
}


// Source: D:\TempleOS-Projects\html\Start-Doc.html
// Date: unknown-date
// Language: HolyC

TempleOS V5.03

                         Public Domain Operating System

Help & Index, Quick Start: Cmd line

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\Start-Doc.html
// Date: unknown-date
// Language: HolyC

TempleOS V5.03

                         Public Domain Operating System

Help & Index, Quick Start: Cmd line


// Source: D:\TempleOS-Projects\html\SpanMain-Span-Apps.html
// Date: unknown-date
// Language: HolyC

F64 SpanTime()
{
  if (run_bttn.state)
    return a.elapsed_t+tS-a.start_wall_t;
  else
    return a.elapsed_t;
}

F64 Cost(CMathODE *ode)
{
  MyMass   *tmpm;
  MySpring *tmps;
  F64 res=0;
  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    res+=tmpm->cost;
    tmpm=tmpm->next;
  }
  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    res+=tmps->cost;
    tmps=tmps->next;
  }
  return res;
}

U0 DrawIt(CTask *task,CDC *dc)
{
  MyMass   *tmpm;
  MySpring *tmps;

  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    if (!(tmps->flags&SSF_INACTIVE)) {
      dc->color=tmps->color;
      dc->thick=tmps->thick;
      GrLine3(dc,tmps->end1->x,tmps->end1->y,0,
            tmps->end2->x,tmps->end2->y,0);
    }
    tmps=tmps->next;
  }

  if (cursor_mass) {
    dc->color=RED;
    dc->thick=2;
    GrLine3(dc,ms.pos.x-task->pix_left-task->scroll_x,
          ms.pos.y-task->pix_top-task->scroll_y,0,
          cursor_mass->x,cursor_mass->y,0);
  }

  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    if (!(tmpm->flags&MSF_INACTIVE)) {
      dc->color=BLACK;
      GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
      GrFloodFill(dc,tmpm->x,tmpm->y,TRUE);
      dc->color=tmpm->color;
      GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
      GrFloodFill(dc,tmpm->x,tmpm->y,TRUE);
      dc->color=BLACK;
      GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
    }
    tmpm=tmpm->next;
  }

  dc->color=BLACK;
  GrPrint(dc,90,0,"Cost:%12.2,f",Cost(ode));
  GrPrint(dc,90,FONT_HEIGHT,"Time:%12.2f",SpanTime);
}

MyMass *PlaceMass(I64 x, I64 y)
{
  MyMass *tmpm=CAlloc(sizeof(MyMass));
  tmpm->drag_profile_factor=1.0;
  tmpm->x=x;
  tmpm->y=y;
  tmpm->mass=MASS_MASS;
  tmpm->radius=MASS_RADIUS;
  tmpm->cost=25.0*COST_SCALE;
  tmpm->color=YELLOW;
  QueIns(tmpm,ode->last_mass);
  return tmpm;
}

U0 NullSpring(MySpring *tmps,F64 scale)
{
  F64 d=D3Dist(&tmps->end1->x,&tmps->end2->x);
  tmps->rest_len=d*scale;
  tmps->compression_strength=
        tmps->base_compression_strength/(tmps->rest_len+1.0);
  tmps->tensile_strength=tmps->base_tensile_strength/(tmps->rest_len+1.0);
  tmps->const=tmps->base_const/(tmps->rest_len+1.0);
  tmps->cost=tmps->base_cost*tmps->rest_len;
}

U0 MoveMass(MyMass *tmpm,I64 x, I64 y)
{
  MySpring *tmps;
  tmpm->x=x;
  tmpm->y=y;
  tmpm->DxDt=0;
  tmpm->DyDt=0;
  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    if (tmps->end1==tmpm || tmps->end2==tmpm) {
      if (tmps->flags&SSF_NO_COMPRESSION)
        NullSpring(tmps,WIRE_PERCENT);
      else
        NullSpring(tmps,1.0);
    }
    tmps=tmps->next;
  }
}

U0 DelSpring(MySpring *tmps)
{
  QueRem(tmps);
  Free(tmps);
}

U0 DelMass(MyMass *tmpm)
{
  MySpring *tmps,*tmps1;
  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    tmps1=tmps->next;
    if (tmps->end1==tmpm || tmps->end2==tmpm)
      DelSpring(tmps);
    tmps=tmps1;
  }
  QueRem(tmpm);
  Free(tmpm);
}

U0 DrawSpring(CDC *dc,MyMass *tmpm,I64 x,I64 y)
{
  switch (mode_bttn.state) {
    case MD_CONCRETE:
      dc->color=LTGRAY;
      dc->thick=2;
      break;
    case MD_STEEL:
      dc->color=DKGRAY;
      dc->thick=2;
      break;
    case MD_WIRE:
      dc->color=RED;
      dc->thick=1;
      break;
  }
  GrLine3(dc,tmpm->x,tmpm->y,0,x,y,0);
}

U0 PlaceSpring(MyMass *tmpm1,MyMass *tmpm2)
{
  MySpring *tmps=CAlloc(sizeof(MySpring));
  tmps->end1=tmpm1;
  tmps->end2=tmpm2;
  switch (mode_bttn.state) {
    case MD_CONCRETE:
      tmps->base_const        = 3.00*SPRING_SCALE;
      tmps->base_compression_strength=10.00*STRENGTH_SCALE;
      tmps->base_tensile_strength    = 0.35*STRENGTH_SCALE;
      tmps->base_cost                 = 0.30*COST_SCALE;
      NullSpring(tmps,1.0);
      tmps->color=LTGRAY;
      tmps->thick=2;
      break;
    case MD_STEEL:
      tmps->base_const        = 1.00*SPRING_SCALE;
      tmps->base_compression_strength= 1.00*STRENGTH_SCALE;
      tmps->base_tensile_strength    = 1.00*STRENGTH_SCALE;
      tmps->base_cost                 = 1.00*COST_SCALE;
      NullSpring(tmps,1.0);
      tmps->color=DKGRAY;
      tmps->thick=2;
      break;
    case MD_WIRE:
      tmps->base_const        = 0.25*SPRING_SCALE;
      tmps->base_compression_strength= 0.00;
      tmps->base_tensile_strength    = 0.50*STRENGTH_SCALE;
      tmps->base_cost                 = 0.10*COST_SCALE;
      NullSpring(tmps,WIRE_PERCENT);
      tmps->color=RED;
      tmps->thick=1;
      tmps->flags|=SSF_NO_COMPRESSION;
      break;
  }
  QueIns(tmps,ode->last_spring);
}

U0 AnimateTask(SpanAnimateStruct *a)
{
  MySpring *tmps,*tmps1;
  Bool old_run=FALSE;
  F64 f;
  while (TRUE) {
    tmps=ode->next_spring;
    while (tmps!=&ode->next_spring) {
      tmps1=tmps->next;
      f=tmps->f;
      if (f>0 &&  f>tmps->compression_strength &&
            !(tmps->flags&SSF_NO_COMPRESSION)||
            f<0 && -f>tmps->tensile_strength &&
            !(tmps->flags&SSF_NO_TENSION))
        tmps->flags|=SSF_INACTIVE;
      tmps=tmps1;
    }
    AdjustLoads(ode);
    Refresh; //CMathODE updated once per refresh.
    if (old_run!=run_bttn.state) {
      if (run_bttn.state) {
        if (!a->elapsed_t || !a->saved_ode) {
          Free(a->saved_ode);
          a->saved_ode=SpanSave(ode);
        }
        a->start_wall_t=tS;
        ODEPause(ode,OFF);
      } else {
        ODEPause(ode);
        a->elapsed_t+=tS-a->start_wall_t;
      }
      old_run=run_bttn.state;
    }
  }
}

U0 Init(SpanAnimateStruct *a)
{
  SpanDel(ode);
  ode=SpanNew;

  run_bttn.state=0;
  Refresh(2); //Allow stop to reg in animate task.

  if (a->saved_ode)
    SpanLoad(ode,a->saved_ode);
  else
    SpanBridge1Init(ode);
  a->elapsed_t=0;
  cursor_mass=NULL;
}

U0 SongTask(I64)
{//Song by Terry A. Davis
  Fs->task_end_cb=&SndTaskEndCB;
  MusicSettingsRst;
  music.tempo= 3.636;
  music.stacatto_factor= 0.902;
  while (TRUE) {
    Play("5q.EeDqED4G5DhE");
    Play("5q.EeDqED4G5DhE");
    Play("5q.FeEFEqF4G5EhF");
    Play("5q.FeEFEqF4G5EhF");
  }
}

U0 Span()
{
  I64 msg_code,arg1,arg2;
  MyMass   *tmpm1=NULL,*tmpm2=NULL;
  MySpri

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\SpanMain-Span-Apps.html
// Date: unknown-date
// Language: HolyC

F64 SpanTime()
{
  if (run_bttn.state)
    return a.elapsed_t+tS-a.start_wall_t;
  else
    return a.elapsed_t;
}

F64 Cost(CMathODE *ode)
{
  MyMass   *tmpm;
  MySpring *tmps;
  F64 res=0;
  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    res+=tmpm->cost;
    tmpm=tmpm->next;
  }
  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    res+=tmps->cost;
    tmps=tmps->next;
  }
  return res;
}

U0 DrawIt(CTask *task,CDC *dc)
{
  MyMass   *tmpm;
  MySpring *tmps;

  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    if (!(tmps->flags&SSF_INACTIVE)) {
      dc->color=tmps->color;
      dc->thick=tmps->thick;
      GrLine3(dc,tmps->end1->x,tmps->end1->y,0,
            tmps->end2->x,tmps->end2->y,0);
    }
    tmps=tmps->next;
  }

  if (cursor_mass) {
    dc->color=RED;
    dc->thick=2;
    GrLine3(dc,ms.pos.x-task->pix_left-task->scroll_x,
          ms.pos.y-task->pix_top-task->scroll_y,0,
          cursor_mass->x,cursor_mass->y,0);
  }

  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    if (!(tmpm->flags&MSF_INACTIVE)) {
      dc->color=BLACK;
      GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
      GrFloodFill(dc,tmpm->x,tmpm->y,TRUE);
      dc->color=tmpm->color;
      GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
      GrFloodFill(dc,tmpm->x,tmpm->y,TRUE);
      dc->color=BLACK;
      GrCircle(dc,tmpm->x,tmpm->y,tmpm->radius);
    }
    tmpm=tmpm->next;
  }

  dc->color=BLACK;
  GrPrint(dc,90,0,"Cost:%12.2,f",Cost(ode));
  GrPrint(dc,90,FONT_HEIGHT,"Time:%12.2f",SpanTime);
}

MyMass *PlaceMass(I64 x, I64 y)
{
  MyMass *tmpm=CAlloc(sizeof(MyMass));
  tmpm->drag_profile_factor=1.0;
  tmpm->x=x;
  tmpm->y=y;
  tmpm->mass=MASS_MASS;
  tmpm->radius=MASS_RADIUS;
  tmpm->cost=25.0*COST_SCALE;
  tmpm->color=YELLOW;
  QueIns(tmpm,ode->last_mass);
  return tmpm;
}

U0 NullSpring(MySpring *tmps,F64 scale)
{
  F64 d=D3Dist(&tmps->end1->x,&tmps->end2->x);
  tmps->rest_len=d*scale;
  tmps->compression_strength=
        tmps->base_compression_strength/(tmps->rest_len+1.0);
  tmps->tensile_strength=tmps->base_tensile_strength/(tmps->rest_len+1.0);
  tmps->const=tmps->base_const/(tmps->rest_len+1.0);
  tmps->cost=tmps->base_cost*tmps->rest_len;
}

U0 MoveMass(MyMass *tmpm,I64 x, I64 y)
{
  MySpring *tmps;
  tmpm->x=x;
  tmpm->y=y;
  tmpm->DxDt=0;
  tmpm->DyDt=0;
  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    if (tmps->end1==tmpm || tmps->end2==tmpm) {
      if (tmps->flags&SSF_NO_COMPRESSION)
        NullSpring(tmps,WIRE_PERCENT);
      else
        NullSpring(tmps,1.0);
    }
    tmps=tmps->next;
  }
}

U0 DelSpring(MySpring *tmps)
{
  QueRem(tmps);
  Free(tmps);
}

U0 DelMass(MyMass *tmpm)
{
  MySpring *tmps,*tmps1;
  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    tmps1=tmps->next;
    if (tmps->end1==tmpm || tmps->end2==tmpm)
      DelSpring(tmps);
    tmps=tmps1;
  }
  QueRem(tmpm);
  Free(tmpm);
}

U0 DrawSpring(CDC *dc,MyMass *tmpm,I64 x,I64 y)
{
  switch (mode_bttn.state) {
    case MD_CONCRETE:
      dc->color=LTGRAY;
      dc->thick=2;
      break;
    case MD_STEEL:
      dc->color=DKGRAY;
      dc->thick=2;
      break;
    case MD_WIRE:
      dc->color=RED;
      dc->thick=1;
      break;
  }
  GrLine3(dc,tmpm->x,tmpm->y,0,x,y,0);
}

U0 PlaceSpring(MyMass *tmpm1,MyMass *tmpm2)
{
  MySpring *tmps=CAlloc(sizeof(MySpring));
  tmps->end1=tmpm1;
  tmps->end2=tmpm2;
  switch (mode_bttn.state) {
    case MD_CONCRETE:
      tmps->base_const        = 3.00*SPRING_SCALE;
      tmps->base_compression_strength=10.00*STRENGTH_SCALE;
      tmps->base_tensile_strength    = 0.35*STRENGTH_SCALE;
      tmps->base_cost                 = 0.30*COST_SCALE;
      NullSpring(tmps,1.0);
      tmps->color=LTGRAY;
      tmps->thick=2;
      break;
    case MD_STEEL:
      tmps->base_const        = 1.00*SPRING_SCALE;
      tmps->base_compression_strength= 1.00*STRENGTH_SCALE;
      tmps->base_tensile_strength    = 1.00*STRENGTH_SCALE;
      tmps->base_cost                 = 1.00*COST_SCALE;
      NullSpring(tmps,1.0);
      tmps->color=DKGRAY;
      tmps->thick=2;
      break;
    case MD_WIRE:
      tmps->base_const        = 0.25*SPRING_SCALE;
      tmps->base_compression_strength= 0.00;
      tmps->base_tensile_strength    = 0.50*STRENGTH_SCALE;
      tmps->base_cost                 = 0.10*COST_SCALE;
      NullSpring(tmps,WIRE_PERCENT);
      tmps->color=RED;
      tmps->thick=1;
      tmps->flags|=SSF_NO_COMPRESSION;
      break;
  }
  QueIns(tmps,ode->last_spring);
}

U0 AnimateTask(SpanAnimateStruct *a)
{
  MySpring *tmps,*tmps1;
  Bool old_run=FALSE;
  F64 f;
  while (TRUE) {
    tmps=ode->next_spring;
    while (tmps!=&ode->next_spring) {
      tmps1=tmps->next;
      f=tmps->f;
      if (f>0 &&  f>tmps->compression_strength &&
            !(tmps->flags&SSF_NO_COMPRESSION)||
            f<0 && -f>tmps->tensile_strength &&
            !(tmps->flags&SSF_NO_TENSION))
        tmps->flags|=SSF_INACTIVE;
      tmps=tmps1;
    }
    AdjustLoads(ode);
    Refresh; //CMathODE updated once per refresh.
    if (old_run!=run_bttn.state) {
      if (run_bttn.state) {
        if (!a->elapsed_t || !a->saved_ode) {
          Free(a->saved_ode);
          a->saved_ode=SpanSave(ode);
        }
        a->start_wall_t=tS;
        ODEPause(ode,OFF);
      } else {
        ODEPause(ode);
        a->elapsed_t+=tS-a->start_wall_t;
      }
      old_run=run_bttn.state;
    }
  }
}

U0 Init(SpanAnimateStruct *a)
{
  SpanDel(ode);
  ode=SpanNew;

  run_bttn.state=0;
  Refresh(2); //Allow stop to reg in animate task.

  if (a->saved_ode)
    SpanLoad(ode,a->saved_ode);
  else
    SpanBridge1Init(ode);
  a->elapsed_t=0;
  cursor_mass=NULL;
}

U0 SongTask(I64)
{//Song by Terry A. Davis
  Fs->task_end_cb=&SndTaskEndCB;
  MusicSettingsRst;
  music.tempo= 3.636;
  music.stacatto_factor= 0.902;
  while (TRUE) {
    Play("5q.EeDqED4G5DhE");
    Play("5q.EeDqED4G5DhE");
    Play("5q.FeEFEqF4G5EhF");
    Play("5q.FeEFEqF4G5EhF");
  }
}

U0 Span()
{
  I64 msg_code,arg1,arg2;
  MyMass   *tmpm1=NULL,*tmpm2=NULL;
  MySpri


// Source: D:\TempleOS-Projects\html\EdLite-Kernel.html
// Date: unknown-date
// Language: HolyC

class CLine
{
  CLine *next,*last;
  U8 *line;
};

U0 EdLiteUpdate(CLine *head,CLine *cur_line,I64 cur_col,I64 line_start_col)
{
  I64 ch,i,j,k,k2,cursor_col,cursor_row=-1;
  U8 *st;
  CLine *tmpl=cur_line;
  Bool done_eof=FALSE;
  text.raw_col=0;
  for (i=0;i<text.rows/2;i++)
    if (tmpl->last!=head)
      tmpl=tmpl->last;
  for (i=0;i<text.rows;i++) {
    if (cursor_row<0 && tmpl==cur_line) {
      k=0;
      for (j=0;j<cur_col;j++)
        if (tmpl->line[j]=='\t')
          k=(k+8)&~7;
        else
          k++;
      cursor_col=k;
      cursor_row=i;
    }
    if (tmpl!=head) {
      st=tmpl->line;
      k=0;
      j=0;
      while (ch=*st++) {
        if (ch=='\t')
          k2=(k+8)&~7;
        else
          k2=k+1;
        if (line_start_col<=k<line_start_col+text.cols) {
          '' ch;
          j=k2-line_start_col;
        }
        k=k2;
      }
      if (j<text.cols)
        '\n';
      tmpl=tmpl->next;
    } else {
      if (!done_eof) {
        '<EOF>';
        done_eof=TRUE;
      }
      '\n';
    }
  }
  text.raw_col=text.cols*cursor_row+cursor_col-line_start_col;
  RawPutChar(0x7F);
}

Bool EdLite(U8 *filename,I64 num=1,I64 edf_dof_flags=0)
{//Light weight text editor for debugging.
  U8 *src,*src2,*src3,*dst,*buf,*bin_data=NULL;
  I64 i,cnt=0,ch,sc,size,bin_size=0,line_start_col=0,cur_col=0,
        old_raw_flags=text.raw_flags;
  CLine head,*tmpl,*tmpl1,*cur_line;
  Bool  res=FALSE,
        old_raw=Raw(ON),
        old_debug=DbgMode(ON),
        old_single=SingleUser(ON);

  if (!filename) filename=blkdev.tmp_filename;
  buf=FileRead(filename,&size);

  PUSHFD
  CLI
  text.raw_flags=text.raw_flags&~RWF_SCROLL|RWF_SHOW_DOLLAR;
  kbd.scan_code=0;
  QueInit(&head);
  head.line=StrNew("");

  if (buf) {
    src=buf;
    while (*src) {
      src2=src;
      while ((ch=*src++) && ch!='\r' && ch!='\n');
      src--;
      *src++=0;
      if (!ch)
        src--;
      while (ch=='\r' && *src=='\n' || *src==CH_CURSOR)
        src++;
      dst=src3=src2;
      while (ch=*src3++)
        if (ch!='\n' && ch!=CH_CURSOR)
          *dst++=ch;
      *dst=0;

      tmpl=MAlloc(sizeof(CLine));
      tmpl->line=StrNew(src2);
      QueIns(tmpl,head.last);
      cnt++;
    }

    if (src+1-buf<size) {
      bin_data=MAlloc(bin_size=size-(src-buf));
      MemCpy(bin_data,src,bin_size);
    }
    Free(buf);
    res=TRUE;
  }

  cur_line=head.next;
  if (--num<0)
    res=FALSE;
  else {
    if (num<=cnt)
      while (num--)
        cur_line=cur_line->next;
    else {
      cur_line=&head;
      res=FALSE;
    }
  }
  do {
    if (cur_line==&head)
      cur_col=0;
    while (cur_col-line_start_col<0)
      line_start_col-=8;
    while (cur_col-line_start_col>=text.cols)
      line_start_col+=8;
    EdLiteUpdate(&head,cur_line,cur_col,line_start_col);
    switch (ch=GetKey(&sc,FALSE,TRUE)) {
      case 0:
        switch (sc.u8[0]) {
          case SC_CURSOR_UP:
            if (cur_line->last!=&head)
              cur_line=cur_line->last;
            if (cur_col>StrLen(cur_line->line))
              cur_col=StrLen(cur_line->line);
            break;
          case SC_CURSOR_DOWN:
            if (cur_line!=&head)
              cur_line=cur_line->next;
            if (cur_col>StrLen(cur_line->line))
              cur_col=StrLen(cur_line->line);
            break;
          case SC_CURSOR_RIGHT:
            cur_col++;
            if (cur_col>StrLen(cur_line->line)) {
              tmpl=cur_line->next;
              if (tmpl!=&head) {
                cur_col=0;
                cur_line=tmpl;
              } else
                cur_col=StrLen(cur_line->line);
            }
            break;
          case SC_CURSOR_LEFT:
            if (cur_col)
              cur_col--;
            else {
              tmpl=cur_line->last;
              if (tmpl!=&head) {
                cur_line=tmpl;
                cur_col=StrLen(tmpl->line);
              }
            }
            break;
          case SC_PAGE_UP:
            for (i=1;i<text.rows;i++) {
              if (cur_line->last!=&head)
                cur_line=cur_line->last;
              if (cur_col>StrLen(cur_line->line))
                cur_col=StrLen(cur_line->line);
            }
            break;
          case SC_PAGE_DOWN:
            for (i=1;i<text.rows;i++) {
              if (cur_line!=&head)
                cur_line=cur_line->next;
              if (cur_col>StrLen(cur_line->line))
                cur_col=StrLen(cur_line->line);
            }
            break;
          case SC_DELETE:
            if (cur_col==StrLen(cur_line->line)) {
              tmpl=cur_line->next;
              if (cur_line!=&head && tmpl!=&head) {
                src=MStrPrint("%s%s",cur_line->line,tmpl->line);
                Free(cur_line->line);
                Free(tmpl->line);
                cur_line->line=src;
                QueRem(tmpl);
                Free(tmpl);
              }
            } else
              StrCpy(cur_line->line+cur_col,cur_line->line+cur_col+1);
            break;
        }
        break;
      case '\n':
      case '\r':
        tmpl=MAlloc(sizeof(CLine));
        tmpl->line=StrNew(cur_line->line+cur_col);
        cur_line->line[cur_col]=0;
        QueIns(tmpl,cur_line);
        cur_line=tmpl;
        cur_col=0;
        break;
      case CH_BACKSPACE:
        if (cur_col) {
          StrCpy(cur_line->line+cur_col-1,cur_line->line+cur_col);
          cur_col--;
        } else if (cur_line!=&head && cur_line->last!=&head) {
          tmpl=cur_line->last;
          src=MStrPrint("%s%s",tmpl->line,cur_line->line);
          cur_col=StrLen(tmpl->line);
          Free(cur_line->line);
          Free(tmpl->line);
          tmpl->line=src;
          QueRem(cur_line);
          Free(cur_line);
          cur_line=tmpl;
        }
        break;
      case CH_CTRLY:
        if (cur_line!=&head) {
          tmpl=cur_line;
          cur_line=cur_line->next;
          QueRem(tmpl);
          Free(tmpl->line);
          Free(tmpl);
          cur_col=0;
        }
        break;
      de

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\EdLite-Kernel.html
// Date: unknown-date
// Language: HolyC

class CLine
{
  CLine *next,*last;
  U8 *line;
};

U0 EdLiteUpdate(CLine *head,CLine *cur_line,I64 cur_col,I64 line_start_col)
{
  I64 ch,i,j,k,k2,cursor_col,cursor_row=-1;
  U8 *st;
  CLine *tmpl=cur_line;
  Bool done_eof=FALSE;
  text.raw_col=0;
  for (i=0;i<text.rows/2;i++)
    if (tmpl->last!=head)
      tmpl=tmpl->last;
  for (i=0;i<text.rows;i++) {
    if (cursor_row<0 && tmpl==cur_line) {
      k=0;
      for (j=0;j<cur_col;j++)
        if (tmpl->line[j]=='\t')
          k=(k+8)&~7;
        else
          k++;
      cursor_col=k;
      cursor_row=i;
    }
    if (tmpl!=head) {
      st=tmpl->line;
      k=0;
      j=0;
      while (ch=*st++) {
        if (ch=='\t')
          k2=(k+8)&~7;
        else
          k2=k+1;
        if (line_start_col<=k<line_start_col+text.cols) {
          '' ch;
          j=k2-line_start_col;
        }
        k=k2;
      }
      if (j<text.cols)
        '\n';
      tmpl=tmpl->next;
    } else {
      if (!done_eof) {
        '<EOF>';
        done_eof=TRUE;
      }
      '\n';
    }
  }
  text.raw_col=text.cols*cursor_row+cursor_col-line_start_col;
  RawPutChar(0x7F);
}

Bool EdLite(U8 *filename,I64 num=1,I64 edf_dof_flags=0)
{//Light weight text editor for debugging.
  U8 *src,*src2,*src3,*dst,*buf,*bin_data=NULL;
  I64 i,cnt=0,ch,sc,size,bin_size=0,line_start_col=0,cur_col=0,
        old_raw_flags=text.raw_flags;
  CLine head,*tmpl,*tmpl1,*cur_line;
  Bool  res=FALSE,
        old_raw=Raw(ON),
        old_debug=DbgMode(ON),
        old_single=SingleUser(ON);

  if (!filename) filename=blkdev.tmp_filename;
  buf=FileRead(filename,&size);

  PUSHFD
  CLI
  text.raw_flags=text.raw_flags&~RWF_SCROLL|RWF_SHOW_DOLLAR;
  kbd.scan_code=0;
  QueInit(&head);
  head.line=StrNew("");

  if (buf) {
    src=buf;
    while (*src) {
      src2=src;
      while ((ch=*src++) && ch!='\r' && ch!='\n');
      src--;
      *src++=0;
      if (!ch)
        src--;
      while (ch=='\r' && *src=='\n' || *src==CH_CURSOR)
        src++;
      dst=src3=src2;
      while (ch=*src3++)
        if (ch!='\n' && ch!=CH_CURSOR)
          *dst++=ch;
      *dst=0;

      tmpl=MAlloc(sizeof(CLine));
      tmpl->line=StrNew(src2);
      QueIns(tmpl,head.last);
      cnt++;
    }

    if (src+1-buf<size) {
      bin_data=MAlloc(bin_size=size-(src-buf));
      MemCpy(bin_data,src,bin_size);
    }
    Free(buf);
    res=TRUE;
  }

  cur_line=head.next;
  if (--num<0)
    res=FALSE;
  else {
    if (num<=cnt)
      while (num--)
        cur_line=cur_line->next;
    else {
      cur_line=&head;
      res=FALSE;
    }
  }
  do {
    if (cur_line==&head)
      cur_col=0;
    while (cur_col-line_start_col<0)
      line_start_col-=8;
    while (cur_col-line_start_col>=text.cols)
      line_start_col+=8;
    EdLiteUpdate(&head,cur_line,cur_col,line_start_col);
    switch (ch=GetKey(&sc,FALSE,TRUE)) {
      case 0:
        switch (sc.u8[0]) {
          case SC_CURSOR_UP:
            if (cur_line->last!=&head)
              cur_line=cur_line->last;
            if (cur_col>StrLen(cur_line->line))
              cur_col=StrLen(cur_line->line);
            break;
          case SC_CURSOR_DOWN:
            if (cur_line!=&head)
              cur_line=cur_line->next;
            if (cur_col>StrLen(cur_line->line))
              cur_col=StrLen(cur_line->line);
            break;
          case SC_CURSOR_RIGHT:
            cur_col++;
            if (cur_col>StrLen(cur_line->line)) {
              tmpl=cur_line->next;
              if (tmpl!=&head) {
                cur_col=0;
                cur_line=tmpl;
              } else
                cur_col=StrLen(cur_line->line);
            }
            break;
          case SC_CURSOR_LEFT:
            if (cur_col)
              cur_col--;
            else {
              tmpl=cur_line->last;
              if (tmpl!=&head) {
                cur_line=tmpl;
                cur_col=StrLen(tmpl->line);
              }
            }
            break;
          case SC_PAGE_UP:
            for (i=1;i<text.rows;i++) {
              if (cur_line->last!=&head)
                cur_line=cur_line->last;
              if (cur_col>StrLen(cur_line->line))
                cur_col=StrLen(cur_line->line);
            }
            break;
          case SC_PAGE_DOWN:
            for (i=1;i<text.rows;i++) {
              if (cur_line!=&head)
                cur_line=cur_line->next;
              if (cur_col>StrLen(cur_line->line))
                cur_col=StrLen(cur_line->line);
            }
            break;
          case SC_DELETE:
            if (cur_col==StrLen(cur_line->line)) {
              tmpl=cur_line->next;
              if (cur_line!=&head && tmpl!=&head) {
                src=MStrPrint("%s%s",cur_line->line,tmpl->line);
                Free(cur_line->line);
                Free(tmpl->line);
                cur_line->line=src;
                QueRem(tmpl);
                Free(tmpl);
              }
            } else
              StrCpy(cur_line->line+cur_col,cur_line->line+cur_col+1);
            break;
        }
        break;
      case '\n':
      case '\r':
        tmpl=MAlloc(sizeof(CLine));
        tmpl->line=StrNew(cur_line->line+cur_col);
        cur_line->line[cur_col]=0;
        QueIns(tmpl,cur_line);
        cur_line=tmpl;
        cur_col=0;
        break;
      case CH_BACKSPACE:
        if (cur_col) {
          StrCpy(cur_line->line+cur_col-1,cur_line->line+cur_col);
          cur_col--;
        } else if (cur_line!=&head && cur_line->last!=&head) {
          tmpl=cur_line->last;
          src=MStrPrint("%s%s",tmpl->line,cur_line->line);
          cur_col=StrLen(tmpl->line);
          Free(cur_line->line);
          Free(tmpl->line);
          tmpl->line=src;
          QueRem(cur_line);
          Free(cur_line);
          cur_line=tmpl;
        }
        break;
      case CH_CTRLY:
        if (cur_line!=&head) {
          tmpl=cur_line;
          cur_line=cur_line->next;
          QueRem(tmpl);
          Free(tmpl->line);
          Free(tmpl);
          cur_col=0;
        }
        break;
      de


// Source: D:\TempleOS-Projects\html\Transform-Graphics-Demo.html
// Date: unknown-date
// Language: HolyC

/*This highlights the 4th dimension
of the transformation matrix which
is used for storing translations (shifts)
in matricies so they can be combined
with a matrix multiplication.

Scroll bar works.

The multiplication takes place in the
Sprite3ZB routine.
*/

#define SLIDER_SPACING 20
#define SLIDER_RANGE   30
#define SLIDER_BORDER  2

class CSliderState
{
  I64 s1,s2,s3;
  F64 arg1,arg2,scale;
} s;

U0 DrawCtrlSlider(CDC *dc,CCtrl *c)
{
  CSliderState *s=c->state;

  dc->color=LTGREEN;
  GrRect(dc, c->left,c->top,SLIDER_SPACING*4+3,SLIDER_SPACING*2+SLIDER_RANGE);
  dc->color=BROWN;
  GrRect(dc, c->left+SLIDER_BORDER,c->top+SLIDER_BORDER,
        SLIDER_SPACING*4+3-2*SLIDER_BORDER,
        SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER);
  dc->color=BLACK;
  GrLine(dc,c->left+SLIDER_SPACING,c->top+SLIDER_SPACING,
        c->left+SLIDER_SPACING,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
  GrLine(dc,c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING,
        c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
  GrLine(dc,c->left+3*SLIDER_SPACING+2,c->top+SLIDER_SPACING,
        c->left+3*SLIDER_SPACING+2,c->top+SLIDER_SPACING+SLIDER_RANGE-1);

  dc->color=LTGREEN;
  GrPrint(dc,c->left+SLIDER_SPACING-FONT_WIDTH/2,
        c->top+SLIDER_SPACING+SLIDER_RANGE+3,
        "%d",s->s1*10/SLIDER_RANGE);
  GrPrint(dc,c->left+2*SLIDER_SPACING+1-FONT_WIDTH/2,
        c->top+SLIDER_SPACING+SLIDER_RANGE+3,
        "%d",s->s2*10/SLIDER_RANGE);
  GrPrint(dc,c->left+3*SLIDER_SPACING+2-FONT_WIDTH/2,
        c->top+SLIDER_SPACING+SLIDER_RANGE+3,
        "%d",s->s3*10/SLIDER_RANGE);
  GrRect(dc,c->left+SLIDER_SPACING-3,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s1-2 ,7,5);
  GrRect(dc,c->left+2*SLIDER_SPACING+1-3,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s2-2,7,5);
  GrRect(dc,c->left+3*SLIDER_SPACING+2-3,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s3-2,7,5);
  dc->color=GREEN;
  GrRect(dc,c->left+SLIDER_SPACING-2,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s1-1 ,5,3);
  GrRect(dc,c->left+2*SLIDER_SPACING+1-2,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s2-1,5,3);
  GrRect(dc,c->left+3*SLIDER_SPACING+2-2,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s3-1,5,3);
}

U0 UpdateDerivedCtrlSlider(CCtrl *c)
{
  CSliderState *s=c->state;
  c->left=c->win_task->pix_width/2-(SLIDER_SPACING*4+3)/2;
  c->right=c->left+SLIDER_SPACING*4+3;
  c->top=c->win_task->pix_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;
  c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;
  s->s1=ClampI64(s->s1,0,SLIDER_RANGE-1);
  s->s2=ClampI64(s->s2,0,SLIDER_RANGE-1);
  s->s3=ClampI64(s->s3,1,SLIDER_RANGE-1);
  s->arg1=pi/2.0*s->s1/SLIDER_RANGE;
  s->arg2=1.0*(s->s2-SLIDER_RANGE/2)/SLIDER_RANGE;
  s->scale=2.0*s->s3/SLIDER_RANGE;
}

U0 LeftClickSlider(CCtrl *c,I64 x,I64 y,Bool)
{
  CSliderState *s=c->state;
  if (x<c->left+(c->right-c->left)/3)
    s->s1=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
  else if (x<c->left+2*(c->right-c->left)/3)
    s->s2=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
  else
    s->s3=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
  if (c->update_derived_vals)
    (*c->update_derived_vals)(c);
}

CCtrl *SliderNew()
{
  CCtrl *c=CAlloc(sizeof(CCtrl));
  c->win_task=Fs;
  c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_MS;
  c->type=CTRLT_GENERIC;
  c->state=&s;
  MemSet(&s,0,sizeof(s));
  c->draw_it=&DrawCtrlSlider;
  c->left_click=&LeftClickSlider;
  c->update_derived_vals=&UpdateDerivedCtrlSlider;
  QueIns(c,Fs->last_ctrl);
  TaskDerivedValsUpdate;
  return c;
}

U0 SliderDel(CCtrl *c)
{
  QueRem(c);
  Free(c);
}

<1>/* Graphics Not Rendered in HTML */

#define MAP_HEIGHT      2048
#define MAP_WIDTH       2048

#define TREES_NUM       256

I64 tree_x[TREES_NUM],tree_y[TREES_NUM];

class MPCtrl {
  I64 mp_cnt;
  I64 r[16];
  F64 a;
} mp;

I64 mp_not_done_flags;

U0 MPDrawIt(CTask *task)
{
  CDC *dc=DCAlias(gr.dc2,task);
  I64 i,lo=Gs->num*TREES_NUM/mp.mp_cnt,hi=(Gs->num+1)*TREES_NUM/mp.mp_cnt;
  MemCpy(dc->r,mp.r,sizeof(I64)*16);
  dc->flags|=DCF_TRANSFORMATION;
  for (i=lo;i<hi;i++)
    Sprite3ZB(dc,tree_x[i],
          tree_y[i],0,<tree>,mp.a);
  DCDel(dc);
  LBtr(&mp_not_done_flags,Gs->num);
}

U0 DrawIt(CTask *task,CDC *dc)
{
  I64 i,h,v;
  task->horz_scroll.min=-s.scale*MAP_HEIGHT*Sin(s.arg1);
  task->horz_scroll.max=s.scale*MAP_WIDTH*Cos(s.arg1)-task->pix_width;
  task->vert_scroll.min=0;
  task->vert_scroll.max=s.scale*(MAP_HEIGHT*Cos(s.arg1)+MAP_WIDTH*Sin(s.arg1))
  -task->pix_height;
  TaskDerivedValsUpdate(task);

  h=task->horz_scroll.pos;
  v=task->vert_scroll.pos;

  Mat4x4RotZ(dc->r,s.arg1);
  Mat4x4Scale(dc->r,s.scale);
  DCMat4x4Set(dc,dc->r);
  Mat4x4TranslationEqu(dc->r,-h,-v,0);
  MemCpy(mp.r,dc->r,sizeof(I64)*16);
  mp.a=s.arg2;

  mp_not_done_flags=1<<mp_cnt-1;
  for (i=0;i<mp.mp_cnt;i++)
    JobQue(&MPDrawIt,task,i);
  while (mp_not_done_flags)
    Yield;

  dc->flags|=DCF_TRANSFORMATION;
  dc->color=BROWN;
  dc->thick=4;
  GrLine3(dc,2,2,0,MAP_WIDTH-3,2,0);
  GrLine3(dc,2,MAP_HEIGHT-3,0,MAP_WIDTH-3,MAP_HEIGHT-3,0);
  GrLine3(dc,2,2,0,2,MAP_HEIGHT-3,0);
  GrLine3(dc,MAP_WIDTH-3,2,0,MAP_WIDTH-3,MAP_HEIGHT-3,0);
}

U0 Init()
{
  I64 i;
  for (i=0;i<TREES_NUM;i++) {
    tree_x[i]=RandU16%MAP_WIDTH;
    tree_y[i]=RandU16%MAP_HEIGHT;
  }
}

U0 TransformDemo(I64 _mp_cnt=mp_cnt)
{
  SettingsPush; //See SettingsPush
  Init;
  Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS-WIF_SELF_BORDER
        -WIF_SELF_GRAB_SCROLL-WIF_FOCUS_TASK_MENU-WIF_SELF_CTRLS;
  Fs->draw_it=&DrawIt;
  WinBorder(ON);
  DocCursor;
  DocClear;
  DocScroll;

  Fs->horz_scroll.pos=0;
  Fs->vert_scroll.pos=0;
  CCtrl *c=SliderNew;
  s.s1=0;
  s.s2=SLIDER_RANGE/2;
  s.s3=SLIDER_RANGE/2;

  MemSet(&mp,0,sizeof(MPCtrl));
  mp.mp_cnt=_mp_cnt;

  View;
  SliderDel(c);
  SettingsPop;
//You might want to save the original state of the scroll bars.
}

TransformDemo;

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\Transform-Graphics-Demo.html
// Date: unknown-date
// Language: HolyC

/*This highlights the 4th dimension
of the transformation matrix which
is used for storing translations (shifts)
in matricies so they can be combined
with a matrix multiplication.

Scroll bar works.

The multiplication takes place in the
Sprite3ZB routine.
*/

#define SLIDER_SPACING 20
#define SLIDER_RANGE   30
#define SLIDER_BORDER  2

class CSliderState
{
  I64 s1,s2,s3;
  F64 arg1,arg2,scale;
} s;

U0 DrawCtrlSlider(CDC *dc,CCtrl *c)
{
  CSliderState *s=c->state;

  dc->color=LTGREEN;
  GrRect(dc, c->left,c->top,SLIDER_SPACING*4+3,SLIDER_SPACING*2+SLIDER_RANGE);
  dc->color=BROWN;
  GrRect(dc, c->left+SLIDER_BORDER,c->top+SLIDER_BORDER,
        SLIDER_SPACING*4+3-2*SLIDER_BORDER,
        SLIDER_SPACING*2+SLIDER_RANGE-2*SLIDER_BORDER);
  dc->color=BLACK;
  GrLine(dc,c->left+SLIDER_SPACING,c->top+SLIDER_SPACING,
        c->left+SLIDER_SPACING,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
  GrLine(dc,c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING,
        c->left+2*SLIDER_SPACING+1,c->top+SLIDER_SPACING+SLIDER_RANGE-1);
  GrLine(dc,c->left+3*SLIDER_SPACING+2,c->top+SLIDER_SPACING,
        c->left+3*SLIDER_SPACING+2,c->top+SLIDER_SPACING+SLIDER_RANGE-1);

  dc->color=LTGREEN;
  GrPrint(dc,c->left+SLIDER_SPACING-FONT_WIDTH/2,
        c->top+SLIDER_SPACING+SLIDER_RANGE+3,
        "%d",s->s1*10/SLIDER_RANGE);
  GrPrint(dc,c->left+2*SLIDER_SPACING+1-FONT_WIDTH/2,
        c->top+SLIDER_SPACING+SLIDER_RANGE+3,
        "%d",s->s2*10/SLIDER_RANGE);
  GrPrint(dc,c->left+3*SLIDER_SPACING+2-FONT_WIDTH/2,
        c->top+SLIDER_SPACING+SLIDER_RANGE+3,
        "%d",s->s3*10/SLIDER_RANGE);
  GrRect(dc,c->left+SLIDER_SPACING-3,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s1-2 ,7,5);
  GrRect(dc,c->left+2*SLIDER_SPACING+1-3,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s2-2,7,5);
  GrRect(dc,c->left+3*SLIDER_SPACING+2-3,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s3-2,7,5);
  dc->color=GREEN;
  GrRect(dc,c->left+SLIDER_SPACING-2,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s1-1 ,5,3);
  GrRect(dc,c->left+2*SLIDER_SPACING+1-2,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s2-1,5,3);
  GrRect(dc,c->left+3*SLIDER_SPACING+2-2,
        c->top+SLIDER_SPACING+SLIDER_RANGE-1-s->s3-1,5,3);
}

U0 UpdateDerivedCtrlSlider(CCtrl *c)
{
  CSliderState *s=c->state;
  c->left=c->win_task->pix_width/2-(SLIDER_SPACING*4+3)/2;
  c->right=c->left+SLIDER_SPACING*4+3;
  c->top=c->win_task->pix_height/2-(SLIDER_SPACING*2+SLIDER_RANGE)/2;
  c->bottom=c->top+SLIDER_SPACING*2+SLIDER_RANGE;
  s->s1=ClampI64(s->s1,0,SLIDER_RANGE-1);
  s->s2=ClampI64(s->s2,0,SLIDER_RANGE-1);
  s->s3=ClampI64(s->s3,1,SLIDER_RANGE-1);
  s->arg1=pi/2.0*s->s1/SLIDER_RANGE;
  s->arg2=1.0*(s->s2-SLIDER_RANGE/2)/SLIDER_RANGE;
  s->scale=2.0*s->s3/SLIDER_RANGE;
}

U0 LeftClickSlider(CCtrl *c,I64 x,I64 y,Bool)
{
  CSliderState *s=c->state;
  if (x<c->left+(c->right-c->left)/3)
    s->s1=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
  else if (x<c->left+2*(c->right-c->left)/3)
    s->s2=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
  else
    s->s3=SLIDER_RANGE-1-(y-(c->top+SLIDER_SPACING));
  if (c->update_derived_vals)
    (*c->update_derived_vals)(c);
}

CCtrl *SliderNew()
{
  CCtrl *c=CAlloc(sizeof(CCtrl));
  c->win_task=Fs;
  c->flags=CTRLF_SHOW|CTRLF_CAPTURE_LEFT_MS;
  c->type=CTRLT_GENERIC;
  c->state=&s;
  MemSet(&s,0,sizeof(s));
  c->draw_it=&DrawCtrlSlider;
  c->left_click=&LeftClickSlider;
  c->update_derived_vals=&UpdateDerivedCtrlSlider;
  QueIns(c,Fs->last_ctrl);
  TaskDerivedValsUpdate;
  return c;
}

U0 SliderDel(CCtrl *c)
{
  QueRem(c);
  Free(c);
}

<1>/* Graphics Not Rendered in HTML */

#define MAP_HEIGHT      2048
#define MAP_WIDTH       2048

#define TREES_NUM       256

I64 tree_x[TREES_NUM],tree_y[TREES_NUM];

class MPCtrl {
  I64 mp_cnt;
  I64 r[16];
  F64 a;
} mp;

I64 mp_not_done_flags;

U0 MPDrawIt(CTask *task)
{
  CDC *dc=DCAlias(gr.dc2,task);
  I64 i,lo=Gs->num*TREES_NUM/mp.mp_cnt,hi=(Gs->num+1)*TREES_NUM/mp.mp_cnt;
  MemCpy(dc->r,mp.r,sizeof(I64)*16);
  dc->flags|=DCF_TRANSFORMATION;
  for (i=lo;i<hi;i++)
    Sprite3ZB(dc,tree_x[i],
          tree_y[i],0,<tree>,mp.a);
  DCDel(dc);
  LBtr(&mp_not_done_flags,Gs->num);
}

U0 DrawIt(CTask *task,CDC *dc)
{
  I64 i,h,v;
  task->horz_scroll.min=-s.scale*MAP_HEIGHT*Sin(s.arg1);
  task->horz_scroll.max=s.scale*MAP_WIDTH*Cos(s.arg1)-task->pix_width;
  task->vert_scroll.min=0;
  task->vert_scroll.max=s.scale*(MAP_HEIGHT*Cos(s.arg1)+MAP_WIDTH*Sin(s.arg1))
  -task->pix_height;
  TaskDerivedValsUpdate(task);

  h=task->horz_scroll.pos;
  v=task->vert_scroll.pos;

  Mat4x4RotZ(dc->r,s.arg1);
  Mat4x4Scale(dc->r,s.scale);
  DCMat4x4Set(dc,dc->r);
  Mat4x4TranslationEqu(dc->r,-h,-v,0);
  MemCpy(mp.r,dc->r,sizeof(I64)*16);
  mp.a=s.arg2;

  mp_not_done_flags=1<<mp_cnt-1;
  for (i=0;i<mp.mp_cnt;i++)
    JobQue(&MPDrawIt,task,i);
  while (mp_not_done_flags)
    Yield;

  dc->flags|=DCF_TRANSFORMATION;
  dc->color=BROWN;
  dc->thick=4;
  GrLine3(dc,2,2,0,MAP_WIDTH-3,2,0);
  GrLine3(dc,2,MAP_HEIGHT-3,0,MAP_WIDTH-3,MAP_HEIGHT-3,0);
  GrLine3(dc,2,2,0,2,MAP_HEIGHT-3,0);
  GrLine3(dc,MAP_WIDTH-3,2,0,MAP_WIDTH-3,MAP_HEIGHT-3,0);
}

U0 Init()
{
  I64 i;
  for (i=0;i<TREES_NUM;i++) {
    tree_x[i]=RandU16%MAP_WIDTH;
    tree_y[i]=RandU16%MAP_HEIGHT;
  }
}

U0 TransformDemo(I64 _mp_cnt=mp_cnt)
{
  SettingsPush; //See SettingsPush
  Init;
  Fs->win_inhibit=WIG_TASK_DFT-WIF_SELF_FOCUS-WIF_SELF_BORDER
        -WIF_SELF_GRAB_SCROLL-WIF_FOCUS_TASK_MENU-WIF_SELF_CTRLS;
  Fs->draw_it=&DrawIt;
  WinBorder(ON);
  DocCursor;
  DocClear;
  DocScroll;

  Fs->horz_scroll.pos=0;
  Fs->vert_scroll.pos=0;
  CCtrl *c=SliderNew;
  s.s1=0;
  s.s2=SLIDER_RANGE/2;
  s.s3=SLIDER_RANGE/2;

  MemSet(&mp,0,sizeof(MPCtrl));
  mp.mp_cnt=_mp_cnt;

  View;
  SliderDel(c);
  SettingsPop;
//You might want to save the original state of the scroll bars.
}

TransformDemo;


// Source: D:\TempleOS-Projects\html\AMathODE-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Math/ODE"
#help_file "::/Doc/ODE"

//See ::/Doc/Credits.DD.

F64 LowPass1(F64 a,F64 y0,F64 y,F64 dt=1.0)
{//First order low pass filter
  dt=Exp(-a*dt);
  return y0*dt+y*(1.0-dt);
}

U0 ODERstPtrs(CMathODE *ode)
{
  I64 s=ode->n_internal*sizeof(F64);
  F64 *ptr=ode->array_base;
  ode->state_internal=ptr;      ptr(I64)+=s;
  ode->state_scale=ptr;         ptr(I64)+=s;
  ode->DstateDt=ptr;            ptr(I64)+=s;
  ode->initial_state=ptr;       ptr(I64)+=s;
  ode->tmp0=ptr;        ptr(I64)+=s;
  ode->tmp1=ptr;        ptr(I64)+=s;
  ode->tmp2=ptr;        ptr(I64)+=s;
  ode->tmp3=ptr;        ptr(I64)+=s;
  ode->tmp4=ptr;        ptr(I64)+=s;
  ode->tmp5=ptr;        ptr(I64)+=s;
  ode->tmp6=ptr;        ptr(I64)+=s;
  ode->tmp7=ptr;
}

public CMathODE *ODENew(I64 n,F64 max_tolerance=1e-6,I64 flags=0)
{//Make differential equation ctrl struct. See flags.
  //The tolerance is not precise.
  //You can min_tolerance and it will
  //dynamically adjust tolerance to utilize
  //the CPU.
  I64 s=n*sizeof(F64);
  CMathODE *ode=CAlloc(sizeof(CMathODE));
  ode->t_scale=1.0;
  ode->flags=flags;
  ode->n_internal=ode->n=n;
  ode->h=1e-6;
  ode->h_min=1e-64;
  ode->h_max=1e32;
  ode->max_tolerance=ode->min_tolerance=ode->tolerance_internal=max_tolerance;
  ode->win_task=ode->mem_task=Fs;
  QueInit(&ode->next_mass);
  QueInit(&ode->next_spring);
  ode->state=CAlloc(s);
  ode->array_base=MAlloc(12*s);
  ODERstPtrs(ode);
  return ode;
}

public Bool ODEPause(CMathODE *ode,Bool val=ON)
{//Pause ODE.
  Bool res;
  if (!ode) return OFF;
  res=LBEqu(&ode->flags,ODEf_PAUSED,val);
  if (val)
    while (Bt(&ode->flags,ODEf_BUSY))
      Yield;
  return res;
}

public U0 ODEDel(CMathODE *ode)
{//Free ODE node, but not masses or springs.
  I64 i;
  if (!ode) return;
  ODEPause(ode);
  Free(ode->state);
  Free(ode->array_base);
  if (ode->slave_tasks) {
    for (i=0;i<mp_cnt;i++)
      Kill(ode->slave_tasks[i]);
    Free(ode->slave_tasks);
  }
  Free(ode);
}

public I64 ODESize(CMathODE *ode)
{//Mem size of ode ctrl, but not masses and springs.
  if (!ode)
    return 0;
  else
    return MSize2(ode->state)+MSize2(ode->array_base)+MSize2(ode);
}

U0 ODESetMassesPtrs(CMathODE *ode,F64 *state,F64 *DstateDt)
{
  COrder2D3 *ptr1=state(F64 *)+ode->n,
        *ptr2=DstateDt(F64 *)+ode->n;
  CMass *tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    tmpm->state=ptr1++;
    tmpm->DstateDt=ptr2++;
    tmpm=tmpm->next;
  }
}

U0 ODEState2Internal(CMathODE *ode)
{
  CMass *tmpm;
  F64 *old_array_base;
  I64 mass_cnt;

  if (ode->flags&ODEF_HAS_MASSES) {
    mass_cnt=0;
    tmpm=ode->next_mass;
    while (tmpm!=&ode->next_mass) {
      mass_cnt++;
      tmpm=tmpm->next;
    }
    old_array_base=ode->array_base;
    ode->n_internal=ode->n+6*mass_cnt;
    ode->array_base=MAlloc(12*ode->n_internal*sizeof(F64),ode->mem_task);
    Free(old_array_base);
    ODERstPtrs(ode);

    ODESetMassesPtrs(ode,ode->state_internal,ode->state_internal);
    tmpm=ode->next_mass;
    while (tmpm!=&ode->next_mass) {
      MemCpy(tmpm->state,&tmpm->saved_state,sizeof(COrder2D3));
      tmpm=tmpm->next;
    }
  }
  MemCpy(ode->state_internal,ode->state,ode->n*sizeof(F64));
}

U0 ODEInternal2State(CMathODE *ode)
{
  CMass *tmpm;
  MemCpy(ode->state,ode->state_internal,ode->n*sizeof(F64));
  if (ode->flags&ODEF_HAS_MASSES) {
    ODESetMassesPtrs(ode,ode->state_internal,ode->state_internal);
    tmpm=ode->next_mass;
    while (tmpm!=&ode->next_mass) {
      MemCpy(&tmpm->saved_state,tmpm->state,sizeof(COrder2D3));
      tmpm=tmpm->next;
    }
  }
}

public U0 ODERenum(CMathODE *ode)
{//Renumber masses and springs.
  I64 i;
  CSpring *tmps;
  CMass *tmpm;

  i=0;
  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    tmpm->num=i++;
    tmpm=tmpm->next;
  }

  i=0;
  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    tmps->num=i++;
    tmps->end1_num=tmps->end1->num;
    tmps->end2_num=tmps->end2->num;
    tmps=tmps->next;
  }
}

public CMass *MassFind(CMathODE *ode,F64 x,F64 y,F64 z=0)
{//Search for mass nearest to x,y,z.
  CMass *tmpm,*best_mass=NULL;
  F64 dd,best_dd=F64_MAX;

  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    dd=Sqr(tmpm->x-x)+Sqr(tmpm->y-y)+Sqr(tmpm->z-z);
    if (dd<best_dd) {
      best_dd=dd;
      best_mass=tmpm;
    }
    tmpm=tmpm->next;
  }
  return best_mass;
}

public CSpring *SpringFind(CMathODE *ode,F64 x,F64 y,F64 z=0)
{//Find spring midpoint nearest x,y,z.
  CSpring *tmps,*best_spring=NULL;
  F64 dd,best_dd=F64_MAX;

  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    dd=Sqr((tmps->end1->x+tmps->end2->x)/2-x)+
          Sqr((tmps->end1->y+tmps->end2->y)/2-y)+
          Sqr((tmps->end1->z+tmps->end2->z)/2-z);
    if (dd<best_dd) {
      best_dd=dd;
      best_spring=tmps;
    }
    tmps=tmps->next;
  }
  return best_spring;
}

public U0 MassOrSpringFind(
        CMathODE *ode,CMass **res_mass,CSpring **res_spring,
        F64 x,F64 y,F64 z=0)
{//Find spring or mass nearest x,y,z.
  CMass   *tmpm,*best_mass=NULL;
  CSpring *tmps,*best_spring=NULL;
  F64 dd,best_dd=F64_MAX;

  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    dd=Sqr(tmpm->x-x)+Sqr(tmpm->y-y)+Sqr(tmpm->z-z);
    if (dd<best_dd) {
      best_dd=dd;
      best_mass=tmpm;
    }
    tmpm=tmpm->next;
  }

  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    dd=Sqr((tmps->end1->x+tmps->end2->x)/2-x)+
          Sqr((tmps->end1->y+tmps->end2->y)/2-y)+
          Sqr((tmps->end1->z+tmps->end2->z)/2-z);
    if (dd<best_dd) {
      best_dd=dd;
      best_spring=tmps;
      best_mass=NULL;
    }
    tmps=tmps->next;
  }
  if (res_mass)   *res_mass  =best_mass;
  if (res_spring) *res_spring=best_spring;
}

public CMass *MassFindNum(CMathODE *ode,I64 num)
{//Return mass number N.
  CMass *tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    if (tmpm->num==num)
      return tmpm;
    tmpm=tmpm->next;
  }
  return NULL;
}

public U0 ODERstInactive(CMathODE *ode)
{//Set all masses and springs to ACTIVE for new trial.
  CMass *tmpm;
  CSpring

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\AMathODE-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Math/ODE"
#help_file "::/Doc/ODE"

//See ::/Doc/Credits.DD.

F64 LowPass1(F64 a,F64 y0,F64 y,F64 dt=1.0)
{//First order low pass filter
  dt=Exp(-a*dt);
  return y0*dt+y*(1.0-dt);
}

U0 ODERstPtrs(CMathODE *ode)
{
  I64 s=ode->n_internal*sizeof(F64);
  F64 *ptr=ode->array_base;
  ode->state_internal=ptr;      ptr(I64)+=s;
  ode->state_scale=ptr;         ptr(I64)+=s;
  ode->DstateDt=ptr;            ptr(I64)+=s;
  ode->initial_state=ptr;       ptr(I64)+=s;
  ode->tmp0=ptr;        ptr(I64)+=s;
  ode->tmp1=ptr;        ptr(I64)+=s;
  ode->tmp2=ptr;        ptr(I64)+=s;
  ode->tmp3=ptr;        ptr(I64)+=s;
  ode->tmp4=ptr;        ptr(I64)+=s;
  ode->tmp5=ptr;        ptr(I64)+=s;
  ode->tmp6=ptr;        ptr(I64)+=s;
  ode->tmp7=ptr;
}

public CMathODE *ODENew(I64 n,F64 max_tolerance=1e-6,I64 flags=0)
{//Make differential equation ctrl struct. See flags.
  //The tolerance is not precise.
  //You can min_tolerance and it will
  //dynamically adjust tolerance to utilize
  //the CPU.
  I64 s=n*sizeof(F64);
  CMathODE *ode=CAlloc(sizeof(CMathODE));
  ode->t_scale=1.0;
  ode->flags=flags;
  ode->n_internal=ode->n=n;
  ode->h=1e-6;
  ode->h_min=1e-64;
  ode->h_max=1e32;
  ode->max_tolerance=ode->min_tolerance=ode->tolerance_internal=max_tolerance;
  ode->win_task=ode->mem_task=Fs;
  QueInit(&ode->next_mass);
  QueInit(&ode->next_spring);
  ode->state=CAlloc(s);
  ode->array_base=MAlloc(12*s);
  ODERstPtrs(ode);
  return ode;
}

public Bool ODEPause(CMathODE *ode,Bool val=ON)
{//Pause ODE.
  Bool res;
  if (!ode) return OFF;
  res=LBEqu(&ode->flags,ODEf_PAUSED,val);
  if (val)
    while (Bt(&ode->flags,ODEf_BUSY))
      Yield;
  return res;
}

public U0 ODEDel(CMathODE *ode)
{//Free ODE node, but not masses or springs.
  I64 i;
  if (!ode) return;
  ODEPause(ode);
  Free(ode->state);
  Free(ode->array_base);
  if (ode->slave_tasks) {
    for (i=0;i<mp_cnt;i++)
      Kill(ode->slave_tasks[i]);
    Free(ode->slave_tasks);
  }
  Free(ode);
}

public I64 ODESize(CMathODE *ode)
{//Mem size of ode ctrl, but not masses and springs.
  if (!ode)
    return 0;
  else
    return MSize2(ode->state)+MSize2(ode->array_base)+MSize2(ode);
}

U0 ODESetMassesPtrs(CMathODE *ode,F64 *state,F64 *DstateDt)
{
  COrder2D3 *ptr1=state(F64 *)+ode->n,
        *ptr2=DstateDt(F64 *)+ode->n;
  CMass *tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    tmpm->state=ptr1++;
    tmpm->DstateDt=ptr2++;
    tmpm=tmpm->next;
  }
}

U0 ODEState2Internal(CMathODE *ode)
{
  CMass *tmpm;
  F64 *old_array_base;
  I64 mass_cnt;

  if (ode->flags&ODEF_HAS_MASSES) {
    mass_cnt=0;
    tmpm=ode->next_mass;
    while (tmpm!=&ode->next_mass) {
      mass_cnt++;
      tmpm=tmpm->next;
    }
    old_array_base=ode->array_base;
    ode->n_internal=ode->n+6*mass_cnt;
    ode->array_base=MAlloc(12*ode->n_internal*sizeof(F64),ode->mem_task);
    Free(old_array_base);
    ODERstPtrs(ode);

    ODESetMassesPtrs(ode,ode->state_internal,ode->state_internal);
    tmpm=ode->next_mass;
    while (tmpm!=&ode->next_mass) {
      MemCpy(tmpm->state,&tmpm->saved_state,sizeof(COrder2D3));
      tmpm=tmpm->next;
    }
  }
  MemCpy(ode->state_internal,ode->state,ode->n*sizeof(F64));
}

U0 ODEInternal2State(CMathODE *ode)
{
  CMass *tmpm;
  MemCpy(ode->state,ode->state_internal,ode->n*sizeof(F64));
  if (ode->flags&ODEF_HAS_MASSES) {
    ODESetMassesPtrs(ode,ode->state_internal,ode->state_internal);
    tmpm=ode->next_mass;
    while (tmpm!=&ode->next_mass) {
      MemCpy(&tmpm->saved_state,tmpm->state,sizeof(COrder2D3));
      tmpm=tmpm->next;
    }
  }
}

public U0 ODERenum(CMathODE *ode)
{//Renumber masses and springs.
  I64 i;
  CSpring *tmps;
  CMass *tmpm;

  i=0;
  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    tmpm->num=i++;
    tmpm=tmpm->next;
  }

  i=0;
  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    tmps->num=i++;
    tmps->end1_num=tmps->end1->num;
    tmps->end2_num=tmps->end2->num;
    tmps=tmps->next;
  }
}

public CMass *MassFind(CMathODE *ode,F64 x,F64 y,F64 z=0)
{//Search for mass nearest to x,y,z.
  CMass *tmpm,*best_mass=NULL;
  F64 dd,best_dd=F64_MAX;

  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    dd=Sqr(tmpm->x-x)+Sqr(tmpm->y-y)+Sqr(tmpm->z-z);
    if (dd<best_dd) {
      best_dd=dd;
      best_mass=tmpm;
    }
    tmpm=tmpm->next;
  }
  return best_mass;
}

public CSpring *SpringFind(CMathODE *ode,F64 x,F64 y,F64 z=0)
{//Find spring midpoint nearest x,y,z.
  CSpring *tmps,*best_spring=NULL;
  F64 dd,best_dd=F64_MAX;

  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    dd=Sqr((tmps->end1->x+tmps->end2->x)/2-x)+
          Sqr((tmps->end1->y+tmps->end2->y)/2-y)+
          Sqr((tmps->end1->z+tmps->end2->z)/2-z);
    if (dd<best_dd) {
      best_dd=dd;
      best_spring=tmps;
    }
    tmps=tmps->next;
  }
  return best_spring;
}

public U0 MassOrSpringFind(
        CMathODE *ode,CMass **res_mass,CSpring **res_spring,
        F64 x,F64 y,F64 z=0)
{//Find spring or mass nearest x,y,z.
  CMass   *tmpm,*best_mass=NULL;
  CSpring *tmps,*best_spring=NULL;
  F64 dd,best_dd=F64_MAX;

  tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    dd=Sqr(tmpm->x-x)+Sqr(tmpm->y-y)+Sqr(tmpm->z-z);
    if (dd<best_dd) {
      best_dd=dd;
      best_mass=tmpm;
    }
    tmpm=tmpm->next;
  }

  tmps=ode->next_spring;
  while (tmps!=&ode->next_spring) {
    dd=Sqr((tmps->end1->x+tmps->end2->x)/2-x)+
          Sqr((tmps->end1->y+tmps->end2->y)/2-y)+
          Sqr((tmps->end1->z+tmps->end2->z)/2-z);
    if (dd<best_dd) {
      best_dd=dd;
      best_spring=tmps;
      best_mass=NULL;
    }
    tmps=tmps->next;
  }
  if (res_mass)   *res_mass  =best_mass;
  if (res_spring) *res_spring=best_spring;
}

public CMass *MassFindNum(CMathODE *ode,I64 num)
{//Return mass number N.
  CMass *tmpm=ode->next_mass;
  while (tmpm!=&ode->next_mass) {
    if (tmpm->num==num)
      return tmpm;
    tmpm=tmpm->next;
  }
  return NULL;
}

public U0 ODERstInactive(CMathODE *ode)
{//Set all masses and springs to ACTIVE for new trial.
  CMass *tmpm;
  CSpring


// Source: D:\TempleOS-Projects\html\FileRead-DolDoc-Demo.html
// Date: unknown-date
// Language: HolyC

public U0 DocProfile(U8 *filename,I64 flags)
{
  I64 i,*cmd_stats=CAlloc(sizeof(I64)*DOCT_TYPES_NUM),
        *flags_stats=CAlloc(sizeof(I64)*64),
        *type_flags_stats=CAlloc(sizeof(I64)*64);
//Note: word wrap is determined by
  //doc->win_task when a CDoc is recalculated
  //use DocRecalc().
  CDoc *doc=DocRead(filename,flags);

  //doc->head which is equ to doc is the
  //header of the CQue and represents the end-of-file marker.
  CDocEntry *doc_e=doc->head.next;
  while (doc_e!=doc) {
    cmd_stats[doc_e->type_u8]++;
    for (i=0;i<64;i++)
      if (Bt(&doc_e->de_flags,i))
        flags_stats[i]++;
    for (i=16;i<32;i++)
      if (Bt(&doc_e->type,i))
        type_flags_stats[i]++;
    doc_e=doc_e->next;
  }
  DocDel(doc);

  "$PURPLE$-------%s-------\n",filename;
  "$GREEN$The lowest byte of the 32-bit 'doc_e->type', "
        "'$PURPLE$doc_e->type.u8[0]$GREEN$', "
        "is cmd and accessed with the union "
        "'$PURPLE$doc_e->type_u8$GREEN$'.  "
        "See $LK,\"CDocEntry\",A=\"MN:CDocEntry\"$, "
        "$LK,\"Doc Type Defines\",A=\"MN:DOCT_TEXT\"$ and "
        "$LK,\"Doc Type Codes\","
        "A=\"FF:::/Adam/DolDoc/DocInit.HC,ST_DOC_CMDS\"$.\n"
        "$FG$";
  for (i=0;i<DOCT_TYPES_NUM;i++)
    if (cmd_stats[i])
      "%4Z:%d\n",i,"ST_DOC_CMDS",cmd_stats[i];

  "\n$GREEN$'$PURPLE$doc_e->type.u8[1]$GREEN$' is "
        "the scrn color attr of the "
        "entry.  '$PURPLE$doc_e->type.u16[1]"
        "$GREEN$' is some flags for blinking and "
        "stuff.  See $LK,\"Doc Type Flag "
        "Defines\",A=\"MN:DOCET_BLINK\"$.\n$FG$";

  for (i=16;i<32;i++)
    if (type_flags_stats[i])
      "%4d:%d\n",i,type_flags_stats[i];

  "$GREEN$\n'$PURPLE$doc_e->de_flags$GREEN$' is 64-bit.  "
        "See $LK,\"Doc Flag Defines\",A=\"MN:DOCEf_TAG\"$ and "
        "$LK,\"Doc Flag Codes\","
        "A=\"FF:::/Adam/DolDoc/DocInit.HC,ST_DOC_FLAGS\"$.\n"
        "$FG$";
  for (i=0;i<64;i++)
    if (flags_stats[i])
      "%4Z:%d\n",i,"ST_DOC_FLAGS",flags_stats[i];

  Free(cmd_stats);
  Free(flags_stats);
  PressAKey;
  '\n';
}

/*See TipOfDay.

Note: Not all CDocEntry's are full-sized nodes.
Some are MAlloced with a smaller size to save
mem.    They all have at least the size CDocEntryBase.

Note: CDocEntry's should be alloced from the
heap of the owning task, doc->mem_task.

The flag arrays doldoc.type_flags_form, etc
are useful.
*/

DocProfile("::/Doc/ChgLog.DD",0);
DocProfile("::/Doc/ChgLog.DD",DOCF_PLAIN_TEXT);

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\FileRead-DolDoc-Demo.html
// Date: unknown-date
// Language: HolyC

public U0 DocProfile(U8 *filename,I64 flags)
{
  I64 i,*cmd_stats=CAlloc(sizeof(I64)*DOCT_TYPES_NUM),
        *flags_stats=CAlloc(sizeof(I64)*64),
        *type_flags_stats=CAlloc(sizeof(I64)*64);
//Note: word wrap is determined by
  //doc->win_task when a CDoc is recalculated
  //use DocRecalc().
  CDoc *doc=DocRead(filename,flags);

  //doc->head which is equ to doc is the
  //header of the CQue and represents the end-of-file marker.
  CDocEntry *doc_e=doc->head.next;
  while (doc_e!=doc) {
    cmd_stats[doc_e->type_u8]++;
    for (i=0;i<64;i++)
      if (Bt(&doc_e->de_flags,i))
        flags_stats[i]++;
    for (i=16;i<32;i++)
      if (Bt(&doc_e->type,i))
        type_flags_stats[i]++;
    doc_e=doc_e->next;
  }
  DocDel(doc);

  "$PURPLE$-------%s-------\n",filename;
  "$GREEN$The lowest byte of the 32-bit 'doc_e->type', "
        "'$PURPLE$doc_e->type.u8[0]$GREEN$', "
        "is cmd and accessed with the union "
        "'$PURPLE$doc_e->type_u8$GREEN$'.  "
        "See $LK,\"CDocEntry\",A=\"MN:CDocEntry\"$, "
        "$LK,\"Doc Type Defines\",A=\"MN:DOCT_TEXT\"$ and "
        "$LK,\"Doc Type Codes\","
        "A=\"FF:::/Adam/DolDoc/DocInit.HC,ST_DOC_CMDS\"$.\n"
        "$FG$";
  for (i=0;i<DOCT_TYPES_NUM;i++)
    if (cmd_stats[i])
      "%4Z:%d\n",i,"ST_DOC_CMDS",cmd_stats[i];

  "\n$GREEN$'$PURPLE$doc_e->type.u8[1]$GREEN$' is "
        "the scrn color attr of the "
        "entry.  '$PURPLE$doc_e->type.u16[1]"
        "$GREEN$' is some flags for blinking and "
        "stuff.  See $LK,\"Doc Type Flag "
        "Defines\",A=\"MN:DOCET_BLINK\"$.\n$FG$";

  for (i=16;i<32;i++)
    if (type_flags_stats[i])
      "%4d:%d\n",i,type_flags_stats[i];

  "$GREEN$\n'$PURPLE$doc_e->de_flags$GREEN$' is 64-bit.  "
        "See $LK,\"Doc Flag Defines\",A=\"MN:DOCEf_TAG\"$ and "
        "$LK,\"Doc Flag Codes\","
        "A=\"FF:::/Adam/DolDoc/DocInit.HC,ST_DOC_FLAGS\"$.\n"
        "$FG$";
  for (i=0;i<64;i++)
    if (flags_stats[i])
      "%4Z:%d\n",i,"ST_DOC_FLAGS",flags_stats[i];

  Free(cmd_stats);
  Free(flags_stats);
  PressAKey;
  '\n';
}

/*See TipOfDay.

Note: Not all CDocEntry's are full-sized nodes.
Some are MAlloced with a smaller size to save
mem.    They all have at least the size CDocEntryBase.

Note: CDocEntry's should be alloced from the
heap of the owning task, doc->mem_task.

The flag arrays doldoc.type_flags_form, etc
are useful.
*/

DocProfile("::/Doc/ChgLog.DD",0);
DocProfile("::/Doc/ChgLog.DD",DOCF_PLAIN_TEXT);


// Source: D:\TempleOS-Projects\html\fog-Sup1-Sup1Hymns-Home.html
// Date: unknown-date
// Language: HolyC

//5 has graphics

<1>/* Graphics Not Rendered in HTML */

#define LH_X 260
#define LH_Y 20

F64 t0=Beat;

U0 DrawIt(CTask *,CDC *dc)
{
  F64 dt=Beat-t0,y;
  Sprite3(dc,LH_X,LH_Y,0,<1>);
  if (dt>24) {
    dc->color=YELLOW;
    for (y=-30;y<30;y+=5)
      GrLine(dc,LH_X,LH_Y,LH_X+80*(dt-28),LH_Y+y);
  }
}

U0 Song()
{
  SettingsPush; //See SettingsPush
  Fs->draw_it=&DrawIt;
  Fs->task_end_cb=&SndTaskEndCB;

  MusicSettingsRst;
  music.tempo= 2.500;
  music.stacatto_factor= 0.900;
  try {
    while (!ScanKey) {
      t0=Beat;
      Play("4etA5CDsEEEEetGG4GqGetGBAqBetRB5GC4A5G",
            "I \0walk \0 \0bo-\0o-\0ld\0ly \0 \0 \0 \0 \0 \0"
            "though \0the \0fog.\n\0 \0 \0 \0 \0 \0 \0");
      Play("4A5CDsEEEEetGG4GqGetGBAqBetRB5GC4A5G",
            "I \0got \0 \0lit\0 \0tle \0 \0choice \0 \0 \0 \0"
            "but \0to \0trust \0God.\n\0 \0 \0 \0 \0 \0 \0");
      Play("4qB5etCCCqCCeCCCDqEetE4B5G",
            " \0Don't \0 \0kno-\0ow \0 \0 \0 \0what \0"
            "to \0do.\n\0 \0 \0 \0");
      Play("4qB5etCCCqCCeCCCDqEetE4B5G",
            " \0Where \0I \0go-\0o, \0 \0 \0 \0I've \0"
            "no \0clue.\n\0 \0 \0 \0");
    }
  } catch
    PutExcept;
  SettingsPop;
}

Song;

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\fog-Sup1-Sup1Hymns-Home.html
// Date: unknown-date
// Language: HolyC

//5 has graphics

<1>/* Graphics Not Rendered in HTML */

#define LH_X 260
#define LH_Y 20

F64 t0=Beat;

U0 DrawIt(CTask *,CDC *dc)
{
  F64 dt=Beat-t0,y;
  Sprite3(dc,LH_X,LH_Y,0,<1>);
  if (dt>24) {
    dc->color=YELLOW;
    for (y=-30;y<30;y+=5)
      GrLine(dc,LH_X,LH_Y,LH_X+80*(dt-28),LH_Y+y);
  }
}

U0 Song()
{
  SettingsPush; //See SettingsPush
  Fs->draw_it=&DrawIt;
  Fs->task_end_cb=&SndTaskEndCB;

  MusicSettingsRst;
  music.tempo= 2.500;
  music.stacatto_factor= 0.900;
  try {
    while (!ScanKey) {
      t0=Beat;
      Play("4etA5CDsEEEEetGG4GqGetGBAqBetRB5GC4A5G",
            "I \0walk \0 \0bo-\0o-\0ld\0ly \0 \0 \0 \0 \0 \0"
            "though \0the \0fog.\n\0 \0 \0 \0 \0 \0 \0");
      Play("4A5CDsEEEEetGG4GqGetGBAqBetRB5GC4A5G",
            "I \0got \0 \0lit\0 \0tle \0 \0choice \0 \0 \0 \0"
            "but \0to \0trust \0God.\n\0 \0 \0 \0 \0 \0 \0");
      Play("4qB5etCCCqCCeCCCDqEetE4B5G",
            " \0Don't \0 \0kno-\0ow \0 \0 \0 \0what \0"
            "to \0do.\n\0 \0 \0 \0");
      Play("4qB5etCCCqCCeCCCDqEetE4B5G",
            " \0Where \0I \0go-\0o, \0 \0 \0 \0I've \0"
            "no \0clue.\n\0 \0 \0 \0");
    }
  } catch
    PutExcept;
  SettingsPop;
}

Song;


// Source: D:\TempleOS-Projects\html\Util2-Templates-Demo.html
// Date: unknown-date
// Language: HolyC

I64 MyUtilDoc(CDoc *doc,I64 fuf_flags)
{
  Bool unlock=DocLock(doc);
  I64 res=0;
  CDocEntry *doc_e;
  DocRecalc(doc);
  doc_e=doc->head.next;
  while (doc_e!=doc) {
    res++;
    doc_e=doc_e->next;
  }
  DocRecalc(doc);
  if (unlock)
    DocUnlock(doc);
  return res;
}

I64 MyUtilFile(U8 *filename,I64 fuf_flags)
{
  I64 res;
  CDoc *doc=DocRead(filename);
  if (res=MyUtilDoc(doc,fuf_flags)) {
    "%8d:%s\n",res,doc->filename.name;
    DocWrite(doc);
  }
  DocDel(doc);
  return res;
}
I64 MyUtilLst(CDirEntry *tmpde,I64 fuf_flags)
{
  I64 res=0;
  CDirEntry *tmpde1;
  while (tmpde) {
    tmpde1=tmpde->next;
    if (tmpde->attr & RS_ATTR_DIR) {
      if (tmpde->sub) {
        "Processing Directory: %s\n",tmpde->full_name;
        res+=MyUtilLst(tmpde->sub,fuf_flags);
      }
    } else
      res+=MyUtilFile(tmpde->full_name,fuf_flags);
    DirEntryDel(tmpde);
    tmpde=tmpde1;
  }
  return res;
}
I64 MyUtil(U8 *files_find_mask="*",U8 *fu_flags=NULL)
{
  I64 fuf_flags=0;
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+$");
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  return MyUtilLst(FilesFind(files_find_mask,fuf_flags&FUG_FILES_FIND),
        fuf_flags&~FUG_FILES_FIND);
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\Util2-Templates-Demo.html
// Date: unknown-date
// Language: HolyC

I64 MyUtilDoc(CDoc *doc,I64 fuf_flags)
{
  Bool unlock=DocLock(doc);
  I64 res=0;
  CDocEntry *doc_e;
  DocRecalc(doc);
  doc_e=doc->head.next;
  while (doc_e!=doc) {
    res++;
    doc_e=doc_e->next;
  }
  DocRecalc(doc);
  if (unlock)
    DocUnlock(doc);
  return res;
}

I64 MyUtilFile(U8 *filename,I64 fuf_flags)
{
  I64 res;
  CDoc *doc=DocRead(filename);
  if (res=MyUtilDoc(doc,fuf_flags)) {
    "%8d:%s\n",res,doc->filename.name;
    DocWrite(doc);
  }
  DocDel(doc);
  return res;
}
I64 MyUtilLst(CDirEntry *tmpde,I64 fuf_flags)
{
  I64 res=0;
  CDirEntry *tmpde1;
  while (tmpde) {
    tmpde1=tmpde->next;
    if (tmpde->attr & RS_ATTR_DIR) {
      if (tmpde->sub) {
        "Processing Directory: %s\n",tmpde->full_name;
        res+=MyUtilLst(tmpde->sub,fuf_flags);
      }
    } else
      res+=MyUtilFile(tmpde->full_name,fuf_flags);
    DirEntryDel(tmpde);
    tmpde=tmpde1;
  }
  return res;
}
I64 MyUtil(U8 *files_find_mask="*",U8 *fu_flags=NULL)
{
  I64 fuf_flags=0;
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+$");
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  return MyUtilLst(FilesFind(files_find_mask,fuf_flags&FUG_FILES_FIND),
        fuf_flags&~FUG_FILES_FIND);
}


// Source: D:\TempleOS-Projects\html\SpriteEdText-Doc.html
// Date: unknown-date
// Language: HolyC

Sprite Edit as Text Help

See the format for CSprites.

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\SpriteEdText-Doc.html
// Date: unknown-date
// Language: HolyC

Sprite Edit as Text Help

See the format for CSprites.


// Source: D:\TempleOS-Projects\html\CMain-Compiler.html
// Date: unknown-date
// Language: HolyC

U8 *LexStmt2Bin(CCmpCtrl *cc,I64 *_type,I64 cmp_flags=0)
{//Compile one cc stmt to bin code.
  I64 size,i,j,k,*res=INVALID_PTR;
  CCodeCtrl *tmpcbh;
  if (_type) *_type=RT_I64;
  Btr(&cc->flags,CCf_PASS_TRACE_PRESENT);
  if (cc->aot_depth==2)
    COCPush(cc);
  COCInit(cc);
  if (!PrsStmt(cc,,,cmp_flags)) {
    if (cc->coc.coc_head.next!=&cc->coc.coc_head) {
      cc->coc.coc_head.last->ic_flags&=~ICF_RES_NOT_USED;
      ICAdd(cc,IC_RETURN_VAL2,0,0);
      ICAdd(cc,IC_RET,0,0);
      if (res=COCCompile(cc,&size,NULL,_type)) {
        if (cc->flags&CCF_AOT_COMPILE) {
          j=cc->aotc->rip;
          k=(size+7)>>3;
          for (i=0;i<k;i++)
            AOTStoreCodeU64(cc,res[i]);
          Free(res);
          res=j;
        }
      }
    } //TODO: else del misc?
  } else //TODO: too dangerous to del Misc?
    QueDel(&cc->coc.coc_head.next);
  if (cc->aot_depth==2) {
    tmpcbh=COCPopNoFree(cc);
    COCAppend(cc,tmpcbh);
  }
  return res;
}

CAOT *CmpJoin(CCmpCtrl *cc,I64 cmp_flags,U8 *map_name=NULL,U8 mapfile_drv_let=0)
{
  CAOTCtrl *aotc,*old_aot=cc->aotc;
  I64 i,j,l;
  U8 *buf;
  CAOTBinBlk *tmpbin;
  CAOTImportExport *tmpie;
  Bool okay=TRUE;
  CLexHashTableContext *htc=MAlloc(sizeof(CLexHashTableContext));
  CAOT *res=CAlloc(sizeof(CAOT)),*parent;
  if (parent=cc->aot) {
    res->parent_aot=parent;
    QueIns(res,parent->last);
  } else
    QueInit(res);
  cc->aot=res;

  res->next_ie=res->last_ie=&res->next_ie;
  cc->aotc=aotc=CAlloc(sizeof(CAOTCtrl));
  cc->aot_depth++;

  aotc->bin=CAlloc(sizeof(CAOTBinBlk));
  aotc->max_align_bits=0;
  aotc->org=INVALID_PTR;

  MemCpy(htc,&cc->htc,sizeof(CLexHashTableContext));
  if (cc->htc.fun)
    cc->htc.glbl_hash_table=HashTableNew(128);
  else
    cc->htc.glbl_hash_table=HashTableNew(1024);
  if (cc->flags&CCF_AOT_COMPILE) {
    cc->htc.define_hash_table=cc->htc.glbl_hash_table;
    if (cc->aot_depth<=1)
      cc->htc.glbl_hash_table->next=cmp.asm_hash;
    else
      cc->htc.glbl_hash_table->next=htc->glbl_hash_table;
  } else
    cc->htc.glbl_hash_table->next=Fs->hash_table;
  cc->htc.hash_table_lst=cc->htc.local_hash_table=HashTableNew(16);
  cc->htc.local_hash_table->next=cc->htc.glbl_hash_table;
  cc->htc.local_var_lst=cc->htc.fun; //HolyC local vars
  cc->htc.fun=NULL;
  try {
    if (cmp_flags&CMPF_LEX_FIRST)
      Lex(cc);
    if (!(cmp_flags&CMPF_ONE_ASM_INS))
      cmp_flags|=CMPF_PRS_SEMICOLON;
    if (cc->flags&CCF_AOT_COMPILE) {
      while (cc->token!=TK_EOF) {
        buf=LexStmt2Bin(cc,NULL,cmp_flags);
        if (buf!=INVALID_PTR) {
          tmpie=CAlloc(sizeof(CAOTImportExport));
          tmpie->type=IET_MAIN;
          tmpie->rip=buf;
          QueIns(tmpie,res->last_ie);
        }
        if (cmp_flags&CMPF_ASM_BLK)
          break;
      }
    } else
      PrsStmt(cc,,,cmp_flags);
    AOTGlblsResolve(cc,res);
  } catch {
    if (Fs->except_ch=='Compiler' && !(cmp_flags&CMPF_ASM_BLK)) {
      LexPutPos(cc);
      Fs->catch_except=TRUE;
    }
    okay=FALSE;
  }
  if (!okay) {
    if (cc->error_cnt<1)
      cc->error_cnt=1;
    cc->aot=res->parent_aot;
    Free(res);
    LinkedLstDel(aotc->bin);
    res=NULL;
  } else {
    if (map_name)
      MapFileWrite(cc->htc.glbl_hash_table,map_name,mapfile_drv_let);
    HashTableDel(cc->htc.local_hash_table);
    HashTableDel(cc->htc.glbl_hash_table);

    if (!aotc->num_bin_U8s)
      res->buf=NULL;
    else {
      if (cc->flags&CCF_AOT_COMPILE)
        res->buf=MAlloc(aotc->num_bin_U8s);
      else {
        if (aotc->org==INVALID_PTR)
          res->buf=MAlloc(aotc->num_bin_U8s,Fs->code_heap);
        else
          res->buf=aotc->org;
      }
      res->aot_U8s=aotc->num_bin_U8s;
      tmpbin=aotc->bin;
      j=0;
      l=aotc->num_bin_U8s;
      while (tmpbin) {
        i=l;
        if (i>AOT_BIN_BLK_SIZE)
          i=AOT_BIN_BLK_SIZE;
        MemCpy(res->buf+j,tmpbin->body,i);
        j+=i;
        l-=i;
        tmpbin=tmpbin->next;
      }
    }
    LinkedLstDel(aotc->bin);
    res->abss=aotc->abss;
    res->heap_glbls=aotc->heap_glbls;
    res->max_align_bits=aotc->max_align_bits;
    res->org=aotc->org;
  }
  cc->aot=parent;
  MemCpy(&cc->htc,htc,sizeof(CLexHashTableContext));
  Free(htc);
  Free(aotc);
  cc->aotc=old_aot;
  cc->aot_depth--;
  return res;
}

CAOT *CmpBuf(U8 *buf,U8 *map_name=NULL,
  I64 *error_cnt=NULL, I64 *warning_cnt=NULL,U8 mapfile_drv_let=0)
{
  CCmpCtrl *cc;
  CAOT *res=NULL;
  cc=CmpCtrlNew(buf,CCF_DONT_FREE_BUF);
  cc->flags|=CCF_AOT_COMPILE;
  QueIns(cc,Fs->last_cc);
  res=CmpJoin(cc,CMPF_LEX_FIRST,map_name,mapfile_drv_let);
  if (error_cnt)   *error_cnt=cc->error_cnt;
  if (warning_cnt) *warning_cnt=cc->warning_cnt;
  QueRem(cc);
  if (res)
    CmpCtrlDel(cc);
  return res;
}

U0 CmpFixUpJITAsm(CCmpCtrl *cc,CAOT *tmpaot)
{
  I64 i,rip2=tmpaot->buf+tmpaot->rip,*str=NULL;
  U8 *ptr;
  CCodeMisc *g_lb;
  CAOTAbsAddr *tmpa,*tmpa1;
  CAOTImportExport *tmpie,*tmpie1;
  CHashExport *tmpex;

  tmpa=tmpaot->abss;
  while (tmpa) {
    tmpa1=tmpa->next;
    ptr=rip2+tmpa->rip;
    switch [tmpa->type] {
      case AAT_ADD_U8:  *ptr(U8 *) +=rip2; break;
      case AAT_SUB_U8:  *ptr(U8 *) -=rip2; break;
      case AAT_ADD_U16: *ptr(U16 *)+=rip2; break;
      case AAT_SUB_U16: *ptr(U16 *)-=rip2; break;
      case AAT_ADD_U32: *ptr(U32 *)+=rip2; break;
      case AAT_SUB_U32: *ptr(U32 *)-=rip2; break;
      case AAT_ADD_U64: *ptr(I64 *)+=rip2; break;
      case AAT_SUB_U64: *ptr(I64 *)-=rip2; break;
    }
    Free(tmpa);
    tmpa=tmpa1;
  }
  tmpie=tmpaot->next_ie;
  while (tmpie!=&tmpaot->next_ie) {
    tmpie1=tmpie->next;
    if (tmpie->str) {
      Free(str);
      str=tmpie->str;
    }
    switch (tmpie->type) {
      case IET_REL32_EXPORT:
      case IET_IMM32_EXPORT:
      case IET_REL64_EXPORT:
      case IET_IMM64_EXPORT:
        tmpex=CAlloc(sizeof(CHashExport));
        tmpex->str=str;
        str=NULL;
        tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
        if (tmpie->type==IET_IMM32_EXPORT||tmpie->type==IET_IMM64_EXPORT)
          tmpex->val=tmpie->rip;
        else
          tmpex->va

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\CMain-Compiler.html
// Date: unknown-date
// Language: HolyC

U8 *LexStmt2Bin(CCmpCtrl *cc,I64 *_type,I64 cmp_flags=0)
{//Compile one cc stmt to bin code.
  I64 size,i,j,k,*res=INVALID_PTR;
  CCodeCtrl *tmpcbh;
  if (_type) *_type=RT_I64;
  Btr(&cc->flags,CCf_PASS_TRACE_PRESENT);
  if (cc->aot_depth==2)
    COCPush(cc);
  COCInit(cc);
  if (!PrsStmt(cc,,,cmp_flags)) {
    if (cc->coc.coc_head.next!=&cc->coc.coc_head) {
      cc->coc.coc_head.last->ic_flags&=~ICF_RES_NOT_USED;
      ICAdd(cc,IC_RETURN_VAL2,0,0);
      ICAdd(cc,IC_RET,0,0);
      if (res=COCCompile(cc,&size,NULL,_type)) {
        if (cc->flags&CCF_AOT_COMPILE) {
          j=cc->aotc->rip;
          k=(size+7)>>3;
          for (i=0;i<k;i++)
            AOTStoreCodeU64(cc,res[i]);
          Free(res);
          res=j;
        }
      }
    } //TODO: else del misc?
  } else //TODO: too dangerous to del Misc?
    QueDel(&cc->coc.coc_head.next);
  if (cc->aot_depth==2) {
    tmpcbh=COCPopNoFree(cc);
    COCAppend(cc,tmpcbh);
  }
  return res;
}

CAOT *CmpJoin(CCmpCtrl *cc,I64 cmp_flags,U8 *map_name=NULL,U8 mapfile_drv_let=0)
{
  CAOTCtrl *aotc,*old_aot=cc->aotc;
  I64 i,j,l;
  U8 *buf;
  CAOTBinBlk *tmpbin;
  CAOTImportExport *tmpie;
  Bool okay=TRUE;
  CLexHashTableContext *htc=MAlloc(sizeof(CLexHashTableContext));
  CAOT *res=CAlloc(sizeof(CAOT)),*parent;
  if (parent=cc->aot) {
    res->parent_aot=parent;
    QueIns(res,parent->last);
  } else
    QueInit(res);
  cc->aot=res;

  res->next_ie=res->last_ie=&res->next_ie;
  cc->aotc=aotc=CAlloc(sizeof(CAOTCtrl));
  cc->aot_depth++;

  aotc->bin=CAlloc(sizeof(CAOTBinBlk));
  aotc->max_align_bits=0;
  aotc->org=INVALID_PTR;

  MemCpy(htc,&cc->htc,sizeof(CLexHashTableContext));
  if (cc->htc.fun)
    cc->htc.glbl_hash_table=HashTableNew(128);
  else
    cc->htc.glbl_hash_table=HashTableNew(1024);
  if (cc->flags&CCF_AOT_COMPILE) {
    cc->htc.define_hash_table=cc->htc.glbl_hash_table;
    if (cc->aot_depth<=1)
      cc->htc.glbl_hash_table->next=cmp.asm_hash;
    else
      cc->htc.glbl_hash_table->next=htc->glbl_hash_table;
  } else
    cc->htc.glbl_hash_table->next=Fs->hash_table;
  cc->htc.hash_table_lst=cc->htc.local_hash_table=HashTableNew(16);
  cc->htc.local_hash_table->next=cc->htc.glbl_hash_table;
  cc->htc.local_var_lst=cc->htc.fun; //HolyC local vars
  cc->htc.fun=NULL;
  try {
    if (cmp_flags&CMPF_LEX_FIRST)
      Lex(cc);
    if (!(cmp_flags&CMPF_ONE_ASM_INS))
      cmp_flags|=CMPF_PRS_SEMICOLON;
    if (cc->flags&CCF_AOT_COMPILE) {
      while (cc->token!=TK_EOF) {
        buf=LexStmt2Bin(cc,NULL,cmp_flags);
        if (buf!=INVALID_PTR) {
          tmpie=CAlloc(sizeof(CAOTImportExport));
          tmpie->type=IET_MAIN;
          tmpie->rip=buf;
          QueIns(tmpie,res->last_ie);
        }
        if (cmp_flags&CMPF_ASM_BLK)
          break;
      }
    } else
      PrsStmt(cc,,,cmp_flags);
    AOTGlblsResolve(cc,res);
  } catch {
    if (Fs->except_ch=='Compiler' && !(cmp_flags&CMPF_ASM_BLK)) {
      LexPutPos(cc);
      Fs->catch_except=TRUE;
    }
    okay=FALSE;
  }
  if (!okay) {
    if (cc->error_cnt<1)
      cc->error_cnt=1;
    cc->aot=res->parent_aot;
    Free(res);
    LinkedLstDel(aotc->bin);
    res=NULL;
  } else {
    if (map_name)
      MapFileWrite(cc->htc.glbl_hash_table,map_name,mapfile_drv_let);
    HashTableDel(cc->htc.local_hash_table);
    HashTableDel(cc->htc.glbl_hash_table);

    if (!aotc->num_bin_U8s)
      res->buf=NULL;
    else {
      if (cc->flags&CCF_AOT_COMPILE)
        res->buf=MAlloc(aotc->num_bin_U8s);
      else {
        if (aotc->org==INVALID_PTR)
          res->buf=MAlloc(aotc->num_bin_U8s,Fs->code_heap);
        else
          res->buf=aotc->org;
      }
      res->aot_U8s=aotc->num_bin_U8s;
      tmpbin=aotc->bin;
      j=0;
      l=aotc->num_bin_U8s;
      while (tmpbin) {
        i=l;
        if (i>AOT_BIN_BLK_SIZE)
          i=AOT_BIN_BLK_SIZE;
        MemCpy(res->buf+j,tmpbin->body,i);
        j+=i;
        l-=i;
        tmpbin=tmpbin->next;
      }
    }
    LinkedLstDel(aotc->bin);
    res->abss=aotc->abss;
    res->heap_glbls=aotc->heap_glbls;
    res->max_align_bits=aotc->max_align_bits;
    res->org=aotc->org;
  }
  cc->aot=parent;
  MemCpy(&cc->htc,htc,sizeof(CLexHashTableContext));
  Free(htc);
  Free(aotc);
  cc->aotc=old_aot;
  cc->aot_depth--;
  return res;
}

CAOT *CmpBuf(U8 *buf,U8 *map_name=NULL,
  I64 *error_cnt=NULL, I64 *warning_cnt=NULL,U8 mapfile_drv_let=0)
{
  CCmpCtrl *cc;
  CAOT *res=NULL;
  cc=CmpCtrlNew(buf,CCF_DONT_FREE_BUF);
  cc->flags|=CCF_AOT_COMPILE;
  QueIns(cc,Fs->last_cc);
  res=CmpJoin(cc,CMPF_LEX_FIRST,map_name,mapfile_drv_let);
  if (error_cnt)   *error_cnt=cc->error_cnt;
  if (warning_cnt) *warning_cnt=cc->warning_cnt;
  QueRem(cc);
  if (res)
    CmpCtrlDel(cc);
  return res;
}

U0 CmpFixUpJITAsm(CCmpCtrl *cc,CAOT *tmpaot)
{
  I64 i,rip2=tmpaot->buf+tmpaot->rip,*str=NULL;
  U8 *ptr;
  CCodeMisc *g_lb;
  CAOTAbsAddr *tmpa,*tmpa1;
  CAOTImportExport *tmpie,*tmpie1;
  CHashExport *tmpex;

  tmpa=tmpaot->abss;
  while (tmpa) {
    tmpa1=tmpa->next;
    ptr=rip2+tmpa->rip;
    switch [tmpa->type] {
      case AAT_ADD_U8:  *ptr(U8 *) +=rip2; break;
      case AAT_SUB_U8:  *ptr(U8 *) -=rip2; break;
      case AAT_ADD_U16: *ptr(U16 *)+=rip2; break;
      case AAT_SUB_U16: *ptr(U16 *)-=rip2; break;
      case AAT_ADD_U32: *ptr(U32 *)+=rip2; break;
      case AAT_SUB_U32: *ptr(U32 *)-=rip2; break;
      case AAT_ADD_U64: *ptr(I64 *)+=rip2; break;
      case AAT_SUB_U64: *ptr(I64 *)-=rip2; break;
    }
    Free(tmpa);
    tmpa=tmpa1;
  }
  tmpie=tmpaot->next_ie;
  while (tmpie!=&tmpaot->next_ie) {
    tmpie1=tmpie->next;
    if (tmpie->str) {
      Free(str);
      str=tmpie->str;
    }
    switch (tmpie->type) {
      case IET_REL32_EXPORT:
      case IET_IMM32_EXPORT:
      case IET_REL64_EXPORT:
      case IET_IMM64_EXPORT:
        tmpex=CAlloc(sizeof(CHashExport));
        tmpex->str=str;
        str=NULL;
        tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
        if (tmpie->type==IET_IMM32_EXPORT||tmpie->type==IET_IMM64_EXPORT)
          tmpex->val=tmpie->rip;
        else
          tmpex->va


// Source: D:\TempleOS-Projects\html\Install-ToTheFront-Apps.html
// Date: unknown-date
// Language: HolyC

DirMk("~/ToTheFront");

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\Install-ToTheFront-Apps.html
// Date: unknown-date
// Language: HolyC

DirMk("~/ToTheFront");