Exemple #1
0
int main(int argc, char *argv[])
{
  char name[100];
  lst = stderr;
  if (argc == 1) {
    Help();
    exit(EXIT_FAILURE);
  }

  InitFrameVars();
  source_name[0] = '\0';
  param_options(argc, argv);

  /* check on correct parameter usage */
  if (source_name[0] == 0) {
    fprintf(stderr, "No input file specified");
    exit(EXIT_FAILURE);
  }

  /* open the Source file (Scanner.S_src)  */
  if ((S_src = open(source_name, O_RDONLY|O_BINARY)) == -1) {
    fprintf(stderr, "Unable to open input file %s\n", source_name);
    exit(EXIT_FAILURE);
  }

  /* open the listing file */
  if (L_option) {
    FileGetName(name, source_name);
    strcat(name, ".lst");
    lstfile = OpenFile(name, "w", 1);
  } else if (!Q_option) lstfile = stderr; else lstfile = stdout;

  /* install error reporting procedure */
  Custom_Error = (Error_Func) StoreError;

  InitTab();
  InitScannerTab();
  Parse();
  close(S_src);

  lst = lstfile;
  if (Errors && !L_option) SummarizeErrors();
  else if (Errors || L_option) PrintListing();

  if (Errors) {  /* Check for Syntax Errors */
    fclose(lstfile);
    exit(EXIT_FAILURE);
  }

  MakeScanner();
  MakeParser();

  if (Errors) {  /* Check for LL(1) Errors, Undeclared Symbols, etc */
    fclose(lstfile);
    exit(EXIT_FAILURE);
  }

  SetupFrameVars();
  if (!T_option) {
    if (!P_option) GenScanner();
    GenParser();
    GenHeaders();
    if (C_option) GenCompiler();
  }

  if (L_option) {
    if (S_option) {
      ShowClassTab();
      ShowTermTab();
      ShowCommentTab();
      ShowSymSetTab();
      ShowNTermTab();
    }
    if (A_option) ShowDFA();
    fclose(lstfile);
  }
  DoneTab();
  DoneScannerTab();
  return (EXIT_SUCCESS);
}
Exemple #2
0
void
HelpRequestCB(
        Widget w,
        caddr_t client_data,
        caddr_t call_data )
{
    char *helpVolume, *locationId;
    intptr_t topic;
    
    topic = (intptr_t) client_data;
    helpVolume = HELP_VOLUME;

    switch (topic)
    {
	case HELP_MAIN_WINDOW:
	    locationId = HELP_MAIN_WINDOW_STR;
	    break;
	case HELP_MENUBAR:
	    locationId = HELP_MENUBAR_STR;
	    break;
	case HELP_FILE_BUTTON:
	    locationId = HELP_FILE_BUTTON_STR;
	    break;
	case HELP_HELP_BUTTON:
	    locationId = HELP_HELP_BUTTON_STR;
	    break;
	case HELP_FILE_MENU:
	    locationId = HELP_FILE_MENU_STR;
	    break;
	case HELP_HELP_MENU:
	    locationId = HELP_HELP_MENU_STR;
	    break;
	case HELP_EXIT:
	    locationId = HELP_EXIT_STR;
	    break;
	case HELP_INTRODUCTION:
	    locationId = HELP_INTRODUCTION_STR;
	    break;
	case HELP_TASKS:        
	    locationId = HELP_TASKS_STR;
	    break;
	case HELP_REFERENCE:
	    locationId = HELP_REFERENCE_STR;
	    break;
	case HELP_ITEM:
	    locationId = HELP_ITEM_STR;
	    break;
	case HELP_USING:
	    locationId = HELP_USING_STR;
            helpVolume = HELP_USING_HELP_VOLUME;
	    break;
	case HELP_VERSION:
	    locationId = HELP_VERSION_STR;
	    break;
	case HELP_COLOR_BUTTON:
	    locationId = HELP_COLOR_BUTTON_STR;
	    break;
	case HELP_FONT_BUTTON:
	    locationId = HELP_FONT_BUTTON_STR;
	    break;
	case HELP_BACKDROP_BUTTON:
	    locationId = HELP_BACKDROP_BUTTON_STR;
	    break;
	case HELP_KEYBOARD_BUTTON:
	    locationId = HELP_KEYBOARD_BUTTON_STR;
	    break;
	case HELP_MOUSE_BUTTON:
	    locationId = HELP_MOUSE_BUTTON_STR;
	    break;
	case HELP_AUDIO_BUTTON:
	    locationId = HELP_AUDIO_BUTTON_STR;
	    break;
	case HELP_SCREEN_BUTTON:
	    locationId = HELP_SCREEN_BUTTON_STR;
	    break;
	case HELP_DTWM_BUTTON:
	    locationId = HELP_DTWM_BUTTON_STR;
	    break;
	case HELP_STARTUP_BUTTON:
	    locationId = HELP_STARTUP_BUTTON_STR;
	    break;
	case HELP_I18N_BUTTON:
	    locationId = HELP_I18N_BUTTON_STR;
	    break;
	case HELP_COLOR_DIALOG:
	    locationId = HELP_COLOR_DIALOG_STR;
	    break;
	case HELP_ADD_PALETTE_DIALOG:
	    locationId = HELP_ADD_PALETTE_DIALOG_STR;
	    break;
	case HELP_ADD_PALETTE_WARNING_DIALOG:
	    locationId = HELP_ADD_PALETTE_WARNING_DIALOG_STR;
	    break;
	case HELP_DELETE_PALETTE_DIALOG:
	    locationId = HELP_DELETE_PALETTE_DIALOG_STR;
	    break;
	case HELP_DELETE_PALETTE_WARNING_DIALOG:
	    locationId = HELP_DELETE_PALETTE_WARNING_DIALOG_STR;
	    break;
	case HELP_MODIFY_PALETTE_DIALOG:
	    locationId = HELP_MODIFY_PALETTE_DIALOG_STR;
	    break;
	case HELP_COLOR_USE_DIALOG:
	    locationId = HELP_COLOR_USE_DIALOG_STR;
	    break;
	case HELP_FONT_DIALOG:
	    locationId = HELP_FONT_DIALOG_STR;
	    break;
	case HELP_BACKDROP_DIALOG:
	    locationId = HELP_BACKDROP_DIALOG_STR;
	    break;
	case HELP_KEYBOARD_DIALOG:
	    locationId = HELP_KEYBOARD_DIALOG_STR;
	    break;
	case HELP_MOUSE_DIALOG:
	    locationId = HELP_MOUSE_DIALOG_STR;
	    break;
	case HELP_AUDIO_DIALOG:
	    locationId = HELP_AUDIO_DIALOG_STR;
	    break;
	case HELP_SCREEN_DIALOG:
	    locationId = HELP_SCREEN_DIALOG_STR;
	    break;
	case HELP_DTWM_DIALOG:
	    locationId = HELP_DTWM_DIALOG_STR;
	    break;
	case HELP_STARTUP_DIALOG:
	    locationId = HELP_STARTUP_DIALOG_STR;
	    break;
	case HELP_I18N_DIALOG:
	    locationId = HELP_I18N_DIALOG_STR;
	    break;
    }

    Help(helpVolume, locationId);
}
Exemple #3
0
void main( int argc, char **argv ) {
	cout << " -- Populate V" << Populate_Version << " -- Copyright 1999 TM Productions" << endl;
	if( argc < 2 )          // Not Enough Arguments
		Help();

  if( argv[1][0] == '?' ) // 1st argument is a ?; display help
    Help();

  // Parse the command line arguments
  Populate * pop = ParseCommands( argc, argv );
  if( pop == NULL )
    exit(20);

  try {
    // Open the files
    int error = pop->OpenFiles();
    if( error != POPULATE_OK ) {
      cout << " ERROR:  " << Populate::GetErrorString( error ) << "; aborting" << endl;
      throw false;
    }

    // Test the Replacement Object Path
    error = pop->LoadReplacementPath();
    switch( error ) {
      case POPULATEREP_OK:    // No Error
        break;
      case POPULATEREP_PATH_DOESNT_EXIST:
        cout << " ERROR:  " << populate_rep_error_strings[ error ] << endl;
        break;
      case POPULATEREP_BAD_OBJECTS:
        cout << " The following replacement objects in the replacement path \""
             << pop->GetRepDir() << "\" are invalid:" << endl;
        for( unsigned int i=0; i < pop->GetRepList().NumElements(); i++ ) {
          if( !pop->GetRepList()[i]->IsValid() )
            cout << "   " << pop->GetRepList()[i]->GetFilename() << endl;
        }

        break;
    }

    // Output the replacement object paths, if applicable:
    if( pop->GetRepList().NumElements() > 0 ) {
      cout << "- Replacement Objects:  " << endl;
      for( unsigned int i = 0; i < pop->GetRepList().NumElements(); i++ ) {
        cout << "    " << setw( 7 ) << pop->GetRepList()[i]->GetProb()
             << "    " << pop->GetRepList()[i]->GetFilename() << endl; 
      }
    }

    // Find PNTS chunk in object, if needed
    if( !pop->FindPNTS() ) {
      cout << " ERROR:  Failed to read PNTS chunk from LWO Point Reference Object \"" << pop->GetLWO() << "\"; aborting" << endl;
      throw false;
    }

    if( pop->GetUseLWO() ) {
      if( pop->GetFirstPoint() > pop->GetLWOPointCount() ) {
        cout << " ERROR:  The number of First Point of " << pop->GetFirstPoint()
             << " exceeds the " << pop->GetLWOPointCount() << " in the LWO Point Reference Object \""
             << pop->GetLWO() << "\"; aborting" << endl;
        throw false;
      }
      cout << "  Number of points in LWO Point Reference Object: " << pop->GetLWOPointCount()
           << "; starting at " << pop->GetFirstPoint() << endl;
    }

    // Build the hierarchy tree
    cout << "-Building Hierarchy Tree... " << endl;
    if( !pop->BuildHierarchy() ) {
      cout << " ERROR:  Failed to read from \"" << pop->GetSource()
           << "\" while building hierarchy; aborting" << endl;
      throw false;
    }

    // Display hierarchy, if applicable
    if( pop->GetDisplayTree() ) {
      cout << "  -------------------- Scene Hierarchy --------------------- " << endl;
      pop->GetBase()->OutputAsText( 4 );
      cout << endl;
    }

    // Process the scene
    cerr << "-Processing \"" << pop->GetSource() << "\"..." << endl;
    error = pop->Process();
    if( error != POPULATE_OK ) {
      cout << " ERROR:  " << Populate::GetErrorString( error ) << "; aborting" << endl;
      throw false;
    }

    cerr << "-Processed " << pop->GetNumObjectsProcessed() << " objects and "
         << pop->GetNumLightsProcessed() << " lights and replaced "
         << pop->GetNumItemsReplaced() << " objects into \""
         << pop->GetOutput() << "\"" << endl;
    cerr << "-Sucessfully Populated \"" << pop->GetOutput() << "\"!" << endl;

  } catch( bool ) {
    ;  // This is just here so that, if there's an error, we will call 
       //  the clean-up at the code outside the try...catch block.
  }
    
  delete pop;
}
Exemple #4
0
/*
 * main
 */
int main(int argc, char *argv[])
{
	#ifdef _NDSTOOL_P_H
		if (sizeof(Header) != 0x200) { fprintf(stderr, "Header size %d != %d\n", sizeof(Header), 0x200); return 1; }
	#endif

	if (argc < 2) { Help(); return 0; }
	
	int num_actions = 0;
	int actions[MAX_ACTIONS];

	/*
	 * parse parameters to actions
	 */

	for (int a=1; a<argc; a++)
	{
		if (argv[a][0] == '-')
		{
			switch (argv[a][1])
			{
				case 'i':	// show information
				{
					ADDACTION(ACTION_SHOWINFO);
					OPTIONAL(ndsfilename);
					break;
				}

				case 'f':	// fix header CRC
				{
					ADDACTION(ACTION_FIXHEADERCRC);
					OPTIONAL(ndsfilename);
					break;
				}

				case 's':	// en-/decrypt secure area
				{
					ADDACTION(ACTION_ENCRYPTSECUREAREA);
					endecrypt_option = argv[a][2];
					OPTIONAL(ndsfilename);
					break;
				}

				case 'l':	// list files
				{
					ADDACTION(ACTION_LISTFILES);
					OPTIONAL(ndsfilename);
					break;
				}

				case 'x':	// extract
				{
					ADDACTION(ACTION_EXTRACT);
					OPTIONAL(ndsfilename);
					break;
				}
				
				case 'w':	// wildcard filemasks
				{
					while (1)
					{
						char *filemask = 0;
						OPTIONAL(filemask);
						if (!(filemasks[filemask_num] = filemask)) break;
						if (++filemask_num >= MAX_FILEMASKS) return 1;
					}
					break;
				}

				case 'c':	// create
				{
					ADDACTION(ACTION_CREATE);
					OPTIONAL(ndsfilename);
					break;
				}

				// file root directory
				case 'd': REQUIRED(filerootdir); break;

				// ARM7 filename
				case '7': 
					if (argv[a][2] == 'i') {
						REQUIRED(arm7ifilename);
					} else {
						REQUIRED(arm7filename);
					}
					break;
				// ARM9 filename
				case '9':
					if (argv[a][2] == 'i') {
						REQUIRED(arm9ifilename);
					} else {
						REQUIRED(arm9filename);
					}
					break;

				// hook ARM7 executable
				case 'k':
				{
					ADDACTION(ACTION_HOOK);
					OPTIONAL(ndsfilename);
					break;
				}

				case 't':
					REQUIRED(bannerfilename);
					bannertype = BANNER_BINARY;
					break;

				case 'b':
					bannertype = BANNER_IMAGE;
					REQUIRED(bannerfilename);
					REQUIRED(bannertext);
					break;

				case 'o':
					REQUIRED(logofilename);
					break;

				case 'h':	// load header or header size
					REQUIRED(headerfilename_or_size);
					break;

				/*case 'u':	// unique ID file
					REQUIRED(uniquefilename);
					break;*/

				case 'u': // DSi title ID high word
					if (argc > a)
						titleidHigh = strtoul(argv[++a], 0, 16);
					break;

				case 'z': // SCFG access flags
					if (argc > a)
						scfgExtMask = strtoul(argv[++a], 0, 16);
					break;

				case 'a': // DSi access control flags
					if (argc > a)
						accessControl = strtoul(argv[++a], 0, 16);
					break;

				case 'p': // DSi application flags
					if (argc > a)
						appFlags = strtoul(argv[++a], 0, 16) & 0xFF;
					break;

				case 'v':	// verbose
					for (char *p=argv[a]; *p; p++) if (*p == 'v') verbose++;
					OPTIONAL(romlistfilename);
					break;

				case 'n':	// latency
					//compatibility = true;
					OPTIONAL_INT(latency1);
					OPTIONAL_INT(latency2);
					break;

				case 'r':	// RAM address
					switch (argv[a][2])
					{
						case '7': arm7RamAddress = (argc > a) ? strtoul(argv[++a], 0, 0) : 0; break;
						case '9': arm9RamAddress = (argc > a) ? strtoul(argv[++a], 0, 0) : 0; break;
						default: Help(argv[a]); return 1;
					}
					break;

				case 'e':	// entry point
					switch (argv[a][2])
					{
						case '7': arm7Entry = (argc > a) ? strtoul(argv[++a], 0, 0) : 0; break;
						case '9': arm9Entry = (argc > a) ? strtoul(argv[++a], 0, 0) : 0; break;
						default: Help(argv[a]); return 1;
					}
					break;

				case 'm':	// maker code
					REQUIRED(makercode);
					break;

				case 'g':	// game code
					REQUIRED(gamecode);
					OPTIONAL(makercode);
					OPTIONAL(title);
					OPTIONAL_INT(romversion);
					break;

				case 'y':	// overlay table file / directory
					switch (argv[a][2])
					{
						case '7': REQUIRED(arm7ovltablefilename); break;
						case '9': REQUIRED(arm9ovltablefilename); break;
						case 0: REQUIRED(overlaydir); break;
						default: Help(argv[a]); return 1;
					}
					break;
				
				case '?':	// global or specific help
				{
					Help(argv[a][2] ? argv[a]+2 : 0);	// 0=global help
					return 0;	// do not perform any other actions
				}

				default:
				{
					Help(argv[a]);
					return 1;
				}
			}
		}
		else
		{
			//Help();
			if (ndsfilename)
			{
				fprintf(stderr, "NDS filename is already given!\n");
				return 1;
			}
			ndsfilename = argv[a];
			break;
		}
	}

	Title();

	/*
	 * sanity checks
	 */

	if (gamecode)
	{
		if (strlen(gamecode) != 4)
		{
			fprintf(stderr, "Game code must be 4 characters!\n");
			return 1;
		}
		for (int i=0; i<4; i++) if ((gamecode[i] >= 'a') && (gamecode[i] <= 'z'))
		{
			fprintf(stderr, "Warning: Gamecode contains lowercase characters.\n");
			break;
		}
		if (gamecode[0] == 'A')
		{
			fprintf(stderr, "Warning: Gamecode starts with 'A', which might be used for another commercial product.\n");
		}
	}
	if (makercode && (strlen(makercode) != 2))
	{
		fprintf(stderr, "Maker code must be 2 characters!\n");
		return 1;
	}
	if (title && (strlen(title) > 12))
	{
		fprintf(stderr, "Title can be no more than 12 characters!\n");
		return 1;
	}
	if (romversion > 255) {
		fprintf(stderr, "romversion can only be 0 - 255!\n");
		return 1;
	}

	/*
	 * perform actions
	 */

	int status = 0;
	for (int i=0; i<num_actions; i++)
	{
//printf("action %d\n", actions[i]);
		switch (actions[i])
		{
			case ACTION_SHOWINFO:
				ShowInfo(ndsfilename);
				break;

			case ACTION_FIXHEADERCRC:
				FixHeaderCRC(ndsfilename);
				break;

			case ACTION_EXTRACT:
				fNDS = fopen(ndsfilename, "rb");
				if (!fNDS) { fprintf(stderr, "Cannot open file '%s'.\n", ndsfilename); exit(1); }
				fread(&header, 512, 1, fNDS);
				fclose(fNDS);

			printf("9i %s, 7i %s, unitcode %x\n",arm9ifilename,arm7ifilename, header.unitcode);
				if (arm9filename) Extract(arm9filename, true, 0x20, true, 0x2C, true);
				if (arm7filename) Extract(arm7filename, true, 0x30, true, 0x3C);
				if (header.unitcode & 2) {
					if (arm9ifilename) Extract(arm9ifilename, true, 0x1C0, true, 0x1CC, true);
					if (arm7ifilename) Extract(arm7ifilename, true, 0x1D0, true, 0x1DC);
				}
				if (bannerfilename) Extract(bannerfilename, true, 0x68, false, 0x840);
				if (headerfilename_or_size) Extract(headerfilename_or_size, false, 0x0, false, 0x200);
				if (logofilename) Extract(logofilename, false, 0xC0, false, 156);	// *** bin only
				if (arm9ovltablefilename) Extract(arm9ovltablefilename, true, 0x50, true, 0x54);
				if (arm7ovltablefilename) Extract(arm7ovltablefilename, true, 0x58, true, 0x5C);
				if (overlaydir) ExtractOverlayFiles();
				if (filerootdir) ExtractFiles(ndsfilename);
				break;

			case ACTION_CREATE:
				Create();
				break;

			case ACTION_LISTFILES:
				filerootdir = 0;
				/*status =*/ ExtractFiles(ndsfilename);
				break;
			
			case ACTION_HOOK:
			{
				Hook(ndsfilename, arm7filename);
				break;
			}

			case ACTION_ENCRYPTSECUREAREA:
			{
				/*status =*/ EnDecryptSecureArea(ndsfilename, endecrypt_option);
				break;
			}
		}
	}

	return (status < 0) ? 1 : 0;
}
Exemple #5
0
void SetOptions(int argc, char *argv[])

