Esempio n. 1
0
MiniPS::Ename::Ename(char const*ptr_, ii_t len_) {
  param_assert(len_>=1 && ptr_[0]!='/');
  char *p=new char[len_+1];
  memcpy(ptr=p, ptr_, len=len_);
  p[len_]='\0';
  ty=T_ENAME;
}
Esempio n. 2
0
/*
 * Frees the param and returns NEXT
 */
static struct param_opt *param_free(struct param_opt *p)
{
	struct param_opt *next;
	param_assert(p);
	free(p->value);
	free(p->name);
	free(p->unit);
	free(p->def);
	free(p->description);
	next = p->next;
	free(p);
	return next;
}
Esempio n. 3
0
void MiniPS::Array::set(ii_t index, VALUE val) {
  param_assert(index>=0 && index<len);
  MiniPS::delete0(((VALUE*)ptr)[index]);
  ((VALUE*)ptr)[index]=val;
}
Esempio n. 4
0
/*
 * I hate myself and I want to die.
 *
 * This should be cleaned up considerably. Numerous flaws (e.g: word-size
 * mix). Unmanageable. Ugly. Fugly. Etc.
 *
 * Newer Varnish versions makes this redundant.
 * (Parses param.show -l and outputs json. Caller must issue free();
 */
static char *vparams_show_json(char *raw)
{
	char word[2048];
	struct param_opt *tmp, *top;
	int pos = 0, i = 0;
	int state = 0;
	char *term = NULL;
	char *out = NULL, *out2 = NULL, *out3 = NULL;
	tmp = malloc(sizeof (struct param_opt));
	top = NULL;
	tmp->next = NULL;

	/*
	 * param.show -l output:
	 *
	 * V3:
	 * (parameter) (value) \[(unit|)\]
	 *             Default is (value)
	 *             (description line 1)
	 *             ..
	 *             (description line n)
	 *
	 * V4/4.1:
	 * (parameter)
	 *   Value is: (value) [\[(unit)\]] [\(default\)]
	 *   [Default is: (value)]
	 *   [Minimum is: (value)]
	 *   [Maximum is: (value)]
	 *
	 *   (description line 1)
	 *   ..
	 *   (description line n)
	 */
	while(raw[pos]) {
		word[i++] = raw[pos];
		assert(i<510);
		if (state == 0 && (raw[pos] == ' ' || raw[pos] == '\n')) {
			word[i-1] = '\0';
			tmp->name = strdup(word);
			i = 0;
			while (raw[pos] == ' ' || raw[pos] == '\n')
				pos++;
			word[0] = raw[pos];
			assert(strncmp("Value is: ", raw+pos, strlen("Value is: ")) == 0);
			pos += strlen("Value is: ");
			state = 1;
			pos--;
		} else if (state == 1 && (raw[pos] == '\n' || raw[pos] == '[')) {
			assert(i<510);
			i--;
			word[i] = '\0';
			term = strrchr(word,'[');
			if (term) {
				assert(*(term-1) == ' ');
				*(term-1) = '\0';
			}
			i = strlen(word);
			size_t dlen = strlen("(default)");

			if (i > (int)dlen) {
				if (strncmp(word + i - dlen, "(default)", dlen) == 0) {
					i -= dlen;
					word[i] = '\0';
				}
			}
			
			while(word[--i] == ' ');
			if (word[i] == '"') {
				assert(word[0] == '"');
				memmove(word, word+1, i-1);
				i-=2;
			}
			word[i+1] = '\0';
			assert(strchr(word,'"') == NULL);

			tmp->value = strdup(word);
			i = 0;
			if (raw[pos] == '\n')
				tmp->unit = strdup("");
			else {
				pos++;
				while (raw[pos] != ']')
					word[i++] = raw[pos++];
				word[i] = '\0';
				tmp->unit = strdup(word);
				i = 0;
			}
			
			if (raw[pos] == '\n')
				pos++;
			term = strstr(raw+pos, "Default is: ");
			assert(term);
			pos = term-raw + strlen("Default is: ");
			if (raw[pos] == 0x01) {
				assert(raw[pos+1] == '\n');
				pos++;
			}
			while (raw[pos] != '\n')  {
				word[i++] = raw[pos++];
				assert(i<2048);
			}
			assert(raw[pos] == '\n');
			assert((isprint(word[0]) || i == 0));
			word[i] = '\0';
			if (word[i-1] == '"') {
				assert(word[0] == '"');
				memmove(word, word+1, i-1);
				i-=2;
			}
			word[i] = '\0';
			assert(strchr(word,'"') == NULL);

			tmp->def = strdup(word);
			i = 0;
			state = 0;
			while (!(raw[pos-1] == '\n' && !isspace(raw[pos]))) {
				if (raw[pos] == '\n') {
					pos++;
					word[i++] = '\\';
					word[i++] = 'n';
					state = 0;
				} else if (state == 0 && isspace(raw[pos])) {
					pos++;
				} else {
					state = 1;
					if (raw[pos] == '"')
						word[i++] = '\\';
					if (raw[pos] == '\t') {
						word[i++] = '\\';
						word[i++] = 't';
						pos++;
					} else
						word[i++] = raw[pos++];
				}
			}
			word[i] = '\0';
			tmp->description = strdup(word);
			tmp->next = top;
			top = tmp;
			state = 0;
			i = 0;
			assert(strlen(tmp->name) < 30);
			tmp = malloc(sizeof (struct param_opt));
			tmp->next = NULL;
			pos--;
		}
		pos++;
	}
	
	state = asprintf(&out3, "{\n");
	assert(state);
	for (tmp = top; tmp != NULL; ) {
		param_assert(tmp);
		state = asprintf(&out, "\t\"%s\": {\n"
			"\t\t\"value\": \"%s\",\n"
			"\t\t\"default\": \"%s\",\n"
			"\t\t\"unit\": \"%s\",\n"
			"\t\t\"description\": \"%s\"\n"
			"\t}",
			tmp->name, tmp->value, tmp->def,
			tmp->unit, tmp->description);
		assert(state);
		state = asprintf(&out2, "%s%s%s", out3, out, (tmp->next) ? ",\n":"");
		assert(state);
		free(out);
		free(out3);
		out3 = out2;
		tmp = param_free(tmp);
	}
	state = asprintf(&out2, "%s\n}\n", out3);
	free(out3);
	return out2;
}