Merge branch 'master' of pitec:the_march
authorjordan@hack_attack <jordanlavatai@gmail.com>
Sun, 9 Oct 2016 03:47:25 +0000 (20:47 -0700)
committerjordan@hack_attack <jordanlavatai@gmail.com>
Sun, 9 Oct 2016 03:47:25 +0000 (20:47 -0700)
src/Makefile
src/apc/lexer.c
src/apc/scanner.c
src/bin/tools/apc.c
src/bin/tools/ockpromo-fcgi.c [deleted file]
src/bin/tools/ockpromo-fcgi.ld [deleted file]
src/bin/tools/testapc.c [new file with mode: 0644]
src/ock/curl_sendmail.c [deleted file]
src/ock/db_store.c [deleted file]
src/ock/ock.h [deleted file]

index b4c8225..06466c6 100644 (file)
@@ -474,7 +474,7 @@ $(eval
 $1_OBJ     := $($($1_C)_OBJ)
 $1_OUT     := $($($1_C)_OUT)
 $1_AROBJ   := $($($1_C)_AROBJ)
-$1_SOURCES := $(subst ./,,$(shell find -name "*.$1"))
+$1_SOURCES := $(subst ./,,$(shell find -name "*.$1" -not -name ".*"))
 $1_DBG     := $($($1_C)_DBG)
 $1_AR      := $($($1_C)_AR)
 )
index 6ef1b4c..1abe5b5 100644 (file)
@@ -30,6 +30,7 @@
 /* Public */
 int  lexer_init(void);
 int  lexer(void);
+int  lexer_lexfile(const char*);
 void lexer_pushtok(int, YYSTYPE);
 extern //lexer_lex.rl
 int lexer_lex(const char*);
