Code

Node tool: snap while scaling a selection of nodes. Consider this as experimental...
[inkscape.git] / src / deptool.cpp
index c35a63e1f2b85e83c2f24446da322b14389be950..45a01c4e7517e5e619dd9376fc605c700870d119 100644 (file)
@@ -81,7 +81,7 @@ make.ref: contains a reverse-dependency listing.  This takes each file
 
 
 //# This will allow us to redefine the string in the future
-typedef std::string DTString;
+typedef std::string String;
 
 /**
  *  Class which holds information for each file.
@@ -130,17 +130,17 @@ public:
     /**
      *  Directory part of the file name
      */
-    DTString path;
+    String path;
 
     /**
      *  Base name, sans directory and suffix
      */
-    DTString baseName;
+    String baseName;
 
     /**
      *  File extension, such as cpp or h
      */
-    DTString suffix;
+    String suffix;
 
     /**
      *  Type of file: CFILE, HFILE, OFILE
@@ -156,13 +156,17 @@ public:
      * Used to list files ref'd by this one, in the case of allFiles,
      * or other files which reference this one, such as refFiles;
      */
-    std::map<DTString, FileRec *> files;
+    std::map<String, FileRec *> files;
 
 
+    bool checked;
+
 private:
 
     void init()
         {
+        type    = UNKNOWN;
+        checked = false;
         }
 
     void assign(const FileRec &other)
@@ -172,6 +176,7 @@ private:
         baseName = other.baseName;
         suffix   = other.suffix;
         files    = other.files;
+        checked  = other.checked;
         }
 
 };
@@ -234,20 +239,20 @@ private:
     /**
      *  Removes whitespace from beginning and end of a string
      */
-    DTString trim(const DTString &val);
+    String trim(const String &val);
 
     /**
      *
      */
-    DTString getSuffix(const DTString &fname);
+    String getSuffix(const String &fname);
 
     /**
      *
      */
-    void parseName(const DTString &fullname,
-                   DTString &path,
-                   DTString &basename,
-                   DTString &suffix);
+    void parseName(const String &fullname,
+                   String &path,
+                   String &basename,
+                   String &suffix);
 
     /**
      *
@@ -262,7 +267,7 @@ private:
     /**
      *
      */
-    int getword(int pos, DTString &ret);
+    int getword(int pos, String &ret);
 
     /**
      *
@@ -272,7 +277,7 @@ private:
     /**
      *
      */
-    bool listFilesInDirectory(const DTString &dirname, int depth);
+    bool listFilesInDirectory(const String &dirname, int depth);
 
     /**
      *
@@ -282,22 +287,27 @@ private:
     /**
      *
      */
-    bool saveDepFile();
+    bool saveDepFile(bool doXml);
+
+    /**
+     *
+     */
+    bool saveCmakeFile();
 
     /**
      *
      */
-    bool saveRefFile();
+    bool saveRefFile(bool doXml);
 
     /**
      *
      */
-    bool addIncludeFile(FileRec *frec, const DTString &fname);
+    bool addIncludeFile(FileRec *frec, const String &fname);
 
     /**
      *
      */
-    bool scanFile(const DTString &fname, FileRec *frec);
+    bool scanFile(const String &fname, FileRec *frec);
 
     /**
      *
@@ -310,49 +320,52 @@ private:
      *
      */
     bool processReference(FileRec *ofile,
-                          DTString &fname,
+                          String &fname,
                           int depth);
 
     /**
      *
      */
-    std::set<DTString> excludes;
+    std::set<String> excludes;
 
     /**
      *
      */
-    std::set<DTString> excludesUsed;
+    std::set<String> excludesUsed;
 
     /**
      *
      */
-    std::set<DTString> excludesUnused;
+    std::set<String> excludesUnused;
 
     /**
      *
      */
-    std::vector<DTString> directories;
+    std::vector<String> directories;
 
     /**
      * A list of all files which will be processed for
      * dependencies.
      */
-    std::map<DTString, FileRec *> allFiles;
+    std::map<String, FileRec *> allFiles;
 
     /**
      * A list of .h files, with a list for each one
      * of which other files include them.
      */
-    std::map<DTString, FileRec *> refFiles;
+    std::map<String, FileRec *> refFiles;
 
     /**
      * The list of .o files, and the
      * dependencies upon them.
      */
