ReactOS 0.4.15-dev-5667-ged97270
ms2ps.cpp File Reference
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <deque>
#include <ctype.h>
Include dependency graph for ms2ps.cpp:

Go to the source code of this file.

Macros

#define MAYBE(x)
 

Typedefs

typedef std::list< std::string > sl_t
 
typedef sl_t::iterator sl_it
 

Enumerations

enum  fstate { EMPTY , INT , FRAC , EXP }
 

Functions

int isident (int c)
 
bool areinclass (string str, int(*isclass)(int))
 
bool areident (string s)
 
bool isop (string tok)
 
string generic_match (string tok, string la, bool(*mf)(string))
 
string match_operator (string tok, string la)
 
string match_ident (string tok, string la)
 
string match_quoted_const (string tok, string la, char q)
 
sl_t snarf_tokens (string line)
 
istreamgetline_no_comments (istream &is, string &line)
 
bool expand_input (sl_t &tok)
 
sl_it complete_block (sl_it i, sl_it end, string start_ch, string end_ch)
 
string makename (string intro)
 
void append_block (sl_t &t, sl_it b, sl_it e)
 
void error (sl_t &container, sl_it it, string l)
 
void handle_try (sl_t &container, sl_it try_kw, sl_it end)
 
void print_tokens (sl_it begin, sl_it end)
 
int main (int argc, char **argv)
 

Variables

string TRY_TOKEN = "__try"
 
string EXCEPT_TOKEN = "__except"
 
string FINALLY_TOKEN = "__finally"
 
charc_operators []
 

Macro Definition Documentation

◆ MAYBE

#define MAYBE (   x)

Definition at line 35 of file ms2ps.cpp.

Typedef Documentation

◆ sl_it

typedef sl_t::iterator sl_it

Definition at line 45 of file ms2ps.cpp.

◆ sl_t

typedef std::list<std::string> sl_t

Definition at line 44 of file ms2ps.cpp.

Enumeration Type Documentation

◆ fstate

Enumerator
EMPTY 
INT 
FRAC 
EXP 

Definition at line 80 of file ms2ps.cpp.

80{ EMPTY, INT, FRAC, EXP };
@ EXP
Definition: ms2ps.cpp:80
@ EMPTY
Definition: ms2ps.cpp:80
@ FRAC
Definition: ms2ps.cpp:80
@ INT
Definition: ms2ps.cpp:80

Function Documentation

◆ append_block()

void append_block ( sl_t t,
sl_it  b,
sl_it  e 
)

Definition at line 257 of file ms2ps.cpp.

257 {
258 while( b != e ) {
259 t.push_back( *b );
260 b++;
261 }
262}
GLdouble GLdouble t
Definition: gl.h:2047
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define e
Definition: ke_i.h:82

Referenced by handle_try().

◆ areident()

bool areident ( string  s)

Definition at line 72 of file ms2ps.cpp.

72{ return areinclass( s, isident ); }
GLdouble s
Definition: gl.h:2039
bool areinclass(string str, int(*isclass)(int))
Definition: ms2ps.cpp:63
int isident(int c)
Definition: ms2ps.cpp:58

Referenced by match_ident().

◆ areinclass()

