Ignore:
Timestamp:
12/27/14 01:02:21 (9 years ago)
Author:
Maciej Komosinski
Message:

Formatted source

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/virtfile/stringfile.cpp

    r247 r282  
    99size_t StringFILE::Vread(void *ptr, size_t size, size_t nmemb)
    1010{
    11 int have=(int)(str.len()-pos);
    12 if (have<=0) return 0;
    13 int need=(int)(size*nmemb);
    14 if (need>have) {nmemb=have/size; need=(int)(size*nmemb);}
    15 memcpy(ptr,((const char*)str)+pos,need);
    16 pos+=need;
    17 return nmemb;
     11        int have = (int)(str.len() - pos);
     12        if (have <= 0) return 0;
     13        int need = (int)(size*nmemb);
     14        if (need > have) { nmemb = have / size; need = (int)(size*nmemb); }
     15        memcpy(ptr, ((const char*)str) + pos, need);
     16        pos += need;
     17        return nmemb;
    1818}
    1919
    2020int StringFILE::Vgetc()
    2121{
    22 if (pos >= str.len()) //...i znowu byl bug roku! :O
    23         return EOF;
    24 else
    25         return str.operator[]((int)pos++);
     22        if (pos >= str.len()) //...i znowu byl bug roku! :O
     23                return EOF;
     24        else
     25                return str.operator[]((int)pos++);
    2626}
    2727
    2828char *StringFILE::Vgets(char *s, int size)
    2929{
    30 int have=str.len()-(int)pos;
    31 if (have<=0) return 0;
    32 if (size<0) size=0;
    33 if (have>size) have=size-1;
    34 const char* src=((const char*)str)+pos;
    35 char *dest=s;
    36 while(have-- > 0)
     30        int have = str.len() - (int)pos;
     31        if (have <= 0) return 0;
     32        if (size < 0) size = 0;
     33        if (have > size) have = size - 1;
     34        const char* src = ((const char*)str) + pos;
     35        char *dest = s;
     36        while (have-- > 0)
    3737        {
    38         *(dest++) = *(src++); pos++;
    39         if (dest[-1]=='\n') break;
     38                *(dest++) = *(src++); pos++;
     39                if (dest[-1] == '\n') break;
    4040        }
    41 *dest=0;
    42 return s;
     41        *dest = 0;
     42        return s;
    4343}
    4444
    4545int StringFILE::Vseek(long offset, int whence)
    4646{
    47 switch(whence)
     47        switch (whence)
    4848        {
    49         case SEEK_SET: pos=offset; break;
    50         case SEEK_CUR: pos+=offset; break;
    51         case SEEK_END: pos=str.len()-offset; break;
     49        case SEEK_SET: pos = offset; break;
     50        case SEEK_CUR: pos += offset; break;
     51        case SEEK_END: pos = str.len() - offset; break;
    5252        default: return EINVAL;
    5353        }
    54 if (pos < 0) pos=0; else if (pos>str.len()) pos=str.len();
    55 return 0;
     54        if (pos < 0) pos = 0; else if (pos>str.len()) pos = str.len();
     55        return 0;
    5656}
    5757
    58 const char StringFileSystem::PREFIX[]="string://";
     58const char StringFileSystem::PREFIX[] = "string://";
    5959
    6060bool StringFileSystem::isStringPath(const char* path)
    6161{
    62 return !strncmp(path,PREFIX,sizeof(PREFIX)-1);
     62        return !strncmp(path, PREFIX, sizeof(PREFIX) - 1);
    6363}
    6464
    65 VirtFILE *StringFileSystem::Vfopen(const char* path,const char*mode)
     65VirtFILE *StringFileSystem::Vfopen(const char* path, const char*mode)
    6666{
    67 if ((*mode=='r') && isStringPath(path))
     67        if ((*mode == 'r') && isStringPath(path))
    6868        {
    69         return new StringFILE2(SString(path+sizeof(PREFIX)-1));
     69                return new StringFILE2(SString(path + sizeof(PREFIX) - 1));
    7070        }
    71 return (chain!=NULL) ? chain->Vfopen(path,mode) : NULL;
     71        return (chain != NULL) ? chain->Vfopen(path, mode) : NULL;
    7272}
    7373
    7474int StringFileSystem::Vfexists(const char* path)
    75 { return (chain!=NULL) ? chain->Vfexists(path) : 0; }
     75{
     76        return (chain != NULL) ? chain->Vfexists(path) : 0;
     77}
    7678
    7779VirtDIR *StringFileSystem::Vopendir(const char* path)
    78 { return (chain!=NULL) ? chain->Vopendir(path) : NULL; }
     80{
     81        return (chain != NULL) ? chain->Vopendir(path) : NULL;
     82}
Note: See TracChangeset for help on using the changeset viewer.