mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 12:58:08 +01:00
WINGS: New function WMReadPropListFromPipe
This functions reads a proplist from a pipe instead of a file (like WMReadPropListFromFile does). It uses a call to popen to open the desired command, reads data into a buffer till EOF and passes the data to getPropList for parsing. v2: code cleanup
This commit is contained in:
committed by
Carlos R. Mafra
parent
a657fafcce
commit
cc69d2aae3
@@ -807,6 +807,8 @@ char* WMGetPropListDescription(WMPropList *plist, Bool indented);
|
|||||||
|
|
||||||
WMPropList* WMReadPropListFromFile(char *file);
|
WMPropList* WMReadPropListFromFile(char *file);
|
||||||
|
|
||||||
|
WMPropList* WMReadPropListFromPipe(char *command);
|
||||||
|
|
||||||
Bool WMWritePropListToFile(WMPropList *plist, char *path);
|
Bool WMWritePropListToFile(WMPropList *plist, char *path);
|
||||||
|
|
||||||
/* ---[ WINGs/userdefaults.c ]-------------------------------------------- */
|
/* ---[ WINGs/userdefaults.c ]-------------------------------------------- */
|
||||||
|
|||||||
@@ -1545,6 +1545,60 @@ WMPropList *WMReadPropListFromFile(char *file)
|
|||||||
return plist;
|
return plist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WMPropList *WMReadPropListFromPipe(char *command)
|
||||||
|
{
|
||||||
|
FILE *file;
|
||||||
|
WMPropList *plist;
|
||||||
|
PLData *pldata;
|
||||||
|
char line[1024];
|
||||||
|
|
||||||
|
file = popen(command, "r");
|
||||||
|
|
||||||
|
if (!file) {
|
||||||
|
werror(_("%s:could not open menu file"), command);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
pldata = (PLData *) wmalloc(sizeof(PLData));
|
||||||
|
pldata->ptr = NULL;
|
||||||
|
pldata->filename = command;
|
||||||
|
pldata->lineNumber = 1;
|
||||||
|
|
||||||
|
/* read from file till EOF or OOM and fill proplist buffer*/
|
||||||
|
while (fgets(line, sizeof(line), file) != NULL) {
|
||||||
|
if (pldata->ptr == NULL) {
|
||||||
|
pldata->ptr = wmalloc(strlen(line)+1);
|
||||||
|
pldata->ptr[0] = '\0';
|
||||||
|
} else {
|
||||||
|
pldata->ptr = wrealloc(pldata->ptr,
|
||||||
|
strlen(line) + strlen(pldata->ptr) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
pldata->ptr = strncat(pldata->ptr, line, strlen(line));
|
||||||
|
}
|
||||||
|
|
||||||
|
pclose(file);
|
||||||
|
|
||||||
|
plist = getPropList(pldata);
|
||||||
|
|
||||||
|
if (getNonSpaceChar(pldata) != 0 && plist) {
|
||||||
|
COMPLAIN(pldata, _("extra data after end of property list"));
|
||||||
|
/*
|
||||||
|
* We can't just ignore garbage after the end of the description
|
||||||
|
* (especially if the description was read from a file), because
|
||||||
|
* the "garbage" can be the real data and the real garbage is in
|
||||||
|
* fact in the beginning of the file (which is now inside plist)
|
||||||
|
*/
|
||||||
|
WMReleasePropList(plist);
|
||||||
|
plist = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wfree(pldata->ptr);
|
||||||
|
wfree(pldata);
|
||||||
|
|
||||||
|
return plist;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: review this function's code */
|
/* TODO: review this function's code */
|
||||||
|
|
||||||
Bool WMWritePropListToFile(WMPropList * plist, char *path)
|
Bool WMWritePropListToFile(WMPropList * plist, char *path)
|
||||||
|
|||||||
Reference in New Issue
Block a user