Browse Source

*** empty log message ***

David Rose 25 years ago
parent
commit
736a3caefb
5 changed files with 348 additions and 35 deletions
  1. 1 1
      ppremake/configure.in
  2. 15 3
      ppremake/ppCommandFile.cxx
  3. 30 31
      ppremake/ppDependableFile.cxx
  4. 293 0
      ppremake/ppScope.cxx
  5. 9 0
      ppremake/ppScope.h

+ 1 - 1
ppremake/configure.in

@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_INIT(ppremake.cxx)
-AM_INIT_AUTOMAKE(ppremake, 0.50)
+AM_INIT_AUTOMAKE(ppremake, 0.51)
 AM_CONFIG_HEADER(config.h)
 
 AC_PREFIX_DEFAULT(/usr/local/panda)

+ 15 - 3
ppremake/ppCommandFile.cxx

@@ -390,8 +390,14 @@ bool PPCommandFile::
 handle_command(const string &line) {
   if (_got_command) {
     // If we were still processing a command from last time, keep
-    // going; this line is just a continuation.
-    _params += line;
+    // going; this line is just a continuation.  But skip any initial
+    // whitespace.
+    size_t p = 0;
+    while (p < line.length() && isspace(line[p])) {
+      p++;
+    }
+    _params += ' ';
+    _params += line.substr(p);
 
   } else {
     // This is the first line of a new command.
@@ -414,7 +420,13 @@ handle_command(const string &line) {
     // If the line ends with a backslash, there's more to come before
     // we can process the command.
     _got_command = true;
-    _params[_params.length() - 1] = ' ';
+
+    // Truncate off the backslash, and any whitespace before it.
+    size_t p = _params.length() - 1;
+    while (p > 0 && isspace(_params[p - 1])) {
+      p--;
+    }
+    _params = _params.substr(0, p);
     return true;
   }
 

+ 30 - 31
ppremake/ppDependableFile.cxx

@@ -316,39 +316,39 @@ compute_dependencies(string &circularity) {
 	cerr << "Warning: dependent file " << get_pathname() 
 	     << " does not exist.\n";
       }
-      return (PPDependableFile *)NULL;
-    }
-    
-    PPDirectoryTree *tree = _directory->get_tree();
-    
-    bool okcircular = false;
-    string line;
-    getline(in, line);
-    while (!in.fail() && !in.eof()) {
-      if (line.substr(0, 16) == "/* okcircular */") {
-	okcircular = true;
-      } else {
-	string filename = check_include(line);
-	if (!filename.empty() && filename.find('/') == string::npos) {
-	  Dependency dep;
-	  dep._okcircular = okcircular;
-	  dep._file = tree->find_dependable_file(filename);
-	  if (dep._file != (PPDependableFile *)NULL) {
-	    // All right!  Here's a file we depend on.  Add it to the
-	    // list.
-	    _dependencies.push_back(dep);
-	    
-	  } else {
-	    // It's an include file from somewhere else, not from within
-	    // our source tree.  We don't care about it, but we do need
-	    // to record it so we can easily check later if the cache
-	    // file has gone stale.
-	    _extra_includes.push_back(filename);
+
+    } else {
+      PPDirectoryTree *tree = _directory->get_tree();
+      
+      bool okcircular = false;
+      string line;
+      getline(in, line);
+      while (!in.fail() && !in.eof()) {
+	if (line.substr(0, 16) == "/* okcircular */") {
+	  okcircular = true;
+	} else {
+	  string filename = check_include(line);
+	  if (!filename.empty() && filename.find('/') == string::npos) {
+	    Dependency dep;
+	    dep._okcircular = okcircular;
+	    dep._file = tree->find_dependable_file(filename);
+	    if (dep._file != (PPDependableFile *)NULL) {
+	      // All right!  Here's a file we depend on.  Add it to the
+	      // list.
+	      _dependencies.push_back(dep);
+	      
+	    } else {
+	      // It's an include file from somewhere else, not from within
+	      // our source tree.  We don't care about it, but we do need
+	      // to record it so we can easily check later if the cache
+	      // file has gone stale.
+	      _extra_includes.push_back(filename);
+	    }
 	  }
+	  okcircular = false;
 	}
-	okcircular = false;
+	getline(in, line);
       }
-      getline(in, line);
     }
   }
 
@@ -376,7 +376,6 @@ compute_dependencies(string &circularity) {
     }
   }
 
-
   _flags = (_flags & ~F_updating) | F_updated;
   return circ;
 }

+ 293 - 0
ppremake/ppScope.cxx

@@ -817,6 +817,24 @@ r_expand_variable(const string &str, size_t &vp,
       return expand_shell(params);
     } else if (funcname == "standardize") {
       return expand_standardize(params);
+    } else if (funcname == "length") {
+      return expand_length(params);
+    } else if (funcname == "substr") {
+      return expand_substr(params);
+    } else if (funcname == "dir") {
+      return expand_dir(params);
+    } else if (funcname == "notdir") {
+      return expand_notdir(params);
+    } else if (funcname == "suffix") {
+      return expand_suffix(params);
+    } else if (funcname == "basename") {
+      return expand_basename(params);
+    } else if (funcname == "word") {
+      return expand_word(params);
+    } else if (funcname == "wordlist") {
+      return expand_wordlist(params);
+    } else if (funcname == "words") {
+      return expand_words(params);
     } else if (funcname == "firstword") {
       return expand_firstword(params);
     } else if (funcname == "patsubst") {
@@ -1385,6 +1403,281 @@ expand_standardize(const string &params) const {
   return result;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_length
+//       Access: Private
+//  Description: Expands the "length" function variable.  This returns
+//               the length of the argument in characters.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_length(const string &params) const {
+  char buffer[32];
+  sprintf(buffer, "%d", params.length());
+  string result = buffer;
+  return result;
+}  
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_substr
+//       Access: Private
+//  Description: Expands the "substr" function variable.  $[substr
+//               S,E,string] returns the substring of "string"
+//               beginning at character S (1-based) and continuing to
+//               character E, inclusive.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_substr(const string &params) const {
+  // Split the string up into tokens based on the commas.
+  vector<string> tokens;
+  tokenize_params(params, tokens, true);
+
+  if (tokens.size() != 3) {
+    cerr << "wordlist requires three parameters.\n";
+    return string();
+  }
+
+  int start = atoi(tokens[0].c_str());
+  int end = atoi(tokens[1].c_str());
+
+  if (end < start) {
+    // Following GNU make's convention, we swap start and end if
+    // they're out of order.
+    int t = end;
+    end = start;
+    start = t;
+  }
+
+  const string &word = tokens[2];
+
+  start = max(start, 1);
+  end = min(end, (int)word.length());
+
+  if (end < start) {
+    return string();
+  }
+
+  string result = word.substr(start - 1, end - start + 1);
+  return result;
+}  
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_dir
+//       Access: Private
+//  Description: Expands the "dir" function variable.  This returns
+//               the directory part of its filename argument(s), or ./
+//               if the words contain no slash.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_dir(const string &params) const {
+  // Split the parameter into tokens based on the spaces.
+  vector<string> words;
+  tokenize_whitespace(expand_string(params), words);
+
+  vector<string>::iterator wi;
+  for (wi = words.begin(); wi != words.end(); ++wi) {
+    string &word = (*wi);
+
+    size_t slash = word.rfind('/');
+    if (slash != string::npos) {
+      word = word.substr(0, slash + 1);
+    } else {
+      word = "./";
+    }
+  }
+
+  string result = repaste(words, " ");
+  return result;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_notdir
+//       Access: Private
+//  Description: Expands the "notdir" function variable.  This returns
+//               everything following the rightmost slash, or the
+//               string itself if there is no slash.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_notdir(const string &params) const {
+  // Split the parameter into tokens based on the spaces.
+  vector<string> words;
+  tokenize_whitespace(expand_string(params), words);
+
+  vector<string>::iterator wi;
+  for (wi = words.begin(); wi != words.end(); ++wi) {
+    string &word = (*wi);
+
+    size_t slash = word.rfind('/');
+    if (slash != string::npos) {
+      word = word.substr(slash + 1);
+    }
+  }
+
+  string result = repaste(words, " ");
+  return result;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_suffix
+//       Access: Private
+//  Description: Expands the "suffix" function variable.  This returns
+//               the filename extension, including a dot, if any.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_suffix(const string &params) const {
+  // Split the parameter into tokens based on the spaces.
+  vector<string> words;
+  tokenize_whitespace(expand_string(params), words);
+
+  vector<string>::iterator wi;
+  for (wi = words.begin(); wi != words.end(); ++wi) {
+    string &word = (*wi);
+
+    size_t dot = word.rfind('.');
+    if (dot != string::npos) {
+      string ext = word.substr(dot);
+      if (ext.find('/') == string::npos) {
+	word = ext;
+      } else {
+	word = string();
+      }
+    } else {
+      word = string();
+    }
+  }
+
+  string result = repaste(words, " ");
+  return result;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_basename
+//       Access: Private
+//  Description: Expands the "basename" function variable.  This returns
+//               everything but the filename extension (including the
+//               directory, if any).
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_basename(const string &params) const {
+  // Split the parameter into tokens based on the spaces.
+  vector<string> words;
+  tokenize_whitespace(expand_string(params), words);
+
+  vector<string>::iterator wi;
+  for (wi = words.begin(); wi != words.end(); ++wi) {
+    string &word = (*wi);
+
+    size_t dot = word.rfind('.');
+    if (dot != string::npos) {
+      string ext = word.substr(dot);
+      if (ext.find('/') == string::npos) {
+	word = word.substr(0, dot);
+      }
+    }
+  }
+
+  string result = repaste(words, " ");
+  return result;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_word
+//       Access: Private
+//  Description: Expands the "word" function variable.  This returns
+//               the nth word, 1-based, of the space-separated list of
+//               words in the second parameter.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_word(const string &params) const {
+  // Split the string up into tokens based on the commas.
+  vector<string> tokens;
+  tokenize_params(params, tokens, true);
+
+  if (tokens.size() != 2) {
+    cerr << "word requires two parameters.\n";
+    return string();
+  }
+
+  int index = atoi(tokens[0].c_str());
+
+  // Split the second parameter into tokens based on the spaces.
+  vector<string> words;
+  tokenize_whitespace(expand_string(tokens[1]), words);
+
+  if (index < 1 || index > (int)words.size()) {
+    // Out of range.
+    return string();
+  }
+  return words[index - 1];
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_wordlist
+//       Access: Private
+//  Description: Expands the "wordlist" function variable.  This
+//               returns a range of words, 1-based, of the
+//               space-separated list of words in the third parameter.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_wordlist(const string &params) const {
+  // Split the string up into tokens based on the commas.
+  vector<string> tokens;
+  tokenize_params(params, tokens, true);
+
+  if (tokens.size() != 3) {
+    cerr << "wordlist requires three parameters.\n";
+    return string();
+  }
+
+  int start = atoi(tokens[0].c_str());
+  int end = atoi(tokens[1].c_str());
+
+  if (end < start) {
+    // Following GNU make's convention, we swap start and end if
+    // they're out of order.
+    int t = end;
+    end = start;
+    start = t;
+  }
+
+  // Split the third parameter into tokens based on the spaces.
+  vector<string> words;
+  tokenize_whitespace(expand_string(tokens[2]), words);
+
+  start = max(start, 1);
+  end = min(end, (int)words.size());
+
+  if (end < start) {
+    return string();
+  }
+
+  vector<string> results;
+  results.insert(results.end(), 
+		 words.begin() + start - 1, 
+		 words.begin() + end - 1);
+
+  string result = repaste(results, " ");
+  return result;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PPScope::expand_words
+//       Access: Private
+//  Description: Expands the "words" function variable.  This
+//               returns the number of space-separated words in the
+//               list.
+////////////////////////////////////////////////////////////////////
+string PPScope::
+expand_words(const string &params) const {
+  // Split the parameter into tokens based on the spaces.
+  vector<string> words;
+  tokenize_whitespace(expand_string(params), words);
+
+  char buffer[32];
+  sprintf(buffer, "%d", words.size());
+  string result = buffer;
+  return result;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PPScope::expand_firstword
 //       Access: Private

+ 9 - 0
ppremake/ppScope.h

@@ -87,6 +87,15 @@ private:
   string expand_bintest(const string &params) const;
   string expand_shell(const string &params) const;
   string expand_standardize(const string &params) const;
+  string expand_length(const string &params) const;
+  string expand_substr(const string &params) const;
+  string expand_dir(const string &params) const;
+  string expand_notdir(const string &params) const;
+  string expand_suffix(const string &params) const;
+  string expand_basename(const string &params) const;
+  string expand_word(const string &params) const;
+  string expand_wordlist(const string &params) const;
+  string expand_words(const string &params) const;
   string expand_firstword(const string &params) const;
   string expand_patsubst(const string &params) const;
   string expand_filter(const string &params) const;