Esempio n. 1
0
/*---------------------------------------------------------------------*/
static int
loadline(lua_State *L)
{
	TRACE_LUA_FUNC_START();

        int status;
        lua_settop(L, 0);
        if (!pushline(L, 1)) {
		TRACE_LUA_FUNC_END();
                return -1;  /* no input */
	}
        for (;;) {  /* repeat until gets a complete line */
                status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
                if (!incomplete(L, status)) break;  /* cannot try to add lines? */
                if (!pushline(L, 0))  {/* no more input? */
			TRACE_LUA_FUNC_END();
                        return -1;
		}
                lua_pushliteral(L, "\n");  /* add a new line... */
                lua_insert(L, -2);  /* ...between the two lines */
                lua_concat(L, 3);  /* join them */
        }
	TRACE_DEBUG_LOG("%s\n", lua_tostring(L, 1));
	TRACE_LUA_FUNC_END();
        return status;
}
Esempio n. 2
0
static int loadline(lua_State *L) {
	int status;

	lua_settop(L, 0);
	if (!pushline(L, 1))
		return -1; /* no input */

	for (;;) { /* repeat until gets a complete line */
		size_t l;
		const char *line = lua_tolstring(L, 1, &l);

		status = luaL_loadbuffer(L, line, l, "=stdin");
		if (!incomplete(L, status))
			break; 					/* cannot try to add lines? */

		if (!pushline(L, 0)) 		/* no more input? */
			return -1;

		lua_pushliteral(L, "\n");	/* add a new line... */
		lua_insert(L, -2);			/* ...between the two lines */
		lua_concat(L, 3);			/* join them */
	}
	lua_saveline(L, 1);
	lua_remove(L, 1);				/* remove line */
	return status;
}
Esempio n. 3
0
static int loadline(lua_State *L)
{
	int status;
	lua_settop(L, 0);
	if(!pushline(L, 1))
	{
		return -1;        /* no input */
	}
	for(;;)     /* repeat until gets a complete line */
	{
		status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
		if(!incomplete(L, status))
		{
			break;        /* cannot try to add lines? */
		}
		if(!pushline(L, 0))   /* no more input? */
		{
			return -1;
		}
		lua_pushliteral(L, "\n");  /* add a new line... */
		lua_insert(L, -2);  /* ...between the two lines */
		lua_concat(L, 3);  /* join them */
	}
	lua_remove(L, 1);  /* remove line */
	return status;
}
Esempio n. 4
0
static int loadline(lua_State *L)
{
    int status;
    size_t len;
    const char *line;

    lua_settop(L, 0);
    if (!pushline(L, 1))
        return -1;  /* no input */

    line = lua_tolstring(L, 1, &len);

    if (strcmp (line, "exit") == 0)
        return -1;

    /* try to load the string as an expression */
    if (yield_expr(L, 1, line, len) == 0)
        return 0;

    /* try to load it as a simple Lua chunk */
    status = luaL_loadbuffer(L, line, len, "=stdin");

    if (incomplete(L, status))
    {
        for (;;) {  /* repeat until gets a complete line */
            if (!pushline(L, 0))  /* no more input? */
                return -1;
            lua_pushliteral(L, "\n");  /* add a new line... */
            lua_insert(L, -2);  /* ...between the two lines */
            lua_concat(L, 3);  /* join them */

            line = lua_tolstring(L, 1, &len);
            status = luaL_loadbuffer(L, line, len, "=stdin");
            if (!incomplete(L, status)) break;  /* cannot try to add lines? */
        }

        /* even if previous "load" was successfull we try to load the string as
        an expression */
        if (yield_expr(L, 1, line, len) == 0)
        {
            /* remove old eval function */
            lua_remove(L, 1);
            return 0;
        }
    }

    my_saveline(L, 1);
    lua_remove(L, 1);  /* remove line */
    return status;
}
Esempio n. 5
0
/* push an unreal line onto the undo stack
 * lp should be the new line, _after_ insertion, so
 *	lforw() and lback() are right
 */
