idep_cdep.cxx File Reference

#include "idep_compiledep.h"
#include "idep_namearray.h"
#include "idep_nameindexmap.h"
#include "idep_binrel.h"
#include "idep_string.h"
#include "idep_filedepiter.h"
#include "idep_tokeniter.h"
#include <ctype.h>
#include <cstring>
#include <fstream>
#include <iostream>
#include <cassert>

Go to the source code of this file.

Classes

struct  idep_CompileDep_i
struct  idep_RootFileIter_i
struct  idep_HeaderFileIter_i

Typedefs

typedef void(idep_CompileDep::* Func )(const char *)

Functions

static std::ostream & err (std::ostream &orr)
static const char * stripDotSlash (const char *originalPath)
static int isAbsolutePath (const char *originalPath)
static int isAsciiFile (const char *fileName)
static void loadFromStream (std::istream &in, idep_CompileDep *dep, Func add)
static int loadFromFile (const char *file, idep_CompileDep *dep, Func add)
static const char * search (idep_String *s, const char *includeDir, const char *file)
static const char * search (idep_String *s, const idep_NameArray &a, const char *file)
static int getDep (int index)
std::ostream & operator<< (std::ostream &o, const idep_CompileDep &(dep))

Variables

static idep_BinRels_dependencies_p
static idep_NameIndexMaps_files_p
static idep_NameArrays_includes_p
static int s_recurse
static std::ostream * s_err_p

Typedef Documentation

typedef void(idep_CompileDep::* Func)(const char *)

Definition at line 56 of file idep_cdep.cxx.


Function Documentation

static std::ostream& err ( std::ostream &  orr  )  [static]

Definition at line 18 of file idep_cdep.cxx.

Referenced by idep_CompileDep::calculate(), and getDep().

00019 {
00020     return orr << "Error: ";
00021 }

static int getDep ( int  index  )  [static]

Definition at line 127 of file idep_cdep.cxx.

References idep_BinRel::appendEntry(), BAD, idep_NameIndexMap::entry(), err(), GOOD, idep_FileDepIter::isValidFile(), it, idep_NameIndexMap::length(), s_err_p, s_recurse, search(), and idep_BinRel::set().

Referenced by idep_CompileDep::calculate().

00128 {
00129     enum { BAD = -1, GOOD = 0 } status = GOOD;
00130      
00131     idep_String buffer; // string buffer, do not use directly
00132     idep_FileDepIter it((*s_files_p)[index]);
00133 
00134     for (; it; ++it) {
00135         const char *dirFile = search(&buffer, *s_includes_p, it());
00136         if (!dirFile) {
00137             err(*s_err_p) << "include directory for file \""
00138                  << it() << "\" not specified." << std::endl; 
00139             status = BAD;
00140             continue;
00141         }
00142 
00143         int length = s_files_p->length();
00144         int otherIndex = s_files_p->entry(dirFile);
00145 
00146         if (s_files_p->length() > length) {
00147             // first time looking at this file
00148             s_dependencies_p->appendEntry();
00149                 
00150             if (s_recurse && getDep(otherIndex)) {
00151                 status = BAD;
00152             }
00153         }
00154 
00155         s_dependencies_p->set(index, otherIndex, 1);
00156     }
00157 
00158     if (!it.isValidFile()) {
00159        err(*s_err_p) << "unable to open file \""
00160          << (*s_files_p)[index] << "\" for read access." << std::endl; 
00161         status = BAD;
00162     }
00163 
00164     return status;
00165 }

static int isAbsolutePath ( const char *  originalPath  )  [static]

Definition at line 33 of file idep_cdep.cxx.

Referenced by operator<<(), and search().

00034 {
00035     return '/' == *originalPath;
00036 }

static int isAsciiFile ( const char *  fileName  )  [static]

Definition at line 38 of file idep_cdep.cxx.

Referenced by loadFromFile().

00039 {
00040     enum { NO = 0, YES = 1 };
00041     std::ifstream in(fileName);
00042     if (!in) {
00043         return NO;
00044     }
00045 
00046     // check for non-ascii characters
00047     char c;
00048     while (in && !in.get(c).eof()) {
00049        if (!isascii(c)) {
00050           return NO;
00051        }
00052     }
00053     return YES;
00054 }

