include/vec.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

vecvec_init (unsigned long int initsize)
vecvec_read (int srcfd, unsigned int size)
vecvec_copy (const struct vec *vec)
vecvec_reinit (struct vec *v, unsigned long int initsize)
int vec_free (struct vec *vec)
void vec_resetpos (struct vec *vec)
void vec_reseterr (struct vec *vec)
unsigned long int vec_putvbyte (struct vec *vec, unsigned long int n)
unsigned long int vec_getvbyte (struct vec *vec, unsigned long int *n)
unsigned long int vec_scanvbyte (struct vec *vec)
unsigned int vec_vbyte_len (unsigned long int n)
int vec_err (const struct vec *vec)
int vec_eof (const struct vec *vec)
unsigned long int vec_length (const struct vec *vec)
unsigned long int vec_position (const struct vec *vec)
unsigned int vec_write (struct vec *src, int dstfd)
unsigned int vec_append (struct vec *dst, const struct vec *src)
int vec_cmp (const struct vec *one, const struct vec *two)


Function Documentation

unsigned int vec_append ( struct vec dst,
const struct vec src 
)

Definition at line 96 of file vec.c.

References vec::err, vec::len, vec::pos, vec::size, vec_expand(), and vec::vector.

00096                                                                 {
00097     unsigned int size = src->len - src->pos;
00098 
00099     /* expand vector if required */
00100     while ((dst->size < dst->pos + size) && vec_expand(dst, dst->pos + size)) ;
00101 
00102     if (!dst->err && (dst != src)) {
00103         /* append stuff */
00104         memcpy(dst->vector + dst->pos, src->vector + src->pos, size);
00105         dst->pos += size;
00106         dst->len = dst->pos;
00107         return size;
00108     } else {
00109         return 0;
00110     }
00111 }

Here is the call graph for this function:

int vec_cmp ( const struct vec one,
const struct vec two 
)

Definition at line 293 of file vec.c.

References vec::len, and vec::vector.

00293                                                           {
00294     if (one->len != two->len) {
00295         return one->len - two->len;
00296     } else {
00297         return (memcmp(one->vector, two->vector, one->len));
00298     }
00299 }

struct vec* vec_copy ( const struct vec vec  )  [read]

Definition at line 219 of file vec.c.

References vec::len, vec::pos, and vec::vector.

00219                                           {
00220     struct vec* nv = malloc(sizeof(*nv));
00221 
00222     if (nv && (nv->vector = malloc(v->len))) {
00223         nv->pos = v->pos;
00224         nv->len = v->len;
00225         nv->size = v->len;
00226         nv->err = 0;
00227         memcpy(nv->vector, v->vector, nv->size);
00228     } else if (nv) {
00229         free(nv);
00230         return NULL;
00231     }
00232 
00233     return nv;
00234 }

int vec_eof ( const struct vec vec  ) 

Definition at line 207 of file vec.c.

References vec::len, and vec::pos.

00207                                  {
00208     return (v->pos == v->len);
00209 }

int vec_err ( const struct vec vec  ) 

Definition at line 203 of file vec.c.

References vec::err.

00203                                  {
00204     return v->err;
00205 }

int vec_free ( struct vec vec  ) 

Definition at line 82 of file vec.c.

References vec::vector.

Referenced by get_list_at().

00082                             {
00083     free(v->vector);
00084     free(v);
00085     return 1;
00086 }

Here is the caller graph for this function:

unsigned long int vec_getvbyte ( struct vec vec,
unsigned long int *  n 
)

Definition at line 139 of file vec.c.

References vec::err, vec::len, vec::pos, and vec::vector.

Referenced by get_list_at().

00139                                                                     {
00140     unsigned long int ret = 1, 
00141                       count = 0, 
00142                       get = 0;
00143 
00144     *n = 0;
00145     while (v->pos < v->len) {
00146         if (((get = ((uint8_t) v->vector[v->pos++])) & 0x80) == 0x80) {
00147             /* For each time we get a group of 7 bits, need to left-shift the 
00148                latest group by an additional 7 places, since the groups were 
00149                effectively stored in reverse order.*/
00150             *n |= ((get & 0x7f) << count);
00151             ret++;
00152             count += 7;
00153         } else if (ret > (sizeof(*n))) {
00154             if (ret == ((sizeof(*n) + 1)) 
00155               && (get < (1 << (sizeof(*n) + 1)))) {
00156                 /* its a large, but valid number */
00157                 *n |= get << count;
00158                 return ret;
00159             } else {
00160                 /* we've overflowed, return error */
00161                 return 0;
00162             }
00163         } else {
00164             /* Now get the final 7 bits, which need to be left-shifted by a 
00165                factor of 7. */
00166             *n |= get << count;
00167             return ret;
00168         }
00169     }
00170 
00171     v->err = ENOSPC;
00172     return 0;
00173 }

Here is the caller graph for this function:

struct vec* vec_init ( unsigned long int  initsize  )  [read]

Definition at line 36 of file vec.c.

Referenced by get_list_at().

