void Classify::ReadNewCutoffs(FILE *CutoffFile, inT64 end_offset,
                              CLASS_CUTOFF_ARRAY Cutoffs) {
/*
 **	Parameters:
 **		Filename	name of file containing cutoff definitions
 **		Cutoffs		array to put cutoffs into
 **	Globals: none
 **	Operation: Open Filename, read in all of the class-id/cutoff pairs
 **		and insert them into the Cutoffs array.  Cutoffs are
 **		indexed in the array by class id.  Unused entries in the
 **		array are set to an arbitrarily high cutoff value.
 **	Return: none
 **	Exceptions: none
 **	History: Wed Feb 20 09:38:26 1991, DSJ, Created.
 */
  char Class[UNICHAR_LEN + 1];
  CLASS_ID ClassId;
  int Cutoff;
  int i;

  for (i = 0; i < MAX_NUM_CLASSES; i++)
    Cutoffs[i] = MAX_CUTOFF;

  while ((end_offset < 0 || ftell(CutoffFile) < end_offset) &&
         fscanf(CutoffFile, "%" REALLY_QUOTE_IT(UNICHAR_LEN) "s %d",
                 Class, &Cutoff) == 2) {
    if (strcmp(Class, "NULL") == 0) {
      ClassId = unicharset.unichar_to_id(" ");
    } else {
      ClassId = unicharset.unichar_to_id(Class);
    }
    Cutoffs[ClassId] = Cutoff;
    SkipNewline(CutoffFile);
  }
}                                /* ReadNewCutoffs */
Exemplo n.º 2
0
/**
 * Open Filename, read in all of the class-id/cutoff pairs
 * and insert them into the Cutoffs array.  Cutoffs are
 * indexed in the array by class id.  Unused entries in the
 * array are set to an arbitrarily high cutoff value.
 * @param CutoffFile name of file containing cutoff definitions
 * @param Cutoffs array to put cutoffs into
 * @param swap
 * @param end_offset
 * @return none
 * @note Globals: none
 * @note Exceptions: none
 * @note History: Wed Feb 20 09:38:26 1991, DSJ, Created.
 */
    void Classify::ReadNewCutoffs(FILE *CutoffFile, bool swap, inT64 end_offset,
                                  CLASS_CUTOFF_ARRAY Cutoffs) {
        char Class[UNICHAR_LEN + 1];
        CLASS_ID ClassId;
        int Cutoff;
        int i;

        if (shape_table_ != NULL) {
            if (!shapetable_cutoffs_.DeSerialize(swap, CutoffFile)) {
                tprintf("Error during read of shapetable pffmtable!\n");
            }
        }
        for (i = 0; i < MAX_NUM_CLASSES; i++)
            Cutoffs[i] = MAX_CUTOFF;

        while ((end_offset < 0 || ftell(CutoffFile) < end_offset) &&
               tfscanf(CutoffFile, "%"
            REALLY_QUOTE_IT(UNICHAR_LEN)
        "s %d",
                Class, &Cutoff) == 2) {
            if (strcmp(Class, "NULL") == 0) {
                ClassId = unicharset.unichar_to_id(" ");
            } else {
                ClassId = unicharset.unichar_to_id(Class);
            }
            Cutoffs[ClassId] = Cutoff;
            SkipNewline(CutoffFile);
        }
    }
Exemplo n.º 3
0
/******************************************************************************
 * read the input file
 * parse each section as it occurs
 * load the data into the coaster variables
 * see COASTER.FORMAT.README.txt for details
 *****************************************************************************/
int ReadInputFile()
{
	char SECTION[BUFSIZ/2];
	int i, sectionOK;

	SkipComment();
	while(!feof(file))
	{
		if (!ReadSectionName(SECTION,BUFSIZ/2))
		{
			PrintError("Section SECTION expected");
			return 0;
		}
		// read each section and parse it
		sectionOK = 0;
		if (!strcmp(SECTION,"trackcontrolpoints"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadUnsignedInt(&nbPointControl)) return 0;
			
			pPointControl = (point*)malloc(nbPointControl*2*sizeof(point));
			for(i=0; i<nbPointControl; i++)
			{
				if (!SkipNewline()) return 0;
				if (!ReadPoint(&pPointControl[i*2])) return 0;
				if (!ReadSeparator()) return 0;
				if (!ReadPoint(&pPointControl[i*2+1])) return 0;
			}
		}
		if (!strcmp(SECTION,"supportscoordinate"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadUnsignedInt(&nbColumnCoord)) return 0;
			pColumnCoordinate = (int*)malloc(nbColumnCoord*sizeof(int));
			for(i=0; i<nbColumnCoord; i++)
			{
				if (!SkipNewline()) return 0;
				if (!ReadUnsignedInt(&pColumnCoordinate[i])) return 0;
			}
		}
		if (!strcmp(SECTION,"platform"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadPoint(&metalPosition)) return 0;
			if (!SkipNewline()) return 0;
			if (!ReadFloat(&metalLength))
			{
				PrintError("Number expected");
				return 0;
			}
			if (!SkipNewline()) return 0;
			if (!ReadFloat(&metalAngle))
			{
				PrintError("Number expected");
				return 0;
			}
		}
		if (!strcmp(SECTION,"trees"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadUnsignedInt(&nbTree)) return 0;
			pTree = (point*)malloc(nbTree*sizeof(point));
			for(i=0; i<nbTree; i++)
			{
				if (!SkipNewline()) return 0;
				if (!ReadPoint(&pTree[i])) return 0;
				pTree[i].z = -0.001f;
			}
		}
		if (!strcmp(SECTION,"startsegment"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadSignedInt(&startSegment)) return 0;
		}
		if (!strcmp(SECTION,"brakesegment"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadSignedInt(&brakeSegment)) return 0;
		}
		if (!strcmp(SECTION,"segmentlength"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadFloat(&avgSegmentLength))
			{
				PrintError("Number expected");
				return 0;
			}
		}
		if (!strcmp(SECTION,"bankfactor"))
		{
			sectionOK = 1;
			if (!SkipNewline()) return 0;
			if (!ReadFloat(&twistFactor))
			{
				PrintError("Number expected");
				return 0;
			}
		}
		if (!sectionOK) PrintError("Unknown section \"%s\"",SECTION);
		// don't print an error if there is no new line at the end of the file, 
		// don't directly call skipnewline
		i = line_number;
		SkipComment();
		if ((line_number - i == 0) && !feof(file)) PrintError("Newline expected");
	}
	return 1;
}