static BOOL PopRegKeyArgs(TCHAR * path, BOOL *options)
{
  TCHAR * param = (TCHAR *)GlobalAlloc(GPTR, g_string_size*sizeof(TCHAR));
  int iRootKey;
  BOOL success = FALSE;

  if (!popstring(param))
  {
    *options = FALSE;
    if (lstrcmpi(param, _T("/noinherit")) == 0)
    {
      *options = TRUE;
      popstring(param);
    }
  }
  else
    ABORT("Root key name missing");

  iRootKey = ParseEnum(g_rootKeyNames, param);
  if (!ARRAY_CONTAINS(g_rootKeyPrefixes, iRootKey))
    ABORT_s("Bad root key name (%s)", param);

  if (popstring(param))
    ABORT("Registry key name missing");

  path[0] = 0;
  lstrcat(path, g_rootKeyPrefixes[iRootKey]);
  lstrcat(path, param);

  success = TRUE;

cleanup:
  GlobalFree(param);
  return success;
}
Example #2
0
//==========================================================================
//
// Reads an actor definition
//
//==========================================================================
static void ParseActor(FScanner &sc)
{
	PClassActor *info = NULL;
	Baggage bag;

	info = ParseActorHeader(sc, &bag);
	sc.MustGetToken('{');
	while (sc.MustGetAnyToken(), sc.TokenType != '}')
	{
		switch (sc.TokenType)
		{
		case TK_Action:
			ParseActionDef (sc, info);
			break;

		case TK_Const:
			ParseConstant (sc, &info->Symbols, info);
			break;

		case TK_Enum:
			ParseEnum (sc, &info->Symbols, info);
			break;

		case TK_Native:
			ParseNativeFunction (sc, info);
			break;

		case TK_Var:
			ParseUserVariable (sc, &info->Symbols, info);
			break;

		case TK_Identifier:
			ParseActorProperty(sc, bag);
			break;

		case TK_States:
			if (bag.StateSet) 
			{
				sc.ScriptMessage("'%s' contains multiple state declarations", bag.Info->TypeName.GetChars());
				FScriptPosition::ErrorCounter++;
			}
			ParseStates(sc, bag.Info, (AActor *)bag.Info->Defaults, bag);
			bag.StateSet = true;
			break;

		case '+':
		case '-':
			ParseActorFlag(sc, bag, sc.TokenType);
			break;

		default:
			sc.ScriptError("Unexpected '%s' in definition of '%s'", sc.String, bag.Info->TypeName.GetChars());
			break;
		}
	}
	FinishActor(sc, info, bag);
	sc.SetCMode (false);
}
//==========================================================================
//
// Reads an actor definition
//
//==========================================================================
static void ParseActor(FScanner &sc)
{
	FActorInfo * info=NULL;
	Baggage bag;

	info = ParseActorHeader(sc, &bag);
	sc.MustGetToken('{');
	while (sc.MustGetAnyToken(), sc.TokenType != '}')
	{
		switch (sc.TokenType)
		{
		case TK_Action:
			ParseActionDef (sc, info->Class);
			break;

		case TK_Const:
			ParseConstant (sc, &info->Class->Symbols, info->Class);
			break;

		case TK_Enum:
			ParseEnum (sc, &info->Class->Symbols, info->Class);
			break;

		case TK_Native:
			ParseNativeVariable (sc, &info->Class->Symbols, info->Class);
			break;

		case TK_Var:
			ParseUserVariable (sc, &info->Class->Symbols, info->Class);
			break;

		case TK_Identifier:
			ParseActorProperty(sc, bag);
			break;

		case '+':
		case '-':
			ParseActorFlag(sc, bag, sc.TokenType);
			break;

		default:
			sc.ScriptError("Unexpected '%s' in definition of '%s'", sc.String, bag.Info->Class->TypeName.GetChars());
			break;
		}
	}
	FinishActor(sc, info, bag);
	sc.SetCMode (false);
}
/* i know: this function is far to generious in accepting strings. 
 * but hey: this all is about code size, isn't it? 
 * so i can live with that pretty well.
 */
