예제 #1
0
int Controller::ReadChannelLabels()
{
   buf_tokens_.clear();
   string label;

   Purge();
   Send("LAMS");
   do {
      ReceiveOneLine();
      buf_tokens_.push_back(buf_string_);
   }
      while(! buf_string_.empty());
   
   
   for (unsigned int i=0;i<buf_tokens_.size();i++)
   {
      if (buf_tokens_[i].substr(0,3).compare("LAM")==0) {
         channelLetters_.push_back(buf_tokens_[i][4]); // Read 4th character
         string label = buf_tokens_[i].substr(6);
         StripString(label);
         channelLabels_.push_back(label);
      }
   }

   if (channelLabels_.size() == 0)
	   return DEVICE_ERR;
   else
	   return DEVICE_OK;
}
예제 #2
0
bool DbgGdb::FilterMessage( const wxString &msg )
{
    wxString tmpmsg ( msg );
    StripString( tmpmsg );
    tmpmsg.Trim().Trim( false );

    if ( tmpmsg.Contains( wxT( "Variable object not found" ) ) || msg.Contains( wxT( "Variable object not found" ) ) ) {
        return true;
    }

    if ( tmpmsg.Contains( wxT( "mi_cmd_var_create: unable to create variable object" ) )||msg.Contains( wxT( "mi_cmd_var_create: unable to create variable object" ) ) ) {
        return true;
    }

    if ( tmpmsg.Contains( wxT( "Variable object not found" ) )|| msg.Contains( wxT( "Variable object not found" ) ) ) {
        return true;
    }

    if ( tmpmsg.Contains( wxT( "No symbol \"this\" in current context" ) )||msg.Contains( wxT( "No symbol \"this\" in current context" ) ) ) {
        return true;
    }

    if ( tmpmsg.Contains( wxT( "*running,thread-id" ) ) ) {
        return true;
    }

    if ( tmpmsg.StartsWith( wxT( ">" ) )||msg.StartsWith( wxT( ">" ) ) ) {
        // shell line
        return true;
    }
    return false;
}
Wtroka CSitFactInterpretation::ToString() const
{
    Wtroka str;
    for (size_t i = 0; i < m_Words.GetMultiWordsCount(); ++i) {
        const CWord* pW = &m_Words.GetOriginalWord(i);
        if (i > 0 && (!pW->IsPunct() || pW->IsOpenBracket() || pW->IsCloseBracket()))
            str += ' ';
        str += pW->GetOriginalText();
    }
    return StripString(str);
}
예제 #4
0
void CProcessor::InitInterviewFile(Stroka strNameFile)
{
    if (strNameFile.empty())
        return;
    if (!PathHelper::Exists(strNameFile))
        ythrow yexception() << "Can't open name dic.";
    TBufferedFileInput file(strNameFile);

    Stroka str;
    while (file.ReadLine(str)) {
        TStringBuf line(str);
        line = StripString(line);
        if (line.empty())
            continue;

        TStringBuf url, fio;
        if (!line.SplitImpl('\t', url, fio))
            continue;

        url = StripString(url);
        fio = StripString(fio);
        InterviewUrl2Fio[ToString(url)] = CharToWide(ToString(fio), m_Parm.GetInputEncoding());
    }
}
예제 #5
0
bool CQuotesFinder::CreateQuoteValue(const Wtroka& quoteStr, CFactFields& factFields) const
{
    DECLARE_STATIC_RUS_WORD(kChto, "что ");
    DECLARE_STATIC_RUS_WORD(kChtoby, "чтобы ");

    Wtroka qstr = quoteStr;

    CTextWS QuoteWS;
    if (qstr.has_prefix(kChto))
        qstr.erase(0,4);
    if (qstr.has_prefix(kChtoby))
        qstr.erase(0,6);
    if (qstr.empty())
         return false;
    qstr = StripString(qstr);
    if (qstr.size() > 1 && qstr[0] =='"' && qstr.back() =='"')
        qstr = qstr.substr(1, qstr.size() - 2);
    qstr = StripString(qstr);

    QuoteWS.AddLemma(SWordSequenceLemma(qstr));
    QuoteWS.SetArtificialPair(CWordsPair(0,0));
    factFields.AddValue(CFactFields::QuoteValue, QuoteWS);
    return true;
}
예제 #6
0
Wtroka    CFactSynGroup::ToString() const
{
    Wtroka Result;
    for (size_t i=0; i <m_Children.size(); i++) {
        CPrimitiveGroup* pPrimGroup = dynamic_cast<CPrimitiveGroup*>(m_Children[i]);
        if (pPrimGroup)
            Result += pPrimGroup->GetMainWord()->GetText();
        else {
            CFactSynGroup* pGroup = dynamic_cast<CFactSynGroup*>(m_Children[i]);
            if (pGroup)
                Result += pGroup->ToString();
        }
        Result += ' ';
    };
    return StripString(Result);
};
예제 #7
0
Stroka CSentence::ToHTMLColorString(const yvector<CWordsPair>& wp, const Stroka& sColor, ECharset encoding) const
{
    Stroka str;
    for (size_t i = 0; i + 1 <= m_words.size(); ++i) {
        CWord* pW = m_words[i].Get();
        for (size_t j = 0; j < wp.size(); ++j)
            if (wp[j].FirstWord() == (int)i)
                str += Substitute("<font color=\"$0\">", sColor);
        if (i > 0 && (!pW->IsPunct() || pW->IsOpenBracket() || pW->IsCloseBracket()))
            str += " ";
        str += NStr::Encode(pW->GetOriginalText(), encoding);
        for (size_t j = 0; j < wp.size(); ++j)
            if (wp[j].LastWord() == (int)i)
                str += "</font>";
    }
    return StripString(str);
}
bool CAgencyInfoRetriver::GetAgNameByDoc(int iDoc, int& agId, Stroka& agName)
{
    if (!m_DocId2AgNameFile.IsOpen())
        return false;
    if (m_iLast_d2a.DocId != -1) {
        if (iDoc == m_iLast_d2a.DocId) {
            agId = m_iLast_d2a.AgId;
            agName = m_iLast_d2a.AgName;
            m_iLast_d2a.DocId = -1;
            return true;
        } else {
            return false;
        }
    }

    TDoc2Ag d2a;
    Stroka s;
    bool bFound = false;
    TBufferedFileInput file(m_DocId2AgNameFile);
    while (file.ReadLine(s)) {
        TStrokaTokenizer tokenizer(s, "\t");

        if (!tokenizer.NextAsNumber(d2a.DocId) || !tokenizer.NextAsNumber(d2a.AgId) || !tokenizer.NextAsString(d2a.AgName))
            ythrow yexception() << "Tab delimited DocId, AgencyId, AgencyName are expected in d2a file";

        d2a.AgName = ToString(StripString(d2a.AgName));
        if (d2a.AgName.length() <= 1)
            ythrow yexception() << "Emtpy AgencyName for AgencyId = " << d2a.AgId << " was found in d2a file";

        if (d2a.DocId > iDoc) {
            m_iLast_d2a = d2a;
            break;
        } else if (d2a.DocId == iDoc) {
            bFound = true;
            break;
        }
    }

    if (bFound) {
        agId = d2a.AgId;
        agName = d2a.AgName;
        return true;
    } else
        return false;
}
예제 #9
0
bool CQuotesFinder::AddQuoteFact(const SValenciesValues& VerbCommunic, CSentenceRusProcessor* pSent,
                                 const Wtroka& QuoteStr, const yvector<SFactAddress>& FioInQuotes, SLeadInfo LeadInfo)
{
    Wtroka qstr = StripString(QuoteStr);
    if (qstr.size() < 3)
        return false;

    if (!(LeadInfo.m_iLastSent == -1 && LeadInfo.m_iFirstSent == -1) &&
        !(LeadInfo.m_iFirstSent >= 0 && LeadInfo.m_iLastSent >= 0))
        ythrow yexception() << "CQuotesFinder::AddQuoteFact : bad lead info";

    if (m_bCreateDBFact) {
        DECLARE_STATIC_RUS_WORD(kSUB, "СУБ");
        if (!AddQuoteDBFact(VerbCommunic.GetValue(kSUB), pSent, qstr, LeadInfo, true))
            return false;

        for (size_t i=0; i < FioInQuotes.size(); i++)
            if (!AddQuoteDBFact(FioInQuotes[i], GetSentPrc(FioInQuotes[i].m_iSentNum), qstr, LeadInfo, false))
                return false;
    } else
        AddSimpleQuoteFact(VerbCommunic, pSent, qstr, LeadInfo);
    return true;
}
예제 #10
0
파일: dng.c 프로젝트: 0xPr0xy/ImageMagick
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   R e a d D N G I m a g e                                                   %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  ReadDNGImage() reads an binary file in the Digital Negative format and
%  returns it.  It allocates the memory necessary for the new Image structure
%  and returns a pointer to the new image. 
%
%  The format of the ReadDNGImage method is:
%
%      Image *ReadDNGImage(const ImageInfo *image_info,
%        ExceptionInfo *exception)
%
%  A description of each parameter follows:
%
%    o image_info: the image info.
%
%    o exception: return any errors or warnings in this structure.
%
*/
static Image *ReadDNGImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
  ExceptionInfo
    *sans_exception;

  Image
    *image;

  ImageInfo
    *read_info;

  MagickBooleanType
    status;

  /*
    Open image file.
  */
  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);
  assert(exception->signature == MagickSignature);
  image=AcquireImage(image_info);
  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
  if (status == MagickFalse)
    {
      image=DestroyImageList(image);
      return((Image *) NULL);
    }
  (void) CloseBlob(image);
  (void) DestroyImageList(image);
  /*
    Convert DNG to PPM with delegate.
  */
  image=AcquireImage(image_info);
  read_info=CloneImageInfo(image_info);
  (void) InvokeDelegate(read_info,image,"dng:decode",(char *) NULL,exception);
  image=DestroyImage(image);
  (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.png",
    read_info->unique);
  sans_exception=AcquireExceptionInfo();
  image=ReadImage(read_info,sans_exception);
  sans_exception=DestroyExceptionInfo(sans_exception);
  if (image == (Image *) NULL)
    {
      (void) FormatMagickString(read_info->filename,MaxTextExtent,"%s.ppm",
        read_info->unique);
      image=ReadImage(read_info,exception);
    }
  (void) RelinquishUniqueFileResource(read_info->filename);
  if (image != (Image *) NULL)
    {
      char
        filename[MaxTextExtent],
        *xml;

      ExceptionInfo
        *sans;

      (void) CopyMagickString(image->magick,read_info->magick,MaxTextExtent);
      (void) FormatMagickString(filename,MaxTextExtent,"%s.ufraw",
        read_info->unique);
      sans=AcquireExceptionInfo();
      xml=FileToString(filename,MaxTextExtent,sans);
      (void) RelinquishUniqueFileResource(filename);
      if (xml != (char *) NULL)
        {
          XMLTreeInfo
           *ufraw;

          /*
            Inject 
          */
          ufraw=NewXMLTree(xml,sans);
          if (ufraw != (XMLTreeInfo *) NULL)
            {
              char
                *content,
                property[MaxTextExtent];

              const char
                *tag;

              XMLTreeInfo
                *next;

              if (image->properties == (void *) NULL)
                ((Image *) image)->properties=NewSplayTree(
                  CompareSplayTreeString,RelinquishMagickMemory,
                  RelinquishMagickMemory);
              next=GetXMLTreeChild(ufraw,(const char *) NULL);
              while (next != (XMLTreeInfo *) NULL)
              {
                tag=GetXMLTreeTag(next);
                if (tag == (char *) NULL)
                  tag="unknown";
                (void) FormatMagickString(property,MaxTextExtent,"dng:%s",tag);
                content=ConstantString(GetXMLTreeContent(next)); 
                StripString(content);
                if ((LocaleCompare(tag,"log") != 0) &&
                    (LocaleCompare(tag,"InputFilename") != 0) &&
                    (LocaleCompare(tag,"OutputFilename") != 0) &&
                    (LocaleCompare(tag,"OutputType") != 0) &&
                    (strlen(content) != 0))
                  (void) AddValueToSplayTree((SplayTreeInfo *)
                    ((Image *) image)->properties,ConstantString(property),
                    content);
                next=GetXMLTreeSibling(next);
              }
              ufraw=DestroyXMLTree(ufraw);
            }
          xml=DestroyString(xml);
        }
      sans=DestroyExceptionInfo(sans);
    }
  read_info=DestroyImageInfo(read_info);
  return(image);
}
예제 #11
0
void DbgGdb::DoProcessAsyncCommand( wxString &line, wxString &id )
{
    if ( line.StartsWith( wxT( "^error" ) ) ) {

        // the command was error, for example:
        // finish in the outer most frame
        // print the error message and remove the command from the queue
        DbgCmdHandler *handler = PopHandler( id );
        bool errorProcessed (false);

        if ( handler && handler->WantsErrors() ) {
            errorProcessed = handler->ProcessOutput( line );
        }

        if ( handler ) {
            delete handler;
        }

        StripString( line );

        //We also need to pass the control back to the program
        if (!errorProcessed) {
            m_observer->UpdateGotControl( DBG_CMD_ERROR );
        }

        if ( !FilterMessage( line ) && m_info.enableDebugLog ) {
            m_observer->UpdateAddLine( line );
        }

    } else if ( line.StartsWith( wxT( "^done" ) ) || line.StartsWith( wxT( "^connected" ) ) ) {
        //The synchronous operation was successful, results are the return values.
        DbgCmdHandler *handler = PopHandler( id );
        if ( handler ) {
            handler->ProcessOutput( line );
            delete handler;
        }

    } else if ( line.StartsWith( wxT( "^running" ) ) ) {
        //asynchronous command was executed
        //send event that we dont have the control anymore
        m_observer->UpdateLostControl();

    } else if ( line.StartsWith( wxT( "*stopped" ) ) ) {
        //get the stop reason,
        if ( line == wxT( "*stopped" ) ) {
            if ( m_bpList.empty() ) {

                ExecuteCmd( wxT( "set auto-solib-add off" ) );
                ExecuteCmd( wxT( "set stop-on-solib-events 0" ) );

            } else {

                //no reason for the failure, this means that we stopped due to
                //hitting a loading of shared library
                //try to place all breakpoints which previously failed
                SetBreakpoints();
            }

            Continue();

        } else {
            //GDB/MI Out-of-band Records
            //caused by async command, this line indicates that we have the control back
            DbgCmdHandler *handler = PopHandler( id );
            if ( handler ) {
                handler->ProcessOutput( line );
                delete handler;
            }
        }
    }
}
예제 #12
0
void DbgGdb::Poke()
{
    static wxRegEx reCommand( wxT( "^([0-9]{8})" ) );



    //poll the debugger output
    wxString curline;
    if ( !m_gdbProcess || m_gdbOutputArr.IsEmpty() ) {
        return;
    }

    while ( DoGetNextLine( curline ) ) {

        GetDebugeePID(curline);

        // For string manipulations without damaging the original line read
        wxString tmpline ( curline );
        StripString( tmpline );
        tmpline.Trim().Trim( false );
        if ( m_info.enableDebugLog ) {
            //Is logging enabled?

            if ( curline.IsEmpty() == false && !tmpline.StartsWith( wxT( ">" ) ) ) {
                wxString strdebug( wxT( "DEBUG>>" ) );
                strdebug << curline;
#if DBG_LOG
                if(gfp.IsOpened()) {
                    gfp.Write(strdebug);
                    gfp.Flush();
                }
#else
                m_observer->UpdateAddLine( strdebug );
#endif
            }
        }

        if ( reConnectionRefused.Matches( curline ) ) {
            StripString( curline );
#ifdef __WXGTK__
            m_consoleFinder.FreeConsole();
#endif
            m_observer->UpdateAddLine( curline );
            m_observer->UpdateGotControl( DBG_EXITED_NORMALLY );
            return;
        }

        // Check for "Operation not permitted" usually means
        // that the process does not have enough permission to
        // attach to the process
        if( curline.Contains(wxT("Operation not permitted")) ) {
#ifdef __WXGTK__
            m_consoleFinder.FreeConsole();
#endif
            m_observer->UpdateAddLine( _("Failed to start debugger: permission denied") );
            m_observer->UpdateGotControl( DBG_EXITED_NORMALLY );
            return;

        }

        if( tmpline.StartsWith( wxT( ">" ) ) ) {
            // Shell line, probably user command line
            continue;
        }

        if ( curline.StartsWith( wxT( "~" ) ) || curline.StartsWith( wxT( "&" ) ) || curline.StartsWith("@") ) {

            // lines starting with ~ are considered "console stream" message
            // and are important to the CLI handler
            bool consoleStream( false );
            bool targetConsoleStream(false);

            if ( curline.StartsWith( wxT( "~" ) ) ) {
                consoleStream = true;
            }

            if ( curline.StartsWith( wxT( "@" ) ) ) {
                targetConsoleStream = true;
            }

            // Filter out some gdb error lines...
            if ( FilterMessage( curline ) ) {
                continue;
            }

            StripString( curline );

            // If we got a valid "CLI Handler" instead of writing the output to
            // the output view, concatenate it into the handler buffer
            if ( targetConsoleStream ) {
                m_observer->UpdateAddLine( curline );

            } else if ( consoleStream && GetCliHandler()) {
                GetCliHandler()->Append( curline );

            } else if ( consoleStream ) {
                // log message
                m_observer->UpdateAddLine( curline );

            }

        } else if ( reCommand.Matches( curline ) ) {

            //not a gdb message, get the command associated with the message
            wxString id = reCommand.GetMatch( curline, 1 );

            if ( GetCliHandler() && GetCliHandler()->GetCommandId() == id ) {
                // probably the "^done" message of the CLI command
                GetCliHandler()->ProcessOutput( curline );
                SetCliHandler( NULL ); // we are done processing the CLI

            } else {
                //strip the id from the line
                curline = curline.Mid( 8 );
                DoProcessAsyncCommand( curline, id );

            }
        } else if ( curline.StartsWith( wxT( "^done" ) ) || curline.StartsWith( wxT( "*stopped" ) ) ) {
            //Unregistered command, use the default AsyncCommand handler to process the line
            DbgCmdHandlerAsyncCmd cmd( m_observer, this );
            cmd.ProcessOutput( curline );
        } else {
            //Unknow format, just log it
            if( m_info.enableDebugLog && !FilterMessage( curline ) ) {
                m_observer->UpdateAddLine( curline );
            }
        }
    }
}
예제 #13
0
std::string StripString(const StringPiece& s, const char* remove, char replacewith)
{
    std::string res = s.as_string();
    StripString(&res, remove, replacewith);
    return res;
}
예제 #14
0
void DbgGdb::Poke()
{
	static wxRegEx reCommand(wxT("^([0-9]{8})"));

	//poll the debugger output
	wxString line;
	if ( !m_gdbProcess || m_gdbOutputArr.IsEmpty() ) {
		return;
	}

	if (m_debuggeePid == wxNOT_FOUND) {
		if (GetIsRemoteDebugging()) {
			m_debuggeePid = m_gdbProcess->GetPid();
			
		} else {
			std::vector<long> children;
			ProcUtils::GetChildren(m_gdbProcess->GetPid(), children);
			std::sort(children.begin(), children.end());
			if (children.empty() == false) {
				m_debuggeePid = children.at(0);
			}

			if (m_debuggeePid != wxNOT_FOUND) {
				wxString msg;
				msg << wxT("Debuggee process ID: ") << m_debuggeePid;
				m_observer->UpdateAddLine(msg);
			}
		}
	}

	while ( DoGetNextLine( line ) ) {

		// For string manipulations without damaging the original line read
		wxString tmpline ( line );
		StripString( tmpline );
		tmpline.Trim().Trim(false);

		if (m_info.enableDebugLog) {
			//Is logging enabled?

			if (line.IsEmpty() == false && !tmpline.StartsWith(wxT(">")) ) {
				wxString strdebug(wxT("DEBUG>>"));
				strdebug << line;
				m_observer->UpdateAddLine(strdebug);
			}
		}

		if (reConnectionRefused.Matches(line)) {
			StripString(line);
#ifdef __WXGTK__
			m_consoleFinder.FreeConsole();
#endif
			m_observer->UpdateAddLine(line);
			m_observer->UpdateGotControl(DBG_EXITED_NORMALLY);
			return;
		}

		if( tmpline.StartsWith(wxT(">")) ) {
			// Shell line, probably user command line
			continue;
		}

		if (line.StartsWith(wxT("~")) || line.StartsWith(wxT("&"))) {

			// lines starting with ~ are considered "console stream" message
			// and are important to the CLI handler
			bool consoleStream(false);
			if ( line.StartsWith(wxT("~")) ) {
				consoleStream = true;
			}

			// Filter out some gdb error lines...
			if (FilterMessage(line)) {
				continue;
			}

			StripString( line );

			// If we got a valid "CLI Handler" instead of writing the output to
			// the output view, concatenate it into the handler buffer
			if ( GetCliHandler() && consoleStream ) {
				GetCliHandler()->Append( line );
			} else if ( consoleStream ) {
				// log message
				m_observer->UpdateAddLine( line );
			}
		} else if (reCommand.Matches(line)) {

			//not a gdb message, get the command associated with the message
			wxString id = reCommand.GetMatch(line, 1);

			if ( GetCliHandler() && GetCliHandler()->GetCommandId() == id ) {
				// probably the "^done" message of the CLI command
				GetCliHandler()->ProcessOutput( line );
				SetCliHandler( NULL ); // we are done processing the CLI

			} else {
				//strip the id from the line
				line = line.Mid(8);
				DoProcessAsyncCommand(line, id);

			}
		} else if (line.StartsWith(wxT("^done")) || line.StartsWith(wxT("*stopped"))) {
			//Unregistered command, use the default AsyncCommand handler to process the line
			DbgCmdHandlerAsyncCmd cmd(m_observer);
			cmd.ProcessOutput(line);
		} else {
			//Unknow format, just log it
			if( m_info.enableDebugLog && !FilterMessage(line)) {
				m_observer->UpdateAddLine(line);
			}
		}
	}
}
예제 #15
0
static MagickBooleanType TraverseLocaleMap(const char *filename,
  XMLTreeInfo **components,XMLTreeInfo *node,const unsigned long depth,
  ExceptionInfo *exception)
{
  MagickBooleanType
    status;

  status=MagickTrue;
  if (depth >= MaxRecursionDepth)
    (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError,
      "IncludeElementNestedTooDeeply","`%s'",filename);
  else
    if (node != (XMLTreeInfo *) NULL)
      {
        XMLTreeInfo
          *child,
          *sibling;

        components[depth]=node;
        if (strcmp(GetXMLTreeTag(node),"message") == 0)
          {
            char
              *message,
              *tag;

            const char
              *attribute,
              *content;

            LocaleInfo
              *locale_info;

            register long
              i;

            locale_info=(LocaleInfo *) AcquireMagickMemory(
              sizeof(*locale_info));
            if (locale_info == (LocaleInfo *) NULL)
              ThrowFatalException(ResourceLimitFatalError,
                "MemoryAllocationFailed");
            (void) ResetMagickMemory(locale_info,0,sizeof(*locale_info));
            locale_info->path=ConstantString(filename);
            locale_info->signature=MagickSignature;
            tag=AcquireString((char *) NULL);
            for (i=1; i < (long) depth; i++)
            {
              (void) ConcatenateString(&tag,GetXMLTreeTag(components[i]));
              (void) ConcatenateString(&tag,"/");
            }
            attribute=GetXMLTreeAttribute(node,"name");
            if (attribute != (const char *) NULL)
              {
                (void) ConcatenateString(&tag,attribute);
                (void) ConcatenateString(&tag,"/");
              }
            locale_info->tag=ConstantString(tag);
            tag=DestroyString(tag);
            message=AcquireString((char *) NULL);
            content=GetXMLTreeContent(node);
            if (content != (const char *) NULL)
              {
                (void) ConcatenateString(&message,content);
                StripString(message);
              }
            locale_info->message=ConstantString(message);
            message=DestroyString(message);
            status=AddValueToSplayTree(locale_list,locale_info->tag,
              locale_info);
            if (status == MagickFalse)
              (void) ThrowMagickException(exception,GetMagickModule(),
                ResourceLimitError,"MemoryAllocationFailed","`%s'",filename);
          }
        child=GetXMLTreeChild(node,(const char *) NULL);
        if (child != (XMLTreeInfo *) NULL)
          status=TraverseLocaleMap(filename,components,child,depth+1,exception);
        sibling=GetXMLTreeOrdered(node);
        if (sibling != (XMLTreeInfo *) NULL)
          status=TraverseLocaleMap(filename,components,sibling,depth,exception);
      }
  return(status);
}
예제 #16
0
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                             %
%                                                                             %
%                                                                             %
%   N T A c q u i r e T y p e C a c h e                                       %
%                                                                             %
%                                                                             %
%                                                                             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  NTAcquireTypeCache() loads a Windows TrueType fonts.
%
%  The format of the NTAcquireTypeCache method is:
%
%      MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache)
%
%  A description of each parameter follows:
%
%    o type_cache: A linked list of fonts.
%
*/
MagickExport MagickBooleanType NTAcquireTypeCache(SplayTreeInfo *type_cache,
  ExceptionInfo *exception)
{
  HKEY
    reg_key = (HKEY) INVALID_HANDLE_VALUE;

  LONG
    res;

  int
    list_entries = 0;

  char
    buffer[MaxTextExtent],
    system_root[MaxTextExtent],
    font_root[MaxTextExtent];

  DWORD
    type,
    system_root_length;

  MagickBooleanType
    status;

  /*
    Try to find the right Windows*\CurrentVersion key, the SystemRoot and
    then the Fonts key
  */
  res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
    "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &reg_key);
  if (res == ERROR_SUCCESS) {
    system_root_length=sizeof(system_root)-1;
    res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
      (BYTE*) system_root, &system_root_length);
  }
  if (res != ERROR_SUCCESS) {
    res = RegOpenKeyExA (HKEY_LOCAL_MACHINE,
      "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0, KEY_READ, &reg_key);
    if (res == ERROR_SUCCESS) {
      system_root_length=sizeof(system_root)-1;
      res = RegQueryValueExA(reg_key,"SystemRoot",NULL, &type,
        (BYTE*)system_root, &system_root_length);
    }
  }
  if (res == ERROR_SUCCESS)
    res = RegOpenKeyExA (reg_key, "Fonts",0, KEY_READ, &reg_key);
  if (res != ERROR_SUCCESS)
    return(MagickFalse);
  *font_root='\0';
  (void) CopyMagickString(buffer,system_root,MaxTextExtent);
  (void) ConcatenateMagickString(buffer,"\\fonts\\arial.ttf",MaxTextExtent);
  if (IsPathAccessible(buffer) != MagickFalse)
    {
      (void) CopyMagickString(font_root,system_root,MaxTextExtent);
      (void) ConcatenateMagickString(font_root,"\\fonts\\",MaxTextExtent);
    }
  else
    {
      (void) CopyMagickString(font_root,system_root,MaxTextExtent);
      (void) ConcatenateMagickString(font_root,"\\",MaxTextExtent);
    }

  {
    TypeInfo
      *type_info;

    DWORD
      registry_index = 0,
      type,
      value_data_size,
      value_name_length;

    char
      value_data[MaxTextExtent],
      value_name[MaxTextExtent];

    res = ERROR_SUCCESS;

    while (res != ERROR_NO_MORE_ITEMS)
      {
        char
          *family_extent,
          token[MaxTextExtent],
          *pos,
          *q;

        value_name_length = sizeof(value_name) - 1;
        value_data_size = sizeof(value_data) - 1;
        res=RegEnumValueA(reg_key,registry_index,value_name,&value_name_length,
          0,&type,(BYTE *) value_data,&value_data_size);
        registry_index++;
        if (res != ERROR_SUCCESS)
          continue;
        if ((pos=strstr(value_name," (TrueType)")) == (char*) NULL)
          continue;
        *pos='\0';  /* Remove (TrueType) from string */
        type_info=(TypeInfo *) AcquireMagickMemory(sizeof(*type_info));
        if (type_info == (TypeInfo *) NULL)
          ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
        (void) ResetMagickMemory(type_info,0,sizeof(TypeInfo));
        type_info->path=ConstantString("Windows Fonts");
        type_info->signature=MagickSignature;
        (void) CopyMagickString(buffer,value_name,MaxTextExtent);  /* name */
        for (pos=buffer; *pos != 0; pos++)
          if (*pos == ' ')
            *pos='-';
        type_info->name=ConstantString(buffer);
        type_info->description=ConstantString(value_name);  /* fullname */
        type_info->format=ConstantString("truetype");  /* format */
        if (strchr(value_data,'\\') != (char *) NULL)  /* glyphs */
          (void) CopyMagickString(buffer,value_data,MaxTextExtent);
        else
          {
            (void) CopyMagickString(buffer,font_root,MaxTextExtent);
            (void) ConcatenateMagickString(buffer,value_data,MaxTextExtent);
          }
        LocaleLower(buffer);
        type_info->glyphs=ConstantString(buffer);
        type_info->stretch=NormalStretch;
        type_info->style=NormalStyle;
        type_info->weight=400;
        /*
          Some fonts are known to require special encodings.
        */
        if ( (LocaleCompare(type_info->name, "Symbol") == 0 ) ||
             (LocaleCompare(type_info->name, "Wingdings") == 0 ) ||
             (LocaleCompare(type_info->name, "Wingdings-2") == 0 ) ||
             (LocaleCompare(type_info->name, "Wingdings-3") == 0 ) )
          type_info->encoding=ConstantString("AppleRoman");
        family_extent=value_name;
        for (q=value_name; *q != '\0'; )
        {
            GetMagickToken(q,(const char **) &q,token);
            if (*token == '\0')
              break;

            if (LocaleCompare(token,"Italic") == 0)
              {
                type_info->style=ItalicStyle;
              }

            else if (LocaleCompare(token,"Oblique") == 0)
              {
                type_info->style=ObliqueStyle;
              }

            else if (LocaleCompare(token,"Bold") == 0)
              {
                type_info->weight=700;
              }

            else if (LocaleCompare(token,"Thin") == 0)
              {
                type_info->weight=100;
              }

            else if ( (LocaleCompare(token,"ExtraLight") == 0) ||
                      (LocaleCompare(token,"UltraLight") == 0) )
              {
                type_info->weight=200;
              }

            else if (LocaleCompare(token,"Light") == 0)
              {
                type_info->weight=300;
              }

            else if ( (LocaleCompare(token,"Normal") == 0) ||
                      (LocaleCompare(token,"Regular") == 0) )
              {
                type_info->weight=400;
              }

            else if (LocaleCompare(token,"Medium") == 0)
              {
                type_info->weight=500;
              }

            else if ( (LocaleCompare(token,"SemiBold") == 0) ||
                      (LocaleCompare(token,"DemiBold") == 0) )
              {
                type_info->weight=600;
              }

            else if ( (LocaleCompare(token,"ExtraBold") == 0) ||
                      (LocaleCompare(token,"UltraBold") == 0) )
              {
                type_info->weight=800;
              }

            else if ( (LocaleCompare(token,"Heavy") == 0) ||
                      (LocaleCompare(token,"Black") == 0) )
              {
                type_info->weight=900;
              }

            else if (LocaleCompare(token,"Condensed") == 0)
              {
                type_info->stretch = CondensedStretch;
              }

            else if (LocaleCompare(token,"Expanded") == 0)
              {
                type_info->stretch = ExpandedStretch;
              }

            else if (LocaleCompare(token,"ExtraCondensed") == 0)
              {
                type_info->stretch = ExtraCondensedStretch;
              }

            else if (LocaleCompare(token,"ExtraExpanded") == 0)
              {
                type_info->stretch = ExtraExpandedStretch;
              }

            else if (LocaleCompare(token,"SemiCondensed") == 0)
              {
                type_info->stretch = SemiCondensedStretch;
              }

            else if (LocaleCompare(token,"SemiExpanded") == 0)
              {
                type_info->stretch = SemiExpandedStretch;
              }

            else if (LocaleCompare(token,"UltraCondensed") == 0)
              {
                type_info->stretch = UltraCondensedStretch;
              }

            else if (LocaleCompare(token,"UltraExpanded") == 0)
              {
                type_info->stretch = UltraExpandedStretch;
              }

            else
              {
                family_extent=q;
              }
          }

        (void) CopyMagickString(buffer,value_name,family_extent-value_name+1);
        StripString(buffer);
        type_info->family=ConstantString(buffer);

        list_entries++;
        status=AddValueToSplayTree(type_cache,ConstantString(type_info->name),
          type_info);
        if (status == MagickFalse)
          (void) ThrowMagickException(exception,GetMagickModule(),
            ResourceLimitError,"MemoryAllocationFailed","`%s'",type_info->name);
      }
  }
  RegCloseKey(reg_key);
  return(MagickTrue);
}
예제 #17
0
파일: xpm.c 프로젝트: MarinaAndenko/MyBlog
static Image *ReadXPMImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
  char
    *grey,
    key[MaxTextExtent],
    target[MaxTextExtent],
    *xpm_buffer;

  Image
    *image;

  MagickBooleanType
    active,
    status;

  register char
    *next,
    *p,
    *q;

  register IndexPacket
    *indexes;

  register ssize_t
    x;

  register PixelPacket
    *r;

  size_t
    length;

  SplayTreeInfo
    *xpm_colors;

  ssize_t
    count,
    j,
    y;

  unsigned long
    colors,
    columns,
    rows,
    width;

  /*
    Open image file.
  */
  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);
  assert(exception->signature == MagickSignature);
  image=AcquireImage(image_info);
  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
  if (status == MagickFalse)
    {
      image=DestroyImageList(image);
      return((Image *) NULL);
    }
  /*
    Read XPM file.
  */
  length=MaxTextExtent;
  xpm_buffer=(char *) AcquireQuantumMemory((size_t) length,sizeof(*xpm_buffer));
  if (xpm_buffer == (char *) NULL)
    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
  *xpm_buffer='\0';
  p=xpm_buffer;
  while (ReadBlobString(image,p) != (char *) NULL)
  {
    if ((*p == '#') && ((p == xpm_buffer) || (*(p-1) == '\n')))
      continue;
    if ((*p == '}') && (*(p+1) == ';'))
      break;
    p+=strlen(p);
    if ((size_t) (p-xpm_buffer+MaxTextExtent) < length)
      continue;
    length<<=1;
    xpm_buffer=(char *) ResizeQuantumMemory(xpm_buffer,length+MaxTextExtent,
      sizeof(*xpm_buffer));
    if (xpm_buffer == (char *) NULL)
      break;
    p=xpm_buffer+strlen(xpm_buffer);
  }
  if (xpm_buffer == (char *) NULL)
    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
  /*
    Remove comments.
  */
  count=0;
  width=0;
  for (p=xpm_buffer; *p != '\0'; p++)
  {
    if (*p != '"')
      continue;
    count=(ssize_t) sscanf(p+1,"%lu %lu %lu %lu",&columns,&rows,&colors,&width);
    image->columns=columns;
    image->rows=rows;
    image->colors=colors;
    if (count == 4)
      break;
  }
  if ((count != 4) || (width > 10) || (image->columns == 0) ||
      (image->rows == 0) || (image->colors == 0))
    {
      xpm_buffer=DestroyString(xpm_buffer);
      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
    }
  /*
    Remove unquoted characters.
  */
  active=MagickFalse;
  q=xpm_buffer;
  while (*p != '\0')
  {
    if (*p++ == '"')
      {
        if (active != MagickFalse)
          *q++='\n';
        active=active != MagickFalse ? MagickFalse : MagickTrue;
      }
    if (active != MagickFalse)
      *q++=(*p);
  }
  *q='\0';
  /*
    Initialize image structure.
  */
  xpm_colors=NewSplayTree(CompareXPMColor,RelinquishMagickMemory,
    (void *(*)(void *)) NULL);
  if (AcquireImageColormap(image,image->colors) == MagickFalse)
    {
      xpm_buffer=DestroyString(xpm_buffer);
      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
    }
  /*
    Read image colormap.
  */
  image->depth=1;
  next=NextXPMLine(xpm_buffer);
  for (j=0; (j < (ssize_t) image->colors) && (next != (char *) NULL); j++)
  {
    MagickPixelPacket
      pixel;

    p=next;
    next=NextXPMLine(p);
    (void) CopyXPMColor(key,p,MagickMin((size_t) width,MaxTextExtent-1));
    status=AddValueToSplayTree(xpm_colors,ConstantString(key),(void *) j);
    /*
      Parse color.
    */
    (void) CopyMagickString(target,"gray",MaxTextExtent);
    q=ParseXPMColor(p+width,MagickTrue);
    if (q != (char *) NULL)
      {
        while ((isspace((int) ((unsigned char) *q)) == 0) && (*q != '\0'))
          q++;
        if ((next-q) < 0)
          break;
        if (next != (char *) NULL)
          (void) CopyXPMColor(target,q,MagickMin((size_t) (next-q),
            MaxTextExtent-1));
        else
          (void) CopyMagickString(target,q,MaxTextExtent);
        q=ParseXPMColor(target,MagickFalse);
        if (q != (char *) NULL)
          *q='\0';
      }
    StripString(target);
    grey=strstr(target,"grey");
    if (grey != (char *) NULL)
      grey[2]='a';
    if (LocaleCompare(target,"none") == 0)
      {
        image->storage_class=DirectClass;
        image->matte=MagickTrue;
      }
    status=QueryColorCompliance(target,XPMCompliance,&image->colormap[j],
      exception);
    if (status == MagickFalse)
      break;
    (void) QueryMagickColorCompliance(target,XPMCompliance,&pixel,exception);
    if (image->depth < pixel.depth)
      image->depth=pixel.depth;
  }
  if (j < (ssize_t) image->colors)
    {
      xpm_colors=DestroySplayTree(xpm_colors);
      xpm_buffer=DestroyString(xpm_buffer);
      ThrowReaderException(CorruptImageError,"CorruptImage");
    }
  j=0;
  if (image_info->ping == MagickFalse)
    {
      /*
        Read image pixels.
      */
      status=SetImageExtent(image,image->columns,image->rows);
      if (status == MagickFalse)
        {
          InheritException(exception,&image->exception);
          return(DestroyImageList(image));
        }
      for (y=0; y < (ssize_t) image->rows; y++)
      {
        p=NextXPMLine(p);
        if (p == (char *) NULL)
          break;
        r=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
        if (r == (PixelPacket *) NULL)
          break;
        indexes=GetAuthenticIndexQueue(image);
        for (x=0; x < (ssize_t) image->columns; x++)
        {
          ssize_t count=CopyXPMColor(key,p,MagickMin(width,MaxTextExtent-1));
          if (count != (ssize_t) width)
            break;
          j=(ssize_t) GetValueFromSplayTree(xpm_colors,key);
          if (image->storage_class == PseudoClass)
            SetPixelIndex(indexes+x,j);
          *r=image->colormap[j];
          p+=count;
          r++;
        }
        if (x < (ssize_t) image->columns)
          break;
        if (SyncAuthenticPixels(image,exception) == MagickFalse)
          break;
      }
      if (y < (ssize_t) image->rows)
        {
          xpm_colors=DestroySplayTree(xpm_colors);
          xpm_buffer=DestroyString(xpm_buffer);
          ThrowReaderException(CorruptImageError,"NotEnoughPixelData");
        }
    }
  /*
    Relinquish resources.
  */
  xpm_colors=DestroySplayTree(xpm_colors);
  xpm_buffer=DestroyString(xpm_buffer);
  (void) CloseBlob(image);
  return(GetFirstImageInList(image));
}
예제 #18
0
void CCommonParm::AnalizeParameter(const TStringBuf& name, const TStringBuf& value) {
    Stroka paramName = ToString(StripString(name));
    Stroka paramValue = ToString(StripString(value));

    paramName.to_lower();
}