TempleOSTS_140317.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:02 +02:00
1 parent 2d2a65d572
commit 7ef616a20e
1416 files changed
+223873 -53917

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
#help_index "Compiler"
DefineLstLoad("ST_BIN_FILE_TYPES",
"END\0 \0"
"REL_EXPORT\0"
"IMM_EXPORT\0"
"REL_I8\0"
"IMM_U8\0"
"REL_I16\0"
"IMM_U16\0"
"REL_I32\0"
"IMM_U32\0"
"REL_I64\0"
"IMM_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",A="FF:::/Compiler/CmpMain.CPP,EIT_MODULE_ALIGNMENT"$ and $LK,"Load",A="MN:Load"$().
U8 *fbuf,*ptr,*sptr,*absname;
I64 i,j,size,etype;
CBinFile *bfh;
CHashExport *saved_hash_ptr=NULL;
fbuf=DftExt(filename,"BIN.Z");
if (!(bfh=FileRead(fbuf,&size))) {
Free(fbuf);
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:$$GREEN$$%s$$FG$$:%X ",etype,"ST_BIN_FILE_TYPES",sptr,i;
switch (etype) {
case EIT_REL_I8...EIT_IMM_U64:
if (*sptr)
saved_hash_ptr=HashFind(sptr,Fs->hash_table,HTG_ALL);
if (!saved_hash_ptr)
"Unresolved Reference:%s\n",sptr;
break;
case EIT_ABS_ADDR:
NewLine;
for (j=0;j<i;j++)
"%X ",*ptr(U32 *)++;
break;
case EIT_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 ""
+349
View File
@@ -0,0 +1,349 @@
#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 PopUpDiffMenu()
{
I64 i;
CDoc *doc=DocNew;
DocPrint(doc,"$$CM+LX,2,4$$$$FG$$$$BT,\"USE FILE1\",LE=DS_USE_FILE1$$"
"$$CM+LX,24,0$$$$CYAN$$$$BT,\"USE FILE2\",LE=DS_USE_FILE2$$"
"$$CM+LX,2,4$$$$FG$$$$BT,\"REMAINDER ALL FILE1\",LE=DS_REMAINDER_1$$"
"$$CM+LX,24,0$$$$CYAN$$$$BT,\"REMAINDER ALL FILE2\",LE=DS_REMAINDER_2$$"
"$$CM+LX,2,4$$$$FG$$$$BT,\"ABORT FILE\",LE=DS_ABORT_FILE$$"
"$$CM+LX,24,0$$$$FG$$$$BT,\"ABORT ALL FILES\",LE=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 0x01
#define DF_DONT_MODIFIED 0x02
#define DF_REMAINDER_ALL_FILE1 0x04
#define DF_REMAINDER_ALL_FILE2 0x08
#define DF_ABORT_FILE 0x10
#define DF_ABORT_ALL_FILES 0x20
#define DF_NO_MORE_PMTS_THIS_FILE 0x40
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_unsorted1,CDocEntry **doc_unsorted2)
{
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))) {
"$$RED$$";
if (0<=j1_lo<cnt1)
"%d,",doc_unsorted1[j1_lo]->y+1;
else if (0<=j1_hi-1<cnt1)
"%d,",doc_unsorted1[j1_hi-1]->y+1;
else
"***,";
if (0<=j2_lo<cnt2)
"%d",doc_unsorted2[j2_lo]->y+1;
else if (0<=j2_hi-1<cnt2)
"%d",doc_unsorted2[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;
}
"%s",doc_unsorted1[i++]->tag;
if (cur_l)
cur_l->flags= cur_l->flags&~DOCF_PLAIN_TEXT |old_flags;
NewLine;
}
"$$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;
}
"%s",doc_unsorted2[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 (PopUpDiffMenu) {
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_unsorted1[j1_lo]->last;
if (j1_lo<j1_hi) {
doc_e=doc_unsorted1[j1_lo];
while (doc_e!=doc_unsorted1[j1_hi]) {
doc_e2=doc_e->next;
DocEntryDel(doc,doc_e);
doc_e=doc_e2;
}
}
if (j2_lo<j2_hi) {
doc_e=doc_unsorted2[j2_lo];
while (doc_e!=doc_unsorted2[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_sorted1,CDocEntry **doc_sorted2,
CDocEntry **doc_unsorted1,CDocEntry **doc_unsorted2)
{
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_unsorted1,doc_unsorted2);
return TRUE;
} else
return FALSE;
}
//Locate longest matching str in intervals
while (i1<cnt1 && i2<cnt2) {
if (!(j1_lo<=doc_sorted1[i1]->user_data<j1_hi)) //user_data is the new y
i1++;
else if (!(j2_lo<=doc_sorted2[i2]->user_data<j2_hi)) //user_data is the new y
i2++;
else {
i=StrCmp(doc_sorted1[i1]->tag,doc_sorted2[i2]->tag);
if (i>0)
i2++;
else if (i<0)
i1++;
else {
i2b=i2;
while (!StrCmp(doc_sorted1[i1]->tag,doc_sorted2[i2]->tag)) {
if (j2_lo<=doc_sorted2[i2]->user_data<j2_hi) { //user_data is the new y
score=0;
j1=doc_sorted1[i1]->user_data; //user_data is the new y
j2=doc_sorted2[i2]->user_data; //user_data is the new y
n=j1_hi-j1;
if (j2_hi-j2<n)
n=j2_hi-j2;
while (score<n) {
if (!StrCmp(doc_unsorted1[j1+score]->tag,
doc_unsorted2[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_unsorted1,doc_unsorted2);
return TRUE;
} else {
if (DiffSub(doc,_df_flags,j1_lo,best_j1,j2_lo,best_j2,cnt1,cnt2,
doc_sorted1,doc_sorted2,doc_unsorted1,doc_unsorted2))
result=TRUE;
if (DiffSub(doc,_df_flags,best_j1+best_score,j1_hi,best_j2+best_score,j2_hi,cnt1,cnt2,
doc_sorted1,doc_sorted2,doc_unsorted1,doc_unsorted2))
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->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,"Merge",A="MN:Merge"$().
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_sorted1,**doc_sorted2,**doc_unsorted1,**doc_unsorted2;
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->user_data=cnt1++; //user_data 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->user_data=cnt2++; //user_data is the new y
doc_e=doc_e->next;
}
doc_sorted1=MAlloc(cnt1*sizeof(CDocEntry *));
doc_unsorted1=MAlloc((cnt1+1)*sizeof(CDocEntry *));
i=0;
doc_e=doc1->root.next;
while (doc_e!=doc1) {
if (doc_e->type_u8==DOCT_TEXT) {
doc_sorted1[i]=doc_e;
doc_unsorted1[i++]=doc_e;
}
doc_e=doc_e->next;
}
doc_unsorted1[i]=doc1;
QSortI64(doc_sorted1,cnt1,&DiffEntriesCompare);
doc_sorted2=MAlloc(cnt2*sizeof(CDocEntry *));
doc_unsorted2=MAlloc((cnt2+1)*sizeof(CDocEntry *));
i=0;
doc_e=doc2->root.next;
while (doc_e!=doc2) {
if (doc_e->type_u8==DOCT_TEXT) {
doc_sorted2[i]=doc_e;
doc_unsorted2[i++]=doc_e;
}
doc_e=doc_e->next;
}
doc_unsorted2[i]=doc2;
QSortI64(doc_sorted2,cnt2,&DiffEntriesCompare);
result=DiffSub(doc1,&df_flags,0,cnt1,0,cnt2,cnt1,cnt2,
doc_sorted1,doc_sorted2,doc_unsorted1,doc_unsorted2);
if (df_flags&DF_MODIFIED && !(df_flags&DF_DONT_MODIFIED))
DocWrite(doc1);
if (DiffBins(doc1,doc2)) {
"$$RED$$Bin Data is Different$$FG$$\n";
result=TRUE;
}
DocDel(doc1);
DocDel(doc2);
Free(doc_sorted1);
Free(doc_sorted2);
Free(doc_unsorted1);
Free(doc_unsorted2);
if (_df_flags)
*_df_flags=df_flags;
return result;
}
#help_index "Utils;Cmd Line (Typically);Info"
I64 ZRepCompare(CDirEntry *e1,CDirEntry *e2)
{
return SignI64(e2->user_data(F64)-e1->user_data(F64));
}
public U0 ZipRep(U8 *files_find_mask="/*",U8 *fu_flags=NULL,
Bool just_text_not_graphics=TRUE)
{//Report of compressibility. Dft is just src files.
//(Used to spot src files with redundancy in them.)
I64 i=0,cnt,size,fuf_flags=0;
CDirEntry *tempde,*tempde1,**sort_buf;
U8 *buf;
CArcCompress *ac;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+F+S");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tempde=tempde1=FilesFind(files_find_mask,fuf_flags);
cnt=FileCnt(tempde);
sort_buf=MAlloc(sizeof(CDirEntry *)*cnt);
while (tempde) {
sort_buf[i++]=tempde;
buf=FileRead(tempde->full_name,&size);
if (just_text_not_graphics)
size=StrLen(buf);
ac=CompressBuf(buf,size);
Free(buf);
tempde->user_data(F64)=100.0*ac->compressed_size/ac->expanded_size;
Free(ac);
tempde=tempde->next;
}
QSortI64(sort_buf,cnt,&ZRepCompare);
for (i=0;i<cnt;i++) {
"%4.1f%% %04X ",sort_buf[i]->user_data,sort_buf[i]->size;
PutFileLink(sort_buf[i]->full_name);
NewLine;
}
Free(sort_buf);
DirLstDel(tempde1);
}
#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_pixs_per_meter;
U32 y_pixs_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(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/Sprite;Graphics/Windows BMP Files;Doc/Output"
public U0 DocBMPFile(CDoc *doc=NULL,U8 *filename,Bool use_ms_paint_palette=FALSE)
{//Put a BMP file into a document as a sprite.
CDC *dc=BMPFileRead(filename,use_ms_paint_palette);
CSprite *elems=DC2Sprite(dc);
DocSprite(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 ""
+251
View File
@@ -0,0 +1,251 @@
#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 PopUpGrepMenu()
{
I64 i;
CDoc *doc=DocNew;
DocPrint(doc,"$$CM+LX,2,4$$$$BT,\"REPLACE\",LE=GRF_REPLACE$$"
"$$CM+LX,22,0$$$$BT,\"SKIP\",LE=GRF_SKIP$$"
"$$CM+LX,2,4$$$$BT,\"ALL\",LE=GRF_ALL$$"
"$$CM+LX,22,0$$$$BT,\"ABORT ALL\",LE=DOCM_CANCEL$$"
"$$CM+LX,2,4$$$$BT,\"EDIT\",LE=GRF_ED$$"
"$$CM+LX,22,0$$$$BT,\"ABORT FILE\",LE=GRF_ABORT_FILE$$"
"$$CM+LX,2,4$$$$BT,\"SKIP FILE\",LE=GRF_SKIP_FILE$$\n");
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
I64 GrepFile(U8 *needle_str,U8 *haystack_filename,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(haystack_filename,DOCF_PLAIN_TEXT_WITH_TABS|DOCF_NO_CURSOR);
CDocEntry *doc_e;
if (Bt(_fuf_flags,FUf_IGNORE))
ss_flags=SFF_IGNORE_CASE;
else
ss_flags=0;
if (Bt(_fuf_flags,FUf_WHOLE_LABELS))
ss_flags|=SFG_WHOLE_LABELS;
if (Bt(_fuf_flags,FUf_WHOLE_LABELS_BEFORE))
ss_flags|=SFF_WHOLE_LABELS_BEFORE;
if (Bt(_fuf_flags,FUf_WHOLE_LABELS_AFTER))
ss_flags|=SFF_WHOLE_LABELS_AFTER;
plen=StrLen(needle_str);
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=StrFind(needle_str,src,ss_flags)) {
cnt++;
if (first_on_line || Bt(_fuf_flags,FUf_REPLACE)) {
first_on_line=FALSE;
PutFileLink(haystack_filename,doc_e->y+1,TRUE);
name_buf=MPrint("%s,%d",haystack_filename,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=PopUpGrepMenu;
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",haystack_filename,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;
}
public I64 Grep(U8 *needle_str,U8 *files_find_mask="*",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.
"+lb"=only checks for label chars before.
"+la"=only checks for label chars after.
*/
{
I64 cnt=0,fuf_flags=0;
CDirEntry *tempde,*tempde1;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+i+f+F+T");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (fuf_flags&~(FUG_FILES_FIND|FUF_IGNORE|FUF_ALL|FUF_WHOLE_LABELS|FUF_WHOLE_LABELS_BEFORE|FUF_WHOLE_LABELS_AFTER))
throw('FUF');
LBEqu(&fuf_flags,FUf_REPLACE,replace_text);
tempde=tempde1=FilesFind(files_find_mask,fuf_flags&FUG_FILES_FIND);
fuf_flags&=FUF_ALL|FUF_REPLACE|FUF_IGNORE|FUF_WHOLE_LABELS|FUF_WHOLE_LABELS_BEFORE|FUF_WHOLE_LABELS_AFTER;
while (tempde && !Bt(&fuf_flags,FUf_CANCEL)) {
cnt+=GrepFile(needle_str,tempde->full_name,&fuf_flags,replace_text);
tempde=tempde->next;
}
DirLstDel(tempde1);
return cnt;
}
public I64 FileOcc(U8 *needle_str,U8 *files_find_mask="*",U8 *fu_flags="+r+i+l")
{/*
"+r"=recurse
"+i"=ignore case
"+l"=whole labels only.
"+lb"=only checks for label chars before.
"+la"=only checks for label chars after.
*/
I64 cnt=0;
Bool old_silent=Silent(TRUE);
cnt=Grep(needle_str,files_find_mask,fu_flags);
Silent(old_silent);
return cnt;
}
class CGrep
{
U8 find_text[136] fmtstr "$$DA-P,135,A=\"FIND :%s\"$$\n";
U8 replace_text[136] fmtstr "$$DA-P,135,A=\"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,A=\"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,FILEMASK_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,,0,"$$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)
CatPrint(buf,"-i");
if (!g->recurse)
CatPrint(buf,"-r");
if (g->whole_labels)
CatPrint(buf,"+l");
if (g->replace)
st=MPrint("\"$$$$WW+H,1$$$$\";Cd(\"%s\");Grep(\"%Q\",\"%Q\",\"%Q\",\"%Q\");UserTaskCont;",dir,g->find_text,g->filemask,buf,g->replace_text);
else
st=MPrint("\"$$$$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 ""
+137
View File
@@ -0,0 +1,137 @@
#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
CHeapCtrl *heaplog_hc_watched,*heaplog_hc=NULL;
CHeapLogHash *heaplog_root=NULL;
U0 HeapLogMAlloc(U8 *addr)
{
CHeapLog *temphl;
I64 i;
if (MHeapCtrl(addr)==heaplog_hc_watched) {
temphl=MAlloc(sizeof(CHeapLog),heaplog_hc);
temphl->addr=addr;
temphl->caller1=Caller(2);
temphl->caller2=Caller(3);
temphl->caller3=Caller(4);
temphl->caller4=Caller(5);
i=addr>>3 &(HEAPLOG_HASH_SIZE-1);
PUSHFD
CLI
while (LBts(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0))
PAUSE
QueIns(temphl,heaplog_root[i].last);
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
POPFD
}
}
U0 HeapLogFree(U8 *addr)
{
I64 i;
CHeapLog *temphl;
if (!addr) return;
if (MHeapCtrl(addr)==heaplog_hc_watched) {
i=addr>>3 &(HEAPLOG_HASH_SIZE-1);
PUSHFD
CLI
while (LBts(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0))
PAUSE
temphl=heaplog_root[i].next;
while (temphl!=&heaplog_root[i]) {
if (addr==temphl->addr) {
QueRem(temphl);
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
POPFD
Free(temphl);
return;
}
temphl=temphl->next;
}
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
POPFD
}
}
public U0 HeapLogRep()
{
I64 i,total=0;
CHeapLog *temphl,hl;
if (!LBtr(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0)) {
"HeapLog Not Active\n";
return;
}
"$$WW,0$$";
while (LBts(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0))
PAUSE
for (i=0;i<HEAPLOG_HASH_SIZE;i++) {
temphl=heaplog_root[i].next;
while (temphl!=&heaplog_root[i]) {
//Take snapshot in case modified. (while we work)
MemCpy(&hl,temphl,sizeof(CHeapLog));
"$$PURPLE$$%08X$$FG$$ %08X %P %P %P %P\n",MSize(hl.addr),hl.addr,
hl.caller1,hl.caller2,hl.caller3,hl.caller4;
total+=MSize(hl.addr);
temphl=hl.next;
}
}
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
"\n$$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_watched=task->data_heap;
else
heaplog_hc_watched=task;
PUSHFD
CLI
while (LBts(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0))
PAUSE
heaplog_hc=HeapCtrlInit(,,sys_data_bp);
ext[EXT_HEAPLOG_MALLOC]=&HeapLogMAlloc;
ext[EXT_HEAPLOG_FREE]=&HeapLogFree;
heaplog_root=MAlloc(sizeof(CHeapLogHash)*HEAPLOG_HASH_SIZE,heaplog_hc);
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 {
HeapCtrlDel(heaplog_hc);
heaplog_root=heaplog_hc=NULL;
ext[EXT_HEAPLOG_MALLOC]=NULL;
ext[EXT_HEAPLOG_FREE]=NULL;
}
}
}
#help_index ""
+111
View File
@@ -0,0 +1,111 @@
#help_index "Utils;Cmd Line (Typically)"
I64 LineRep1(CDirEntry *tempde)
{
CDoc *doc;
I64 result=0,i;
while (tempde) {
i=0;
if (tempde->attr&_ATTR_DIR)
i=LineRep1(tempde->sub);
else {
doc=DocRead(tempde->full_name);
if (doc->root.next!=doc)
i=doc->root.last->y+2;
DocDel(doc);
}
tempde->user_data=i;
result+=i;
tempde=tempde->next;
}
return result;
}
U0 LineRep2(CDoc *doc,CDirEntry *tempde)
{
while (tempde) {
if (tempde->attr&_ATTR_DIR) {
DocPrint(doc,"%8,d $$TR+C,\"%s\"$$\n$$ID,2$$",tempde->user_data,tempde->name);
LineRep2(doc,tempde->sub);
DocPrint(doc,"$$ID,-2$$");
} else
DocPrint(doc,"%8,d $$LK,\"%s\",A=\"FI:%s\"$$\n",
tempde->user_data,tempde->name,tempde->full_name);
tempde=tempde->next;
}
}
public I64 LineRep(U8 *files_find_mask="/*",U8 *fu_flags=NULL)
{
I64 fuf_flags=0,result=0;
CDoc *doc=DocNew;
CDirEntry *tempde1=NULL;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+S");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (tempde1=FilesFind(files_find_mask,fuf_flags)) {
result=LineRep1(tempde1);
DocPrint(doc,"%8,d $$TR+C,\"%s\"$$\n$$ID,2$$",result,files_find_mask);
LineRep2(doc,tempde1);
DocPrint(doc,"$$ID,-2$$");
DirLstDel(tempde1);
}
DocInsDoc(DocPut,doc);
DocDel(doc);
return result;
}
I64 SizeRep1(CDirEntry *tempde,I64 *_fuf_flags)
{
I64 result=0,i;
U8 buf[BLK_SIZE];
CPrt *p;
while (tempde) {
if (tempde->attr&_ATTR_DIR)
i=SizeRep1(tempde->sub,_fuf_flags);
else if ((i=tempde->size) && Bt(_fuf_flags,FUf_EXPAND) &&
FileAttr(tempde->name)&_ATTR_COMPRESSED) {
p=Drv2Prt(*tempde->full_name);
RBlks(p,buf,Cluster2Blk(p,tempde->cluster),1);
i=(&buf)(CArcCompress *)->expanded_size;
}
tempde->user_data=i;
result+=i;
tempde=tempde->next;
}
return result;
}
U0 SizeRep2(CDoc *doc,CDirEntry *tempde)
{
while (tempde) {
if (tempde->attr&_ATTR_DIR) {
DocPrint(doc,"%10,d $$TR+C,\"%s\"$$\n$$ID,2$$",tempde->user_data,tempde->name);
SizeRep2(doc,tempde->sub);
DocPrint(doc,"$$ID,-2$$");
} else {
DocPrint(doc,"%10,d ",tempde->user_data);
DocPrint(doc,"$$LK,\"%s\",A=\"FI:%s\"$$\n",
tempde->name,tempde->full_name);
}
tempde=tempde->next;
}
}
public I64 SizeRep(U8 *files_find_mask="/*",U8 *fu_flags=NULL)
{
//"+x" for expanded size.
I64 fuf_flags=0,result=0;
CDoc *doc=DocNew;
CDirEntry *tempde1=NULL;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (tempde1=FilesFind(files_find_mask,fuf_flags&FUG_FILES_FIND)) {
fuf_flags&=FUF_EXPAND;
result=SizeRep1(tempde1,&fuf_flags);
DocPrint(doc,"%10,d $$TR+C,\"%s\"$$\n$$ID,2$$",result,files_find_mask);
SizeRep2(doc,tempde1);
DocPrint(doc,"$$ID,-2$$");
DirLstDel(tempde1);
}
DocInsDoc(DocPut,doc);
DocDel(doc);
return result;
}
#help_index ""
+61
View File
@@ -0,0 +1,61 @@
#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);
"$$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);
"$$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;
}
public I64 LinkChk(U8 *files_find_mask="/*",U8 *fu_flags=NULL)
//Checks for broken file links.
{
I64 fuf_flags=0,result=0;
CDirEntry *tempde,*tempde1;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+T+f+F+O");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tempde=tempde1=FilesFind(files_find_mask,fuf_flags);
while (tempde && !Bt(&fuf_flags,FUf_CANCEL)) {
result+=LinkChkFile(tempde->full_name,&fuf_flags);
tempde=tempde->next;
}
DirLstDel(tempde1);
return result;
}
#help_index ""
+246
View File
@@ -0,0 +1,246 @@
#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=GetRSP;
st=MStrUtil(task->task_title,SUF_REM_CTRL_CHARS|SUF_SAFE_DOLLAR);
"$$GREEN$$Task:%010X$$CYAN$$ %-30ts$$FG$$\n$$ID,2$$",task,st;
Free(st);
"$$PURPLE$$Alloced:%010X Used:%010X $$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 $$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_pen_brushes\t:%010X\n",PenBrushesSize;
"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);
"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_dc\t\t:%010X\n",DCSize(gr_dc);
"gr_dc1\t\t:%010X\n",DCSize(gr_dc1);
"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);
}
"$$ID,-2$$";
return TRUE;
}
public U0 MemRep()
{
I64 i;
CTask *task;
CCPU *c;
Bool old_preempt=Preempt(OFF);
CBinFile *bfh=sys_boot_base-sizeof(CBinFile);
bfh(I64)+=bfh->file_size-1;
"$$BLACK$$Low Memory\t:0000100000$$FG$$\n$$ID,2$$";
"Kernel\t:%010X-%010X\n",sys_boot_base-sizeof(CBinFile),bfh;
"VGA\t\t:00000A0000-00000BFFFF\n";
"$$ID,-2$$$$BLACK$$High Memory\t:0000100000-%010X$$FG$$\n",
sys_heap_limit;
"$$ID,2$$Fixed Area for page tables and misc\n\t\t:%010X-%010X\n",
SYS_FIXED_AREA,SYS_FIXED_AREA+sizeof(CSysFixedArea)-1;
"$$ID,-2$$";
if (sys_data_bp) {
"$$BLACK$$Code Heap:%010X Used:%010X $$RED$$Unused:%010X$$FG$$\n",
sys_code_bp->size*PAGE_SIZE,sys_code_bp->allocated_u8s,UnusedBPMem(sys_code_bp);
"$$BLACK$$Data Heap:%010X Used:%010X $$RED$$Unused:%010X$$FG$$\n",
sys_data_bp->size*PAGE_SIZE,sys_data_bp->allocated_u8s,UnusedBPMem(sys_data_bp);
} else
"$$BLACK$$Code/Data Heap:%010X Used:%010X $$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];
"$$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$$";
}
"$$GREEN$$Independent Heaps$$FG$$\n$$ID,2$$";
"$$BLACK$$sys_uncached_heap:%010X Used:%010X $$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 ""
+76
View File
@@ -0,0 +1,76 @@
#help_index "Utils;Cmd Line (Typically)"
CDirEntry MGFind(CDirEntry *needle_entry,CDirEntry *haystack_lst)
{
while (haystack_lst) {
if (!StrCmp(needle_entry->name,haystack_lst->name))
return haystack_lst;
haystack_lst=haystack_lst->next;
}
return NULL;
}
U0 Merge2(CDirEntry *tempde1,CDirEntry *tempde2,I64 *_fuf_flags,I64 *_df_flags)
{
I64 i;
CDirEntry *tempde;
while (tempde1 && !(*_df_flags & DF_ABORT_ALL_FILES)) {
tempde=MGFind(tempde1,tempde2);
if (!tempde)
"$$BROWN$$Does Not Exist:%s$$FG$$\n",tempde1->full_name;
else {
if (tempde1->attr & _ATTR_DIR)
Merge2(tempde1->sub,tempde->sub,_fuf_flags,_df_flags);
else {
i=tempde1->datetime-tempde->datetime;
if (AbsI64(i)>CDATE_FREQ*2) { //Filedates can shift due to conversion
"%s",tempde1->full_name;
NewLine;
if (Bt(_fuf_flags,FUf_DIFF)) {
if (FilesFindMatch(tempde1->full_name,FILEMASK_TXT))
Diff(tempde->full_name,tempde1->full_name,_df_flags);
}
}
}
}
tempde1=tempde1->next;
}
}
public U0 Merge(U8 *dst_files_find_mask="/*",U8 *src_files_find_mask="/*",
U8 *fu_flags=NULL)
//"+d"=Do $LK,"Diff",A="MN:Diff"$() on files
{
I64 df_flags=0,fuf_flags=0;
CDirEntry *tempde1=NULL,*tempde2=NULL;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
if (fuf_flags&~(FUG_FILES_FIND|FUF_DIFF))
throw('FUF');
PrintWarn("This is based strictly on file dates.\n");
tempde1=FilesFind(src_files_find_mask,fuf_flags&FUG_FILES_FIND);
tempde2=FilesFind(dst_files_find_mask,fuf_flags&FUG_FILES_FIND);
fuf_flags&=FUF_DIFF;
Merge2(tempde1,tempde2,&fuf_flags,&df_flags);
DirLstDel(tempde1);
DirLstDel(tempde2);
}
#help_index "Utils;Cmd Line (Typically)"
public U0 NewFiles(U8 *files_find_mask="/*",CDate cdt=0,U8 *fu_flags=NULL)
{//List new files
I64 fuf_flags=0;
CDirEntry *tempde,*tempde1;
if (!cdt) cdt=sys_compile_time;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+F");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tempde=tempde1=FilesFind(files_find_mask,fuf_flags);
while (tempde) {
if (tempde->datetime>cdt)
"%s\n",tempde->full_name;
tempde=tempde->next;
}
DirLstDel(tempde1);
}
#help_index ""
+200
View File
@@ -0,0 +1,200 @@
#help_index "Debugging/Profiler;Utils/Profiler;Profiler"
#help_file "::/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",A="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=tS;
}
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",A="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=tS;
}
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=tS;
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;
SPrint(buf,"%p",ip);
StrCpy(buf3,buf);
StrFirstRem(buf3,"+",buf2);
if (StrCmp(buf2,last_buf)) {
if (*last_buf && routine_total>=filter_cnt) {
"$$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) {
"$$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;
}
SPrint(buf,"%p",ip);
StrCpy(buf3,buf);
StrFirstRem(buf3,"+",buf2);
if (StrCmp(buf2,last_buf)) {
if (*last_buf && routine_total>=filter_cnt) {
"$$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) {
"$$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 ""
+56
View File
@@ -0,0 +1,56 @@
#help_index "Utils;Cmd Line (Typically)"
//$LK,"StrUtil",A="MN:StrUtil"$() operations on files
U0 SUFile(U8 *name,I64 suf_flags,F64 indent_scale_factor)
{//String utility on a single file
//See $LK,"SU Flags",A="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,suf_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;
DocWrite(doc);
}
DocDel(doc);
}
public U0 SU(U8 *files_find_mask,I64 suf_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,"SUF Flags",A="MN:SUF_SINGLE_SPACE"$
I64 fuf_flags=0;
CDirEntry *tempde,*tempde1;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+f+F+T");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tempde=tempde1=FilesFind(files_find_mask,fuf_flags);
while (tempde) {
SUFile(tempde->full_name,suf_flags,indent_scale_factor);
tempde=tempde->next;
}
DirLstDel(tempde1);
}
public U0 S2T(U8 *files_find_mask,U8 *fu_flags=NULL)
{
//Spaces to tabs.
//Use "Hard Space" (SHIFT-SPACE) for spaces
//in string consts in your code.
SU(files_find_mask,SUF_S2T|SUF_REM_TRAILING,fu_flags);
}
#help_index ""
+304
View File
@@ -0,0 +1,304 @@
#help_index "Doc/Cvt"
//See $LK,"::/Doc/Acknowledgements.TXT"$.
U0 HtmlPutS(CDoc *doc,I64 c,I64 *_old_c,U8 *st,I64 *_col,U8 *style_bitmap=NULL)
{
U8 *ch,*ptr;
if (c!=*_old_c) {
if (*_old_c!=-1)
DocPrint(doc,"</span>");
DocPrint(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;
sub_switch_start:
case 'ã': ptr="pi"; break;
case 'é': ptr="theta"; break;
case 'è': ptr="phi"; break;
case 'ê': ptr="omega"; break;
case 'ì': ptr="inf"; break;
case 'æ': ptr="u"; break;
sub_switch_end:
DocPrint(doc,ptr);
*_col=*_col+StrLen(ptr);
break;
sub_switch_start:
case CH_SHIFT_SPACE: ptr=" "; break;
case '&': ptr="&amp;"; break;
case '<': ptr="&lt;"; break;
case '>': ptr="&gt;"; break;
case '"': ptr="&quot;"; break;
sub_switch_end:
DocPrint(doc,ptr);
*_col=*_col+1;
break;
default:
if (CH_SPACE<=ch<0x7F || ch=='\n')
DocPutKey(doc,ch,0);
else
DocPrint(doc,".");
*_col=*_col+1;
}
}
}
U8 *TSLinkCvt2(U8 *filename,I64 line_num)
{ // ::/ --> http://www.templeos.org/Wb/
// Make your own LinkCvt routine
U8 *result=NULL,*st;
if (filename) {
st=ChgExt(filename,"html");
if (st && StrLen(st)>3 && !StrNCmp(st+1,":/",2))
result=MPrint("http://www.templeos.org/Wb/%s#l%d",st+3,line_num);
Free(st);
}
return result;
}
U8 *TSLinkCvt1(U8 *link_st)
{
static CDoc *bible=NULL;
static I64 locks=0;
U8 *result=NULL,*filename,*needle;
I64 i,num;
if (link_st) {
switch (i=EdLinkCvt(link_st,&filename,&needle,&num)) {
case LK_FILE_LINE:
case LK_PLAIN_LINE:
case LK_FILE:
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 (DocFind(bible,num,needle))
result=TSLinkCvt2(filename,bible->cur_entry->y+1);
LBtr(&locks,0);
break;
default:
if (DocFileEd(i,filename,needle,&num,EDF_UNCOLLAPSE|EDF_BAIL))
result=TSLinkCvt2(filename,num);
}
Free(filename);
Free(needle);
}
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;
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="";
DocPrint(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;
DocPrint(doc_out,
"</style>\n"
"</head>\n"
"<body>\n"
"<pre style=\"font-family:courier;font-size:10pt\">\n");
DocPrint(doc_out,"%s",body_header);
doc_e=doc_in->root.next;
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) {
DocPrint(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) {
DocPrint(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) {
DocPrint(doc_out,"</span>");
old_c=-1;
}
DocPrint(doc_out,"<a href=\"%s\">",link_st);
}
cur_u8_attr=doc_e->type.u8[1];
switch (doc_e->type_u8) {
case DOCT_TEXT:
if (doc_e->flags1&DOCEF1_HIGHLIGHT) {
if (doc_e->last==doc_in)
MemCpy(&doc_e->settings,&doc_in->settings_root,sizeof(CDocSettings));
else
MemCpy(&doc_e->settings,&doc_e->last->settings,sizeof(CDocSettings));
src=hl=DocHighlight(doc_e,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_CODE:
if (old_c!=-1) {
DocPrint(doc_out,"</span>");
old_c=-1;
}
DocPrint(doc_out,"%s",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 (doc_e->flags1&DOCEF1_TAG)
HtmlPutS(doc_out,cur_u8_attr,&old_c,doc_e->tag,&col,style_bitmap);
}
if (link_st) {
if (old_c!=-1) {
DocPrint(doc_out,"</span>");
old_c=-1;
}
DocPrint(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) {
DocPrint(doc_out,"</span>");
old_c=-1;
}
DocPrint(doc_out,"%s",body_footer);
DocPrint(doc_out,"</pre></body>\n</html>\n");
doc_out->cur_entry=style->next;
for (i=0;i<256;i++)
if (Bt(style_bitmap,i))
DocPrint(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;
}
#help_index "Utils;Cmd Line (Typically);Doc/Cvt;Doc/Cmd Line (Typically)"
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",A="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 ""
+133
View File
@@ -0,0 +1,133 @@
#help_index "Doc/Cvt"
U0 TXTPutS(CDoc *doc,U8 *st,I64 *_col)
{
U8 *ch,*ptr;
while (ch=*st++) {
switch (ch) {
case '\t':
do {
DocPutKey(doc,CH_SPACE,0);
*_col=*_col+1;
} while (*_col&7);
break;
sub_switch_start:
case 'ã': ptr="pi"; break;
case 'é': ptr="theta"; break;
case 'è': ptr="phi"; break;
case 'ê': ptr="omega"; break;
case 'ì': ptr="inf"; break;
case 'æ': ptr="u"; break;
case CH_SHIFT_SPACE: ptr=" "; break;
sub_switch_end:
DocPrint(doc,ptr);
*_col=*_col+StrLen(ptr);
break;
default:
if (CH_SPACE<=ch<0x7F || ch=='\n')
DocPutKey(doc,ch,0);
else
DocPrint(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_CODE:
break;
case DOCT_SPRITE:
break;
default:
if (doc_e->flags1&DOCEF1_TAG)
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;
}
#help_index "Utils;Cmd Line (Typically);Doc/Cvt;Doc/Cmd Line (Typically)"
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",A="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 ""