-    std::map<DTString, FileRec *> depFiles;
+    std::map<String, FileRec *> depFiles;
 
     char *fileBuf;
     int   fileSize;
+    
+    static const int readBufLen = 8192;
+    char readBuf[8193];
 
 
 };
@@ -384,7 +397,7 @@ DepTool::~DepTool()
  */
 void DepTool::reset()
 {
-    std::map<DTString, FileRec *>::iterator iter;
+    std::map<String, FileRec *>::iterator iter;
     for (iter=allFiles.begin() ; iter!=allFiles.end() ; iter++)
         {
         FileRec *frec = iter->second;
@@ -446,7 +459,7 @@ void DepTool::trace(char *fmt, ...)
 /**
  *  Removes whitespace from beginning and end of a string
  */
-DTString DepTool::trim(const DTString &s)
+String DepTool::trim(const String &s)
 {
     if (s.size() < 1)
         return s;
@@ -468,7 +481,7 @@ DTString DepTool::trim(const DTString &s)
         }
     //trace("begin:%d  end:%d", begin, end);
 
-    DTString res = s.substr(begin, end-begin+1);
+    String res = s.substr(begin, end-begin+1);
     return res;
 }
 
@@ -476,15 +489,15 @@ DTString DepTool::trim(const DTString &s)
 /**
  *  Parse a full path name into path, base name, and suffix
  */
-void DepTool::parseName(const DTString &fullname,
-                        DTString &path,
-                        DTString &basename,
-                        DTString &suffix)
+void DepTool::parseName(const String &fullname,
+                        String &path,
+                        String &basename,
+                        String &suffix)
 {
     if (fullname.size() < 2)
         return;
 
-    unsigned int pos = fullname.find_last_of('/');
+    String::size_type pos = fullname.find_last_of('/');
     if (pos != fullname.npos && pos<fullname.size()-1)
         {
         path = fullname.substr(0, pos);
@@ -512,15 +525,15 @@ void DepTool::parseName(const DTString &fullname,
 /**
  *  Return the suffix, if any, of a file name
  */
-DTString DepTool::getSuffix(const DTString &fname)
+String DepTool::getSuffix(const String &fname)
 {
     if (fname.size() < 2)
         return "";
-    unsigned int pos = fname.find_last_of('.');
+    String::size_type pos = fname.find_last_of('.');
     if (pos == fname.npos)
         return "";
     pos++;
-    DTString res = fname.substr(pos, fname.size()-pos);
+    String res = fname.substr(pos, fname.size()-pos);
     //trace("suffix:%s", res.c_str()); 
     return res;
 }
@@ -535,23 +548,23 @@ DTString DepTool::getSuffix(const DTString &fname)
  *  Recursively list all files and directories under 'dirname', except
  *  those in the exclude list.
  */
-bool DepTool::listFilesInDirectory(const DTString &dirname, int depth)
+bool DepTool::listFilesInDirectory(const String &dirname, int depth)
 {
     //trace("### listFilesInDirectory(%s, %d)", dirname.c_str(), depth);
 
     int cFiles = 0;
     int hFiles = 0;
 
-    std::vector<DTString> subdirs;
+    std::vector<String> subdirs;
     DIR *dir = opendir(dirname.c_str());
     while (true)
         {
         struct dirent *de = readdir(dir);
         if (!de)
             break;
-        DTString s = de->d_name;
+        String s = de->d_name;
         struct stat finfo;
-        DTString fname;
+        String fname;
         if (s.size() == 0 || s[0] == '.')
             continue;
 
@@ -581,9 +594,9 @@ bool DepTool::listFilesInDirectory(const DTString &dirname, int depth)
             }
         else
             {
-            DTString path;
-            DTString basename;
-            DTString sfx;
+            String path;
+            String basename;
+            String sfx;
             parseName(fname, path, basename, sfx);
             if (sfx == "cpp" || sfx == "c" || sfx == "cxx"   || sfx == "cc")
                 {
@@ -639,7 +652,7 @@ bool DepTool::createFileList()
             {
             if (!fgets(readBuf, 255, f))
                 break;
-            DTString s = readBuf;
+            String s = readBuf;
             s = trim(s);
             //trace("s: %d '%s' ", s.size(), s.c_str());
             if (s.size() > 0 && s[0]!='#')
@@ -651,11 +664,11 @@ bool DepTool::createFileList()
     listFilesInDirectory(".", 0);
 
     // Note which files in the exclude list were not used.
-    std::set<DTString>::iterator iter;
+    std::set<String>::iterator iter;
     for (iter=excludes.begin() ; iter!=excludes.end() ; iter++)
         {
-        DTString fname = *iter;
-        std::set<DTString>::iterator citer = excludesUsed.find(fname);
+        String fname = *iter;
+        std::set<String>::iterator citer = excludesUsed.find(fname);
         if (citer == excludesUsed.end())
             excludesUnused.insert(fname);
         }
@@ -703,7 +716,7 @@ int DepTool::skipwhite(int pos)
  *  'ret' with the result.  Return the position after the
  *  word.
  */
-int DepTool::getword(int pos, DTString &ret)
+int DepTool::getword(int pos, String &ret)
 {
     while (pos < fileSize)
         {
@@ -740,10 +753,10 @@ bool DepTool::sequ(int pos, char *key)
  *  is not found in allFiles explicitly, try prepending include
  *  directory names to it and try again.
  */
-bool DepTool::addIncludeFile(FileRec *frec, const DTString &iname)
+bool DepTool::addIncludeFile(FileRec *frec, const String &iname)
 {
 
-    std::map<DTString, FileRec *>::iterator iter =
+    std::map<String, FileRec *>::iterator iter =
            allFiles.find(iname);
     if (iter != allFiles.end())
         {
@@ -756,11 +769,11 @@ bool DepTool::addIncludeFile(FileRec *frec, const DTString &iname)
     else 
         {
         //look in other dirs
-        std::vector<DTString>::iterator diter;
+        std::vector<String>::iterator diter;
         for (diter=directories.begin() ;
              diter!=directories.end() ; diter++)
             {
-            DTString dfname = *diter;
+            String dfname = *diter;
             dfname.append("/");
             dfname.append(iname);
             iter = allFiles.find(dfname);
@@ -783,7 +796,7 @@ bool DepTool::addIncludeFile(FileRec *frec, const DTString &iname)
  *  a bit of state machine stuff to make sure that the directive
  *  is valid.  (Like not in a comment).
  */
-bool DepTool::scanFile(const DTString &fname, FileRec *frec)
+bool DepTool::scanFile(const String &fname, FileRec *frec)
 {
     FILE *f = fopen(fname.c_str(), "r");
     if (!f)
@@ -791,13 +804,12 @@ bool DepTool::scanFile(const DTString &fname, FileRec *frec)
         error("Could not open '%s' for reading", fname.c_str());
         return false;
         }
-    DTString buf;
-    while (true)
+    String buf;
+    while (!feof(f))
         {
-        int ch = fgetc(f);
-        if (ch < 0)
-            break;
-        buf.push_back((char)ch);
+        int len = fread(readBuf, 1, readBufLen, f);
+        readBuf[len] = '\0';
+        buf.append(readBuf);
         }
     fclose(f);
 
@@ -845,7 +857,7 @@ bool DepTool::scanFile(const DTString &fname, FileRec *frec)
             {
             pos += 8;
             pos = skipwhite(pos);
-            DTString iname;
+            String iname;
             pos = getword(pos, iname);
             if (iname.size()>2)
                 {
@@ -872,10 +884,10 @@ bool DepTool::processDependency(FileRec *ofile,
                                 FileRec *include,
                                 int depth)
 {
-    std::map<DTString, FileRec *>::iterator iter;
+    std::map<String, FileRec *>::iterator iter;
     for (iter=include->files.begin() ; iter!=include->files.end() ; iter++)
         {
-        DTString fname  = iter->first;
+        String fname  = iter->first;
         if (ofile->files.find(fname) != ofile->files.end())
             {
             //trace("file '%s' already seen", fname.c_str());
@@ -899,18 +911,18 @@ bool DepTool::processDependency(FileRec *ofile,
  *  the inverse of processDependency().
  */
 bool DepTool::processReference(FileRec *hfile,
-                               DTString &fname,
+                               String &fname,
                                int depth)
 {
-    std::map<DTString, FileRec *>::iterator iter;
+    std::map<String, FileRec *>::iterator iter;
     for (iter=allFiles.begin() ; iter!=allFiles.end() ; iter++)
         {
         FileRec *frec = iter->second;
-        std::map<DTString, FileRec *>::iterator fiter =
+        std::map<String, FileRec *>::iterator fiter =
                   frec->files.find(fname);
         if (fiter != frec->files.end())
             {
-            DTString cfname  = iter->first;
+            String cfname  = iter->first;
             if (hfile->files.find(cfname) != hfile->files.end())
                 {
                 //trace("%d reffile '%s' already seen", depth, cfname.c_str());
@@ -933,7 +945,7 @@ bool DepTool::processReference(FileRec *hfile,
  */
 bool DepTool::generateDependencies()
 {
-    std::map<DTString, FileRec *>::iterator iter;
+    std::map<String, FileRec *>::iterator iter;
     //# First pass.  Scan for all includes
     for (iter=allFiles.begin() ; iter!=allFiles.end() ; iter++)
         {
@@ -950,12 +962,12 @@ bool DepTool::generateDependencies()
         FileRec *include = iter->second;
         if (include->type == FileRec::CFILE)
             {
-            DTString cFileName = iter->first;
+            String cFileName = iter->first;
             FileRec *ofile     = new FileRec(FileRec::OFILE);
             ofile->path        = include->path;
             ofile->baseName    = include->baseName;
             ofile->suffix      = include->suffix;
-            DTString fname     = include->path;
+            String fname     = include->path;
             if (fname.size()>0)
                 fname.append("/");
             fname.append(include->baseName);
@@ -967,9 +979,10 @@ bool DepTool::generateDependencies()
 
             processDependency(ofile, include, 0);
             }
+        /*
         else if (include->type == FileRec::HFILE)
             {
-            DTString fname     = iter->first;
+            String fname     = iter->first;
             FileRec *hfile     = new FileRec(FileRec::HFILE);
             hfile->path        = include->path;
             hfile->baseName    = include->baseName;
@@ -979,6 +992,7 @@ bool DepTool::generateDependencies()
 
             processReference(hfile, fname, 0);
             }
+        */
         }
 
       
@@ -996,8 +1010,9 @@ bool DepTool::run()
         return false;
     if (!generateDependencies())
         return false;
-    saveDepFile();
-    saveRefFile();
+    saveDepFile(false);
+    saveCmakeFile();
+    //saveRefFile(true);
     return true;
 }
 
@@ -1032,7 +1047,7 @@ bool DepTool::saveFileList()
     fprintf(f, "## F I L E S\n");
     fprintf(f, "########################################################\n");
 
-    std::map<DTString, FileRec *>::iterator iter;
+    std::map<String, FileRec *>::iterator iter;
     for (iter=allFiles.begin() ; iter!=allFiles.end() ; iter++)
         {
         fprintf(f, "%s\n", iter->first.c_str());
@@ -1043,10 +1058,10 @@ bool DepTool::saveFileList()
     fprintf(f, "## E X C L U D E D\n");
     fprintf(f, "########################################################\n");
 
-    std::set<DTString>::iterator uiter;
+    std::set<String>::iterator uiter;
     for (uiter=excludesUsed.begin() ; uiter!=excludesUsed.end() ; uiter++)
         {
-        DTString fname = *uiter;
+        String fname = *uiter;
         fprintf(f, "%s\n", fname.c_str());
         }
 
@@ -1057,7 +1072,7 @@ bool DepTool::saveFileList()
 
     for (uiter=excludesUnused.begin() ; uiter!=excludesUnused.end() ; uiter++)
         {
-        DTString fname = *uiter;
+        String fname = *uiter;
         fprintf(f, "%s\n", fname.c_str());
         }
 
@@ -1076,7 +1091,7 @@ bool DepTool::saveFileList()
  *   This is the main product.  This file lists the Include directives,
  *   the Object list, and the dependency list.
  */
-bool DepTool::saveDepFile()
+bool DepTool::saveDepFile(bool doXml)
 {
     time_t tim;
     time(&tim);
@@ -1086,76 +1101,168 @@ bool DepTool::saveDepFile()
         {
         trace("cannot open 'make.dep' for writing");
         }
-    fprintf(f, "########################################################\n");
-    fprintf(f, "## File: make.dep\n");
-    fprintf(f, "## Generated by DepTool at :%s", ctime(&tim));
-    fprintf(f, "########################################################\n");
-
-    fprintf(f, "\n\n");
+    if (doXml)
+        {
+        fprintf(f, "<?xml version='1.0'?>\n");
+        fprintf(f, "<deptool>\n");
+        fprintf(f, "\n");
+        fprintf(f, "<!--\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## File: make.dep\n");
+        fprintf(f, "## Generated by DepTool at :%s", ctime(&tim));
+        fprintf(f, "########################################################\n");
+        fprintf(f, "-->\n");
+
+        fprintf(f, "\n\n");
     
-    fprintf(f, "########################################################\n");
-    fprintf(f, "## I N C L U D E\n");
-    fprintf(f, "########################################################\n");
-    fprintf(f, "DEPTOOL_INCLUDE =");
+        fprintf(f, "\n");
+        fprintf(f, "<!--\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## I N C L U D E\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "-->\n");
+        fprintf(f, "<includes>\n");
     
-    std::vector<DTString>::iterator inciter;
-    for (inciter=directories.begin() ; inciter!=directories.end() ; inciter++)
-        {
-        fprintf(f, " \\\n");
-        DTString dirname = *inciter;
-        fprintf(f, "-I%s", dirname.c_str());
-        }
+        std::vector<String>::iterator inciter;
+        for (inciter=directories.begin() ; inciter!=directories.end() ; inciter++)
+            {
+            String dirname = *inciter;
+            fprintf(f, "    <inc name='%s'/>\n", dirname.c_str());
+            }
 
-    fprintf(f, "\n\n\n");
-    fprintf(f, "########################################################\n");
-    fprintf(f, "## O B J E C T S\n");
-    fprintf(f, "########################################################\n");
-    fprintf(f, "DEPTOOL_OBJECTS =");
+        fprintf(f, "</includes>\n");
+        fprintf(f, "\n\n\n");
+        fprintf(f, "<!--\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## O B J E C T S\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "-->\n");
+        fprintf(f, "<objects>\n");
     
-    std::map<DTString, FileRec *>::iterator oiter;
-    for (oiter=allFiles.begin() ; oiter!=allFiles.end() ; oiter++)
-        {
-        FileRec *frec = oiter->second;
-        if (frec->type == FileRec::CFILE)
+        std::map<String, FileRec *>::iterator oiter;
+        for (oiter=allFiles.begin() ; oiter!=allFiles.end() ; oiter++)
             {
-            fprintf(f, " \\\n");
-            DTString fname = frec->path;
-            if (fname.size()>0)
-                fname.append("/");
-            fname.append(frec->baseName);
-            fname.append(".o");
-            fprintf(f, "%s", fname.c_str());
+            FileRec *frec = oiter->second;
+            if (frec->type == FileRec::CFILE)
+                {
+                String fname = frec->path;
+                if (fname.size()>0)
+                    fname.append("/");
+                fname.append(frec->baseName);
+                fname.append(".o");
+                fprintf(f, "   <obj name='%s'/>\n", fname.c_str());
+                }
             }
-        }
 
 
-    fprintf(f, "\n\n\n");
-    fprintf(f, "########################################################\n");
-    fprintf(f, "## D E P E N D E N C I E S\n");
-    fprintf(f, "########################################################\n");
-    std::map<DTString, FileRec *>::iterator iter;
-    for (iter=depFiles.begin() ; iter!=depFiles.end() ; iter++)
+        fprintf(f, "</objects>\n");
+        fprintf(f, "\n\n\n");
+        fprintf(f, "<!--\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## D E P E N D E N C I E S\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "-->\n");
+        fprintf(f, "<dependencies>\n\n");
+        std::map<String, FileRec *>::iterator iter;
+        for (iter=depFiles.begin() ; iter!=depFiles.end() ; iter++)
+            {
+            FileRec *frec = iter->second;
+            if (frec->type == FileRec::OFILE)
+                {
+                String fname = iter->first;
+                fprintf(f, "<file name='%s'>\n", fname.c_str());
+                std::map<String, FileRec *>::iterator citer;
+                for (citer=frec->files.begin() ; citer!=frec->files.end() ; citer++)
+                    {
+                    String cfname = citer->first;
+                    fprintf(f, "    <dep name='%s'/>\n", cfname.c_str());
+                    }
+                fprintf(f, "</file>\n\n");
+                }
+            }
+
+        fprintf(f, "</dependencies>\n");
+        fprintf(f, "\n\n\n");
+        fprintf(f, "</deptool>\n");
+        fprintf(f, "<!--\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## E N D\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "-->\n");
+        }
+    else // ######### !XML
         {
-        FileRec *frec = iter->second;
-        if (frec->type == FileRec::OFILE)
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## File: make.dep\n");
+        fprintf(f, "## Generated by DepTool at :%s", ctime(&tim));
+        fprintf(f, "########################################################\n");
+
+        fprintf(f, "\n\n");
+    
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## I N C L U D E\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "DEPTOOL_INCLUDE =");
+    
+        std::vector<String>::iterator inciter;
+        for (inciter=directories.begin() ; inciter!=directories.end() ; inciter++)
+            {
+            fprintf(f, " \\\n");
+            String dirname = *inciter;
+            fprintf(f, "-I%s", dirname.c_str());
+            }
+
+        fprintf(f, "\n\n\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## O B J E C T S\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "DEPTOOL_OBJECTS =");
+    
+        std::map<String, FileRec *>::iterator oiter;
+        for (oiter=allFiles.begin() ; oiter!=allFiles.end() ; oiter++)
             {
-            DTString fname = iter->first;
-            fprintf(f, "%s:", fname.c_str());
-            std::map<DTString, FileRec *>::iterator citer;
-            for (citer=frec->files.begin() ; citer!=frec->files.end() ; citer++)
+            FileRec *frec = oiter->second;
+            if (frec->type == FileRec::CFILE)
                 {
-                DTString cfname = citer->first;
                 fprintf(f, " \\\n");
-                fprintf(f, "\t%s", cfname.c_str());
+                String fname = frec->path;
+                if (fname.size()>0)
+                    fname.append("/");
+                fname.append(frec->baseName);
+                fname.append(".o");
+                fprintf(f, "%s", fname.c_str());
                 }
-            fprintf(f, "\n\n\n");
             }
-        }
 
-    fprintf(f, "\n\n\n");
-    fprintf(f, "########################################################\n");
-    fprintf(f, "## E N D\n");
-    fprintf(f, "########################################################\n");
+
+        fprintf(f, "\n\n\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## D E P E N D E N C I E S\n");
+        fprintf(f, "########################################################\n");
+        std::map<String, FileRec *>::iterator iter;
+        for (iter=depFiles.begin() ; iter!=depFiles.end() ; iter++)
+            {
+            FileRec *frec = iter->second;
+            if (frec->type == FileRec::OFILE)
+                {
+                String fname = iter->first;
+                fprintf(f, "%s:", fname.c_str());
+                std::map<String, FileRec *>::iterator citer;
+                for (citer=frec->files.begin() ; citer!=frec->files.end() ; citer++)
+                    {
+                    String cfname = citer->first;
+                    fprintf(f, " \\\n");
+                    fprintf(f, "\t%s", cfname.c_str());
+                    }
+                fprintf(f, "\n\n\n");
+                }
+            }
+
+        fprintf(f, "\n\n\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## E N D\n");
+        fprintf(f, "########################################################\n");
+        }
 
     fclose(f);
 
@@ -1167,7 +1274,7 @@ bool DepTool::saveDepFile()
  *  Save the "reference" file, which lists each include file, and any files
  *  that are judged to be dependent upon it.
  */
-bool DepTool::saveRefFile()
+bool DepTool::saveRefFile(bool doXml)
 {
     time_t tim;
     time(&tim);
@@ -1177,33 +1284,141 @@ bool DepTool::saveRefFile()
         {
         trace("cannot open 'make.ref' for writing");
         }
+    if (doXml)
+        {
+        fprintf(f, "<?xml version='1.0'?>\n");
+        fprintf(f, "<deptool>\n\n");
+        fprintf(f, "<!--\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## File: make.ref\n");
+        fprintf(f, "## Generated by DepTool at :%s", ctime(&tim));
+        fprintf(f, "## Note: The metric is the 'distance' of inclusion from\n");
+        fprintf(f, "##    the given file.\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "-->\n");
+        fprintf(f, "\n\n");
+    
+
+        std::map<String, FileRec *>::iterator iter;
+        for (iter=refFiles.begin() ; iter!=refFiles.end() ; iter++)
+            {
+            FileRec *frec = iter->second;
+            if (frec->type == FileRec::HFILE)
+                {
+                String fname = iter->first;
+                fprintf(f, "<file name='%s'>\n", fname.c_str());
+                std::map<String, FileRec *>::iterator citer;
+                for (citer=frec->files.begin() ; citer!=frec->files.end() ; citer++)
+                    {
+                    String cfname = citer->first;
+                    fprintf(f, "    <ref d='%d' name='%s'/>\n", 
+                               citer->second->distance, cfname.c_str());
+                    }
+                fprintf(f, "</file>\n\n");
+                }
+            }
+        fprintf(f, "\n\n\n");
+        fprintf(f, "</deptool>\n");
+        fprintf(f, "<!--\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## E N D\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "-->\n");
+        }
+
+    else //######### not xml
+        {
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## File: make.ref\n");
+        fprintf(f, "## Generated by DepTool at :%s", ctime(&tim));
+        fprintf(f, "## Note: The metric is the 'distance' of inclusion from\n");
+        fprintf(f, "##    the given file.\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "\n\n");
+    
+
+        std::map<String, FileRec *>::iterator iter;
+        for (iter=refFiles.begin() ; iter!=refFiles.end() ; iter++)
+            {
+            FileRec *frec = iter->second;
+            if (frec->type == FileRec::HFILE)
+                {
+                String fname = iter->first;
+                fprintf(f, "### %s\n", fname.c_str());
+                std::map<String, FileRec *>::iterator citer;
+                for (citer=frec->files.begin() ; citer!=frec->files.end() ; citer++)
+                    {
+                    String cfname = citer->first;
+                    fprintf(f, "%3d %s\n", citer->second->distance,
+                                   cfname.c_str());
+                    }
+                fprintf(f, "\n");
+                }
+            }
+
+        fprintf(f, "\n\n\n");
+        fprintf(f, "########################################################\n");
+        fprintf(f, "## E N D\n");
+        fprintf(f, "########################################################\n");
+        }
+
+    fclose(f);
+
+    return true;
+}
+
+
+/**
+ *   This is a new thing.  It creates a cmake file that should be able to
+ *   build the entire thing. 
+ */
+bool DepTool::saveCmakeFile()
+{
+    time_t tim;
+    time(&tim);
+
+    FILE *f = fopen("CMakeLists.txt", "w");
+    if (!f)
+        {
+        trace("cannot open 'CMakeLists.txt' for writing");
+        }
     fprintf(f, "########################################################\n");
-    fprintf(f, "## File: make.ref\n");
+    fprintf(f, "## File: CMakeLists.txt\n");
     fprintf(f, "## Generated by DepTool at :%s", ctime(&tim));
-    fprintf(f, "## Note: The metric is the 'distance' of inclusion from\n");
-    fprintf(f, "##    the given file.\n");
     fprintf(f, "########################################################\n");
 
     fprintf(f, "\n\n");
     
-    std::map<DTString, FileRec *>::iterator iter;
-    for (iter=refFiles.begin() ; iter!=refFiles.end() ; iter++)
+    fprintf(f, "\n\n\n");
+    fprintf(f, "########################################################\n");
+    fprintf(f, "## P R O J E C T\n");
+    fprintf(f, "########################################################\n");
+    fprintf(f, "project (INKSCAPE)\n");
+    fprintf(f, "\n\n\n");
+    fprintf(f, "########################################################\n");
+    fprintf(f, "## O B J E C T S\n");
+    fprintf(f, "########################################################\n");
+    fprintf(f, "set (INKSCAPE_SRCS\n");
+    
+    std::map<String, FileRec *>::iterator oiter;
+    for (oiter=allFiles.begin() ; oiter!=allFiles.end() ; oiter++)
         {
-        FileRec *frec = iter->second;
-        if (frec->type == FileRec::HFILE)
+        FileRec *frec = oiter->second;
+        if (frec->type == FileRec::CFILE)
             {
-            DTString fname = iter->first;
-            fprintf(f, "### %s\n", fname.c_str());
-            std::map<DTString, FileRec *>::iterator citer;
-            for (citer=frec->files.begin() ; citer!=frec->files.end() ; citer++)
-                {
-                DTString cfname = citer->first;
-                fprintf(f, "%3d %s\n", citer->second->distance,
-                               cfname.c_str());
-                }
-            fprintf(f, "\n");
+            //fprintf(f, " \\\n");
+            String fname = frec->path;
+            if (fname.size()>0)
+                fname.append("/");
+            fname.append(frec->baseName);
+            fname.append(".");
+            fname.append(frec->suffix);
+            fprintf(f, "%s\n", fname.c_str());
             }
         }
+    fprintf(f, ")\n\n");
+
+    fprintf(f, "add_executable (inkscape ${INKSCAPE_SRCS})\n");
 
     fprintf(f, "\n\n\n");
     fprintf(f, "########################################################\n");