Пример #1
0
static int backup(BW *bw)
{
	if (!bw->b->backup && !nobackups && !bw->o.nobackup && bw->b->name && bw->b->name[0]) {
		char tmp[1024];
		char name[1024];

#ifdef __MSDOS__
		int x;

		if (backpath) {
			char *t = vsncpy(NULL,0,sz(backpath));
			t = canonical(t);
			joe_snprintf_2(name, SIZEOF(name), "%s/%s", t, namepart(tmp, SIZEOF(tmp), bw->b->name));
			vsrm(t);
		} else {
			joe_snprintf_1(name, SIZEOF(name), "%s", bw->b->name);
		}

		for (x = zlen(name); name[--x] != '.';) {
			if (name[x] == '\\' || (name[x] == ':' && x == 1) || x == 0) {
				x = zlen(name);
				break;
			}
		}

		zlcpy(name + x, SIZEOF(name) - x, ".bak");

#else

		/* Create backup file name */
		const char *simple_backup_suffix = getenv("SIMPLE_BACKUP_SUFFIX");
		
		if (simple_backup_suffix == NULL) {
			simple_backup_suffix = "~";
		}
		if (backpath) {
			char *t = vsncpy(NULL, 0, sz(backpath));
			t = canonical(t);
			joe_snprintf_3(name, SIZEOF(name), "%s/%s%s", t, namepart(tmp, SIZEOF(tmp), dequote(bw->b->name)), simple_backup_suffix);
			vsrm(t);
		} else {
			joe_snprintf_2(name, SIZEOF(name), "%s%s", dequote(bw->b->name), simple_backup_suffix);
		}
		
		/* Attempt to delete backup file first */
		unlink(name);

#endif

		/* Copy original file to backup file */
		if (cp(dequote(bw->b->name), name)) {
			return 1;
		} else {
			bw->b->backup = 1;
			return 0;
		}
	} else {
		return 0;
	}
}
Пример #2
0
////////////////////////////////////////////////////////////////////////////////
// / <from> / <to> / [<flags>]
bool Lexer::decomposeSubstitution (
  const std::string& text,
  std::string& from,
  std::string& to,
  std::string& flags)
{
  std::string parsed_from;
  std::string::size_type cursor = 0;
  if (readWord (text, "/", cursor, parsed_from) &&
      parsed_from.length ())
  {
    --cursor;
    std::string parsed_to;
    if (readWord (text, "/", cursor, parsed_to))
    {
      std::string parsed_flags = text.substr (cursor);
      if (parsed_flags.find ("/") == std::string::npos)
      {
        dequote (parsed_from, "/");
        dequote (parsed_to,   "/");

        from  = parsed_from;
        to    = parsed_to;
        flags = parsed_flags;
        return true;
      }
    }
  }

  return false;
}
Пример #3
0
std::vector<wxString> tokenize2(const std::string & line, const char delim) {
	std::string field;
	std::vector<wxString> ret;
	std::stringstream linestream(line);
	while(getline(linestream, field, delim))
		ret.emplace_back(dequote(field));
	return ret;
}
Пример #4
0
std::vector<std::string> tokenize(const std::string & line, const char delim) {
	std::string field;
	std::vector<std::string> fields;
	std::stringstream linestream(line);
	while(getline(linestream, field, delim))
		fields.emplace_back(dequote(field));
	return fields;
}
Пример #5
0
wxArrayString ArrayVariableProperty::read_cache() const {
	wxArrayString ret;
	const wxString name = GetLabel();
	const wxString dir = boost::filesystem::current_path().string();
	const wxString pathname = dir + '/' + name + ".csv";;
	std::fstream fs(pathname.c_str(), std::fstream::in);
	if (fs.fail()) return ret; // file not found
	std::string line;
	while (getline(fs, line)) {
		if (iscntrl(line.back())) line.pop_back(); // remove Microsoft return
		ret.Add(dequote(line));
	}
	fs.close();
	return ret;
}
Пример #6
0
 const strings
 split (strings&           se,
        const std::string& s,
        char               delimiter,
        bool               strip_quotes,
        bool               strip_whitespace,
        bool               empty)
 {
   std::stringstream ss(s);
   std::string       e;
   se.clear ();
   while (std::getline (ss, e, delimiter))
   {
     if (strip_whitespace)
       e = trim (e);
     if (strip_quotes)
       e = dequote (e);
     if (empty || !e.empty ())
     {
       se.push_back (e);
     }
   }
   return se;
 }