int
tag_for_undo(LINE *lp)
{
    int status = FALSE;
    LINE *nlp;

    TRACE2((T_CALLED "tag_for_undo(%p)\n", lp));
    if (needundocleanup)
	preundocleanup();

    if (liscopied(lp)) {
	status = TRUE;
    } else if ((nlp = lalloc(LINENOTREAL, curbp)) == 0) {
	TRACE(("tag_for_undo: no memory\n"));
	status = ABORT;
    } else {
	set_lforw(nlp, lforw(lp));
	set_lback(nlp, lback(lp));

	pushline(nlp, BACKSTK(curbp));

	lsetcopied(lp);
	FORWDOT(curbp).l = lp;
	FORWDOT(curbp).o = DOT.o;

	status = TRUE;
    }
    return2Code(status);
}
Esempio n. 6
0
/*
 * Push a copy of a line onto the undo stack.  Push a patch so we can
 * later fix up any references to this line that might already be in the
 * stack.  When the undo happens, the later pops (i.e. those lines still
 * in the stack) will point at the _original_ (which will by then be on the
 * redo stack) instead of at the copy, which will have just been popped,
 * unless we fix them by popping and using the patch.
 */
int
copy_for_undo(LINE *lp)
{
    int status = FALSE;
    LINE *nlp;

    TRACE2((T_CALLED "copy_for_undo(%p)\n", lp));
    if (needundocleanup)
	preundocleanup();

    if (liscopied(lp)) {
	status = TRUE;
    } else if ((nlp = copyline(lp)) == 0) {
	status = ABORT;
    } else {
	/* take care of the normal undo stack */
	pushline(nlp, BACKSTK(curbp));

	make_undo_patch(lp, nlp);

	lsetcopied(lp);

	setupuline(lp);

	FORWDOT(curbp).l = lp;
	FORWDOT(curbp).o = DOT.o;

	status = TRUE;
    }
    return2Code(status);
}
Esempio n. 7
0
bool PositionData::next()
{
    if (eof() || linesRead > totalLines - skip) return false;
    popline();
    pushline();
    return true;
}
static int loadline (lua_State *L) {
  int status;
  lua_settop(L, 0);
  if (!pushline(L, 1))
    return -1;
  for (;;) {
    status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
    if (!incomplete(L, status)) break;
    if (!pushline(L, 0))
      return -1;
    lua_pushliteral(L, "\n");
    lua_insert(L, -2);
    lua_concat(L, 3);
  }
  lua_saveline(L, 1);
  lua_remove(L, 1);
  return status;
}
Esempio n. 9
0
/*
** Read a line and try to load (compile) it first as an expression (by
** adding "return " in front of it) and second as a statement. Return
** the final status of load/call with the resulting function (if any)
** in the top of the stack.
*/
static int loadline (lua_State *L) {
  int status;
  lua_settop(L, 0);
  if (!pushline(L, 1))
    return -1;  /* no input */
  if ((status = addreturn(L)) != LUA_OK)  /* 'return ...' did not work? */
    status = multiline(L);  /* try as command, maybe with continuation lines */
  lua_remove(L, 1);  /* remove line from the stack */
  lua_assert(lua_gettop(L) == 1);
  return status;
}
Esempio n. 10
0
/*
** Read multiple lines until a complete Lua statement
*/
static int multiline (lua_State *L) {
  for (;;) {  /* repeat until gets a complete statement */
    size_t len;
    const char *line = lua_tolstring(L, 1, &len);  /* get what it has */
    int status = luaL_loadbuffer(L, line, len, "=stdin");  /* try it */
    if (!incomplete(L, status) || !pushline(L, 0))
      return status;  /* cannot or should not try to add continuation line */
    lua_pushliteral(L, "\n");  /* add newline... */
    lua_insert(L, -2);  /* ...between the two lines */
    lua_concat(L, 3);  /* join them */
  }
}
Esempio n. 11
0
void PositionData::init()
{
    string inDataFile = Options::get(Options::VariantData);
    totalLines = getLineCount(inDataFile);
    ignore(2560,'\n');
    linesRead++;

    //uint skip = atoi(inDataFile.c_str());
    if (skip > 0)
    {
        if (totalLines < 2*skip + 2*windowSize +1) return;
        for (uint i = 0 ; i < skip ; i++ )
        {
            ignore(2560,'\n');
            linesRead++;
        }
    }

    for (uint i = 0 ; i < 2*windowSize+1 ; i++ )
    {
        pushline();
    }
}
Esempio n. 12
0
/* push a deleted line onto the undo stack. */
void
toss_to_undo(LINE *lp)
{
    LINE *next;
    LINE *prev;
    int fc;

    TRACE2((T_CALLED "toss_to_undo(%p)\n", lp));
    if (needundocleanup)
	preundocleanup();

    pushline(lp, BACKSTK(curbp));

    next = lforw(lp);

    /* need to save a dot -- either the next line or
       the previous one */
    if (next == buf_head(curbp)) {
	prev = lback(lp);
	FORWDOT(curbp).l = prev;
	fc = firstchar(prev);
	if (fc < 0)		/* all white */
	    FORWDOT(curbp).o = llength(prev) - 1;
	else
	    FORWDOT(curbp).o = fc;
    } else {
	FORWDOT(curbp).l = next;
	fc = firstchar(next);
	if (fc < 0)		/* all white */
	    FORWDOT(curbp).o = b_left_margin(curbp);
	else
	    FORWDOT(curbp).o = fc;
    }

    dumpuline(lp);
    return2Void();
}
Esempio n. 13
0
void
pushlineoredit(void)
{
    int ics;
    unsigned char *s;
    char *hline = hgetline();

    if (zmult < 0)
	return;
    if (hline && *hline) {
	ics = ztrlen(hline);
	sizeline(ics + ll + 1);
	for (s = line + ll; --s >= line; *(s + ics) = *s);
	for (s = line; *hline; hline++)
	    *s++ = *hline == Meta ? *++hline ^ 32 : *hline;
	ll += ics;
	cs += ics;
    }
    pushline();
    if (!isfirstln) {
	errflag = done = 1;
    }
    clearlist = 1;
}
Esempio n. 14
0
/**
 * Parse key/value pairs from the configuration file
 */
