parser: add is_directive helper
authorFrancesco Romani <fromani@gmail.com>
Sun, 6 Jul 2014 13:13:57 +0000 (15:13 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Wed, 12 Apr 2023 17:04:26 +0000 (20:04 +0300)
To improve encapsulation

Part-of: <https://gitlab.freedesktop.org/gstreamer/orc/-/merge_requests/30>

orc/orcparse.c

index 43a41f8..a9fd31b 100644 (file)
@@ -65,6 +65,7 @@ static void orc_line_parse_tokens (OrcLine *line);
 static void orc_line_advance (OrcLine *line);
 static void orc_line_add_token (OrcLine *line);
 static int orc_line_has_tokens (const OrcLine *line);
+static int orc_line_is_directive (const OrcLine *line);
 
 static void orc_parse_add_error_valist (OrcParser *parser, const char *format, va_list args);
 static void orc_parse_add_error (OrcParser *parser, const char *format, ...);
@@ -160,7 +161,7 @@ orc_parse_code (const char *code, OrcProgram ***programs, int *n_programs,
     n_tokens = line->n_tokens;
     token = line->tokens;
 
-    if (token[0][0] == '.') {
+    if (orc_line_is_directive (line)) {
       if (strcmp (token[0], ".function") == 0) {
         if (n_tokens < 2) {
           orc_parse_add_error (parser, "line %d: .function without function name\n",
@@ -548,6 +549,12 @@ orc_line_parse_tokens (OrcLine *line)
   }
 }
 
+static int
+orc_line_is_directive (const OrcLine *line)
+{
+  return line->tokens[0][0] == '.';
+}
+
 
 static void
 orc_parse_init (OrcParser *parser, const char *code, int enable_errors)