Exemple #1
0
void saveContraintes(const QString& file, const Date& dateDebut, const Date& dateFin) {
    QFile newfile(file);
    if (!newfile.open(QIODevice::WriteOnly | QIODevice::Text))
        throw ToolsException("XmlParser erreur : impossible d'ouvrir le fichier !");
    QXmlStreamWriter stream(&newfile);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    ProgrammationManager::getInstance().exportContraintes(stream,dateDebut,dateFin);
    stream.writeEndDocument();
    newfile.close();
}
/*
** assumes that top of the stack is the `io' library, and next is
** the `io' metatable
*/
static void registerfile (lua_State *L, FILE *f, const char *name,
                                                 const char *impname) {
  lua_pushstring(L, name);
  *newfile(L) = f;
  if (impname) {
    lua_pushstring(L, impname);
    lua_pushvalue(L, -2);
    lua_settable(L, -6);  /* metatable[impname] = file */
  }
  lua_settable(L, -3);  /* io[name] = file */
}
Exemple #3
0
void saveProjetProgrammations(const QString& file, Projet& projet) {
    QFile newfile(file);
    if (!newfile.open(QIODevice::WriteOnly | QIODevice::Text))
        throw ToolsException("XmlParser erreur : impossible d'ouvrir le fichier !");
    QXmlStreamWriter stream(&newfile);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    projet.exportProgrammations(stream);
    stream.writeEndDocument();
    newfile.close();
}
Exemple #4
0
static void registerfile (lua_State *L, FILE *f, const char *name,
                                                 const char *impname) {
  lua_pushstring(L, name);
  newfile(L, f);
  if (impname) {
    lua_pushstring(L, impname);
    lua_pushvalue(L, -2);
    lua_settable(L, -6);
  }
  lua_settable(L, -3);
}
Exemple #5
0
/*
 * split1 --
 *	Split the input by bytes.
 */
