Posts database functions.
//////////////////////////////////////////////////////////////////////////////
Text PdbSep = Repeat("_",78);
//////////////////////////////////////////////////////////////////////////////
PutDescription("Post separator inside the agendas.", PdbSep);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbRead(Text inpDir)
//////////////////////////////////////////////////////////////////////////////
{
Real err(Text msg) { Text WriteLn("\nERROR: "+msg+"\n"); FALSE }; // Function
Text filSep = Char(7);
Text WriteLn("Reading "+inpDir+"...");
Text inpAll = DirReadFiles(inpDir, "age", filSep);
Text inpTxt = Replace(inpAll, PdbSep+"\n",filSep);
Set inpSet = Tokenizer(inpTxt,filSep);
Set inpTab = EvalSet(inpSet, Set(Text inf)
{
// Read
Set pstCla = Txt2Set( TxtBetween2Tag(inf,"<Pst.Cla>", "\n<Pst.", TRUE),";");
Text pstSta = Sub( TxtBetween2Tag(inf,"<Pst.Sta>", "\n<Pst.", TRUE)+"C",1,1); // C por defecto
Text pstCod = TxtBetween2Tag(inf,"<Pst.Cod>", "\n<Pst.", TRUE);
Text pstTh1 = PhtExpText( TxtBetween2Tag(inf,"<Pst.Tit>", "\n<Pst.", TRUE));
Text pstTit = TxtOutHtmScr(TxtBetween2Tag(inf,"<Pst.Tit>", "\n<Pst.", TRUE));
Date pstDte = Eval( TxtBetween2Tag(inf,"<Pst.Dte>", "\n<Pst.", TRUE));
Text pstAut = TxtBetween2Tag(inf,"<Pst.Aut>", "\n<Pst.", TRUE);
Text pstTxt = TxtBetween2Tag(inf,"<Pst.Txt>", "\n<Pst.", FALSE);
// Check
Text chkAut = If(pstAut=="", "Antonio Salmerón", pstAut);
Set chkCla = EvalSet(pstCla, Real(Text claNam) // Category class
{ If(claNam <: CatAll, TRUE, err("Class: "+pstCod+" "+claNam)) });
// Store
Set pstObj = PdbSt(pstCla, pstSta, pstCod, pstTh1, pstTit, pstDte, chkAut, pstTxt);
// Text WriteLn(PhtFileName(TxtOutside2Tag(pstObj->pstTit, "<", ">")));
pstObj
});
Set inpSel = Select(inpTab, Real(Set a) { a->pstSta != "A" }); // Not deleted
Set inpSor = Sort(inpSel, Real(Set a, Set b) // By code
{ Compare(a->pstCod, b->pstCod) });
// Check
Real chkDup =
{
Set codCla = Classify(inpTab, Real(Set a, Set b) // By name
{ Compare(a->pstCod,b->pstCod) });
Set codDup = EvalSet(codCla, Real(Set cla)
{
Real crd = Card(cla);
Text nam = cla[1]->pstCod;
If(EQ(crd,1), TRUE, err("Name: "+nam+" "+FormatReal(crd,"%.0lf")+" times"))
});
Set pthCla = Classify(inpTab, Real(Set a, Set b) // By external path / Title
{ Compare(PhtFileName(TxtOutside2Tag(a->pstTit, "<", ">")),
PhtFileName(TxtOutside2Tag(b->pstTit, "<", ">"))) });
Set pthDup = EvalSet(pthCla, Real(Set cla)
{
Real crd = Card(cla);
Text pth = cla[1]->pstCod;
If(EQ(crd,1), TRUE, err("Similar titles:\n ["+cla[1]->pstTit+"]\n ["+cla[2]->pstTit+"]"))
});
Card(codDup)+Card(pthDup)
};
Text WriteLn("Status ABC "+FormatReal(Card(inpTab),"%3.0lf")+" registers");
Text WriteLn("Status _BC "+FormatReal(Card(inpSel),"%3.0lf")+" registers");
inpSor
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Reads and returns a post database.",
PdbRead);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbFirstN(Set inpSet, // Post database
Real maxNum, // Maximum numbers of posts to return
Code funSel) // Post selection conditions
//////////////////////////////////////////////////////////////////////////////
{
Set selFst = Select(inpSet, funSel); // Select all that funSel()
SetFirstN(selFst, maxNum) // Fst maxNum or all if there are few
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the maxNum recents posts for funSel.",
PdbFirstN);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FILE : pdb.tol
// AUTHOR : http://www.asolver.com
// PURPOSE : Posts database functions.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// CONSTANTS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text PdbSep = Repeat("_",78);
//////////////////////////////////////////////////////////////////////////////
PutDescription("Post separator inside the agendas.", PdbSep);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbRead(Text inpDir)
//////////////////////////////////////////////////////////////////////////////
{
Real err(Text msg) { Text WriteLn("\nERROR: "+msg+"\n"); FALSE }; // Function
Text filSep = Char(7);
Text WriteLn("Reading "+inpDir+"...");
Text inpAll = DirReadFiles(inpDir, "age", filSep);
Text inpTxt = Replace(inpAll, PdbSep+"\n",filSep);
Set inpSet = Tokenizer(inpTxt,filSep);
Set inpTab = EvalSet(inpSet, Set(Text inf)
{
// Read
Set pstCla = Txt2Set( TxtBetween2Tag(inf,"<Pst.Cla>", "\n<Pst.", TRUE),";");
Text pstSta = Sub( TxtBetween2Tag(inf,"<Pst.Sta>", "\n<Pst.", TRUE)+"C",1,1); // C por defecto
Text pstCod = TxtBetween2Tag(inf,"<Pst.Cod>", "\n<Pst.", TRUE);
Text pstTh1 = PhtExpText( TxtBetween2Tag(inf,"<Pst.Tit>", "\n<Pst.", TRUE));
Text pstTit = TxtOutHtmScr(TxtBetween2Tag(inf,"<Pst.Tit>", "\n<Pst.", TRUE));
Date pstDte = Eval( TxtBetween2Tag(inf,"<Pst.Dte>", "\n<Pst.", TRUE));
Text pstAut = TxtBetween2Tag(inf,"<Pst.Aut>", "\n<Pst.", TRUE);
Text pstTxt = TxtBetween2Tag(inf,"<Pst.Txt>", "\n<Pst.", FALSE);
// Check
Text chkAut = If(pstAut=="", "Antonio Salmerón", pstAut);
Set chkCla = EvalSet(pstCla, Real(Text claNam) // Category class
{ If(claNam <: CatAll, TRUE, err("Class: "+pstCod+" "+claNam)) });
// Store
Set pstObj = PdbSt(pstCla, pstSta, pstCod, pstTh1, pstTit, pstDte, chkAut, pstTxt);
// Text WriteLn(PhtFileName(TxtOutside2Tag(pstObj->pstTit, "<", ">")));
pstObj
});
Set inpSel = Select(inpTab, Real(Set a) { a->pstSta != "A" }); // Not deleted
Set inpSor = Sort(inpSel, Real(Set a, Set b) // By code
{ Compare(a->pstCod, b->pstCod) });
// Check
Real chkDup =
{
Set codCla = Classify(inpTab, Real(Set a, Set b) // By name
{ Compare(a->pstCod,b->pstCod) });
Set codDup = EvalSet(codCla, Real(Set cla)
{
Real crd = Card(cla);
Text nam = cla[1]->pstCod;
If(EQ(crd,1), TRUE, err("Name: "+nam+" "+FormatReal(crd,"%.0lf")+" times"))
});
Set pthCla = Classify(inpTab, Real(Set a, Set b) // By external path / Title
{ Compare(PhtFileName(TxtOutside2Tag(a->pstTit, "<", ">")),
PhtFileName(TxtOutside2Tag(b->pstTit, "<", ">"))) });
Set pthDup = EvalSet(pthCla, Real(Set cla)
{
Real crd = Card(cla);
Text pth = cla[1]->pstCod;
If(EQ(crd,1), TRUE, err("Similar titles:\n ["+cla[1]->pstTit+"]\n ["+cla[2]->pstTit+"]"))
});
Card(codDup)+Card(pthDup)
};
Text WriteLn("Status ABC "+FormatReal(Card(inpTab),"%3.0lf")+" registers");
Text WriteLn("Status _BC "+FormatReal(Card(inpSel),"%3.0lf")+" registers");
inpSor
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Reads and returns a post database.",
PdbRead);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set PdbFirstN(Set inpSet, // Post database
Real maxNum, // Maximum numbers of posts to return
Code funSel) // Post selection conditions
//////////////////////////////////////////////////////////////////////////////
{
Set selFst = Select(inpSet, funSel); // Select all that funSel()
SetFirstN(selFst, maxNum) // Fst maxNum or all if there are few
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns the maxNum recents posts for funSel.",
PdbFirstN);
//////////////////////////////////////////////////////////////////////////////
iForense construye las paginas del sitio sobre informática forense Forense.Info
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio