コード例 #1
0
ファイル: test_tifiles_2.c プロジェクト: TC01/tilibs
static int test_tixx_ungroup_support(const char * message,
                                     const char * input_group,
                                     const char * input_file_1,
                                     const char * dest_file_1,
                                     const char * input_file_2,
                                     const char * dest_file_2,
                                     const char * input_file_3,
                                     const char * input_file_4)
{
	int ret;
	printf("%s", message);
	ret = tifiles_ungroup_file(PATH(input_group), NULL);
	if (!ret)
	{
		move_file(input_file_1, dest_file_1);
		move_file(input_file_2, dest_file_2);
		ret = compare_files(PATH(dest_file_1), PATH2(input_file_3));
		if (!ret)
		{
			ret = compare_files(PATH(dest_file_2), PATH2(input_file_3));
		}
	}

	return ret;
}
コード例 #2
0
ファイル: queue_manager.cpp プロジェクト: 2202877/acl
bool queue_manager::move_file(queue_file* fp, queue_manager* toQueue, const char* extName)
{
	bool ret = move_file(fp, toQueue->get_queueName(), extName);
	if (ret == false)
		return false;
	return toQueue->cache_add(fp);
}
コード例 #3
0
ファイル: veentry.cpp プロジェクト: OpenVZ/vzmigrate
/* For new layout only
   After rsync we have 2 config on destination node:
   valid, in /etc/ and invalid (rsynced), in private area.
   Rewrote config in private by valid config content, remove
   config from etc and 'register' VE.
*/
int VEObj::veRegister()
{
	int rc;
	char tmpfile[PATH_MAX + 1];
	struct stat st;

	tmpfile[0] = 0;
	if (stat(confRealPath().c_str(), &st) == 0) {
		/* to save origin config (https://jira.sw.ru/browse/PSBM-10260) */
		snprintf(tmpfile, sizeof(tmpfile), "%s.XXXXXX", confRealPath().c_str());
		mktemp(tmpfile);
		if (rename(confRealPath().c_str(), tmpfile))
			return putErr(MIG_ERR_SYSTEM, "rename(%s, %s) : %m", confRealPath().c_str(), tmpfile);
	}

	/* rewrite private config */
	if ((rc = move_file(confRealPath().c_str(), confPath().c_str()))) {
		if (tmpfile[0])
			rename(tmpfile, confRealPath().c_str());
		return rc;
	}
	if (tmpfile[0])
		unlink(tmpfile);

	/* vzctl register for new layout VE */
	return registration();
}
コード例 #4
0
/*
 * Apply an ed script by feeding ed itself.
 */
void
do_ed_script(void)
{
	char	*t;
	long	beginning_of_this_line;
	FILE	*pipefp = NULL;

	if (!skip_rest_of_patch) {
		if (copy_file(filearg[0], TMPOUTNAME) < 0) {
			unlink(TMPOUTNAME);
			fatal("can't create temp file %s", TMPOUTNAME);
		}
		snprintf(buf, buf_size, "%s%s%s", _PATH_ED,
		    verbose ? " " : " -s ", TMPOUTNAME);
		pipefp = popen(buf, "w");
	}
	for (;;) {
		beginning_of_this_line = ftell(pfp);
		if (pgets(true) == 0) {
			next_intuit_at(beginning_of_this_line, p_input_line);
			break;
		}
		p_input_line++;
		for (t = buf; isdigit((unsigned char)*t) || *t == ','; t++)
			;
		/* POSIX defines allowed commands as {a,c,d,i,s} */
		if (isdigit((unsigned char)*buf) && (*t == 'a' || *t == 'c' ||
		    *t == 'd' || *t == 'i' || *t == 's')) {
			if (pipefp != NULL)
				fputs(buf, pipefp);
			if (*t != 'd') {
				while (pgets(true)) {
					p_input_line++;
					if (pipefp != NULL)
						fputs(buf, pipefp);
					if (strEQ(buf, ".\n"))
						break;
				}
			}
		} else {
			next_intuit_at(beginning_of_this_line, p_input_line);
			break;
		}
	}
	if (pipefp == NULL)
		return;
	fprintf(pipefp, "w\n");
	fprintf(pipefp, "q\n");
	fflush(pipefp);
	pclose(pipefp);
	ignore_signals();
	if (!check_only) {
		if (move_file(TMPOUTNAME, outname) < 0) {
			toutkeep = true;
			chmod(TMPOUTNAME, filemode);
		} else
			chmod(outname, filemode);
	}
	set_signals(1);
}
コード例 #5
0
ファイル: image.cpp プロジェクト: pefimo/factor
/* Save the current image to disk. We don't throw any exceptions here
   because if the 'then-die' argument is t it is not safe to do
   so. Instead we signal failure by returning false. */
bool factor_vm::save_image(const vm_char* saving_filename,
                           const vm_char* filename) {
  image_header h;

  h.magic = image_magic;
  h.version = image_version;
  h.data_relocation_base = data->tenured->start;
  h.data_size = data->tenured->occupied_space();
  h.code_relocation_base = code->allocator->start;
  h.code_size = code->allocator->occupied_space();

  for (cell i = 0; i < special_object_count; i++)
    h.special_objects[i] =
        (save_special_p(i) ? special_objects[i] : false_object);

  FILE* file = OPEN_WRITE(saving_filename);
  if (file == NULL)
    return false;
  if (safe_fwrite(&h, sizeof(image_header), 1, file) != 1)
    return false;
  if (safe_fwrite((void*)data->tenured->start, h.data_size, 1, file) != 1)
    return false;
  if (safe_fwrite((void*)code->allocator->start, h.code_size, 1, file) != 1)
    return false;
  if (raw_fclose(file) == -1)
    return false;
  if (!move_file(saving_filename, filename))
    return false;
  return true;
}
コード例 #6
0
ファイル: cache_maint.c プロジェクト: GroupO/geeqie_zas
static void cache_file_move(const gchar *src, const gchar *dest)
{
	if (!dest || !src || !isfile(src)) return;

	if (!move_file(src, dest))
		{
		DEBUG_1("Failed to move cache file \"%s\" to \"%s\"", src, dest);
		/* we remove it anyway - it's stale */
		unlink_file(src);
		}
}
コード例 #7
0
ファイル: move_files.cpp プロジェクト: wutzi15/analyse-suite
bool move_files(const char *new_path, const char* files) {
    std::stringstream sstr(files);
    std::vector<fs::path > f;
    std::string line;

    while (std::getline(sstr,line)) {
        f.push_back(fs::path(line));
    }

    for (std::vector<fs::path>::iterator i = f.begin(); i != f.end(); i++) {
        fs::path dir = i->parent_path();
        std::string name = i->filename().string();
        move_file(new_path, dir/("_dist_"+name));
        move_file(new_path, dir/("_my_ana_"+name));
        move_file(new_path, dir/("_peak_"+name));
        move_file(new_path, dir/("_only_"+name));
        copy_file(new_path, dir/name);
    }


    return true;
}
コード例 #8
0
ファイル: module_builds.c プロジェクト: stewartsmith/ccan
char *build_module(struct manifest *m, bool keep, char **errstr)
{
	char *name = link_objects(m, m->basename, false, obj_list(m), errstr);
	if (name) {
		if (keep) {
			char *realname = talloc_asprintf(m, "%s.o", m->dir);
			/* We leave this object file around, all built. */
			if (!move_file(name, realname))
				err(1, "Renaming %s to %s", name, realname);
			name = realname;
		}
	}
	return name;
}
コード例 #9
0
ファイル: cache.c プロジェクト: gentoo/pornview
static void
cache_file_move (const gchar * src, const gchar * dest)
{
    if (!dest || !src || !isfile (src))
	return;

    if (!move_file (src, dest))
    {
	/*
	 * we remove it anyway - it's stale 
	 */
	unlink (src);
    }
}
コード例 #10
0
ファイル: move_reuse.cpp プロジェクト: faldah/nt2
void move_files(std::string const& old, std::string const& new_)
{
    for ( fs::directory_iterator current_dir(new_.c_str()); *current_dir; ++current_dir )
    {
        std::string const entry_name( *current_dir            );
        std::string const      entry( old + '/' + entry_name  );
        std::string const  new_entry( new_ + '/' + entry_name );
        
        if(fs::extension(entry_name) == ".hpp")
            move_file(entry, new_entry);
            
        if(fs::is_directory(new_entry))
            move_files(entry, new_entry);
    }
}
コード例 #11
0
ファイル: record.c プロジェクト: MaChao5/pdfviewer-win32
static int record_result_save(gfxresult_t*r, const char*filename)
{
    internal_result_t*i = (internal_result_t*)r->internal;
    if(i->use_tempfile) {
	move_file(i->filename, filename);
    } else {
	FILE*fi = fopen(filename, "wb");
	if(!fi) {
	    fprintf(stderr, "Couldn't open file %s for writing\n", filename);
	    return -1;
	}
	fwrite(i->data, i->length, 1, fi);
	fclose(fi);
    }
    return 0;
}
コード例 #12
0
ファイル: main.c プロジェクト: vdudouyt/mhddfs-nosegfault
// write
static int mhdd_write(const char *path, const char *buf, size_t count,
		off_t offset, struct fuse_file_info *fi)
{
	ssize_t res;
	struct flist *info;
	mhdd_debug(MHDD_INFO, "mhdd_write: %s, handle = %lld\n", path, fi->fh);
	info = flist_item_by_id(fi->fh);

	if (!info) {
		errno = EBADF;
		return -errno;
	}

	res = pwrite(info->fh, buf, count, offset);
	if ((res == count) || (res == -1 && errno != ENOSPC)) {
		flist_unlock();
		if (res == -1) {
			mhdd_debug(MHDD_DEBUG,
				"mhdd_write: error write %s: %s\n",
				info->real_name, strerror(errno));
			return -errno;
		}
		return res;
	}

	// end free space
	if (move_file(info, offset + count) == 0) {
		res = pwrite(info->fh, buf, count, offset);
		flist_unlock();
		if (res == -1) {
			mhdd_debug(MHDD_DEBUG,
				"mhdd_write: error restart write: %s\n",
				strerror(errno));
			return -errno;
		}
		if (res < count) {
			mhdd_debug(MHDD_DEBUG,
				"mhdd_write: error (re)write file %s %s\n",
				info->real_name,
				strerror(ENOSPC));
		}
		return res;
	}
	errno = ENOSPC;
	flist_unlock();
	return -errno;
}
コード例 #13
0
ファイル: image.cpp プロジェクト: littledan/Factor
/* Save the current image to disk */
bool factor_vm::save_image(const vm_char *saving_filename, const vm_char *filename)
{
	FILE* file;
	image_header h;

	file = OPEN_WRITE(saving_filename);
	if(file == NULL)
	{
		std::cout << "Cannot open image file: " << saving_filename << std::endl;
		std::cout << strerror(errno) << std::endl;
		return false;
	}

	h.magic = image_magic;
	h.version = image_version;
	h.data_relocation_base = data->tenured->start;
	h.data_size = data->tenured->occupied_space();
	h.code_relocation_base = code->seg->start;
	h.code_size = code->allocator->occupied_space();

	h.true_object = true_object;
	h.bignum_zero = bignum_zero;
	h.bignum_pos_one = bignum_pos_one;
	h.bignum_neg_one = bignum_neg_one;

	for(cell i = 0; i < special_object_count; i++)
		h.special_objects[i] = (save_special_p(i) ? special_objects[i] : false_object);

	bool ok = true;

	if(safe_fwrite(&h,sizeof(image_header),1,file) != 1) ok = false;
	if(safe_fwrite((void*)data->tenured->start,h.data_size,1,file) != 1) ok = false;
	if(safe_fwrite(code->allocator->first_block(),h.code_size,1,file) != 1) ok = false;
	safe_fclose(file);

	if(!ok)
		std::cout << "save-image failed: " << strerror(errno) << std::endl;
	else
		move_file(saving_filename,filename); 

	return ok;
}
コード例 #14
0
/*
* builtin_cmd
*
* 내장 명령을 수행한다.
* 내장 명령이 아니면 1을 리턴한다.
*/
int builtin_cmd(int argc, char **argv)
{ 
	// 내장 명령어 문자열과 argv[0]을 비교하여 각각의 처리 함수 호출
	if ( (!strcmp (argv[0], "quit")) || (!strcmp (argv[0], "exit")) ) {
		exit(0);
	}
    if ( !strcmp(argv[0], "ls")){
       return list_files(argc, argv);
    }
    if ( !strcmp(argv[0], "ll")){
       return list_all_files(argc, argv);
    }
    if ( !strcmp(argv[0], "cp")){
        return copy_file(argc, argv);
    }
    if ( !strcmp(argv[0], "rm")){
        return remove_file(argc, argv);
    }
    if ( !strcmp(argv[0], "move")){
        return move_file(argc, argv);
    }
    if ( !strcmp(argv[0], "cd")){
        return change_directory(argc, argv);
    }
    if ( !strcmp(argv[0], "pwd")){
        return print_working_directory();
    }
    if ( !strcmp(argv[0], "mkdir")){
        return make_directory(argc, argv);
    }
    if ( !strcmp(argv[0], "rmdir")){
        return remove_directory(argc, argv);
    }
    if ( !strcmp(argv[0], "cpdir")){
        return copy_directory(argc, argv);
    }
        
	// 내장 명령어가 아님.
    printf("command not found\n");
	return 1;
}
コード例 #15
0
ファイル: python_plugin.c プロジェクト: SpOOnman/claws
static void migrate_scripts_out_of_base_dir(void)
{
  char *base_dir;
  GDir *dir;
  const char *filename;
  gchar *dest_dir;

  base_dir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, PYTHON_SCRIPTS_BASE_DIR, NULL);
  dir = g_dir_open(base_dir, 0, NULL);
  g_free(base_dir);
  if(!dir)
    return;

  dest_dir = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
      PYTHON_SCRIPTS_BASE_DIR, G_DIR_SEPARATOR_S,
      PYTHON_SCRIPTS_MAIN_DIR, NULL);
  if(!g_file_test(dest_dir, G_FILE_TEST_IS_DIR)) {
    if(g_mkdir(dest_dir, 0777) != 0) {
      g_free(dest_dir);
      g_dir_close(dir);
      return;
    }
  }

  while((filename = g_dir_read_name(dir)) != NULL) {
    gchar *filepath;
    filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, PYTHON_SCRIPTS_BASE_DIR, G_DIR_SEPARATOR_S, filename, NULL);
    if(g_file_test(filepath, G_FILE_TEST_IS_REGULAR)) {
      gchar *dest_file;
      dest_file = g_strconcat(dest_dir, G_DIR_SEPARATOR_S, filename, NULL);
      if(move_file(filepath, dest_file, FALSE) == 0)
        debug_print("Python plugin: Moved file '%s' to %s subdir\n", filename, PYTHON_SCRIPTS_MAIN_DIR);
      else
        debug_print("Python plugin: Warning: Could not move file '%s' to %s subdir\n", filename, PYTHON_SCRIPTS_MAIN_DIR);
      g_free(dest_file);
    }
    g_free(filepath);
  }
  g_dir_close(dir);
  g_free(dest_dir);
}
コード例 #16
0
ファイル: rssyl_update_format.c プロジェクト: Mortal/claws
/* Copy each item in a feed to the new directory */
static void rssyl_update_format_move_contents(FolderItem *olditem,
		FolderItem *newitem)
{
	gchar *oldpath, *newpath, *fname, *fpath, *nfpath;
	GDir *d = NULL;
	GError *error = NULL;

	oldpath = _old_rssyl_item_get_path(NULL, olditem);
	newpath = folder_item_get_path(newitem);

	if ((d = g_dir_open(oldpath, 0, &error)) == NULL) {
		debug_print("RSSyl: (FORMAT) couldn't open dir '%s': %s\n", oldpath,
				error->message);
		g_error_free(error);
		return;
	}

	debug_print("RSSyl: (FORMAT) moving contents of '%s' to '%s'\n",
			oldpath, newpath);

	while ((fname = (gchar *)g_dir_read_name(d)) != NULL) {
		gboolean migrate_file = to_number(fname) > 0 || strstr(fname, ".claws_") == fname;
		fpath = g_strconcat(oldpath, G_DIR_SEPARATOR_S, fname, NULL);
		if (migrate_file && g_file_test(fpath, G_FILE_TEST_IS_REGULAR)) {
			nfpath = g_strconcat(newpath, G_DIR_SEPARATOR_S, fname, NULL);
			move_file(fpath, nfpath, FALSE);
			g_free(nfpath);
		}
		g_remove(fpath);
		g_free(fpath);
	}

	g_dir_close(d);
	g_rmdir(oldpath);

	g_free(oldpath);
	g_free(newpath);
}
コード例 #17
0
ファイル: mh.c プロジェクト: buzz/claws
static gboolean mh_renumber_msg(MsgInfo *info)
{
	gchar *src, *dest;
	gboolean result = FALSE;
	guint num;
	cm_return_val_if_fail(info != NULL, FALSE);

	src = folder_item_fetch_msg(info->folder, info->msgnum);
	dest = mh_get_new_msg_filename(info->folder);
	num = info->folder->last_num + 1;

	if (move_file(src, dest, FALSE) == 0) {
		msgcache_remove_msg(info->folder->cache, info->msgnum);
		info->msgnum = num;
		msgcache_add_msg(info->folder->cache, info);
		result = TRUE;
	}

	g_free(src);
	g_free(dest);

	return result;
}
コード例 #18
0
ファイル: test_tifiles_2.c プロジェクト: TC01/tilibs
static int test_tigroup()
{
	TigContent *content = NULL;
	TigEntry te = { NULL, 0, { NULL } };
	int ret = -1;

	// SVN can't handle file like 'pépé'. You will have to rename it from pepe to pépé and
	// uncomment line below and another line.
	//char *name = g_filename_from_utf8("tig/p\xC3\xA9p\xC3\xA9.tig", -1, NULL, NULL, NULL);

	char *array[2];
	char files[2][1024];

	printf("--> Testing TiGroup support (r/w)...\n");
	tifiles_file_display_tigroup(PATH("tig/test.tig"));

	content = tifiles_content_create_tigroup(CALC_NONE, 0);
	if (content != NULL)
	{
		ret = tifiles_file_read_tigroup(PATH("tig/test2.tig"), content);
		if (!ret)
		{
			ret = tifiles_file_write_tigroup(PATH("tig/test2_.tig"), content);
		}
		tifiles_content_delete_tigroup(content);
	}

	if (!ret)
	{
		content = tifiles_content_create_tigroup(CALC_NONE, 0);
		if (content != NULL)
		{
			ret = tifiles_file_read_tigroup(PATH("tig/test.tig"), content);
			if (!ret)
			{
				ret = tifiles_file_write_tigroup(PATH("tig/test_.tig"), content);
				if (!ret)
				{
					ret = compare_files(PATH("tig/test.tig"), PATH2("tig/test_.tig"));
				}
			}
			tifiles_content_delete_tigroup(content);
		}
	}

	if (!ret)
	{
		printf("--> Testing add/del from TiGroup support (r/w)...\n");
		ret = tifiles_tigroup_add_file(PATH("tig/C.8Xn"), PATH2("tig/test2.tig"));
		if (!ret)
		{
			ret = tifiles_tigroup_add_file(PATH("tig/D.8Xn"), PATH2("tig/test2.tig"));
			if (!ret)
			{
				te.filename = strdup("C.8Xn");
				ret = tifiles_tigroup_del_file(&te, PATH("tig/test2.tig"));
				if (!ret)
				{
					te.filename = strdup("D.8Xn");
					ret = tifiles_tigroup_del_file(&te, PATH("tig/test2.tig"));
					if (!ret)
					{
						tifiles_file_display_tigroup(PATH("tig/test2.tig"));
						ret = compare_files(PATH("tig/test.tig"), PATH2("tig/test2.tig"));
					}
				}
			}
		}
	}

	if (!ret)
	{
		printf("--> Testing TiGroup support (group/ungroup)...\n");

		strncpy(files[0], PATH("tig/str.89s"), 1023);
		files[0][1023] = 0;
		strncpy(files[1], PATH("tig/ticabfra.89k"), 1023);
		files[1][1023] = 0;
		array[0] = files[0];
		array[1] = files[1];
		ret = tifiles_tigroup_files(array, PATH("tig/test_.tig"));
		if (!ret)
		{
			tifiles_file_display(PATH("tig/test_.tig"));
			ret = tifiles_untigroup_file(PATH("tig/test.tig"), NULL);
			if (!ret)
			{
				move_file("A.8Xn", "tig/AA.8Xn");
				move_file("B.8Xn", "tig/BB.8Xn");
				ret = compare_files(PATH("tig/A.8Xn"), PATH2("tig/AA.8Xn"));
				if (!ret)
				{
					ret = compare_files(PATH("tig/B.8Xn"), PATH2("tig/BB.8Xn"));
				}
			}
		}
	}

	return ret;
}
コード例 #19
0
	int main(int argc, char *argv[])
	{
		if(argc != 4)
		{
			printf("Invalid Arguments\n");
			return -1;
		}
		
		char *file = argv[1];
		char *id = argv[2];
		char *marks = argv[3];
		
		FILE *fp = fopen("flag.txt", "w");
		fprintf(fp, "%d", 0);
		fclose(fp);
		if(!fork())
			search("/home/user/evaluator/", file);	// setting the current directory
		wait(NULL);
		delete("flag.txt");
		
		char loc[100];
		fp = fopen("path.txt", "r");
		fscanf(fp, "%s", loc);
		fclose(fp);
		delete("path.txt");
		
		/* Precautionary change of permission of the file to be modified */
		
		if(!fork())
		{
			execl("/bin/chmod", "chmod", "777", loc, 0);
			exit(0);
		}
		wait(NULL);
		
		fp = fopen(loc, "r");
		FILE *wfp = fopen("new_marks.txt", "w");
		char c;
		while((c = fgetc(fp))!= EOF)
		{
			fseek(fp, -1,1);
			char temp[100];
			fscanf(fp, "%[^\n]s", temp);
			fgetc(fp);
			if(!strncmp(id, temp, 12))	// finding the id	
			{
				int i = 13;
				int x = 0;
				int len = strlen(marks);
				while(x < len)
					temp[i++] = marks[x++];

				temp[i] = 0;		
			}
			fprintf(wfp, "%s\n", temp);
		}
		
		fclose(wfp);
		fclose(fp);
		move_file("new_marks.txt", loc);	//changing the old marks file
		
		return 0;		
	}
コード例 #20
0
ファイル: folder.c プロジェクト: arcfide/Unicode-NN
static void
rewrite_folder(void)
{
    register FILE  *src, *dst;
    char           *oldfile;
    register int    c;
    register long   cnt;
    register article_header *ah, **ahp;
    register article_number n;

    if (strchr(backup_folder_path, '/'))
	oldfile = backup_folder_path;
    else
	oldfile = relative(nn_directory, backup_folder_path);

    if (move_file(group_path_name, oldfile, 1) < 0) {
	tprintf("\r\n\nCannot backup folder in %s\n", oldfile);
	goto confirm;
    }
    if ((src = open_file(oldfile, OPEN_READ)) == NULL) {
	tprintf("\rCannot open %s\n\r", oldfile);
	goto move_back;
    }
    if ((dst = open_file(group_path_name, OPEN_CREATE)) == NULL) {
	fclose(src);
	tprintf("\rCannot create %s\n\r", group_path_name);
	goto move_back;
    }
    sort_articles(-2);

    tprintf("\rCompressing folder...\n\r");
    fl;

    get_folder_type(src);

    for (ahp = articles, n = n_articles; --n >= 0; ahp++) {
	ah = *ahp;
	cnt = ah->lpos - ah->hpos;
	if (folder_rewrite_trace)
	    tprintf("%s\t%s (%ld-%ld=%ld)\n\r",
		    ah->attr == A_CANCEL ? "CANCEL" : "KEEP",
		    ah->subject, ah->hpos, (long) (ah->lpos), cnt);
	if (ah->attr == A_CANCEL)
	    continue;
	fseek(src, ah->hpos, 0);
	mailbox_format(dst, -1);
	while (--cnt >= 0) {
	    if ((c = getc(src)) == EOF)
		break;
	    putc(c, dst);
	}
	mailbox_format(dst, 0);
    }

    fclose(src);
    if (fclose(dst) == EOF)
	goto move_back;
    if (!keep_backup_folder)
	unlink(oldfile);
    if (folder_rewrite_trace)
	goto confirm;
    return;

move_back:
    if (move_file(oldfile, group_path_name, 2) == 0)
	tprintf("Cannot create new file -- Folder restored\n\r");
    else
	tprintf("Cannot create new file\n\n\rFolder saved in %s\n\r", oldfile);

confirm:
    any_key(0);
}
コード例 #21
0
ファイル: mps_util.c プロジェクト: huilang22/Projects
int
generate_bcp_scripts_db(char *dir_name, char *file_name, char *table_name)
{

  int count = 0;
  int ret_code;
  int i;
  FILE *fp;
  int status;
  char bcp_file_name[256];
  char init_file_name[256];
  char *str_ptr;

    

    /* tmp is the file name with lower cases */
    for(i=0; i< strlen(file_name); i++)
    {
      if(file_name[i] != '.')
        bcp_file_name[i] = tolower(file_name[i]);
      else
	break;
    }
    bcp_file_name[i] = '\0';
    strcat(bcp_file_name,".bcp");
    if(dir_name[0] != '\0')
      sprintf(scratch, "%s/%s",dir_name,bcp_file_name); 
    strcpy(bcp_file_name, scratch);
    if(dir_name[0] != '\0')
      sprintf(init_file_name, "%s/%s",dir_name,file_name); 
    else
      strcpy(init_file_name, file_name); 

    status = valid_dbobject(dbproc1, table_name, "U");

    if(status == FALSE)
    {
/*
      sprintf(scratch,"Table %s does not exist", table_name);
      post_dialog(atm_script_shell,XmDIALOG_MESSAGE,scratch);
*/
      return(FAILURE);
    }

    if((fp = fopen(init_file_name,"w+b")) == NULL)
    {
/*
      sprintf(scratch,"File %s openning error",init_file_name);
      post_dialog(atm_script_shell,XmDIALOG_MESSAGE,scratch);
*/
      return(FAILURE);
    }

    sprintf(scratch,"#\n# Copyright 1995, 1996 Kenan Systems Corporation. ");
    fwrite(scratch,strlen(scratch),1,fp);

    sprintf(scratch,"All Rights Reserved.\n#\n#\n");
    fwrite(scratch,strlen(scratch),1,fp);
    sprintf(scratch,"DB=$1\nUSER=$2\nPASS=$3\n\n");
    fwrite(scratch,strlen(scratch),1,fp);
    sprintf(scratch,"isql -U$USER -P$PASS <<THEEND\nuse $DB\ngo\n\n");
    fwrite(scratch,strlen(scratch),1,fp);
    sprintf(scratch,"delete %s\ngo\n\n",table_name);
    fwrite(scratch,strlen(scratch),1,fp);
    sprintf(scratch,"quit\n\nTHEEND\n");
    fwrite(scratch,strlen(scratch),1,fp);
    sprintf(scratch,"bcp $DB..%s in %s -c -U$USER -P$PASS\n",
      table_name, bcp_file_name);
    fwrite(scratch,strlen(scratch),1,fp);
    fclose(fp);

    if(!access(bcp_file_name, R_OK))
    {
      /* init script exists. move it to file.bak just in case */
      sprintf(scratch,"%s.bak",bcp_file_name);
      move_file(bcp_file_name, scratch);
    }

    if((fp = fopen(bcp_file_name,"w+b")) == NULL)
    {
/*
      sprintf(scratch,"File %s openning error",bcp_file_name);
      post_dialog(atm_script_shell,XmDIALOG_MESSAGE,scratch);
*/
      return(FAILURE);
    }
    fclose(fp);
    
    return(SUCCESS);
}
コード例 #22
0
/*
* builtin_cmd
*
* 내장 명령을 수행한다.
* 내장 명령이 아니면 1을 리턴한다.
*/
int builtin_cmd(int argc, char **argv)
{
	//아무것도 안들어올 경우 예외처리
	if(argc == 0)
	{
		return -1;
	}
	//에러처리
	if(argc < 0)
	{
		fprintf(stderr ,"error. check your commane and retry\n");
		return -1;
	}
	// 내장 명령어 문자열과 argv[0]을 비교하여 각각의 처리 함수 호출
	if ( (!strcmp (argv[0], "quit")) || (!strcmp (argv[0], "exit")) ) 
	{
		exit(0);
	}
	if ( !strcmp(argv[0], "ls"))
	{
		return list_files(argc, argv);
	}
   	if ( !strcmp(argv[0], "ll"))
	{
       		return list_all_files(argc, argv);
    	}
    	if ( !strcmp(argv[0], "cp"))
	{
        	return copy_file(argc, argv);
    	}
    	if ( !strcmp(argv[0], "rm"))
	{
        	return remove_file(argc, argv);
    	}
    	if ( !strcmp(argv[0], "mv"))
	{
        	return move_file(argc, argv);
    	}
    	if ( !strcmp(argv[0], "cd"))
	{
        	return change_directory(argc, argv);
    	}
    	if ( !strcmp(argv[0], "pwd"))
	{
        	return print_working_directory(argc);
    	}
    	if ( !strcmp(argv[0], "mkdir"))
	{
        	return make_directory(argc, argv);
    	}
    	if ( !strcmp(argv[0], "rmdir"))
	{
        	return remove_directory(argc, argv);
    	}
	if( !strcmp(argv[0], "help"))
	{
		return help(argc);
	}
        
	// 내장 명령어가 아님.
   	fprintf(stderr,"command not found\n");
	return 1;
}
コード例 #23
0
ファイル: fileutil.c プロジェクト: gentoo/pornview
static void
file_util_move_multiple (FileDataMult * fdm)
{
    while (fdm->dest || fdm->source_next)
    {
	if (!fdm->dest)
	{
	    GList  *work = fdm->source_next;
	    fdm->source = work->data;
	    fdm->dest =
		concat_dir_and_file (fdm->dest_base,
				     filename_from_path (fdm->source));
	    fdm->source_next = work->next;
	}

	if (fdm->dest && fdm->source && strcmp (fdm->dest, fdm->source) == 0)
	{
	    GenericDialog *gd;
	    const gchar *title;
	    gchar  *text;

	    if (fdm->progress)
	    {
		gtk_grab_remove (fdm->progress);
		gtk_widget_destroy (fdm->progress);
		fdm->progress = NULL;
		fdm->cancel = FALSE;
	    }

	    if (fdm->copy)
	    {
		title = _("Source to copy matches destination");
		text =
		    g_strdup_printf (_
				     ("Unable to copy file:\n%s\nto itself."),
				     fdm->dest);
	    }
	    else
	    {
		title = _("Source to move matches destination");
		text =
		    g_strdup_printf (_
				     ("Unable to move file:\n%s\nto itself."),
				     fdm->dest);
	    }

	    gd = file_util_gen_dlg (title, text, "PornView", "dlg_confirm",
				    TRUE, cb_file_util_move_multiple_cancel,
				    fdm);
	    g_free (text);
	    generic_dialog_add (gd, _("Continue"),
				cb_file_util_move_multiple_skip, TRUE);

	    gtk_widget_show (gd->dialog);
	    return;
	}
	else if (isfile (fdm->dest) && !fdm->confirmed && !fdm->confirm_all
		 && !fdm->skip)
	{
	    GenericDialog *gd;
	    gchar  *text;

	    GtkWidget *hbox;

	    if (fdm->progress)
	    {
		gtk_grab_remove (fdm->progress);
		gtk_widget_destroy (fdm->progress);
		fdm->progress = NULL;
		fdm->cancel = FALSE;
	    }

	    text =
		g_strdup_printf (_("Overwrite file:\n %s\n with:\n %s"),
				 fdm->dest, fdm->source);
	    gd = file_util_gen_dlg (_("Overwrite file"), text, "PornView",
				    "dlg_confirm", TRUE,
				    cb_file_util_move_multiple_cancel, fdm);
	    g_free (text);

	    generic_dialog_add (gd, _("Yes"), cb_file_util_move_multiple_ok,
				TRUE);
	    fdm->yes_all_button =
		generic_dialog_add (gd, _("Yes to all"),
				    cb_file_util_move_multiple_all, FALSE);
	    generic_dialog_add (gd, _("Skip"),
				cb_file_util_move_multiple_skip, FALSE);
	    generic_dialog_add (gd, _("Skip all"),
				cb_file_util_move_multiple_skip_all, FALSE);
	    generic_dialog_add_images (gd, fdm->dest, fdm->source);

	    /*
	     * rename option 
	     */

	    fdm->rename = FALSE;
	    fdm->rename_all = FALSE;
	    fdm->rename_auto = FALSE;

	    hbox = gtk_hbox_new (FALSE, 5);
	    gtk_box_pack_start (GTK_BOX (gd->vbox), hbox, FALSE, FALSE, 0);
	    gtk_widget_show (hbox);

	    fdm->rename_auto_box =
		gtk_check_button_new_with_label (_("Auto rename"));
	    gtk_signal_connect (GTK_OBJECT (fdm->rename_auto_box), "clicked",
				GTK_SIGNAL_FUNC
				(cb_file_util_move_multiple_rename_auto), gd);
	    gtk_box_pack_start (GTK_BOX (hbox), fdm->rename_auto_box, FALSE,
				FALSE, 0);
	    gtk_widget_show (fdm->rename_auto_box);

	    hbox = gtk_hbox_new (FALSE, 5);
	    gtk_box_pack_start (GTK_BOX (gd->vbox), hbox, FALSE, FALSE, 0);
	    gtk_widget_show (hbox);

	    fdm->rename_box = gtk_check_button_new_with_label (_("Rename"));
	    gtk_signal_connect (GTK_OBJECT (fdm->rename_box), "clicked",
				GTK_SIGNAL_FUNC
				(cb_file_util_move_multiple_rename), gd);
	    gtk_box_pack_start (GTK_BOX (hbox), fdm->rename_box, FALSE, FALSE,
				0);
	    gtk_widget_show (fdm->rename_box);

	    fdm->rename_entry = gtk_entry_new ();
	    gtk_entry_set_text (GTK_ENTRY (fdm->rename_entry),
				filename_from_path (fdm->dest));
	    gtk_widget_set_sensitive (fdm->rename_entry, FALSE);
	    gtk_box_pack_start (GTK_BOX (hbox), fdm->rename_entry, TRUE, TRUE,
				0);
	    gtk_widget_show (fdm->rename_entry);

	    gtk_widget_show (gd->dialog);
	    return;
	}
	else
	{
	    gint    success = FALSE;
	    if (fdm->skip)
	    {
		success = TRUE;
		if (!fdm->confirm_all)
		    fdm->skip = FALSE;
	    }
	    else
	    {
		gint    try = TRUE;

		if (fdm->confirm_all && fdm->rename_all && isfile (fdm->dest))
		{
		    gchar  *buf;
		    buf = unique_filename_simple (fdm->dest);
		    if (buf)
		    {
			g_free (fdm->dest);
			fdm->dest = buf;
		    }
		    else
		    {
			try = FALSE;
		    }
		}

		if (try)
		{
		    if (!fdm->progress)
			fdm->progress =
			    dialog_progress_create (_("Pornview - copy/move"),
						    _(" "), &fdm->cancel, 300,
						    -1);
		    gtk_grab_add (fdm->progress);


		    if (fdm->copy)
		    {
			gfloat  c;
			c = (gfloat) fdm->count / (gfloat) fdm->length;
			dialog_progress_update (fdm->progress,
						_("PornView - copy"),
						g_basename (fdm->source),
						_(" "), c);

			if (fdm->cancel)
			    break;
			success = copy_file (fdm->source, fdm->dest);
			fdm->count++;
		    }
		    else
		    {
			gfloat  c;

			c = (gfloat) fdm->count / (gfloat) fdm->length;
			dialog_progress_update (fdm->progress,
						_("PornView - move"),
						g_basename (fdm->source),
						_(" "), c);

			if (fdm->cancel)
			    break;

			while (gtk_events_pending ())
			    gtk_main_iteration ();

			fdm->count++;

			if (move_file (fdm->source, fdm->dest))
			{
			    success = TRUE;
			    file_maint_moved (fdm->source, fdm->dest,
					      fdm->source_list);

			}
		    }
		}
	    }
	    if (!success)
	    {
		GenericDialog *gd;
		const gchar *title;
		gchar  *text;

		if (fdm->progress)
		{
		    gtk_grab_remove (fdm->progress);
		    gtk_widget_destroy (fdm->progress);
		    fdm->progress = NULL;
		    fdm->cancel = FALSE;
		}

		if (fdm->copy)
		{
		    title = _("Error copying file");
		    text =
			g_strdup_printf (_
					 ("Unable to copy file:\n%sto:\n%s\n during multiple file copy."),
					 fdm->source, fdm->dest);
		}
		else
		{
		    title = _("Error moving file");
		    text =
			g_strdup_printf (_
					 ("Unable to move file:\n%sto:\n%s\n during multiple file move."),
					 fdm->source, fdm->dest);
		}
		gd = file_util_gen_dlg (title, text, "PornView",
					"dlg_confirm", TRUE,
					cb_file_util_move_multiple_cancel,
					fdm);
		g_free (text);

		generic_dialog_add (gd, _("Continue"),
				    cb_file_util_move_multiple_skip, TRUE);

		gtk_widget_show (gd->dialog);
		return;
	    }
	    fdm->confirmed = FALSE;
	    g_free (fdm->dest);
	    fdm->dest = NULL;
	}
    }
コード例 #24
0
ファイル: mh.c プロジェクト: ignatenkobrain/claws
static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist, 
			 GHashTable *relation)
{
	gboolean dest_need_scan = FALSE;
	gboolean src_need_scan = FALSE;
	FolderItem *src = NULL;
	gchar *srcfile;
	gchar *destfile;
	FolderItemPrefs *prefs;
	MsgInfo *msginfo = NULL;
	MsgInfoList *cur = NULL;
	gint curnum = 0, total = 0;
	gchar *srcpath = NULL;
	gboolean full_fetch = FALSE;
	time_t last_dest_mtime = (time_t)0;
	time_t last_src_mtime = (time_t)0;

	cm_return_val_if_fail(dest != NULL, -1);
	cm_return_val_if_fail(msglist != NULL, -1);
	
	msginfo = (MsgInfo *)msglist->data;

	cm_return_val_if_fail(msginfo != NULL, -1);

	if (msginfo->folder == dest) {
		g_warning("the src folder is identical to the dest.\n");
		return -1;
	}

	if (msginfo->folder->folder != dest->folder)
		full_fetch = TRUE;
	
	if (FOLDER_TYPE(msginfo->folder->folder) == F_MH) {
		src = msginfo->folder;
	}

	if (dest->last_num < 0) {
		mh_get_last_num(folder, dest);
		if (dest->last_num < 0) return -1;
	}

	prefs = dest->prefs;

	srcpath = folder_item_get_path(msginfo->folder);

	dest_need_scan = mh_scan_required(dest->folder, dest);
	last_dest_mtime = dest->mtime;

	if (src) {
		src_need_scan = mh_scan_required(src->folder, src);
		last_src_mtime = src->mtime;
	}

	total = g_slist_length(msglist);
	if (total > 100) {
		if (MSG_IS_MOVE(msginfo->flags))
			statusbar_print_all(_("Moving messages..."));
		else
			statusbar_print_all(_("Copying messages..."));
	}
	for (cur = msglist; cur; cur = cur->next) {
		msginfo = (MsgInfo *)cur->data;
		if (!msginfo) {
			goto err_reset_status;
		}
		if (!full_fetch) {
			srcfile = g_strconcat(srcpath, 
				G_DIR_SEPARATOR_S, 
				itos(msginfo->msgnum), NULL);
		} else {
			srcfile = procmsg_get_message_file(msginfo);
		}
		if (!srcfile) {
			goto err_reset_status;
		}
		destfile = mh_get_new_msg_filename(dest);
		if (!destfile) {
			g_free(srcfile);
			goto err_reset_status;
		}

		if (total > 100) {
			statusbar_progress_all(curnum, total, 100);
			if (curnum % 100 == 0)
				GTK_EVENTS_FLUSH();
			curnum++;
		}

		debug_print("Copying message %s%c%d to %s ...\n",
			    msginfo->folder->path, G_DIR_SEPARATOR,
			    msginfo->msgnum, dest->path);


		if (MSG_IS_MOVE(msginfo->flags)) {
			msginfo->flags.tmp_flags &= ~MSG_MOVE_DONE;
			if (move_file(srcfile, destfile, TRUE) < 0) {
				FILE_OP_ERROR(srcfile, "move");
				if (copy_file(srcfile, destfile, TRUE) < 0) {
					FILE_OP_ERROR(srcfile, "copy");
					g_free(srcfile);
					g_free(destfile);
					goto err_reset_status;
				}
			} else {
				/* say unlinking's not necessary */
				msginfo->flags.tmp_flags |= MSG_MOVE_DONE;
			}
		} else if (copy_file(srcfile, destfile, TRUE) < 0) {
			FILE_OP_ERROR(srcfile, "copy");
			g_free(srcfile);
			g_free(destfile);
			goto err_reset_status;
		} 
		if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
			if (chmod(destfile, prefs->folder_chmod) < 0)
				FILE_OP_ERROR(destfile, "chmod");
		}
		if (relation) {
			if (g_hash_table_lookup(relation, msginfo) != NULL)
				g_warning("already in : %p", msginfo);
			
			g_hash_table_insert(relation, msginfo, GINT_TO_POINTER(dest->last_num+1));
		}
		g_free(srcfile);
		g_free(destfile);
		dest->last_num++;
	}

	g_free(srcpath);
	mh_write_sequences(dest, TRUE);

	if (dest->mtime == last_dest_mtime && !dest_need_scan) {
		mh_set_mtime(folder, dest);
	}

	if (src && src->mtime == last_src_mtime && !src_need_scan) {
		mh_set_mtime(folder, src);
	}

	if (total > 100) {
		statusbar_progress_all(0,0,0);
		statusbar_pop_all();
	}
	return dest->last_num;
err_reset_status:
	g_free(srcpath);
	mh_write_sequences(dest, TRUE);
	if (total > 100) {
		statusbar_progress_all(0,0,0);
		statusbar_pop_all();
	}
	return -1;

}
コード例 #25
0
ファイル: commands.c プロジェクト: pstef/cq410z
/* then move temp to msgfile*/
void rmessage(void) {
  int unlink();
  FILE *mesgfp;
  FILE *fptemp;
  int i;
  int count, msglen;
  int contd;
  int done = FALSE;
  char tempfile[FILELTH];
  char mesgfile[FILELTH];
  char line[LINELTH + 1], inpch;
  char save[LINELTH][LINELTH + 1];
  struct stat fst;

  /* open file; used in mailopen() as well */
  sprintf(tempfile, "/tmp/%s.%03d-tmp", msgfile, country);
  if ((fptemp = fopen(tempfile, "w")) == NULL) {
    clear_bottom(0);
    sprintf(mesgfile, "error: %s open", tempfile);
    errormsg(mesgfile);
    redraw = DONE;
    makebottom();
    return;
  }
  chmod(tempfile, (mode_t) FCMASK);
  sprintf(mesgfile, "%s.%03d", msgfile, country);
  if ((mesgfp = fopen(mesgfile, "r")) == NULL) {
    (void) unlink(tempfile);
    clear_bottom(0);
    errormsg("No Messages");
    makebottom();
    redraw = DONE;
    return;
  }
  /* check for people sending mail */
  sprintf(line, "send.%s-%03d", msgfile, country);
  if (stat(line, &fst) == 0) {
    long now;

    now = time(0);
    if (now - fst.st_mtime < TIME_DEAD) {
      /* someone is sending mail to the country */
      (void) unlink(tempfile);
      clear_bottom(0);
      errormsg("Someone is sending you mail... please wait.");
      makebottom();
      redraw = DONE;
      return;
    } else {
      /* remove useless file */
      (void) unlink(line);
    }
  }
  /* read in file a line at at time */
  if (fgets(line, LINELTH, mesgfp) == NULL) {
    done = TRUE;
    redraw = DONE;
    clear_bottom(0);
    errormsg("No messages");
    makebottom();
  }
  if (done == FALSE)
    clear();
  while (done == FALSE) {
    contd = FALSE;
    msglen = 0;
    count = 3;
    clear();
    standout();
    /* print to end of message */
    while (contd == FALSE) {
      if (msglen < LINELTH)
        strcpy(save[msglen], line);
      if (count == LINES - 3) {
        standout();
        mvaddstr(LINES - 3, (COLS / 2) - 8, "--- more ---");
        standend();
        refresh();
        getch();
        clear();
        count = 3;
      }
      mvprintw(count, 0, "%s", line);
      standend();
      count++;
      msglen++;
      if (fgets(line, LINELTH, mesgfp) == NULL)
        contd = TRUE;
      if (strncmp(line, "END", 3) == 0)
        contd = TRUE;
    }
    standout();
    mvaddstr(LINES - 3, (COLS / 2) - 13, "HIT ANY KEY TO CONTINUE");
    mvaddstr(LINES - 2, (COLS / 2) - 16, "HIT RETURN TO DELETE MESSAGE");
    standend();
    refresh();
    inpch = getch();
    if ((inpch != '\n' && inpch != '\r')) {
      for (i = 0; i < msglen; i++)
        fputs(save[i], fptemp);
      strcpy(line, "END\n");
      fputs(line, fptemp);
    }
    if (fgets(line, LINELTH, mesgfp) == NULL)
      done = TRUE;
  }
#ifdef USE_COMPRESS
  pclose(mesgfp);
  pclose(fptemp);
#else
  fclose(mesgfp);
  fclose(fptemp);
#endif
  chmod(mesgfile, (mode_t) FCMASK);
  chmod(tempfile, (mode_t) FCMASK);

  /* IMPLEMENT A MOVE BETWEEN TMP FILE AND REAL FILE HERE */
  move_file(tempfile, mesgfile);

#ifdef SYSMAIL
  /* increase size to ensure mail check works */
  conq_mail_size++;
#endif /* SYSMAIL */
}
コード例 #26
0
ファイル: bogofilter.c プロジェクト: eworm-de/claws-mail
static void bogofilter_do_filter(BogoFilterData *data)
{
	GPid bogo_pid;
	gint bogo_stdin, bogo_stdout;
	GError *error = NULL;
	gboolean bogo_forked;
	int status = 0;
	MsgInfo *msginfo;
	GSList *cur = NULL;
	int total = 0, curnum = 1;
	gchar *file = NULL;
	gchar buf[BUFSIZ];

	total = g_slist_length(data->msglist);

	bogo_forked = g_spawn_async_with_pipes(
			NULL, data->bogo_args,NULL, G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD,
			NULL, NULL, &bogo_pid, &bogo_stdin,
			&bogo_stdout, NULL, &error);
		
	if (bogo_forked == FALSE) {
		g_warning("%s", error ? error->message:"ERROR???");
		g_error_free(error);
		error = NULL;
		status = -1;
	} else {
	
		if (config.whitelist_ab) {
			gchar *ab_folderpath;

			if (*config.whitelist_ab_folder == '\0' ||
				strcasecmp(config.whitelist_ab_folder, "Any") == 0) {
				/* match the whole addressbook */
				ab_folderpath = NULL;
			} else {
				/* match the specific book/folder of the addressbook */
				ab_folderpath = config.whitelist_ab_folder;
			}

			start_address_completion(ab_folderpath);
		}

		for (cur = data->msglist; cur; cur = cur->next) {
			gboolean whitelisted = FALSE;
			msginfo = (MsgInfo *)cur->data;
			debug_print("Filtering message %d (%d/%d)\n", msginfo->msgnum, curnum, total);

			if (message_callback != NULL)
				message_callback(NULL, total, curnum++, data->in_thread);

			if (config.whitelist_ab && msginfo->from && 
			    found_in_addressbook(msginfo->from))
				whitelisted = TRUE;

			/* can set flags (SCANNED, ATTACHMENT) but that's ok 
			 * as GUI updates are hooked not direct */

			file = procmsg_get_message_file(msginfo);

			if (file) {
				gchar *tmp = g_strdup_printf("%s\n",file);
				/* send filename to bogofilter */
				write_all(bogo_stdin, tmp, strlen(tmp));
				g_free(tmp);
				memset(buf, 0, sizeof(buf));
				/* get the result */
				if (read(bogo_stdout, buf, sizeof(buf)-1) < 0) {
					g_warning("bogofilter short read");
					debug_print("message %d is ham\n", msginfo->msgnum);
					data->mail_filtering_data->unfiltered = g_slist_prepend(
						data->mail_filtering_data->unfiltered, msginfo);
					data->new_hams = g_slist_prepend(data->new_hams, msginfo);
				} else {
					gchar **parts = NULL;

					buf[sizeof(buf) - 1] = '\0';
					if (strchr(buf, '/')) {
						tmp = strrchr(buf, '/')+1;
					} else {
						tmp = buf;
					}
					parts = g_strsplit(tmp, " ", 0);
					debug_print("read %s\n", buf);
					
					/* note the result if the header if needed */
					if (parts && parts[0] && parts[1] && parts[2] && 
					    FOLDER_TYPE(msginfo->folder->folder) == F_MH &&
					    config.insert_header) {
						gchar *tmpfile = get_tmp_file();
						FILE *input = claws_fopen(file, "r");
						FILE *output = claws_fopen(tmpfile, "w");
						if (strstr(parts[2], "\n"))
							*(strstr(parts[2], "\n")) = '\0';
						if (input && !output) 
							claws_fclose (input);
						else if (!input && output)
							claws_fclose (output);
						else if (input && output) {
							gchar tmpbuf[BUFFSIZE];
							gboolean err = FALSE;
							const gchar *bogosity = *parts[1] == 'S' ? "Spam":
										 (*parts[1] == 'H' ? "Ham":"Unsure");
							gchar *tmpstr = g_strdup_printf(
									"X-Bogosity: %s, spamicity=%s%s\n",
									bogosity, parts[2],
									whitelisted?" [whitelisted]":"");
							if (claws_fwrite(tmpstr, 1, strlen(tmpstr), output) < strlen(tmpstr)) {
								err = TRUE;
							} else {
								while (claws_fgets(tmpbuf, sizeof(buf), input)) {
									if (claws_fputs(tmpbuf, output) == EOF) {
										err = TRUE;
										break;
									}
								}
							}
							claws_fclose(input);
							if (claws_safe_fclose(output) == EOF)
								err = TRUE;
							if (!err)
								move_file(tmpfile, file, TRUE);
							g_free(tmpstr);
						}
						g_free(tmpfile);
					}

					/* file the mail */
					if (!whitelisted && parts && parts[0] && parts[1] && *parts[1] == 'S') {

						debug_print("message %d is spam\n", msginfo->msgnum);
						/* Spam will be filtered away, unless we want "mark only".
						 * In that case, we want it among unfiltered messages, so
						 * it gets processed further. */
						if (config.receive_spam == SPAM_MARK_ONLY) {
							data->mail_filtering_data->unfiltered = g_slist_prepend(
								data->mail_filtering_data->unfiltered, msginfo);
						} else {
							data->mail_filtering_data->filtered = g_slist_prepend(
								data->mail_filtering_data->filtered, msginfo);
						}
						data->new_spams = g_slist_prepend(data->new_spams, msginfo);

					} else if (whitelisted && parts && parts[0] && parts[1] && 
							(*parts[1] == 'S' || *parts[1] == 'U')) {

						debug_print("message %d is whitelisted %s\n", msginfo->msgnum,
							*parts[1] == 'S' ? "spam":"unsure");
						/* Whitelisted spam will *not* be filtered away, but continue
						 * their trip through filtering as if it was ham. */
						data->mail_filtering_data->unfiltered = g_slist_prepend(
							data->mail_filtering_data->unfiltered, msginfo);
						/* But it gets put in a different list, so that we 
						 * can still flag it and inform the user that it is
						 * considered a spam (so that he can teach bogo that 
						 * it was not). */
						data->whitelisted_new_spams = g_slist_prepend(data->whitelisted_new_spams, msginfo);

					} else if (config.save_unsure && parts && parts[0] && parts[1] && *parts[1] == 'U') {
						
						debug_print("message %d is unsure\n", msginfo->msgnum);
						/* Spam will be filtered away */
						data->mail_filtering_data->filtered = g_slist_prepend(
							data->mail_filtering_data->filtered, msginfo);
						data->new_unsure = g_slist_prepend(data->new_unsure, msginfo);

					} else {
						
						debug_print("message %d is ham\n", msginfo->msgnum);
						data->mail_filtering_data->unfiltered = g_slist_prepend(
							data->mail_filtering_data->unfiltered, msginfo);
						data->new_hams = g_slist_prepend(data->new_hams, msginfo);

					}
					g_strfreev(parts);
				}
				g_free(file);
			} else {
				data->mail_filtering_data->unfiltered = g_slist_prepend(
					data->mail_filtering_data->unfiltered, msginfo);
				data->new_hams = g_slist_prepend(data->new_hams, msginfo);
			}
		}
		if (config.whitelist_ab)
			end_address_completion();
	}
	if (status != -1) {
		close(bogo_stdout);
		close(bogo_stdin);
		waitpid(bogo_pid, &status, 0);
		if (!WIFEXITED(status))
			status = -1;
		else
			status = WEXITSTATUS(status);
	}

	to_filter_data->status = status; 
}
コード例 #27
0
ファイル: eft_cr_knn.c プロジェクト: huilang22/Projects
/*
***********************************************************
*    Function: create_knn_file()
*
*    Description: read data, write file
*
*    Input:    none
*
*    Output:	num_trans - total number of transactions written
*		debit_amt - total amount of debit transactions
*		credit_amt - total amount of credit transactions
*
*    Return:  1 if SUCCESS, 0 if FAILURE, -1 if Serious Error
*             2 if Process success, but file contains no detail record
****************************************************************
*/
static 
int create_knn_file(int *num_trans, int *num_closed,
	Arb_numeric *debit_amt, Arb_numeric *credit_amt)
{
    int status;
    char   file_name[szPATHNAME];
    char   ready_name[szPATHNAME];
    FILE   *file_fd;
	char   error_name[szPATHNAME];
    Arb_numeric result = ARB_NUMERIC_ZERO;

    sprintf(file_name, "%s/%s.%.2d.%d",  gWork_path, gFile_name, gServer_id, gFile_id);
    sprintf(ready_name, "%s/%s.%.2d.%d",gReady_path, gFile_name, gServer_id, gFile_id);
	sprintf(error_name, "%s/%s.%.2d.%d", gError_path, gFile_name, gServer_id, gFile_id);

    /* open file */
    if ((file_fd = fopen(file_name, "w")) == NULL) {
	emit(FILE_LINE, EFT_OPEN_ERR, errno, file_name);
	return(0);
    }

    /* write FILE HEADER */
    if (knn_write_header(file_fd) != 1) {
	emit(FILE_LINE, EFT_WRITE_HEADER, "file");
	fclose(file_fd);
	return(0);
    }

    /* read transaction data, write to file, summarize totals */
    if ((status = knn_write_recs(file_fd, num_trans, num_closed,
		debit_amt, credit_amt)) != 1)
    {
	if(status != 2)
	{
		/* ERROR: TRANS records for this file_id must be handled manually */
		emit(FILE_LINE, EFT_READ_LOCKED, gFile_id);
	}
	fclose(file_fd);
	if (move_file(file_name, error_name) == FAILURE)
	{
		emit(FILE_LINE, EFT_MOVE_FILE, errno, file_name, error_name);
	}

	return(status);
    }

    arb_num_arith(&result, debit_amt, ARB_NUM_ADD, credit_amt);

    /* write trailer record */
    if (knn_write_trailer(file_fd, *num_trans - *num_closed, &result) != 1) {
	emit(FILE_LINE, EFT_WRITE_TRAILER, "file");
	fclose(file_fd);
	return(0);
    }

    fclose(file_fd);


    /* DO CLEANUP AND DATABASE STATUS UPDATES */

    /* Move send file to ready directory */

    if (move_file(file_name, ready_name) == FAILURE) {
	emit(FILE_LINE, EFT_MOVE_FILE, errno, file_name, ready_name);
	/* unlink(file_name); */
	return(0);
    }

    return(1);
}
コード例 #28
0
ファイル: cit-helper.c プロジェクト: ConnectIT/streamvise
/**
 * This function writes a setting to a configuration file (*filename input). The setting to
 * be written is *towrite and the setting's name is *setting. The delimiter used
 * for each configuration file can be different, so *delimiter input is required.
 * Returns 1 for success, -1 for failure
 *
 * @todo: Make debugging (DBG) printfs run only if debugging mode is ON
 * @param char * the filename of the file to be edited
 * @param char * the name of the setting to be written/edited
 * @param char * the value to be written
 * @param char * delimiter used for the specific configuration file
 */
int writesetting(char *filename, char *setting, char *towrite, char *delimiter){

	printf("Will write string %s in file %s, as setting %s\n", towrite, filename, setting);
	FILE *file;
	FILE *filetmp;
	size_t len = 0;
	char *line = NULL; //Will hold one line of the conf file
	int foundflag = 0; //Flag: Did we find the setting we were looking for? NOT found by default


	if (filetmp = fopen("/tmp/filetmp","w")) {
	  if (file = fopen(filename,"r") ) { // Open the file	
      	    printf("DBG: scanning through the lines\n");
	    while ((getline(&line, &len, file)) != -1) { //Scan through the lines

			  char tmp[100];	//TODO: maybe tmp should be defined as char *tmp[1] ???			
			  sprintf(tmp, "%.*s\n", 1, &line[0]); //Save the line to a temporary variable
     
			  //Now do 2 checks:
			  //1. First character of line is not "#", so this is not a comment line
			  //2. Try to find the string we're looking for. If not null, we found it!
			  if (strstr(tmp, "#") == NULL && strstr(line, setting) != NULL){ 
  					foundflag = 2; //The setting has been found
  		          printf("DBG: Setting found. Changing it\n");

        /*	TODO: Uncomment the following, in order to enable smart searching and writing

            //Is this about a dns setting?
            if (strstr(setting, "option  dns") != NULL) {
  				  printf("This is a dns request.");
					
  				  strtok(line, delimiter); //Skip the line's first word
  				  strtok(NULL, delimiter); //Skip the line's second word
				    //If the third word is the same as the one we would write...
  				  if (strstr(towrite, strdup(strtok(NULL , delimiter))) != NULL) {
  				    fprintf(filetmp, "%s", line); //Just rewrite the line
  				  }else{//Append the line to the file
  				    fprintf(filetmp, "%s", line); //First rewrite the line
				      //Then append the new line:
  				    fprintf(filetmp,"%s%s%s\n", setting, delimiter, towrite);
  				  }
  				}else{ //This is not a DNS setting, just write the new value
      */
					  fprintf(filetmp,"%s%s%s\n", setting, delimiter, towrite);
 	    //	}
			  }else{ //This is not the line we were looking for. Rewrite it just to move the fprintf pointer.
				  fprintf(filetmp, "%s", line);
			          printf("DBG: Not the line we're looking for. Rewriting it\n");
			  }			
      }


      if (foundflag == 0) { //If setting has not been found in file, write it
  			fprintf(filetmp,"%s%s%s\n", setting, delimiter, towrite);
  			printf("DBG: Setting not found, writing it\n");
  			foundflag = 0;
  		}
  		printf("DBG: Closing files\n");
		  fclose(file);
		  fclose(filetmp);

		  move_file("/tmp/filetmp", filename); //Move the temporary file over the original settings file, overwriting it
		  return 1;
	  }else{
		  printf("Error opening file %s!\n", filename);
		  return -1;
	  } //End else
	} //End if
}
コード例 #29
0
ファイル: partial_download.c プロジェクト: Mortal/claws
static int partial_uidl_mark_mail(MsgInfo *msginfo, int download)
{
	gchar *path;
	gchar *pathnew;
	FILE *fp;
	FILE *fpnew;
	gchar buf[POPBUFSIZE];
	gchar uidl[POPBUFSIZE];
	time_t recv_time;
	time_t now;
	gchar partial_recv[POPBUFSIZE];
	int err = -1;
	gchar *filename;
	MsgInfo *tinfo;
	gchar *sanitized_uid = NULL;	

	filename = procmsg_get_message_file_path(msginfo);
	if (!filename) {
		g_warning("can't get message file path.");
		return err;
	}
	tinfo = procheader_parse_file(filename, msginfo->flags, TRUE, TRUE);
	
	if (!tinfo->extradata) {
		g_free(filename);
		return err;
	}

	sanitized_uid = g_strdup(tinfo->extradata->account_login);
	subst_for_filename(sanitized_uid);

	if (!tinfo->extradata->account_server
	||  !tinfo->extradata->account_login
	||  !tinfo->extradata->partial_recv) {
		goto bail;
	}
	path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
			   "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
			   "-", sanitized_uid, NULL);

	if ((fp = g_fopen(path, "rb")) == NULL) {
		perror("fopen1");
		if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
		g_free(path);
		path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
				   "uidl-", tinfo->extradata->account_server,
				   "-", tinfo->extradata->account_login, NULL);
		if ((fp = g_fopen(path, "rb")) == NULL) {
			if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
			g_free(path);
			goto bail;
		}
	}

	pathnew = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
			   "uidl", G_DIR_SEPARATOR_S, tinfo->extradata->account_server,
			   "-", sanitized_uid, ".new", NULL);
	
	g_free(sanitized_uid);

	if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
		perror("fopen2");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	
	now = time(NULL);

	while (fgets(buf, sizeof(buf), fp) != NULL) {
		strretchomp(buf);
		recv_time = RECV_TIME_NONE;
		sprintf(partial_recv,"0");
		
		if (sscanf(buf, "%s\t%ld\t%s", 
			   uidl, (long int *) &recv_time, partial_recv) < 2) {
			if (sscanf(buf, "%s", uidl) != 1)
				continue;
			else {
				recv_time = now;
			}
		}
		if (strcmp(tinfo->extradata->partial_recv, uidl)) {
			if (fprintf(fpnew, "%s\t%ld\t%s\n", 
				uidl, (long int) recv_time, partial_recv) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(path);
				g_free(pathnew);
				goto bail;
			}
		} else {
			gchar *stat = NULL;
			if (download == POP3_PARTIAL_DLOAD_DLOAD) {
				gchar *folder_id = folder_item_get_identifier(
							msginfo->folder);
				stat = g_strdup_printf("%s:%d",
					folder_id, msginfo->msgnum);
				g_free(folder_id);
			}
			else if (download == POP3_PARTIAL_DLOAD_UNKN)
				stat = g_strdup("1");
			else if (download == POP3_PARTIAL_DLOAD_DELE)
				stat = g_strdup("0");
			
			if (fprintf(fpnew, "%s\t%ld\t%s\n", 
				uidl, (long int) recv_time, stat) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(path);
				g_free(pathnew);
				goto bail;
			}
			g_free(stat);
		}
	}
	if (fclose(fpnew) == EOF) {
		FILE_OP_ERROR(pathnew, "fclose");
		fclose(fp);
		g_free(path);
		g_free(pathnew);
		goto bail;
	}
	fclose(fp);

	move_file(pathnew, path, TRUE);

	g_free(path);
	g_free(pathnew);
	
	if ((fp = g_fopen(filename,"rb")) == NULL) {
		perror("fopen3");
		goto bail;
	}
	pathnew = g_strdup_printf("%s.new", filename);
	if ((fpnew = g_fopen(pathnew, "wb")) == NULL) {
		perror("fopen4");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	
	if (fprintf(fpnew, "SC-Marked-For-Download: %d\n", 
			download) < 0) {
		FILE_OP_ERROR(pathnew, "fprintf");
		fclose(fpnew);
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}
	while (fgets(buf, sizeof(buf)-1, fp) != NULL) {
		if(strlen(buf) > strlen("SC-Marked-For-Download: x\n")
		&& !strncmp(buf, "SC-Marked-For-Download:", 
		            strlen("SC-Marked-For-Download:"))) {
			if (fprintf(fpnew, "%s", 
			 buf+strlen("SC-Marked-For-Download: x\n")) < 0) {
				FILE_OP_ERROR(pathnew, "fprintf");
				fclose(fpnew);
				fclose(fp);
				g_free(pathnew);
				goto bail;
			}
			continue;
		} else if (strlen(buf) == strlen("SC-Marked-For-Download: x\n")
		&& !strncmp(buf, "SC-Marked-For-Download:", 
		            strlen("SC-Marked-For-Download:"))) {
			continue;
		}
		if (fprintf(fpnew, "%s", buf) < 0) {
			FILE_OP_ERROR(pathnew, "fprintf");
			fclose(fpnew);
			fclose(fp);
			g_free(pathnew);
			goto bail;
		}
	}
	if (fclose(fpnew) == EOF) {
		FILE_OP_ERROR(pathnew, "fclose");
		fclose(fp);
		g_free(pathnew);
		goto bail;
	}

	fclose(fp);
	if (rename_force(pathnew, filename) != 0) {
		g_free(pathnew);
		goto bail;
	}

	g_free(pathnew);
	msginfo->planned_download = download;
	msgcache_update_msg(msginfo->folder->cache, msginfo);

	err = 0;
bail:
	g_free(filename);
	procmsg_msginfo_free(&tinfo);
	
	return err;
}
コード例 #30
0
ファイル: eft_cr_frn.c プロジェクト: huilang22/Projects
/*
***********************************************************
*    Function: create_frn_file()
*
*    Description: read data, write file
*
*    Input:    none
*
*    Output:	num_trans - total number of transactions written
*		debit_amt - total amount of debit transactions
*		credit_amt - total amount of credit transactions
*
*    Return:  1 if SUCCESS, 0 if FAILURE, -1 if Serious Error
*             2 if Process success, but file contains no detail record
****************************************************************
*/
static 
int create_frn_file(int *num_trans, int *num_closed,
	Arb_numeric *debit_amt, Arb_numeric *credit_amt,
	CURRENCY_STRUCT *currency_struct)
{
    int status;
    char   file_name[szPATHNAME];
    char   ready_name[szPATHNAME];
    FILE   *file_fd;
	char   error_name[szPATHNAME];

    sprintf(file_name, "%s/%s.%.2d.%d",  gWork_path, gFile_name, gServer_id, gFile_id);
    sprintf(ready_name, "%s/%s.%.2d.%d",gReady_path, gFile_name, gServer_id, gFile_id);
	sprintf(error_name, "%s/%s.%.2d.%d", gError_path, gFile_name, gServer_id, gFile_id);
	/* CAMqa54502 - pass in currency_struct) */

    /* open file */
    if ((file_fd = fopen(file_name, "w")) == NULL) {
	emit(FILE_LINE, EFT_OPEN_ERR, errno, file_name);
	return(0);
    }

    /* write FILE HEADER */
    if (frn_write_header(file_fd, currency_struct) != 1) {
	emit(FILE_LINE, EFT_WRITE_HEADER, "file");
	fclose(file_fd);
	return(0);
    }

    /* read transaction data, write to file, summarize totals */
    if ((status = frn_write_recs(file_fd, num_trans, num_closed, debit_amt, credit_amt, currency_struct)) != 1)
    {
	if(status != 2)
	{
		/* ERROR: TRANS records for this file_id must be handled manually */
		emit(FILE_LINE, EFT_READ_LOCKED, gFile_id);
	}
	fclose(file_fd);
	if (move_file(file_name, error_name) == FAILURE)
	{
		emit(FILE_LINE, EFT_MOVE_FILE, errno, file_name, error_name);
	}
	return(status);
    }

    /***********************************************************/
    /* CAMqa86327 - Pass in debit and credit amount separately */
    /* to trailer record                                       */
    /***********************************************************/

    /* write trailer record */
    if (frn_write_trailer(file_fd, debit_amt, credit_amt) != 1) {
	emit(FILE_LINE, EFT_WRITE_TRAILER, "file");
	fclose(file_fd);
	return(0);
    }

    fclose(file_fd);


    /* DO CLEANUP AND DATABASE STATUS UPDATES */

    /* Move send file to ready directory */

    if (move_file(file_name, ready_name) == FAILURE) {
	emit(FILE_LINE, EFT_MOVE_FILE, errno, file_name, ready_name);
	/* unlink(file_name); */
	return(0);
    }

    return(1);
}