]> git.cworth.org Git - apitrace/blobdiff - trace_parser.cpp
Catch exceptions on Windows.
[apitrace] / trace_parser.cpp
index da9d8a487c4ccefa1dfdf9c66db86509df528b08..f4073e75282b3dd2777891ee74635e03e70d7fb1 100644 (file)
@@ -28,8 +28,7 @@
 #include <assert.h>
 #include <stdlib.h>
 
-#include <zlib.h>
-
+#include "trace_file.hpp"
 #include "trace_parser.hpp"
 
 
@@ -52,8 +51,14 @@ Parser::~Parser() {
 
 
 bool Parser::open(const char *filename) {
-    file = gzopen(filename, "rb");
-    if (!file) {
+    assert(!file);
+    if (File::isZLibCompressed(filename)) {
+        file = new ZLibFile;
+    } else {
+        file = new SnappyFile;
+    }
+
+    if (!file->open(filename, File::Read)) {
         return false;
     }
 
@@ -85,7 +90,8 @@ deleteAll(const Container &c)
 
 void Parser::close(void) {
     if (file) {
-        gzclose(file);
+        file->close();
+        delete file;
         file = NULL;
     }
 
@@ -140,6 +146,7 @@ void Parser::parse_enter(void) {
     FunctionSig *sig = lookup(functions, id);
     if (!sig) {
         sig = new FunctionSig;
+        sig->id = id;
         sig->name = read_string();
         sig->num_args = read_uint();
         const char **arg_names = new const char *[sig->num_args];
@@ -198,7 +205,8 @@ bool Parser::parse_call_details(Call *call) {
             call->ret = parse_value();
             break;
         default:
-            std::cerr << "error: unknown call detail " << c << "\n";
+            std::cerr << "error: ("<<call->name()<< ") unknown call detail "
+                      << c << "\n";
             exit(1);
         case -1:
             return false;
@@ -292,14 +300,14 @@ Value *Parser::parse_uint() {
 
 Value *Parser::parse_float() {
     float value;
-    gzread(file, &value, sizeof value);
+    file->read(&value, sizeof value);
     return new Float(value);
 }
 
 
 Value *Parser::parse_double() {
     double value;
-    gzread(file, &value, sizeof value);
+    file->read(&value, sizeof value);
     return new Float(value);
 }
 
@@ -330,19 +338,18 @@ Value *Parser::parse_bitmask() {
     size_t id = read_uint();
     BitmaskSig *sig = lookup(bitmasks, id);
     if (!sig) {
-        size_t count = read_uint();
-        BitmaskVal *values = new BitmaskVal[count];
-        for (BitmaskVal *it = values; it != values + count; ++it) {
+        sig = new BitmaskSig;
+        sig->id = id;
+        sig->num_flags = read_uint();
+        BitmaskFlag *flags = new BitmaskFlag[sig->num_flags];
+        for (BitmaskFlag *it = flags; it != flags + sig->num_flags; ++it) {
             it->name = read_string();
             it->value = read_uint();
-            if (it->value == 0 && it != values) {
+            if (it->value == 0 && it != flags) {
                 std::cerr << "warning: bitmask " << it->name << " is zero but is not first flag\n";
             }
         }
-        sig = new BitmaskSig;
-        sig->id = id;
-        sig->count = count;
-        sig->values = values;
+        sig->flags = flags;
         bitmasks[id] = sig;
     }
     assert(sig);
@@ -367,7 +374,7 @@ Value *Parser::parse_blob(void) {
     size_t size = read_uint();
     Blob *blob = new Blob(size);
     if (size) {
-        gzread(file, blob->buf, (unsigned)size);
+        file->read(blob->buf, (unsigned)size);
     }
     return blob;
 }
@@ -412,7 +419,7 @@ const char * Parser::read_string(void) {
     size_t len = read_uint();
     char * value = new char[len + 1];
     if (len) {
-        gzread(file, value, (unsigned)len);
+        file->read(value, (unsigned)len);
     }
     value[len] = 0;
 #if TRACE_VERBOSE
@@ -427,7 +434,7 @@ unsigned long long Parser::read_uint(void) {
     int c;
     unsigned shift = 0;
     do {
-        c = gzgetc(file);
+        c = file->getc();
         if (c == -1) {
             break;
         }
@@ -442,7 +449,7 @@ unsigned long long Parser::read_uint(void) {
 
 
 inline int Parser::read_byte(void) {
-    int c = gzgetc(file);
+    int c = file->getc();
 #if TRACE_VERBOSE
     if (c < 0)
         std::cerr << "\tEOF" << "\n";