static DWORD ParsePermissions(const SchemeType * scheme, TCHAR * str)
{
  DWORD perms = 0;
  TCHAR * first, * last;

  for(first = str; *first; first = last)
  {
    int token;

    while(*first && *first <= ' ') ++first;
    for(last = first; *last && *last > ' ' && *last != '|' && 
      *last != '+'; ++last);
    if (*last) *last++ = '\0';

    token = ParseEnum(scheme->permissionNames, first);
    if (token >= 0 && token < scheme->permissionCount)
      perms|= scheme->permissionFlags[token];
  }

  return perms;
}
Example #5
0
int
ParseDiversionReason(struct asn1_parm *pc, u_char *p, u_char *end, char *str)
{
	int ret;
	int diversionReason;

	ret = ParseEnum(pc, p, end, &diversionReason);
	if (ret < 0)
		return ret;
	
	switch (diversionReason) {
	case 0: sprintf(str, "unknown"); break;
	case 1: sprintf(str, "CFU"); break;
	case 2: sprintf(str, "CFB"); break;
	case 3: sprintf(str, "CFNR"); break;
	case 4: sprintf(str, "CD (Alerting)"); break;
	case 5: sprintf(str, "CD (Immediate)"); break;
	default: sprintf(str, "(%d)", diversionReason); break;
	}

	return ret;
}
int ParseBasicService(struct asn1_parm *pc, u_char *p, u_char *end, int *basicService)
{
	return ParseEnum(pc, p, end, basicService);
}
Example #7
0
/*
 * File ::= { Declaration }
 * Declaration ::= Node
 *               | Operation
 *               | OperationCase
 *               | Option
 *               | Enum
 *               | Literal
 *               | Header
 *               | Output
 *               | Common
 *               | Include
 * Literal ::= { LiteralFlag } ( LITERAL_DEFNS | LITERAL_END )
 * LiteralFlag ::= %both | %decls | %end
 * Header ::= %header STRING
 * Output ::= %output STRING
 * Common ::= %common
 * Include ::= %include [ %readonly ] STRING
 */
