Example #1
0
int fs_insert(FileSystem *fs, const char *f, int pos, int l, const char *data) {
    Inode *inode = NULL;
    char *buffer = NULL;
    File *file = NULL;
    int i = 0;
    
    inode = folder_lookup(fs, fs->cur, f);
    if (!inode) return ERROR;
    buffer = (char *) malloc(inode->filesize + l);
    if (!buffer) return ERROR;
    file = file_new(fs, inode);
    file_get_contents(file, buffer);
    file_free(&file);
    if (pos > inode->filesize) {
        pos = inode->filesize;
    }
    for (i = inode->filesize - 1; i >= pos; --i) {
        buffer[i + l] = buffer[i];
    }
    memcpy(buffer + pos, data, l);
    file = file_new(fs, inode);
    file_put_contents(file, buffer, inode->filesize + l);
    file_free(&file);
    free(buffer);
    return OK;
}
Example #2
0
static ssize_t data_file_t_convert_from(data_t *data, fastcall_convert_from *fargs){ // {{{
	ssize_t                ret;
	
	if(fargs->src == NULL)
		return -EINVAL; 
		
	switch(fargs->format){
		case FORMAT(config):;
		case FORMAT(human):;
		case FORMAT(native):;
			request_t r_config[] = {
				{ HK(filename), *fargs->src },
				hash_end
			};
			return file_new((file_t **)&data->ptr, r_config);

		case FORMAT(hash):;
			hash_t            *config;
			
			data_get(ret, TYPE_HASHT, config, fargs->src);
			if(ret != 0)
				return -EINVAL;
			
			return file_new((file_t **)&data->ptr, config);
			
		default:
			break;
	};
	return -ENOSYS;
} // }}}
Example #3
0
int fs_delete(FileSystem *fs, const char *f, int pos, int l) {
    Inode *inode = NULL;
    char *data = NULL;
    File *file = NULL;
    int i = 0;
    
    inode = folder_lookup(fs, fs->cur, f);
    if (!inode) return ERROR;
    data = (char *) malloc(inode->filesize);
    if (!data) return ERROR;
    file = file_new(fs, inode);
    file_get_contents(file, data);
    file_free(&file);
    if (pos + l > inode->filesize) {
        l = inode->filesize - pos;
    }
    for (i = pos + l; i < inode->filesize; ++i) {
        data[i - l] = data[i];
    }
    file = file_new(fs, inode);
    file_put_contents(file, data, inode->filesize - l);
    file_free(&file);
    free(data);
    return OK;
}
Example #4
0
static int set_state_letter(int argc, char *argv[])
{
	/* 
	 * [0]   [1]       [2]    [3]       [4]
	 * y3act set-state <file> <part-id> <state letter> 
	 */
	
	if (!(strcmp(".", argv[4]) == 0 || strcmp(">", argv[4]) == 0 || strcmp("$", argv[4]) == 0)) {
		fprintf(stderr, "ERROR: Invalid state letter: '%s'\n", argv[4]);
		display_state_letter();
		return 1;
	}

	struct task tasks;
	INIT_LIST_HEAD(&tasks.list);
	if (file_read(&tasks, argv[2]) == -1)
		return 1;

	struct task *t;
	int ret	= find_task(&tasks, &t, argv[3], strlen(argv[3]));
	if (1 != ret) {
		free_tasks(&tasks);
		return 1;
	}
	strcpy(t->state, argv[4]);
	ret = file_new(&tasks, argv[2]); 
	free_tasks(&tasks);
	return ret;
}
Example #5
0
int file_create( const char *path)
{
	t_file *file = file_new( path);
	int ret = file_make( file);
	file_free( file);
	return ret;
}
Example #6
0
/* Randomly select something to do with a directory */
static void operate_on_dir(struct dir_info *dir)
{
	size_t r;
	struct dir_entry_info *entry;
	struct file_info *file;

	r = tests_random_no(14);
	if (r == 0 && grow)
		/* When growing, 1 time in 14 create a file */
		file_new(dir, make_name(dir));
	else if (r == 1 && grow)
		/* When growing, 1 time in 14 create a directory */
		dir_new(dir, make_name(dir));
	else if (r == 2 && grow && (file = pick_file()) != NULL)
		/* When growing, 1 time in 14 create a hard link */
		link_new(dir, make_name(dir), file);
	else if (r == 3 && grow && tests_random_no(5) == 0)
		/* When growing, 1 time in 70 create a symbolic link */
		symlink_new(dir, make_name(dir));
	else {
		/* Otherwise randomly select an entry to operate on */
		r = tests_random_no(dir->number_of_entries);
		entry = dir->first;
		while (entry && r) {
			entry = entry->next;
			--r;
		}
		if (entry)
			operate_on_entry(entry);
	}
}
Example #7
0
File: ar.c Project: z88dk/z88dk
int main(int argc, char *argv[])
{
	opt_obj_list = true;
	opt_obj_hide_local = true;
	opt_obj_hide_expr = true;
	opt_obj_hide_code = true;

	int 	opt;
	while ((opt = getopt(argc, argv, "leca")) != -1) {
		switch (opt) {
		case 'l': opt_obj_hide_local = false; break;
		case 'e': opt_obj_hide_expr = false; break;
		case 'c': opt_obj_hide_code = false; break;
		case 'a': opt_obj_hide_local = opt_obj_hide_expr = opt_obj_hide_code = false; break;
		default:
			usage(argv[0]);
			return 0;
		}
	}

	if ( optind == argc ) 
		usage(argv[0]);

	while (optind < argc) {
		char *filename = argv[optind++];
		file_t *file = file_new();
		file_read(file, filename);
		file_free(file);
	}
}
Example #8
0
void sumfile(char *name)
{
	autofile *af;

	af = file_new(name);
	if(!af) return;

	if(!af->size) return;

	if(!file_initbuf(af, BUFSIZE)) {
		fprintf(stderr, "Couldn't initialise a read buffer\n");
		return;
	}

	file_readhook(af, my_hook);
	MD5Init(&context);

	while(af->pos < af->size) {
		file_read(af, BUFSIZE);
	}
	MD5Final(key1, &context);
	MD5Ascii(key1, key2);
	printf("%s %s%s\n", key2, binary, af->name);
	file_free(af);
}
Example #9
0
void image_get_filename( const char *path, char *name)
{
	t_file *file = file_new( path);
	file_init( file);
	s_cp( name, file->file_name, _NAME_);
	file_free( file);
}
Example #10
0
t_image *image_open( const char *path)
{
	t_image *image = NULL;
	t_file *file = file_new( path);
	file_init( file);

	if( is( file->ext, "jpg"))
	{
		#ifdef HAVE_JPG
	     	image = img_read_jpg( path);
		#else
		printf("[WARNING] image_open: JPG not enabled\n");
		#endif
	}
	else if( is( file->ext, "png"))
	{
		#ifdef HAVE_PNG
	       	image = img_read_png( path);
		#else
		printf("[WARNING] image_open: PNG not enabled\n");
		#endif
	}
	else printf("[WARNING] image_open, unknown image type:%s\n", file->ext);

	file_free( file);

	return image;
}
Example #11
0
/* convert locale alias to canonical name using LOCALE_ALIAS_FILE (presumably
   /usr/share/locale/locale.alias) and return it

   Returned string should be freed by caller.

   FIXME: this function can get easily confused by lines longer than BUFSIZE
   (but the worst thing that can happen is we return wrong locale name)
   the locale.alias format is nowhere described, so we assume every line
   consists of alias (row 1), some whitespace and canonical name */
