Wez Furlong avatar Wez Furlong committed 094ad12

more code cleanup

Comments (0)

Files changed (3)

src/AtomicParsley.h

                                                                    */
 //==================================================================//
 
+#if defined (_MSC_VER)
+#define _UNICODE
+#define strncasecmp strnicmp
+#endif
+
 #include "config.h"
 
 #define __STDC_LIMIT_MACROS
 # define MAXPATHLEN
 #endif
 
-#if defined (_MSC_VER)
-#define _UNICODE
-#define strncasecmp strnicmp
-#endif
-
 #include "util.h"
 
 #define MAX_ATOMS 1024
 #define MAXDATA_PAYLOAD 1256
-
 #define DEFAULT_PADDING_LENGTH          2048;
 #define MINIMUM_REQUIRED_PADDING_LENGTH 0;
 #define MAXIMUM_REQUIRED_PADDING_LENGTH 5000;
 void APar_FreeMemory();
 
 short APar_FindParentAtom(int order_in_tree, uint8_t this_atom_level);
-AtomicInfo* APar_FindAtomInTrack(uint8_t &total_tracks, uint8_t &track_num, char* search_atom_str);
-AtomicInfo* APar_FindAtom(const char* atom_name, bool createMissing, uint8_t atom_type, uint16_t atom_lang,
-                                                 bool match_full_uuids = false, const char* reverseDNSdomain = NULL);
 
-int APar_MatchToKnownAtom(const char* atom_name, const char* atom_container, bool fromFile, const char* find_atom_path);
+AtomicInfo* APar_FindAtomInTrack(uint8_t &total_tracks, uint8_t &track_num,
+  char* search_atom_str);
+
+AtomicInfo* APar_FindAtom(const char* atom_name, bool createMissing,
+  uint8_t atom_type, uint16_t atom_lang, bool match_full_uuids = false,
+  const char* reverseDNSdomain = NULL);
+
+int APar_MatchToKnownAtom(const char* atom_name, const char* atom_container,
+  bool fromFile, const char* find_atom_path);
+
 void APar_ScanAtoms(const char *path, bool deepscan_REQ = false);
 void APar_IdentifyBrand(char* file_brand);
 
-AtomicInfo* APar_CreateSparseAtom(AtomicInfo* surrogate_atom, AtomicInfo* parent_atom, short preceding_atom);
-void APar_Unified_atom_Put(AtomicInfo* target_atom, const char* unicode_data, uint8_t text_tag_style, uint64_t ancillary_data, uint8_t anc_bit_width);
-void APar_atom_Binary_Put(AtomicInfo* target_atom, const char* binary_data, uint32_t bytecount, uint64_t atomic_data_offset);
+AtomicInfo* APar_CreateSparseAtom(AtomicInfo* surrogate_atom,
+  AtomicInfo* parent_atom, short preceding_atom);
+
+void APar_Unified_atom_Put(AtomicInfo* target_atom, const char* unicode_data,
+  uint8_t text_tag_style, uint64_t ancillary_data, uint8_t anc_bit_width);
+
+void APar_atom_Binary_Put(AtomicInfo* target_atom, const char* binary_data,
+  uint32_t bytecount, uint64_t atomic_data_offset);
 
 /* iTunes-style metadata */
-void APar_MetaData_atomArtwork_Set(const char* artworkPath, char* env_PicOptions);
+void APar_MetaData_atomArtwork_Set(const char* artworkPath,
+  char* env_PicOptions);
+
 void APar_MetaData_atomGenre_Set(const char* atomPayload);
-void APar_MetaData_atom_QuickInit(short atom_num, const uint32_t atomFlags, uint32_t supplemental_length, uint32_t allotment = MAXDATA_PAYLOAD + 1);
-AtomicInfo* APar_MetaData_atom_Init(const char* atom_path, const char* MD_Payload, const uint32_t atomFlags);
+void APar_MetaData_atom_QuickInit(short atom_num, const uint32_t atomFlags,
+  uint32_t supplemental_length, uint32_t allotment = MAXDATA_PAYLOAD + 1);
 
