Skip to content
Snippets Groups Projects
Commit a6201505 authored by rswindell's avatar rswindell
Browse files

Created File methods: iniRemoveKey() and iniRemoveSection()

- Thanks RM for pointing out their absence.
parent 8b7b9bd3
No related branches found
No related tags found
No related merge requests found
......@@ -596,6 +596,70 @@ js_iniSetValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva
return(JS_TRUE);
}
static JSBool
js_iniRemoveKey(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* section=ROOT_SECTION;
char* key;
private_t* p;
str_list_t list;
*rval = JSVAL_FALSE;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
return(JS_FALSE);
}
if(p->fp==NULL)
return(JS_TRUE);
if(argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
section=JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
key=JS_GetStringBytes(JS_ValueToString(cx, argv[1]));
if((list=iniReadFile(p->fp))==NULL)
return(JS_TRUE);
if(iniRemoveKey(&list,section,key))
*rval = BOOLEAN_TO_JSVAL(iniWriteFile(p->fp,list));
strListFree(&list);
return(JS_TRUE);
}
static JSBool
js_iniRemoveSection(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
char* section=ROOT_SECTION;
private_t* p;
str_list_t list;
*rval = JSVAL_FALSE;
if((p=(private_t*)JS_GetPrivate(cx,obj))==NULL) {
JS_ReportError(cx,getprivate_failure,WHERE);
return(JS_FALSE);
}
if(p->fp==NULL)
return(JS_TRUE);
if(argv[0]!=JSVAL_VOID && argv[0]!=JSVAL_NULL)
section=JS_GetStringBytes(JS_ValueToString(cx, argv[0]));
if((list=iniReadFile(p->fp))==NULL)
return(JS_TRUE);
if(iniRemoveSection(&list,section))
*rval = BOOLEAN_TO_JSVAL(iniWriteFile(p->fp,list));
strListFree(&list);
return(JS_TRUE);
}
static JSBool
js_iniGetSections(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
......@@ -1739,6 +1803,14 @@ static jsSyncMethodSpec js_file_functions[] = {
"after the object's <i>name_property</i> (default: <tt>name</tt>)")
,312
},
{"iniRemoveKey", js_iniRemoveKey, 2, JSTYPE_BOOLEAN, JSDOCSTR("section, key")
,JSDOCSTR("remove specified <i>key</i> from specified <i>section</i> in <tt>.ini</tt> file.")
,31301
},
{"iniRemoveSection",js_iniRemoveSection,1, JSTYPE_BOOLEAN, JSDOCSTR("section")
,JSDOCSTR("remove specified <i>section</i> from <tt>.ini</tt> file.")
,31301
},
{0}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment