aboutsummaryrefslogtreecommitdiffhomepage
path: root/fish_indent.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2011-12-26 19:18:46 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2011-12-26 19:18:46 -0800
commit8d2f107d61a8b0e099ab9a59b8a32c236da5a5fc (patch)
tree89f718ab74f8400332534aee237c6f925348f05c /fish_indent.cpp
parent3f16ace6784caab54fb054836ee93902e9701913 (diff)
Some changes to migrate towards C++ and a multithreaded model
Diffstat (limited to 'fish_indent.cpp')
-rw-r--r--fish_indent.cpp144
1 files changed, 72 insertions, 72 deletions
diff --git a/fish_indent.cpp b/fish_indent.cpp
index 14cf5a6c..39bd1de0 100644
--- a/fish_indent.cpp
+++ b/fish_indent.cpp
@@ -64,10 +64,10 @@ static void read_file( FILE *f, string_buffer_t *b )
wperror(L"fgetwc");
exit(1);
}
-
+
break;
}
-
+
sb_append_char( b, c );
}
}
@@ -78,12 +78,12 @@ static void read_file( FILE *f, string_buffer_t *b )
static void insert_tabs( string_buffer_t *out, int indent )
{
int i;
-
+
for( i=0; i<indent; i++ )
{
sb_append( out, L"\t" );
}
-
+
}
/**
@@ -100,12 +100,12 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
int prev_prev_type = 0;
tok_init( &tok, in, TOK_SHOW_COMMENTS );
-
+
for( ; tok_has_next( &tok ); tok_next( &tok ) )
{
int type = tok_last_type( &tok );
wchar_t *last = tok_last( &tok );
-
+
switch( type )
{
case TOK_STRING:
@@ -116,7 +116,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
is_command = 0;
wchar_t *unesc = unescape( last, UNESCAPE_SPECIAL );
-
+
if( parser_keywords_is_block( unesc ) )
{
next_indent++;
@@ -135,17 +135,17 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
indent--;
next_indent--;
}
-
-
+
+
if( do_indent && flags && prev_type != TOK_PIPE )
{
insert_tabs( out, indent );
}
-
+
sb_printf( out, L"%ls", last );
-
+
indent = next_indent;
-
+
}
else
{
@@ -153,13 +153,13 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
sb_append( out, L" " );
sb_append( out, last );
}
-
+
break;
}
-
+
case TOK_END:
{
- if( prev_type != TOK_END || prev_prev_type != TOK_END )
+ if( prev_type != TOK_END || prev_prev_type != TOK_END )
sb_append( out, L"\n" );
do_indent = 1;
is_command = 1;
@@ -174,11 +174,11 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
} else if ( last[0] != '1' || last[1] ) {
sb_append( out, last, L">" );
}
- sb_append( out, L"| " );
+ sb_append( out, L" | " );
is_command = 1;
break;
}
-
+
case TOK_REDIRECT_OUT:
{
sb_append( out, L" " );
@@ -186,13 +186,13 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
sb_append( out, L"^" );
} else {
if ( wcscmp( last, L"1" ) != 0 )
- sb_append( out, last );
- sb_append( out, L">" );
+ sb_append( out, last );
+ sb_append( out, L"> " );
}
- break;
+ break;
}
-
- case TOK_REDIRECT_APPEND:
+
+ case TOK_REDIRECT_APPEND:
{
sb_append( out, L" " );
if ( wcscmp( last, L"2" ) == 0 ) {
@@ -200,28 +200,28 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
} else {
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
- sb_append( out, L">>" );
+ sb_append( out, L">> " );
}
- break;
+ break;
}
-
- case TOK_REDIRECT_IN:
+
+ case TOK_REDIRECT_IN:
{
sb_append( out, L" " );
if ( wcscmp( last, L"0" ) != 0 )
sb_append( out, last );
- sb_append( out, L"<" );
- break;
+ sb_append( out, L"< " );
+ break;
}
-
- case TOK_REDIRECT_FD:
+
+ case TOK_REDIRECT_FD:
{
sb_append( out, L" " );
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
- sb_append( out, L">&" );
- break;
- }
+ sb_append( out, L">& " );
+ break;
+ }
case TOK_BACKGROUND:
{
@@ -230,31 +230,31 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
is_command = 1;
break;
}
-
+
case TOK_COMMENT:
{
if( do_indent && flags)
{
insert_tabs( out, indent );
}
-
+
sb_printf( out, L"%ls", last );
do_indent = 1;
- break;
+ break;
}
-
+
default:
{
debug( 0, L"Unknown token '%ls'", last );
exit(1);
- }
+ }
}
-
+
prev_prev_type = prev_type;
prev_type = type;
-
+
}
-
+
tok_destroy( &tok );
return res;
@@ -268,27 +268,27 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
static wchar_t *trim( wchar_t *in )
{
wchar_t *end;
-
+
while( *in == L'\n' )
{
in++;
}
-
+
end = in + wcslen(in);
-
+
while( 1 )
{
if( end < in+2 )
break;
end--;
-
+
if( (*end == L'\n' ) && ( *(end-1) == L'\n' ) )
*end=0;
else
break;
}
-
+
return in;
}
@@ -300,9 +300,9 @@ int main( int argc, char **argv )
{
string_buffer_t sb_in;
string_buffer_t sb_out;
-
+
int do_indent=1;
-
+
wsetlocale( LC_ALL, L"" );
program_name=L"fish_indent";
@@ -312,55 +312,55 @@ int main( int argc, char **argv )
long_options[] =
{
{
- "no-indent", no_argument, 0, 'i'
+ "no-indent", no_argument, 0, 'i'
}
,
{
- "help", no_argument, 0, 'h'
+ "help", no_argument, 0, 'h'
}
,
{
- "version", no_argument, 0, 'v'
+ "version", no_argument, 0, 'v'
}
,
- {
- 0, 0, 0, 0
+ {
+ 0, 0, 0, 0
}
}
;
-
+
int opt_index = 0;
-
+
int opt = getopt_long( argc,
- argv,
+ argv,
GETOPT_STRING,
- long_options,
+ long_options,
&opt_index );
-
+
if( opt == -1 )
break;
-
+
switch( opt )
{
case 0:
{
break;
}
-
+
case 'h':
{
print_help( "fish_indent", 1 );
- exit( 0 );
+ exit( 0 );
break;
}
-
+
case 'v':
{
- fwprintf( stderr,
- _(L"%ls, version %s\n"),
+ fwprintf( stderr,
+ _(L"%ls, version %s\n"),
program_name,
PACKAGE_VERSION );
- exit( 0 );
+ exit( 0 );
}
case 'i':
@@ -368,23 +368,23 @@ int main( int argc, char **argv )
do_indent = 0;
break;
}
-
-
+
+
case '?':
{
exit( 1 );
}
-
- }
+
+ }
}
- halloc_util_init();
+ halloc_util_init();
sb_init( &sb_in );
sb_init( &sb_out );
read_file( stdin, &sb_in );
-
+
wutil_init();
if( !indent( &sb_out, (wchar_t *)sb_in.buff, do_indent ) )
@@ -398,7 +398,7 @@ int main( int argc, char **argv )
*/
fwprintf( stdout, L"%ls", (wchar_t *)sb_in.buff );
}
-
+
wutil_destroy();