void
split1(void)
{
	ssize_t bcnt, dist, len;
	char *C;

	for (bcnt = 0;;)
		switch ((len = read(ifd, bfr, MAXBSIZE))) {
		case 0:
			exit(0);
		case -1:
			err(EX_IOERR, "read");
			/* NOTREACHED */
		default:
			if (!file_open)
				newfile();
			if (bcnt + len >= bytecnt) {
				dist = bytecnt - bcnt;
				if (write(ofd, bfr, dist) != dist)
					err(EX_IOERR, "write");
				len -= dist;
				for (C = bfr + dist; len >= bytecnt;
				    len -= bytecnt, C += bytecnt) {
					newfile();
					if (write(ofd, C, bytecnt) != bytecnt)
						err(EX_IOERR, "write");
				}
				if (len != 0) {
					newfile();
					if (write(ofd, C, len) != len)
						err(EX_IOERR, "write");
				} else
					file_open = 0;
				bcnt = len;
			} else {
				bcnt += len;
				if (write(ofd, bfr, len) != len)
					err(EX_IOERR, "write");
			}
		}
}
Exemple #6
0
static void createstdfile(lua_State* L, FILE* f, int k, const char* fname)
{
	*newfile(L) = f;
	if (k > 0)
	{
		lua_pushvalue(L, -1);
		lua_rawseti(L, LUA_ENVIRONINDEX, k);
	}
	lua_pushvalue(L, -2);	 /* copy environment */
	lua_setfenv(L, -2);  /* set it */
	lua_setfield(L, -3, fname);
}
Exemple #7
0
static int io_popen (lua_State *L) {
#if !USE_POPEN
  luaL_error(L, "`popen' not supported");
  return 0;
#else
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  FILE **pf = newfile(L);
  *pf = lua_popen(L, filename, mode);
  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
#endif
}
Exemple #8
0
int test_dot(void)
{
    errorf("\n");   /* prints the function name */
    File *file = newfile("", ".");
    assert(strcmp(getname(file), ".") == 0);
    assert(strcmp(getpath(file), ".") == 0);
    char *dir = getdirname(file);
    assert(strcmp(dir, ".") == 0);
    free(dir);
    free(file);
    return 0;
}
Exemple #9
0
uint8_t write_core_image(void)
{
	inoptr parent = NULLINODE;
	inoptr ino;

	udata.u_error = 0;

	/* FIXME: need to think more about the case sp is lala */
	if (uput("core", (uint8_t *)udata.u_syscall_sp - 5, 5))
		return 0;

	ino = n_open((char *)udata.u_syscall_sp - 5, &parent);
	if (ino) {
		i_deref(parent);
		return 0;
	}
	if (parent) {
		i_lock(parent);
		if ((ino = newfile(parent, "core")) != NULL) {
			ino->c_node.i_mode = F_REG | 0400;
			setftime(ino, A_TIME | M_TIME | C_TIME);
			wr_inode(ino);
			f_trunc(ino);
#if 0
	/* FIXME address ranges for different models - move core writer
	   for address spaces into helpers ?  */
			/* FIXME: need to add some arch specific header bits, and
			   also pull stuff like the true sp and registers out of
			   the return stack properly */

			corehdr.ch_base = pagemap_base;
			corehdr.ch_break = udata.u_break;
			corehdr.ch_sp = udata.u_syscall_sp;
			corehdr.ch_top = PROGTOP;
			udata.u_offset = 0;
			udata.u_base = (uint8_t *)&corehdr;
			udata.u_sysio = true;
			udata.u_count = sizeof(corehdr);
			writei(ino, 0);
			udata.u_sysio = false;
			udata.u_base = (uint8_t *)pagemap_base;
			udata.u_count = udata.u_break - pagemap_base;
			writei(ino, 0);
			udata.u_base = udata.u_sp;
			udata.u_count = PROGTOP - (uint32_t)udata.u_sp;
			writei(ino, 0);
#endif
			i_unlock_deref(ino);
			return W_COREDUMP;
		}
	}
	return 0;
}
Exemple #10
0
int open(char *name, int flags, int mode, struct file **retval) {
  struct fs *fs;
  struct file *filp;
  int rc;
  char *rest;
  char path[MAXPATH];

  rc = canonicalize(name, path);
  if (rc < 0) return rc;

  rc = fslookup(path, 0, &fs, &rest);
  if (rc < 0) return rc;

  filp = newfile(fs, path, flags, mode);
  if (!filp) return -EMFILE;

  if (fs->ops->open) {
    fs->locks++;
    if (lock_fs(fs, FSOP_OPEN) < 0)  {
      fs->locks--;
      kfree(filp->path);
      kfree(filp);
      return -ETIMEOUT;
    }

    rc = fs->ops->open(filp, rest);
    if (rc == 0) {
      int access;

      if (filp->flags & O_RDWR) {
        access = S_IREAD | S_IWRITE;
      } else if (filp->flags & O_WRONLY) {
        access = S_IWRITE;
      } else {
        access = S_IREAD;
      }

      rc = check(filp->mode, filp->owner, filp->group, access);
    }

    unlock_fs(fs, FSOP_OPEN);

    if (rc != 0) {
      fs->locks--;
      kfree(filp->path);
      kfree(filp);
      return rc;
    }
  }

  *retval = filp;
  return 0;
}
Exemple #11
0
void Ut::newdir()
{
qDebug() << "newdir";
	if(read_cat())
	{
		newfile();
	}
	else
	{
		ui.convert->setDisabled(true);
		ui.convert->update();
	}
}
Exemple #12
0
void output(char *buf, int size, FILE **ofpp) {
  int bytes;
  if (*ofpp == NULL || bytes_written > byte_size )
    newfile(ofpp);

  bytes = fwrite(buf, 1, size, *ofpp);
  if (bytes < size) {
    fprintf(stderr, "Error while writing to '%s'\n", current_output_file);
    fprintf(stderr, "Error: %s\n", strerror(errno));
    exit(1);
  }
  bytes_written += bytes;
}
Exemple #13
0
static int io_accept (lua_State *L) {
  const char *port = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  FILE **pf = newfile(L);
  TCPSOCKET *sock;

  if ((sock = NutTcpCreateSocket()) != NULL) {
    if (NutTcpAccept(sock, (uint16_t)atoi(port)) == 0) {
      *pf = _fdopen((int) sock, mode);
    }
  }
  return (*pf == NULL) ? pushresult(L, 0, port) : 1;
}
Exemple #14
0
void ofApp::record(){
    ofFile newfile(ofToDataPath("coordinates.json"), ofFile::WriteOnly);
    string time = ofToString(ofGetElapsedTimef());
    for(Json::ValueIterator i = untimedData.begin() ; i != untimedData.end(); i++) {
        string id = i.key().asString();
        data[id][time]["position"] = untimedData[id]["position"];
        data[ofToString(id)][time]["rotation"] = untimedData[id]["rotation"];
        cout << data;
    }
    if (data != ofxJSONElement::null)
        newfile << data;
    sound.play();
}
Exemple #15
0
static int io_open(lua_State * L)
{
    const char *filename = luaL_checkstring(L, 1);
    const char *mode = luaL_optstring(L, 2, "rb");
    FILE **pf = newfile(L);
    *pf = fopen(filename, mode);
    if (*pf == NULL)
        return pushresult(L, 0, filename);
    if (mode[0]=='r') 
        recorder_record_input(filename);
    else
        recorder_record_output(filename);
    return 1;
}
bool PathManager::ReplacePakNameInJava(QString &srcPath, QString &fileName, QString &oldName, QString &newName)
{
	if (fileName.toLower().endsWith(".java")){
		QString regularEx = QString("(?<=(\\bpackage)|(\\bimport))[\\s\\t\\r\\n]+%1[\\s\\t\\r\\n]*;").arg(oldName);
		QString replaceName = QString(" ") + newName + ";";
		QFile file(fileName);
		if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
			return false;
		}
		QTextStream in(&file);
		in.setCodec("UTF-8");
		QString content;
		content = in.readAll();
		file.close();
		ReplaceByRegular(regularEx, content, replaceName);
		QString contentEx = QString("(?<=[({};])[\\s\\t\\r\\n]*%1\\.").arg(oldName);
		SPCRE *spcre = PCRECache::instance()->getObject(contentEx);
		QList<SPCRE::MatchInfo> match_info = spcre->getEveryMatchInfo(content);
		for (int i = match_info.count() - 1; i >= 0; i--)
		{
			QString replaced_text;
			bool replacement_made = spcre->replaceText(content.mid(match_info.at(i).offset.first, match_info.at(i).offset.second - match_info.at(i).offset.first), match_info.at(i).capture_groups_offsets, newName + ".", replaced_text);
			if (replacement_made) {
				int pos = content.indexOf(QRegExp("\\.|\\s"), match_info.at(i).offset.second);
				// Replace the text.
				if (pos < 0){
					continue;
				}
				QString classNm = content.mid(match_info.at(i).offset.second, pos - match_info.at(i).offset.second);
				QString packName = oldName;
				QFile javaClass(srcPath + "/src/" + packName.replace(".", "/") + "/" + classNm + ".java");
				if (javaClass.exists()){
					content = content.replace(match_info.at(i).offset.first, match_info.at(i).offset.second - match_info.at(i).offset.first, replaced_text);
				}
			}
		}

		if (!QFile::remove(fileName)){
			return false;
		}
		QFile newfile(fileName);
		if (!newfile.open(QIODevice::ReadWrite | QIODevice::Text)){
			return false;
		}
		newfile.write(content.toUtf8());
		newfile.close();
		return true;
	}
	return true;
}
Exemple #17
0
static int io_open_ro(lua_State * L)
{
    FILE **pf;
    const char *filename = luaL_checkstring(L, 1);
    const char *mode = luaL_optstring(L, 2, "rb");
    if ((strcmp(mode, "r") != 0) && (strcmp(mode, "rb") != 0))
        return pushresult(L, 0, filename);
    pf = newfile(L);
    *pf = fopen(filename, mode);
    if (*pf == NULL)
        return pushresult(L, 0, filename);
    recorder_record_input(filename);
    return 1;
}
Exemple #18
0
uint8_t write_core_image(void)
{
	inoptr parent = NULLINODE;
	inoptr ino;

	udata.u_error = 0;

	/* FIXME: need to think more about the case sp is lala */
	if (uput("core", udata.u_syscall_sp - 5, 5))
		return 0;

	ino = n_open(udata.u_syscall_sp - 5, &parent);
	if (ino) {
		i_deref(parent);
		return 0;
	}
	if (parent) {
		i_lock(parent);
		if (ino = newfile(parent, "core")) {
			ino->c_node.i_mode = F_REG | 0400;
			setftime(ino, A_TIME | M_TIME | C_TIME);
			wr_inode(ino);
			f_trunc(ino);

			/* FIXME: need to add some arch specific header bits, and
			   also pull stuff like the true sp and registers out of
			   the return stack properly */

			corehdr.ch_base = MAPBASE;
			corehdr.ch_break = udata.u_break;
			corehdr.ch_sp = udata.u_syscall_sp;
			corehdr.ch_top = PROGTOP;
			udata.u_offset = 0;
			udata.u_base = (uint8_t *)&corehdr;
			udata.u_sysio = true;
			udata.u_count = sizeof(corehdr);
			writei(ino, 0);
			udata.u_sysio = false;
			udata.u_base = MAPBASE;
			udata.u_count = udata.u_break - MAPBASE;
			writei(ino, 0);
			udata.u_base = udata.u_sp;
			udata.u_count = PROGTOP - (uint16_t)udata.u_sp;
			writei(ino, 0);
			i_unlock_deref(ino);
			return W_COREDUMP;
		}
	}
	return 0;
}
Exemple #19
0
void save(const QString& file){
    QFile newfile(file);
    if (!newfile.open(QIODevice::WriteOnly | QIODevice::Text))
        throw ToolsException("XmlParser erreur : impossible d'ouvrir le fichier !");
    QXmlStreamWriter stream(&newfile);
    stream.setAutoFormatting(true);
    stream.writeStartDocument();
    stream.writeStartElement("root");
    ProjetManager::getInstance().exportTo(stream);
    ProgrammationManager::getInstance().exportTo(stream);
    stream.writeEndElement();
    stream.writeEndDocument();
    newfile.close();
}
Exemple #20
0
static int zip_open (lua_State *L) {
  const char *zipfilename = luaL_checkstring(L, 1);
  /*const char *mode = luaL_optstring(L, 2, "r");*/

  ZZIP_DIR** pf = newfile(L);
  *pf = zzip_dir_open(zipfilename, 0);
  if (*pf == NULL)
  {
    lua_pushnil(L);
    lua_pushfstring(L, "could not open file `%s'", zipfilename);
    return 2;
  }
  return 1;
}
Exemple #21
0
void Ut::inpfilename()
{
qDebug() << "inpfilename";
	if (ui.LT2UT->isChecked()) 
	{	
		ui.label4->setText("maindata_lt.txt");
		read_dst();
	}
	else if (ui.ST2UT->isChecked()) ui.label4->setText("maindata_st.txt");
    else ui.label4->setText("maindata_jd.txt");

	ui.label4->update();
	newfile();	
}
Exemple #22
0
static int io_lines (lua_State *L) {
  if (lua_isnoneornil(L, 1)) {  /* no arguments? */
    lua_pushstring(L, IO_INPUT);
    lua_rawget(L, lua_upvalueindex(1));  /* will iterate over default input */
    return f_lines(L);
  }
  else {
    const char *filename = luaL_checkstring(L, 1);
    FILE **pf = newfile(L);
    *pf = fopen(filename, "r");
    luaL_argcheck(L, *pf, 1,  strerror(errno));
    aux_lines(L, lua_gettop(L), 1);
    return 1;
  }
}
Exemple #23
0
static int io_lines (lua_State *L) {
    if (lua_isnoneornil(L, 1)) {  /* no arguments? */
        /* will iterate over default input */
        LUA_IO_GETFIELD(IO_INPUT);
        return f_lines(L);
    } else {
        const char *filename = luaL_checkstring(L, 1);
        FILE **pf = newfile(L);
        *pf = fopen(filename, "r");
        if (*pf == NULL)
            fileerror(L, 1, filename);
        aux_lines(L, lua_gettop(L), 1);
        return 1;
    }
}
Exemple #24
0
static void opencheck (lua_State *L, const char *fname, const char *mode) {
  LStream *p = newfile(L);
  p->f = fopen(fname, mode);
  if (p->f == NULL) {
    luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno));
  } else {
#ifdef WIN32
    _setmode (fileno (p->f), _O_BINARY);
#endif
    if (mode[0]=='r') 
       recorder_record_input(fname);
    else
       recorder_record_output(fname);
  }
}
Exemple #25
0
int test_relative_file(void)
{
    errorf("\n");   /* prints the function name */
    File *file = newfile(".", "../tmp/foo");
    assert(strcmp(getname(file), "../tmp/foo") == 0);
    assert(strcmp(getpath(file), "./../tmp/foo") == 0);
    char *dir = getdirname(file);
    assert(strcmp(dir, "./../tmp") == 0);
    free(dir);
    char *base = getbasename(file);
    assert(strcmp(base, "foo") == 0);
    free(base);
    free(file);
    return 0;
}
Exemple #26
0
int test_bare_file(void)
{
    errorf("\n");   /* prints the function name */
    File *file = newfile(".", "buf.c");
    assert(strcmp(getname(file), "buf.c") == 0);
    assert(strcmp(getpath(file), "./buf.c") == 0);
    char *dir = getdirname(file);
    assert(strcmp(dir, ".") == 0);
    free(dir);
    char *base = getbasename(file);
    assert(strcmp(base, "buf.c") == 0);
    free(base);
    free(file);
    return 0;
}
Exemple #27
0
  bool File::rename (const String &name)
  {
    close();

    File newfile( name );
    CharString oldlongpath = "\\\\?\\" + getPathName();
    CharString newlongpath = "\\\\?\\" + newfile.getPathName();
    if (MoveFile( oldlongpath.buffer(), newlongpath.buffer() ) == TRUE)
    {
      this->path = newfile.path;
      this->name = newfile.name;
      return true;
    }
    else return false;
  }
