Plan 9 from Bell Labs’s /usr/web/sources/contrib/akumar/dict/src/dictd.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <bio.h>
#include "dict.h"

/* 
 * dictd-based dictionary files
 * slightly modified
 */

/* 
 * the index file contains the name of the world, 
 * in lowercase, and the location in the dictionary file
 * as a character offset from the beginning.
 *  
 * the index file is created separately by gunzipping 
 * the original dictionary file and running a program
 * which looks for the beginning of each word.
 * 
 * the dictionary is a flat file, unencrypted (and utf-8
 * encoded!)
 *  
 * entries in the dictionary are separated by an empty
 * line.
 */

#define	GSHORT(p)	(((p)[0]<<8)|(p)[1])

void
dictdprintentry(Entry e, int cmd)
{
	uchar *p, *pe;


	p = (uchar *)e.start;
	pe = (uchar *)e.end;

	if(cmd == 'h') 
		while(*p != '\n' && p < pe) 
			outchar(*p++);
	else 
		while(p < pe) {
			if(*p == '\n')
				*p = ' ';
			outchar(*p++);
		}


	outnl(0);
}

long
dictdnextoff(long fromoff)
{
	int o, n, a;
	
	o = 0;
	a = Bseek(bdict, fromoff, 0);
	if(a < 0)
		return -1;
	for(;;) {
		n = Bgetc(bdict);
		if(!n)
			break;
		if(n == '\n' && o == '\n')
			return (Boffset(bdict)-2);
		o = n;
	}
	return -1;
}

void
dictdprintkey(void)
{
	Bprint(bout, "No key\n");
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].