mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-31 02:52:30 +01:00
WINGs: Added 'const' attribute to 'WMCreatePropListFromDescription'
To be able to do this in a clean way, it was necessary to add the attribute also in PLData's ptr field, which is actually right because none of the function changes its content. The function that fills it from a file/pipe however needed small changes to respect the const-ness of the field.
This commit is contained in:
committed by
Carlos R. Mafra
parent
75a0beffeb
commit
28e6bde782
@@ -802,7 +802,7 @@ WMPropList* WMShallowCopyPropList(WMPropList *plist);
|
|||||||
/* Makes a completely separate replica of the original proplist */
|
/* Makes a completely separate replica of the original proplist */
|
||||||
WMPropList* WMDeepCopyPropList(WMPropList *plist);
|
WMPropList* WMDeepCopyPropList(WMPropList *plist);
|
||||||
|
|
||||||
WMPropList* WMCreatePropListFromDescription(char *desc);
|
WMPropList* WMCreatePropListFromDescription(const char *desc);
|
||||||
|
|
||||||
/* Free the returned string when you no longer need it */
|
/* Free the returned string when you no longer need it */
|
||||||
char* WMGetPropListDescription(WMPropList *plist, Bool indented);
|
char* WMGetPropListDescription(WMPropList *plist, Bool indented);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ typedef struct W_PropList {
|
|||||||
} W_PropList;
|
} W_PropList;
|
||||||
|
|
||||||
typedef struct PLData {
|
typedef struct PLData {
|
||||||
char *ptr;
|
const char *ptr;
|
||||||
int pos;
|
int pos;
|
||||||
const char *filename;
|
const char *filename;
|
||||||
int lineNumber;
|
int lineNumber;
|
||||||
@@ -1469,7 +1469,7 @@ WMPropList *WMDeepCopyPropList(WMPropList * plist)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
WMPropList *WMCreatePropListFromDescription(char *desc)
|
WMPropList *WMCreatePropListFromDescription(const char *desc)
|
||||||
{
|
{
|
||||||
WMPropList *plist = NULL;
|
WMPropList *plist = NULL;
|
||||||
PLData *pldata;
|
PLData *pldata;
|
||||||
@@ -1506,6 +1506,7 @@ WMPropList *WMReadPropListFromFile(const char *file)
|
|||||||
{
|
{
|
||||||
WMPropList *plist = NULL;
|
WMPropList *plist = NULL;
|
||||||
PLData *pldata;
|
PLData *pldata;
|
||||||
|
char *read_buf;
|
||||||
FILE *f;
|
FILE *f;
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
size_t length;
|
size_t length;
|
||||||
@@ -1525,20 +1526,22 @@ WMPropList *WMReadPropListFromFile(const char *file)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pldata = (PLData *) wmalloc(sizeof(PLData));
|
read_buf = wmalloc(length + 1);
|
||||||
pldata->ptr = (char *)wmalloc(length + 1);
|
if (fread(read_buf, length, 1, f) != 1) {
|
||||||
pldata->filename = file;
|
|
||||||
pldata->lineNumber = 1;
|
|
||||||
|
|
||||||
if (fread(pldata->ptr, length, 1, f) != 1) {
|
|
||||||
if (ferror(f)) {
|
if (ferror(f)) {
|
||||||
werror(_("error reading from file '%s'"), file);
|
werror(_("error reading from file '%s'"), file);
|
||||||
}
|
}
|
||||||
plist = NULL;
|
fclose(f);
|
||||||
goto cleanup;
|
wfree(read_buf);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
read_buf[length] = '\0';
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
pldata->ptr[length] = 0;
|
pldata = (PLData *) wmalloc(sizeof(PLData));
|
||||||
|
pldata->ptr = read_buf;
|
||||||
|
pldata->filename = file;
|
||||||
|
pldata->lineNumber = 1;
|
||||||
|
|
||||||
plist = getPropList(pldata);
|
plist = getPropList(pldata);
|
||||||
|
|
||||||
@@ -1554,10 +1557,8 @@ WMPropList *WMReadPropListFromFile(const char *file)
|
|||||||
plist = NULL;
|
plist = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
wfree(read_buf);
|
||||||
wfree(pldata->ptr);
|
|
||||||
wfree(pldata);
|
wfree(pldata);
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
return plist;
|
return plist;
|
||||||
}
|
}
|
||||||
@@ -1568,6 +1569,7 @@ WMPropList *WMReadPropListFromPipe(const char *command)
|
|||||||
WMPropList *plist;
|
WMPropList *plist;
|
||||||
PLData *pldata;
|
PLData *pldata;
|
||||||
char line[1024];
|
char line[1024];
|
||||||
|
char *read_buf;
|
||||||
|
|
||||||
file = popen(command, "r");
|
file = popen(command, "r");
|
||||||
|
|
||||||
@@ -1582,17 +1584,19 @@ WMPropList *WMReadPropListFromPipe(const char *command)
|
|||||||
pldata->lineNumber = 1;
|
pldata->lineNumber = 1;
|
||||||
|
|
||||||
/* read from file till EOF or OOM and fill proplist buffer*/
|
/* read from file till EOF or OOM and fill proplist buffer*/
|
||||||
|
read_buf = NULL;
|
||||||
while (fgets(line, sizeof(line), file) != NULL) {
|
while (fgets(line, sizeof(line), file) != NULL) {
|
||||||
if (pldata->ptr == NULL) {
|
if (read_buf == NULL) {
|
||||||
pldata->ptr = wmalloc(strlen(line)+1);
|
read_buf = wmalloc(strlen(line)+1);
|
||||||
pldata->ptr[0] = '\0';
|
read_buf[0] = '\0';
|
||||||
} else {
|
} else {
|
||||||
pldata->ptr = wrealloc(pldata->ptr,
|
read_buf = wrealloc(read_buf,
|
||||||
strlen(line) + strlen(pldata->ptr) + 1);
|
strlen(line) + strlen(read_buf) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pldata->ptr = strncat(pldata->ptr, line, strlen(line));
|
read_buf = strncat(read_buf, line, strlen(line));
|
||||||
}
|
}
|
||||||
|
pldata->ptr = read_buf;
|
||||||
|
|
||||||
pclose(file);
|
pclose(file);
|
||||||
|
|
||||||
@@ -1610,7 +1614,7 @@ WMPropList *WMReadPropListFromPipe(const char *command)
|
|||||||
plist = NULL;
|
plist = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wfree(pldata->ptr);
|
wfree(read_buf);
|
||||||
wfree(pldata);
|
wfree(pldata);
|
||||||
|
|
||||||
return plist;
|
return plist;
|
||||||
|
|||||||
Reference in New Issue
Block a user