From: wessels <> Date: Fri, 27 Feb 1998 00:47:59 +0000 (+0000) Subject: gindent X-Git-Tag: SQUID_3_0_PRE1~3971 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f6aaeace12a859bedb0b3b5d16d4be877f71f539;p=thirdparty%2Fsquid.git gindent --- diff --git a/lib/MemPool.c b/lib/MemPool.c index 646364b5f4..e7d163ff75 100644 --- a/lib/MemPool.c +++ b/lib/MemPool.c @@ -1,5 +1,5 @@ /* - * $Id: MemPool.c,v 1.4 1998/02/25 17:39:46 rousskov Exp $ + * $Id: MemPool.c,v 1.5 1998/02/26 17:47:59 wessels Exp $ * * AUTHOR: Alex Rousskov * @@ -52,26 +52,26 @@ Synopsis: * pre-allocated objects and 10% for dynamic stack. Any of the first two * parameters can be 0. If name is NULL "anonymous" will be used instead */ - MemPool *mp1 = memPoolCreate(objCnt, objCnt/10, objSz, "urls"); +MemPool * mp1 = memPoolCreate(objCnt, objCnt / 10, objSz, "urls"); /* * getting a new object from a pool; object buffer is initialized with 0s */ - void *buf = memPoolGetObj(mp1); +void *buf = memPoolGetObj(mp1); /* * returning an object back */ - memPoolPutObj(mp1, buf); +memPoolPutObj(mp1, buf); /* * accounting: generate report as an ASCII string * warning: static buffer is used, strdup your copy! */ - char *report = xstrdup(memPoolReport()); +char *report = xstrdup(memPoolReport()); /* destroy your pools when done playing! */ - memPoolDestroy(mp1); +memPoolDestroy(mp1); #endif /* synopsis */ @@ -91,18 +91,18 @@ memPoolCreate(size_t preallocCnt, size_t dynStackCnt, size_t objSz, const char * mp->buf = xcalloc(preallocCnt, objSz); mp->obj_size = objSz; mp->name = xstrdup(poolName ? poolName : "anonymous"); - mp->_buf_end = mp->buf + objSz*preallocCnt; /* internal, never dereference this! */ + mp->_buf_end = mp->buf + objSz * preallocCnt; /* internal, never dereference this! */ mp->static_stack = stackCreate(preallocCnt); mp->dynamic_stack = stackCreate(dynStackCnt); /* other members are initialized with 0 because of calloc() */ /* push all pre-allocated memory on stack because it is currently free */ - while(preallocCnt-- > 0) - stackPush(mp->static_stack, mp->buf + objSz*preallocCnt); + while (preallocCnt-- > 0) + stackPush(mp->static_stack, mp->buf + objSz * preallocCnt); return mp; } void -memPoolDestroy(MemPool *mp) +memPoolDestroy(MemPool * mp) { assert(mp); /* could also warn if some objects are left */ @@ -120,13 +120,12 @@ memPoolDestroy(MemPool *mp) * never fails */ void * -memPoolGetObj(MemPool *mp) +memPoolGetObj(MemPool * mp) { assert(mp); if (mp->static_stack->count) return stackPop(mp->static_stack); - else - if (mp->dynamic_stack->count) + else if (mp->dynamic_stack->count) return stackPop(mp->dynamic_stack); /* have to alloc, monitor high whater mark */ if (++mp->alloc_count - mp->free_count > mp->alloc_high_water) @@ -139,30 +138,30 @@ memPoolGetObj(MemPool *mp) * corresponding stack is full */ void -memPoolPutObj(MemPool *mp, void *obj) +memPoolPutObj(MemPool * mp, void *obj) { assert(mp); /* static object? */ - if (mp->buf <= (char*)obj && mp->_buf_end > (char*)obj) { - assert(!mp->static_stack->is_full); /* never full if we got here! */ + if (mp->buf <= (char *) obj && mp->_buf_end > (char *) obj) { + assert(!mp->static_stack->is_full); /* never full if we got here! */ stackPush(mp->static_stack, obj); } else - /* dynamic object, but stack may be full */ + /* dynamic object, but stack may be full */ if (!mp->dynamic_stack->is_full) { assert(mp->alloc_count); stackPush(mp->dynamic_stack, obj); } else { - /* free-ing is the last option */ + /* free-ing is the last option */ mp->free_count++; assert(mp->free_count <= mp->alloc_count); - xfree(obj); /* do this after assert */ + xfree(obj); /* do this after assert */ } } const char * -memPoolReport(MemPool *mp) +memPoolReport(MemPool * mp) { - static char buf[1024]; /* we do not use LOCALL_ARRAY in squid/lib, do we? */ + static char buf[1024]; /* we do not use LOCALL_ARRAY in squid/lib, do we? */ assert(mp); snprintf(buf, sizeof(buf), @@ -171,7 +170,7 @@ memPoolReport(MemPool *mp) mp->name, mp->obj_size, mp->static_stack->capacity, - (double)(mp->obj_size*mp->static_stack->capacity)/1024., + (double) (mp->obj_size * mp->static_stack->capacity) / 1024., mp->dynamic_stack->capacity, mp->static_stack->capacity + mp->static_stack->pop_count - mp->static_stack->push_count, mp->alloc_count - mp->free_count, diff --git a/lib/Stack.c b/lib/Stack.c index cc55683bd6..b8b2e67c90 100644 --- a/lib/Stack.c +++ b/lib/Stack.c @@ -1,5 +1,5 @@ /* - * $Id: Stack.c,v 1.2 1998/02/21 00:56:38 rousskov Exp $ + * $Id: Stack.c,v 1.3 1998/02/26 17:49:54 wessels Exp $ * * AUTHOR: Alex Rousskov * @@ -41,23 +41,25 @@ #if 0 -Synopsis: - - /* - * creating a stack that can hold up to objCnt pointers. - * If objCnt is zero, the stack is always full (disabled) - */ - Stack *s1 = stackCreate(objCnt); - Stack *s2 = stackCreate(objCnt*2); - - /* - * pop/push works as expected; it is OK to push a null pointer - */ - if (!s2->is_full && s1->count) - stackPush(s2, stackPop(s1)); +Synopsis(void) +{ - /* destroying a stack */ - stackDestroy(s1); + /* + * creating a stack that can hold up to objCnt pointers. + * If objCnt is zero, the stack is always full (disabled) + */ + Stack *s1 = stackCreate(objCnt); + Stack *s2 = stackCreate(objCnt * 2); + + /* + * pop/push works as expected; it is OK to push a null pointer + */ + if (!s2->is_full && s1->count) + stackPush(s2, stackPop(s1)); + + /* destroying a stack */ + stackDestroy(s1); +} #endif /* Synopsis */ @@ -75,16 +77,16 @@ Stack * stackCreate(size_t capacity) { Stack *s = xcalloc(1, sizeof(Stack)); - s->buf = capacity > 0 ? xcalloc(capacity, sizeof(void*)) : NULL; + s->buf = capacity > 0 ? xcalloc(capacity, sizeof(void *)) : NULL; s->capacity = capacity; - s->count = 0; - s->is_full = stackIsFull(s); - /* other members are set to 0 in calloc */ + s->count = 0; + s->is_full = stackIsFull(s); + /* other members are set to 0 in calloc */ return s; } void -stackDestroy(Stack *s) +stackDestroy(Stack * s) { assert(s); /* could also warn if some objects are left */ @@ -94,23 +96,23 @@ stackDestroy(Stack *s) } void * -stackPop(Stack *s) +stackPop(Stack * s) { void *popped; assert(s); assert(s->count); popped = s->buf[--s->count]; s->is_full = stackIsFull(s); - s->pop_count++; /* might overflow eventually, but ok */ + s->pop_count++; /* might overflow eventually, but ok */ return popped; } void -stackPush(Stack *s, void *obj) +stackPush(Stack * s, void *obj) { assert(s); assert(!s->is_full); s->buf[s->count++] = obj; s->is_full = stackIsFull(s); - s->push_count++; /* might overflow eventually, but ok */ + s->push_count++; /* might overflow eventually, but ok */ } diff --git a/lib/base64.c b/lib/base64.c index 02cfe085fb..61d5d9f1f3 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -80,32 +80,32 @@ base64_encode(const char *decoded_str) if (!base64_initialized) base64_init(); - while ((c = *decoded_str++) && out_cnt < sizeof(result)-1) { - bits += c; - char_count++; - if (char_count == 3) { - result[out_cnt++] = base64_code[bits >> 18]; - result[out_cnt++] = base64_code[(bits >> 12) & 0x3f]; - result[out_cnt++] = base64_code[(bits >> 6) & 0x3f]; - result[out_cnt++] = base64_code[bits & 0x3f]; - bits = 0; - char_count = 0; + while ((c = *decoded_str++) && out_cnt < sizeof(result) - 1) { + bits += c; + char_count++; + if (char_count == 3) { + result[out_cnt++] = base64_code[bits >> 18]; + result[out_cnt++] = base64_code[(bits >> 12) & 0x3f]; + result[out_cnt++] = base64_code[(bits >> 6) & 0x3f]; + result[out_cnt++] = base64_code[bits & 0x3f]; + bits = 0; + char_count = 0; } else { - bits <<= 8; + bits <<= 8; } } if (char_count != 0) { - bits <<= 16 - (8 * char_count); - result[out_cnt++] = base64_code[bits >> 18]; - result[out_cnt++] = base64_code[(bits >> 12) & 0x3f]; - if (char_count == 1) { - result[out_cnt++] = '='; - result[out_cnt++] = '='; + bits <<= 16 - (8 * char_count); + result[out_cnt++] = base64_code[bits >> 18]; + result[out_cnt++] = base64_code[(bits >> 12) & 0x3f]; + if (char_count == 1) { + result[out_cnt++] = '='; + result[out_cnt++] = '='; } else { - result[out_cnt++] = base64_code[(bits >> 6) & 0x3f]; - result[out_cnt++] = '='; + result[out_cnt++] = base64_code[(bits >> 6) & 0x3f]; + result[out_cnt++] = '='; } } - result[out_cnt] = '\0'; /* terminate */ + result[out_cnt] = '\0'; /* terminate */ return result; }