if (trace(2))
htrc("PROFILE_FlushFile: CurProfile=%p\n", CurProfile);
if (!CurProfile) {
fprintf(stderr, "No current profile!\n"); returnFALSE;
} // endif !CurProfile
if (!CurProfile->changed || !CurProfile->filename) returnTRUE;
#if0 if (!(file = fopen(unix_name, "w"))) { /* Try to create it in $HOME/.wine */ /* FIXME: this will need a more general solution */ //strcpy( buffer, get_config_dir() ); //p = buffer + strlen(buffer); //*p++ = '/'; char *p1 = strrchr(CurProfile->filename, '\\');
/* Flush the old current profile */
PROFILE_FlushFile();
/* Make the oldest profile the current one only in order to get rid of it */ if (i == N_CACHED_PROFILES) {
tempProfile = MRUProfile[N_CACHED_PROFILES-1];
for(i = N_CACHED_PROFILES-1; i > 0; i--)
MRUProfile[i] = MRUProfile[i-1];
CurProfile = tempProfile;
} // endif i
if (CurProfile->filename)
PROFILE_ReleaseFile();
/* OK, now that CurProfile is definitely free we assign it our new file */ // newdos_name = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.short_name)+1 ); // strcpy( newdos_name, full_name.short_name );
if (file) {
CurProfile->section = PROFILE_Load(file);
fclose(file);
if (!stat(CurProfile->filename, &buf))
CurProfile->mtime = buf.st_mtime;
} else { /* Does not exist yet, we will create it in PROFILE_FlushFile */
fprintf(stderr, "profile file %s not found\n", filename);
} /* endif file */
returnTRUE;
}
/*********************************************************************** *PROFILE_Close * *Flushthenamedprofiletodiskandremoveitfromthecache.
***********************************************************************/ void PROFILE_Close(LPCSTR filename)
{ int i; BOOL close = FALSE; struct stat buf;
PROFILE *tempProfile;
if (trace(2))
htrc("PROFILE_Close: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES);
/* Check for a match */ for (i = 0; i < N_CACHED_PROFILES; i++) { if (trace(2))
htrc("MRU=%s i=%d\n", SVP(MRUProfile[i]->filename), i);
if (MRUProfile[i]->filename && !strcmp(filename, MRUProfile[i]->filename)) { if (i) { /* Make the profile to close current */
tempProfile = MRUProfile[i];
MRUProfile[i] = MRUProfile[0];
MRUProfile[0] = tempProfile;
CurProfile=tempProfile;
} // endif i
if (trace(2)) { if (!stat(CurProfile->filename, &buf) && CurProfile->mtime == buf.st_mtime)
htrc("(%s): already opened (mru=%d)\n", filename, i); else
htrc("(%s): already opened, needs refreshing (mru=%d)\n", filename, i);
} // endif trace
close = TRUE; break;
} // endif filename
} // endfor i
if (close)
PROFILE_ReleaseFile();
} // end of PROFILE_Close
/*********************************************************************** *PROFILE_End * *Terminateandreleasethecache.
***********************************************************************/ void PROFILE_End(void)
{ int i;
if (trace(3))
htrc("PROFILE_End: CurProfile=%p N=%d\n", CurProfile, N_CACHED_PROFILES);
/* Close all opened files and free the cache structure */ for (i = 0; i < N_CACHED_PROFILES; i++) {
CurProfile = MRUProfile[i]; if (!CurProfile) continue; if (trace(3))
htrc("MRU=%s i=%d\n", SVP(CurProfile->filename), i);
PROFILE_ReleaseFile();
memfree(CurProfile);
} // endfor i
CurProfile = NULL;
while (PROFILE_isspace(*section_name))
section_name++;
p = section_name + strlen(section_name) - 1;
while ((p > section_name) && PROFILE_isspace(*p))
p--;
seclen = p - section_name + 1;
while (PROFILE_isspace(*key_name))
key_name++;
p = key_name + strlen(key_name) - 1;
while ((p > key_name) && PROFILE_isspace(*p))
p--;
keylen = p - key_name + 1;
while (*section) { if (((*section)->name[0])
&& (!(_strnicmp((*section)->name, section_name, seclen )))
&& (((*section)->name)[seclen] == '\0')) {
PROFILEKEY* *key = &(*section)->key;
while (*key) { /* If create_always is FALSE then we check if the keyname already exists. *Otherwiseweadditregardlessofitsexistence,toallow *keystobeaddedmorethenonceinsomecases.
*/ if (!create_always) { if ((!(_strnicmp( (*key)->name, key_name, keylen )))
&& (((*key)->name)[keylen] == '\0')) return *key;
} // endif !create_always
key = &(*key)->next;
} // endwhile *key
if (!create) return NULL;
if (!(*key = (PROFILEKEY*)malloc(sizeof(PROFILEKEY) + strlen(key_name)))) return NULL;
while (section) { if (section->name[0] && !stricmp(section->name, section_name)) {
uint oldlen = len;
for (key = section->key; key; key = key->next) { if (len <= 2) break;
if (!*key->name) continue; /* Skip empty lines */
if (IS_ENTRY_COMMENT(key->name)) continue; /* Skip comments */
PROFILE_CopyEntry(buffer, key->name, len - 1, handle_env);
len -= strlen(buffer) + 1;
buffer += strlen(buffer) + 1;
if (len < 2) break;
if (return_values && key->value) {
buffer[-1] = '=';
PROFILE_CopyEntry(buffer, key->value, len - 1, handle_env);
len -= strlen(buffer) + 1;
buffer += strlen(buffer) + 1;
} // endif return_values
} // endfor key
*buffer = '\0';
if (len <= 1) { /*If either lpszSection or lpszKey is NULL and the supplied destinationbufferistoosmalltoholdallthestrings, thelaststringistruncatedandfollowedbytwonullcharacters. Inthiscase,thereturnvalueisequaltocchReturnBuffer
minus two. */
buffer[-1] = '\0'; return oldlen - 2;
} // endif len
return oldlen - len;
} // endif section->name
section = section->next;
} // endwhile section
buffer[0] = buffer[1] = '\0'; return0;
} // end of PROFILE_GetSection
/* See GetPrivateProfileSectionNamesA for documentation */ staticint PROFILE_GetSectionNames(LPSTR buffer, uint len)
{
LPSTR buf;
uint f,l;
PROFILESECTION *section;
if (trace(2))
htrc("GetSectionNames: buffer=%p len=%u\n", buffer, len);
if (!buffer || !len) return0;
if (len == 1) {
*buffer='\0'; return0;
} // endif len
f = len - 1;
buf = buffer;
section = CurProfile->section;
if (trace(2))
htrc("GetSectionNames: section=%p\n", section);
while (section != NULL) { if (trace(2))
htrc("section=%s\n", section->name);
if (section->name[0]) {
l = strlen(section->name) + 1;
if (trace(2))
htrc("l=%u f=%u\n", l, f);
if (l > f) { if (f > 0) {
strncpy(buf, section->name, f-1);
buf += f-1;
*buf++='\0';
} // endif f
if (trace(2))
htrc("('%s','%s','%s'): returning '%s'\n",
section, key_name, def_val, buffer );
return strlen(buffer);
} // endif key_name
if (key_name && !(key_name[0])) /* Win95 returns 0 on keyname "". Tested with Likse32 bon 000227 */ return0;
if (section && section[0]) return PROFILE_GetSection(CurProfile->section, section, buffer, len, FALSE, FALSE);
buffer[0] = '\0'; return0;
} // end of PROFILE_GetString
/*********************************************************************** *PROFILE_SetString * *Setaprofilestring.
***********************************************************************/ staticBOOL PROFILE_SetString(LPCSTR section_name, LPCSTR key_name,
LPCSTR value, BOOL create_always)
{ if (!key_name) { /* Delete a whole section */ if (trace(2))
htrc("Deleting('%s')\n", section_name);
CurProfile->changed |= PROFILE_DeleteSection(&CurProfile->section,
section_name); returnTRUE; /* Even if PROFILE_DeleteSection() has failed,
this is not an error on application's level.*/
} elseif (!value) { /* Delete a key */ if (trace(2))
htrc("Deleting('%s','%s')\n", section_name, key_name);
CurProfile->changed |= PROFILE_DeleteKey(&CurProfile->section,
section_name, key_name); returnTRUE; /* same error handling as above */
} else { /* Set the key value */
PROFILEKEY *key = PROFILE_Find(&CurProfile->section, section_name,
key_name, TRUE, create_always); if (trace(2))
htrc("Setting('%s','%s','%s')\n", section_name, key_name, value);
if (!key) returnFALSE;
if (key->value) { /* strip the leading spaces. We can safely strip \n\r and
* friends too, they should not happen here anyway. */ while (PROFILE_isspace(*value))
value++;
if (!strcmp(key->value, value)) { if (trace(2))
htrc(" no change needed\n" );
returnTRUE; /* No change needed */
} // endif value
if (trace(2))
htrc(" replacing '%s'\n", key->value);
if (PROFILE_Open(filename)) { if ((allow_section_name_copy) && (section == NULL))
ret = PROFILE_GetSectionNames(buffer, len); else /* PROFILE_GetString already handles the 'entry == NULL' case */
ret = PROFILE_GetString(section, entry, pDefVal, buffer, len);
} else {
strncpy(buffer, pDefVal, len);
ret = strlen(buffer);
} // endif Open
LeaveCriticalSection(&PROFILE_CritSect);
if (pDefVal != def_val) /* allocated */
memfree(pDefVal);
return ret;
} // end of PROFILE_GetPrivateProfileString
/********************** API functions **********************************/
/*********************************************************************** *GetPrivateProfileStringA(KERNEL32.@)
***********************************************************************/ int GetPrivateProfileString(LPCSTR section, LPCSTR entry, LPCSTR def_val,
LPSTR buffer, DWORD len, LPCSTR filename)
{ return PROFILE_GetPrivateProfileString(section, entry, def_val,
buffer, len, filename, TRUE);
} // end of GetPrivateProfileString
/*********************************************************************** *GetPrivateProfileIntA(KERNEL32.@)
***********************************************************************/
uint GetPrivateProfileInt(LPCSTR section, LPCSTR entry, int def_val, LPCSTR filename)
{ char buffer[20]; int result;
if (!PROFILE_GetPrivateProfileString(section, entry, "", buffer, sizeof(buffer), filename, FALSE)) return def_val;
/* FIXME: if entry can be found but it's empty, then Win16 is *supposedtoreturn0insteadofdef_val!Difficult/problematic *toimplement(everyotherfailurealsoreturnszerobuffer), *thuswaituntiltestingframeworkavailformakingsurenothing
* else gets broken that way. */ if (!buffer[0]) return (uint)def_val;
/* Don't use strtol() here ! *(returnsLONG_MAX/MINonoverflowinsteadof"proper"overflow)
YES, scan for unsigned format ! (otherwise compatibility error) */ if (!sscanf(buffer, "%u", &result)) return0;
return (uint)result;
} // end of GetPrivateProfileInt
/*********************************************************************** *GetPrivateProfileSectionA(KERNEL32.@)
***********************************************************************/ int GetPrivateProfileSection(LPCSTR section, LPSTR buffer,
DWORD len, LPCSTR filename)
{ int ret = 0;
EnterCriticalSection( &PROFILE_CritSect );
if (PROFILE_Open(filename))
ret = PROFILE_GetSection(CurProfile->section, section, buffer, len, FALSE, TRUE);
LeaveCriticalSection( &PROFILE_CritSect ); return ret;
} // end of GetPrivateProfileSection
if (PROFILE_Open(filename)) { if (!section && !entry && !string) /* documented "file flush" case */
PROFILE_ReleaseFile(); /* always return FALSE in this case */ else { if (!section) { //FIXME("(NULL?,%s,%s,%s)? \n",entry,string,filename);
} else {
ret = PROFILE_SetString(section, entry, string, FALSE);
if (ret)
ret = PROFILE_FlushFile();
} // endif section
} // endif section || entry|| string
} // endif Open
LeaveCriticalSection( &PROFILE_CritSect ); return ret;
} // end of WritePrivateProfileString
/*********************************************************************** *WritePrivateProfileSectionA(KERNEL32.@)
***********************************************************************/ BOOL WritePrivateProfileSection(LPCSTR section,
LPCSTR string, LPCSTR filename )
{ BOOL ret = FALSE;
LPSTR p ;
EnterCriticalSection(&PROFILE_CritSect);
if (PROFILE_Open(filename)) { if (!section && !string)
PROFILE_ReleaseFile(); /* always return FALSE in this case */ elseif (!string) { /* delete the named section*/
ret = PROFILE_SetString(section, NULL, NULL, FALSE);
if (ret)
ret = PROFILE_FlushFile();
} else {
PROFILE_DeleteAllKeys(section);
ret = TRUE;
printf("FOO name: ");
fgets(buff, sizeof(buff), stdin); if (buff[strlen(buff) - 1] == '\n')
buff[strlen(buff) - 1] = '\0';
WritePrivateProfileString("FOO", "name", buff, inifile);
GetPrivateProfileString("FOO", "name", "X", buff, 128, inifile);
printf("[FOO](name) = %s\n", buff);
} // end of main #endif// TEST_MODULE
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.41Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.