static char*
locale_alias_convert(const char *locname)
{
#ifdef HAVE_LOCALE_ALIAS
  File *fla; /* locale.alias file */
  Buffer *buf;
  char *s,*p,*q;
  size_t n;
#endif /* HAVE_LOCALE_ALIAS */

  if (!locname)
    return NULL;

  /* Catch the special language name `none' */
  if (strcmp(locname, "none") == 0)
    return enca_strdup("__");

#ifdef HAVE_LOCALE_ALIAS
  /* try to read locale.alias */
  buf = buffer_new(0);
  fla = file_new(LOCALE_ALIAS_PATH, buf);
  if (file_open(fla, "r") != 0) {
    if (options.verbosity_level) {
      fprintf(stderr, "Cannot find locale.alias file.\n"
                      "This build of enca probably has been configured for "
                      "quite a different system\n");
    }
    file_free(fla);
    buffer_free(buf);
    return enca_strdup(locname);
  }

  /* scan locale.alias
     somewhat crude now */
  n = strlen(locname);
  p = NULL;
  s = (char*)buf->data; /* alias */
  while (file_getline(fla) != NULL) {
    if (strncmp(s, locname, n) == 0 &&
        (isspace(s[n]) || (s[n] == ':' && isspace(s[n+1])))) {
      p = s + n;
      /* skip any amount of whitespace */
      while (isspace(*p)) p++;
      q = p;
      /* anything up to next whitespace is the canonical locale name */
      while (*q != '\0' && !isspace(*q)) q++;
      *q = '\0';
      p = enca_strdup(p);
      break;
    }
  }
  file_close(fla);
  file_free(fla);

  buffer_free(buf);
  return p != NULL ? p : static_iso639_alias_convert(locname);
#else /* HAVE_LOCALE_ALIAS */
  return static_iso639_alias_convert(locname);
#endif /* HAVE_LOCALE_ALIAS */
}
Example #12
0
File: fopen.c Project: hxhlb/GridOS
DLLEXPORT FILE *fopen(const char *path, const char *type)
{
	struct file *filp;
	struct stdio_file *file;
	
	filp = file_new(sizeof(struct stdio_file));
	if (!filp)
		goto err;
	file = file_get_detail(filp);
	memset(file, 0, sizeof(struct stdio_file));
	
	if (false == set_file_flags(file, type))
	{
		set_errno(EINVAL);
		goto err;
	}	
	if (KE_INVALID_HANDLE == file_open(filp, path, file->flags))
		goto err;	
	stream_file_init_ops(filp);
	
	return (FILE*)file;
	
err:
	if (filp)
		file_delete(filp);
	return NULL;
}
Example #13
0
File: vis.c Project: ewqasd200g/vis
static File *file_new_internal(Vis *vis, const char *filename) {
	File *file = file_new(vis, filename);
	if (file) {
		file->refcount = 1;
		file->internal = true;
	}
	return file;
}
Example #14
0
int file_get_info_by_id(mdb_conn *conn, int id, char *url, int pid, file_t **file)
{
    char mmckey[LEN_MMC_KEY];
    file_t *fl;
    size_t datalen;
    char *buf;
    int ret;
    
    if (id < 0 && (url == NULL || pid < 0))    return RET_RBTOP_INPUTE;

    if (id <= 0)
        snprintf(mmckey, LEN_MMC_KEY, "%s.%d.%s", PRE_MMC_FILE, pid, url);
    else
        snprintf(mmckey, LEN_MMC_KEY, "%s.%d", PRE_MMC_FILE, id);
    buf = mmc_get(mmckey, &datalen, 0);
    if (buf == NULL || datalen < sizeof(file_t)) {
        if (buf != NULL && datalen < sizeof(file_t)) {
            mtc_warn("get %d %d.%s info error from mmc %d",
                     id, pid, url, datalen);
        }
        if (mdb_get_errcode(conn) != MDB_ERR_NONE) {
            mtc_err("conn err %s", mdb_get_errmsg(conn));
            return RET_RBTOP_INPUTE;
        }
        fl = file_new();
        if (fl == NULL) return RET_RBTOP_MEMALLOCE;
        if (id <= 0) {
            LDB_QUERY_RAW(conn, "fileinfo", FILE_QUERY_COL,
                          "pid=%d AND name=$1", "s", pid, url);
        } else {
            LDB_QUERY_RAW(conn, "fileinfo", FILE_QUERY_COL,
                          "id=%d", NULL, id);
        }
        ret = FILE_GET_RAW(conn, fl);
        if (ret != MDB_ERR_NONE) {
            mtc_err("get %d %d.%s info failure from db %s",
                    id, pid, url, mdb_get_errmsg(conn));
            if (ret == MDB_ERR_NORESULT)
                return RET_RBTOP_NEXIST;
            return RET_RBTOP_SELECTE;
        } else {
            file_pack(fl, &buf, &datalen);
            mmc_store(MMC_OP_SET, mmckey, (void*)buf, datalen, ONE_HOUR, 0);
        }
    } else {
        ret = file_unpack(buf, datalen, &fl, NULL);
        if (ret != RET_RBTOP_OK) {
            mtc_err("assembly file from mmc error");
            return RET_RBTOP_MMCERR;
        }
    }
    free(buf);
    *file = fl;
    return RET_RBTOP_OK;
}
Example #15
0
int fs_write(FileSystem *fs, const char *f, int l, const char *data) {
    Inode *inode = NULL;
    File *file = NULL;
    
    inode = folder_lookup(fs, fs->cur, f);
    if (!inode) return ERROR;
    file = file_new(fs, inode);
    file_put_contents(file, data, l);
    file_free(&file);
    return OK;
}
Example #16
0
File: misc.c Project: MicBosi/GTS
/**
 * gts_file_new:
 * @fp: a file pointer.
 *
 * Returns: a new #GtsFile.
 */
GtsFile * gts_file_new (FILE * fp)
{
  GtsFile * f;

  g_return_val_if_fail (fp != NULL, NULL);

  f = file_new ();
  f->fp = fp;
  gts_file_next_token (f);

  return f;
}
Example #17
0
File: vis.c Project: 5paceToast/vis
bool vis_window_new(Vis *vis, const char *filename) {
	File *file = file_new(vis, filename);
	if (!file)
		return false;
	Win *win = window_new_file(vis, file, UI_OPTION_STATUSBAR);
	if (!win) {
		file_free(vis, file);
		return false;
	}

	return true;
}
Example #18
0
/******************************************************
 Create a new character based on the specified template
 return the id of the newly created character
 the returned string MUST BE FREED by caller
 return nullptr if fails
 *******************************************************/
char * character_create_from_template(context_t * ctx, const char * my_template,
		const char * map, int layer, int x, int y)
{
	char * new_id;

	new_id = file_new(CHARACTER_TABLE, nullptr);
	if (file_copy(CHARACTER_TEMPLATE_TABLE, my_template, CHARACTER_TABLE,
			new_id) == false)
	{
		file_delete(CHARACTER_TABLE, new_id);
		return nullptr;
	}

	// Check if new character is allowed to be created here
	if (map_check_tile(ctx, new_id, map, layer, x, y) == 0)
	{
		entry_destroy(CHARACTER_TABLE, new_id);
		file_delete(CHARACTER_TABLE, new_id);
		free(new_id);
		return nullptr;
	}

	// Write position
	if (entry_write_string(CHARACTER_TABLE, new_id, map, CHARACTER_KEY_MAP,
			nullptr) == RET_NOK)
	{
		entry_destroy(CHARACTER_TABLE, new_id);
		file_delete(CHARACTER_TABLE, new_id);
		free(new_id);
		return nullptr;
	}

	if (entry_write_int(CHARACTER_TABLE, new_id, x, CHARACTER_KEY_POS_X,
			nullptr) == RET_NOK)
	{
		entry_destroy(CHARACTER_TABLE, new_id);
		file_delete(CHARACTER_TABLE, new_id);
		free(new_id);
		return nullptr;
	}

	if (entry_write_int(CHARACTER_TABLE, new_id, y, CHARACTER_KEY_POS_Y,
			nullptr) == RET_NOK)
	{
		entry_destroy(CHARACTER_TABLE, new_id);
		file_delete(CHARACTER_TABLE, new_id);
		free(new_id);
		return nullptr;
	}

	return new_id;
}
Example #19
0
bool editor_window_reload(Win *win) {
	const char *filename = text_filename_get(win->file->text);
	/* can't reload unsaved file */
	if (!filename)
		return false;
	File *file = file_new(win->editor, filename);
	if (!file)
		return false;
	file_free(win->editor, win->file);
	win->file = file;
	view_reload(win->view, file->text);
	return true;
}
Example #20
0
int main()
{
    FILE * input = file_new("input.txt","r");
    FILE * output = file_new("output.txt","w");
    char buffer[100000];
    sentence_t * sentence;
    word_t * word;
    fread(buffer,1,100000,input);
    text_t * text = text_new(buffer);
    removeSymbols(buffer);
    text_divide(text);
    int sentences_count = text_getSentencesCount(text);
    for (int i = 0; i < sentences_count; i++)
    {
        sentence = text_getSentence(text,i);
        sentence_divide(sentence);
        int words_count = sentence_getWordsCount(sentence);
        if (words_count < 5) sentence_deleteSentence(sentence);
        else {

                for (int j = 0; j < words_count; j++)
                {
                    word = sentence_getWords(sentence,j);
                    if (word_getWord(word) != NULL) fprintf(output,"%s,",word_getWord(word));
                }

        fprintf(output,"\n");
        }


    }
    word_free(word);
    sentence_free(sentence);
    text_free(text);
    file_free(input);
    file_free(output);
    printf("DONE");
    return 0;
}
Example #21
0
File: misc.c Project: MicBosi/GTS
/**
 * gts_file_new_from_buffer:
 * @buf: a buffer.
 * @len: the size of the buffer.
 *
 * Returns: a new #GtsFile.
 */