{
	int c;
	char *options = "hinNeElLsSt:T:d:D:v:V:uo:Caxr:R:";

	while( (c=GetOpt(argc,argv,options)) != EOF ) {
		switch(c) {
		case 'h' :              /* h - help screen */
			Logos();
			Test();
			Usage(FALSE);
			Help();
			Assistance();
			exit(0);
			break;
		case 'i' :
			OpInfo = 1;
			break;
		case 'n' :
			OpExtractNodes = 1;
			break;
		case 'N' :
			OpDeleteNodes = 1;
			break;
		case 'e' :
			OpExtractElems = 1;
			break;
		case 'E' :
			OpDeleteElems = 1;
			break;
		case 'l' :
			OpExtractLines = 1;
			break;
		case 'L' :
			OpDeleteLines = 1;
			break;
		case 's' :
			OpExtractUnusedNodes = 1;
			break;
		case 'S' :
			OpDeleteUnusedNodes = 1;
			break;
		case 't' :
			OpMinType = atoi(GetOptArg());
			break;
		case 'T' :
			OpMaxType = atoi(GetOptArg());
			break;
		case 'd' :
			OpMinDepth = atof(GetOptArg());
			break;
		case 'D' :
			OpMaxDepth = atof(GetOptArg());
			break;
		case 'v' :
			OpMinVertex = atoi(GetOptArg());
			break;
		case 'V' :
			OpMaxVertex = atoi(GetOptArg());
			break;
		case 'r' :
			OpMinRange = atoi(GetOptArg());
			break;
		case 'R' :
			OpMaxRange = atoi(GetOptArg());
			break;
		case 'u' :
			OpUnifyNodes = 1;
			break;
		case 'o' :
			OpTollerance = atof(GetOptArg());
			break;
		case 'C' :
			OpCompressNumbers = 1;
			break;
		case 'a' :
			OpMakeAntiClockwise = 1;
			break;
		case 'x' :
			OpDeleteStrangeElements = 1;
			break;
		default :
			exit(1);
			break;
		}
	}

	OpArgc = GetOptInd();

	if( argc <= OpArgc ) {
		Logos();
		Test();
		Usage(TRUE);
		exit(0);
	} else {
		Logos();
		Test();
	}

	if( OpExtractNodes && OpDeleteNodes )
		Error("Options 'n' and 'N' are mutually exclusive.");
	if( OpExtractUnusedNodes && OpDeleteUnusedNodes )
		Error("Options 's' and 'S' are mutually exclusive.");
	if( ( OpExtractUnusedNodes || OpDeleteUnusedNodes ) &&
	   		 ( OpExtractNodes || OpDeleteNodes ) )
		Error("Options 'nN' and 'sS' are mutually exclusive.");
	if( OpExtractElems && OpDeleteElems )
		Error("Options 'e' and 'E' are mutually exclusive.");
	if( OpExtractLines && OpDeleteLines )
		Error("Options 'l' and 'L' are mutually exclusive.");

}
Exemple #6
0
// ParseCommands():
//  Parses the argument string passed into the command line.
//   Exits if the arguments are incorrect (or maybe returns
//   NULL); otherwise, it returns a pointer to a Populate
//   class
Populate * ParseCommands( int argc, char **argv ) {
  // Check for too few arguments
  if( argc < 3 )
    Help();

  // Check for help ?
  if( strchr( argv[1], '?' ) != 0 )
    Help();

  Populate *pop = new Populate( argv[1] );
  if( pop == NULL ) {
    cerr << " ERROR: Unable to allocate memory for Populate!" << endl;
    return NULL;
  }
          
  try {
    if( !pop->SetItem( argv[2] ) ) {
      cerr << " ERROR: The item name \"" << argv[2] << "\"is invalid!" << endl;
      throw( false );
    }

    cerr << "-Settings..." << endl;
    cerr << "  Source File will be \"" << pop->GetSource() << "\"" << endl;
    cerr << "  Item name starts with \"" << pop->GetItem() << "\"" << endl;

    for( int i=3; i < argc; i++ ) {
      switch( argv[i][1] ) {
      case 'c':
        // Content Dir Test
        if( ++i >= argc ) {
          cerr << " ERROR: No content directory following argument -c!" << endl;
          throw false;
        }
        pop->SetContentDir( argv[i] );
        cerr << "  Content Dir is " << pop->GetContentDir() << endl;
        break;

      case 'd':
        // Delta Test
        if( i+1 >= argc ) {
          cerr << " ERROR: No time delta following argument -d!" << endl;
          throw false;
        }
        if( argv[i][2] == 'a' )
          pop->SetDeltaMode( Populate::absolute );

        pop->SetDelta( atoi( argv[++i] ) );
        cerr << "  Max random time delta will be " << pop->GetDelta() << endl;
        break;

      case 'f':
        // First Point Test
        if( ++i >= argc ) {
          cerr << " ERROR: No first point index following argument -f!" << endl;
          throw false;
        }
        pop->SetFirstPoint( atoi( argv[i] ) );
        cerr << "  First point will be " << pop->GetFirstPoint() << endl;
        break;

      case 'g':
        // Seed Test
        if( ++i >= argc ) {
          cerr << " ERROR: No generation seed following argument -g!" << endl;
          throw false;
        }
        pop->SetSeed( atoi( argv[i] ) );
        cerr << "  Generation Seed for random numbers will be " << pop->GetSeed() << endl;
        break;

      case 'h':
        // Stretch Test
        if( i+3 >= argc ) {
          cerr << " ERROR: 3 scalar values must follow argument -h (one for each axis)!" << endl;
          throw false;
        }
        if( argv[i][2] == 'a' )
          pop->SetScaleMode( Populate::absolute );
        else if( argv[i][2] == 'r' )
          pop->SetScaleMode( Populate::replace );

        pop->SetScale( (float)atof( argv[i+1] ), (float)atof( argv[i+2] ), (float)atof( argv[i+3] ) );
        i+=3;
        cerr << "  Max random scale from point/origin will be " << pop->GetScale()[0] << ", "
            <<  pop->GetScale()[1] << ", " << pop->GetScale()[2] << endl;
        break;

      case 'H':
        // Scale Uniformly Test
        if( i+1 >= argc ) {
          cerr << " ERROR: a scalar values must follow argument -H!" << endl;
          throw false;
        }
        if( argv[i][2] == 'a' )
          pop->SetScaleMode( Populate::absolute );
        else if( argv[i][2] == 'r' )
          pop->SetScaleMode( Populate::replace );

        pop->SetUseUniformScale( true );
        i++;
        pop->SetScale( (float)atof( argv[i] ), (float)atof( argv[i] ), (float)atof( argv[i] ) );
        cerr << "  Max random uniform scale from point/origin will be " << pop->GetScale()[0] << endl;
        break;

      case 'l':  // that's a lower-case 'L'
        // LWO File Test
        if( ++i >= argc ) {
          cerr << " ERROR: No LWO Point Reference Object following argument -l!" << endl;
          throw false;
        }
        pop->SetUseLWO( true );
        pop->SetLWO( argv[i] );
        cerr << "  LWO Point Reference Object will be \"" << pop->GetLWO() << "\"" << endl;
        break;

      case 'o':
        // Output File Test
        if( ++i >= argc ) {
          cerr << " ERROR: No output path following argument -o!" << endl;
          throw false;
        }
        pop->SetOutput( argv[i] );
        cerr << "  Output File will be \"" << pop->GetOutput() << "\"" << endl;
        break;

      case 'r':
        // Replacement Dir Test
        if( i+2 >= argc ) {
          cerr << " ERROR: No Replacement Item and Path following argument -r!" << endl;
          throw false;
        }
        pop->SetUseRepDir( true );
        pop->SetRepItem( argv[++i] );
        pop->SetRepDir( argv[++i] );
        cerr << "  Replacement Path will be \"" << pop->GetRepDir() << "\" on item\""
				     << pop->GetRepItem() << "\"" << endl;
        break;

      case 's':
        // Scale Time Test
        if( i+1 >= argc ) {
          cerr << " ERROR: No scale time delta following argument -s!" << endl;
          throw false;
        }
        if( argv[i][2] == 'a' )
          pop->SetScaleTimeMode( Populate::absolute );

        pop->SetScaleTime( (float)atof( argv[++i] ) );
        cerr << "  Max random time delta will be " << pop->GetScaleTime() << endl;
        break;

      case 't':
        // Position Test
        if( i+3 >= argc ) {
          cerr << " ERROR: 3 positional values must follow argument -t (one for each axis)!" << endl;
          throw false;
        }
        if( argv[i][2] == 'a' )
          pop->SetPositionMode( Populate::absolute );
        else if( argv[i][2] == 'r' )
          pop->SetPositionMode( Populate::replace );

        pop->SetPosition( (float)atof( argv[i+1] ), (float)atof( argv[i+2] ), (float)atof( argv[i+3] ) );
        i+=3;
        cerr << "  Max random offset from point/origin will be " << pop->GetPosition()[0] << ", "
             <<  pop->GetPosition()[1] << ", " << pop->GetPosition()[2] << endl;
        break;

      case 'y':
        // Rotation Test
        if( i+3 >= argc ) {
          cerr << " ERROR: 3 rotational values must follow argument -y (one for each axis)!" << endl;
          throw false;
        }
        if( argv[i][2] == 'a' )
          pop->SetRotationMode( Populate::absolute );
        else if( argv[i][2] == 'r' )
          pop->SetRotationMode( Populate::replace );

        pop->SetRotation( (float)atof( argv[i+1] ), (float)atof( argv[i+2] ), (float)atof( argv[i+3] ) );
        i+=3;
        cerr << "  Max random rotation from point/origin will be " << pop->GetRotation()[0] << ", "
             <<  pop->GetRotation()[1] << ", " << pop->GetRotation()[2] << endl;
        break;

      default:
        // Unknown Argument
        cerr << " ERROR: Unrecognized argument \"" << argv[i] << "\"!" << endl;
        throw false;
      }
    }

    return pop;
  } catch( bool ) {
    // Common error stuff
    cerr << " Type Populate ? for help" << endl;
    delete pop;
    exit(20);
  }
}
Exemple #7
0
int main(int argc, const char* argv[]) {
  int return_code = -1;
  int dump_frames = 0;
  const char* dump_folder = NULL;
  double min_psnr = 0.;
  int got_input1 = 0;
  int got_input2 = 0;
  int premultiply = 1;
  int max_diff = 0;
  int i, c;
  const char* files[2] = { NULL, NULL };
  AnimatedImage images[2];

  for (c = 1; c < argc; ++c) {
    int parse_error = 0;
    if (!strcmp(argv[c], "-dump_frames")) {
      if (c < argc - 1) {
        dump_frames = 1;
        dump_folder = argv[++c];
      } else {
        parse_error = 1;
      }
    } else if (!strcmp(argv[c], "-min_psnr")) {
      if (c < argc - 1) {
        const char* const v = argv[++c];
        char* end = NULL;
        const double d = strtod(v, &end);
        if (end == v) {
          parse_error = 1;
          fprintf(stderr, "Error! '%s' is not a floating point number.\n", v);
        }
        min_psnr = d;
      } else {
        parse_error = 1;
      }
    } else if (!strcmp(argv[c], "-raw_comparison")) {
      premultiply = 0;
    } else if (!strcmp(argv[c], "-max_diff")) {
      if (c < argc - 1) {
        const char* const v = argv[++c];
        char* end = NULL;
        const int n = (int)strtol(v, &end, 10);
        if (end == v) {
          parse_error = 1;
          fprintf(stderr, "Error! '%s' is not an integer.\n", v);
        }
        max_diff = n;
      } else {
        parse_error = 1;
      }
    } else if (!strcmp(argv[c], "-h") || !strcmp(argv[c], "-help")) {
      Help();
      return 0;
    } else if (!strcmp(argv[c], "-version")) {
      int dec_version, demux_version;
      GetAnimatedImageVersions(&dec_version, &demux_version);
      printf("WebP Decoder version: %d.%d.%d\nWebP Demux version: %d.%d.%d\n",
             (dec_version >> 16) & 0xff, (dec_version >> 8) & 0xff,
             (dec_version >> 0) & 0xff,
             (demux_version >> 16) & 0xff, (demux_version >> 8) & 0xff,
             (demux_version >> 0) & 0xff);
      return 0;
    } else {
      if (!got_input1) {
// Action_MakeStructure::Init()
Action::RetType Action_MakeStructure::Init(ArgList& actionArgs, TopologyList* PFL, DataSetList* DSL, DataFileList* DFL, int debugIn)
{
  debug_ = debugIn;
  secstruct_.clear();
  // Get all arguments 
  std::string ss_expr = actionArgs.GetStringNext();
  while ( !ss_expr.empty() ) {
    ArgList ss_arg(ss_expr, ":");
    if (ss_arg.Nargs() < 2) {
      mprinterr("Error: Malformed SS arg.\n");
      Help();
      return Action::ERR;
    }
    // Type is 1st arg, range is 2nd arg.
    SecStructHolder ss_holder(ss_arg[1], FindSStype(ss_arg[0]));

    if (ss_arg.Nargs() == 2) {
    // Find SS type: <ss type>:<range>
      if (ss_holder.sstype_idx == SS_EMPTY) {
        mprinterr("Error: SS type %s not found.\n", ss_arg[0].c_str());
        return Action::ERR;
      } 
      ss_holder.dihSearch_.SearchFor(MetaData::PHI);
      ss_holder.dihSearch_.SearchFor(MetaData::PSI);
      secstruct_.push_back( ss_holder );

    } else if (ss_arg[0] == "ref") {
    // Use dihedrals from reference structure
      if (ss_arg.Nargs() < 3) {
        mprinterr("Error: Invalid 'ref' arg. Requires 'ref:<range>:<refname>[:<ref range>]'\n");
        return Action::ERR;
      }
      ss_arg.MarkArg(0);
      ss_arg.MarkArg(1);
      // Sanity check: Currently only unique args of this type are allowed
      if (ss_holder.sstype_idx != SS_EMPTY) {
        mprinterr("Error: Ref backbone types must be unique [%s]\n", ss_arg[0].c_str());
        return Action::ERR;
      }
      // Use backbone phi/psi from reference structure
      ss_holder.dihSearch_.SearchFor(MetaData::PHI);
      ss_holder.dihSearch_.SearchFor(MetaData::PSI);
      // Get reference structure
      DataSet_Coords_REF* REF = (DataSet_Coords_REF*)
                                DSL->FindSetOfType(ss_arg.GetStringNext(),
                                                   DataSet::REF_FRAME); // ss_arg[2]
      if (REF == 0) {
        mprinterr("Error: Could not get reference structure [%s]\n", ss_arg[2].c_str());
        return Action::ERR;
      }
      // Get reference residue range, or use resRange
      Range refRange(ss_arg.GetStringNext(), -1); // ss_arg[3]
      if (!refRange.Empty()) {
        if (ss_holder.resRange.Size() != refRange.Size()) {
          mprinterr("Error: Reference range [%s] must match residue range [%s]\n",
                    refRange.RangeArg(), ss_holder.resRange.RangeArg());
          return Action::ERR;
        }
      } else
        refRange = ss_holder.resRange;
      // Look for phi/psi only in reference
      DihedralSearch refSearch;
      refSearch.SearchFor(MetaData::PHI);
      refSearch.SearchFor(MetaData::PSI);
      if (refSearch.FindDihedrals( REF->Top(), refRange )) return Action::ERR;
      // For each found dihedral, set theta 
      for (DihedralSearch::mask_it dih = refSearch.begin(); dih != refSearch.end(); ++dih)
      {
        double torsion = Torsion( REF->RefFrame().XYZ(dih->A0()),
                                  REF->RefFrame().XYZ(dih->A1()),
                                  REF->RefFrame().XYZ(dih->A2()),
                                  REF->RefFrame().XYZ(dih->A3()) );
        ss_holder.thetas_.push_back( (float)torsion );
      }
      secstruct_.push_back( ss_holder );

    } else if (ss_arg.Nargs() == 4 && isalpha(ss_arg[2][0])) {
    // Single dihedral type: <name>:<range>:<dih type>:<angle>
      DihedralSearch::DihedralType dtype = DihedralSearch::GetType(ss_arg[2]);
      if (ss_holder.sstype_idx == SS_EMPTY) {
        // Type not yet defined. Create new type. 
        if (dtype == MetaData::UNDEFINED) {
          mprinterr("Error: Dihedral type %s not found.\n", ss_arg[2].c_str());
          return Action::ERR;
        }
        if (!validDouble(ss_arg[3])) {
          mprinterr("Error: 4th arg (angle) is not a valid number.\n");
          return Action::ERR;
        }
        SS.push_back( SS_TYPE(convertToDouble(ss_arg[3]), 0.0, 0.0, 0.0, 2, ss_arg[0]) );
        ss_holder.sstype_idx = (int)(SS.size() - 1);
      }
      ss_holder.dihSearch_.SearchFor( dtype ); 
      secstruct_.push_back( ss_holder );

    } else if (ss_arg.Nargs() == 7 || ss_arg.Nargs() == 8) {
    // Single custom dihedral type: <name>:<range>:<at0>:<at1>:<at2>:<at3>:<angle>[:<offset>]
      if (ss_holder.sstype_idx == SS_EMPTY) {
        // Type not yet defined. Create new type.
        if (!validDouble(ss_arg[6])) {
          mprinterr("Error: 7th arg (angle) is not a valid number.\n");
          return Action::ERR;
        }
        SS.push_back( SS_TYPE(convertToDouble(ss_arg[6]), 0.0, 0.0, 0.0, 2, ss_arg[0]) );
        ss_holder.sstype_idx = (int)(SS.size() - 1);
      }
      int offset = 0;
      if (ss_arg.Nargs() == 8) {
        if (!validInteger(ss_arg[7])) {
          mprinterr("Error: 8th arg (offset) is not a valid number.\n");
          return Action::ERR;
        }
        offset = convertToInteger(ss_arg[7]);
      }
      ss_holder.dihSearch_.SearchForNewType(offset,ss_arg[2],ss_arg[3],ss_arg[4],ss_arg[5],
                                            ss_arg[0]);
      secstruct_.push_back( ss_holder );

    } else if (ss_arg.Nargs() == 4 || ss_arg.Nargs() == 6) {
    // Custom SS/turn type: <name>:<range>:<phi1>:<psi1>[:<phi2>:<psi2>]
      if (ss_holder.sstype_idx == SS_EMPTY) {
        // Type not yet defined. Create new type.
        if (!validDouble(ss_arg[2]) || !validDouble(ss_arg[3])) {
          mprinterr("Error: 3rd or 4th arg (phi1/psi1) is not a valid number.\n");
          return Action::ERR;
        }
        double phi1 = convertToDouble(ss_arg[2]);
        double psi1 = convertToDouble(ss_arg[3]);
        int isTurn = 0;
        double phi2 = 0.0;
        double psi2 = 0.0;
        if (ss_arg.Nargs() == 6) {
          isTurn = 1;
          if (!validDouble(ss_arg[4]) || !validDouble(ss_arg[5])) {
            mprinterr("Error: 5th or 6th arg (phi2/psi2) is not a valid number.\n");
            return Action::ERR;
          }
          phi2 = convertToDouble(ss_arg[4]);
          psi2 = convertToDouble(ss_arg[5]);
        }
        SS.push_back(SS_TYPE(phi1, psi1, phi2, psi2, isTurn, ss_arg[0] ));
        ss_holder.sstype_idx = (int)(SS.size() - 1);
      }
      ss_holder.dihSearch_.SearchFor(MetaData::PHI);
      ss_holder.dihSearch_.SearchFor(MetaData::PSI);
      secstruct_.push_back( ss_holder );

    } else {
      mprinterr("Error: SS arg type [%s] not recognized.\n", ss_arg[0].c_str());
      return Action::ERR;
    }
    ss_expr = actionArgs.GetStringNext();
  } // End loop over args
  if (secstruct_.empty()) {
    mprinterr("Error: No SS types defined.\n");
    return Action::ERR;
  }
  mprintf("    MAKESTRUCTURE:\n");
  for (std::vector<SecStructHolder>::iterator ss = secstruct_.begin();
                                              ss != secstruct_.end(); ++ss)
  {
    if (ss->sstype_idx != SS_EMPTY) {
      const SS_TYPE& myType = SS[ss->sstype_idx];
      switch ( myType.isTurn ) {
        case 0:
          mprintf("\tSS type %s will be applied to residue(s) %s\n",
                 myType.type_arg.c_str(), ss->resRange.RangeArg());
          break;
        case 1:
          mprintf("\tTurn type %s will be applied to residue(s) %s\n",
                  myType.type_arg.c_str(), ss->resRange.RangeArg());
          break;
        case 2:
          mprintf("\tDihedral value of %.2f will be applied to %s dihedrals in residue(s) %s\n",
                  myType.phi, myType.type_arg.c_str(), ss->resRange.RangeArg());
      }
    } else 
      mprintf("\tBackbone angles from reference will be applied to residue(s) %s\n",
              ss->resRange.RangeArg());
  }
  return Action::OK;
}
Exemple #9
0
int main(int argc,char *argv[]) {

	int c,rcode=0,colnum=0,srcfsize;
	long int numLines=10000, fsize=5, pref_indicator=0;
	char seperator=',';
	char *col_stmt=NULL;
	char *ifname=NULL,*ofname=NULL;
	FILE *ofile=NULL, *ifile=NULL;
	short int prefix_select=0;
	//char buff[MAX_LENGTH];
	char buff[2048];
	int quot_val = 0;

	arg_options argopts = { 0 , 0, 0, 0, 0, 0, 0, 0, 0 };

	while ((c = getopt(argc, argv, "vs:hnaf:o:il:z:c:")) != -1 ) 
		switch(c) {
			case 'v':
				argopts.ver_opt = 1;
			break;
			
			case 's':
				seperator = optarg[0];
			break;

			case 'h':
				Help(0);
			break;

			case 'n':
				argopts.num_opt = 1;
			break;

			case 'a':
				argopts.alph_opt = 1;
			break;

			case 'f':
				ifname = optarg;
				argopts.ifile_opt = 1;
			break;

			case 'o':
				argopts.ofile_opt = 1;
				ofname = optarg;

			break;
		
			case 'i':
				argopts.incl_opt = 1;
			break;

			case 'l':
				argopts.line_opt =1;
				numLines = atoi(optarg);
			break;

			case 'z':
				argopts.size_opt =1;
				fsize = atoi(optarg);
			break;
			
			case 'c':
				col_stmt = optarg;
			break;	

			default:
				Help(1);
			break;
		}

	if (argopts.ifile_opt == 0) {
		fprintf(stderr,"an input file must be specified\n");
		Help(1);
	}

	if ( (argopts.num_opt == 1) && (argopts.alph_opt == 1 ) ) {
		fprintf(stderr,"only one of the arguments should be specified ( -n  \\ -a) \n");
		Help(2);
	}
	else if ( argopts.alph_opt == 1 )
		fsize = fsize * 1024;

	if (argopts.alph_opt == 1 )
		prefix_select = 1;
	else
		prefix_select = 0;

	if (getenv("CSVS_SEPERATOR"))
		strncpy(&seperator,getenv("CSVS_SEPERATOR"),1);

	if (getenv("CSVS_OUTPUT"))
		ofname = getenv("CSVS_OUTPUT");

	if (getenv("CSVS_LINE_NUMBER"))
		numLines = atoi(getenv("CSVS_LINE_NUMBER"));

	if ( (getenv("CSVS_FILE_SIZE")) && (!getenv("CSVS_LINE_NUMBER")) ) 
		fsize = atoi(getenv("CSVS_FILE_SIZE")) * 1024;
	
	if ( getenv("CSVS_COLUMNS_NAME") )
		col_stmt = getenv("CSVS_COLUMNS_NAME");	
	
	//  openning the read file 
	
	if (ifile = fopen(ifname,"r")){
		if ( argopts.ver_opt == 1 )
			printf("the file %s is o.k.\n",ifname);

		argopts.ifile_opt = 1;
	}

	else {
		fprintf(stderr,"the file \"%s\" can not be opened\n",ifname);
		exit(1);
	}

	// 1) chicking if the read file is not empty 
	
	if (ifile) {

		fseek (ifile ,0, SEEK_END);
		srcfsize = ftell(ifile);

		if ( srcfsize == 0 ) {
			fclose(ifile);
			fprintf(stderr,"The Input file is empty !!!, exiting\n");
			exit(4);
		}
	}	
	
	// 2) setting the new file name according to user choice & \
	// creating the new file for writing (with a function)

	if ( argopts.ofile_opt == 0 ) {
	
		ofname = ifname;
		ofname =  basename(ofname);
	}


	if (argopts.alph_opt == 1 ) 
		strcat(ofname,".a");
	else
		strcat(ofname,".1");
	
 	if ( argopts.ver_opt == 1 )
		printf("the first output file name is : %s \n",ofname);

	// going over the read file and making sure each line is CSV competable
	

	fseek (ifile ,0, SEEK_SET);

	while( fgets(buff,2048,ifile) != NULL )  {


                if (strlen(buff) < (colnum+1))
                        break;
	
		if ( col_stmt == NULL ) {
		
			colnum = firstlinetst(buff,argopts.ver_opt,seperator,&quot_val);	
			col_stmt = (char *)calloc(strlen(buff),sizeof(char));
			strcpy(col_stmt,buff);
			continue;
		}

		

	}

	// 5) for each approved line inserting it to the new file while checking predefine limits
	// 6) if the write file as reached a limit start a new file
	// 7) if the read file is done , close all the files
	// 8) 
	


   return rcode;
}
Exemple #10
0
void main( int argc, char **argv ) {
  cout << " MultiLFS V" << MultiLFS_Version << "." << MultiLFS_Revision
       << " --- Copyright 1999 TM Productions" << endl;

  // Check for too few args
  if( argc < 4 )
    Help();

  // Check for help ?
  if( strchr( argv[1], '?' ) != 0 )
    Help();

  // Set up some variables
  char * &source = argv[1];
  char * &lfs    = argv[2];
  int    count   = atoi( argv[3] );
  int    lights  = false;
  bool   psm     = false;
  char   output[ MAX_PATH_LENGTH ] = "";

  for( int i=4; i < argc; i++ ) {
    if( argv[i][0] == '-' ) {
      switch( argv[i][1] ) {
      case 'o':
        // Output Scene Test
        if( ++i >= argc ) {
          cerr << " ERROR: No output path following argument -o!" << endl;
          cerr << " Type MultiLFS ? for help" << endl;
          exit(20);
        }
        strcpy( output, argv[i] );
        break;

      case 'l':
        // Load Lights Test
        lights = true;
        break;

      case 'p':
        // Enumerate Particle Storm information
        psm = true;
        break;

      default:
        // Unknown Argument
        cerr << " ERROR: Unrecognized argument \"" << argv[i] << "\"!" << endl;
        cerr << " Type MultiLFS ? for help" << endl;
        exit(20);
      }
    } else {
      cerr << " ERROR: Unrecognized argument \"" << argv[i] << "\"!" << endl;
      cerr << " Type MultiLFS ? for help" << endl;
      exit(20);
    }
  }

  // Test the args
  if( count < 1 ) {
    cerr << " ERROR: The count must be non-zero!" << endl;
    cerr << " Type MultiLFS ? for help" << endl;
    exit(20);
  }

  // Create the output path, if needed
  if( output[0] == '\0' ) {
    strcpy( output, source );
    char * ext = DirStrings::HasExtension( output ); // Find any extension
    if( ext )                                        // Strip the extension
      *ext = '\0';
    strcat( output, "-MultiLFSed" );                 // Append -MultiLFS
    ext = DirStrings::HasExtension( source );        // Find the original extension
    if( ext )                                        // Append the origianl extension to the output_name
      strcat( output, ext );
  } 

  // Test the paths
  if( !DirInfo::Exists( source ) ) {
    cerr << " ERROR: The source file \"" << source << "\" doesn't exist!" << endl;
    cerr << " Type MultiLFS ? for help" << endl;
    exit(20);
  }  

  if( stricmp( source, output ) == 0 ) {
    cerr << " ERROR: The source and output files cannot be the same!" << endl;
    cerr << " Type MultiLFS ? for help" << endl;
    exit(20);
  }

  // Open the Input and Output files
  ifstream in( source, ios::nocreate );
  if( !in ) {
    cerr << " ERROR: Unable to open source scene \"" << source << "\"!" << endl;
    cerr << " File may be exclusively locked by another program; aborting" << endl;
    exit(20);
  }

  ifstream lfs_in( lfs, ios::nocreate );
  if( !lfs_in ) {
    cerr << " ERROR: Unable to open load-from scene \"" << lfs << "\"!" << endl;
    cerr << " File may be exclusively locked by another program; aborting" << endl;
    exit(20);
  }

  ofstream out( output );
  if( !out ) {
    cerr << " ERROR: Unable to open output scene \"" << output << "\"!" << endl;
    cerr << " File may be in use by another program or write-protected; aborting" << endl;
    exit(20);
  }

  // Set up some variables
  char line[8192], lfs_line[8192];
  int  orig_object_count = 0;
  int  object_count = 0, lfs_object_count = 0;
  int  light_count  = 0, lfs_light_count  = 0;

  streampos lfs_end_of_objects = 0;

  DynArray< char * > psm_names;
  DynArray< int >    psm_counts;

  // The Loop
  do {
    in.getline( line, 8192 );
    if( (in.bad() || in.fail()) && !in.eof() ) {
      cerr << " ERROR:  File error reading from source \""
           << source << "\"; aborting" << endl;
      exit(20);
    }

    // Look for a new object
    if( (strnicmp( line, "LoadObject",    10 ) == 0) ||
        (strnicmp( line, "AddNullObject", 13 ) == 0) )
      object_count++;

    // Look for the end of the object data (ie: AmbientColor)
    if( strnicmp( line, "AmbientColor", 12 ) == 0 ) {
      cout << "  Adding Objects..." << endl;
      orig_object_count = object_count;
      // Load the object data from the scene <count> times
      for( int j=0; j < count; j++ ) {
        lfs_in.seekg( 0 );       // Seek to the start of the file
        lfs_object_count = 0;    // Reset the LFS object counter

        bool in_object = false;
        bool in_bone   = false;
        bool in_psm    = false;
        int  psm_match = -1;
        bool output_line = true;

        do {
          lfs_in.getline( lfs_line, 8192 );
          if( (in.bad() || in.fail()) && !in.eof() ) {
            cerr << " ERROR:  File error reading from load-from scene \""
                 << lfs << "\"; aborting" << endl;
            exit(20);
          }

          // Look for the end of the object data (AmbientColor)
          if( strnicmp( lfs_line, "AmbientColor", 12 ) == 0 )
            break;

          // Look for an object
          if( (strnicmp( lfs_line, "LoadObject",    10 ) == 0) ||
              (strnicmp( lfs_line, "AddNullObject", 13 ) == 0) ) {
            lfs_object_count++;
            in_object = true;
            in_bone   = false;
          }

          // See if we're found any bones
          if( strnicmp( lfs_line, "AddBone", 7 ) == 0 )
            in_bone = true;

          // Increment the Parent Object, but only for objects (not bones)
          if( (strnicmp( lfs_line, "ParentObject", 12 ) == 0) && !in_bone ) {
            int parent = atoi( &lfs_line[12] );
            sprintf( lfs_line, "ParentObject %d", parent + object_count );
          }

          // Increment the Morph Target
          if( strncmp( lfs_line, "MorphTarget", 11 ) == 0 ) {
            int target = atoi( &lfs_line[ 12 ] );
            sprintf( lfs_line, "MorphTarget %d", target + object_count );
          }

          // Check for Particle Storm Data
          if( psm ) {
            if( strncmp( lfs_line, "Plugin", 6 ) == 0 ) {
              if( strstr( lfs_line, "ParticleStorm" ) != 0 ){
                in_psm = true;
              }
            }

            if( in_psm ) {
              // Check for end of PS data
              if( strncmp( lfs_line, "EndPlugin", 9 ) == 0 )
                in_psm = false;

              // Check for a new PSM, or increment from an old one.
              if( strncmp( lfs_line, "MotionDataFile", 14 ) == 0 ) {
                psm_match = -1;
                for( int i=0; i < (int)psm_names.NumElements(); i++ ) {
                  if( stricmp( psm_names[i], &(lfs_line[15]) ) == 0 ) {
                    psm_match = i;
                    break;
                  }
                }

                // Not loaded yet; add it as a new one.
                if( psm_match == -1 ) {
                  psm_names.Add( strdup( &(lfs_line[15]) ) );
                  psm_match = psm_names.NumElements()-1;
                  psm_counts.Add( -1 );
                }
              }

              // Check for MotionIndex and increment it.
              if( strncmp( lfs_line, "MotionIndex", 11 ) == 0 ) {
                if( psm_counts[ psm_match ] == -1 ) // No index yet assigned; get it from the file
                  psm_counts[ psm_match ] = atoi( &(lfs_line[12]) );

                out << "MotionIndex " << psm_counts[ psm_match ]++ << endl;
                output_line = false;
              }
            }
          }

          // Output the line if we're in an object
          if( output_line ) {
            if( in_object ) {
              out << lfs_line << endl;
            }
          } else {
            output_line = true;
          }

          if( strnicmp( lfs_line, "ShadowOptions", 13 ) == 0 ) {
            in_object = false;
            in_bone   = false;
            out << endl;
          }
        
        } while( !lfs_in.eof() );

        // Add the lfs object count to the base scene object count for the next pass
        object_count += lfs_object_count;
      }
      lfs_end_of_objects = lfs_in.tellg();
    }

    // Look for a new light
    if( strnicmp( line, "AddLight", 8 ) == 0 )
      light_count++;

    if( lights ) { // Only load lights if the user asked us to
      // Look for the end of the light data (ie: ShowCamera)
      if( strnicmp( line, "ShowCamera", 10 ) == 0 ) {
        cout << "  Adding Lights..." << endl;
        object_count = orig_object_count;
        // Load the light data from the scene <count> times
        for( int j=0; j < count; j++ ) {
          lfs_in.seekg( lfs_end_of_objects, ios::beg ); // Seek to the start of the file
          lfs_light_count = 0;                          // Reset the LFS object counter

          bool in_light = false;

          do {
            lfs_in.getline( lfs_line, 8192 );
            if( (lfs_in.bad() || lfs_in.fail()) && !lfs_in.eof() ) {
              cerr << " ERROR:  File error reading from load-from scene \""
                   << lfs << "\"; aborting" << endl;
              exit(20);
            }

            // Look for the end of the light data (ShowCamera)
            if( strnicmp( lfs_line, "ShowCamera", 10 ) == 0 ) {
              break;
            }

            // Look for a light
            if( strnicmp( lfs_line, "AddLight", 8 ) == 0 ) {
              lfs_light_count++;
              in_light = true;
            }

            // Increment the Parent Object
            if( strnicmp( lfs_line, "ParentObject", 12 ) == 0 ) {
              int parent = atoi( &lfs_line[12] );
              sprintf( lfs_line, "ParentObject %d", parent + object_count );
            }

            // Increment the Target Object
            if( strnicmp( lfs_line, "TargetObject", 12 ) == 0 ) {
              int target = atoi( &lfs_line[12] );
              sprintf( lfs_line, "TargetObject %d", target + object_count );
            }

            out << lfs_line << endl;
          } while( !lfs_in.eof() );

          // Add the lfs object count to the base scene object count for the next pass
          light_count += lfs_light_count;
          object_count += lfs_object_count;
        }
      }
    }

    out << line << endl;

  } while( !in.eof() );

  // Free the strdup()ed PSM Names
  if( psm ) {
    if( psm_names.NumElements() > 0 )
      cout << " PSMs found:" << endl;
    else
      cout << " No PSMs found in load-from scene!" << endl;

    for( i=0; i < (int)psm_names.NumElements(); i++ ) {
      cout << "   Enums: " << setw(10) << psm_counts[i] << "  Name: " << psm_names[i] << endl;
      free( psm_names[i] );
    }
  }

  cout << "  Successfully added " << count << " instances of \"" << lfs
       << "\" to " << output << "\"!" << endl;

}
Exemple #11
0
int
main(
    int argc,
    char** ppszArgv
    )
{
    DWORD dwError = 0;
    DWORD dwIndex = 0;

    dwError = SrvSvcInitMemory();
    BAIL_ON_SRVSVC_ERROR(dwError);

    if (argc < 2)
    {
        Usage();
        return 1;
    }

    for (dwIndex = 1; dwIndex < argc; dwIndex++)
    {
        if (!strcasecmp(ppszArgv[dwIndex], "--server"))
        {
            dwError = LwMbsToWc16s(ppszArgv[++dwIndex], &gState.pwszServerName);
            BAIL_ON_SRVSVC_ERROR(dwError);
        }
        else if (!strcasecmp(ppszArgv[dwIndex], "--help"))
        {
            Help();
            return 1;
        }
        else if (!strcasecmp(ppszArgv[dwIndex], "--usage"))
        {
            Help();
            return 1;
        }
        else if (!strcasecmp(ppszArgv[dwIndex], "enum"))
        {
            dwError = Enum(argc - dwIndex, ppszArgv + dwIndex);
            BAIL_ON_SRVSVC_ERROR(dwError);
            break;
        }
        else if (!strcasecmp(ppszArgv[dwIndex], "enum-info"))
        {
            dwError = EnumInfo(argc - dwIndex, ppszArgv + dwIndex);
            BAIL_ON_SRVSVC_ERROR(dwError);
            break;
        }
        else if (!strcasecmp(ppszArgv[dwIndex], "get-info"))
        {
            dwError = GetInfo(argc - dwIndex, ppszArgv + dwIndex);
            BAIL_ON_SRVSVC_ERROR(dwError);
            break;
        }
        else if (!strcasecmp(ppszArgv[dwIndex], "set-info"))
        {
            dwError = SetInfo(argc - dwIndex, ppszArgv + dwIndex);
            BAIL_ON_SRVSVC_ERROR(dwError);
            break;
        }
        else if (!strcasecmp(ppszArgv[dwIndex], "add"))
        {
            dwError = Add(argc - dwIndex, ppszArgv + dwIndex);
            BAIL_ON_SRVSVC_ERROR(dwError);
            break;
        }
        else if (!strcasecmp(ppszArgv[dwIndex], "del"))
        {
            dwError = Del(argc - dwIndex, ppszArgv + dwIndex);
            BAIL_ON_SRVSVC_ERROR(dwError);
            break;
        }
        else
        {
            Usage();
            return 1;
        }
    }

error:

    if (dwError)
    {
        fprintf(stderr, "%s\n", LwWin32ExtErrorToName(dwError));
        return 1;
    }
    else
    {
        return 0;
    }
}
Exemple #12
0
int main(int argc, char **argv)
{
    PRThread **threads;
    int num_thread_funcs = sizeof(threadFuncs)/sizeof(NSPRThreadFunc);
    int num_thread_scopes = sizeof(threadScopes)/sizeof(PRThreadScope);
    int i, j;
    int idx;
    PRInt32 secs;
    PLOptStatus os;
    PLOptState *opt = PL_CreateOptState(argc, argv, "dl:t:h");

    while (PL_OPT_EOL != (os = PL_GetNextOpt(opt))) {
        if (PL_OPT_BAD == os) continue;
        switch (opt->option) {
            case 'd':  /* debug mode */
                debug_mode = PR_TRUE;
                break;
            case 'l':  /* lead time */
                lead_time_secs = atoi(opt->value);
                break;
            case 't':  /* tolerance */
                tolerance_msecs = atoi(opt->value);
                break;
            case 'h':
            default:
                Help();
                return 2;
        }
    }
    PL_DestroyOptState(opt);

    if (debug_mode) {
        fprintf(stderr, "lead time: %d secs\n", lead_time_secs);
        fprintf(stderr, "tolerance: %d msecs\n", tolerance_msecs);
    }

    start_time = PR_IntervalNow();
#if defined(XP_UNIX)
    gettimeofday(&start_time_tv, NULL);
#endif
#if defined(WIN32)
    _ftime(&start_time_tb);
#endif
    tolerance = PR_MillisecondsToInterval(tolerance_msecs);

    threads = PR_Malloc(
            num_thread_scopes * num_thread_funcs * sizeof(PRThread*));
    if (threads == NULL) {
        fprintf(stderr, "PR_Malloc failed\n");
        exit(1);
    }

    /* start to time out 5 seconds after a rollover date */
    secs = lead_time_secs + 5;
    idx = 0;
    for (i = 0; i < num_thread_scopes; i++) { 
        for (j = 0; j < num_thread_funcs; j++) {
            threads[idx] = PR_CreateThread(PR_USER_THREAD, threadFuncs[j],
                (void*)PR_SecondsToInterval(secs), PR_PRIORITY_NORMAL,
                threadScopes[i], PR_JOINABLE_THREAD, 0);
            if (threads[idx] == NULL) {
                fprintf(stderr, "PR_CreateThread failed\n");
                exit(1);
            }
            secs++;
            idx++;
        }
    }
    for (idx = 0; idx < num_thread_scopes*num_thread_funcs; idx++) {
        if (PR_JoinThread(threads[idx]) == PR_FAILURE) {
            fprintf(stderr, "PR_JoinThread failed\n");
            exit(1);
        }
    }
    PR_Free(threads);
    printf("PASS\n");
    return 0;
}
// Поток приложения вызывает WindowProc всякий раз, когда для окна есть сообщение.
// Window - окно, Message - сообщение, *_parameter - данные, которые передаются вместе с сообщением.
MRESULT EXPENTRY Mouse_Clipboard_WndProc( HWND Window, ULONG Message, MPARAM First_parameter, MPARAM Second_parameter )
{
 // Указатель на страницу.
 PPAGE Page = Enhancer.Pages.Mouse_clipboard;

 // Проверяем сообщение.
 switch( Message )
  {
   // Отображаем настройки.
   case SM_SHOW_SETTINGS:
    {
     BYTE Value = 0; if( MouseMapper.Settings.Use_middle_button_for_CopyPaste ) Value = 1;
     WinSendDlgItemMsg( Window, Mouse_Clipboard.Settings.Use_MB_ID, BM_SETCHECK, MPFROMLONG( Value ), 0 );
     WinEnableWindow( WinWindowFromID( Window, Mouse_Clipboard.Settings.Mouse_cmbox_ID ), Value );

     BYTE Enabled = 1;
     if( WinQuerySysValue( QueryDesktopWindow(), SV_CMOUSEBUTTONS ) != 3 ) Enabled = 0;

     WinEnableWindow( WinWindowFromID( Window, Mouse_Clipboard.Settings.Use_MB_ID ), Enabled );
     WinEnableWindow( WinWindowFromID( Window, Mouse_Clipboard.Settings.Mouse_cmbox_ID ), Enabled );

     if( MouseMapper.Settings.Use_middle_button_for_CopyPaste )
      {
       INT Selected_string = MouseMapper.Settings.Use_middle_button_for_CopyPaste - 1;
       WinSendDlgItemMsg( Window, Mouse_Clipboard.Settings.Mouse_cmbox_ID, LM_SELECTITEM, MPFROMLONG( Selected_string ), MPFROMLONG( 1 ) );
      }
    }
   return 0;

   // Распознаем настройки.
   case SM_RECOGNIZE_SELECTION:
    {
     LONG Selected_string = (LONG) WinSendDlgItemMsg( Window, Mouse_Clipboard.Settings.Mouse_cmbox_ID, LM_QUERYSELECTION, (MPARAM) LIT_CURSOR, 0 );
     if( Selected_string != LIT_NONE ) MouseMapper.Settings.Use_middle_button_for_CopyPaste = Selected_string + 1;
    }
   return 0;

   // Следим за полями ввода.
   case WM_CONTROL:
    {
     ULONG WM_Control_Window_ID = SHORT1FROMMP( First_parameter );
     ULONG WM_Control_Action_ID = SHORT2FROMMP( First_parameter );

     if( WM_Control_Window_ID == Mouse_Clipboard.Settings.Use_MB_ID )
      {
       switch( WM_Control_Action_ID )
        {
         case BN_CLICKED:
         case BN_DBLCLICKED:
          {
           ULONG Button_is_checked = (ULONG) WinSendDlgItemMsg( Window, WM_Control_Window_ID, BM_QUERYCHECK, 0, 0 );

           if( Button_is_checked ) MouseMapper.Settings.Use_middle_button_for_CopyPaste = 0;
           else MouseMapper.Settings.Use_middle_button_for_CopyPaste = 1;

           WinSendMsg( Window, SM_SHOW_SETTINGS, 0, 0 );
          }
         break;
        }
      }

     if( WM_Control_Window_ID == Mouse_Clipboard.Settings.Mouse_cmbox_ID )
      {
       switch( WM_Control_Action_ID )
        {
         case CBN_ENTER:
          {
           WinSendMsg( Window, SM_RECOGNIZE_SELECTION, 0, 0 );
          }
         break;
        }
      }
    }
   return 0;

   // Обрабатываем нажатия на кнопки.
   case WM_COMMAND:
    {
     ULONG WM_Control_Button_ID = SHORT1FROMMP( First_parameter );

     if( WM_Control_Button_ID == OK_BUTTON_ID )
      {
       CHAR Settings_file_name[ SIZE_OF_PATH ] = ""; GetSettingsFileName( Settings_file_name );
       HINI Ini_file = OpenIniProfile( Enhancer.Application, Settings_file_name );

       if( Ini_file )
        {
         PrfWriteProfileData( Ini_file, "Settings", "Use middle button for CopyPaste", &MouseMapper.Settings.Use_middle_button_for_CopyPaste, sizeof( BYTE ) );

         PrfCloseProfile( Ini_file );

         BroadcastRSMessages();
         NiceReadSettings();
        }
      }

     if( WM_Control_Button_ID == PD_BUTTON_ID )
      {
       if( Page->SetDefSettings ) Page->SetDefSettings( Page->Settings_to_show );
       if( Page->SetDefSettings_Ext1 ) Page->SetDefSettings_Ext1( Page->Settings_to_show );
       if( Page->SetDefSettings_Ext2 ) Page->SetDefSettings_Ext2( Page->Settings_to_show );
       if( Page->SetDefSettings_Ext3 ) Page->SetDefSettings_Ext3( Page->Settings_to_show );

       WinPostMsg( Window, WM_COMMAND, (MPARAM) OK_BUTTON_ID, 0 );
      }

     if( WM_Control_Button_ID == HP_BUTTON_ID )
      {
       Help( Page->Settings_to_show, Enhancer.Code_page );
      }
    }
   return 0;
  }

 // Возврат.
 return WinDefWindowProc( Window, Message, First_parameter, Second_parameter );
}
Exemple #14
0
int main(void)
{
//extern variables
char *help_topic=NULL,*fname=NULL,buff[5000]={'\0'},file[50]={};
int logc,logr,ch,i,j,k,flag;
FILE *fp;

// initialise curses mode and colors
initCurses();
noecho();
cbreak();
keypad(stdscr,TRUE);
mousemask(ALL_MOUSE_EVENTS,NULL);
curs_set(0);

//displays starting blue screen
Screen();
	while(1)
	{
		int ch;
		ch=getResponse();
		switch(ch)
		{
			//file menu
			case 1:
					//pop up menu file
					(WINDOW**)draw_menu(fmenu,SIZE(fmenu),1,0);
			break;
			
			//new item
			case 2:
				refresh();
				//draws black screen
				new_file();
				noecho();
				//displays filename and line number on black screen
				New();						
			break;
			
			//Return To Shell
			case 5:
				clear();
	       		refresh();
	       		endwin();
	       		system("sh");
	       		clear();
				refresh();
				Screen();
			break;
			
			//exit menu
			case 6:
				clear();
	    		refresh();
				endwin();
				exit(EXIT_SUCCESS);
			break;
			
			/*compile menu
			case 7:
				//pop up menu compile
					(WINDOW**)draw_menu(cmenu,SIZE(cmenu),1,12);
			break;
			
			*/
			/*compile item
			case 8:
				compile();
			break;*/
			
			//help menu
			case 11:
				//pop up  help menu
 					(WINDOW**)draw_menu(hmenu,SIZE(hmenu),1,27);
			break;
			
			//help index
			case KEY_F(1):
			case 12:
				Help();
			break;
			
			//help topic
			case 13:
				help_topic=(char*)calloc(30,sizeof(char));
				help_topic=dialog("| Help |"," Find "," Cancel ");
			break;
			
			
			
			//open file
			case KEY_F(3):
			case 3:
						k=0;
					for(i=2;i<22;++i)
					{
						for(j=0;j<78;++j)
							buff[k++]=(mvinch(i,j)&A_CHARTEXT);
						buff[k++]='\n';
					}
				new_file();
					//pops up open dialogbox				
				fname=(char*)calloc(30,sizeof(char));
				fname=dialog("| Open |"," Open "," Cancel ");
				
				//if user press cancel display screen contents
				if((strlen(fname)==0))
				{
					logc=1;logr=2;
					for(k=0;buff[k]!='\0';++k)
					{
						refresh();
						if(buff[k]=='\n')
						{
					        logr+=1;
					        logc=1;
					       	move(logr+1,logc);
						}
						else
						{
							mvaddch(logr,logc,buff[k]);
							logc+=1;
						}
					}
				}
				
				//othewise open a file and display it's contents
				else
				{
					//redraws new screen
					new_file();
				
				
					if(!(fp=fopen(fname,"r")))
					{
						warning("| Warning |","	No such file ","Press a key to return !!!");
						getch();
						//new_file();
							logc=1;logr=2;
							for(k=0;buff[k]!='\0';++k)
							{
								refresh();
								if(buff[k]=='\n')
								{
					        		logr+=1;
					        		logc=1;
					       			 move(logr+1,logc);
								}
								else
								{
									mvaddch(logr,logc,buff[k]);
									logc+=1;
								}
							}	
					
					}
					//if file is exist display contents 
					else
					{	
						new_file();
						logc=1;logr=2;
						while((ch=fgetc(fp))!=EOF)
						{
							if(ch=='\n')
							{
						        logr+=1;
						        logc=1;
						        move(logr+1,logc);
							}
							else
							{
								mvaddch(logr,logc,ch);
								logc+=1;
							}
						}
						fclose(fp);
						move(2,2);
						refresh();
						
						//displays file name
							move(1,2);
						hline(ACS_HLINE,75);
						strcat(file,"| ");
						strcat(file,fname);
						strcat(file," |");
						//move(1,2);
						//hline(ACS_HLINE,60);
						writeString(stdscr,1,35,file,white_black);
					}
				}
			break;
			
			
		}
	}
}
Exemple #15
0
int main(int argc, const char* argv[]) {
  int log_tab_size = 12;
  int compress = 1;
  FSCCodingMethod method = CODING_METHOD_DEFAULT;
  int stats_only = 0;
  int ok = 0;
  int c;

  for (c = 1; c < argc; ++c) {
    if (!strcmp(argv[c], "-l") && c + 1 < argc) {
      log_tab_size = atoi(argv[++c]);
      if (log_tab_size > LOG_TAB_SIZE) log_tab_size = LOG_TAB_SIZE;
      else if (log_tab_size < 2) log_tab_size = 2;
    } else if (FSCParseCodingMethodOpt(argv[c], &method)) {
      continue;
    } else if (!strcmp(argv[c], "-m") && c + 1 < argc) {
      method = (FSCCodingMethod)atoi(argv[++c]);
    } else if (!strcmp(argv[c], "-s")) {
      stats_only = 1;
    } else if (!strcmp(argv[c], "-c")) {
      compress = 1;
    } else if (!strcmp(argv[c], "-d")) {
      compress = 0;
    } else if (!strcmp(argv[c], "-h")) {
      Help();
    }
  }

  uint8_t* out = NULL;
  size_t out_size = 0;
  uint8_t* in = NULL;
  size_t in_size = 0;

  // Read input
  fseek(stdin, 0L, SEEK_END);
  in_size = ftell(stdin);
  fseek(stdin, 0L, SEEK_SET);
  if (in_size == (size_t)-1) {
    fprintf(stderr, "Missing/erroneous input!\n");
    goto End;
  }
  in = (uint8_t*)malloc(in_size * sizeof(*in));
  if (in == NULL) {
    fprintf(stderr, "Malloc(%lu) failed!\n", in_size);
    exit(-1);
  }
  ok = (fread(in, in_size, 1, stdin) == 1);
  if (!ok) {
    fprintf(stderr, "Error reading from stdin!\n");
    goto End;
  }

  // Compress or decompress.
  MyClock start, tmp;
  if (compress) {   // encoding
    GetElapsed(&start, NULL);
    ok = FSCEncode(in, in_size, &out, &out_size, log_tab_size, method);
    if (!ok) {
      fprintf(stderr, "ERROR while encoding!\n");
      goto End;
    }

    if (stats_only) {
      const double elapsed = GetElapsed(&tmp, &start);
      const double entropy = GetEntropy(in, in_size);
      const double MS = 1.e-6 * in_size;
      const double reduction = 1. * out_size / in_size;
      printf("Enc time: %.3f sec [%.2lf MS/s] (%ld bytes out, %ld in).\n",
             elapsed, MS / elapsed, out_size, in_size);
      printf("Entropy: %.4lf vs expected %.4lf "
             "(off by %.5lf bit/symbol [%.3lf%%])\n",
             reduction, entropy, reduction - entropy,
             100. * (reduction - entropy) / entropy);
    }
  } else {         // decoding
    GetElapsed(&start, NULL);
    ok = FSCDecode(in, in_size, &out, &out_size);
    if (!ok) {
      fprintf(stderr, "ERROR while decoding!\n");
      goto End;
    }
    if (stats_only) {
      const double elapsed = GetElapsed(&tmp, &start);
      const double MS = 1.e-6 * out_size;
      printf("Dec time: %.3f sec [%.2lf MS/s].\n", elapsed, MS / elapsed);
    }
  }

  if (!stats_only) {
    ok = (fwrite(out, out_size, 1, stdout) == 1);
    if (!ok) {
      fprintf(stderr, "Error writing to stdout!\n");
      goto End;
    }
  }

 End:
  free(in);
  free(out);
  return !ok;
}