Esempio n. 1
0
File: seq_save.c Progetto: dscho/nmh
void
seq_save (struct msgs *mp)
{
    size_t i;
    char flags, *cp, attr[BUFSIZ], seqfile[PATH_MAX];
    FILE *fp;
    sigset_t set, oset;

    /* check if sequence information has changed */
    if (!(mp->msgflags & SEQMOD)) {
    	if (mp->seqhandle) {
	    lkfclosedata (mp->seqhandle, mp->seqname);
	    mp->seqhandle = NULL;
	    free(mp->seqname);
	    mp->seqname = NULL;
	}
	return;
    }
    mp->msgflags &= ~SEQMOD;

    fp = NULL;
    flags = mp->msgflags;	/* record folder flags */

    /*
     * If no mh-sequences file is defined, or if a mh-sequences file
     * is defined but empty (*mh_seq == '\0'), then pretend folder
     * is readonly.  This will force all sequences to be private.
     */
    if (mh_seq == NULL || *mh_seq == '\0')
	set_readonly (mp);
    else
	snprintf (seqfile, sizeof(seqfile), "%s/%s", mp->foldpath, mh_seq);

    for (i = 0; i < svector_size (mp->msgattrs); i++) {
	snprintf (attr, sizeof(attr), "atr-%s-%s",
		  svector_at (mp->msgattrs, i), mp->foldpath);

	/* get space separated list of sequence ranges */
	if (!(cp = seq_list(mp, svector_at (mp->msgattrs, i)))) {
	    context_del (attr);			/* delete sequence from context */
	    continue;
	}

	if (is_readonly(mp) || is_seq_private(mp, i)) {
priv:
	    /*
	     * sequence is private
	     */
	    context_replace (attr, cp);		/* update sequence in context   */
	} else {
	    /*
	     * sequence is public
	     */
	    context_del (attr);			/* delete sequence from context */

	    if (!fp) {
		/*
		 * Attempt to open file for public sequences.
		 * If that fails (probably because folder is
		 * readonly), then make sequence private.
		 */

		if (mp->seqhandle) {
		    fp = mp->seqhandle;
		    mp->seqhandle = NULL;
		    free(mp->seqname);
		    mp->seqname = NULL;
		    rewind(fp);
		    ftruncate(fileno(fp), 0);
		} else if ((fp = lkfopendata (seqfile, "w")) == NULL
			&& (m_unlink (seqfile) == -1 ||
			    (fp = lkfopendata (seqfile, "w")) == NULL)) {
		    admonish (attr, "unable to write");
		    goto priv;
		}

		/* block a few signals */
		sigemptyset (&set);
		sigaddset(&set, SIGHUP);
		sigaddset(&set, SIGINT);
		sigaddset(&set, SIGQUIT);
		sigaddset(&set, SIGTERM);
		sigprocmask (SIG_BLOCK, &set, &oset);
	    }
	    fprintf (fp, "%s: %s\n", svector_at (mp->msgattrs, i), cp);
	}
    }

    if (fp) {
	lkfclosedata (fp, seqfile);
	sigprocmask (SIG_SETMASK, &oset, &set);  /* reset signal mask */
    } else {
	/*
	 * If folder is not readonly, and we didn't save any
	 * public sequences, then remove that file.
	 */
	if (!is_readonly(mp))
	    (void) m_unlink (seqfile);
    }

    /*
     * Reset folder flag, since we may be
     * pretending that folder is readonly.
     */
    mp->msgflags = flags;
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
	clock_t tick = clock();

	std::list<std::string> names_list({"jcheng", "empty", "hello"});
	names_list.push_back("push_back");

	std::list<std::string>::iterator iter = names_list.begin();
	for (; iter != names_list.end(); ++iter){
		std::cout << *iter << " ";
	}
	std::cout << std::endl;

	std::list<std::string> value_list(10, "abc");
	for (auto itr: value_list){
		std::cout << itr << " ";
	}
	std::cout << std::endl;

	int sequeue_nums[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};	
	std::list<int> num_list(sequeue_nums, sequeue_nums + 10);
	for (auto itr = num_list.begin(); itr != num_list.end(); ++itr){
		std::cout << *itr << " ";
	}
	std::cout << std::endl;

	std::list<char> alph_list;
	for (char ch = 'a'; ch <= 'z'; ++ch){
		alph_list.push_back(ch);
	}

	std::list<char> ralph_list(alph_list);
	ralph_list.reverse();
	auto itr = ralph_list.rbegin();
	for (; itr != ralph_list.rend(); ++itr){
		std::cout << *itr << " ";
	}
	std::cout << std::endl;

	for (auto& itr: ralph_list){
		itr = toupper(itr);
	}

	for (auto itr: ralph_list){
		std::cout << itr << " ";
	}
	std::cout << std::endl;
/*
	while(!alph_list.empty()){
		std::cout << alph_list.front() << " ";
		alph_list.pop_front();
	}
	std::cout << std::endl;
*/
	alph_list.remove('a');
	alph_list.pop_front();
	//alph_list.erase('c');
	alph_list.remove_if([](const char value){
			if (value > 'c' && value < 'h')
				return true;
			return false;
		});

	std::list<char> seq_list(alph_list.begin(), alph_list.end());
	seq_list.insert(seq_list.end(), 3, 'A');
	seq_list.insert(seq_list.end(), alph_list.begin(), alph_list.end());

	for (auto itr: seq_list){
		std::cout << itr << " ";
	}
	std::cout << std::endl;

	std::cout << "ticks: " << clock() - tick << std::endl;

	return 0;
}