| 1 |
/* do not edit automatically generated by mc from mcPretty. */ |
| 2 |
/* This file is part of GNU Modula-2. |
| 3 |
|
| 4 |
GNU Modula-2 is free software; you can redistribute it and/or modify it under |
| 5 |
the terms of the GNU General Public License as published by the Free |
| 6 |
Software Foundation; either version 3, or (at your option) any later |
| 7 |
version. |
| 8 |
|
| 9 |
GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 |
for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with GCC; see the file COPYING3. If not see |
| 16 |
<http://www.gnu.org/licenses/>. */ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
#include "system.h" |
| 20 |
#include <stdbool.h> |
| 21 |
# if !defined (PROC_D) |
| 22 |
# define PROC_D |
| 23 |
typedef void (*PROC_t) (void); |
| 24 |
typedef struct { PROC_t proc; } PROC; |
| 25 |
# endif |
| 26 |
|
| 27 |
# if !defined (TRUE) |
| 28 |
# define TRUE (1==1) |
| 29 |
# endif |
| 30 |
|
| 31 |
# if !defined (FALSE) |
| 32 |
# define FALSE (1==0) |
| 33 |
# endif |
| 34 |
|
| 35 |
# include "GStorage.h" |
| 36 |
#if defined(__cplusplus) |
| 37 |
# undef NULL |
| 38 |
# define NULL 0 |
| 39 |
#endif |
| 40 |
#define _mcPretty_C |
| 41 |
|
| 42 |
#include "GmcPretty.h" |
| 43 |
# include "GDynamicStrings.h" |
| 44 |
# include "GStorage.h" |
| 45 |
|
| 46 |
typedef struct mcPretty_writeProc_p mcPretty_writeProc; |
| 47 |
|
| 48 |
typedef struct mcPretty_writeLnProc_p mcPretty_writeLnProc; |
| 49 |
|
| 50 |
typedef struct mcPretty__T1_r mcPretty__T1; |
| 51 |
|
| 52 |
typedef mcPretty__T1 *mcPretty_pretty__opaque; |
| 53 |
|
| 54 |
struct mcPretty__T1_r { |
| 55 |
mcPretty_writeProc write_; |
| 56 |
mcPretty_writeLnProc writeln; |
| 57 |
bool needsSpace; |
| 58 |
bool needsIndent; |
| 59 |
unsigned int seekPos; |
| 60 |
unsigned int curLine; |
| 61 |
unsigned int curPos; |
| 62 |
unsigned int indent; |
| 63 |
mcPretty_pretty__opaque stacked; |
| 64 |
}; |
| 65 |
|
| 66 |
|
| 67 |
/* |
| 68 |
initPretty - initialise a pretty print data structure. |
| 69 |
*/ |
| 70 |
|
| 71 |
extern "C" mcPretty_pretty mcPretty_initPretty (mcPretty_writeProc w, mcPretty_writeLnProc l); |
| 72 |
|
| 73 |
/* |
| 74 |
dupPretty - duplicate a pretty print data structure. |
| 75 |
*/ |
| 76 |
|
| 77 |
extern "C" mcPretty_pretty mcPretty_dupPretty (mcPretty_pretty p); |
| 78 |
|
| 79 |
/* |
| 80 |
killPretty - destroy a pretty print data structure. |
| 81 |
Post condition: p is assigned to NIL. |
| 82 |
*/ |
| 83 |
|
| 84 |
extern "C" void mcPretty_killPretty (mcPretty_pretty *p); |
| 85 |
|
| 86 |
/* |
| 87 |
pushPretty - duplicate, p. Push, p, and return the duplicate. |
| 88 |
*/ |
| 89 |
|
| 90 |
extern "C" mcPretty_pretty mcPretty_pushPretty (mcPretty_pretty p); |
| 91 |
|
| 92 |
/* |
| 93 |
popPretty - pops the pretty object from the stack. |
| 94 |
*/ |
| 95 |
|
| 96 |
extern "C" mcPretty_pretty mcPretty_popPretty (mcPretty_pretty p); |
| 97 |
|
| 98 |
/* |
| 99 |
getindent - returns the current indent value. |
| 100 |
*/ |
| 101 |
|
| 102 |
extern "C" unsigned int mcPretty_getindent (mcPretty_pretty p); |
| 103 |
|
| 104 |
/* |
| 105 |
setindent - sets the current indent to, n. |
| 106 |
*/ |
| 107 |
|
| 108 |
extern "C" void mcPretty_setindent (mcPretty_pretty p, unsigned int n); |
| 109 |
|
| 110 |
/* |
| 111 |
getcurpos - returns the current cursor position. |
| 112 |
*/ |
| 113 |
|
| 114 |
extern "C" unsigned int mcPretty_getcurpos (mcPretty_pretty s); |
| 115 |
|
| 116 |
/* |
| 117 |
getseekpos - returns the seek position. |
| 118 |
*/ |
| 119 |
|
| 120 |
extern "C" unsigned int mcPretty_getseekpos (mcPretty_pretty s); |
| 121 |
|
| 122 |
/* |
| 123 |
getcurline - returns the current line number. |
| 124 |
*/ |
| 125 |
|
| 126 |
extern "C" unsigned int mcPretty_getcurline (mcPretty_pretty s); |
| 127 |
extern "C" void mcPretty_setNeedSpace (mcPretty_pretty s); |
| 128 |
|
| 129 |
/* |
| 130 |
noSpace - unset needsSpace. |
| 131 |
*/ |
| 132 |
|
| 133 |
extern "C" void mcPretty_noSpace (mcPretty_pretty s); |
| 134 |
|
| 135 |
/* |
| 136 |
print - print a string using, p. |
| 137 |
*/ |
| 138 |
|
| 139 |
extern "C" void mcPretty_print (mcPretty_pretty p, const char *a_, unsigned int _a_high); |
| 140 |
|
| 141 |
/* |
| 142 |
prints - print a string using, p. |
| 143 |
*/ |
| 144 |
|
| 145 |
extern "C" void mcPretty_prints (mcPretty_pretty p, DynamicStrings_String s); |
| 146 |
|
| 147 |
/* |
| 148 |
raw - print out string, s, without any translation of |
| 149 |
escape sequences. |
| 150 |
*/ |
| 151 |
|
| 152 |
extern "C" void mcPretty_raw (mcPretty_pretty p, DynamicStrings_String s); |
| 153 |
|
| 154 |
/* |
| 155 |
flushSpace - |
| 156 |
*/ |
| 157 |
|
| 158 |
static void flushSpace (mcPretty_pretty__opaque p); |
| 159 |
|
| 160 |
/* |
| 161 |
flushIndent - |
| 162 |
*/ |
| 163 |
|
| 164 |
static void flushIndent (mcPretty_pretty__opaque p); |
| 165 |
|
| 166 |
|
| 167 |
/* |
| 168 |
flushSpace - |
| 169 |
*/ |
| 170 |
|
| 171 |
static void flushSpace (mcPretty_pretty__opaque p) |
| 172 |
{ |
| 173 |
if (p->needsSpace) |
| 174 |
{ |
| 175 |
(*p->write_.proc) (' '); |
| 176 |
p->needsSpace = false; |
| 177 |
p->curPos += 1; |
| 178 |
p->seekPos += 1; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
/* |
| 184 |
flushIndent - |
| 185 |
*/ |
| 186 |
|
| 187 |
static void flushIndent (mcPretty_pretty__opaque p) |
| 188 |
{ |
| 189 |
unsigned int i; |
| 190 |
|
| 191 |
flushSpace (p); |
| 192 |
if (p->needsIndent) |
| 193 |
{ |
| 194 |
while (p->curPos < p->indent) |
| 195 |
{ |
| 196 |
(*p->write_.proc) (' '); |
| 197 |
p->curPos += 1; |
| 198 |
p->seekPos += 1; |
| 199 |
} |
| 200 |
p->needsIndent = false; |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
/* |
| 206 |
initPretty - initialise a pretty print data structure. |
| 207 |
*/ |
| 208 |
|
| 209 |
extern "C" mcPretty_pretty mcPretty_initPretty (mcPretty_writeProc w, mcPretty_writeLnProc l) |
| 210 |
{ |
| 211 |
mcPretty_pretty__opaque p; |
| 212 |
|
| 213 |
Storage_ALLOCATE ((void **) &p, sizeof (mcPretty__T1)); |
| 214 |
p->write_ = w; |
| 215 |
p->writeln = l; |
| 216 |
p->needsSpace = false; |
| 217 |
p->needsIndent = false; |
| 218 |
p->curPos = 0; |
| 219 |
p->curLine = 0; |
| 220 |
p->seekPos = 0; |
| 221 |
p->indent = 0; |
| 222 |
p->stacked = static_cast<mcPretty_pretty__opaque> (NULL); |
| 223 |
return static_cast<mcPretty_pretty> (p); |
| 224 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 225 |
__builtin_unreachable (); |
| 226 |
} |
| 227 |
|
| 228 |
|
| 229 |
/* |
| 230 |
dupPretty - duplicate a pretty print data structure. |
| 231 |
*/ |
| 232 |
|
| 233 |
extern "C" mcPretty_pretty mcPretty_dupPretty (mcPretty_pretty p) |
| 234 |
{ |
| 235 |
mcPretty_pretty__opaque q; |
| 236 |
|
| 237 |
Storage_ALLOCATE ((void **) &q, sizeof (mcPretty__T1)); |
| 238 |
(*q) = (*static_cast<mcPretty_pretty__opaque> (p)); |
| 239 |
return static_cast<mcPretty_pretty> (q); |
| 240 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 241 |
__builtin_unreachable (); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
/* |
| 246 |
killPretty - destroy a pretty print data structure. |
| 247 |
Post condition: p is assigned to NIL. |
| 248 |
*/ |
| 249 |
|
| 250 |
extern "C" void mcPretty_killPretty (mcPretty_pretty *p) |
| 251 |
{ |
| 252 |
(*p) = static_cast<mcPretty_pretty> (NULL); |
| 253 |
return; |
| 254 |
Storage_DEALLOCATE ((void **) &(*p), sizeof (mcPretty__T1)); |
| 255 |
(*p) = static_cast<mcPretty_pretty> (NULL); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
/* |
| 260 |
pushPretty - duplicate, p. Push, p, and return the duplicate. |
| 261 |
*/ |
| 262 |
|
| 263 |
extern "C" mcPretty_pretty mcPretty_pushPretty (mcPretty_pretty p) |
| 264 |
{ |
| 265 |
mcPretty_pretty__opaque q; |
| 266 |
|
| 267 |
q = static_cast<mcPretty_pretty__opaque> (mcPretty_dupPretty (p)); |
| 268 |
q->stacked = static_cast<mcPretty_pretty__opaque> (p); |
| 269 |
return static_cast<mcPretty_pretty> (q); |
| 270 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 271 |
__builtin_unreachable (); |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
/* |
| 276 |
popPretty - pops the pretty object from the stack. |
| 277 |
*/ |
| 278 |
|
| 279 |
extern "C" mcPretty_pretty mcPretty_popPretty (mcPretty_pretty p) |
| 280 |
{ |
| 281 |
mcPretty_pretty__opaque q; |
| 282 |
|
| 283 |
q = static_cast<mcPretty_pretty__opaque> (p)->stacked; |
| 284 |
q->needsIndent = static_cast<mcPretty_pretty__opaque> (p)->needsIndent; |
| 285 |
q->needsSpace = static_cast<mcPretty_pretty__opaque> (p)->needsSpace; |
| 286 |
q->curPos = static_cast<mcPretty_pretty__opaque> (p)->curPos; |
| 287 |
q->seekPos = static_cast<mcPretty_pretty__opaque> (p)->seekPos; |
| 288 |
q->curLine = static_cast<mcPretty_pretty__opaque> (p)->curLine; |
| 289 |
mcPretty_killPretty (&p); |
| 290 |
return static_cast<mcPretty_pretty> (q); |
| 291 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 292 |
__builtin_unreachable (); |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
/* |
| 297 |
getindent - returns the current indent value. |
| 298 |
*/ |
| 299 |
|
| 300 |
extern "C" unsigned int mcPretty_getindent (mcPretty_pretty p) |
| 301 |
{ |
| 302 |
return static_cast<mcPretty_pretty__opaque> (p)->indent; |
| 303 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 304 |
__builtin_unreachable (); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
/* |
| 309 |
setindent - sets the current indent to, n. |
| 310 |
*/ |
| 311 |
|
| 312 |
extern "C" void mcPretty_setindent (mcPretty_pretty p, unsigned int n) |
| 313 |
{ |
| 314 |
static_cast<mcPretty_pretty__opaque> (p)->indent = n; |
| 315 |
} |
| 316 |
|
| 317 |
|
| 318 |
/* |
| 319 |
getcurpos - returns the current cursor position. |
| 320 |
*/ |
| 321 |
|
| 322 |
extern "C" unsigned int mcPretty_getcurpos (mcPretty_pretty s) |
| 323 |
{ |
| 324 |
if (static_cast<mcPretty_pretty__opaque> (s)->needsSpace) |
| 325 |
{ |
| 326 |
return static_cast<mcPretty_pretty__opaque> (s)->curPos+1; |
| 327 |
} |
| 328 |
else |
| 329 |
{ |
| 330 |
return static_cast<mcPretty_pretty__opaque> (s)->curPos; |
| 331 |
} |
| 332 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 333 |
__builtin_unreachable (); |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
/* |
| 338 |
getseekpos - returns the seek position. |
| 339 |
*/ |
| 340 |
|
| 341 |
extern "C" unsigned int mcPretty_getseekpos (mcPretty_pretty s) |
| 342 |
{ |
| 343 |
return static_cast<mcPretty_pretty__opaque> (s)->seekPos; |
| 344 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 345 |
__builtin_unreachable (); |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
/* |
| 350 |
getcurline - returns the current line number. |
| 351 |
*/ |
| 352 |
|
| 353 |
extern "C" unsigned int mcPretty_getcurline (mcPretty_pretty s) |
| 354 |
{ |
| 355 |
return static_cast<mcPretty_pretty__opaque> (s)->curLine; |
| 356 |
/* static analysis guarentees a RETURN statement will be used before here. */ |
| 357 |
__builtin_unreachable (); |
| 358 |
} |
| 359 |
|
| 360 |
extern "C" void mcPretty_setNeedSpace (mcPretty_pretty s) |
| 361 |
{ |
| 362 |
/* |
| 363 |
setneedSpace - sets needSpace flag to TRUE. |
| 364 |
*/ |
| 365 |
static_cast<mcPretty_pretty__opaque> (s)->needsSpace = true; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
/* |
| 370 |
noSpace - unset needsSpace. |
| 371 |
*/ |
| 372 |
|
| 373 |
extern "C" void mcPretty_noSpace (mcPretty_pretty s) |
| 374 |
{ |
| 375 |
static_cast<mcPretty_pretty__opaque> (s)->needsSpace = false; |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
/* |
| 380 |
print - print a string using, p. |
| 381 |
*/ |
| 382 |
|
| 383 |
extern "C" void mcPretty_print (mcPretty_pretty p, const char *a_, unsigned int _a_high) |
| 384 |
{ |
| 385 |
DynamicStrings_String s; |
| 386 |
char a[_a_high+1]; |
| 387 |
|
| 388 |
/* make a local copy of each unbounded array. */ |
| 389 |
memcpy (a, a_, _a_high+1); |
| 390 |
|
| 391 |
s = DynamicStrings_InitString ((const char *) a, _a_high); |
| 392 |
mcPretty_prints (p, s); |
| 393 |
s = DynamicStrings_KillString (s); |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
/* |
| 398 |
prints - print a string using, p. |
| 399 |
*/ |
| 400 |
|
| 401 |
extern "C" void mcPretty_prints (mcPretty_pretty p, DynamicStrings_String s) |
| 402 |
{ |
| 403 |
unsigned int l; |
| 404 |
unsigned int i; |
| 405 |
|
| 406 |
l = DynamicStrings_Length (s); |
| 407 |
i = 0; |
| 408 |
flushSpace (static_cast<mcPretty_pretty__opaque> (p)); |
| 409 |
while (i < l) |
| 410 |
{ |
| 411 |
if ((((i+2) <= l) && ((DynamicStrings_char (s, static_cast<int> (i))) == '\\')) && ((DynamicStrings_char (s, static_cast<int> (i+1))) == 'n')) |
| 412 |
{ |
| 413 |
static_cast<mcPretty_pretty__opaque> (p)->needsIndent = true; |
| 414 |
static_cast<mcPretty_pretty__opaque> (p)->needsSpace = false; |
| 415 |
static_cast<mcPretty_pretty__opaque> (p)->curPos = 0; |
| 416 |
(*static_cast<mcPretty_pretty__opaque> (p)->writeln.proc) (); |
| 417 |
static_cast<mcPretty_pretty__opaque> (p)->seekPos += 1; |
| 418 |
static_cast<mcPretty_pretty__opaque> (p)->curLine += 1; |
| 419 |
i += 1; |
| 420 |
} |
| 421 |
else |
| 422 |
{ |
| 423 |
flushIndent (static_cast<mcPretty_pretty__opaque> (p)); |
| 424 |
(*static_cast<mcPretty_pretty__opaque> (p)->write_.proc) (DynamicStrings_char (s, static_cast<int> (i))); |
| 425 |
static_cast<mcPretty_pretty__opaque> (p)->curPos += 1; |
| 426 |
static_cast<mcPretty_pretty__opaque> (p)->seekPos += 1; |
| 427 |
} |
| 428 |
i += 1; |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
/* |
| 434 |
raw - print out string, s, without any translation of |
| 435 |
escape sequences. |
| 436 |
*/ |
| 437 |
|
| 438 |
extern "C" void mcPretty_raw (mcPretty_pretty p, DynamicStrings_String s) |
| 439 |
{ |
| 440 |
unsigned int l; |
| 441 |
unsigned int i; |
| 442 |
|
| 443 |
l = DynamicStrings_Length (s); |
| 444 |
i = 0; |
| 445 |
flushSpace (static_cast<mcPretty_pretty__opaque> (p)); |
| 446 |
flushIndent (static_cast<mcPretty_pretty__opaque> (p)); |
| 447 |
while (i < l) |
| 448 |
{ |
| 449 |
(*static_cast<mcPretty_pretty__opaque> (p)->write_.proc) (DynamicStrings_char (s, static_cast<int> (i))); |
| 450 |
static_cast<mcPretty_pretty__opaque> (p)->curPos += 1; |
| 451 |
static_cast<mcPretty_pretty__opaque> (p)->seekPos += 1; |
| 452 |
i += 1; |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
extern "C" void _M2_mcPretty_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 457 |
{ |
| 458 |
} |
| 459 |
|
| 460 |
extern "C" void _M2_mcPretty_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[]) |
| 461 |
{ |
| 462 |
} |