poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix issues reported by `make syntax-check`


From: Mohammad-Reza Nabipoor
Subject: [PATCH] Fix issues reported by `make syntax-check`
Date: Mon, 19 Oct 2020 23:46:27 +0330

2020-10-19  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>

        * testsuite/poke.mi-json/pk_int.json: Add new line at the end.
        * testsuite/poke.mi-json/pk_uint.json: Likewise.
        * testsuite/poke.mi-json/pk_offset.json: Likewise.
        * testsuite/poke.mi-json/pk_string.json: Likewise.
        * testsuite/poke.mi-json/pk_array.json: Add new line at the end and
        trim trailing whitespaces.
        * testsuite/poke.mi-json/pk_sct.json: Likewise.
        * poke/pk-cmd-ios.c: Expand TAB to 8 spaces.
        * libpoke/ios-buffer.h: Likewise.
        * libpoke/ios-buffer.c: Likewise.
        * libpoke/ios.c: Put space after function name.
        * libpoke/ios-dev-stream.c: Expand TAB to 8 spaces. Put space after
        function names. Use STREQ. Remove `if` before `free`. Remove inclusion
        of assert.h.
        * libpoke/ios-buffer.h: Reformat function prototypes according to the
        GNU Coding Standards.
---
 ChangeLog                             | 19 +++++++
 libpoke/ios-buffer.c                  | 74 +++++++++++++--------------
 libpoke/ios-buffer.h                  | 31 +++++------
 libpoke/ios-dev-stream.c              | 58 ++++++++++-----------
 libpoke/ios.c                         |  2 +-
 poke/pk-cmd-ios.c                     |  2 +-
 testsuite/poke.mi-json/pk_array.json  |  6 +--
 testsuite/poke.mi-json/pk_int.json    |  2 +-
 testsuite/poke.mi-json/pk_offset.json |  2 +-
 testsuite/poke.mi-json/pk_sct.json    | 20 ++++----
 testsuite/poke.mi-json/pk_string.json |  2 +-
 testsuite/poke.mi-json/pk_uint.json   |  2 +-
 12 files changed, 116 insertions(+), 104 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e481d90b..04e0c5ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2020-10-19  Mohammad-Reza Nabipoor  <m.nabipoor@yahoo.com>
+
+       * testsuite/poke.mi-json/pk_int.json: Add new line at the end.
+       * testsuite/poke.mi-json/pk_uint.json: Likewise.
+       * testsuite/poke.mi-json/pk_offset.json: Likewise.
+       * testsuite/poke.mi-json/pk_string.json: Likewise.
+       * testsuite/poke.mi-json/pk_array.json: Add new line at the end and
+       trim trailing whitespaces.
+       * testsuite/poke.mi-json/pk_sct.json: Likewise.
+       * poke/pk-cmd-ios.c: Expand TAB to 8 spaces.
+       * libpoke/ios-buffer.h: Likewise.
+       * libpoke/ios-buffer.c: Likewise.
+       * libpoke/ios.c: Put space after function name.
+       * libpoke/ios-dev-stream.c: Expand TAB to 8 spaces. Put space after
+       function names. Use STREQ. Remove `if` before `free`. Remove inclusion
+       of assert.h.
+       * libpoke/ios-buffer.h: Reformat function prototypes according to the
+       GNU Coding Standards.
+
 2020-10-12  Egeyar Bagcioglu  <egeyar@gmail.com>
 
        * libpoke/Makefile.am (libpoke_la_SOURCES): Add ios-buffer.h,
diff --git a/libpoke/ios-buffer.c b/libpoke/ios-buffer.c
index f3e1ad63..4a4cf19b 100644
--- a/libpoke/ios-buffer.c
+++ b/libpoke/ios-buffer.c
@@ -24,16 +24,16 @@
 #include "ios.h"
 #include "ios-dev.h"
 
-#define IOB_CHUNK_SIZE         2048
-#define IOB_BUCKET_COUNT       8
+#define IOB_CHUNK_SIZE          2048
+#define IOB_BUCKET_COUNT        8
 
-#define IOB_CHUNK_OFFSET(offset)       \
+#define IOB_CHUNK_OFFSET(offset)        \
   ((offset) % IOB_CHUNK_SIZE)
 
-#define IOB_CHUNK_NO(offset)           \
+#define IOB_CHUNK_NO(offset)            \
   ((offset) / IOB_CHUNK_SIZE)
 
-#define IOB_BUCKET_NO(chunk_no)                \
+#define IOB_BUCKET_NO(chunk_no)         \
   ((chunk_no) % IOB_BUCKET_COUNT)
 
 struct ios_buffer_chunk
@@ -80,11 +80,11 @@ ios_buffer_free (struct ios_buffer *buffer)
     {
       chunk = buffer->chunks[i];
       while (chunk)
-       {
-         chunk_next = chunk->next;
-         free (chunk);
-         chunk = chunk_next;
-       }
+        {
+          chunk_next = chunk->next;
+          free (chunk);
+          chunk = chunk_next;
+        }
     }
 
   free (buffer);
@@ -106,7 +106,7 @@ ios_buffer_get_chunk (struct ios_buffer *buffer, int 
chunk_no)
 
 int
 ios_buffer_allocate_new_chunk (struct ios_buffer *buffer, int final_chunk_no,
-                              struct ios_buffer_chunk **final_chunk)
+                               struct ios_buffer_chunk **final_chunk)
 {
   struct ios_buffer_chunk *chunk;
   int bucket_no;
@@ -117,7 +117,7 @@ ios_buffer_allocate_new_chunk (struct ios_buffer *buffer, 
int final_chunk_no,
     {
       chunk = calloc (1, sizeof (struct ios_buffer_chunk));
       if (!chunk)
-       return IOD_ERROR;
+        return IOD_ERROR;
       /* Place the new chunk into the buffer.  */
       chunk->chunk_no = buffer->next_chunk_no;
       bucket_no = IOB_BUCKET_NO (chunk->chunk_no);
@@ -139,13 +139,13 @@ ios_buffer_allocate_new_chunk (struct ios_buffer *buffer, 
int final_chunk_no,
 
 int
 ios_buffer_pread (struct ios_buffer *buffer, void *buf, size_t count,
-                 ios_dev_off offset)
+                  ios_dev_off offset)
 {
   int chunk_no;
   struct ios_buffer_chunk *chunk;
   ios_dev_off chunk_offset;
   size_t already_read_count = 0,
-        to_be_read_count = 0;
+         to_be_read_count = 0;
 
   chunk_no = IOB_CHUNK_NO (offset);
   chunk_offset = IOB_CHUNK_OFFSET (offset);
@@ -156,20 +156,20 @@ ios_buffer_pread (struct ios_buffer *buffer, void *buf, 
size_t count,
   /* The amount we read from this chunk is the maximum of
      the COUNT requested and the size of the rest of this chunk. */
   to_be_read_count = IOB_CHUNK_SIZE - chunk_offset > count
-                    ? count
-                    : IOB_CHUNK_SIZE - chunk_offset;
+                     ? count
+                     : IOB_CHUNK_SIZE - chunk_offset;
 
   memcpy (buf, (void *) chunk + chunk_offset, to_be_read_count);
 
   while ((already_read_count += to_be_read_count) < count)
     {
       to_be_read_count = count - already_read_count > IOB_CHUNK_SIZE
-                        ? IOB_CHUNK_SIZE
-                        : count - already_read_count;
+                         ? IOB_CHUNK_SIZE
+                         : count - already_read_count;
 
       chunk = ios_buffer_get_chunk (buffer, ++chunk_no);
       if (!chunk && ios_buffer_allocate_new_chunk (buffer, chunk_no, &chunk))
-       return IOD_ERROR;
+        return IOD_ERROR;
       memcpy (buf + already_read_count, chunk, to_be_read_count);
     };
 
@@ -182,13 +182,13 @@ ios_buffer_pread (struct ios_buffer *buffer, void *buf, 
size_t count,
 
 int
 ios_buffer_pwrite (struct ios_buffer *buffer, const void *buf, size_t count,
-                  ios_dev_off offset)
+                   ios_dev_off offset)
 {
   int chunk_no;
   struct ios_buffer_chunk *chunk;
   ios_dev_off chunk_offset;
   size_t already_written_count = 0,
-        to_be_written_count = 0;
+         to_be_written_count = 0;
 
   chunk_no = IOB_CHUNK_NO (offset);
   chunk_offset = IOB_CHUNK_OFFSET (offset);
@@ -199,20 +199,20 @@ ios_buffer_pwrite (struct ios_buffer *buffer, const void 
*buf, size_t count,
   /* The amount we write to this chunk is the maximum of the COUNT requested
      and the size of the rest of this chunk. */
   to_be_written_count = IOB_CHUNK_SIZE - chunk_offset > count
-                       ? count
-                       : IOB_CHUNK_SIZE - chunk_offset;
+                        ? count
+                        : IOB_CHUNK_SIZE - chunk_offset;
 
   memcpy ((void *) chunk + chunk_offset, buf, to_be_written_count);
 
   while ((already_written_count += to_be_written_count) < count)
     {
       to_be_written_count = count - already_written_count > IOB_CHUNK_SIZE
-                           ? IOB_CHUNK_SIZE
-                           : count - already_written_count;
+                            ? IOB_CHUNK_SIZE
+                            : count - already_written_count;
 
       chunk = ios_buffer_get_chunk (buffer, ++chunk_no);
       if (!chunk && ios_buffer_allocate_new_chunk (buffer, chunk_no, &chunk))
-       return IOD_ERROR;
+        return IOD_ERROR;
       memcpy (chunk, buf + already_written_count, to_be_written_count);
     };
 
@@ -235,17 +235,17 @@ ios_buffer_forget_till (struct ios_buffer *buffer, 
ios_dev_off offset)
       chunk = buffer->chunks[i];
       buffer->chunks[i] = NULL;
       while (chunk)
-       {
-         chunk_next = chunk->next;
-         if (chunk->chunk_no >= chunk_no)
-           {
-             chunk->next = buffer->chunks[i];
-             buffer->chunks[i] = chunk;
-           }
-         else
-           free (chunk);
-         chunk = chunk_next;
-       }
+        {
+          chunk_next = chunk->next;
+          if (chunk->chunk_no >= chunk_no)
+            {
+              chunk->next = buffer->chunks[i];
+              buffer->chunks[i] = chunk;
+            }
+          else
+            free (chunk);
+          chunk = chunk_next;
+        }
     }
 
   buffer->begin_offset = chunk_no * IOB_CHUNK_SIZE;
diff --git a/libpoke/ios-buffer.h b/libpoke/ios-buffer.h
index 838999d6..e04d29fe 100644
--- a/libpoke/ios-buffer.h
+++ b/libpoke/ios-buffer.h
@@ -18,30 +18,25 @@
 
 struct ios_buffer;
 
-struct ios_buffer * ios_buffer_init ();
+struct ios_buffer *ios_buffer_init ();
 
 int ios_buffer_free (struct ios_buffer *buffer);
 
-ios_dev_off
-ios_buffer_get_begin_offset (struct ios_buffer *buffer);
+ios_dev_off ios_buffer_get_begin_offset (struct ios_buffer *buffer);
 
-ios_dev_off
-ios_buffer_get_end_offset (struct ios_buffer *buffer);
+ios_dev_off ios_buffer_get_end_offset (struct ios_buffer *buffer);
 
-struct ios_buffer_chunk*
-ios_buffer_get_chunk (struct ios_buffer *buffer, int chunk_no);
+struct ios_buffer_chunk *ios_buffer_get_chunk (struct ios_buffer *buffer,
+                                               int chunk_no);
 
-int
-ios_buffer_allocate_new_chunk (struct ios_buffer *buffer, int final_chunk_no,
-                              struct ios_buffer_chunk **final_chunk);
+int ios_buffer_allocate_new_chunk (struct ios_buffer *buffer,
+                                   int final_chunk_no,
+                                   struct ios_buffer_chunk **final_chunk);
 
-int
-ios_buffer_pread (struct ios_buffer *buffer, void *buf, size_t count,
-                 ios_dev_off offset);
+int ios_buffer_pread (struct ios_buffer *buffer, void *buf, size_t count,
+                      ios_dev_off offset);
 
-int
-ios_buffer_pwrite (struct ios_buffer *buffer, const void *buf, size_t count,
-                  ios_dev_off offset);
+int ios_buffer_pwrite (struct ios_buffer *buffer, const void *buf,
+                       size_t count, ios_dev_off offset);
 
-int
-ios_buffer_forget_till (struct ios_buffer *buffer, ios_dev_off offset);
+int ios_buffer_forget_till (struct ios_buffer *buffer, ios_dev_off offset);
diff --git a/libpoke/ios-dev-stream.c b/libpoke/ios-dev-stream.c
index 1258bfe5..50b46479 100644
--- a/libpoke/ios-dev-stream.c
+++ b/libpoke/ios-dev-stream.c
@@ -23,15 +23,14 @@
 #include <stdio.h>
 #include <malloc.h>
 #include <string.h>
-#include <assert.h>
 
 #include "ios.h"
 #include "ios-dev.h"
 #include "ios-buffer.h"
 
-#define IOS_STDIN_HANDLER      ("<stdin>")
-#define IOS_STDOUT_HANDLER     ("<stdout>")
-#define IOS_STDERR_HANDLER     ("<stderr>")
+#define IOS_STDIN_HANDLER       ("<stdin>")
+#define IOS_STDOUT_HANDLER      ("<stdout>")
+#define IOS_STDERR_HANDLER      ("<stderr>")
 
 /* State associated with a stream device.  */
 
@@ -56,9 +55,9 @@ static char *
 ios_dev_stream_handler_normalize (const char *handler, uint64_t flags)
 {
   /* TODO handle the case where strdup fails. */
-  if (!strcmp (handler, IOS_STDIN_HANDLER)
-      || !strcmp (handler, IOS_STDOUT_HANDLER)
-      || !strcmp (handler, IOS_STDERR_HANDLER))
+  if (STREQ (handler, IOS_STDIN_HANDLER)
+      || STREQ (handler, IOS_STDOUT_HANDLER)
+      || STREQ (handler, IOS_STDERR_HANDLER))
     return strdup (handler);
   else
     return NULL;
@@ -77,21 +76,21 @@ ios_dev_stream_open (const char *handler, uint64_t flags, 
int *error)
   if (!sio->handler)
     goto error;
 
-  if (!strcmp (handler, IOS_STDIN_HANDLER))
+  if (STREQ (handler, IOS_STDIN_HANDLER))
     {
       sio->file = stdin;
       sio->flags = IOS_F_READ;
       sio->buffer = ios_buffer_init ();
       if (!sio->buffer)
-       goto error;
+        goto error;
     }
-  else if (!strcmp (handler, IOS_STDOUT_HANDLER))
+  else if (STREQ (handler, IOS_STDOUT_HANDLER))
     {
       sio->file = stdout;
       sio->flags = IOS_F_WRITE;
       sio->write_offset = 0;
     }
-  else if (!strcmp (handler, IOS_STDERR_HANDLER))
+  else if (STREQ (handler, IOS_STDERR_HANDLER))
     {
       sio->file = stderr;
       sio->flags = IOS_F_WRITE;
@@ -105,8 +104,7 @@ ios_dev_stream_open (const char *handler, uint64_t flags, 
int *error)
 error:
   if (sio)
     {
-      if (sio->handler)
-       free (sio->handler);
+      free (sio->handler);
       free (sio);
     }
   *error = IOD_ERROR;
@@ -142,37 +140,37 @@ ios_dev_stream_pread (void *iod, void *buf, size_t count, 
ios_dev_off offset)
     return IOD_ERROR;
 
   /* If the beginning of the buffer is discarded, return EOF. */
-  if (ios_buffer_get_begin_offset(buffer) > offset)
+  if (ios_buffer_get_begin_offset (buffer) > offset)
     return IOD_EOF;
 
   /* If the requsted range is in the buffer, return it. */
-  if (ios_buffer_get_end_offset(buffer) >= offset + count)
+  if (ios_buffer_get_end_offset (buffer) >= offset + count)
     return ios_buffer_pread (buffer, buf, count, offset);
 
   /* What was last read into the buffer may be before or after the
      offset that this function is provided with.  */
-  if (ios_buffer_get_end_offset(buffer) == offset)
+  if (ios_buffer_get_end_offset (buffer) == offset)
     {
       do
-       {
-         read_count = fread (buf + total_read_count, count, 1, sio->file);
-         total_read_count += read_count;
-       }
+        {
+          read_count = fread (buf + total_read_count, count, 1, sio->file);
+          total_read_count += read_count;
+        }
       while (total_read_count < count && read_count);
 
       if (ios_buffer_pwrite (buffer, buf, total_read_count, offset)
-         || total_read_count < count)
-       return IOD_ERROR;
+          || total_read_count < count)
+        return IOD_ERROR;
 
       return IOS_OK;
     }
   else
     {
-      size_t to_be_read = (offset + count) - ios_buffer_get_end_offset(buffer);
+      size_t to_be_read = (offset + count) - ios_buffer_get_end_offset 
(buffer);
       void *temp = malloc (to_be_read);
       fread (temp, to_be_read, 1, sio->file);
-      if (ios_buffer_pwrite (buffer, temp, to_be_read, 
ios_buffer_get_end_offset(buffer)))
-       return IOD_ERROR;
+      if (ios_buffer_pwrite (buffer, temp, to_be_read, 
ios_buffer_get_end_offset (buffer)))
+        return IOD_ERROR;
       free (temp);
       return ios_buffer_pread (buffer, buf, count, offset);
     }
@@ -180,7 +178,7 @@ ios_dev_stream_pread (void *iod, void *buf, size_t count, 
ios_dev_off offset)
 
 static int
 ios_dev_stream_pwrite (void *iod, const void *buf, size_t count,
-                      ios_dev_off offset)
+                       ios_dev_off offset)
 {
   struct ios_dev_stream *sio = iod;
 
@@ -195,7 +193,7 @@ ios_dev_stream_pwrite (void *iod, const void *buf, size_t 
count,
   if (offset > sio->write_offset)
     /* TODO: Write this more efficiently. */
     for (int i=0; i < (offset - sio->write_offset); i++)
-      fputc (0,         sio->file);
+      fputc (0,  sio->file);
 
   fwrite (buf, count, 1, sio->file);
   sio->write_offset = offset + count;
@@ -208,7 +206,7 @@ ios_dev_stream_size (void *iod)
 {
   struct ios_dev_stream *sio = iod;
   if (sio->flags & IOS_F_READ)
-    return ios_buffer_get_end_offset(sio->buffer);
+    return ios_buffer_get_end_offset (sio->buffer);
   else
     return sio->write_offset;
 }
@@ -218,8 +216,8 @@ ios_dev_stream_flush (void *iod, ios_dev_off offset)
 {
   struct ios_dev_stream *sio = iod;
   if (sio->flags & IOS_F_READ
-      && offset > ios_buffer_get_begin_offset(sio->buffer)
-      && offset <= ios_buffer_get_end_offset(sio->buffer))
+      && offset > ios_buffer_get_begin_offset (sio->buffer)
+      && offset <= ios_buffer_get_end_offset (sio->buffer))
     return ios_buffer_forget_till (sio->buffer, offset);
   else
     return IOS_OK;
diff --git a/libpoke/ios.c b/libpoke/ios.c
index 0d6cff0d..b77acf20 100644
--- a/libpoke/ios.c
+++ b/libpoke/ios.c
@@ -263,7 +263,7 @@ ios_get_id (ios io)
 char *
 ios_get_dev_if_name (ios io)
 {
-  return io->dev_if->get_if_name();
+  return io->dev_if->get_if_name ();
 }
 
 ios_off
diff --git a/poke/pk-cmd-ios.c b/poke/pk-cmd-ios.c
index a375e8f5..0e706fc2 100644
--- a/poke/pk-cmd-ios.c
+++ b/poke/pk-cmd-ios.c
@@ -154,7 +154,7 @@ print_info_ios (pk_ios io, void *data)
   pk_printf ("%s#%d\t%s\t%s\t",
              io == pk_ios_cur (poke_compiler) ? "* " : "  ",
              pk_ios_get_id (io),
-            pk_ios_get_dev_if_name (io),
+             pk_ios_get_dev_if_name (io),
              mode);
 
 #if HAVE_HSERVER
diff --git a/testsuite/poke.mi-json/pk_array.json 
b/testsuite/poke.mi-json/pk_array.json
index 3ed5d833..1a42c5be 100644
--- a/testsuite/poke.mi-json/pk_array.json
+++ b/testsuite/poke.mi-json/pk_array.json
@@ -1,7 +1,7 @@
 ##
 [1L, 2L, 3L, 15L, 25L, -35L, 64L, 9223372036854775807L] as int<64>[]
 ##
-{ 
+{
     "PokeValue" : {
         "type" : "Array",
         "elements" : [
@@ -104,6 +104,6 @@
         ],
         "mapping" : {
             "type" : "Null", "value" : null
-        } 
+        }
     }
-}
\ No newline at end of file
+}
diff --git a/testsuite/poke.mi-json/pk_int.json 
b/testsuite/poke.mi-json/pk_int.json
index 0b9bff0c..1937dd6a 100644
--- a/testsuite/poke.mi-json/pk_int.json
+++ b/testsuite/poke.mi-json/pk_int.json
@@ -7,4 +7,4 @@
         "value" : -3500,
         "size" : 32
     }
-}
\ No newline at end of file
+}
diff --git a/testsuite/poke.mi-json/pk_offset.json 
b/testsuite/poke.mi-json/pk_offset.json
index 2c9e3c5a..855f53c4 100644
--- a/testsuite/poke.mi-json/pk_offset.json
+++ b/testsuite/poke.mi-json/pk_offset.json
@@ -15,4 +15,4 @@
             "size" : 64
         }
     }
-}
\ No newline at end of file
+}
diff --git a/testsuite/poke.mi-json/pk_sct.json 
b/testsuite/poke.mi-json/pk_sct.json
index 9a928f52..0f27cbf1 100644
--- a/testsuite/poke.mi-json/pk_sct.json
+++ b/testsuite/poke.mi-json/pk_sct.json
@@ -2,11 +2,11 @@ deftype Packet = struct { int i; long j; };
 ##
 Packet { i = 1, j = 2}
 ##
