#include #include "config.h" #include "sm.h" #include "util.h" extern char kcontentdir[]; extern char krssexport[]; extern char krsstitle[]; extern char krssdescription[]; extern char krsslink[]; static void rssexport(Document **, int); Plugin rss = {"rss", rssexport, NULL, 0}; static int creatcompar(const Document **d1, const Document **d2) { return (*d2)->creat - (*d1)->creat; } static void rssexport(Document **doc, int ndoc) { char inpath[512]; FILE *outf; int i, j; char *header[] = { "\ \n\ \n\ \n\ \n\ ", krsstitle, "\n\ ", krssdescription, "\n\ en-us\n\ ", krsslink, "\n\ sm-"VERSION"\n\ \n\ " }; char *footer[] = { "\ \n\ \n\ " }; char filename[64], title[128], creat[64], link[CLEN]; char *itemheader[] = { "\ \n\ ", title, "\n\ ", filename, "\n\ ", creat, "\n\ ", link, "\n\ \n\ \n\ " }; qsort(doc, ndoc, sizeof(*doc), (int (*)(const void *, const void *))creatcompar); outf = xfopen(krssexport, "w"); for (j = 0; j < LEN(header); j++) xfputs(header[j], outf); for (i = 0; i < ndoc; i++) { snprintf(inpath, sizeof(inpath), "%s/%s", kcontentdir, doc[i]->filename); my_strlcpy(filename, doc[i]->filename, sizeof(filename)); my_strlcpy(title, doc[i]->title, sizeof(title)); strftime(creat, sizeof(creat), "%a, %d %b %Y %H:%M:%S %z", gmtime(&doc[i]->creat)); my_strlcpy(link, doc[i]->link, sizeof(link)); for (j = 0; j < LEN(itemheader); j++) xfputs(itemheader[j], outf); cat(inpath, outf); for (j = 0; j < LEN(itemfooter); j++) xfputs(itemfooter[j], outf); } for (j = 0; j < LEN(footer); j++) xfputs(footer[j], outf); fclose(outf); }