Skip to content

Commit

Permalink
syntax sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
iceman1001 committed Jan 25, 2018
1 parent a6c50d7 commit 20e9931
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
60 changes: 26 additions & 34 deletions client/reveng/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -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);
Expand All @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions zlib/trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/* ===========================================================================
Expand Down

0 comments on commit 20e9931

Please sign in to comment.