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
a4b52485
Commit
a4b52485
authored
22 years ago
by
rswindell
Browse files
Options
Downloads
Patches
Plain Diff
Created new global methods: word_wrap() and quote_msg().
parent
5b1bfe81
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sbbs3/js_global.c
+123
-0
123 additions, 0 deletions
src/sbbs3/js_global.c
with
123 additions
and
0 deletions
src/sbbs3/js_global.c
+
123
−
0
View file @
a4b52485
...
...
@@ -439,6 +439,122 @@ js_lfexpand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
return
(
JS_TRUE
);
}
static
JSBool
js_word_wrap
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
int32
len
=
79
;
ulong
i
,
k
,
l
;
int
col
=
1
;
uchar
*
inbuf
;
char
*
outbuf
;
char
*
linebuf
;
JSString
*
js_str
;
if
((
inbuf
=
JS_GetStringBytes
(
JS_ValueToString
(
cx
,
argv
[
0
])))
==
NULL
)
return
(
JS_FALSE
);
if
((
outbuf
=
(
char
*
)
malloc
((
strlen
(
inbuf
)
*
2
)
+
1
))
==
NULL
)
return
(
JS_FALSE
);
if
(
argc
>
1
)
JS_ValueToInt32
(
cx
,
argv
[
1
],
&
len
);
if
((
linebuf
=
(
char
*
)
malloc
(
len
+
1
))
==
NULL
)
return
(
JS_FALSE
);
outbuf
[
0
]
=
0
;
for
(
i
=
l
=
0
;
inbuf
[
i
];)
{
if
(
inbuf
[
i
]
==
'\r'
||
inbuf
[
i
]
==
FF
)
col
=
1
;
else
if
(
inbuf
[
i
]
==
'\t'
)
col
+=
8
;
else
if
(
inbuf
[
i
]
>=
' '
)
col
++
;
linebuf
[
l
]
=
inbuf
[
i
++
];
if
(
col
<
len
)
{
l
++
;
continue
;
}
k
=
l
;
while
(
k
&&
linebuf
[
k
]
>
' '
)
k
--
;
if
(
k
==
0
)
/* continuous printing chars, no word wrap possible */
strncat
(
outbuf
,
linebuf
,
l
+
1
);
else
{
i
-=
(
l
-
k
);
/* rewind to start of next word */
linebuf
[
k
]
=
0
;
truncsp
(
linebuf
);
strcat
(
outbuf
,
linebuf
);
}
strcat
(
outbuf
,
"
\r\n
"
);
/* skip white space (but no more than one LF) for starting of new line */
while
(
inbuf
[
i
]
&&
inbuf
[
i
]
<=
' '
&&
inbuf
[
i
]
!=
'\n'
)
i
++
;
if
(
inbuf
[
i
]
==
'\n'
)
i
++
;
l
=
0
;
col
=
1
;
}
if
(
l
)
/* remainder */
strncat
(
outbuf
,
linebuf
,
l
);
js_str
=
JS_NewStringCopyZ
(
cx
,
outbuf
);
free
(
outbuf
);
if
(
js_str
==
NULL
)
return
(
JS_FALSE
);
*
rval
=
STRING_TO_JSVAL
(
js_str
);
return
(
JS_TRUE
);
}
static
JSBool
js_quote_msg
(
JSContext
*
cx
,
JSObject
*
obj
,
uintN
argc
,
jsval
*
argv
,
jsval
*
rval
)
{
int32
len
=
79
;
int
i
,
l
;
uchar
*
inbuf
;
char
*
outbuf
;
char
*
linebuf
;
char
*
prefix
=
" > "
;
JSString
*
js_str
;
if
((
inbuf
=
JS_GetStringBytes
(
JS_ValueToString
(
cx
,
argv
[
0
])))
==
NULL
)
return
(
JS_FALSE
);
if
(
argc
>
1
)
JS_ValueToInt32
(
cx
,
argv
[
1
],
&
len
);
if
(
argc
>
2
)
prefix
=
JS_GetStringBytes
(
JS_ValueToString
(
cx
,
argv
[
2
]));
if
((
outbuf
=
(
char
*
)
malloc
((
strlen
(
inbuf
)
*
strlen
(
prefix
))
+
1
))
==
NULL
)
return
(
JS_FALSE
);
if
((
linebuf
=
(
char
*
)
malloc
(
len
+
1
))
==
NULL
)
return
(
JS_FALSE
);
outbuf
[
0
]
=
0
;
for
(
i
=
l
=
0
;
inbuf
[
i
];
i
++
)
{
if
(
l
==
0
)
strcat
(
outbuf
,
prefix
);
if
(
l
<
len
)
linebuf
[
l
++
]
=
inbuf
[
i
];
if
(
inbuf
[
i
]
==
'\n'
)
{
strncat
(
outbuf
,
linebuf
,
l
);
l
=
0
;
}
}
if
(
l
)
/* remainder */
strncat
(
outbuf
,
linebuf
,
l
);
js_str
=
JS_NewStringCopyZ
(
cx
,
outbuf
);
free
(
outbuf
);
if
(
js_str
==
NULL
)
return
(
JS_FALSE
);
*
rval
=
STRING_TO_JSVAL
(
js_str
);
return
(
JS_TRUE
);
}
/* This table is used to convert between IBM ex-ASCII and HTML character entities */
/* Much of this table supplied by Deuce (thanks!) */
static
struct
{
...
...
@@ -1117,6 +1233,13 @@ static jsMethodSpec js_global_functions[] = {
{
"html_decode"
,
js_html_decode
,
1
,
JSTYPE_STRING
,
JSDOCSTR
(
"string text"
)
,
JSDOCSTR
(
"return a decoded HTML-encoded text buffer"
)
},
{
"word_wrap"
,
js_word_wrap
,
1
,
JSTYPE_STRING
,
JSDOCSTR
(
"string text [,line_length]"
)
,
JSDOCSTR
(
"returns a word-wrapped version of the text string argument, <i>line_length</i> defaults to <i>79</i>"
)
},
{
"quote_msg"
,
js_quote_msg
,
1
,
JSTYPE_STRING
,
JSDOCSTR
(
"string text [,line_length] [,prefix]"
)
,
JSDOCSTR
(
"returns a quoted version of the message text string argumnet, <i>line_length</i> defaults to <i>79</i>, "
"<i>prefix</i> defaults to <tt>
\"
>
\"
</tt>"
)
},
{
0
}
};
...
...
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