Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdb90bcf

Browse files
committed
Add more C comments to entab.c.
1 parent25b1daf commitdb90bcf

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

‎src/tools/entab/entab.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
externchar*optarg;
2828
externintoptind;
2929

30+
3031
int
3132
main(intargc,char**argv)
3233
{
@@ -88,6 +89,7 @@ main(int argc, char **argv)
8889
argv+=optind;
8990
argc-=optind;
9091

92+
/* process arguments */
9193
do
9294
{
9395
if (argc<1)
@@ -104,6 +106,7 @@ main(int argc, char **argv)
104106

105107
escaped= FALSE;
106108

109+
/* process lines */
107110
while (fgets(in_line,sizeof(in_line),in_file)!=NULL)
108111
{
109112
col_in_tab=0;
@@ -114,9 +117,11 @@ main(int argc, char **argv)
114117
quote_char=' ';
115118
escaped= FALSE;
116119

120+
/* process line */
117121
while (*src!=NUL)
118122
{
119123
col_in_tab++;
124+
/* Is this a potential space/tab replacement? */
120125
if (quote_char==' '&& (*src==' '||*src=='\t'))
121126
{
122127
if (*src=='\t')
@@ -127,29 +132,34 @@ main(int argc, char **argv)
127132
else
128133
prv_spaces++;
129134

135+
/* Are we at a tab stop? */
130136
if (col_in_tab==tab_size)
131137
{
132138
/*
133-
* Is the next character going to be a tab?Needed to
134-
*dotab replacement in current spot ifnext char is
135-
* going to be a tab, ignoringmin_spaces
139+
* Is the next character going to be a tab? We do
140+
* tab replacement inthecurrent spot ifthe next
141+
*char isgoing to be a tab and ignoremin_spaces.
136142
*/
137143
nxt_spaces=0;
138144
while (1)
139145
{
146+
/* Have we reached non-whitespace? */
140147
if (*(src+nxt_spaces+1)==NUL||
141148
(*(src+nxt_spaces+1)!=' '&&
142149
*(src+nxt_spaces+1)!='\t'))
143150
break;
151+
/* count spaces */
144152
if (*(src+nxt_spaces+1)==' ')
145153
++nxt_spaces;
154+
/* Have we found a forward tab? */
146155
if (*(src+nxt_spaces+1)=='\t'||
147156
nxt_spaces==tab_size)
148157
{
149158
nxt_spaces=tab_size;
150159
break;
151160
}
152161
}
162+
/* Do tab replacment for spaces? */
153163
if ((prv_spaces >=min_spaces||
154164
nxt_spaces==tab_size)&&
155165
del_tabs== FALSE)
@@ -158,40 +168,51 @@ main(int argc, char **argv)
158168
prv_spaces=0;
159169
}
160170
else
171+
/* output accumulated spaces */
161172
{
162173
for (;prv_spaces>0;prv_spaces--)
163174
*(dst++)=' ';
164175
}
165176
}
166177
}
178+
/* Not a potential space/tab replacement */
167179
else
168180
{
181+
/* output accumulated spaces */
169182
for (;prv_spaces>0;prv_spaces--)
170183
*(dst++)=' ';
171-
if (*src=='\t')/* only when in quote */
184+
/* This can only happen in a quote. */
185+
if (*src=='\t')
172186
col_in_tab=0;
187+
/* visual backspace? */
173188
if (*src=='\b')
174189
col_in_tab-=2;
190+
/* Do we process quotes? */
175191
if (escaped== FALSE&&protect_quotes== TRUE)
176192
{
177193
if (*src=='\\')
178194
escaped= TRUE;
195+
/* Is this a quote character? */
179196
if (*src=='"'||*src=='\'')
180197
{
198+
/* toggle quote mode */
181199
if (quote_char==' ')
182200
quote_char=*src;
183201
elseif (*src==quote_char)
184202
quote_char=' ';
185203
}
186204
}
205+
/* newlines/CRs do not terminate escapes */
187206
elseif (*src!='\r'&&*src!='\n')
188207
escaped= FALSE;
189208

209+
/* reached newline/CR; clip line? */
190210
if ((*src=='\r'||*src=='\n')&&
191-
quote_char==' '&&
192211
clip_lines== TRUE&&
212+
quote_char==' '&&
193213
escaped== FALSE)
194214
{
215+
/* trim spaces starting from the end */
195216
while (dst>out_line&&
196217
(*(dst-1)==' '||*(dst-1)=='\t'))
197218
dst--;
@@ -210,9 +231,11 @@ main(int argc, char **argv)
210231
dst--;
211232
prv_spaces=0;
212233
}
234+
/* output accumulated spaces */
213235
for (;prv_spaces>0;prv_spaces--)
214236
*(dst++)=' ';
215237
*dst=NUL;
238+
216239
if (fputs(out_line,stdout)==EOF)
217240
{
218241
fprintf(stderr,"Cannot write to output file %s: %s\n",argv[0],strerror(errno));

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp