[esnacc-dev] [PATCH] backends: set code readonly

Aaron Conole aconole at bytheb.org
Mon Jul 24 15:21:20 UTC 2017


Most editors do understand the buffer-read-only directive, so include it
upfront.  This improves usage overall - generated code in those editors
will toggle the read-only flag, and be uneditable.

Signed-off-by: Aaron Conole <aconole at bytheb.org>
---
 compiler/back-ends/c++-gen/gen-code.c | 38 +++++++++++++++++------------------
 compiler/back-ends/c-gen/gen-code.c   | 31 ++++++++++++++--------------
 compiler/back-ends/py-gen/gen-code.c  | 16 +++++++--------
 3 files changed, 43 insertions(+), 42 deletions(-)

diff --git a/compiler/back-ends/c++-gen/gen-code.c b/compiler/back-ends/c++-gen/gen-code.c
index 780df10..395b424 100644
--- a/compiler/back-ends/c++-gen/gen-code.c
+++ b/compiler/back-ends/c++-gen/gen-code.c
@@ -224,14 +224,15 @@ PrintHdrComment PARAMS ((hdr, m),
 {
     time_t now = time (NULL);
 
-    fprintf (hdr, "// %s - class definitions for ASN.1 module %s\n",
-             m->cxxHdrFileName, m->modId->name);
-    fprintf (hdr, "//\n");
-    fprintf (hdr, "//   This file was generated by esnacc on %s\n",
-             ctime(&now));
-    fprintf (hdr, "//   NOTE: this is a machine generated file-"
-             "-editing not recommended\n");
-    fprintf (hdr, "\n");
+
+    fprintf(hdr, "// definitions for module %s -*- buffer-read-only: t -*-\n",
+            m->modId->name);
+    fprintf(hdr, "//\n");
+    fprintf(hdr, "//   This file was generated by esnacc on %s\n",
+            ctime(&now));
+    fprintf(hdr, "//   NOTE: this is a machine generated file-"
+            "-editing not recommended\n");
+    fprintf(hdr, "\n");
 
 } /* PrintHdrComment */
 
@@ -240,17 +241,16 @@ PrintSrcComment PARAMS ((src, m),
     FILE *src _AND_
     Module *m)
 {
-    time_t now = time (NULL);
-
-    fprintf (src, "// %s - class definitions for ASN.1 module %s\n",
-             m->cxxSrcFileName, m->modId->name);
-    fprintf (src, "//\n");
-    fprintf (src, "//   This file was generated by esnacc on %s\n",
-             ctime(&now));
-    fprintf (src, "//   NOTE: this is a machine generated file-"
-             "-editing not recommended\n");
-    fprintf (src, "\n");
-
+    time_t now = time(NULL);
+
+    fprintf(src, "// definitions for module %s -*- buffer-read-only: t -*-\n",
+            m->modId->name);
+    fprintf(src, "//\n");
+    fprintf(src, "//   This file was generated by esnacc on %s\n",
+            ctime(&now));
+    fprintf(src, "//   NOTE: this is a machine generated file-"
+            "-editing not recommended\n");
+    fprintf(src, "\n");
 } /* PrintSrcComment */
 
 
diff --git a/compiler/back-ends/c-gen/gen-code.c b/compiler/back-ends/c-gen/gen-code.c
index 0e19d82..abf0d32 100644
--- a/compiler/back-ends/c-gen/gen-code.c
+++ b/compiler/back-ends/c-gen/gen-code.c
@@ -482,12 +482,13 @@ PrintCSrcComment PARAMS ((src, m),
     time_t t;
 
     t = time (0);
-    fprintf (src, "/*\n");
-    fprintf (src, " *    %s\n", m->cSrcFileName);
-    fprintf (src, " *    \"%s\" ASN.1 module encode/decode/print/free C src.\n", m->modId->name);
-    fprintf (src, " *    This file was generated by esnacc on %s", ctime (&t));
-    fprintf (src, " *    NOTE: This is a machine generated file - editing not recommended\n");
-    fprintf (src, " */\n\n");
+    fprintf(src, "/* -*- buffer-read-only: t -*- \n");
+    fprintf(src, " *    %s\n", m->cSrcFileName);
+    fprintf(src, " *    \"%s\" ASN.1 module encode/decode/print/free C src.\n",
+            m->modId->name);
+    fprintf(src, " *    This file was generated by esnacc on %s", ctime (&t));
+    fprintf(src, " *    NOTE: This is a machine generated file - editing not recommended\n");
+    fprintf(src, " */\n\n");
 
 } /* PrintSrcComment */
 
@@ -568,13 +569,13 @@ PrintCHdrComment PARAMS ((f, m),
 {
     time_t t;
 
-    t = time (0);
-    fprintf (f, "/*\n");
-    fprintf (f, " *    %s\n", m->cHdrFileName);
-    fprintf (f, " *    \"%s\" ASN.1 module C type definitions and"
-             " prototypes\n", m->modId->name);
-    fprintf (f, " *    This file was generated by esnacc on %s", ctime (&t));
-    fprintf (f, " *    NOTE: This is a machine generated file-"
-             "-editing not recommended\n");
-    fprintf (f, " */\n\n");
+    t = time(0);
+    fprintf(f, "/* -*- buffer-read-only: t -*-\n");
+    fprintf(f, " *    %s\n", m->cHdrFileName);
+    fprintf(f, " *    \"%s\" ASN.1 module C type definitions and"
+            " prototypes\n", m->modId->name);
+    fprintf(f, " *    This file was generated by esnacc on %s", ctime (&t));
+    fprintf(f, " *    NOTE: This is a machine generated file-"
+            "-editing not recommended\n");
+    fprintf(f, " */\n\n");
 } /* PrintCHdrComment */
diff --git a/compiler/back-ends/py-gen/gen-code.c b/compiler/back-ends/py-gen/gen-code.c
index 21ed6b4..ebc8f9e 100644
--- a/compiler/back-ends/py-gen/gen-code.c
+++ b/compiler/back-ends/py-gen/gen-code.c
@@ -126,14 +126,14 @@ PrintSrcComment PARAMS ((src, m),
 {
     time_t now = time (NULL);
 
-    fprintf (src, "# %s - class definitions for ASN.1 module %s\n",
-             m->cxxSrcFileName, m->modId->name);
-    fprintf (src, "#\n");
-    fprintf (src, "#   This file was generated by esnacc on %s\n",
-             ctime(&now));
-    fprintf (src, "#   NOTE: this is a machine generated file-"
-             "-editing not recommended\n");
-    fprintf (src, "\n");
+    fprintf(src, "# class definitions for module %s -*- buffer-read-only: t -*-\n",
+            m->modId->name);
+    fprintf(src, "#\n");
+    fprintf(src, "#   This file was generated by esnacc on %s\n",
+            ctime(&now));
+    fprintf(src, "#   NOTE: this is a machine generated file-"
+            "-editing not recommended\n");
+    fprintf(src, "\n");
 
 } /* PrintSrcComment */
 
-- 
2.9.4




More information about the dev mailing list