orcc: use #pragma once in generated headers
authorTim-Philipp Müller <tim@centricular.com>
Sat, 4 Jul 2020 10:49:09 +0000 (11:49 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 4 Jul 2020 10:52:44 +0000 (11:52 +0100)
Simplifies code and removes build path fragments from
generated file (paths may be different if generated
in a gst-build setup).

There shouldn't be any portability issues with this. Meson
has been using this in its generated config.h for years.

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

tools/orcc.c

index 7d58593..3585e93 100644 (file)
@@ -22,7 +22,6 @@ void output_code_assembly (OrcProgram *p, FILE *output);
 void output_code_execute (OrcProgram *p, FILE *output, int is_inline);
 void output_program_generation (OrcProgram *p, FILE *output, int is_inline);
 void output_init_function (FILE *output);
-static char * get_barrier (const char *s);
 static const char * my_basename (const char *s);
 
 int verbose = 0;
@@ -319,11 +318,7 @@ main (int argc, char *argv[])
       fprintf(output, "\n");
     }
   } else if (mode == MODE_HEADER) {
-    char *barrier = get_barrier (output_file);
-
-    fprintf(output, "#ifndef _%s_\n", barrier);
-    fprintf(output, "#define _%s_\n", barrier);
-    free (barrier);
+    fprintf(output, "#pragma once\n");
     fprintf(output, "\n");
     if (include_file) {
       fprintf(output, "#include <%s>\n", include_file);
@@ -357,8 +352,6 @@ main (int argc, char *argv[])
     fprintf(output, "}\n");
     fprintf(output, "#endif\n");
     fprintf(output, "\n");
-    fprintf(output, "#endif\n");
-    fprintf(output, "\n");
   } else if (mode == MODE_TEST) {
     fprintf(output, "#include <stdio.h>\n");
     fprintf(output, "#include <string.h>\n");
@@ -450,28 +443,6 @@ main (int argc, char *argv[])
   return 0;
 }
 
-
-static char *
-get_barrier (const char *s)
-{
-  char *barrier;
-  int n;
-  int i;
-
-  n = strlen(s);
-  barrier = malloc (n + 1);
-  for(i=0;i<n;i++) {
-    if (isalnum (s[i])) {
-      barrier[i] = toupper(s[i]);
-    } else {
-      barrier[i] = '_';
-    }
-  }
-  barrier[n] = 0;
-
-  return barrier;
-}
-
 static char *
 read_file (const char *filename)
 {