Exemple #28
0
static int io_open (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  LStream *p = newfile(L);
  int i = 0;
  /* check whether 'mode' matches '[rwa]%+?b?' */
  if (!(mode[i] != '\0' && strchr("rwa", mode[i++]) != NULL &&
       (mode[i] != '+' || ++i) &&  /* skip if char is '+' */
       (mode[i] != 'b' || ++i) &&  /* skip if char is 'b' */
       (mode[i] == '\0')))
    return luaL_error(L, "invalid mode " LUA_QS
                         " (should match " LUA_QL("[rwa]%%+?b?") ")", mode);
  p->f = fopen(filename, mode);
  return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
}
Exemple #29
0
static void createstdfile (lua_State *L, FILE *f, int k, const char *fname) {
    *newfile(L) = f;
#if LUA_OPTIMIZE_MEMORY != 2
    if (k > 0) {
        lua_pushvalue(L, -1);
        lua_rawseti(L, LUA_ENVIRONINDEX, k);
    }
    lua_pushvalue(L, -2);  /* copy environment */
    lua_setfenv(L, -2);  /* set it */
    lua_setfield(L, -3, fname);
#else
    lua_pushvalue(L, -1);
    lua_rawseti(L, LUA_REGISTRYINDEX, liolib_keys[k]);
    lua_setfield(L, -2, fname);
#endif
}
Exemple #30
0
static int io_popen (lua_State *L) {
  const char *filename = luaL_checkstring(L, 1);
  const char *mode = luaL_optstring(L, 2, "r");
  FILE **pf = newfile(L);
#ifdef WIN32
  wchar_t wfilename[MAX_PATH+1];
  wchar_t wmode[10];
  MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, MAX_PATH+1);
  MultiByteToWideChar(CP_UTF8, 0, mode, -1, wmode, 10);
  *pf = _wpopen(wfilename, wmode);
#else
  // FIXME: this should probably be patched to translate UTF-8 strings to the local filesystem encoding on other systems
  *pf = lua_popen(L, filename, mode);
#endif
  return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
}