📄 vs.h
字号:
sELEMENT *vsndup PARAMS((sELEMENT *vary, int pos, sELEMENT *array, int len));/* sELEMENT *vsdup(sELEMENT *vary)); * Duplicate array. This is just a functionalized version of: * * vsndup(NULL, 0, vary, sLEN(vary)); * * but since you need to be able to refer to this particular function by * address often it's given here. * * (actually, there's bazillions of these simple combinations of the above * functions and the macros of the next section. You'll probably want to make * functionalized instances of the ones you use most often - especially since * the macros aren't safe). */sELEMENT *vsdup PARAMS((sELEMENT *vary));/* sELEMENT *vsset(sELEMENT *vary, int pos, sELEMENT element); * Set an element in an array. Any value of 'pos' is valid. A new array * is created if 'vary' is 0. The previous contents of the position is * deleted. This does not duplicate 'element'. If you need 'element' * duplicated, call: vsset(vary,pos,sdup(element)); */sELEMENT *_vsset PARAMS((sELEMENT *vary, int pos, sELEMENT el));#define vsset(v, p, el) \ (!(v) || (p) > sLen(v) || (p) >= sSiz(v) ? \ _vsset((v), (p), (el)) \ : \ ((p) == sLen(v) ? \ ((v)[(p) + 1] = 0, sLen(v) = (p) + 1, (v)[p] = (el), (v)) \ : \ ((v)[p] = (el), (v)) \ ) \ )/* sELEMENT *vsadd(sELEMENT *vary, sELEMENT element); * Concatenate a single element to the end of 'vary'. A new array is created * if 'vary' is 0. This does not duplicate element: call * vsadd(vary,sdup(element)); If you need it duplicated. */#define vsadd(v, el) \ (!(v) || sLen(v) == sSiz(v) ? \ _vsset((v), sLEN(v), (el)) \ : \ ((v)[sLen(v) + 1] = 0, (v)[sLen(v)] = (el), sLen(v) = sLen(v) + 1, (v)) \ )/**************************************//* Functions which read from an array *//**************************************//* These macros are used to generate the address/size pairs which get * passed to the functions of the previous section. *//* { sELEMENT *, int } sv(sELEMENT *array); * Return array, size pair. Uses sLEN to get size. */#define sv(a) (a), sLEN(a)/* { sELEMENT *, int } sz(sELEMENT *array); * Return array, size pair. Uses slen to get size. */#define sz(a) (a), slen(a)/* { sELEMENT *, int } sc(sELEMENT *array); * Return array, size pair. Uses 'sizeof' to get size. */#define sc(a) (unsigned char *)(a), (sizeof(a) / sizeof(sELEMENT) - 1)/* { sELEMENT *, int } srest(sELEMENT *vary, int pos); * Return array, size pair of rest of array beginning at pos. If * pos is past end of array, gives size of 0. */#define srest(a, p) ((a) + (p)), (((p) > sLEN(a)) ? 0 : sLen(a) - (p))/* { sELEMENT *, int } spart(sELEMENT *vary, int pos, int len); * Return array,size pair of 'len' elements of array beginning with pos. If * pos is past end of array, gives size of 0. If pos+len is past end of array, * returns number of elements to end of array. */#define spart(a, p, l) \ ((a) + (p)), ((p) >= sLEN(a) ? 0 : ((p) + (l) > sLen(a) ? sLen(a) - (p) : (l)))/* sELEMENT vsget(sELEMENT *vary, int pos); * Get an element from an array. Any value of pos is valid; if it's past the * end of the array or if 'vary' is 0, the terminator is returned. This * does not make a duplicate of the returned element. If you want that, pass * the return value of this to sdup. */#define vsget(a, p) ((p) >= sLEN(a) ? sterm : (a)[p])/**********************//* Insertion/Deletion *//**********************/#ifdef junk/* sELEMENT *vsins(sELEMENT *vary, int pos, int n)); * Insert n empty slots into the array. If 'pos' >= the length of the array, * the array is simply extended. The new slots are not set to anything. * This does not set the elements in the created hole to any particular * value: use vsfill if you need that to occur. */sELEMENT *vsins PARAMS((sELEMENT *vary, int pos, int n));/* sELEMENT *vsdel(sELEMENT *vary, int pos, int n)); * Delete n slots from the array. This does not zap the elements first; call * vszap first if you need this to happen. */sELEMENT *vsdel PARAMS((SELEMENT *vary, int pos, int n));/*************************//* Searching and Sorting *//*************************//* sELEMENT *vssort(sELEMENT *ary, int len)) * Sort the elements of an array (char or variable length) using qsort(). */sELEMENT *vssort PARAMS((sELEMENT *ary, int len));#endif/* int vsbsearch(sELEMENT *ary, int len, sELEMENT element); * Do a binary search on a sorted variable length or char array. Returns position * of matching element or the position where the element should be if it was * not found. (You should test with scmp to find out which). * * Hmm... this should really indicate whether or not the element was found. */int vsbsearch PARAMS((sELEMENT *ary, int len, sELEMENT el));#ifdef junk/* int vsfirst(sELEMENT *ary, int len, sELEMENT element); * Find offset to first matching element in 'vary' or return ~0 if not found. */int vsfirst PARAMS((sELEMENT *ary, int len, sELEMENT element));/* int vslast(sELEMENT *ary, int len, sELEMENT element); * Find offset to last matching element in 'vary' or return ~0 if none found. */int vslast PARAMS((sELEMENT *ary, int len, sELEMENT element));/* int vss(sELEMENT *a, int alen, sELEMENT *b, int blen); * Do a substring search on 'a'. Return offset from 'a' to first matching * occurance of 'b' in 'a' or return ~0 if none found. */int vss PARAMS((sELEMENT *a, int alen, sELEMENT *b, int blen));#endif/* int vscmpn(sELEMENT *a, int alen, sELEMENT *b, int blen); * * Compare two arrays using scmp. If 'a' > 'b', return 1. If 'a' == 'b', * return 0. If 'a' < 'b', return -1. Longer strings are > shorter ones if * their beginning match. */int vscmpn PARAMS((sELEMENT *a, int alen, sELEMENT *b, int blen));/* int vscmp(sELEMENT *a, sELEMENT *b); * * Functionalized version of: vscmpn(sv(a), sv(b)); */int vscmp PARAMS((sELEMENT *a, sELEMENT *b));#ifdef junk/* int vsicmpn(sELEMENT *a, int alen, sELEMENT *b, int blen); * * Compare two arrays using sicmp. If 'a' > 'b', return 1. If 'a' == 'b', * return 0. If 'a' < 'b', return -1. Longer strings are > shorter ones if * their beginning match. * * This is same as vscmpn except that it is case insensitive. */int vsicmpn PARAMS((sELEMENT *a, int alen, sELEMENT *b, int blen));/* int vsicmp(sELEMENT *a, sELEMENT *b); * * Functionalized version of: vsicmpn(sv(a), sv(b)); */int vsicmp PARAMS((sELEMENT *a, sELEMENT *b));#endif/* int vsscan(sELEMENT *a, int alen, sELEMENT *b, int blen); * Find offset of first matching element in 'a' which matches any * of the elements passed in 'b'. Array 'b' must be sorted. * * Hmm... this really needs to return what the found element is. */int vsscan PARAMS((sELEMENT *a, int alen, sELEMENT *b, int blen));/* int vsspan(sELEMENT *a, int alen, sELEMENT *b, int blen); * Find offset of first matching element in 'a' which does not match any * of the elements passed in 'b'. Array 'b' must be sorted. */int vsspan PARAMS((sELEMENT *a, int alen, sELEMENT *b, int blen));/***************//* Other stuff *//***************/#ifdef junk/* char *vsread(char *d, int p, int (*getC)(void *ptr), void *ptr); * Replace 'd' with next line read from read-character function 'getC'. If * 'd' is 0, a new string is allocated. If there is no more input, the string * is freed and 0 is returned. The \n is deleted from the entered line. * * 'ptr' is passed as the first arg to 'getC'. 'getC' should return -1 if * there is no more input. */unsigned char *vsread PARAMS(());/* char *vwords(char *s, char **a, int len, char t); * * Generate a 't'-seperated word list from the words in the zero-terminated * array of zero-terminated strings 'a'. For example a simple 'echo.c': * * main(argc, argv) * char *argv[]; * { * printf("%s\n",vwords(NULL,argv,argc,' ')): * } * */unsigned char *vwords PARAMS(());#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -