summaryrefslogtreecommitdiff
path: root/blog/content/util/indexer.cpp
blob: b0726332bc89b0723a91638730eb7b1765f82953 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//filename		title		date		tags
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#define stripr(s) s[strlen(s)-1]=='\n'?s[strlen(s)-1]=0:0
std::vector<std::string> fn;
char buf1[65536],buf2[65536],buf3[65536];
int main()
{
	struct dirent* pd;DIR* pdir;
	pdir=opendir("/var/www/html/blog/content");
	while((pd=readdir(pdir))!=NULL)
	{
		std::string s(pd->d_name);
		if(s.length()<4)continue;
		if(s.substr(s.length()-4)==".txt")
		fn.push_back(s.substr(0,s.length()-4));
	}
	closedir(pdir);
	std::sort(fn.begin(),fn.end(),std::greater<std::string>());
	FILE *f,*rf;
	f=fopen("/var/www/html/blog/content/pindex","w");
	for(size_t i=0;i<fn.size();++i)
	{
		puts(("/var/www/html/blog/content/"+fn[i]+".txt").c_str());
		struct stat st;struct tm* mt;
		stat(("/var/www/html/blog/content/"+fn[i]+".txt").c_str(),&st);
		mt=localtime(&st.st_mtime);
		rf=fopen(("/var/www/html/blog/content/"+fn[i]+".txt").c_str(),"r");
		fgets(buf1,65536,rf);stripr(buf1);
		fgets(buf2,65536,rf);stripr(buf2);
		fgets(buf3,65536,rf);stripr(buf3);
		if(strstr(buf2,"WIP")){puts(" SKIPPED");continue;}
		fprintf(f,"%s\t",fn[i].c_str());
		fprintf(f,"%s\t",buf1);
		fprintf(f,"%s/%d-%02d-%02d\t",buf2,mt->tm_year+1900,mt->tm_mon+1,mt->tm_mday);
		fprintf(f,"%s\n",buf3);
		fclose(rf);
	}
	fclose(f);
}