bool wxArchive::WriteInt(int value) { if(CanStore()) { SaveChar(wxARCHIVE_HDR_INT); // save the size of the int SaveChar(sizeof(int)); // save int itself by proper casting switch(sizeof(int)) { case 1: SaveChar(value); break; case 2: SaveUint16(value); break; case 4: SaveUint32(value); break; case 8: SaveUint64(value); break; default: LogError(wxARCHIVE_ERR_ILL, wxARCHIVE_ERR_STR_SINTSIZE); break; } } return IsOk(); }
bool wxArchive::WriteUint8(wxUint8 value) { if(CanStore()) { SaveChar(wxARCHIVE_HDR_INT8); SaveChar(value); } return IsOk(); }
bool wxArchive::WriteBool(bool value) { wxUint8 nval = 0; if(CanStore()) { // set to boolean if(value) nval = 1; SaveChar(wxARCHIVE_HDR_BOOL); SaveChar(nval); } return IsOk(); }
bool wxArchive::EnterObject() { // increments the level. This will also mean // that with reading we expect to read this level. We skip all // headers until we get this level. if(IsOk()) { if(!m_writeMode) { if(CanLoad()) { m_objectLevel ++; FindCurrentEnterLevel(); } else return false; // we did not enter } else { if(CanStore()) { m_objectLevel++; SaveChar(wxARCHIVE_HDR_ENTER); } else return false; // we did not enter } } return IsOk(); }
bool wxArchive::WriteString(const wxString& value) { if(CanStore()) { // write header + string SaveChar(wxARCHIVE_HDR_STRING); SaveString(value); } return IsOk(); }
bool wxArchive::WriteArrayString(const wxArrayString& value) { if(CanStore()) { // write header + string SaveChar(wxARCHIVE_HDR_ARRSTRING); SaveUint32(value.Count()); for(size_t i = 0; i < value.Count(); i++) SaveString(value[i]); } return IsOk(); }
bool wxArchive::WriteDouble(double value) { if(CanStore()) { SaveChar(wxARCHIVE_HDR_DOUBLE); unsigned char buf[10]; #if wxUSE_APPLE_IEEE ConvertToIeeeExtended(value, (unsigned char *)buf); #else #if !defined(__VMS__) && !defined(__GNUG__) #pragma warning "wxArchive::WriteDouble() not using IeeeExtended - will not work!" #endif // fill with zeros when writing memset(buf, 0, 10); #endif m_odstr.Write(buf, 10); } return IsOk(); }
bool wxArchive::LeaveObject() { // increments the level. This will also mean // that with reading we expect to read this level. We skip all // headers until we get this level. if(IsOk()) { if(!m_writeMode) { if(CanLoad()) { m_objectLevel --; if(m_objectLevel < 0) LogError(wxARCHIVE_ERR_ILL, wxARCHIVE_ERR_STR_ILL_LEVEL); else FindCurrentLeaveLevel(); } else return false; // we did not enter } else { if(CanStore()) { m_objectLevel--; if(m_objectLevel < 0) LogError(wxARCHIVE_ERR_ILL, wxARCHIVE_ERR_STR_ILL_LEVEL); else SaveChar(wxARCHIVE_HDR_LEAVE); } else return false; // we did not enter } } return IsOk(); }
WandExport MagickBooleanType GetScriptToken(ScriptTokenInfo *token_info) { int quote, c; int state; ssize_t offset; /* EOF - no more tokens! */ if (token_info->status != TokenStatusOK) { token_info->token[0]='\0'; return(MagickFalse); } state=IN_WHITE; quote='\0'; offset=0; while(1) { /* get character */ GetChar(c); /* hash comment handling */ if ( state == IN_COMMENT ) { if ( c == '\n' ) state=IN_WHITE; continue; } if ( state == IN_WHITE ) if (c == '#' || (c == ':' && token_info->curr_column==1)) state=IN_COMMENT; /* whitespace break character */ if (strchr(" \n\r\t",c) != (char *)NULL) { switch (state) { case IN_TOKEN: token_info->token[offset]='\0'; return(MagickTrue); case IN_QUOTE: SaveChar(c); break; } continue; } /* quote character */ if (strchr("'\"",c) != (char *)NULL) { switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; case IN_TOKEN: state=IN_QUOTE; quote=c; break; case IN_QUOTE: if (c == quote) { state=IN_TOKEN; quote='\0'; } else SaveChar(c); break; } continue; } /* escape char (preserve in quotes - unless escaping the same quote) */ if (c == '\\') { if ( state==IN_QUOTE && quote == '\'' ) { SaveChar('\\'); continue; } GetChar(c); if (c == '\n' || c == '\r' ) switch (state) { case IN_COMMENT: state=IN_WHITE; /* end comment */ case IN_WHITE: case IN_TOKEN: continue; /* line continuation (outside quotes and comment) */ } switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; state=IN_TOKEN; break; case IN_QUOTE: if (c != quote && c != '\\') SaveChar('\\'); break; } SaveChar(c); continue; } /* ordinary character */ switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; state=IN_TOKEN; case IN_TOKEN: case IN_QUOTE: SaveChar(c); break; case IN_COMMENT: break; } } /* input stream has EOF or produced a fatal error */ token_info->token[offset]='\0'; if ( token_info->status != TokenStatusOK ) return(MagickFalse); /* fatal condition - no valid token */ token_info->status = TokenStatusEOF; if ( state == IN_QUOTE) token_info->status = TokenStatusBadQuotes; if ( state == IN_TOKEN) return(MagickTrue); /* token with EOF at end - no problem */ return(MagickFalse); /* in white space or in quotes - invalid token */ }
WandExport MagickBooleanType GetScriptToken(ScriptTokenInfo *token_info) { int quote, c; int state; ssize_t offset; /* EOF - no more tokens! */ if (token_info == (ScriptTokenInfo *) NULL) return(MagickFalse); if (token_info->status != TokenStatusOK) { token_info->token[0]='\0'; return(MagickFalse); } state=IN_WHITE; quote='\0'; offset=0; DisableMSCWarning(4127) while(1) RestoreMSCWarning { /* get character */ GetChar(c); /* hash comment handling */ if ( state == IN_COMMENT ) { if ( c == '\n' ) state=IN_WHITE; continue; } /* comment lines start with '#' anywhere, or ':' or '@' at start of line */ if ( state == IN_WHITE ) if ( ( c == '#' ) || ( token_info->curr_column==1 && (c == ':' || c == '@' ) ) ) state=IN_COMMENT; /* whitespace token separator character */ if (strchr(" \n\r\t",c) != (char *) NULL) { switch (state) { case IN_TOKEN: token_info->token[offset]='\0'; return(MagickTrue); case IN_QUOTE: SaveChar(c); break; } continue; } /* quote character */ if ( c=='\'' || c =='"' ) { switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; case IN_TOKEN: state=IN_QUOTE; quote=c; break; case IN_QUOTE: if (c == quote) { state=IN_TOKEN; quote='\0'; } else SaveChar(c); break; } continue; } /* escape char (preserve in quotes - unless escaping the same quote) */ if (c == '\\') { if ( state==IN_QUOTE && quote == '\'' ) { SaveChar('\\'); continue; } GetChar(c); if (c == '\n') switch (state) { case IN_COMMENT: state=IN_WHITE; /* end comment */ case IN_QUOTE: if (quote != '"') break; /* in double quotes only */ case IN_WHITE: case IN_TOKEN: continue; /* line continuation - remove line feed */ } switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; state=IN_TOKEN; break; case IN_QUOTE: if (c != quote && c != '\\') SaveChar('\\'); break; } SaveChar(c); continue; } /* ordinary character */ switch (state) { case IN_WHITE: token_info->token_line=token_info->curr_line; token_info->token_column=token_info->curr_column; state=IN_TOKEN; case IN_TOKEN: case IN_QUOTE: SaveChar(c); break; case IN_COMMENT: break; } } /* input stream has EOF or produced a fatal error */ token_info->token[offset]='\0'; if ( token_info->status != TokenStatusOK ) return(MagickFalse); /* fatal condition - no valid token */ token_info->status = TokenStatusEOF; if ( state == IN_QUOTE) token_info->status = TokenStatusBadQuotes; if ( state == IN_TOKEN) return(MagickTrue); /* token with EOF at end - no problem */ return(MagickFalse); /* in white space or in quotes - invalid token */ }