Reposted. Posted originally on Jan. 24, 2020 on my personal web page at rawtext.club
I like genealogy. In this web site there is the history of my family. I once wrote a script in C++ to convert an ahnentafel into a gedcom file. I am publishing here the code. A compiled executable for Bill Gates lovers can be bought here.
Gedcom is a standard for digital genealogic trees. It was created by the Church of Jesus Christ of Latter-day Saints, who have contributed a great deal to genealogy in the recent decades. The ahnentafel is not properly speaking a digital format. It is a table of ancestors to narrate the family history. I had to make up some extremely ad hoc specifications for it, since there is no standardization of it.
The program will take a file named ahnentafel.txt
residing in the pwd and convert it to gedcom. The resulting gedcom file
should open in any major genealogy application. It was tested with Legacy.
This is the code:
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
using namespace std;
int main ()
{
string str[32768];
int i = 0, last;
string finalstring;
string genderfirstperson;
ifstream myFile("ahnentafel.txt");
if (! myFile)
{
cout << "Unable to open input file" << endl;
return -1;
}
while (! myFile.eof())
{
if ((i + 1) % 2 ==0) getline(myFile, str[i++]);
else getline(myFile, str[i++], '\t');
}
last = i;
i = 0;
ofstream myGedcomfile("tree.ged");
if (! myGedcomfile)
{
cout << "Error opening output file" << endl;
return -1;
}
while (i < last)
{
string anhnr;
int anhnumber;
string personsname;
anhnr = (str [i++]);
istringstream buffer(anhnr);
buffer >> anhnumber;
personsname = str [i++];
if (anhnr == "1")
{
cout << "Type gender of person nr 1: (M or F): ";
cin >> genderfirstperson;
finalstring = "0 HEAD\n0 @I" + anhnr + "@ INDI\n1 NAME " + personsname + "\n1 SEX " + genderfirstperson + "\n";
}
if (anhnumber % 2 == 0)
{
int child;
child = anhnumber/2;
std::string childstr;
std::stringstream out;
out << child;
childstr = out.str();
finalstring += "0 @I" + anhnr + "@ INDI\n1 NAME " + personsname + "\n" + "1 SEX M\n0 @I" + str[i] + "@ INDI\n1 NAME " + str[i+1] + "\n1 SEX F\n0 FAM\n1 HUSB @I" + anhnr + "@\n1 WIFE @I" + str[i] + "@\n1 CHIL @I" + childstr +"@\n";
}
}
myFile.close();
finalstring += "0 TRLR\n";
myGedcomfile << finalstring;
myGedcomfile.close();
return 0;
}
I didn’t even comment it at all. Now I have troble understanding it, after almost ten years. I am not a programmer. I did this in 2011 or so, after a 22-year gap. The last programming I had done by then was some childish stuff in the ZX Spectrum’s BASIC. I don’t even know why I chose C++ to do this ahnentafel to gedcom converter. I was new to Linux by then, I think I googled about “modern” programming languages, and C++ seemed just right for the task. Should I have to do it today, I would do it in BASH. C++ is overkill for this.
I can’t program in C++. I did the above script with the textbook on sight all the time, and took me about two weeks. It was an ordeal. I know a real C++ programmer could write this in half an hour, eyes closed.
This kind of utility had never been written, as far as I know. It is not very usefull for carefully managing one’s genealogical data. Still, this thing hadn’t been written. I read in some online forums about the possibility of writing it, I waited for someone to code it, bubkis, so I rolled up my sleeves, googled for programming languages, purchased online a C++ manual, and did it myself.
Hey, I sold it twice, which makes me a professional programmer.
Get back to my home page. Be excellent to each other. It is January 2020 now.
back Email: gasconheart@sdf.org