Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
1291793d
Commit
1291793d
authored
22 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Created iniRead() method to read the (integer, string, or bool) value of a .ini
file key.
parent
f3d30adb
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sbbs3/js_file.c
+48
-0
48 additions, 0 deletions
src/sbbs3/js_file.c
with
48 additions
and
0 deletions
src/sbbs3/js_file.c
+
48
−
0
View file @
1291793d
...
...
@@ -39,6 +39,7 @@
#include
"md5.h"
#include
"base64.h"
#include
"uucode.h"
#include
"ini_file.h"
#ifdef JAVASCRIPT
...
...
@@ -397,6 +398,49 @@ js_readall(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return
(
JS_TRUE
);
}
static
JSBool
js_ini_read
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
char
*
section
;
char
*
key
;
jsval
dflt
=
argv
[
2
];
private_t
*
p
;
*
rval
=
JSVAL_NULL
;
if
((
p
=
(
private_t
*
)
JS_GetPrivate
(
cx
,
obj
))
==
NULL
)
{
JS_ReportError
(
cx
,
getprivate_failure
,
WHERE
);
return
(
JS_FALSE
);
}
section
=
JS_GetStringBytes
(
JS_ValueToString
(
cx
,
argv
[
0
]));
key
=
JS_GetStringBytes
(
JS_ValueToString
(
cx
,
argv
[
1
]));
switch
(
JSVAL_TAG
(
dflt
))
{
case
JSVAL_STRING
:
*
rval
=
STRING_TO_JSVAL
(
JS_NewStringCopyZ
(
cx
,
iniReadString
(
p
->
fp
,
section
,
key
,
JS_GetStringBytes
(
JS_ValueToString
(
cx
,
dflt
)))));
break
;
case
JSVAL_BOOLEAN
:
*
rval
=
BOOLEAN_TO_JSVAL
(
iniReadBool
(
p
->
fp
,
section
,
key
,
JSVAL_TO_BOOLEAN
(
dflt
)));
break
;
case
JSVAL_DOUBLE
:
JS_NewNumberValue
(
cx
,
iniReadFloat
(
p
->
fp
,
section
,
key
,
*
JSVAL_TO_DOUBLE
(
dflt
)),
rval
);
break
;
default:
if
(
JSVAL_IS_INT
(
dflt
))
{
*
rval
=
INT_TO_JSVAL
(
iniReadInteger
(
p
->
fp
,
section
,
key
,
JSVAL_TO_INT
(
dflt
)));
break
;
}
break
;
}
return
(
JS_TRUE
);
}
static
JSBool
js_write
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
...
...
@@ -1108,6 +1152,10 @@ static jsMethodSpec js_file_functions[] = {
{
"readAll"
,
js_readall
,
0
,
JSTYPE_ARRAY
,
""
,
JSDOCSTR
(
"read all lines into an array of strings"
)
},
{
"iniRead"
,
js_ini_read
,
3
,
JSTYPE_STRING
,
JSDOCSTR
(
"section, key, default"
)
,
JSDOCSTR
(
"read a key from a .ini file and return its value, "
"may return <i>bool</i>, <i>string</i>, or <i>number</i> value"
)
},
{
"write"
,
js_write
,
1
,
JSTYPE_BOOLEAN
,
JSDOCSTR
(
"string text [,len]"
)
,
JSDOCSTR
(
"write a string to the file (optionally unix-to-unix or base64 decoding in the process)"
)
},
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment