Beispiel #1
0
int
locate(void)
{
	vlong top, bot, mid;
	long c;
	int n;

	bot = 0;
	top = Bseek(dfile, 0, 2);
	for(;;) {
		mid = (top+bot) / 2;
		Bseek(dfile, mid, 0);
		do
			c = Bgetrune(dfile);
		while(c>=0 && c!='\n');
		mid = Boffset(dfile);
		if(!getword(dfile, entry, sizeof(entry)/sizeof(entry[0])))
			break;
		rcanon(entry, word);
		n = compare(key, word);
		switch(n) {
		case -2:
		case -1:
		case 0:
			if(top <= mid)
				break;
			top = mid;
			continue;
		case 1:
		case 2:
			bot = mid;
			continue;
		}
		break;
	}
	Bseek(dfile, bot, 0);
	while(getword(dfile, entry, sizeof(entry)/sizeof(entry[0]))) {
		rcanon(entry, word);
		n = compare(key, word);
		switch(n) {
		case -2:
			return 0;
		case -1:
			if(exact)
				return 0;
		case 0:
			return 1;
		case 1:
		case 2:
			continue;
		}
	}
	return 0;
}
Beispiel #2
0
/* smooth  != 0 gives continuous not segmented bar */
progressbar newprogressbar(rect r, int pbmin, int pbmax, int incr, int smooth)
{
	HWND hwnd;
	progressbar obj;
	int sm;

	ensure_window();
	r = rcanon(r);
	sm = smooth ? PBS_SMOOTH : 0 ;
	hwnd = CreateWindowEx(0, PROGRESS_CLASS, NULL,
		(WS_CHILD | WS_VISIBLE | sm),
		r.x, r.y, r.width, r.height,
		current_window->handle,
		(HMENU) child_id, this_instance, NULL);
	obj = new_object(ControlObject, hwnd, current_window);
	if (! obj) {
		DestroyWindow(hwnd);
		return NULL;
	}
	obj->die = private_delcontrol;
	obj->rect = r;
	obj->id = child_id++;
	obj->action = NULL;
	obj->state = (Visible | Enabled);
	obj->flags = ChildWindow;
	set_new_winproc(obj); /* set custom winproc */
	settextfont(obj, SystemFont);
	obj->kind = ListboxObject;
	SendMessage(hwnd, PBM_SETRANGE32, (WPARAM) pbmin, (LPARAM) pbmax);
	SendMessage(hwnd, PBM_SETSTEP, (WPARAM) incr, 0);

	return obj;
}
Beispiel #3
0
scrollbar newscrollbar(rect r, int max, int pagesize, scrollfn fn)
{
	scrollbar obj;
	HWND hwnd;

	r = rcanon(r);

	obj = newchildwin("scrollbar", NULL,
			(r.width > r.height) ? SBS_HORZ : SBS_VERT,
			r, NULL);
	if (obj) {
		obj->kind = ScrollbarObject;
		obj->hit = fn;
		obj->value = 0;
		obj->max = max;
		obj->size = pagesize;

		hwnd = obj->handle;
		si.cbSize = sizeof(si);
		si.fMask = SIF_ALL;
		si.nMin = 0;
		si.nMax = max + pagesize - 1;
		si.nPage = pagesize;
		si.nPos = 0;
		SetScrollInfo(hwnd, SB_CTL, &si, 1);
	}
	return obj;
}
Beispiel #4
0
static object newchildwin(char *kind, char *text,
		unsigned long style, rect r, actionfn fn)
{
	HWND hwnd;
	object obj;

	ensure_window();
	r = rcanon(r);

	hwnd = CreateWindow(kind, text,
		(WS_CHILD | WS_VISIBLE) | style,
		r.x, r.y, r.width, r.height,
		current_window->handle,
		(HMENU) child_id, this_instance, NULL);

	obj = new_object(ControlObject, hwnd, current_window);
	if (! obj) {
		DestroyWindow(hwnd);
		return NULL;
	}
	obj->die = private_delcontrol;
	obj->rect = r;
	obj->id = child_id++;
	obj->action = fn;
	obj->state = (Visible | Enabled);
	obj->flags = ChildWindow;
	obj->text = new_string(text);
	set_new_winproc(obj); /* set custom winproc */
	settextfont(obj, SystemFont);
	return obj;
}
Beispiel #5
0
void
main(int argc, char *argv[])
{
	int n;

	Binit(&bin, 0, OREAD);
	Binit(&bout, 1, OWRITE);
	compare = acomp;
	ARGBEGIN{
	case 'd':
		direc++;
		break;
	case 'f':
		fold++;
		break;
	case 'i': 
		iflag++;
		break;
	case 'n':
		compare = ncomp;
		break;
	case 't':
		chartorune(&tab, EARGF(usage()));
		break;
	case 'x':
		exact++;
		break;
	default:
		fprint(2, "%s: bad option %c\n", argv0, ARGC());
		usage();
	} ARGEND
	if(!iflag){
		if(argc >= 1) {
			torune(argv[0], orig);
			argv++;
			argc--;
		} else
			iflag++;
	}
	if(argc < 1) {
		direc++;
		fold++;
	} else 
		filename = argv[0];
	if (!iflag)
		rcanon(orig, key);
	dfile = Bopen(filename, OREAD);
	if(dfile == 0) {
		fprint(2, "look: can't open %s\n", filename);
		exits("no dictionary");
	}
	if(!iflag)
		if(!locate())
			exits("not found");
	do {
		if(iflag) {
			Bflush(&bout);
			if(!getword(&bin, orig, sizeof(orig)/sizeof(orig[0])))
				exits(0);
			rcanon(orig, key);
			if(!locate())
				continue;
		}
		if (!exact || !acomp(word, key))
			Bprint(&bout, "%S\n", entry);
		while(getword(dfile, entry, sizeof(entry)/sizeof(entry[0]))) {
			rcanon(entry, word);
			n = compare(key, word);
			switch(n) {
			case -1:
				if(exact)
					break;
			case 0:
				if (!exact || !acomp(word, orig))
					Bprint(&bout, "%S\n", entry);
				continue;
			}
			break;
		}
	} while(iflag);
	exits(0);
}