Skip to content

Commit

Permalink
Fix functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodan-ilic committed Jun 21, 2024
1 parent 07e323f commit b0a99ef
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 161 deletions.
161 changes: 80 additions & 81 deletions src/spss/readstat_sav_parse_mr_name.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
#include <stdlib.h>
#include "../readstat.h"
#include "../readstat_malloc.h"
#include "readstat_sav_parse_mr_name.h"


#line 12 "./src/spss/readstat_sav_parse_mr_name.c"
static const char _parse_multiple_response_actions[] = {
#line 11 "./src/spss/readstat_sav_parse_mr_name.c"
static const char _mr_extractor_actions[] = {
0, 1, 0, 1, 1, 1, 2, 1,
3, 1, 4
};

static const char _parse_multiple_response_key_offsets[] = {
static const char _mr_extractor_key_offsets[] = {
0, 0, 7, 15, 17, 20, 22, 25,
33, 44
};

static const char _parse_multiple_response_trans_keys[] = {
static const char _mr_extractor_trans_keys[] = {
95, 48, 57, 65, 90, 97, 122, 61,
95, 48, 57, 65, 90, 97, 122, 67,
68, 32, 48, 57, 48, 57, 32, 48,
Expand All @@ -29,22 +28,22 @@ static const char _parse_multiple_response_trans_keys[] = {
90, 97, 122, 0
};

static const char _parse_multiple_response_single_lengths[] = {
static const char _mr_extractor_single_lengths[] = {
0, 1, 2, 0, 1, 0, 1, 2,
3, 1
};

static const char _parse_multiple_response_range_lengths[] = {
static const char _mr_extractor_range_lengths[] = {
0, 3, 3, 1, 1, 1, 1, 3,
4, 3
};

static const char _parse_multiple_response_index_offsets[] = {
static const char _mr_extractor_index_offsets[] = {
0, 0, 5, 11, 13, 16, 18, 21,
27, 35
};

static const char _parse_multiple_response_indicies[] = {
static const char _mr_extractor_indicies[] = {
0, 0, 0, 0, 1, 2, 0, 0,
0, 0, 1, 3, 1, 4, 5, 1,
6, 1, 7, 6, 1, 8, 9, 9,
Expand All @@ -53,23 +52,22 @@ static const char _parse_multiple_response_indicies[] = {
0
};

static const char _parse_multiple_response_trans_targs[] = {
static const char _mr_extractor_trans_targs[] = {
2, 0, 3, 4, 5, 4, 6, 7,
7, 8, 9
};

static const char _parse_multiple_response_trans_actions[] = {
static const char _mr_extractor_trans_actions[] = {
0, 0, 1, 3, 5, 0, 0, 7,
0, 0, 9
};

static const int parse_multiple_response_start = 1;
static const int mr_extractor_start = 1;

static const int parse_multiple_response_en_main = 1;
static const int mr_extractor_en_main = 1;


#line 11 "./src/spss/readstat_sav_parse_mr_name.rl"

#line 75 "./src/spss/readstat_sav_parse_mr_name.rl"


readstat_error_t extract_mr_data(const char *line, mr_set_t *result) {
Expand All @@ -84,18 +82,20 @@ readstat_error_t extract_mr_data(const char *line, mr_set_t *result) {
// Variables needed for passing Ragel intermediate results
char mr_type = '\0';
int mr_counted_value = -1;
int mr_subvar_count = -1;
char** mr_subvariables = NULL;
char* mr_name = NULL;
char* mr_label = NULL;
int mr_subvar_count = 0;
char **mr_subvariables = NULL;
char *mr_name = NULL;
char *mr_label = NULL;

// Execute Ragel finite state machine (FSM)

#line 95 "./src/spss/readstat_sav_parse_mr_name.c"
#line 93 "./src/spss/readstat_sav_parse_mr_name.c"
{
cs = parse_multiple_response_start;
cs = mr_extractor_start;
}

#line 96 "./src/spss/readstat_sav_parse_mr_name.rl"

#line 100 "./src/spss/readstat_sav_parse_mr_name.c"
{
int _klen;
Expand All @@ -109,10 +109,10 @@ readstat_error_t extract_mr_data(const char *line, mr_set_t *result) {
if ( cs == 0 )
goto _out;
_resume:
_keys = _parse_multiple_response_trans_keys + _parse_multiple_response_key_offsets[cs];
_trans = _parse_multiple_response_index_offsets[cs];
_keys = _mr_extractor_trans_keys + _mr_extractor_key_offsets[cs];
_trans = _mr_extractor_index_offsets[cs];

_klen = _parse_multiple_response_single_lengths[cs];
_klen = _mr_extractor_single_lengths[cs];
if ( _klen > 0 ) {
const char *_lower = _keys;
const char *_mid;
Expand All @@ -135,7 +135,7 @@ readstat_error_t extract_mr_data(const char *line, mr_set_t *result) {
_trans += _klen;
}

_klen = _parse_multiple_response_range_lengths[cs];
_klen = _mr_extractor_range_lengths[cs];
if ( _klen > 0 ) {
const char *_lower = _keys;
const char *_mid;
Expand All @@ -158,80 +158,80 @@ readstat_error_t extract_mr_data(const char *line, mr_set_t *result) {
}

_match:
_trans = _parse_multiple_response_indicies[_trans];
cs = _parse_multiple_response_trans_targs[_trans];
_trans = _mr_extractor_indicies[_trans];
cs = _mr_extractor_trans_targs[_trans];

if ( _parse_multiple_response_trans_actions[_trans] == 0 )
if ( _mr_extractor_trans_actions[_trans] == 0 )
goto _again;

_acts = _parse_multiple_response_actions + _parse_multiple_response_trans_actions[_trans];
_acts = _mr_extractor_actions + _mr_extractor_trans_actions[_trans];
_nacts = (unsigned int) *_acts++;
while ( _nacts-- > 0 )
{
switch ( *_acts++ )
{
case 0:
#line 33 "./src/spss/readstat_sav_parse_mr_name.rl"
#line 10 "./src/spss/readstat_sav_parse_mr_name.rl"
{
mr_name = readstat_malloc(p - start + 1);
memcpy(mr_name, start, p - start);
mr_name[p - start] = '\0';
}
mr_name = (char *)malloc(p - start + 1);
memcpy(mr_name, start, p - start);
mr_name[p - start] = '\0';
}
break;
case 1:
#line 39 "./src/spss/readstat_sav_parse_mr_name.rl"
#line 16 "./src/spss/readstat_sav_parse_mr_name.rl"
{
mr_type = *p;
start = p + 1;
}
mr_type = *p;
start = p + 1;
}
break;
case 2:
#line 44 "./src/spss/readstat_sav_parse_mr_name.rl"
#line 21 "./src/spss/readstat_sav_parse_mr_name.rl"
{
int n_cv_digs = p - start;
char *n_dig_str = readstat_malloc(n_cv_digs + 1);
memcpy(n_dig_str, start, n_cv_digs);
n_dig_str[n_cv_digs] = '\0';
int n_digs = strtol(n_dig_str, NULL, 10);
if (n_digs != 0) {
char *cv = readstat_malloc(n_digs + 1);
memcpy(cv, p + 1, n_digs);
cv[n_digs] = '\0';
mr_counted_value = strtol(cv, NULL, 10);
p = p + 1 + n_digs;
start = p + 1;
}
else {
mr_counted_value = -1;
}
int n_cv_digs = p - start;
char *n_dig_str = (char *)malloc(n_cv_digs + 1);
memcpy(n_dig_str, start, n_cv_digs);
n_dig_str[n_cv_digs] = '\0';
int n_digs = strtol(n_dig_str, NULL, 10);
if (n_digs != 0) {
char *cv = (char *)malloc(n_digs + 1);
memcpy(cv, p + 1, n_digs);
cv[n_digs] = '\0';
mr_counted_value = strtol(cv, NULL, 10);
p = p + 1 + n_digs;
start = p + 1;
}
else {
mr_counted_value = -1;
}
}
break;
case 3:
#line 63 "./src/spss/readstat_sav_parse_mr_name.rl"
#line 40 "./src/spss/readstat_sav_parse_mr_name.rl"
{
char *lbl_len_str = readstat_malloc(p - start + 1);
memcpy(lbl_len_str, start, p - start);
lbl_len_str[p - start] = '\0';
int len = strtol(lbl_len_str, NULL, 10);
mr_label = readstat_malloc(len + 1);
memcpy(mr_label, p + 1, len);
mr_label[len] = '\0';
p = p + 1 + len;
start = p + 1;
}
char *lbl_len_str = (char *)malloc(p - start + 1);
memcpy(lbl_len_str, start, p - start);
lbl_len_str[p - start] = '\0';
int len = strtol(lbl_len_str, NULL, 10);
mr_label = (char *)malloc(len + 1);
memcpy(mr_label, p + 1, len);
mr_label[len] = '\0';
p = p + 1 + len;
start = p + 1;
}
break;
case 4:
#line 75 "./src/spss/readstat_sav_parse_mr_name.rl"
#line 52 "./src/spss/readstat_sav_parse_mr_name.rl"
{
int len = p - start;
char *subvar = readstat_malloc(len + 1);
memcpy(subvar, start, len);
subvar[len] = '\0';
start = p + 1;

mr_subvariables = readstat_realloc(mr_subvariables, sizeof(char *) * (mr_subvar_count + 1));
mr_subvariables[mr_subvar_count++] = subvar;
}
int len = p - start;
char *subvar = (char *)malloc(len + 1);
memcpy(subvar, start, len);
subvar[len] = '\0';
start = p + 1;

mr_subvariables = realloc(mr_subvariables, sizeof(char *) * (mr_subvar_count + 1));
mr_subvariables[mr_subvar_count++] = subvar;
}
break;
#line 237 "./src/spss/readstat_sav_parse_mr_name.c"
}
Expand All @@ -246,14 +246,16 @@ readstat_error_t extract_mr_data(const char *line, mr_set_t *result) {
_out: {}
}

#line 99 "./src/spss/readstat_sav_parse_mr_name.rl"

#line 97 "./src/spss/readstat_sav_parse_mr_name.rl"

// Check if FSM finished successfully
if (cs < 9 || p != pe) {
retval = READSTAT_ERROR_BAD_MR_STRING;
goto cleanup;
}

(void)mr_extractor_en_main;

// Assign parsed values to output parameter
result->name = mr_name;
result->label = mr_label;
Expand All @@ -276,9 +278,6 @@ readstat_error_t extract_mr_data(const char *line, mr_set_t *result) {
if (mr_name != NULL) free(mr_name);
if (mr_label != NULL) free(mr_label);
}

(void)parse_multiple_response_en_main;

return retval;
}

Expand Down
1 change: 1 addition & 0 deletions src/spss/readstat_sav_parse_mr_name.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define READSTAT_PARSE_MR_NAME_H

#include "../readstat.h"
#include "../readstat_malloc.h"

readstat_error_t parse_mr_line(const char *line, mr_set_t *result);

Expand Down
Loading

0 comments on commit b0a99ef

Please sign in to comment.