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); // Bell character
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 each field
Set pstCla =
{
Text claTxt = TxtBetween2Tag(inf,"<Pst.Cla>","\n<Pst.",TRUE);
Set claSet = Txt2Set(claTxt, ";");
Case( // Categoria de completo para los que han de salir en completo
Card(claSet * CatBuy), claSet, // Hay interseccion con la tienda
"Buscar" <: claSet, claSet, // Es de busqueda
TRUE, claSet <<
[["Completo"]]) // Post normal a completo
};
Text pstSta = // C por defecto
Sub( TxtBetween2Tag(inf,"<Pst.Sta>", "\n<Pst.", TRUE)+"C",1,1);
Text pstCod = TxtBetween2Tag(inf,"<Pst.Cod>", "\n<Pst.", TRUE);
Text pstRed =
PhtRedTitle( TxtBetween2Tag(inf,"<Pst.Tit>", "\n<Pst.", TRUE));
Text pstTit = TxtOutHtmScr(pstRed);
Date pstDte =
Eval( TxtBetween2Tag(inf,"<Pst.Dte>", "\n<Pst.", TRUE));
Text pstTyp = TxtBetween2Tag(inf,"<Pst.Typ>", "\n<Pst.", TRUE);
Text pstAut = TxtBetween2Tag(inf,"<Pst.Aut>", "\n<Pst.", TRUE);
Text pstHtm =
PhtRedText( TxtBetween2Tag(inf,"<Pst.Txt>", "\n<Pst.", FALSE));
Text pstTxt = TxtOutHtmScr(pstHtm);
Text pstLnk =
PhtRedText( TxtBetween2Tag(inf,"<Pst.Lnk>", "\n<Pst.", FALSE));
Text pstPay = TxtBetween2Tag(inf,"<Pst.Pay>", "\n<Pst.", FALSE);
Text pstRem = TxtBetween2Tag(inf,"<Pst.Rem>", "\n<Pst.", FALSE);
// Check valid end <Pst.End> not old end <End>
Real chkEnd = If(TextFind(inf,"<Pst.End>"), TRUE,
err("Not <Pst.End> at: "+pstCod));
// Check that all categories are valid
Set chkCla = EvalSet(pstCla, Real(Text claNam) // Category class
{ If(claNam <: CatAll, TRUE, err("Class: "+pstCod+" "+claNam)) });
// Build a Pdb object and returns it
PdbSt(pstCla, pstSta, pstCod, pstRed, pstTit, pstDte, pstTyp,
pstAut, pstHtm, pstTxt, pstLnk, pstPay, pstRem)
});
// Seleccionar los post no anulado
Set inpSel = Select(inpTab, Real(Set a) { a->pstSta != "A" }); // No Anulado
// Ordenar por el codigo (clave) del post
Set inpSor = Sort(inpSel, Real(Set a, Set b) // By code
{ Compare(a->pstCod, b->pstCod) });
Real chkDup = // Check duplicated posts, with the same code
{
Set codCla = Classify(inpTab, Real(Set a, Set b) // By code
{ 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"))
});
// Los titulos han de ser diferentes para que los ficheros sean diferentes
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 ABCD "+FormatReal(Card(inpTab),"%3.0lf")+" registers");
Text WriteLn("Status _BCD "+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); // Bell character
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 each field
Set pstCla =
{
Text claTxt = TxtBetween2Tag(inf,"<Pst.Cla>","\n<Pst.",TRUE);
Set claSet = Txt2Set(claTxt, ";");
Case( // Categoria de completo para los que han de salir en completo
Card(claSet * CatBuy), claSet, // Hay interseccion con la tienda
"Buscar" <: claSet, claSet, // Es de busqueda
TRUE, claSet <<
[["Completo"]]) // Post normal a completo
};
Text pstSta = // C por defecto
Sub( TxtBetween2Tag(inf,"<Pst.Sta>", "\n<Pst.", TRUE)+"C",1,1);
Text pstCod = TxtBetween2Tag(inf,"<Pst.Cod>", "\n<Pst.", TRUE);
Text pstRed =
PhtRedTitle( TxtBetween2Tag(inf,"<Pst.Tit>", "\n<Pst.", TRUE));
Text pstTit = TxtOutHtmScr(pstRed);
Date pstDte =
Eval( TxtBetween2Tag(inf,"<Pst.Dte>", "\n<Pst.", TRUE));
Text pstTyp = TxtBetween2Tag(inf,"<Pst.Typ>", "\n<Pst.", TRUE);
Text pstAut = TxtBetween2Tag(inf,"<Pst.Aut>", "\n<Pst.", TRUE);
Text pstHtm =
PhtRedText( TxtBetween2Tag(inf,"<Pst.Txt>", "\n<Pst.", FALSE));
Text pstTxt = TxtOutHtmScr(pstHtm);
Text pstLnk =
PhtRedText( TxtBetween2Tag(inf,"<Pst.Lnk>", "\n<Pst.", FALSE));
Text pstPay = TxtBetween2Tag(inf,"<Pst.Pay>", "\n<Pst.", FALSE);
Text pstRem = TxtBetween2Tag(inf,"<Pst.Rem>", "\n<Pst.", FALSE);
// Check valid end <Pst.End> not old end <End>
Real chkEnd = If(TextFind(inf,"<Pst.End>"), TRUE,
err("Not <Pst.End> at: "+pstCod));
// Check that all categories are valid
Set chkCla = EvalSet(pstCla, Real(Text claNam) // Category class
{ If(claNam <: CatAll, TRUE, err("Class: "+pstCod+" "+claNam)) });
// Build a Pdb object and returns it
PdbSt(pstCla, pstSta, pstCod, pstRed, pstTit, pstDte, pstTyp,
pstAut, pstHtm, pstTxt, pstLnk, pstPay, pstRem)
});
// Seleccionar los post no anulado
Set inpSel = Select(inpTab, Real(Set a) { a->pstSta != "A" }); // No Anulado
// Ordenar por el codigo (clave) del post
Set inpSor = Sort(inpSel, Real(Set a, Set b) // By code
{ Compare(a->pstCod, b->pstCod) });
Real chkDup = // Check duplicated posts, with the same code
{
Set codCla = Classify(inpTab, Real(Set a, Set b) // By code
{ 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"))
});
// Los titulos han de ser diferentes para que los ficheros sean diferentes
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 ABCD "+FormatReal(Card(inpTab),"%3.0lf")+" registers");
Text WriteLn("Status _BCD "+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);
//////////////////////////////////////////////////////////////////////////////
Ediciones.aContracorriente construye las páginas del sitio web edicionesacontracorriente.com
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio