rotoの日記: iEPGを壁カレに食わせるコード
日記 by
roto
エラーチェックはザツ。
#include "stdafx.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
// int main(int argc, char* argv[])
{
std::locale::global(std::locale("japanese"));
if(__argc < 2)
{
std::cout << "USAGE: iEPG2CSV <input.tvpi> [output.CSV]" << std::endl;
exit(1);
}
std::string csvFile = "TV.CSV";
if(__argc >= 3)
{
csvFile = __argv[2];
}
std::string iepgFile = __argv[1];
std::ifstream fin(iepgFile.c_str());
if(fin.is_open())
{
bool isComment = false;
std::map<std::string, std::string> iepg;
while(!fin.eof())
{
char buf[1024];
fin.getline(buf, sizeof(buf));
std::string str = buf;
if(str.length() == 0)
{
isComment = true;
continue;
}
if(!isComment)
{
int token = str.find(' ');
if(token != std::string::npos)
{
iepg[str.substr(0, token)] = str.substr(token + 1);
}
}
else
{
// comment
iepg["comment"] += str;
}
}
std::ofstream fout(csvFile.c_str(), std::ios::out | std::ios::app);
fout << iepg["year:"] << iepg["month:"] << iepg["date:"] << ","
<< iepg["start:"] << iepg["program-title:"] << std::endl;
}
return 0;
}
#include "stdafx.h"
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
// int main(int argc, char* argv[])
{
std::locale::global(std::locale("japanese"));
if(__argc < 2)
{
std::cout << "USAGE: iEPG2CSV <input.tvpi> [output.CSV]" << std::endl;
exit(1);
}
std::string csvFile = "TV.CSV";
if(__argc >= 3)
{
csvFile = __argv[2];
}
std::string iepgFile = __argv[1];
std::ifstream fin(iepgFile.c_str());
if(fin.is_open())
{
bool isComment = false;
std::map<std::string, std::string> iepg;
while(!fin.eof())
{
char buf[1024];
fin.getline(buf, sizeof(buf));
std::string str = buf;
if(str.length() == 0)
{
isComment = true;
continue;
}
if(!isComment)
{
int token = str.find(' ');
if(token != std::string::npos)
{
iepg[str.substr(0, token)] = str.substr(token + 1);
}
}
else
{
// comment
iepg["comment"] += str;
}
}
std::ofstream fout(csvFile.c_str(), std::ios::out | std::ios::app);
fout << iepg["year:"] << iepg["month:"] << iepg["date:"] << ","
<< iepg["start:"] << iepg["program-title:"] << std::endl;
}
return 0;
}