From 99355b76f3d7ff761dca63b53f2c43b393613a09 Mon Sep 17 00:00:00 2001
From: Anders Blomdell <anders.blomdell@control.lth.se>
Date: Fri, 22 Feb 2019 11:17:10 +0100
Subject: [PATCH] Name shortening

---
 Makefile                                  |  6 +--
 moberg.c                                  |  2 +-
 moberg_config_parser.h                    | 10 ----
 moberg_config_parser_module.h             | 56 ----------------------
 moberg_device.c                           |  4 +-
 moberg_device.h                           | 12 ++---
 moberg_module.h                           | 58 +++++++++++++++++++++++
 moberg_config_parser.c => moberg_parser.c | 32 ++++++-------
 moberg_parser.h                           | 10 ++++
 modules/comedi/Makefile                   |  2 +-
 modules/comedi/comedi.c                   | 24 +++++-----
 modules/serial2002/Makefile               |  2 +-
 modules/serial2002/serial2002.c           | 22 ++++-----
 13 files changed, 121 insertions(+), 119 deletions(-)
 delete mode 100644 moberg_config_parser.h
 delete mode 100644 moberg_config_parser_module.h
 create mode 100644 moberg_module.h
 rename moberg_config_parser.c => moberg_parser.c (92%)
 create mode 100644 moberg_parser.h

diff --git a/Makefile b/Makefile
index 1820181..0c509fa 100644
--- a/Makefile
+++ b/Makefile
@@ -42,12 +42,12 @@ test: all
 
 clean:
 	find build -type f -delete
-	rm *~
+	rm -f *~
 
 build/libmoberg.so: build/lib/moberg_config.o
 build/libmoberg.so: build/lib/moberg_device.o
-build/libmoberg.so: build/lib/moberg_config_parser.o
+build/libmoberg.so: build/lib/moberg_parser.o
 build/lib/moberg_device.o: moberg_device.h
-build/parse_config.o: moberg_config_parser.h
+build/parse_config.o: moberg_parser.h
 parse_config: build/moberg_driver.o
 parse_config: build/parse_config.o
diff --git a/moberg.c b/moberg.c
index f89e8b2..fc44eee 100644
--- a/moberg.c
+++ b/moberg.c
@@ -12,7 +12,7 @@
 #include <string.h>
 #include <moberg.h>
 #include <moberg_config.h>
-#include <moberg_config_parser.h>
+#include <moberg_parser.h>
 
 struct moberg_digital_in_t {
   int index;
diff --git a/moberg_config_parser.h b/moberg_config_parser.h
deleted file mode 100644
index cc50adc..0000000
--- a/moberg_config_parser.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#ifndef __MOBERG_CONFIG_PARSER_H__
-#define __MOBERG_CONFIG_PARSER_H__
-
-#include <moberg_config.h>
-
-struct moberg_config_parser_context;
-
-struct moberg_config *moberg_config_parse(const char *buf);
-
-#endif
diff --git a/moberg_config_parser_module.h b/moberg_config_parser_module.h
deleted file mode 100644
index e51fb6e..0000000
--- a/moberg_config_parser_module.h
+++ /dev/null
@@ -1,56 +0,0 @@
-#ifndef __MOBERG_CONFIG_PARSER_MODULE_H__
-#define __MOBERG_CONFIG_PARSER_MODULE_H__
-
-#include <stdio.h>
-#include <moberg_config_parser.h>
-
-struct moberg_config_parser_token;
-
-enum moberg_config_parser_token_kind {
-  tok_none,
-  tok_EOF,
-  tok_LPAREN,
-  tok_RPAREN,
-  tok_LBRACE,
-  tok_RBRACE,
-  tok_LBRACKET,
-  tok_RBRACKET,
-  tok_EQUAL,
-  tok_COMMA,
-  tok_COLON,
-  tok_SEMICOLON,
-  tok_INTEGER,
-  tok_IDENT,
-  tok_STRING,
-};
-
-struct moberg_config_parser_ident {
-  int length;
-  const char *value;
-};
-
-struct moberg_config_parser_token {
-  enum moberg_config_parser_token_kind kind;
-  union {
-    struct moberg_config_parser_ident ident;
-    struct moberg_config_parser_ident string;
-    struct moberg_config_parser_integer {
-      int value;
-    } integer;
-  } u;
-};
-
-int moberg_config_parser_acceptsym(
-  struct moberg_config_parser_context *c,
-  enum moberg_config_parser_token_kind kind,
-  struct moberg_config_parser_token *token);
-
-int moberg_config_parser_acceptkeyword(
-  struct moberg_config_parser_context *c,
-  const char *keyword);
-
-void moberg_config_parser_failed(
-  struct moberg_config_parser_context *c,
-  FILE *f);
-
-#endif
diff --git a/moberg_device.c b/moberg_device.c
index a7e2fae..aff00c5 100644
--- a/moberg_device.c
+++ b/moberg_device.c
@@ -56,7 +56,7 @@ void moberg_device_free(struct moberg_device *device)
 }
 
 int moberg_device_parse_config(struct moberg_device *device,
-                               struct moberg_config_parser_context *context)
+                               struct moberg_parser_context *context)
 {
   return device->driver.parse_config(device, context);
 }
