@@ -230,289 +230,6 @@ static time_t now; /* current timestamp, for built-in constants "__
230
230
static HWND hwndFinish = 0 ;
231
231
#endif
232
232
233
- #if !defined NO_MAIN
234
-
235
- #if defined __TURBOC__ && !defined __32BIT__
236
- extern unsigned int _stklen = 0x2000 ;
237
- #endif
238
-
239
- int main (int argc , char * argv [])
240
- {
241
- return pc_compile (argc ,argv );
242
- }
243
-
244
- /* pc_printf()
245
- * Called for general purpose "console" output. This function prints general
246
- * purpose messages; errors go through pc_error(). The function is modelled
247
- * after printf().
248
- */
249
- int pc_printf (const char * message ,...)
250
- {
251
- int ret ;
252
- va_list argptr ;
253
-
254
- va_start (argptr ,message );
255
- ret = vprintf (message ,argptr );
256
- va_end (argptr );
257
-
258
- return ret ;
259
- }
260
-
261
- /* pc_error()
262
- * Called for producing error output.
263
- * number the error number (as documented in the manual)
264
- * message a string describing the error with embedded %d and %s tokens
265
- * filename the name of the file currently being parsed
266
- * firstline the line number at which the expression started on which
267
- * the error was found, or -1 if there is no "starting line"
268
- * lastline the line number at which the error was detected
269
- * argptr a pointer to the first of a series of arguments (for macro
270
- * "va_arg")
271
- * Return:
272
- * If the function returns 0, the parser attempts to continue compilation.
273
- * On a non-zero return value, the parser aborts.
274
- */
275
- int pc_error (int number ,char * message ,char * filename ,int firstline ,int lastline ,va_list argptr )
276
- {
277
- static char * prefix [3 ]= { "error" , "fatal error" , "warning" };
278
-
279
- if (number != 0 ) {
280
- char * pre ;
281
-
282
- pre = prefix [number /100 ];
283
- if (number >=200 && pc_geterrorwarnings ()){
284
- pre = prefix [0 ];
285
- }
286
- if (firstline >=0 )
287
- fprintf (stderr ,"%s(%d -- %d) : %s %03d: " ,filename ,firstline ,lastline ,pre ,number );
288
- else
289
- fprintf (stderr ,"%s(%d) : %s %03d: " ,filename ,lastline ,pre ,number );
290
- } /* if */
291
- vfprintf (stderr ,message ,argptr );
292
- fflush (stderr );
293
- return 0 ;
294
- }
295
-
296
- /* pc_opensrc()
297
- * Opens a source file (or include file) for reading. The "file" does not have
298
- * to be a physical file, one might compile from memory.
299
- * filename the name of the "file" to read from
300
- * Return:
301
- * The function must return a pointer, which is used as a "magic cookie" to
302
- * all I/O functions. When failing to open the file for reading, the
303
- * function must return NULL.
304
- * Note:
305
- * Several "source files" may be open at the same time. Specifically, one
306
- * file can be open for reading and another for writing.
307
- */
308
- void * pc_opensrc (char * filename )
309
- {
310
- return fopen (filename ,"r" );
311
- }
312
-
313
- /* pc_createsrc()
314
- * Creates/overwrites a source file for writing. The "file" does not have
315
- * to be a physical file, one might compile from memory.
316
- * filename the name of the "file" to create
317
- * Return:
318
- * The function must return a pointer, which is used as a "magic cookie" to
319
- * all I/O functions. When failing to open the file for reading, the
320
- * function must return NULL.
321
- * Note:
322
- * Several "source files" may be open at the same time. Specifically, one
323
- * file can be open for reading and another for writing.
324
- */
325
- void * pc_createsrc (char * filename )
326
- {
327
- return fopen (filename ,"w" );
328
- }
329
-
330
- /* pc_createtmpsrc()
331
- * Creates a temporary source file with a unique name for writing.
332
- * Return:
333
- * The function must return a pointer, which is used as a "magic cookie" to
334
- * all I/O functions. When failing to open the file for reading, the
335
- * function must return NULL.
336
- */
337
- void * pc_createtmpsrc (char * * filename )
338
- {
339
- char * tname = NULL ;
340
- FILE * ftmp = NULL ;
341
-
342
- #if defined __WIN32__ || defined _WIN32
343
- tname = _tempnam (NULL ,"pawn" );
344
- ftmp = fopen (tname ,"wt" );
345
- #elif defined __MSDOS__ || defined _Windows
346
- tname = tempnam (NULL ,"pawn" );
347
- ftmp = fopen (tname ,"wt" );
348
- #else
349
- static const char template []= "/tmp/pawnXXXXXX" ;
350
- if ((tname = malloc (sizeof (template )))!= NULL ) {
351
- int fdtmp ;
352
- strncpy (tname ,template ,arraysize (template ));
353
- if ((fdtmp = mkstemp (tname )) >= 0 ) {
354
- ftmp = fdopen (fdtmp ,"wt" );
355
- } else {
356
- free (tname );
357
- tname = NULL ;
358
- } /* if */
359
- } /* if */
360
- #endif
361
- if (filename != NULL )
362
- * filename = tname ;
363
- return ftmp ;
364
- }
365
-
366
- /* pc_closesrc()
367
- * Closes a source file (or include file). The "handle" parameter has the
368
- * value that pc_opensrc() returned in an earlier call.
369
- */
370
- void pc_closesrc (void * handle )
371
- {
372
- assert (handle != NULL );
373
- fclose ((FILE * )handle );
374
- }
375
-
376
- /* pc_resetsrc()
377
- * "position" may only hold a pointer that was previously obtained from
378
- * pc_getpossrc()
379
- */
380
- void pc_resetsrc (void * handle ,void * position )
381
- {
382
- assert (handle != NULL );
383
- fsetpos ((FILE * )handle ,(fpos_t * )position );
384
- }
385
-
386
- /* pc_readsrc()
387
- * Reads a single line from the source file (or up to a maximum number of
388
- * characters if the line in the input file is too long).
389
- */
390
- char * pc_readsrc (void * handle ,unsigned char * target ,int maxchars )
391
- {
392
- return fgets ((char * )target ,maxchars ,(FILE * )handle );
393
- }
394
-
395
- /* pc_writesrc()
396
- * Writes to to the source file. There is no automatic line ending; to end a
397
- * line, write a "\n".
398
- */
399
- int pc_writesrc (void * handle ,unsigned char * source )
400
- {
401
- return fputs ((char * )source ,(FILE * )handle ) >= 0 ;
402
- }
403
-
404
- void * pc_getpossrc (void * handle )
405
- {
406
- static fpos_t lastpos ; /* may need to have a LIFO stack of such positions */
407
-
408
- fgetpos ((FILE * )handle ,& lastpos );
409
- return & lastpos ;
410
- }
411
-
412
- int pc_eofsrc (void * handle )
413
- {
414
- return feof ((FILE * )handle );
415
- }
416
-
417
- /* should return a pointer, which is used as a "magic cookie" to all I/O
418
- * functions; return NULL for failure
419
- */
420
- void * pc_openasm (char * filename )
421
- {
422
- #if defined __MSDOS__ || defined SC_LIGHT
423
- return fopen (filename ,"w+" );
424
- #else
425
- return mfcreate (filename );
426
- #endif
427
- }
428
-
429
- void pc_closeasm (void * handle , int deletefile )
430
- {
431
- #if defined __MSDOS__ || defined SC_LIGHT
432
- if (handle != NULL )
433
- fclose ((FILE * )handle );
434
- if (deletefile )
435
- remove (outfname );
436
- #else
437
- if (handle != NULL ) {
438
- if (!deletefile )
439
- mfdump ((MEMFILE * )handle );
440
- mfclose ((MEMFILE * )handle );
441
- } /* if */
442
- #endif
443
- }
444
-
445
- void pc_resetasm (void * handle )
446
- {
447
- assert (handle != NULL );
448
- #if defined __MSDOS__ || defined SC_LIGHT
449
- fflush ((FILE * )handle );
450
- fseek ((FILE * )handle ,0 ,SEEK_SET );
451
- #else
452
- mfseek ((MEMFILE * )handle ,0 ,SEEK_SET );
453
- #endif
454
- }
455
-
456
- int pc_writeasm (void * handle ,char * string )
457
- {
458
- #if defined __MSDOS__ || defined SC_LIGHT
459
- return fputs (string ,(FILE * )handle ) >= 0 ;
460
- #else
461
- return mfputs ((MEMFILE * )handle ,string );
462
- #endif
463
- }
464
-
465
- char * pc_readasm (void * handle , char * string , int maxchars )
466
- {
467
- #if defined __MSDOS__ || defined SC_LIGHT
468
- return fgets (string ,maxchars ,(FILE * )handle );
469
- #else
470
- return mfgets ((MEMFILE * )handle ,string ,maxchars );
471
- #endif
472
- }
473
-
474
- /* Should return a pointer, which is used as a "magic cookie" to all I/O
475
- * functions; return NULL for failure.
476
- */
477
- void * pc_openbin (char * filename )
478
- {
479
- FILE * fbin ;
480
-
481
- fbin = fopen (filename ,"wb" );
482
- setvbuf (fbin ,NULL ,_IOFBF ,1UL <<20 );
483
- return fbin ;
484
- }
485
-
486
- void pc_closebin (void * handle ,int deletefile )
487
- {
488
- fclose ((FILE * )handle );
489
- if (deletefile )
490
- remove (binfname );
491
- }
492
-
493
- /* pc_resetbin()
494
- * Can seek to any location in the file.
495
- * The offset is always from the start of the file.
496
- */
497
- void pc_resetbin (void * handle ,long offset )
498
- {
499
- fflush ((FILE * )handle );
500
- fseek ((FILE * )handle ,offset ,SEEK_SET );
501
- }
502
-
503
- int pc_writebin (void * handle ,void * buffer ,int size )
504
- {
505
- return (int )fwrite (buffer ,1 ,size ,(FILE * )handle ) == size ;
506
- }
507
-
508
- long pc_lengthbin (void * handle )
509
- {
510
- return ftell ((FILE * )handle );
511
- }
512
-
513
- #endif /* !defined NO_MAIN */
514
-
515
-
516
233
/* "main" of the compiler
517
234
*/
518
235
#if defined __cplusplus
0 commit comments