/* **++ ** FACILITY: SCA Example ** ** MODULE DESCRIPTION: ** ** This is the main program for the transliteration example used by SCA. ** ** AUTHORS: ** ** Jones ** ** CREATION DATE: 16-Jul-1991 ** ** DESIGN ISSUES: ** ** None ** ** MODIFICATION HISTORY: ** ** {@tbs@}... **-- */ /* ** ** INCLUDE FILES ** */ #include #include #include "openfiles.h" #include "types.h" extern int trnlit__openin, trnlit__openout, trnlit__badorig, trnlit__badrepl, trnlit__null, trnlit__compnull, trnlit__complete; int expand_string ( param_string str, code_vector codes, param_string error_text ); void build_table (code_vector orig_vector, code_vector repl_vector, code_vector_length orig_length, code_vector_length repl_length, boolean complement, trans_table table ); void copy_file (FILE *in_file, FILE *out_file, trans_table table); void write_error (int error_status, int extra_status, char *err_text); int read_command_line (int argc, char *argv[], FILE *in_file, FILE *out_file, trans_table table ); /* **++ ** FUNCTIONAL DESCRIPTION: ** ** Read the command line and do the translation. ** ** FORMAL PARAMETERS: ** ** argc: ** Argument count for command line. ** ** argv: ** Argument values from command line. ** ** RETURN VALUE: ** ** Completion status ** ** SIDE EFFECTS: ** ** A new file is created. ** **-- */ main (int argc, char *argv[]) { FILE *in_file; FILE *out_file; trans_table table; read_command_line (argc, argv, in_file, out_file, table); copy_file (in_file, out_file, table); return trnlit__complete; } /* **++ ** FUNCTIONAL DESCRIPTION: ** ** Get arguments from the translit command line, and do initialization. ** ** Parse the command line. Open the input file, build the translation ** table, and open the output file. ** ** FORMAL PARAMETERS: ** ** argc: ** Argument count for command line. ** ** argv: ** Argument values from command line. ** ** in_file: ** The input file. The input file will be opened by this function. ** ** out_file: ** The output file. The output file will be opened by this function. ** ** table: ** The translation table. This function causes the translation table ** to be built. ** ** RETURN VALUE: ** ** Status. **-- */ int read_command_line (int argc, char *argv[], FILE *in_file, FILE *out_file, trans_table table ) { param_string in_file_name; param_string orig_chars_string; param_string repl_chars_string; param_string out_file_name; code_vector orig_vector; code_vector repl_vector; code_vector_length orig_len; code_vector_length repl_len; int status; param_string err_text; boolean complement_originals; /* ** Initialize variables. */ orig_len = 0; repl_len = 0; /* ** Get command line arguments. */ in_file_name = argv[1]; orig_chars_string = argv[2]; repl_chars_string = argv[3]; out_file_name = argv[4]; /* ** Open the input file. */ open_in (in_file, in_file_name, "", trnlit__openin); /* ** Get the original characters string. */ err_text = ""; if (strlen (orig_chars_string) == 0) { /* ** The string is empty. Set the status now, and signal it later. */ status = trnlit__null; } else { /* ** The string is non-empty, so we can parse it. */ /* ** Check to see if we are to complement the original characters. */ complement_originals = (orig_chars_string[0] == '-'); if (complement_originals) { strncpy (orig_chars_string, &orig_chars_string[1], strlen(orig_chars_string) - 1); }; if (strlen(orig_chars_string) == 0) { status = trnlit__compnull; } else { status = expand_string (orig_chars_string, orig_vector, err_text); }; }; if (status != 1) { write_error (trnlit__badorig, status, err_text); return status; }; /* ** Get the replacement characters string. */ status = expand_string (repl_chars_string, repl_vector, err_text); if (status != 1) { write_error (trnlit__badrepl, status, err_text); return status; }; /* ** Build the translation table. */ build_table (orig_vector, repl_vector, orig_len, repl_len, complement_originals, table); /* ** Get the output file. */ open_out (out_file, out_file_name, "", in_file, trnlit__openout); }