00036                                                  {
00037     struct vec* v = malloc(sizeof(*v));
00038 
00039     if (v && (v->vector = malloc(initsize))) {
00040         v->size = initsize;
00041         v->pos = v->len = 0;
00042         v->err = 0;
00043         return v;
00044     } else if (v) {
00045         free(v);
00046     }
00047 
00048     return NULL;
00049 }

Here is the caller graph for this function:

unsigned long int vec_length ( const struct vec vec  ) 

Definition at line 215 of file vec.c.

References vec::len.

00215                                                   {
00216     return v->len;
00217 }

unsigned long int vec_position ( const struct vec vec  ) 

Definition at line 211 of file vec.c.

References vec::pos.

00211                                                     {
00212     return v->pos;
00213 }

unsigned long int vec_putvbyte ( struct vec vec,
unsigned long int  n 
)

Definition at line 114 of file vec.c.

References vec::err, GROWTHFACTOR, vec::len, vec::pos, vec::size, vec_expand(), and vec::vector.

00114                                                                    {
00115     unsigned long int ret = 1;
00116 
00117     while (n >= 128) {
00118         if ((v->pos >= v->size) && !vec_expand(v, GROWTHFACTOR * v->size + 1)) {
00119             v->err = ENOSPC;
00120             return 0;
00121         }
00122         
00123         v->vector[v->pos++] = (char) ((n & 0x7f) | 0x80);
00124         n >>= 7;
00125         ret++;
00126     }
00127 
00128     if ((v->pos >= v->size) && !vec_expand(v, GROWTHFACTOR * v->size + 1)) {
00129         v->err = ENOSPC;
00130         return 0;
00131     }
00132     
00133     v->vector[v->pos++] = (char) n;
00134     v->len = v->pos;                 /* truncate vector */
00135     
00136     return ret;
00137 }

Here is the call graph for this function:

struct vec* vec_read ( int  srcfd,
unsigned int  size 
) [read]

Definition at line 261 of file vec.c.

References vec_read_inplace().

00261                                                   {
00262     struct vec* v;
00263 
00264     if ((v = malloc(sizeof(*v))) && vec_read_inplace(srcfd, v, len)) {
00265         return v;
00266     } else {
00267         if (v) {
00268             free(v);
00269         }
00270         return NULL;
00271     }
00272 }

Here is the call graph for this function:

struct vec* vec_reinit ( struct vec v,
unsigned long int  initsize 
) [read]

Definition at line 51 of file vec.c.

References vec::err, vec::len, vec::pos, vec::size, and vec::vector.

00051                                                                   {
00052     void* newmem;
00053 
00054     if (!v) {
00055         /* need to allocate a new vector */
00056         if ((v = malloc(sizeof(*v))) 
00057           && (v->vector = malloc(initsize))) {
00058             v->size = initsize;
00059             v->pos = v->len = 0;
00060             v->err = 0;
00061         } else if (v) {
00062             free(v);
00063             return NULL;
00064         } else {
00065             return NULL;
00066         }
00067     } else {
00068         /* reinit old one */
00069         if ((newmem = realloc(v->vector, initsize))) {
00070             v->size = initsize;
00071             v->vector = newmem;
00072             v->pos = v->len = 0;
00073             v->err = 0;
00074         } else {
00075             return NULL;
00076         }
00077     }
00078 
00079     return v;
00080 }

void vec_reseterr ( struct vec vec  ) 

Definition at line 92 of file vec.c.

References vec::err.

00092                                  {
00093     v->err = 0;
00094 }

void vec_resetpos ( struct vec vec  ) 

Definition at line 88 of file vec.c.

References vec::pos.

00088                                  {
00089     v->pos = 0;
00090 }

unsigned long int vec_scanvbyte ( struct vec vec  ) 

Definition at line 175 of file vec.c.

References vec::err, vec::len, vec::pos, and vec::vector.

00175                                                {
00176     unsigned long int ret = 1;
00177 
00178     while ((v->pos < v->len)) {
00179         if (!(v->vector[v->pos++] & 0x80)) { 
00180             return ret;
00181         }
00182         ret++;
00183     }
00184 
00185     v->err = ENOSPC;
00186     return 0;
00187 }

unsigned int vec_vbyte_len ( unsigned long int  n  ) 

Definition at line 301 of file vec.c.

00301                                                 {
00302     unsigned int ret = 1;
00303     while (n >= 128) {
00304         n >>= 7;
00305         ret++;
00306     }
00307     return ret;
00308 }

unsigned int vec_write ( struct vec src,
int  dstfd 
)

Definition at line 274 of file vec.c.

References vec::err, vec::len, vec::pos, and vec::vector.

00274                                                    {
00275     unsigned int wlen,
00276                  len = src->len - src->pos;
00277     char *srcbuf = src->vector;
00278 
00279 
00280     while (len && ((wlen = write(dstfd, srcbuf, len)) >= 0)) {
00281         len -= wlen;
00282         srcbuf += wlen;
00283     }
00284 
00285     if (!len) {
00286         return src->len - src->pos;
00287     } else {
00288         src->err = errno;
00289         return 0;
00290     }
00291 }


Generated on Wed Dec 19 20:52:51 2007 for fsa-blast by  doxygen 1.5.2