TempleOSTS_130315.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:45:37 +02:00
1 parent e57428affb
commit 17b71f1a2d
958 files changed
+26043 -15907

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
#help_index "Doc"
#help_file "::/TempleOS/Doc/Doc"
//See $LK-A,"::/TempleOS/Doc/Doc.TXT"$
extern I64 EdLeftClickLink(CDoc *doc,CDocEntry *doc_e);
extern I64 TermRightClickLink(CDoc *doc,CDocEntry *doc_e);
extern U0 DocPutSPartial(CDoc *doc,U8 *st);
extern U0 DocFormBackward(CDoc *doc,Bool giveup=FALSE);
extern U0 EdUndoFilter(CDoc *doc);
U0 DocInit()
{
DefineLstLoad("ST_DOC_CMDS","TX\0CR\0SR\0CU\0TB\0CL\0PB\0DA\0PL\0LM\0RM\0HD\0FO\0ID\0"
"FG\0BG\0FD\0BD\0F2\0FL\0FM\0FA\0FH\0FE\0FU\0FB\0FY\0FR\0FC\0FQ\0"
"WW\0UL\0IV\0BK\0SX\0SY\0CM\0AN\0LK\0BT\0"
"CB\0MA\0MU\0HX\0HS\0HE\0TR\0SP\0IB\0IT\0IS\0BP\0SO\0HL\0LP\0CC\0HI\0HV\0HC\0ER\0");
DefineLstLoad("ST_DOC_FLAGS",
//flags1
"A\0L\0"
"LC\0LE\0LM\0LA\0RC\0RE\0RM\0RA\0"
"TC\0BI\0X\0Q\0LX\0CX\0RX\0TY\0CY\0BY\0SX\0SY\0SCX\0SCY\0"
"HL\0LP\0CC\0WW\0BK\0IV\0SEL\0UL\0"
"B\0S\0BD\0C\0CA\0RD\0P\0T\0"
"Z\0H\0TR\0SK\0AL\0PU\0PRY\0MRX\0"
"FST\0SIF\0WD\0HT\0HS\0FS\0NC\0DD\0UD\0U8\0U16\0U32\0U64\0D\0WR\0HTML\0"
//flags2
"BP\0"
);
DefineLstLoad("ST_LINK_TYPES","FI\0FA\0FF\0FL\0MN\0PI\0PF\0PL\0BF\0DF\0HI\0AD\0");
}
DocInit;
//--TEMPLEOS LINK TYPES--
// "filename"
// "FI:filename"
// "FA:filename,anchor"
// "FF:filename,pattern"
// "FF:filename,pattern:occurnum"
// "FL:filename,linenum"
#define LK_FILE 0
#define LK_FILE_ANCHOR 1
#define LK_FILE_FIND 2
#define LK_FILE_LINE 3
// "MN:SymName"
#define LK_MAN_PAGE 4
// "PI:filename"
// "PF:filename,pattern"
// "PF:filename,pattern:occurnum"
// "PL:filename,linenum"
#define LK_PLAIN 5
#define LK_PLAIN_FIND 6
#define LK_PLAIN_LINE 7
// "BF:book,pattern"
#define LK_BIBLE_FIND 8
// "DF:word"
// "DF:word,defnum"
#define LK_DEF 9
// "HI:index"
#define LK_HELP_INDEX 10
// "AD:address_number"
#define LK_ADDR 11
#define LK_PLACE_ANCHOR 12
#include "DocNew"
#include "DocHighlight"
#include "DocRecalc"
#include "DocPlain"
#include "DocFile"
#include "DocOpt"
#include "DocPopUp"
#include "DocCtrlL"
#include "DocMacro"
#include "DocIDE"
#include "DocEd"
#include "DocCodeTools"
#include "DocBible"
#include "DocTree"
#include "DocMain"
#help_index ""
$WW,1$/*$AN,"","Doc"$
TempleOS Doc's can have "cursor movement" cmds which can move the cursor up the screen and layer on existing text. It can also have call-back funs which supply live, changing text. For these reasons, you can't assume you know where the visible portion of the document is and must process an extensive portion of the document each time it is placed on the screen, becoming CPU intensive on big documents. The doc->recalc_start member attempts to limit what is recalculated. This is tricky, howeve, and optimizations create minor glitches. Similarly, an optimization to only refresh the entire document 1 in 10 times it is drawn to the screen creates minor glitches. Since the Doc handles the cmd line, it must also be fast when adding text output from programs. doc->recalc_start comes into play here.
*/
+192
View File
@@ -0,0 +1,192 @@
#help_index "Doc/Bible"
DefineLoad("ST_BIBLE_FILE","::/TempleOS/Misc/Bible.TXT.Z");
DefineLstLoad("ST_BIBLE_BOOKS",
"Genesis\0"
"Exodus\0"
"Leviticus\0"
"Numbers\0"
"Deuteronomy\0"
"Joshua\0"
"Judges\0"
"Ruth\0"
"1 Samuel\0"
"2 Samuel\0"
"1 Kings\0"
"2 Kings\0"
"1 Chronicles\0"
"2 Chronicles\0"
"Ezra\0"
"Nehemiah\0"
"Tobit\0"
"Judith\0"
"Esther\0"
"1 Maccabees\0"
"2 Maccabees\0"
"Job\0"
"Psalms\0"
"Proverbs\0"
"Ecclesiastes\0"
"Song of Songs\0"
"Wisdom\0"
"Sirach\0"
"Isaiah\0"
"Jeremiah\0"
"Lamentations\0"
"Baruch\0"
"Ezekiel\0"
"Daniel\0"
"Hosea\0"
"Joel\0"
"Amos\0"
"Obadiah\0"
"Jonah\0"
"Micah\0"
"Nahum\0"
"Habakkuk\0"
"Zephaniah\0"
"Haggai\0"
"Zechariah\0"
"Malachi\0"
"Matthew\0"
"Mark\0"
"Luke\0"
"John\0"
"Acts\0"
"Romans\0"
"1 Corinthians\0"
"2 Corinthians\0"
"Galatians\0"
"Ephesians\0"
"Philippians\0"
"Colossians\0"
"1 Thessalonians\0"
"2 Thessalonians\0"
"1 Timothy\0"
"2 Timothy\0"
"Titus\0"
"Philemon\0"
"Hebrews\0"
"James\0"
"1 Peter\0"
"2 Peter\0"
"1 John\0"
"2 John\0"
"3 John\0"
"Jude\0"
"Revelation\0"
"\0");
DefineLstLoad("ST_BIBLE_BOOK_LINES",
"297\0"
"5068\0"
"9123\0"
"12005\0"
"15977\0"
"19168\0"
"21329\0"
"23598\0"
"23902\0"
"26892\0"
"29345\0"
"32241\0"
"34961\0"
"37633\0"
"40756\0"
"41671\0"
"Tobit\0"
"Judith\0"
"42963\0"
"1 Maccabees\0"
"2 Maccabees\0"
"43605\0"
"46190\0"
"53793\0"
"56267\0"
"56966\0"
"Wisdom\0"
"Sirach\0"
"57332\0"
"61806\0"
"66736\0"
"Baruch\0"
"67217\0"
"71804\0"
"73189\0"
"73876\0"
"74130\0"
"74615\0"
"74697\0"
"74860\0"
"75241\0"
"75416\0"
"75604\0"
"75806\0"
"75932\0"
"76684\0"
"76908\0"
"79970\0"
"81941\0"
"85266\0"
"87803\0"
"90914\0"
"92110\0"
"93323\0"
"94088\0"
"94514\0"
"94869\0"
"95153\0"
"95402\0"
"95647\0"
"95772\0"
"96090\0"
"96320\0"
"96440\0"
"96500\0"
"97370\0"
"97687\0"
"97976\0"
"98163\0"
"98506\0"
"98552\0"
"98597\0"
"98684\0"
"\0");
public U0 PutBibleVerse(U8 *verse,I64 lines)
{
I64 i;
CDoc *doc;
CDocEntry *doc_e;
U8 *st=StrNew(verse),
*st2=StrNew(verse);
if (StrOcc(st,','))
StrLastRem(st,",",st2);
else
*st2=0;
i=DefineMatch(st,"ST_BIBLE_BOOKS",LEF_IGNORE_CASE);
if (i>=0) {
i=A2I(DefineSub(i,"ST_BIBLE_BOOK_LINES"));
doc=DocRead(Define("ST_BIBLE_FILE"),DOCF_PLAIN_TEXT);
DocLineNumGoTo(doc,i); //one based
if (*st2) {
StrCpy(doc->find_replace->find_text,st2);
EdFindNext(doc);
}
doc_e=doc->cur_entry;
while (lines) {
if (doc_e->type_u8==DOCT_TEXT)
"" doc_e->tag;
else if (doc_e->type_u8==DOCT_NEW_LINE) {
NewLine;
lines--;
}
doc_e=doc_e->next;
}
DocDel(doc);
}
Free(st);
Free(st2);
}
+428
View File
@@ -0,0 +1,428 @@
#define EF_DONT_RECOMPILE 0
#define EF_RECOMPILE 1
#define EF_RENUM_ASM 2
#define EF_SLIDER_CTRL 3
#define EF_CH_SC 4
I64 PopUpEdFmt()
{
I64 i;
CDoc *doc=DocNew;
DocPutS(doc,"$$FG,PURPLE$$Reformat Function$$FG$$\n"
"If you enter $$FG,GREEN$$DONT RECOMPILE$$FG$$ the stored\n"
"source line indentation information will\n"
"be used. $$BK,1$$Be sure it is up-to-date!$$BK,0$$\n"
"For $$FG,GREEN$$#exe$$FG$$ config'ed projects, enter $$FG,GREEN$$DONT RECOMPILE$$FG$$.\n"
"$$MU,\"Recompile and autoindent CPP.Z Fun\",EF_RECOMPILE$$\n"
"$$MU,\"Don't Recompile but autoindent CPP.Z Fun\",EF_DONT_RECOMPILE$$\n\n"
"$$MU,\"Renum Asm Local @@ Labels for Fun\",EF_RENUM_ASM$$\n\n"
"$$FG,PURPLE$$Insert Managed Code$$FG$$\n"
"$$MU,\"Slider Ctrl\",EF_SLIDER_CTRL$$\n\n"
"$$FG,PURPLE$$Misc$$FG$$\n"
"$$MU,\"Insert ASCII/Scan Code Hex Codes for key pressed\",EF_CH_SC$$\n\n"
"$$MU,\"CANCEL\",DOCM_CANCEL$$\n"
"$$FG,GREEN$$<ALT-BACKSPACE>$$FG$$ to undo if not happy\n"
"with the results.\n");
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
#define C_INDENT_SPACES 2
#define ASM_RENUM_SPACING 5
U0 EdRemFunLeadingSpace(CDoc *doc)
{
Bool unlock=DocLock(doc),
start_of_line=TRUE;
U8 ch,*ptr;
I64 levels=1;
CDocEntry *doc_e,*doc_e2;
EdGoToFun(doc,FALSE,FALSE);
doc_e=doc->cur_entry->next;
do {
doc_e2=doc_e->next;
if (doc_e!=doc && doc_e!=doc->cur_entry &&
!(doc_e->flags1&(DOCEG1_DONT_EDIT-DOCEF1_SCROLLING_X)) &&
!(doc_e->flags2&DOCEG2_DONT_EDIT))
switch (doc_e->type_u8) {
case DOCT_TEXT:
ptr=doc_e->tag;
if (start_of_line) {
while (*ptr==CH_SPACE)
ptr++;
if (*ptr)
start_of_line=FALSE;
ptr=StrNew(ptr,doc->mem_task);
Free(doc_e->tag);
doc_e->tag=ptr;
}
if (!*ptr)
DocEntryDel(doc,doc_e);
else {
while (ch=*ptr++)
if (ch=='{')
levels++;
else if (ch=='}') {
if (!--levels)
break;
}
if (!levels) goto ls_done;
}
break;
case DOCT_TAB:
if (start_of_line)
DocEntryDel(doc,doc_e);
break;
case DOCT_NEW_LINE:
start_of_line=TRUE;
break;
default:
start_of_line=FALSE;
}
doc_e=doc_e2;
} while (doc_e!=doc->cur_entry);
ls_done:
DocRecalc(doc);
DocCenter(doc);
if (unlock)
DocUnlock(doc);
}
class CRenum
{
CRenum *next,*last;
U8 label[sizeof(CEdFindText.find_text)];
};
I64 EdRAGetU8(CDoc *doc)
{
I64 result=-1;
while (doc->cur_entry!=doc && doc->cur_entry->type&DOCET_SELECTED && result<0) {
result=EdCurU8(doc);
EdCursorRight(doc);
}
return result;
}
U0 EdRACollect(CDoc *doc,CRenum *root)
{
I64 ch,i;
CRenum *tempr;
U8 buf[sizeof(CEdFindText.find_text)];
ch=EdRAGetU8(doc);
while (ch>=0) {
if (ch!='@')
ch=EdRAGetU8(doc);
else {
ch=EdRAGetU8(doc);
if (ch=='@') {
ch=EdRAGetU8(doc);
StrCpy(buf,"@@");
i=2;
while (ch>=0 && i<sizeof(CEdFindText.find_text)) {
if (Bt(alpha_numeric_bitmap,ch))
buf[i++]=ch;
else
break;
ch=EdRAGetU8(doc);
}
if (i<sizeof(CEdFindText.find_text)) {
buf[i++]=0;
while (ch>=0 && Bt(white_space_bitmap,ch))
ch=EdRAGetU8(doc);
if (ch==':') {
ch=EdRAGetU8(doc);
tempr=MAlloc(sizeof(CRenum));
StrCpy(tempr->label,buf);
QueIns(tempr,root->last);
}
}
}
}
}
//This is needed because we moved the
//cursor and it didn't recalc.
DocRecalc(doc);
}
U0 EdRenumAsm(CDoc *doc)
{
Bool unlock=DocLock(doc);
I64 num=0;
CRenum root,*tempr,*tempr1;
U8 buf[sizeof(CEdFindText.find_text)],
buf2[sizeof(CEdFindText.find_text)];
QueInit(&root);
EdSelectFun(doc,TRUE);
EdRACollect(doc,&root);
tempr=root.next;
while (tempr!=&root) {
tempr1=tempr->next;
num+=ASM_RENUM_SPACING;
SPrintF(buf,"@#%02d",num);
EdReplace(doc,tempr->label,buf,TRUE,TRUE,TRUE);
Free(tempr);
tempr=tempr1;
}
while (num) {
SPrintF(buf, "@#%02d",num);
SPrintF(buf2,"@@%02d",num);
EdReplace(doc,buf,buf2,TRUE,TRUE,TRUE);
num-=ASM_RENUM_SPACING;
}
EdSelectAll(doc,FALSE);
DocRecalc(doc);
DocCenter(doc);
if (unlock)
DocUnlock(doc);
}
#define AC_ABORT -1
#define AC_REINDENT 0
#define AC_RENUM_ASM 1
U0 EdRefmtFun(CDoc *doc,I64 fmt_type)
{
Bool unlock=DocLock(doc),start_of_line=TRUE;
CDocEntry *doc_e,*doc_ne;
I64 i,x,r,action=AC_ABORT,old_line_num;
U8 *b,*st,*st2,*prj_file;
CHashSrcSym *temph;
CIndentInfo *indent;
CTask *task=NULL;
CTaskCmd *tempc;
DocRecalc(doc);
old_line_num=doc->cur_entry->y+1;
DocCaptureUndo(doc,TRUE);
switch (fmt_type) {
case EF_RECOMPILE:
if (EdGoToFun(doc,FALSE,FALSE)) {
if (doc->flags&DOCF_PLAIN_TEXT)
DocFlagsToggle(doc,DOCF_PLAIN_TEXT);
DocWrite(doc);
task=Spawn(&ServantUserCmdLine,NULL,"Servant",Fs);
st2=CurDir;
st=MSPrintF("Cd(\"%s\");",st2);
tempc=TaskRqstQue(task,Fs,st,1<<TASKCf_WAKE_MASTER|1<<TASKCf_FOCUS_MASTER);
Free(st2);
Free(st);
SetWinHorz(Fs->win_left,Fs->win_right, task);
SetWinVert(Fs->win_top, Fs->win_bottom,task);
if (GetRqstResult(tempc,&r)) {
st=DirFile(doc->filename.name,,"PRJ.Z"),
prj_file=FileNameAbs(st,FUF_Z_OR_NOT_Z);
Free(st);
if (FileFind(prj_file)) {
st2=DirFile(prj_file),
st=MSPrintF("Cd(\"%s\");",st2);
Free(st2);
tempc=TaskRqstQue(task,Fs,st,1<<TASKCf_WAKE_MASTER|1<<TASKCf_FOCUS_MASTER);
Free(st);
st=MSPrintF("\"$$WW,1$$\";Cmp(\"%s\",\"SysTemp\",\"SysTemp\");",prj_file);
tempc=TaskRqstQue(task,Fs,st,1<<TASKCf_WAKE_MASTER|1<<TASKCf_FOCUS_MASTER);
Free(st);
if (GetRqstResult(tempc,&r))
if (!r) {
tempc=TaskRqstQue(task,Fs,
"Load(\"SysTemp\",LDF_JUST_LOAD);"
"MapFileLoad(\"SysTemp\");",1<<TASKCf_WAKE_MASTER|1<<TASKCf_FOCUS_MASTER);
if (GetRqstResult(tempc,&r))
action=AC_REINDENT;
}
tempc=TaskRqstQue(task,Fs,"Del(\"SysTemp.*\");",1<<TASKCf_WAKE_MASTER|1<<TASKCf_FOCUS_MASTER);
GetRqstResult(tempc,&r);
} else {
Free(prj_file);
st=DirFile(doc->filename.name,"Load","CPP.Z");
prj_file=FileNameAbs(st,FUF_Z_OR_NOT_Z);
Free(st);
if (FileFind(prj_file))
st=MSPrintF("\"$$WW,1$$\";ExeFile(\"%s\",TRUE);",prj_file);
else
st=MSPrintF("\"$$WW,1$$\";ExeFile(\"%s\",TRUE);",doc->filename.name);
tempc=TaskRqstQue(task,Fs,st,1<<TASKCf_WAKE_MASTER|1<<TASKCf_FOCUS_MASTER);
Free(st);
if (GetRqstResult(tempc,&r) && r)
action=AC_REINDENT;
}
Free(prj_file);
}
if (action==AC_REINDENT) {
DocUnlock(doc);
st=MSPrintF("DbgFunFind(0x%X,0);",doc);
tempc=TaskRqstQue(task,Fs,st,1<<TASKCf_WAKE_MASTER|1<<TASKCf_FOCUS_MASTER);
Free(st);
if (GetRqstResult(tempc,&r))
temph=r;
else
action=AC_ABORT;
DocLock(doc);
} else
PopUpOk("Has Errors");
}
break;
case EF_DONT_RECOMPILE:
if (EdGoToFun(doc,FALSE,FALSE)) {
if (temph=DbgFunFind(doc,0))
action=AC_REINDENT;
}
break;
case EF_RENUM_ASM:
if (EdGoToFun(doc,FALSE,TRUE)) {
if (EdCurU8(doc)=='{') {
EdCursorRight(doc);
DocRecalc(doc);
} else if (EdCurU8(doc)==':') {
EdCursorRight(doc);
if (EdCurU8(doc)==':')
EdCursorRight(doc);
DocRecalc(doc);
}
action=AC_RENUM_ASM;
}
break;
}
switch (action) {
case AC_RENUM_ASM:
DocUnlock(doc);
Snd(2000); Sleep(150); Snd(0);
Sleep(100);
Snd(2000); Sleep(150); Snd(0);
DocLock(doc);
EdRenumAsm(doc);
break;
case AC_REINDENT:
if (temph->type&(HTT_FUN|HTT_EXPORT_SYS_SYM))
indent=temph->indent;
else
indent=NULL;
if (indent && indent->min_line<=indent->max_line) {
DocUnlock(doc);
Snd(2000); Sleep(150); Snd(0);
Sleep(100);
Snd(2000); Sleep(150); Snd(0);
DocLock(doc);
EdRemFunLeadingSpace(doc);
DocLineNumGoTo(doc,indent->min_line);
doc_e=doc->cur_entry;
while (indent->min_line<=doc_e->y+1<=indent->max_line) {
if (doc_e!=doc && doc_e!=doc->cur_entry &&
!(doc_e->flags1&(DOCEG1_DONT_EDIT-DOCEF1_SCROLLING_X)) &&
!(doc_e->flags2&DOCEG2_DONT_EDIT)) {
if (doc_e->type_u8==DOCT_NEW_LINE||doc_e->type_u8==DOCT_SOFT_NEW_LINE)
start_of_line=TRUE;
else {
if (start_of_line) {
i=indent->body[doc_e->y+1-indent->min_line]*C_INDENT_SPACES;
x=doc_e->x+1;
while (i>8) {
doc_ne=CAlloc(sizeof(CDocEntryBase),doc->mem_task);
doc_ne->type=DOCT_TAB | doc->settings_root.dft_text_attr << 8;
doc_ne->x=x;
doc_ne->y=doc_e->y;
doc_ne->page_line_num=doc_e->page_line_num;
QueIns(doc_ne,doc_e->last);
i-=8;
x+=8;
}
if (i>0) {
b=MAlloc(i+1,doc->mem_task);
MemSet(b,CH_SPACE,i);
b[i]=0;
doc_ne=CAlloc(sizeof(CDocEntryBase)+sizeof(U8 *),doc->mem_task);
doc_ne->type=DOCT_TEXT | doc->settings_root.dft_text_attr << 8;
doc_ne->tag=b;
doc_ne->max_col=1;
doc_ne->x=x;
doc_ne->y=doc_e->y;
doc_ne->page_line_num=doc_e->page_line_num;
QueIns(doc_ne,doc_e->last);
}
}
start_of_line=FALSE;
}
}
doc_e=doc_e->next;
}
break;
}
}
DocRecalc(doc);
DocLineNumGoTo(doc,old_line_num);
DocUnlock(doc);
if (!unlock)
DocLock(doc);
if (task)
Kill(task,FALSE);
}
U0 EdPopUpChSC(I64 *_ch,I64 *_sc)
{
I64 sc;
"Press A Key\n";
DocCur->flags|=DOCF_MIN_SIZE;
do GetMsg(_ch,&sc,1<<MSG_KEY_DOWN);
while (sc.u8[0]==SC_SHIFT || sc.u8[0]==SC_CTRL || sc.u8[0]==SC_ALT);
*_sc=sc;
}
U0 EdChSC(CDoc *doc)
{
I64 ch,sc;
U8 buf[136];
SPrintF(buf,"EdPopUpChSC(%d,%d);",&ch,&sc);
PopUp(buf,Fs);
if (ch==CH_BACKSPACE)
DocPrintF(doc,"CH_BACKSPACE,0x%X",sc);
else if (ch=='\n')
DocPrintF(doc,"'\n',0x%X",sc);
else if (CH_CTRLA<=ch<=CH_CTRLZ)
DocPrintF(doc,"CH_CTRL%C,0x%X",ch+'@',sc);
else if (ch=='$$')
DocPrintF(doc,"'$$$$',0x%X",sc);
else if (ch=='\\')
DocPrintF(doc,"'\\\\',0x%X",sc);
else if (ch=='\'')
DocPrintF(doc,"'\\\'',0x%X",sc);
else if (ch==CH_ESC)
DocPrintF(doc,"CH_ESC,0x%X",sc);
else if (ch==CH_SHIFT_ESC)
DocPrintF(doc,"CH_SHIFT_ESC,0x%X",sc);
else if (ch==CH_SPACE)
DocPrintF(doc,"CH_SPACE,0x%X",sc);
else if (ch==CH_SHIFT_SPACE)
DocPrintF(doc,"CH_SHIFT_SPACE,0x%X",sc);
else if (Bt(displayable_chars_bitmap,ch))
DocPrintF(doc,"'%c',0x%X",ch,sc);
else
DocPrintF(doc,"0x%X,0x%X",ch,sc);
}
U0 EdCodeTools(CDoc *doc)
{
I64 fmt_type=PopUpEdFmt;
switch (fmt_type) {
case EF_DONT_RECOMPILE:
case EF_RECOMPILE:
case EF_RENUM_ASM:
EdRefmtFun(doc,fmt_type);
break;
case EF_SLIDER_CTRL:
MgdSliderCtrl(doc);
break;
case EF_CH_SC:
EdChSC(doc);
break;
}
}
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+455
View File
@@ -0,0 +1,455 @@
#help_index "Doc/File"
public U0 DocLoad(CDoc *doc,U8 *src2,I64 size)
{
I64 i;
U8 *src;
Bool unlock=DocLock(doc);
CDocBin *tempb;
doc->find_replace->filter_lines=0;
if (src2) {
DocPutS(doc,src2);
src=src2+StrLen(src2)+1;
i=size-(offset(CDocBin.data)-offset(CDocBin.start));
while (src<=src2+i) {
tempb=CAlloc(sizeof(CDocBin),doc->mem_task);
MemCpy(&tempb->start,src,offset(CDocBin.data)-offset(CDocBin.start));
src+=offset(CDocBin.data)-offset(CDocBin.start);
tempb->data=MAlloc(tempb->size,doc->mem_task);
if (tempb->size) {
MemCpy(tempb->data,src,tempb->size);
src+=tempb->size;
}
QueIns(tempb,doc->bin_root.last);
if (tempb->num>=doc->cur_bin_num)
doc->cur_bin_num=tempb->num+1;
}
}
if (!(doc->flags & (DOCF_PLAIN_TEXT|DOCF_PLAIN_TEXT_WITH_TABS)))
DocBinsValidate(doc);
DocHome(doc); //DOCT_CURSOR will set it in recalc
DocRecalc(doc);
if (unlock)
DocUnlock(doc);
}
public CDoc *DocRead(U8 *name,I64 flags=0)
{
CDoc *doc=DocNew;
U8 *src,*name2;
I64 size=0;
doc->flags|=flags;
name2=FileNameAbs(name);
StrCpy(doc->filename.name,name2);
src=FileRead(name2,&size,&doc->file_attr);
Free(name2);
if (src) {
DocLoad(doc,src,size);
Free(src);
}
return doc;
}
public U8 *DocSave(CDoc *doc,I64 *_size=NULL)
{
CDocEntry *doc_e;
CDocBin *b;
Bool unlock=DocLock(doc);
I64 i,cnt;
U8 *st,*result,*dst,*src,ch;
if (doc->flags&DOCF_NO_CURSOR)
cnt=1; //terminator
else
cnt=2; //cursor + terminator
if (!(doc->flags & (DOCF_PLAIN_TEXT|DOCF_PLAIN_TEXT_WITH_TABS)))
DocBinsValidate(doc);
DocRecalc(doc);
for (doc_e=doc->root.next;doc_e!=doc;doc_e=doc_e->next) {
if (!Bt(doc_data_types,doc_e->type_u8)) {
switch (doc_e->type_u8) {
case DOCT_TAB:
case DOCT_PAGE_BREAK:
cnt++;
break;
case DOCT_NEW_LINE:
if (doc->flags&DOCF_CARRIAGE_RETURN)
cnt+=2;
else
cnt++;
break;
case DOCT_TEXT://$BK,1$Update $LK,"DOCT_TEXT","FF:D:/TempleOS/Compiler/Lex.CPP,DOCT_TEXT"$$BK,0$
if (!(doc_e->flags1 & ~(DOCG_BL_IV_UL|DOCEF1_WORD_WRAP|DOCEF1_HIGHLIGHT|DOCEF1_LOCK_TO_PAGE|DOCEF1_LOCK_TO_CENTER|DOCEF1_SKIP|DOCEF1_HARD_SKIP|DOCEF1_FILTER_SKIP))) {
cnt+=StrLen(doc_e->tag);
if (!(doc->flags & (DOCF_PLAIN_TEXT | DOCF_PLAIN_TEXT_WITH_TABS)) ||
doc->flags&DOCF_DBL_DOLLARS)
cnt+=StrOcc(doc_e->tag,'$$');
} else {
st=Doc2PlainText(doc,doc_e);
cnt+=StrLen(st)+2;
Free(st);
}
break;
default:
if (doc_e->type_u8!=DOCT_SOFT_NEW_LINE &&
doc_e->type_u8!=DOCT_CURSOR &&
doc_e->type_u8!=DOCT_BPT) {
st=Doc2PlainText(doc,doc_e);
cnt+=StrLen(st)+2;
Free(st);
}
}
}
}
for (b=doc->bin_root.next;b!=&doc->bin_root;b=b->next) {
if (b->use_cnt>b->temp_use_cnt)
cnt+=offset(CDocBin.data)-
offset(CDocBin.start)+b->size;
}
result=MAlloc(cnt);
dst=result;
for (doc_e=doc->root.next;doc_e!=doc;doc_e=doc_e->next) {
if (!Bt(doc_data_types,doc_e->type_u8)) {
if (doc_e->type_u8==DOCT_TEXT &&
!(doc_e->flags1 & ~(DOCG_BL_IV_UL|DOCEF1_WORD_WRAP|DOCEF1_HIGHLIGHT|DOCEF1_LOCK_TO_PAGE|DOCEF1_LOCK_TO_CENTER|DOCEF1_SKIP|DOCEF1_HARD_SKIP|DOCEF1_FILTER_SKIP))) {
src=doc_e->tag;
i=0;
while (ch=*src++) {
if (doc_e==doc->cur_entry && i++==doc->cur_data_col && !(doc->flags&DOCF_NO_CURSOR))
*dst++=CH_CURSOR;
*dst++=ch;
if (ch=='$$') {
if (!(doc->flags & (DOCF_PLAIN_TEXT | DOCF_PLAIN_TEXT_WITH_TABS)) ||
doc->flags&DOCF_DBL_DOLLARS)
*dst++=ch;
}
}
if (doc_e==doc->cur_entry && i++==doc->cur_data_col && !(doc->flags&DOCF_NO_CURSOR))
*dst++=CH_CURSOR;
} else {
if (doc_e==doc->cur_entry && !(doc->flags&DOCF_NO_CURSOR))
*dst++=CH_CURSOR;
switch (doc_e->type_u8) {
case DOCT_TAB:
*dst++='\t';
break;
case DOCT_PAGE_BREAK:
*dst++=CH_FORM_FEED;
break;
case DOCT_NEW_LINE:
if (doc->flags&DOCF_CARRIAGE_RETURN)
*dst++=CH_CARRIAGE_RETURN;
*dst++='\n';
break;
default:
if (doc_e->type_u8!=DOCT_SOFT_NEW_LINE &&
doc_e->type_u8!=DOCT_CURSOR &&
doc_e->type_u8!=DOCT_BPT) {
*dst++='$$';
st=Doc2PlainText(doc,doc_e);
StrCpy(dst,st);
dst+=StrLen(st);
*dst++='$$';
Free(st);
}
break;
}
}
}
}
*dst++=0;
b=doc->bin_root.next;
if (b!=&doc->bin_root) {
do {
if (b->use_cnt>b->temp_use_cnt) {
MemCpy(dst,&b->type,offset(CDocBin.data)-offset(CDocBin.start));
dst+=offset(CDocBin.data)-offset(CDocBin.start);
MemCpy(dst,b->data,b->size);
dst+=b->size;
}
b=b->next;
} while (b!=&doc->bin_root);
} else
cnt--;
if (_size) *_size=cnt;
if (unlock)
DocUnlock(doc);
return result;
}
public U0 DocWrite(CDoc *doc,Bool prompt=FALSE)
{
I64 size;
U8 *buf=DocSave(doc,&size);
if (prompt) {
if (DocFormDo(&doc->filename,"CEdFileName"))
FileWrite(doc->filename.name,buf,size,0,doc->file_attr);
} else
FileWrite(doc->filename.name,buf,size,0,doc->file_attr);
Free(buf);
}
#help_index "Doc"
public U0 DocInsDoc(CDoc *doc,CDoc *doc2)
{ //TODO: $LK,"DocRst","MN:DocRst"$
U8 *dst;
Bool unlock_doc=DocLock(doc),
unlock_doc2=DocLock(doc2);
CDocEntry *doc_ne,*doc_e=doc2->root.next;
DocRemSoftNewLines(doc,NULL);
if (doc->cur_entry->type_u8==DOCT_TEXT &&
doc->cur_data_col>doc->cur_entry->min_col) {
if (doc->cur_data_col<doc->cur_entry->max_col) {
doc_ne=CAlloc(sizeof(CDocEntryBase)+sizeof(U8 *),doc->mem_task);
doc_ne->type=DOCT_TEXT | doc->cur_entry->type & 0xFFFFFF00;
doc_ne->flags1=doc->cur_entry->flags1;
doc_ne->flags2=doc->cur_entry->flags2;
doc_ne->x=doc->cur_entry->x;
doc_ne->y=doc->cur_entry->y;
doc_ne->page_line_num=doc->cur_entry->page_line_num;
dst=doc->cur_entry->tag+doc->cur_data_col;
doc_ne->tag=StrNew(dst,doc->mem_task);
doc_ne->max_col=StrLen(dst);
*dst=0;
doc->cur_entry->max_col=doc->cur_data_col;
QueIns(doc_ne,doc->cur_entry);
doc->cur_entry=doc_ne;
doc->cur_data_col=doc_ne->min_col;
} else
if (doc->cur_entry!=doc)
doc->cur_entry=doc->cur_entry->next;
}
while (doc_e!=doc2) {
if (doc_e->type_u8!=DOCT_SOFT_NEW_LINE) {
doc_ne=DocEntryCopy(doc,doc_e);
QueIns(doc_ne,doc->cur_entry->last);
}
doc_e=doc_e->next;
}
DocRecalc(doc);
if (unlock_doc2)
DocUnlock(doc2);
if (unlock_doc)
DocUnlock(doc);
}
#help_index "Doc/Clipboard"
public U0 ClipBoardDel()
{
DocRst(sys_clipboard_doc,TRUE);
}
public U0 EdCopyToClipboard(CDoc *doc)
{
CDoc *doc2=sys_clipboard_doc;
Bool unlock_doc=DocLock(doc),
unlock_doc2=DocLock(doc2);
CDocEntry *doc_e=doc->root.next,*doc_ne;
ClipBoardDel;
while (doc_e!=doc) {
if (doc_e->type & DOCET_SELECTED) {
doc_e->type&=~DOCET_SELECTED;
if (!Bt(doc_data_types,doc_e->type_u8)) {
doc_ne=DocEntryCopy(doc2,doc_e);
QueIns(doc_ne,doc2->root.last);
}
}
doc_e=doc_e->next;
}
if (unlock_doc2)
DocUnlock(doc2);
if (unlock_doc)
DocUnlock(doc);
}
public U0 EdCutToClipboard(CDoc *doc)
{
CDoc *doc2=sys_clipboard_doc;
Bool unlock_doc=DocLock(doc),
unlock_doc2=DocLock(doc2);
CDocEntry *doc_e=doc->root.next,*doc_e1,*doc_ne,*doc_e2=NULL;
ClipBoardDel;
while (doc_e!=doc) {
doc_e1=doc_e->next;
if (doc_e->type & DOCET_SELECTED) {
doc_e->type&=~DOCET_SELECTED;
if (!Bt(doc_data_types,doc_e->type_u8)) {
doc_ne=DocEntryCopy(doc2,doc_e);
QueIns(doc_ne,doc2->root.last);
}
if (doc_e==doc->cur_entry || doc_e==doc_e2)
doc_e2=doc_e->next;
DocEntryDel(doc,doc_e);
}
doc_e=doc_e1;
}
if (doc_e2) {
doc->cur_entry=doc_e2;
doc->cur_data_col=doc_e2->min_col;
}
doc->recalc_start=doc;
DocRemSoftNewLines(doc,NULL);
if (unlock_doc2)
DocUnlock(doc2);
if (unlock_doc)
DocUnlock(doc);
}
public U0 EdPasteClipboard(CDoc *doc)
{
CDoc *doc2=sys_clipboard_doc;
Bool unlock_doc=DocLock(doc),
unlock_doc2=DocLock(doc2);
CDocEntry *doc_ce=doc->cur_entry,*doc_e;
if (doc_ce->type_u8==DOCT_DATA) {
doc_e=doc2->root.next;
while (doc_e!=doc2) {
if (Bt(doc_tag_types,doc_e->type_u8))
DocPutSPartial(doc,doc_e->tag);
doc_e=doc_e->next;
}
} else
DocInsDoc(doc,doc2);
if (unlock_doc2)
DocUnlock(doc2);
if (unlock_doc)
DocUnlock(doc);
}
public U0 DocCut(CDoc *doc,CDocEntry *start,CDocEntry *end)
{ //deletes including end points
Bool unlock_doc=DocLock(doc);
CDocEntry *doc_e1;
while (start!=doc) {
doc_e1=start->next;
if (start==doc->cur_entry) {
doc->cur_entry=start->next;
doc->cur_data_col=doc->cur_entry->min_col;
}
DocEntryDel(doc,start);
if (start==end)
break;
start=doc_e1;
}
doc->recalc_start=doc;
DocRemSoftNewLines(doc,NULL);
if (unlock_doc)
DocUnlock(doc);
}
public CDoc *DocCopy(CDoc *doc,CDocEntry *start,CDocEntry *end)
{ //copies including end points
CDoc *doc2=DocNew;
Bool unlock_doc=DocLock(doc);
CDocEntry *doc_ne;
while (start!=doc) {
if (!Bt(doc_data_types,start->type_u8)) {
doc_ne=DocEntryCopy(doc2,start);
QueIns(doc_ne,doc2->root.last);
}
if (start==end)
break;
start=start->next;
}
if (unlock_doc)
DocUnlock(doc);
return doc2;
}
#help_index "Doc;Compiler/Directive"
public U0 StreamDoc(CDoc *doc)
{ //TODO: $LK,"DocRst","MN:DocRst"$
Bool unlock_doc=DocLock(doc);
CDocEntry *doc_e=doc->root.next;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_TEXT)
StreamPutS(doc_e->tag);
else if (doc_e->type_u8==DOCT_NEW_LINE)
StreamPutS("\n");
else if (doc_e->type_u8==DOCT_TAB)
StreamPutS("\t");
doc_e=doc_e->next;
}
if (unlock_doc)
DocUnlock(doc);
}
#help_index "Doc"
Bool DocCaptureUndo(CDoc *doc,Bool force=FALSE)
{
Bool result=FALSE,unlock;
I64 time_stamp;
CDocUndo *u;
if (doc->flags&DOCF_ALLOW_UNDO) {
unlock=DocLock(doc);
time_stamp=GetTimeStamp;
if (doc->flags&DOCF_UNDO_DIRTY &&
time_stamp>doc->undo_root.last->time_stamp+time_stamp_freq<<4 || force) {
u=CAlloc(sizeof(CDocUndo),doc->mem_task);
u->time_stamp=time_stamp;
u->body=DocSave(doc,&u->size);
QueIns(u,doc->undo_root.last);
doc->flags&=~DOCF_UNDO_DIRTY;
doc->undo_cnt++;
u->doc_flags=doc->flags;
result=TRUE;
}
if (unlock)
DocUnlock(doc);
}
return result;
}
U0 DocUndoRestore(CDoc *doc)
{
Bool unlock=DocLock(doc);
CDocUndo *u=doc->undo_root.last,*u_next,*u_last;
if (u!=&doc->undo_root) {
QueRem(u);
u_next=doc->undo_root.next;
u_last=doc->undo_root.last;
QueInit(&doc->undo_root);
DocRst(doc,TRUE);
doc->flags=u->doc_flags;
DocLoad(doc,u->body,u->size);
DocUndoDel(doc,u);
doc->undo_root.next=u_next;
doc->undo_root.last=u_last;
}
DocUndoCntSet(doc);
doc->flags&=~DOCF_UNDO_DIRTY;
if (unlock)
DocUnlock(doc);
}
#help_index "File/Cmd Line (Typically);Doc/Cmd Line (Typically);Cmd Line (Typically)"
public Bool Type(U8 *fname)
//Output a file to the cmd line.
//Even graphics and macros will be sent.
{
CDoc *doc,*doc2;
if (doc=DocCur) {
if (FilesFindMatch(FILENAME_MASK_TXT,fname)) {
doc2=DocRead(fname);
DocInsDoc(doc,doc2);
DocDel(doc2);
return TRUE;
} else if (FilesFindMatch("*.BMP.Z",fname)) {
DocPutBMPFile(doc,fname,FALSE);
return TRUE;
} else if (FilesFindMatch("*.BMP;*.bmp",fname)) {
DocPutBMPFile(doc,fname,TRUE);
return TRUE;
} else if (FilesFindMatch("*.GRA*",fname)) {
DocPutGRAFile(doc,fname);
return TRUE;
}
}
return FALSE;
}
#help_index "Doc"
+385
View File
@@ -0,0 +1,385 @@
CHashTable *doc_hash;
U0 DocHighlightInit()
{
doc_hash=MAllocIdentical(asm_hash);
doc_hash->next=NULL;
}
DocHighlightInit;
U32 *DocHighlight(CDoc *doc,Bool full_refresh,CDocEntry *doc_e,CDocSettings **_s,
U8 *src,I64 len,I64 _temp_u32_attr)
{ //Be aware of $LK-A,"::/TempleOS/Adam/ToHtml.CPP"$.
U32 *result=MAlloc((len+1)*sizeof(U32)),*dst=result;
U8 *ptr,ch,ch1,last_ch;
CDocSettings *s=*_s;
I64 temp_u32_attr,mask_temp_u32_attr=_temp_u32_attr&0xFFFFF000,
comment_depth,brace_depth=s->brace_depth,paren_depth=s->paren_depth;
CHash *temph;
nobound_switch (s->state) {
case DOCSS_NORMAL:
hl_normal:
while (len) {
while (len && !Bt(alpha_numeric_bitmap,*src)) {
temp_u32_attr=_temp_u32_attr;
ch1=*src++;
switch (ch1) {
case '/':
if (len>=2) {
if (*src=='/') {
temp_u32_attr=(s->comment_attr&15)<<8|mask_temp_u32_attr;
*dst++=ch1+temp_u32_attr;
*dst++=*src++ +temp_u32_attr;
len-=2;
goto hl_cpp_comment;
} else if (*src=='*') {
temp_u32_attr=(s->comment_attr&15)<<8|mask_temp_u32_attr;
*dst++=ch1+temp_u32_attr;
*dst++=*src++ +temp_u32_attr;
len-=2;
comment_depth=1;
goto hl_comment;
}
}
break;
case '\'':
temp_u32_attr=(s->quote_attr&15)<<8|mask_temp_u32_attr;
*dst++=ch1+temp_u32_attr;
len--;
goto hl_single_quote;
case '\"':
temp_u32_attr=(s->quote_attr&15)<<8|mask_temp_u32_attr;
*dst++=ch1+temp_u32_attr;
len--;
goto hl_dbl_quote;
case '(':
if (paren_depth++&1)
temp_u32_attr=(s->alt_text_attr&15)<<8|mask_temp_u32_attr;
break;
case ')':
if (--paren_depth&1)
temp_u32_attr=(s->alt_text_attr&15)<<8|mask_temp_u32_attr;
break;
case '{':
if (brace_depth++&1)
temp_u32_attr=(s->alt_text_attr&15)<<8|mask_temp_u32_attr;
break;
case '}':
if (--brace_depth&1)
temp_u32_attr=(s->alt_text_attr&15)<<8|mask_temp_u32_attr;
break;
}
*dst++=ch1+temp_u32_attr;
if (!--len) goto hl_normal_done;
}
ptr=src;
while (len && Bt(alpha_numeric_bitmap,*src)) {
src++;
len--;
}
ch=*src;
*src=0;
if (temph=HashFind(ptr,doc_hash,HTT_KEYWORD|HTT_ASM_KEYWORD|HTT_OPCODE|HTT_REG)) {
if (temph->type&(HTT_KEYWORD|HTT_ASM_KEYWORD|HTT_OPCODE))
temp_u32_attr=(s->keyword_attr&15) <<8|mask_temp_u32_attr;
else
temp_u32_attr=(s->keyword2_attr&15)<<8|mask_temp_u32_attr;
} else
temp_u32_attr=_temp_u32_attr;
while (ch1=*ptr++)
*dst++=ch1+temp_u32_attr;
*src=ch;
}
hl_normal_done:
if (s->state!=DOCSS_NORMAL||s->comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_NORMAL;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=0;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_SINGLE_QUOTE:
temp_u32_attr=(s->quote_attr&15)<<8|mask_temp_u32_attr;
hl_single_quote:
last_ch=0;
while (len--) {
ch1=*src++;
*dst++=ch1+temp_u32_attr;
if (last_ch!='\\' && ch1=='\'')
goto hl_normal;
if (last_ch=='\\' && ch1=='\\')
last_ch=0;
else
last_ch=ch1;
}
if (s->state!=DOCSS_SINGLE_QUOTE||s->comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_SINGLE_QUOTE;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=0;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_DBL_QUOTE:
temp_u32_attr=(s->quote_attr&15)<<8|mask_temp_u32_attr;
hl_dbl_quote:
last_ch=0;
while (len--) {
ch1=*src++;
*dst++=ch1+temp_u32_attr;
if (last_ch!='\\' && ch1=='\"')
goto hl_normal;
if (last_ch=='\\' && ch1=='\\')
last_ch=0;
else
last_ch=ch1;
}
if (s->state!=DOCSS_DBL_QUOTE||s->comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_DBL_QUOTE;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=0;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_COMMENT:
temp_u32_attr=(s->comment_attr&15)<<8|mask_temp_u32_attr;
comment_depth=s->comment_depth;
hl_comment:
last_ch=0;
while (len--) {
ch1=*src++;
*dst++=ch1+temp_u32_attr;
if (last_ch=='*' && ch1=='/') {
if (!--comment_depth)
goto hl_normal;
} else if (last_ch=='/' && ch1=='*')
comment_depth++;
last_ch=ch1;
}
if (s->state!=DOCSS_COMMENT||s->comment_depth!=comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_COMMENT;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=comment_depth;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_CPP_Z_COMMENT:
temp_u32_attr=(s->comment_attr&15)<<8|mask_temp_u32_attr;
hl_cpp_comment:
while (len--)
*dst++=*src++ +temp_u32_attr;
if (s->state!=DOCSS_CPP_Z_COMMENT||s->comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_CPP_Z_COMMENT;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=0;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_NORMAL+DOCSSF_BPT:
temp_u32_attr=_temp_u32_attr & 0xFFFFF000 | RED<<8;
hl_bpt_normal:
while (len) {
while (len && !Bt(alpha_numeric_bitmap,*src)) {
ch1=*src++;
switch (ch1) {
case '/':
if (len>=2) {
if (*src=='/') {
*dst++=ch1+temp_u32_attr;
*dst++=*src++ +temp_u32_attr;
len-=2;
goto hl_bpt_cpp_comment;
} else if (*src=='*') {
*dst++=ch1+temp_u32_attr;
*dst++=*src++ +temp_u32_attr;
len-=2;
comment_depth=1;
goto hl_bpt_comment;
}
}
break;
case '\'':
*dst++=ch1+temp_u32_attr;
len--;
goto hl_bpt_single_quote;
case '\"':
*dst++=ch1+temp_u32_attr;
len--;
goto hl_bpt_dbl_quote;
case '(':
paren_depth++;
break;
case ')':
paren_depth--;
break;
case '{':
brace_depth++;
break;
case '}':
brace_depth--;
break;
}
*dst++=ch1+temp_u32_attr;
if (!--len) goto hl_bpt_normal_done;
}
ptr=src;
while (len && Bt(alpha_numeric_bitmap,*src)) {
src++;
len--;
}
ch=*src;
*src=0;
while (ch1=*ptr++)
*dst++=ch1+temp_u32_attr;
*src=ch;
}
hl_bpt_normal_done:
if (s->state!=DOCSS_NORMAL+DOCSSF_BPT||s->comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_NORMAL+DOCSSF_BPT;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=0;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_SINGLE_QUOTE+DOCSSF_BPT:
temp_u32_attr=_temp_u32_attr & 0xFFFFF000 | RED<<8;
hl_bpt_single_quote:
last_ch=0;
while (len--) {
ch1=*src++;
*dst++=ch1+temp_u32_attr;
if (last_ch!='\\' && ch1=='\'')
goto hl_bpt_normal;
if (last_ch=='\\' && ch1=='\\')
last_ch=0;
else
last_ch=ch1;
}
if (s->state!=DOCSS_SINGLE_QUOTE+DOCSSF_BPT||s->comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_SINGLE_QUOTE+DOCSSF_BPT;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=0;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_DBL_QUOTE+DOCSSF_BPT:
temp_u32_attr=_temp_u32_attr & 0xFFFFF000 | RED<<8;
hl_bpt_dbl_quote:
last_ch=0;
while (len--) {
ch1=*src++;
*dst++=ch1+temp_u32_attr;
if (last_ch!='\\' && ch1=='\"')
goto hl_bpt_normal;
if (last_ch=='\\' && ch1=='\\')
last_ch=0;
else
last_ch=ch1;
}
if (s->state!=DOCSS_DBL_QUOTE+DOCSSF_BPT||s->comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_DBL_QUOTE+DOCSSF_BPT;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=0;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_COMMENT+DOCSSF_BPT:
temp_u32_attr=_temp_u32_attr & 0xFFFFF000 | RED<<8;
comment_depth=s->comment_depth;
hl_bpt_comment:
last_ch=0;
while (len--) {
ch1=*src++;
*dst++=ch1+temp_u32_attr;
if (last_ch=='*' && ch1=='/') {
if (!--comment_depth)
goto hl_bpt_normal;
} else if (last_ch=='/' && ch1=='*')
comment_depth++;
last_ch=ch1;
}
if (s->state!=DOCSS_COMMENT+DOCSSF_BPT||s->comment_depth!=comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_COMMENT+DOCSSF_BPT;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=comment_depth;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
case DOCSS_CPP_Z_COMMENT+DOCSSF_BPT:
temp_u32_attr=_temp_u32_attr & 0xFFFFF000 | RED<<8;
hl_bpt_cpp_comment:
while (len--)
*dst++=*src++ +temp_u32_attr;
if (s->state!=DOCSS_CPP_Z_COMMENT+DOCSSF_BPT||s->comment_depth||
s->paren_depth!=paren_depth||s->brace_depth!=brace_depth) {
if (full_refresh) {
s=DocSettingsIdentical(doc,s);
s->state=DOCSS_CPP_Z_COMMENT+DOCSSF_BPT;
s->paren_depth=paren_depth;
s->brace_depth=brace_depth;
s->comment_depth=0;
QueIns(s,doc->settings_root.last);
} else
s=DocSettingsNext(doc_e->next);
}
break;
}
*dst=0;
*_s=s;
return result;
}
+506
View File
@@ -0,0 +1,506 @@
#help_index "Debugging/IDE"
#define IDET_GO 1
#define IDET_STEP_INTO 2
#define IDET_STEP_OVER 3
class CIDE
{
I64 type;
U8 *cur_line,*next_line;
U8 *call_bpt;
Bool existing_bpt;
};
U0 IDEWaitParent()
{
CTask *task=Fs->parent_task;
while (!IsSuspended(task) &&
!Bt(&task->task_flags,TASKf_IDLE) &&
!Bt(&task->rflags,RFLAGf_TRAP))
Yield;
}
public CHashFun *DbgFunFind(CDoc *doc,I64 line_offset=0)
{
U8 st[256],*filename=doc->filename.name;
I64 line=doc->cur_entry->y+1+line_offset;
CHashTable *h=Fs->hash_table;
CHashSrcSym *temph;
CDbgInfo *dbg;
while (h) {
temph=h->next_added;
while (temph!=h) {
if (temph->type&(HTT_FUN|HTT_EXPORT_SYS_SYM))
dbg=temph->debug;
else
dbg=NULL;
if (dbg) {
StrCpy(st,temph->src_link);
StrFirstRem(st,":");
StrLastRem(st,",");
if (!StrCmp(st,filename)) {
if (dbg->min_line<=line<=dbg->max_line)
return temph;
}
}
temph=temph->next_added;
}
h=h->next;
}
return NULL;
}
U0 WatchLocals()
{
Bool old_preempt=Preempt(OFF);
CTask *task=Fs->parent_task,*dbg_task;
CDoc *doc;
CHashFun *tempf,*tempf1;
I64 sc,ch,offset,ip;
F64 timeout;
U8 **rbp,**ptr;
while (TRUE) {
IDEWaitParent;
if (!TaskValidate(dbg_task=task->dbg_task))
Exit;
if (ScanKey(&ch,&sc,TRUE)) {
timeout=tS+4.0;
do {
if (ch==CH_SHIFT_ESC || ch==CH_ESC)
Exit;
if (ScanKey(&ch,&sc,TRUE))
timeout=tS+4.0;
WinMgrSync;
} while (tS<timeout);
} else {
IDEWaitParent;
if (!TaskValidate(dbg_task=task->dbg_task))
Exit;
DocDblBufStart;
if (doc=DocCur(dbg_task)) {
if (tempf=DbgFunFind(doc,0)) {
"$$WW,1$$";
rbp=task->rbp;
ip=task->rip;
while (TRUE) {
tempf1=PSectFind(ip,&offset);
break; //TODO: load reg vars for higher level subroutines
if (tempf==tempf1)
break;
else {
if (rbp>=*rbp)
break;
ptr=rbp+1;
rbp=*rbp;
ip=*ptr;
if (!ChkOnStk(rbp,task))
break;
}
}
if (tempf==tempf1)
FunRep(tempf->str,rbp,1,task);
}
}
DocDblBufEnd;
WinMgrSync;
}
}
Preempt(old_preempt);
}
public U0 IDE(U8 *filename)
//Spawns a child process which has
//access to parents syms. Can be used
//to debug parent.
{
CTask *task;
U8 *fn1=DftExt(filename,"CPP.Z"),
*fn2=FileNameAbs(fn1);
if (PopUpCancelOk("$$BK,1$$$$FG,RED$$TempleOS IDE Debugger$$FG$$$$BK,0$$\n"
"Do not use this on files that run when included.\n"
"\nTo use:\n"
" 1) Set a break-point in the editor window.\n"
" 2) Run program from cmd line.\n\n"
"$$FG,GREEN$$F5$$FG$$\t\tGo\n"
"$$FG,GREEN$$F10$$FG$$\t\tStep Over\n"
"$$FG,GREEN$$F11$$FG$$\t\tStep Into\n"
"$$FG,GREEN$$F9$$FG$$\t\tToggle Break Point\n"
"$$FG,GREEN$$SHIFT-F9$$FG$$\tClear All Break Points\n",
"\n\n\nNote: I don't use this debugger because\n"
"I'm always doing multitasking stuff, \n"
"kernel stuff and multicore stuff. Also,\n"
"you can't debug code in the window\n"
"mgr callbacks. It works on really\n"
"simple stuff, sort-of.\n\n"
"I recommend making use of:\n"
"$$LK,\"progress1\",\"MN:progress1\"$$-$$LK,\"progress4\",\"MN:progress4\"$$, -- glbl I64 vars shown on wallpaper\n"
"$$LK,\"DbgI64\",\"MN:DbgI64\"$$() $$LK,\"DbgStr\",\"MN:DbgStr\"$$() $$LK,\"DbgAdd\",\"MN:DbgAdd\"$$() -- raw text output for a time\n"
"$$LK,\"Beep\",\"MN:Beep\"$$() $$LK,\"Snd\",\"MN:Snd\"$$() -- sound\n"
"$$LK,\"AdamLog\",\"MN:AdamLog\"$$() $$LK,\"AdamErr\",\"MN:AdamErr\"$$() -- printf to adam task's window\n"
"$$LK,\"SysDbg\",\"MN:SysDbg\"$$() and $$LK,\"IsSysDbg\",\"MN:IsSysDbg\"$$() -- just a flag\n\n")) {
SetWinHorz(1,TEXT_COLS>>1-1);
SetWinVert(2,TEXT_ROWS-2);
LBts(&Fs->display_flags,DISPLAYf_CHILDREN_NOT_ON_TOP);
task=Spawn(&UserCmdLine,NULL,"Debug",Fs);
TaskWait(task);
SetWinHorz(TEXT_COLS>>1+1,TEXT_COLS-2,task);
SetWinVert(12,TEXT_ROWS-2,task);
XTalk(task,"Ed(\"%s\");\n",fn2);
Fs->dbg_task=task;
task=Spawn(&UserCmdLine,NULL,"Watch",Fs);
TaskWait(task);
SetWinHorz(TEXT_COLS>>1+1,TEXT_COLS-2,task);
SetWinVert(2,10,task);
XTalk(task,"WatchLocals;\n");
ExeFile(fn2);
Free(fn1);
Free(fn2);
}
}
I64 IDELineAdd(CDbgInfo *dbg,I64 line)
{
I64 max=dbg->max_line-dbg->min_line;
line-=dbg->min_line;
if (line<0)
return IDELineAdd(dbg,dbg->min_line);
while (!dbg->body[line] && line<=max)
line++;
return dbg->body[line];
}
I64 IDERIPLineNum(CDoc *doc,U8 *rip)
{
U8 st[256],*filename=doc->filename.name;
I64 line;
CHashTable *h=Fs->hash_table;
CHashFun *tempf;
CDbgInfo *dbg;
while (h) {
tempf=h->next_added;
while (tempf!=h) {
if (tempf->type&HTT_FUN) {
if (dbg=tempf->debug) {
StrCpy(st,tempf->src_link);
StrFirstRem(st,":");
StrLastRem(st,",");
if (!StrCmp(st,filename)) {
for (line=dbg->min_line;line<=dbg->max_line;line++)
if (rip>=IDELineAdd(dbg,line) &&
rip<IDELineAdd(dbg,line+1))
return line;
}
}
}
tempf=tempf->next_added;
}
h=h->next;
}
return -1;
}
U0 IDESetStepRange(CDoc *doc)
{
U8 st[256],*filename=doc->filename.name;
I64 line=doc->cur_entry->y+1;
CHashTable *h=Fs->hash_table;
CHashFun *tempf;
CIDE *tempi=NamedFramePtr("IDEFrame");
CDbgInfo *dbg;
while (h) {
tempf=h->next_added;
while (tempf!=h) {
if (tempf->type&HTT_FUN) {
if (dbg=tempf->debug) {
StrCpy(st,tempf->src_link);
StrFirstRem(st,":");
StrLastRem(st,",");
if (!StrCmp(st,filename)) {
if (dbg->min_line<=line<=dbg->max_line) {
tempi->cur_line =IDELineAdd(dbg,line);
tempi->next_line=IDELineAdd(dbg,line+1);
return;
}
}
}
}
tempf=tempf->next_added;
}
h=h->next;
}
}
U0 IDEToggleBpt(CDoc *doc)
{ //F9
U8 st[512],*filename=doc->filename.name;
I64 a,line=doc->cur_entry->y+1;
Bool unlock;
CHashTable *h=Fs->hash_table;
CHashFun *tempf;
CDbgInfo *dbg;
CDocEntry *doc_e;
while (h) {
tempf=h->next_added;
while (tempf!=h) {
if (tempf->type&HTT_FUN) {
if (dbg=tempf->debug) {
StrCpy(st,tempf->src_link);
StrFirstRem(st,":");
StrLastRem(st,",");
if (!StrCmp(st,filename)) {
if (dbg->min_line<=line<=dbg->max_line) {
a=IDELineAdd(dbg,line);
unlock=DocLock(doc);
doc_e=doc->cur_entry;
while (doc_e->last->type_u8!=DOCT_NEW_LINE &&
doc_e->last->type_u8!=DOCT_SOFT_NEW_LINE &&
doc_e->last!=doc)
doc_e=doc_e->last;
doc->cur_entry=doc_e;
doc->cur_data_col=doc_e->min_col;
if (!BptR(a,Fs->parent_task)) {
BptS(a,Fs->parent_task);
DocPutS(doc,"$$BP$$");
} else {
if (doc_e->type_u8==DOCT_BPT) {
doc->cur_entry=doc_e->next;
doc->cur_data_col=doc->cur_entry->min_col;
DocEntryDel(doc,doc_e);
}
}
if (unlock)
DocUnlock(doc);
DocLineNumGoTo(doc,line);
return;
}
}
}
}
tempf=tempf->next_added;
}
h=h->next;
}
}
U0 IDEClearAllBpts(CDoc *doc)
{ //SHIFT-F9
CDocEntry *doc_e,*doc_e2;
Bool unlock;
IDEWaitParent;
B2(Fs->parent_task);
unlock=DocLock(doc);
doc_e=doc->root.next;
while (doc_e!=doc) {
doc_e2=doc_e->next;
if (doc_e->type_u8==DOCT_BPT) {
if (doc->cur_entry==doc_e) {
doc->cur_entry=doc_e->next;
doc->cur_data_col=doc->cur_entry->min_col;
}
DocEntryDel(doc,doc_e);
}
doc_e=doc_e2;
}
if (unlock)
DocUnlock(doc);
}
U0 IDEGo() //Continue after breakpoint
{ //F5
CTask *task=Fs->parent_task;
CIDE *tempi=NamedFramePtr("IDEFrame");
if (!tempi) {
tempi=CAlloc(sizeof(CIDE));
NamedFramePtrAdd("IDEFrame",tempi);
}
IDEWaitParent;
LBts(&task->task_flags,TASKf_DISABLE_BPTS);
tempi->cur_line=task->rip;
tempi->type=IDET_GO;
LBts(&task->rflags,RFLAGf_TRAP);
Suspend(task,FALSE);
}
U0 IDEStepOver(CDoc *doc)
{ //F10
CTask *task=Fs->parent_task;
I64 line;
U8 *opcode;
CIDE *tempi=NamedFramePtr("IDEFrame");
if (!tempi) {
tempi=CAlloc(sizeof(CIDE));
NamedFramePtrAdd("IDEFrame",tempi);
}
IDEWaitParent;
line=IDERIPLineNum(doc,task->rip);
LBts(&task->task_flags,TASKf_DISABLE_BPTS);
if (line>0) {
DocLineNumGoTo(doc,line);
IDESetStepRange(doc);
} else {
tempi->cur_line=NULL;
tempi->next_line=NULL;
}
tempi->type=IDET_STEP_OVER;
tempi->call_bpt=NULL;
LBts(&task->rflags,RFLAGf_TRAP);
Suspend(task,FALSE);
opcode=task->rip;
if (*opcode==OC_CALL) {
if (BptS(opcode+5,task)) {
if (tempi->call_bpt!=opcode+5)
tempi->existing_bpt=TRUE;
} else
tempi->existing_bpt=FALSE;
tempi->call_bpt=opcode+5;
LBtr(&task->task_flags,TASKf_DISABLE_BPTS);
LBtr(&task->rflags,RFLAGf_TRAP);
}
}
U0 IDEStepInto(CDoc *doc)
{ //F11
CTask *task=Fs->parent_task;
I64 line;
CIDE *tempi=NamedFramePtr("IDEFrame");
if (!tempi) {
tempi=CAlloc(sizeof(CIDE));
NamedFramePtrAdd("IDEFrame",tempi);
}
IDEWaitParent;
line=IDERIPLineNum(doc,task->rip);
LBts(&task->task_flags,TASKf_DISABLE_BPTS);
if (line>0) {
DocLineNumGoTo(doc,line);
IDESetStepRange(doc);
} else {
tempi->cur_line=NULL;
tempi->next_line=NULL;
}
tempi->type=IDET_STEP_INTO;
LBts(&task->rflags,RFLAGf_TRAP);
Suspend(task,FALSE);
}
U0 IDEEdTask(I64)
{
CTask *task=Fs->parent_task,
*ed_task=NULL,*dbg_task;
U8 *rip=task->rip,
*st,*rip_filename,*bpt_filename;
CIDE *tempi,*tempi1;
CDoc *doc;
CBpt *tempb;
if (rip_filename=SrcFileName(rip)) {
ed_task=Spawn(&UserCmdLine,NULL,"Debug",task);
TaskWait(ed_task);
st=MSPrintF("Preempt(OFF);Ed(\"%s\");\n",rip_filename);
XTalkWait(ed_task,st);
Free(st);
doc=DocCur(ed_task);
if (TaskValidate(dbg_task=task->dbg_task)) {
SetWinHorz(dbg_task->win_left,dbg_task->win_right, ed_task);
SetWinVert(dbg_task->win_top, dbg_task->win_bottom,ed_task);
if (tempi=NamedFramePtr("IDEFrame",dbg_task)) {
tempi1=MAllocIdentical(tempi,ed_task);
NamedFramePtrAdd("IDEFrame",tempi1);
}
Kill(dbg_task);
}
task->dbg_task=ed_task;
tempb=task->bpt_lst;
while (tempb) {
if (bpt_filename=SrcFileName(tempb->addr)) {
if (!StrCmp(rip_filename,bpt_filename)) {
DocLineNumGoTo(doc,SrcLineNum(tempb->addr));
DocPutS(doc,"$$BP$$");
}
Free(bpt_filename);
}
tempb=tempb->next;
}
DocLineNumGoTo(doc,SrcLineNum(rip));
Free(rip_filename);
StrCpy(ed_task->task_title,"Debug Task");
}
}
U0 IDEResumeDbg()
{
CTask *dbg_task=Fs->dbg_task;
CIDE *tempi=NamedFramePtr("IDEFrame",dbg_task);
U8 *opcode;
if (!tempi) {
Spawn(&IDEEdTask,NULL,"Resume Dbg",Fs);
Suspend(Fs);
} else
switch (tempi->type) {
case IDET_GO:
if (tempi->cur_line) {
LBtr(&Fs->task_flags,TASKf_DISABLE_BPTS);
LBtr(&Fs->rflags,RFLAGf_TRAP);
if (Fs->rip==tempi->cur_line) {//Jmp to self
tempi->cur_line=NULL;
Spawn(&IDEEdTask,NULL,"Resume Dbg",Fs);
Suspend(Fs);
} else
tempi->cur_line=NULL;
} else {
Spawn(&IDEEdTask,NULL,"Resume Dbg",Fs);
Suspend(Fs);
}
break;
case IDET_STEP_INTO:
if (!tempi->cur_line ||
Fs->rip<tempi->cur_line || Fs->rip>=tempi->next_line) {
Spawn(&IDEEdTask,NULL,"Resume Dbg",Fs);
Suspend(Fs);
} else
Suspend(Fs,FALSE);
break;
case IDET_STEP_OVER:
LBts(&Fs->rflags,RFLAGf_TRAP);
LBts(&Fs->task_flags,TASKf_DISABLE_BPTS);
if (Fs->rip==tempi->call_bpt) {
if (!tempi->existing_bpt)
BptR(Fs->rip,Fs,FALSE);
tempi->call_bpt=NULL;
}
if (!tempi->cur_line ||
Fs->rip<tempi->cur_line || Fs->rip>=tempi->next_line) {
Spawn(&IDEEdTask,NULL,"Resume Dbg",Fs);
Suspend(Fs);
} else {
opcode=Fs->rip;
if (*opcode==OC_CALL) {
if (BptS(opcode+5,Fs,FALSE)) {
if (tempi->call_bpt!=opcode+5)
tempi->existing_bpt=TRUE;
} else
tempi->existing_bpt=FALSE;
tempi->call_bpt=opcode+5;
LBtr(&Fs->task_flags,TASKf_DISABLE_BPTS);
LBtr(&Fs->rflags,RFLAGf_TRAP);
}
Suspend(Fs,FALSE);
}
break;
}
}
ext[EXT_RESUME_DBG]=&IDEResumeDbg;
#help_index ""
+219
View File
@@ -0,0 +1,219 @@
U8 captured_macro_name[136];
StrCpy(captured_macro_name,"Test");
I64 sys_macro_repeat_n=1;
U0 SysMacroStripKey(CTaskCmd *macro_root,I64 p1,I64 p2)
{
CTaskCmd *tempc,*tempc1;
tempc=macro_root->next;
while (tempc!=macro_root) {
tempc1=tempc->next;
if (tempc->cmd_code==TASKCT_MSG &&
(tempc->msg_code==MSG_KEY_DOWN ||
tempc->msg_code==MSG_KEY_UP ||
tempc->msg_code==MSG_KEY_DOWN_UP) &&
p1 && tempc->p1==p1 ||
!p1 && tempc->p2==p2) {
QueRem(tempc);
Free(tempc);
}
tempc=tempc1;
}
}
#define MT_NULL 0
#define MT_MSG 1
#define MT_CHAR 2
class CMacroTemp
{
CMacroTemp *next,*last;
I64 type;
U8 buf[136];
};
CMacroTemp *Cmd2MT(CTaskCmd *tempc)
{
U8 buf[8];
CMacroTemp *tempmt=CAlloc(sizeof(CMacroTemp));
if (Bt(getkey_chars_bitmap,tempc->p1) && tempc->msg_code==MSG_KEY_DOWN) {
tempmt->type=MT_CHAR;
buf[0]=tempc->p1;
buf[1]=0;
SPrintF(tempmt->buf,"%Q",buf);
} else {
tempmt->type=MT_MSG;
SPrintF(tempmt->buf,"Msg(0x%X,0x%X,0x%X);",
tempc->msg_code,tempc->p1,tempc->p2);
}
return tempmt;
}
U8 *SysMacro2Str(CTaskCmd *macro_root)
{
CTaskCmd *tempc;
I64 cnt=1; //terminating zero
U8 *ptr,*m;
CMacroTemp *tempmt,*tempmt1,root;
Bool old_preempt=Preempt(OFF);
LBtr(&sys_semas[SYS_SEMA_RECORD_MACRO],0);
QueInit(&root);
root.type=MT_NULL;
tempc=macro_root->next;
while (tempc!=macro_root) {
tempmt=Cmd2MT(tempc);
QueIns(tempmt,root.last);
cnt+=StrLen(tempmt->buf);
if (tempmt->type==MT_CHAR) {
if (tempmt->last->type!=MT_CHAR)
cnt+=StrLen("\"");
if (tempmt->next->type!=MT_CHAR)
cnt+=StrLen("\";");
}
tempc=tempc->next;
}
m=MAlloc(cnt);
ptr=m;
tempmt=root.next;
while (tempmt!=&root) {
tempmt1=tempmt->next;
if (tempmt->type==MT_MSG) {
StrCpy(ptr, tempmt->buf);
ptr+=StrLen(tempmt->buf);
} else {
if (tempmt->last->type!=MT_CHAR) {
StrCpy(ptr, "\"");
ptr+=StrLen("\"");
}
StrCpy(ptr,tempmt->buf);
ptr+=StrLen(tempmt->buf);
if (tempmt->next->type!=MT_CHAR) {
StrCpy(ptr, "\";");
ptr+=StrLen("\";");
}
}
Free(tempmt);
tempmt=tempmt1;
}
*ptr=0;
Preempt(old_preempt);
return m;
}
U0 PlaySysMacro(I64 n=1)
{
CTask *task=sys_focus_task;
Bool old_preempt;
U8 *m;
if (TaskValidate(task)) {
LBtr(&sys_semas[SYS_SEMA_RECORD_MACRO],0);
old_preempt=Preempt(OFF);
m=SysMacro2Str(&sys_macro_root);
while (n-- && TaskValidate(task)) {
if (task==Fs)
AutoStr("%s",m);
else
XTalkStrWait(task,"%s",m);
}
Free(m);
Preempt(old_preempt);
}
}
U0 EdInsCapturedMacro()
{
Bool old_preempt=Preempt(OFF);
U8 *st=SysMacro2Str(&sys_macro_root);
if (sys_focus_task) {
XTalk(sys_focus_task,"$$MA+A+LM+LA,\"%s\",\"%Q\"$$",
captured_macro_name,st);
Free(st);
}
Preempt(old_preempt);
}
#define SM_CANCEL -1
#define SM_RECORD 0
#define SM_INS 1
#define SM_PLAY 2
#define SM_REPEAT_N 3
#define SM_STOP 4
I64 PopUpExitRecordPlayStopIns()
{
U8 buf[136];
CTaskCmd *tempc;
CDoc *doc=DocNew;
CDocEntry *doc_e=DocPutS(doc,"$$DA-P,135,\"Name:%s\"$$");
I64 result=0;
doc_e->data=captured_macro_name;
DocDataFmt(doc_e);
doc_e=DocPutS(doc,"\n$$DA,32,\"Repeat N:%d\"$$");
doc_e->data=&sys_macro_repeat_n;
DocDataFmt(doc_e);
DocPutS(doc,"\n"
"$$CM+LX,1,3$$$$BT,\"RECORD\",SM_RECORD$$"
"$$CM+LX,17,0$$$$BT,\"INSERT\",SM_INS$$"
"$$CM+LX,1,3$$$$BT,\"PLAY\",SM_PLAY$$"
"$$CM+LX,17,0$$$$BT,\"REPEAT N\",SM_REPEAT_N$$"
"$$CM+LX,1,3$$$$BT,\"STOP\",SM_STOP$$"
"$$CM+LX,17,0$$$$BT,\"CANCEL\",SM_CANCEL$$"
"\n\n\n$$FG,GREEN$$SHIFT-F2$$FG$$ will play macro.\n");
doc->flags|=DOCF_MIN_SIZE | DOCF_FORM;
SPrintF(buf,"DocMenuDo(0x%X);",doc);
sys_macro_util_task=Spawn(&ServantUserCmdLine,NULL,"Macro Popup",Fs);
Fs->popup_task=sys_macro_util_task;
LBts(&sys_macro_util_task->display_flags,DISPLAYf_WIN_ON_TOP);
tempc=TaskRqstQue(sys_macro_util_task,Fs,buf,
1<<TASKCf_WAKE_MASTER | 1<<TASKCf_FOCUS_MASTER);
GetRqstResult(tempc,&result);
Fs->popup_task=NULL;
Kill(sys_macro_util_task);
sys_macro_util_task=NULL;
DocDataGet(doc_e);
DocDel(doc);
return result;
}
U0 MacroTask(I64)
{
I64 i;
StrCpy(captured_macro_name,"Click Here");
sys_macro_repeat_n=1;
do {
i=PopUpExitRecordPlayStopIns;
WinRefocus;
switch (i) {
case SM_RECORD:
LBtr(&sys_semas[SYS_SEMA_RECORD_MACRO],0);
QueDel(&sys_macro_root,TRUE);
LBts(&sys_semas[SYS_SEMA_RECORD_MACRO],0);
break;
case SM_PLAY:
PlaySysMacro;
break;
case SM_REPEAT_N:
PlaySysMacro(sys_macro_repeat_n);
break;
case SM_STOP:
LBtr(&sys_semas[SYS_SEMA_RECORD_MACRO],0);
break;
case SM_INS:
LBtr(&sys_semas[SYS_SEMA_RECORD_MACRO],0);
EdInsCapturedMacro;
break;
}
} while (i>=0);
}
U0 EdMacroUtil()
{
if (!sys_macro_util_task)
Spawn(&MacroTask,NULL,"Macro");
}
+690
View File
@@ -0,0 +1,690 @@
#help_index "Doc/Cmd Line (Typically);Cmd Line (Typically)"
Bool Ed(U8 *link_st,I64 ed_flags=0)
{
U8 *filename,*pattern;
I64 i,num;
Bool cont,result=FALSE;
CDoc *doc;
switch (i=EdLinkCvt(link_st,&filename,&pattern,&num,ed_flags)) {
case -1:
break;
case LK_DEF:
doc=DocNew;
StrCpy(doc->desc,"DictDef");
WSDDisplayDefs(doc,filename,num);
goto ej_doc;
case LK_HELP_INDEX:
doc=DocNew;
StrCpy(doc->desc,"HelpIdx");
DocHelpIndex(doc,filename);
ej_doc:
if (!(ed_flags&EDF_BAIL)) {
DocDo(doc);
DocDel(doc);
}
result=TRUE;
break;
default:
if (IsRaw)
EdLite(filename,num);
else {
cont=TRUE;
if (!(ed_flags&EDF_BAIL) && !FilesFindMatch(FILENAME_MASK_TXT,filename) &&
!PopUpCancelOk(ST_WARN_ST "Not Text File\n\n"))
cont=FALSE;
if (cont)
result=DocFileEd(i,filename,pattern,&num,ed_flags);
}
}
Free(filename);
Free(pattern);
return result;
}
public Bool Plain(U8 *filename)
//Open a document in plain text mode,
//so that dollar signs are not special.
{
Bool result;
U8 *st=MSPrintF("PI:%s",filename);
result=Ed(st);
Free(st);
return result;
}
#help_index "Doc"
public Bool DocLinkChk(U8 *link_st)
{
U8 *filename;
I64 num;
Bool result=FALSE;
if (link_st) {
switch (EdLinkCvt(link_st,&filename,,&num)) {
case -1:
break;
case LK_FILE_LINE:
case LK_PLAIN_LINE:
case LK_FILE:
//We don't check line number
result=FileFind(filename,,FUF_JUST_FILES|FUF_Z_OR_NOT_Z|FUF_SCAN_PARENTS);
break;
case LK_BIBLE_FIND:
result=TRUE; //We don't check verse string
break;
default://TODO: Need to validate HI: and DF:
if (Ed(link_st,EDF_BAIL))
result=TRUE;
}
Free(filename);
}
return result;
}
public U8 *DocLinkFile(U8 *link_st,CTask *mem_task=NULL)
{
U8 *filename=NULL,*st,*result=NULL;
if (link_st) {
switch (EdLinkCvt(link_st,&filename)) {
case LK_FILE:
case LK_FILE_ANCHOR:
case LK_FILE_FIND:
case LK_FILE_LINE:
case LK_PLAIN:
case LK_PLAIN_FIND:
case LK_PLAIN_LINE:
st=FileNameAbs(filename,FUF_Z_OR_NOT_Z|FUF_SCAN_PARENTS);
result=StrNew(st);
Free(st);
break;
case LK_BIBLE_FIND:
result=StrNew(Define("ST_BIBLE_FILE"),mem_task);
break;
}
Free(filename);
}
return result;
}
#help_index "Doc/Task"
public CDoc *SysAuxDocInit()
{
CDocEntry *doc_e;
CDoc *aux,*doc=DocCur;
aux=DocNew;
aux->flags|=DOCF_AUX_DOC;
if (doc) {
DocPutS(aux,"$$CM+H+BY+RX+NC,-7,1$$");
doc_e=DocPutS(aux,"$$TX+H+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdFilterCB;
doc_e=DocPutS(aux,"$$TX+H+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdOverStrikeCB;
doc_e=DocPutS(aux,"$$TX+H+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdDollarCB;
}
DocPutS(aux,"$$CM+H+BY+RX+NC,-4,1$$");
doc_e=DocPutS(aux,"$$TX+H+BD+TC,\" \"$$");
doc_e->tag_cb=&EdQuotesCB;
doc_e=DocPutS(aux,"$$TX+H+BD+TC,\" \"$$");
doc_e->tag_cb=&EdBracesCB;
doc_e=DocPutS(aux,"$$TX+H+BD+TC,\" \"$$");
doc_e->tag_cb=&EdSemicolonCB;
if (doc) {
DocPutS(aux,"$$CM+H+BY+RX+NC,-18,1$$");
doc_e=DocPutS(aux,"$$TX+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdMoreCB;
doc_e=DocPutS(aux,"$$TX+H+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdDollarTypeCB;
}
if (Fs->user_num)
DocPrintF(aux,"$$CM+H+TY+LX+NC,5,-1$$$$TX+H+BD,\"#%d\"$$",Fs->user_num);
DocPutS(aux,"$$CM+H+TY+NC,0,-1$$");
doc_e=DocPutS(aux,"$$DA+H-T-P+BD+RD+CX+SCX+IV,140,\"%s...\",16$$");
doc_e->data=&Fs->task_title;
DocDataFmt(doc_e);
DocPrintF(aux,"$$CM+H+NC,1,0$$$$TX+H+BD+IV,\"%X\"$$",Fs);
aux->settings_root.dft_text_attr=Fs->border_attr;
if (Bt(&Fs->display_flags,DISPLAYf_HAS_CLOSE_WIN))
DocPutS(aux,"$$TX+H+RX+BD,\"[X]\"$$");
DocPutS(aux,"$$BK,1$$$$TX+H+LX+BD,\"MENU\"$$$$BK,0$$");
return aux;
}
public U0 UseTermDoc()
{
Bool old_preempt=Preempt(OFF);
CDoc *doc=DocNew;
doc->start_text_attr=WHITE<<4+BLUE;
DocQueIns(doc,Fs->last_doc);
doc->right_click_link=&TermRightClickLink;
doc->max_entries=4096;
doc->flags|=DOCF_ATTR_BY_PRT;
StrCpy(doc->desc,"Term");
DocQueInsRev(SysAuxDocInit,Fs->next_doc);
Fs->cur_menu=MenuFile("::/TempleOS/Doc/EdPullDown.TXT");
WinScrollsInit(Fs);
Preempt(old_preempt);
Raw(OFF);
}
#help_index "Doc/Input"
public U8 *DocGetLine(CDoc *doc,CDocEntry *doc_e,I64 *cur_col=NULL,CDocEntry **_do_e_end=NULL)
{
CDocEntry *doc_e2=doc_e;
Bool unlock=DocLock(doc);
U8 *dst,*src,*start,*result;
I64 i=0;
if (cur_col)
*cur_col=-1;
while (doc_e2!=doc && doc_e2->type_u8!=DOCT_NEW_LINE) {
if (Bt(doc_tag_types,doc_e2->type_u8)) {
src=doc_e2->tag;
i+=StrLen(src);
} else if (doc_e2->type_u8==DOCT_TAB)
i++;
doc_e2=doc_e2->next;
}
result=MAlloc(i+1);
dst=result;
while (doc_e!=doc && doc_e->type_u8!=DOCT_NEW_LINE) {
start=dst;
if (Bt(doc_tag_types,doc_e->type_u8)) {
src=doc_e->tag;
while (*src)
*dst++=*src++;
} else if (doc_e->type_u8==DOCT_TAB)
*dst++='\t';
if (doc_e==doc->cur_entry && cur_col)
*cur_col=start-result+doc->cur_data_col;
doc_e=doc_e->next;
}
if (_do_e_end) *_do_e_end=doc_e;
*dst=0;
if (doc_e==doc->cur_entry && cur_col && !doc->cur_data_col)
*cur_col=dst-result;
if (unlock)
DocUnlock(doc);
return result;
}
#help_index "Doc/Output"
public U0 DocDump(CDoc *doc,I64 uS_delay=0)
{
U8 *st;
CDocEntry *doc_e,*doc_e2;
Bool unlock=DocLock(doc);
doc_e=doc->root.next;
while (doc_e!=doc) {
st=DocGetLine(doc,doc_e,NULL,&doc_e2);
"" st;
Free(st);
doc_e=doc_e2;
if (doc_e->type_u8==DOCT_NEW_LINE) {
NewLine;
BusyWait(uS_delay);
doc_e=doc_e->next;
}
}
if (unlock)
DocUnlock(doc);
}
public CDocEntry *DocPutLine(CDocEntry *doc_e)
{
U8 ch,*ptr,*ptr2;
while (doc_e->type_u8!=DOCT_ERROR && doc_e->type_u8!=DOCT_NEW_LINE) {
if (Bt(doc_tag_types,doc_e->type_u8)) {
ptr=doc_e->tag;
do {
ptr2=ptr;
while (ch=*ptr)
if (ch=='$$')
break;
else
ptr++;
*ptr=0;
"" ptr2;
*ptr=ch;
if (ch=='$$') {
"$$$$";
ptr++;
}
} while (ch);
} else if (doc_e->type_u8==DOCT_TAB)
'\t';
doc_e=doc_e->next;
}
NewLine;
return doc_e->type_u8==DOCT_ERROR ? doc_e:doc_e->next;
}
#help_index "Doc/Input"
public U8 *DocMGetS(I64 flags=0)
//$LK,"Flags","MN:GETSF_SHIFT_ESC_EXIT"$
{
CDoc *doc;
CDocEntry *doc_e,*doc_e_end;
Bool old_preempt=IsPreempt;
U8 *st,*result;
I64 ch,sc;
"$$FU$$";
do {
ch=DocGetKey(&sc);
if (ch==CH_ESC) {
doc=Fs->next_doc;
while (doc!=(&Fs->next_doc)(U8 *)-offset(CDoc.next_doc) &&
doc->doc_in_que_signature==DOC_IN_QUE_SIGNATURE_VAL) {
DocLock(doc);
if (!(doc->flags&DOCF_DONT_SHOW) &&
(!doc->best_d || !(doc->flags&DOCF_AUX_DOC)) &&
doc->doc_in_que_signature==DOC_IN_QUE_SIGNATURE_VAL && doc->cur_entry!=doc) {
doc_e=DocEntryCopy(doc,doc->cur_entry);
if (doc->flags&DOCF_AUX_DOC && DocCur)
DocBottom;
else
DocBottom(doc);
DocEntryRun(doc,doc_e,TRUE);
DocEntryDel(doc,doc_e);
DocUnlock(doc);
break;
}
DocUnlock(doc);
doc=doc->next_doc;
}
if (flags&GETSF_WITH_NEW_LINE)
break;
} if (ch==CH_SHIFT_ESC) {
if (flags&GETSF_SHIFT_ESC_EXIT)
Exit;
else {
result=StrNew("");
goto mgets_done;
}
}
//<CTRL-SHIFT-CR> is a blank line without entry
} while (flags&GETSF_WITH_NEW_LINE || ch!='\n' || sc & SCF_CTRL && sc & SCF_SHIFT);
Preempt(OFF);
doc=DocCur;
DocLock(doc);
if (flags&GETSF_WITH_NEW_LINE) {
doc_e=doc->cur_entry;
do doc_e=doc_e->last;
while (doc_e!=doc && doc_e->type_u8!=DOCT_USER_FOREGROUND);
doc_e=doc_e->next;
if (result=DocGetLine(doc,doc_e,NULL,&doc_e_end)) {
while (doc_e_end!=doc && doc_e_end->type_u8==DOCT_NEW_LINE) {
result=StrAdd(result,"\n");
if (st=DocGetLine(doc,doc_e_end->next,NULL,&doc_e_end)) {
result=StrAdd(result,st);
Free(st);
}
}
}
} else {
doc_e=doc->cur_entry;
do doc_e=doc_e->last;
while (doc_e!=doc && doc_e->type_u8!=DOCT_NEW_LINE &&
doc_e->type_u8!=DOCT_USER_FOREGROUND);
if (doc_e!=doc && doc_e->type_u8!=DOCT_USER_FOREGROUND) {
do doc_e=doc_e->last;
while (doc_e!=doc && doc_e->type_u8!=DOCT_NEW_LINE &&
doc_e->type_u8!=DOCT_USER_FOREGROUND);
}
doc_e=doc_e->next;
result=DocGetLine(doc,doc_e,NULL);
}
DocUnlock(doc);
mgets_done:
"$$FU$$$$FG$$$$BG$$";
Preempt(old_preempt);
return result;
}
#help_index "Char/Input"
public I64 PmtI64(U8 *msg,I64 dft,I64 lo=MIN_I64,I64 hi=MAX_I64)
{
Bool okay;
U8 *st;
I64 result;
while (TRUE) {
"" msg,dft;
st=MGetS;
if (!*st) {
Free(st);
return dft;
}
try {
okay=FALSE;
result=ExePrintF3("ToI64(%s);",st);
okay=TRUE;
} catch
Fs->catch_except=TRUE;
Free(st);
if (okay && lo<=result<=hi)
return result;
}
}
public F64 PmtF64(U8 *msg,F64 dft,F64 lo=MIN_F64,F64 hi=MAX_F64)
{
Bool okay;
U8 *st;
F64 result;
while (TRUE) {
"" msg,dft;
st=MGetS;
if (!*st) {
Free(st);
return dft;
}
try {
okay=FALSE;
result=ExePrintF3("ToF64(%s);",st)(F64);
okay=TRUE;
} catch
Fs->catch_except=TRUE;
Free(st);
if (okay && lo<=result<=hi)
return result;
}
}
public U8 *PmtStr(U8 *msg=NULL,U8 *dft=NULL)
{
U8 *st;
if (msg) {
if (dft)
"" msg,dft;
else
"" msg;
}
st=MGetS;
if (!*st) {
Free(st);
if (dft)
return StrNew(dft);
else
return StrNew("");
}
return st;
}
public CDate PmtCDate(U8 *msg,CDate dft,CDate lo=MIN_I64,CDate hi=MAX_I64)
{
U8 *st;
CDate result;
while (TRUE) {
"" msg,dft,dft;
st=MGetS;
if (!*st) {
Free(st);
return dft;
}
result=A2CDate(st);
Free(st);
if (result>=lo && result<=hi)
return result;
}
}
#help_index "Doc"
#define RIGHT_INCLUDE 0
#define RIGHT_DEBUG 1
#define RIGHT_COMPILE 2
#define RIGHT_LOAD 3
#define RIGHT_AINCLUDE 4
#define RIGHT_AUTOFILE 5
#define RIGHT_COPY 6
#define RIGHT_MOVE 7
#define RIGHT_DELETE 8
#define RIGHT_TYPE 9
#define RIGHT_ED 10
#define RIGHT_PLAIN 11
#define RIGHT_BINREP 12
I64 PopUpCancelIncludeDelAuto(U8 *header=NULL,U8 *footer=NULL)
{
I64 i;
CDoc *doc=DocNew;
if (header) DocPutS(doc,header);
DocPrintF(doc,"\n\n"
"TXT=%s\n"
"SRC=%s\n"
"AOT=%s\n"
"JIT=%s\n"
"GRA=%s"
"$$CM+LX,1,3 $$$$BT,\"INCLUDE JIT\",RIGHT_INCLUDE$$"
"$$CM+LX,26,0$$$$BT,\"DEBUG JIT\",RIGHT_DEBUG$$"
"$$CM+LX,1,3 $$$$BT,\"AOT COMPILE AOT\",RIGHT_COMPILE$$"
"$$CM+LX,26,0$$$$BT,\"LOAD BIN\",RIGHT_LOAD$$"
"$$CM+LX,1,3 $$$$BT,\"ADAM_INCLUDE JIT\",RIGHT_AINCLUDE$$"
"$$CM+LX,26,0$$$$BT,\"AUTOFILE AUT\",RIGHT_AUTOFILE$$"
"$$CM+LX,1,3 $$$$BT,\"COPY \",RIGHT_COPY$$"
"$$CM+LX,26,0$$$$BT,\"MOVE \",RIGHT_MOVE$$"
"$$CM+LX,1,3 $$$$BT,\"DELETE \",RIGHT_DELETE$$"
"$$CM+LX,26,0$$$$BT,\"TYPE TXT;GRA\",RIGHT_TYPE$$"
"$$CM+LX,1,3 $$$$BT,\"ED TXT\",RIGHT_ED$$"
"$$CM+LX,26,0$$$$BT,\"PLAIN ED TXT\",RIGHT_PLAIN$$"
"$$CM+LX,1,3 $$$$BT,\"CANCEL \",DOCM_CANCEL$$"
"$$CM+LX,26,0$$$$BT,\"BINREP BIN\",RIGHT_BINREP$$\n",
FILENAME_MASK_TXT,
FILENAME_MASK_SRC,
FILENAME_MASK_AOT,
FILENAME_MASK_JIT,
FILENAME_MASK_GRA);
if (footer) DocPutS(doc,footer);
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
I64 EdLeftClickLink(CDoc *doc,CDocEntry *doc_e)
{ //called with doc locked, exit unlocked
Bool result;
U8 *st;
if (st=DocEntryLink(doc,doc_e)) {
DocUnlock(doc);
result=Ed(st);
Free(st);
return result;
}
}
I64 TermRightClickLink(CDoc *doc,CDocEntry *doc_e)
{ //called with doc locked, exit unlocked
Bool send_new_line=FALSE,result=FALSE;
U8 *st,*st2;
I64 i;
CEdFileName fn;
if (st2=DocEntryLink(doc,doc_e)) {
if (st=DocLinkFile(st2)) {
DocUnlock(doc);
if ((i=PopUpCancelIncludeDelAuto(st))>=0) {
DocBottom(doc);
switch (i) {
case RIGHT_INCLUDE:
if (FileExtDot(st) && !FilesFindMatch(FILENAME_MASK_JIT,st)) {
if (!PopUpCancelOk(ST_WARN_ST "Not .CPP File\n\n")) {
send_new_line=TRUE;
break;
}
}
"#include \"%s\";\n$$FU$$$$FG$$$$BG$$",st;
WinZBufUpdate;
ExeFile(st);
result=TRUE;
break;
case RIGHT_DELETE:
result=ToBool(Del(st));
break;
case RIGHT_TYPE:
result=Type(st);
break;
case RIGHT_ED:
"Ed(\"%s\");\n$$FU$$$$FG$$$$BG$$",st;
result=Ed(st);
break;
case RIGHT_PLAIN:
"Plain(\"%s\");\n$$FU$$$$FG$$$$BG$$",st;
result=Plain(st);
break;
case RIGHT_AUTOFILE:
if (FileExtDot(st) && !FilesFindMatch("*.AUT*",st)) {
if (!PopUpCancelOk(ST_WARN_ST "Not .AUT File\n\n")) {
send_new_line=TRUE;
break;
}
}
"AutoFile(\"%s\");\n$$FU$$$$FG$$$$BG$$",st;
WinZBufUpdate;
AutoStr("%F\n",st);
result=TRUE;
break;
case RIGHT_AINCLUDE:
if (FileExtDot(st) && !FilesFindMatch(FILENAME_MASK_JIT,st)) {
if (!PopUpCancelOk(ST_WARN_ST "Not .CPP File\n\n")) {
send_new_line=TRUE;
break;
}
}
"Adam(\"#include \\\"%s\\\"\" );\n$$FU$$$$FG$$$$BG$$",st;
WinZBufUpdate;
AdamFile(st,FALSE);
result=TRUE;
break;
case RIGHT_COMPILE:
if (FileExtDot(st) && !FilesFindMatch(FILENAME_MASK_AOT,st)) {
if (!PopUpCancelOk(ST_WARN_ST "Not .PRJ File\n\n")) {
send_new_line=TRUE;
break;
}
}
"Cmp(\"%s\");\n$$FU$$$$FG$$$$BG$$",st;
WinZBufUpdate;
result=!ToBool(Cmp(st));
break;
case RIGHT_LOAD:
if (FileExtDot(st) && !FilesFindMatch("*.BIN*",st)) {
if (!PopUpCancelOk(ST_WARN_ST "Not .BIN File\n\n")) {
send_new_line=TRUE;
break;
}
}
"Load(\"%s\");\n$$FU$$$$FG$$$$BG$$",st;
WinZBufUpdate;
result=ToBool(Load(st));
break;
case RIGHT_BINREP:
if (FileExtDot(st) && !FilesFindMatch("*.BIN*",st)) {
if (!PopUpCancelOk(ST_WARN_ST "Not .BIN File\n\n")) {
send_new_line=TRUE;
break;
}
}
"BinRep(\"%s\");\n$$FU$$$$FG$$$$BG$$",st;
WinZBufUpdate;
result=BinRep(st);
break;
case RIGHT_COPY:
StrCpy(fn.name,st);
if (DocFormDo(fn.name,"CEdFileName")) {
result=ToBool(Copy(st,fn.name));
} else
send_new_line=TRUE;
break;
case RIGHT_MOVE:
StrCpy(fn.name,st);
if (DocFormDo(fn.name,"CEdFileName"))
result=Move(st,fn.name);
else
send_new_line=TRUE;
break;
case RIGHT_DEBUG:
if (FileExtDot(st) && !FilesFindMatch(FILENAME_MASK_JIT,st)) {
if (!PopUpCancelOk(ST_WARN_ST "Not .CPP File\n\n")) {
send_new_line=TRUE;
break;
}
}
"IDE(\"%s\");\n$$FU$$$$FG$$$$BG$$",st;
WinZBufUpdate;
IDE(st);
result=TRUE;
break;
}
} else
send_new_line=TRUE;
Free(st);
} else
send_new_line=TRUE;
Free(st2);
} else
send_new_line=TRUE;
DocBottom(doc);
"$$FU$$$$FG$$$$BG$$";
if (send_new_line)
'\n';
return result;
}
#help_index "Debugging/Dump;Doc/Cmd Line (Typically);Cmd Line (Typically);Doc/Output"
public U0 DocDm(U8 *buf,I64 cnt=0x80)
//Dumps a chunk of mem, showing
//addresses. It is live and can be
//edited.
{
CDocEntry *doc_e;
CDoc *doc=DocCur;
Bool unlock=DocLock(doc);
doc_e=DocPrintF(doc,"$$HX-Z,%d,16$$",cnt);
doc_e->data=buf;
doc->cur_entry=doc_e->next;
DocRecalc(doc);
if (unlock)
DocUnlock(doc);
}
public U0 DocD(U8 *buf,I64 cnt=0x80)
//Dumps a chunk of mem, showing
//offsets. It is live and can be
//edited.
{
CDocEntry *doc_e;
CDoc *doc=DocCur;
Bool unlock=DocLock(doc);
doc_e=DocPrintF(doc,"$$HX,%d,16$$",cnt);
doc_e->data=buf;
doc->cur_entry=doc_e->next;
DocRecalc(doc);
if (unlock)
DocUnlock(doc);
}
#help_index "Doc/Output"
Bool AKDDocPutS(U8 *st)
{
CDoc *doc;
if (doc=DocCur)
DocPutSPartial(doc,st);
return FALSE;
}
KeyDevAdd(&AKDDocPutKey,&AKDDocPutS,0x80000000,TRUE);
fp_mgets=&DocMGetS;
fp_doc_cur=&DocCur;
#help_index "Doc"
+908
View File
@@ -0,0 +1,908 @@
I64 doc_tag_types[(DOCT_NUM_TYPES+63)/64],
doc_nontag_invisible_types[(DOCT_NUM_TYPES+63)/64],
doc_form_types[(DOCT_NUM_TYPES+63)/64],
doc_data_types[(DOCT_NUM_TYPES+63)/64];
I64 doc_clean_scancodes[4]={0,0,0,0};
//Don't forget $LK,"doc_stop_btypes","FF:::/TempleOS/Compiler/Lex.CPP,doc_stop_btypes"$
U0 DocTablesInit()
{
doc_tag_types[0]=
1<<DOCT_TEXT|
1<<DOCT_DATA|
1<<DOCT_MENU_VAL|
1<<DOCT_HIDE_START |
1<<DOCT_TREE|
1<<DOCT_HIDE_END|
1<<DOCT_MACRO|
1<<DOCT_BUTTON|
1<<DOCT_CHECK_BOX|
1<<DOCT_LINK|
1<<DOCT_ANCHOR|
1<<DOCT_SPRITE|
1<<DOCT_INS_BINARY|
1<<DOCT_INS_BINARY_TYPE|
1<<DOCT_INS_BINARY_SIZE|
1<<DOCT_SONG|
1<<DOCT_HTML_IMG|
1<<DOCT_HTML_VIDEO|
1<<DOCT_HTML_CODE;
//Don't forget $LK,"doc_stop_btypes","FF:::/TempleOS/Compiler/Lex.CPP,doc_stop_btypes"$
doc_nontag_invisible_types[0]=
1<<DOCT_PAGE_LEN|
1<<DOCT_LEFT_MARGIN|
1<<DOCT_RIGHT_MARGIN|
1<<DOCT_HEADER|
1<<DOCT_FOOTER|
1<<DOCT_INDENT|
1<<DOCT_FOREGROUND|
1<<DOCT_BACKGROUND|
1<<DOCT_DFT_FOREGROUND|
1<<DOCT_DFT_BACKGROUND|
1<<DOCT_ALT_FOREGROUND|
1<<DOCT_LINK_FOREGROUND|
1<<DOCT_MACRO_FOREGROUND|
1<<DOCT_ANCHOR_FOREGROUND|
1<<DOCT_HIDDEN_FOREGROUND|
1<<DOCT_TREE_FOREGROUND|
1<<DOCT_USER_FOREGROUND|
1<<DOCT_BINARY_FOREGROUND|
1<<DOCT_KEYWORD_FOREGROUND|
1<<DOCT_KEYWORD2_FOREGROUND|
1<<DOCT_COMMENT_FOREGROUND|
1<<DOCT_QUOTE_FOREGROUND|
1<<DOCT_WORD_WRAP|
1<<DOCT_UNDERLINE|
1<<DOCT_INVERT|
1<<DOCT_BLINK|
1<<DOCT_SHIFTED_X|
1<<DOCT_SHIFTED_Y|
1<<DOCT_SPRITE|
1<<DOCT_BPT|
1<<DOCT_HIGHLIGHT|
1<<DOCT_LOCK_TO_PAGE|
1<<DOCT_LOCK_TO_CENTER;
doc_form_types[0]=doc_tag_types[0]&~(1<<DOCT_TEXT)|1<<DOCT_HEX_ED;
doc_data_types[0]=
1<<DOCT_DATA|
1<<DOCT_HEX_ED|
1<<DOCT_CHECK_BOX;
Bts(doc_clean_scancodes,SC_CURSOR_RIGHT);
Bts(doc_clean_scancodes,SC_CURSOR_LEFT);
Bts(doc_clean_scancodes,SC_CURSOR_UP);
Bts(doc_clean_scancodes,SC_CURSOR_DOWN);
Bts(doc_clean_scancodes,SC_PAGE_UP);
Bts(doc_clean_scancodes,SC_PAGE_DOWN);
Bts(doc_clean_scancodes,SC_ALT);
Bts(doc_clean_scancodes,SC_CTRL);
Bts(doc_clean_scancodes,SC_SHIFT);
Bts(doc_clean_scancodes,SC_CAPS);
Bts(doc_clean_scancodes,SC_NUM);
Bts(doc_clean_scancodes,SC_SCROLL);
Bts(doc_clean_scancodes,SC_HOME);
Bts(doc_clean_scancodes,SC_END);
Bts(doc_clean_scancodes,SC_GUI);
Bts(doc_clean_scancodes,SC_BACKSPACE); //Handled specially
}
DocTablesInit;
public Bool DocLock(CDoc *doc)
{
if (!Bt(&doc->locked_flags,DOClf_LOCKED) || doc->owning_task!=Fs) {
while (LBts(&doc->locked_flags,DOClf_LOCKED))
Yield;
if (doc->owning_task!=Fs)
LBEqu(&doc->flags,DOCf_BREAK_UNLOCKED,BreakLock(Fs));
doc->owning_task=Fs;
return TRUE;
} else
return FALSE;
}
public Bool DocUnlock(CDoc *doc)
{
Bool unlock_break;
if (Bt(&doc->locked_flags,DOClf_LOCKED) && doc->owning_task==Fs) {
doc->owning_task=0;
unlock_break=Bt(&doc->flags,DOCf_BREAK_UNLOCKED);
LBtr(&doc->locked_flags,DOClf_LOCKED);
if (unlock_break)
BreakUnlock(Fs);
return TRUE;
} else
return FALSE;
}
CDocBin *DocBinFindNum(CDoc *doc,I64 num)
{
CDocBin *b=doc->bin_root.next;
while (b!=&doc->bin_root) {
if (b->num==num)
return b;
b=b->next;
}
return NULL;
}
CDocBin *DocBinFindTag(CDoc *doc,U8 *tag)
{
CDocBin *b;
if (tag) {
b=doc->bin_root.next;
while (b!=&doc->bin_root) {
if (b->tag && !StrCmp(b->tag,tag))
return b;
b=b->next;
}
}
return NULL;
}
U0 DocBinsValidate(CDoc *doc)
{
Bool unlock=DocLock(doc);
CDocBin *b,*b1;
CDocEntry *doc_e,*doc_e2;
I64 renum_num=0;
b=doc->bin_root.next;
while (b!=&doc->bin_root) {
b->use_cnt=0;
b->temp_use_cnt=0;
b->renum_num=-1;
Free(b->tag);
b->tag=NULL;
b=b->next;
}
doc_e=doc->root.next;
while (doc_e!=doc) {
doc_e2=doc_e->next;
if (doc_e->flags1 & DOCEF1_HAS_BIN) {
if (b=doc_e->bin_data=DocBinFindNum(doc,doc_e->bin_num)) {
if (doc_e->flags2 & DOCEF2_BIN_PTR_LINK)
b->temp_use_cnt=MAX_I32;
if (!b->use_cnt++)
b->renum_num=++renum_num;
doc_e->bin_num=b->renum_num;
if (!b->tag && Bt(doc_tag_types,doc_e->type_u8) &&
doc_e->tag && *doc_e->tag)
b->tag=StrNew(doc_e->tag,doc->mem_task);
} else {
DbgStr("Bin Not Found",3000);
doc_e->type=doc_e->flags2=doc_e->flags1=0;
doc_e->type_u8=DOCT_ERROR;
}
}
doc_e=doc_e2;
}
b=doc->bin_root.next;
doc->cur_bin_num=1;
while (b!=&doc->bin_root) {
b1=b->next;
if (!b->use_cnt) {
QueRem(b);
Free(b->data);
Free(b);
} else {
b->num=b->renum_num;
if (b->num>=doc->cur_bin_num)
doc->cur_bin_num=b->num+1;
}
b=b1;
}
if (unlock)
DocUnlock(doc);
}
U0 DocBinDel(CDoc *doc,CDocBin *b)
{
if (doc && b && b->use_cnt) {
b->use_cnt--;
if (!b->use_cnt) {
QueRem(b);
Free(b->tag);
Free(b->data);
Free(b);
}
} else
DbgStr("DocBinDel",3000);
}
public U0 DocEntryDel(CDoc *doc,CDocEntry *doc_e)
{
if (!doc || doc==doc_e)
DbgStr("DocEntryDel",3000);
else {
if (doc->cur_entry==doc_e)
doc->cur_entry=doc_e->next;
QueRem(doc_e);
if (Bt(doc_tag_types,doc_e->type_u8))
Free(doc_e->tag);
if (doc_e->flags1 & DOCEF1_LEFT_MACRO)
Free(doc_e->left_macro);
if (doc_e->flags1 & DOCEF1_RIGHT_MACRO)
Free(doc_e->right_macro);
if (doc_e->flags1 & DOCEF1_AUX_STR)
Free(doc_e->aux_str);
if (doc_e->flags1 & DOCEF1_DEFINE)
Free(doc_e->define_str);
if (doc_e->flags1 & DOCEF1_HTML_LINK)
Free(doc_e->html_link);
if (doc_e->flags2 & DOCEF2_BIN_PTR_LINK)
Free(doc_e->bin_ptr_link);
if (doc_e->flags1 & DOCEF1_HAS_BIN)
DocBinDel(doc,doc_e->bin_data);
Free(doc_e);
}
}
public I64 DocEntrySize(CDoc *,CDocEntry *doc_e)
{
I64 result;
if (!doc_e) return 0;
result=MSize2(doc_e);
if (Bt(doc_tag_types,doc_e->type_u8))
result+=MSize2(doc_e->tag);
if (doc_e->flags1 & DOCEF1_AUX_STR)
result+=MSize2(doc_e->aux_str);
if (doc_e->flags1 & DOCEF1_DEFINE)
result+=MSize2(doc_e->define_str);
if (doc_e->flags1 & DOCEF1_HTML_LINK)
result+=MSize2(doc_e->html_link);
if (doc_e->flags2 & DOCEF2_BIN_PTR_LINK)
result+=MSize2(doc_e->bin_ptr_link);
if (doc_e->flags1 & DOCEF1_LEFT_MACRO)
result+=MSize2(doc_e->left_macro);
if (doc_e->flags1 & DOCEF1_RIGHT_MACRO)
result+=MSize2(doc_e->right_macro);
return result;
}
U0 DocUndoDel(CDoc *,CDocUndo *u)
{
Free(u->body);
Free(u);
}
U0 DocUndoCntSet(CDoc *doc)
{
Bool unlock=DocLock(doc);
CDocUndo *u=doc->undo_root.next;
doc->undo_cnt=0;
while (u!=&doc->undo_root) {
doc->undo_cnt++;
u=u->next;
}
if (unlock)
DocUnlock(doc);
}
public CDocEntry *DocEntryCopy(CDoc *doc,CDocEntry *doc_e)
{
CDocEntry *doc_ne;
CDocBin *tempb;
CTask *task=doc->mem_task;
doc_ne=MAllocIdentical(doc_e,task);
doc_ne->next=doc_ne;
doc_ne->last=doc_ne;
doc_ne->settings=NULL;
if (Bt(doc_tag_types,doc_e->type_u8))
doc_ne->tag=MAllocIdentical(doc_e->tag,task);
if (doc_e->flags1 & DOCEF1_AUX_STR)
doc_ne->aux_str=MAllocIdentical(doc_e->aux_str,task);
if (doc_e->flags1 & DOCEF1_DEFINE)
doc_ne->define_str=MAllocIdentical(doc_e->define_str,task);
if (doc_e->flags1 & DOCEF1_HTML_LINK)
doc_ne->html_link=MAllocIdentical(doc_e->html_link,task);
if (doc_e->flags2 & DOCEF2_BIN_PTR_LINK)
doc_ne->bin_ptr_link=MAllocIdentical(doc_e->bin_ptr_link,task);
if (doc_e->flags1 & DOCEF1_LEFT_MACRO)
doc_ne->left_macro=MAllocIdentical(doc_e->left_macro,task);
if (doc_e->flags1 & DOCEF1_RIGHT_MACRO)
doc_ne->right_macro=MAllocIdentical(doc_e->right_macro,task);
if (doc_e->flags1 & DOCEF1_HAS_BIN) {
tempb=MAllocIdentical(doc_e->bin_data,task);
tempb->data=MAllocIdentical(doc_e->bin_data->data,task);
doc_ne->bin_num=doc->cur_bin_num;
tempb->num=doc->cur_bin_num++;
doc_ne->bin_data=tempb;
if (Bt(doc_tag_types,doc_e->type_u8) && doc_e->tag && *doc_e->tag)
tempb->tag=StrNew(doc_e->tag,task);
else
tempb->tag=NULL;
QueIns(tempb,doc->bin_root.last);
}
return doc_ne;
}
public U8 *DocEntryLink(CDoc *doc,CDocEntry *doc_e)
{
if (doc_e->flags1&DOCEF1_LINK) {
if (doc_e->flags1 & DOCEF1_AUX_STR)
return StrNew(doc_e->aux_str,doc->mem_task);
else
return StrNew(doc_e->tag,doc->mem_task);
}
return NULL;
}
U0 DocFormFwd(CDoc *doc,Bool giveup=FALSE)
{
CDocEntry *doc_e=doc->cur_entry,*doc_e2=doc_e;
if (doc->flags & DOCF_FORM) {
if (doc_e==doc) goto recover;
while (!Bt(doc_form_types,doc_e->type_u8) ||
doc_e->flags1&DOCEF1_SKIP_IN_FORM) {
doc_e=doc_e->next;
if (doc_e==doc) {
recover:
doc->cur_data_col=0;
if (!giveup) {
doc->cur_entry=doc_e->last;
DocFormBackward(doc,TRUE);
} else
doc->cur_entry=doc;
return;
}
}
}
while (doc_e->type_u8==DOCT_INDENT)
doc_e=doc_e->next;
if (doc_e!=doc_e2) {
doc->cur_data_col=doc_e->min_col;
doc->cur_entry=doc_e;
}
}
U0 DocFormBackward(CDoc *doc,Bool giveup=FALSE)
{
CDocEntry *doc_e=doc->cur_entry,*doc_e2=doc_e;
if (doc->flags & DOCF_FORM) {
while (!Bt(doc_form_types,doc_e->type_u8) ||
doc_e->flags1&DOCEF1_SKIP_IN_FORM) {
doc_e=doc_e->last;
if (doc_e==doc) {
doc->cur_data_col=0;
if (!giveup) {
doc->cur_entry=doc_e->next;
DocFormFwd(doc,TRUE);
} else
doc->cur_entry=doc;
return;
}
}
}
while (doc_e->type_u8==DOCT_INDENT)
doc_e=doc_e->next;
if (doc_e!=doc_e2) {
doc->cur_data_col=doc_e->min_col;
doc->cur_entry=doc_e;
}
}
public U0 DocHome(CDoc *doc=NULL)
{
Bool unlock;
if (!doc) {
doc=DocCur;
if (!doc) return;
}
unlock=DocLock(doc);
doc->cur_entry=doc->root.next;
doc->cur_data_col=doc->cur_entry->min_col;
doc->x=0;
doc->y=0;
doc->line_start_col=0;
doc->cur_top_line_num=0;
DocFormFwd(doc);
if (unlock)
DocUnlock(doc);
}
U0 DocSettlingsRemainingDel(CDoc *doc,CDocEntry *doc_e,CDocSettings *s)
{
CDocSettings *s1;
if (doc_e) {
while (doc_e!=doc) {
doc_e->settings=NULL;
doc_e=doc_e->next;
}
}
if (!s) return;
while (s!=&doc->settings_root) {
s1=s->next;
QueRem(s);
Free(s);
s=s1;
}
}
CDocSettings *DocSettingsIdentical(CDoc *doc,CDocSettings *s1)
{
CDocSettings *s=MAlloc(sizeof(CDocSettings),doc->mem_task);
MemCpy(&s->start,&s1->start,sizeof(CDocSettings)-offset(CDocSettings.start));
return s;
}
CDocSettings *DocSettingsLast(CDocEntry *doc_e)
{
while (!doc_e->settings)
doc_e=doc_e->last;
return doc_e->settings;
}
CDocSettings *DocSettingsNext(CDocEntry *doc_e)
{
while (!doc_e->settings)
doc_e=doc_e->next;
return doc_e->settings;
}
public U0 DocRst(CDoc *doc,Bool is_old)
{
Bool unlock;
CDocEntry *doc_e,*doc_e2;
CDocUndo *u,*u8;
CDocSettings *s;
CDocBin *b,*b1;
if (!doc) {
doc=DocCur;
if (!doc) return;
}
unlock=DocLock(doc);
if (is_old) {
doc_e=doc->root.next;
while (doc_e!=doc) {
doc_e2=doc_e->next;
DocEntryDel(doc,doc_e);
doc_e=doc_e2;
}
DocSettlingsRemainingDel(doc,NULL,doc->settings_root.next);
u=doc->undo_root.next;
while (u!=&doc->undo_root) {
u8=u->next;
DocUndoDel(doc,u);
u=u8;
}
b=doc->bin_root.next;
while (b!=&doc->bin_root) {
b1=b->next;
QueRem(b);
Free(b->data);
Free(b);
b=b1;
}
}
//Check $LK,"DocInsDoc","MN:DocInsDoc"$
doc->flags&=DOCF_BREAK_UNLOCKED;
doc->root.next=doc->root.last=doc;
QueInit(&doc->bin_root);
QueInit(&doc->undo_root);
doc->undo_root.time_stamp=0;
doc->undo_cnt=0;
doc->cur_bin_num=1;
doc->recalc_start=doc;
doc->dollar_buf_ptr=0;
doc->ext_ascii_cnt=doc->ext_ascii_val=0;
doc->cmd_U8=CH_SPACE;
doc->page_line_num=0;
doc->best_d=MAX_I64;
s=&doc->settings_root;
s->next=s->last=s;
s->left_margin=DOC_DFT;
s->right_margin=DOC_DFT;
s->indent=0;
s->page_len=66;
s->header=DOC_DFT;
s->footer=DOC_DFT;
s->state=DOCSS_NORMAL;
s->comment_depth=0;
s->paren_depth=0;
s->brace_depth=0;
s->shifted_x=0;
s->shifted_y=0;
s->cur_text_attr=s->dft_text_attr=doc->start_text_attr=WHITE<<4+BLACK;
s->alt_text_attr =LTGRAY;
s->link_attr =RED;
s->macro_attr =LTBLUE;
s->anchor_attr =DKGRAY;
s->hidden_attr =DKGRAY;
s->tree_attr =PURPLE;
s->user_attr =GREEN;
s->bin_attr =CYAN;
s->keyword_attr =BLUE;
s->keyword2_attr =LTRED;
s->comment_attr =GREEN;
s->quote_attr =BROWN;
doc_e=&doc->root;
doc_e->type=DOCT_ERROR;
doc_e->flags1=0;
doc_e->flags2=0;
doc_e->x=0;
doc_e->y=0;
doc_e->min_col=0;
doc_e->max_col=0;
doc_e->page_line_num=doc->page_line_num;
doc_e->settings=s;
DocHome(doc);
if (unlock)
DocUnlock(doc);
}
public U0 DocDel(CDoc *doc)
{
if (!doc || doc->doc_signature!=DOC_SIGNATURE_VAL) return;
DocLock(doc);
doc->doc_signature=0;
doc->doc_in_que_signature=0;
DocRst(doc,TRUE);
Free(doc->find_replace);
Free(doc->dollar_buf);
DocUnlock(doc);
Free(doc);
}
public I64 DocSize(CDoc *doc)
{
Bool unlock;
CDocEntry *doc_e;
CDocUndo *u;
CDocSettings *s;
CDocBin *b;
I64 result=0;
if (!doc || doc->doc_signature!=DOC_SIGNATURE_VAL) return 0;
unlock=DocLock(doc);
doc_e=doc->root.next;
while (doc_e!=doc) {
result+=DocEntrySize(doc,doc_e);
doc_e=doc_e->next;
}
s=doc->settings_root.next;
while (s!=&doc->settings_root) {
result+=MSize2(s);
s=s->next;
}
u=doc->undo_root.next;
while (u!=&doc->undo_root) {
result+=MSize2(u->body);
result+=MSize2(u);
u=u->next;
}
b=doc->bin_root.next;
while (b!=&doc->bin_root) {
result+=MSize2(b->data);
result+=MSize2(b);
b=b->next;
}
result+=MSize2(doc->find_replace);
result+=MSize2(doc->dollar_buf);
result+=MSize2(doc);
if (unlock)
DocUnlock(doc);
return result;
}
U0 DocDataFmt(CDocEntry *doc_e)
{
I64 i,d;
U8 *ptr;
if (doc_e->type_u8==DOCT_DATA || doc_e->type_u8==DOCT_CHECK_BOX) {
if (doc_e->flags1 & DOCEF1_DATA_IS_PTR) {
if (!(ptr=doc_e->data)) return;
} else
ptr=&doc_e->data;
if (doc_e->flags1&DOCEF1_U8)
d=*ptr;
else if (doc_e->flags1&DOCEF1_U16)
d=*ptr(U16 *);
else if (doc_e->flags1&DOCEF1_U32)
d=*ptr(U32 *);
else
d=*ptr(I64 *);
if (doc_e->type_u8==DOCT_DATA) {
SPrintF(doc_e->tag,doc_e->aux_str,d,doc_e->my_fmt_data);
if (doc_e->flags1 & DOCEF1_HAS_TERMINATOR) {
i=StrLen(doc_e->tag);
doc_e->tag[i++]='_';
doc_e->tag[i]=0;
}
doc_e->max_col=StrLen(doc_e->tag);
} else {
if (d)
doc_e->flags1|=DOCEF1_CHECKED_COLLAPSED;
else
doc_e->flags1&=~DOCEF1_CHECKED_COLLAPSED;
}
}
}
U0 DocDataGet(CDocEntry *doc_e)
{
I64 i,d;
U8 *ptr;
if (doc_e->type_u8==DOCT_DATA || doc_e->type_u8==DOCT_CHECK_BOX) {
if (doc_e->flags1 & DOCEF1_DATA_IS_PTR) {
if (!(ptr=doc_e->data)) return;
} else
ptr=&doc_e->data;
if (doc_e->type_u8==DOCT_DATA) {
i=StrLen(doc_e->tag);
if (doc_e->flags1 & DOCEF1_HAS_TERMINATOR)
doc_e->tag[--i]=0;
if (i>doc_e->len+doc_e->min_col)
doc_e->tag[doc_e->len+doc_e->min_col]=0;
if (doc_e->flags1&(DOCEF1_U8|DOCEF1_U16|DOCEF1_U32)) {
GetF(doc_e->tag,doc_e->aux_str,&d,doc_e->my_fmt_data);
if (doc_e->flags1 & DOCEF1_HAS_TERMINATOR)
doc_e->tag[i]='_';
} else {
GetF(doc_e->tag,doc_e->aux_str,ptr,doc_e->my_fmt_data);
if (doc_e->flags1 & DOCEF1_HAS_TERMINATOR)
doc_e->tag[i]='_';
return;
}
} else {
if (doc_e->flags1 & DOCEF1_CHECKED_COLLAPSED)
d=TRUE;
else
d=FALSE;
}
if (doc_e->flags1&DOCEF1_U8)
*ptr=d;
else if (doc_e->flags1&DOCEF1_U16)
*ptr(U16 *)=d;
else if (doc_e->flags1&DOCEF1_U32)
*ptr(U32 *)=d;
else
*ptr(I64 *)=d;
}
}
U0 DocRemSoftNewLines(CDoc *doc=NULL,CDocEntry *doc_e=NULL)
{
CDocEntry *doc_e2,*saved_ll=doc_e;
Bool unlock;
if (!doc) {
doc=DocCur;
if (!doc) return;
}
unlock=DocLock(doc);
if (!doc_e) doc_e=doc->root.next;
while (doc_e!=doc) {
doc_e2=doc_e->next;
if (doc_e->type_u8==DOCT_SOFT_NEW_LINE) {
if (doc->cur_entry==doc_e) {
doc->cur_entry=doc_e2;
doc->cur_data_col=doc->cur_entry->min_col;
}
DocEntryDel(doc,doc_e);
} else if (saved_ll && doc_e->type_u8==DOCT_NEW_LINE)
break;
doc_e=doc_e2;
}
if (unlock)
DocUnlock(doc);
}
#help_index "Doc/Cmd Line (Typically);Cmd Line (Typically)"
public I64 DocMax(I64 i=MAX_I32)
//Adjusts the size of the Doc buf.
//Normally, the cmd line deletes
//entries after a while.
{
I64 result;
CDoc *doc=DocCur;
if (doc) {
result=doc->max_entries;
doc->max_entries=i;
return result;
} else
return 0;
}
#help_index "Doc"
public CDoc *DocNew(CTask *task=NULL)
{
CDoc *doc;
if (!task) task=Fs;
doc=CAlloc(sizeof(CDoc),task);
StrCpy(doc->filename.name,sys_temp_filename);
doc->find_replace=CAlloc(sizeof(CEdFindText),task);
doc->find_replace->scan_fwd=TRUE;
doc->find_replace->match_case=TRUE;
doc->find_replace->pmt=TRUE;
doc->left_click_link=&EdLeftClickLink;
doc->dollar_buf_size=84;
doc->dollar_buf=MAlloc(doc->dollar_buf_size,task);
doc->max_entries=MAX_I32;
doc->ww_lines_back=32;
doc->win_task=task;
doc->mem_task=task;
DocRst(doc,FALSE);
doc->doc_signature=DOC_SIGNATURE_VAL;
return doc;
}
sys_clipboard_doc=DocNew;
#help_index "Doc/Task"
public U0 DocQueIns(CDoc *doc,CDoc *pred)
{
CDoc *succ;
Bool *old_preempt;
if (!doc) return;
old_preempt=Preempt(OFF);
succ=pred->next_doc;
doc->last_doc=pred;
doc->next_doc=succ;
pred->next_doc=doc;
succ->last_doc=doc;
doc->doc_in_que_signature=DOC_IN_QUE_SIGNATURE_VAL;
Preempt(old_preempt);
}
public U0 DocQueInsRev(CDoc *doc,CDoc *succ)
{
CDoc *pred;
Bool *old_preempt;
if (!doc) return;
old_preempt=Preempt(OFF);
pred=succ->last_doc;
doc->last_doc=pred;
doc->next_doc=succ;
pred->next_doc=doc;
succ->last_doc=doc;
doc->doc_in_que_signature=DOC_IN_QUE_SIGNATURE_VAL;
Preempt(old_preempt);
}
public U0 DocQueRem(CDoc *doc)
{
CDoc *succ,*pred;
Bool *old_preempt;
if (!doc) return;
old_preempt=Preempt(OFF);
doc->doc_in_que_signature=0;
succ=doc->next_doc;
pred=doc->last_doc;
pred->next_doc=succ;
succ->last_doc=pred;
Preempt(old_preempt);
}
public CDoc *DocCur(CTask *task=NULL)
{
CDoc *result;
if (!task) task=Fs;
result=task->last_doc;
if (result==(&task->next_doc)(U8 *)-offset(CDoc.next_doc) ||
result->flags&DOCF_AUX_DOC ||
result->doc_in_que_signature!=DOC_IN_QUE_SIGNATURE_VAL)
result=NULL;
return result;
}
public CDoc *DocAux(CTask *task=NULL)
{
CDoc *result;
if (!task) task=Fs;
result=task->next_doc;
if (result==(&task->next_doc)(U8 *)-offset(CDoc.next_doc) ||
!(result->flags&DOCF_AUX_DOC) ||
result->doc_in_que_signature!=DOC_IN_QUE_SIGNATURE_VAL)
result=NULL;
return result;
}
public CDoc *DocDblBufStart(CTask *task=NULL)
{ //See $LK-A,"::/TempleOS/Demo/Spy.CPP"$
CDoc *doc,*doc2;
Bool unlock_doc2,old_preempt=Preempt(OFF);
if (!task) task=Fs;
doc2=task->last_doc;
unlock_doc2=DocLock(doc2); //dont want change during winupdate, so lock DocCur$WW,0$
doc=DocNew(task);
doc->win_task =doc2->win_task;
doc->start_text_attr=doc2->start_text_attr;
doc->max_entries=doc2->max_entries;
MemCpy(doc->find_replace,doc2->find_replace,sizeof(CEdFindText));
doc->start_x =doc2->start_x;
doc->start_y =doc2->start_y;
MemCpy(&doc->filename,&doc2->filename,sizeof(CEdFileName));
doc->left_click_link =doc2->left_click_link;
doc->right_click_link=doc2->right_click_link;
doc->user_put_data=doc2->user_put_data;
doc->user_put_key =doc2->user_put_key;
doc->user_put_s =doc2->user_put_s;
doc->parent_doc =doc2->parent_doc;
doc->desc[0](I64)=doc2->desc[0](I64);
doc->user_data =doc2->user_data;
doc->flags|=doc2->flags&DOCG_DBL_BUF_FLAGS | DOCF_DONT_SHOW;
DocQueIns(doc,task->last_doc);
if (unlock_doc2)
DocUnlock(doc2);
Preempt(old_preempt);
return doc;
}
public Bool DocDblBufEnd(CTask *task=NULL)
{ //See $LK-A,"::/TempleOS/Demo/Spy.CPP"$
Bool okay=FALSE,old_preempt=Preempt(OFF);
CDoc *doc1,*doc2;
if (!task) task=Fs;
if (doc1=DocCur(task)) {
doc2=doc1->last_doc;
if (doc2!=(&task->next_doc)(U8 *)-offset(CDoc.next_doc) &&
!(doc2->flags&DOCF_AUX_DOC) &&
doc2->doc_in_que_signature==DOC_IN_QUE_SIGNATURE_VAL) {
doc2->flags|=DOCF_DONT_SHOW;
doc1->flags&=~DOCF_DONT_SHOW;
DocLock(doc2);
DocQueRem(doc2);
DocUnlock(doc2);
DocDel(doc2);
okay=TRUE;
}
}
Preempt(old_preempt);
return okay;
}
public Bool DocDblBufSwap(CTask *task=NULL)
{ //See $LK-A,"::/TempleOS/Demo/Spy.CPP"$
Bool okay=FALSE,old_preempt=Preempt(OFF);
CDoc *doc1,*doc2;
if (!task) task=Fs;
if (doc1=DocCur(task)) {
doc2=doc1->last_doc;
if (doc2!=(&task->next_doc)(U8 *)-offset(CDoc.next_doc) &&
!(doc2->flags&DOCF_AUX_DOC) &&
doc2->doc_in_que_signature==DOC_IN_QUE_SIGNATURE_VAL) {
doc2->flags|=DOCF_DONT_SHOW;
doc1->flags&=~DOCF_DONT_SHOW;
DocLock(doc2);
DocQueRem(doc2);
DocUnlock(doc2);
DocRst(doc2,TRUE);
MemCpy(doc2->find_replace,doc1->find_replace,sizeof(CEdFindText));
MemCpy(&doc2->filename,&doc1->filename,sizeof(CEdFileName));
doc2->start_text_attr=doc1->start_text_attr;
doc2->max_entries =doc1->max_entries;
doc2->flags =doc1->flags&DOCG_DBL_BUF_FLAGS | doc2->flags&~DOCG_DBL_BUF_FLAGS;
doc2->left_click_link =doc1->left_click_link;
doc2->right_click_link=doc1->right_click_link;
doc2->user_put_data=doc1->user_put_data;
doc2->user_put_key =doc1->user_put_key;
doc2->user_put_s =doc1->user_put_s;
doc2->desc[0](I64)=doc1->desc[0](I64);
doc2->user_data =doc1->user_data;
DocQueIns(doc2,task->last_doc);
okay=TRUE;
}
}
Preempt(old_preempt);
return okay;
}
#help_index "Doc"
+115
View File
@@ -0,0 +1,115 @@
#help_index "Doc"
I64 DocOptEntry(CDoc *,CDocEntry *doc_e)
{
U8 *st,*st2,**dst;
I64 i,result=0;
if (doc_e->flags1&DOCEF1_LINK) {
if (doc_e->flags1 & DOCEF1_AUX_STR &&
Bt(doc_tag_types,doc_e->type_u8) &&
!MemCmp(doc_e->aux_str,"FI:",3) &&
!StrCmp(doc_e->aux_str+3,doc_e->tag)) {
Free(doc_e->aux_str);
doc_e->aux_str=NULL;
doc_e->flags1&=~DOCEF1_AUX_STR;
result++;
}
if (doc_e->flags1 & DOCEF1_AUX_STR)
dst=&doc_e->aux_str;
else
dst=&doc_e->tag;
if (StrStr(*dst,".Z")) {
st=DocLinkFile(*dst);
if (FileFind(st)) {
if (IsDotZ(st))
st[StrLen(st)-2]=0;
i=StrLen(st);
if ((st2=StrStr(*dst,st)) && st2[i]=='.' && st2[i+1]=='Z') {
StrCpy(st2+i,st2+i+2);
result++;
}
}
Free(st);
}
/* !!! Dangerous, but handy !!!
if (doc_e->flags1 & DOCEF1_AUX_STR) {
if (st=StrStr(doc_e->aux_str,".Z")) {
StrCpy(st,st+2);
result++;
}
}
if (Bt(doc_tag_types,doc_e->type_u8)) {
if (st=StrStr(doc_e->tag,".Z")) {
StrCpy(st,st+2);
result++;
}
}
*/
}
if (doc_e->type_u8==DOCT_MACRO && doc_e->flags1&DOCEF1_AUX_STR &&
doc_e->flags1&DOCEF1_LEFT_MACRO && !StrCmp(doc_e->tag,doc_e->left_macro) ||
doc_e->flags1&DOCEF1_RIGHT_MACRO && !StrCmp(doc_e->tag,doc_e->right_macro)) {
doc_e->flags1&=~DOCEF1_AUX_STR;
Free(doc_e->aux_str);
doc_e->aux_str=NULL;
result++;
}
return result;
}
public I64 DocOptDoc(CDoc *doc)
{//Optimize Doc
Bool unlock=DocLock(doc);
I64 result=0;
CDocEntry *doc_e;
DocRecalc(doc);
doc_e=doc->root.next;
while (doc_e!=doc) {
if (result+=DocOptEntry(doc,doc_e))
result+=DocOptEntry(doc,doc_e);
doc_e=doc_e->next;
}
DocRecalc(doc);
if (unlock)
DocUnlock(doc);
return result;
}
public I64 DocOptFile(U8 *filename)
{//Optimize File
I64 result;
CDoc *doc=DocRead(filename);
if (result=DocOptDoc(doc)) {
"-%d:%s\n",result,doc->filename.name;
DocWrite(doc);
}
DocDel(doc);
return result;
}
I64 DocOptLst(CDirEntry *tempm1)
{
I64 result=0;
CDirEntry *tempm2;
while (tempm1) {
tempm2=tempm1->next;
if (tempm1->attr & _ATTR_DIR) {
if (tempm1->sub) {
"%S %s\n","ST_SCANNING_DIR",tempm1->full_name;
result+=DocOptLst(tempm1->sub);
}
} else
result+=DocOptFile(tempm1->full_name);
CDirEntryDel(tempm1);
tempm1=tempm2;
}
return result;
}
public I64 DocOpt(U8 *files_find_mask="*",U8 *fu_flags=NULL)
{//Optimize Files
I64 f=0;
GetFFlags(&f,Define("ST_FILE_UTIL_FLAGS"),"+r+T");
GetFFlags(&f,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
return DocOptLst(FilesFind(files_find_mask,f));
}
File diff suppressed because it is too large. Load diff
+879
View File
@@ -0,0 +1,879 @@
public I64 DocEntryRun(CDoc *doc,CDocEntry *doc_e,Bool exited)
{ //sometimes returns locked, sometimes unlocked
U8 ch=doc->cmd_U8,*st;
I64 result=-1;
DocLock(doc);
if (!exited) {
if (doc_e->flags1 & DOCEF1_ESC) {
Msg(MSG_KEY_DOWN,CH_ESC,0,1<<TASKCf_DONT_FILTER);
return 0;
} if (doc_e->flags1 & DOCEF1_QUIT) {
Msg(MSG_KEY_DOWN,CH_SHIFT_ESC,0,1<<TASKCf_DONT_FILTER);
return 0;
} else if (doc_e->flags1 & DOCEF1_CHECK_COLLAPSABLE)
doc_e->flags1^=DOCEF1_CHECKED_COLLAPSED;
}
doc->best_d=MAX_I64;
try {
if (ch==CH_SPACE) {
if (doc_e->flags1 & DOCEF1_LINK && doc->left_click_link)
result=(*doc->left_click_link)(doc,doc_e);
if (doc_e->flags1 & DOCEF1_LEFT_EXP) {
result=doc_e->left_exp;
Msg(MSG_CMD,result,0,1<<TASKCf_DONT_FILTER);
}
if (doc_e->flags1 & DOCEF1_LEFT_CB && doc_e->left_cb) {
DocUnlock(doc);
result=(*doc_e->left_cb)(doc,doc_e);
Msg(MSG_CMD,result,0,1<<TASKCf_DONT_FILTER);
}
if (doc_e->flags1 & DOCEF1_LEFT_MACRO) {
if (doc_e->flags1 & DOCEF1_POPUP) {
st=StrNew(doc_e->left_macro);
DocUnlock(doc);
PopUp(st,Fs);
Free(st);
} else {
if (doc_e->flags1 & DOCEF1_LEFT_AUTO)
AutoStr("%s",doc_e->left_macro);
else
Auto("%s",doc_e->left_macro);
}
}
} else if (ch=='\n') {
if (doc_e->flags1 & DOCEF1_LINK && doc->right_click_link)
result=(*doc->right_click_link)(doc,doc_e);
if (doc_e->flags1 & DOCEF1_RIGHT_EXP) {
result=doc_e->right_exp;
Msg(MSG_CMD,result,0,1<<TASKCf_DONT_FILTER);
}
if (doc_e->flags1 & DOCEF1_RIGHT_CB && doc_e->right_cb) {
DocUnlock(doc);
result=(*doc_e->right_cb)(doc,doc_e);
Msg(MSG_CMD,result,0,1<<TASKCf_DONT_FILTER);
}
if (doc_e->flags1 & DOCEF1_RIGHT_MACRO) {
if (doc_e->flags1 & DOCEF1_POPUP) {
st=StrNew(doc_e->right_macro);
DocUnlock(doc);
PopUp(st,Fs);
Free(st);
} else {
if (doc_e->flags1 & DOCEF1_RIGHT_AUTO)
AutoStr("%s",doc_e->right_macro);
else
Auto("%s",doc_e->right_macro);
}
}
}
}
catch
DocBottom(doc);
doc->cmd_U8=CH_SPACE;
return result;
}
U8 *EdOverStrikeCB(CDoc *,CDocEntry *doc_e,CTask *mem_task)
{
CDoc *doc=doc_e->user_data;
U8 *st=MAlloc(8,mem_task);
*st=doc->flags & DOCF_OVERSTRIKE ? 'O':'Ä';
st[1]=0;
return st;
}
U8 *EdFilterCB(CDoc *,CDocEntry *doc_e,CTask *mem_task)
{
CDoc *doc=doc_e->user_data;
U8 *st=MAlloc(8,mem_task);
*st=doc->find_replace->filter_lines ? 'F':'Ä';
st[1]=0;
return st;
}
U8 *EdDollarCB(CDoc *,CDocEntry *doc_e,CTask *mem_task)
{
CDoc *doc=doc_e->user_data;
U8 *st=MAlloc(8,mem_task);
*st=doc->flags & DOCF_IN_DOLLAR ? '$$':'Ä';
st[1]=0;
return st;
}
U8 *EdMoreCB(CDoc *,CDocEntry *doc_e,CTask *mem_task)
{
CDoc *doc=doc_e->user_data;
U8 *st=MAlloc(8,mem_task);
if (doc->flags&DOCF_MORE)
StrCpy(st,"MoreÄ");
else
StrCpy(st,"ÄÄÄÄÄ");
return st;
}
U8 *EdQuotesCB(CDoc *,CDocEntry *,CTask *mem_task)
{
CLex *lx=mem_task->last_lex;
U8 *st=MAlloc(8,mem_task);
*st=lx->flags & LF_IN_QUOTES ? '"':'Ä';
st[1]=0;
return st;
}
U8 *EdBracesCB(CDoc *,CDocEntry *,CTask *mem_task)
{
CLex *lx=mem_task->last_lex;
U8 *st=MAlloc(8,mem_task);
*st=lx->braces_cnt ? '}':'Ä';
st[1]=0;
return st;
}
U8 *EdSemicolonCB(CDoc *,CDocEntry *,CTask *mem_task)
{
CLex *lx=mem_task->last_lex;
U8 *st=MAlloc(8,mem_task);
*st=lx->statement_cnt ? ';':'Ä';
st[1]=0;
return st;
}
U8 *EdDollarTypeCB(CDoc *,CDocEntry *doc_e,CTask *mem_task)
{
CDoc *doc=doc_e->user_data;
U8 *src=DefineSub(doc->cur_entry->type_u8,"ST_DOC_CMDS"),
*st=CAlloc(8,mem_task);
if (doc->cur_entry==doc)
src="EOF";
else if (!src)
src="ERR";
SPrintF(st,"%-3ts",src);
return st;
}
public I64 DocGetKey(I64 *_sc=NULL)
{
I64 ch,sc;
Bool cont,old_preempt=IsPreempt;
do {
ch=GetKey(&sc,TRUE);
DocRecalc(DocCur);
cont=FALSE;
if (ch==CH_ESC || ch==CH_SHIFT_ESC) { //Check for exit filter mode
Preempt(OFF);
if (DocCur && DocCur->find_replace->filter_lines) {
EdUndoFilter(DocCur);
cont=TRUE;
}
Preempt(old_preempt);
}
} while (cont);
if (_sc) *_sc=sc;
return ch;
}
#help_index "Doc/Output"
public Bool View()
{
I64 ch;
do ch=DocGetKey;
while (ch!=CH_ESC && ch!=CH_SHIFT_ESC);
return ch==CH_ESC;
}
#help_index "Doc"
public Bool DocDo(CDoc *doc,I64 doc_flags=0)
{
CDoc *old_doc=DocCur,*old_aux_doc=DocAux,*aux;
CDocEntry *doc_e;
I64 old_attr=Fs->text_attr,
old_top =Fs->win_top, old_bottom=Fs->win_bottom,
old_left=Fs->win_left,old_right =Fs->win_right;
Bool result,unlock,old_preempt;
if (doc_flags&DOF_WIN_MAX)
WinMax;
unlock=DocLock(doc);
doc->win_task=Fs;
aux=DocNew;
aux->flags|=DOCF_AUX_DOC;
aux->settings_root.dft_text_attr=Fs->border_attr;
DocPutS(aux,"$$CM+TY+LX+NC,0,-1$$");
if (Bt(&Fs->display_flags,DISPLAYf_HAS_CLOSE_WIN))
DocPutS(aux,"$$TX+RX+BD,\"[X]\"$$");
DocPutS(aux,"$$BK,1$$$$TX+LX+BD,\"MENU\"$$$$BK,0$$");
doc_e=DocPutS(aux,"$$DA-T-P+BD+RD+CX+SCX+IV,256,\"%s...\",16$$");
doc_e->data=&doc->filename.name;
DocDataFmt(doc_e);
if (doc->flags & DOCF_ALLOW_UNDO) {
DocPutS(aux,"$$CM+BY+LX+NC,1,1$$");
doc_e=DocPutS(aux,"$$DA+BD+RD-T,32,\"Undo:%03d\"$$\n");
doc_e->data=&doc->undo_cnt;
DocDataFmt(doc_e);
}
DocPutS(aux,"$$CM+BY+RX+NC,-30,1$$");
doc_e=DocPutS(aux,"$$TX+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdMoreCB;
doc_e=DocPutS(aux,"$$TX+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdDollarTypeCB;
doc_e=DocPutS(aux,"$$TX+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdFilterCB;
doc_e=DocPutS(aux,"$$TX+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdOverStrikeCB;
doc_e=DocPutS(aux,"$$TX+BD+TC,\" \"$$");
doc_e->user_data=doc;
doc_e->tag_cb=&EdDollarCB;
doc_e=DocPutS(aux,"$$DA+BD+RD-T,32,\"Line:%04d \"$$");
doc_e->data=&doc->line;
DocDataFmt(doc_e);
doc_e=DocPutS(aux,"$$DA+BD+RD-T,32,\"Col:%04d\"$$\n");
doc_e->data=&doc->col;
DocDataFmt(doc_e);
DocRecalc(aux);
DocRecalc(doc);
if (!(doc_flags&DOF_DONT_HOME))
DocHome(doc);
old_preempt=Preempt(OFF);
DocQueRem(old_aux_doc);
DocQueInsRev(aux,Fs->next_doc);
if (doc!=old_doc)
doc->parent_doc=old_doc;
DocQueRem(old_doc);
DocQueIns(doc,Fs->last_doc);
Fs->text_attr=doc->settings_root.dft_text_attr;
LBts(&Fs->display_flags,DISPLAYf_SHOW);
WinZBufUpdate;
if (doc_flags&DOF_MIN_SIZE)
doc->flags|=DOCF_MIN_SIZE;
Preempt(old_preempt);
DocUnlock(doc);
WinMgrSync(2,TRUE);
if (doc->flags&DOCF_MIN_SIZE)
WinMgrSync(2,TRUE);
result=View;
Preempt(OFF);
DocLock(doc);
if (result) {
doc_e=doc->root.next;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_DATA || doc_e->type_u8==DOCT_CHECK_BOX)
DocDataGet(doc_e);
doc_e=doc_e->next;
}
}
if (unlock)
DocUnlock(doc);
DocQueRem(aux);
DocQueInsRev(old_aux_doc,Fs->next_doc);
DocDel(aux);
DocQueRem(doc);
DocQueIns(old_doc,Fs->last_doc);
Fs->text_attr=old_attr;
if (doc_flags&DOF_MIN_SIZE) {
SetWinHorz(old_left,old_right);
SetWinVert(old_top,old_bottom);
}
Preempt(old_preempt);
return result;
}
#help_index "Doc/Input"
public Bool DocFormDo(U8 *D,U8 *class_name,
I64 doc_flags=0,U8 *header=NULL,U8 *footer=NULL)
//Supply a class name that has fmtstr definitions
//and this routine will allow user input.
{
CMemberLst *ml;
CDocEntry *doc_e;
U8 *fmtstr;
CHashClass *tempc;
CDoc *doc;
Bool result=FALSE;
if (!(tempc=HashFind(class_name,Fs->hash_table,HTT_CLASS)))
return FALSE;
doc=DocNew;
StrCpy(doc->desc,"Form");
if (header) DocPutS(doc,header);
doc->flags|=DOCF_OVERSTRIKE|DOCF_FORM;
if (doc_flags&DOF_MIN_SIZE)
doc->flags|=DOCF_MIN_SIZE;
ml=tempc->member_lst;
while (ml) {
if (fmtstr=MemberMetaData("fmtstr",ml)) {
doc_e=DocPutS(doc,fmtstr);
doc_e->data=D+ml->offset;
doc_e->my_fmt_data=MemberMetaData("fmtdata",ml);
DocDataFmt(doc_e);
}
ml=ml->next;
}
if (footer) DocPutS(doc,footer);
if (doc->root.next!=doc) {
doc->flags&=~(DOCF_ATTR_BY_PRT | DOCF_ATTR_BY_FILENAME);
DocRecalc(doc);
if (DocDo(doc,doc_flags)) {
doc_e=doc->cur_entry;
if (doc_e!=doc) {
DocEntryRun(doc,doc_e,TRUE);
DocUnlock(doc);
}
result=TRUE;
}
}
DocDel(doc);
return result;
}
U0 DocMenuDoEndTaskCB()
{
WinToTop;
throw(EXCEPT_LOCAL);
}
public I64 DocMenuDo(CDoc *m,I64 doc_flags=0)
{ //returns m unlocked
U8 *old_end_cb=Fs->task_end_cb;
Bool old_break_shift_esc=LBts(&Fs->task_flags,TASKf_BREAK_TO_SHIFT_ESC);
CDocEntry *doc_e;
I64 old_doc_flags=m->flags,result=DOCM_CANCEL;
Fs->task_end_cb=&DocMenuDoEndTaskCB;
try {
if (m) {
StrCpy(m->desc,"Menu");
m->flags&=~(DOCF_ATTR_BY_PRT | DOCF_ATTR_BY_FILENAME);
if (DocDo(m,doc_flags)) {
doc_e=m->cur_entry;
if (doc_e!=m) {
result=DocEntryRun(m,doc_e,TRUE);
DocUnlock(m);
}
}
}
} catch {
if (Fs->except_argc==1 && Fs->except_argv[0]==EXCEPT_LOCAL) {
if (!(doc_flags & DOF_INTERCEPT_TASK_END))
Exit;
Fs->catch_except=TRUE;
}
}
m->flags|=old_doc_flags&(DOCF_ATTR_BY_PRT | DOCF_ATTR_BY_FILENAME);
LBEqu(&Fs->task_flags,TASKf_BREAK_TO_SHIFT_ESC,old_break_shift_esc);
Fs->task_end_cb=old_end_cb;
return result;
}
#help_index "Doc"
public I64 PopUp(U8 *msg,CTask *parent=NULL,CTask **_pu_task=NULL)
{
I64 result=0;
Bool old_preempt=Preempt(OFF);
CTaskCmd *tempc;
CTask *task=Spawn(&ServantUserCmdLine,NULL,"System",parent);
if (!parent) {
TaskRqstQue(task,parent,msg,1<<TASKCf_EXIT_ON_COMPLETE);
if (_pu_task) *_pu_task=task;
Preempt(old_preempt);
return 0;
} else {
Fs->popup_task=task;
tempc=TaskRqstQue(task,parent,msg,
1<<TASKCf_WAKE_MASTER | 1<<TASKCf_FOCUS_MASTER);
if (_pu_task) *_pu_task=task;
GetRqstResult(tempc,&result);
Fs->popup_task=NULL;
Kill(task);
if (_pu_task) *_pu_task=NULL;
Preempt(old_preempt);
return result;
}
}
#help_index "Doc/Output"
public CTask *PopUpViewDoc(CDoc *doc,I64 doc_flags=0)
{
U8 *buf=MSPrintF("if (!IsSysDeterministic) Preempt(ON);DocDo(0x%X,0x%X);",doc,doc_flags);
CTask *task=Spawn(&ServantUserCmdLine,NULL,"View",Fs);
TaskRqstQue(task,NULL,buf,1<<TASKCf_EXIT_ON_COMPLETE);
Free(buf);
return task;
}
U0 PopUpViewStrTaskEndCB()
{
DocDel(NamedFramePtr("ViewStrFrame"));
Exit;
}
public CTask *PopUpViewStr(U8 *msg)
{
CTask *task;
CDoc *doc=DocNew;
DocPrintF(doc,msg);
task=PopUpViewDoc(doc);
NamedFramePtrAdd("ViewStrFrame",doc,task);
task->task_end_cb=&PopUpViewStrTaskEndCB;
return task;
}
#help_index "Doc/Input"
public I64 PopUpMenu(CDoc *doc,I64 doc_flags=0)
{
doc->flags|=DOCF_MIN_SIZE | DOCF_FORM;
return ServantUser("DocMenuDo(0x%X,0x%X);",doc,doc_flags);
}
public Bool PopUpForm(U8 *D,U8 *class_name,I64 doc_flags=DOF_MIN_SIZE,
U8 *header=NULL,U8 *footer=NULL)
{
return ServantUser("DocFormDo(0x%X,0x%X,0x%X,0x%X,0x%X);",D,class_name,
doc_flags,header,footer);
}
#help_index "Doc/Input;File/FileNames"
public U8 *PopUpPickFile(U8 *dir=NULL)
{
U8 *result,*st,*st2;
if (dir)
st=MSPrintF("Cd(\"%Q\");FileMgr(FM_PICK_FILE,Fs->parent_task);",dir);
else {
st2=CurDir;
st=MSPrintF("Cd(\"%Q\");FileMgr(FM_PICK_FILE,Fs->parent_task);",st2);
Free(st2);
}
result=PopUp(st,Fs);
Free(st);
return result;
}
public U8 *PopUpPickDir(U8 *dir=NULL)
{
U8 *result,*st,*st2;
if (dir)
st=MSPrintF("Cd(\"%Q\");FileMgr(FM_PICK_DIR,Fs->parent_task);",dir);
else {
st2=CurDir;
st=MSPrintF("Cd(\"%Q\");FileMgr(FM_PICK_DIR,Fs->parent_task);",st2);
Free(st2);
}
result=PopUp(st,Fs);
Free(st);
return result;
}
public U8 *FileNameForm(U8 *dft=NULL,I64 doc_flags=0,CTask *mem_task=NULL)
{
CEdFileName fn;
if (dft)
StrCpy(fn.name,dft);
else
*fn.name=0;
if (DocFormDo(fn.name,"CEdFileName",doc_flags))
return StrNew(fn.name,mem_task);
else
return NULL;
}
public U8 *PopUpFileName(U8 *dft=NULL,I64 doc_flags=0)
{
U8 *st=MSPrintF("FileNameForm(\"%Q\",0x%X,Fs->parent_task);",dft,doc_flags|DOF_MIN_SIZE),
*result=PopUp(st,Fs);
Free(st);
return result;
}
#help_index "Doc"
public Bool PopUpCd()
{
Bool result;
U8 *st=PopUpPickDir;
if (st) {
result=Cd(st);
Free(st);
} else
result=FALSE;
return result;
}
#help_index "Doc/Input"
public U8 *PopUpPickLstEntry(U8 *lst)
{
I64 i=0;
CDoc *doc=DocNew;
while (*lst) {
if (*lst=='@') { //Check for '@' alias lst entry
i--;
lst++;
}
DocPrintF(doc,"$$MU,\"%s\",0x%08X$$\n",
lst,i++);
lst+=StrLen(lst)+1;
}
DocPutS(doc,"\n$$MU,\"CANCEL\",DOCM_CANCEL$$\n");
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
public U8 *PopUpPickDefineSub(U8 *st)
{
return PopUpPickLstEntry(Define(st));
}
public I64 PopUp1(U8 *b1,I64 n1,U8 *header=NULL,U8 *footer=NULL)
{
I64 i,l1=StrLen(b1);
CDoc *doc=DocNew;
if (header) DocPutS(doc,header);
DocPrintF(doc,"$$CM+CX,%d,4$$$$BT,\"%s\",%d$$\n",-l1/2,b1,n1);
if (footer) DocPutS(doc,footer);
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
public I64 PopUp2(U8 *b1,I64 n1,U8 *b2,I64 n2,U8 *header=NULL,U8 *footer=NULL)
{
I64 i,l1=StrLen(b1),l2=StrLen(b2),y;
CDoc *doc=DocNew;
if (header) {
DocPutS(doc,header);
y=4;
} else {
DocPrintF(doc,"%*s\n",l1+l2+10,"");
y=3;
}
DocPrintF(doc,"$$CM+CX,%d,%d$$$$BT,\"%s\",%d$$",-(l1+l2+3)>>1,y,b1,n1);
DocPrintF(doc,"$$CM+CX,%d,0$$$$BT,\"%s\",%d$$\n" ,-(l1+l2+3)>>1+l1+6,b2,n2);
if (footer) DocPutS(doc,footer);
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
public Bool PopUpOk(U8 *header=NULL,U8 *footer=NULL)
{
return PopUp1("OKAY",1,header,footer)>0;
}
public Bool PopUpNoYes(U8 *header=NULL,U8 *footer=NULL)
{
return $WW,0$PopUp2("YES",1,"NO",0,header,footer)>0;
}
public Bool PopUpCancelOk(U8 *header=NULL,U8 *footer=NULL)
{
return PopUp2("OKAY",1,"CANCEL",0,header,footer)>0;
}
#define RSAC_REPLACE 0
#define RSAC_SKIP 1
#define RSAC_ALL 2
public I64 PopUpReplaceSkipAllCancel(U8 *header=NULL,U8 *footer=NULL)
{
I64 i;
CDoc *doc=DocNew;
if (header) DocPutS(doc,header);
DocPutS(doc,"$$CM+LX,1,4$$$$BT,\"REPLACE\",RSAC_REPLACE$$"
"$$CM+LX,17,0$$$$BT,\"SKIP\",RSAC_SKIP$$"
"$$CM+LX,1,3$$$$BT,\"ALL\",RSAC_ALL$$"
"$$CM+LX,17,0$$$$BT,\"CANCEL\",DOCM_CANCEL$$\n");
if (footer) DocPutS(doc,footer);
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
U8 *DoPopUpMGetS(U8 *header,CTask *mem_task)
{
U8 *result,*st;
if (header)
"" header;
st=MGetS(GETSF_WITH_NEW_LINE);
result=StrNew(st,mem_task);
Free(st);
return result;
}
public U8 *PopUpMGetS(U8 *header=NULL)
{
U8 *st=MSPrintF("DoPopUpMGetS(0x%X,0x%X);",header,Fs),
*result=PopUp(st,Fs);
Free(st);
return result;
}
public I64 PopUpRangeI64(I64 lo,I64 hi,I64 step=1,U8 *header=NULL,U8 *footer=NULL)
{
I64 i;
CDoc *doc=DocNew;
if (header)
DocPutS(doc,header);
for (i=lo;i<=hi;i+=step)
DocPrintF(doc,"$$MU,\"%d\",%d$$\n",i,i);
if (footer)
DocPutS(doc,footer);
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
public F64 PopUpRangeF64(F64 lo,F64 hi,F64 step,
U8 *fmt="%9.4f",U8 *header=NULL,U8 *footer=NULL)
{
F64 d;
I64 i;
U8 buf[136];
CDoc *doc=DocNew;
if (header)
DocPutS(doc,header);
for (d=lo;d<=hi;d+=step) {
SPrintF(buf,fmt,d);
DocPrintF(doc,"$$MU,\"%s\",0x%X$$\n",buf,d);
}
if (footer)
DocPutS(doc,footer);
i=PopUpMenu(doc);
DocDel(doc);
return i(F64);
}
public F64 PopUpRangeF64Exp(F64 lo,F64 hi,F64 factor,
U8 *fmt="%9.4f",U8 *header=NULL,U8 *footer=NULL)
{
F64 d;
I64 i;
U8 buf[136];
CDoc *doc=DocNew;
if (header)
DocPutS(doc,header);
for (d=lo;d<=hi;d*=factor) {
SPrintF(buf,fmt,d);
DocPrintF(doc,"$$MU,\"%s\",0x%X$$\n",buf,d);
}
if (footer)
DocPutS(doc,footer);
i=PopUpMenu(doc);
DocDel(doc);
return i(F64);
}
public F64 PopUpRangeF64Log(F64 lo,F64 hi,I64 steps,
U8 *fmt="%9.4f",U8 *header=NULL,U8 *footer=NULL)
{
return PopUpRangeF64Exp(lo,hi,Exp(Ln(hi/lo)/(steps-1)),fmt,header,footer);
}
#help_index "Task/Rqsts"
public I64 AdamFile(U8 *filename,Bool warn_ext=TRUE)
{
Bool okay=TRUE;
U8 *name=FileNameAbs(filename),
*name2=DftExt(name,"CPP.Z");
I64 result=0;
if (warn_ext &&
!FilesFindMatch(FILENAME_MASK_JIT,name2) &&
!PopUpCancelOk(ST_WARN_ST "Not .CPP File\n\n"))
okay=FALSE;
if (okay)
result=Adam("#include \"%s\";",name2);
Free(name2);
Free(name);
return result;
}
#help_index "Doc"
public I64 PopUpFile(U8 *filename,Bool warn_ext=TRUE,CTask *parent=NULL,CTask **_pu_task=NULL)
{
Bool okay=TRUE;
U8 *st,*name=FileNameAbs(filename),
*name2=DftExt(name,"CPP.Z");
I64 result=0;
if (warn_ext &&
!FilesFindMatch(FILENAME_MASK_JIT,name2) &&
!PopUpCancelOk(ST_WARN_ST "Not .CPP File\n\n"))
okay=FALSE;
if (okay) {
st=MSPrintF("\"$$$$WW+H,1$$$$\";Auto(\"ExeFile(\\\"%s\\\");\\n\");UserTaskCont;",name2);
result=PopUp(st,parent,_pu_task);
Free(st);
}
Free(name2);
Free(name);
return result;
}
#help_index "Graphics/Input"
public I64 PopUpColor(U8 *header=NULL,Bool allow_transparent=TRUE,Bool allow_dft=TRUE)
{
I64 i;
CDoc *doc=DocNew;
if (header)
DocPutS(doc,header);
if (allow_transparent)
DocPutS(doc,"$$BG,WHITE$$$$MU,\"TRANSPARENT\",COLOR_TRANSPARENT$$$$BG$$\n");
DocPutS(doc,"$$FM,BLACK$$");
for (i=0;i<16;i++)
DocPrintF(doc,"$$BG,%d$$$$MU,\"__%-8Z__\",%d$$$$BG$$\n",i,i,"ST_COLORS",i);
if (allow_dft)
DocPutS(doc,"$$BG,WHITE$$$$MU,\"DEFAULT\",DOC_DFT$$$$BG$$");
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
public I64 PopUpLightingColor(U8 *header=NULL)
{
I64 i;
CDoc *doc=DocNew;
if (header)
DocPutS(doc,header);
DocPutS(doc,"\n$$FM,BLACK$$Single-Sided Full-Range Double-Sided Full-Range\n");
for (i=0;i<8;i++) {
DocPrintF(doc,"$$BG,%d$$$$MU,\"__%-19Z__\",%d$$$$BG$$ ",i,i,"ST_COLORS",i);
DocPrintF(doc,"$$BG,%d$$$$MU,\"__%-19Z__\",%d$$$$BG$$\n",i,i,"ST_COLORS",ROPF_TWO_SIDED+i);
}
DocPutS(doc,"\nSingle-Sided Half-Range Double-Sided Half-Range\n");
for (i=0;i<16;i++) {
DocPrintF(doc,"$$BG,%d$$$$MU,\"__%-19Z__\",%d$$$$BG$$ ",i,i,"ST_COLORS",ROPF_HALF_RANGE_COLOR+i);
DocPrintF(doc,"$$BG,%d$$$$MU,\"__%-19Z__\",%d$$$$BG$$\n",i,i,"ST_COLORS",ROPF_TWO_SIDED+ROPF_HALF_RANGE_COLOR+i);
}
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
class CTransformForm
{
F64 x_scale fmtstr "$$DA-T,32,\"X Scale :%12.6f\"$$\n";
F64 y_scale fmtstr "$$DA-T,32,\"Y Scale :%12.6f\"$$\n";
F64 z_scale fmtstr "$$DA-T,32,\"Z Scale :%12.6f\"$$\n";
F64 é_z fmtstr "\nAngles are in degrees\n$$DA-T,32,\"Z-Axis :%12.6f\"$$\n";
F64 é_y fmtstr "$$DA-T,32,\"Y-Axis :%12.6f\"$$\n";
F64 é_x fmtstr "$$DA-T,32,\"X-Axis :%12.6f\"$$\n";
F64 x_offset fmtstr "\n$$DA-T,32,\"X Offset:%12.6f\"$$\n";
F64 y_offset fmtstr "$$DA-T,32,\"Y Offset:%12.6f\"$$\n";
F64 z_offset fmtstr "$$DA-T,32,\"Z Offset:%12.6f\"$$\n";
};
Bool PopUpTransform(I64 *r)
{
CTransformForm *tf=MAlloc(sizeof(CTransformForm));
tf->x_scale=1.0;
tf->y_scale=1.0;
tf->z_scale=1.0;
tf->é_x=0.0;
tf->é_y=0.0;
tf->é_z=0.0;
tf->x_offset=0.0;
tf->y_offset=0.0;
tf->z_offset=0.0;
if (PopUpForm(tf,"CTransformForm")) {
MemSet(r,0,16*sizeof(I64));
r[0] =tf->x_scale*gr_scale;
r[5] =tf->y_scale*gr_scale;
r[10]=tf->z_scale*gr_scale;
r[15]=gr_scale;
GrRotZEqu(r,tf->é_z*ã/180.0);
GrRotYEqu(r,tf->é_y*ã/180.0);
GrRotXEqu(r,tf->é_x*ã/180.0);
r[3] =tf->x_offset*gr_scale;
r[7] =tf->y_offset*gr_scale;
r[11]=tf->z_offset*gr_scale;
return TRUE;
} else
return FALSE;
}
#define PU_SPACING 10
U0 DrawIt(CTask *task,CDC *dc)
{
I64 i,j,i1,j1;
CDoc *doc=DocCur(task);
for (j=0;j<17;j++)
for (i=0;i<17;i++) {
if (j<16)
j1=j;
else
j1=COLOR_TRANSPARENT;
if (i<16)
i1=i;
else
i1=COLOR_TRANSPARENT;
dc->color=j1+i1<<16+ROPF_DITHER;
GrRect(dc,i*PU_SPACING,j*PU_SPACING+NamedFramePtr("DitherDoFrame",task),PU_SPACING,PU_SPACING);
}
i=(17*PU_SPACING+FONT_WIDTH-1)/FONT_WIDTH;
if (doc->max_x>i) i=doc->max_x;
SetWinHorz(task->win_left,task->win_left+i,task);
SetWinVert(task->win_top,task->win_top+doc->max_y+(17*PU_SPACING+FONT_WIDTH-1)/FONT_WIDTH,task);
}
I64 DitherColorDo(U8 *header=NULL)
{
I64 msg_code,p1,p2,result=-1,i,j;
DocClear;
"" header;
DocRecalc(DocCur);
NamedFramePtrAdd("DitherDoFrame",(DocCur->max_y+1)*FONT_HEIGHT);
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
Fs->draw_it=&DrawIt;
do {
msg_code=GetMsg(&p1,&p2,1<<MSG_IP_L_DOWN|1<<MSG_KEY_DOWN);
if (msg_code==MSG_IP_L_DOWN) {
msg_code=GetMsg(&p1,&p2,1<<MSG_IP_L_UP);
i=p1/PU_SPACING;
j=(p2-NamedFramePtr("DitherDoFrame"))/PU_SPACING;
if (p1>=0 && p2>=0 && 0<=j<17 && 0<=i<17) {
if (j==16) j=COLOR_TRANSPARENT;
if (i==16) i=COLOR_TRANSPARENT;
result=j+i<<16+ROPF_DITHER;
goto dcd_done;
}
}
} while (!(msg_code==MSG_KEY_DOWN && (p1==CH_ESC || p1==CH_SHIFT_ESC)));
do GetMsg(&p1,&p2,1<<MSG_KEY_UP);
while (!p1);
dcd_done:
SettingsPop;
NamedFramePtrDel("DitherDoFrame");
return result;
}
public I64 PopUpDitherColor(U8 *header=NULL)
{
U8 buf[136];
SPrintF(buf,"DitherColorDo(0x%X);",header);
return PopUp(buf,Fs);
}
U0 PopUpSnap(CSnap *g)
{
F64 d;
I64 i=PopUpRangeI64(1,16,1,"Snap\n");
if (i>=1) {
d=PopUpRangeF64Exp(1.0/16.0,4.0,2.0,"%5.3f","Pointer Speed Scaler\n");
if (d>0)
SetSnap(g,i,d);
}
}
#help_index "Doc"
File diff suppressed because it is too large. Load diff
+175
View File
@@ -0,0 +1,175 @@
#help_index "Doc"
public Bool DocTreeFind(CDoc *doc,U8 *path,
CDocEntry **_tree_entry=NULL,
CDocEntry **_start_indent=NULL, CDocEntry **_end_indent=NULL)
{
I64 i=0,k=0;
U8 *st1=StrNew(path),*st2=MAlloc(StrLen(path)+1);
Bool result=FALSE,unlock_doc=DocLock(doc);
CDocEntry *doc_e=doc->root.next;
if (_tree_entry) *_tree_entry=doc;
if (_start_indent) *_start_indent=doc;
if (_end_indent) *_end_indent=doc;
while (*st1 && doc_e!=doc) {
StrFirstRem(st1,"/",st2);
if (*st2) {
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_INDENT)
i+=doc_e->attr;
else if (i==k && doc_e->flags1&DOCEF1_TREE && !StrCmp(doc_e->tag+3,st2)) {
if (*st1)
break;
else {
if (_tree_entry) *_tree_entry=doc_e;
i=0;
while (doc_e!=doc && doc_e->type_u8!=DOCT_INDENT)
doc_e=doc_e->next;
if (doc_e!=doc) {
i=doc_e->attr;
if (_start_indent) *_start_indent=doc_e;
doc_e=doc_e->next;
while (doc_e!=doc && i>0) {
if (doc_e->type_u8==DOCT_INDENT) {
i+=doc_e->attr;
if (i<=0) {
if (_end_indent) *_end_indent=doc_e;
result=TRUE;
break;
}
}
doc_e=doc_e->next;
}
}
goto ft_done;
}
}
doc_e=doc_e->next;
}
k+=2;
}
}
ft_done:
if (unlock_doc)
DocUnlock(doc);
Free(st1);
Free(st2);
return result;
}
public Bool DocTreeMake(CDoc *doc,U8 *path)
{
I64 i=0,j=MIN_I64,k=0;
U8 *st1=StrNew(path),
*st2=MAlloc(StrLen(path)+1),
*st3=StrNew(path);
Bool result=TRUE,unlock_doc=DocLock(doc);
CDocEntry *doc_e=doc->root.next;
doc->cur_entry=doc;
doc->cur_data_col=0;
while (*st1 && doc_e!=doc) {
StrFirstRem(st1,"/",st2);
if (*st2) {
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_INDENT) {
i+=doc_e->attr;
if (i==j) {
doc->cur_entry=doc_e;
doc->cur_data_col=0;
goto mt_done;
}
} else if (i==k && doc_e->flags1&DOCEF1_TREE && !StrCmp(doc_e->tag+3,st2)) {
Free(st3);
st3=StrNew(st1);
j=i;
if (!*st1)
result=FALSE;
else
break;
}
doc_e=doc_e->next;
}
k+=2;
}
}
mt_done:
if (result) {
while (*st3) {
StrFirstRem(st3,"/",st2);
if (*st2) {
DocPrintF(doc,"$$TR+C,\"%s\"$$\n$$ID,2$$",st2);
doc->cur_entry=DocPutS(doc,"$$ID,-2$$");
doc->cur_data_col=0;
}
}
}
if (unlock_doc)
DocUnlock(doc);
Free(st1);
Free(st2);
Free(st3);
return result;
}
#help_index "Doc/Compiler;Compiler"
public I64 ExeDoc(CDoc *doc,Bool just_load=FALSE)
{
I64 result;
Bool okay=TRUE,unlock_doc=DocLock(doc);
CLex *lx;
lx=LexNew("",LF_DONT_FREE_BUF,FileNameAbs(sys_temp_filename));
if (just_load)
lx->flags|=LF_JUST_LOAD;
if (Fs->last_lex!=&Fs->next_lex)
lx->opts=Fs->last_lex->opts;
QueIns(lx,Fs->last_lex);
LexIncludeDoc(lx,NULL,doc);
try {
Lex(lx);
result=ExeCmdLine(lx);
} catch {
if (Fs->except_argc>0) {
if (Fs->except_argv[0]==EXCEPT_COMPILER ||
Fs->except_argv[0]==EXCEPT_BREAK) {
Fs->catch_except=TRUE;
okay=FALSE;
result=0;
}
}
}
QueRem(lx);
if (okay)
LexDel(lx); //TODO: can crash
if (unlock_doc)
DocUnlock(doc);
return result;
}
public I64 DocTreeBranchExe(CDoc *doc,U8 *path)
{
CDoc *doc2;
Bool unlock_doc=DocLock(doc);
CDocEntry *tree_branch,*start_indent,*end_indent;
I64 result=0;
if (DocTreeFind(doc,path,&tree_branch,&start_indent,&end_indent)) {
doc2=DocCopy(doc,tree_branch,end_indent);
result=ExeDoc(doc2);
DocDel(doc2);
}
if (unlock_doc)
DocUnlock(doc);
return result;
}
public I64 ExeTreeBranch(U8 *registry_file,U8 *path)
{
I64 result;
CDoc *doc=DocRead(registry_file);
result=DocTreeBranchExe(doc,path);
DocDel(doc);
return result;
}
#help_index "Doc"