예제 #1
0
void yyerror(const char *msg)
{
    char *errMsg = strdup(msg);

    //printf("MSG: %s\n", errMsg);

    //printf("Global lineno: %d\n", globallineno);
    //printf("Last scanned token: %s\n", lasttokenscanned);
    if (strstr(msg, "Invalid input character")) {
        printf("WARNING(%d): %s: %s.  Character ignored.\n", 
               globallineno, 
               msg, 
               niceStringOut(lasttokenscanned));
        numwarnings++;
    }
    
    else {
        char *msgParts[32];
        int numParts;
        char *unexpected;
       
        // split the input
        numParts = split(errMsg, (char *)" ", msgParts);
        
        if (msgParts[3][strlen(msgParts[3])-1] == ',') 
            msgParts[3][strlen(msgParts[3])-1] = '\0';
        
        unexpected = decodeName(msgParts[3]);
        
        // print the error
        if (strcmp(unexpected, (char *)"id")==0 ||
            strcmp(unexpected, (char *)"number")==0 ||
            strcmp(unexpected, (char *)"character constant")==0 ||
            strcmp(unexpected, (char *)"string constant")==0) 
        {
            printf("ERROR(%d): Syntax error.  Unexpected %s: %s.", globallineno, unexpected, lasttokenscanned);
        }
        else if (strcmp(unexpected, (char *)"number")==0) 
        {
            printf("ERROR(%d): Syntax error.  Unexpected %s: %s.", globallineno, unexpected, lasttokenscanned);
        }
        else 
        {
            printf("ERROR(%d): Syntax error.  Unexpected %s.", globallineno, unexpected);
        }
        if (numParts>=5) {
            printf("  Expecting ");
            for (int i=5; i<numParts; i+=2) {
                printf("%s", decodeName(msgParts[i]));
                if (i<numParts-2) printf(" or ");
            }
            printf(".");
        }
        printf("\n");

        numerrors++;
    }

    fflush(stdout);   // force a dump of the error
}
예제 #2
0
void BrowserDialog::linkClicked(const QUrl& url)
{
    do {
        if (url.host() != DOWNLOAD_HOST_BASE) {
            break;
        }
        if (url.path() != "/dict/download_cell.php") {
            break;
        }
        QString id = url.queryItemValue("id");
        QByteArray name = url.encodedQueryItemValue("name");
        QString sname = decodeName(name);

        m_name = sname;

        if (!id.isEmpty() && !sname.isEmpty()) {
            download(url);
            return;
        }
    } while(0);

    if (url.host() != HOST_BASE) {
        QMessageBox::information(this, _("Wrong Link"),
                                 _("No browsing outside pinyin.sogou.com, now redirect to home page."));
        m_ui->webView->load(QUrl(URL_BASE));
    } else {
        m_ui->webView->load(url);
    }
}
예제 #3
0
  /**
  * Return the keys used for identifying algorithms. This includes those within the Factory itself and 
  * any cleanly constructed algorithms stored here.
  * @param includeHidden true includes the hidden algorithm names and is faster, the default is false
  * @returns The strings used to identify individual algorithms
  */
  const std::vector<std::string> AlgorithmFactoryImpl::getKeys(bool includeHidden) const
  {
    //Start with those subscribed with the factory and add the cleanly constructed algorithm keys
    std::vector<std::string> names = Kernel::DynamicFactory<Algorithm>::getKeys();
    names.reserve(names.size() + m_cloneable_algs.size());

    std::map<std::string, API::CloneableAlgorithm*>::const_iterator itr_end = m_cloneable_algs.end();
    for(std::map<std::string, API::CloneableAlgorithm*>::const_iterator itr = m_cloneable_algs.begin(); 
      itr!= itr_end; ++itr )
    {
      names.push_back(itr->first);
    }

    if (includeHidden)
    {
      return names;
    }
    else
    {
      //hidden categories
      std::set<std::string> hiddenCategories;
      fillHiddenCategories(&hiddenCategories);

      //strip out any algorithms names where all of the categories are hidden
      std::vector<std::string> validNames;
      std::vector<std::string>::const_iterator itr_end = names.end();
      for(std::vector<std::string>::const_iterator itr = names.begin(); itr!= itr_end; ++itr )
      {
        std::string name = *itr;
        //check the categories
        std::pair<std::string,int> namePair = decodeName(name);
        boost::shared_ptr<IAlgorithm> alg = create(namePair.first,namePair.second);
        std::vector<std::string> categories = alg->categories();
        bool toBeRemoved=true;

        //for each category
        std::vector<std::string>::const_iterator itCategoriesEnd = categories.end();
        for(std::vector<std::string>::const_iterator itCategories = categories.begin(); itCategories!=itCategoriesEnd; ++itCategories)
        {
          //if the entry is not in the set of hidden categories
          if (hiddenCategories.find(*itCategories) == hiddenCategories.end())
          {
            toBeRemoved=false;
          }
        }

        if (!toBeRemoved)
        {
          //just mark them to be removed as we are iterating around the vector at the moment
          validNames.push_back(name);
        }
      }
      return validNames;
    }
  }
예제 #4
0
std::string digidoc::util::File::env(const std::string &varname)
{
    f_string _varname = encodeName( varname );
#ifdef _WIN32
    if( wchar_t *var = _wgetenv( _varname.c_str() ) )
#else
    if( char *var = getenv( _varname.c_str() ) )
#endif
        return decodeName( var );
    return std::string();
}
예제 #5
0
std::string digidoc::util::File::cwd()
{
#ifdef _WIN32
    wchar_t *path = _wgetcwd( 0, 0 );
#else
    char *path = getcwd( 0, 0 );
#endif
    std::string ret;
    if( path )
        ret = decodeName( path );
    free( path );
    return ret;
}
예제 #6
0
/**
 * @return returns temporary filename.
 */
std::string digidoc::util::File::tempFileName()
{
#ifdef _WIN32
    // requires TMP environment variable to be set
    wchar_t *fileName = _wtempnam(0, 0); // TODO: static buffer, not thread-safe
    if ( !fileName )
        THROW_IOEXCEPTION("Failed to create a temporary file name.");
#else
    char *fileName = tempnam(0, 0);
    if ( !fileName )
        THROW_IOEXCEPTION("Failed to create a temporary file name.");
#endif
    std::string path = decodeName(fileName);
    free(fileName);
    tempFiles.push(path);
    return path;
}
예제 #7
0
size_t IDnsResource::decodeName(const char* encodedName, std::string& result)
{
	size_t encodedNameLength = 0;
	result = "";

	uint8_t wordLength = encodedName[0];

	// A string to parse
	while (wordLength != 0)
	{
		// A pointer to another place in the packet
		if (wordLength == 0xc0)
		{
			uint8_t offsetInLayer = encodedName[1];
			if (offsetInLayer < sizeof(dnshdr))
			{
				LOG_ERROR("DNS parsing error: name pointer is illegal");
				return 0;
			}

			std::string tempResult;
			decodeName((const char*)(m_DnsLayer->m_Data + offsetInLayer), tempResult);
			result += tempResult;

			// in this case the length of the pointer is: 1B for 0xc0 + 1B for the offset itself
			return encodedNameLength + sizeof(uint16_t);
		}
		else
		{
			result.append(encodedName+1, wordLength);
			result.append(".");
			encodedName += wordLength + 1;
			encodedNameLength += wordLength + 1;
			wordLength = encodedName[0];
		}
	}

	// remove the last "."
	if (result != "")
		result = result.substr(0, result.size()-1);

	// add the last '\0' to encodedNameLength
	encodedNameLength++;
	return encodedNameLength;
}
예제 #8
0
/**
  * Return the categories of the algorithms. This includes those within the Factory itself and 
  * any cleanly constructed algorithms stored here.
  * @returns The map of the categories, together with a true false value difining if they are hidden
  */
  const std::map<std::string,bool> AlgorithmFactoryImpl::getCategoriesWithState() const
  {
    std::map<std::string,bool> resultCategories;

    //hidden categories - empty initially
    std::set<std::string> hiddenCategories;
    fillHiddenCategories(&hiddenCategories);

    //get all of the alroithm keys, including the hidden ones for speed purposes we will filter later if required
    std::vector<std::string> names = getKeys(true);
    
    std::vector<std::string>::const_iterator itr_end = names.end();
    //for each algorithm
    for(std::vector<std::string>::const_iterator itr = names.begin(); itr!= itr_end; ++itr )
    {
      std::string name = *itr;
      //decode the name and create an instance
      std::pair<std::string,int> namePair = decodeName(name);
      boost::shared_ptr<IAlgorithm> alg = create(namePair.first,namePair.second);
      //extract out the categories
      std::vector<std::string> categories = alg->categories();

      //for each category of the algorithm
      std::vector<std::string>::const_iterator itCategoriesEnd = categories.end();
      for(std::vector<std::string>::const_iterator itCategories = categories.begin(); itCategories!=itCategoriesEnd; ++itCategories)
      {
        bool isHidden = true;
        //check if the category is hidden
        if (hiddenCategories.find(*itCategories) == hiddenCategories.end())
        {
          isHidden = false;
        }
        resultCategories[*itCategories] = isHidden;
      }

    }
    return resultCategories;
  }
