FAUST compiler  0.9.9.6b8
Functions | Variables
doc_lang.cpp File Reference
#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"
Include dependency graph for doc_lang.cpp:

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. More...
 
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. More...
 
static istream * openArchFile (const string &filename)
 Open architecture file. More...
 
static void getCurrentDir ()
 Get current directory and store it in gCurrentDir. More...
 
static int cholddir ()
 Switch back to the previously stored current directory. More...
 
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. More...
 

Function Documentation

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 drawSchema(), openArchFile(), and printDoc().

243 {
244  if (chdir(gCurrentDir.c_str()) == 0) {
245  return 0;
246  } else {
247  perror("cholddir");
248  exit(errno);
249  }
250 }
static string gCurrentDir
Room to save current directory name.
Definition: doc_lang.cpp:66

Here is the caller graph for this function:

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().

257 {
258  char buffer[FAUST_PATH_MAX];
259  gCurrentDir = getcwd (buffer, FAUST_PATH_MAX);
260 }
static string gCurrentDir
Room to save current directory name.
Definition: doc_lang.cpp:66
#define FAUST_PATH_MAX

Here is the caller graph for this function:

static void getKey ( string &  s,
string &  key,
size_t &  pt1 
)
static

Definition at line 145 of file doc_lang.cpp.

Referenced by importDocStrings().

146 {
147  /* Initialisation. */
148  key = "";
149  string separators = " \t";
150  size_t pk1 = 1;
151  size_t pk2 = s.find_first_of(separators);
152 
153  /* Immediate '\n' after keyword case. */
154  if (pk2==string::npos) pk2 = s.size();
155 
156  /* Capture and check the keyword. */
157  key = s.substr(pk1, pk2-1);
158 
159  /* Prepare text capture. */
160  pt1 = s.find_first_of("\"", pk2);
161 }

Here is the caller graph for this function:

static void getText ( string &  s,
size_t &  pt1,
string &  text 
)
static

Definition at line 164 of file doc_lang.cpp.

Referenced by importDocStrings().

165 {
166  /* Capture the text on the current line. */
167  size_t pt2;
168  pt2 = s.find_last_not_of("\"");
169  if (pt2!=string::npos) {
170  if (text.size() > 0) text += "\n"; // Handle line breaks.
171  text += s.substr(pt1+1, pt2-pt1);
172  }
173 }

Here is the caller graph for this function:

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 :

  • a line beginning by ':' immediately declares a keyword,
  • a line beginning by '"' contains text until the last '"',
  • text can directly follow a keyword, if separated by one or many separator characters (space or tab).
  • a direct line break between two double quoted strings will insert a '
    ' line break in the resulting notice string.

Definition at line 113 of file doc_lang.cpp.

References gDocAutodocStringMap, gDocMathStringMap, gDocMetadatasStringMap, gDocNoticeStringMap, getKey(), getText(), openArchFile(), printStringMapContent(), and storePair().

Referenced by loadTranslationFile().

114 {
115  string s;
116  string key, text;
117  istream* file = openArchFile(filename);
118 
119  while ( getline(*file, s) ) {
120  size_t pt1; // Text pointer.
121 
122  /* The first character determines whether will follow a key or a text. */
123  switch (s[0]) {
124  case ':':
125  text = "";
126  getKey(s, key, pt1);
127  if (pt1==string::npos) continue;
128  break;
129  case '\"':
130  pt1 = 0;
131  break;
132  default:
133  continue;
134  }
135  getText(s, pt1, text);
136  storePair(key, text);
137  }
138  printStringMapContent(gDocNoticeStringMap, "gDocNoticeStringMap");
139  printStringMapContent(gDocAutodocStringMap, "gDocAutodocStringMap");
140  printStringMapContent(gDocMathStringMap, "gDocMathStringMap");
141  printStringMapContent(gDocMetadatasStringMap, "gDocMetadatasStringMap");
142 }
map< string, string > gDocMetadatasStringMap
static void storePair(const string &key, const string &text)
Definition: doc_lang.cpp:176
static void getText(string &s, size_t &pt1, string &text)
Definition: doc_lang.cpp:164
map< string, string > gDocNoticeStringMap
Definition: doc_notice.cpp:38
static istream * openArchFile(const string &filename)
Open architecture file.
Definition: doc_lang.cpp:224
map< string, string > gDocMathStringMap
Definition: lateq.cpp:51
map< string, string > gDocAutodocStringMap
Definition: doc_autodoc.cpp:40
static void printStringMapContent(map< string, string > &map, const string &name)
Simple trace function.
Definition: doc_lang.cpp:204
static void getKey(string &s, string &key, size_t &pt1)
Definition: doc_lang.cpp:145

