Ejemplo n.º 1
0
bool InitDisplay(int width, int height, int depth) {
  if (!Display) {
    size_t i, j;

    Display = NewRecord(DisplayT);

    for (i = 0; i < 2; i++)
      Display->Bitmap[i] = AllocBitMap(width, height, depth,
                                       BMF_DISPLAYABLE|BMF_CLEAR, NULL);

    Display->Palette = NewRecord(ScreenPaletteT);
    Display->Palette->Count = 256;

    for (i = 0, j = 0; i < 256; i++) {
      Display->Palette->Colors[j++] = i << 24;
      Display->Palette->Colors[j++] = i << 24;
      Display->Palette->Colors[j++] = i << 24;
    }

    ScreenTags[0].ti_Data = width;
    ScreenTags[1].ti_Data = height;
    ScreenTags[2].ti_Data = depth;
    ScreenTags[3].ti_Data = (ULONG)Display->Bitmap[0];
    ScreenTags[4].ti_Data = (ULONG)Display->Palette;

    if ((Display->Screen = OpenScreenTagList(0L, ScreenTags))) {
      return TRUE;
    } else {
      KillDisplay();
    }
  }

  return FALSE;
}
Ejemplo n.º 2
0
/* Add Plucker document */
void AddDocument
    (
    DocumentInfo*   docInfo,
    Char*           volumeLabel
    )
    /* THROWS */
{
    MemHandle   handle;
    UInt8*      dataPtr;
    UInt16      infoSize;
    UInt16      dataSize;
    UInt16      dbIndex;

    infoSize = sizeof *docInfo - 2 * sizeof( UInt16) - sizeof( Char* );
    if ( docInfo->location == RAM )
        dataSize = 0;
    else
        dataSize = StrLen( docInfo->filename ) + StrLen( volumeLabel ) + 2;

    dbIndex = dmMaxRecordIndex;
    handle  = NewRecord( plkrDocList, &dbIndex, infoSize + dataSize );
    THROW_IF( handle == NULL, DmGetLastErr() );
    dataPtr = MemHandleLock( handle );
    DmWrite( dataPtr, 0, docInfo, infoSize );
    if ( docInfo->location != RAM ) {
        DmWrite( dataPtr, infoSize, docInfo->filename,
            StrLen( docInfo->filename ) + 1 );
        DmWrite( dataPtr, infoSize + StrLen( docInfo->filename ) + 1,
            volumeLabel, StrLen( volumeLabel ) + 1 );
    }
    MemHandleUnlock( handle );
    CloseRecord( handle, true );
}
Ejemplo n.º 3
0
/* TODO: Update value if key exists. */
static void AddEntry(HashMapT *self, StrT key, PtrT value, bool ownership) {
  EntryT *entry = GetEntry(self, key);

  if (entry->key) {
    EntryT *next = NewRecord(EntryT);

    *next = *entry;

    entry->next = next;
  } else {
    entry->next = NULL;
  }

  entry->key = StrDup(key);
  entry->value = value;
  entry->ownership = ownership;
}
Ejemplo n.º 4
0
 bool Loop()
 {
    size_t row = 0;
    if (!(IsBOF() && IsEOF())) for (MoveFirst(); !IsEOF(); MoveNext(), row++)
    {
       //TRACE(_T("row %3d\n"), row);
       NewRecord();
       for (int i = 0; i < GetFieldCount(); i++)
       {
          COleVariant var;
    	   GetFieldValue(i, var);
          SaveField(i, var);
       }
       SaveRecord();
    }
    return true;
 }