void TreeCCParse(TreeCCContext *context)
{
	/* Fetch the first token from the input stream */
	if(!TreeCCNextToken(context->input))
	{
		return;
	}

	/* Parse lines of input until the input is exhausted */
	do
	{
		switch(context->input->token)
		{
			case TREECC_TOKEN_EOF:
			{
				/* Shouldn't happen, but ignore it if it does */
			}
			break;

			case TREECC_TOKEN_IDENTIFIER:
			{
				/* Parse an operation case definition */
				ParseOperationCase(context);
			}
			continue;	/* Skip the call to TreeCCNextToken */

			case TREECC_TOKEN_LITERAL_DEFNS:
			case TREECC_TOKEN_LITERAL_END:
			case TREECC_TOKEN_BOTH:
			case TREECC_TOKEN_DECLS:
			case TREECC_TOKEN_END:
			{
				/* Parse a literal definition block for this file */
				int flags = 0;
				while(context->input->token == TREECC_TOKEN_BOTH ||
				      context->input->token == TREECC_TOKEN_DECLS ||
				      context->input->token == TREECC_TOKEN_END)
				{
					if(context->input->token == TREECC_TOKEN_BOTH)
					{
						flags |= TREECC_LITERAL_CODE |
								 TREECC_LITERAL_DECLS;
					}
					else if(context->input->token == TREECC_TOKEN_DECLS)
					{
						flags |= TREECC_LITERAL_DECLS;
					}
					else
					{
						flags |= TREECC_LITERAL_END;
					}
					TreeCCNextToken(context->input);
				}
				if((flags & TREECC_LITERAL_DECLS) == 0)
				{
					flags |= TREECC_LITERAL_CODE;
				}
				if(context->input->token == TREECC_TOKEN_LITERAL_DEFNS)
				{
					TreeCCAddLiteralDefn(context, TreeCCValue(context->input),
										 flags);
				}
				else if(context->input->token == TREECC_TOKEN_LITERAL_END)
				{
					TreeCCAddLiteralDefn(context, TreeCCValue(context->input),
										 flags | TREECC_LITERAL_END);
				}
				else
				{
					TreeCCError(context->input,
								"literal definition block expected");
					continue;
				}
			}
			break;

			case TREECC_TOKEN_NODE:
			{
				/* Parse a node definition */
				ParseNode(context);
			}
			continue;	/* Skip the call to TreeCCNextToken */

			case TREECC_TOKEN_OPERATION:
			{
				/* Parse an operation definition */
				ParseOperation(context);
			}
			continue;	/* Skip the call to TreeCCNextToken */

			case TREECC_TOKEN_OPTION:
			{
				/* Parse an option declaration */
				ParseOption(context);
			}
			continue;	/* Skip the call to TreeCCNextToken */

			case TREECC_TOKEN_HEADER:
			{
				/* Parse a header filename specification */
				TreeCCNextToken(context->input);
				if(context->input->token == TREECC_TOKEN_STRING)
				{
					TreeCCStream *stream =
						TreeCCStreamCreate(context, context->input->text,
										   context->input->text, 1);
					context->headerStream = stream;
					stream->readOnly |= context->input->readOnly;
					if(!(context->commonHeader))
					{
						context->commonHeader = stream;
					}
				}
				else
				{
					TreeCCError(context->input, "header filename expected");
					continue;
				}
			}
			break;

			case TREECC_TOKEN_OUTPUT:
			{
				/* Parse an output filename specification */
				TreeCCNextToken(context->input);
				if(context->input->token == TREECC_TOKEN_STRING)
				{
					TreeCCStream *stream =
						TreeCCStreamCreate(context, context->input->text,
										   context->input->text, 0);
					context->sourceStream = stream;
					stream->readOnly |= context->input->readOnly;
					if(!(context->commonSource))
					{
						context->commonSource = stream;
					}
				}
				else
				{
					TreeCCError(context->input, "output filename expected");
					continue;
				}
			}
			break;

			case TREECC_TOKEN_OUTDIR:
			{
				/* Parse an output directory specification */
				TreeCCNextToken(context->input);
				if(context->input->token == TREECC_TOKEN_STRING)
				{
					context->outputDirectory =
						TreeCCResolvePathname(context->input->filename,
											  context->input->text);
				}
				else
				{
					TreeCCError(context->input, "output filename expected");
					continue;
				}
			}
			break;

			case TREECC_TOKEN_ENUM:
			{
				/* Parse an enumerated type definition */
				ParseEnum(context);
			}
			continue;	/* Skip the call to TreeCCNextToken */

			case TREECC_TOKEN_COMMON:
			{
				/* Put the common housekeeping code in the
				   current header and source streams */
				context->commonHeader = context->headerStream;
				context->commonSource = context->sourceStream;
			}
			break;

			case TREECC_TOKEN_INCLUDE:
			{
				/* Include another file at this point */
				int readOnly = context->input->readOnly;
				TreeCCNextToken(context->input);
				if(context->input->token == TREECC_TOKEN_READONLY)
				{
					readOnly = 1;
					TreeCCNextToken(context->input);
				}
				if(context->input->token == TREECC_TOKEN_STRING)
				{
					char *includeFile =
						TreeCCResolvePathname(context->input->filename,
											  context->input->text);
					FILE *file = fopen(includeFile, "r");
					if(file != NULL)
					{
						/* Parse the contents of the included file */
						TreeCCInput *newInput =
							(TreeCCInput *)malloc(sizeof(TreeCCInput));
						TreeCCInput *origInput = context->input;
						if(!newInput)
						{
							TreeCCOutOfMemory(context->input);
						}
						TreeCCOpen(newInput, context->input->progname,
								   file, includeFile);
						context->input = newInput;
						TreeCCParse(context);
						context->input = origInput;
						TreeCCClose(newInput, 1);
						free(newInput);
					}
					else
					{
						TreeCCError(context->input, "cannot open \"%s\"",
									includeFile);
						free(includeFile);
					}
				}
				else
				{
					TreeCCError(context->input, "include filename expected");
				}
			}
			break;

			case TREECC_TOKEN_LITERAL_CODE:
			case TREECC_TOKEN_LPAREN:
			case TREECC_TOKEN_RPAREN:
			case TREECC_TOKEN_LBRACE:
			case TREECC_TOKEN_RBRACE:
			case TREECC_TOKEN_LSQUARE:
			case TREECC_TOKEN_RSQUARE:
			case TREECC_TOKEN_COMMA:
			case TREECC_TOKEN_EQUALS:
			case TREECC_TOKEN_STAR:
			case TREECC_TOKEN_REF:
			case TREECC_TOKEN_SEMI:
			case TREECC_TOKEN_COLON_COLON:
			case TREECC_TOKEN_STRING:
			case TREECC_TOKEN_UNKNOWN:
			case TREECC_TOKEN_ABSTRACT:
			case TREECC_TOKEN_TYPEDEF:
			case TREECC_TOKEN_NOCREATE:
			case TREECC_TOKEN_VIRTUAL:
			case TREECC_TOKEN_INLINE:
			case TREECC_TOKEN_SPLIT:
			case TREECC_TOKEN_READONLY:
			{
				/* This token is not valid here */
				TreeCCError(context->input, "declaration expected");
				do
				{
					/* Attempt to re-synchronise on the next declaration */
					TreeCCNextToken(context->input);
				}
				while(!IsStartDecl(context->input->token));
			}
			continue;	/* Skip the call to TreeCCNextToken */
		}

		/* Get the next token from the input stream */
		TreeCCNextToken(context->input);
	}
	while(context->input->token != TREECC_TOKEN_EOF);
}
Example #8
0
void ParseDecorate (FScanner &sc)
{
	// Get actor class name.
	for(;;)
	{
		FScanner::SavedPos pos = sc.SavePos();
		if (!sc.GetToken ())
		{
			return;
		}
		switch (sc.TokenType)
		{
		case TK_Include:
		{
			sc.MustGetString();
			// This check needs to remain overridable for testing purposes.
			if (Wads.GetLumpFile(sc.LumpNum) == 0 && !Args->CheckParm("-allowdecoratecrossincludes"))
			{
				int includefile = Wads.GetLumpFile(Wads.CheckNumForFullName(sc.String, true));
				if (includefile != 0)
				{
					I_FatalError("File %s is overriding core lump %s.",
						Wads.GetWadFullName(includefile), sc.String);
				}
			}
			FScanner newscanner;
			newscanner.Open(sc.String);
			ParseDecorate(newscanner);
			break;
		}

		case TK_Const:
			ParseConstant (sc, &GlobalSymbols, NULL);
			break;

		case TK_Enum:
			ParseEnum (sc, &GlobalSymbols, NULL);
			break;

		case ';':
			// ';' is the start of a comment in the non-cmode parser which
			// is used to parse parts of the DECORATE lump. If we don't add 
			// a check here the user will only get weird non-informative
			// error messages if a semicolon is found.
			sc.ScriptError("Unexpected ';'");
			break;

		case TK_Identifier:
			// 'ACTOR' cannot be a keyword because it is also needed as a class identifier
			// so let's do a special case for this.
			if (sc.Compare("ACTOR"))
			{
				ParseActor (sc);
				break;
			}
			else if (sc.Compare("PICKUP"))
			{
				ParseOldDecoration (sc, DEF_Pickup);
				break;
			}
			else if (sc.Compare("BREAKABLE"))
			{
				ParseOldDecoration (sc, DEF_BreakableDecoration);
				break;
			}
			else if (sc.Compare("PROJECTILE"))
			{
				ParseOldDecoration (sc, DEF_Projectile);
				break;
			}
			else if (sc.Compare("DAMAGETYPE"))
			{
				ParseDamageDefinition(sc);
				break;
			}
		default:
			sc.RestorePos(pos);
			ParseOldDecoration(sc, DEF_Decoration);
			break;
		}
	}
}
Example #9
0
int
ParseProcedure(struct asn1_parm *pc, u_char *p, u_char *end, int *procedure)
{
	return ParseEnum(pc, p, end, procedure);
}