#include <iostream>
#include <fstream>
#include <set>
#include <string>
#include <time.h>
#include <cstdlib>
#include <errno.h>
#include "doc_lang.hh"
#include "doc_notice.hh"
#include "doc_autodoc.hh"
#include "doc_metadatas.hh"
#include "lateq.hh"
#include "enrobage.hh"
#include "compatibility.hh"
Go to the source code of this file.
Functions | |
static void | importDocStrings (const string &filename) |
Feed the content of doc texts maps from a file. | |
static void | getKey (string &s, string &key, size_t &pt1) |
static void | getText (string &s, size_t &pt1, string &text) |
static void | storePair (const string &key, const string &text) |
static void | printStringMapContent (map< string, string > &m, const string &name) |
Simple trace function. | |
static istream * | openArchFile (const string &filename) |
Open architecture file. | |
static void | getCurrentDir () |
Get current directory and store it in gCurrentDir. | |
static int | cholddir () |
Switch back to the previously stored current directory. | |
void | loadTranslationFile (const string &lang) |
Variables | |
map< string, string > | gDocNoticeStringMap |
set< string > | gDocNoticeKeySet |
map< string, string > | gDocAutodocStringMap |
set< string > | gDocAutodocKeySet |
map< string, string > | gDocMathStringMap |
set< string > | gDocMathKeySet |
map< string, string > | gDocMetadatasStringMap |
set< string > | gDocMetadatasKeySet |
static const string | gDocTextsDefaultFile = "mathdoctexts-default.txt" |
static string | gCurrentDir |
Room to save current directory name. |
static int cholddir | ( | ) | [static] |
Switch back to the previously stored current directory.
Definition at line 242 of file doc_lang.cpp.
References gCurrentDir.
Referenced by openArchFile().
00243 { 00244 if (chdir(gCurrentDir.c_str()) == 0) { 00245 return 0; 00246 } else { 00247 perror("cholddir"); 00248 exit(errno); 00249 } 00250 }
static void getCurrentDir | ( | ) | [static] |
Get current directory and store it in gCurrentDir.
Definition at line 256 of file doc_lang.cpp.
References FAUST_PATH_MAX, and gCurrentDir.
Referenced by openArchFile().
00257 { 00258 char buffer[FAUST_PATH_MAX]; 00259 gCurrentDir = getcwd (buffer, FAUST_PATH_MAX); 00260 }
static void getKey | ( | string & | s, | |
string & | key, | |||
size_t & | pt1 | |||
) | [static] |
Definition at line 145 of file doc_lang.cpp.
Referenced by importDocStrings().
00146 { 00147 /* Initialisation. */ 00148 key = ""; 00149 string separators = " \t"; 00150 size_t pk1 = 1; 00151 size_t pk2 = s.find_first_of(separators); 00152 00153 /* Immediate '\n' after keyword case. */ 00154 if (pk2==string::npos) pk2 = s.size(); 00155 00156 /* Capture and check the keyword. */ 00157 key = s.substr(pk1, pk2-1); 00158 00159 /* Prepare text capture. */ 00160 pt1 = s.find_first_of("\"", pk2); 00161 }
static void getText | ( | string & | s, | |
size_t & | pt1, | |||
string & | text | |||
) | [static] |
Definition at line 164 of file doc_lang.cpp.
Referenced by importDocStrings().
00165 { 00166 /* Capture the text on the current line. */ 00167 size_t pt2; 00168 pt2 = s.find_last_not_of("\""); 00169 if (pt2!=string::npos) { 00170 if (text.size() > 0) text += "\n"; // Handle line breaks. 00171 text += s.substr(pt1+1, pt2-pt1); 00172 } 00173 }
static void importDocStrings | ( | const string & | filename | ) | [static] |
Feed the content of doc texts maps from a file.
This mecchanism allows to load different files for translation.
"mathdoctexts" files must have been formatted as follows :
Definition at line 113 of file doc_lang.cpp.
References gDocAutodocStringMap, gDocMathStringMap, gDocMetadatasStringMap, gDocNoticeStringMap, getKey(), getText(), openArchFile(), printStringMapContent(), and storePair().
Referenced by loadTranslationFile().
00114 { 00115 string s; 00116 string key, text; 00117 istream* file = openArchFile(filename); 00118 00119 while ( getline(*file, s) ) { 00120 size_t pt1; // Text pointer. 00121 00122 /* The first character determines whether will follow a key or a text. */ 00123 switch (s[0]) { 00124 case ':': 00125 text = ""; 00126 getKey(s, key, pt1); 00127 if (pt1==string::npos) continue; 00128 break; 00129 case '\"': 00130 pt1 = 0; 00131 break; 00132 default: 00133 continue; 00134 } 00135 getText(s, pt1, text); 00136 storePair(key, text); 00137 } 00138 printStringMapContent(gDocNoticeStringMap, "gDocNoticeStringMap"); 00139 printStringMapContent(gDocAutodocStringMap, "gDocAutodocStringMap"); 00140 printStringMapContent(gDocMathStringMap, "gDocMathStringMap"); 00141 printStringMapContent(gDocMetadatasStringMap, "gDocMetadatasStringMap"); 00142 }
void loadTranslationFile | ( | const string & | lang | ) |
First ensure that the default file is loaded a least.
Then try and load the target file.
Definition at line 76 of file doc_lang.cpp.
References gDocTextsDefaultFile, importDocStrings(), initDocAutodoc(), initDocMath(), initDocMetadatas(), and initDocNotice().
Referenced by printDoc().
00077 { 00078 initDocMath(); 00079 initDocNotice(); 00080 initDocAutodoc(); 00081 initDocMetadatas(); 00082 00084 importDocStrings(gDocTextsDefaultFile); 00085 00087 if ( ! lang.empty() ) { 00088 importDocStrings( "mathdoctexts-" + lang + ".txt" ); 00089 } 00090 }
static istream * openArchFile | ( | const string & | filename | ) | [static] |
Open architecture file.
Definition at line 224 of file doc_lang.cpp.
References cholddir(), getCurrentDir(), and open_arch_stream().
Referenced by importDocStrings().
00225 { 00226 istream* file; 00227 getCurrentDir(); // Save the current directory. 00228 if ( (file = open_arch_stream(filename.c_str())) ) { 00229 //cerr << "Documentator : openArchFile : Opening '" << filename << "'" << endl; 00230 } else { 00231 cerr << "ERROR : can't open architecture file " << filename << endl; 00232 exit(1); 00233 } 00234 cholddir(); // Return to current directory. 00235 return file; 00236 }
static void printStringMapContent | ( | map< string, string > & | map, | |
const string & | name | |||
) | [static] |
Simple trace function.
Definition at line 204 of file doc_lang.cpp.
Referenced by importDocStrings().
00204 { 00205 bool trace = false; 00206 if(trace) { 00207 cout << name << ".size() = " << m.size() << endl; 00208 map<string,string>::iterator it; 00209 int i = 1; 00210 for(it = m.begin(); it!=m.end(); ++it) 00211 cout << i++ << ".\t" << name << "[" << it->first << "] \t= '" << it->second << "'" << endl; 00212 } 00213 }
static void storePair | ( | const string & | key, | |
const string & | text | |||
) | [static] |
Definition at line 176 of file doc_lang.cpp.
References gDocAutodocKeySet, gDocAutodocStringMap, gDocMathKeySet, gDocMathStringMap, gDocMetadatasKeySet, gDocMetadatasStringMap, gDocNoticeKeySet, and gDocNoticeStringMap.
Referenced by importDocStrings().
00177 { 00178 /* Store the current pair. */ 00179 if(!key.empty() && !text.empty()) { 00180 00181 if (gDocNoticeKeySet.find(key) != gDocNoticeKeySet.end()) { 00182 gDocNoticeStringMap[key] = text; 00183 } 00184 else if (gDocAutodocKeySet.find(key) != gDocAutodocKeySet.end()) { 00185 gDocAutodocStringMap[key] = text; 00186 } 00187 else if (gDocMathKeySet.find(key) != gDocMathKeySet.end()) { 00188 gDocMathStringMap[key] = text; 00189 } 00190 else if (gDocMetadatasKeySet.find(key) != gDocMetadatasKeySet.end()) { 00191 gDocMetadatasStringMap[key] = text; 00192 } 00193 else { 00194 cerr << "Documentator : importDocStings : " << "warning : unknown key \"" << key << "\"" << endl; 00195 } 00196 //cerr << "gDocNoticeStringMap[\"" << key << "\"] = \"" << gDocNoticeStringMap[key] << "\"" << endl; 00197 } 00198 }
string gCurrentDir [static] |
Room to save current directory name.
Definition at line 66 of file doc_lang.cpp.
Referenced by cholddir(), and getCurrentDir().
set<string> gDocAutodocKeySet |
Definition at line 41 of file doc_autodoc.cpp.
Referenced by initDocAutodocKeySet(), and storePair().
map<string, string> gDocAutodocStringMap |
Definition at line 40 of file doc_autodoc.cpp.
set<string> gDocMathKeySet |
Definition at line 52 of file lateq.cpp.
Referenced by initDocMathKeySet(), and storePair().
map<string, string> gDocMathStringMap |
set<string> gDocMetadatasKeySet |
Definition at line 36 of file doc_metadatas.cpp.
Referenced by initDocMetadatasKeySet(), and storePair().
map<string, string> gDocMetadatasStringMap |
Definition at line 35 of file doc_metadatas.cpp.
set<string> gDocNoticeKeySet |
Definition at line 39 of file doc_notice.cpp.
Referenced by initDocNoticeFlagMap(), initDocNoticeKeySet(), and storePair().
map<string, string> gDocNoticeStringMap |
Definition at line 38 of file doc_notice.cpp.
Referenced by importDocStrings(), printDocNotice(), and storePair().
const string gDocTextsDefaultFile = "mathdoctexts-default.txt" [static] |
Definition at line 53 of file doc_lang.cpp.
Referenced by loadTranslationFile().