Commits

Oleg Oshmyan committed ae6da08

Corrected conditional compilation on Win32

  • Participants
  • Parent commits 877ea5c

Comments (0)

Files changed (7)

File src/AtomicParsley.h

                                                                    */
 //==================================================================//
 
+#ifdef _WIN32
+#define _UNICODE
 #if defined (_MSC_VER)
-#define _UNICODE
 #define strncasecmp _strnicmp
 #endif
+#endif
 
 #include "config.h"
 

File src/main.cpp

 
 static const char* fileLevelHelp_text =
 "AtomicParsley help page for general & file level options.\n"
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 "  Note: you can change the input/output behavior to raw 8-bit utf8 if the program name\n"
 "        is appended with \"-utf8\". AtomicParsley-utf8.exe will have problems with files/\n"
 "        folders with unicode characters in given paths.\n"
 "  rewrite of the original file. Another case where a full rewrite will occur is when the original file\n"
 "  is not optimized and has 'mdat' preceding 'moov'.\n"
 "\n"
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 "Examples:\n"
 "   c:> SET AP_PADDING=\"DEFAULT_PAD=0\"      or    c:> SET AP_PADDING=\"DEFAULT_PAD=3128\"\n"
 "   c:> SET AP_PADDING=\"DEFAULT_PAD=5128:MIN_PAD=200:MAX_PAD=6049\"\n"
 " is to preserve it - if it is present at all. You can choose to eliminate it by setting the environ-\n"
 " mental preference for AP_PADDING to have DEFAULT_PAD=0\n"
 "\n"
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 "Example:\n"
 "   c:> SET AP_PADDING=\"DEFAULT_PAD=0\"\n"
 #else
 			fprintf(stdout, "%s\n", shortHelp_text); exit(0);
 
 		} else if ( (strncmp(argv[1],"--longhelp", 10) == 0) || (strncmp(argv[1],"-longhelp", 9) == 0) || (strncmp(argv[1],"-Lh", 3) == 0) ) {
+#if defined (_WIN32)
 			if (UnicodeOutputStatus == WIN32_UTF16) { //convert the helptext to utf16 to preserve � characters
 				int help_len = strlen(longHelp_text)+1;
 				wchar_t* Lhelp_text = (wchar_t *)malloc(sizeof(wchar_t)*help_len);
 				wmemset(Lhelp_text, 0, help_len);
 				UTF8ToUTF16LE((unsigned char*)Lhelp_text, 2*help_len, (unsigned char*)longHelp_text, help_len);
-#if defined (_MSC_VER)
 				APar_unicode_win32Printout(Lhelp_text, (char *) longHelp_text);
-#endif
 				free(Lhelp_text);
 			} else {
+#endif
 				fprintf(stdout, "%s", longHelp_text);
+#if defined (_WIN32)
 			}
+#endif
 			exit(0);
 
 		} else if ( (strncmp(argv[1],"--3gp-help", 10) == 0) || (strncmp(argv[1],"-3gp-help", 9) == 0) || (strncmp(argv[1],"--3gp-h", 7) == 0) ) {
 	return 0;
 }
 
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 
 int wmain( int argc, wchar_t *arguments[])
 {
 	return return_val;
 }
 
+#ifdef __MINGW32__
+
+int main()
+{
+	int argc;
+	wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc);
+	return wmain(argc, argv);
+}
+
+#endif
+
 #else
 
 int main( int argc, char *argv[])

