run_scc = a.run_scc;
tail_calls = !a.no_tail_calls;
-
- char *f;
+ std::string f;
if (strcmp(_filename,"stdin") == 0) {
curfile = stdin;
- f = strdup(_filename);
+ f = std::string(_filename);
}
else {
if (prev_curfile) {
- f = strdup(prev_filename);
+ f = std::string(prev_filename);
#ifdef _MSC_VER
std::string str( f );
for( int n=str.length(); n>=0; n-- ){
}
char *tmp = (char*)str.c_str();
#else
- char *tmp = dirname(f);
+ // Note: dirname may modify its argument, so we create a non-const copy.
+ char *f_copy = strdup(f.c_str());
+ std::string str = std::string(dirname(f_copy));
+ free(f_copy);
#endif
- delete f;
- f = new char[strlen(tmp) + 10 + strlen(_filename)];
- strcpy(f,tmp);
- strcat(f,"/");
- strcat(f,_filename);
+ f = str + std::string("/") + std::string(_filename);
+ } else {
+ f = std::string(_filename);
}
- else
- f = strdup(_filename);
- curfile = fopen(f,"r");
+ curfile = fopen(f.c_str(), "r");
if (!curfile)
- report_error(string("Could not open file \"")
- + string(f)
- + string("\" for reading.\n"));
+ report_error(string("Could not open file \"") + f +
+ string("\" for reading.\n"));
}
linenum = 1;
colnum = 1;
- filename = f;
+ filename = f.c_str();
char c;
while ((c = non_ws()) && c!=EOF ) {
}
}
}
- free(f);
if (curfile != stdin)
fclose(curfile);
linenum = prev_linenum;
#ifndef sc2__trie_h
#define sc2__trie_h
-#include <vector>
-#include <string.h>
+#include <assert.h>
#include <stdlib.h>
+#include <string.h>
+#include <vector>
template<class Data>
class Trie {
// s is assumed to be non-empty (and non-null)
Data insert_next(const char *s, const Data &x) {
+ assert(s != NULL && s[0] != '\0');
unsigned c = s[0];
if (c >= next.size()) {
using_next = true;
// s is assumed to be non-empty (and non-null)
Data get_next(const char *s) {
+ assert(s != NULL && s[0] != '\0');
unsigned c = s[0];
if (c >= next.size())
return Data();
static Cleaner *cleaner;
- bool eqstr(const char *s1, const char *s2) {
- while (*s1 && *s2) {
- if (*s1++ != *s2++)
- return false;
- }
- return (*s1 == *s2);
- }
-
Data get(const char *s) {
if (!s[0] && (!str || !str[0]))
return d;
- if (str && eqstr(str,s))
- return d;
+ if (str && strcmp(str, s) == 0) return d;
if (using_next)
return get_next(s);
return Data();