@@ -378,7 +378,7 @@ static int PrintImpl__writeBufConvertLines(const char *filename)
378378 regex_t re_begin ,re_end ;
379379 regmatch_t matches [3 ];
380380 int i ;
381- long nlines = 3 /* We start at 3 because we write 2 lines before the first line */ , modelicaLine = 0 ;
381+ long nlines = 6 /* We start at 6 because we write 6 lines before the first line */ , modelicaLine = 0 ;
382382 /* What we try to match: */
383383 /*#modelicaLine [/path/to/a.mo:4:3-4:12]*/
384384 /*#endModelicaLine*/
@@ -429,13 +429,21 @@ static int PrintImpl__writeBufConvertLines(const char *filename)
429429 fclose (file );
430430 return 1 ;
431431 }
432- fprintf (file ,"#ifdef __BASE_FILE__\n"
433- " #define OMC_FILE __BASE_FILE__\n"
432+ #if defined(__MINGW32__ ) || defined(_MSC_VER )
433+ /* on Windows change the backslashes to forward slashes */
434+ strtmp = _replace (filename , "\\" , "/" );
435+ #endif
436+ fprintf (file ,"#ifdef OMC_BASE_FILE\n"
437+ " #define OMC_FILE OMC_BASE_FILE\n"
434438 "#else\n"
435439 " #define OMC_FILE \"%s\"\n"
436- "#endif\n"
437- "#line %ld OMC_FILE\n" ,
438- filename , nlines ++ );
440+ "#endif\n" ,
441+ #if defined(__MINGW32__ ) || defined (_MSC_VER )
442+ strtmp );
443+ free (strtmp );
444+ #else
445+ filename );
446+ #endif
439447 do {
440448 next = strchr (str ,'\n' );
441449 if (!next ) {
@@ -448,20 +456,20 @@ static int PrintImpl__writeBufConvertLines(const char *filename)
448456 str [matches [2 ].rm_eo ] = '\0' ;
449457 modelicaFileName = str + matches [1 ].rm_so ;
450458 modelicaLine = strtol (str + matches [2 ].rm_so , NULL , 10 );
459+ #if defined(__MINGW32__ ) || defined(_MSC_VER )
460+ /* on Windows change the backslashes to forward slashes */
461+ modelicaFileName = _replace (modelicaFileName , "\\" , "/" );
462+ #endif
451463 } else if (0 == regexec (& re_end , str , 3 , matches , 0 )) {
452464 if (modelicaFileName ) { /* There is sometimes #endModlicaLine without a matching #modelicaLine */
465+ #if defined(__MINGW32__ ) || defined(_MSC_VER )
466+ free (modelicaFileName );
467+ #endif
453468 modelicaFileName = NULL ;
454469 fprintf (file ,"#line %ld OMC_FILE\n" , nlines ++ );
455470 }
456471 } else if (modelicaFileName ) {
457- #if defined(__MINGW32__ ) || defined(_MSC_VER )
458- /* on Windows escape the backslashes */
459- strtmp = _replace (modelicaFileName , "\\" , "\\\\" );
460- fprintf (file ,"#line %ld \"%s\"\n" , modelicaLine , strtmp );
461- free (strtmp );
462- #else /* real OSes */
463472 fprintf (file ,"#line %ld \"%s\"\n" , modelicaLine , modelicaFileName );
464- #endif
465473 fprintf (file ,"%s\n" , str );
466474 nlines += 2 ;
467475 } else {
@@ -470,6 +478,11 @@ static int PrintImpl__writeBufConvertLines(const char *filename)
470478 }
471479 str = next ;
472480 } while (1 );
481+ #if defined(__MINGW32__ ) || defined(_MSC_VER )
482+ if (modelicaFileName ) {
483+ free (modelicaFileName );
484+ }
485+ #endif
473486 /* We do destructive updates on the print buffer; hide our tracks */
474487 * buf = 0 ;
475488 nfilled = 0 ;
0 commit comments