Main Page | Class List | Directories | File List | Class Members | File Members

ansi2knr.c File Reference

#include <stdio.h>
#include <ctype.h>
#include <string.h>

Go to the source code of this file.

Defines

#define NULL   (0)
#define is_ascii(c)   1
#define is_space(c)   (is_ascii(c) && isspace(c))
#define is_alpha(c)   (is_ascii(c) && isalpha(c))
#define is_alnum(c)   (is_ascii(c) && isalnum(c))
#define isidchar(ch)   (is_alnum(ch) || (ch) == '_')
#define isidfirstchar(ch)   (is_alpha(ch) || (ch) == '_')
#define bufsize   5000

Functions

char * malloc ()
int free ()
char * ppdirforward ()
char * ppdirbackward ()
char * skipspace ()
char * scanstring ()
int writeblanks ()
int test1 ()
int convert1 ()
int main (int argc, argv)


Define Documentation

#define bufsize   5000
 

Referenced by do_strftime(), and main().

#define is_alnum  )     (is_ascii(c) && isalnum(c))
 

Definition at line 213 of file ansi2knr.c.

#define is_alpha  )     (is_ascii(c) && isalpha(c))
 

Definition at line 212 of file ansi2knr.c.

#define is_ascii  )     1
 

Definition at line 206 of file ansi2knr.c.

#define is_space  )     (is_ascii(c) && isspace(c))
 

Definition at line 211 of file ansi2knr.c.

Referenced by skipspace().

#define isidchar ch   )     (is_alnum(ch) || (ch) == '_')
 

Definition at line 216 of file ansi2knr.c.

Referenced by convert1(), and test1().

#define isidfirstchar ch   )     (is_alpha(ch) || (ch) == '_')
 

Definition at line 217 of file ansi2knr.c.

Referenced by convert1(), and test1().

#define NULL   (0)
 

Definition at line 193 of file ansi2knr.c.

Referenced by _getopt_initialize(), _getopt_internal(), _nl_explode_name(), _nl_find_domain(), _nl_free_domain_conv(), _nl_getenv(), _nl_init_domain_conv(), _nl_load_domain(), _nl_locale_name(), _nl_log_untranslated(), _nl_make_l10nflist(), _nl_normalize_codeset(), add_src(), analyze(), analyze_tree(), append_pattern(), append_right(), arg_assign(), argz_next__(), array_init(), array_vname(), asort_actual(), assoc_clear(), assoc_dump(), assoc_find(), assoc_from_list(), assoc_lookup(), assoc_sort_inplace(), build_charclass(), build_equiv_class(), build_range_exp(), build_trtable(), build_upper_buffer(), build_word_op(), calc_epsdest(), calc_first(), calc_next(), check_arrival(), check_arrival_add_next_nodes(), check_funcs(), check_matching(), close_io(), close_one(), close_redir(), concat_exp(), convert1(), copynode(), count_args(), create_cd_newstate(), create_ci_newstate(), create_initial_state(), create_newstate_common(), create_tree(), devopen(), dlerror(), dlopen(), do_bindtextdomain(), do_chdir(), do_chr(), do_close(), do_dcgettext(), do_dcngettext(), do_delete(), do_delete_loop(), do_fflush(), do_getline(), do_input(), do_match(), do_mkarray(), do_ord(), do_pathopen(), do_print(), do_print_rec(), do_printf(), do_readfile(), do_split(), do_srand(), do_strftime(), do_substr(), do_waitpid(), dump_funcs(), dump_prog(), dump_vars(), dumpintlstr(), dumpintlstr2(), dup_parms(), dup_table(), duplicate_tree(), efwrite(), err(), eval_condition(), exchange(), expand_bkref_cache(), extend_alias_table(), extend_buffers(), flags2str(), flush_io(), fmt_index(), fmt_ok(), format_tree(), format_val(), free_bin_tree(), free_dfa_content(), free_workarea_compile(), func_call(), func_install(), func_use(), gawk_name(), gawk_pclose(), gawk_popen(), gawk_strtod(), genflags2str(), get_a_record(), get_actual(), get_charset_aliases(), get_field(), get_src_buf(), get_subexp(), get_sysdep_segment_value(), getfname(), getredirect(), grow_table(), in_array(), init_args(), init_dfa(), init_groupset(), init_vars(), init_word_char(), inrec(), interpret(), iop_alloc(), iop_close(), iop_open(), iopflags2str(), isdirpunct(), ispath(), load_environ(), load_procinfo(), locale_charset(), lookup(), main(), make_param(), make_regexp(), match_ctx_add_entry(), match_ctx_add_sublast(), match_ctx_add_subtop(), match_ctx_init(), merge(), merge_sort(), merge_state_array(), mk_number(), mk_rexp(), more_nodes(), new_exp(), new_exp_0(), nextfile(), nondec2awknum(), op_assign(), optimal_bufsize(), os_popen(), param_sanity(), parenthesize(), parms_shadow(), parse(), parse_args(), parse_bracket_exp(), parse_branch(), parse_dup_op(), parse_expression(), parse_reg_exp(), parse_sub_exp(), pop_forloop(), pop_params(), pop_var(), pp_delete(), pp_getline(), pp_list(), pp_match_op(), pp_op_assign(), pp_print_stmt(), pp_redir(), pp_string_fp(), pprint(), proceed_next_node(), prune_impossible_nodes(), pty_vs_pipe(), push_args(), push_fail_stack(), push_forloop(), r_force_number(), r_force_string(), r_get_lhs(), r_tree_eval(), re_acquire_state(), re_acquire_state_context(), re_compile_internal(), re_compile_pattern(), re_copy_regs(), re_dfa_add_node(), re_node_set_add_intersect(), re_node_set_alloc(), re_node_set_compare(), re_node_set_init_1(), re_node_set_init_2(), re_node_set_init_copy(), re_node_set_init_union(), re_node_set_insert(), re_node_set_merge(), re_search_2_stub(), re_search_internal(), re_search_stub(), re_string_construct(), re_string_realloc_buffers(), re_string_reconstruct(), re_update(), read_alias_file(), redflags2str(), redirect(), redirect_to_fp(), reflags2str(), refree(), regcomp(), regexec(), regfree(), register_state(), reisstring(), release_all_vars(), remaybelong(), research(), set_binding_values(), set_FIELDWIDTHS(), set_FS(), set_prof_file(), set_regs(), set_RS(), shadow_funcs(), sift_states_backward(), sift_states_bkref(), snode(), specfdopen(), stdfile(), str2mode(), strchr(), strrchr(), sub_common(), system(), tokexpand(), transit_state(), transit_state_bkref(), transit_state_sb(), tree_eval(), two_way_open(), unlink(), unref(), update_cur_sifted_state(), update_PROCINFO(), v_add_arg(), variable(), vms_arg_fixup(), vms_devopen(), vms_expand_wildcards(), wait_any(), yyerror(), yylex(), yyparse(), and zaxxon().


