diff --git a/wmake/src/Makefile b/wmake/src/Makefile index cac2a639a5..405ce98dc2 100644 --- a/wmake/src/Makefile +++ b/wmake/src/Makefile @@ -22,7 +22,7 @@ # along with OpenFOAM; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # -# Script +# File # Makefile # # Description diff --git a/wmake/src/makeParserCode b/wmake/src/makeParserCode new file mode 100755 index 0000000000..801cf057fd --- /dev/null +++ b/wmake/src/makeParserCode @@ -0,0 +1,56 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2010-2010 OpenCFD Ltd. +# \\/ M anipulation | +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM. +# +# OpenFOAM is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with OpenFOAM; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# +# Script +# makeParserCode +# +# Description +# Use coco-cpp to create parser code +# +#------------------------------------------------------------------------------ +cd ${0%/*} || exit 1 # run from this directory + + +bindir=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/coco-cpp/bin +frames=$WM_THIRD_PARTY_DIR/platforms/share/coco-cpp + +[ -d "$bindir" -a -x "$bindir/coco-cpp" ] || { + echo "no coco-cpp binary found" + exit 1 +} + +[ -d "$frames" -a -f "$frames/Parser.frame" -a -f "$frames/Scanner.frame" ] || { + echo "no coco-cpp frames found" + exit 1 +} + +# run coco-cpp: + +$bindir/coco-cpp -frames $frames wmkdependParser.atg + +echo +echo Done + +#------------------------------------------------------------------------------ diff --git a/wmake/src/wmkdep.l b/wmake/src/wmkdep.l index 3c2d500bed..08c9b5149b 100644 --- a/wmake/src/wmkdep.l +++ b/wmake/src/wmkdep.l @@ -36,7 +36,7 @@ Description only once. This is why this program is faster than cpp. Usage - wmkdep [ -Idirectory ... -Idirectory ] filename + wmkdep [ -Idir ... -Idir ] [ -iheader .. -iheader ] filename \*---------------------------------------------------------------------------*/ @@ -50,7 +50,7 @@ Usage void nextFile(const char* fileName); void importFile(const char* fileName); -void importDirectory(const char* dirName); +void importDir(const char* dirName); # undef yywrap /* sometimes a macro by default */ @@ -76,7 +76,7 @@ void importDirectory(const char* dirName); sun.*; BEGIN(INITIAL); launcher.*; BEGIN(INITIAL); [^"\n*]*; { BEGIN(INITIAL); importFile(yytext); } /*"*/ -[^"\n]*\*; { BEGIN(INITIAL); importDirectory(yytext); } /*"*/ +[^"\n]*\*; { BEGIN(INITIAL); importDir(yytext); } /*"*/ " "include[ \t]+\' BEGIN(FFNAME); /* FORTRAN-file name */ [^']* { BEGIN(INITIAL); nextFile(yytext); } /*'*/ @@ -86,160 +86,24 @@ void importDirectory(const char* dirName); %% -int nDirectories; -char** directories; -char* sourceFile = NULL; -char* sourceExt = NULL; -char* objectFile = NULL; -char* classFile = NULL; -char* depFile = NULL; - -int main(int argc, char* argv[]) -{ - char *dotPtr, *slashPtr; - int i; - - if (argc == 1) - { - fprintf(stderr,"input file not supplied\n"); - exit(1); - } - - sourceFile = (char*)malloc(strlen(argv[argc-1]) + 1); - strcpy(sourceFile, argv[argc-1]); - fprintf(stderr, "Making dependency list for source file %s\n", sourceFile); - - - /* Get list of -I directories. */ - nDirectories = 0; - - for (i = 1; i < argc; i++) - { - if (strncmp(argv[i], "-I", 2) == 0) - { - nDirectories++; - } - } - - directories = (char**)malloc(sizeof(char*)*nDirectories); - - nDirectories = 0; - - for (i = 1; i < argc; i++) - { - if (strncmp(argv[i], "-I", 2) == 0) - { - directories[nDirectories++] = strdup(argv[i] + 2); - } - } - - - - if ((dotPtr = strrchr(sourceFile, '.')) == NULL) - { - fprintf - ( - stderr, - "Cannot find extension in source file name %s\n", - sourceFile - ); - exit(1); - } - - if ((slashPtr = strrchr(sourceFile, '/')) == NULL) - { - slashPtr = sourceFile; - } - else - { - slashPtr++; - } - - sourceExt = (char*)malloc(strlen(sourceFile)); - sourceExt[0] = 0; - strncat - ( - sourceExt, - dotPtr+1, - (&sourceFile[strlen(sourceFile) - 1] - dotPtr)/sizeof(char) - ); - - /* - * initialise depFile to zero and use strncat rather than strncpy - * because there is a bug in the SGI strncat that if 0 preceeds the '.' - * it inserts a space - */ - depFile = (char*)malloc(strlen(sourceFile) + 3); - depFile[0] = 0; - strncat(depFile, sourceFile, (dotPtr - sourceFile)/sizeof(char)); - strcat(depFile, ".dep"); - - if (strcmp(sourceExt, "java") == 0) - { - classFile = (char*)malloc(strlen(sourceFile) + 17); - strcpy(classFile, "$(CLASSES_DIR)/"); - strncat(classFile, sourceFile, (dotPtr - sourceFile)/sizeof(char)); - strcat(classFile, ".class"); - - printf("%s: %s\n", classFile, depFile); - } - else - { - objectFile = (char*)malloc(strlen(sourceFile) + 16); - strcpy(objectFile, "$(OBJECTS_DIR)/"); - strncat(objectFile, slashPtr, (dotPtr - slashPtr)/sizeof(char)); - strcat(objectFile, ".o"); - - printf("%s: %s\n", objectFile, depFile); - } - - nextFile(sourceFile); - yylex(); - - - for (i = 0; i < nDirectories; i++) - { - free(directories[i]); - } - free(directories); - - free(sourceFile); - free(sourceExt); - free(objectFile); - free(classFile); - free(depFile); - - return 0; -} - - -int currentBuffer = 0; /* Buffer pointer stack counter */ -YY_BUFFER_STATE buffers[FILE_STACK_SIZE]; /* Buffer pointer stack */ - -/* file name entry in hash table */ - -struct FileName +/* char* entry in hash table */ +struct HashEntry { char* name; - struct FileName* next; + struct HashEntry* next; }; -/* Set of files already visited */ -struct FileName* visitedFiles[HASH_TABLE_SIZE]; - -/* Set of (java) directories already visited */ -struct FileName* visitedDirs[HASH_TABLE_SIZE]; - - /* - * lookup name in hash table, if not found insert in table + * lookup name in hash table. + * if found - return 1 + * if not found - insert in table and return 0 */ -int lookUp(struct FileName** hashTable, const char* p) +int lookUp(struct HashEntry** hashTable, const char* p) { int ii = 0; - struct FileName* n; - struct FileName* nn; + struct HashEntry* n; + struct HashEntry* nn; /* hash */ const char* pp = p; @@ -258,9 +122,8 @@ int lookUp(struct FileName** hashTable, const char* p) } /* insert */ - nn = (struct FileName*)malloc(sizeof(struct FileName)); - nn->name = (char*)malloc(strlen(p)+1); - strcpy(nn->name, p); + nn = (struct HashEntry*)malloc(sizeof(struct HashEntry)); + nn->name = strdup(p); nn->next = hashTable[ii]; hashTable[ii] = nn; @@ -269,17 +132,152 @@ int lookUp(struct FileName** hashTable, const char* p) } +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +int nDirectories = 0; +char** directories; +char* sourceFile = NULL; +char* depFile = NULL; + +/* Set of files already visited */ +struct HashEntry* visitedFiles[HASH_TABLE_SIZE]; + +/* Set of (java) directories already visited */ +struct HashEntry* visitedDirs[HASH_TABLE_SIZE]; + + +int main(int argc, char* argv[]) +{ + char *basePos, *dotPos; + int i; + + if (argc == 1) + { + fprintf(stderr, "input file not supplied\n"); + exit(1); + } + + sourceFile = strdup(argv[argc-1]); + fprintf(stderr, "Making dependency list for source file %s\n", sourceFile); + + + if ((basePos = strrchr(sourceFile, '/')) == NULL) + { + basePos = sourceFile; + } + else + { + basePos++; + } + + if + ( + (dotPos = strrchr(sourceFile, '.')) == NULL + || (dotPos < basePos) + ) + { + fprintf + ( + stderr, + "cannot find extension in source file name %s\n", + sourceFile + ); + exit(1); + } + + /* count number of -I directories */ + nDirectories = 0; + for (i = 1; i < argc; i++) + { + if (strncmp(argv[i], "-I", 2) == 0) + { + if (strlen(argv[i]) > 2) + { + nDirectories++; + } + } + } + + directories = (char**)malloc(sizeof(char*)*nDirectories); + + /* build list of -I directories and add -i ignores */ + nDirectories = 0; + for (i = 1; i < argc; i++) + { + if (strncmp(argv[i], "-I", 2) == 0) + { + if (strlen(argv[i]) > 2) + { + directories[nDirectories++] = strdup(argv[i] + 2); + } + } + else if (strncmp(argv[i], "-i", 2) == 0) + { + if (strlen(argv[i]) > 2) + { + lookUp(visitedFiles, (argv[i] + 2)); + } + } + } + + /* + * initialise depFile to zero and use strncat rather than strncpy + * because there is a bug in the SGI strncat that if 0 preceeds the '.' + * it inserts a space + */ + depFile = (char*)malloc(strlen(sourceFile) + 3); + depFile[0] = 0; + strncat(depFile, sourceFile, (dotPos - sourceFile)/sizeof(char)); + strcat(depFile, ".dep"); + + if (strcmp(dotPos, ".java") == 0) + { + char *classFile = strdup(sourceFile); + classFile[(dotPos - sourceFile)/sizeof(char)] = 0; + + printf("$(CLASSES_DIR)/%s.class: %s\n", classFile, depFile); + free(classFile); + } + else + { + char *objectFile = strdup(basePos); + objectFile[(dotPos - basePos)/sizeof(char)] = 0; + + printf("$(OBJECTS_DIR)/%s.o: %s\n", objectFile, depFile); + free(objectFile); + } + + nextFile(sourceFile); + yylex(); + + + for (i = 0; i < nDirectories; i++) + { + free(directories[i]); + } + free(directories); + + free(sourceFile); + free(depFile); + + return 0; +} + + +int currentBuffer = 0; /* Buffer pointer stack counter */ +YY_BUFFER_STATE buffers[FILE_STACK_SIZE]; /* Buffer pointer stack */ + + /* * Add a directory name to the file name */ -char* addDirectoryName(const char* directoryName, const char* fileName) +char* addDirectoryName(const char* dirName, const char* fileName) { - char* pathName; - pathName = (char*)malloc(strlen(directoryName) + strlen(fileName) + 2); + char* pathName = (char*)malloc(strlen(dirName) + strlen(fileName) + 2); + strcpy(pathName, dirName); - strcpy(pathName, directoryName); - - if (directoryName[strlen(directoryName)-1] != '/') + if (dirName[strlen(dirName)-1] != '/') { strcat(pathName, "/"); } @@ -295,10 +293,10 @@ char* addDirectoryName(const char* directoryName, const char* fileName) */ void nextFile(const char* fileName) { - int d; - char* pathName; - - if (lookUp(visitedFiles, fileName)) return; + if (lookUp(visitedFiles, fileName)) + { + return; /* already existed (did not insert) */ + } if (currentBuffer >= FILE_STACK_SIZE) { @@ -317,9 +315,10 @@ void nextFile(const char* fileName) if (!(newyyin = fopen(fileName, "r"))) { + int d; for (d=0; dd_name, ".java") - && !strstr(list->d_name, ".java~") - ) + char* dotPos = strrchr(list->d_name, '.'); + + if (dotPos != NULL && strcmp(dotPos, ".java") == 0) { - path = addDirectoryName(uDirName, list->d_name); - nextFile(path); - free(path); + char* pathName = addDirectoryName(uDirName, list->d_name); + nextFile(pathName); + free(pathName); } } closedir(source); - free(uDirName); } + free(uDirName); } diff --git a/wmake/src/wmkdepend.cpp b/wmake/src/wmkdepend.cpp index 159fb3849b..8a92a1fa4d 100644 --- a/wmake/src/wmkdepend.cpp +++ b/wmake/src/wmkdepend.cpp @@ -35,12 +35,12 @@ Description only once. This is why this program is faster than cpp. Usage - wmkdep [ -Idirectory ... -Idirectory ] filename + wmkdepend [ -Idir ... -Idir ] [ -iheader .. -iheader ] filename \*---------------------------------------------------------------------------*/ #include -#include +#include #include #include "wmkdependParser.h" @@ -58,7 +58,10 @@ void printUsage(const char* message = NULL) fwprintf ( stderr, - L"Usage: wmkdepend [ -Idirectory ... -Idirectory ] filename\n" + L"Usage: wmkdepend %s filename\nOptions:\n%s\n", + "[ -Idir ... -Idir ] [ -iheader .. -iheader ]", + " -Idir specify include directory\n" + " -iheader specify header name to ignore\n" ); } @@ -67,23 +70,33 @@ int main(int argc, char* argv[]) { if (argc == 1) { - printUsage("Error: input file not supplied"); + printUsage("input file not supplied"); ::exit(1); } for (int i=1; i < argc; i++) { - if (strncmp(argv[i], "-I", 2) == 0 && strlen(argv[i]) > 2) + if (strncmp(argv[i], "-I", 2) == 0) { - std::string dirName(argv[i] + 2); - - // add trailing slash if required - if (dirName.rfind('/') != dirName.size()-1) + if (strlen(argv[i]) > 2) { - dirName += '/'; - } + std::string dirName(argv[i] + 2); - wmake::Parser::includeDirs.push_back(dirName); + // add trailing slash if required + if (dirName.rfind('/') != dirName.size()-1) + { + dirName += '/'; + } + + wmake::Parser::includeDirs.push_back(dirName); + } + } + else if (strncmp(argv[i], "-i", 2) == 0) + { + if (strlen(argv[i]) > 2) + { + wmake::Parser::visitedFiles.insert(argv[i] + 2); + } } } @@ -117,7 +130,7 @@ int main(int argc, char* argv[]) fwprintf ( stderr, - L"Cannot find extension in source file name %s\n", + L"cannot find extension in source file name %s\n", sourceFile.c_str() ); ::exit(1); diff --git a/wmake/src/wmkdependParser.atg b/wmake/src/wmkdependParser.atg index 60a68f0f9b..d485a84c5d 100644 --- a/wmake/src/wmkdependParser.atg +++ b/wmake/src/wmkdependParser.atg @@ -59,9 +59,6 @@ COMPILER wmkdepend /*---------------------------------------------------------------------------*/ private: - //! Set of files already visited - static std::set visitedFiles_; - //! Set of (java) directories already visited static std::set visitedDirs_; @@ -75,6 +72,9 @@ private: static void importFile(const std::string& name); public: + //! Set of files already visited + static std::set visitedFiles; + //! Include directories to search static std::list includeDirs; @@ -95,9 +95,9 @@ public: #include #include -std::set Parser::visitedFiles_; std::set Parser::visitedDirs_; +std::set Parser::visitedFiles; std::list Parser::includeDirs; std::string Parser::sourceFile; std::string Parser::depFile; @@ -123,7 +123,7 @@ void Parser::ignoreDir(const std::string& name) void Parser::includeFile(const std::string& name) { - if (!visitedFiles_.insert(name).second) + if (!visitedFiles.insert(name).second) { return; // already existed (did not insert) } @@ -172,7 +172,7 @@ void Parser::includeFile(const std::string& name) ); // only report the first occurance - visitedFiles_.insert(name); + visitedFiles.insert(name); } } diff --git a/wmake/src/wmkdependParser.cpp b/wmake/src/wmkdependParser.cpp index 9c1ac56cac..8d59a862bb 100644 --- a/wmake/src/wmkdependParser.cpp +++ b/wmake/src/wmkdependParser.cpp @@ -52,9 +52,9 @@ namespace wmake { #include #include -std::set Parser::visitedFiles_; std::set Parser::visitedDirs_; +std::set Parser::visitedFiles; std::list Parser::includeDirs; std::string Parser::sourceFile; std::string Parser::depFile; @@ -80,7 +80,7 @@ void Parser::ignoreDir(const std::string& name) void Parser::includeFile(const std::string& name) { - if (!visitedFiles_.insert(name).second) + if (!visitedFiles.insert(name).second) { return; // already existed (did not insert) } @@ -129,7 +129,7 @@ void Parser::includeFile(const std::string& name) ); // only report the first occurance - visitedFiles_.insert(name); + visitedFiles.insert(name); } } diff --git a/wmake/src/wmkdependParser.h b/wmake/src/wmkdependParser.h index b91f364f27..df807bd10f 100644 --- a/wmake/src/wmkdependParser.h +++ b/wmake/src/wmkdependParser.h @@ -122,9 +122,6 @@ public: private: - //! Set of files already visited - static std::set visitedFiles_; - //! Set of (java) directories already visited static std::set visitedDirs_; @@ -138,6 +135,9 @@ private: static void importFile(const std::string& name); public: + //! Set of files already visited + static std::set visitedFiles; + //! Include directories to search static std::list includeDirs;