static int loadFromFile ( const char *  file,
idep_CompileDep dep,
Func  add 
) [static]

Definition at line 73 of file idep_cdep.cxx.

References BAD, GOOD, isAsciiFile(), and loadFromStream().

Referenced by idep_CompileDep::readIncludeDirectories(), and idep_CompileDep::readRootFiles().

00074 {
00075     enum { BAD = -1, GOOD = 0 };
00076     if (!isAsciiFile(file)) {
00077         return BAD;
00078     }
00079     std::ifstream in(file);
00080     assert(in);
00081     loadFromStream(in, dep, add); 
00082     return GOOD;
00083 }

static void loadFromStream ( std::istream &  in,
idep_CompileDep dep,
Func  add 
) [static]

Definition at line 57 of file idep_cdep.cxx.

References it.

Referenced by idep_CompileDep::inputRootFiles(), and loadFromFile().

00058 { 
00059     assert(in);
00060     for (idep_TokenIter it(in); it; ++it) {
00061         if ('#' == *it()) {                     // strip comment if any
00062              while (it && '\n' != *it()) { 
00063                 ++it;
00064             }
00065             continue;                           // either !it or '\n' 
00066         }
00067         if ('\n' != *it()) {            
00068             (dep->*add)(it());
00069         }
00070     }
00071 }

std::ostream& operator<< ( std::ostream &  o,
const idep_CompileDep dep 
)

Definition at line 317 of file idep_cdep.cxx.

References MuELoss::a, idep_NameArray::append(), isAbsolutePath(), and idep_NameArray::length().

00318 {
00319     const char *INDENT = "    ";
00320     for (idep_RootFileIter rit(dep); rit; ++rit) {
00321         idep_NameArray a;
00322         o << rit() << std::endl;
00323         for (idep_HeaderFileIter hit(rit); hit; ++hit) {
00324             if (isAbsolutePath(hit())) {
00325                 a.append(hit());
00326             }  
00327             else {
00328                 o << INDENT << hit() << std::endl;
00329             }
00330         }
00331         for (int i = 0; i < a.length(); ++i) {
00332            o << INDENT << a[i] << std::endl;
00333         }
00334         o << std::endl;
00335     }
00336     return o;
00337 }

static const char* search ( idep_String s,
const idep_NameArray a,
const char *  file 
) [static]

Definition at line 94 of file idep_cdep.cxx.

References isAbsolutePath(), idep_NameArray::length(), and search().

00096 {
00097     if (isAbsolutePath(file)) {
00098         *s = file;
00099         const char *absFile = *s;
00100         return std::ifstream(absFile) ? absFile : 0;
00101     }
00102 
00103     const char *dirFile = 0;
00104     for (int i = 0; i < a.length(); ++i) {
00105         dirFile = search(s, a[i], file);
00106         if (dirFile) {
00107             break;
00108         }
00109     }
00110 
00111     return dirFile;
00112 }

static const char* search ( idep_String s,
const char *  includeDir,
const char *  file 
) [static]

Definition at line 85 of file idep_cdep.cxx.

References isAbsolutePath(), and stripDotSlash().

Referenced by idep_CompileDep::calculate(), getDep(), and search().

00087 {
00088     assert(!isAbsolutePath(file));
00089     (*s = includeDir) += file;
00090     const char *dirFile = stripDotSlash(*s);
00091     return std::ifstream(dirFile) ? dirFile : 0;
00092 }

static const char* stripDotSlash ( const char *  originalPath  )  [static]

Definition at line 23 of file idep_cdep.cxx.

Referenced by search().

00024 {
00025     if (originalPath) {
00026         while ('.' == originalPath[0] && '/' == originalPath[1]) {
00027             originalPath += 2;
00028         }
00029     }
00030     return originalPath;
00031 }


Variable Documentation

Definition at line 121 of file idep_cdep.cxx.

std::ostream* s_err_p [static]

Definition at line 125 of file idep_cdep.cxx.

Referenced by idep_CompileDep::calculate(), and getDep().

Definition at line 122 of file idep_cdep.cxx.

Definition at line 123 of file idep_cdep.cxx.

int s_recurse [static]

Definition at line 124 of file idep_cdep.cxx.

Referenced by idep_CompileDep::calculate(), and getDep().


Generated on 24 Apr 2018 for loon by  doxygen 1.6.1