-AtomicInfo* APar_reverseDNS_atom_Init(const char* rDNS_atom_name, const char* rDNS_payload, const uint32_t* atomFlags, const char* rDNS_domain);
+AtomicInfo* APar_MetaData_atom_Init(const char* atom_path,
+  const char* MD_Payload, const uint32_t atomFlags);
 
-/* uuid user extension metadata; made to look much like iTunes-style metadata with a 4byte NULL */
-AtomicInfo* APar_uuid_atom_Init(const char* atom_path, const char* uuidName, const uint32_t dataType, const char* uuidValue, bool shellAtom);
+AtomicInfo* APar_reverseDNS_atom_Init(const char* rDNS_atom_name,
+  const char* rDNS_payload, const uint32_t* atomFlags, const char* rDNS_domain);
 
-uint16_t APar_TestVideoDescription(AtomicInfo* video_desc_atom, FILE* ISObmff_file); //test whether the ipod uuid can be added for a video track
+/* uuid user extension metadata; made to look much like iTunes-style metadata
+ * with a 4byte NULL */
+AtomicInfo* APar_uuid_atom_Init(const char* atom_path, const char* uuidName,
+  const uint32_t dataType, const char* uuidValue, bool shellAtom);
+
+//test whether the ipod uuid can be added for a video track
+uint16_t APar_TestVideoDescription(AtomicInfo* video_desc_atom,
+  FILE* ISObmff_file);
+
 void APar_Generate_iPod_uuid(char* atom_path);
 
 /* 3GP-style metadata */
-uint32_t APar_3GP_Keyword_atom_Format(char* keywords_globbed, uint8_t keyword_count, bool set_UTF16_text, char* &formed_keyword_struct);
-AtomicInfo* APar_UserData_atom_Init(const char* userdata_atom_name, const char* atom_payload, uint8_t udta_container, uint8_t track_idx, uint16_t userdata_lang);
+uint32_t APar_3GP_Keyword_atom_Format(char* keywords_globbed,
+  uint8_t keyword_count, bool set_UTF16_text, char* &formed_keyword_struct);
+
+AtomicInfo* APar_UserData_atom_Init(const char* userdata_atom_name,
+  const char* atom_payload, uint8_t udta_container, uint8_t track_idx,
+  uint16_t userdata_lang);
 
 /* ID3v2 (2.4) style metadata, non-external form */
-AtomicInfo* APar_ID32_atom_Init(const char* frameID_str, char meta_area, const char* lang_str, uint16_t id32_lang);
+AtomicInfo* APar_ID32_atom_Init(const char* frameID_str, char meta_area,
+  const char* lang_str, uint16_t id32_lang);
 
-void APar_RemoveAtom(const char* atom_path, uint8_t atom_type, uint16_t UD_lang, const char* rDNS_domain = NULL);
+void APar_RemoveAtom(const char* atom_path, uint8_t atom_type,
+  uint16_t UD_lang, const char* rDNS_domain = NULL);
+
 void APar_freefree(int purge_level);
 
 void APar_MetadataFileDump(const char* ISObasemediafile);
 
 void APar_Optimize(bool mdat_test_only);
 void APar_DetermineAtomLengths();
-void APar_WriteFile(const char* ISObasemediafile, const char* outfile, bool rewrite_original);
+void APar_WriteFile(const char* ISObasemediafile, const char* outfile,
+  bool rewrite_original);
 
-#if defined (WIN32)
-bool APar_win32_zlib_LoadLibrary();
-void APar_win32_zlib_FreeLibrary();
-#endif
+void APar_zlib_inflate(char* in_buffer, uint32_t in_buf_len,
+  char* out_buffer, uint32_t out_buf_len);
 
