Ejemplo n.º 1
0
//------------------------------------------------------------------------------
/// \brief Does file conversion
//------------------------------------------------------------------------------
bool ProcessorMNW2::impl::DoConvertFile (const char * const a_inputFile,
                                         const char * const a_outputFile,
                                         const int& /*a_nRow*/,
                                         const int& /*a_nCol*/)
{
  bool rval(1);
  CStr inputFile(a_inputFile), outputFile(a_outputFile);

  try
  {
    std::fstream is;
    is.open((LPCTSTR)a_inputFile, std::ios_base::in);
    if (is.bad())
      throw ioError();

    std::fstream os;
    os.open((LPCTSTR)a_outputFile, std::ios_base::out);
    if (os.bad())
      throw ioError();

    ReadComments(is, os);
    ReadLn1(is, os);
    ReadWells(is, os);
    ReadStressPeriods(is, os);

  }
  catch (std::exception&)
  {
    CStr msg("Error processing file: ");
    msg += inputFile;
    msg += ".";
    ErrorStack::Get().PutError(msg);
    rval = false;
  }

  return rval;
} // ProcessorMNW2::impl::DoConvertFile
Ejemplo n.º 2
0
void AnalyseFile (char *filename)
	{
	int		done = 0,curr_stack=0;
	FILE	*fp;
	char	default_value_string[5] = "0 1";
	char	*sptr,*vptr,token[256],tmp[5];
	char	if_token[MAX_STACK][256];

	fp = OpenCampFile(filename,"","r");
	while (!done)
		{
		ReadComments(fp);
		ReadToken(fp,token,120);
		if (!token[0])
			continue;

		if (strncmp(token,"#IF",3)==0)
			{
			sptr = token+4;
			vptr = strchr(sptr,' ');
			if (!vptr)
				{
				strcpy(tmp,default_value_string);
				vptr = tmp;
				}
			else
				{
				*vptr = 0;
				vptr++;
				}
			curr_stack++;
			// Don't repeat package missions with flight missions
			if (strcmp(token,"#IF_PACKAGE_MISSION_EQ")==0)
				{
				sptr = strchr(token,'E');
				sptr += 2;
//				AddToTokenList("MISSION_EQ",vptr);
				}
			// Ignore player specific stuff - it's just color changes
			if (strncmp(token,"#IF_PLAYER",10))
				{
				AddToTokenList(sptr,vptr);
				strcpy(if_token[curr_stack],sptr);
				}
			}
		else if (strcmp(token,"#ELSE")==0)
			{
			int i = FindTokenIndex(if_token[curr_stack]);
			if (i >= 0)
				AddToValueList(i,"0");
			}
		else if (strcmp(token,"#ENDIF")==0)
			{
			if (curr_stack>0)
				curr_stack--;
			}
		else if (strcmp(token,"#ENDSCRIPT")==0)
			{
			done = 1;
			continue;
			}

		// Check for hidden evaluators..
		if (strncmp(token,"MISSION_DESCRIPTION",19)==0)
			AddToTokenList("MISSION_EQ","1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33");
//		else if (strncmp(token,"PACKAGE_MISSION_DESCRIPTION",27)==0)
//			AddToTokenList("PACKAGE_MISSION_EQ","1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33");
		else if (strncmp(token,"PACKAGE_MISSION_DESCRIPTION",27)==0)
			AddToTokenList("MISSION_EQ","1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33");
		else if (strncmp(token,"CONTEXT_STR",11)==0)
			AddToTokenList("CONTEXT_EQ","1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45");
//		else if (strcmp(token,"PACKAGE_SUCCESS")==0 || strcmp(token,"FLIGHT_SUCCESS")==0 || strcmp(token,"LONG_MISSION_SUCCESS")==0)
//			AddToTokenList("MISSION_SUCCESS","1 2 3 4 5");
		}
	fclose(fp);
	}
Ejemplo n.º 3
0
void DoFile (char *filename, FILE *op)
	{
	int		done=0,curr_stack=0,stack_active[MAX_STACK] = { 1 };
	FILE	*fp;
	char	brief_string[1024],token[256];

	do
		{
		brief_string[0] = 0;
		done = 0;
		stack_active[0] = 1;
		fp = OpenCampFile(filename,"","r");
		while (fp && !done)
			{
			ReadComments(fp);
			ReadToken(fp,token,120);
			if (!token[0])
				continue;

			// Handle standard tokens
			if (strncmp(token,"#IF",3)==0)
				{
				// Don't repeat package missions with flight missions
				if (strncmp(token,"#IF_PACKAGE_MISSION_EQ",22)==0)
					{
					char *sptr = strchr(token,'E');
					sptr -= 2;
					sptr[0] = '#';
					sptr[1] = 'I';
					sptr[2] = 'F';
					sprintf(token,sptr);
					}
				curr_stack++;
				if (!stack_active[curr_stack-1])
					stack_active[curr_stack] = 0;
				else
					stack_active[curr_stack] = DoIfToken(token+4);
				continue;
				}
			else if (strcmp(token,"#ELSE")==0)
				{
				if (curr_stack>0 && stack_active[curr_stack-1])
					stack_active[curr_stack] = !stack_active[curr_stack];
				continue;
				}
			else if (strcmp(token,"#ENDIF")==0)
				{
				if (!curr_stack)
					printf("<Brief reading Error - unmatched #ENDIF>\n");
				else
					curr_stack--;
				continue;
				}
			else if (strcmp(token,"#ENDSCRIPT")==0)
				{
				done = 1;
				continue;
				}

			// Check for section activity
			if (stack_active[curr_stack])
				DoToken(token, brief_string);

			}
		if (strlen(brief_string) > 1)
			{
			fprintf(op,"\n");
//			printf("\n");
			for (int i=0; i<gNumTokens; i++)
				{
				fprintf(op,"%s = %d\n",gTokenList[i],FindCurrentValue(gTokenList[i]));
//				printf("%s = %d\n",gTokenList[i],FindCurrentValue(gTokenList[i]));
				}
//			printf(brief_string);
			fprintf(op,brief_string);
			}
		fclose(fp);
		}
		while (IncrementPassOptions());
	}
Ejemplo n.º 4
0
int LoadTacticsTableText (char* filename)
	{
	FILE*			fh;
	char			buffer[40];
	int				i,j,k,l,n,m,r,a,id,fc;
	
	fh = fopen(filename,"r");
	if (fh==NULL)
	  return -1;

	// Read Number of entries
	ReadComments(fh);
	fc = fscanf(fh,"%d %d %d\n",&AirTactics,&GroundTactics,&NavalTactics);
	FirstAirTactic = 1;
	FirstGroundTactic = AirTactics;
	FirstNavalTactic = AirTactics + GroundTactics;
	TotalTactics = 1 + AirTactics + GroundTactics + NavalTactics;
//	TacticsTable = (TacticData*) malloc(sizeof(TacticData)*TotalTactics);
	TacticsTable = new TacticData[TotalTactics];

	for (id=0; id<TotalTactics; id++)
		{
		ReadComments(fh);
		fscanf(fh, "%s", buffer);
		sprintf(TacticsTable[id].name,buffer);
		fscanf(fh, "%d %d %d %d %d %d %d", &n, &m, &i, &j, &k, &l, &r);
		TacticsTable[id].id = id;
		TacticsTable[id].team = m;
		TacticsTable[id].domainType = i;
		TacticsTable[id].unitSize = j;		
		TacticsTable[id].minRangeToDest = k;
		TacticsTable[id].maxRangeToDest = l;
		TacticsTable[id].distToFront = r;
		ReadComments(fh);
		fc = fscanf(fh, "%d %d %d %d %d %d %d %d", &i, &j, &n, &l, &r, &k, &a, &m);
		TacticsTable[id].broken = i;
		TacticsTable[id].engaged = j;
		TacticsTable[id].combat = n;
		TacticsTable[id].losses = l;
		TacticsTable[id].retreating = r;
		TacticsTable[id].owned = k;
		TacticsTable[id].airborne = a;
		TacticsTable[id].marine = m;
		ReadComments(fh);
		for (i=0; i<10; i++)
			{
			fc = fscanf(fh, "%d", &n);
			TacticsTable[id].actionList[i] = n;
			}
		ReadComments(fh);
		fc = fscanf(fh, "%d %d %d %d %d", &i, &r, &j, &n, &m);
		TacticsTable[id].minOdds = i;
		TacticsTable[id].role = r;
		TacticsTable[id].fuel = j;
		TacticsTable[id].weapons = n;
		TacticsTable[id].priority = m;
		fc = fscanf(fh, "%d %d", &i, &j);
		TacticsTable[id].formation = i;
		TacticsTable[id].special = j;
		}
	fclose(fh);
	return 1;
	}