예제 #9
0
bool UHokuyo::receiveData()
{
  bool gotData = false;
  int n, i = 0;
  char * dend = NULL;
  UTime t;
  bool gotRngData = false;
  const int MSL = 500;
  char s[MSL];
  //
  if (modeSimulated)
  {
    //gotData = receiveSimulatedData(&length);
    Wait(0.1);
  }
  else
  {
    if (dataCnt > 0)
    { // test for old data
      if (dataTime.getTimePassed() > 1.0)
      {
        printf("Discarded '%s'\n", dataBuf);
        for (n = 0; n < dataCnt; n++)
          printf("%02x,", dataBuf[n]);
        printf("\n");
        printf("Discarded %d bytes of old data\n", dataCnt);
        statBadCnt++;
        dataCnt = 0;
      }
    }
    lock();
    if (isPortOpen())
    {
      // set timeout to ~30 ms
      n = receiveFromDevice(&dataBuf[dataCnt], MAX_DATA_LNG - dataCnt - 1, 0.015);
      if (/*repeatGetScan and*/ (n > 0))
      { // request more data
        requestMoreData();
      }
      //if (n > 0)
      //  printf("(%d bytes)", n);
    }
    else
      n = 0;
    unlock();
    if (n > 0)
    {
      dataCnt += n;
      dataBuf[dataCnt] = '\0';
      dend = strstr(dataBuf, "\n\n");
      // debug
/*      if (verbose and (datalog != NULL))
      { // log the received part of the buffer
       dataBuf[n] = '\0';
       fprintf(datalog, "%4d (n=%3d) got:'%s'\n", dataCnt, n, dataBuf);
      }*/
      // debug end
      gotData = (dend != NULL);
    }
  }
  //
  while (gotData)
  { // message length
    badSeries++;
    n = dend - dataBuf;
    // debug
    if (n > dataCnt)
    {
      printf("UHokuyo::receiveData message end found after buffer end? n=%d dataCnt=%d\n", n, dataCnt);
    }
    if (verbose)
    {
      snprintf(s, MSL, "In %d 'gotData' dataCnt=%d n=%d  %c%c%c%c%c%c%c%c%c... after %g sec\n", i, dataCnt, n,
            dataBuf[0], dataBuf[1], dataBuf[2],dataBuf[3], dataBuf[4], dataBuf[5], dataBuf[6], dataBuf[7], dataBuf[8],
            dataTime.getTimePassed());
      laslog.toLog("urg:", s);
    }
    //printf("msg:%s", dataBuf);
    i++;
    // debug end
    switch (dataBuf[0])
    {
    case 'V':
      dend[1] = '\0';
      if (dataBuf[1] == '\n')
      { // some garbage may also start with a V
        if (versionInfoCnt < 5 or verbose)
          printf("Got version (%d) info ((grp %d) %d chars):'%s'\n", versionInfoCnt, i, dataCnt, dataBuf);
        decodeName(dataBuf);
        versionInfoCnt++;
        if (verbose)
          laslog.toLog(" - V:", &dataBuf[4]);
      }
      break;
    case 'G':
      if (dataBuf[10] != '0')
      { // must be '0 to be valid scandata
        // printf("Bad data set laser may be off (bdSeries=%d) - send an on-command (\\nL1\\n)\n", badSeries);
        sendToDevice("\nL1\n", 4);
        break;
      }
      badSeries = 0;
      if (lasData == NULL)
        lasData = new ULaserData();
      if (lasData != NULL)
      { // save data into decoded buffer
        lasData->lock();
        lasData->setDeviceNum(deviceNum);
        gotRngData = decodeData(dataBuf, n, lasData);
        lasData->setMaxValidRange(maxValidRange);
        //if (repeatGetScan and not gotRngData)
        //{ // error message - request new data
        //  // send request for more data right away
        //  lock();
        //  //sendToDevice("00038401\n", 9);
        //  //sendToDevice("00076801\n", 9);
        //  unlock();
        //}
        if (gotRngData)
          statGoodCnt++;
        lasData->setMirror(mirrorData);
        lasData->unlock();
        //
        if (gotRngData)
          // do pending push commands.
          // No need to set data as locked, as
          // a client scanGet may use data at the same time as a scanpush,
          // as none of these will modify the 'lasData' structure.
          gotNewScan(lasData);
        if (verbose)
        { // debug logging
          snprintf(s, MSL, "UHokuyo::receiveData: scan=%6s %drngs In %2d msgCnt=%4d/%4d : %c%c%c%c%c%c%c%c%c %c %c%c... after %g sec\n",
            bool2str(gotRngData), lasData->getRangeCnt(),  i, n, dataCnt,
            dataBuf[0], dataBuf[1], dataBuf[2],dataBuf[3], dataBuf[4], dataBuf[5], dataBuf[6], dataBuf[7], dataBuf[8],
            dataBuf[10], dataBuf[12], dataBuf[13],
            dataTime.getTimePassed());
          laslog.toLog(" - G:", s);
          // to screen also
          printf("%s", s);
        }
        dataTime.Now();
      }
      break;
    default:
      // got error
      // discard to first newline
/*      char * nl = strchr(dataBuf, '\n');
      if (nl < dend and nl > dataBuf)
      { // newline found,
        // set new data end (dend) to one earlier, as if it was
        // a real "\n\n" command termination.
        // this is to avoid a situation where OK scans
        // are part of an error-respond.
        dend = --nl;
      }*/
      // close string and restart
      dend[1] = '\0';
      // debug
      if (verbose)
      {
        snprintf(s, MSL, "UHokuyo::receiveData: garbage msg %4d of %4d chars in buffer:'%c%c%c...'\n", n, dataCnt, dataBuf[0], dataBuf[1], dataBuf[2]);
        laslog.toLog(" - ", s);
      }
      //printf("UHokuyo::receiveData: ignored garbage (%d chars):'%s'\n", dataCnt, dataBuf);
      //rp = true; //repeatGetScan;
      // no other than G???... should be
      // received in repeat mode, well
      //    sometimes a LFLF is in the error message
      //repeatGetScan = false;
        /*closePort();
        printf("Got unknown garbage:--------Closing port\n");
        Wait(0.2);
        if (rp)
        { // repeat is enabled - request dummy data
          printf("-------------restarting in repeat mode\n");
          getNewestData(NULL, 0, false);
          //repeatGetScan = true;
        }*/
      statBadCnt++;
      break;
    }
    // discard the used (or unknown) data
    n = dataCnt - (dend - dataBuf) - 2;
    memmove(dataBuf, dend + 2,  n);
    // reduce available data count
    dataCnt = n;
    dataBuf[dataCnt] = '\0';
    // test for more data in buffer
    gotData = dataCnt > 3;
    if (gotData)
    { // is it a full message
      dend = strstr(dataBuf, "\n\n");
      gotData = (dend != NULL);
      //printf("****Got more messages in one read (OK, but indicate latency)\n");
    }
  }
  return gotRngData;
}
예제 #10
0
/**
 * Lists files or sub directories in directory. If flag <code>filesOnly</code> is set
 * to <code>true</code> returns ONLY files, otherwise returns ONLY directories.
 *
 * @param directory full path of the directory.
 * @param relative should the returned file list be relative to the <code>directory</code>.
 * @param filesOnly if set to <code>true</code>, returns only files, otherwise returns only directories.
 * @param unixStyle should the returned file path entries in the file list use the unix style
 *        path separators.
 * @throws IOException throws exception if the directory listing failed.
 */
std::vector<std::string> digidoc::util::File::getDirSubElements(const std::string& directory,
		bool relative, bool filesOnly, bool unixStyle) throw(IOException)
{
    std::vector<std::string> files;

#ifdef _POSIX_VERSION

    std::string _directory = encodeName(directory);
    DIR* pDir = opendir(_directory.c_str());
    if(!pDir)
    {
        THROW_IOEXCEPTION("Failed to open directory '%s'", _directory.c_str());
    }

    char fullPath[MAXPATHLEN];
    struct stat info;
    dirent* entry;
    while((entry = readdir(pDir)) != NULL)
    {
        if(std::string(".").compare(entry->d_name) == 0
        || std::string("..").compare(entry->d_name) == 0)
        {
            continue;
        }

        sprintf(fullPath, "%s/%s", _directory.c_str(), entry->d_name);
        lstat(fullPath, &info);

        if((!filesOnly && (entry->d_type == 0x04||S_ISDIR(info.st_mode))) // Directory
        || (filesOnly && (entry->d_type == 0x08||S_ISREG(info.st_mode)))) // File
        {
            if(relative)
                files.push_back(decodeName(entry->d_name));
            else
                files.push_back(path(directory, decodeName(entry->d_name), unixStyle));
        }
    }

    closedir(pDir);

#else

    WIN32_FIND_DATAW findFileData;
    HANDLE hFind = NULL;

    try
    {
        if ( directory.size() > MAX_PATH )
        {
            // MSDN: "Relative paths are limited to MAX_PATH characters." - can this be true?
            THROW_IOEXCEPTION("Directory path '%s' exceeds the limit %d", directory.c_str(), MAX_PATH);
        }

        std::wstring findPattern = encodeName(directory + "\\*");
        hFind = ::FindFirstFileW(findPattern.c_str(), &findFileData);
        if (hFind == INVALID_HANDLE_VALUE)
        {
            THROW_IOEXCEPTION("Listing contents of directory '%s' failed with error %d", directory.c_str(), ::GetLastError());
        }

        do
        {
            std::wstring fileName(findFileData.cFileName);
            if ( fileName == L"." || fileName == L".." )
            {
                continue; // skip those too
            }

            if(!filesOnly && (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // Directory
            || filesOnly && !(findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) // File
            {
                if(relative)
                    files.push_back(decodeName(fileName));
                else
                    files.push_back(path(directory, decodeName(fileName), unixStyle));
            }
        } while ( ::FindNextFileW(hFind, &findFileData) != FALSE );

        // double-check for errors
        if ( ::GetLastError() != ERROR_NO_MORE_FILES )
        {
            THROW_IOEXCEPTION("Listing contents of directory '%s' failed with error %d", directory.c_str(), ::GetLastError());
        }

        ::FindClose(hFind);
    }
    catch (...)
    {
        ::FindClose(hFind);
        throw;
    }


#endif

    return files;
}
예제 #11
0
const std::string TetrisScene::name(){
	return decodeName(
		typeid(*this).name()
	);
}
예제 #12
0
파일: NameIO.cpp 프로젝트: UIKit0/encfs
string NameIO::decodeName(const string &name) const {
  return getReverseEncryption() ? encodeName(name, nullptr)
                                : decodeName(name, nullptr);
}
예제 #13
0
std::string DnsResource::getDataAsString()
{
	uint8_t* resourceRawData = getRawData() + m_NameLength + 3*sizeof(uint16_t) + sizeof(uint32_t);
	size_t dataLength = getDataLength();

	DnsType dnsType = getDnsType();

	std::string result = "";

	switch (dnsType)
	{
	case DNS_TYPE_A:
	{
		if (dataLength != 4)
		{
			LOG_ERROR("DNS type is A but resource length is not 4 - packet is malformed");
			break;
		}

		uint32_t addrAsInt = *(uint32_t*)resourceRawData;
		IPv4Address ip4AddrElad(addrAsInt);
		if (!ip4AddrElad.isValid())
		{
			LOG_ERROR("Invalid IPv4 address for DNS resource of type A");
			break;
		}

		result = ip4AddrElad.toString();
		break;
	}

	case DNS_TYPE_AAAA:
	{
		if (dataLength != 16)
		{
			LOG_ERROR("DNS type is AAAA but resource length is not 16 - packet is malformed");
			break;
		}

		IPv6Address ip6Addr(resourceRawData);
		if (!ip6Addr.isValid())
		{
			LOG_ERROR("Invalid IPv6 address for DNS resource of type AAAA");
			break;
		}
		result = ip6Addr.toString();
		break;
	}

	case DNS_TYPE_NS:
	case DNS_TYPE_CNAME:
	case DNS_TYPE_DNAM:
	case DNS_TYPE_PTR:
	case DNS_TYPE_MX:
	{
		decodeName((const char*)resourceRawData, result);
		break;
	}

	default:
	{
		std::stringstream sstream;
	    sstream << "0x" << std::hex;
	    for(size_t i = 0; i < dataLength; i++)
	        sstream << std::setw(2) << std::setfill('0') << (int)resourceRawData[i];
	    result = sstream.str();

		break;
	}

	}

	return result;

}
예제 #14
0
IDnsResource::IDnsResource(DnsLayer* dnsLayer, size_t offsetInLayer)
	: m_DnsLayer(dnsLayer), m_OffsetInLayer(offsetInLayer), m_NextResource(NULL)
{
	m_NameLength = decodeName((const char*)getRawData(), m_DecodedName);
}