ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

inifile.c
Go to the documentation of this file.
00001 /*
00002  *  FreeLoader
00003  *  Copyright (C) 1998-2003  Brian Palmer  <brianp@sginet.com>
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License along
00016  *  with this program; if not, write to the Free Software Foundation, Inc.,
00017  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #include <freeldr.h>
00021 #include <debug.h>
00022 
00023 DBG_DEFAULT_CHANNEL(INIFILE);
00024 
00025 BOOLEAN IniOpenSection(PCSTR SectionName, ULONG_PTR* SectionId)
00026 {
00027     PINI_SECTION    Section;
00028 
00029     TRACE("IniOpenSection() SectionName = %s\n", SectionName);
00030 
00031     // Loop through each section and find the one they want
00032     Section = CONTAINING_RECORD(IniFileSectionListHead.Flink, INI_SECTION, ListEntry);
00033     while (&Section->ListEntry != &IniFileSectionListHead)
00034     {
00035         // Compare against the section name
00036         if (_stricmp(SectionName, Section->SectionName) == 0)
00037         {
00038             // We found it
00039             if (SectionId)
00040                 *SectionId = (ULONG_PTR)Section;
00041             TRACE("IniOpenSection() Found it! SectionId = 0x%x\n", SectionId);
00042             return TRUE;
00043         }
00044 
00045         // Get the next section in the list
00046         Section = CONTAINING_RECORD(Section->ListEntry.Flink, INI_SECTION, ListEntry);
00047     }
00048 
00049     TRACE("IniOpenSection() Section not found.\n");
00050 
00051     return FALSE;
00052 }
00053 
00054 ULONG IniGetNumSectionItems(ULONG_PTR SectionId)
00055 {
00056     PINI_SECTION    Section = (PINI_SECTION)SectionId;
00057 
00058     TRACE("IniGetNumSectionItems() SectionId = 0x%x\n", SectionId);
00059     TRACE("IniGetNumSectionItems() Item count = %d\n", Section->SectionItemCount);
00060 
00061     return Section->SectionItemCount;
00062 }
00063 
00064 PINI_SECTION_ITEM IniGetSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber)
00065 {
00066     PINI_SECTION        Section = (PINI_SECTION)SectionId;
00067     PINI_SECTION_ITEM   SectionItem;
00068 
00069     // Loop through each section item and find the one they want
00070     SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM, ListEntry);
00071     while (&SectionItem->ListEntry != &Section->SectionItemList)
00072     {
00073         // Check to see if this is the setting they want
00074         if (SettingNumber == 0)
00075         {
00076             return SectionItem;
00077         }
00078 
00079         // Nope, keep going
00080         SettingNumber--;
00081 
00082         // Get the next section item in the list
00083         SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink, INI_SECTION_ITEM, ListEntry);
00084     }
00085     return NULL;
00086 }
00087 
00088 ULONG IniGetSectionSettingNameSize(ULONG_PTR SectionId, ULONG SettingIndex)
00089 {
00090     PINI_SECTION_ITEM   SectionItem;
00091 
00092     // Retrieve requested setting
00093     SectionItem = IniGetSettingByNumber(SectionId, SettingIndex);
00094     if (!SectionItem)
00095         return 0;
00096 
00097     // Return the size of the string plus 1 for the null-terminator
00098     return (ULONG)(strlen(SectionItem->ItemName) + 1);
00099 }
00100 
00101 ULONG IniGetSectionSettingValueSize(ULONG_PTR SectionId, ULONG SettingIndex)
00102 {
00103     PINI_SECTION_ITEM   SectionItem;
00104 
00105     // Retrieve requested setting
00106     SectionItem = IniGetSettingByNumber(SectionId, SettingIndex);
00107     if (!SectionItem)
00108         return 0;
00109 
00110     // Return the size of the string plus 1 for the null-terminator
00111     return (ULONG)(strlen(SectionItem->ItemValue) + 1);
00112 }
00113 
00114 BOOLEAN IniReadSettingByNumber(ULONG_PTR SectionId, ULONG SettingNumber, PCHAR SettingName, ULONG NameSize, PCHAR SettingValue, ULONG ValueSize)
00115 {
00116     PINI_SECTION_ITEM   SectionItem;
00117     TRACE(".001 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
00118 
00119     TRACE("IniReadSettingByNumber() SectionId = 0x%x\n", SectionId);
00120 
00121     // Retrieve requested setting
00122     SectionItem = IniGetSettingByNumber(SectionId, SettingNumber);
00123     if (!SectionItem)
00124     {
00125         TRACE("IniReadSettingByNumber() Setting number %d not found.\n", SettingNumber);
00126         return FALSE;
00127     }
00128 
00129     TRACE("IniReadSettingByNumber() Setting number %d found.\n", SettingNumber);
00130     TRACE("IniReadSettingByNumber() Setting name = %s\n", SectionItem->ItemName);
00131     TRACE("IniReadSettingByNumber() Setting value = %s\n", SectionItem->ItemValue);
00132 
00133     TRACE("1 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
00134     TRACE("2 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
00135     strncpy(SettingName, SectionItem->ItemName, NameSize - 1);
00136     SettingName[NameSize - 1] = '\0';
00137     TRACE("3 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
00138     strncpy(SettingValue, SectionItem->ItemValue, ValueSize - 1);
00139     SettingValue[ValueSize - 1] = '\0';
00140     TRACE("4 NameSize = %d ValueSize = %d\n", NameSize, ValueSize);
00141     DbgDumpBuffer(DPRINT_INIFILE, SettingName, NameSize);
00142     DbgDumpBuffer(DPRINT_INIFILE, SettingValue, ValueSize);
00143 
00144     return TRUE;
00145 }
00146 
00147 BOOLEAN IniReadSettingByName(ULONG_PTR SectionId, PCSTR SettingName, PCHAR Buffer, ULONG BufferSize)
00148 {
00149     PINI_SECTION        Section = (PINI_SECTION)SectionId;
00150     PINI_SECTION_ITEM   SectionItem;
00151 
00152     TRACE("IniReadSettingByName() SectionId = 0x%x\n", SectionId);
00153 
00154     // Loop through each section item and find the one they want
00155     SectionItem = CONTAINING_RECORD(Section->SectionItemList.Flink, INI_SECTION_ITEM, ListEntry);
00156     while (&SectionItem->ListEntry != &Section->SectionItemList)
00157     {
00158         // Check to see if this is the setting they want
00159         if (_stricmp(SettingName, SectionItem->ItemName) == 0)
00160         {
00161             TRACE("IniReadSettingByName() Setting \'%s\' found.\n", SettingName);
00162             TRACE("IniReadSettingByName() Setting value = %s\n", SectionItem->ItemValue);
00163 
00164             strncpy(Buffer, SectionItem->ItemValue, BufferSize - 1);
00165             Buffer[BufferSize - 1] = '\0';
00166 
00167             return TRUE;
00168         }
00169 
00170         // Get the next section item in the list
00171         SectionItem = CONTAINING_RECORD(SectionItem->ListEntry.Flink, INI_SECTION_ITEM, ListEntry);
00172     }
00173 
00174     WARN("IniReadSettingByName() Setting \'%s\' not found.\n", SettingName);
00175 
00176     return FALSE;
00177 }
00178 
00179 BOOLEAN IniAddSection(PCSTR SectionName, ULONG_PTR* SectionId)
00180 {
00181     PINI_SECTION    Section;
00182 
00183     // Allocate a new section structure
00184     Section = MmHeapAlloc(sizeof(INI_SECTION));
00185     if (!Section)
00186     {
00187         return FALSE;
00188     }
00189 
00190     RtlZeroMemory(Section, sizeof(INI_SECTION));
00191 
00192     // Allocate the section name buffer
00193     Section->SectionName = MmHeapAlloc(strlen(SectionName));
00194     if (!Section->SectionName)
00195     {
00196         MmHeapFree(Section);
00197         return FALSE;
00198     }
00199 
00200     // Get the section name
00201     strcpy(Section->SectionName, SectionName);
00202 
00203     // Add it to the section list head
00204     IniFileSectionCount++;
00205     InsertHeadList(&IniFileSectionListHead, &Section->ListEntry);
00206 
00207     *SectionId = (ULONG_PTR)Section;
00208 
00209     return TRUE;
00210 }
00211 
00212 BOOLEAN IniAddSettingValueToSection(ULONG_PTR SectionId, PCSTR SettingName, PCSTR SettingValue)
00213 {
00214     PINI_SECTION        Section = (PINI_SECTION)SectionId;
00215     PINI_SECTION_ITEM   SectionItem;
00216 
00217     // Allocate a new item structure
00218     SectionItem = MmHeapAlloc(sizeof(INI_SECTION_ITEM));
00219     if (!SectionItem)
00220     {
00221         return FALSE;
00222     }
00223 
00224     RtlZeroMemory(SectionItem, sizeof(INI_SECTION_ITEM));
00225 
00226     // Allocate the setting name buffer
00227     SectionItem->ItemName = MmHeapAlloc(strlen(SettingName) + 1);
00228     if (!SectionItem->ItemName)
00229     {
00230         MmHeapFree(SectionItem);
00231         return FALSE;
00232     }
00233 
00234     // Allocate the setting value buffer
00235     SectionItem->ItemValue = MmHeapAlloc(strlen(SettingValue) + 1);
00236     if (!SectionItem->ItemValue)
00237     {
00238         MmHeapFree(SectionItem->ItemName);
00239         MmHeapFree(SectionItem);
00240         return FALSE;
00241     }
00242 
00243     strcpy(SectionItem->ItemName, SettingName);
00244     strcpy(SectionItem->ItemValue, SettingValue);
00245 
00246     // Add it to the current section
00247     Section->SectionItemCount++;
00248     InsertTailList(&Section->SectionItemList, &SectionItem->ListEntry);
00249 
00250     return TRUE;
00251 }

Generated on Sun May 27 2012 04:19:15 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.