Ignore:
Timestamp:
10/01/21 22:38:58 (2 months ago)
Author:
Maciej Komosinski
Message:

Added debugging messages and a non-VirtFILE implementation of readUntilEOL()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/util-file.cpp

    r1124 r1153  
    1010#include <common/virtfile/virtfile.h>
    1111#endif
     12#ifdef DEBUGGING_READWRITECOMPLETEFILE
     13#include <common/dirs.h>
     14#endif
    1215
    1316bool readCompleteFile(const char* filename, vector<char>& data, bool warn_on_missing_file)
     
    1518        bool ok = false;
    1619#ifdef USE_VIRTFILE
     20#ifdef DEBUGGING_READWRITECOMPLETEFILE
     21        logPrintf("","readCompleteFile",LOG_DEBUG,"virtfile: '%s'",filename);
     22#endif 
    1723//      if (!isAbsolutePath(filename))
    1824        {
     
    3036#endif
    3137        {
     38#ifdef DEBUGGING_READWRITECOMPLETEFILE
     39        if (isAbsolutePath(filename))
     40                logPrintf("","readCompleteFile",LOG_DEBUG,"mfopen absolute path: '%s'",filename);
     41        else
     42                logPrintf("","readCompleteFile",LOG_DEBUG,"mfopen: '%s' in current dir: '%s'",filename,getCurrentDirectory().c_str());
     43#endif 
    3244                MFILE *f = mfopen(filename, FOPEN_READ_BINARY);
     45#ifdef DEBUGGING_READWRITECOMPLETEFILE
     46        logPrintf("", "readCompleteFile", LOG_DEBUG, "mfopen status: %s", f?"ok":"fail");
     47#endif
    3348                if (f)
    3449                {
     
    4156        }
    4257        if (warn_on_missing_file && !ok)
    43                 logPrintf("stl-util", "readCompleteFile", LOG_WARN, "Couldn't open file '%s'", filename);
     58                logPrintf("", "readCompleteFile", LOG_WARN, "Couldn't open file '%s'", filename);
     59#ifdef DEBUGGING_READWRITECOMPLETEFILE
     60        logPrintf("", "readCompleteFile", LOG_DEBUG, "bytes:%d status: %s", data.size(), ok?"ok":"fail");
     61#endif
    4462        return ok;
    4563}
     
    5977{
    6078#ifdef USE_VIRTFILE
     79#ifdef DEBUGGING_READWRITECOMPLETEFILE
     80        logPrintf("","writeCompleteFile",LOG_DEBUG,"virtfile: '%s'",filename);
     81#endif 
    6182        VirtFILE *f = Vfopen(filename, FOPEN_WRITE_BINARY);
    6283        bool ok = f != NULL;
     
    6889        }
    6990#else
     91#ifdef DEBUGGING_READWRITECOMPLETEFILE
     92        if (isAbsolutePath(filename))
     93                logPrintf("","writeCompleteFile",LOG_DEBUG,"mfopen absolute path: '%s'",filename);
     94        else
     95                logPrintf("","writeCompleteFile",LOG_DEBUG,"mfopen: '%s' in current dir: '%s'",filename,getCurrentDirectory().c_str());
     96#endif
    7097        MFILE *f = mfopen(filename, FOPEN_WRITE_BINARY);
    7198        bool ok = f != NULL;
     99#ifdef DEBUGGING_READWRITECOMPLETEFILE
     100        logPrintf("", "writeCompleteFile", LOG_DEBUG, "mfopen status: %s", ok?"ok":"fail");
     101#endif
    72102        if (f)
    73103        {
     
    78108#endif
    79109        if (warn_on_fail && !ok)
    80                 logPrintf("stl-util", "writeCompleteFile", LOG_WARN, "Couldn't write file '%s'", filename);
     110                logPrintf("", "writeCompleteFile", LOG_WARN, "Couldn't write file '%s'", filename);
     111#ifdef DEBUGGING_READWRITECOMPLETEFILE
     112        logPrintf("", "writeCompleteFile", LOG_DEBUG, "status: %s", ok?"ok":"fail");
     113#endif
    81114        return ok;
    82115}
     
    89122
    90123// Just like fgets(), but string length is unlimited and does not store trailing \r \n
     124#ifdef USE_VIRTFILE
    91125string readUntilEOL(VirtFILE *f)
     126#else
     127string readUntilEOL(FILE *f)
     128#endif
    92129{
    93130        char buf[100];
     
    95132        std::string ret;
    96133        bool endofline;
    97         while ((line = f->Vgets(buf, sizeof(buf))))
     134        while ((line =
     135#ifdef USE_VIRTFILE
     136            f->Vgets(buf, sizeof(buf))
     137#else
     138            fgets(buf, sizeof(buf), f)
     139#endif
     140            ))
    98141        {
    99142                char* end = line + strlen(line);
Note: See TracChangeset for help on using the changeset viewer.