-{ 
-    "PokeValue" : { 
+{
+    "PokeValue" : {
         "type" : "Struct",
         "name" : {
-            "type" : "String", 
+            "type" : "String",
             "value" : "Packet"
         },
         "fields" : [
@@ -15,10 +15,10 @@ Packet { i = 1, j = 2}
                     "type" : "String",
                     "value" : "i"
                 },
-                "value" : { 
+                "value" : {
                     "type" : "Integer",
                     "value" : 1,
-                    "size" : 32 
+                    "size" : 32
                 },
                 "boffset" : {
                     "type" : "UnsignedInteger",
@@ -28,7 +28,7 @@ Packet { i = 1, j = 2}
             },
             {
                 "name" : {
-                    "type" : "String", 
+                    "type" : "String",
                     "value" : "j"
                 },
                 "value" : {
@@ -43,9 +43,9 @@ Packet { i = 1, j = 2}
                 }
             }
         ],
-        "mapping" : { 
+        "mapping" : {
             "type" : "Null",
-            "value" : null 
+            "value" : null
         }
-    } 
-}
\ No newline at end of file
+    }
+}
diff --git a/testsuite/poke.mi-json/pk_string.json 
b/testsuite/poke.mi-json/pk_string.json
index 045eb1b3..b80b089b 100644
--- a/testsuite/poke.mi-json/pk_string.json
+++ b/testsuite/poke.mi-json/pk_string.json
@@ -6,4 +6,4 @@
         "type" : "String",
         "value" : "foo"
     }
-}
\ No newline at end of file
+}
diff --git a/testsuite/poke.mi-json/pk_uint.json 
b/testsuite/poke.mi-json/pk_uint.json
index 2cd83dcf..43eb168f 100644
--- a/testsuite/poke.mi-json/pk_uint.json
+++ b/testsuite/poke.mi-json/pk_uint.json
@@ -7,4 +7,4 @@
         "value" : 3500,
         "size" : 32
     }
-}
\ No newline at end of file
+}
-- 
2.28.0



reply via email to

[Prev in Thread] Current Thread [Next in Thread]