Ejemplo n.º 1
0
/*
**
**  [func] - fflush.
**  [desc] - if the stream file is opened as read-only then returns 0. else
**           if stream is a valid FILE stream and able to flush the stream
**           file write buffer then returns 0. else returns EOF.
**  [entr] - FILE *stream; the pointer to the FILE stream.
**  [exit] - int; 0 if able to flush the write buffer or file is read-only. else EOF.
**  [prec] - stream is a valid FILE pointer.
**  [post] - the stream FILE stream write buffer is flushed.
**
*/
int fflush(FILE *stream)
{
  int ret = EOF; // Same as default case below.

  switch(LOCAL_FILE(stream)->type) {
    case STD_IOBUF_TYPE_GE:
    case STD_IOBUF_TYPE_STDOUTHOST:
      /* stdout & stderr are never buffered. */
    case STD_IOBUF_TYPE_UMD:
      /* cd-rom files are read-only so no write buffer to flush. */
      ret = 0;
      break;
    case STD_IOBUF_TYPE_MS:
      if (LOCAL_FILE(stream)->flag & (_IOWRT | _IORW)) {
        //if (ret != 0) ret = EOF;
		  /* Need to implement sync or something */
      }
      else ret = 0;
      break;
    case STD_IOBUF_TYPE_HOST:
      /* flush host file write buffer. */
      if (LOCAL_FILE(stream)->flag & (_IOWRT | _IORW)) ret = 0;
      else ret = 0;
      break;
    default:
      /* unknown/invalid I/O buffer type. */
      ret = EOF;
  }
  return (ret);
}
Ejemplo n.º 2
0
/*
**
**  [func] - ungetc.
**  [desc] -
**  [entr] - int c;
**           FILE *stream; the pointer to the FILE stream.
**  [exit] - int;
**  [prec] - stream is a valid FILE pointer.
**  [post] - the stream FILE stream is modified.
**
*/
int ungetc(int c, FILE *stream)
{
  // int ret = EOF;

  if (c == EOF || LOCAL_FILE(stream)->has_putback) {
    /* invalid input, or putback queue full */
    return EOF;
  }

  LOCAL_FILE(stream)->putback = (u8)c;
  LOCAL_FILE(stream)->has_putback = 1;
  return c;
}
void NanoXmlUnitTest::test5()
{
    NanoXml parser(LOCAL_FILE("test5.xml"));
    QCOMPARE(parser.didFail(), false);
    AssocTree tree = parser.result();
    QCOMPARE(tree.value("param1").toString(), QString("value1"));
}
void NanoXmlUnitTest::test1()
{
    NanoXml parser(LOCAL_FILE("test1.xml"));
    QCOMPARE(parser.didFail(), false);
    AssocTree tree = parser.result();

    QVERIFY(tree.type() == QVariant::List);
    QCOMPARE(tree.toList().count(), 4);
    QVERIFY(tree.toList().at(0).type() == QVariant::String);
    QCOMPARE(tree.toList().at(0).toString(), QString("key"));

    QVERIFY(tree.toList().at(1).type() == QVariant::List);
    QCOMPARE(tree.toList().at(1).toList().count(), 2);
    QVERIFY(tree.toList().at(1).toList().at(0).type() == QVariant::String);
    QCOMPARE(tree.toList().at(1).toList().at(0).toString(), QString("name"));
    QVERIFY(tree.toList().at(1).toList().at(1).type() == QVariant::String);
    QCOMPARE(tree.toList().at(1).toList().at(1).toString(), QString("Example.Random"));

    QVERIFY(tree.toList().at(2).type() == QVariant::List);
    QCOMPARE(tree.toList().at(2).toList().count(), 2);
    QVERIFY(tree.toList().at(2).toList().at(0).type() == QVariant::String);
    QCOMPARE(tree.toList().at(2).toList().at(0).toString(), QString("type"));
    QVERIFY(tree.toList().at(2).toList().at(1).type() == QVariant::String);
    QCOMPARE(tree.toList().at(2).toList().at(1).toString(), QString("string"));

    QVERIFY(tree.toList().at(3).type() == QVariant::List);
    QCOMPARE(tree.toList().at(3).toList().count(), 2);
    QVERIFY(tree.toList().at(3).toList().at(0).type() == QVariant::String);
    QCOMPARE(tree.toList().at(3).toList().at(0).toString(), QString("doc"));
    QVERIFY(tree.toList().at(3).toList().at(1).type() == QVariant::String);
    QCOMPARE(tree.toList().at(3).toList().at(1).toString(), QString("A random property."));
}
void NanoXmlUnitTest::test2()
{
    NanoXml parser(LOCAL_FILE("test2.xml"));
    QCOMPARE(parser.didFail(), false);
    AssocTree tree = parser.result();

    QVERIFY(tree.type() == QVariant::List);
    QCOMPARE(tree.toList().count(), 3);
    QVERIFY(tree.toList().at(0).type() == QVariant::String);
    QCOMPARE(tree.toList().at(0).toString(), QString("key"));

    QVERIFY(tree.toList().at(1).type() == QVariant::List);
    QCOMPARE(tree.toList().at(1).toList().count(), 2);
    QVERIFY(tree.toList().at(1).toList().at(0).type() == QVariant::String);
    QCOMPARE(tree.toList().at(1).toList().at(0).toString(), QString("name"));
    QVERIFY(tree.toList().at(1).toList().at(1).type() == QVariant::String);
    QCOMPARE(tree.toList().at(1).toList().at(1).toString(), QString("Example.Random"));

    QVERIFY(tree.toList().at(2).type() == QVariant::List);
    QCOMPARE(tree.toList().at(2).toList().count(), 2);
    QVERIFY(tree.toList().at(2).toList().at(0).type() == QVariant::String);
    QCOMPARE(tree.toList().at(2).toList().at(0).toString(), QString("type"));
    QVERIFY(tree.toList().at(2).toList().at(1).type() == QVariant::List);
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().count(), 2);
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().at(0).type(), QVariant::String);
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().at(0).toString(), QString("uniform-list"));
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().at(1).type(), QVariant::List);
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().at(1).toList().count(), 2);
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().at(1).toList().at(0).type(), QVariant::String);
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().at(1).toList().at(0).toString(), QString("type"));
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().at(1).toList().at(1).type(), QVariant::String);
    QCOMPARE(tree.toList().at(2).toList().at(1).toList().at(1).toList().at(1).toString(), QString("number"));
}
Ejemplo n.º 6
0
/*
**
**  [func] - fread.
**  [desc] - attempts to read n number of records of r size to the stream file
**           and returns the number of records successfully read from the file.
**  [entr] - void *buf; the pointer to the destination data buffer.
**           size_t r; the size of the records to read.
**           size_t n; the number of records to read.
**           FILE *stream; the pointer to the FILE stream.
**  [exit] - size_t; the number of records successfully read from the stream file.
**  [prec] - buf is a valid memory pointer of (r * n) size in bytes and stream
**           is a valid FILE pointer.
**  [post] - the stream file is modified.
**
*/
size_t fread(void *buf, size_t r, size_t n, FILE *stream)
{
  size_t ret;

  switch(LOCAL_FILE(stream)->type) {
    case STD_IOBUF_TYPE_NONE:
    case STD_IOBUF_TYPE_GE:
    case STD_IOBUF_TYPE_STDOUTHOST:
      /* cannot read from stdout or stderr. */
      ret = 0;
      break;
    default:
      /* attempt to read from the stream file. */
      ret = (sceIoRead(LOCAL_FILE(stream)->fd, buf, (int)(r * n)) / (int)r);
  }
  return (ret);
}
Ejemplo n.º 7
0
/*
**
**  [func] - fseek.
**  [desc] - attempts to seek the stream file pointer to offset from origin.
**           if able to seek the stream file pointer to offset from origin
**           returns 0. else returns -1.
**  [entr] - FILE *stream; the pointer to the FILE stream.
**           long offset; the seek offset.
**           int origin; the seek origin.
**  [exit] - int; 0 if able to seek to offset from origin successfully. else -1.
**  [prec] - stream is a valid FILE pointer and origin is a valid seek origin
**           type.
**  [post] - the stream file pointer position is modified.
**
*/
int fseeko64(FILE *stream, int64_t offset, int origin)
{
  int ret;

  switch(LOCAL_FILE(stream)->type) {
    case STD_IOBUF_TYPE_NONE:
    case STD_IOBUF_TYPE_GE:
    case STD_IOBUF_TYPE_STDOUTHOST:
      /* cannot seek stdout or stderr. */
      ret = -1;
      break;
    default:
      /* attempt to seek to offset from origin. */
      ret = ((sceIoLseek(LOCAL_FILE(stream)->fd, offset, origin) >= 0) ? 0 : -1);
  }
  return (ret);
}
Ejemplo n.º 8
0
/*
**
**  [func] - fclose.
**  [desc] - if stream is a valid FILE stream and able to close the stream file
**           then returns 0. else returns EOF.
**  [entr] - FILE *stream; the pointer to the FILE stream.
**  [exit] - int; 0 if able to close the stream file. else EOF.
**  [prec] - stream is a valid FILE pointer.
**  [post] - the stream file is closed.
**
*/
int fclose(FILE *stream)
{
  int ret;

  /* test the file stream type. */
  switch(LOCAL_FILE(stream)->type) {
    case STD_IOBUF_TYPE_NONE:
    case STD_IOBUF_TYPE_GE:
    case STD_IOBUF_TYPE_STDOUTHOST:
      /* cannot close stdin, stdout, or stderr. */
      // duh.. this is wrong. One SHOULD be able to close
      // std*. That's a common unix doing. However, I doubt
      // allowing this madness could be a good idea.
      ret = EOF;
      break;
    default:
      if ((LOCAL_FILE(stream)->fd >= 0) && (sceIoClose(LOCAL_FILE(stream)->fd) >= 0)) {
        LOCAL_FILE(stream)->type = STD_IOBUF_TYPE_NONE;
        LOCAL_FILE(stream)->fd = -1;
        LOCAL_FILE(stream)->cnt = 0;
        LOCAL_FILE(stream)->flag = 0;
        ret = 0;
      }
      else ret = EOF;
  }
  return (ret);
}
Ejemplo n.º 9
0
/*
**
**  [func] - fwrite.
**  [desc] - attempts to write n number of records of r size to the stream file
**           and returns the number of records successfully written to the file.
**  [entr] - const void *buf; the pointer to the source data buffer.
**           size_t r; the size of the records to write.
**           size_t n the number of records to write.
**           FILE *stream; the pointer to the FILE stream.
**  [exit] - size_t; the number of records successfully written to the stream file.
**  [prec] - buf is a valid memory pointer of (r * n) size in bytes and stream
**           is a valid FILE pointer.
**  [post] - the stream file is modified.
**
*/
size_t fwrite(const void *buf, size_t r, size_t n, FILE *stream)
{
  size_t ret;

  /* attempt to write the stream file. */
  //ret = (sceIoWrite(stream->fd, (void *)buf, (int)(r * n)) / (int)r);
  ret = (sceIoWrite(LOCAL_FILE(stream)->fd, (void *)buf, (int)(r * n)) / (int) r);

  return (ret);
}
Ejemplo n.º 10
0
/*
**
**  [func] - fgetc.
**  [desc] - attempts to read one character from the stream file. if able to
**           read one character from the file then returns the chaaracter
**           read. else EOF.
**  [entr] - FILE *stream; the pointer to the FILE stream.
**  [exit] - int; the character read from the stream file. else -1.
**  [prec] - stream is a valid FILE pointer.
**  [post] - the stream file is modified.
**
*/
int fgetc(FILE *stream)
{
  char c;
  int  ret;

  if (LOCAL_FILE(stream)->has_putback) {
    LOCAL_FILE(stream)->has_putback = 0;
    return LOCAL_FILE(stream)->putback;
  }

  switch(LOCAL_FILE(stream)->type) {
    case STD_IOBUF_TYPE_GE:
    case STD_IOBUF_TYPE_STDOUTHOST:
      /* cannot read from stdout or stderr. */
      ret = EOF;
      break;
    default:
      ret = ((fread(&c, 1, 1, stream) == 1) ? (int)c : EOF);
  }
  return (ret);
}
Ejemplo n.º 11
0
int64_t ftello64(FILE *stream)
{
  int64_t n, ret;

  switch(LOCAL_FILE(stream)->type) {
    case STD_IOBUF_TYPE_NONE:
    case STD_IOBUF_TYPE_GE:
    case STD_IOBUF_TYPE_STDOUTHOST:
      /* stdout or stderr is an invalid seek stream argument. */
      errno = EINVAL;
      ret = -1L;
      break;
    default:
      if (LOCAL_FILE(stream)->fd < 0) {
        /* file is not open. */
        errno = EBADF;
        ret = -1L;
      }
      else ret = (((n = sceIoLseek(LOCAL_FILE(stream)->fd, 0, SEEK_CUR)) >= 0) ? (int64_t)n : -1);
  }
  return (ret);
}
Ejemplo n.º 12
0
/*
**
**  [func] - putc.
**  [desc] - attempts to write the c character to the stream file. if able to
**           write the character to the stream file then returns the character
**           written. else returns -1.
**  [entr] - int c; the character to write to the file.
**           FILE *stream; the pointer to the FILE stream.
**  [exit] - int; the character written to the file if successful. else -1.
**  [prec] - stream is a valid FILE pointer.
**  [post] - the stream file is modified.
**
*/
int putc(int c, FILE *stream)
{
  char ch;
  int  ret = 0;

  switch(LOCAL_FILE(stream)->type) {
      break;
    default:
      /* write one character to the stream file. */
      ch = (char)c;
      ret = ((fwrite(&ch, 1, 1, stream) == 1) ? c : EOF);
  }
  return (ret);
}
Ejemplo n.º 13
0
/*
**
**  [func] - _fcloseall.
**  [desc] - attempts to flush all the open files with write-access. if able
**           to flush all the open files with write-access then returns the
**           number of files flushed. else returns -1.
**  [entr] - none.
**  [exit] - int; the number of files flushed if successful. else -1.
**  [prec] - none.
**  [post] - all open non-system files with write-access are flushed.
**
*/
int _fflushall(void)
{
  int  i, ret = 0;
  FILE *iob;

  /* process all open files except for stdout, stdin and stderr. */
  for (i = 3, iob = &__iob[3]; i < _NFILE; ++i, ++iob) {
    if (LOCAL_FILE(iob)->fd >= 0) {
      /* attempt to flush the current file. */
      if ((fflush(iob) == 0) && (ret >= 0)) ++ret;
      else ret = EOF;
    }
  }
  return (ret);
}
Ejemplo n.º 14
0
/*
**
**  [func] - fopen.
**  [desc] - attempts to open the fname file using the mode file mode. if able
**           open the fname then returns the pointer to the FILE stream. else
**           returns NULL.
**  [entr] - const char *fname; the filename string pointer.
**           const char *mode; the file mode string pointer.
**  [exit] - FILE *; the pointer the fname FILE stream. else NULL.
**  [prec] - fname and mode are valid string pointers.
**  [post] - the fname file is opened.
**
*/
FILE *fopen(const char *fname, const char *mode)
{
  FILE *ret = NULL;
  int  fd, flag = 0, i, iomode = 0;

  /* ensure file name and mode are not NULL strings. */
  if ((fname != NULL) && (*fname != '\0')) {
    if ((mode != NULL) && (*mode != '\0')) {
      /* test the file mode. */
      switch(*mode++) {
        case 'r':
          flag = _IOREAD;
          iomode = PSP_O_RDONLY;
          break;
        case 'w':
          flag = _IOWRT;
          iomode = (PSP_O_WRONLY | PSP_O_CREAT);
          break;
        case 'a':
          flag = _IORW;
          iomode = PSP_O_APPEND;
          break;
      }
      /* test the extended file mode. */
      for (; (*mode++ != '\0'); ) {
        switch(*mode) {
          case 'b':
            continue;
          case '+':
            flag |= (_IOREAD | _IOWRT);
            iomode |= (PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC);
            continue;
          default:
            break;
        }
      }
      /* search for an available fd slot. */
      for (i = 2; i < _NFILE; ++i) if (LOCAL_FILE(&__iob[i])->fd < 0) break;
      if (i < _NFILE) {
        /* attempt to open the fname file. */
        if ((fd = sceIoOpen((char *)fname, iomode, 0777)) >= 0) {
          LOCAL_FILE(&__iob[i])->type = __stdio_get_fd_type(fname);
          LOCAL_FILE(&__iob[i])->fd = fd;
          LOCAL_FILE(&__iob[i])->cnt = 0;
          LOCAL_FILE(&__iob[i])->flag = flag;
          LOCAL_FILE(&__iob[i])->has_putback = 0;
          ret = (__iob + i);
        }
      }
    }
  }
  return (ret);
}
Ejemplo n.º 15
0
/*
**
**  [func] - fdopen.
**  [desc] - produces a file descriptor of type `FILE *', from a 
**           descriptor for an already-open file (returned, for 
**           example, by the system subroutine `open' rather than by `fopen').
**           The MODE argument has the same meanings as in `fopen'.
**  [entr] - int fd; file descriptor returned by 'open'.
**           const char *mode; the file mode string pointer.
**  [exit] - file pointer or `NULL', as for `fopen'.
**
*/
FILE *fdopen(int fd, const char *mode)
{
  FILE *ret = NULL;
  int  flag = 0, i, iomode = 0;

  /* ensure valid descriptor, and that mode is not a NULL string. */
  if (fd >= 0) {
    if ((mode != NULL) && (*mode != '\0')) {
      /* test the file mode. */
      switch(*mode++) {
        case 'r':
          flag = _IOREAD;
          iomode = PSP_O_RDONLY;
          break;
        case 'w':
          flag = _IOWRT;
          iomode = (PSP_O_WRONLY | PSP_O_CREAT);
          break;
        case 'a':
          flag = _IORW;
          iomode = PSP_O_APPEND;
          break;
      }
      /* test the extended file mode. */
      for (; (*mode++ != '\0'); ) {
        switch(*mode) {
          case 'b':
            continue;
          case '+':
            flag |= (_IOREAD | _IOWRT);
            iomode |= (PSP_O_RDWR | PSP_O_CREAT | PSP_O_TRUNC);
            continue;
          default:
            break;
        }
      }
      /* search for an available fd slot. */
      for (i = 2; i < _NFILE; ++i) if (LOCAL_FILE(&__iob[i])->fd < 0) break;
      if (i < _NFILE) {
        /* attempt to open the fname file. */
        LOCAL_FILE(&__iob[i])->type = STD_IOBUF_TYPE_NONE;
        LOCAL_FILE(&__iob[i])->fd = fd;
        LOCAL_FILE(&__iob[i])->cnt = 0;
        LOCAL_FILE(&__iob[i])->flag = flag;
        LOCAL_FILE(&__iob[i])->has_putback = 0;
        ret = (__iob + i);
      }
    }
  }
  return (ret);
}
Ejemplo n.º 16
0
/*
**
**  [func] - fgets.
**  [desc] - attempts to read a string from the stream file. if able to read
**           a string from the stream file stdin then stores the string up to
**           n characters to the memory pointed by buf and returns buf. else
**           returns NULL.
**  [entr] - char *buf; the pointer to the destination string buffer.
**           int n; the maximum number of characters to write to buf.
**           FILE *stream; the pointer to the FILE stream.
**  [exit] - char *; buf if the string is read successfully. else NULL.
**  [prec] - buf is a valid memory pointer of n size in bytes and stream is a
**           valid FILE pointer.
**  [post] - the memory pointed to by buf is modified and the stream file
**           pointer is modified.
**
*/
char *fgets(char *buf, int n, FILE *stream)
{
  char *ret = buf;
  int  c, done;

  switch(LOCAL_FILE(stream)->type) {
    case STD_IOBUF_TYPE_GE:
    case STD_IOBUF_TYPE_STDOUTHOST:
      /* cannot read from stdout or stderr. */
      ret = NULL;
      break;
    default:
      for (done = 0; (!done); ) {
        switch(c = fgetc(stream)) {
          case '\r':
          case '\n':
            if (n > 0) {
              /* newline terminates fgets. */
              *buf++ = '\0';
              --n;
              done = 1;
              break;
            }
            break;
          case EOF:
            /* end of file or error. */
            ret = NULL;
            done = 1;
            break;
          default:
            if (n > 0) {
              /* store the current character to buf. */
              *buf++ = (char)c;
              --n;
            }
        }
      }
  }
  return (ret);
}
Ejemplo n.º 17
0
/*
**
**  [func] - feof.
**  [desc] - if the stream file stream has reached the end of the file then
**           returns non-zero. else returns 0.
**  [entr] - FILE *stream; the pointer to the FILE stream.
**  [exit] - int; non-zero if the stream file has reached EOF. else 0.
**  [prec] - stream is a valid FILE pointer.
**  [post] - none.
**
*/
int feof(FILE *stream)
{
  return ((LOCAL_FILE(stream)->flag & _IOEOF) != 0);
}
Ejemplo n.º 18
0
void NanoXmlUnitTest::broken()
{
    NanoXml parser(LOCAL_FILE("broken.xml"));
    QCOMPARE(parser.didFail(), true);
}
Ejemplo n.º 19
0
/*
**
**  [func] - ferror.
**  [desc] - if an error has occured for the stream file stream then returns
**           non-zero. else returns 0.
**  [entr] - FILE *stream; the pointer to the FILE stream.
**  [exit] - int; non-zero if error has occured for the stream file. else 0.
**  [prec] - stream is a valid FILE pointer.
**  [post] - none.
**
*/
int ferror(FILE *stream)
{
  return ((LOCAL_FILE(stream)->flag & _IOERR) != 0);
}
Ejemplo n.º 20
0
void NanoXmlUnitTest::test3()
{
    NanoXml parser(LOCAL_FILE("test3.xml"));
    QCOMPARE(parser.didFail(), false);
    QCOMPARE(parser.namespaceUri(), QString("http://www.test.org/document"));
}
Ejemplo n.º 21
0
/*
**
**  [func] - clearerr.
**  [desc] - clears the stream file stream error condition.
**  [entr] - FILE *stream; the pointer to the FILE stream.
**  [exit] - none.
**  [prec] - stream is a valid FILE pointer.
**  [post] - the stream file stream error condition is cleared.
**
*/
void clearerr(FILE *stream)
{
  LOCAL_FILE(stream)->flag &= (~_IOERR);
}
Ejemplo n.º 22
0
int fileno(FILE * f) {
    return LOCAL_FILE(f)->fd;
}