]> git.ipfire.org Git - pakfire.git/commitdiff
Add libpakfire-parser
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 9 Mar 2019 18:15:37 +0000 (18:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 9 Mar 2019 18:15:37 +0000 (18:15 +0000)
This library is now a prototype for a bison/flex parser
of the package metadata.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/archive.c
src/libpakfire/include/pakfire/parser.h [new file with mode: 0644]
src/libpakfire/parser/.gitignore [new file with mode: 0644]
src/libpakfire/parser/grammar.y [new file with mode: 0644]
src/libpakfire/parser/scanner.l [new file with mode: 0644]

index b8af3230b9f189f69a9c6cb7457794ce085936ac..9e0fd84f3fc1b84de8cb48d331696105cc635169 100644 (file)
@@ -70,6 +70,7 @@ PAKFIRE_LIBS     = libpakfire.la
 check_PROGRAMS =
 lib_LTLIBRARIES =
 libexec_PROGRAMS =
+noinst_LTLIBRARIES =
 pkgpyexec_LTLIBRARIES =
 pkginclude_HEADERS =
 
@@ -239,6 +240,24 @@ _pakfire_la_LIBADD = \
 
 # ------------------------------------------------------------------------------
 
+CLEANFILES += \
+       src/libpakfire/grammar.c \
+       src/libpakfire/grammar.h \
+       src/libpakfire/scanner.c
+
+noinst_LTLIBRARIES += \
+       libpakfire-parser.la
+
+libpakfire_parser_la_SOURCES = \
+       src/libpakfire/parser/grammar.h \
+       src/libpakfire/parser/grammar.y \
+       src/libpakfire/parser/scanner.l
+
+libpakfire_parser_la_CFLAGS = \
+       $(AM_CFLAGS)
+
+src/libpakfire/parser/scanner.c: src/libpakfire/parser/grammar.h
+
 lib_LTLIBRARIES += \
        libpakfire.la
 
@@ -276,6 +295,7 @@ pkginclude_HEADERS += \
        src/libpakfire/include/pakfire/package.h \
        src/libpakfire/include/pakfire/packagelist.h \
        src/libpakfire/include/pakfire/pakfire.h \
+       src/libpakfire/include/pakfire/parser.h \
        src/libpakfire/include/pakfire/private.h \
        src/libpakfire/include/pakfire/problem.h \
        src/libpakfire/include/pakfire/relation.h \
@@ -307,6 +327,7 @@ libpakfire_la_LDFLAGS = \
        -Wl,--version-script=$(top_srcdir)/src/libpakfire/libpakfire.sym
 
 libpakfire_la_LIBADD = \
+       libpakfire-parser.la \
        $(ARCHIVE_LIBS) \
        $(GPGME_LIBS) \
        $(LIBGCRYPT_LIBS) \
@@ -314,7 +335,8 @@ libpakfire_la_LIBADD = \
        $(SOLV_LIBS)
 
 libpakfire_la_DEPENDENCIES = \
-       src/libpakfire/libpakfire.sym
+       src/libpakfire/libpakfire.sym \
+       libpakfire-parser.la
 
 EXTRA_DIST += \
        src/libpakfire/libpakfire.sym
index e47284fd6a96eff4499715498fe9eb51b2a4e295..54cf977d901edbac4507ec878cd795c41b45d35a 100644 (file)
@@ -357,11 +357,12 @@ static int pakfire_archive_parse_entry_metadata(PakfireArchive archive,
                return 1;
        }
 
-       #warning actually parse this
+       // Parse metadata file
+       r = pakfire_parser_parse_metadata(archive->pakfire, data, data_size);
 
        pakfire_free(data);
 
-       return 0;
+       return r;
 }
 
 static int pakfire_archive_parse_entry_filelist(PakfireArchive archive,
diff --git a/src/libpakfire/include/pakfire/parser.h b/src/libpakfire/include/pakfire/parser.h
new file mode 100644 (file)
index 0000000..4f73a98
--- /dev/null
@@ -0,0 +1,30 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2019 Pakfire development team                                 #
+#                                                                             #
+# 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, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_PARSER_H
+#define PAKFIRE_PARSER_H
+
+#ifdef PAKFIRE_PRIVATE
+
+int pakfire_parser_parse_metadata(const char* data, size_t len);
+
+#endif /* PAKFIRE_PRIVATE */
+
+#endif /* PAKFIRE_PARSER_H */
diff --git a/src/libpakfire/parser/.gitignore b/src/libpakfire/parser/.gitignore
new file mode 100644 (file)
index 0000000..59f9e3c
--- /dev/null
@@ -0,0 +1,2 @@
+/grammar.[ch]
+/scanner.c
diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y
new file mode 100644 (file)
index 0000000..04c7616
--- /dev/null
@@ -0,0 +1,63 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2019 Pakfire development team                                 #
+#                                                                             #
+# 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, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+%{
+#include <stdio.h>
+#include <stdlib.h>
+
+#define YYERROR_VERBOSE 1
+
+typedef struct yy_buffer_state* YY_BUFFER_STATE;
+extern YY_BUFFER_STATE yy_scan_bytes(const char* buffer, size_t len);
+extern void yy_delete_buffer(YY_BUFFER_STATE buffer);
+
+extern int yylex();
+extern int yyparse();
+void yyerror(const char* s);
+%}
+
+%token APPEND
+%token ASSIGN
+%token DEFINE
+%token END
+%token NEWLINE
+%token TAB
+%token VARIABLE
+%token VALUE
+%token WHITESPACE
+
+%%
+
+top: NEWLINE
+
+%%
+
+int pakfire_parser_parse_metadata(const char* data, size_t len) {
+       YY_BUFFER_STATE buffer = yy_scan_bytes(data, len);
+       int r = yyparse();
+       yy_delete_buffer(buffer);
+
+       return r;
+}
+
+void yyerror(const char* s) {
+       fprintf(stderr, "Parse error: %s\n", s);
+       abort();
+}
diff --git a/src/libpakfire/parser/scanner.l b/src/libpakfire/parser/scanner.l
new file mode 100644 (file)
index 0000000..406c5c4
--- /dev/null
@@ -0,0 +1,45 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2019 Pakfire development team                                 #
+#                                                                             #
+# 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, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+%option nounput noinput noyywrap yylineno
+
+%{
+#define YY_DECL int yylex()
+
+#include "grammar.h"
+%}
+
+%%
+
+[ \t]          { return WHITESPACE; }
+\t                     { return TAB; }
+\n                     { return NEWLINE; }
+
+[A-Za-z]       { return VARIABLE; }
+[A-Za-z0-9]    { return VALUE; }
+
+"="                    { return ASSIGN; }
+"+="           { return APPEND; }
+
+"define"       { return DEFINE; }
+"def"          { return DEFINE; }
+"end"          { return END; }
+
+%%