GtsFile * gts_file_new_from_buffer (gchar * buf, size_t len)
{
  GtsFile * f;

  g_return_val_if_fail (buf != NULL, NULL);

  f = file_new ();
  f->buf = buf;
  f->len = len;
  gts_file_next_token (f);

  return f;
}
Example #22
0
NTSTATUS open_np_file(struct smb_request *smb_req, const char *name,
                      struct files_struct **pfsp)
{
    struct connection_struct *conn = smb_req->conn;
    struct files_struct *fsp;
    struct smb_filename *smb_fname = NULL;
    NTSTATUS status;

    status = file_new(smb_req, conn, &fsp);
    if (!NT_STATUS_IS_OK(status)) {
        DEBUG(0, ("file_new failed: %s\n", nt_errstr(status)));
        return status;
    }

    fsp->conn = conn;
    fsp->fh->fd = -1;
    fsp->vuid = smb_req->vuid;
    fsp->can_lock = false;
    fsp->access_mask = FILE_READ_DATA | FILE_WRITE_DATA;

    status = create_synthetic_smb_fname(talloc_tos(), name, NULL, NULL,
                                        &smb_fname);
    if (!NT_STATUS_IS_OK(status)) {
        file_free(smb_req, fsp);
        return status;
    }
    status = fsp_set_smb_fname(fsp, smb_fname);
    TALLOC_FREE(smb_fname);
    if (!NT_STATUS_IS_OK(status)) {
        file_free(smb_req, fsp);
        return status;
    }

