Skip to content
Snippets Groups Projects
Commit 6dbd2070 authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

add Rule

This will provide methods to manipulate a rule. It is separated from a
grammar in order to simplify it. Essentially it is just a wrapper for
two arrays.
parent 1de6b093
No related branches found
No related tags found
No related merge requests found
......@@ -28,14 +28,14 @@ long_line_behaviour=1
long_line_column=72
[files]
current_page=12
current_page=14
FILE_NAME_0=309;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2FREADME;0;8
FILE_NAME_1=47;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2F.gitignore;0;8
FILE_NAME_2=1770;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fconfigure.ac;0;8
FILE_NAME_3=100;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2FMakefile.am;0;8
FILE_NAME_4=74;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2FMakefile.am;0;8
FILE_NAME_5=887;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Fmain.c;0;8
FILE_NAME_6=335;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2FMakefile.am;0;8
FILE_NAME_6=350;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2FMakefile.am;0;8
FILE_NAME_7=947;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fmacro.h;0;8
FILE_NAME_8=4638;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fstatus.h;0;8
FILE_NAME_9=881;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Flog.h;0;8
......@@ -43,13 +43,16 @@ FILE_NAME_10=8070;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fp
FILE_NAME_11=957;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fgrammar.h;0;8
FILE_NAME_12=6482;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Ffile.c;0;8
FILE_NAME_13=1457;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Ffile.h;0;8
FILE_NAME_14=1282;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fword.c;0;8
FILE_NAME_15=908;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fword.h;0;8
FILE_NAME_16=919;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2FMakefile.am;0;8
FILE_NAME_17=0;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Fno_test.sh;0;8
FILE_NAME_18=51550;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Ftest_grammar.c;0;8
FILE_NAME_19=17996;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Ftest_file.c;0;8
FILE_NAME_20=1731;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Ftest_word.c;0;8
FILE_NAME_14=968;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Frule.c;0;8
FILE_NAME_15=1068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Frule.h;0;8
FILE_NAME_16=1282;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fword.c;0;8
FILE_NAME_17=908;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Fsrc%2Flib%2Fword.h;0;8
FILE_NAME_18=433;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2FMakefile.am;0;8
FILE_NAME_19=0;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Fno_test.sh;0;8
FILE_NAME_20=51550;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Ftest_grammar.c;0;8
FILE_NAME_21=17996;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Ftest_file.c;0;8
FILE_NAME_22=1280;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Ftest_rule.c;0;8
FILE_NAME_23=1731;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDocuments%2Fprojects%2Fprgm%2Flanguage%2FGSAT%2Ftests%2Ftest_word.c;0;8
[prjorg]
source_patterns=*.c;
......
......@@ -10,6 +10,7 @@ libgsat_la_SOURCES += macro.h
libgsat_la_SOURCES += log.h
libgsat_la_SOURCES += grammar.c grammar.h
libgsat_la_SOURCES += file.c file.h
libgsat_la_SOURCES += rule.c rule.h
libgsat_la_SOURCES += word.c word.h
libgsat_la_LDFLAGS = -version_info 0:0:0
/*
* rule.c
*
* Copyright 2024 Jonathan Schöbel <jonathan@xn--schbel-yxa.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <stdlib.h>
#include "macro.h"
#include "status.h"
#include "rule.h"
struct GR_Rule
{
};
/*@null@*/
/*@only@*/
struct GR_Rule *
GR_Rule_new (/*@null@*/ /*@out@*/ struct GR_Status * status)
{
struct GR_Rule * rule;
rule = malloc (sizeof (struct GR_Rule));
if (NULL == rule)
{
set_status (status, E_ALLOC, 3, "malloc failed");
return NULL;
}
set_success (status);
return rule;
}
void
GR_Rule_free (/*@only@*/ struct GR_Rule * rule)
{
free (rule);
return;
}
/*
* rule.h
*
* Copyright 2024 Jonathan Schöbel <jonathan@xn--schbel-yxa.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <limits.h>
#include "status.h"
#ifndef GRAMMAR_RULE_H
#define GRAMMAR_RULE_H
typedef struct GR_Rule GR_Rule;
/*@null@*/
/*@only@*/
GR_Rule *
GR_Rule_new (/*@null@*/ /*@out@*/ struct GR_Status * status);
void
GR_Rule_free (/*@only@*/ GR_Rule * rule);
#endif /* GRAMMAR_RULE_H */
......@@ -15,6 +15,7 @@ if !MISSING_CHECK
check_PROGRAMS =
check_PROGRAMS += grammar_test
check_PROGRAMS += file_test
check_PROGRAMS += rule_test
check_PROGRAMS += word_test
endif
......@@ -40,6 +41,11 @@ file_test_LDADD =
file_test_LDADD += $(OBJECT_PREFIX)grammar.o
file_test_LDADD += $(tests_LDADD)
rule_test_SOURCES = test_rule.c
rule_test_CPPFLAGS = $(tests_CPPFLAGS)
rule_test_LDADD =
rule_test_LDADD += $(tests_LDADD)
word_test_SOURCES = test_word.c
word_test_CPPFLAGS = $(tests_CPPFLAGS)
word_test_LDADD =
......
/*
* test_rule.c
*
* Copyright 2024 Jonathan Schöbel <jonathan@xn--schbel-yxa.info>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*
*/
#include <check.h>
#include <stdlib.h>
#include "status.h"
#include "rule.c"
START_TEST(test_rule_no_status)
{
struct GR_Rule * rule;
rule = GR_Rule_new (NULL);
ck_assert_ptr_ne (NULL, rule);
GR_Rule_free (rule);
}
END_TEST
START_TEST(test_rule_with_status)
{
struct GR_Status status;
struct GR_Rule * rule;
_status_preinit(status);
rule = GR_Rule_new (&status);
ck_assert_ptr_ne (NULL, rule);
ck_assert_int_eq (SUCCESS, status.status);
GR_Rule_free (rule);
}
END_TEST
Suite * test_suite (void)
{
Suite *s;
TCase *tc_core;
s = suite_create ("Testsuite GSAT Rule");
/* Core test case */
tc_core = tcase_create ("Core");
tcase_add_test (tc_core, test_rule_no_status);
tcase_add_test (tc_core, test_rule_with_status);
suite_add_tcase (s, tc_core);
return s;
}
int main (void)
{
int number_failed;
Suite *s;
SRunner *sr;
s = test_suite ();
sr = srunner_create (s);
srunner_run_all (sr, CK_NORMAL);
number_failed = srunner_ntests_failed (sr);
srunner_free (sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment