TempleOSCDV3.11.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:29 +02:00
1 parent f8c05f98f4
commit ed64d7e3b8
549 files changed
+10643 -12855

No files matched your search

+353
View File
@@ -0,0 +1,353 @@
#help_index "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;
'\n';
}
"$$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;
'\n';
}
"$$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 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)
{//Report differences between two files and merge differences
//from src_file to dst_file. Don't use _df_flags arg. (Used 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 "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 file 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 *arc;
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);
arc=CompressBuf(buf,size);
Free(buf);
tempde->user_data(F64)=100.0*arc->compressed_size/arc->expanded_size;
Free(arc);
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);
'\n';
}
Free(sort_buf);
DirTreeDel(tempde1);
}
+343
View File
@@ -0,0 +1,343 @@
#help_index "Graphics/Windows BMP Files"
#define NUM_BMP_COLORS 16
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;
CBGR24 palette[NUM_BMP_COLORS];
};
public CFileBMP *BMP4To(CDC *dc)
{//To Windows 4-bit BMP.
U8 *src,*ptr;
CBGR48 palette[NUM_COLORS];
I64 i,x,y,w=dc->width>>1,
size=sizeof(CFileBMP)+dc->width*dc->height>>1;
CFileBMP *bmp =CAlloc(size);
bmp->type ='BM';
bmp->planes =1;
bmp->file_size =size;
bmp->data_offset=sizeof(CFileBMP);
bmp->header_size=offset(CFileBMP.end)-offset(CFileBMP.header_size);
bmp->width =dc->width;
bmp->height =dc->height;
bmp->bit_cnt =4;
bmp->image_size =dc->width*dc->height>>1;
GrPaletteGet(palette);
#assert NUM_COLORS==NUM_BMP_COLORS
for (i=0;i<NUM_BMP_COLORS;i++) {
bmp->palette[i].b=palette[i].b>>8;
bmp->palette[i].g=palette[i].g>>8;
bmp->palette[i].r=palette[i].r>>8;
bmp->palette[i].pad=0;
}
ptr=bmp(U8 *)+bmp->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 bmp;
}
public CFileBMP *BMPRLE4To(CDC *dc)
{//To Windows RLE4 bit BMP.
U8 *src,*ptr,*start;
I64 i,x,y,w=dc->width,cnt,pattern;
CBGR48 palette[NUM_COLORS];
CFileBMP *bmp =CAlloc(sizeof(CFileBMP)+2*(dc->width+1)*dc->height);
bmp->type ='BM';
bmp->planes =1;
bmp->data_offset=sizeof(CFileBMP);
bmp->header_size=offset(CFileBMP.end)-offset(CFileBMP.header_size);
bmp->width =dc->width;
bmp->height =dc->height;
bmp->bit_cnt =4;
bmp->compression=2; //RLE4
GrPaletteGet(palette);
#assert NUM_COLORS==NUM_BMP_COLORS
for (i=0;i<NUM_BMP_COLORS;i++) {
bmp->palette[i].b=palette[i].b>>8;
bmp->palette[i].g=palette[i].g>>8;
bmp->palette[i].r=palette[i].r>>8;
bmp->palette[i].pad=0;
}
start=ptr=bmp(U8 *)+bmp->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;
}
bmp->image_size=ptr-start;
bmp->file_size=sizeof(CFileBMP)+bmp->image_size;
return bmp;
}
public CFileBMP *BMP24To(CDC *dc)
{//To Windows 24-bit BMP.
U8 *src;
I64 i,x,y,size=offset(CFileBMP.end)+dc->width*dc->height*sizeof(CBGR24);
CBGR24 *bgr;
CFileBMP *bmp =CAlloc(size);
bmp->type ='BM';
bmp->planes =1;
bmp->file_size =size;
bmp->data_offset=offset(CFileBMP.end);
bmp->header_size=offset(CFileBMP.end)-offset(CFileBMP.header_size);
bmp->width =dc->width;
bmp->height =dc->height;
bmp->bit_cnt =32;
bmp->image_size =dc->width*dc->height<<2;
bgr=bmp(U8 *)+bmp->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 bmp;
}
public I64 BMPWrite(U8 *filename,CDC *dc,I64 bits=4)
{//Window's BMP Files.
I64 size;
CFileBMP *bmp;
if (bits==4) {
if (IsDotZ(filename)) //.Z compression is better than RLE
bmp=BMP4To(dc);
else {
bmp=BMPRLE4To(dc);
if (bmp->file_size>sizeof(CFileBMP)+dc->width*dc->height>>1) {
Free(bmp);
bmp=BMP4To(dc);
}
}
} else if (bits==24)
bmp=BMP24To(dc);
else {
"Format Not Supported.\n";
return 0;
}
size=bmp->file_size;
FileWrite(filename,bmp,bmp->file_size);
Free(bmp);
return size;
}
U8 *BMPPaletteNew(CFileBMP *bmp)
{
I64 i,j,best,score,best_score;
CBGR48 palette[NUM_COLORS];
U8 *result=CAlloc(NUM_BMP_COLORS*sizeof(U8));
GrPaletteGet(palette);
#assert NUM_COLORS==NUM_BMP_COLORS
for (i=0;i<NUM_BMP_COLORS;i++) {
best=i;
best_score=MAX_I64;
for (j=0;j<NUM_BMP_COLORS;j++) {
score=SqrI64(bmp->palette[i].r-palette[j].r>>8)+
SqrI64(bmp->palette[i].g-palette[j].g>>8)+
SqrI64(bmp->palette[i].b-palette[j].b>>8);
if (score<best_score) {
best=j;
best_score=score;
}
}
result[i]=best;
}
return result;
}
U8 ms_paint_palette[NUM_BMP_COLORS]={0,4,2,6,1,5,3,8,7,12,10,14,9,13,11,15};
I64 BMP24Color(CBGR24 *ptr,Bool dither_probability)
{
I64 result,k;
if (dither_probability) {
k=RandU32;
if (SqrI64(ptr->r)+SqrI64(ptr->g)+SqrI64(ptr->b)>=3*SqrI64(k.u8[0]))
result=8;
else
result=0;
if (ptr->r>=k.u8[1]) result|=RED;
if (ptr->g>=k.u8[2]) result|=GREEN;
if (ptr->b>=k.u8[3]) result|=BLUE;
} else {
if (SqrI64(ptr->r)+SqrI64(ptr->g)+SqrI64(ptr->b)>=SqrI64(0x80)) {
result=8;
if (ptr->r>=0x80) result|=RED;
if (ptr->g>=0x80) result|=GREEN;
if (ptr->b>=0x80) result|=BLUE;
} else {
result=0;
if (ptr->r>=0x40) result|=RED;
if (ptr->g>=0x40) result|=GREEN;
if (ptr->b>=0x40) result|=BLUE;
}
}
return result;
}
public CDC *BMPRead(U8 *filename,Bool dither_probability=FALSE,
Bool use_ms_paint_palette=FALSE)
{//Window's BMP Files.
I64 i,j,cnt;
U8 *palette_map,*ptr;
Bool rle;
CFileBMP *bmp;
CDC *result=NULL;
if (ptr=FileRead(filename)) {
bmp=ptr;
if (0<bmp->width<MAX_I32 && 0<bmp->height<MAX_I32) {
result=DCNew(bmp->width,bmp->height);
ptr+=bmp->data_offset;
if (bmp->compression==2)
rle=TRUE;
else
rle=FALSE;
if (use_ms_paint_palette)
palette_map=ms_paint_palette;
else
palette_map=BMPPaletteNew(bmp);
if (bmp->bit_cnt==4) {
for (i=bmp->height-1;i>=0;i--)
if (rle) {//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<(bmp->width+7)&~7;) {
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 if (bmp->bit_cnt==24) {
for (i=bmp->height-1;i>=0;i--) {
for (j=0;j<bmp->width;j++,ptr+=3) {
result->color=BMP24Color(ptr,dither_probability);
GrPlot(result,j,i);
}
ptr+=bmp->width&3;
}
if (!use_ms_paint_palette)
Free(palette_map);
} else if (bmp->bit_cnt>=32) {
for (i=bmp->height-1;i>=0;i--)
for (j=0;j<bmp->width;j++,ptr+=4) {
result->color=BMP24Color(ptr,dither_probability);
GrPlot(result,j,i);
}
if (!use_ms_paint_palette)
Free(palette_map);
} else {
"Format Not Supported.\n";
DCDel(result);
result=NULL;
}
} else
"Invalid BMP File\n";
Free(bmp);
}
return result;
}
#help_index "Graphics/Sprite;Graphics/Windows BMP Files;"\
"DolDoc/Output;StdOut/DolDoc"
public U0 DocBMP(CDoc *doc=NULL,U8 *filename,Bool dither_probability=FALSE,
Bool use_ms_paint_palette=FALSE)
{//Put a BMP file into a document as a sprite.
CDC *dc=BMPRead(filename,dither_probability,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 BMPScreenCapture(U8 *filename,I64 bits=4,Bool include_zoom=TRUE)
{//Capture screen as BMP file.
CDC *dc=DCScreenCapture(include_zoom);
I64 size=BMPWrite(filename,dc,bits);
DCDel(dc);
return size;
}
+255
View File
@@ -0,0 +1,255 @@
#help_index "Cmd Line (Typically)"
#define FND_REPLACE 0
#define FND_SKIP 1
#define FND_ALL 2
#define FND_ED 3
#define FND_ABORT_FILE 4
#define FND_SKIP_FILE 5
I64 PopUpFindMenu()
{
I64 i;
CDoc *doc=DocNew;
DocPrint(doc,"$$CM+LX,2,4$$$$BT,\"REPLACE\",LE=FND_REPLACE$$"
"$$CM+LX,22,0$$$$BT,\"SKIP\",LE=FND_SKIP$$"
"$$CM+LX,2,4$$$$BT,\"ALL\",LE=FND_ALL$$"
"$$CM+LX,22,0$$$$BT,\"ABORT ALL\",LE=DOCM_CANCEL$$"
"$$CM+LX,2,4$$$$BT,\"EDIT\",LE=FND_ED$$"
"$$CM+LX,22,0$$$$BT,\"ABORT FILE\",LE=FND_ABORT_FILE$$"
"$$CM+LX,2,4$$$$BT,\"SKIP FILE\",LE=FND_SKIP_FILE$$\n");
i=PopUpMenu(doc);
DocDel(doc);
return i;
}
I64 FindFile(U8 *needle_str,U8 *haystack_filename,
I64 *_fuf_flags,U8 *replace_text)
{//Have you confused with $LK,"FileFind",A="MN:FileFind"$()?
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=MStrPrint("%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=FND_ALL;
else {
i=PopUpFindMenu;
if (i<0) {
LBts(_fuf_flags,FUf_CANCEL);
cont=FALSE;
write_this_file=FALSE;
} else if (i==FND_ALL)
LBts(_fuf_flags,FUf_ALL);
else if (i==FND_ABORT_FILE) {
cont=FALSE;
write_this_file=FALSE;
} else if (i==FND_SKIP_FILE)
cont=FALSE;
}
if (i==FND_REPLACE || i==FND_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==FND_ED) {
Free(name_buf);
name_buf=StrNew(doc->filename.name);
doc->flags&=~DOCF_NO_CURSOR;
doc->cur_entry=doc_e;
doc->cur_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 Find(U8 *needle_str,U8 *files_find_mask="*",
U8 *fu_flags=NULL,U8 *replace_text=NULL)
{/*Find occurrences of a string in files.
This does not do regular expressions.
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 "dd" 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+=FindFile(needle_str,tempde->full_name,&fuf_flags,replace_text);
tempde=tempde->next;
}
DirTreeDel(tempde1);
return cnt;
}
public I64 FileOcc(U8 *needle_str,
U8 *files_find_mask="*",U8 *fu_flags="+r+i+l")
{/*Silently return occurrences of a string in files.
"+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=Find(needle_str,files_find_mask,fu_flags);
Silent(old_silent);
return cnt;
}
class CFind
{
U8 find_text[STR_LEN] fmtstr "$$DA-P,STR_LEN-1,A=\"FIND :%s\"$$\n";
U8 replace_text[STR_LEN] fmtstr "$$DA-P,STR_LEN-1,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[STR_LEN] fmtstr "$$DA-P,STR_LEN-1,A=\"FILE MASK :%s\"$$\n";
Bool recurse fmtstr "$$CB,\"RECURSE\"$$\n";
};
I64 FindWiz()
{
CDoc *doc;
U8 buf[32],*dir,*st;
CFind *g=CAlloc(sizeof(CFind));
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 (DocForm(g,,0,"$$PURPLE$$$$TX+CX,\"Find\"$$\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=MStrPrint("\"$$$$WW+H,1$$$$\";Cd(\"%s\");"
"Find(\"%Q\",\"%Q\",\"%Q\",\"%Q\");UserTaskCont;",
dir,g->find_text,g->filemask,buf,g->replace_text);
else
st=MStrPrint("\"$$$$WW+H,1$$$$\";Cd(\"%s\");"
"Find(\"%Q\",\"%Q\",\"%Q\");UserTaskCont;",
dir,g->find_text,g->filemask,buf);
result=PopUp(st);
}
Free(dir);
}
Free(g);
return result;
}
+140
View File
@@ -0,0 +1,140 @@
#help_index "Debugging/Heap"
#help_file "::/Doc/HeapDbg"
#define HL_CALLER_DEPTH 4
#define HL_HASH_SIZE 0x1000
class CHeapLog
{
CHeapLog *next,*last;
U8 *addr;
U8 *caller[HL_CALLER_DEPTH];
};
class CHeapLogHash
{
CHeapLog *next,*last;
};
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;
for (i=0;i<HL_CALLER_DEPTH;i++)
temphl->caller[i]=Caller(i+2);
i=addr>>3 &(HL_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 &(HL_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 Bool HeapLog(Bool val=ON,CTask *task=NULL)
{//Turn on. Collect data. Call $LK,"HeapLogRep",A="MN:HeapLogRep"$().
I64 i;
if (val) {
if (Bt(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0)) {
"HeapLog Already Active\n";
return TRUE;
} else {
if (!task) task=Fs;
if (TaskValidate(task))
heaplog_hc_watched=task->data_heap;
else
heaplog_hc_watched=task;//Actually, not a task, must be a HeapCtrl.
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)*HL_HASH_SIZE,heaplog_hc);
for (i=0;i<HL_HASH_SIZE;i++)
QueInit(&heaplog_root[i]);
LBtr(&sys_semas[SYS_SEMA_HEAPLOG_LOCK],0);
POPFD
LBts(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0);
return FALSE;
}
} else {
if (!LBtr(&sys_semas[SYS_SEMA_HEAPLOG_ACTIVE],0)) {
"HeapLog Not Active\n";
return FALSE;
} else {
HeapCtrlDel(heaplog_hc);
heaplog_root=heaplog_hc=NULL;
ext[EXT_HEAPLOG_MALLOC]=NULL;
ext[EXT_HEAPLOG_FREE]=NULL;
return TRUE;
}
}
}
public U0 HeapLogRep(Bool leave_it=OFF)
{//Call $LK,"HeapLog",A="MN:HeapLog"$() first and collect data.
I64 i,j,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<HL_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",MSize(hl.addr),hl.addr;
for (j=0;j<HL_CALLER_DEPTH;j++)
" %P",hl.caller[j];
'\n';
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);
if (!leave_it)
HeapLog(OFF);
}
+109
View File
@@ -0,0 +1,109 @@
#help_index "Cmd Line (Typically)"
I64 LineRep1(CDirEntry *tempde)
{
CDoc *doc;
I64 result=0,i;
while (tempde) {
i=0;
if (tempde->attr&RS_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&RS_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)
{//Source line-of-code count report.
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$$");
DirTreeDel(tempde1);
}
DocInsDoc(DocPut,doc);
DocDel(doc);
return result;
}
I64 SizeRep1(CDirEntry *tempde,I64 *_fuf_flags)
{
I64 result=0,i;
U8 buf[BLK_SIZE];
CDrv *dv;
while (tempde) {
if (tempde->attr&RS_ATTR_DIR)
i=SizeRep1(tempde->sub,_fuf_flags);
else if ((i=tempde->size) && Bt(_fuf_flags,FUf_EXPAND) &&
FileAttr(tempde->name)&RS_ATTR_COMPRESSED) {
dv=Let2Drv(*tempde->full_name);
RBlks(dv,buf,Cluster2Blk(dv,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&RS_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)
{//Report file sizes. "+x" for expanded size of compressed files.
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$$");
DirTreeDel(tempde1);
}
DocInsDoc(DocPut,doc);
DocDel(doc);
return result;
}
+59
View File
@@ -0,0 +1,59 @@
#help_index "Debugging;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)
{//Check documents 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;
}
DirTreeDel(tempde1);
return result;
}
+15
View File
@@ -0,0 +1,15 @@
Cd(__DIR__);;
#include "Diff"
#include "FileBMP"
#include "Find"
#include "HeapLog"
#include "LineRep"
#include "LinkChk"
#include "MemRep"
#include "Merge"
#include "Profiler"
#include "StrUtils"
#include "ToDolDoc"
#include "ToHtml"
#include "ToTXT"
Cd("..");;
+235
View File
@@ -0,0 +1,235 @@
#help_index "Info;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(blkdev.blkdevs);
CBlkDev *bd;
for (i=0;i<NUM_BLKDEVS;i++) {
bd=&blkdev.blkdevs[i];
if (bd->bd_signature==BD_SIGNATURE_VAL) {
if (bd->type==BDT_RAM)
"RAMDsk %C\t:%010X Unused:%010X\n",
bd->first_drv_let,(bd->max_blk+1)<<BLK_SIZE_BITS,
UnusedDrvSpace(bd->first_drv_let);
result+=MSize2(bd->dev_id_record);
}
}
return result;
}
I64 DrvsSize()
{
I64 i,result=MSize2(blkdev.drvs);
for (i=0;i<NUM_DRVS;i++)
result+=MSize2(blkdev.drvs[i].cur_fat_blk)+MSize2(blkdev.drvs[i].fis);
return result;
}
Bool MemRepTask(CTask *task,Bool override_validate=FALSE)
{
I64 i,j,k,m,n;
U8 *st;
CDoc *pdoc,*ddoc,*bdoc;
CCmpCtrl *cc;
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$$FG$$\n",
TaskMemAlloced(task,override_validate),
TaskMemUsed(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);
cc=task->next_lex;
while (cc!=&task->next_lex) {
"Lex\t\t:%010X\n",CmpCtrlSize(cc);
cc=cc->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;
if (n)
"TaskQues\t:%010X\n",n;
"BlkDevs\t:%010X\n",BlkDevsSize;
"Drvs\t:%010X\n",DrvsSize;
if (blkdev.cache_base)
"DskCache\t:%010X\n",
MSize2(blkdev.cache_base)+MSize2(blkdev.cache_hash_table)+
MSize2(blkdev.cache_ctrl);
"Clipboard\t:%010X\n",DocSize(sys_clipboard_doc);
"AutoComplete:%010X\n",CallExtStr("AutoCompleteSize");
"gr.to_8_bits\t:%010X\n",MSize2(gr.to_8_bits);
"gr.to_8_colors\t:%010X\n",MSize2(gr.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()
{//Memory usage report.
I64 i;
CTask *task;
CCPU *c;
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$$FG$$\n",
sys_code_bp->alloced_u8s,sys_code_bp->used_u8s;
"$$BLACK$$Data Heap:%010X Used:%010X$$FG$$\n",
sys_data_bp->alloced_u8s,sys_data_bp->used_u8s;
} else
"$$BLACK$$Code/Data Heap:%010X Used:%010X$$FG$$\n",
sys_code_bp->alloced_u8s,sys_code_bp->used_u8s;
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$$dev.uncached_heap:%010X Used:%010X$$FG$$\n",
dev.uncached_heap->bp->alloced_u8s,dev.uncached_heap->used_u8s;
"$$ID,-2$$\n";
}
+77
View File
@@ -0,0 +1,77 @@
#help_index "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)
{
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 & RS_ATTR_DIR)
Merge2(tempde1->sub,tempde->sub,_fuf_flags,_df_flags);
else {
if (AbsI64(tempde1->datetime-tempde->datetime)>CDATE_FREQ*2) {//slop
"%s",tempde1->full_name;
'\n';
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)
{/*Merge text files from one list into another.
Report files whos date/time is different.
"+d" will do $LK,"Diff",A="MN:Diff"$() on files and prompt to
merge changes from source files into
destination 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);
DirTreeDel(tempde1);
DirTreeDel(tempde2);
}
#help_index "Utils;Cmd Line (Typically)"
public U0 NewFiles(U8 *files_find_mask="/*",CDate cdt=0,U8 *fu_flags=NULL)
{//Report files newer than a certain date.
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;
}
DirTreeDel(tempde1);
}
+102
View File
@@ -0,0 +1,102 @@
#help_index "Debugging/Profiler;Profiler;Cmd Line (Typically)/Profiler"
#help_file "::/Doc/Profiler"
#define PF_ARRAY_CNT 0x100000
I64 pf_jiffy_start,pf_jiffy_end;
I64 *pf_array=NULL;
I64 pf_cpu=0;
I64 pf_buf_in_ptr=0,pf_depth;
I64 pf_prof_active=0;
U0 ProfTimerInt(CTask *task)
{//See $LK,"profiler_timer_irq",A="FF:::/Kernel/KInts.CPP,profiler_timer_irq"$.
I64 i,k;
if (Bt(&pf_prof_active,0))
for (k=0;k<=pf_depth;k++) {
if (task==Gs->idle_task)
i=SYS_IDLE_PT;
else
i=TaskCaller(task,k,TRUE);
if (pf_buf_in_ptr<PF_ARRAY_CNT) {
pf_array[pf_buf_in_ptr++]=i;
pf_jiffy_end=cnts.jiffies;
}
}
}
public U0 Prof(I64 depth=0,I64 cpu_num=0)
{/*Start collecting profiler statistics.
Profilers report where time is spent
by sampling RIP during the $TX,"1000 Hz",D="DD_JIFFY_HZ"$
timer interrupt.
Do a $LK,"ProfRep",A="MN:ProfRep"$(), (profiler report)
after you have collected data.
*/
if (!(0<=cpu_num<mp_cnt))
ST_ERR_ST "Invalid CPU\n";
else {
cpu_structs[pf_cpu].profiler_timer_irq=NULL;
pf_cpu=cpu_num;
pf_depth=depth;
pf_buf_in_ptr=0;
if (!pf_array)
pf_array=AMAlloc(sizeof(I64)*PF_ARRAY_CNT);
pf_jiffy_end=pf_jiffy_start=cnts.jiffies;
LBts(&pf_prof_active,0);
cpu_structs[pf_cpu].profiler_timer_irq=&ProfTimerInt;
}
}
I64 ProfCompare(U8 *i1,U8 *i2)
{
return i1-i2;
}
public U0 ProfRep(I64 filter_cnt=1,Bool leave_it=OFF)
{//Profiler report. Call $LK,"Prof",A="MN:Prof"$() first and collect data.
I64 i,hits,ip,last_ip=0,routine_total=0;
F64 total_time;
U8 buf[256],buf2[256],last_buf[256];
if (!LBtr(&pf_prof_active,0))
"Profiler Not Active\n";
if (!pf_buf_in_ptr)
"No Profiler Statistic\n";
else {
if (!(total_time=pf_jiffy_end-pf_jiffy_start))
total_time=1;
QSortI64(pf_array,pf_buf_in_ptr,&ProfCompare);
*last_buf=0;
for (i=0;i<pf_buf_in_ptr;i+=hits) {
ip=pf_array[i];
hits=0;
do hits++;
while (i+hits<pf_buf_in_ptr && pf_array[i+hits]==ip);
StrPrint(buf,"%p",ip);
StrFirstRem(buf,"+",buf2);
if (StrCmp(buf2,last_buf)) {
if (*last_buf && routine_total>=filter_cnt)
"$$GREEN$$%6.2f %08X:%s\n$$FG$$",100*routine_total/total_time,
routine_total,last_buf;
StrCpy(last_buf,buf2);
routine_total=0;
}
routine_total+=hits;
if (hits>=filter_cnt) {
"%6.2f %08X:%P\n",100*hits/total_time,hits,ip;
last_ip=ip;
}
}
if (*last_buf && routine_total>=filter_cnt)
"$$GREEN$$%6.2f %08X:%s\n$$FG$$",100*routine_total/total_time,
routine_total,last_buf;
"Total Time:%0.6fs\n",total_time/JIFFY_FREQ;
if (leave_it) {
cpu_structs[pf_cpu].profiler_timer_irq=&ProfTimerInt;
LBts(&pf_prof_active,0);
} else
cpu_structs[pf_cpu].profiler_timer_irq=NULL;
}
}
+200
View File
@@ -0,0 +1,200 @@
#help_index "Cmd Line (Typically)"
I64 DECompare(CDocEntry *e1,CDocEntry *e2)
{
return StrCmp(e1->tag,e2->tag);
}
public I64 Sort(U8 *_in_name,U8 *_out_name=NULL,Bool unique=FALSE)
{//Sort lines of a text file. Removes blank lines.
U8 *in_name,*out_name,*st;
CDoc *doc;
CDocEntry *doc_e,*doc_e1,**a;
I64 i,cnt=0,result;
if (!_in_name) return 0;
in_name=DftExt(_in_name,"TXT.Z");
if (_out_name)
out_name=DftExt(_out_name,"TXT.Z");
else
out_name=StrNew(in_name);
doc=DocRead(in_name,DOCF_PLAIN_TEXT_WITH_TABS|DOCF_NO_CURSOR);
doc_e=doc->root.next;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_TEXT)
cnt++;
doc_e=doc_e->next;
}
a=MAlloc(cnt*sizeof(CDocEntry *));
doc_e=doc->root.next;
i=0;
while (doc_e!=doc) {
doc_e1=doc_e->next;
if (doc_e->type_u8==DOCT_TEXT) {
QueRem(doc_e);
a[i++]=doc_e;
} else
DocEntryDel(doc,doc_e);
doc_e=doc_e1;
}
QSortI64(a,cnt,&DECompare);
result=0;
st=NULL;
for (i=0;i<cnt;i++) {
QueIns(a[i],doc->root.last);
if (!unique || !st || StrCmp(a[i]->tag,st)) {
st=a[i]->tag;
doc->cur_entry=&doc->root;
doc->cur_col=0;
DocPrint(doc,"\n");
result++;
} else
DocEntryDel(doc,a[i]);
}
StrCpy(doc->filename.name,out_name);
DocWrite(doc);
Free(a);
DocDel(doc);
Free(in_name);
Free(out_name);
return result; //Num Lines
}
I64 DocWordsFile(CDoc *doc_out=NULL,U8 *filename,U32 *chars_bmp)
{
U8 *ptr,*ptr2;
I64 result=0,ch;
CDoc *doc_in=DocRead(filename);
CDocEntry *doc_e=doc_in->root.next;
while (doc_e!=doc_in) {
if (doc_e->de_flags & DOCEF_TAG) {
ptr=doc_e->tag;
while (*ptr) {
while (*ptr && !Bt(chars_bmp,*ptr))
ptr++;
ptr2=ptr;
while (*ptr && Bt(chars_bmp,*ptr))
ptr++;
ch=*ptr;
*ptr=0;
if (*ptr2) {
DocPrint(doc_out,"%s\n",ptr2);
result++;
}
*ptr=ch;
}
}
doc_e=doc_e->next;
}
DocDel(doc_in);
return result;
}
public I64 Words(U8 *files_find_mask="*",U32 *chars_bmp=chars_bmp_alpha,
U8 *fu_flags=NULL)
{//Break file into list of not-unique words.
I64 fuf_flags=0,result=0;
CDoc *doc_out=DocNew;
CDirEntry *tempde,*tempde1;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+T");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tempde=tempde1=FilesFind(files_find_mask,fuf_flags);
while (tempde) {
result+=DocWordsFile(doc_out,tempde->full_name,chars_bmp);
tempde=tempde->next;
}
DirTreeDel(tempde1);
DocInsDoc(NULL,doc_out);
DocDel(doc_out);
return result;
}
I64 LongLinesFile(U8 *filename,I64 cols)
{
I64 result=0;
CDoc *doc=DocRead(filename);
CDocEntry *doc_e=doc->root.next;
while (doc_e!=doc) {
if (doc_e->type_u8==DOCT_NEW_LINE && doc_e->x>=cols+1)
result++;
doc_e=doc_e->next;
}
DocDel(doc);
if (result) {
"%04d ",result;
PutFileLink(filename);
'\n';
}
return result;
}
public I64 LongLines(U8 *files_find_mask="*",I64 cols=80,U8 *fu_flags=NULL)
{//Report files with lines of too many cols.
I64 result=0,fuf_flags=0;
CDirEntry *tempde,*tempde1;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+S");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tempde=tempde1=FilesFind(files_find_mask,fuf_flags);
while (tempde) {
if (LongLinesFile(tempde->full_name,cols))
result++;
tempde=tempde->next;
}
DirTreeDel(tempde1);
return result;
}
U0 SUFile(U8 *filename,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(filename,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",filename,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 $LK,"StrUtil",A="MN:StrUtil"$() on 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;
}
DirTreeDel(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);
}
+19
View File
@@ -0,0 +1,19 @@
#help_index "Cmd Line (Typically);DolDoc/Conversion;DolDoc/Cmd Line (Typically)"
public U0 ToDolDoc(U8 *files_find_mask,U8 *fu_flags=NULL)
{//Convert text file to $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT"$ by making double $$'s.
CDoc *doc;
I64 fuf_flags=0;
CDirEntry *tempde,*tempde1;
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F");
ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
tempde=tempde1=FilesFind(files_find_mask,fuf_flags);
while (tempde) {
"%s\n",tempde->full_name;
doc=DocRead(tempde->full_name,DOCF_PLAIN_TEXT|DOCF_DBL_DOLLARS);
DocWrite(doc);
DocDel(doc);
tempde=tempde->next;
}
DirTreeDel(tempde1);
}
+329
View File
@@ -0,0 +1,329 @@
#help_index "DolDoc/Conversion"
//See $LK,"::/Doc/Credits.TXT"$.
U0 HtmlPutS(CDoc *doc,I64 u32_attr,I64 *_old_u32_attr,
U8 *st,I64 *_col,U8 *style_bitmap=NULL)
{
U8 *ch,*ptr;
u32_attr&=0xFFFFFF00;
if (u32_attr&DOCET_INVERT)
u32_attr.u8[1]=(u32_attr.u8[1]&15)<<4|u32_attr.u8[1]>>4;
if (u32_attr!=*_old_u32_attr) {
if (!(u32_attr&DOCET_BLINK) &&
*_old_u32_attr!=-1 && *_old_u32_attr&DOCET_BLINK)
DocPrint(doc,"</blink>");
if (*_old_u32_attr!=-1)
DocPrint(doc,"</span>");
DocPrint(doc,"<span class=c%02X>",u32_attr.u8[1]);
if (u32_attr&DOCET_BLINK &&
(*_old_u32_attr==-1 || !(*_old_u32_attr&DOCET_BLINK)))
DocPrint(doc,"<blink>");
*_old_u32_attr=u32_attr;
if (style_bitmap)
LBts(style_bitmap,u32_attr.u8[1]);
}
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 *TOSLinkCvt2(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=MStrPrint("http://www.templeos.org/Wb/%s#l%d",st+3,line_num);
Free(st);
}
return result;
}
U8 *TOSLinkCvt1(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=TOSLinkCvt2(filename,num);
break;
case -1:
case LK_DEF:
case LK_HELP_INDEX:
case LK_DOC:
case LK_DOC_ANCHOR:
case LK_DOC_FIND:
case LK_DOC_LINE:
break;
case LK_BIBLE_FIND:
while (LBts(&locks,0))
Yield;
if (!bible)
bible=Adam("DocRead(\"%s\");",filename);
if (DocFind(bible,num,needle))
result=TOSLinkCvt2(filename,bible->cur_entry->y+1);
LBtr(&locks,0);
break;
default:
if (DocFileEd(i,filename,needle,&num,EDF_UNCOLLAPSE|EDF_BAIL))
result=TOSLinkCvt2(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)=&TOSLinkCvt1)
{//Cvt $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT"$ doc to HTML file.
CDocEntry *doc_e,*style,*doc_e2;
I64 i,y,old_y=MIN_I64,col,old_u32_attr=-1,old_attr;
U32 *hl,*src;
U8 *st,st_2[2],*link_st,*style_bitmap=CAlloc(256/8);
CBGR48 p[NUM_COLORS];
GrPaletteGet(p);
CDoc *doc_out=DocNew;
Bool unlock_doc_in=DocLock(doc_in),no_bwd;
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;
while (doc_e!=doc_in) {
if (!(doc_e->de_flags&(DOCEF_SKIP|DOCEF_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,doc_e->settings.final_u32_attr,
&old_u32_attr,"\n",&col,style_bitmap);
if (line_anchors && ++y!=old_y) {
DocPrint(doc_out,"<a name=\"l%d\"></a>",y+1);
old_y=y;
}
col=0;
}
no_bwd=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_bwd=FALSE;
break;
}
doc_e2=doc_e2->next;
}
if (no_bwd)
while (col<doc_e->x)
HtmlPutS(doc_out,doc_e->settings.final_u32_attr,
&old_u32_attr," ",&col,style_bitmap);
link_st=NULL;
if (doc_e->de_flags&DOCEF_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_u32_attr!=-1) {
DocPrint(doc_out,"</span>");
old_u32_attr=-1;
}
DocPrint(doc_out,"<a href=\"%s\">",link_st);
}
switch (doc_e->type_u8) {
case DOCT_TEXT:
if (doc_e->de_flags&DOCEF_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),
doc_e->type&0xFF00);
while (*src) {
st_2[0]=*src&0xFF;
HtmlPutS(doc_out,*src++,&old_u32_attr,st_2,&col,style_bitmap);
}
Free(hl);
} else
HtmlPutS(doc_out,doc_e->settings.final_u32_attr,
&old_u32_attr,doc_e->tag,&col,style_bitmap);
break;
case DOCT_TAB:
HtmlPutS(doc_out,doc_e->settings.final_u32_attr,
&old_u32_attr,"\t",&col,style_bitmap);
break;
case DOCT_HTML_CODE:
if (old_u32_attr!=-1) {
DocPrint(doc_out,"</span>");
old_u32_attr=-1;
}
DocPrint(doc_out,"%s",doc_e->tag);
break;
case DOCT_SPRITE:
HtmlPutS(doc_out,doc_e->settings.final_u32_attr,
&old_u32_attr,doc_e->tag,&col,style_bitmap);
HtmlPutS(doc_out,doc_e->settings.final_u32_attr,
&old_u32_attr,"/* Graphics Not Rendered in HTML */",
&col,style_bitmap);
break;
default:
if (doc_e->de_flags&DOCEF_TAG)
HtmlPutS(doc_out,doc_e->settings.final_u32_attr,
&old_u32_attr,doc_e->tag,&col,style_bitmap);
}
if (link_st) {
if (old_u32_attr!=-1) {
DocPrint(doc_out,"</span>");
old_u32_attr=-1;
}
DocPrint(doc_out,"</a>");
Free(link_st);
}
}
doc_e=doc_e->next;
}
while (y++<doc_e->y) {
HtmlPutS(doc_out,doc_e->settings.final_u32_attr,
&old_u32_attr,"\n",&col,style_bitmap);
col=0;
}
if (old_u32_attr!=-1) {
if (old_u32_attr&DOCET_BLINK)
DocPrint(doc_out,"</blink>");
DocPrint(doc_out,"</span>");
old_u32_attr=-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>>8,p[i&15].g>>8,p[i&15].b>>8,
p[i/16].r>>8,p[i/16].g>>8,p[i/16].b>>8);
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 "Cmd Line (Typically);DolDoc/Conversion;DolDoc/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)=&TOSLinkCvt1)
{//Convert $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT"$ file to HTML.
//Supply your own link_cvt routine.
U8 *in_name,*out_name;
CDoc *doc_in,*doc_out;
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
WinHorz(0,width-1); //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);
}
+130
View File
@@ -0,0 +1,130 @@
#help_index "DolDoc/Conversion"
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)
{//Cvt $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT"$ doc to plain text.
CDocEntry *doc_e,*doc_e2;
I64 y,col;
CDoc *doc_out=DocNew;
Bool unlock_doc_in=DocLock(doc_in),no_bwd;
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->de_flags&(DOCEF_SKIP|DOCEF_HARD_SKIP))) {
while (y<doc_e->y) {
TXTPutS(doc_out,"\n",&col);
y++;
col=0;
}
no_bwd=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_bwd=FALSE;
break;
}
doc_e2=doc_e2->next;
}
if (no_bwd)
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->de_flags&DOCEF_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 "Cmd Line (Typically);DolDoc/Conversion;DolDoc/Cmd Line (Typically)"
public U0 ToTXT(U8 *_in_name,U8 *_out_name=NULL,I64 width=70)
{//Convert $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT"$ file to plain text.
U8 *in_name,*out_name;
CDoc *doc_in,*doc_out;
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
WinHorz(0,width-1); //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);
}