int InitializeCodetables () { int Result = E_PERFECTSUCCESS; //060115 don't load if already loaded // -- look at an arbitrary one, but not near the beginning because // it may be null on purpose if (UTF2MARC[1000].utf8[0]) return Result; int i; long kk; char* tablenames [] = {"MARC2UTF", "UTF2MARC"}; long table_len; // pointers to first element in each table charconvert_rt* tables [] = {MARC2UTF, UTF2MARC}; FILE* FH; char t_line [80]; WString tablename, t_string; WStringArray tlinearray; charconvert_rt* thistable; // loop to load multiple tables for (i = 0; i < (sizeof (tables) / sizeof (thistable)); i++) { tablename = tablenames [i]; if (i == 0) table_len = sizeof (MARC2UTF); else if (i == 1) table_len = sizeof (UTF2MARC); tablename.Concat (".txt"); thistable = tables [i]; memset (thistable, 0, table_len); /* find default dir -- debugging char *cwd; cwd = getcwd( NULL, 0 ); */ if ((FH = fopen (tablename, "r")) == NULL) { return E_FILENOTOPEN; } else { kk = 0; // loop to load a single table while (!feof (FH)) { fgets (t_line, sizeof (t_line), FH); if (!feof(FH)) { t_string = t_line; tlinearray = t_string.Parse (",\r\n"); if (tlinearray.GetCount () < 4) return E_CONVERSION; strcpy ((thistable + kk)->marc, tlinearray [0].GetText ()); strcpy ((thistable + kk)->utf8, tlinearray [1].GetText ()); if (tlinearray[2].GetCharacter(0) == '0') strcpy ((thistable + kk)->combining, "0"); else strcpy ((thistable + kk)->combining, "1"); strcpy ((thistable + kk)->charset, tlinearray [3].GetText ()); kk++; } } } fclose (FH); } //051231 LOAD DECOMPOSITION TABLE tablename = "DECOMP.TXT"; table_len = sizeof (DECOMP); memset (DECOMP, 0, table_len); if ((FH = fopen (tablename, "r")) == NULL) { return E_FILENOTOPEN; } else { kk = 0; while (!feof (FH)) { fgets (t_line, sizeof (t_line), FH); if (!feof(FH)) { t_string = t_line; tlinearray = t_string.Parse (",\r\n"); if (tlinearray.GetCount () < 2) return E_CONVERSION; strcpy ((DECOMP + kk)->utf8, tlinearray [0].GetText ()); strcpy ((DECOMP + kk)->decomp, tlinearray [1].GetText ()); kk++; } } } fclose (FH); return Result; }