summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClayton <nrootconauto@gmail.com>2023-03-01 18:30:44 -0500
committerClayton <nrootconauto@gmail.com>2023-03-01 18:30:44 -0500
commit9a46461e957a49883371737ef60e32c124686708 (patch)
tree2f06fd1487aab5900a18592e0be596c3722ef8ac
parent46c4fb262396c002994c7dad1ec5ec9b7dd07a17 (diff)
POST checks for profanity,returns sent text in TEXTAREA
Updated the assembler part of the wiki
-rw-r--r--T/Server/edit.HC31
-rw-r--r--T/Server/filter.HC1
-rw-r--r--T/Server/http.HC1
-rw-r--r--T/Server/run.HC2
-rw-r--r--T/Wiki/HolyAsm.WIKI91
5 files changed, 111 insertions, 15 deletions
diff --git a/T/Server/edit.HC b/T/Server/edit.HC
index 3661d7e..2882f6e 100644
--- a/T/Server/edit.HC
+++ b/T/Server/edit.HC
@@ -1,7 +1,8 @@
-U0 __EditGet(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req,U8 *file) {
+U0 __EditGet(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req,U8 *file,U8 *profan=NULL,U8 *edit_text=NULL) {
if(!UserPrivCheck(srv,stream,url,req,file)) return;
U8 *page=GetQueryValue(url->query,"PAGENAME"),*ptr,*ftxt,*t1,*ln,*t2;
- U8 *profan;
+ if(profan)
+ profan=StrNew(profan);
CConnection *con;
if(!page||!file) {
new_page:
@@ -48,9 +49,17 @@ new_page:
WikiHeader(stream,NULL,page,WHF_CHANGES);
WriteLn(stream,NULL,"<FORM ACTION=\""WIKI_EDIT"?PAGENAME=%s\"CLASS=\"form-group\" METHOD=\"POST\">",page);
WriteLn(stream,NULL,"<TEXTAREA NAME=\"PAGETEXT\" COLS=\"70\" ROWS=\"100\" TYPE=\"textarea\">");
- if(FileFind(file)) {
+ if(edit_text) {
+ ptr=edit_text;
+ while(ln=ReadLine(ptr,&ptr)) {
+ if(StrFirstOcc(ln,"\x0d\n"))
+ *StrFirstOcc(ln,"\x0d\n")=0;
+ t1=HTMLify(ln);
+ WriteLn(stream,NULL,"%s",t1);
+ Free(ln);Free(t1);
+ }
+ } else if(FileFind(file)) {
ptr=ftxt=FileRead(file);
- profan=HasProfanity(ftxt);
while(ln=ReadLine(ptr,&ptr)) {
if(StrFirstOcc(ln,"\x0d\n"))
*StrFirstOcc(ln,"\x0d\n")=0;
@@ -64,7 +73,6 @@ new_page:
t1=GetCurrentUserName;
BackupFile(page,"",0,t1,"c");
Free(t1),Free(t2);
- profan=NULL;
}
WriteLn(stream,NULL,"</TEXTAREA>");
if(profan) {
@@ -100,7 +108,7 @@ U0 EditGet(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req) {
U0 EditPost(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req,CHashTable *tab) {
CHashGeneric *hash=HashFind("PAGENAME",tab,-1),*hash2=HashFind("PAGETEXT",tab,-1),*hash3=HashFind("PREVIEW",tab,-1);
CConnection *con;
- U8 *link,*ftxt,*ptr,*t1,*ln,*plink,*t2,*profan;
+ U8 *link,*ftxt,*ptr,*t1,*ln,*plink,*t2,*profan=NULL;
Bool first_run=TRUE;
if(!hash&&!(t1=GetQueryValue(url->query,"PAGENAME"))) return;
if(hash) {
@@ -168,13 +176,12 @@ loop:
Free(t2);
}
}
- Free(profan);
- Free(ftxt);
if(hash3)
if(hash3&&!StrICmp(hash3->user_data1,"PREVIEW"))
- __EditGet(srv,stream,url,req,plink);
+ __EditGet(srv,stream,url,req,plink,profan,ftxt);
else
- __EditGet(srv,stream,url,req,link);
+ __EditGet(srv,stream,url,req,link,profan,ftxt);
+ Free(ftxt);
goto en;
}
if(FileFind(link)) {
@@ -196,6 +203,10 @@ loop:
}
Free(ftxt);
WriteLn(stream,NULL,"</TEXTAREA>");
+ if(profan) {
+ WriteLn(stream,NULL,"<DIV CLASS=\"alert alert-danger\">Use of profranity \"%s\"</DIV>",profan);
+ }
+ Free(profan);
WriteLn(stream,NULL,"<FIELDSET CLASS=\"form-group\">");
WriteLn(stream,NULL,"<LEGEND>Preview or Publish?</LEGEND>");
WriteLn(stream,NULL,"<LABEL CLASS=\"paper-radio\" FOR=\"PREVIEW\">");
diff --git a/T/Server/filter.HC b/T/Server/filter.HC
index 65841ad..9210d2e 100644
--- a/T/Server/filter.HC
+++ b/T/Server/filter.HC
@@ -41,6 +41,7 @@ CTrie *ConstructProfans() {
while(ln=ReadLine(ptr,&ptr)) {
if(StrFirstOcc(ln,"\n"))
*StrFirstOcc(ln,"\n")=0;
+ StrUtil(ln,SUF_REM_SPACES|SUF_REM_CTRL_CHARS);
TrieIns(profans,ln,ln);
Free(ln);
}
diff --git a/T/Server/http.HC b/T/Server/http.HC
index a33c10b..1b70a9d 100644
--- a/T/Server/http.HC
+++ b/T/Server/http.HC
@@ -642,6 +642,7 @@ found:
U0 ListenCallback(CDyadStream *s,CServer *srv) {
CUniqueToken *ut=MAlloc(sizeof(CUniqueToken));
ut->srv=srv;
+ DyadSetTimeout(s,30);
DyadSetReadCallback(s,&SReadLine,ut);
DyadSetOnCloseCallback(s,&CloseCallback,ut);
}
diff --git a/T/Server/run.HC b/T/Server/run.HC
index 0a61834..25c2ed5 100644
--- a/T/Server/run.HC
+++ b/T/Server/run.HC
@@ -77,4 +77,4 @@ if(!FileFind(WIKI_BACKUP))
#include "index.HC"
#include "cache.HC"
#include "users.HC"
-#include "gen_html.HC"; \ No newline at end of file
+#include "gen_html.HC"; \ No newline at end of file
diff --git a/T/Wiki/HolyAsm.WIKI b/T/Wiki/HolyAsm.WIKI
index 8a16954..77fb71a 100644
--- a/T/Wiki/HolyAsm.WIKI
+++ b/T/Wiki/HolyAsm.WIKI
@@ -382,7 +382,7 @@ Many of the awesome FPU instructions end in _P_. This means the instruction *POP
Main;
== Mixing it up: Floating-Points with Integers
-Mixing Integers and Floating!-Points is quite easy. We are given the *FILD* instruction for loading integers into the *X87 FPU*. If we want to store a floating point into an integer,we can use *FISTP*(which *POP*s for us)
+Mixing Integers and Floating!-Points is quite easy. We are given the *FILD* instruction for loading integers into the *X87 FPU*. If we want to store a floating point into an integer,we can use *FISTP*(which *POP*s for us). +We can "FLD ST0" to clone the first FPU stack item by loading it onto the stack(again)+
U0 SayF64(F64 f) {
"I Got %n\n",f;
@@ -392,8 +392,8 @@ Mixing Integers and Floating!-Points is quite easy. We are given the *FILD* inst
_MAIN::
PUSH RBP
MOV RBP,RSP
- FILD U64 SF_ARG1[RBP] //a
- FILD U64 SF_ARG2[RBP] //b
+ FILD U64 SF_ARG1[RBP] //I64 a
+ FILD U64 SF_ARG2[RBP] //I64 b
//FPU Stack is
// ST1=>a
@@ -427,4 +427,87 @@ Mixing Integers and Floating!-Points is quite easy. We are given the *FILD* inst
_extern _MAIN I64 Main(I64,I64);
Main(5,3);
- "integer is now %d\n",integer; \ No newline at end of file
+ "integer is now %d\n",integer;
+
+== Making Declsions(2): Floating Point edition
+Your best freind when it comes to making (float!-ing point) decisions is +FCOMIP+. This will set the *EFlags* register. +BE SURE TO USE THE "UNSIGNED" STYLE JUMPS AFTER FCOMIP+. This is because *FCOMIP* doesnt set all the flags needed for _signed_ style jumps.
+
+ U0 Say(U64 ch) {
+ "%c\n",ch;
+ }
+ asm {
+ _MAIN::
+ PUSH RBP
+ MOV RBP,RSP
+ FLD U64 SF_ARG1[RBP] //F64 a
+ FLD U64 SF_ARG2[RBP] //F64 b
+ //we want to compare a,b(we current have b,a on the stack)
+ FXCH ST1 //(Exchanges ST0 with STn)
+ FCOMIP ST0,ST1
+ FSTP ST0 //Pop ST0(storing into itself does nothing)
+ //>
+ JNA @@gt
+ PUSHFD //Push the flags to the stack
+ PUSH '>' //This argument will be eaten by Say
+ CALL &Say
+ POPFD //Restore the flags from the stack
+ @@gt:
+ //'<'
+ JNB @@lt
+ PUSHFD
+ PUSH '<'
+ CALL &Say
+ POPFD
+ @@lt:
+ //==
+ JNE @@eq
+ PUSHFD
+ PUSH '=='
+ CALL &Say
+ POPFD
+ @@eq:
+ //!=
+ JE @@ne
+ PUSHFD
+ PUSH '!='
+ CALL &Say
+ POPFD
+ @@ne:
+ //>=
+ JNAE @@ge
+ PUSHFD
+ PUSH '>='
+ CALL &Say
+ POPFD
+ @@ge:
+ //<=
+ JNBE @@le
+ PUSHFD
+ PUSH '<='
+ CALL &Say
+ POPFD
+ @@le:
+ LEAVE
+ RET1 2*8
+ }
+ _extern _MAIN U0 Main(F64,F64);
+ "=== %n,%n ===\n",-1.,5.;
+ Main(-1.,5.);
+ "=== %n,%n ===\n",5.,-1.;
+ Main(5.,-1.);
+ "=== %n,%n ===\n",5.,5.;
+ Main(5.,5.);
+
+== Floating Point Operations list
+* FCHS //+Make ST0 negative+(CHange Sign)
+* FADDP STn,ST0 (Add)
+* FMULP STn,ST0 (Multiply)
+* FDIVP STn,ST0 (Divide)
+* FPREM //+Modulo for Floating Points+
+* FLD U64 [addr] //Load a floating point
+* FILD U64 [addr] //Load an integer as a floating point
+* FST U64 [addr] //Store a floating point
+* FIST U64 [addr] //Store a floating point as an integer
+* FXCH STn //Swap ST0 with STn
+
+The FPU lacks an exponet operation,so call Pow from assembly \ No newline at end of file