TempleOSTS_130707.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:45:45 +02:00
1 parent 17b71f1a2d
commit 1343005a29
617 files changed
+14399 -25130

No files matched your search

+83
View File
@@ -0,0 +1,83 @@
#help_index "Compiler"
DefineLstLoad("ST_BIN_FILE_TYPES",
"END\0 \0"
"REL_EXPORT\0"
"LIT_EXPORT\0"
"REL_U8\0"
"LIT_U8\0"
"REL_U16\0"
"LIT_U16\0"
"REL_U32\0"
"LIT_U32\0"
"REL_U64\0"
"LIT_U64\0"
" \0 \0 \0 \0"
"MAIN\0"
"MODULE_ALIGN\0MODULE_ORG\0"
" \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0"
"ABS_ADDR\0"
"HEAP_GLBL\0"
);
public Bool BinRep(U8 *filename)
{//This reports imports, exports, etc
//for a .BI* file.
//See $LK,"Loader Patch Table Generation","FF:::/TempleOS/Compiler/CmpMain.CPP,EIE_MODULE_ALIGNMENT"$ and $LK,"Load","MN:Load"$().
U8 *fbuf,*ptr,etype,*sptr,*absname;
I64 i,j,size;
CBinFile *bfh,*bfh2;
CHashExport *saved_hash_ptr=NULL;
fbuf=DftExt(filename,"BIN.Z");
if (!(bfh2=FileRead(fbuf,&size))) {
Free(fbuf);
return FALSE;
}
bfh=bfh2;
if (ArcXSum(bfh,bfh->file_size)!=TEMPLEOS_XSUM) {
"Bad XSum\n\n";
return FALSE;
}
absname=FileNameAbs(fbuf);
Free(fbuf);
fbuf=StrNew(absname);
FileExtRem(fbuf);
if (fbuf[1]==':' && StrLen(fbuf)>2)
"Module Name:%s\n",fbuf+2;
else
"No Module Name\n";
Free(fbuf);
ptr=bfh(U8 *)+bfh->loader_patch_table_offset;
while (etype=*ptr++) {
i=*ptr(U32 *)++;
sptr=ptr;
ptr+=StrLen(sptr)+1;
"%16Z:$$FG,GREEN$$%s$$FG$$:%X ",etype,"ST_BIN_FILE_TYPES",sptr,i;
switch (etype) {
case EIE_REL_U8...EIE_LIT_U64:
if (*sptr)
saved_hash_ptr=HashFind(sptr,Fs->hash_table,HTG_ALL);
if (!saved_hash_ptr)
"%S%s\n","ST_UNRESOLVED_REFERENCE",sptr;
break;
case EIE_ABS_ADDR:
NewLine;
for (j=0;j<i;j++)
"%X ",*ptr(U32 *)++;
break;
case EIE_HEAP_GLBL:
"Size:%X ",*ptr(I64 *)++;
for (j=0;j<i;j++)
"%X ",*ptr(U32 *)++;
break;
}
NewLine;
}
Free(absname);
Free(bfh);
return TRUE;
}
#help_index ""
+303
View File
@@ -0,0 +1,303 @@
#help_index "Utils;Cmd Line (Typically)"
#define DS_USE_FILE1 0
#define DS_USE_FILE2 1
#define DS_REMAINDER_1 2
#define DS_REMAINDER_2 3
#define DS_ABORT_FILE 4
I64 PopUpDiffOptions()
{
I64 i;
CDoc *doc=DocNew;
DocPutS(doc,"$$CM+LX,2,4$$$$FG$$$$BT,\"USE FILE1\",DS_USE_FILE1$$"
"$$CM+LX,24,0$$$$FG,CYAN$$$$BT,\"USE FILE2\",DS_USE_FILE2$$"
"$$CM+LX,2,4$$$$FG$$$$BT,\"REMAINDER ALL FILE1\",DS_REMAINDER_1$$"
"$$CM+LX,24,0$$$$FG,CYAN$$$$BT,\"REMAINDER ALL FILE2\",DS_REMAINDER_2$$"
"$$CM+LX,2,4$$$$FG$$$$BT,\"ABORT FILE\",DS_ABORT_FILE$$"
"$$CM+LX,24,0$$$$FG$$$$BT,\"ABORT ALL FILES\",DOCM_CANCEL$$\n");
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
I64 DiffEntriesCompare(CDocEntry *doc_e1,CDocEntry *doc_e2)
{
return StrCmp(doc_e1->tag,doc_e2->tag);
}
#define DF_MODIFIED 1
#define DF_DONT_MODIFIED 2
#define DF_REMAINDER_ALL_FILE1 4
#define DF_REMAINDER_ALL_FILE2 8
#define DF_ABORT_FILE 16
#define DF_ABORT_ALL_FILES 32
#define DF_NO_MORE_PMTS_THIS_FILE 64
U0 DiffSelect(CDoc *doc,I64 *_df_flags,I64 j1_lo,I64 j1_hi,
I64 j2_lo,I64 j2_hi,I64 cnt1,I64 cnt2,CDocEntry **doc_us1,CDocEntry **doc_us2)
{
CDocEntry *doc_e,*doc_e1,*doc_e2;
Bool use_file1;
I64 i,old_flags;
CDoc *cur_l;
if (!(*_df_flags & (DF_ABORT_FILE|DF_ABORT_ALL_FILES))) {
"$$FG,RED$$";
if (0<=j1_lo<cnt1)
"%d,",doc_us1[j1_lo]->y+1;
else if (0<=j1_hi-1<cnt1)
"%d,",doc_us1[j1_hi-1]->y+1;
else
"***,";
if (0<=j2_lo<cnt2)
"%d",doc_us2[j2_lo]->y+1;
else if (0<=j2_hi-1<cnt2)
"%d",doc_us2[j2_hi-1]->y+1;
else
"***";
"---------------------$$FG$$\n";
if (j1_lo<=0)
i=0;
else
i=j1_lo-1;
while (i<j1_hi) {
if (cur_l=DocPut) {
old_flags=cur_l->flags&DOCF_PLAIN_TEXT;
cur_l->flags|=DOCF_PLAIN_TEXT;
}
"" doc_us1[i++]->tag;
if (cur_l)
cur_l->flags= cur_l->flags&~DOCF_PLAIN_TEXT |old_flags;
NewLine;
}
"$$FG,CYAN$$";
if (j2_lo<=0)
i=0;
else
i=j2_lo-1;
while (i<j2_hi) {
if (cur_l=DocPut) {
old_flags=cur_l->flags&DOCF_PLAIN_TEXT;
cur_l->flags|=DOCF_PLAIN_TEXT;
}
"" doc_us2[i++]->tag;
if (cur_l)
cur_l->flags= cur_l->flags&~DOCF_PLAIN_TEXT |old_flags;
NewLine;
}
"$$FG$$";
use_file1=TRUE;
if (!(*_df_flags & DF_NO_MORE_PMTS_THIS_FILE)) {
switch (PopUpDiffOptions) {
case DS_USE_FILE1:
break;
case DS_USE_FILE2:
use_file1=FALSE;
break;
case DS_REMAINDER_1:
*_df_flags=*_df_flags&~DF_REMAINDER_ALL_FILE2|DF_REMAINDER_ALL_FILE1|DF_NO_MORE_PMTS_THIS_FILE;
break;
case DS_REMAINDER_2:
*_df_flags=*_df_flags&~DF_REMAINDER_ALL_FILE1|DF_REMAINDER_ALL_FILE2|DF_NO_MORE_PMTS_THIS_FILE;
break;
case DS_ABORT_FILE:
*_df_flags|=DF_DONT_MODIFIED|DF_ABORT_FILE|DF_NO_MORE_PMTS_THIS_FILE;
break;
default:
*_df_flags|=DF_DONT_MODIFIED|DF_ABORT_ALL_FILES|DF_NO_MORE_PMTS_THIS_FILE;
}
}
if (*_df_flags & DF_REMAINDER_ALL_FILE2 &&
!(*_df_flags & (DF_DONT_MODIFIED|DF_REMAINDER_ALL_FILE1)))
use_file1=FALSE;
if (!use_file1) {
*_df_flags|=DF_MODIFIED;
doc_e1=doc_us1[j1_lo]->last;
if (j1_lo<j1_hi) {
doc_e=doc_us1[j1_lo];
while (doc_e!=doc_us1[j1_hi]) {
doc_e2=doc_e->next;
DocEntryDel(doc,doc_e);
doc_e=doc_e2;
}
}
if (j2_lo<j2_hi) {
doc_e=doc_us2[j2_lo];
while (doc_e!=doc_us2[j2_hi]) {
doc_e2=DocEntryCopy(doc,doc_e);
QueIns(doc_e2,doc_e1);
doc_e1=doc_e2;
doc_e=doc_e->next;
}
}
}
}
}
Bool DiffSub(CDoc *doc,I64 *_df_flags,I64 j1_lo,I64 j1_hi,I64 j2_lo,I64 j2_hi,
I64 cnt1,I64 cnt2,CDocEntry **doc_s1,CDocEntry **doc_s2,CDocEntry **doc_us1,CDocEntry **doc_us2)
{
I64 i,i1=0,i2=0,i2b,j1,j2,n,
best_j1,best_j2,best_score=0,score;
Bool result=FALSE;
if (j1_lo>=j1_hi || j2_lo>=j2_hi) {
if (j1_lo<j1_hi || j2_lo<j2_hi) {
DiffSelect(doc,_df_flags,j1_lo,j1_hi,j2_lo,j2_hi,cnt1,cnt2,doc_us1,doc_us2);
return TRUE;
} else
return FALSE;
}
//Locate longest matching str in intervals
while (i1<cnt1 && i2<cnt2) {
if (!(j1_lo<=doc_s1[i1]->x<j1_hi)) //x is the new y
i1++;
else if (!(j2_lo<=doc_s2[i2]->x<j2_hi)) //x is the new y
i2++;
else {
i=StrCmp(doc_s1[i1]->tag,doc_s2[i2]->tag);
if (i>0)
i2++;
else if (i<0)
i1++;
else {
i2b=i2;
while (!StrCmp(doc_s1[i1]->tag,doc_s2[i2]->tag)) {
if (j2_lo<=doc_s2[i2]->x<j2_hi) { //x is the new y
score=0;
j1=doc_s1[i1]->x; //x is the new y
j2=doc_s2[i2]->x; //x is the new y
n=j1_hi-j1;
if (j2_hi-j2<n)
n=j2_hi-j2;
while (score<n) {
if (!StrCmp(doc_us1[j1+score]->tag,doc_us2[j2+score]->tag))
score++;
else
break;
}
if (score>best_score) {
best_score=score;
best_j1=j1;
best_j2=j2;
}
}
i2++;
if (i2>=cnt2)
break;
}
i2=i2b;
i1++;
}
}
}
if (!best_score) {
DiffSelect(doc,_df_flags,j1_lo,j1_hi,j2_lo,j2_hi,cnt1,cnt2,doc_us1,doc_us2);
return TRUE;
} else {
if (DiffSub(doc,_df_flags,j1_lo,best_j1,j2_lo,best_j2,cnt1,cnt2,doc_s1,doc_s2,doc_us1,doc_us2))
result=TRUE;
if (DiffSub(doc,_df_flags,best_j1+best_score,j1_hi,best_j2+best_score,j2_hi,cnt1,cnt2,
doc_s1,doc_s2,doc_us1,doc_us2))
result=TRUE;
return result;
}
}
Bool DiffBins(CDoc *doc1,CDoc *doc2)
{
CDocBin *tempb1=doc1->bin_root.next,
*tempb2=doc2->bin_root.next;
if (tempb1->last->last->num!=
tempb2->last->last->num)
return TRUE;
while (tempb1!=&doc1->bin_root) {
if (tempb1->type!=tempb2->type ||
tempb1->size!=tempb2->size ||
MemCmp(tempb1->data,tempb2->data,tempb1->size))
return TRUE;
tempb1=tempb1->next;
tempb2=tempb2->next;
}
return FALSE;
}
public Bool Diff(U8 *dst_file,U8 *src_file,I64 *_df_flags=NULL)
{ //The _df_flags arg is used when this is called by $LK,"MergeChk","MN:MergeChk"$().
CDoc *doc1=DocRead(dst_file,DOCF_PLAIN_TEXT_WITH_TABS|DOCF_NO_CURSOR),
*doc2=DocRead(src_file,DOCF_PLAIN_TEXT_WITH_TABS|DOCF_NO_CURSOR);
CDocEntry *doc_e,**doc_s1,**doc_s2,**doc_us1,**doc_us2;
I64 i,cnt1=0,cnt2=0,df_flags;
Bool result=FALSE;
if (_df_flags)
df_flags=*_df_flags;
else
df_flags=0;
df_flags&=DF_ABORT_ALL_FILES;
doc_e=doc1->root.next;
while (doc_e!=doc1) {
if (doc_e->type_u8==DOCT_TEXT)
doc_e->x=cnt1++; //x is the new y
doc_e=doc_e->next;
}
doc_e=doc2->root.next;
while (doc_e!=doc2) {
if (doc_e->type_u8==DOCT_TEXT)
doc_e->x=cnt2++; //x is the new y
doc_e=doc_e->next;
}
doc_s1=MAlloc(cnt1*sizeof(CDocEntry *));
doc_us1=MAlloc((cnt1+1)*sizeof(CDocEntry *));
i=0;
doc_e=doc1->root.next;
while (doc_e!=doc1) {
if (doc_e->type_u8==DOCT_TEXT) {
doc_s1[i]=doc_e;
doc_us1[i++]=doc_e;
}
doc_e=doc_e->next;
}
doc_us1[i]=doc1;
QSortI64(doc_s1,cnt1,&DiffEntriesCompare);
doc_s2=MAlloc(cnt2*sizeof(CDocEntry *));
doc_us2=MAlloc((cnt2+1)*sizeof(CDocEntry *));
i=0;
doc_e=doc2->root.next;
while (doc_e!=doc2) {
if (doc_e->type_u8==DOCT_TEXT) {
doc_s2[i]=doc_e;
doc_us2[i++]=doc_e;
}
doc_e=doc_e->next;
}
doc_us2[i]=doc2;
QSortI64(doc_s2,cnt2,&DiffEntriesCompare);
result=DiffSub(doc1,&df_flags,0,cnt1,0,cnt2,cnt1,cnt2,doc_s1,doc_s2,doc_us1,doc_us2);
if (df_flags&DF_MODIFIED && !(df_flags&DF_DONT_MODIFIED))
DocWrite(doc1);
if (DiffBins(doc1,doc2)) {
"$$FG,RED$$Bin Data is Different$$FG$$\n";
result=TRUE;
}
DocDel(doc1);
DocDel(doc2);
Free(doc_s1);
Free(doc_s2);
Free(doc_us1);
Free(doc_us2);
if (_df_flags)
*_df_flags=df_flags;
return result;
}
#help_index ""
+287
View File
@@ -0,0 +1,287 @@
#help_index "Graphics/Windows BMP Files"
//This provides support for Window's BMP files.
class CFileBMP
{
U16 type;
U32 file_size;
U32 reserved;
U32 data_offset;
U32 header_size;
U32 width;
U32 height;
U16 planes;
U16 bit_cnt;
U32 compression;
U32 image_size;
U32 x_pixels_per_meter;
U32 y_pixels_per_meter;
U32 colors_used;
U32 important_colors;
U0 end;
CBGR palette[16];
};
public CFileBMP *BMPFile4To(CDC *dc)
{
//To Windows 4 bit BMP
U8 *src,*ptr;
I64 x,y,w=dc->width>>1,
size=offset(CFileBMP.end)+dc->width*dc->height>>1+16*sizeof(CBGR);
CFileBMP *r=CAlloc(size);
r->type='BM';
r->planes=1;
r->file_size=size;
r->data_offset=offset(CFileBMP.end);
r->header_size=offset(CFileBMP.end)-
offset(CFileBMP.header_size);
r->width=dc->width;
r->height=dc->height;
r->bit_cnt=4;
r->image_size=dc->width*dc->height>>1;
r->data_offset+=16*sizeof(CBGR);
GetVGAPalette4(r->palette);
ptr=r(U8 *)+r->data_offset;
for (y=dc->height-1;y>=0;y--) {
src=y*dc->width_internal+dc->body;
for (x=0;x<w;x++) {
*ptr|=(*src++&15)<<4;
*ptr|=*src++&15;
ptr++;
}
}
return r;
}
public CFileBMP *BMPFileRLE4To(CDC *dc)
{
//To Windows RLE4 bit BMP
U8 *src,*ptr;
I64 x,y,w=dc->width,cnt,pattern;
CFileBMP *r=CAlloc(offset(CFileBMP.end)+2*(dc->width+1)*dc->height+16*sizeof(CBGR));
r->type='BM';
r->planes=1;
r->data_offset=offset(CFileBMP.end);
r->header_size=offset(CFileBMP.end)-
offset(CFileBMP.header_size);
r->width=dc->width;
r->height=dc->height;
r->bit_cnt=4;
r->compression=2; //RLE4
r->data_offset+=16*sizeof(CBGR);
GetVGAPalette4(r->palette);
ptr=r(U8 *)+r->data_offset;
for (y=dc->height-1;y>=0;y--) {
src=y*dc->width_internal+dc->body;
x=0;
while (x<w) {
pattern=(src[0]&15)<<4+src[1]&15;
if (x+1<w && src[0]&15==src[1]&15) {
src+=2;
cnt=2;
x+=2;
while (x<w && cnt<MAX_U8) {
if (*src&15==pattern&15) {
src++;
cnt++;
x++;
} else
break;
}
} else {
src+=2;
if (x+1<w)
cnt=2;
else
cnt=1;
x+=2;
}
*ptr++=cnt;
*ptr++=pattern;
}
*ptr(U16 *)++=0;
}
r->image_size=ptr-(&r->data_offset)(U8 *);
r->file_size=offset(CFileBMP.end)+r->image_size+16*sizeof(CBGR);
return r;
}
public CFileBMP *BMPFile24To(CDC *dc)
{
//To Windows 24 bit BMP
U8 *src;
I64 i,x,y,size=offset(CFileBMP.end)+dc->width*dc->height*sizeof(CRGB);
CBGR *bgr;
CFileBMP *r=CAlloc(size);
r->type='BM';
r->planes=1;
r->file_size=size;
r->data_offset=offset(CFileBMP.end);
r->header_size=offset(CFileBMP.end)-
offset(CFileBMP.header_size);
r->width=dc->width;
r->height=dc->height;
r->bit_cnt=32;
r->image_size=dc->width*dc->height<<2;
bgr=r(U8 *)+r->data_offset;
for (y=dc->height-1;y>=0;y--) {
src=y*dc->width_internal+dc->body;
for (x=0;x<dc->width;x++) {
i=*src++;
if (i&BLUE) bgr->b=0x7F;
if (i&GREEN) bgr->g=0x7F;
if (i&RED) bgr->r=0x7F;
if (i&8) {
if (bgr->b) bgr->b=0xFF;
if (bgr->g) bgr->g=0xFF;
if (bgr->r) bgr->r=0xFF;
}
bgr(U8 *)+=4;
}
}
return r;
}
public I64 BMPFileWrite(U8 *filename,CDC *dc,I64 bits=4)
{ //Window's BMP Files
I64 size;
CFileBMP *r;
if (bits==4) {
if (IsDotZ(filename)) //.Z compression is better than RLE
r=BMPFile4To(dc);
else {
r=BMPFileRLE4To(dc);
if (r->file_size>offset(CFileBMP.end)+dc->width*dc->height>>1+16*sizeof(CBGR)) {
Free(r);
r=BMPFile4To(dc);
}
}
} else if (bits==24)
r=BMPFile24To(dc);
else {
"Format Not Supported.\n";
return 0;
}
size=r->file_size;
FileWrite(filename,r,r->file_size);
Free(r);
return size;
}
U8 *BMPFilePaletteNew(CFileBMP *r)
{
I64 i,j,best,score,best_score;
CBGR palette[16];
U8 *result=CAlloc(16*sizeof(U8));
GetVGAPalette4(palette);
for (i=0;i<16;i++) {
best=i;
best_score=MAX_I64;
for (j=0;j<16;j++) {
score=SqrI64(r->palette[i].r-palette[j].r)+
SqrI64(r->palette[i].g-palette[j].g)+
SqrI64(r->palette[i].b-palette[j].b);
if (score<best_score) {
best=j;
best_score=score;
}
}
result[i]=best;
}
return result;
}
U8 ms_paint_palette[16]={0,4,2,6,1,5,3,8,7,12,10,14,9,13,11,15};
public CDC *BMPFileRead(U8 *filename,Bool use_ms_paint_palette=FALSE)
{ //Window's BMP Files
I64 i,j,cnt;
U8 *palette_map,*ptr;
Bool rle4;
CFileBMP *r;
CDC *result=NULL;
if (ptr=FileRead(filename)) {
r=ptr;
if (0<r->width<MAX_I32 && 0<r->height<MAX_I32) {
result=DCNew(DCT_COLOR8,r->width,r->height);
ptr+=r->data_offset;
if (r->bit_cnt==4) {
if (r->compression==2)
rle4=TRUE;
else
rle4=FALSE;
if (use_ms_paint_palette)
palette_map=ms_paint_palette;
else
palette_map=BMPFilePaletteNew(r);
for (i=r->height-1;i>=0;i--)
if (rle4) { //We don't support full RLE4, just our own subset
j=0;
while (cnt=*ptr++) {
if (cnt==1) {
result->color=palette_map[*ptr++&15];
GrPlot(result,j++,i);
} else {
if (cnt==2 && *ptr>>4!=*ptr&15) {
result->color=palette_map[*ptr&15];
GrPlot(result,j+1,i);
result->color=palette_map[*ptr>>4];
GrPlot(result,j,i);
ptr++;
j+=2;
} else {
result->color=palette_map[*ptr++&15];
while (cnt--)
GrPlot(result,j++,i);
}
}
}
ptr++;
} else
for (j=0;j<(r->width+7)&-8;) {
result->color=palette_map[*ptr&15];
GrPlot(result,j+1,i);
result->color=palette_map[*ptr>>4];
GrPlot(result,j,i);
ptr++;
j+=2;
}
if (!use_ms_paint_palette)
Free(palette_map);
} else {
"Format Not Supported.\n";
DCDel(result);
result=NULL;
}
} else
"Invalid BMP File\n";
Free(r);
}
return result;
}
#help_index "Graphics/CSprite;Graphics/Windows BMP Files;Doc/Output"
public U0 DocPutBMPFile(CDoc *doc=NULL,U8 *filename,Bool use_ms_paint_palette=FALSE)
{
CDC *dc=BMPFileRead(filename,use_ms_paint_palette);
CSprite *elems=DC2Sprite(dc);
DocPutSprite(doc,elems);
Free(elems);
DCDel(dc);
}
#help_index "Graphics/Windows BMP Files;Graphics/Screen"
public I64 BMPFileCaptureScreen(U8 *filename,I64 bits=4)
{
CDC *dc=DCCaptureScreen;
I64 size=BMPFileWrite(filename,dc,bits);
DCDel(dc);
return size;
}
#help_index ""
+266
View File
@@ -0,0 +1,266 @@
#help_index "Utils;Cmd Line (Typically)"
#define GRF_REPLACE 0
#define GRF_SKIP 1
#define GRF_ALL 2
#define GRF_ED 3
#define GRF_ABORT_FILE 4
#define GRF_SKIP_FILE 5
I64 PopUpReplaceSkipAllCancelEd(U8 *msg)
{
I64 i;
CDoc *doc=DocNew;
DocPutS(doc,msg);
DocPutS(doc,"$$CM+LX,2,4$$$$BT,\"REPLACE\",GRF_REPLACE$$"
"$$CM+LX,22,0$$$$BT,\"SKIP\",GRF_SKIP$$"
"$$CM+LX,2,4$$$$BT,\"ALL\",GRF_ALL$$"
"$$CM+LX,22,0$$$$BT,\"ABORT ALL\",DOCM_CANCEL$$"
"$$CM+LX,2,4$$$$BT,\"EDIT\",GRF_ED$$"
"$$CM+LX,22,0$$$$BT,\"ABORT FILE\",GRF_ABORT_FILE$$"
"$$CM+LX,2,4$$$$BT,\"SKIP FILE\",GRF_SKIP_FILE$$\n");
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
I64 GrepFile(U8 *pattern,U8 *name,I64 *_fuf_flags,U8 *replace_text)
{
Bool first_on_line,write_this_file=FALSE,cont=!Bt(_fuf_flags,FUf_CANCEL);
U8 *src,*dst,*dst2,*name_buf=NULL;
I64 i,j,plen,rlen,dlen,cnt=0,old_flags,ss_flags;
CDoc *cur_l,*doc=DocRead(name,DOCF_PLAIN_TEXT_WITH_TABS|DOCF_NO_CURSOR);
CDocEntry *doc_e;
if (Bt(_fuf_flags,FUf_IGNORE))
ss_flags=SRF_IGNORE_CASE;
else
ss_flags=0;
if (Bt(_fuf_flags,FUf_WHOLE_LABELS))
ss_flags|=SRG_WHOLE_LABELS;
if (Bt(_fuf_flags,FUf_WHOLE_LABELS_FRONT))
ss_flags|=SRF_WHOLE_LABELS_FRONT;
if (Bt(_fuf_flags,FUf_WHOLE_LABELS_BACK))
ss_flags|=SRF_WHOLE_LABELS_BACK;
plen=StrLen(pattern);
if (replace_text)
rlen=StrLen(replace_text);
doc_e=doc->root.next;
while (doc_e!=doc && cont) {
if (doc_e->type_u8==DOCT_TEXT) {
src=doc_e->tag;
first_on_line=TRUE;
while (src && cont) {
if (src=SearchStr(src,pattern,ss_flags)) {
cnt++;
if (first_on_line || Bt(_fuf_flags,FUf_REPLACE)) {
first_on_line=FALSE;
PutFileLink(name,doc_e->y+1,TRUE);
name_buf=MSPrintF("%s,%d",name,doc_e->y+1);
if (cur_l=DocPut) {
old_flags=cur_l->flags&DOCF_PLAIN_TEXT;
cur_l->flags|=DOCF_PLAIN_TEXT;
}
" %s\n",doc_e->tag;
if (cur_l)
cur_l->flags= cur_l->flags&~DOCF_PLAIN_TEXT |old_flags;
}
if (Bt(_fuf_flags,FUf_REPLACE)) {
if (Bt(_fuf_flags,FUf_ALL))
i=GRF_ALL;
else {
i=PopUpReplaceSkipAllCancelEd("");
if (i<0) {
LBts(_fuf_flags,FUf_CANCEL);
cont=FALSE;
write_this_file=FALSE;
} else if (i==GRF_ALL)
LBts(_fuf_flags,FUf_ALL);
else if (i==GRF_ABORT_FILE) {
cont=FALSE;
write_this_file=FALSE;
} else if (i==GRF_SKIP_FILE)
cont=FALSE;
}
if (i==GRF_REPLACE || i==GRF_ALL) {
dlen=StrLen(doc_e->tag);
dst=MAlloc(dlen+1+rlen-plen);
dst2=dst;
j=src-doc_e->tag;
for (i=0;i<j;i++)
*dst++=doc_e->tag[i];
for (i=0;i<rlen;i++)
*dst++=replace_text[i];
src=dst;
for (i=j+plen;i<=dlen;i++)
*dst++=doc_e->tag[i];
Free(doc_e->tag);
doc_e->tag=dst2;
if (cur_l=DocPut) {
old_flags=cur_l->flags&DOCF_PLAIN_TEXT;
cur_l->flags|=DOCF_PLAIN_TEXT;
}
"%12s,%04d*%s\n",name,doc_e->y+1,dst2;
if (cur_l)
cur_l->flags= cur_l->flags&~DOCF_PLAIN_TEXT |old_flags;
write_this_file=TRUE;
} else {
src++;
if (i==GRF_ED) {
Free(name_buf);
name_buf=StrNew(doc->filename.name);
doc->flags&=~DOCF_NO_CURSOR;
doc->cur_entry=doc_e;
doc->cur_data_col=doc_e->min_col;
DocWrite(doc);
DocDel(doc);
"Wrote:%s\n",name_buf;
Ed(name_buf);
doc=DocRead(name_buf, DOCF_PLAIN_TEXT_WITH_TABS);
doc_e=doc->cur_entry;
if (doc_e->last!=doc) doc_e=doc_e->last;
src=NULL;
write_this_file=FALSE;
}
}
} else
src++;
Free(name_buf);
name_buf=NULL;
}
}
}
doc_e=doc_e->next;
}
if (write_this_file) {
DocWrite(doc);
"Wrote:%s\n",doc->filename.name;
}
DocDel(doc);
return cnt;
}
I64 GrepLst(U8 *pattern,CDirEntry *tempm1,I64 *_fuf_flags,U8 *replace_text)
{
I64 cnt=0;
CDirEntry *tempm2;
while (tempm1 && !Bt(_fuf_flags,FUf_CANCEL)) {
tempm2=tempm1->next;
if (tempm1->attr & _ATTR_DIR) {
if (tempm1->sub) {
"%S %s\n","ST_SCANNING_DIR",tempm1->full_name;
cnt+=GrepLst(pattern,tempm1->sub,_fuf_flags,replace_text);
}
} else
cnt+=GrepFile(pattern,tempm1->full_name,_fuf_flags,replace_text);
CDirEntryDel(tempm1);
tempm1=tempm2;
}
return cnt;
}
public I64 Grep(U8 *pattern,U8 *files_find_mask=FILENAME_MASK_TXT,U8 *fu_flags=NULL,U8 *replace_text=NULL)
/*
This does not do regular expressions--my bad.
Anyway, it's good for searching and replacing.
Let's say it stands for global replace ;-)
"+r" =recurse
"+i" =ignore case
"+l" =whole labels only.
This will check for a nonlabel character before
and after. If you have a var, "dd" and don't
want to match words like "Add", you
set this flag and it will see that the characters
before or after "ll" are label characters.
"+lf"=only checks for label chars in front
"+lb"=only checks for label chars behind (after).
*/
{
I64 cnt=0,fuf_flags=0;
CDirEntry *tempm;
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+i"); //Set dft flags
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (fuf_flags&~(FUG_FILES_FIND|FUF_IGNORE|FUF_WHOLE_LABELS|FUF_WHOLE_LABELS_FRONT|FUF_WHOLE_LABELS_BACK))
throw(EXCEPT_FUF,1);
LBEqu(&fuf_flags,FUf_REPLACE,replace_text);
tempm=FilesFind(files_find_mask,fuf_flags&FUG_FILES_FIND);
fuf_flags&=FUF_REPLACE|FUF_IGNORE|FUF_WHOLE_LABELS|FUF_WHOLE_LABELS_FRONT|FUF_WHOLE_LABELS_BACK;
cnt+=GrepLst(pattern,tempm,&fuf_flags,replace_text);
return cnt;
}
public I64 FileOcc(U8 *pattern,U8 *files_find_mask=FILENAME_MASK_TXT,U8 *fu_flags="+r+i+l")
{/*
"+r"=recurse
"+i"=ignore case
"+l"=whole labels only.
*/
I64 cnt=0;
Bool old_silent=Silent(TRUE);
cnt=Grep(pattern,files_find_mask,fu_flags);
Silent(old_silent);
return cnt;
}
class CGrep
{
U8 find_text[136] fmtstr "$$DA-P,135,\"FIND :%s\"$$\n";
U8 replace_text[136] fmtstr "$$DA-P,135,\"REPLACE :%s\"$$\n";
Bool replace fmtstr "$$CB,\"REPLACE\"$$\n";
Bool match_case fmtstr "$$CB,\"MATCH CASE\"$$\n";
Bool whole_labels fmtstr "$$CB,\"WHOLE LABELS\"$$\n";
U8 filemask[136] fmtstr "$$DA-P,135,\"FILE MASK :%s\"$$\n";
Bool recurse fmtstr "$$CB,\"RECURSE\"$$\n";
};
I64 GrepWiz()
{
CDoc *doc;
U8 buf[32],*dir,*st;
CGrep *g=CAlloc(sizeof(CGrep));
I64 result=0;
g->recurse=TRUE;
StrCpy(g->filemask,FILENAME_MASK_TXT);
if (doc=DocPut) {
StrCpy(g->find_text,doc->find_replace->find_text);
StrCpy(g->replace_text,doc->find_replace->replace_text);
g->replace=doc->find_replace->replace;
g->match_case=doc->find_replace->match_case;
g->whole_labels=doc->find_replace->whole_labels;
}
if (DocFormDo(g,"CGrep",0,"$$FG,PURPLE$$$$TX+CX,\"Grep\"$$\n$$FG$$")) {
if (doc) {
StrCpy(doc->find_replace->find_text,g->find_text);
StrCpy(doc->find_replace->replace_text,g->replace_text);
doc->find_replace->replace=g->replace;
doc->find_replace->match_case=g->match_case;
doc->find_replace->whole_labels=g->whole_labels;
}
dir=PopUpPickDir;
if (*dir) {
*buf=0;
if (g->match_case)
StrCat(buf,"-i");
if (!g->recurse)
StrCat(buf,"-r");
if (g->whole_labels)
StrCat(buf,"+l");
if (g->replace)
st=MSPrintF("\"$$$$WW+H,1$$$$\";Cd(\"%s\");Grep(\"%Q\",\"%Q\",\"%Q\",\"%Q\");UserTaskCont;",dir,g->find_text,g->filemask,buf,g->replace_text);
else
st=MSPrintF("\"$$$$WW+H,1$$$$\";Cd(\"%s\");Grep(\"%Q\",\"%Q\",\"%Q\");UserTaskCont;",dir,g->find_text,g->filemask,buf);
result=PopUp(st);
}
Free(dir);
}
Free(g);
return result;
}
#help_index ""
+159
View File
@@ -0,0 +1,159 @@
#help_index "Debugging/Heap"
class CHeapLog
{
CHeapLog *next,*last;
U8 *addr;
U8 *caller1;
U8 *caller2;
U8 *caller3;
U8 *caller4;
};
class CHeapLogHash
{
CHeapLog *next,*last;
};
#define HEAPLOG_HASH_SIZE 0x1000
CTask *heaplog_task=NULL;
CHeapCtrl *heaplog_hc;
CHeapLogHash *heaplog_root=NULL;
U0 HeapLogTask(I64)
{
while (TRUE)
Yield;
}
U0 HeapLogMAlloc(U8 *addr)
{
CHeapLog *temph;
I64 i;
if (MHeapCtrl(addr)==heaplog_hc) {
temph=MAlloc(sizeof(CHeapLog),heaplog_task);
temph->addr=addr;
temph->caller1=Caller(2);
temph->caller2=Caller(3);
temph->caller3=Caller(4);
temph->caller4=Caller(5);
i=addr>>3 &(HEAPLOG_HASH_SIZE-1);
PushFD;
Cli;
while (LBts(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0))
Pause;
QueIns(temph,heaplog_root[i].last);
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
PopFD;
}
}
U0 HeapLogFree(U8 *addr)
{
I64 i;
CHeapLog *temph;
if (!addr) return;
if (MHeapCtrl(addr)==heaplog_hc) {
i=addr>>3 &(HEAPLOG_HASH_SIZE-1);
PushFD;
Cli;
while (LBts(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0))
Pause;
temph=heaplog_root[i].next;
while (temph!=&heaplog_root[i]) {
if (addr==temph->addr) {
QueRem(temph);
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
PopFD;
Free(temph);
return;
}
temph=temph->next;
}
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
PopFD;
}
}
public U0 HeapLogRep()
{
I64 i,total=0;
CHeapLog *temph;
if (!LBtr(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0)) {
"HeapLog Not Active\n";
return;
}
"$$WW,0$$";
PushFD;
Cli;
while (LBts(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0))
Pause;
for (i=0;i<HEAPLOG_HASH_SIZE;i++) {
temph=heaplog_root[i].next;
while (temph!=&heaplog_root[i]) {
"$$FG,PURPLE$$%08X$$FG$$ %08X ",MSize(temph->addr),temph->addr;
if (!PutSrcLink(temph->caller1,64))
"%P",temph->caller1;
'' CH_SPACE;
if (!PutSrcLink(temph->caller2,64))
"%P",temph->caller2;
'' CH_SPACE;
if (!PutSrcLink(temph->caller3,64))
"%P",temph->caller3;
'' CH_SPACE;
if (!PutSrcLink(temph->caller4,64))
"%P",temph->caller4;
NewLine;
total+=MSize(temph->addr);
temph=temph->next;
}
}
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
PopFD;
"\n$$FG,LTRED$$Total:%08X$$FG$$\n",total;
LBts(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0);
}
public U0 HeapLog(Bool val=TRUE,CTask *task=NULL)
{
I64 i;
if (val) {
if (Bt(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0))
"HeapLog Already Active\n";
else {
if (!task) task=Fs;
if (TaskValidate(task))
heaplog_hc=task->data_heap;
else
heaplog_hc=task;
PushFD;
Cli;
while (LBts(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0))
Pause;
heaplog_task=Spawn(&HeapLogTask);
ext[EXT_HEAPLOG_MALLOC]=&HeapLogMAlloc;
ext[EXT_HEAPLOG_FREE]=&HeapLogFree;
heaplog_root=MAlloc(sizeof(CHeapLogHash)*HEAPLOG_HASH_SIZE,heaplog_task);
for (i=0;i<HEAPLOG_HASH_SIZE;i++)
QueInit(&heaplog_root[i]);
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
PopFD;
LBts(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0);
}
} else {
if (!LBtr(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0))
"HeapLog Not Active\n";
else {
Kill(heaplog_task);
heaplog_root=heaplog_task=NULL;
ext[EXT_HEAPLOG_MALLOC]=NULL;
ext[EXT_HEAPLOG_FREE]=NULL;
}
}
}
#help_index ""
+113
View File
@@ -0,0 +1,113 @@
#help_index "Utils;Cmd Line (Typically)"
I64 LineCntRepFiles(CDirEntry *tempm)
{
CDoc *doc;
I64 result=0,i;
while (tempm) {
i=0;
if (tempm->attr&_ATTR_DIR)
i=LineCntRepFiles(tempm->sub);
else {
if (FilesFindMatch(FILENAME_MASK_SRC,tempm->name)) {
doc=DocRead(tempm->full_name);
if (doc->root.next!=doc)
i=doc->root.last->y+2;
DocDel(doc);
}
}
tempm->user_data=i;
result+=i;
tempm=tempm->next;
}
return result;
}
U0 PutLineCntFiles(CDoc *doc,CDirEntry *tempm)
{
while (tempm) {
if (tempm->attr&_ATTR_DIR) {
DocPrintF(doc,"%8,d $$TR+C,\"%s\"$$\n$$ID,2$$",tempm->user_data,tempm->name);
PutLineCntFiles(doc,tempm->sub);
DocPutS(doc,"$$ID,-2$$");
} else {
if (FilesFindMatch(FILENAME_MASK_SRC,tempm->name)) {
DocPrintF(doc,"%8,d ",tempm->user_data);
DocPrintF(doc,"$$LK,\"%s\",\"FI:%s\"$$\n",
tempm->name,tempm->full_name);
}
}
tempm=tempm->next;
}
}
public I64 LineCntRep(U8 *files_find_mask="/TempleOS/*",U8 *fu_flags=NULL)
{
I64 fuf_flags=0,result=0;
CDoc *doc=DocNew;
CDirEntry *tempm1=NULL;
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (tempm1=FilesFind(files_find_mask,fuf_flags)) {
result=LineCntRepFiles(tempm1);
DocPrintF(doc,"%8,d $$TR+C,\"%s\"$$\n$$ID,2$$",result,files_find_mask);
PutLineCntFiles(doc,tempm1);
DocPutS(doc,"$$ID,-2$$");
CDirLstDel(tempm1);
}
DocInsDoc(DocPut,doc);
DocDel(doc);
return result;
}
I64 TreeSizeRepFiles(CDirEntry *tempm)
{
I64 result=0,i;
while (tempm) {
if (tempm->attr&_ATTR_DIR)
i=TreeSizeRepFiles(tempm->sub);
else
i=tempm->size;
tempm->user_data=i;
result+=i;
tempm=tempm->next;
}
return result;
}
U0 PutTreeSizeFiles(CDoc *doc,CDirEntry *tempm)
{
while (tempm) {
if (tempm->attr&_ATTR_DIR) {
DocPrintF(doc,"%10,d $$TR+C,\"%s\"$$\n$$ID,2$$",tempm->user_data,tempm->name);
PutTreeSizeFiles(doc,tempm->sub);
DocPutS(doc,"$$ID,-2$$");
} else {
DocPrintF(doc,"%10,d ",tempm->user_data);
DocPrintF(doc,"$$LK,\"%s\",\"FI:%s\"$$\n",
tempm->name,tempm->full_name);
}
tempm=tempm->next;
}
}
public I64 TreeSizeRep(U8 *files_find_mask="/TempleOS/*",U8 *fu_flags=NULL)
{
I64 fuf_flags=0,result=0;
CDoc *doc=DocNew;
CDirEntry *tempm1=NULL;
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (tempm1=FilesFind(files_find_mask,fuf_flags)) {
result=TreeSizeRepFiles(tempm1);
DocPrintF(doc,"%10,d $$TR+C,\"%s\"$$\n$$ID,2$$",result,files_find_mask);
PutTreeSizeFiles(doc,tempm1);
DocPutS(doc,"$$ID,-2$$");
CDirLstDel(tempm1);
}
DocInsDoc(DocPut,doc);
DocDel(doc);
return result;
}
#help_index ""
+74
View File
@@ -0,0 +1,74 @@
#help_index "Debugging;Utils;Cmd Line (Typically)"
I64 LinkChkDoc(CDoc *doc,I64 *_fuf_flags)
{
U8 *st;
Bool found,unlock=DocLock(doc);
CDoc *old_doc;
CDocEntry *doc_e=doc->root.next;
I64 result=0;
while (doc_e!=doc) {
if (ScanKey) {
LBts(_fuf_flags,FUf_CANCEL);
break;
}
if (st=DocEntryLink(doc,doc_e)) {
old_doc=DocPut;
DocLock(old_doc);
Fs->put_doc=doc;
found=DocLinkChk(st);
Fs->put_doc=old_doc;
DocUnlock(old_doc);
if (!found) {
PutFileLink(doc->filename.name,doc_e->y);
"$$FG,RED$$ %04d:%s\n$$FG$$",doc_e->y,st;
result++;
}
Free(st);
} else if (doc_e->type_u8==DOCT_ERROR) {
PutFileLink(doc->filename.name,doc_e->y);
"$$FG,RED$$ Doc Error\n$$FG$$";
result++;
}
doc_e=doc_e->next;
}
if (unlock) DocUnlock(doc);
return result;
}
I64 LinkChkFile(U8 *filename,I64 *_fuf_flags)
{
CDoc *doc=DocRead(filename,DOCF_NO_CURSOR);
I64 result=LinkChkDoc(doc,_fuf_flags);
DocDel(doc);
return result;
}
I64 LinkChkLst(CDirEntry *tempm1,I64 *_fuf_flags)
{
CDirEntry *tempm2;
I64 result=0;
while (tempm1 && !Bt(_fuf_flags,FUf_CANCEL)) {
tempm2=tempm1->next;
if (tempm1->attr & _ATTR_DIR) {
if (tempm1->sub) {
"%S %s\n","ST_SCANNING_DIR",tempm1->full_name;
result+=LinkChkLst(tempm1->sub,_fuf_flags);
}
} else
result+=LinkChkFile(tempm1->full_name,_fuf_flags);
CDirEntryDel(tempm1);
tempm1=tempm2;
}
return result;
}
public I64 LinkChk(U8 *files_find_mask=FILENAME_MASK_TXT,U8 *fu_flags=NULL)
//Checks for broken file links.
{
I64 fuf_flags=0;
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+T");
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
return LinkChkLst(FilesFind(files_find_mask,fuf_flags),&fuf_flags);
}
#help_index ""
+245
View File
@@ -0,0 +1,245 @@
#help_index "Info;Utils;Memory/Info;Cmd Line (Typically)"
I64 TSSSize(CTSS *tss)
{
return MSize2(tss)+
MSize2(tss->st0)+
MSize2(tss->st1)+
MSize2(tss->st2);
}
I64 PenBrushesSize()
{
I64 result=0,i;
for (i=0;i<GR_NUM_PEN_BRUSHES;i++)
result+=
DCSize(gr_pen_brushes[i])+
DCSize(gr_collision_pen_brushes[i])+
DCSize(gr_even_pen_brushes[i])+
DCSize(gr_odd_pen_brushes[i] );
return result;
}
I64 ScreenZoomTablesSize()
{
I64 result=0,i;
for (i=1;i<=GR_MAX_SCREEN_ZOOM;i++)
result+=MSize2(gr_screen_zoom_tables[i]);
return result;
}
I64 TaskStkSize(CTask *task)
{
CTaskStk *temps=task->stk;
I64 result=0;
while (temps) {
result+=MSize2(temps);
temps=temps->next_stk;
}
return result;
}
I64 TaskQueSize(CTask *task)
{
CSrvCmd *tempc,*tempc1;
I64 result=0;
PushFD;
Cli;
while (LBts(&task->srv_ctrl.flags,SVCRf_LOCKED))
Pause;
tempc1=&task->srv_ctrl.next_waiting;
tempc=tempc1->next;
while (tempc!=tempc1) {
result+=MSize2(tempc)+MSize2(tempc->aux_str);
tempc=tempc->next;
}
tempc1=&task->srv_ctrl.next_done;
tempc=tempc1->next;
while (tempc!=tempc1) {
result+=MSize2(tempc)+MSize2(tempc->aux_str);
tempc=tempc->next;
}
LBtr(&task->srv_ctrl.flags,SVCRf_LOCKED);
PopFD;
return result;
}
I64 BlkDevsSize()
{
I64 i,result=MSize2(sys_blkdevs);
CBlkDev *bdev;
for (i=0;i<NUM_BLKDEVS;i++) {
bdev=&sys_blkdevs[i];
if (bdev->bd_signature==BD_SIGNATURE_VAL) {
if (bdev->type==BDT_RAM)
"RAMDsk %C\t:%010X Unused:%010X\n",
bdev->first_drv_let,(bdev->max_blk+1)<<BLK_SIZE_BITS,
UnusedDrvSpace(bdev->first_drv_let);
result+=MSize2(bdev->dev_id_record);
}
}
return result;
}
I64 PrtsSize()
{
I64 i,result=MSize2(sys_prts);
for (i=0;i<NUM_PRTS;i++)
result+=MSize2(sys_prts[i].buffered_map_dirty_bits)+
MSize2(sys_prts[i].fis);
return result;
}
Bool MemRepTask(CTask *task,Bool override_validate=FALSE)
{
I64 i,j,k,m,n;
U8 *st;
CDoc *pdoc,*ddoc,*bdoc;
CLex *lx;
CMathODE *o;
CCPU *c;
CTask *task1;
if (!override_validate && !TaskValidate(task))
return FALSE;
if (task==Fs)
task->rsp=GetStkPtr;
st=MStrUtil(task->task_title,SUF_REM_CTRL_CHARS|SUF_SAFE_DOLLAR);
"$$FG,GREEN$$Task:%010X$$FG,CYAN$$ %-30ts$$FG$$\n$$ID,2$$",task,st;
Free(st);
"$$FG,PURPLE$$Alloced:%010X Used:%010X $$FG,RED$$Unused:%010X$$FG$$\n",
TaskAllocatedMem(task,override_validate),
TaskUsedMem(task,override_validate),
TaskUnusedAllocatedMem(task,override_validate);
"HashTable\t:%010X\n",HashTableSize2(task->hash_table);
i=UnusedStk(task);
if (0<=i<=task->stk->stk_size)
"Stk Size\t:%010X Unused:%010X\n",TaskStkSize(task),i;
else
"Stk Size\t:%010X $$FG,RED$$$$BK,1$$Overflow$$BK,0$$$$FG$$\n",TaskStkSize(task);
if (pdoc=DocPut(task))
"PutDoc\t:%010X\n",DocSize(pdoc);
if ((ddoc=DocDisplay(task)) && pdoc!=ddoc)
"DisplayDoc\t:%010X\n",DocSize(ddoc);
if (bdoc=DocBorder(task))
"BorderDoc\t:%010X\n",DocSize(bdoc);
lx=task->next_lex;
while (lx!=&task->next_lex) {
"Lex\t\t:%010X\n",LexSize(lx);
lx=lx->next;
}
o=task->next_ode;
while (o!=&task->next_ode) {
"CMathODE\t:%010X\n",ODESize(o);
o=o->next;
}
if (task==sys_winmgr_task) {
"gr_dc\t\t:%010X\n",DCSize(gr_dc);
"gr_dc2\t\t:%010X\n",DCSize(gr_dc2);
"gr_dc_cache\t\t:%010X\n",DCSize(gr_dc_cache);
"gr_screen_image\t:%010X\n",DCSize(gr_screen_image);
"gr_zoomed_dc\t:%010X\n",DCSize(gr_zoomed_dc);
"gr_pen_brushes\t:%010X\n",PenBrushesSize;
"gr_1_to_8_bits\t:%010X\n",MSize2(gr_1_to_8_bits);
"gr_1_to_8_colors\t:%010X\n",MSize2(gr_1_to_8_colors);
"gr_text_base\t:%010X\n",MSize2(gr_text_base);
"gr_vga_text_cache\t:%010X\n",MSize2(gr_vga_text_cache);
"gr_win_z_buf\t:%010X\n",MSize2(gr_win_z_buf)+MSize2(gr_win_uncovered_bitmap);
"gr_screen_zoom_tbles:%010X\n",ScreenZoomTablesSize;
} else if (task==adam_task) {
j=0;k=0;m=0;n=0;
for (i=0;i<mp_cnt;i++) {
c=&cpu_structs[i];
k+=TSSSize(c->tss);
task1=c->seth_task;
do {
if (task1!=adam_task) {//adam task located in Kernel mem
j+=MSize2(task1);
m+=MSize2(task1->code_heap);
if (task1->data_heap!=task1->code_heap)
m+=MSize2(task1->code_heap);
}
n+=TaskQueSize(task1);
task1=task1->next_task;
} while (task1!=c->seth_task);
task1=c->idle_task;
j+=MSize2(task1);
m+=MSize2(task1->code_heap);
if (task1->data_heap!=task1->code_heap)
m+=MSize2(task1->code_heap);
}
"TaskStructs\t:%010X\n",j;
"TSSes\t:%010X\n",k;
"HeapCtrls\t:%010X\n",m;
"TaskQues\t:%010X\n",n;
"BlkDevs\t:%010X\n",BlkDevsSize;
"Prts\t:%010X\n",PrtsSize;
"Audio\t:%010X\n",CallExtStr("AudioSize");
if (sys_dsk_cache_base)
"DskCache\t:%010X\n",
MSize2(sys_dsk_cache_base)+MSize2(sys_dsk_cache_hash_table)+MSize2(sys_dsk_cache_ctrl);
"WordStat\t:%010X\n",CallExtStr("WordStatSize");
"Clipboard\t:%010X\n",DocSize(sys_clipboard_doc);
}
"$$ID,-2$$";
return TRUE;
}
public U0 MemRep()
{
I64 i;
CTask *task;
CCPU *c;
U32 *u32_ptr;
Bool old_preempt=Preempt(OFF);
CBinFile *bfh=sys_boot_base-sizeof(CBinFile);
bfh(I64)+=bfh->file_size-1;
"$$FG,BLACK$$Low Memory\t:0000100000$$FG$$\n$$ID,2$$";
u32_ptr=SYS_BOOT_BASE;
"Kernel\t:%010X-%010X\n",*u32_ptr-sizeof(CBinFile),bfh;
"VGA\t\t:00000A0000-00000BFFFF\n";
"$$ID,-2$$$$FG,BLACK$$High Memory\t:0000100000-%010X$$FG$$\n",
sys_heap_limit;
"$$ID,2$$Page Tables\t:%010X-%010X\n",PAGE_TABLE_BASE,sys_heap_base-1;
"$$ID,-2$$";
if (sys_data_bp) {
"$$FG,BLACK$$Code Heap:%010X Used:%010X $$FG,RED$$Unused:%010X$$FG$$\n",
sys_code_bp->size*PAGE_SIZE,sys_code_bp->allocated_u8s,UnusedBPMem(sys_code_bp);
"$$FG,BLACK$$Data Heap:%010X Used:%010X $$FG,RED$$Unused:%010X$$FG$$\n",
sys_data_bp->size*PAGE_SIZE,sys_data_bp->allocated_u8s,UnusedBPMem(sys_data_bp);
} else
"$$FG,BLACK$$Code/Data Heap:%010X Used:%010X $$FG,RED$$Unused:%010X$$FG$$\n",
sys_code_bp->size*PAGE_SIZE,sys_code_bp->allocated_u8s,UnusedBPMem(sys_code_bp);
for (i=0;i<mp_cnt;i++) {
c=&cpu_structs[i];
"$$FG,GREEN$$CPU%d$$FG$$\n$$ID,2$$",i;
task=c->seth_task;
do {
if (!MemRepTask(task))
break;
task=task->next_task;
} while (task!=c->seth_task);
MemRepTask(c->idle_task,TRUE);
"$$ID,-2$$";
}
"$$FG,GREEN$$Independent Heaps$$FG$$\n$$ID,2$$";
"$$FG,BLACK$$sys_uncached_heap:%010X Used:%010X $$FG,RED$$Unused:%010X$$FG$$\n",
sys_uncached_heap->bp->size*PAGE_SIZE,sys_uncached_heap->used_u8s,UnusedBPMem(sys_uncached_heap->bp);
"$$ID,-2$$\n";
Preempt(old_preempt);
}
#help_index ""
+91
View File
@@ -0,0 +1,91 @@
#help_index "Utils;Cmd Line (Typically)"
CDirEntry MCMatchFind(CDirEntry *pattern,CDirEntry *lst)
{
while (lst) {
if (!StrCmp(pattern->name,lst->name))
return lst;
lst=lst->next;
}
return NULL;
}
U0 MergeChkLst(CDirEntry *m1,CDirEntry *m2,I64 *_fuf_flags,I64 *_df_flags)
{
I64 i;
CDirEntry *tempm2;
while (m1 && !(*_df_flags & DF_ABORT_ALL_FILES)) {
tempm2=MCMatchFind(m1,m2);
if (!tempm2)
"$$FG,BROWN$$Does Not Exist:%s$$FG$$\n",m1->full_name;
else {
if (m1->attr & _ATTR_DIR)
MergeChkLst(m1->sub,tempm2->sub,_fuf_flags,_df_flags);
else {
i=m1->datetime-tempm2->datetime;
if (AbsI64(i)>CDATE_FREQ*2) { //Filedates can shift due to conversion
"" m1->full_name;
NewLine;
if (Bt(_fuf_flags,FUf_DIFF)) {
if (FilesFindMatch(FILENAME_MASK_TXT,m1->full_name))
Diff(tempm2->full_name,m1->full_name,_df_flags);
}
}
}
}
m1=m1->next;
}
}
public U0 MergeChk(
U8 *dst_files_find_mask="/TempleOS/*",
U8 *src_files_find_mask="/TempleOS/*",
U8 *fu_flags=NULL)
//"+d"=Do $LK,"Diff","MN:Diff"$() on files
{
I64 df_flags=0,fuf_flags=0;
CDirEntry *tempm1=NULL,*tempm2=NULL;
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (fuf_flags&~(FUG_FILES_FIND|FUF_DIFF))
throw(EXCEPT_FUF,3);
PrintFWarn("This is based strictly on file dates.\n");
tempm1=FilesFind(src_files_find_mask,fuf_flags&FUG_FILES_FIND);
tempm2=FilesFind(dst_files_find_mask,fuf_flags&FUG_FILES_FIND);
fuf_flags&=FUF_DIFF;
MergeChkLst(tempm1,tempm2,&fuf_flags,&df_flags);
CDirLstDel(tempm1);
CDirLstDel(tempm2);
}
#help_index "Utils;Cmd Line (Typically)"
U0 LstNewFilesLst(CDirEntry *tempm,CDate cdt)
{
while (tempm) {
if (tempm->datetime>cdt) {
"" tempm->full_name;
NewLine;
}
LstNewFilesLst(tempm->sub,cdt);
tempm=tempm->next;
}
}
public U0 LstNewFiles(U8 *files_find_mask="/TempleOS/*",CDate cdt=0,
U8 *fu_flags=NULL)
//"+T"=is just text files
{
I64 fuf_flags=0;
CDirEntry *tempm1=NULL;
if (!cdt)
cdt=sys_compile_time;
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+T");
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (tempm1=FilesFind(files_find_mask,fuf_flags)) {
LstNewFilesLst(tempm1,cdt);
CDirLstDel(tempm1);
}
}
#help_index ""
+200
View File
@@ -0,0 +1,200 @@
#help_index "Debugging/Profiler;Utils/Profiler;Profiler"
#help_file "::/TempleOS/Doc/Profiler"
#define PF_ARRAY_CNT 0x100000
I64 pf_time_start,pf_time_end;
I64 pf_low=0,pf_high=SYS_KERNEL_END,pf_size=PF_ARRAY_CNT;
I64 *pf_array=NULL;
I64 pf_cpu=0;
U0 (*fp_chained_timer_routine)(CTask *task)=cpu_structs[pf_cpu].timer_irq_chain;
I64 pf_ptr,pf_depth;
#define PFM_OFF 0
#define PFM_BIN 1
#define PFM_ALL 2
I64 prof_mode=PFM_OFF;
F64 pf_t0;
U0 ProfTimerInt(CTask *task)
{
I64 i,j=task->rip,k;
nobound_switch (prof_mode) {
case PFM_OFF:
break;
case PFM_BIN:
i=(j-pf_low) * pf_size/(pf_high-pf_low);
if (0<=i<pf_size)
pf_array[i]++;
break;
case PFM_ALL:
for (k=0;k<=pf_depth;k++) {
if (task==Gs->idle_task)
j=SYS_IDLE_PT;
else
j=TaskCaller(task,k,TRUE);
if (pf_ptr<PF_ARRAY_CNT) {
pf_array[pf_ptr++]=j;
if (pf_ptr==PF_ARRAY_CNT)
pf_time_end=sys_jiffies;
}
}
break;
}
(*fp_chained_timer_routine)(task);
}
cpu_structs[pf_cpu].timer_irq_chain=&ProfTimerInt;
public U0 ProfBin(U8 *start,I64 cnt=PF_ARRAY_CNT*3)
//Start profiler in bin mode. Profilers
//report where time is spent by checking
//the instruction ptr during the
//timer interrupt. Do a $LK,"ProfRep","MN:ProfRep"$(), (profiler report)
//after you have collected data.
{
if (cnt<PF_ARRAY_CNT)
pf_size=cnt;
else
pf_size=PF_ARRAY_CNT;
pf_low=start;
pf_high=start+cnt;
if (!pf_array)
pf_array=AMAlloc(sizeof(I64)*PF_ARRAY_CNT);
MemSet(pf_array,0,PF_ARRAY_CNT*sizeof(I64));
pf_time_end=0;
pf_time_start=sys_jiffies;
prof_mode=PFM_BIN;
pf_t0=tT;
}
public U0 ProfCPUSet(I64 num)
{
if (num>=mp_cnt)
ST_ERR_ST "Invalid CPU\n";
else if (cpu_structs[pf_cpu].timer_irq_chain!=&ProfTimerInt)
ST_ERR_ST "Unchaining not implemented!\n";
else {
cpu_structs[pf_cpu].timer_irq_chain=fp_chained_timer_routine;
pf_cpu=num;
fp_chained_timer_routine=cpu_structs[pf_cpu].timer_irq_chain;
cpu_structs[pf_cpu].timer_irq_chain=&ProfTimerInt;
}
}
public U0 ProfAll(I64 depth=0)
//Start profiler in record-all mode. Profilers
//report where time is spent by checking
//the instruction ptr during the
//timer interrupt. Do a $LK,"ProfRep","MN:ProfRep"$(), (profiler report)
//after you have collected data.
{
pf_depth=depth;
pf_ptr=0;
if (!pf_array)
pf_array=AMAlloc(sizeof(I64)*PF_ARRAY_CNT);
pf_time_end=0;
pf_time_start=sys_jiffies;
prof_mode=PFM_ALL;
pf_t0=tT;
}
I64 PFACompare(U8 *i1,U8 *i2)
{
if (i1<i2)
return -1;
else if (i1>i2)
return 1;
else
return 0;
}
public U0 ProfRep(I64 filter_cnt=1)
{
F64 pf_tf=tT;
I64 i,ip,last_ip=pf_low,hits,
total_time,routine_total=0,old_mode=prof_mode;
U8 buf[128],buf2[128],buf3[128],last_buf[128];
prof_mode=PFM_OFF;
if (pf_time_end)
total_time=pf_time_end-pf_time_start;
else
total_time=sys_jiffies-pf_time_start;
if (!total_time) total_time=1;
switch (old_mode) {
case PFM_BIN:
*last_buf=0;
for (i=0;i<pf_size;i++) {
ip=pf_low+i*(pf_high-pf_low)/pf_size;
SPrintF(buf,"%P",ip);
StrCpy(buf3,buf);
StrFirstRem(buf3,"+",buf2);
if (StrCmp(buf2,last_buf)) {
if (*last_buf && routine_total>=filter_cnt) {
"$$FG,GREEN$$%3d.%02d%% %08X:",routine_total*100/total_time,
routine_total*10000/total_time%100,routine_total;
"%s\n$$FG$$",last_buf;
}
StrCpy(last_buf,buf2);
routine_total=0;
}
hits=pf_array[i];
routine_total+=hits;
if (hits>=filter_cnt) {
"%3d.%02d%% %08X:",hits*100/total_time,
hits*10000/total_time%100,hits;
if (!PutSrcLink(ip,ip-last_ip))
"%s\n",buf;
else
NewLine;
last_ip=ip;
}
}
if (*last_buf && routine_total>=filter_cnt) {
"$$FG,GREEN$$%3d.%02d%% %08X:",routine_total*100/total_time,
routine_total*10000/total_time%100,routine_total;
"%s\n$$FG$$",last_buf;
}
break;
case PFM_ALL:
QSortI64(pf_array,pf_ptr,&PFACompare);
*last_buf=0;
for (i=0;i<pf_ptr;i++) {
ip=pf_array[i];
hits=0;
while (pf_array[i]==ip) {
hits++;
i++;
if (i>=pf_ptr) break;
}
SPrintF(buf,"%P",ip);
StrCpy(buf3,buf);
StrFirstRem(buf3,"+",buf2);
if (StrCmp(buf2,last_buf)) {
if (*last_buf && routine_total>=filter_cnt) {
"$$FG,GREEN$$%3d.%02d%% %08X:",routine_total*100/total_time,
routine_total*10000/total_time%100,routine_total;
"%s\n$$FG$$",last_buf;
}
StrCpy(last_buf,buf2);
routine_total=0;
}
routine_total+=hits;
if (hits>=filter_cnt) {
"%3d.%02d%% %08X:",hits*100/total_time,
hits*10000/total_time%100,hits;
if (!PutSrcLink(ip,ip-last_ip))
"%s\n",buf;
else
NewLine;
last_ip=ip;
}
}
if (*last_buf && routine_total>=filter_cnt) {
"$$FG,GREEN$$%3d.%02d%% %08X:",routine_total*100/total_time,
routine_total*10000/total_time%100,routine_total;
"%s\n$$FG$$",last_buf;
}
break;
}
"Total Time:%12.6fs\n",pf_tf-pf_t0;
}
#help_index ""
+69
View File
@@ -0,0 +1,69 @@
#help_index "Utils;Cmd Line (Typically)"
//$LK,"StrUtil","MN:StrUtil"$() operations on files
public U0 SUFile(U8 *name,I64 su_flags,F64 indent_scale_factor)
{//String utility on a single file
//See $LK,"SU Flags","MN:SUF_SINGLE_SPACE"$
U8 *dst;
Bool chged=FALSE;
I64 reduced=0;
CDoc *doc=DocRead(name,DOCF_PLAIN_TEXT_WITH_TABS | DOCF_NO_CURSOR);
CDocEntry *doc_e=doc->root.next;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_TEXT) {
dst=MStrUtil(doc_e->tag,su_flags,indent_scale_factor);
if (StrCmp(dst,doc_e->tag)) {
reduced+=StrLen(doc_e->tag)-StrLen(dst);
chged=TRUE;
Free(doc_e->tag);
doc_e->tag=dst;
} else
Free(dst);
}
doc_e=doc_e->next;
}
if (chged) {
"Reduced %s by %d chars\n",name,reduced;
StrCpy(doc->filename.name,name);
DocWrite(doc);
}
DocDel(doc);
}
U0 SULst(CDirEntry *tempm1,I64 su_flags,F64 indent_scale_factor)
{
CDirEntry *tempm2;
while (tempm1) {
tempm2=tempm1->next;
if (tempm1->attr & _ATTR_DIR) {
if (tempm1->sub) {
"%S%s\n","ST_SCANNING_DIR",tempm1->full_name;
SULst(tempm1->sub,su_flags,indent_scale_factor);
}
} else
SUFile(tempm1->full_name,su_flags,indent_scale_factor);
CDirEntryDel(tempm1);
tempm1=tempm2;
}
}
public U0 SU(U8 *files_find_mask,I64 su_flags,U8 *fu_flags=NULL,F64 indent_scale_factor=0)
{//Apply string utilities to files
//You can convert spaces to tabs, for example
//or removing trailing spaces on lines.
//See $LK,"SU Flags","MN:SUF_SINGLE_SPACE"$
I64 fuf_flags=0;
GetFFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
SULst(FilesFind(files_find_mask,fuf_flags),su_flags,indent_scale_factor);
}
public U0 S2T(U8 *files_find_mask,U8 *fu_flags=NULL)
{
//Spaces to tabs.
//Use "Hard Space" (SHIFT-SPACE) for spaces
//in string constants in your code.
SU(files_find_mask,SUF_S2T|SUF_REM_TRAILING,fu_flags);
}
#help_index ""
+353
View File
@@ -0,0 +1,353 @@
#help_index "Utils;Cmd Line (Typically);Doc/Html"
//See $LK-A,"::/TempleOS/Doc/Acknowledgements.TXT"$.
U0 HtmlPutS(CDoc *doc,I64 c,I64 *_old_c,U8 *st,I64 *_col,U8 *style_bitmap=NULL)
{
U8 *ch;
if (c!=*_old_c) {
if (*_old_c!=-1)
DocPutS(doc,"</span>");
DocPrintF(doc,"<span class=c%02X>",c);
*_old_c=c;
if (style_bitmap)
LBts(style_bitmap,c);
}
while (ch=*st++) {
switch (ch) {
case '\t':
do {
DocPutKey(doc,CH_SPACE,0);
*_col=*_col+1;
} while (*_col&7);
break;
case '&':
DocPutS(doc,"&amp;");
*_col=*_col+1;
break;
case '<':
DocPutS(doc,"&lt;");
*_col=*_col+1;
break;
case '>':
DocPutS(doc,"&gt;");
*_col=*_col+1;
break;
case '"':
DocPutS(doc,"&quot;");
*_col=*_col+1;
break;
case 'ã':
DocPutS(doc,"pi");
*_col=*_col+1;
break;
case 'é':
DocPutS(doc,"theta");
*_col=*_col+1;
break;
case 'è':
DocPutS(doc,"phi");
*_col=*_col+1;
break;
case 'ê':
DocPutS(doc,"omega");
*_col=*_col+1;
break;
case 'ì':
DocPutS(doc,"inf");
*_col=*_col+1;
break;
case 'æ':
DocPutS(doc,"u");
*_col=*_col+1;
break;
case CH_SHIFT_SPACE:
DocPutS(doc," ");
*_col=*_col+1;
break;
default:
if (CH_SPACE<=ch<0x7F || ch=='\n')
DocPutKey(doc,ch,0);
else
DocPutS(doc,".");
*_col=*_col+1;
}
}
}
U8 *TSLinkCvt2(U8 *filename,I64 line_num)
{ // ::/TempleOS/ --> http://www.templeos.org/Wb/
// Make your own LinkCvt routine
U8 *result=NULL,*st;
if (filename) {
st=ChgExt(filename,"html");
if (st && StrLen(st)>12 && !StrNCmp(st+1,":/TempleOS/",11))
result=MSPrintF("http://www.templeos.org/Wb/%s#l%d",st+12,line_num);
Free(st);
}
return result;
}
U8 *TSLinkCvt1(U8 *link_st)
{
static CDoc *bible=NULL;
static I64 locks=0;
U8 *result=NULL,*filename,*pattern;
I64 i,num;
if (link_st) {
switch (i=EdLinkCvt(link_st,&filename,&pattern,&num)) {
case LK_FILE_LINE:
case LK_PLAIN_LINE:
case LK_FILE:
result=TSLinkCvt2(filename,num);
break;
case -1:
case LK_DEF:
case LK_HELP_INDEX:
break;
case LK_BIBLE_FIND:
while (LBts(&locks,0))
Yield;
if (!bible)
bible=Adam("DocRead(\"%s\");",filename);
if (DocPatternFind(bible,num,pattern))
result=TSLinkCvt2(filename,bible->cur_entry->y+1);
LBtr(&locks,0);
break;
default:
if (DocFileEd(i,filename,pattern,&num,EDF_UNCOLLAPSE|EDF_BAIL))
result=TSLinkCvt2(filename,num);
}
Free(filename);
Free(pattern);
}
return result;
}
public CDoc *Doc2Html(CDoc *doc_in,
U8 *html_header=NULL,
U8 *body_header=NULL,U8 *body_footer=NULL,Bool line_anchors=TRUE,
U8 (*link_cvt)(U8 *link_st)=&TSLinkCvt1)
{
CDocEntry *doc_e,*style,*doc_e2;
CDocSettings *s;
I64 i,y,old_y=MIN_I64,cur_u8_attr,col,old_c=-1,old_attr;
U32 *hl,*src;
U8 *st,st_2[2],*link_st,*style_bitmap=CAlloc(256/8);
CBGR p[16];
GetVGAPalette4(p);
CDoc *doc_out=DocNew;
Bool unlock_doc_in=DocLock(doc_in),no_backward;
old_attr=doc_in->win_task->text_attr;
doc_in->win_task->text_attr=DOC_ATTR_DFT_TEXT;
for (i=0xF0;i<=0xFF;i++)
LBts(style_bitmap,i);
DocRecalc(doc_in);
st_2[0]=0; st_2[1]=0;
doc_out->flags|=DOCF_PLAIN_TEXT|DOCF_NO_CURSOR;
if (!html_header) html_header="";
if (!body_header) body_header="";
if (!body_footer) body_footer="";
DocPrintF(doc_out,
"<!DOCTYPE HTML>\n"
"<html>\n"
"<head>\n"
"<meta http-equiv=\"Content-Type\" content=\"text/html;charset=US-ASCII\">\n"
"%s"
"<meta name=\"generator\" content=\"TempleOS V%4.2f\">\n"
"<style type=\"text/css\">\n",html_header,os_version);
style=doc_out->cur_entry->last;
DocPutS(doc_out,
"</style>\n"
"</head>\n"
"<body>\n"
"<pre style=\"font-family:courier;font-size:10pt\">\n");
DocPutS(doc_out,body_header);
doc_e=doc_in->root.next;
s=DocSettingsLast(doc_e);
col=doc_e->x;
y=doc_e->y;
cur_u8_attr=doc_e->type.u8[1];
while (doc_e!=doc_in) {
if (!(doc_e->flags1&(DOCEF1_SKIP|DOCEF1_HARD_SKIP))) {
if (line_anchors && y!=old_y) {
DocPrintF(doc_out,"<a name=\"l%d\"></a>",y+1);
old_y=y;
}
while (y<doc_e->y) {
HtmlPutS(doc_out,cur_u8_attr,&old_c,"\n",&col,style_bitmap);
y++;
if (line_anchors && y!=old_y) {
DocPrintF(doc_out,"<a name=\"l%d\"></a>",y+1);
old_y=y;
}
col=0;
}
no_backward=TRUE;
doc_e2=doc_e->next;
while (doc_e2!=doc_in && doc_e2->y==doc_e->y) {
if (doc_e2->x<doc_e->x) {
no_backward=FALSE;
break;
}
doc_e2=doc_e2->next;
}
if (no_backward)
while (col<doc_e->x)
HtmlPutS(doc_out,cur_u8_attr,&old_c," ",&col,style_bitmap);
link_st=NULL;
if (doc_e->flags1&DOCEF1_HTML_LINK)
link_st=StrNew(doc_e->html_link);
else if (st=DocEntryLink(doc_in,doc_e)) {
link_st=link_cvt(st);
Free(st);
}
if (link_st) {
if (old_c!=-1) {
DocPutS(doc_out,"</span>");
old_c=-1;
}
DocPrintF(doc_out,"<a href=\"%s\">",link_st);
}
if (doc_e->settings)
s=doc_e->settings;
cur_u8_attr=doc_e->type.u8[1];
switch (doc_e->type_u8) {
case DOCT_TEXT:
if (doc_e->flags1&DOCEF1_HIGHLIGHT) {
src=hl=DocHighlight(doc_in,FALSE,doc_e,&s,doc_e->tag,StrLen(doc_e->tag),cur_u8_attr<<8);
while (*src) {
st_2[0]=*src&0xFF;
HtmlPutS(doc_out,*src>>8,&old_c,st_2,&col,style_bitmap);
src++;
}
Free(hl);
} else
HtmlPutS(doc_out,cur_u8_attr,&old_c,doc_e->tag,&col,style_bitmap);
break;
case DOCT_TAB:
HtmlPutS(doc_out,cur_u8_attr,&old_c,"\t",&col,style_bitmap);
break;
case DOCT_HTML_IMG:
if (old_c!=-1) {
DocPutS(doc_out,"</span>");
old_c=-1;
}
DocPrintF(doc_out,"<img src=\"%s\" width=\"640\" height=\"480\" alt=\"\">\n",doc_e->tag);
break;
case DOCT_HTML_VIDEO:
if (old_c!=-1) {
DocPutS(doc_out,"</span>");
old_c=-1;
}
DocPrintF(doc_out,
"<!--begin exclude-->\n"
"<object classid=\"clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" "
"codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab\" "
"width=\"640\" height=\"512\">\n"
"<param name=\"FileName\" value=\"%s\">\n"
"<param name=\"AutoStart\" value=\"false\">\n"
"<param name=\"ShowTracker\" value=\"true\">\n"
"<param name=\"ShowControls\" value=\"true\">\n"
"<param name=\"ShowGotoBar\" value=\"false\">\n"
"<param name=\"ShowDisplay\" value=\"false\">\n"
"<param name=\"ShowStatusBar\" value=\"false\">\n"
"<param name=\"AutoSize\" value=\"false\">\n"
"<embed src=\"%s\" AutoStart=\"false\" ShowTracker=\"true\" ShowControls=\"true\" "
"ShowGotoBar=\"false\" ShowDisplay=\"false\" ShowStatusBar=\"false\" "
"AutoSize=\"false\" pluginspage=\"http://www.microsoft.com/windows/windowsmedia/download/\" "
"width=\"640\" height=\"512\"></embed></object>\n"
"<!--end exclude-->\n",doc_e->tag,doc_e->tag);
break;
case DOCT_HTML_CODE:
if (old_c!=-1) {
DocPutS(doc_out,"</span>");
old_c=-1;
}
DocPutS(doc_out,doc_e->tag);
break;
case DOCT_SPRITE:
HtmlPutS(doc_out,cur_u8_attr,&old_c,doc_e->tag,&col,style_bitmap);
HtmlPutS(doc_out,DOC_COLOR_COMMENT+old_c&0xF0,&old_c,"/* Graphics Not Rendered in HTML */",&col,style_bitmap);
break;
default:
if (Bt(doc_tag_types,doc_e->type_u8))
HtmlPutS(doc_out,cur_u8_attr,&old_c,doc_e->tag,&col,style_bitmap);
}
if (link_st) {
if (old_c!=-1) {
DocPutS(doc_out,"</span>");
old_c=-1;
}
DocPutS(doc_out,"</a>");
Free(link_st);
}
}
doc_e=doc_e->next;
}
while (y<doc_e->y) {
HtmlPutS(doc_out,cur_u8_attr,&old_c,"\n",&col,style_bitmap);
y++;
col=0;
}
if (old_c!=-1) {
DocPutS(doc_out,"</span>");
old_c=-1;
}
DocPutS(doc_out,body_footer);
DocPutS(doc_out,"</pre></body>\n</html>\n");
doc_out->cur_entry=style->next;
for (i=0;i<256;i++)
if (Bt(style_bitmap,i))
DocPrintF(doc_out,".c%02X{color:#%02x%02x%02x;background-color:#%02x%02x%02x;}\n",i,p[i&15].r,p[i&15].g,p[i&15].b,p[i/16].r,p[i/16].g,p[i/16].b);
doc_out->cur_entry=&doc_out->root;
DocRecalc(doc_out);
doc_in->win_task->text_attr=old_attr;
if (unlock_doc_in)
DocUnlock(doc_in);
return doc_out;
}
public U0 ToHtml(U8 *_in_name,U8 *_out_name=NULL,U8 *html_header=NULL,
U8 *body_header=NULL,U8 *body_footer=NULL,I64 width=80,
Bool line_anchors=TRUE,U8 (*link_cvt)(U8 *link_st)=&TSLinkCvt1)
//Supply your own link_cvt routine.
{
U8 *in_name,*out_name;
CDoc *doc_in,*doc_out;
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
SetWinHorz(0,width-1); //This sets doc width for word wrap
in_name=DftExt(_in_name,"CPP.Z"),
if (_out_name)
out_name=DftExt(_out_name,"html");
else
out_name=ChgExt(_in_name,"html");
doc_in=DocRead(in_name);
doc_out=Doc2Html(doc_in,html_header,body_header,body_footer,line_anchors,link_cvt);
StrCpy(&doc_out->filename.name,out_name);
SettingsPop;
DocWrite(doc_out);
DocDel(doc_in);
DocDel(doc_out);
Free(in_name);
Free(out_name);
}
#help_index ""
+149
View File
@@ -0,0 +1,149 @@
#help_index "Utils;Cmd Line (Typically)"
U0 TXTPutS(CDoc *doc,U8 *st,I64 *_col)
{
U8 *ch;
while (ch=*st++) {
switch (ch) {
case '\t':
do {
DocPutKey(doc,CH_SPACE,0);
*_col=*_col+1;
} while (*_col&7);
break;
case 'ã':
DocPutS(doc,"pi");
*_col=*_col+1;
break;
case 'é':
DocPutS(doc,"theta");
*_col=*_col+1;
break;
case 'è':
DocPutS(doc,"phi");
*_col=*_col+1;
break;
case 'ê':
DocPutS(doc,"omega");
*_col=*_col+1;
break;
case 'ì':
DocPutS(doc,"inf");
*_col=*_col+1;
break;
case 'æ':
DocPutS(doc,"u");
*_col=*_col+1;
break;
case CH_SHIFT_SPACE:
DocPutS(doc," ");
*_col=*_col+1;
break;
default:
if (CH_SPACE<=ch<0x7F || ch=='\n')
DocPutKey(doc,ch,0);
else
DocPutS(doc,".");
*_col=*_col+1;
}
}
}
public CDoc *Doc2TXT(CDoc *doc_in)
{
CDocEntry *doc_e,*doc_e2;
I64 y,col;
CDoc *doc_out=DocNew;
Bool unlock_doc_in=DocLock(doc_in),no_backward;
DocRecalc(doc_in);
doc_out->flags|=DOCF_PLAIN_TEXT|DOCF_NO_CURSOR;
doc_e=doc_in->root.next;
col=doc_e->x;
y=doc_e->y;
while (doc_e!=doc_in) {
if (!(doc_e->flags1&(DOCEF1_SKIP|DOCEF1_HARD_SKIP))) {
while (y<doc_e->y) {
TXTPutS(doc_out,"\n",&col);
y++;
col=0;
}
no_backward=TRUE;
doc_e2=doc_e->next;
while (doc_e2!=doc_in && doc_e2->y==doc_e->y) {
if (doc_e2->x<doc_e->x) {
no_backward=FALSE;
break;
}
doc_e2=doc_e2->next;
}
if (no_backward)
while (col<doc_e->x)
TXTPutS(doc_out," ",&col);
switch (doc_e->type_u8) {
case DOCT_TEXT:
TXTPutS(doc_out,doc_e->tag,&col);
break;
case DOCT_TAB:
TXTPutS(doc_out,"\t",&col);
break;
case DOCT_HTML_IMG:
break;
case DOCT_HTML_VIDEO:
break;
case DOCT_HTML_CODE:
break;
case DOCT_SPRITE:
break;
default:
if (Bt(doc_tag_types,doc_e->type_u8))
TXTPutS(doc_out,doc_e->tag,&col);
}
}
doc_e=doc_e->next;
}
while (y<doc_e->y) {
TXTPutS(doc_out,"\n",&col);
y++;
col=0;
}
doc_out->cur_entry=&doc_out->root;
DocRecalc(doc_out);
if (unlock_doc_in)
DocUnlock(doc_in);
return doc_out;
}
public U0 ToTXT(U8 *_in_name,U8 *_out_name=NULL,I64 width=70)
{
U8 *in_name,*out_name;
CDoc *doc_in,*doc_out;
SettingsPush; //See $LK,"SettingsPush","MN:SettingsPush"$
SetWinHorz(0,width-1); //This sets doc width for word wrap
in_name=DftExt(_in_name,"TXT.Z"),
if (_out_name)
out_name=DftExt(_out_name,"TXT");
else
out_name=ChgExt(_in_name,"TXT");
doc_in=DocRead(in_name);
doc_out=Doc2TXT(doc_in);
StrCpy(&doc_out->filename.name,out_name);
SettingsPop;
DocWrite(doc_out);
DocDel(doc_in);
DocDel(doc_out);
Free(in_name);
Free(out_name);
}
#help_index ""