WMII Reforge  Artifact [0da522b9d2]

Artifact 0da522b9d2cd2fe50a7f21f2506ff9e7ab4bf75fa856265e90843065ede53040:

  • File lib/libstuff/util/comm.c — part of check-in [15eae1e8e6] at 2019-06-20 16:42:23 on branch trunk — Import sources to have something to work with (user: KhazAkar size: 748)

/* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail>
 * See LICENSE file for license details.
 */
#include <string.h>
#include "util.h"
#include <stuff/x11.h>


char**
comm(int cols, char **toka, char **tokb) {
	Vector_ptr vec;
	char **ret;
	int cmp;

	vector_pinit(&vec);
	while(*toka || *tokb) {
		if(!*toka)
			cmp = 1;
		else if(!*tokb)
			cmp = -1;
		else
			cmp = strcmp(*toka, *tokb);
		if(cmp < 0) {
			if(cols & CLeft)
				vector_ppush(&vec, *toka);
			toka++;
		}else if(cmp > 0) {
			if(cols & CRight)
				vector_ppush(&vec, *tokb);
			tokb++;
		}else {
			if(cols & CCenter)
				vector_ppush(&vec, *toka);
			toka++;
			tokb++;
		}
	}
	vector_ppush(&vec, nil);
	ret = strlistdup((char**)vec.ary);
	free(vec.ary);
	return ret;
}