64 lines
1.2 KiB
C
64 lines
1.2 KiB
C
|
/*
|
||
|
* This file is part of the UCB release of Plan 9. It is subject to the license
|
||
|
* terms in the LICENSE file found in the top-level directory of this
|
||
|
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
|
||
|
* part of the UCB release of Plan 9, including this file, may be copied,
|
||
|
* modified, propagated, or distributed except according to the terms contained
|
||
|
* in the LICENSE file.
|
||
|
*/
|
||
|
|
||
|
#include "sam.h"
|
||
|
|
||
|
void
|
||
|
cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls)
|
||
|
{
|
||
|
uchar *q;
|
||
|
Rune *s;
|
||
|
int j, w;
|
||
|
|
||
|
/*
|
||
|
* Always guaranteed that n bytes may be interpreted
|
||
|
* without worrying about partial runes. This may mean
|
||
|
* reading up to UTFmax-1 more bytes than n; the caller
|
||
|
* knows this. If n is a firm limit, the caller should
|
||
|
* set p[n] = 0.
|
||
|
*/
|
||
|
q = (uchar*)p;
|
||
|
s = r;
|
||
|
for(j=0; j<n; j+=w){
|
||
|
if(*q < Runeself){
|
||
|
w = 1;
|
||
|
*s = *q++;
|
||
|
}else{
|
||
|
w = chartorune(s, (char*)q);
|
||
|
q += w;
|
||
|
}
|
||
|
if(*s)
|
||
|
s++;
|
||
|
else if(nulls)
|
||
|
*nulls = TRUE;
|
||
|
}
|
||
|
*nb = (char*)q-p;
|
||
|
*nr = s-r;
|
||
|
}
|
||
|
|
||
|
void*
|
||
|
fbufalloc(void)
|
||
|
{
|
||
|
return emalloc(BUFSIZE);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
fbuffree(void *f)
|
||
|
{
|
||
|
free(f);
|
||
|
}
|
||
|
|
||
|
uint
|
||
|
min(uint a, uint b)
|
||
|
{
|
||
|
if(a < b)
|
||
|
return a;
|
||
|
return b;
|
||
|
}
|