File src/metalist.cpp

 void printBOM() {
 	if (BOM_printed) return;
 	
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 	if (UnicodeOutputStatus == WIN32_UTF16) {
 		APar_unicode_win32Printout(L"\xEF\xBB\xBF", "\xEF\xBB\xBF");
 	}
 	return;
 }
 
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 void APar_unicode_win32Printout(wchar_t* unicode_out, char* utf8_out) { //based on http://blogs.msdn.com/junfeng/archive/2004/02/25/79621.aspx
 	//its possible that this isn't even available on windows95
 	DWORD dwBytesWritten;
 #endif
 
 void APar_fprintf_UTF8_data(const char* utf8_encoded_data) {
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 	if (GetVersion() & 0x80000000 || UnicodeOutputStatus == UNIVERSAL_UTF8) {
 		fprintf(stdout, "%s", utf8_encoded_data); //just printout the raw utf8 bytes (not characters) under pre-NT windows
 	} else {
 		}
 		unsigned char* utf8_data = Convert_multibyteUTF16_to_UTF8(unicode_string, asset_length * 6, asset_length);
 
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 		if (GetVersion() & 0x80000000 || UnicodeOutputStatus == UNIVERSAL_UTF8) { //pre-NT or AP-utf8.exe (pish, thats my win98se, and without unicows support convert utf16toutf8 and output raw bytes)
 			unsigned char* utf8_data = Convert_multibyteUTF16_to_UTF8(unicode_string, asset_length * 6, asset_length-14);
 			fprintf(stdout, "%s", utf8_data);
 		
 		unsigned char* utf8_data = Convert_multibyteUTF16_to_UTF8(unicode_string, (asset_length-13) * 6, asset_length-14);
 
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 		if (GetVersion() & 0x80000000 || UnicodeOutputStatus == UNIVERSAL_UTF8) { //pre-NT or AP-utf8.exe (pish, thats my win98se, and without unicows support convert utf16toutf8 and output raw bytes)
 			unsigned char* utf8_data = Convert_multibyteUTF16_to_UTF8(unicode_string, (asset_length -13) * 6, asset_length-14);
 			fprintf(stdout, "%s", utf8_data);

File src/parsley.cpp

 
 void ShowVersionInfo() {
 
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 	char unicode_enabled[12];
 	memset(unicode_enabled, 0, 12);
 	if (UnicodeOutputStatus == WIN32_UTF16) {
 		if (parsedAtoms[iter].AtomicLength > file_size && file_size > 300000) {
 			if (parsedAtoms[iter].AtomicData == NULL) {
 				fprintf(stderr, "AtomicParsley error: an atom was detected that presents as larger than filesize. Aborting. %c\n", '\a');
-#if defined (_MSC_VER) /* apparently, long long is forbidden there*/
+#if defined (_WIN32) /* apparently, long long is forbidden there*/
 				fprintf(stderr, "atom %s is %I64u\n bytes long which is greater than the filesize of %I64u\n", parsedAtoms[iter].AtomicName, parsedAtoms[iter].AtomicLength, file_size);
 #else
 				fprintf(stderr, "atom %s is %" PRIu64 " bytes long which is greater than the filesize of %" PRIu64 "\n", parsedAtoms[iter].AtomicName, parsedAtoms[iter].AtomicLength, file_size);
 		memcpy(temp_path + base_len, file_kind, strlen(file_kind));
 
 	} else if (output_type == -1) { //make the output file invisible by prefacing the filename with '.'
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 		memcpy(temp_path, filePath, base_len);
 		memcpy(temp_path + base_len, file_kind, strlen(file_kind));
 #else
 			APar_readX(buffer, src_file, file_pos, max_buffer);
 
 			//fseek(dest_file, dest_position + file_pos, SEEK_SET);
-#if defined(_MSC_VER)
+#if defined(_WIN32)
 			fpos_t file_offset = dest_position + file_pos;
 #elif defined(__GLIBC__)
       fpos_t file_offset = {0};
 		} else {
 			APar_readX(buffer, src_file, file_pos, src_file_size - file_pos);
 			//fprintf(stdout, "buff starts with %s\n", buffer+4);
-#if defined(_MSC_VER)
+#if defined(_WIN32)
 			fpos_t file_offset = dest_position + file_pos;
 #elif defined(__GLIBC__)
       fpos_t file_offset = {0};
 		}
 	}
 	if (dynUpd.optimization_flags & MEDIADATA__PRECEDES__MOOV) {
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 		fflush(dest_file);
 		SetEndOfFile((HANDLE)_get_osfhandle(_fileno(dest_file)));
 #else
 	if (dynUpd.updage_by_padding) {
 		APar_DeriveNewPath(ISObasemediafile, temp_file_name, 0, "-data-", NULL); //APar_DeriveNewPath(ISObasemediafile, temp_file_name, -1, "-data-", NULL);
 		temp_file = APar_OpenFile(temp_file_name, "wb");
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 		char* invisi_command=(char*)malloc(sizeof(char)*2*MAXPATHLEN);
 		sprintf (invisi_command,"ATTRIB +S +H \"%s\"",temp_file_name);
 
 	} else if (rewrite_original && !outfile) { //disable overWrite when writing out to a specifically named file; presumably the enumerated output file was meant to be the final destination
 		fclose(source_file);
 
+#if defined (_WIN32) /* native Windows requires removing the file first; rename() on POSIX does the removing automatically as needed */
 		if ( IsUnicodeWinOS() && UnicodeOutputStatus == WIN32_UTF16) {
-#if defined (_MSC_VER) /* native windows seems to require removing the file first; rename() on Mac OS X does the removing automatically as needed */
 			wchar_t* utf16_filepath = Convert_multibyteUTF8_to_wchar(ISObasemediafile);
 
 			_wremove(utf16_filepath);
 
 			free(utf16_filepath);
 			utf16_filepath = NULL;
+		} else {
 #endif
-		} else {
 			remove(ISObasemediafile);
+#if defined (_WIN32)
 		}
+#endif
 
 		int err = 0;
 
 			originating_file = (char*)ISObasemediafile;
 		}
 
+#if defined (_WIN32)
 		if ( IsUnicodeWinOS() && UnicodeOutputStatus == WIN32_UTF16) {
-#if defined (_MSC_VER)
 			wchar_t* utf16_filepath = Convert_multibyteUTF8_to_wchar(originating_file);
 			wchar_t* temp_utf16_filepath = Convert_multibyteUTF8_to_wchar(temp_file_name);
 
 			free(temp_utf16_filepath);
 			utf16_filepath = NULL;
 			temp_utf16_filepath = NULL;
+		} else {
 #endif
-		} else {
 			err = rename(temp_file_name, originating_file);
+#if defined (_WIN32)
 		}
+#endif
 
 		if (err != 0) {
 			switch (errno) {

File src/util.cpp

 		(native-endian) filepath & pass that to a wide stat. Or stat it with a utf8 filepath on Unixen & win32 (stripped utf8).
 ----------------------*/
 off_t findFileSize(const char *utf8_filepath) {
+#if defined (_WIN32)
 	if ( IsUnicodeWinOS() && UnicodeOutputStatus == WIN32_UTF16) {
-#if defined (_MSC_VER)
 		wchar_t* utf16_filepath = Convert_multibyteUTF8_to_wchar(utf8_filepath);
 		
 		struct _stat fileStats;
 		free(utf16_filepath);
 		utf16_filepath = NULL;
 		return fileStats.st_size;
+	} else {
 #endif
-	} else {
 		struct stat fileStats;
 		stat(utf8_filepath, &fileStats);
 		return fileStats.st_size;
+#if defined (_WIN32)
 	}
+#endif
 	return 0; //won't ever get here.... unless this is win32, set to utf8 and the folder/file had unicode.... TODO (? use isUTF8() for high ascii?)
 }
 
 ----------------------*/
 FILE* APar_OpenFile(const char* utf8_filepath, const char* file_flags) {
 	FILE* aFile = NULL;
+#if defined (_WIN32)
 	if ( IsUnicodeWinOS() && UnicodeOutputStatus == WIN32_UTF16) {
-#if defined (_MSC_VER)
 		wchar_t* Lfile_flags = (wchar_t *)malloc(sizeof(wchar_t)*4);
 		memset(Lfile_flags, 0, sizeof(wchar_t)*4);
 		mbstowcs(Lfile_flags, file_flags, strlen(file_flags) );
 		free(Lfile_flags); Lfile_flags=NULL;
 		free(utf16_filepath);
 		utf16_filepath = NULL;
+	} else {
 #endif
-	} else {
 		aFile = fopen(utf8_filepath, file_flags);
+#if defined (_WIN32)
 	}
+#endif
 	
 	if (!aFile) {
 		fprintf(stdout, "AP error trying to fopen %s: %s\n", utf8_filepath, strerror(errno));
 }
 
 
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 
 ///////////////////////////////////////////////////////////////////////////////////////
 //                                Win32 functions                                    //
 
 // http://www.flipcode.com/articles/article_advstrings01.shtml
 bool IsUnicodeWinOS() {
-#if defined (_MSC_VER)
+#if defined (_WIN32)
   OSVERSIONINFOW		os;
   memset(&os, 0, sizeof(OSVERSIONINFOW));
   os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW);
 FILE* APar_OpenISOBaseMediaFile(const char* file, bool open); //openSomeFile
 void TestFileExistence(const char *filePath, bool errorOut);
 
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 int fseeko(FILE *stream, uint64_t pos, int whence);
 #endif
 bool IsUnicodeWinOS();

File src/uuid.cpp

 	char *uuid_str, *end_uuid_str, *uuid_byte;
 	uint8_t uuid_pos, uuid_len;
 	uint8_t keeprap = 0;
-#if defined (_MSC_VER)
+#if defined (_WIN32)
 	char *raw_uuid = _strdup(raw_uuid_in);
 #else
 	char *raw_uuid = strdup(raw_uuid_in);