File size: 4,325 Bytes
806d4b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

#help_index "Misc/Blog"

public Bool IsTOSBlog(U8 *filename)
{//Is this in the TOSBlog dir?
  Bool res;
  U8 *st=DirNameAbs(filename),*home=DirNameAbs("~");
  I64 l=StrLen(home);
  if (StrLen(st)>=l+12 && !StrNCmp(st+1,home+1,l-1) &&
      st[l]=='/' && !StrNCmp(st+l+4,"/TOSBlog",8))
    res=TRUE;
  else
    res=FALSE;
  Free(st);
  Free(home);
  return res;
}

public U8 *TOSBlogAbs(U8 *filename)
{//Absolute filename, adjusted for moving TOSBlog.
  U8 *st=DirNameAbs(filename),*home=DirNameAbs("~");
  I64 l=StrLen(home);
  if (IsTOSBlog(st)) {
    MemCpy(st+l+5,st+l+1,3);
    MemCpy(st+l+1,"Web",3);
    StrCpy(st+l+8,st+l+12);
  }
  Free(home);
  return st;
}

public U8 *BlogLocalDir(CDate cdt=0)
{//MAlloc dirname of blog for date.
  static U8 dir[STR_LEN];
  CDateStruct ds;
  if (!cdt) cdt=Now+local_time_offset;
  Date2Struct(&ds,cdt);
  StrPrint(dir,BLOG_LOCAL_SRC "/%d%Z",ds.year,ds.mon-1,"ST_MONTHS");
  if (!FileFind(dir,,FUF_JUST_DIRS))
    DirMk(dir);
  return dir;
}

public U8 *BlogLocalFile(CDate cdt=0)
{//MAlloc filename of blog for date.
  static U8 file[STR_LEN];
  CDateStruct ds;
  if (!cdt) cdt=Now+local_time_offset;
  Date2Struct(&ds,cdt);
  StrPrint(file,"%s/" INS_REG_PERSONAL_INITIALS "%02d%02d%02d.DD.Z",
        BlogLocalDir(cdt),ds.year%100,ds.mon,ds.day_of_mon);
  return file;
}

public U8 *BlogWebDir(CDate cdt=0)
{//MAlloc D:/Wb/dirname of blog for date.
  static U8 dir[STR_LEN];
  CDateStruct ds;
  if (!cdt) cdt=Now+local_time_offset;
  Date2Struct(&ds,cdt);
  StrPrint(dir,BLOG_WEB_DST "/%d%Z",
        ds.year,ds.mon-1,"ST_MONTHS");
  return dir;
}

public U8 *BlogWebFile(CDate cdt=0)
{//MAlloc D:/Wb/filename of blog for date.
  static U8 file[STR_LEN];
  CDateStruct ds;
  if (!cdt) cdt=Now+local_time_offset;
  Date2Struct(&ds,cdt);
  StrPrint(file,"%s/" INS_REG_PERSONAL_INITIALS "%02d%02d%02d.DD.Z",
        BlogWebDir(cdt),ds.year%100,ds.mon,ds.day_of_mon);
  return file;
}

public U8 *FileNameNumNext(U8 *files_find_mask,U8 *fmt)
{//Cnt files in a mask. Create next filename.
  CDirEntry *tmpde=FilesFind(files_find_mask);
  U8 *res=MStrPrint(fmt,FileCnt(tmpde));
  DirTreeDel(tmpde);
  return res;
}

public U0 BlogDCImgWrite(CDC *dc,CDate cdt=0)
{//Add dc to blog as BMP file.
  U8 file_mask[STR_LEN],file_name[STR_LEN],*st,*st2;
  if (!cdt) cdt=Now+local_time_offset;
  StrPrint(file_mask,"%s/Img*",BlogLocalDir(cdt));
  StrPrint(file_name,"%s/Img%%03d.BMP",BlogLocalDir(cdt));
  st=FileNameNumNext(file_mask,file_name);
  BMPWrite(st,dc);
  st2=TOSBlogAbs(st);
  Free(st);
  st=MStrPrint("/Wb%s",st2+2);
  Free(st2);
  "$HC,\"<img src=\\\"%s\\\" width=\\\"%d\\\" "
        "height=\\\"%d\\\" alt=\\\"\\\">\"$\n",st,dc->width,dc->height;
  Free(st);
}

public U0 BlogScrnShot()
{//Add scrn shot to blog as BMP file.
  Bool old_cursor=DocCursor,old_silent;
  CDC *dc1,*dc2;
  U8 *old_fp_draw_ms=gr.fp_draw_ms;
  gr.fp_draw_ms=NULL;
  Refresh(2);
  dc1=DCScrnCapture;
  dc2=DCExt(dc1,0,FONT_HEIGHT,GR_WIDTH-1,GR_HEIGHT-1);
  BlogDCImgWrite(dc2);
  gr.fp_draw_ms=old_fp_draw_ms;
  DCDel(dc1);
  DCDel(dc2);
  DocCursor(old_cursor);
  old_silent=Silent;
  FreshenBlog;
  Silent(old_silent);
}

public U0 FreshenBlog()
{//Regen html files for D:/Home/Web.
  DirMk("D:/Wb");
  DirMk("D:/Wb/Home");
  DirMk("D:/Wb/Home/Web");
  DirMk("D:/Wb/Home/Web/" INS_REG_PERSONAL_INITIALS);
  DirMk("D:/Wb/Home/Web/" INS_REG_PERSONAL_INITIALS "/BlogDir");

  FreshenWebDir("/Home/Web");
  FreshenWebDir("/Home/" INS_REG_PERSONAL_INITIALS "/TOSBlog");
  FreshenWebDir(BlogLocalDir+2);
  Drv('C');
}

public U0 Blog(Bool god_misc2=FALSE)
{//Make entry in blog.
  if (!FileFind(BlogLocalFile,,FUF_JUST_FILES))
    Copy("~/" INS_REG_PERSONAL_INITIALS "/TOSBlog/DailyBlogHeader.DD.Z",
          BlogLocalFile);
  AutoComplete;
  WinBorder;
  WinMax;
  Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN|SCF_CTRL);
  if (god_misc2)
    Msg(MSG_KEY_DOWN_UP,0,SC_F7|SCF_SHIFT|SCF_ALT);
  else {
    Msg(MSG_KEY_DOWN_UP,0,SC_F6|SCF_ALT);
    Msg(MSG_KEY_DOWN_UP,'\n',0);
  }
  Msg(MSG_KEY_DOWN_UP,CH_CTRLS,0x61F0000061F);
  if (Ed(BlogLocalFile,EDF_WAS_WRITE)) {
    DocOpt(BlogLocalFile,"-r");
    Copy(BlogLocalFile,"::" DAILY_SRC ".DD.Z");
    Copy(BlogLocalFile,"D:" DAILY_SRC ".DD.Z");
    Copy(BlogLocalFile,"D:/Wb" DAILY_DST ".DD.Z");
    TOSWebFile("D:/Wb" DAILY_DST ".DD.Z");
    FreshenBlog;
  }
}