//------------------------------------------------------------------------------
size_t StdioStream::fwrite(const void* ptr, size_t size, size_t count) {
  return write(ptr, count*size) < 0 ? EOF : count;
#if 0  ////////////////////////////////////////////////////////////////////////////////////
  const uint8_t* src = static_cast<const uint8_t*>(ptr);
  size_t total = count*size;
  if (total == 0) {
    return 0;
  }
  size_t todo = total;

  while (todo > m_w) {
    memcpy(m_p, src, m_w);
    m_p += m_w;
    src += m_w;
    todo -= m_w;
    if (!flushBuf()) {
      return (total - todo)/size;
    }
  }
  memcpy(m_p, src, todo);
  m_p += todo;
  m_w -= todo;
  return count;
#endif  //////////////////////////////////////////////////////////////////////////////////
}
ServerOutputStream& ServerOutputStream::setPrefix(const QString& prefix) {
    flushBuf();
    m_prefix = prefix;
    m_prefixBytes = prefix.toUtf8();
    clearBuf();
    return *this;
}
//------------------------------------------------------------------------------
// private
bool StdioStream::fillBuf() {
  if (!(m_flags &
        F_SRD)) {  /////////////check for F_ERR and F_EOF ??/////////////////
    if (!(m_flags & F_SRW)) {
      m_flags |= F_ERR;
      return false;
    }
    if (m_flags & F_SWR) {
      if (!flushBuf()) {
        return false;
      }
      m_flags &= ~F_SWR;
      m_flags |= F_SRD;
      m_w = 0;
    }
  }
  m_p = m_buf + UNGETC_BUF_SIZE;
  int nr = FatFile::read(m_p, sizeof(m_buf) - UNGETC_BUF_SIZE);
  if (nr <= 0) {
    m_flags |= nr < 0 ? F_ERR : F_EOF;
    m_r = 0;
    return false;
  }
  m_r = nr;
  return true;
}
Example #4
0
/*!

*/
gzfilebuf *
gzfilebuf::close() throw()
{
#ifdef HAVE_LIBZ
    if ( this->is_open() )
    {
        flushBuf();
        destroyInternalBuffer();

        if ( ! M_impl )
        {
            return NULL;
        }

        if ( M_impl->file_ == NULL )
        {
            return NULL;
        }

        // TODO: checking close status...
        gzclose( M_impl->file_ );
        M_impl->file_ = NULL;
        M_impl->open_mode_ = static_cast< std::ios_base::openmode >( 0 );
    }
#endif
    return NULL;
}
//------------------------------------------------------------------------------
int StdioStream::flushPut(uint8_t c) {
  if (!flushBuf()) {
    return EOF;
  }
  m_w--;
  return *m_p++ = c;
}
Example #6
0
/* Write to dst/tmp stream buffer. */
static void writeBuf(ufwCtx h, size_t writeCnt, const char *ptr) {
    char *buf;
    size_t *cnt;
    int err;
    size_t left;
    if (h->state == 0) {
        buf = h->tmp.buf;
        cnt = &h->tmp.cnt;
        err = ufwErrTmpStream;
    } else /* h->state == 1 */
    {
        buf = h->dst.buf;
        cnt = &h->dst.cnt;
        err = ufwErrDstStream;
    }

    left = BUFSIZ - *cnt; /* Bytes left in buffer */
    while (writeCnt >= left) {
        memcpy(&buf[*cnt], ptr, left);
        *cnt += left;
        flushBuf(h);
        ptr += left;
        writeCnt -= left;
        left = BUFSIZ;
    }
    if (writeCnt > 0) {
        memcpy(&buf[*cnt], ptr, writeCnt);
        *cnt += writeCnt;
    }
}
Example #7
0
/* End glyph definition. */
static void glyphEnd(abfGlyphCallbacks *cb) {
    ufwCtx h = cb->direct_ctx;

    if (h->err.code != 0)
        return;
    else if (h->path.state < 2) {
        /* Call sequence error */
        h->err.code = ufwErrBadCall;
        return;
    }

    if (h->path.state >= 3) /* have seen a move to. */
        writeContour(h);

    if (h->path.state < 3) /* have NOT seen a move to, hence have never emitted an <outline> tag. */
        writeLine(h, "\t<outline>");

    writeLine(h, "\t</outline>");
    writeLine(h, "</glyph>");
    h->path.state = 0;

    flushBuf(h);
    /* Close dst stream */
    h->cb.stm.close(&h->cb.stm, h->stm.dst);

    return;
}
//------------------------------------------------------------------------------
int StdioStream::fflush() {
  if ((m_flags & (F_SWR | F_SRW)) && !(m_flags & F_SRD)) {
    if (flushBuf() && FatFile::sync()) {
      return 0;
    }
  }
  return EOF;
}
//------------------------------------------------------------------------------
bool StdioStream::rewind() {
  if (m_flags & F_SWR) {
    if (!flushBuf()) {
      return false;
    }
  }
  FatFile::seekSet(0);
  m_r = 0;
  return true;
}
Example #10
0
/*!

*/
std::streambuf::int_type
gzfilebuf::overflow( std::streambuf::int_type c )
{
    flushBuf();
    if ( c != traits_type::eof() )
    {
        *pptr() = traits_type::to_char_type( c );
        pbump( 1 );
    }
    return 0;
}
Example #11
0
//------------------------------------------------------------------------------
char* StdioStream::fmtSpace(uint8_t len) {
  if (m_w < len) {
    if (!flushBuf() || m_w < len) {
      return 0;
    }
  }
  if (len > m_w) {
    return 0;
  }
  m_p += len;
  m_w -= len;
  return reinterpret_cast<char*>(m_p);
}
qint64 ServerOutputStream::writeData(const char *data, qint64 len)
{
    qint64 start = 0;
    while (start < len) {
        qint64 i;
        for (i=start; i<len && data[i]!='\n'; ++i) {}
        if (i == len) {
            appendToBuf(data+start, len-start);
            break;
        }
        appendToBuf(data+start, i+1-start);
        flushBuf();
        start = i+1;
    }
    return len;
}
Example #13
0
int recvFileList(int sfd, struct actionParameters *ap,
		struct serverActionParameters *sap){
	int res;
	struct flEntry file;
	struct array *fl2; 

	//memmove(&file.ip,&ap->comip, sizeof(struct sockaddr));
	file.ip = ap->comip;
	while (( res = getTokenFromStream( sfd, &ap->combuf, &ap->comline, "\n", 
			"\r\n",NULL ))){
		if (res ==  -1) return -1;

		strcpy(file.filename, (char *)ap->comline.buf);
		flushBuf(&ap->comline);

		if (getTokenFromStream( sfd, &ap->combuf, &ap->comline, 
          "\n", "\r\n",NULL ) == -1)
			return -1;
		long size = my_strtol((char *)ap->comline.buf);

		if ( errno || size < 0 ) {
      file.size = size;
			logmsg(ap->semid, ap->logfd, LOGLEVEL_WARN, 
          "problem converting file size for %s - %s\n", file.filename, 
          ap->comline.buf);
			continue;
		}
		logmsg(ap->semid, ap->logfd, LOGLEVEL_VERBOSE, "recvFileList: %s - %lu\n",
        file.filename, file.size);

		if ( (res = semWait(ap->semid, SEM_FILELIST)))
			logmsg(ap->semid, ap->logfd, LOGLEVEL_WARN, 
          "(recvfile) can't get semaphore, %d", res);
		fl2 = addArrayItem(sap->filelist, &file);
		if ( (res = semSignal(ap->semid, SEM_FILELIST)))
			logmsg(ap->semid, ap->logfd, LOGLEVEL_WARN, 
          "(recvfile) can't release semaphore, %d", res);
		if (fl2) sap->filelist = fl2;
		else {
			logmsg(ap->semid, ap->logfd, LOGLEVEL_FATAL, 
          "leaving the functions because realloc failed %d", fl2);
			return -1;
		}
	}
	
	return 1;
}
Example #14
0
static void writeContents(ufwCtx h) {
    Glyph *glyphRec;
    char buffer[FILENAME_MAX];
    int i;
    /* Set error handler */
    DURING_EX(h->err.env)

    h->state = 1; /* Indicates writing to dst stream */

    /* Open fontinfo.plist file as dst stream */

    sprintf(buffer, "%s/%s", h->arg.glyphLayer, "contents.plist");
    h->cb.stm.clientFileName = buffer;
    h->stm.dst = h->cb.stm.open(&h->cb.stm, UFW_DST_STREAM_ID, 0);
    if (h->stm.dst == NULL)
        fatal(h, ufwErrDstStream);

    writeLine(h, XML_HEADER);
    writeLine(h, PLIST_DTD_HEADER);
    writeLine(h, "<plist version=\"1.0\">");
    writeLine(h, "<dict>");
    for (i = 0; i < h->glyphs.cnt; i++) {
        glyphRec = &h->glyphs.array[i];
        sprintf(buffer, "\t<key>%s</key>", glyphRec->glyphName);
        writeLine(h, buffer);
        sprintf(buffer, "\t<string>%s</string>", glyphRec->glifFileName);
        writeLine(h, buffer);
    }

    writeLine(h, "</dict>");
    writeLine(h, "</plist>");

    /* Close dst stream */
    flushBuf(h);
    h->cb.stm.close(&h->cb.stm, h->stm.dst);

    HANDLER

    if (h->stm.dst)
        h->cb.stm.close(&h->cb.stm, h->stm.dst);

    END_HANDLER

    return;
}
Example #15
0
int StdioStream::fclose() {
  int rtn = 0;
  if (!m_flags) {
    return EOF;
  }
  if (m_flags & F_SWR) {
    if (!flushBuf()) {
      rtn = EOF;
    }
  }
  if (!FatFile::close()) {
    rtn = EOF;
  }
  m_r = 0;
  m_w = 0;
  m_flags = 0;
  return rtn;
}
Example #16
0
//------------------------------------------------------------------------------
int StdioStream::write(const void* buf, size_t count) {
  const uint8_t* src = static_cast<const uint8_t*>(buf);
  size_t todo = count;

  while (todo > m_w) {
    memcpy(m_p, src, m_w);
    m_p += m_w;
    src += m_w;
    todo -= m_w;
    if (!flushBuf()) {
      return EOF;
    }
  }
  memcpy(m_p, src, todo);
  m_p += todo;
  m_w -= todo;
  return count;
}
OutputCharStream &OutputCharStream::write(const Char *s, size_t n)
{
  for (;;) {
    size_t spare = end_ - ptr_;
    if (n <= spare) {
      memcpy(ptr_, s, n*sizeof(Char));
      ptr_ += n;
      break;
    }
    if (spare > 0) {
      memcpy(ptr_, s, spare*sizeof(Char));
      ptr_ += spare;
      s += spare;
      n -= spare;
    }
    n--;
    flushBuf(*s++);
  }
  return *this;
}
Example #18
0
//------------------------------------------------------------------------------
int StdioStream::fseek(int32_t offset, int origin) {
  int32_t pos;
  if (m_flags & F_SWR) {
    if (!flushBuf()) {
      goto fail;
    }
  }
  switch (origin) {
  case SEEK_CUR:
    pos = ftell();
    if (pos < 0) {
      goto fail;
    }
    pos += offset;
    if (!FatFile::seekCur(pos)) {
      goto fail;
    }
    break;

  case SEEK_SET:
    if (!FatFile::seekSet(offset)) {
      goto fail;
    }
    break;

  case SEEK_END:
    if (!FatFile::seekEnd(offset)) {
      goto fail;
    }
    break;

  default:
    goto fail;
  }
  m_r = 0;
  m_p = m_buf;
  return 0;

fail:
  return EOF;
}
Example #19
0
static void writeMetaInfo(ufwCtx h) {
    char buffer[FILENAME_MAX];

    /* Set error handler */
    DURING_EX(h->err.env)

    h->state = 1; /* Indicates writing to dst stream */

    /* Open lib.plist file as dst stream */

    sprintf(buffer, "%s", "metainfo.plist");
    h->cb.stm.clientFileName = buffer;
    h->stm.dst = h->cb.stm.open(&h->cb.stm, UFW_DST_STREAM_ID, 0);
    if (h->stm.dst == NULL)
        fatal(h, ufwErrDstStream);

    writeLine(h, XML_HEADER);
    writeLine(h, PLIST_DTD_HEADER);
    writeLine(h, "<plist version=\"1.0\">");
    writeLine(h, "<dict>");
    writeLine(h, "\t<key>creator</key>");
    writeLine(h, "\t<string>com.adobe.type.tx</string>");
    writeLine(h, "\t<key>formatVersion</key>");
    writeLine(h, "\t<integer>2</integer>");
    writeLine(h, "</dict>");
    writeLine(h, "</plist>");

    /* Close dst stream */
    flushBuf(h);
    h->cb.stm.close(&h->cb.stm, h->stm.dst);

    HANDLER
    if (h->stm.dst)
        h->cb.stm.close(&h->cb.stm, h->stm.dst);
    END_HANDLER
}
Example #20
0
int recvResult(int fd, struct actionParameters *ap,struct array * results){
	int counter=0, res;
	struct flEntry file;///, *f;
	struct array * results2;
	char port[7];
	char ipstr[56];
	flushBuf(&ap->combuf);
	/* I don't flush results on purpose  */
	/* get a line */
	logmsg(ap->semid, ap->logfd, LOGLEVEL_WARN, "before loop%lu\n\n", 
      results->itemcount);
	while (( res = getTokenFromStream(fd, &ap->combuf, &ap->comline, 
					"\n", "\r\n",NULL ))){
		/* get first word -> ip */
		strncpy(ipstr, (char *)ap->comline.buf, 56);
		if (res ==  -1) return -3;
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "(recvResult) ip: %s\n", ipstr);

		/* get second word -> port */
		if (getTokenFromBuffer(&ap->combuf, &ap->comline, " ", "\n",NULL ) == -1)
			return -3;
		strncpy(port, (char *)ap->comline.buf, 7);
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "(recvResult) port: %s\n", 
        port);

		if (parseIP(ipstr, (struct sockaddr *)&file.ip, port, 0) == -1)
			return -3;

		/* get third word -> filename */
		if (getTokenFromBuffer( &ap->combuf, &ap->comline, " ", "\n",NULL ) == -1)
			return -3;
		strcpy(file.filename, (char *)ap->comline.buf);
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "(recvResult) filename: %s\n",
			 	file.filename);

		/* get fourth word -> size */
		if (getTokenFromBuffer( &ap->combuf, &ap->comline, " ", "\n",NULL ) == -1)
			return -3;
    long size;
		if ((size = my_strtol((char *)ap->comline.buf)) < 0 || errno) return -3;
    file.size = size;
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "(recvResult) size: %d\n", 
        file.size);

		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, "got this: %s\n%d\n%s\n%lu\n", 
        putIP((struct sockaddr *)&file.ip), 
					getPort((struct sockaddr *) &file.ip), file.filename, file.size);

		results2 = addArrayItem(results, &file);
		if (results2) results = results2;
		else {
			logmsg(ap->semid, ap->logfd, LOGLEVEL_FATAL, 
          "couldn't resize Resultsarray");
			return -3;
		}

		file = *((struct flEntry *)getArrayItem(results, counter));
		logmsg(ap->semid, ap->logfd, LOGLEVEL_DEBUG, 
				"Array Memory got this: %s\n%d\n%s\n%lu - entry no %d\n",
			 	putIP((struct sockaddr *)&file.ip), getPort((struct sockaddr *) &file.ip),
				file.filename, file.size, results->itemcount);
		counter++;
	}
	return counter;
}
Example #21
0
static int writeFontInfo(ufwCtx h, abfTopDict *top) {
    char buffer[FILENAME_MAX];
    char buffer2[FILENAME_MAX];
    abfFontDict *fontDict0;
    abfPrivateDict *privateDict;
    int i;

    if (h->lastiFD != ABF_UNSET_INT)
        fontDict0 = &(top->FDArray.array[h->lastiFD]);
    else
        fontDict0 = &(top->FDArray.array[0]);
    privateDict = &(fontDict0->Private);

    /* Set error handler */
    DURING_EX(h->err.env)

    h->state = 1; /* Indicates writing to dst stream */

    /* Open fontinfo.plist file as dst stream */

    sprintf(buffer, "%s", "fontinfo.plist");
    h->cb.stm.clientFileName = buffer;
    h->stm.dst = h->cb.stm.open(&h->cb.stm, UFW_DST_STREAM_ID, 0);
    if (h->stm.dst == NULL)
        fatal(h, ufwErrDstStream);

    writeLine(h, XML_HEADER);
    writeLine(h, PLIST_DTD_HEADER);
    writeLine(h, "<plist version=\"1.0\">");
    writeLine(h, "<dict>");

    /* This is what I care about the most. Add the rest in the order of the
     UFO 3 spec. */
    writeLine(h, "\t<key>postscriptFontName</key>");
    if (top->sup.flags & ABF_CID_FONT) {
        sprintf(buffer, "\t<string>%s</string>", top->cid.CIDFontName.ptr);
        writeLine(h, buffer);
        setStyleName(buffer2, top->cid.CIDFontName.ptr);
        writeLine(h, "\t<key>styleName</key>");
        sprintf(buffer, "\t<string>%s</string>", buffer2);
        writeLine(h, buffer);
    } else {
        sprintf(buffer, "\t<string>%s</string>", fontDict0->FontName.ptr);
        writeLine(h, buffer);
        setStyleName(buffer2, fontDict0->FontName.ptr);
        writeLine(h, "\t<key>styleName</key>");
        sprintf(buffer, "\t<string>%s</string>", buffer2);
        writeLine(h, buffer);
    }

    if (top->FamilyName.ptr != NULL) {
        writeLine(h, "\t<key>familyName</key>");
        sprintf(buffer, "\t<string>%s</string>", top->FamilyName.ptr);
        writeLine(h, buffer);
    }

    if (top->sup.flags & ABF_CID_FONT) {
        if (top->cid.CIDFontVersion != 0) {
            char versionStr[32];
            sprintf(versionStr, "%.3f", top->cid.CIDFontVersion);
            setVersionMajor(buffer2, versionStr);
            writeLine(h, "\t<key>versionMajor</key>");
            sprintf(buffer, "\t<integer>%s</integer>", buffer2);
            writeLine(h, buffer);
            setVersionMinor(buffer2, versionStr);
            writeLine(h, "\t<key>versionMinor</key>");
            sprintf(buffer, "\t<integer>%s</integer>", buffer2);
            writeLine(h, buffer);
        }
    } else {
        if (top->version.ptr != NULL) {
            setVersionMajor(buffer2, top->version.ptr);
            writeLine(h, "\t<key>versionMajor</key>");
            sprintf(buffer, "\t<integer>%s</integer>", buffer2);
            writeLine(h, buffer);
            setVersionMinor(buffer2, top->version.ptr);
            writeLine(h, "\t<key>versionMinor</key>");
            sprintf(buffer, "\t<integer>%s</integer>", buffer2);
            writeLine(h, buffer);
        }
    }

    if (top->Copyright.ptr != NULL) {
        writeLine(h, "\t<key>copyright</key>");
        sprintf(buffer, "\t<string>%s</string>", top->Copyright.ptr);
        writeLine(h, buffer);
    }

    if (top->Notice.ptr != NULL) {
        writeLine(h, "\t<key>trademark</key>");
        sprintf(buffer, "\t<string>%s</string>", top->Notice.ptr);
        writeLine(h, buffer);
    }

    writeLine(h, "\t<key>unitsPerEm</key>");
    if (fontDict0->FontMatrix.cnt > 0) {
        sprintf(buffer, "\t<integer>%d</integer>",
                (int)round(1.0 / fontDict0->FontMatrix.array[0]));
        writeLine(h, buffer);

    } else {
        writeLine(h, "\t<integer>1000</integer>");
    }

    if (top->ItalicAngle != cff_DFLT_ItalicAngle) {
        writeLine(h, "\t<key>italicAngle</key>");
        sprintf(buffer, "\t<real>%.8f</real>", top->ItalicAngle);
        writeLine(h, buffer);
    }

    /* Now for all the other PostScript-specific UFO data */
    if (top->FullName.ptr != NULL) {
        writeLine(h, "\t<key>postscriptFullName</key>");
        sprintf(buffer, "\t<string>%s</string>", top->FullName.ptr);
        writeLine(h, buffer);
    }

    if (top->Weight.ptr != NULL) {
        writeLine(h, "\t<key>postscriptWeightName</key>");
        sprintf(buffer, "\t<string>%s</string>", top->Weight.ptr);
        writeLine(h, buffer);
    }

    if (top->UnderlinePosition != cff_DFLT_UnderlinePosition) {
        writeLine(h, "\t<key>postscriptUnderlinePosition</key>");
        sprintf(buffer, "\t<integer>%d</integer>", (int)round(0.5 + top->UnderlinePosition));
        writeLine(h, buffer);
    }

    if (top->UnderlineThickness != cff_DFLT_UnderlineThickness) {
        writeLine(h, "\t<key>postscriptUnderlineThickness</key>");
        sprintf(buffer, "\t<integer>%d</integer>", (int)round(0.5 + top->UnderlineThickness));
        writeLine(h, buffer);
    }

    if ((top->isFixedPitch != cff_DFLT_isFixedPitch) && (top->isFixedPitch > 0)) {
        writeLine(h, "\t<key>postscriptIsFixedPitch</key>");
        writeLine(h, "\t<true/>");
    }

    /* All the Blue values */
    if (privateDict->BlueValues.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptBlueValues</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->BlueValues.cnt; i++) {
            float stem = privateDict->BlueValues.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    }

    if (privateDict->OtherBlues.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptOtherBlues</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->OtherBlues.cnt; i++) {
            float stem = privateDict->OtherBlues.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    }

    if (privateDict->FamilyBlues.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptFamilyBlues</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->FamilyBlues.cnt; i++) {
            float stem = privateDict->FamilyBlues.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    }

    if (privateDict->FamilyOtherBlues.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptFamilyOtherBlues</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->FamilyOtherBlues.cnt; i++) {
            float stem = privateDict->FamilyOtherBlues.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    }

    if (privateDict->StemSnapH.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptStemSnapH</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->StemSnapH.cnt; i++) {
            float stem = privateDict->StemSnapH.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    } else if (privateDict->StdHW != ABF_UNSET_REAL) {
        float stem = privateDict->StdHW;
        writeLine(h, "\t<key>postscriptStemSnapH</key>");
        writeLine(h, "\t<array>");
        if (stem == ((int)stem))
            sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
        else
            sprintf(buffer, "\t\t<real>%.2f</real>", stem);
        writeLine(h, buffer);
        writeLine(h, "\t</array>");
    }

    if (privateDict->StemSnapV.cnt != ABF_EMPTY_ARRAY) {
        writeLine(h, "\t<key>postscriptStemSnapV</key>");
        writeLine(h, "\t<array>");
        for (i = 0; i < privateDict->StemSnapV.cnt; i++) {
            float stem = privateDict->StemSnapV.array[i];
            if (stem == ((int)stem))
                sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
            else
                sprintf(buffer, "\t\t<real>%.2f</real>", stem);
            writeLine(h, buffer);
        }
        writeLine(h, "\t</array>");
    } else if (privateDict->StdVW != ABF_UNSET_REAL) {
        float stem = privateDict->StdVW;
        writeLine(h, "\t<key>postscriptStemSnapV</key>");
        writeLine(h, "\t<array>");
        if (stem == ((int)stem))
            sprintf(buffer, "\t\t<integer>%d</integer>", (int)stem);
        else
            sprintf(buffer, "\t\t<real>%.2f</real>", stem);
        writeLine(h, buffer);
        writeLine(h, "\t</array>");
    }

    if (privateDict->BlueScale != ABF_UNSET_REAL) {
        char *p;
        char valueBuffer[50];
        /* 8 places is as good as it gets when converting ASCII real numbers->float-> ASCII real numbers, as happens to all the  PrivateDict values.*/
        sprintf(valueBuffer, "%.8f", privateDict->BlueScale);
        p = strchr(valueBuffer, '.');
        if (p != NULL) {
            /* Have decimal point. Remove trailing zeroes.*/
            int l = strlen(p);
            p += l - 1;
            while (*p == '0') {
                *p = '\0';
                p--;
            }
            if (*p == '.') {
                *p = '\0';
            }
        }

        writeLine(h, "\t<key>postscriptBlueScale</key>");
        sprintf(buffer, "\t<real>%s</real>", valueBuffer);
        writeLine(h, buffer);
    }

    if (privateDict->BlueShift != ABF_UNSET_REAL) {
        writeLine(h, "\t<key>postscriptBlueShift</key>");
        sprintf(buffer, "\t<integer>%d</integer>", (int)(0.5 + privateDict->BlueShift));
        writeLine(h, buffer);
    }

    if (privateDict->BlueFuzz != ABF_UNSET_REAL) {
        writeLine(h, "\t<key>postscriptBlueFuzz</key>");
        sprintf(buffer, "\t<integer>%d</integer>", (int)(0.5 + privateDict->BlueFuzz));
        writeLine(h, buffer);
    }

    if ((privateDict->ForceBold != ABF_UNSET_INT) && (privateDict->ForceBold > 0)) {
        writeLine(h, "\t<key>postscriptForceBold</key>");
        writeLine(h, "\t<true/>");
    }

    /* Finish the file */
    writeLine(h, "</dict>");
    writeLine(h, "</plist>");
    flushBuf(h);

    /* Close dst stream */
    if (h->cb.stm.close(&h->cb.stm, h->stm.dst) == -1)
        return ufwErrDstStream;

    HANDLER
    if (h->stm.dst)
        h->cb.stm.close(&h->cb.stm, h->stm.dst);
    return Exception.Code;

    END_HANDLER

    return ufwSuccess;
}
Example #22
0
int Java5Lex::getNextLexeme() {
  int  state           = 0;     // Current state
  int  lastAcceptState = 0;     // Most recently seen accept state
  int  prevState;               // State before lastAcceptState
  int  nextState;               // Next state
  unsigned int  lookahead;      // Lookahead character
  int  anchor;                  // Anchor mode for most recently seen accepting state

  unTerminateLexeme();
  initMore();
  markStart();

  for(;;) {
    // Check end of file. If there's an unprocessed accepting state,
    // lastAcceptState will be nonzero. In this case, ignore EOF for now so
    // that you can do the accepting action; otherwise, try to open another
    // file and return if you can't.

    for(;;) {
      if(((int)(lookahead = look(1))) != EOF) {
        assert(lookahead < 256);
        nextState = nextState(state, lookahead);
        break;
      } else if(lastAcceptState != 0) {   // still something to do
        nextState = -1;
        break;
      } else if(isWrap()) {               // another file?
        terminateLexeme();
        return 0;                         // EOI
      }
    }
    if(m_debug) {
      debugState(_T("--------"), state, lookahead);
    }

    if(nextState != -1) {
      if(advance() < 0) {                 // Buffer full
        const TCHAR *tooLongMessage = _T("Lexeme too long. Discarding extra characters.");
        error(getPos(), tooLongMessage);

        flush(true);

        if(m_debug) {
          debug(tooLongMessage);
          debugState(_T("--------"), state, look(1));
        }
      }

      if(anchor = lexAccept[nextState]) { // Is this an accept state
        prevState       = state;
        lastAcceptState = nextState;
        markEnd();                        // Mark input at current character
      }                                   // A subsequent gotoMark() returns us to this position.
      state = nextState;
    } else if(lastAcceptState == 0) {     // illegal input
      error(getPos(), _istprint(lookahead)?_T("Ignore bad input:'%c'"):_T("Ignore bad input:%#x"),lookahead);

      if(m_debug) {
        debug(_T("Ignore bad input:'%c'"), lookahead);
      }

      advance();
    } else {
      if(m_debug) {
        debugState(_T("accept--"), lastAcceptState, lookahead);
      }

      gotoMark();                         // Back up to previous accept state
      if(anchor & ANCHOR_END) {           // If end anchor is active
        pushback(1);                      // Push back the CR or LF
      }
      if(anchor & ANCHOR_START) {         // If start anchor is active
        moveStart();                      // Skip the leading newline
      }
      terminateLexeme();                  // Null-terminate the string

      switch(lastAcceptState) {
      case 1:
#line 124 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        ;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 2:
#line 87 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return NOT;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 3:
#line 108 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return MOD;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 4:
#line 105 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return AND;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 5:
#line 75 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return LPAR;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 6:
#line 76 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return RPAR;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 7:
#line 103 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return STAR;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 8:
#line 101 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return PLUS;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 9:
#line 82 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return COMMA;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 10:
#line 102 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return MINUS;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 11:
#line 83 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return DOT;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 12:
#line 104 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return DIV;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 13:
      case 58:
      case 61:
      case 64:
      case 66:
#line 39 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return INTEGERLITERAL;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 14:
#line 90 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return COLON;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 15:
#line 81 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return SEMICOLON;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 16:
#line 85 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return LT;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 17:
#line 84 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return ASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 18:
#line 86 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return GT;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 19:
#line 89 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return QUESTION;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 20:
#line 92 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return AT;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 21:
#line 48 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return nameOrKeyWord(getText());
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 22:
#line 79 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return LB;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 23:
#line 80 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return RB;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 24:
#line 107 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return XOR;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 25:
#line 77 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return LC;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 26:
#line 106 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return OR;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 27:
#line 78 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return RC;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 28:
#line 88 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return COMPLEMENT;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 29:
#line 96 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return NEQ;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 30:
#line 43 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return STRINGLITERAL;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 31:
#line 119 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return MODASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 32:
#line 97 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return ANDAND;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 33:
#line 116 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return ANDASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 34:
#line 114 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return STARASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 35:
#line 99 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return PLUSPLUS;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 36:
#line 112 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return PLUSASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 37:
#line 100 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return MINUSMINUS;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 38:
#line 113 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return MINUSASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 39:
      case 59:
      case 62:
#line 41 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return FLOATLITERAL;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 40:
#line 50 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        { int i;
        							  SourcePosition startpos = getPos();
        							  while(i = input()) {
        							    if(i < 0) {
        							      flushBuf();  /* Discard lexeme. */
        							    } else if(i == '*' && look(1) == '/') {
        							     input();
        							     break;       /* Recognized comment.*/
        							    }
        							  }
        							  if(i == 0) {
        							    error( startpos,_T("End of file in comment\n") );
                                      }
        							}
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 41:
#line 65 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        { int i;
        							  while(i = input()) {
        							    if(i < 0) {
        							      flushBuf();  /* Discard lexeme. */
        							    } else if(i == '\n') {
        							      break;
        							    }
                                      }
        							}
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 42:
#line 115 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return DIVASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 43:
#line 109 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return SHL;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 44:
#line 94 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return LE;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 45:
#line 93 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return EQ;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 46:
#line 95 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return GE;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 47:
#line 110 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return SSHR;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 48:
#line 118 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return XORASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 49:
#line 117 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return ORASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 50:
#line 98 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return OROR;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 51:
#line 45 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return CHARACTERLITERAL;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 52:
#line 91 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return ELLIPSIS;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 53:
#line 120 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return SHLASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 54:
#line 121 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return SSHRASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 55:
#line 111 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return USHR;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;
      case 56:
#line 122 "C:\\mytools2015\\ParserGen\\java\\Java5.lex"
        return USHRASSIGN;
#line 94 "C:\\mytools2015\\parsergen\\lib\\lexgencpp.par"
        break;

      default:
        throwException(_T("%s:Unknown accept state:%d, text=<%s>"), __TFUNCTION__, lastAcceptState,getText());
        break;
      }

      unTerminateLexeme();
      lastAcceptState = 0;

      if(isMore()) {
        state = prevState;                // Back up
        initMore();
      } else {
        state = 0;
        markStart();
      }
    }
  }
}
Example #23
0
/*!

*/
int
gzfilebuf::sync()
{
    return flushBuf() ? 0 : -1;
}
void ServerOutputStream::close()
{
    flushBuf();
    DefaultOutputStream::close();
}