Changeset 27592

Show
Ignore:
Timestamp:
11/16/08 22:51:18 (2 months ago)
Author:
lasgouttes
Message:

Now tex2lyx is able to set the encoding from what it reads in the preamble.

What works:
- parsing of inputenc should work
- \inputencoding is acted on in the preamble

What does not work:
- \inputencoding in the text
- all the corner cases I have not considered, and all buggy stuff in the

'what works' paragraph

- InsetLatexAccent? are still created, but I do not know when they got added
to the code.

The only notable trick in the code is that I had to disable buffering. Otherwise
the whole text was read before I had a chance to change the encoding...

Finally I remove the artificial limitation that forbid

\usepackage[opt1,opt2]{package1,package2}

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lyx-devel/trunk/src/Encoding.cpp

    r27425 r27592  
    514514void Encodings::initUnicodeMath(Buffer const & buffer) 
    515515{ 
     516#ifdef TEX2LYX 
     517        // The code below is not needed in tex2lyx and requires additional stuff 
     518        (void)buffer; 
     519#else 
    516520        mathcmd.clear(); 
    517521        textcmd.clear(); 
     
    524528        for (; it != end; ++it) 
    525529                it->initUnicodeMath(); 
     530#endif 
    526531} 
    527532 
     
    529534void Encodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed) 
    530535{ 
     536#ifdef TEX2LYX 
     537        // The code below is not needed in tex2lyx and requires additional stuff 
     538        (void)c; 
     539        (void)features; 
     540        (void)for_mathed; 
     541#else 
    531542        CharInfoMap::const_iterator const it = unicodesymbols.find(c); 
    532543        if (it != unicodesymbols.end()) { 
     
    567578                features.require("lyxmathsym"); 
    568579        } 
     580#endif 
    569581} 
    570582 
  • lyx-devel/trunk/src/tex2lyx/Makefile.am

    r27573 r27592  
    4242        ../lengthcommon.cpp \ 
    4343        ../Color.cpp \ 
    44         ../Color.h 
     44        ../Color.h \ 
     45        ../Encoding.cpp 
    4546 
    4647BUILT_SOURCES = $(PCH_FILE) 
  • lyx-devel/trunk/src/tex2lyx/Parser.cpp

    r27563 r27592  
    1111#include <config.h> 
    1212 
     13#include "Encoding.h" 
    1314#include "Parser.h" 
    1415 
     
    147148{ 
    148149        delete iss_; 
     150} 
     151 
     152 
     153void Parser::setEncoding(std::string const & e) 
     154{ 
     155        Encoding const * enc = encodings.fromLaTeXName(e); 
     156        cerr << "setting encoding to " << enc->iconvName(); 
     157        is_ << lyx::setEncoding(enc->iconvName()); 
    149158} 
    150159 
  • lyx-devel/trunk/src/tex2lyx/Parser.h

    r27563 r27592  
    120120        ~Parser(); 
    121121 
     122        /// change the encoding of the input stream 
     123        void setEncoding(std::string const & encoding); 
     124 
    122125        /// 
    123126        int lineno() const { return lineno_; } 
  • lyx-devel/trunk/src/tex2lyx/preamble.cpp

    r27563 r27592  
    249249 
    250250 
    251 void handle_package(string const & name, string const & opts, 
     251void handle_package(Parser &p, string const & name, string const & opts, 
    252252                    bool in_lyx_preamble) 
    253253{ 
     
    327327 
    328328        else if (name == "inputenc") { 
    329                 // only set when there is not more than one inputenc option 
    330                 // therefore check for the "," character 
    331                 // also only set when there is not more then one babel language option 
     329                // only set when there is not more than one inputenc 
     330                // option therefore check for the "," character also 
     331                // only set when there is not more then one babel 
     332                // language option 
    332333                if (opts.find(",") == string::npos && one_language == true) { 
    333334                        if (opts == "ascii") 
     
    338339                                h_inputencoding = opts; 
    339340                } 
     341                if (!options.empty()) 
     342                        p.setEncoding(options.back()); 
    340343                options.clear(); 
    341344        } 
     
    664667                        string const options = p.getArg('[', ']'); 
    665668                        string const name = p.getArg('{', '}'); 
    666                         if (options.empty() && name.find(',')) { 
    667                                 vector<string> vecnames; 
    668                                 split(name, vecnames, ','); 
    669                                 vector<string>::const_iterator it  = vecnames.begin(); 
    670                                 vector<string>::const_iterator end = vecnames.end(); 
    671                                 for (; it != end; ++it) 
    672                                         handle_package(trim(*it), string(),  
    673                                                        in_lyx_preamble); 
    674                         } else { 
    675                                 handle_package(name, options, in_lyx_preamble); 
    676                         } 
     669                        vector<string> vecnames; 
     670                        split(name, vecnames, ','); 
     671                        vector<string>::const_iterator it  = vecnames.begin(); 
     672                        vector<string>::const_iterator end = vecnames.end(); 
     673                        for (; it != end; ++it) 
     674                                handle_package(p, trim(*it), options,  
     675                                               in_lyx_preamble); 
    677676                } 
    678677 
    679678                else if (t.cs() == "inputencoding") { 
    680                         h_inputencoding = p.getArg('{','}'); 
     679                        string const encoding = p.getArg('{','}'); 
     680                        h_inputencoding = encoding; 
     681                        p.setEncoding(encoding); 
    681682                } 
    682683 
  • lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp

    r27563 r27592  
    1616 
    1717#include "Context.h" 
     18#include "Encoding.h" 
     19#include "Layout.h" 
    1820#include "TextClass.h" 
    19 #include "Layout.h" 
    2021 
    2122#include "support/convert.h" 
     
    422423bool tex2lyx(FileName const & infilename, ostream & os) 
    423424{ 
    424         ifdocstream is(infilename.toFilesystemEncoding().c_str()); 
     425        ifdocstream is; 
     426        // forbid buffering on this stream 
     427        is.rdbuf()->pubsetbuf(0,0); 
     428        is.open(infilename.toFilesystemEncoding().c_str()); 
    425429        if (!is.good()) { 
    426430                cerr << "Could not open input file \"" << infilename 
     
    488492        try { 
    489493                init_package(internal_path(to_utf8(from_local8bit(argv[0]))), 
    490                 cl_system_support, cl_user_support, 
    491                 top_build_dir_is_two_levels_up); 
     494                            cl_system_support, cl_user_support, 
     495                            top_build_dir_is_two_levels_up); 
    492496        } catch (ExceptionMessage const & message) { 
    493497                cerr << to_utf8(message.title_) << ":\n" 
    494                        << to_utf8(message.details_) << endl; 
     498                     << to_utf8(message.details_) << endl; 
    495499                if (message.type_ == ErrorException) 
    496500                        exit(1); 
     
    510514                outfilename = changeExtension(infilename, ".lyx"); 
    511515 
     516        // Read the syntax tables 
    512517        FileName const system_syntaxfile = libFileSearch("", "syntax.default"); 
    513518        if (system_syntaxfile.empty()) { 
     
    519524                read_syntaxfile(makeAbsPath(syntaxfile)); 
    520525 
     526        // Read the encodings table. 
     527        FileName const symbols_path = libFileSearch(string(), "unicodesymbols"); 
     528        if (symbols_path.empty()) { 
     529                cerr << "Error: Could not find file \"unicodesymbols\"."  
     530                     << endl; 
     531                exit(1); 
     532        } 
     533        FileName const enc_path = libFileSearch(string(), "encodings"); 
     534        if (enc_path.empty()) { 
     535                cerr << "Error: Could not find file \"encodings\"."  
     536                     << endl; 
     537                exit(1); 
     538        } 
     539        encodings.read(enc_path, symbols_path); 
     540 
     541        // The real work now. 
    521542        masterFilePath = onlyPath(infilename); 
    522543        parentFilePath = masterFilePath; 
    523  
    524544        if (outfilename == "-") { 
    525545                if (tex2lyx(FileName(infilename), cout)) 
  • lyx-devel/trunk/src/tex2lyx/text.cpp

    r27563 r27592  
    17641764                        context.check_layout(os); 
    17651765                        string const s = p.verbatim_item(); 
     1766                        //FIXME: this never triggers in UTF8 
    17661767                        if (s == "\xb1" || s == "\xb3" || s == "\xb2" || s == "\xb5") 
    17671768                                os << s; 
     
    22392240                } 
    22402241 
     2242#if 0 
     2243//FIXME: rewrite this 
    22412244                else if (t.cs() == "\"") { 
    22422245                        context.check_layout(os); 
     
    22502253                        else handle_ert(os, "\"{" + name + "}", context); 
    22512254                } 
     2255#endif 
    22522256 
    22532257                // Problem: \= creates a tabstop inside the tabbing environment 
     
    22742278                } 
    22752279 
     2280#if 0 
     2281//FIXME: rewrite this 
    22762282                else if (t.cs() == "ss") { 
    22772283                        context.check_layout(os); 
     
    22792285                        skip_braces(p); // eat {} 
    22802286                } 
     2287#endif 
    22812288 
    22822289                else if (t.cs() == "i" || t.cs() == "j" || t.cs() == "l" ||