Beispiel #1
0
/**
 * Print a fixed-point number as a string.
 **/
static char *
ason_asprint_number(int64_t num)
{
	char *ret = xasprintf("%lld", FP_WHOLE(num));
	char *tmp;

	if (num < 0)
		num = -num;

	num -= TO_FP(FP_WHOLE(num));

	if (! num)
		return ret;

	tmp = ret;
	ret = xasprintf("%s.", tmp);
	free(tmp);

	while (num) {
		num *= 10;
		tmp = ret;
		ret = xasprintf("%s%lld", tmp, FP_WHOLE(num));
		free(tmp);
		num -= TO_FP(FP_WHOLE(num));
	}

	return ret;
}
Beispiel #2
0
char *_fdupstr(unsigned const segm, unsigned const ofs)
{	size_t len;
	char *p;

	if(!(p = malloc(len = _fstrlen(MK_FP(segm, ofs)) + 1)))
		return 0;
	copy_seg(TO_FP(p), segm, ofs, len);

	return p;
}
Beispiel #3
0
char *_fdupstr(const char far * const s)
{	size_t len;
	char *p;

	chkHeap
	if((p = malloc(len = _fstrlen(s) + 1)) == 0)
		return 0;
	_fmemcpy(TO_FP(p), s, len);

	chkHeap
	return p;
}
Beispiel #4
0
static int renumber(void *arg, word segm, word ofs)
{	char buf[CTXT_ITEMNAME_LENGTH];

#define tag (Context_Tag)(int)arg

	assert(segm);
	assert(ofs != (word)-1);

	if(ctxtProbeItemTag(segm, ofs, arg)) {
		ctxtMkItemName(buf, tag, ++CTXT_INFO(tag, nummax));
		assert(peekb(segm , ofs + strlen(buf)) == '=');
		_fmemcpy(MK_FP(segm, ofs), TO_FP(buf), strlen(buf));
	}

#undef tag
	return 0;
}
Beispiel #5
0
void aliasexpand(char * const cmd, const int maxlen)
{	char *hbuf;				/* work buffer */
	char *cp, *p;
	unsigned ofs, *expanded, *he;
	int i, numExpanded;

	assert(cmd);
	assert(strlen(cmd) < maxlen);

	if((hbuf = malloc(maxlen)) == 0) {
		error_out_of_memory();
		return;
	}
	numExpanded = 0;
	expanded = 0;

redo:						/* iteration to expand all aliases */
	cp = ltrimcl(cmd);		/* skip leading whitespaces */

	/* Check if the user disabled alias expansion */
	if(*cp == '*') {
		memmove(cmd, cp + 1, strlen(cp));
		goto errRet;
	}

	/* Get the name of this command */
	for(p = hbuf; is_fnchar(*cp) || *cp == '.';)
		*p++ = *cp++;
	if(p == hbuf || is_pathdelim(*cp) || is_quote(*cp))
		/* no name || part of path -> no alias */
		goto errRet;

	*p = 0;
	StrFUpr(hbuf);			/* all aliases are uppercased */
	if((ofs = env_findVar(ctxtAlias, hbuf)) == (unsigned)-1)
		/* not found -> no alias */
		goto errRet;

	/* Prevent recursion by recording the offset of the found variable */
	for(i = 0; i < numExpanded; ++i)
		if(expanded[i] == ofs)		/* already used -> ignore */
			goto errRet;

	if((he = realloc(expanded, ++numExpanded)) == 0) {
		error_out_of_memory();
		goto errRet;
	}
	expanded = he;
	expanded[numExpanded - 1] = ofs;

	/************ Expand the command line "cp" with the alias at
						MK_FP(ctxtAlias, ofs)  ***********************/
	ofs += strlen(hbuf) + 1;		/* advance to value */
	if(_fstrlen(MK_FP(ctxtAlias, ofs)) < maxlen - strlen(cp)) {
		/* prepend alias value to remaining command line */
		_fstrcpy(TO_FP(hbuf), MK_FP(ctxtAlias, ofs));
		strcat(hbuf, cp);
		assert(strlen(hbuf) < maxlen);
		strcpy(cmd, hbuf);
		goto redo;				/* next expansion */
	}

	error_command_too_long();

errRet:							/* return to caller */
	free(expanded);
	free(hbuf);
}