~ubuntu-branches/ubuntu/natty/9base/natty

« back to all changes in this revision

Viewing changes to sam/util.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2010-06-04 17:22:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100604172203-ei85j0da495sr8ut
Tags: 1:6-1
* Adding Kai as co-maintainer.
* Merging upstream version 6.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "sam.h"
 
2
 
 
3
void
 
4
cvttorunes(char *p, int n, Rune *r, int *nb, int *nr, int *nulls)
 
5
{
 
6
        uchar *q;
 
7
        Rune *s;
 
8
        int j, w;
 
9
 
 
10
        /*
 
11
         * Always guaranteed that n bytes may be interpreted
 
12
         * without worrying about partial runes.  This may mean
 
13
         * reading up to UTFmax-1 more bytes than n; the caller
 
14
         * knows this.  If n is a firm limit, the caller should
 
15
         * set p[n] = 0.
 
16
         */
 
17
        q = (uchar*)p;
 
18
        s = r;
 
19
        for(j=0; j<n; j+=w){
 
20
                if(*q < Runeself){
 
21
                        w = 1;
 
22
                        *s = *q++;
 
23
                }else{
 
24
                        w = chartorune(s, (char*)q);
 
25
                        q += w;
 
26
                }
 
27
                if(*s)
 
28
                        s++;
 
29
                else if(nulls)
 
30
                        *nulls = TRUE;
 
31
        }
 
32
        *nb = (char*)q-p;
 
33
        *nr = s-r;
 
34
}
 
35
 
 
36
void*
 
37
fbufalloc(void)
 
38
{
 
39
        return emalloc(BUFSIZE);
 
40
}
 
41
 
 
42
void
 
43
fbuffree(void *f)
 
44
{
 
45
        free(f);
 
46
}
 
47
 
 
48
uint
 
49
min(uint a, uint b)
 
50
{
 
51
        if(a < b)
 
52
                return a;
 
53
        return b;
 
54
}