vector.c

来自「CFL是Unix下的通用抽象库,以简化Unix下的系统软件开发,CFL库中包含几」· C语言 代码 · 共 107 行

C
107
字号
/* ----------------------------------------------------------------------------   CFL - A C Foundation Library   Copyright (C) 1994-2003  Mark A Lindner   This file is part of CFL.      This library is free software; you can redistribute it and/or   modify it under the terms of the GNU Library General Public   License as published by the Free Software Foundation; either   version 2 of the License, or (at your option) any later version.      This library is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU   Library General Public License for more details.      You should have received a copy of the GNU Library General Public   License along with this library; if not, write to the Free   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   ----------------------------------------------------------------------------   $Log: vector.c,v $   Revision 1.1  2003/03/03 08:20:08  markl   Initial checkin (clean compile on Solaris & OS X)   ----------------------------------------------------------------------------*//* Feature test switches */#include "config.h"/* Local headers */#include "cfl/defs.h"#include "cfl/system.h"#include "cfl/util.h"/* Functions */c_vector_t *C_vector_start(uint_t resize_rate)  {  c_vector_t *v = C_new(c_vector_t);  v->len = v->c = 0;  v->vs = v->v = C_newa(resize_rate, char *);  v->blk = 1;  v->blksz = resize_rate;  return(v);  }/* */c_bool_t C_vector_store(c_vector_t *v, const char *s)  {   if(!v || !s)    return(FALSE);  *(v->v) = (char *)s;  (v->len)++;  if(++(v->c) == v->blksz)    {    v->c = 0;    v->vs = C_realloc(v->vs, v->blksz * ++(v->blk), char *);    v->v = v->vs + ((v->blk - 1) * v->blksz);    }  else    (v->v)++;  return(TRUE);  }/* */char **C_vector_end(c_vector_t *v, uint_t *len)  {  char **r;  if(!v) return(NULL);  if(len) *len = v->len;  r = C_realloc(v->vs, ++(v->len), char *);  *(r + v->len - 1) = NULL;  C_free(v);  return(r);  }/* */void C_vector_abort(c_vector_t *v)  {  if(v)    {    C_free_vec(v->vs);    C_free(v);    }  }/* end of source file */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?