diff options
Diffstat (limited to 'app/bin/fileio.c')
| -rw-r--r-- | app/bin/fileio.c | 99 | 
1 files changed, 20 insertions, 79 deletions
diff --git a/app/bin/fileio.c b/app/bin/fileio.c index 4741c05..8695c5a 100644 --- a/app/bin/fileio.c +++ b/app/bin/fileio.c @@ -39,6 +39,7 @@  #include "include/paramfile.h"  #include "include/paramfilelist.h"  #include "paths.h" +#include "include/stringxtc.h"  #include "track.h"  #include "version.h"  #include "dynstring.h" @@ -49,8 +50,6 @@  #include "include/utf8convert.h"  #endif // UTFCONVERT -EXPORT dynArr_t paramProc_da; -  #define COPYBLOCKSIZE	1024  EXPORT const char * workingDir; @@ -61,8 +60,8 @@ static coOrd paste_offset, cursor_offset;  EXPORT wBool_t bExample = FALSE;  EXPORT wBool_t bReadOnly = FALSE; -EXPORT wBool_t bInReadTracks = FALSE; +static int log_timereadfile = 0;  #ifdef WINDOWS  #define rename( F1, F2 ) Copyfile( F1, F2 ) @@ -89,52 +88,6 @@ EXPORT int Copyfile( const char * fn1, const char * fn2 )  	return 0;  } -// -// Locale handling -// SetCLocale is called before reading/writing any data files (.xtc, .xti, .xtq, .cus...) -// SetUserLocale is called after -// Calls can be nested: C, C, User, User -// -static char * sUserLocale = NULL;	// current user locale -static long lCLocale = 0;		// locale state: > 0 C locale, <= 0 user locale -static long nCLocale = 0;		// total # of setlocals calls -static int log_locale = 0;		// logging -static int log_timereadfile = 0; - -EXPORT void SetCLocale() -{ -	if ( sUserLocale == NULL ) { -		sUserLocale = MyStrdup( setlocale( LC_ALL, NULL ) ); -	} -	if ( lCLocale == 0 ) { -		LOG( log_locale, 1, ( "Set C Locale: %ld\n", ++nCLocale ) ); -		setlocale(  LC_ALL, "C" ); -#ifdef LC_MESSAGES -		setlocale( LC_MESSAGES, ""); -#endif -	} -	lCLocale++; -	if ( lCLocale > 1 ) { -		LOG( log_locale, 3, ( "SetClocale - C! %ld\n", nCLocale) ); -	} else if ( lCLocale < 1 ) { -		LOG( log_locale, 2, ( "SetClocale - User! %ld\n", nCLocale) ); -	} -} - -EXPORT void SetUserLocale() -{ -	if ( lCLocale == 1 ) { -		LOG( log_locale, 1, ( "Set %s Locale: %ld\n", sUserLocale, ++nCLocale ) ); -		setlocale( LC_ALL, sUserLocale ); -	} -	lCLocale--; -	if ( lCLocale < 0 ) { -		LOG( log_locale, 2, ("SetUserLocale - User! %ld\n", nCLocale) ); -	} else if ( lCLocale > 0 ) { -		LOG( log_locale, 3, ("SetUserLocale - C! %ld\n", nCLocale) ); -	} -} -  /****************************************************************************   * @@ -151,23 +104,8 @@ EXPORT char * curSubContents;  #define PARAM_DEMO (-1) -dynArr_t paramProc_da; +EXPORT dynArr_t paramProc_da; -EXPORT void Stripcr( char * line ) -{ -	char * cp; -	cp = line + strlen(line); -	if (cp == line) { -		return; -	} -	cp--; -	if (*cp == '\n') { -		*cp-- = '\0'; -	} -	if (cp >= line && *cp == '\r') { -		*cp = '\0'; -	} -}  EXPORT char * GetNextLine( void )  { @@ -274,7 +212,7 @@ EXPORT void SyntaxError(  EXPORT BOOL_T GetArgs(          char * line, -        char * format, +        const char * format,          ... )  {  	char * cp, * cq; @@ -288,10 +226,6 @@ EXPORT BOOL_T GetArgs(  	va_list ap;  	char * sError = NULL; -	if ( lCLocale < 1 ) { -		LOG( log_locale, 1, ( "GetArgs: not in C locale\n" ) ); -	} -  	cp = line;  	va_start( ap, format );  	for ( ; sError==NULL && *format; format++ ) { @@ -680,7 +614,7 @@ static BOOL_T ReadTrackFile(  		return FALSE;  	} -	bInReadTracks = TRUE; +	ParamSetInReadTracks(TRUE);  	SetCLocale();  	checkPtFileNameBackup = NULL;  	paramLineNum = 0; @@ -790,7 +724,7 @@ static BOOL_T ReadTrackFile(  		}  	} -	bInReadTracks = FALSE; +	ParamSetInReadTracks(FALSE);  	if (paramFile) {  		fclose(paramFile);  		paramFile = NULL; @@ -889,8 +823,7 @@ int LoadTracks(  				fseek(f, 0, SEEK_SET);  				manifest = malloc(length + 1);  				if (manifest) { -					fread(manifest, 1, length, f); -					manifest[length] = '\0'; +					manifest[ fread(manifest, 1, length, f) ] = '\0';  				}  				fclose(f);  			} else { @@ -971,7 +904,6 @@ int LoadTracks(  		RecomputeElevations(NULL);  		AttachTrains();  		DoChangeNotification( CHANGE_ALL ); -		DoUpdateTitles();  		LayerSetCounts();  	} @@ -1511,7 +1443,6 @@ EXPORT int LoadCheckpoint( BOOL_T sameName )  		RecomputeElevations(NULL);  		AttachTrains();  		DoChangeNotification( CHANGE_ALL ); -		DoUpdateTitles();  	} else { SetLayoutFullPath(""); } @@ -1593,9 +1524,8 @@ static int ImportTracks(  	return TRUE;  } -EXPORT void DoImport( void * type ) +static void DoImport( void * type )  { -	importAsModule = (int)VP2L(type);  	if (importFile_fs == NULL)  		importFile_fs = wFilSelCreate( mainW, FS_LOAD, 0,  		                               type == 0 ? _("Import Tracks") : _("Import Module"), @@ -1604,6 +1534,17 @@ EXPORT void DoImport( void * type )  	wFilSelect( importFile_fs, GetCurrentPath(LAYOUTPATHKEY));  } +EXPORT void DoImportObjects( void * unused ) +{ +	importAsModule = FALSE; +	DoImport( unused ); +} + +EXPORT void DoImportModule( void * unused ) +{ +	importAsModule = TRUE; +	DoImport( unused ); +}  /**   * Export the selected track pieces @@ -1800,7 +1741,7 @@ EXPORT void FileInit( void )  	SetLayoutFullPath("");  	MakeFullpath(&clipBoardN, workingDir, sClipboardF, NULL); +	LocaleInit(); -	log_locale = LogFindIndex( "locale" );  	log_timereadfile = LogFindIndex( "timereadfile" );  }  | 