    status = np_open(fsp, name,
                     conn->sconn->local_address,
                     conn->sconn->remote_address,
                     &conn->sconn->client_id,
                     conn->session_info,
                     conn->sconn->msg_ctx,
                     &fsp->fake_file_handle);
    if (!NT_STATUS_IS_OK(status)) {
        DEBUG(10, ("np_open(%s) returned %s\n", name,
                   nt_errstr(status)));
        file_free(smb_req, fsp);
        return status;
    }

    *pfsp = fsp;

    return NT_STATUS_OK;
}
Example #23
0
AccountWindow::AccountWindow(QWidget* parent, const QString &name, Qt::WindowFlags wflags)
	:TableWindow(parent, name, wflags)
{
	QStringList nameList;
	QTableWidget *pTable;
	QAction* pAction;

  pTable = TableWindow::getTable();
	m_pDb = ISql::pInstance();

	pAction = new QAction(tr("&New..."), this);
	connect(pAction, SIGNAL(triggered()), this, SLOT(file_new()));
	MDIWindow::addAction(pAction);

	pAction = new QAction(tr("&Edit..."), this);
	connect(pAction, SIGNAL(triggered()), this, SLOT(file_edit()));
	MDIWindow::addAction(pAction, true);

	pAction = new QAction(tr("&Delete"), this);
	connect(pAction, SIGNAL(triggered()), this, SLOT(file_delete()));
	MDIWindow::addAction(pAction);

	pAction = new QAction(this);
	pAction->setSeparator(true);
	MDIWindow::addAction(pAction);

	pAction = new QAction(tr("&Export all..."), this);
	connect(pAction, SIGNAL(triggered()), this, SLOT(exportTable()));
	MDIWindow::addAction(pAction);

	// configure the table
	TableWindow::setWindowIcon(QIcon(":/document.xpm"));
	pTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
	pTable->setSelectionMode(QAbstractItemView::SingleSelection);

	// header
  nameList += tr("Username");
  nameList += tr("Contest");
  nameList += tr("Description");

	setupHeader(nameList);

  pTable->setColumnWidth(Username, 100);
  pTable->setColumnWidth(Contest, 100);
  pTable->setColumnWidth(Description, 200);

  connect(m_pDb, SIGNAL(accountsChanged()), this, SLOT(file_update()));

	file_update();
}
Example #24
0
File: vis.c Project: ewqasd200g/vis
bool vis_window_new(Vis *vis, const char *filename) {
	File *file = file_new(vis, filename);
	if (!file)
		return false;
	Win *win = window_new_file(vis, file);
	if (!win) {
		file_free(vis, file);
		return false;
	}

	vis_draw(vis);

	return true;
}
Example #25
0
t_file *file_access( const char *path)
{
	if( sys_file_exists( path))
	{
		t_file *file = file_new( path);
		return file;

	}
	else
	{
		printf("[FILE] Error, can't access %s\n", path);
		return NULL;
	}
}
Example #26
0
void fs_cat(FileSystem *fs, const char *f, FILE *fp) {
    Inode *inode = NULL;
    char *data = NULL;
    File *file = NULL;
    
    inode = folder_lookup(fs, fs->cur, f);
    data = (char *) malloc(inode->filesize);
    file = file_new(fs, inode);
    file_get_contents(file, data);
    file_free(&file);
    fprintf(fp, "%s\n", data);
    fflush(fp);
    free(data);
}
QMenuBar *win_char_editor::setup_menuBar()
{
	file_new_Act = new QAction(tr("New"), this); 
    connect(file_new_Act, SIGNAL(triggered()), this, SLOT(file_new()));

	file_open_Act = new QAction(tr("Open"), this); 
    connect(file_open_Act, SIGNAL(triggered()), this, SLOT(file_open()));

	file_saveAct = new QAction(tr("Save"), this); 
	file_saveAct->setEnabled(FALSE);
    connect(file_saveAct, SIGNAL(triggered()), this, SLOT(file_save()));

	file_save_asAct = new QAction(tr("Save &As..."), this); 
	file_save_asAct->setEnabled(TRUE);
    connect(file_save_asAct, SIGNAL(triggered()), this, SLOT(file_save_as()));

	file_exitAct = new QAction(tr("Exit"), this); 
    connect(file_exitAct, SIGNAL(triggered()), this, SLOT(close()));

	edit_undoAct = new QAction(tr("Undo"), this); 
	edit_undoAct->setShortcut(tr("Ctrl+Z"));
	connect(edit_undoAct, SIGNAL(triggered()), this, SLOT(edit_undo()));
	edit_undoAct->setEnabled(FALSE);
    
	edit_redoAct = new QAction(tr("Redo"), this); 
	edit_redoAct->setShortcut(tr("Ctrl+Y"));
	connect(edit_redoAct, SIGNAL(triggered()), this, SLOT(edit_redo()));
	edit_redoAct->setEnabled(FALSE);

	fileMenu = new QMenu(tr("&File"));
	fileMenu->addAction(file_new_Act);
	fileMenu->addSeparator();
	fileMenu->addAction(file_open_Act);
	fileMenu->addSeparator();
	fileMenu->addAction(file_saveAct);
	fileMenu->addAction(file_save_asAct);
	fileMenu->addSeparator();
	fileMenu->addAction(file_exitAct);
	connect(fileMenu,SIGNAL(aboutToShow()),this,SLOT(menu_file_open()));
	editMenu = new QMenu(tr("&Edit"));
	editMenu->addAction(edit_undoAct);
	editMenu->addAction(edit_redoAct);
	
	mb = new QMenuBar(this);
	mb->clear();
	mb->addMenu(fileMenu);
	mb->addMenu(editMenu);
	return mb;
}
Example #28
0
struct fdpass *
fdpass_new(int sock, struct fileops *ops)
{
	struct fdpass *f;

	f = xmalloc(sizeof(struct fdpass));
	f->file = file_new(ops, f, ops->name, 1);
	if (f->file == NULL) {
		close(sock);
		return NULL;
	}
	f->fd = sock;
	fdpass_peer = f;
	return f;
}
Example #29
0
int main(int argc, char *argv[])
{

	if(argc < 3) {
		fprintf(stderr, "Usage:\n%s fontdesc.def outfile.iff\n", argv[0]);
		return 0;
	}

	def = file_new(argv[1], 0);
	if(!def) {
		fprintf(stderr, "Can't find font definition '%s'\n", argv[1]);
		return 1;
	}
	file_load(def);
	if(!def->buf) {
		file_free(def);
		fprintf(stderr, "Not enough memory to load %s\n", argv[1]);
		return 2;
	}

	if(!parse_def()) {
		file_free(def);
		return 1;
	}

	font = iff_new(argv[2], MAKE_ID('F','O','N','T'));
	if(!font) {
		file_free(def);
	}

	iff_newchunk(font, MAKE_ID('N','A','M','E'));
	iff_writechunkdata(font, name, strlen(name)+1);
	iff_endchunk(font);

	iff_newchunk(font, MAKE_ID('F','I','L','E'));
	iff_writechunkdata(font, file, strlen(file)+1);
	iff_endchunk(font);

	iff_newchunk(font, MAKE_ID('A','U','T','H'));
	iff_writechunkdata(font, author, strlen(author)+1);
	iff_endchunk(font);

	parse_letters();

	iff_close(font);
	file_free(def);
	return 0;
}
Example #30
0
File: vis.c Project: ewqasd200g/vis
bool vis_window_reload(Win *win) {
	const char *name = win->file->name;
	if (!name)
		return false; /* can't reload unsaved file */
	/* temporarily unset file name, otherwise file_new returns the same File */
	win->file->name = NULL;
	File *file = file_new(win->vis, name);
	win->file->name = name;
	if (!file)
		return false;
	file_free(win->vis, win->file);
	file->refcount = 1;
	win->file = file;
	win->ui->reload(win->ui, file);
	return true;
}