Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
Training.txt186 linesDownload Raw Back to Adam
1 2#help_index "Help System"3 4U8 *KeyMapKeyMStrPrint(I64 sc,U0 (*fp_hndlr)(I64 sc),5        U8 *desc,CTask *task=NULL)6{7  I64 i=9,k,c;8  U8 *st,*st2,*res,*ptr;9  CHashTable *old_hash=Fs->hash_table;10  st=ScanCode2KeyName(sc);11  if (sc&SCF_CTRL)      i+=5;12  if (sc&SCF_ALT)       i+=4;13  if (sc&(SCF_SHIFT|SCF_NO_SHIFT)) i+=6;14  if (TaskValidate(task))15    Fs->hash_table=task->hash_table;16  st2=SrcEdLink(fp_hndlr,256);17  Fs->hash_table=old_hash;18 19  k=*desc(U32 *);20  if (k=='Edit')        c=BLUE;21  else if (k=='Dol ')   c=GREEN;22  else if (k=='Cmd ')   c=RED;23  else                  c=BLACK;24 25  res=MStrPrint("%-*s $FG,%d$$TX+UL+L+PU,\"%$Q\",A=\"%s\"$$FG$\n",26        i,st,c,desc,st2);27  Free(st);28  Free(st2);29 30  ptr=res;31  while (*ptr) {32    if (*ptr==CH_SPACE)33      *ptr=CH_SHIFT_SPACE;34    ptr++;35  }36 37  return res;38}39 40U0 KeyMapKeyPrint(I64 sc,U0 (*fp_hndlr)(I64 sc),U8 *desc,CTask *task=NULL)41{42  U8 *st=KeyMapKeyMStrPrint(sc,fp_hndlr,desc,task);43  "%s",st;44  Free(st);45}46 47U0 KeyMapCtrlAltFamily(Bool no_shift,Bool shift)48{49  I64 i,no_shift_f;50  if (no_shift && shift)51    no_shift_f=SCF_NO_SHIFT;52  else53    no_shift_f=0;54  if (no_shift) KeyMapKeyPrint(SC_DELETE+SCF_CTRL+SCF_ALT+no_shift_f,55          &Reboot,"Cmd /Reboot");56  if (no_shift) KeyMapKeyPrint(SC_ESC+SCF_CTRL+SCF_ALT+no_shift_f,57          &User,"Cmd /Terminal Window");58  if (no_shift) KeyMapKeyPrint(SC_TAB+SCF_CTRL+SCF_ALT+no_shift_f,59          &WinToTop,"Cmd /Next Focus Task");60 61  for (i=0;i<26;i++)62    if (keydev.fp_ctrl_alt_cbs[i]) {63      if (no_shift && keydev.ctrl_alt_no_shift_descs[i])64        KeyMapKeyPrint(Char2ScanCode(i+'a')+SCF_CTRL+SCF_ALT+no_shift_f,65              keydev.fp_ctrl_alt_cbs[i],keydev.ctrl_alt_no_shift_descs[i]);66      if (shift && keydev.ctrl_alt_shift_descs[i])67        KeyMapKeyPrint(Char2ScanCode(i+'a')+SCF_CTRL+SCF_ALT+SCF_SHIFT,68              keydev.fp_ctrl_alt_cbs[i],keydev.ctrl_alt_shift_descs[i]);69    }70}71 72U0 KMComparePrepare(U8 *buf,I64 *src)73{74  I64 i,*dst=buf;75  U8 *ptr;76  if (src) {77    *dst++=*src++;78    *dst++=*src++;79    *dst++=*src++;80    *dst++=*src++;81    *dst(U8 *)=0;82    if (ptr=StrMatch("SHIFT",buf)) {83      for (i=0;i<5;i++)84        ptr[i]=CH_SHIFT_SPACE;85      if (ptr=StrMatch("$",buf))86        *ptr=255;87    }88  } else89    *buf=0;90}91 92I64 KMCompare(U8 *e1,U8 *e2)93{94  U8 buf1[STR_LEN],buf2[STR_LEN];95  KMComparePrepare(buf1,e1);96  KMComparePrepare(buf2,e2);97  return StrCmp(buf1,buf2);98}99 100U0 KeyMapFamily2(U8 **entries,CTask *task,I64 scf)101{102  I64 i,arg1,arg2;103  for (i=0;i<256;i++) {104    arg2=scf|i|SCF_KEY_DESC;105    arg1=ScanCode2Char(arg2);106    *keydev.desc=0;107    keydev.hndlr=NULL;108    if (TaskValidate(task) && !Bt(&task->win_inhibit,WIf_SELF_KEY_DESC)) {109      if (task==Fs)110        PutKey(arg1,arg2);111      else112        PostMsg(task,MSG_KEY_DOWN,arg1,arg2);113      Refresh(0,TRUE);114      Sleep(1); //Open loop because might be no response.  TODO: Drops msgs.115    }116    if (*keydev.desc && StrNCmp(keydev.desc,"Char  /",7))117      entries[i]=KeyMapKeyMStrPrint(arg2,keydev.hndlr,keydev.desc,task);118  }119}120 121U0 KeyMapFamily(CTask *task,I64 scf,Bool no_shift,Bool shift)122{123  I64 i,cnt=0;124  U8 **entries=CAlloc(2*256*sizeof(U8 *)),**ptr=entries;125  if (no_shift) {126    if (shift)127      KeyMapFamily2(ptr,task,scf+SCF_NO_SHIFT);128    else129      KeyMapFamily2(ptr,task,scf);130    ptr+=256;131    cnt+=256;132  }133  if (shift) {134    KeyMapFamily2(ptr,task,scf+SCF_SHIFT);135    ptr+=256;136    cnt+=256;137  }138  QSortI64(entries,cnt,&KMCompare);139  for (i=0;i<cnt;i++)140    if (entries[i]) {141      "%s",entries[i];142      Free(entries[i]);143    }144  Free(entries);145}146 147public U0 KeyMap(CTask *task=NULL)148{//Report desc of all keys.149  Bool old_key_desc;150  if (!task) task=Fs;151  old_key_desc=LBtr(&task->win_inhibit,WIf_SELF_KEY_DESC);152  DocMax;153  KeyMapFamily(task,0,TRUE,TRUE);154  KeyMapFamily(task,SCF_CTRL,TRUE,TRUE);155  KeyMapFamily(task,SCF_ALT,TRUE,TRUE);156  KeyMapCtrlAltFamily(TRUE,TRUE);157  LBEqu(&task->win_inhibit,WIf_SELF_KEY_DESC,old_key_desc);158  "\nKeyMap Completed.\n";159}160 161#help_index "Help System/Training"162public U0 TipOfDay(U8 *tip_file="::/Doc/Tips.DD")163{//Print random tip-of-day from ::/Doc/Tips.DD.164  I64 i=RandU16;165  CDoc *doc=DocRead(tip_file),*doc2=DocNew;166  CDocEntry *doc_e=doc->head.next;167  "$WW,1$\n";168  while (TRUE) {169    if (doc_e->type_u8==DOCT_TEXT && *doc_e->tag=='*')170      if (!i--) break;171    doc_e=doc_e->next;172  }173  if (doc_e->type_u8==DOCT_TEXT && *doc_e->tag=='*') {174    while (doc_e!=doc) {175      if (doc_e->type_u8!=DOCT_ERROR)176        DocInsEntry(doc2,DocEntryCopy(doc2,doc_e));177      doc_e=doc_e->next;178      if (doc_e->type_u8==DOCT_TEXT && *doc_e->tag=='*')179        break;180    }181  }182  DocInsDoc(DocPut,doc2);183  DocDel(doc2);184  DocDel(doc);185}186