-void APar_zlib_inflate(char* in_buffer, uint32_t in_buf_len, char* out_buffer, uint32_t out_buf_len);
-
-uint32_t APar_zlib_deflate(char* in_buffer, uint32_t in_buf_len, char* out_buffer, uint32_t out_buf_len);
+uint32_t APar_zlib_deflate(char* in_buffer, uint32_t in_buf_len,
+  char* out_buffer, uint32_t out_buf_len);
 
 
 void APar_print_uuid(ap_uuid_t* uuid, bool new_line = true);
    digest.  */
 extern void *sha1_buffer (const char *buffer, size_t len, void *resblock);
 
-int isolat1ToUTF8(unsigned char* out, int outlen, const unsigned char* in, int inlen);
-int UTF8Toisolat1(unsigned char* out, int outlen, const unsigned char* in, int inlen);
-int UTF16BEToUTF8(unsigned char* out, int outlen, const unsigned char* inb, int inlenb);
-int UTF8ToUTF16BE(unsigned char* outb, int outlen, const unsigned char* in, int inlen);
-int UTF16LEToUTF8(unsigned char* out, int outlen, const unsigned char* inb, int inlenb);
-int UTF8ToUTF16LE(unsigned char* outb, int outlen, const unsigned char* in, int inlen);
+int isolat1ToUTF8(unsigned char* out, int outlen,
+  const unsigned char* in, int inlen);
+
+int UTF8Toisolat1(unsigned char* out, int outlen,
+  const unsigned char* in, int inlen);
+
+int UTF16BEToUTF8(unsigned char* out, int outlen,
+  const unsigned char* inb, int inlenb);
+
+int UTF8ToUTF16BE(unsigned char* outb, int outlen,
+  const unsigned char* in, int inlen);
+
+int UTF16LEToUTF8(unsigned char* out, int outlen,
+  const unsigned char* inb, int inlenb);
+
+int UTF8ToUTF16LE(unsigned char* outb, int outlen,
+  const unsigned char* in, int inlen);
 
 int isUTF8(const char* in_string);
+
 unsigned int utf8_length(const char *in_string, unsigned int char_limit);
 
-int strip_bogusUTF16toRawUTF8 (unsigned char* out, int inlen, wchar_t* in, int outlen);
+int strip_bogusUTF16toRawUTF8(unsigned char* out, int inlen,
+  wchar_t* in, int outlen);
 
 int test_conforming_alpha_string(char* in_string);
 bool test_limited_ascii(char* in_string, unsigned int str_len);
 void APar_fprintf_UTF8_data(const char* utf8_encoded_data);
 void APar_unicode_win32Printout(wchar_t* unicode_out, char* utf8_out);
 
-void APar_Extract_uuid_binary_file(AtomicInfo* uuid_atom, const char* originating_file, char* output_path);
-void APar_Print_APuuid_atoms(const char *path, char* output_path, uint8_t target_information);
+void APar_Extract_uuid_binary_file(AtomicInfo* uuid_atom,
+  const char* originating_file, char* output_path);
 
-void APar_Print_iTunesData(const char *path, char* output_path, uint8_t supplemental_info, uint8_t target_information, AtomicInfo* ilstAtom = NULL);
+void APar_Print_APuuid_atoms(const char *path, char* output_path,
+  uint8_t target_information);
+
+void APar_Print_iTunesData(const char *path, char* output_path,
+  uint8_t supplemental_info, uint8_t target_information,
+  AtomicInfo* ilstAtom = NULL);
+
 void APar_PrintUserDataAssests(bool quantum_listing = false);
 
-void APar_Extract_ID3v2_file(AtomicInfo* id32_atom, const char* frame_str, const char* originfile, const char* destination_folder, AdjunctArgs* id3args);
+void APar_Extract_ID3v2_file(AtomicInfo* id32_atom, const char* frame_str,
+  const char* originfile, const char* destination_folder, AdjunctArgs* id3args);
+
 void APar_Print_ID3v2_tags(AtomicInfo* id32_atom);
 
 void APar_Print_ISO_UserData_per_track();