Ejemplo n.º 5
0
//
// read a single record(row) from the file and format it into
// the provided gstRecord(rec)
//
gstRecordHandle gstTXTTable::Row(uint32 row) {
  if (!Readline(row)) {
    status_ = GST_READ_FAIL;
    return gstRecordHandle();
  }

  char* buff = &row_buffer_[0];
  char* end = &row_buffer_[row_buffer_.size() - 1];

  if (end == NULL) {
    notify(NFY_WARN, "No trailing new line for row: %d", row);
    status_ = GST_READ_FAIL;
    return gstRecordHandle();
  }

  uint field = 0;
  if (file_type_ == Delimited) {
    gstRecordHandle new_rec = NewRecord();
    while (end > buff && isspace(*(end - 1)))
      end--;
    *end = '\0';

    char *pos = &buff[0];

    while (pos < end) {
      if (field == new_rec->NumFields()) {
        notify(NFY_WARN, "Row %d has more fields than specified.", row);
        break;
      }

      // char *stop = end;

      // special case if field begins with double-quotes
      if (*pos == '\"') {
        // crawl along field looking for end double-quotes
        // taking special care to look for a pair of double-quotes,
        // which will be interpreted to mean the double-quote is part of
        // the field
        char tmpbuf[end - pos + 1];
        char* out = &tmpbuf[0];
        ++pos;
        while (pos < end - 1) {
          // normal characters pass through
          if (*pos != '"') {
            *out = *pos;
            out++;
            pos++;
            // a single double quote closes the string,
            // and a pair means take just a single double-quote
          } else {
            if (*(pos + 1) == '"') {
              *out = '"';
              out++;
              pos += 2;
            } else {
              break;
            }
          }
        }

        *out = '\0';
        new_rec->Field(field)->set(reinterpret_cast<char*>(tmpbuf));

        // get past the final closing double-quotes, and delimiter
        pos += 2;
      } else {
        char* stop = static_cast<char*>(memchr(static_cast<void*>(pos),
                                               delimiter_, end - pos));
        if (stop == NULL)
          stop = end;
        new_rec->Field(field)->set(static_cast<char*>(pos),
                                   static_cast<int>(stop - pos));
        pos = stop + 1;
      }

      ++field;
    }
    return new_rec;
  } else if (file_type_ == FixedWidth) {
    gstRecordHandle new_rec = NewRecord();
    gstHeaderHandle hdr = GetHeader();
    char* pos = &buff[0];
    for (uint ii = 0; ii < hdr->numColumns(); ++ii) {
      new_rec->Field(ii)->set(reinterpret_cast<char*>(pos), hdr->length(ii));
      if (hdr->mult(ii) != 0)
        *(new_rec->Field(ii)) *= gstValue(hdr->mult(ii));
      pos += hdr->length(ii);
    }
    return new_rec;
  } else {
    notify(NFY_WARN, "Unknown FileType\n");
    status_ = GST_READ_FAIL;
    return gstRecordHandle();
  }
}
Ejemplo n.º 6
0
static bool ReadPNG(PngT *png, RwOpsT *stream) {
  uint32_t id[2];
  bool error = false;
  PngChunkT chunk;

  memset(png, 0, sizeof(PngT));

  if (!IoRead32(stream, &id[0]) || !IoRead32(stream, &id[1])) {
    LOG("Could not read PNG header!");
    return false;
  }

  if (id[0] != PNG_ID0 || id[1] != PNG_ID1) {
    LOG("Not a PNG file!");
    return false;
  }

  memset(&chunk, 0, sizeof(chunk));

  while (chunk.id != PNG_IEND && !error) {
    uint32_t their_crc;
    uint8_t *ptr;

    if (IoRead(stream, &chunk, 8) != 8)
      return false;

    LOG("%.4s: length: %d", (char *)&chunk.id, chunk.length);

    ptr = MemNew(chunk.length);

    if (IoRead(stream, ptr, chunk.length) != chunk.length)
      return false;

    if (chunk.id == PNG_IHDR) {
      MemCopy(&png->ihdr, ptr, sizeof(IhdrT));
    } else if (chunk.id == PNG_IDAT) {
      if (!png->idat.data) {
        png->idat.length = chunk.length;
        png->idat.data = ptr;
      } else {
        IdatT *idat = &png->idat;

        while (idat->next)
          idat = idat->next;

        idat->next = NewRecord(IdatT);
        idat->next->length = chunk.length;
        idat->next->data = ptr;
      }
      ptr = NULL;
    } else if (chunk.id == PNG_PLTE) {
      png->plte.no_colors = chunk.length / 3;
      png->plte.colors = (RGB *)ptr;
      ptr = NULL;
    } else if (chunk.id == PNG_tRNS) {
      if (png->ihdr.colour_type == PNG_INDEXED) {
        png->trns = MemNew(sizeof(uint32_t) + chunk.length);
        png->trns->type3.length = chunk.length;
        MemCopy(png->trns->type3.alpha, ptr, chunk.length);
      } else {
        png->trns = (TrnsT *)ptr;
        ptr = NULL;
      }
    }

    if (ptr)
      MemUnref(ptr);

    if (!IoRead32(stream, &their_crc))
      return false;
  }

  return !error;
}