Update procedures
[shapes.git] / source / main.h
blobbaa1a4685fc8551fe8594da21b680d40ac929366
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, 2009 Henrik Tidefelt
19 #pragma once
21 #include "Shapes_Kernel_decls.h"
23 #include "simplepdfi.h"
24 #include "simplepdfo.h"
25 #include "globals.h"
26 #include "consts.h"
27 #include "shapesexceptions.h"
28 #include "hottypes.h"
29 #include "multipage.h"
30 #include "continuations.h"
31 #include "charconverters.h"
32 #include "pagecontentstates.h"
33 #include "autoonoff.h"
34 #include "shapesscanner.h"
35 #include "texlabelmanager.h"
36 #include "debuglog.h"
37 #include "config.h"
39 #include <iostream>
40 #include <iomanip>
41 #include <fstream>
42 #include <string>
43 #include <unistd.h>
44 #include <stdlib.h>
45 #include <list>
46 #include <time.h>
47 #include <errno.h>
48 #include <limits>
49 #include <iconv.h>
50 #ifdef HAVE_FONTCONFIG
51 #include <fontconfig/fontconfig.h>
52 #endif
54 int shapesparse( );
55 extern int shapesdebug;
56 void printHelp( );
57 void printVersion( );
59 enum SplitMode{ SPLIT_NO, SPLIT_FLAT, SPLIT_DIR };
61 void argcAssertion( const char * optionSpecifier, int argc, int argcMin );
62 bool strprefixcmp( char * str, const char * prefix, const char ** prefixDst, char ** endp );
63 bool strtobool( const char * str, const char * containingString, const char * trueLabel = 0, const char * falseLabel = 0 );
64 std::string absoluteFilename( const char * filename );
65 std::string absoluteDirectory( const char * filename );
66 void ensureTmpDirectoryExists( const std::string & dirname, bool allowCreate );
67 RefCountPtr< std::ifstream > performIterativeStartup( const std::string & texJobName );
68 void abortProcedure( int exitCode );
69 void shipout( Shapes::Kernel::ValueRef resultUntyped, Shapes::Kernel::PassedDyn baseDyn, Shapes::Kernel::WarmCatalog::ShipoutList * documents, SplitMode splitMode );
70 void writeOutput( std::string & outputName, const Shapes::Kernel::WarmCatalog::ShipoutList & documents, SplitMode splitMode );
71 void setupGlobals( );
72 namespace Shapes
74 namespace Interaction
76 class PreviewOptions
78 public:
79 enum XpdfAction{ XPDF_DEFAULT, XPDF_RAISE, XPDF_RELOAD, XPDF_QUIT, XPDF_NOSERVER };
80 public:
81 bool launch_xpdf;
82 XpdfAction xpdfAction;
83 std::string xpdfServer;
84 bool do_open;
85 const char * do_open_application;
86 public:
87 PreviewOptions( );
88 void preview( const std::string & filename, bool splitNoLaunch = false ) const;
89 protected:
90 void xpdfHelper( const std::string & filename ) const;
91 void openHelper( const std::string & filename ) const;
94 class InteractionFormats
96 const char * prompt_;
97 const char * show_;
98 const char * file_;
99 const char * bye_;
100 public:
101 InteractionFormats( );
102 void setPrompt( const char * format );
103 void setShow( const char * format );
104 void setFile( const char * format );
105 void setBye( const char * format );
107 void formatPrompt( std::ostream & os, size_t inputNo ) const;
108 void formatShow( std::ostream & os, size_t inputNo ) const;
109 void formatFile( std::ostream & os, size_t inputNo ) const;
110 void formatBye( std::ostream & os, size_t inputNo ) const;
112 private:
113 void writePrompt( std::ostream & os, const char * format, size_t inputNo ) const;
114 void writeEscape( std::ostream & os, char c ) const;
119 namespace Kernel
121 class InteractionContinuation;
123 class WarmDebugger : public Kernel::State
125 public:
126 Kernel::Environment * env_;
127 Kernel::PassedDyn dyn_;
128 Kernel::ContRef resume_;
129 Ast::Expression * breakExpr_;
130 WarmDebugger( Kernel::Environment * env, Kernel::PassedDyn dyn, Kernel::ContRef resume, Ast::Expression * breakExpr );
131 virtual ~WarmDebugger( );
132 virtual void tackOnImpl( Kernel::EvalState * evalState, const RefCountPtr< const Lang::Value > & piece, const Ast::SourceLocation & callLoc );
133 virtual void peekImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
134 virtual void freezeImpl( Kernel::EvalState * evalState, const Ast::SourceLocation & callLoc );
135 virtual void gcMark( Kernel::GCMarkedSet & marked );
136 TYPEINFODECL;
142 extern Shapes::Interaction::PreviewOptions previewOptions;
143 extern Shapes::Interaction::InteractionFormats interactionFormats;
145 void addDefaultNeedPath( );
146 void addDefaultFontMetricsPath( );
147 void destroyGlobals( );
148 void escapeExtGlobChars( const std::string & str, std::ostream & dst );
150 void rmSplitFiles( const std::string & outputName, const char * sep );
151 void mkSplitDir( const std::string & outputName );
152 void noSplitOpen( std::ofstream * oFile, const std::string & outputName );
153 std::string splitOpen( std::ofstream * oFile, const std::string outputName, const char * sep, size_t physicalPageNo );
154 void interactiveEvaluation( std::istream & in, std::ostream & out, const std::string & outputName, SplitMode splitMode,
155 bool evalTrace, bool evalBackTrace, bool cleanupMemory,
156 RefCountPtr< std::ifstream > & labelDBFile, const std::string & labelDBName );
157 void nonInteractiveEvaluation( Shapes::Kernel::WarmCatalog::ShipoutList & documents, SplitMode splitMode,
158 bool evalTrace, bool evalBackTrace, bool cleanupMemory,
159 RefCountPtr< std::ifstream > & labelDBFile, const std::string & labelDBName );
160 void initCore( RefCountPtr< std::ifstream > & labelDBFile, const std::string & labelDBName );