From 20e9931b63dab9e6185a0f24f9dc66645eeb9896 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Thu, 25 Jan 2018 18:45:13 +0100 Subject: [PATCH] syntax sugar --- client/reveng/model.c | 60 +++++++++++++++++++------------------------ zlib/trees.c | 3 +-- 2 files changed, 27 insertions(+), 36 deletions(-) diff --git a/client/reveng/model.c b/client/reveng/model.c index d1728b39f..c5eccb8b3 100644 --- a/client/reveng/model.c +++ b/client/reveng/model.c @@ -47,12 +47,11 @@ static const poly_t pzero = PZERO; /* Definitions */ -void -mcpy(model_t *dest, const model_t *src) { +void mcpy(model_t *dest, const model_t *src) { /* Copies the parameters of src to dest. * dest must be an initialised model. */ - if(!dest || !src) return; + if (!dest || !src) return; pcpy(&dest->spoly, src->spoly); pcpy(&dest->init, src->init); pcpy(&dest->xorout, src->xorout); @@ -63,10 +62,9 @@ mcpy(model_t *dest, const model_t *src) { dest->name = src->name; } -void -mfree(model_t *model) { +void mfree(model_t *model) { /* Frees the parameters of model. */ - if(!model) return; + if (!model) return; pfree(&model->spoly); pfree(&model->init); pfree(&model->xorout); @@ -76,25 +74,23 @@ mfree(model_t *model) { /* not model either, it might point to an array! */ } -int -mcmp(const model_t *a, const model_t *b) { +int mcmp(const model_t *a, const model_t *b) { /* Compares a and b for identical effect, i.e. disregarding * trailing zeroes in parameter polys. * Intended for bsearch(). */ int result; - if(!a || !b) return(!b - !a); - if((result = psncmp(&a->spoly, &b->spoly))) return(result); - if((result = psncmp(&a->init, &b->init))) return(result); - if((a->flags & P_REFIN) && (~b->flags & P_REFIN)) return(1); - if((~a->flags & P_REFIN) && (b->flags & P_REFIN)) return(-1); - if((a->flags & P_REFOUT) && (~b->flags & P_REFOUT)) return(1); - if((~a->flags & P_REFOUT) && (b->flags & P_REFOUT)) return(-1); - return(psncmp(&a->xorout, &b->xorout)); + if (!a || !b) return (!b - !a); + if ((result = psncmp(&a->spoly, &b->spoly))) return (result); + if ((result = psncmp(&a->init, &b->init))) return (result); + if ((a->flags & P_REFIN) && (~b->flags & P_REFIN)) return (1); + if ((~a->flags & P_REFIN) && (b->flags & P_REFIN)) return (-1); + if ((a->flags & P_REFOUT) && (~b->flags & P_REFOUT)) return (1); + if ((~a->flags & P_REFOUT) && (b->flags & P_REFOUT)) return (-1); + return (psncmp(&a->xorout, &b->xorout)); } -char * -mtostr(const model_t *model) { +char * mtostr(const model_t *model) { /* Returns a malloc()-ed string containing a Williams model * record representing the input model. * mcanon() should be called on the argument before printing. @@ -103,7 +99,7 @@ mtostr(const model_t *model) { char *polystr, *initstr, *xorotstr, *checkstr, *magicstr, strbuf[512], *string = NULL; - if(!model) return(NULL); + if (!model) return(NULL); polystr = ptostr(model->spoly, P_RTJUST, 4); initstr = ptostr(model->init, P_RTJUST, 4); xorotstr = ptostr(model->xorout, P_RTJUST, 4); @@ -122,7 +118,7 @@ mtostr(const model_t *model) { + (checkstr && *checkstr ? strlen(checkstr) : 6) + (magicstr && *magicstr ? strlen(magicstr) : 6) + (model->name && *model->name ? 2 + strlen(model->name) : 6); - if((string = malloc(size))) { + if ((string = malloc(size))) { sprintf(strbuf, "\"%s\"", model->name); sprintf(string, "width=%lu" @@ -154,12 +150,11 @@ mtostr(const model_t *model) { return(string); } -void -mcanon(model_t *model) { +void mcanon(model_t *model) { /* canonicalise a model */ unsigned long dlen; - if(!model) return; + if (!model) return; /* extending on the right here. This preserves the functionality * of a presumed working model. @@ -177,12 +172,11 @@ mcanon(model_t *model) { * might be noticed. Storing the Check value with each preset * is highly preferred. */ - if(!(plen(model->check) && plen(model->magic))) + if (!(plen(model->check) && plen(model->magic))) mcheck(model); } -void -mcheck(model_t *model) { +void mcheck(model_t *model) { /* calculate a check for the model */ poly_t checkstr, check, xorout, magic; @@ -195,7 +189,7 @@ mcheck(model_t *model) { checkstr = strtop("313233343536373839", model->flags, 8); check = pcrc(checkstr, model->spoly, model->init, pzero, model->flags); pfree(&checkstr); - if(model->flags & P_REFOUT) + if (model->flags & P_REFOUT) prev(&check); psum(&check, model->xorout, 0UL); model->check = check; @@ -206,17 +200,16 @@ mcheck(model_t *model) { * reflected before submitting the codeword. */ xorout=pclone(model->xorout); - if(model->flags & P_REFOUT) + if (model->flags & P_REFOUT) prev(&xorout); magic = pcrc(xorout, model->spoly, pzero, pzero, model->flags); pfree(&xorout); - if(model->flags & P_REFIN) + if (model->flags & P_REFIN) prev(&magic); model->magic = magic; } -void -mrev(model_t *model) { +void mrev(model_t *model) { /* reverse the model to calculate reversed CRCs */ /* Here we invert RefIn and RefOut so that the user need only * reverse the order of characters in the arguments, not the @@ -230,7 +223,7 @@ mrev(model_t *model) { poly_t temp; prcp(&model->spoly); - if(model->flags & P_REFOUT) + if (model->flags & P_REFOUT) prev(&model->init); else prev(&model->xorout); @@ -246,8 +239,7 @@ mrev(model_t *model) { mnovel(model); } -void -mnovel(model_t *model) { +void mnovel(model_t *model) { /* remove name and check string from modified model */ model->name = NULL; pfree(&model->check); diff --git a/zlib/trees.c b/zlib/trees.c index 49cce330a..df83f56a3 100644 --- a/zlib/trees.c +++ b/zlib/trees.c @@ -1012,8 +1012,7 @@ void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) s->compressed_len += 7; /* align on byte boundary */ #endif } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, - s->compressed_len-7*last)); + Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len >> 3, s->compressed_len - 7 * last)); } /* ===========================================================================