bool areinclass ( string  str,
int(*)(int isclass 
)

Definition at line 63 of file ms2ps.cpp.

63 {
64 int i;
65
66 for( i = 0; i < (int)str.size(); i++ )
67 if( !isclass( str[i] ) ) return false;
68
69 return true;
70}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const WCHAR * str

Referenced by areident().

◆ complete_block()

sl_it complete_block ( sl_it  i,
sl_it  end,
string  start_ch,
string  end_ch 
)

Definition at line 234 of file ms2ps.cpp.

237 {
238 int bc = 1;
239
240 for( i++; i != end && bc; i++ ) {
241 if( *i == start_ch ) bc++;
242 if( *i == end_ch ) bc--;
243 }
244
245 return i;
246}
PBATCH_CONTEXT bc
Definition: batch.c:67
GLuint GLuint end
Definition: gl.h:1545

Referenced by handle_try().

◆ error()

void error ( sl_t container,
sl_it  it,
string  l 
)

Definition at line 264 of file ms2ps.cpp.

264 {
265 int line = 0;
266 for( sl_it i = container.begin(); i != it; i++ )
267 if( (*i)[0] == '#' ) {
268 sscanf( i->substr(1).c_str(), "%d", &line );
269 cerr << "*standard-input*:" << line << ": " << l;
270 }
271}
r l[0]
Definition: byte_order.h:167
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define cerr
Definition: iostream.cpp:39
sl_t::iterator sl_it
Definition: ms2ps.cpp:45
Definition: parser.c:49

◆ expand_input()

bool expand_input ( sl_t tok)

Definition at line 208 of file ms2ps.cpp.

208 {
209 string line;
210 sl_t new_tokens;
211 bool out = false;
212
214 while( line.size() && isspace( line[0] ) )
215 line = line.substr( 1 );
216 if( line[0] == '#' ) {
217 tok.push_back( line );
218 while( line[line.size()-1] == '\\' ) {
220 tok.push_back( line );
221 tok.push_back( "\n" );
222 }
223 tok.push_back( "\n" );
224 } else {
225 new_tokens = snarf_tokens( line );
226 tok.splice( tok.end(), new_tokens );
227 tok.push_back( "\n" );
228 }
229
230 return out;
231}
#define isspace(c)
Definition: acclib.h:69
#define cin
Definition: iostream.cpp:37
std::list< std::string > sl_t
Definition: ms2ps.cpp:44
istream & getline_no_comments(istream &is, string &line)
Definition: ms2ps.cpp:172
sl_t snarf_tokens(string line)
Definition: ms2ps.cpp:108
static FILE * out
Definition: regtests2xml.c:44

Referenced by main().

◆ generic_match()

string generic_match ( string  tok,
string  la,
bool(*)(string mf 
)

Definition at line 82 of file ms2ps.cpp.

83 {
84 if( tok.size() < 1 ) return "";
85 if( mf(tok) && !mf(la) ) return tok; else return "";
86}
size_type size() const
Definition: _string.h:400

Referenced by match_ident(), and match_operator().

◆ getline_no_comments()

istream & getline_no_comments ( istream is,
string line 
)

Definition at line 172 of file ms2ps.cpp.

172 {
173 string buf;
174 int ch;
175 int seen_slash = false;
176
177 while( (ch = is.get()) != -1 ) {
178 if( seen_slash ) {
179 if( ch == '/' ) {
180 do {
181 ch = is.get();
182 } while( ch != -1 && ch != '\n' && ch != '\r' );
183 break;
184 } else if( ch == '*' ) {
185 ch = is.get(); /* Skip one char */
186 do {
187 while( ch != '*' )
188 ch = is.get();
189 ch = is.get();
190 } while( ch != '/' );
191 buf += ' ';
192 } else {
193 buf += '/'; buf += (char)ch;
194 }
195 seen_slash = false;
196 } else {
197 if( ch == '/' ) seen_slash = true;
198 else if( ch == '\r' || ch == '\n' ) break;
199 else buf += (char)ch;
200 }
201 }
202
203 line = buf;
204
205 return is;
206}
int_type get()
Definition: _istream.c:339
unsigned char
Definition: typeof.h:29
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751

Referenced by expand_input().

◆ handle_try()

void handle_try ( sl_t container,
sl_it  try_kw,
sl_it  end 
)

Definition at line 287 of file ms2ps.cpp.

287 {
288 string temp;
289 sl_t pseh_clause, temp_tok;
290 string finally_name, filter_name;
291 sl_it try_block, try_block_end, except_kw, paren, end_paren,
292 except_block, except_block_end, todelete,
293 finally_kw, finally_block, finally_block_end, clause_end;
294
295 try_block = try_kw;
296 try_block++;
297 try_block_end = complete_block( try_block, end, "{", "}" );
298
299 if( try_block_end == end )
300 error( container, try_block, "unclosed try block");
301
302 except_kw = try_block_end;
303
304 if( *except_kw == FINALLY_TOKEN ) {
305 finally_kw = except_kw;
306 except_kw = end;
307 paren = end;
308 end_paren = end;
309 except_block = end;
310 except_block_end = end;
311 } else if( *except_kw == EXCEPT_TOKEN ) {
312 paren = except_kw;
313 paren++;
314 if( *paren == "(" ) {
315 end_paren = complete_block( paren, end, "(", ")" );
316 except_block = end_paren;
317 } else {
318 except_block = paren;
319 paren = end;
320 end_paren = end;
321 }
322 except_block_end = complete_block( except_block, end, "{", "}" );
323 finally_kw = except_block_end;
324 } else {
325 except_kw = paren = end_paren = except_block = except_block_end =
326 finally_kw = finally_block = finally_block_end = end;
327 }
328
329 if( finally_kw != end && *finally_kw != FINALLY_TOKEN ) {
330 finally_kw = end;
331 finally_block = end;
332 finally_block_end = end;
333 } else {
334 finally_block = finally_kw;
335 finally_block++;
336 finally_block_end = complete_block( finally_block, end, "{", "}" );
337 }
338
339 if( finally_block_end != end ) clause_end = finally_block_end;
340 else if( except_block_end != end ) clause_end = except_block_end;
341 else clause_end = try_block_end;
342
343 /* Skip one so that we can do != on clause_end */
344
345 /* Now for the output phase -- we've collected the whole seh clause
346 * and it lies between try_kw and clause_end */
347
348 finally_name = makename("_Finally");
349 filter_name = makename("_Filter");
350
351 pseh_clause.push_back( "_SEH_FINALLY" );
352 pseh_clause.push_back( "(" );
353 pseh_clause.push_back( finally_name );
354 pseh_clause.push_back( ")" );
355 if( finally_kw != end )
356 append_block( pseh_clause, finally_block, finally_block_end );
357 else {
358 pseh_clause.push_back( "{" );
359 pseh_clause.push_back( "}" );
360 }
361
362 pseh_clause.push_back( "_SEH_FILTER" );
363 pseh_clause.push_back( "(" );
364 pseh_clause.push_back( filter_name );
365 pseh_clause.push_back( ")" );
366 pseh_clause.push_back( "{" );
367 pseh_clause.push_back( "return" );
368 if( paren != end )
369 append_block( pseh_clause, paren, end_paren );
370 else
371 pseh_clause.push_back( "EXCEPTION_EXECUTE_HANDLER" );
372 pseh_clause.push_back( ";" );
373 pseh_clause.push_back( "}" );
374
375 pseh_clause.push_back( "_SEH_TRY_FILTER_FINALLY" );
376 pseh_clause.push_back( "(" );
377 pseh_clause.push_back( filter_name );
378 pseh_clause.push_back( "," );
379 pseh_clause.push_back( finally_name );
380 pseh_clause.push_back( ")" );
381 append_block( pseh_clause, try_block, try_block_end );
382 pseh_clause.push_back( "_SEH_HANDLE" );
383 pseh_clause.push_back( "{" );
384 if( except_block != end )
385 append_block( pseh_clause, except_block, except_block_end );
386 pseh_clause.push_back( "}" );
387 pseh_clause.push_back( "_SEH_END" );
388 pseh_clause.push_back( ";" );
389
390 container.splice( try_kw, pseh_clause );
391 while( try_kw != clause_end ) {
392 todelete = try_kw;
393 try_kw++;
394 container.erase( todelete );
395 }
396}
#define error(str)
Definition: mkdosfs.c:1605
sl_it complete_block(sl_it i, sl_it end, string start_ch, string end_ch)
Definition: ms2ps.cpp:234
string FINALLY_TOKEN
Definition: ms2ps.cpp:49
void append_block(sl_t &t, sl_it b, sl_it e)
Definition: ms2ps.cpp:257
string EXCEPT_TOKEN
Definition: ms2ps.cpp:48
string makename(string intro)
Definition: ms2ps.cpp:248
static calc_node_t temp
Definition: rpn_ieee.c:38

Referenced by main().

◆ isident()

int isident ( int  c)

Definition at line 58 of file ms2ps.cpp.

58 {
59 return (c != '{') && (c != '}') && (c != '(') && (c != ')') &&
60 (c != '\'') && (c != '\"') && !isspace(c);
61}
const GLubyte * c
Definition: glext.h:8905

Referenced by areident().

◆ isop()

bool isop ( string  tok)

Definition at line 74 of file ms2ps.cpp.

74 {
75 int i;
76 for( i = 0; c_operators[i] && tok != c_operators[i]; i++ );
77 if( c_operators[i] ) return true; else return false;
78}
char * c_operators[]
Definition: ms2ps.cpp:50

Referenced by match_operator().

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 404 of file ms2ps.cpp.

404 {
405 sl_t tok;
406 sl_it try_found;
407 int i;
408
409 for( i = 1; i < argc; i++ ) {
410 if( string(argv[i]) == "-try" && i < argc - 1 ) {
411 i++;
412 TRY_TOKEN = argv[i];
413 } else if( string(argv[i]) == "-except" && i < argc - 1 ) {
414 i++;
416 } else if( string(argv[i]) == "-finally" && i < argc - 1 ) {
417 i++;
419 }
420 }
421
422 /* XXX Uses much memory for large files */
423 while( expand_input(tok) );
424
425 while( (try_found = find( tok.begin(), tok.end(), TRY_TOKEN )) !=
426 tok.end() ) {
427 handle_try( tok, try_found, tok.end() );
428 }
429
430 tok.push_front("#include <pseh/framebased.h>\n");
431 print_tokens( tok.begin(), tok.end() );
432}
static int argc
Definition: ServiceArgs.c:12
static TAGID TAGID find
Definition: db.cpp:155
#define argv
Definition: mplay32.c:18
string TRY_TOKEN
Definition: ms2ps.cpp:47
void handle_try(sl_t &container, sl_it try_kw, sl_it end)
Definition: ms2ps.cpp:287
void print_tokens(sl_it begin, sl_it end)
Definition: ms2ps.cpp:398
bool expand_input(sl_t &tok)
Definition: ms2ps.cpp:208

◆ makename()

string makename ( string  intro)

Definition at line 248 of file ms2ps.cpp.

248 {
249 static int i = 0;
250 char buf[100];
251
252 sprintf( buf, "%s%d", intro.c_str(), i++ );
253
254 return buf;
255}
const _CharT * c_str() const
Definition: _string.h:949
#define sprintf(buf, format,...)
Definition: sprintf.c:55

Referenced by handle_try().

◆ match_ident()

string match_ident ( string  tok,
string  la 
)

Definition at line 92 of file ms2ps.cpp.

92 {
93 return generic_match( tok, la, areident );
94}
string generic_match(string tok, string la, bool(*mf)(string))
Definition: ms2ps.cpp:82
bool areident(string s)
Definition: ms2ps.cpp:72

Referenced by snarf_tokens().

◆ match_operator()

string match_operator ( string  tok,
string  la 
)

Definition at line 88 of file ms2ps.cpp.

88 {
89 return generic_match( tok, la, isop );
90}
bool isop(string tok)
Definition: ms2ps.cpp:74

Referenced by snarf_tokens().

◆ match_quoted_const()

string match_quoted_const ( string  tok,
string  la,
char  q 
)

Definition at line 96 of file ms2ps.cpp.

96 {
97 if( ((tok.size() && tok[0] == q) ||
98 ((tok.size() > 2) && tok[0] == 'L' && tok[1] == q)) &&
99 (tok.rfind(q) == (tok.size() - 1)) ) {
100 if( (tok.rfind("\\") != (tok.size() - 2)) ||
101 (tok.size() > 3 && tok.rfind("\\\\") == (tok.size() - 3)) )
102 return tok;
103 else return "";
104 }
105 else return "";
106}
size_type rfind(const _Self &__s, size_type __pos=npos) const
Definition: _string.h:966
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063

Referenced by snarf_tokens().

◆ print_tokens()

void print_tokens ( sl_it  begin,
sl_it  end 
)

Definition at line 398 of file ms2ps.cpp.

398 {
399 for( sl_it i = begin; i != end; i++ )
400 if( *i == "\n" ) cout << *i;
401 else cout << /*"[" <<*/ *i << /*"]" <<*/ " ";
402}
#define cout
Definition: iostream.cpp:38
static clock_t begin
Definition: xmllint.c:458

Referenced by main().

◆ snarf_tokens()

sl_t snarf_tokens ( string  line)

Definition at line 108 of file ms2ps.cpp.

108 {
109 int i;
110 sl_t out;
111 string curtok, la, op, ident, qconst;
112
113 line += " ";
114
115 for( i = 0; i < (int)line.size() - 1; i++ ) {
116 /*cout << "Char [" << line[i] << "] and [" << line[i+1] << "]"
117 << endl; */
118
119 if( (!curtok.size() ||
120 (curtok[0] != '\'' && curtok[0] != '\"')) &&
121 (curtok.size() <= 2 ||
122 curtok[0] != 'L' ||
123 (curtok[1] != '\'' && curtok[1] != '\"')) &&
124 isspace(line[i]) ) {
125 if( curtok.size() ) out.push_back( curtok );
126 curtok = "";
127 continue;
128 }
129
130 curtok.push_back( line[i] );
131
132 la = curtok + line[i+1];
133
134 op = match_operator( curtok, la );
135
136 if( op != "" ) {
137 out.push_back( op MAYBE(+ "O") );
138 curtok = "";
139 continue;
140 }
141
142 if( la != "L\"" && la != "L\'" ) {
143 ident = match_ident( curtok, la );
144
145 if( ident != "" ) {
146 out.push_back( ident MAYBE(+ "I") );
147 curtok = "";
148 continue;
149 }
150 }
151
152 qconst = match_quoted_const( curtok, la, '\'' );
153
154 if( qconst != "" ) {
155 out.push_back( qconst MAYBE(+ "q") );
156 curtok = "";
157 continue;
158 }
159
160 qconst = match_quoted_const( curtok, la, '\"' );
161
162 if( qconst != "" ) {
163 out.push_back( qconst MAYBE(+ "Q") );
164 curtok = "";
165 continue;
166 }
167 }
168
169 return out;
170}
void push_back(_CharT __c)
Definition: _string.h:534
UINT op
Definition: effect.c:236
string match_ident(string tok, string la)
Definition: ms2ps.cpp:92
string match_quoted_const(string tok, string la, char q)
Definition: ms2ps.cpp:96
#define MAYBE(x)
Definition: ms2ps.cpp:35
string match_operator(string tok, string la)
Definition: ms2ps.cpp:88
_In_ ULONG _In_ ULONG_PTR ident
Definition: winddi.h:3994

Referenced by expand_input().

Variable Documentation

◆ c_operators

char* c_operators[]
Initial value:
= {
"{",
"}",
"(",
")",
}
#define NULL
Definition: types.h:112

Definition at line 50 of file ms2ps.cpp.

Referenced by isop().

◆ EXCEPT_TOKEN

string EXCEPT_TOKEN = "__except"

Definition at line 48 of file ms2ps.cpp.

Referenced by handle_try(), and main().

◆ FINALLY_TOKEN

string FINALLY_TOKEN = "__finally"

Definition at line 49 of file ms2ps.cpp.

Referenced by handle_try(), and main().

◆ TRY_TOKEN

string TRY_TOKEN = "__try"

Definition at line 47 of file ms2ps.cpp.

Referenced by main().