-void APar_Mark_UserData_area(uint8_t track_num, short userdata_atom, bool quantum_listing);
+void APar_Mark_UserData_area(uint8_t track_num, short userdata_atom,
+  bool quantum_listing);
 
 //trees
 void APar_PrintAtomicTree();
 void APar_SimpleAtomPrintout();
 
 uint32_t APar_4CC_CreatorCode(const char* filepath, uint32_t new_type_code);
-void APar_SupplySelectiveTypeCreatorCodes(const char *inputPath, const char *outputPath, uint8_t forced_type_code);
+void APar_SupplySelectiveTypeCreatorCodes(const char *inputPath,
+  const char *outputPath, uint8_t forced_type_code);
 
-bool ResizeGivenImage(const char* filePath, PicPrefs myPicPrefs, char* resized_path);
+bool ResizeGivenImage(const char* filePath, PicPrefs myPicPrefs,
+  char* resized_path);
 
 char* GenreIntToString(int genre);
 uint8_t StringGenreToInt(const char* genre_string);
 
 char* ID3GenreIntToString(int genre);
 uint8_t ID3StringGenreToInt(const char* genre_string);
-#endif
+
+#endif /* ATOMIC_PARSLEY_H */
 
 // vim:ts=2:sw=2:et:
 #include "AtomicParsley.h"
 #include <zlib.h>
 
