Commits

Tony Cesaro committed 4bbf9d8

Correcting spacing to better conform to C style guidelines

Comments (0)

Files changed (1)

 #include <string.h>
 #include <pcre.h>
 
+//BEGIN CPP
+
 #define CHUNK 1024
 
-void
-readPrint (FILE *inputFile, char *readBuffer)
+//END CPP
+
+// BEGIN Function prototypes
+
+int regexMatch (char *line, const char *regexPattern)
+
+// END Function prototypes
+
+// BEGIN Functions
+
+void readPrint (FILE *inputFile, char *readBuffer)
 {
-    if (inputFile)
+  if (inputFile)
+  {
+    unsigned long curOffset = ftell(inputFile);
+    size_t nread;
+
+    while (1)
     {
-        unsigned long curOffset = ftell(inputFile);
-        size_t nread;
-
-        while (1)
-        {
-            while ((nread = fread(readBuffer, 1, CHUNK, inputFile)) > 0)
-            {
-                fwrite(readBuffer, 1, nread, stdout);
-                curOffset = ftell(inputFile);
-                int regexMatches = regexMatch(readBuffer,"*");
-                printf("Matches = %d", regexMatches);
-            }
-            sleep(1);
-        }
-        fclose(inputFile);
+      while ((nread = fread(readBuffer, 1, CHUNK, inputFile)) > 0)
+      {
+        fwrite(readBuffer, 1, nread, stdout);
+        curOffset = ftell(inputFile);
+        int regexMatches = regexMatch(readBuffer,"*");
+        printf("Matches = %d", regexMatches);
+      }
+      sleep(1);
     }
+    fclose(inputFile);
+  }
 }
 
-int
-regexMatch (char *line, const char *regexPattern)
+int regexMatch (char *line, const char *regexPattern)
 {
-    const char *error;
-    int errorOffset;
-    pcre *reCompiled;
-
-    reCompiled = pcre_compile(
-                    regexPattern,
-                    0,
-                    &error,
-                    &errorOffset,
-                    NULL);
-
-    if (reCompiled == NULL)
-    {
-        printf("pcre_compile failed (offset: %d), %s\n", errorOffset, error);
-        return -1;
-    }
+  const char *error;
+  int errorOffset;
+  pcre *reCompiled;
+
+  reCompiled = pcre_compile(
+          regexPattern,
+          0,
+          &error,
+          &errorOffset,
+          NULL);
+
+  if (reCompiled == NULL)
+  {
+    printf("pcre_compile failed (offset: %d), %s\n", errorOffset, error);
+    return -1;
+  }
+
+  unsigned int lineLength = (int)strlen(line);
+  int ovector[1];
+  int regexMatchResult = pcre_exec(
+              reCompiled,
+              NULL,
+              line,
+              lineLength,
+              0,
+              0,
+              ovector,
+              1);
+  
+  if (regexMatchResult == NULL)
+  {
+    printf("pcre_exec failed");
+    return -1;
+  }
+  else
+  {
+    return regexMatchResult;
+  }
 
-    unsigned int lineLength = (int)strlen(line);
-    int ovector[1];
-    int regexMatchResult = pcre_exec(
-                        reCompiled,
-                        NULL,
-                        line,
-                        lineLength,
-                        0,
-                        0,
-                        ovector,
-                        1);
-    
-    if (regexMatchResult == NULL)
-    {
-        printf("pcre_exec failed");
-        return -1;
-    }
-    else
-    {
-        return regexMatchResult;
-    }
-                        
 }
 
-int
-main (int argc, char *argv[])
-{   
-
-    char *filename = NULL;
-    char *pattern = NULL;
-    char *readBuffer = malloc(CHUNK);
-    FILE *ifp;
+// END functions
 
-    if (argc - 1 < 1) 
-    {
-        fprintf(stderr, "Usage: %s <filename> <pattern>\n", argv[0]);
-        return 1;
-    } 
+// BEGIN main
+int main (int argc, char *argv[])
+{   
 
+  char *filename = NULL;
+  char *pattern = NULL;
+  char *readBuffer = malloc(CHUNK);
+  FILE *ifp;
 
-    if (argc - 1 >= 1) 
-    {
-        while (--argc > 0)
-        {
-            filename = argv[1];
-            pattern = argv[2];
-        }
-        ifp = fopen(filename, "r");
-    }
-    else
-    {
-        filename = "stdin";
-        ifp = stdin;
-    }
+  if (argc - 1 < 1) 
+  {
+    fprintf(stderr, "Usage: %s <filename> <pattern>\n", argv[0]);
+    return 1;
+  } 
 
-    if (ifp == NULL)
-    {
-        fprintf(stderr, "File open error.\n");
-        exit(1);
-    }
 
-    if (readBuffer == NULL)
+  if (argc - 1 >= 1) 
+  {
+    while (--argc > 0)
     {
-        fprintf(stderr, "Could not allocate read buffer.\n");
-        exit(1);
+      filename = argv[1];
+      pattern = argv[2];
     }
-
-    printf ("File being concatenated: %s\n", filename);
-    printf ("Pattern used for filter: %s\n\n", pattern);
-    readPrint (ifp, readBuffer);
-
-    free (readBuffer);
-    
-    return 0;
+    ifp = fopen(filename, "r");
+  }
+  else
+  {
+    filename = "stdin";
+    ifp = stdin;
+  }
+
+  if (ifp == NULL)
+  {
+    fprintf(stderr, "File open error.\n");
+    exit(1);
+  }
+
+  if (readBuffer == NULL)
+  {
+    fprintf(stderr, "Could not allocate read buffer.\n");
+    exit(1);
+  }
+
+  printf ("File being concatenated: %s\n", filename);
+  printf ("Pattern used for filter: %s\n\n", pattern);
+  readPrint (ifp, readBuffer);
+
+  free (readBuffer);
+  
+  return 0;
 }
+// END main