Here is the call graph for this function:

Here is the caller graph for this function:

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().

77 {
78  initDocMath();
79  initDocNotice();
82 
85 
87  if ( ! lang.empty() ) {
88  importDocStrings( "mathdoctexts-" + lang + ".txt" );
89  }
90 }
static const string gDocTextsDefaultFile
Definition: doc_lang.cpp:53
static void importDocStrings(const string &filename)
Feed the content of doc texts maps from a file.
Definition: doc_lang.cpp:113
void initDocMetadatas()
Dispatch initialization of metadatas container.
void initDocNotice()
Dispatch initialization of notice containers, after default notice file loading.
Definition: doc_notice.cpp:134
void initDocMath()
Dispatch initialization of autodoc container.
Definition: lateq.cpp:468
void initDocAutodoc()
Dispatch initialization of autodoc container.

Here is the call graph for this function:

Here is the caller graph for this function:

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().

225 {
226  istream* file;
227  getCurrentDir(); // Save the current directory.
228  if ( (file = open_arch_stream(filename.c_str())) ) {
229  //cerr << "Documentator : openArchFile : Opening '" << filename << "'" << endl;
230  } else {
231  cerr << "ERROR : can't open architecture file " << filename << endl;
232  exit(1);
233  }
234  cholddir(); // Return to current directory.
235  return file;
236 }
static int cholddir()
Switch back to the previously stored current directory.
Definition: doc_lang.cpp:242
ifstream * open_arch_stream(const char *filename)
Try to open an architecture file searching in various directories.
Definition: enrobage.cpp:220
static void getCurrentDir()
Get current directory and store it in gCurrentDir.
Definition: doc_lang.cpp:256

Here is the call graph for this function:

Here is the caller graph for this function:

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().

204  {
205  bool trace = false;
206  if(trace) {
207  cout << name << ".size() = " << m.size() << endl;
208  map<string,string>::iterator it;
209  int i = 1;
210  for(it = m.begin(); it!=m.end(); ++it)
211  cout << i++ << ".\t" << name << "[" << it->first << "] \t= '" << it->second << "'" << endl;
212  }
213 }
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98

Here is the caller graph for this function:

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().

177 {
178  /* Store the current pair. */
179  if(!key.empty() && !text.empty()) {
180 
181  if (gDocNoticeKeySet.find(key) != gDocNoticeKeySet.end()) {
182  gDocNoticeStringMap[key] = text;
183  }
184  else if (gDocAutodocKeySet.find(key) != gDocAutodocKeySet.end()) {
185  gDocAutodocStringMap[key] = text;
186  }
187  else if (gDocMathKeySet.find(key) != gDocMathKeySet.end()) {
188  gDocMathStringMap[key] = text;
189  }
190  else if (gDocMetadatasKeySet.find(key) != gDocMetadatasKeySet.end()) {
191  gDocMetadatasStringMap[key] = text;
192  }
193  else {
194  cerr << "Documentator : importDocStings : " << "warning : unknown key \"" << key << "\"" << endl;
195  }
196  //cerr << "gDocNoticeStringMap[\"" << key << "\"] = \"" << gDocNoticeStringMap[key] << "\"" << endl;
197  }
198 }
set< string > gDocNoticeKeySet
Definition: doc_notice.cpp:39
map< string, string > gDocMetadatasStringMap
map< string, string > gDocNoticeStringMap
Definition: doc_notice.cpp:38
map< string, string > gDocMathStringMap
Definition: lateq.cpp:51
set< string > gDocMathKeySet
Definition: lateq.cpp:52
map< string, string > gDocAutodocStringMap
Definition: doc_autodoc.cpp:40
set< string > gDocMetadatasKeySet
set< string > gDocAutodocKeySet
Definition: doc_autodoc.cpp:41

Here is the caller graph for this function:

Variable Documentation

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.

Referenced by importDocStrings(), and storePair().

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.

Referenced by importDocStrings(), and storePair().

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().