Uriel Web Browser for TempleOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

153 lines
3.6 KiB

#define URIEL_GETPAGE 0x10
#define URIEL_NAVBACK 0x11
#define URIEL_NAVFWD 0x12
#define URIEL_THUMB 0x13
#define URIEL_DOWNLOAD 0x14
#define URIEL_DL_PATH "::/Home/Downloads/"
#define URIEL_THUMB_BMP "/Tmp/UrielThumb.bmp"
#define URIEL_VERSION "Uriel/0.2"
U8 URIEL_USER_AGENT[64];
StrCpy(URIEL_USER_AGENT, URIEL_VERSION);
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), " (");
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), Define("DD_OS_NAME_VERSION"));
StrCpy(URIEL_USER_AGENT+StrLen(URIEL_USER_AGENT), ")");
U0 U_CloseBrowser()
{
Bool close=FALSE;
close = PopUpCancelOk("Close Uriel Browser?");
if (close) { In("x\n"); };
}
U0 U_InsertThumb(U8 *anchor, U8 *indent, U8 *outdent, U8 *url)
{
DocAnchorFind(DocPut,anchor);
I64 size;
ZeroParamBuf;
StrCpy(HGBD_PARAM_BUF,URIEL_USER_AGENT);
WriteParamBuf;
BlkWrite(HGBD,url,1,(StrLen(url)/BLK_SIZE)+1);
HGExec(URIEL_THUMB);
ReadParamBuf;
size = Str2I64(HGBD_PARAM_BUF);
if (size==-1) {
PopUpOk("Error loading image.");
return;
};
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
FileWrite(URIEL_THUMB_BMP, HGFS_BUF, size);
DocAnchorFind(DocPut,anchor);
DocBMP(,URIEL_THUMB_BMP);
if (StrCmp(indent,"")!=0) {
DocAnchorFind(DocPut,indent);
DocPrintPartial(DocPut,"$ID,14$");
};
if (StrCmp(indent,"")!=0) {
DocAnchorFind(DocPut,outdent);
DocPrintPartial(DocPut,"$ID,-14$");
};
DocAnchorFind(DocPut,anchor);
}
U0 U_Browser(U8 *url)
{
I64 size;
U8 *cmd;
ZeroParamBuf;
StrCpy(HGBD_PARAM_BUF,URIEL_USER_AGENT);
WriteParamBuf;
BlkWrite(HGBD,url,1,(StrLen(url)/BLK_SIZE)+1);
HGExec(URIEL_GETPAGE);
ReadParamBuf;
size = Str2I64(HGBD_PARAM_BUF);
if (size==-1) {
PopUpOk("Bad URL.");
return;
};
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
MemSetU8(ToI64(HGFS_BUF)+size, 0x0, 1);
WinMax;
CDoc *page = DocNew();
DocPrintPartial(page,HGFS_BUF);
DocClear;
DocInsDoc(DocPut,page);
DocTop;
DocDel(page);
while (TRUE) {
cmd = GetStr;
if (StrCmp(cmd,"x")==0) { break; };
}
Free(cmd);
DocBottom;
}
U0 U_HistNav(I64 index)
{
I64 size;
U8 *cmd;
ZeroParamBuf;
if (index==0) { HGExec(URIEL_NAVBACK); };
if (index==1) { HGExec(URIEL_NAVFWD); };
ReadParamBuf;
size = Str2I64(HGBD_PARAM_BUF);
if (size==-1) {
PopUpOk("Bad URL.");
return;
};
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
MemSetU8(ToI64(HGFS_BUF)+size, 0x0, 1);
WinMax;
CDoc *page = DocNew();
DocPrintPartial(page,HGFS_BUF);
DocClear;
DocInsDoc(DocPut,page);
DocTop;
DocDel(page);
while (TRUE) {
cmd = GetStr;
if (StrCmp(cmd,"x")==0) { break; };
}
Free(cmd);
DocBottom;
}
U0 U_Download(U8 *url)
{
I64 size;
U8 localfile[StrLen(URIEL_DL_PATH)+28];
U8 msg[128];
StrCpy(localfile,URIEL_DL_PATH);
if (StrLen(StrLastOcc(url,"/")+1)>0) {
StrCpy(localfile+StrLen(localfile), StrLastOcc(url,"/")+1);
} else {
StrCpy(localfile+StrLen(localfile), "Download.OUT");
};
ZeroParamBuf;
HGExec(URIEL_DOWNLOAD);
ReadParamBuf;
size = Str2I64(HGBD_PARAM_BUF);
if (size==-1) {
PopUpOk("Bad URL.");
return;
};
BlkRead(HGBD,HGFS_BUF,1,(size/BLK_SIZE)+1);
if (StrCmp(localfile+StrLen(localfile)-2,".Z")==0) {
U8 uzlocalfile[StrLen(URIEL_DL_PATH)+28];
MemCpy(uzlocalfile,localfile,StrLen(localfile)-2);
uzlocalfile[StrLen(localfile)-1] = 0x0;
FileWrite(uzlocalfile, HGFS_BUF, size);
Move(uzlocalfile, localfile);
} else {
FileWrite(localfile, HGFS_BUF, size);
};
StrCpy(msg, "Downloaded file: ");
StrCpy(msg+StrLen(msg), localfile);
PopUpOk(msg);
}
U0 U_Navigate(U8 *anchor, U8 *url) {
DocAnchorFind(DocPut,anchor);
U_Browser(url);
}