@@ -51,13 +51,18 @@ main(int argc, char **argv)
5151{
5252int tab_size = 8 ,
5353min_spaces = 2 ,
54+ only_comment_periods = FALSE,
5455protect_quotes = FALSE,
56+ protect_leading_whitespace = FALSE,
5557del_tabs = FALSE,
5658clip_lines = FALSE,
59+ in_comment = FALSE,
60+ was_period = FALSE,
5761prv_spaces ,
5862col_in_tab ,
5963escaped ,
60- nxt_spaces ;
64+ nxt_spaces ,
65+ in_leading_whitespace ;
6166char in_line [BUFSIZ ],
6267out_line [BUFSIZ ],
6368* src ,
@@ -74,7 +79,7 @@ main(int argc, char **argv)
7479if (strcmp (cp ,"detab" )== 0 )
7580del_tabs = 1 ;
7681
77- while ((ch = getopt (argc ,argv ,"cdhqs :t:" ))!= -1 )
82+ while ((ch = getopt (argc ,argv ,"cdhlmqs :t:" ))!= -1 )
7883switch (ch )
7984{
8085case 'c' :
@@ -83,6 +88,13 @@ main(int argc, char **argv)
8388case 'd' :
8489del_tabs = TRUE;
8590break ;
91+ case 'l' :
92+ protect_leading_whitespace = TRUE;
93+ break ;
94+ case 'm' :
95+ /* only process text followed by periods in C comments */
96+ only_comment_periods = TRUE;
97+ break ;
8698case 'q' :
8799protect_quotes = TRUE;
88100break ;
@@ -97,6 +109,8 @@ main(int argc, char **argv)
97109fprintf (stderr ,"USAGE: %s [ -cdqst ] [file ...]\n\
98110-c (clip trailing whitespace)\n\
99111-d (delete tabs)\n\
112+ -l (protect leading whitespace)\n\
113+ -m (only C comment periods)\n\
100114-q (protect quotes)\n\
101115-s minimum_spaces\n\
102116-t tab_width\n" ,
@@ -134,13 +148,24 @@ main(int argc, char **argv)
134148if (escaped == FALSE)
135149quote_char = ' ' ;
136150escaped = FALSE;
151+ in_leading_whitespace = TRUE;
137152
138153/* process line */
139154while (* src != NUL )
140155{
141156col_in_tab ++ ;
157+
158+ /* look backward so we handle slash-star-slash properly */
159+ if (!in_comment && src > in_line &&
160+ * (src - 1 )== '/' && * src == '*' )
161+ in_comment = TRUE;
162+ else if (in_comment && * src == '*' && * (src + 1 )== '/' )
163+ in_comment = FALSE;
164+
142165/* Is this a potential space/tab replacement? */
143- if (quote_char == ' ' && (* src == ' ' || * src == '\t' ))
166+ if ((!only_comment_periods || (in_comment && was_period ))&&
167+ (!protect_leading_whitespace || !in_leading_whitespace )&&
168+ quote_char == ' ' && (* src == ' ' || * src == '\t' ))
144169{
145170if (* src == '\t' )
146171{
@@ -192,6 +217,11 @@ main(int argc, char **argv)
192217/* Not a potential space/tab replacement */
193218else
194219{
220+ /* allow leading stars in comments */
221+ if (in_leading_whitespace && * src != ' ' && * src != '\t' &&
222+ (!in_comment || * src != '*' ))
223+ in_leading_whitespace = FALSE;
224+ was_period = (* src == '.' );
195225/* output accumulated spaces */
196226output_accumulated_spaces (& prv_spaces ,& dst );
197227/* This can only happen in a quote. */