Updating the changelog in the VERSION file, and version_sync.
[shapes.git] / source / texlabelmanager.h
blob531c00862e8d5e274b6e785ddbc266ef89540f79
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008 Henrik Tidefelt
19 #pragma once
21 #include "SimplePDF_decls.h"
22 #include "Shapes_Lang_decls.h"
23 #include "Shapes_Kernel_decls.h"
25 #include "shapestypes.h"
27 #include <set>
28 #include <string>
29 #include <map>
30 #include <iostream>
31 #include <sstream>
33 namespace Shapes
35 namespace Kernel
38 class TeXLabelManager
40 public:
41 class RequestLocation
43 public:
44 bool literal_;
45 Ast::SourceLocation loc_;
46 RequestLocation( bool literal, const Ast::SourceLocation & loc )
47 : literal_( literal ), loc_( loc )
48 { }
50 private:
51 std::set< std::string > allRequests;
52 std::map< std::string, RequestLocation > currentRequests;
54 public:
55 typedef std::map< std::string, RefCountPtr< const Lang::XObject > > MapType;
56 private:
57 MapType availableLabels;
58 bool anyLabelMiss;
59 int loadCount;
61 std::string inDir_; /* Absolute path. Change to this directory before running pdfLaTeX! */
62 std::string tmpDir_; /* Absolute path. Specify this as -output-directory when running pdfLaTeX! */
63 std::string texJobName_; /* This is the jobname without the directory part. */
65 int jobNumber;
66 std::string stringWithJobNumber( const std::string & str, bool withDirectory = true ) const;
68 std::string documentclass;
69 std::list< std::string > documentoptions;
70 bool lmodernT1;
71 bool utf8;
72 std::ostringstream preamble;
73 std::ostringstream documentTop;
75 bool setupFinalized;
76 std::string setupCode;
77 std::string setupCodeHash;
79 public:
80 TeXLabelManager( );
81 ~TeXLabelManager( );
83 void setup( const std::string & inDir, const std::string & tmpDir, const std::string & texJobName );
85 void announce( const std::string & str, const Ast::SourceLocation & loc );
86 RefCountPtr< const Lang::Value > request( const std::string & str, const Ast::SourceLocation & loc, Kernel::PassedDyn dyn );
88 void iterativeStartup( RefCountPtr< std::istream > labelsFile );
89 void iterativeFinish( const std::string & labelDBFilename );
91 void setDocumentClass( const Ast::SourceLocation & loc, const char * str );
92 void addDocumentOption( const Ast::SourceLocation & loc, const char * str );
93 void setlmodernT1( const Ast::SourceLocation & loc, bool val );
94 void setutf8( const Ast::SourceLocation & loc, bool val );
95 void addPreambleLine( const Ast::SourceLocation & loc, const char * line );
96 void addDocumentTopLine( const Ast::SourceLocation & loc, const char * line );
98 private:
99 void assertNotSetupFinalized( const Ast::SourceLocation & loc ) const;
100 void processRequests( );
101 void loadLabels( RefCountPtr< std::istream > labelsFile );
102 static std::string safeSourceHash( const std::string & str );
103 void compileSetupCode( );
104 static bool isAllBlank( const char * str );
105 void assertBalanced( const std::string & str, const RequestLocation & loc ) const;
106 void parseTeXErrors( std::istream & interaction );