/* Destroys CSV file writer W. */ static void csv_file_casewriter_destroy (struct casewriter *writer, void *w_) { struct csv_writer *w = w_; if (!close_writer (w)) casewriter_force_error (writer); }
int main (int argc, const char * argv[]) { /* initialize the file reader */ init_reader("../../../resources/sample.lua"); initialize_writer("../../../resources/sample.asm"); /* initialize transducer automata transitions */ initialize_transitions(); /* initialize semantic */ initialize_semantic(); /* initialize semantic actions */ init_semantic_actions(); // start APE machines init_ape_machines(); /* call sintatic analyser*/ run_sintatic(); close_writer(); return 0; }
/* Opens the CSV file designated by file handle FH for writing cases from dictionary DICT according to the given OPTS. No reference to D is retained, so it may be modified or destroyed at will after this function returns. */ struct casewriter * csv_writer_open (struct file_handle *fh, const struct dictionary *dict, const struct csv_writer_options *opts) { struct csv_writer *w; int i; /* Create and initialize writer. */ w = xmalloc (sizeof *w); w->fh = fh_ref (fh); w->lock = NULL; w->file = NULL; w->rf = NULL; w->opts = *opts; w->encoding = xstrdup (dict_get_encoding (dict)); w->n_csv_vars = dict_get_var_cnt (dict); w->csv_vars = xnmalloc (w->n_csv_vars, sizeof *w->csv_vars); for (i = 0; i < w->n_csv_vars; i++) { const struct variable *var = dict_get_var (dict, i); struct csv_var *cv = &w->csv_vars[i]; cv->width = var_get_width (var); cv->case_index = var_get_case_index (var); cv->format = *var_get_print_format (var); if (opts->recode_user_missing) mv_copy (&cv->missing, var_get_missing_values (var)); else mv_init (&cv->missing, cv->width); if (opts->use_value_labels) cv->val_labs = val_labs_clone (var_get_value_labels (var)); else cv->val_labs = NULL; } /* Open file handle as an exclusive writer. */ /* TRANSLATORS: this fragment will be interpolated into messages in fh_lock() that identify types of files. */ w->lock = fh_lock (fh, FH_REF_FILE, N_("CSV file"), FH_ACC_WRITE, true); if (w->lock == NULL) goto error; /* Create the file on disk. */ w->rf = replace_file_start (fh_get_file_name (fh), "w", 0666, &w->file, NULL); if (w->rf == NULL) { msg (ME, _("Error opening `%s' for writing as a system file: %s."), fh_get_file_name (fh), strerror (errno)); goto error; } if (opts->include_var_names) write_var_names (w, dict); if (write_error (w)) goto error; return casewriter_create (dict_get_proto (dict), &csv_file_casewriter_class, w); error: close_writer (w); return NULL; }