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
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
21 #include "Shapes_Kernel_decls.h"
23 #include "simplepdfi.h"
24 #include "simplepdfo.h"
27 #include "shapesexceptions.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"
50 #ifdef HAVE_FONTCONFIG
51 #include <fontconfig/fontconfig.h>
55 extern int shapesdebug
;
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
);
79 enum XpdfAction
{ XPDF_DEFAULT
, XPDF_RAISE
, XPDF_RELOAD
, XPDF_QUIT
, XPDF_NOSERVER
};
82 XpdfAction xpdfAction
;
83 std::string xpdfServer
;
85 const char * do_open_application
;
88 void preview( const std::string
& filename
, bool splitNoLaunch
= false ) const;
90 void xpdfHelper( const std::string
& filename
) const;
91 void openHelper( const std::string
& filename
) const;
94 class InteractionFormats
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;
113 void writePrompt( std::ostream
& os
, const char * format
, size_t inputNo
) const;
114 void writeEscape( std::ostream
& os
, char c
) const;
121 class InteractionContinuation
;
123 class WarmDebugger
: public Kernel::State
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
);
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
);