Permalink
Browse files

Add named. Fix parser conflicts.

  • Loading branch information...
1 parent 23c6563 commit 6a4df3f2880e0c05d3d1fe1719d78b65a087bdd3 @weyrick committed Jul 17, 2012
Showing with 284 additions and 112 deletions.
  1. +2 −0 CMakeLists.txt
  2. +10 −0 src/efind_parser.y
  3. +11 −21 src/main.c
  4. +1 −7 src/parse_expr.c
  5. +1 −1 src/parse_expr.h
  6. +235 −67 src/scanner.c
  7. +17 −10 src/scanner.re
  8. +7 −6 test/test1.c
View
@@ -8,6 +8,8 @@ MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} )
MESSAGE( STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH} )
MESSAGE( STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR} )
+set(CMAKE_C_FLAGS "-Wall")
+
include_directories (
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/src
View
@@ -47,6 +47,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
}
%extra_argument {list* argList}
+%left AND.
+%left OR.
+%right NOT.
+
%type goal {int}
%type expr {list*}
goal ::= expr(E). { list_push_list(argList, E); }
@@ -83,6 +87,12 @@ expr(RET) ::= GROUPEDBY WORD(B). {
list_push_str(RET, B->data);
}
+expr(RET) ::= NAMED WORD(B). {
+ RET = list_create();
+ list_push_str(RET, strdup("-name"));
+ list_push_str(RET, B->data);
+}
+
expr(RET) ::= SIZE INT(N) SIZEQUAL(B). {
RET = list_create();
list_push_str(RET, strdup("-size"));
View
@@ -58,9 +58,17 @@ void usage(int retval) {
}
-void runFind(char *argVec[])
+void runFind(char *path, list *argList)
{
+ list *finalArgs = list_create();
+ list_push_str(finalArgs, strdup(path));
+ list_push_list(finalArgs, argList);
+
+ char **argVec = list_to_array(finalArgs);
+ if (argVec == NULL)
+ return;
+
#if 0
char *s = argVec[0];
int i=0;
@@ -76,24 +84,6 @@ void runFind(char *argVec[])
}
-char **parseExpression(char *path, char *expr) {
-
- list *argList = parse_expr(path, expr);
-
- if (commandOnly) {
- char *result = list_to_str(argList);
- printf("find %s\n", result);
- exit(0);
- }
-
- char **args = list_to_array(argList);
- if (args == NULL)
- return NULL;
- // note, argList is leaked
- return args;
-
-}
-
int main(int argc, char *argv[]) {
if (argc < 3)
@@ -124,12 +114,12 @@ int main(int argc, char *argv[]) {
if (optionsError)
usage(1);
- char **argVec = parseExpression(argv[1], argv[2]);
+ list *argVec = parse_expr(argv[2]);
if (argVec == NULL) {
printf("null expression\n");
exit(1);
}
- runFind(argVec);
+ runFind(argv[1], argVec);
return 0;
View
@@ -48,7 +48,7 @@ void Parse(
list *argList
);
-list* parse_expr(char *path, char *expr) {
+list* parse_expr(char *expr) {
scanner_token token;
scanner_state state;
@@ -57,12 +57,6 @@ list* parse_expr(char *path, char *expr) {
list *argList = list_create();
- // push find command
- list_push_str(argList, strdup("find"));
-
- // push the path as the first argument, as find expects
- list_push_str(argList, strdup(path));
-
void *pParser = (void*)ParseAlloc(malloc);
state.start = expr;
View
@@ -28,6 +28,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define PARSE_EXPR_H
#include "list.h"
-list * parse_expr(char *path, char *expr);
+list* parse_expr(char *expr);
#endif
Oops, something went wrong.

0 comments on commit 6a4df3f

Please sign in to comment.