hschumann2/TempleOS-Source-Code
0838
1 2#help_index "Misc/Blog"3 4public Bool IsTOSBlog(U8 *filename)5{//Is this in the TOSBlog dir?6 Bool res;7 U8 *st=DirNameAbs(filename),*home=DirNameAbs("~");8 I64 l=StrLen(home);9 if (StrLen(st)>=l+12 && !StrNCmp(st+1,home+1,l-1) &&10 st[l]=='/' && !StrNCmp(st+l+4,"/TOSBlog",8))11 res=TRUE;12 else13 res=FALSE;14 Free(st);15 Free(home);16 return res;17}18 19public U8 *TOSBlogAbs(U8 *filename)20{//Absolute filename, adjusted for moving TOSBlog.21 U8 *st=DirNameAbs(filename),*home=DirNameAbs("~");22 I64 l=StrLen(home);23 if (IsTOSBlog(st)) {24 MemCpy(st+l+5,st+l+1,3);25 MemCpy(st+l+1,"Web",3);26 StrCpy(st+l+8,st+l+12);27 }28 Free(home);29 return st;30}31 32public U8 *BlogLocalDir(CDate cdt=0)33{//MAlloc dirname of blog for date.34 static U8 dir[STR_LEN];35 CDateStruct ds;36 if (!cdt) cdt=Now+local_time_offset;37 Date2Struct(&ds,cdt);38 StrPrint(dir,BLOG_LOCAL_SRC "/%d%Z",ds.year,ds.mon-1,"ST_MONTHS");39 if (!FileFind(dir,,FUF_JUST_DIRS))40 DirMk(dir);41 return dir;42}43 44public U8 *BlogLocalFile(CDate cdt=0)45{//MAlloc filename of blog for date.46 static U8 file[STR_LEN];47 CDateStruct ds;48 if (!cdt) cdt=Now+local_time_offset;49 Date2Struct(&ds,cdt);50 StrPrint(file,"%s/" INS_REG_PERSONAL_INITIALS "%02d%02d%02d.DD.Z",51 BlogLocalDir(cdt),ds.year%100,ds.mon,ds.day_of_mon);52 return file;53}54 55public U8 *BlogWebDir(CDate cdt=0)56{//MAlloc D:/Wb/dirname of blog for date.57 static U8 dir[STR_LEN];58 CDateStruct ds;59 if (!cdt) cdt=Now+local_time_offset;60 Date2Struct(&ds,cdt);61 StrPrint(dir,BLOG_WEB_DST "/%d%Z",62 ds.year,ds.mon-1,"ST_MONTHS");63 return dir;64}65 66public U8 *BlogWebFile(CDate cdt=0)67{//MAlloc D:/Wb/filename of blog for date.68 static U8 file[STR_LEN];69 CDateStruct ds;70 if (!cdt) cdt=Now+local_time_offset;71 Date2Struct(&ds,cdt);72 StrPrint(file,"%s/" INS_REG_PERSONAL_INITIALS "%02d%02d%02d.DD.Z",73 BlogWebDir(cdt),ds.year%100,ds.mon,ds.day_of_mon);74 return file;75}76 77public U8 *FileNameNumNext(U8 *files_find_mask,U8 *fmt)78{//Cnt files in a mask. Create next filename.79 CDirEntry *tmpde=FilesFind(files_find_mask);80 U8 *res=MStrPrint(fmt,FileCnt(tmpde));81 DirTreeDel(tmpde);82 return res;83}84 85public U0 BlogDCImgWrite(CDC *dc,CDate cdt=0)86{//Add dc to blog as BMP file.87 U8 file_mask[STR_LEN],file_name[STR_LEN],*st,*st2;88 if (!cdt) cdt=Now+local_time_offset;89 StrPrint(file_mask,"%s/Img*",BlogLocalDir(cdt));90 StrPrint(file_name,"%s/Img%%03d.BMP",BlogLocalDir(cdt));91 st=FileNameNumNext(file_mask,file_name);92 BMPWrite(st,dc);93 st2=TOSBlogAbs(st);94 Free(st);95 st=MStrPrint("/Wb%s",st2+2);96 Free(st2);97 "$HC,\"<img src=\\\"%s\\\" width=\\\"%d\\\" "98 "height=\\\"%d\\\" alt=\\\"\\\">\"$\n",st,dc->width,dc->height;99 Free(st);100}101 102public U0 BlogScrnShot()103{//Add scrn shot to blog as BMP file.104 Bool old_cursor=DocCursor,old_silent;105 CDC *dc1,*dc2;106 U8 *old_fp_draw_ms=gr.fp_draw_ms;107 gr.fp_draw_ms=NULL;108 Refresh(2);109 dc1=DCScrnCapture;110 dc2=DCExt(dc1,0,FONT_HEIGHT,GR_WIDTH-1,GR_HEIGHT-1);111 BlogDCImgWrite(dc2);112 gr.fp_draw_ms=old_fp_draw_ms;113 DCDel(dc1);114 DCDel(dc2);115 DocCursor(old_cursor);116 old_silent=Silent;117 FreshenBlog;118 Silent(old_silent);119}120 121public U0 FreshenBlog()122{//Regen html files for D:/Home/Web.123 DirMk("D:/Wb");124 DirMk("D:/Wb/Home");125 DirMk("D:/Wb/Home/Web");126 DirMk("D:/Wb/Home/Web/" INS_REG_PERSONAL_INITIALS);127 DirMk("D:/Wb/Home/Web/" INS_REG_PERSONAL_INITIALS "/BlogDir");128 129 FreshenWebDir("/Home/Web");130 FreshenWebDir("/Home/" INS_REG_PERSONAL_INITIALS "/TOSBlog");131 FreshenWebDir(BlogLocalDir+2);132 Drv('C');133}134 135public U0 Blog(Bool god_misc2=FALSE)136{//Make entry in blog.137 if (!FileFind(BlogLocalFile,,FUF_JUST_FILES))138 Copy("~/" INS_REG_PERSONAL_INITIALS "/TOSBlog/DailyBlogHeader.DD.Z",139 BlogLocalFile);140 AutoComplete;141 WinBorder;142 WinMax;143 Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN|SCF_CTRL);144 if (god_misc2)145 Msg(MSG_KEY_DOWN_UP,0,SC_F7|SCF_SHIFT|SCF_ALT);146 else {147 Msg(MSG_KEY_DOWN_UP,0,SC_F6|SCF_ALT);148 Msg(MSG_KEY_DOWN_UP,'\n',0);149 }150 Msg(MSG_KEY_DOWN_UP,CH_CTRLS,0x61F0000061F);151 if (Ed(BlogLocalFile,EDF_WAS_WRITE)) {152 DocOpt(BlogLocalFile,"-r");153 Copy(BlogLocalFile,"::" DAILY_SRC ".DD.Z");154 Copy(BlogLocalFile,"D:" DAILY_SRC ".DD.Z");155 Copy(BlogLocalFile,"D:/Wb" DAILY_DST ".DD.Z");156 TOSWebFile("D:/Wb" DAILY_DST ".DD.Z");157 FreshenBlog;158 }159}160 