-#if defined (WIN32)
-static bool zlibdll_loaded = 0;
-static HINSTANCE zlib_library;
-
-#define GETPROC(result, name, args)\
-	    typedef result (__cdecl *__PROC__##name) args;\
-		    __PROC__##name name = (__PROC__##name)GetProcAddress (zlib_library, #name);
-
-int (*inflateInit);
-int inflate OF((z_streamp strm, int flush));
-int inflateEnd OF((z_streamp strm));
-int (*deflateInit);
-int deflate OF((z_streamp strm, int flush));
-int deflateEnd(z_streamp strm);
-
-//end global variables
-
-bool APar_win32_zlib_LoadLibrary() {
-	HINSTANCE zlib_lib;
-	if (zlibdll_loaded) return true;
-	
-	zlib_lib = LoadLibrary("zlib1.dll");
-	if (zlib_lib == NULL){
-		fprintf(stdout,"AtomicParsley warning: zlib library missing. Compression is disabled.\n");
-		return false;
-	}
-
-	GETPROC(int, inflateInit, (z_streamp, int));
-	GETPROC(int, inflate, (z_streamp, int));
-	GETPROC(int, inflateEnd, (z_streamp));
-	GETPROC(int, deflateInit, (z_streamp, int));
-	GETPROC(int, deflate, (z_streamp, int));
-	GETPROC(int, deflateEnd, (z_streamp));
-
-	if (inflateInit && inflate && inflateEnd && deflateInit && deflate && deflateEnd) {
-		zlibdll_loaded = true;
-		zlib_library = zlib_lib;
-	} else {
-		fprintf(stdout,"AtomicParsley warning: zlib library addressing failed. Compression is disabled.\n");
-		return false;
-	}
-	return true;
-}
-
-void APar_win32_zlib_FreeLibrary() {
-	if (!zlibdll_loaded) return;
-	FreeLibrary(zlib_library);
-	zlibdll_loaded = false;
-	return;
-}
-
-#endif
-
-static void* zalloc(void *opaque, unsigned int items, unsigned int size) {
+static void* zalloc(void *opaque, unsigned int items, unsigned int size)
+{
 	return calloc(items, size);
 }
 
-static void zfree(void *opaque, void *ptr) {
+static void zfree(void *opaque, void *ptr)
+{
 	free(ptr);
 }
 
 
     fill
 ----------------------*/
-void APar_zlib_inflate(char* in_buffer, uint32_t in_buf_len, char* out_buffer, uint32_t out_buf_len) {
+void APar_zlib_inflate(char* in_buffer, uint32_t in_buf_len,
+	char* out_buffer, uint32_t out_buf_len)
+{
 	z_stream zlib;
 
+	memset(&zlib, 0, sizeof(zlib));
+
 	// Decompress to another buffer
-  zlib.zalloc = zalloc;
-  zlib.zfree = zfree;
+	zlib.zalloc = zalloc;
+	zlib.zfree = zfree;
 	zlib.opaque = NULL;
 	zlib.avail_out = out_buf_len +1;
 	zlib.next_out = (unsigned char*)out_buffer;
 	return ;
 }
 
-uint32_t APar_zlib_deflate(char* in_buffer, uint32_t in_buf_len, char* out_buffer, uint32_t out_buf_len) {
+uint32_t APar_zlib_deflate(char* in_buffer, uint32_t in_buf_len,
+	char* out_buffer, uint32_t out_buf_len)
+{
 	uint32_t compressed_bytes = 0;
-	
 	z_stream zlib;
 
+	memset(&zlib, 0, sizeof(zlib));
+
 	// Compress(default level 6) to another buffer
-  zlib.zalloc = zalloc;
-  zlib.zfree = zfree;
+  	zlib.zalloc = zalloc;
+	zlib.zfree = zfree;
 	zlib.opaque = NULL;
 	zlib.avail_out = out_buf_len +1;
 	zlib.next_out = (unsigned char*)out_buffer;
 	ID32_FRAMEFLAG_LENINDICATED   =  0x0001
 };
 
-// the wording of the ID3 (v2.4 in this case) 'informal standard' is not always replete with clarity.
-// text encodings are worded as having a NULL terminator (8or16bit), even for the body of text frames
-// with that in hand, then a description field from COMM should look much like a utf8 text field
-// and yet for TXXX, description is expressely worded as:
+// the wording of the ID3 (v2.4 in this case) 'informal standard' is not always
+// replete with clarity.  text encodings are worded as having a NULL terminator
+// (8or16bit), even for the body of text frames with that in hand, then a
+// description field from COMM should look much like a utf8 text field and yet
+// for TXXX, description is expressely worded as:
 //
-// "The frame body consists of a description of the string, represented as a terminated string, followed by the actual string."
+// "The frame body consists of a description of the string, represented as a
+// terminated string, followed by the actual string."
+//
 //     Description       <text string according to encoding> $00 (00)
 //     Value             <text string according to encoding>
 //
-// Note how description is expressly *worded* as having a NULL terminator, but the text field is not.
-// GEOB text clarifies things better:
-// "The first two strings [mime & filename] may be omitted, leaving only their terminations.
+// Note how description is expressly *worded* as having a NULL terminator, but
+// the text field is not.  GEOB text clarifies things better: "The first two
+// strings [mime & filename] may be omitted, leaving only their terminations.
+//
 //     MIME type              <text string> $00
 //     Filename               <text string according to encoding> $00 (00)
 //
-// so these trailing $00 (00) are the terminators for the strings - not separators between n-length string fields.
-// If the string is devoid of content (not NULLed out, but *devoid* of info), then the only thing that should exist
-// is for a utf16 BOM to exist on text encoding 0x01. The (required) terminator for mime & filename are specifically
-// enumerated in the frame format, which matches the wording of the frame description.
-// ...and so AP does not terminate text fields
+// so these trailing $00 (00) are the terminators for the strings - not
+// separators between n-length string fields.  If the string is devoid of
+// content (not NULLed out, but *devoid* of info), then the only thing that
+// should exist is for a utf16 BOM to exist on text encoding 0x01. The
+// (required) terminator for mime & filename are specifically enumerated in the
+// frame format, which matches the wording of the frame description.  ...and so
+// AP does not terminate text fields
 //
-// Further sealing the case is the reference implementation for id3v2.3 (id3lib) doesn't terminate text fields:
+// Further sealing the case is the reference implementation for id3v2.3
+// (id3lib) doesn't terminate text fields:
+//
 // http://sourceforge.net/project/showfiles.php?group_id=979&package_id=4679
 
 enum text_encodings {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.