void config::parse_file() {
  vector<pair<int, string>> lines;
  vector<string> files{m_file};

  std::function<void(int, string&&)> pushline = [&](int lineno, string&& line) {
    // Ignore empty lines and comments
    if (line.empty() || line[0] == ';' || line[0] == '#') {
      return;
    }

    string key, value;
    string::size_type pos;

    // Filter lines by:
    // - key/value pairs
    // - section headers
    if ((pos = line.find('=')) != string::npos) {
      key = forward<string>(string_util::trim(forward<string>(line.substr(0, pos))));
      value = forward<string>(string_util::trim(line.substr(pos + 1)));
    } else if (line[0] != '[' || line[line.length() - 1] != ']') {
      return;
    }

    if (key == "include-file") {
      auto file_path = file_util::expand(value);
      if (file_path.empty() || !file_util::exists(file_path)) {
        throw value_error("Invalid include file \"" + file_path + "\" defined on line " + to_string(lineno));
      }
      if (std::find(files.begin(), files.end(), file_path) != files.end()) {
        throw value_error("Recursive include file \"" + file_path + "\"");
      }
      files.push_back(file_util::expand(file_path));
      m_log.trace("config: Including file \"%s\"", file_path);
      for (auto&& l : string_util::split(file_util::contents(file_path), '\n')) {
        pushline(lineno, forward<string>(l));
      }
      files.pop_back();
    } else {
      lines.emplace_back(make_pair(lineno, line));
    }
  };

  int lineno{0};
  string line;
  std::ifstream in(m_file);
  while (std::getline(in, line)) {
    pushline(++lineno, string_util::replace_all(line, "\t", ""));
  }

  string section;
  for (auto&& l : lines) {
    auto& lineno = l.first;
    auto& line = l.second;

    // New section
    if (line[0] == '[' && line[line.length() - 1] == ']') {
      section = line.substr(1, line.length() - 2);
      continue;
    } else if (section.empty()) {
      continue;
    }

    size_t equal_pos;

    // Check for key-value pair equal sign
    if ((equal_pos = line.find('=')) == string::npos) {
      continue;
    }

    string key{forward<string>(string_util::trim(forward<string>(line.substr(0, equal_pos))))};
    string value;

    auto it = m_sections[section].find(key);
    if (it != m_sections[section].end()) {
      throw key_error("Duplicate key name \"" + key + "\" defined on line " + to_string(lineno));
    }

    if (equal_pos + 1 < line.size()) {
      value = forward<string>(string_util::trim(line.substr(equal_pos + 1)));
      size_t len{value.size()};
      if (len > 2 && value[0] == '"' && value[len - 1] == '"') {
        value.erase(len - 1, 1).erase(0, 1);
      }
    }

#if WITH_XRM
    // Initialize the xresource manage if there are any xrdb refs
    // present in the configuration
    if (!m_xrm && value.find("${xrdb") != string::npos) {
      m_xrm.reset(new xresource_manager{connection::make()});
    }
#endif

    m_sections[section].emplace_hint(it, move(key), move(value));
  }
}