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
3cc78378
Commit
3cc78378
authored
9 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Bring back the "Only use CRs in the output if they're in the input" feature.
parent
40f0454c
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/wordwrap.c
+19
-9
19 additions, 9 deletions
src/sbbs3/wordwrap.c
with
19 additions
and
9 deletions
src/sbbs3/wordwrap.c
+
19
−
9
View file @
3cc78378
...
...
@@ -318,18 +318,19 @@ static BOOL paragraph_append(struct paragraph *paragraph, const char *bytes, siz
* The returned malloc()ed array will have the text member of the last
* paragraph set to NULL.
*/
static
struct
paragraph
*
word_unwrap
(
char
*
inbuf
,
int
oldlen
,
BOOL
handle_quotes
)
static
struct
paragraph
*
word_unwrap
(
char
*
inbuf
,
int
oldlen
,
BOOL
handle_quotes
,
BOOL
*
has_crs
)
{
unsigned
inpos
=
0
;
struct
prefix
new_prefix
;
int
incol
;
BOOL
has_crs
=
FALSE
;
int
paragraph
=
0
;
struct
paragraph
*
ret
=
NULL
;
struct
paragraph
*
newret
=
NULL
;
BOOL
paragraph_done
;
int
next_word_len
;
if
(
has_crs
)
*
has_crs
=
FALSE
;
while
(
inbuf
[
inpos
])
{
incol
=
0
;
/* Start of a new paragraph (ie: after a hard CR) */
...
...
@@ -356,7 +357,8 @@ static struct paragraph *word_unwrap(char *inbuf, int oldlen, BOOL handle_quotes
while
(
!
paragraph_done
)
{
switch
(
inbuf
[
inpos
])
{
case
'\r'
:
// Strip CRs and add them in later.
has_crs
=
TRUE
;
if
(
has_crs
)
*
has_crs
=
TRUE
;
// Fall-through to strip
case
'\b'
:
// Strip backspaces.
case
'\x1f'
:
// Strip delete chars.
...
...
@@ -464,7 +466,7 @@ fail_return:
*
* Returns a malloc()ed string.
*/
static
char
*
wrap_paragraphs
(
struct
paragraph
*
paragraph
,
int
outlen
,
BOOL
handle_quotes
)
static
char
*
wrap_paragraphs
(
struct
paragraph
*
paragraph
,
int
outlen
,
BOOL
handle_quotes
,
BOOL
has_crs
)
{
int
outcol
;
char
*
outbuf
=
NULL
;
...
...
@@ -497,8 +499,12 @@ static char *wrap_paragraphs(struct paragraph *paragraph, int outlen, BOOL handl
}
}
inp
=
paragraph
->
text
;
if
(
*
inp
==
0
)
outbuf_append
(
&
outbuf
,
&
outp
,
"
\r\n
"
,
2
,
&
outbuf_size
);
if
(
*
inp
==
0
)
{
if
(
has_crs
)
outbuf_append
(
&
outbuf
,
&
outp
,
"
\r\n
"
,
2
,
&
outbuf_size
);
else
outbuf_append
(
&
outbuf
,
&
outp
,
"
\n
"
,
1
,
&
outbuf_size
);
}
while
(
*
inp
)
{
outcol
=
0
;
// First, add the prefix...
...
...
@@ -526,7 +532,10 @@ static char *wrap_paragraphs(struct paragraph *paragraph, int outlen, BOOL handl
inp
+=
word_len
.
bytes
;
outcol
+=
word_len
.
len
;
}
outbuf_append
(
&
outbuf
,
&
outp
,
"
\r\n
"
,
2
,
&
outbuf_size
);
if
(
has_crs
)
outbuf_append
(
&
outbuf
,
&
outp
,
"
\r\n
"
,
2
,
&
outbuf_size
);
else
outbuf_append
(
&
outbuf
,
&
outp
,
"
\n
"
,
1
,
&
outbuf_size
);
}
paragraph
++
;
}
...
...
@@ -538,15 +547,16 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
{
char
*
outbuf
;
struct
paragraph
*
paragraphs
;
BOOL
has_crs
;
paragraphs
=
word_unwrap
(
inbuf
,
oldlen
,
handle_quotes
);
paragraphs
=
word_unwrap
(
inbuf
,
oldlen
,
handle_quotes
,
&
has_crs
);
#if 0
for(int i=0;paragraphs[i].text;i++)
fprintf(stderr, "PREFIX: '%s'\nTEXT: '%s'\n\n", paragraphs[i].prefix.bytes, paragraphs[i].text);
#endif
outbuf
=
wrap_paragraphs
(
paragraphs
,
len
,
handle_quotes
);
outbuf
=
wrap_paragraphs
(
paragraphs
,
len
,
handle_quotes
,
has_crs
);
free_paragraphs
(
paragraphs
,
-
1
);
free
(
paragraphs
);
return
outbuf
;
...
...
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