예제 #1
0
파일: term_ps.c 프로젝트: ajinkya93/OpenBSD
void
pspdf_free(void *arg)
{
	struct termp	*p;

	p = (struct termp *)arg;

	free(p->ps->psmarg);
	free(p->ps->pdfobjs);

	free(p->ps);
	term_free(p);
}
예제 #2
0
파일: pull.c 프로젝트: aprillinden/reprepro
static void pull_rule_free(/*@only@*/struct pull_rule *pull) {
	if (pull == NULL)
		return;
	free(pull->name);
	free(pull->from);
	atomlist_done(&pull->architectures_from);
	atomlist_done(&pull->architectures_into);
	atomlist_done(&pull->components);
	atomlist_done(&pull->udebcomponents);
	term_free(pull->includecondition);
	filterlist_release(&pull->filterlist);
	filterlist_release(&pull->filtersrclist);
	free(pull);
}
예제 #3
0
void
ascii_free(void *arg)
{

	term_free((struct termp *)arg);
}
예제 #4
0
static retvalue parseatom(const char **formula, /*@out@*/struct term_atom **atom, int options, const struct term_special *specials) {
	struct term_atom *a;
	const char *f = *formula;
#define overspace() while (*f != '\0' && xisspace(*f)) f++
	const char *keystart, *keyend;
	const char *valuestart, *valueend;
	enum term_comparison comparison = tc_none;
	bool negated = false;
	const struct term_special *s;


	overspace();
	if (*f == '!' && ISSET(options, T_NEGATION)) {
		negated = true;
		f++;
	}
	keystart = f;
	// TODO: allow more strict checking again with some option?
	while (*f != '\0' && *f != '(' && !xisspace(*f) && *f != ','
			&& *f != '|' && *f !='(' && *f != ')'
			&& *f != '[' && *f != '!')
		f++;
	keyend = f;
	if (keystart == keyend) {
		*formula = f;
		return RET_NOTHING;
	}
	overspace();
	if (ISSET(options, T_VERSION) && *f == '(') {
		f++;
		overspace();
		switch (*f) {
			case '>':
				f++;
				if (*f == '=') {
					comparison = tc_moreorequal;
					f++;
				} else if (*f == '>') {
					comparison = tc_strictmore;
					f++;
				} else {
					comparison = tc_moreorequal;
					fprintf(stderr,
"Warning: Found a '(>' without '=' or '>'  in '%s'(beginning cut), will be treated as '>='.\n",
							*formula);
				}
				break;
			case '<':
				f++;
				if (*f == '=') {
					comparison = tc_lessorequal;
					f++;
				} else if (*f == '<') {
					comparison = tc_strictless;
					f++;
				} else {
					comparison = tc_lessorequal;
					fprintf(stderr,
"Warning: Found a '(<' without '=' or '<'  in '%s'(begin cut), will be treated as '<='.\n",
							*formula);
				}
				break;
			case '=':
				f++;
				if (*f == '=')
					f++;
				else if (*f != ' ') {
					*formula = f;
					return RET_NOTHING;
				}
				comparison = tc_equal;
				break;
			case '%':
				if (ISSET(options, T_GLOBMATCH)) {
					f++;
					comparison = tc_globmatch;
					break;
				}
				*formula = f;
				return RET_NOTHING;
			case '!':
				if (f[1] == '%' &&
						ISSET(options, T_GLOBMATCH)) {
					f += 2;
					comparison = tc_notglobmatch;
					break;
				}
				if (ISSET(options, T_NOTEQUAL)) {
					f++;
					if (*f != '=') {
						*formula = f;
						return RET_NOTHING;
					}
					f++;
					comparison = tc_notequal;
					break;
				}
				// no break here...
			default:
				*formula = f;
				return RET_NOTHING;
		}
		overspace();
		valueend = valuestart = f;
		while (*f != '\0' && *f != ')') {
			valueend = f+1;
			f++;
			while (*f != '\0' && xisspace(*f))
				f++;
		}
		if (*f != ')' || valueend == valuestart) {
			*formula = f;
			return RET_NOTHING;
		}
		f++;

	} else {
		comparison = tc_none;
		valuestart = valueend = NULL;
	}
	overspace();
	if (ISSET(options, T_ARCHITECTURES) && *f == '[') {
		//TODO: implement this one...
		assert ("Not yet implemented!" == NULL);
	}
	for (s = specials ; s->name != NULL ; s++) {
		if (strncasecmp(s->name, keystart, keyend-keystart) == 0 &&
				s->name[keyend-keystart] == '\0')
			break;
	}
	a = zNEW(struct term_atom);
	if (FAILEDTOALLOC(a))
		return RET_ERROR_OOM;
	a->negated = negated;
	a->comparison = comparison;
	if (s->name != NULL) {
		retvalue r;

		a->isspecial = true;
		a->special.type = s;
		r = s->parse(comparison, valuestart, valueend-valuestart,
				&a->special.comparewith);
		if (RET_WAS_ERROR(r)) {
			term_free(a);
			return r;
		}
	} else {
		a->isspecial = false;
		a->generic.key = strndup(keystart, keyend - keystart);
		if (FAILEDTOALLOC(a->generic.key)) {
			term_free(a);
			return RET_ERROR_OOM;
		}
		if (comparison != tc_none) {
			if (valueend - valuestart > 2048 &&
					(comparison == tc_globmatch ||
					 comparison == tc_notglobmatch)) {
				fprintf(stderr,
"Ridicilous long globmatch '%.10s...'!\n",
						valuestart);
				term_free(a);
				return RET_ERROR;
			}
			a->generic.comparewith = strndup(valuestart,
					valueend - valuestart);
			if (FAILEDTOALLOC(a->generic.comparewith)) {
				term_free(a);
				return RET_ERROR_OOM;
			}
		}
	}
	//TODO: here architectures, too

	*atom = a;
	*formula = f;
	return RET_OK;
#undef overspace
}
예제 #5
0
retvalue term_compile(term **term_p, const char *origformula, int options, const struct term_special *specials) {
	const char *formula = origformula;
	/* for the global list */
	struct term_atom *first, *last;
	/* the atom just read */
	struct term_atom *atom IFSTUPIDCC(=NULL);
	struct {
		/*@dependent@*/struct term_atom *firstinand, *firstinor;
	} levels[50];
	int lastinitializeddepth=-1;
	int depth=0;
	retvalue r;
	int i;
	//TODO: ???
	char junction = '\0';

	if (ISSET(options, T_ARCHITECTURES)) {
		//TODO: implement this one...
		assert ("Not yet implemented!" == NULL);
	}

#define overspace() while (*formula!='\0' && xisspace(*formula)) formula++

	lastinitializeddepth=-1;
	depth=0;
	first = last = NULL;

	while (true) {
		overspace();
		while (*formula == '(' && ISSET(options, T_BRACKETS)) {
			depth++; formula++;
			overspace();
		}
		if (depth >= 50) {
			term_free(first);
			fprintf(stderr,
"Nested too deep: '%s'!\n",
					origformula);
			return RET_ERROR;
		}
		r = parseatom(&formula, &atom, options, specials);
		if (r == RET_NOTHING) {
			if (*formula == '\0')
				fprintf(stderr,
"Unexpected end of string parsing formula '%s'!\n",
					origformula);
			else
				fprintf(stderr,
"Unexpected character '%c' parsing formula '%s'!\n",
					*formula, origformula);

			r = RET_ERROR;
		}
		if (RET_WAS_ERROR(r)) {
			term_free(first);
			return r;
		}
		for (i=lastinitializeddepth+1 ; i <= depth ; i ++) {
			levels[i].firstinand = atom;
			levels[i].firstinor = atom;
		}
		if (junction != '\0') {
			assert(lastinitializeddepth >= 0);
			assert (first != NULL);
			last->next = atom;
			last = atom;
			if (junction == ',') {
				andterm(levels[lastinitializeddepth].firstinand,
						atom);
				levels[lastinitializeddepth].firstinand = atom;
				levels[lastinitializeddepth].firstinor = atom;
			} else {
				assert (junction == '|');
				orterm(levels[lastinitializeddepth].firstinor,
						atom);
				levels[lastinitializeddepth].firstinor = atom;
			}
		} else {
			assert(lastinitializeddepth == -1);
			assert (first == NULL);
			first = last = atom;
		}
		lastinitializeddepth = depth;
		overspace();
		if (*formula == ')' && ISSET(options, T_BRACKETS)) {
			formula++;
			if (depth > 0) {
				depth--;
				lastinitializeddepth = depth;
			} else {
				fprintf(stderr,
"Too many ')'s in '%s'!\n",
						origformula);
				term_free(first);
				return RET_ERROR;
			}
			overspace();
		}
		overspace();
		if (*formula == '\0')
			break;
		if (*formula != ',' &&
				(*formula != '|' || NOTSET(options, T_OR))) {
			fprintf(stderr,
"Unexpected character '%c' within '%s'!\n",
				*formula, origformula);
			term_free(first);
			return RET_ERROR;
		}
		junction = *formula;
		formula++;
	}
	if (depth > 0) {
		fprintf(stderr,
"Missing ')' at end of formula '%s'!\n",
				origformula);
		term_free(first);
		return RET_ERROR;

	}
	if (*formula != '\0') {
		fprintf(stderr,
"Trailing garbage at end of term: '%s'\n",
				formula);
		term_free(first);
		return RET_ERROR;
	}
	*term_p = first;
	return RET_OK;
}
예제 #6
0
void lps_free(Lps* lp)
{
   Var* var;
   Var* var_next;
   Con* con;
   Con* con_next;
   Sos* sos;
   Sos* sos_next;
   Sse* sse;
   Sse* sse_next;
   Sto* sto;
   Sto* sto_next;
   unsigned int  i;
   
   assert(lps_valid(lp));

   lps_hash_free(lp->var_hash);
   lps_hash_free(lp->con_hash);
   lps_hash_free(lp->sos_hash);

   for(sto = lp->sto_root; sto != NULL; sto = sto_next)
   {
      for(i = 0; i < sto_size; i++)
         mpq_clear(sto->begin[i].value);

      sto_next = sto->next;
       
      free(sto->begin);
      free(sto);
   }
   for(var = lp->var_root; var != NULL; var = var_next) 
   {
      var_next = var->next;
      var->sid = 0x0;

      mpq_clear(var->cost);
      mpq_clear(var->lower);
      mpq_clear(var->upper);
      mpq_clear(var->value);
      mpq_clear(var->startval);
      
      free(var->name);
      free(var);
   }
   for(con = lp->con_root; con != NULL; con = con_next)
   {
      Qme* qme;
      Qme* qme_next;

      con_next = con->next;
      con->sid = 0x0;

      for(qme = con->qme_first; qme != NULL; qme = qme_next)
      {
         qme_next = qme->next;

         mpq_clear(qme->value);
         free(qme);
      }
      mpq_clear(con->lhs);
      mpq_clear(con->rhs);
      mpq_clear(con->scale);
      
      if (con->term != NULL)
         term_free(con->term);
      
      free(con->name);
      free(con);
   }
   for(sos = lp->sos_root; sos != NULL; sos = sos_next)
   {
      sos_next = sos->next;
      sos->sid = 0x0;

      for(sse = sos->first; sse != NULL; sse = sse_next)
      {
         sse_next = sse->next;
         mpq_clear(sse->weight);
         free(sse);
      }
      free(sos->name);
      free(sos);
   }
   if (lp->probname != NULL)
      free(lp->probname);
   if (lp->objname != NULL)
      free(lp->objname);
   if (lp->rhsname != NULL)
      free(lp->rhsname);
   if (lp->bndname != NULL)
      free(lp->bndname);
   if (lp->rngname != NULL)
      free(lp->rngname);
   
   free(lp->name);
   free(lp);
}
예제 #7
0
파일: dict_types.c 프로젝트: fizx/sit
void
_term_free(void *privdata, void *term) {
  (void) privdata;
  term_free(term);
}