Function Documentation

int convert1  ) 
 

Referenced by main().

int free  ) 
 

Referenced by _getopt_internal(), _nl_explode_name(), _nl_find_domain(), _nl_free_domain_conv(), _nl_load_domain(), _nl_log_untranslated(), _nl_make_l10nflist(), assoc_clear(), assoc_sort_inplace(), build_trtable(), check_funcs(), close_redir(), convert1(), do_delete(), do_match(), do_pathopen(), do_print(), do_strftime(), dump_funcs(), dump_vars(), dup_parms(), format_tree(), get_charset_aliases(), get_src_buf(), grow_table(), iop_close(), load_procinfo(), main(), make_regexp(), match_ctx_free_subtops(), os_pclose(), pathopen(), pop_fcall(), pop_forloop(), pop_var(), pty_vs_pipe(), r_tree_eval(), refree(), set_binding_values(), shadow_funcs(), specfdopen(), sub_common(), unref(), variable(), vms_arg_fixup(), yyerror(), and yylex().

int main int  argc,
argv 
 

Definition at line 230 of file ansi2knr.c.

References bufsize, convert1(), exit, fclose, free(), malloc(), NULL, ppdirforward(), skipspace(), test1(), and usage().

00233 {       FILE *in = stdin;
00234         FILE *out = stdout;
00235         char *filename = 0;
00236         char *program_name = argv[0];
00237         char *output_name = 0;
00238 #define bufsize 5000                    /* arbitrary size */
00239         char *buf;
00240         char *line;
00241         char *more;
00242         char *usage =
00243           "Usage: ansi2knr [--filename FILENAME] [INPUT_FILE [OUTPUT_FILE]]\n";
00244         /*
00245          * In previous versions, ansi2knr recognized a --varargs switch.
00246          * If this switch was supplied, ansi2knr would attempt to convert
00247          * a ... argument to va_alist and va_dcl; if this switch was not
00248          * supplied, ansi2knr would simply drop any such arguments.
00249          * Now, ansi2knr always does this conversion, and we only
00250          * check for this switch for backward compatibility.
00251          */
00252         int convert_varargs = 1;
00253         int output_error;
00254 
00255         while ( argc > 1 && argv[1][0] == '-' ) {
00256           if ( !strcmp(argv[1], "--varargs") ) {
00257             convert_varargs = 1;
00258             argc--;
00259             argv++;
00260             continue;
00261           }
00262           if ( !strcmp(argv[1], "--filename") && argc > 2 ) {
00263             filename = argv[2];
00264             argc -= 2;
00265             argv += 2;
00266             continue;
00267           }
00268           fprintf(stderr, "%s: Unrecognized switch: %s\n", program_name,
00269                   argv[1]);
00270           fprintf(stderr, usage);
00271           exit(1);
00272         }
00273         switch ( argc )
00274            {
00275         default:
00276                 fprintf(stderr, usage);
00277                 exit(0);
00278         case 3:
00279                 output_name = argv[2];
00280                 out = fopen(output_name, "w");
00281                 if ( out == NULL ) {
00282                   fprintf(stderr, "%s: Cannot open output file %s\n",
00283                           program_name, output_name);
00284                   exit(1);
00285                 }
00286                 /* falls through */
00287         case 2:
00288                 in = fopen(argv[1], "r");
00289                 if ( in == NULL ) {
00290                   fprintf(stderr, "%s: Cannot open input file %s\n",
00291                           program_name, argv[1]);
00292                   exit(1);
00293                 }
00294                 if ( filename == 0 )
00295                   filename = argv[1];
00296                 /* falls through */
00297         case 1:
00298                 break;
00299            }
00300         if ( filename )
00301           fprintf(out, "#line 1 \"%s\"\n", filename);
00302         buf = malloc(bufsize);
00303         if ( buf == NULL )
00304            {
00305                 fprintf(stderr, "Unable to allocate read buffer!\n");
00306                 exit(1);
00307            }
00308         line = buf;
00309         while ( fgets(line, (unsigned)(buf + bufsize - line), in) != NULL )
00310            {
00311 test:           line += strlen(line);
00312                 switch ( test1(buf) )
00313                    {
00314                 case 2:                 /* a function header */
00315                         convert1(buf, out, 1, convert_varargs);
00316                         break;
00317                 case 1:                 /* a function */
00318                         /* Check for a { at the start of the next line. */
00319                         more = ++line;
00320 f:                      if ( line >= buf + (bufsize - 1) ) /* overflow check */
00321                           goto wl;
00322                         if ( fgets(line, (unsigned)(buf + bufsize - line), in) == NULL )
00323                           goto wl;
00324                         switch ( *skipspace(ppdirforward(more), 1) )
00325                           {
00326                           case '{':
00327                             /* Definitely a function header. */
00328                             convert1(buf, out, 0, convert_varargs);
00329                             fputs(more, out);
00330                             break;
00331                           case 0:
00332                             /* The next line was blank or a comment: */
00333                             /* keep scanning for a non-comment. */
00334                             line += strlen(line);
00335                             goto f;
00336                           default:
00337                             /* buf isn't a function header, but */
00338                             /* more might be. */
00339                             fputs(buf, out);
00340                             strcpy(buf, more);
00341                             line = buf;
00342                             goto test;
00343                           }
00344                         break;
00345                 case -1:                /* maybe the start of a function */
00346                         if ( line != buf + (bufsize - 1) ) /* overflow check */
00347                           continue;
00348                         /* falls through */
00349                 default:                /* not a function */
00350 wl:                     fputs(buf, out);
00351                         break;
00352                    }
00353                 line = buf;
00354            }
00355         if ( line != buf )
00356           fputs(buf, out);
00357         free(buf);
00358         if ( output_name ) {
00359           output_error = ferror(out);
00360           output_error |= fclose(out);
00361         } else {                /* out == stdout */
00362           fflush(out);
00363           output_error = ferror(out);
00364         }
00365         if ( output_error ) {
00366           fprintf(stderr, "%s: error writing to %s\n", program_name,
00367                   (output_name ? output_name : "stdout"));
00368           exit(1);
00369         }
00370         if ( in != stdin )
00371           fclose(in);
00372         return 0;
00373 }

char* malloc  ) 
 

Referenced by __attribute__(), _getopt_initialize(), _nl_find_domain(), _nl_load_domain(), _nl_log_untranslated(), _nl_make_l10nflist(), _nl_normalize_codeset(), build_trtable(), convert1(), exchange(), get_charset_aliases(), main(), new_exp(), set_binding_values(), strdup(), and v_add_arg().

char* ppdirbackward  ) 
 

Referenced by test1().

char* ppdirforward  ) 
 

Referenced by main().

char* scanstring  ) 
 

Referenced by convert1().

char* skipspace  ) 
 

Referenced by convert1(), main(), and test1().

int test1  ) 
 

Referenced by main().

int writeblanks  ) 
 

Referenced by convert1().


© sourcejam.com 2005-2008