Skip to content

Instantly share code, notes, and snippets.

@t-nissie
Last active August 29, 2015 13:57
Show Gist options
  • Save t-nissie/9771048 to your computer and use it in GitHub Desktop.
Save t-nissie/9771048 to your computer and use it in GitHub Desktop.
crd2enex: cardfile (.crd file of Windows 3.1) to Evernote export format (.enex) converter
// crd2enex.cpp
// Description: cardfile (.crd file of Windows 3.1) to Evernote export format (.enex) converter
// Copyright (C) 2014,2015 Takeshi Nishimatsu
// Gist: https://gist.github.com/t-nissie/9771048
// Compile: g++ -Wall -g -o crd2enex crd2enex.cpp
// Usage: ./crd2enex English.crd > English.enex
// ./crd2enex Japanese.crd | nkf -S -w > Japanese.enex
// Bug: If a card has <> or [] in its text, its converted note will be irregular.
// You can find the irregularity by synchronization failure of the note.
// Please fix the irregular note manually.
// License: crd2enex.cpp is distributed in the hope that
// it will be useful, but WITHOUT ANY WARRANTY.
// You can copy, modify and redistribute crd2enex.cpp,
// but only under the conditions described in
// the GNU General Public License version 3 (the "GPLv3").
////
#include <stdlib.h>
#include <fstream>
#include <iostream>
int main( int argc, char *argv[] )
{
int i, j;
int NCard=0, ContentsLength=0 ;
char c, Index[41];
long ContentsSeekOffset=0L;
char *psNCard = (char *)&NCard;
char *psContentsSeekOffset = (char *)&ContentsSeekOffset;
char *psContentsLength = (char *)&ContentsLength;
Index[40]=0;
//****************** open the file *********************
std::ifstream inCardFile(argv[1], std::ios::in);
inCardFile.seekg(0L, std::ios::end );
if ( inCardFile.tellg() < 0) {
std::cerr << __FILE__ << ": cannot open file, " << argv[1] << std::endl;
exit(1);
}
//******** get NCard, the number of the cards *********
inCardFile.seekg( 3L, std::ios::beg );
inCardFile.read( psNCard, 2 );
//std::cout << NCard << std::endl;
std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl
<< "<!DOCTYPE en-export SYSTEM \"http://xml.evernote.com/pub/evernote-export.dtd\">" << std::endl
<< "<en-export export-date=\"20100503T054739Z\" application=\"Evernote\" version=\"Evernote Mac 1.8.1 (79826)\">"
<< std::endl;
//*************************************************************
// LOOP
//*************************************************************
for(i=0 ; i < NCard ; i++){
//******************************************************
// get Index
//******************************************************
inCardFile.seekg( 52L*i+11L, std::ios::beg );
inCardFile.read( psContentsSeekOffset, 4 ); //*** get ContentsSeekOffset **
inCardFile.seekg( 1L, std::ios::cur );
inCardFile.read( Index, 40 ); //******* get Index ********
//****** print index *******************************
std::cout << "<note><title>" << Index << "</title><content><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n<en-note style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; \"><span style=\"font-weight: bold;\">" << Index << "</span><br clear=\"none\" />";
//******************************************************
// get contents and print cards
//******************************************************
inCardFile.seekg( ContentsSeekOffset+2L, std::ios::beg );
inCardFile.read( psContentsLength, 2 ); //*** get contentsLength ***
//****** get contents and print contents ***********
for (j=0 ; j<ContentsLength ; j++) {
inCardFile.read( &c, 1 );
if(c!=13) std::cout.write( &c, 1 );
}
std::cout << "<br clear=\"none\" /><br clear=\"none\" /></en-note>]]></content></note>" << std::endl;
}
return 0;
}
//Local variables:
// compile-command: "g++ -Wall -g -o crd2enex crd2enex.cpp && ./crd2enex science.crd | nkf -S -w > science.enex"
//End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment