Esempio n. 1
0
void ReadInitFile(char *SubWatershedFileName, LISTPTR * Input, char* CustomConfig)
{
  FILE *SubWatershedFile = NULL;/*File with watershed specific info*/
  FILE *InFile = NULL;		/* File with generic input information */
  char Buffer[BUFSIZE + 1];	/* Tempora */
  int i;			/* counter */
  int NLines;			/* Number of lines in the input file */
  LISTPTR Current = NULL;	/* pointer to current node in list */
  LISTPTR Head = NULL;		/* pointer to the start of the list */
  char buffer[40];
  sprintf(buffer, "..\\config\\basins\\%s",SubWatershedFileName);
  OpenFile(&SubWatershedFile, (char *) buffer, "r", FALSE);
NLines = CountLines(SubWatershedFile);
  rewind(SubWatershedFile);
  for (i = 0; i < NLines; i++) {
    fgets(Buffer, BUFSIZE, SubWatershedFile);
    Strip(Buffer);
    if (IsSection(Buffer) || IsKeyEntryPair(Buffer)) {
      if (Head == NULL) {
		Head = CreateNode();
		Current = Head;
		*Input = Head;
      }
      else {
		Current->Next = CreateNode();
		Current = Current->Next;
      }
      strncpy(Current->Str, Buffer, BUFSIZE);
    }
  }
  fclose(SubWatershedFile);

  //use two part config files- info common to all subbasins in ConFigFileName
		if(CustomConfig==NULL)strcpy(CustomConfig,"base");
		  OpenFile(&InFile, (char *) CustomConfig, "r", FALSE);
		  printf("Using config info from file: %s \n\n", CustomConfig);

	 NLines = CountLines(InFile);
	 rewind(InFile);
	 for (i = 0; i < NLines; i++) {
	   fgets(Buffer, BUFSIZE, InFile);
		strcpy(Buffer,replace(Buffer,"<basin>",SubWatershedFileName));
		strcpy(Buffer,replace(Buffer,"<condition>",CustomConfig));
	  Strip(Buffer);
	  if (IsSection(Buffer) || IsKeyEntryPair(Buffer)) {
	    if (Head == NULL) {
			Head = CreateNode();
			Current = Head;
			*Input = Head;
	   }
	   else {
			Current->Next = CreateNode();
			Current = Current->Next;
		 }
      strncpy(Current->Str, Buffer, BUFSIZE);
	  }
	}//for i == 0 to nlines
	fclose(InFile); 
  return;
}
Esempio n. 2
0
void TIniFile::WriteString(const wxString &Section, const wxString &Ident,
  const wxString &Value)
{
	int I;

	I = GetSectionIndex(Section);
	// Section exists
	if (I != -1)
	{
		++I;
		while ((I < FFileBuffer->Count()) && !IsSection(FFileBuffer->Item(I)) &&
		  (GetName(FFileBuffer->Item(I)) != Ident))
			++I;
		// End of File or Ident doesn't exists in the Section
		if ((I >= FFileBuffer->Count()) || IsSection(FFileBuffer->Item(I)))
		{
			if (Ident != EmptyStr)
				FFileBuffer->Insert(I, Ident + IniSeparator + Value);
		}
		// Ident does exists in the section
		else if (Ident != EmptyStr)
			FFileBuffer->Item(I) = Ident + IniSeparator + Value;
	}
	// Section doesn't exists, so add new [Section] with Ident=Value
	else
	{
		FFileBuffer->Add(EmptyStr);
		FFileBuffer->Add(IniBrackets[0] + Section + IniBrackets[1]);
		if (Ident != EmptyStr)
			FFileBuffer->Add(Ident + IniSeparator + Value);
	}
	SaveToFile();
}
Esempio n. 3
0
LISTPTR LocateSection(const char *Section, LISTPTR Input)
{
  char Buffer[BUFSIZE + 1];
  char *StartPtr = NULL;
  char *EndPtr = NULL;

  while (Input) {
    strncpy(Buffer, Input->Str, BUFSIZE);
    if (IsSection(Buffer)) {
      if (Buffer[0] == OPENSECTION) {
	StartPtr = &Buffer[1];
	EndPtr = strchr(Buffer, CLOSESECTION);
	*EndPtr = '\0';
	strcpy(Buffer, StartPtr);
	Strip(Buffer);
	MakeKeyString(Buffer);
	if (strcmp(Section, Buffer) == 0) {
	  Input = Input->Next;
	  break;
	}
      }
    }
    Input = Input->Next;
  }
  return Input;
}
Esempio n. 4
0
void TIniFile::ReadSectionNames(const wxString &Section, TStringList &Strings)
{
	wxString N;
	wxString V;
	int I;

	// Assert( !! Strings , SStringsUnassignedError );
	Strings.BeginUpdate();
	try
	{
		Strings.Clear();
		if (FFileBuffer->Count() > 0)
		{
			I = GetSectionIndex(Section);
			if (I != -1)
			{
				++I;
				while ((I < FFileBuffer->Count()) && !IsSection
				  (FFileBuffer->Item(I)))
				{
					N = GetName(FFileBuffer->Item(I));
					if (N != EmptyStr)
					{
						Strings.Add(N);
					}
					++I;
				}
			}
		}
	} /* ? *//* FINALLY */
	catch (...)
	{
		Strings.EndUpdate();
	}
}
Esempio n. 5
0
wxString TIniFile::ReadString(const wxString &Section, const wxString &Ident,
  const wxString &Default)
{
	wxString result;
	int I;
	wxString V;

	result = Default;
	if (FFileBuffer->Count() > 0)
	{
		I = GetSectionIndex(Section);
		if (I != -1)
		{
			++I;
			while ((I < FFileBuffer->Count()) && !IsSection
			  (FFileBuffer->Item(I)))
			{
				wxString vName = GetName(FFileBuffer->Item(I));
				if (vName.CmpNoCase(Ident) == 0)
				{
					V = GetValue(FFileBuffer->Item(I), Ident);
					if (V != EmptyStr)
						result = V;
					return result;
				}
				++I;
			}
		}
	}
	return result;
}
Esempio n. 6
0
void TIniFile::ReadSections(TStringList &Strings)
{
	long I;
	wxString Section;

	// Assert( !! Strings , SStringsUnassignedError );
	Strings.BeginUpdate();
	try
	{
		Strings.Clear();
		if (FFileBuffer->Count() > 0)
		{
			I = 0;
			while ((I < FFileBuffer->Count()))
			{
				if (IsSection(FFileBuffer->Item(I)))
				{
					Section = Trim(FFileBuffer->Item(I));
					Delete(Section, 0, 1);
					Delete(Section, Length(Section) - 1, 1);
					Strings.Add(Trim(Section));
				}
				++I;
			}
		}
	} /* ? *//* FINALLY */
	catch (...)
	{
		Strings.EndUpdate();
	}
}
Esempio n. 7
0
void TIniFile::DeleteKey(const wxString &Section, const wxString &Ident)
{
	long I;

	I = GetSectionIndex(Section);
	if (I != -1)
	{
		++I;
		while ((I < FFileBuffer->Count()) && !IsSection(FFileBuffer->Item(I)) &&
		  (GetName(FFileBuffer->Item(I)) != Ident))
			++I;
		// Ident does exists
		if (!(I >= FFileBuffer->Count()) && !IsSection(FFileBuffer->Item(I)))
		{
			FFileBuffer->Delete(I);
			SaveToFile();
		}
	}
}
Esempio n. 8
0
void TIniFile::EraseSection(const wxString &Section)
{
	long I;

	I = GetSectionIndex(Section);
	if (I != -1)
	{
		// Delete Section-Header
		FFileBuffer->Delete(I);
		// Delete Section-Items
		while ((I < FFileBuffer->Count()) && !IsSection(FFileBuffer->Item(I)))
			FFileBuffer->Delete(I);
		if (I > 0)
			FFileBuffer->Insert(I, EmptyStr);
		SaveToFile();
	}
}
Esempio n. 9
0
unsigned char LocateKey(const char *Key, char *Entry, LISTPTR Input)
{
  unsigned char Found = FALSE;
  char Buffer[BUFSIZE + 1];
  char KeyBuffer[BUFSIZE + 1];
  char EntryBuffer[BUFSIZE + 1];
  char *StrPtr = NULL;

  /* Find a key in the current section */

  if (Input) {
    strncpy(Buffer, Input->Str, BUFSIZE);
    while (!IsSection(Buffer)) {

      /* Check whether the current line contains a key-entry pair */

      if (IsKeyEntryPair(Buffer)) {
		StrPtr = strchr(Buffer, SEPARATOR);//advance pointer to separator
		*StrPtr = '\0';
		strcpy(KeyBuffer, Buffer);
		++StrPtr;
		//entrybuffer is value
		strcpy(EntryBuffer, StrPtr);
		Strip(KeyBuffer);
		Strip(EntryBuffer);//jsb
		MakeKeyString(KeyBuffer);
		if (strcmp(Key, KeyBuffer) == 0) {
		  Found = TRUE;
		  Strip(EntryBuffer);
		  strcpy(Entry, EntryBuffer);
		 break;
		}
      }
      /* Get the next line */
      Input = Input->Next;
      if (Input)
	strncpy(Buffer, Input->Str, BUFSIZE);
      else
	break;
    }
  }

  return Found;
}
Esempio n. 10
0
static int
ReadStatusFile (statusfile_t *sf)
{
FILE *fp;
char *section = NULL, *new_section = NULL;
char buf[BUFSIZE];
int length;
int ret = 0;
int c;

if ((fp = fopen (sf->filename, "r")) != NULL) {
   while (fgets (buf, BUFSIZE, fp) != NULL) {
      length = strlen (buf);
      if (((length >= 1) && (buf[length - 1] == '\n')) ||
	  ((length >= 2) && (buf[length - 1] == '\r') && (buf[length - 2] == '\n'))) {
	 /* Canonicalize on Unix style EOL */
	 if ((new_section = IsSection(buf)) != NULL) {
	    if (section) free(section);
	    section = new_section;
	    }
	 else {
	    if (!ProcessLine(sf, section, buf)) {
	       /* Ignore blank lines */
	       if (StrTrim(buf))
		  trace(INFO, default_trace, "ERROR: Failed to process line [%s]\n", buf);
	       }
	    }
	 continue;
	 }
      else {
         StrTrim(buf);
	 trace (INFO, default_trace, "ERROR: Overflowed line for statusfile %s [%s]\n", sf->filename, buf);
	 do {
	    c = fgetc(fp);
	    } while ((c != '\n') && (c != EOF));
         if (c == EOF) break;
         continue;
	 }
      }
   ret = 1;
   }

return (ret);
}
Esempio n. 11
0
void MYIniReadTools::LoadFile()
{
	mapAllIniInfo.clear();
	FILE *fp;
	char strContainer[512];
	fp=fopen(FileName,"r");
	if (fp == NULL)
	{
		return ;
	}
	vector<INIKEYINFO> st;
	BOOL isFirst=TRUE;
	CString strSection="";
	while(!feof(fp))
	{
		fgets(strContainer,512,fp);
		CString strTmp=CString(strContainer);
		
		if (IsSection(strTmp))
		{
			if (strSection!="")
			{
				mapAllIniInfo.insert(make_pair(strSection,st));
			}
			strSection=strTmp;
			//保存现在的节名
			st.clear();//清空上次保存的节点
		}
		else
		{
			if (isFirst)
			{
				break;
			}
			InsertKeyAndValue(strTmp, st);
		}
		isFirst=FALSE;
	}
	if (strSection!="")
	{
		mapAllIniInfo.insert(make_pair(strSection,st));
	}
}
Esempio n. 12
0
/* Read all Names of one Section */
void TIniFile::ReadSection(const wxString &Section, TStringList &Strings)
{
	int I;
	wxString N;
	Strings.BeginUpdate();
	Strings.Clear();
	if (FFileBuffer->Count() > 0)
	{
		I = GetSectionIndex(Section);
		if (I != -1)
		{
			++I;
			while ((I < FFileBuffer->Count()) && !IsSection
			  (FFileBuffer->Item(I)))
			{
				N = GetName(FFileBuffer->Item(I));
				if (N != EmptyStr)
					Strings.Add(N);
				++I;
			}
		}
	}
}