Пример #7
0
 static std::string index_for_table(std::string const& table, std::string const& field)
 {
     std::string table_trimmed = table;
     dequote(table_trimmed);
     return "\"idx_" + table_trimmed + "_" + field + "\"";
 }
Пример #8
0
static void doSetCompilerPath(const char * path, const char * includes, const char * libs, const char * tmpdir, unsigned targetCompiler, bool verbose)
{
    if (!includes)
        includes = INCLUDEPATH[targetCompiler];
    if (!libs)
        libs = LIB_DIR[targetCompiler];
    if (verbose)
    {
        PrintLog("Include directory set to %s", includes);
        PrintLog("Library directory set to %s", libs);
    }
    compilerRoot.set(path ? path : targetCompiler==GccCppCompiler ? "/usr" : ".\\CL");
    stdIncludes.set(includes);
    stdLibs.clear();
    for (;;)
    {
        StringBuffer thislib;
        while (*libs && *libs != ENVSEPCHAR)
            thislib.append(*libs++);
        if (thislib.length())
        {
            stdLibs.append(" ").append(USE_LIBPATH_FLAG[targetCompiler]).append(thislib).append(USE_LIBPATH_TAIL[targetCompiler]);
            if (USE_LIBRPATH_FLAG[targetCompiler])
                stdLibs.append(" ").append(USE_LIBRPATH_FLAG[targetCompiler]).append(thislib);
        }
        if (!*libs)
            break;
        libs++;
    }
    StringBuffer fname;
    if (path)
    {
        const char *finger = CC_NAME[targetCompiler];
        while (*finger)
        {
            if (*finger == '#')
                fname.append(path);
            else
                fname.append(*finger);
            finger++;
        }

#if defined(__linux__)
        StringBuffer clbin_dir;
        const char* dir_end = strrchr(fname, '/');
        if(dir_end == NULL)
            clbin_dir.append(".");
        else
            clbin_dir.append((dir_end - fname.str()) + 1, fname.str());
        
        StringBuffer pathenv(clbin_dir.str());
        const char* oldpath = getenv("PATH");
        if(oldpath != NULL && *oldpath != '\0')
        pathenv.append(":").append(oldpath);
        setenv("PATH", pathenv.str(), 1);
#endif
    }
    else
    {
        fname.append(compilerRoot).append(CC_NAME[targetCompiler]);
        fname.replaceString("#",NULL);
    }
    if (verbose)
        PrintLog("Compiler path set to %s", fname.str());

    dequote(fname);
#ifdef _WIN32
    if (_access(fname.str(), 4))
    {
#else
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
    struct stat filestatus;
    int r = stat(fname.str(), &filestatus);
    if (    (r != 0)
        ||  (!S_ISREG(filestatus.st_mode))
        ||  ((filestatus.st_mode&(S_IXOTH|S_IXGRP|S_IXUSR))==0))
    {
        if (r == -1) errno = ENOENT;
#endif
#endif
        if (verbose)
            PrintLog("SetCompilerPath - no compiler found");
        throw makeOsExceptionV(GetLastError(), "setCompilerPath could not locate compiler %s", fname.str());
    }

    if(tmpdir && *tmpdir)
    {
        //MORE: this should be done for the child process instead of the parent but invoke does not let me do it
#if defined(__linux__)
        setenv("TMPDIR", tmpdir, 1);
#endif

#ifdef _WIN32
        StringBuffer tmpbuf;
        tmpbuf.append("TMP=").append(tmpdir);
        _putenv(tmpbuf.str());
#endif
    }
}

//===========================================================================

class CCompilerThreadParam : public CInterface
{
public:
    CCompilerThreadParam(const StringBuffer & _cmdline, Semaphore & _finishedCompiling, const StringBuffer & _logfile) : cmdline(_cmdline), logfile(_logfile), finishedCompiling(_finishedCompiling) {};

    StringBuffer        cmdline;
    StringBuffer        logfile;
    Semaphore       &   finishedCompiling;
};

//===========================================================================

static void setDirectoryPrefix(StringAttr & target, const char * source)
{
    if (source && *source)
    {
        StringBuffer temp;
        target.set(addDirectoryPrefix(temp, source));
    }
}

CppCompiler::CppCompiler(const char * _coreName, const char * _sourceDir, const char * _targetDir, unsigned _targetCompiler, bool _verbose)
{
    coreName.set(_coreName);
    targetCompiler = _targetCompiler;
    createDLL = true;
#ifdef _DEBUG
    setDebug(true);
    setDebugLibrary(true);
#else
    setDebug(false);
    setDebugLibrary(false);
#endif
    
    setDirectoryPrefix(sourceDir, _sourceDir);
    setDirectoryPrefix(targetDir, _targetDir);
    maxCompileThreads = 1;
    onlyCompile = false;
    verbose = _verbose;
    saveTemps = false;
    abortChecker = NULL;
    precompileHeader = false;
    linkFailed = false;
}
Пример #9
0
void callmacro(const char * data)
{
	int numcm=reallycalledmacros++;
	macrodata * thisone;
	if (!confirmqpar(data)) merror("Broken macro usage");
	string line=data;
	clean(line);
	char * startpar=strqchr(line.str, '(');
	if (!startpar) merror("Broken macro usage");
	*startpar=0;
	startpar++;
	if (!confirmname(line)) merror("Bad macro name");
	if (!macros.find(line, thisone)) merror("Unknown macro");
	char * endpar=strqrchr(startpar, ')');
	if (endpar[1]) merror("Broken macro usage");
	*endpar=0;
	autoptr<const char **> args;
	int numargs=0;
	char *tmp_asd=strdup(startpar);
	if (*startpar) args=(const char**)qpsplit(tmp_asd, ",", &numargs);
	//free(tmp_asd);
	if (numargs!=thisone->numargs) merror("Wrong number of arguments to macro");
	macrorecursion++;
	int startif=numif;
	for (int i=0;i<thisone->numlines;i++)
	{
		try
		{
			thisfilename=thisone->fname;
			thisline=thisone->startline+i+1;
			thisblock=NULL;
			string out;
			string intmp=thisone->lines[i];
			for (char * in=intmp.str;*in;)
			{
				if (*in=='<' && in[1]=='<')
				{
					out+="<<";
					in+=2;
				}
				else if (*in=='<' && isalnum(in[1]))
				{
					char * end=in+1;
					while (*end && *end!='<' && *end!='>') end++;
					if (*end!='>')
					{
						out+=*(in++);
						continue;
					}
					*end=0;
					in++;
					if (!confirmname(in)) error<errline>(0, "Broken macro contents");
					bool found=false;
					for (int i=0;thisone->arguments[i];i++)
					{
						if (!strcmp(in, thisone->arguments[i]))
						{
							found=true;
							if (args[i][0]=='"')
							{
								string s=args[i];
								out+=dequote(s.str);
							}
							else out+=args[i];
							break;
						}
					}
					if (!found) error<errline>(0, "Unknown macro argument");
					in=end+1;
				}
				else out+=*(in++);
			}
			calledmacros=numcm;
			assembleline(thisone->fname, thisone->startline+i, out);
		}
		catch(errline&){}
	}
	macrorecursion--;
	if (repeatnext!=1)
	{
		thisblock=NULL;
		repeatnext=1;
		merror("rep or if at the end of a macro");
	}
	if (numif!=startif)
	{
		thisblock=NULL;
		numif=startif;
		numtrue=startif;
		merror("Unclosed if statement");
	}
}
Пример #10
0
void			GUI_Prefs_Read(const char *app_name)
{
	sPrefs.clear();
	string pref_dir;
	if (!GUI_GetPrefsDir(pref_dir)) return;
	pref_dir += DIR_STR;
    #if LIN
    pref_dir += ".";
    pref_dir +=  app_name;
    #else
	pref_dir += app_name;
    #endif
	pref_dir += ".prefs";
	MFMemFile* f = MemFile_Open(pref_dir.c_str());
	GUI_PrefSection_t * cur=NULL;
	if(f)
	{
		const char * p = MemFile_GetBegin(f);
		const char * e = MemFile_GetEnd(f);
		while(p<e)
		{
			skip_space(p,e);
			if(p<e && *p=='[')
			{
				++p;
				const char * cs = p;
				while(p<e && !is_eol(*p) && *p != ']')
					++p;
				string cur_name(cs,p);
				cur=&sPrefs[cur_name];
			}
			else if(p<e && *p != '\r' && *p != '\n')
			{
				const char * ks = p;
				while(p<e && !is_spc(*p) && !is_eol(*p) && *p != '=')
				{
					if (*p=='\\')	++p;
					if(p<e)			++p;
				}

				const char * ke = p;
				skip_space(p,e);
				if(p<e && *p=='=')
				{
					++p;
					skip_space(p,e);
					if(p<e)
					{
						const char * vs = p;
						while(p<e && !is_spc(*p) && !is_eol(*p) && *p != '=')
						{
							if (*p=='\\')	++p;
							if(p<e)			++p;
						}
						const char * ve = p;
						if(cur)
						{
							string key(ks,ke);
							string val(vs,ve);
							dequote(key);
							dequote(val);
							(*cur)[key] = val;
						}
					}
				}
			}
			skip_eol(p,e);
		}
		MemFile_Close(f);
	}

	#if DEBUG_PREFS
	for(GUI_Prefs_t::iterator s = sPrefs.begin(); s != sPrefs.end(); ++s)
	{
		printf("[%s]" CRLF, s->first.c_str());
		for(GUI_PrefSection_t::iterator p = s->second.begin(); p != s->second.end(); ++p)
			printf("'%s'='%s'" CRLF, p->first.c_str(), p->second.c_str());
	}
	#endif
}
Пример #11
0
struct netdev *get_configs() {
	int ncfgs = 0;
	struct netdev *ret, *tmpdev;
	struct dirent **cfgs;
	int x;
	
	ret = NULL;
	
	if ((ncfgs = scandir("/etc/sysconfig/network-scripts",&cfgs,
			     isCfg, alphasort)) == -1) {
		return ret;
	}
	for (x = 0; x < ncfgs; x++ ) {
		char *path;
		char *devname, *hwaddr;
		int vlan;
		gchar *contents, **lines;
		int i;
		
		devname = hwaddr = contents = NULL;
		lines = NULL;
		vlan = 0;
		if (asprintf(&path,"/etc/sysconfig/network-scripts/%s",
			     cfgs[x]->d_name) == -1)
			continue;
		g_file_get_contents(path, &contents, NULL, NULL);
		if (!contents)
			continue;
		lines = g_strsplit(contents,"\n", 0);
		for (i = 0; lines[i]; i++) {
			if (g_str_has_prefix(lines[i],"DEVICE=")) {
				devname = dequote(lines[i] + 7, NULL);
				/* ignore alias devices */
				if (strchr(devname,':'))
					devname = NULL;
			}
#if defined(__s390__) || defined(__s390x__)
			if (g_str_has_prefix(lines[i],"SUBCHANNELS=")) {
				hwaddr = dequote(lines[i] + 12, NULL);
			} else if (g_str_has_prefix(lines[i],"HWADDR=")) {
				hwaddr = dequote(lines[i] + 7, NULL);
			}
#else
			if (g_str_has_prefix(lines[i],"HWADDR=")) {
				hwaddr = dequote(lines[i] + 7, NULL);
			}
#endif
			if (g_str_has_prefix(lines[i],"VLAN=yes")) {
				vlan=1;
			}
		}
		if (!devname || !hwaddr || vlan) {
			g_free(contents);
			g_strfreev(lines);
			continue;
		}
		tmpdev = calloc(1, sizeof(struct netdev));
		tmpdev->dev = g_strstrip(g_strdup(devname));
		tmpdev->hwaddr = g_strstrip(g_strdup(hwaddr));
		if (ret)
			tmpdev->next = ret;
		ret = tmpdev;
		g_free(contents);
		g_strfreev(lines);
	}
	free(cfgs);
	return ret;
}