@@ -117,7 +118,7 @@ int lexer
 ()
 {start:
   while (DE_LEN() > 0)    //lex any directory entries in our stack
-    if (lexer_lex(DE_POP()->d_name) == 0) //fail if it generates no tokens
+    if (lexer_lexfile(DE_POP()->d_name) == 0)
       FAIL("Lexer failed to tokenize [%s]\n",(*DE_STACKP)->d_name);
   if (TK_EMPTY)           //if there are no tokens,
     { TK_INIT();            //initialize the token stack back to 0
@@ -152,3 +153,28 @@ void lexer_pushtok
   TK_PUSH(tok, lval);
   printf("Pushed Token  %i | %i\n", TK_STACK[TK_LEN() - 1].tok_t, TK_STACK[TK_LEN() - 1].lval.val);
 }
+
+/* Lexical analysis of a file
+   Strips a filename to its base name, then sends it to lexer_lex
+*/
+int lexer_lexfile
+#define MAX_FNAME 2048
+#define HIDDEN_WARNING "%s is hidden and will not be parsed!\n", filename
+( const char  *filename
+)
+{ static char fname[MAX_FNAME];
+  char        *last_period = NULL, *iter;
+
+  if (*filename == '.')
+    { fprintf (stderr, HIDDEN_WARNING);
+      return 0;
+    }
+  strncpy(fname,filename,MAX_FNAME);
+  last_period = NULL;
+  for (iter = fname; *iter; iter++)
+    if (*iter == '.')
+      last_period = iter;
+  if (last_period)
+    *last_period = '\0';
+  return lexer_lex(fname);
+}
index c669b10..8490e02 100644 (file)
@@ -134,7 +134,6 @@ int scanner
   if (DL_CD_LEN() > 0)               //There are entities to process
     { if ((direntp = DL_CD_POP()) == NULL)//If the dirent is null, the library
         goto libfail;                     //function in dirent has failed
-      printf("Lexdir %s\n",direntp->d_name);
       lexer_lex(direntp->d_name);         //lex the directory name
       if (DL_LEN() >= DL_STACKSIZE)       //fail if maxdepth exceeded
         { fprintf(stderr, ERR_DEPTH);
index be902bd..a2ab6e7 100644 (file)
@@ -45,6 +45,7 @@ int main
 #define $($)#$ //stringifier
 #define MAXSTR 255
 #define MAXERR "-%c allows at most " $(MAXSTR) " input characters\n", opt
+#define OPTS  "d:o:h-"
 #define USAGE "Usage %s [-d dir_root][-o output_file][-h]\n", argv[0]
 #define USAGE_LONG                                     \
   "\tOptions:\n"                                       \
@@ -55,7 +56,7 @@ int main
 { int   opt;
 
  getopt:
-  switch (opt = getopt(argc, argv, "d:o:h-"))
+  switch (opt = getopt(argc, argv, OPTS))
   { case DONE:
       break;
     case 'd' :
diff --git a/src/bin/tools/ockpromo-fcgi.c b/src/bin/tools/ockpromo-fcgi.c
deleted file mode 100644 (file)
index 9ecc790..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-/*!@file
-  \brief   Mail router for OCKoreanMartialArts.com
-  \details This mail routing system is intended to run as a daemon for fastcgi
-           and stores usage information in a database before sending mail to the
-           administrator
-  \author  Ken
-  \date    Sept 2016
-  ----------------------------------------------------------------------------*/
-/* Standard */
-#include <stdlib.h> //atoi
-#include <string.h> //mem
-/* Third Party */
-#include <fcgi_stdio.h>
-/* Internal */
-#include <ock/ock.h>
-
-int get_body(void);
-
-int
-main
-()
-{ if (db_init())
-    return -1;
-
-  while(FCGI_Accept() >= 0)
-    { printf("Content-type: application/json\r\n\r\n");
-      printf("{ \"submission\" : ");
-      if (!get_body())
-       printf("\"fail\"");
-      printf("\"pass\"");
-      printf(" }");
-    }
-  return 0;
-}
-
-int
-get_body
-()
-{ char *lencp;
-  int   len, i;
-
-  if ((lencp = getenv("CONTENT_LENGTH")) == NULL
-      || (len = atoi(lencp)) < 1)
-    return -1;
-  for (i = 0; i < len; i++)
-    putchar(getchar());
-
-  return 0;
-}
-
diff --git a/src/bin/tools/ockpromo-fcgi.ld b/src/bin/tools/ockpromo-fcgi.ld
deleted file mode 100644 (file)
index 7e72f14..0000000
+++ /dev/null
@@ -1 +0,0 @@
--lfcgi -lmysqlclient
diff --git a/src/bin/tools/testapc.c b/src/bin/tools/testapc.c
new file mode 100644 (file)
index 0000000..ea9cbe3
--- /dev/null
@@ -0,0 +1,91 @@
+/*!@file
+  \brief   APC test driver
+  \details This driver does what APC does, but in staggered stages with
+           additional debugging information
+  \author  Jordan Lavatai
+  \date    Aug 2016
+  ----------------------------------------------------------------------------*/
+/* Standard */
+#include <stdio.h>  //print
+#include <errno.h>  //errors
+#include <string.h> //strnlen
+/* Posix */
+#include <stdlib.h> //exit
+#include <unistd.h> //getopt
+/* Internal */
+#include <apc/parser.tab.h> //bison
+#include <apc/ir.h>         //ir
+
+/* Import apc.c but redefine its primary symbols for jumping */
+#define main apc_main
+#define yyparse testapc_yyparse
+#include <bin/tools/apc.c>
+#undef yyparse
+#undef main
+
+int main(int, char*[]);
+int testapc_yyparse(void);
+
+extern //bison
+int yyparse(void);
+extern //lexer.c
+int  lexer_init(void);
+extern //apc.c
+const char* cargs['Z'];
+
+extern //apc/parser.tab.c
+YYSTYPE yylval;
+extern //lexer.c
+int  lexer(void);
+
+/* Ansi Term Colors */
+#define RED     "\x1b[31m"
+#define GREEN   "\x1b[32m"
+#define YELLOW  "\x1b[33m"
+#define BLUE    "\x1b[34m"
+#define MAGENTA "\x1b[35m"
+#define CYAN    "\x1b[36m"
+#define CLRC    "\x1b[0m" //clear current color
+
+/* Main entry from terminal
+   parses debugging options for testing apc, and calls apc_main
+*/
+int main
+( int   argc,
+  char* argv[]
+)
+{ apc_main(argc, argv);
+  printf(GREEN "PASS\n");
+  exit(EXIT_SUCCESS);
+}
+
+#define MAX_TOK 1024
+char tok_lval[MAX_TOK];
+
+/* yyparse intercept */
+int testapc_yyparse
+()
+{ int i, tok;
+  char* tok_pattern = "T[%i]L[%i]";
+  char* lval_type   = tok_pattern + 8; //location of i
+  tok_lval[NUM]  = 'i';
+  tok_lval[STR]  = 's';
+  tok_lval[SS]   = 'i';
+  tok_lval[NAME] = 's';
+  tok_lval[REF]  = 'x';
+  tok_lval[SSD]  = 'i';
+  tok_lval[FPTR] = 'x';
+  //lex 10 tokens
+  printf(YELLOW);
+  for (i = 0; i < 10; i++)
+    { if ((tok = lexer()) != 0)
+       { *lval_type = tok_lval[tok] ? tok_lval[tok] : 'i';
+         printf(tok_pattern, tok, yylval.val);
+       }
+      else
+       { printf(";");
+         break;
+       }
+    }
+  printf("\n" CLRC);
+}
diff --git a/src/ock/curl_sendmail.c b/src/ock/curl_sendmail.c
deleted file mode 100644 (file)
index c139262..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/*!@file
-  \brief   Mail router for OCKoreanMartialArts.com
-  \details This mail routing system is intended to run as a daemon for fastcgi
-           and stores usage information in a database before sending mail to the
-           administrator
-  \author  Ken
-  \date    Sept 2016
-  ----------------------------------------------------------------------------*/
-/* Standard */
-#include <stdlib.h>
-#include <string.h> //mem
-/* Third Party */
-#include <curl/curl.h>
-/* Internal */
-#include <ock/ock.h>
-
-int send_mail(void);
-
-int
-send_mail
-()
-{ return 0;
-}
diff --git a/src/ock/db_store.c b/src/ock/db_store.c
deleted file mode 100644 (file)
index 85a4ee8..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*!@file
-  \brief   Database storage for OCK's promo handler
-  \details 
-  \author  Ken
-  \date    Sept 2016
-  ----------------------------------------------------------------------------*/
-/* Standard */
-#include <stdio.h>  //print
-#include <string.h> //mem
-/* Third Party */
-#include <mysql/mysql.h>
-/* Internal */
-#include <ock/ock.h>
-
-int db_init(void);
-int db_insert(char*,char*,char*,char*);
-
-MYSQL *mysql;
-
-int
-db_init
-()
-#define HOST     "localhost"
-#define USER     "ock"
-#define PASS     "#0CK0r34!"
-#define DATABASE "ock_db"
-#define PORT     3306
-#define SOCKET   NULL
-#define FLAGS    0
-#define DATTABLE "promo_submissions"
-#define DTABFMT                                        \
-  "id not null auto_increment,"                        \
-  "firstname varchar (32) not null,"           \
-  "lastname varchar (32) not null,"            \
-  "email varchar (64) not null,"               \
-  "phone varchar (16) not null,"               \
-  "primary key (id)"
-{ mysql = mysql_init(NULL);
-  if ((mysql = mysql_real_connect(mysql, HOST, USER, PASS, DATABASE, PORT, SOCKET, FLAGS)) == NULL)
-    { fprintf(stderr,"Failed to establish connection to db.\n");
-      return -1;
-    }
-  if (mysql_query(mysql, "SHOW TABLES LIKE '" DATTABLE "';"))
-    { fprintf(stderr,"Initial query failed\n");
-      return -1;
-    }
-  if (mysql_num_rows(mysql_use_result(mysql)) < 1)
-    if (mysql_query(mysql, "create table " DATTABLE " (" DTABFMT ");"))
-      { fprintf(stderr,"Failed to create table.\n");
-       return -1;
-      }
-  return 0;
-}
-
-int
-db_insert
-( char *fname,
-  char *lname,
-  char *email,
-  char *phone
-)
-#define INSERT_FMT                             \
-  "INSERT INTO " DATTABLE                      \
-  " VALUES ('%s','%s','%s','%s')"              \
-  , fname, lname, email, phone
-#define INSERT_ERR "SQL Insertion Failed for %s %s - %s %s\n"  \
-  , fname, lname, email, phone
-{ char sqlinsert[256];
-  sprintf(sqlinsert, INSERT_FMT);
-  if (mysql_query(mysql, sqlinsert))
-    { fprintf(stderr, INSERT_ERR);
-      return -1;
-    }
-  return 0;
-}
diff --git a/src/ock/ock.h b/src/ock/ock.h
deleted file mode 100644 (file)
index 182ed0a..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef _OCK_H
-#define _OCK_H
-
-int db_init(void);
-int db_insert(char*,char*,char*,char*);
-
-#endif //_OCK_H