Ejemplo n.º 1
0
/////////////////////////////////////////////////////////////////
// TMainClient
// -----------
//
void TMainClient::CmFileExtractRaw ()
{
	static char ObjectName[12];
	WadPtr wad;
	MDirPtr entry;
	FILE *file;

	SET_HELP_CONTEXT(Extract_object);
	// Get objet name
	// Stupid InputDialog box, would be better with a list box
	if ( TInputDialog (this, "Enter object name", "Object :",
					   ObjectName, 12).Execute() != IDOK )
		goto End;

	// Check the name of the object exists
	for (entry = MasterDir ; entry != NULL ; entry = entry->next)
		if ( strnicmp (entry->dir.name, ObjectName, 8) == 0 )
			break;

	if ( entry == NULL )
	{
		Notify ("The object \"%s\" doesn't exist", ObjectName);
		goto End;
	}

	//
	// Display standard Open dialog box to select a file name.
	//
	*FileData.FileName = 0;
	if (TFileSaveDialog(this, FileData).Execute() != IDOK)
		goto End;

	// Check WAD isn't opened
	for (wad = WadFileList; wad; wad = wad->next)
		if (!stricmp(FileData.FileName, wad->filename))
		   break;

	if (wad)
	{
		Notify ("You may not overwrite an opened Wad file with raw data");
		goto End;
	}

	// Opening .RAW file in .WAD entry
	WorkMessage ("Saving directory entry data to \"%s\".", FileData.FileName);

	file = fopen(FileData.FileName, "wb");
	if (file == NULL)
	{
		Notify ("Error opening output file \"%s\"", FileData.FileName);
	}
	else
	{
		SaveEntryToRawFile(file, ObjectName);
		fclose(file);
	}
End:
	RESTORE_HELP_CONTEXT();
}
Ejemplo n.º 2
0
/////////////////////////////////////////////////////////////////
// TMainClient
// -----------
//
void TMainClient::CmFileInsertRaw ()
{
	static char ObjectName[12];
	char input[MAX_PATH];
	MDirPtr entry;
	FILE *raw;
	FILE *file;
	WadPtr wad;

	SET_HELP_CONTEXT(Insert_RAW_file);
	//
	// Display standard Open dialog box to select a file name.
	//
	*FileData.FileName = 0;
	if (TFileOpenDialog(this, FileData).Execute() != IDOK)
		goto End;

	// Get objet name
	//TODO: Stupid InputDialog box, would be better with a list box
	if ( TInputDialog (this, "Enter object name", "Object :",
					   ObjectName, 12).Execute() != IDOK )
		goto End;

	// Check the name of the object exists
	for (entry = MasterDir ; entry != NULL ; entry = entry->next)
		if ( strnicmp (entry->dir.name, ObjectName, 8) == 0 )
			break;

	if ( entry == NULL )
	{
		Notify ("The object \"%s\" doesn't exist", ObjectName);
		goto End;
	}

	// Check WAD file isn't opened
	raw = fopen(FileData.FileName, "rb");
	if (raw == NULL)
	{
		Notify ("Error opening input file \"%s\"", FileData.FileName);
		goto End;
	}

	// kluge: Check WAD isn't opened
	strcpy (input, ObjectName);
	strcat (input, ".WAD");

	for (wad = WadFileList; wad; wad = wad->next)
		if (!stricmp( input, wad->filename))
		   break;

	if (wad)
	{
		Notify ("The Wad file \"%s\" is already in use. You may not "
				"overwrite it.", input);
		goto End;
	}

	// Opening .RAW file in .WAD entry
	WorkMessage ("Including new object %s in \"%s\".", ObjectName, input);

	file = fopen (input, "wb");
	if (file == NULL)
		Notify ("Error opening output file \"%s\"", input);

	SaveEntryFromRawFile (file, raw, ObjectName);

	fclose(raw);
	fclose(file);
End:
	RESTORE_HELP_CONTEXT();
}
Ejemplo n.º 3
0
void ParseConfigFileOptions(char *filename)
{
	FILE *cfgfile;
	char  line[1024];
	char *value;
	char *option;
	char *p;
	int   optnum;

	if ((cfgfile = fopen (filename, "r")) == NULL)
	{
		Notify ("Configuration file not found (%s)", filename);
		return;
	}

	while (fgets (line, 1024, cfgfile) != NULL)
	{
		if (line[0] == '#' || strlen( line) < 2)
			continue;

		if (line[ strlen( line) - 1] == '\n')
			line[ strlen( line) - 1] = '\0';

		/* skip blanks before the option name */
		option = line;
		while (isspace( option[ 0]))
			option++;

		/* skip the option name */
		value = option;
		while (value[ 0] && value[ 0] != '=' && !isspace( value[ 0]))
			value++;

		if (!value[0])
			ProgError( "invalid line in %s (ends prematurely)", filename);

		if (value[0] == '=')
		{
			/* mark the end of the option name */
			value[0] = '\0';
		}
		else
		{
			/* mark the end of the option name */
			value[0] = '\0';
			value++;

			/* skip blanks after the option name */
			while (isspace( value[ 0]))
				value++;
			if (value[ 0] != '=')
				ProgError( "invalid line in %s (no '=')", filename);
		}
		value++;

		/* skip blanks after the equal sign */
		while (isspace( value[ 0]))
			value++;

		for (optnum = 0; options[ optnum].opt_type != OPT_END; optnum++)
		{
			if (!stricmp( option, options[ optnum].long_name))
			{
				switch (options[ optnum].opt_type)
				{
					case OPT_BOOLEAN:
						if ( !stricmp(value, "yes") ||
							 !stricmp(value, "true") ||
							 !stricmp(value, "on") ||
							 !stricmp(value, "1"))
						{
							*((Bool *) (options[ optnum].data_ptr)) = TRUE;
							if (options[ optnum].msg_if_true)
								WorkMessage("%s", options[ optnum].msg_if_true);
						}
						else if ( !stricmp(value, "no") ||
								  !stricmp(value, "false") ||
								  !stricmp(value, "off") ||
								  !stricmp(value, "0"))
						{
							*((Bool *) (options[ optnum].data_ptr)) = FALSE;
							if (options[ optnum].msg_if_false)
								WorkMessage("%s", options[ optnum].msg_if_false);
						}
						else
							ProgError("Invalid value for option %s: \"%s\"", option, value);
					break;

					case OPT_INTEGER:
						*((int *) (options[ optnum].data_ptr)) = atoi( value);
						if (options[ optnum].msg_if_true)
							WorkMessage("%s: %d", options[ optnum].msg_if_true, atoi( value)) ;
						break;

					case OPT_STRING:
						p = (char *)GetMemory( (strlen( value) + 1) * sizeof( char));
						strcpy( p, value);
						*((char **) (options[ optnum].data_ptr)) = p;
						if (options[ optnum].msg_if_true)
							WorkMessage("%s: %s", options[ optnum].msg_if_true, value);
						break;

					case OPT_STRINGACC:
						p = (char *)GetMemory( (strlen( value) + 1) * sizeof( char));
						strcpy( p, value);
						AppendItemToList( (char ***) options[ optnum].data_ptr, p);
						if (options[ optnum].msg_if_true)
							WorkMessage("%s: %s", options[ optnum].msg_if_true, value);
						break;

					case OPT_STRINGLIST:
						while (value[ 0])
						{
							option = value;
							while (option[ 0] && !isspace( option[ 0]))
								option++;
							option[ 0] = '\0';
							option++;

							while (isspace( option[ 0]))
								option++;

							p = (char *)GetMemory( (strlen( value) + 1) * sizeof( char));
							strcpy( p, value);
							AppendItemToList( (char ***) options[ optnum].data_ptr, p);

							if (options[ optnum].msg_if_true)
								WorkMessage("%s: %s", options[ optnum].msg_if_true, value);
							value = option;
						}
						break;

					default:
						ProgError("Unknown option type (BUG!)");
				}
				break;
			}
		}
		if (options[ optnum].opt_type == OPT_END)
			ProgError("Invalid option in %s: \"%s\"", filename, option);
	}

	fclose( cfgfile);
}
Ejemplo n.º 4
0
void ParseCommandLineOptions( int argc, char *argv[], char *init_level)
{
	int optnum;

	init_level[0] = 0;
	while (argc > 0)
	{
		if (argv[0][0] != '-' && argv[0][0] != '+')
		{
//			Notify ("Options must start with '-' or '+'");
		   strcpy(init_level, argv[0]);
			argc--;
			argv++;
			continue;
		}

		if ( !strcmp (argv[0], "-?") ||
			 !stricmp(argv[0], "-h") ||
			 !stricmp(argv[0], "-help"))
		{
			Usage();
			exit(1);
		}

		for (optnum = 0; options[optnum].opt_type != OPT_END; optnum++)
		{
			//BUG: We must test there's a short and/or long name before
			//     using stricmp.
			if ( (options[optnum].short_name != NULL &&
				  !stricmp(&(argv[0][1]), options[optnum].short_name)) ||
				 (options[optnum].long_name != NULL &&
				  !stricmp(&(argv[0][1]), options[optnum].long_name)) )
			{
				switch (options[optnum].opt_type)
				{
				case OPT_BOOLEAN:
					if (argv[ 0][ 0] == '-')
					{
						*((Bool *) (options[ optnum].data_ptr)) = TRUE;
						if (options[ optnum].msg_if_true)
							WorkMessage("%s", options[ optnum].msg_if_true) ;
					}
					else
					{
						*((Bool *) (options[ optnum].data_ptr)) = FALSE;
						if (options[ optnum].msg_if_false)
							WorkMessage("%s", options[ optnum].msg_if_false);
					}
					break;

				case OPT_INTEGER:
					if (argc <= 1)
					{
						Notify ("Missing argument after \"%s\"", argv[0]);
						argc--;
						argv++;
						break;
					}
					argv++;
					argc--;
					*((int *) (options[ optnum].data_ptr)) = atoi( argv[ 0]);
					if (options[ optnum].msg_if_true)
						WorkMessage("%s: %d", options[ optnum].msg_if_true,
											  atoi( argv[ 0]));
					break;

				case OPT_STRING:
					if (argc <= 1)
					{
						Notify ("missing argument after \"%s\"", argv[0]);
						argc--;
						argv++;
						break;
					}
					argv++;
					argc--;
					*((char **) (options[ optnum].data_ptr)) = argv[ 0];
					if (options[ optnum].msg_if_true)
						WorkMessage("%s: %s", options[ optnum].msg_if_true,
											  argv[ 0]);
					break;

				case OPT_STRINGACC:
					if (argc <= 1)
					{
						Notify ("Missing argument after \"%s\"", argv[0]);
						argc--;
						argv++;
						break;
					}
					argv++;
					argc--;
					AppendItemToList( (char ***) options[ optnum].data_ptr,
									  argv[ 0]);
					if (options[ optnum].msg_if_true)
						WorkMessage("%s: %s", options[ optnum].msg_if_true,
											  argv[ 0]) ;
					break;

				case OPT_STRINGLIST:
					if (argc <= 1)
					{
						Notify ("Missing argument after \"%s\"", argv[0]);
						argc--;
						argv++;
						break;
					}
					while (argc > 1 && argv[ 1][ 0] != '-' && argv[ 1][ 0] != '+')
					{
						argv++;
						argc--;
						AppendItemToList( (char ***) options[ optnum].data_ptr,
										  argv[ 0]);
						if (options[optnum].msg_if_true)
							WorkMessage("%s: %s", options[ optnum].msg_if_true,
												  argv[ 0]);
					}
					break;

				default:
					Notify ("Unknown option type (BUG!)");
				} /* end switch */
				break;
			} /* end if */
		} /* end for */
		if (options[optnum].opt_type == OPT_END)
			Notify ("Invalid argument: \"%s\"", argv[0]);
		argv++;
		argc--;
	} /* end while */
}