Example #1
0
bool wxCurlFTPTool::GetFTPFs(wxArrayFTPFs& fs, const wxString& szRemoteLoc /*= wxEmptyString*/)
{
	if(List(szRemoteLoc))
	{
        wxString str = wxCURL_BUF2STRING(m_szResponseBody);
		wxStringInputStream inStream(str);

		if(inStream.IsOk())
		{
			wxTextInputStream txtInStream(inStream);
			wxString szCurrentLine = txtInStream.ReadLine();

			while(!szCurrentLine.IsEmpty())
			{
				struct ftpparse ftppItem;

				wxCharBuffer charBuffer(szCurrentLine.ToUTF8());
				
				if(ftpparse(&ftppItem,charBuffer.data(), charBuffer.length()) != 0)
				{					
					fs.Add(wxCurlFTPFs((wxChar*)ftppItem.name, 
                            (ftppItem.flagtrycwd == 1),(ftppItem.flagtryretr == 1),
                                ftppItem.mtime,ftppItem.size));
				}

				szCurrentLine = txtInStream.ReadLine();
			}

			return true;
		}
	}

	return false;
}
std::string AG_ReadNotes( filehandle refNum )
{
    
    // File notes
    std::ostringstream notes; notes << "\0";
    AXGLONG notes_size = 0;
    AXGLONG bytes = sizeof(AXGLONG);
    int result = ReadFromFile( refNum, &bytes, &notes_size );
    if ( result )
        return notes.str();
#ifdef __LITTLE_ENDIAN__
    ByteSwapLong( &notes_size );
#endif

    if (notes_size > 0) {
        std::vector< unsigned char > charBuffer( notes_size, '\0' );
        result = ReadFromFile( refNum, &notes_size, &charBuffer[0] );
        if ( result )
            return notes.str();
        // Copy characters one by one into title (tedious but safe)
        for (std::size_t nc=1; nc<charBuffer.size(); nc+=2) {
            notes << char(charBuffer[nc]);
        }
    }
    return notes.str();
}
int AG_ReadColumn( filehandle refNum, const int fileFormat, const int columnNumber, ColumnData *columnData )
{
    // Initialize in case of error during read
    columnData->points = 0;
    columnData->title = "";

    switch ( fileFormat )
    {
     case kAxoGraph_Graph_Format:
         {
             // Read the standard column header
             ColumnHeader columnHeader;
             AXGLONG bytes = sizeof( ColumnHeader );
             int result = ReadFromFile( refNum, &bytes, &columnHeader );
             if ( result )
                 return result;

#ifdef __LITTLE_ENDIAN__
             ByteSwapLong( &columnHeader.points );
#endif

             // Retrieve the title and number of points in the column
             columnData->type = FloatArrayType;
             columnData->points = columnHeader.points;
             columnData->title.resize( 80 );
             PascalToCString( columnHeader.title );
             columnData->title = std::string( (char*)columnHeader.title );

             // create a new pointer to receive the data
             AXGLONG columnBytes = columnHeader.points * sizeof( float );
             columnData->floatArray.resize( columnHeader.points );
             if ( columnData->floatArray.empty() )
                 return kAG_MemoryErr;

             // Read in the column's data
             result = ReadFromFile( refNum, &columnBytes, &(columnData->floatArray[0]) );

#ifdef __LITTLE_ENDIAN__
             ByteSwapFloatArray( &(columnData->floatArray[0]), columnHeader.points );
#endif

             break;
         }

     case kAxoGraph_Digitized_Format:
         {
             if ( columnNumber == 0 )
             {
                 // Read the column header
                 DigitizedFirstColumnHeader columnHeader;
                 AXGLONG bytes = sizeof( DigitizedFirstColumnHeader );
                 int result = ReadFromFile( refNum, &bytes, &columnHeader );
                 if ( result )
                     return result;

#ifdef __LITTLE_ENDIAN__
                 ByteSwapLong( &columnHeader.points );
                 ByteSwapFloat( &columnHeader.firstPoint );
                 ByteSwapFloat( &columnHeader.sampleInterval );
#endif

                 // Retrieve the title, number of points in the column, and sample interval
                 columnData->type = SeriesArrayType;
                 columnData->points = columnHeader.points;
                 columnData->title.resize( 80 );
                 PascalToCString( columnHeader.title );
                 columnData->title = std::string( (char*)columnHeader.title );

                 columnData->seriesArray.firstValue = columnHeader.firstPoint;
                 columnData->seriesArray.increment = columnHeader.sampleInterval;
             }
             else
             {
                 // Read the column header
                 DigitizedColumnHeader columnHeader;
                 AXGLONG bytes = sizeof( DigitizedColumnHeader );
                 int result = ReadFromFile( refNum, &bytes, &columnHeader );
                 if ( result )
                     return result;

#ifdef __LITTLE_ENDIAN__
                 ByteSwapLong( &columnHeader.points );
                 ByteSwapFloat( &columnHeader.scalingFactor );
#endif

                 // Retrieve the title and number of points in the column
                 columnData->type = ScaledShortArrayType;
                 columnData->points = columnHeader.points;
                 columnData->title.resize( 80 );
                 PascalToCString( columnHeader.title );
                 columnData->title = std::string( (char*)columnHeader.title );

                 columnData->scaledShortArray.scale = columnHeader.scalingFactor;
                 columnData->scaledShortArray.offset = 0;

                 // create a new pointer to receive the data
                 AXGLONG columnBytes = columnHeader.points * sizeof( short );
                 columnData->scaledShortArray.shortArray.resize( columnHeader.points );
                 if ( columnData->scaledShortArray.shortArray.empty() )
                     return kAG_MemoryErr;

                 // Read in the column's data
                 result = ReadFromFile( refNum, &columnBytes, &(columnData->scaledShortArray.shortArray[0]) );

#ifdef __LITTLE_ENDIAN__
                 ByteSwapShortArray( &(columnData->scaledShortArray.shortArray[0]), columnHeader.points );
#endif

             }
             break;
         }

     case kAxoGraph_X_Format:
         {
             // Read the column header
             AxoGraphXColumnHeader columnHeader;
             AXGLONG bytes = sizeof( AxoGraphXColumnHeader );
             int result = ReadFromFile( refNum, &bytes, &columnHeader );
             if ( result )
                 return result;

#ifdef __LITTLE_ENDIAN__
             ByteSwapLong( &columnHeader.points );
             ByteSwapLong( &columnHeader.dataType );
             ByteSwapLong( &columnHeader.titleLength );
#endif

             // Retrieve the column type and number of points in the column
             columnData->type = (ColumnType)columnHeader.dataType;
             columnData->points = columnHeader.points;

             // sanity check on column type
             if ( columnData->type < 0 || columnData->type > 14 )
                 return -1;

             // Read the column title
             columnData->titleLength = columnHeader.titleLength;
             // columnData->title.resize( columnHeader.titleLength );
             std::vector< unsigned char > charBuffer( columnHeader.titleLength, '\0' );
             result = ReadFromFile( refNum, &columnHeader.titleLength, &charBuffer[0] );
             if ( result )
                 return result;
             // Copy characters one by one into title (tedious but safe)
             for (std::size_t nc=1; nc<charBuffer.size(); nc+=2) {
                 columnData->title += char(charBuffer[nc]);
             }
             // UnicodeToCString( columnData->title, columnData->titleLength );

             switch ( columnHeader.dataType )
             {
              case ShortArrayType:
                  {
                      // create a new pointer to receive the data
                      AXGLONG columnBytes = columnHeader.points * sizeof( short );
                      columnData->shortArray.resize( columnHeader.points );
                      if ( columnData->shortArray.empty() )
                          return kAG_MemoryErr;

                      // Read in the column's data
                      result = ReadFromFile( refNum, &columnBytes, &(columnData->shortArray[0]) );

#ifdef __LITTLE_ENDIAN__
                      ByteSwapShortArray( &(columnData->shortArray[0]), columnHeader.points );
#endif

                      break;
                  }
              case IntArrayType:
                  {
                      // create a new pointer to receive the data
                      AXGLONG columnBytes = columnHeader.points * sizeof( int );
                      columnData->intArray.resize( columnHeader.points );
                      if ( columnData->intArray.empty() )
                          return kAG_MemoryErr;

                      // Read in the column's data
                      result = ReadFromFile( refNum, &columnBytes, &(columnData->intArray[0]) );

#ifdef __LITTLE_ENDIAN__
                      ByteSwapLongArray( (AXGLONG *)&(columnData->intArray[0]), columnHeader.points );
#endif

                      break;
                  }
              case FloatArrayType:
                  {
                      // create a new pointer to receive the data
                      AXGLONG columnBytes = columnHeader.points * sizeof( float );
                      columnData->floatArray.resize( columnHeader.points );
                      if ( columnData->floatArray.empty() )
                          return kAG_MemoryErr;

                      // Read in the column's data
                      result = ReadFromFile( refNum, &columnBytes, &(columnData->floatArray[0]) );

#ifdef __LITTLE_ENDIAN__
                      ByteSwapFloatArray( &(columnData->floatArray[0]), columnHeader.points );
#endif
                      break;
                  }
              case DoubleArrayType:
                  {
                      // create a new pointer to receive the data
                      AXGLONG columnBytes = columnHeader.points * sizeof( double );
                      columnData->doubleArray.resize( columnHeader.points );
                      if ( columnData->doubleArray.empty() )
                          return kAG_MemoryErr;

                      // Read in the column's data
                      result = ReadFromFile( refNum, &columnBytes, &(columnData->doubleArray[0]) );

#ifdef __LITTLE_ENDIAN__
                      ByteSwapDoubleArray( &(columnData->doubleArray[0]), columnHeader.points );
#endif

                      break;
                  }
              case SeriesArrayType:
                  {
                      SeriesArray seriesParameters;
                      AXGLONG bytes = sizeof( SeriesArray );
                      result = ReadFromFile( refNum, &bytes, &seriesParameters );

#ifdef __LITTLE_ENDIAN__
                      ByteSwapDouble( &seriesParameters.firstValue );
                      ByteSwapDouble( &seriesParameters.increment );
#endif

                      columnData->seriesArray.firstValue = seriesParameters.firstValue;
                      columnData->seriesArray.increment = seriesParameters.increment;
                      break;
                  }
              case ScaledShortArrayType:
                  {
                      double scale, offset;
                      AXGLONG bytes = sizeof( double );
                      result = ReadFromFile( refNum, &bytes, &scale );
                      result = ReadFromFile( refNum, &bytes, &offset );
#ifdef __LITTLE_ENDIAN__
                      ByteSwapDouble( &scale );
                      ByteSwapDouble( &offset );
#endif

                      columnData->scaledShortArray.scale = scale;
                      columnData->scaledShortArray.offset = offset;

                      // create a new pointer to receive the data
                      AXGLONG columnBytes = columnHeader.points * sizeof( short );
                      columnData->scaledShortArray.shortArray.resize( columnHeader.points );
                      if ( columnData->scaledShortArray.shortArray.empty() )
                          return kAG_MemoryErr;

                      // Read in the column's data
                      result = ReadFromFile( refNum, &columnBytes, &(columnData->scaledShortArray.shortArray[0]) );

#ifdef __LITTLE_ENDIAN__
                      ByteSwapShortArray( &(columnData->scaledShortArray.shortArray[0]), columnHeader.points );
#endif

                      break;
                  }
             }
         }
         break;
     default:
         {
             return -1;
         }
    }
    return 0;
}
Example #4
0
std::vector<std::string> DGLRunAppProject::getCommandLineArgVector() {
    std::vector<std::string> ret;

// some magic here. We have arguments from user, but we must pre-parse them and
// split into and array.
// due to laziness some weird system-specific functions are used here.
#ifdef _WIN32
    int numArgs;
    if (m_args.length()) {
        LPWSTR* strings =
                CommandLineToArgvW(m_args.c_str(), &numArgs);
        if (!strings) {
            if (int osError = Os::getLastosError()) {
                throw std::runtime_error("Program arguments: " +
                                         Os::translateOsError(osError));
            } else {
                throw std::runtime_error("Program arguments: unknown error");
            }
        }

        if (numArgs > 0) {
            ret.resize(static_cast<size_t>(numArgs));
            for (size_t i = 0; i < ret.size(); i++) {
                ret[i] = QString::fromWCharArray(strings[i]).toStdString();
            }
        }
        LocalFree(strings);
    }
#else
    wordexp_t wordExp;


    std::string argsUtf8 = "";

    if (m_args.size()) {
        std::vector<char> charBuffer(MB_CUR_MAX * m_args.size(), 0);
        wcstombs(&charBuffer[0], &m_args[0], charBuffer.size());
        argsUtf8 = &charBuffer[0];
    }

    int status = wordexp(argsUtf8.c_str(), &wordExp, 0);
    switch (status) {
        case WRDE_BADCHAR:
            throw std::runtime_error(
                    "Program arguments: Illegal occurrence of newline or one "
                    "of |, "
                    "&, ;, <, >, (, ), {, }.");
        case WRDE_BADVAL:
            DGL_ASSERT(!"no  WRDE_UNDEF was set, but got WRDE_BADVAL");
            throw std::runtime_error(
                    "Program arguments: An undefined shell variable was "
                    "referenced");
        case WRDE_CMDSUB:
            DGL_ASSERT(!" WRDE_NOCMD flag not set, but got WRDE_CMDSUB");
            throw std::runtime_error(
                    "Program arguments: Command substitution occurred");
        case WRDE_NOSPACE:
            throw std::runtime_error("Program arguments: Out of memory.");
        case WRDE_SYNTAX:
            throw std::runtime_error("Program arguments: syntax error");
        case 0:
            break;
        default:
            throw std::runtime_error("Program arguments: unknown error");
    }

    ret.resize(wordExp.we_wordc);
    for (size_t i = 0; i < ret.size(); i++) {
        ret[i] = wordExp.we_wordv[i];
    }

    wordfree(&wordExp);

#endif
    return ret;
}