Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
DocMacro.txt213 linesDownload Raw Back to DolDoc
1 2#help_index "DolDoc/Misc"3 4U8 captured_macro_name[STR_LEN];5StrCpy(captured_macro_name,"Test");6 7I64 sys_macro_repeat_n=1;8 9U0 SysMacroStripKey(CJob *macro_head,I64 arg1,I64 arg2)10{11  CJob *tmpc,*tmpc1;12  tmpc=macro_head->next;13  while (tmpc!=macro_head) {14    tmpc1=tmpc->next;15    if (tmpc->job_code==JOBT_MSG &&16          (tmpc->msg_code==MSG_KEY_DOWN || tmpc->msg_code==MSG_KEY_UP ||17          tmpc->msg_code==MSG_KEY_DOWN_UP) &&18          arg1 && tmpc->aux1==arg1 || !arg1 && tmpc->aux2==arg2) {19      QueRem(tmpc);20      JobDel(tmpc);21    }22    tmpc=tmpc1;23  }24}25 26#define MT_NULL 027#define MT_MSG  128#define MT_CHAR 229 30class CMacroTmp31{32  CMacroTmp *next,*last;33  I64 type;34  U8 buf[STR_LEN];35};36 37CMacroTmp *Cmd2MT(CJob *tmpc)38{39  U8 buf[8];40  CMacroTmp *tmpmt=CAlloc(sizeof(CMacroTmp));41  if (Bt(char_bmp_macro,tmpc->aux1) && tmpc->msg_code==MSG_KEY_DOWN) {42    tmpmt->type=MT_CHAR;43    buf[0]=tmpc->aux1;44    buf[1]=0;45    StrPrint(tmpmt->buf,"%Q",buf);46  } else {47    tmpmt->type=MT_MSG;48    StrPrint(tmpmt->buf,"Msg(0x%X,0x%X,0x%X);",49          tmpc->msg_code,tmpc->aux1,tmpc->aux2);50  }51  return tmpmt;52}53 54U8 *SysMacro2Str(CJob *macro_head)55{56  CJob *tmpc;57  I64 cnt=1; //terminating zero58  U8 *ptr,*m;59  CMacroTmp *tmpmt,*tmpmt1,head;60  LBtr(&sys_semas[SEMA_RECORD_MACRO],0);61 62  QueInit(&head);63  head.type=MT_NULL;64  tmpc=macro_head->next;65  while (tmpc!=macro_head) {66    tmpmt=Cmd2MT(tmpc);67    QueIns(tmpmt,head.last);68    cnt+=StrLen(tmpmt->buf);69    if (tmpmt->type==MT_CHAR) {70      if (tmpmt->last->type!=MT_CHAR)71        cnt+=StrLen("\"");72      if (tmpmt->next->type!=MT_CHAR)73        cnt+=StrLen("\";");74    }75    tmpc=tmpc->next;76  }77 78  m=MAlloc(cnt);79  ptr=m;80 81  tmpmt=head.next;82  while (tmpmt!=&head) {83    tmpmt1=tmpmt->next;84    if (tmpmt->type==MT_MSG) {85      StrCpy(ptr, tmpmt->buf);86      ptr+=StrLen(tmpmt->buf);87    } else {88      if (tmpmt->last->type!=MT_CHAR) {89        StrCpy(ptr, "\"");90        ptr+=StrLen("\"");91      }92      StrCpy(ptr,tmpmt->buf);93      ptr+=StrLen(tmpmt->buf);94      if (tmpmt->next->type!=MT_CHAR) {95        StrCpy(ptr, "\";");96        ptr+=StrLen("\";");97      }98    }99    Free(tmpmt);100    tmpmt=tmpmt1;101  }102  *ptr=0;103  return m;104}105 106U0 PlaySysMacro(I64 n=1)107{108  CTask *task=sys_focus_task;109  U8 *m;110  if (TaskValidate(task)) {111    LBtr(&sys_semas[SEMA_RECORD_MACRO],0);112    m=SysMacro2Str(&sys_macro_head);113    while (n-- && TaskValidate(task)) {114      if (task==Fs)115        InStr("%s",m);116      else117        XTalkStrWait(task,"%s",m);118    }119    Free(m);120  }121}122 123U0 EdInsCapturedMacro()124{125  U8 *st=SysMacro2Str(&sys_macro_head);126  if (sys_focus_task) {127    XTalk(sys_focus_task,"$MA+LIS,T=\"%s\",LM=\"%$Q\"$",128          captured_macro_name,st);129    Free(st);130  }131}132 133#define SM_RECORD       0134#define SM_INS          1135#define SM_PLAY         2136#define SM_REPEAT_N     3137#define SM_STOP         4138 139I64 PopUpMacroMenu()140{141  I64 res=0;142  U8 buf[STR_LEN];143  CJob *tmpc;144  CDoc *doc=DocNew;145  CDocEntry *doc_e=DocPrint(doc,"$DA-P,LEN=STR_LEN-1,A=\"Name:%%s\"$");146  doc_e->data=captured_macro_name;147  DocDataFmt(doc,doc_e);148 149  doc_e=DocPrint(doc,"\n$DA,A=\"Repeat N:%%d\"$");150  doc_e->data=&sys_macro_repeat_n;151  DocDataFmt(doc,doc_e);152 153  DocPrint(doc,"\n"154        "$CM+LX,1,3$$BT,\"RECORD\",LE=SM_RECORD$"155        "$CM+LX,17,0$$BT,\"INSERT\",LE=SM_INS$"156        "$CM+LX,1,3$$BT,\"PLAY\",LE=SM_PLAY$"157        "$CM+LX,17,0$$BT,\"REPEAT N\",LE=SM_REPEAT_N$"158        "$CM+LX,1,3$$BT,\"STOP\",LE=SM_STOP$"159        "$CM+LX,17,0$$BT,\"CANCEL\",LE=DOCM_CANCEL$"160        "\n\n\n$GREEN$SHIFT-F2$FG$ will play macro.\n");161  doc->flags|=DOCF_SIZE_MIN | DOCF_FORM;162  StrPrint(buf,"DocMenu(%d);",doc);163  sys_macro_task=Spawn(&SrvCmdLine,NULL,"Macro Popup",,Fs);164  Fs->popup_task=sys_macro_task;165  LBts(&sys_macro_task->display_flags,DISPLAYf_WIN_ON_TOP);166  tmpc=TaskExe(sys_macro_task,Fs,buf,167        1<<JOBf_WAKE_MASTER|1<<JOBf_FOCUS_MASTER);168  JobResScan(tmpc,&res);169  Fs->popup_task=NULL;170  Kill(sys_macro_task);171  sys_macro_task=NULL;172  DocDataScan(doc,doc_e);173  DocDel(doc);174  return res;175}176 177U0 MacroTask(I64)178{179  I64 i;180  StrCpy(captured_macro_name,"Click Here");181  sys_macro_repeat_n=1;182  do {183    i=PopUpMacroMenu;184    WinRefocus(sys_focus_task);185    switch (i) {186      case SM_RECORD:187        LBtr(&sys_semas[SEMA_RECORD_MACRO],0);188        QueDel(&sys_macro_head,TRUE);189        LBts(&sys_semas[SEMA_RECORD_MACRO],0);190        break;191      case SM_PLAY:192        PlaySysMacro;193        break;194      case SM_REPEAT_N:195        PlaySysMacro(sys_macro_repeat_n);196        break;197      case SM_STOP:198        LBtr(&sys_semas[SEMA_RECORD_MACRO],0);199        break;200      case SM_INS:201        LBtr(&sys_semas[SEMA_RECORD_MACRO],0);202        EdInsCapturedMacro;203        break;204    }205  } while (i>=0);206}207 208U0 EdMacroUtil()209{210  if (!sys_macro_task)211    Spawn(&MacroTask,NULL,"Macro");212}213