@@ -73,7 +73,7 @@ int moberg_device_set_config(struct moberg_device *device,
 }
 
 int moberg_device_parse_map(struct moberg_device* device,
-                            struct moberg_config_parser_context *context,
+                            struct moberg_parser_context *context,
                             struct moberg_device_map_range range)
 {
   int result;
diff --git a/moberg_device.h b/moberg_device.h
index c379b3d..1aeb7fa 100644
--- a/moberg_device.h
+++ b/moberg_device.h
@@ -2,7 +2,7 @@
 #define __MOBERG_DEVICE_H__
 
 #include <moberg_config.h>
-#include <moberg_config_parser.h>
+#include <moberg_parser.h>
 
 struct moberg_device_map_range {
   enum moberg_device_map_kind {
@@ -51,17 +51,17 @@ struct moberg_device_encoder_in {
   int (*read)(struct moberg_device_encoder_in_context *, long *value);
 };
   
-struct moberg_config_parser_context;
+struct moberg_parser_context;
 struct moberg_device;
 struct moberg_device_config;
 
 struct moberg_device_driver {
   int (*parse_config)(
     struct moberg_device* device,
-    struct moberg_config_parser_context *context);
+    struct moberg_parser_context *context);
   int (*parse_map)(
     struct moberg_device* device,
-    struct moberg_config_parser_context *context,
+    struct moberg_parser_context *context,
     enum moberg_device_map_kind kind);
   int (*config_free)(
     struct moberg_device_config *config);
@@ -74,13 +74,13 @@ struct moberg_device *moberg_device_new(const char *driver);
 void moberg_device_free(struct moberg_device *device);
 
 int moberg_device_parse_config(struct moberg_device* device,
-                               struct moberg_config_parser_context *context);
+                               struct moberg_parser_context *context);
 
 int moberg_device_set_config(struct moberg_device* device,
                              struct moberg_device_config *config);
 
 int moberg_device_parse_map(struct moberg_device* device,
-                            struct moberg_config_parser_context *context,
+                            struct moberg_parser_context *context,
                             struct moberg_device_map_range range);
 
 int moberg_device_add_analog_in(struct moberg_device* device,
diff --git a/moberg_module.h b/moberg_module.h
new file mode 100644
index 0000000..29ce501
--- /dev/null
+++ b/moberg_module.h
@@ -0,0 +1,58 @@
+#ifndef __MOBERG_MODULE_H__
+#define __MOBERG_MODULE_H__
+
+#include <stdio.h>
+#include <moberg_parser.h>
+
+struct moberg_parser_token;
+
+enum moberg_parser_token_kind {
+  tok_none,
+  tok_EOF,
+  tok_LPAREN,
+  tok_RPAREN,
+  tok_LBRACE,
+  tok_RBRACE,
+  tok_LBRACKET,
+  tok_RBRACKET,
+  tok_EQUAL,
+  tok_COMMA,
+  tok_COLON,
+  tok_SEMICOLON,
+  tok_INTEGER,
+  tok_IDENT,
+  tok_STRING,
+};
+
+struct moberg_parser_ident {
+  int length;
+  const char *value;
+};
+
+struct moberg_parser_integer {
+  int value;
+};
+
+struct moberg_parser_token {
+  enum moberg_parser_token_kind kind;
+  union {
+    struct moberg_parser_ident ident;
+    struct moberg_parser_ident string;
+    struct moberg_parser_integer integer;
+  } u;
+};
+
+int moberg_parser_acceptsym(
+  struct moberg_parser_context *c,
+  enum moberg_parser_token_kind kind,
+  struct moberg_parser_token *token);
+
+int moberg_parser_acceptkeyword(
+  struct moberg_parser_context *c,
+  const char *keyword);
+
+void moberg_parser_failed(
+  struct moberg_parser_context *c,
+  FILE *f);
+
+#endif
diff --git a/moberg_config_parser.c b/moberg_parser.c
similarity index 92%
rename from moberg_config_parser.c
rename to moberg_parser.c
index 3ede13b..7a46d9d 100644
--- a/moberg_config_parser.c
+++ b/moberg_parser.c
@@ -5,17 +5,17 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <moberg_config_parser.h>
-#include <moberg_config_parser_module.h>
+#include <moberg_parser.h>
+#include <moberg_module.h>
 #include <moberg_device.h>
 
-typedef enum moberg_config_parser_token_kind kind_t;
-typedef struct moberg_config_parser_token token_t;
-typedef struct moberg_config_parser_ident ident_t;
+typedef enum moberg_parser_token_kind kind_t;
+typedef struct moberg_parser_token token_t;
+typedef struct moberg_parser_ident ident_t;
 
 #define MAX_EXPECTED 10
 
-typedef struct moberg_config_parser_context {
+typedef struct moberg_parser_context {
   struct moberg_config *config;
   const char *buf; /* Pointer to data to be parsed */
   const char *p;   /* current parse location */
@@ -31,13 +31,13 @@ static inline int acceptsym(context_t *c,
 			   kind_t kind,
 			   token_t *token)
 {
-  return moberg_config_parser_acceptsym(c, kind, token);
+  return moberg_parser_acceptsym(c, kind, token);
 }
   
 static inline int acceptkeyword(context_t *c,
 				const char *keyword)
 {
-  return moberg_config_parser_acceptkeyword(c, keyword);
+  return moberg_parser_acceptkeyword(c, keyword);
 }
  
 static const void nextsym_ident(context_t *c)
@@ -190,7 +190,7 @@ static int peeksym(context_t *c,
   return 0;
 }
 
-int moberg_config_parser_acceptsym(context_t *c,
+int moberg_parser_acceptsym(context_t *c,
                                    kind_t kind,
                                    token_t *token)
 {
@@ -229,7 +229,7 @@ int moberg_config_parser_acceptsym(context_t *c,
   return 0;
 }
 
-int moberg_config_parser_acceptkeyword(context_t *c,
+int moberg_parser_acceptkeyword(context_t *c,
 				       const char *keyword)
 {
   token_t t;
@@ -246,8 +246,8 @@ int moberg_config_parser_acceptkeyword(context_t *c,
   return 0;
 }
 
-void moberg_config_parser_failed(
-  struct moberg_config_parser_context *c,
+void moberg_parser_failed(
+  struct moberg_parser_context *c,
   FILE *f)
 {
   fprintf(f, "EXPECTED ");
@@ -307,7 +307,7 @@ static int parse_map_range(context_t *c,
   range->max = max.u.integer.value;
   return 1;
 syntax_err:
-  moberg_config_parser_failed(c, stderr);
+  moberg_parser_failed(c, stderr);
 err:
   return 0;
 }
@@ -329,7 +329,7 @@ static int parse_map(context_t *c,
   if (! acceptsym(c, tok_SEMICOLON, NULL)) { goto syntax_err; }
   return 1;
 syntax_err:
-  moberg_config_parser_failed(c, stderr);
+  moberg_parser_failed(c, stderr);
 err:    
   return 0;
 }
@@ -356,7 +356,7 @@ static int parse_device(context_t *c,
   }
   return 1;
 syntax_err:
-  moberg_config_parser_failed(c, stderr);
+  moberg_parser_failed(c, stderr);
 err:
   return 0;
 }
@@ -397,7 +397,7 @@ static int parse(context_t *c)
   }
   return 1;
 syntax_err:  
-  moberg_config_parser_failed(c, stderr);
+  moberg_parser_failed(c, stderr);
   goto err;
 err:
   return 0;
diff --git a/moberg_parser.h b/moberg_parser.h
new file mode 100644
index 0000000..1d8148c
--- /dev/null
+++ b/moberg_parser.h
@@ -0,0 +1,10 @@
+#ifndef __MOBERG_PARSER_H__
+#define __MOBERG_PARSER_H__
+
+#include <moberg_config.h>
+
+struct moberg_parser_context;
+
+struct moberg_config *moberg_config_parse(const char *buf);
+
+#endif
diff --git a/modules/comedi/Makefile b/modules/comedi/Makefile
index 4923fc6..ca1e0e2 100644
--- a/modules/comedi/Makefile
+++ b/modules/comedi/Makefile
@@ -8,4 +8,4 @@ all:	$(LIBRARIES:%=../../build/%)
 ../../build/libmoberg_comedi.so: comedi.c Makefile
 	$(CC) -o $@ $(CCFLAGS) -shared -fPIC $<
 
-../../build/libmoberg_comedi.so: ../../moberg_config_parser_module.h
+../../build/libmoberg_comedi.so: ../../moberg_module.h
diff --git a/modules/comedi/comedi.c b/modules/comedi/comedi.c
index 457c2a7..ccf738c 100644
--- a/modules/comedi/comedi.c
+++ b/modules/comedi/comedi.c
@@ -1,15 +1,15 @@
 #include <moberg_config.h>
-#include <moberg_config_parser.h>
-#include <moberg_config_parser_module.h>
+#include <moberg_parser.h>
+#include <moberg_module.h>
 #include <moberg_device.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-typedef enum moberg_config_parser_token_kind kind_t;
-typedef struct moberg_config_parser_token token_t;
-typedef struct moberg_config_parser_ident ident_t;
-typedef struct moberg_config_parser_context context_t;
+typedef enum moberg_parser_token_kind kind_t;
+typedef struct moberg_parser_token token_t;
+typedef struct moberg_parser_ident ident_t;
+typedef struct moberg_parser_context context_t;
 
 struct moberg_device_map {};
 struct moberg_device_config {
@@ -20,18 +20,18 @@ static inline int acceptsym(context_t *c,
 			   kind_t kind,
 			   token_t *token)
 {
-  return moberg_config_parser_acceptsym(c, kind, token);
+  return moberg_parser_acceptsym(c, kind, token);
 }
   
 static inline int acceptkeyword(context_t *c,
 				const char *keyword)
 {
-  return moberg_config_parser_acceptkeyword(c, keyword);
+  return moberg_parser_acceptkeyword(c, keyword);
 }
   
 static int parse_config(
   struct moberg_device *device,
-  struct moberg_config_parser_context *c)
+  struct moberg_parser_context *c)
 {
   struct moberg_device_config *config = malloc(sizeof *config);
   if (! config) {
@@ -81,7 +81,7 @@ static int parse_config(
   moberg_device_set_config(device, config);
   return 1;
 syntax_err:
-  moberg_config_parser_failed(c, stderr);
+  moberg_parser_failed(c, stderr);
   free(config);
 err:
   return 0;
@@ -89,7 +89,7 @@ err:
 
 static int parse_map(
   struct moberg_device *device,
-  struct moberg_config_parser_context *c,
+  struct moberg_parser_context *c,
   enum moberg_device_map_kind kind)
 {
   token_t min, max;
@@ -138,7 +138,7 @@ static int parse_map(
   if (! acceptsym(c, tok_RBRACE, NULL)) { goto err; }
   return 1;
 err:
-  moberg_config_parser_failed(c, stderr);
+  moberg_parser_failed(c, stderr);
   return 0;
 }
 
diff --git a/modules/serial2002/Makefile b/modules/serial2002/Makefile
index 9f66f2d..e6b34fb 100644
--- a/modules/serial2002/Makefile
+++ b/modules/serial2002/Makefile
@@ -8,4 +8,4 @@ all:	$(LIBRARIES:%=../../build/%)
 ../../build/libmoberg_serial2002.so: serial2002.c Makefile
 	$(CC) -o $@ $(CCFLAGS) -shared -fPIC $<
 
-../../build/libmoberg_serial2002.so: ../../moberg_config_parser_module.h
+../../build/libmoberg_serial2002.so: ../../moberg_module.h
diff --git a/modules/serial2002/serial2002.c b/modules/serial2002/serial2002.c
index b1e2a8c..f89a5b8 100644
--- a/modules/serial2002/serial2002.c
+++ b/modules/serial2002/serial2002.c
@@ -1,26 +1,26 @@
 #include <moberg_config.h>
-#include <moberg_config_parser.h>
-#include <moberg_config_parser_module.h>
+#include <moberg_parser.h>
+#include <moberg_module.h>
 #include <moberg_device.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-typedef enum moberg_config_parser_token_kind kind_t;
-typedef struct moberg_config_parser_token token_t;
-typedef struct moberg_config_parser_context context_t;
+typedef enum moberg_parser_token_kind kind_t;
+typedef struct moberg_parser_token token_t;
+typedef struct moberg_parser_context context_t;
 
 static inline int acceptsym(context_t *c,
                             kind_t kind,
                             token_t *token)
 {
-  return moberg_config_parser_acceptsym(c, kind, token);
+  return moberg_parser_acceptsym(c, kind, token);
 }
   
 static inline int acceptkeyword(context_t *c,
 				const char *keyword)
 {
-  return moberg_config_parser_acceptkeyword(c, keyword);
+  return moberg_parser_acceptkeyword(c, keyword);
 }
   
 struct moberg_device_config {
@@ -30,7 +30,7 @@ struct moberg_device_config {
 
 static int parse_config(
   struct moberg_device *device,
-  struct moberg_config_parser_context *c)
+  struct moberg_parser_context *c)
 {
   struct moberg_device_config *config = malloc(sizeof *config);
   if (! config) {
@@ -60,7 +60,7 @@ static int parse_config(
   moberg_device_set_config(device, config);
   return 1;
 syntax_err:
-  moberg_config_parser_failed(c, stderr);
+  moberg_parser_failed(c, stderr);
   free(config);
 err:
   return 0;
@@ -68,7 +68,7 @@ err:
 
 static int parse_map(
   struct moberg_device *device,
-  struct moberg_config_parser_context *c,
+  struct moberg_parser_context *c,
   enum moberg_device_map_kind ignore)
 {
   enum moberg_device_map_kind kind;
@@ -109,7 +109,7 @@ static int parse_map(
   }
   return 1;
 syntax_err:
-  moberg_config_parser_failed(c, stderr);
+  moberg_parser_failed(c, stderr);
   return 0;
 }
 
-- 
GitLab