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

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

{
    if (chdir(gCurrentDir.c_str()) == 0) {
        return 0;
    } else {
        perror("cholddir");
        exit(errno);
    }
}

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

{
    char    buffer[FAUST_PATH_MAX];
    gCurrentDir = getcwd (buffer, 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().

{
    /* Initialisation. */
    key = "";
    string separators = " \t";
    size_t pk1 = 1;
    size_t pk2 = s.find_first_of(separators);
    
    /* Immediate '\n' after keyword case. */
    if (pk2==string::npos) pk2 = s.size();
    
    /* Capture and check the keyword. */
    key = s.substr(pk1, pk2-1);
    
    /* Prepare text capture. */
    pt1 = s.find_first_of("\"", pk2);
}

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

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

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

{   
    string s;
    string key, text;
    istream* file = openArchFile(filename);
    
    while ( getline(*file, s) ) {
        size_t pt1; // Text pointer.
        
        /* The first character determines whether will follow a key or a text. */
        switch (s[0]) {
            case ':':
                text = "";
                getKey(s, key, pt1);
                if (pt1==string::npos) continue;
                break;
            case '\"':
                pt1 = 0;
                break;
            default:
                continue;
        }
        getText(s, pt1, text);
        storePair(key, text);
    }
    printStringMapContent(gDocNoticeStringMap, "gDocNoticeStringMap");
    printStringMapContent(gDocAutodocStringMap, "gDocAutodocStringMap");
    printStringMapContent(gDocMathStringMap, "gDocMathStringMap");
    printStringMapContent(gDocMetadatasStringMap, "gDocMetadatasStringMap");
}

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

{
    initDocMath();
    initDocNotice();
    initDocAutodoc();
    initDocMetadatas();
    
    importDocStrings(gDocTextsDefaultFile);
    
    if ( ! lang.empty() ) {
        importDocStrings( "mathdoctexts-" + lang + ".txt" );
    }
}

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

{
    istream* file;
    getCurrentDir();    // Save the current directory.
    if ( (file = open_arch_stream(filename.c_str())) ) {
        //cerr << "Documentator : openArchFile : Opening '" << filename << "'" << endl;
    } else {
        cerr << "ERROR : can't open architecture file " << filename << endl;
        exit(1);
    }
    cholddir();         // Return to current directory.
    return file;
}

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

                                                                             {
    bool trace = false;
    if(trace) {
        cout << name << ".size() = " << m.size() << endl;
        map<string,string>::iterator it;
        int i = 1;
        for(it = m.begin(); it!=m.end(); ++it)
            cout << i++ << ".\t" << name << "[" << it->first << "] \t= '" << it->second << "'" << endl;
    }
}

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

{
    /* Store the current pair. */
    if(!key.empty() && !text.empty()) {
        
        if (gDocNoticeKeySet.find(key) != gDocNoticeKeySet.end()) {
            gDocNoticeStringMap[key] = text;
        } 
        else if (gDocAutodocKeySet.find(key) != gDocAutodocKeySet.end()) {
            gDocAutodocStringMap[key] = text;
        }
        else if (gDocMathKeySet.find(key) != gDocMathKeySet.end()) {
            gDocMathStringMap[key] = text;
        }
        else if (gDocMetadatasKeySet.find(key) != gDocMetadatasKeySet.end()) {
            gDocMetadatasStringMap[key] = text;
        }
        else {
            cerr << "Documentator : importDocStings : " << "warning : unknown key \"" << key << "\"" << endl;
        }
        //cerr << "gDocNoticeStringMap[\"" << key << "\"] = \"" << gDocNoticeStringMap[key] << "\"" << endl;
    }
}

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.

set<string> gDocMathKeySet

Definition at line 52 of file lateq.cpp.

Referenced by initDocMathKeySet(), and storePair().

map<string, string> gDocMathStringMap

Definition at line 51 of file lateq.cpp.

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