Ejemplo n.º 1
0
/* export_cb : Export Callback
   Export to file the entry highlighted in the browser. */
void export_cb(FL_OBJECT *a, long l)
{
  Int4 index;
  int RetVal;
  unsigned char *pImgBuf;
  short Width;
  short Height;
  const char *format;

  RetVal = fl_get_browser(wad_brow);
  if ( RetVal == 1 )           /* first line is the legend */
    return;
  index = LinearMap[RetVal];
  
  switch (pEntryTag[index])
    {
    case TAG_MUS  : 
      GenFileName(pDirEnt[index].name, ".mus", TmpNameStr);
      RetVal = Gen_MUS_File(WADfp, pDirEnt[index], TmpNameStr);
      break;
    case TAG_SFX  :
      GenFileName(pDirEnt[index].name, ".wav", TmpNameStr);
      RetVal = Gen_WAV_File(WADfp, pDirEnt[index], TmpNameStr);
      break;
    case TAG_FLAT :
    case TAG_FULL :
    case TAG_IMG  :
      pImgBuf = ParseImgBlock(pDirEnt[index], pEntryTag[index], 
			      &Width, &Height, NULL, NULL, WADfp);
      if (pImgBuf == NULL) {
	RetVal = 4;
	break;
      }
      format = fl_get_choice_text( exp_img_fmt_cho );
      if ( !strcmp(format, PCX_STR ) ) {           /* pcx */
	GenFileName(pDirEnt[index].name, ".pcx", TmpNameStr);
	RetVal = PCX_WriteImage(pDirEnt[index], WADfp, Width, Height, 
				pImgBuf, 1, TmpNameStr);
      }
      else {  /* xpm */
	char **xpm;
	GenFileName(pDirEnt[index].name, ".xpm", TmpNameStr);
	/* don't just redraw, we don't know what's in the xpm: */
	xpm = CreateXpmImage( pImgBuf, Width, Height, 0, NULL ); 
	if ( xpm && CreateXpmFile( xpm, TmpNameStr ) ) 
	  RetVal = 0;
	else
	  RetVal = 666; /* why not? */
      }
      break;
    case TAG_HIRES:
      GenFileName(pDirEnt[index].name, ".pcx", TmpNameStr);
      RetVal = PCX_WriteImage(pDirEnt[index], WADfp, 640, 480, 
			      pBitMap, 4, TmpNameStr);
      break;
    default:
      RetVal = 1;
      break;
    }
  
  if (RetVal != 0) {
    Beep();
    Message("error generating external file \"%s\" (%d)\n", 
	   TmpNameStr, RetVal);
  }
  else
    Message("External file \"%s\" created OK\n", TmpNameStr); 
}
Ejemplo n.º 2
0
int ParseArgs(int nArgc, char *ppArgv[], CommandArgs *pArgs)
{
    char c;
    ArgsStream stream;

    memset(pArgs, 0, sizeof(CommandArgs));
    stream.Initialize(nArgc, ppArgv);
//    GetCygpath();

    while ((c = stream.PeekChar()) != 0) {
        if (IsCommandSwitch(c)) {
            stream.GetChar(); // skip switch char: '-'

            switch (c = stream.GetChar()) {
                case 'o':
                    if (pArgs->dwAttribs & Command_o_GenLBO) {
                        CmdError(CommandError_DupSwitch, c);
                        return CommandError_DupSwitch;
                    }
                    pArgs->dwAttribs |= Command_o_GenLBO;

                    if (!IsCommandSwitch(stream.PeekChar())) {
                        GetFileName(&stream, ".lbo", pArgs, &pArgs->pszLBO);
                    }
                    break;

                case 'u':
                    pArgs->dwAttribs |= Command_u_ListUserFuncs;
                    break;

                case 'p':
                    pArgs->dwAttribs |= Command_p_Preview;
                    break;

                case 'I':
//                    if(HasCygpath()){
//                        pArgs->pszSourcePath = Turn2WinPath(stream.GetWord());
//                    } else {
                        pArgs->pszSourcePath = stream.GetWord();
//                    }
                    if (!pArgs->pszSourcePath) {
                        CmdError(CommandError_NoPathStr, c);
                        return CommandError_NoPathStr;
                    }
                    break;

                case '?':
                    fputs(c_pszCopyright, stdout);
                    fputs(c_pszUsage, stdout);
                    exit(0);

                default:
                    CmdError(CommandError_UnknownArg, c);
                    return CommandError_UnknownArg;
            }
        }
        else {
            if (pArgs->pszSource) {
                CmdError(CommandError_DupSource, c);
                return CommandError_DupSource;
            }
//            if(HasCygpath()){
//                pArgs->pszSource = Turn2WinPath(stream.GetWord());
//            } else {
                pArgs->pszSource = stream.GetWord();
//            }
        }
    }

    if (pArgs->dwAttribs & Command_u_ListUserFuncs) {
        ListAllUserFuncs();
        if (!pArgs->pszSource) exit(0);
    }

    if (!pArgs->pszSource) {
        CmdError(CommandError_NoSource, c);
        return CommandError_NoSource;
    }
    if ((pArgs->dwAttribs & Command_o_GenLBO) && NULL == pArgs->pszLBO) {
        pArgs->pszLBO = GenFileName(pArgs->pszSource, ".lbo");
        if (NULL == pArgs->pszLBO) {
            CmdError(CommandError_OutOfMemory, 0);
            return CommandError_OutOfMemory;
        }
    }

    return 0;
}
void FdoSpatialContextTest::DoTest( bool hasMetaSchema )
{
    FdoPtr<FdoIConnection> connection;
    StaticConnection* staticConn = NULL;

    try {
        if ( !hasMetaSchema ) {
            staticConn = UnitTestUtil::NewStaticConnection();
            staticConn->connect();
            UnitTestUtil::CreateDBNoMeta( 
                staticConn->CreateSchemaManager(),
                UnitTestUtil::GetEnviron("datastore", DB_NAME_SUFFIX)
            );
        }


        // delete, re-create and open the datastore
		printf( "Initializing Connection ... \n" );
		connection = UnitTestUtil::CreateConnection(
			hasMetaSchema,
			hasMetaSchema,
            DB_NAME_SUFFIX,
            0,
            NULL,
            0
		);

		printf( "Creating Spatial Contexts ... \n" );

        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda", L"Bermuda 1957", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular", L"", 0, 0, 1000, 1000 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda Duplicate", L"Bermuda 1957", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Luxembourg Delete", L"Luxembourg 1930", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"sc_2", L"Puerto Rico", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South Delete", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"sc_1", L"NAD27", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"South Duplicate", L"Australian Antarctic", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Liberia by WKT", L"", 0, 0, 10, 10, L"GEOGCS[\"Liberia 1964\", DATUM[\"Liberia 1964\", ELLIPSOID[\"Clarke 1880 (RGS)\", 6378249.145, 293.465]], PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.0174532925199433]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Qatar wrong name", L"Bermuda 1957", 0, 0, 10, 10, L"GEOGCS[\"Qatar 1974\", DATUM[\"Qatar 1974\", ELLIPSOID[\"International 1924\", 6378388, 297]], PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.0174532925199433]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"California", L"CA-I", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Bermuda Mentor", L"Bermuda.LL", 0, 0, 10, 10 ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Mentor by WKT", L"", 0, 0, 10, 10, L"PROJCS[\"Quebec test\",GEOGCS[\"For testing only\",DATUM[\"Test\",SPHEROID[\"NAD 27\",6300000,123.465,]]]]" ); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular (Metre)", L"XY-M", 0, 0, 10, 10); 
        UnitTestUtil::CreateSpatialContext( connection, L"Rectangular (Feet)", L"XY-FT", 0, 0, 10, 10); 

        connection->Close();
        connection->Open();

		printf( "Deleting Spatial Contexts ... \n" );

        UnitTestUtil::DeleteSpatialContext( connection, L"Luxembourg Delete" );
        UnitTestUtil::DeleteSpatialContext( connection, L"South Delete" );

        connection->Close();
        connection->Open();

        CreateSchema( connection, hasMetaSchema );

		printf( "Writing output ... \n" );

        FdoStringP datastore = UnitTestUtil::GetEnviron("datastore", DB_NAME_SUFFIX);

        FdoIoMemoryStreamP stream1 = FdoIoMemoryStream::Create();

        FdoXmlSpatialContextFlagsP flags = FdoXmlSpatialContextFlags::Create(
            L"fdo.osgeo.org/schemas/feature",
            FdoXmlFlags::ErrorLevel_Normal,
            true,
            FdoXmlSpatialContextFlags::ConflictOption_Add,
            true
        );

        UnitTestUtil::ExportDb( 
            connection, 
            stream1, 
            flags,
            false, 
            FdoStringP(L"Fdo") + datastore
        );

   		UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(1, hasMetaSchema, false) ) );

        UnitTestUtil::CheckOutput( 
            GenFileName( 1, hasMetaSchema, true ),
            UnitTestUtil::GetOutputFileName( GenFileName(1, hasMetaSchema, false) )
        );

        InsertFeatures( connection );

        stream1 = FdoIoMemoryStream::Create();

        UnitTestUtil::ExportDb( 
            connection, 
            stream1, 
            flags,
            false, 
            FdoStringP(L"Fdo") + datastore,
            L"AutoGen",
            true
        );

   		UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(2, hasMetaSchema, false) ) );

        UnitTestUtil::CheckOutput( 
            GenFileName( 2, hasMetaSchema, true ),
            UnitTestUtil::GetOutputFileName( GenFileName(2, hasMetaSchema, false) )
        );

        if ( !hasMetaSchema ) {
            CreateTables( staticConn, datastore );

            connection->Close();
            connection->Open();

            stream1 = FdoIoMemoryStream::Create();

            UnitTestUtil::ExportDb( 
                connection, 
                stream1, 
                flags,
                false, 
                FdoStringP(L"Fdo") + datastore,
                L"AutoGen",
                true
            );

   		    UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) ) );

            UnitTestUtil::CheckOutput( 
                GenFileName( 3, hasMetaSchema, true ),
                UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) )
            );


            try {
                UnitTestUtil::CreateSpatialContext( connection, L"Nowhere", L"JunkCS", 0, 0, 10, 10 ); 
                CPPUNIT_FAIL( "Setting unsupported coordinate system by name supposed to fail" );
            }
            catch (FdoException* e ) {
#ifdef _WIN32
#ifdef _DEBUG
                FdoStringP expectedMessage = L" Error creating spatial context Nowhere, coordinate system JunkCS is not in current datastore. ";
                FdoString* pMessage = wcschr( e->GetExceptionMessage(), ')' );
                if (pMessage) pMessage++;
#else
                FdoStringP expectedMessage = L"Error creating spatial context Nowhere, coordinate system JunkCS is not in current datastore. ";
                FdoString* pMessage = e->GetExceptionMessage();
#endif
                CPPUNIT_ASSERT( pMessage && expectedMessage.ICompare(pMessage) == 0 );
#endif
                FDO_SAFE_RELEASE(e);
            }

            try {
                UnitTestUtil::CreateSpatialContext( connection, L"California2", L"", 0, 0, 10, 10, L"PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]" ); 
                CPPUNIT_FAIL( "Setting unsupported coordinate system by wkt supposed to fail" );
            }
            catch (FdoException* e ) {
#ifdef _WIN32
#ifdef _DEBUG
                FdoStringP expectedMessage = L" Error creating spatial context California2, coordinate system catalog does not contain entry for WKT 'PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]' ";
                FdoString* pMessage = wcschr( e->GetExceptionMessage(), ')' );
                if (pMessage) pMessage++;
#else
                FdoStringP expectedMessage = L"Error creating spatial context California2, coordinate system catalog does not contain entry for WKT 'PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]' ";
                FdoString* pMessage = e->GetExceptionMessage();
#endif
                CPPUNIT_ASSERT( pMessage && expectedMessage.ICompare(pMessage) == 0 );
#endif
                FDO_SAFE_RELEASE(e);
            }
        }
        else {
            UnitTestUtil::CreateSpatialContext( connection, L"Nowhere", L"JunkCS", 0, 0, 10, 10 ); 
            UnitTestUtil::CreateSpatialContext( connection, L"California2", L"CA_I", 0, 0, 10, 10, L"PROJCS[\"CA-I\",GEOGCS[\"LL27\",DATUM[\"NAD27\",SPHEROID[\"CLRK66\",60.400,294.97869821]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"false_easting\",2000000.000],PARAMETER[\"false_northing\",0.000],PARAMETER[\"central_meridian\",-122.00000000000000],PARAMETER[\"latitude_of_origin\",39.33333333333333],PARAMETER[\"standard_parallel_1\",41.66666666666666],PARAMETER[\"standard_parallel_2\",40.00000000000000],UNIT[\"Foot_US\",0.30480060960122]]" ); 

            stream1 = FdoIoMemoryStream::Create();
            UnitTestUtil::ExportDb( 
                connection, 
                stream1, 
                flags,
                false, 
                FdoStringP(L"Fdo") + datastore,
                L"AutoGen",
                true
            );

            UnitTestUtil::Config2SortedFile( stream1, UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) ) );

            UnitTestUtil::CheckOutput( 
                GenFileName( 3, hasMetaSchema, true ),
                UnitTestUtil::GetOutputFileName( GenFileName(3, hasMetaSchema, false) )
            );

        }

        delete staticConn;
        connection->Close();
    }
    catch ( ... )
    {
        try {
            if ( staticConn ) delete staticConn;
            if ( connection ) connection->Close();
        }
        catch ( ... ) {
        }

        throw;
    }
}