Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
db90bcf8
Commit
db90bcf8
authored
Jan 29, 2014
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more C comments to entab.c.
parent
25b1dafa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
5 deletions
+28
-5
src/tools/entab/entab.c
src/tools/entab/entab.c
+28
-5
No files found.
src/tools/entab/entab.c
View file @
db90bcf8
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
extern
char
*
optarg
;
extern
char
*
optarg
;
extern
int
optind
;
extern
int
optind
;
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
{
...
@@ -88,6 +89,7 @@ main(int argc, char **argv)
...
@@ -88,6 +89,7 @@ main(int argc, char **argv)
argv
+=
optind
;
argv
+=
optind
;
argc
-=
optind
;
argc
-=
optind
;
/* process arguments */
do
do
{
{
if
(
argc
<
1
)
if
(
argc
<
1
)
...
@@ -104,6 +106,7 @@ main(int argc, char **argv)
...
@@ -104,6 +106,7 @@ main(int argc, char **argv)
escaped
=
FALSE
;
escaped
=
FALSE
;
/* process lines */
while
(
fgets
(
in_line
,
sizeof
(
in_line
),
in_file
)
!=
NULL
)
while
(
fgets
(
in_line
,
sizeof
(
in_line
),
in_file
)
!=
NULL
)
{
{
col_in_tab
=
0
;
col_in_tab
=
0
;
...
@@ -114,9 +117,11 @@ main(int argc, char **argv)
...
@@ -114,9 +117,11 @@ main(int argc, char **argv)
quote_char
=
' '
;
quote_char
=
' '
;
escaped
=
FALSE
;
escaped
=
FALSE
;
/* process line */
while
(
*
src
!=
NUL
)
while
(
*
src
!=
NUL
)
{
{
col_in_tab
++
;
col_in_tab
++
;
/* Is this a potential space/tab replacement? */
if
(
quote_char
==
' '
&&
(
*
src
==
' '
||
*
src
==
'\t'
))
if
(
quote_char
==
' '
&&
(
*
src
==
' '
||
*
src
==
'\t'
))
{
{
if
(
*
src
==
'\t'
)
if
(
*
src
==
'\t'
)
...
@@ -127,22 +132,26 @@ main(int argc, char **argv)
...
@@ -127,22 +132,26 @@ main(int argc, char **argv)
else
else
prv_spaces
++
;
prv_spaces
++
;
/* Are we at a tab stop? */
if
(
col_in_tab
==
tab_size
)
if
(
col_in_tab
==
tab_size
)
{
{
/*
/*
* Is the next character going to be a tab?
Needed t
o
* Is the next character going to be a tab?
We d
o
*
do tab replacement in current spot if next char is
*
tab replacement in the current spot if the next
*
going to be a tab, ignoring min_spaces
*
char is going to be a tab and ignore min_spaces.
*/
*/
nxt_spaces
=
0
;
nxt_spaces
=
0
;
while
(
1
)
while
(
1
)
{
{
/* Have we reached non-whitespace? */
if
(
*
(
src
+
nxt_spaces
+
1
)
==
NUL
||
if
(
*
(
src
+
nxt_spaces
+
1
)
==
NUL
||
(
*
(
src
+
nxt_spaces
+
1
)
!=
' '
&&
(
*
(
src
+
nxt_spaces
+
1
)
!=
' '
&&
*
(
src
+
nxt_spaces
+
1
)
!=
'\t'
))
*
(
src
+
nxt_spaces
+
1
)
!=
'\t'
))
break
;
break
;
/* count spaces */
if
(
*
(
src
+
nxt_spaces
+
1
)
==
' '
)
if
(
*
(
src
+
nxt_spaces
+
1
)
==
' '
)
++
nxt_spaces
;
++
nxt_spaces
;
/* Have we found a forward tab? */
if
(
*
(
src
+
nxt_spaces
+
1
)
==
'\t'
||
if
(
*
(
src
+
nxt_spaces
+
1
)
==
'\t'
||
nxt_spaces
==
tab_size
)
nxt_spaces
==
tab_size
)
{
{
...
@@ -150,6 +159,7 @@ main(int argc, char **argv)
...
@@ -150,6 +159,7 @@ main(int argc, char **argv)
break
;
break
;
}
}
}
}
/* Do tab replacment for spaces? */
if
((
prv_spaces
>=
min_spaces
||
if
((
prv_spaces
>=
min_spaces
||
nxt_spaces
==
tab_size
)
&&
nxt_spaces
==
tab_size
)
&&
del_tabs
==
FALSE
)
del_tabs
==
FALSE
)
...
@@ -158,40 +168,51 @@ main(int argc, char **argv)
...
@@ -158,40 +168,51 @@ main(int argc, char **argv)
prv_spaces
=
0
;
prv_spaces
=
0
;
}
}
else
else
/* output accumulated spaces */
{
{
for
(;
prv_spaces
>
0
;
prv_spaces
--
)
for
(;
prv_spaces
>
0
;
prv_spaces
--
)
*
(
dst
++
)
=
' '
;
*
(
dst
++
)
=
' '
;
}
}
}
}
}
}
/* Not a potential space/tab replacement */
else
else
{
{
/* output accumulated spaces */
for
(;
prv_spaces
>
0
;
prv_spaces
--
)
for
(;
prv_spaces
>
0
;
prv_spaces
--
)
*
(
dst
++
)
=
' '
;
*
(
dst
++
)
=
' '
;
if
(
*
src
==
'\t'
)
/* only when in quote */
/* This can only happen in a quote. */
if
(
*
src
==
'\t'
)
col_in_tab
=
0
;
col_in_tab
=
0
;
/* visual backspace? */
if
(
*
src
==
'\b'
)
if
(
*
src
==
'\b'
)
col_in_tab
-=
2
;
col_in_tab
-=
2
;
/* Do we process quotes? */
if
(
escaped
==
FALSE
&&
protect_quotes
==
TRUE
)
if
(
escaped
==
FALSE
&&
protect_quotes
==
TRUE
)
{
{
if
(
*
src
==
'\\'
)
if
(
*
src
==
'\\'
)
escaped
=
TRUE
;
escaped
=
TRUE
;
/* Is this a quote character? */
if
(
*
src
==
'"'
||
*
src
==
'\''
)
if
(
*
src
==
'"'
||
*
src
==
'\''
)
{
{
/* toggle quote mode */
if
(
quote_char
==
' '
)
if
(
quote_char
==
' '
)
quote_char
=
*
src
;
quote_char
=
*
src
;
else
if
(
*
src
==
quote_char
)
else
if
(
*
src
==
quote_char
)
quote_char
=
' '
;
quote_char
=
' '
;
}
}
}
}
/* newlines/CRs do not terminate escapes */
else
if
(
*
src
!=
'\r'
&&
*
src
!=
'\n'
)
else
if
(
*
src
!=
'\r'
&&
*
src
!=
'\n'
)
escaped
=
FALSE
;
escaped
=
FALSE
;
/* reached newline/CR; clip line? */
if
((
*
src
==
'\r'
||
*
src
==
'\n'
)
&&
if
((
*
src
==
'\r'
||
*
src
==
'\n'
)
&&
quote_char
==
' '
&&
clip_lines
==
TRUE
&&
clip_lines
==
TRUE
&&
quote_char
==
' '
&&
escaped
==
FALSE
)
escaped
==
FALSE
)
{
{
/* trim spaces starting from the end */
while
(
dst
>
out_line
&&
while
(
dst
>
out_line
&&
(
*
(
dst
-
1
)
==
' '
||
*
(
dst
-
1
)
==
'\t'
))
(
*
(
dst
-
1
)
==
' '
||
*
(
dst
-
1
)
==
'\t'
))
dst
--
;
dst
--
;
...
@@ -210,9 +231,11 @@ main(int argc, char **argv)
...
@@ -210,9 +231,11 @@ main(int argc, char **argv)
dst
--
;
dst
--
;
prv_spaces
=
0
;
prv_spaces
=
0
;
}
}
/* output accumulated spaces */
for
(;
prv_spaces
>
0
;
prv_spaces
--
)
for
(;
prv_spaces
>
0
;
prv_spaces
--
)
*
(
dst
++
)
=
' '
;
*
(
dst
++
)
=
' '
;
*
dst
=
NUL
;
*
dst
=
NUL
;
if
(
fputs
(
out_line
,
stdout
)
==
EOF
)
if
(
fputs
(
out_line
,
stdout
)
==
EOF
)
{
{
fprintf
(
stderr
,
"Cannot write to output file %s: %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
fprintf
(
stderr
,
"Cannot write to output file %s: %s
\n
"
,
argv
[
0
],
strerror
(
errno
));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment