Mercurial > ~dholland > hg > ag > index.cgi
view help2html/support.c @ 13:43d8b194fb4e
Remove unused variables.
author | David A. Holland |
---|---|
date | Tue, 31 May 2022 00:59:00 -0400 |
parents | 60d3ca9d3f6b |
children |
line wrap: on
line source
#include <stdlib.h> #include <string.h> #include <assert.h> #include <err.h> #include "must.h" #include "stringdict.h" #include "support.h" //////////////////////////////////////////////////////////// void intstack_init(struct intstack *is) { is->pos = 0; } void intstack_push(struct intstack *is, int val) { if (is->pos >= INTSTACKSIZE) { errx(1, "Paragraph stack overflow - increase INTSTACKSIZE and recompile"); } is->vals[is->pos++] = val; } int intstack_pop(struct intstack *is) { assert(is->pos > 0); return is->vals[--is->pos]; } int intstack_top(const struct intstack *is) { assert(is->pos > 0); return is->vals[is->pos-1]; } //////////////////////////////////////////////////////////// static const struct stringdict *sortdict; static int sorter(const void *av, const void *bv) { const char *as = stringdict_getbynum(sortdict, *(const unsigned *)av); const char *bs = stringdict_getbynum(sortdict, *(const unsigned *)bv); return strcmp(as, bs); } struct permutation *mySort(const struct stringdict *sd) { sortdict = sd; /* establish permutation vector */ int i, n = stringdict_count(sortdict); int *pv = must_malloc(n*sizeof(int)); for (i=0; i<n; i++) { pv[i] = i; } /* sort it */ qsort(pv, n, sizeof(int), sorter); sortdict = NULL; /* return it */ struct permutation *p = must_malloc(sizeof(*p)); p->v = pv; p->num = n; return p; } void permutation_destroy(struct permutation *p) { free(p->v); free(p); }