示例#1
0
文件: ex5_14v2.c 项目: ducanhng/ctuto
// Save lines inputed in a pointer array and return number of lines
int readlines(char *ptarr[],int maxlines, char *alloc)
{
	int nlines,i;
	nlines = i = 0;
	int len;
		
	char line[MAXLENGTH];
	char *p;
	p = alloc;
	while ((len=getline1(line, MAXLENGTH)) > 0)
	{
		// Check available in storage
		if (ALLOCSIZE - (strlen(alloc) + len) > 0)
		{
			line[len-1] = '\0';
			strcp(p,line);
		}
		else 
		{
			printf("Error: Not enough storage !!!!");
		}
		nlines++;
		ptarr[i++] = p;
		p += len;
	}

	return nlines;
}
char * strcat(char *s, const char *t){
	char * p  = s ;
	while(*s){
		++s;
	}
	strcp(s, t);
	return  p;
}
示例#3
0
struct Person* create_person(char *name){
	struct Person *p;
	p = (struct Person*)malloc(sizeof(struct Person));
	p->n = NULL;
	p->balance = 0;
	strcp(name, p->name);
	return p;
}
示例#4
0
void	pipe_traitement(char *buffer, char **env)
{
  t_traite      tr;
  int	pipefd[2];

  tr.tmp = strcp(buffer);
  buffer = recup_arg_pipe(buffer);
  first_pipe_traitement(buffer, env, &tr, pipefd);
  second_pipe_traitement(buffer, env, &tr, pipefd);
}
示例#5
0
PCB *newPcb(char *name,int reqTime) {
	PCB *p = (PCB*)malloc(sizeof(PCB));
	strcp(p->name,name);
	p->next = NULL;
	p->reqTime = reqTime;
	p->ranTime = 0;
	p->statue = 'R';

	return p;
}
示例#6
0
文件: g_xfmt.c 项目: 0mp/freebsd
g_xfmt(char *buf, void *V, int ndig, size_t bufsize)
#endif
{
	static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 };
	char *b, *s, *se;
	ULong bits[2], sign;
	UShort *L;
	int decpt, ex, i, mode;
#ifdef Honor_FLT_ROUNDS
#include "gdtoa_fltrnds.h"
#else
#define fpi &fpi0
#endif

	if (ndig < 0)
		ndig = 0;
	if (bufsize < ndig + 10)
		return 0;

	L = (UShort *)V;
	sign = L[_0] & 0x8000;
	bits[1] = (L[_1] << 16) | L[_2];
	bits[0] = (L[_3] << 16) | L[_4];
	if ( (ex = L[_0] & 0x7fff) !=0) {
		if (ex == 0x7fff) {
			/* Infinity or NaN */
			if (bits[0] | bits[1])
				b = strcp(buf, "NaN");
			else {
				b = buf;
				if (sign)
					*b++ = '-';
				b = strcp(b, "Infinity");
				}
			return b;
			}
		i = STRTOG_Normal;
		}
	else if (bits[0] | bits[1]) {
		i = STRTOG_Denormal;
		ex = 1;
		}
	else {
		b = buf;
#ifndef IGNORE_ZERO_SIGN
		if (sign)
			*b++ = '-';
#endif
		*b++ = '0';
		*b = 0;
		return b;
		}
	ex -= 0x3fff + 63;
	mode = 2;
	if (ndig <= 0) {
		if (bufsize < 32)
			return 0;
		mode = 0;
		}
	s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
	return g__fmt(buf, s, se, decpt, sign, bufsize);
	}
示例#7
0
文件: g_ddfmt.c 项目: 0mp/freebsd
g_ddfmt(char *buf, double *dd0, int ndig, size_t bufsize)
#endif
{
	FPI fpi;
	char *b, *s, *se;
	ULong *L, bits0[4], *bits, *zx;
	int bx, by, decpt, ex, ey, i, j, mode;
	Bigint *x, *y, *z;
	U *dd, ddx[2];
#ifdef Honor_FLT_ROUNDS /*{{*/
	int Rounding;
#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
	Rounding = Flt_Rounds;
#else /*}{*/
	Rounding = 1;
	switch(fegetround()) {
	  case FE_TOWARDZERO:	Rounding = 0; break;
	  case FE_UPWARD:	Rounding = 2; break;
	  case FE_DOWNWARD:	Rounding = 3;
	  }
#endif /*}}*/
#else /*}{*/
#define Rounding FPI_Round_near
#endif /*}}*/

	if (bufsize < 10 || bufsize < ndig + 8)
		return 0;

	dd = (U*)dd0;
	L = dd->L;
	if ((L[_0] & 0x7ff00000L) == 0x7ff00000L) {
		/* Infinity or NaN */
		if (L[_0] & 0xfffff || L[_1]) {
 nanret:
			return strcp(buf, "NaN");
			}
		if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) {
			if (L[2+_0] & 0xfffff || L[2+_1])
				goto nanret;
			if ((L[_0] ^ L[2+_0]) & 0x80000000L)
				goto nanret;	/* Infinity - Infinity */
			}
 infret:
		b = buf;
		if (L[_0] & 0x80000000L)
			*b++ = '-';
		return strcp(b, "Infinity");
		}
	if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) {
		L += 2;
		if (L[_0] & 0xfffff || L[_1])
			goto nanret;
		goto infret;
		}
	if (dval(&dd[0]) + dval(&dd[1]) == 0.) {
		b = buf;
#ifndef IGNORE_ZERO_SIGN
		if (L[_0] & L[2+_0] & 0x80000000L)
			*b++ = '-';
#endif
		*b++ = '0';
		*b = 0;
		return b;
		}
	if ((L[_0] & 0x7ff00000L) < (L[2+_0] & 0x7ff00000L)) {
		dval(&ddx[1]) = dval(&dd[0]);
		dval(&ddx[0]) = dval(&dd[1]);
		dd = ddx;
		L = dd->L;
		}
	z = d2b(dval(&dd[0]), &ex, &bx);
	if (dval(&dd[1]) == 0.)
		goto no_y;
	x = z;
	y = d2b(dval(&dd[1]), &ey, &by);
	if ( (i = ex - ey) !=0) {
		if (i > 0) {
			x = lshift(x, i);
			ex = ey;
			}
		else
			y = lshift(y, -i);
		}
	if ((L[_0] ^ L[2+_0]) & 0x80000000L) {
		z = diff(x, y);
		if (L[_0] & 0x80000000L)
			z->sign = 1 - z->sign;
		}
	else {
		z = sum(x, y);
		if (L[_0] & 0x80000000L)
			z->sign = 1;
		}
	Bfree(x);
	Bfree(y);
 no_y:
	bits = zx = z->x;
	for(i = 0; !*zx; zx++)
		i += 32;
	i += lo0bits(zx);
	if (i) {
		rshift(z, i);
		ex += i;
		}
	fpi.nbits = z->wds * 32 - hi0bits(z->x[j = z->wds-1]);
	if (fpi.nbits < 106) {
		fpi.nbits = 106;
		if (j < 3) {
			for(i = 0; i <= j; i++)
				bits0[i] = bits[i];
			while(i < 4)
				bits0[i++] = 0;
			bits = bits0;
			}
		}
	mode = 2;
	if (ndig <= 0) {
		if (bufsize < (int)(fpi.nbits * .301029995664) + 10) {
			Bfree(z);
			return 0;
			}
		mode = 0;
		}
	fpi.emin = 1-1023-53+1;
	fpi.emax = 2046-1023-106+1;
	fpi.rounding = Rounding;
	fpi.sudden_underflow = 0;
	i = STRTOG_Normal;
	s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
	b = g__fmt(buf, s, se, decpt, z->sign, bufsize);
	Bfree(z);
	return b;
	}
示例#8
0
char *__g_xfmt (char *buf, void *V, int ndig, size_t bufsize)
{
	static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 };
	char *b, *s, *se;
	ULong bits[2], sign;
	UShort *L;
	int decpt, ex, i, mode;
#if defined(__MINGW32__) || defined(__MINGW64__)
	int fptype = __fpclassifyl (*(long double*) V);
#endif	/* MinGW */
#ifdef Honor_FLT_ROUNDS
#include "gdtoa_fltrnds.h"
#else
#define fpi &fpi0
#endif

	if (ndig < 0)
		ndig = 0;
	if (bufsize < ndig + 10)
		return 0;

	L = (UShort *)V;
	sign = L[_0] & 0x8000;
	ex = L[_0] & 0x7fff;
	bits[1] = (L[_1] << 16) | L[_2];
	bits[0] = (L[_3] << 16) | L[_4];

#if defined(__MINGW32__) || defined(__MINGW64__)
	if (fptype & FP_NAN) {
		/* NaN or Inf */
		if (fptype & FP_NORMAL) {
			b = buf;
			*b++ = sign ? '-': '+';
			strncpy (b, "Infinity", ndig ? ndig : 8);
			return (buf + strlen (buf));
		}
		strncpy (buf, "NaN", ndig ? ndig : 3);
		return (buf + strlen (buf));
	}
	else if (fptype & FP_NORMAL) {
		/* Normal or subnormal */
		if  (fptype & FP_ZERO) {
			i = STRTOG_Denormal;
			ex = 1;
		}
		else
			i = STRTOG_Normal;
	}
#else
	if (ex != 0) {
		if (ex == 0x7fff) {
			/* Infinity or NaN */
			if (bits[0] | bits[1])
				b = strcp(buf, "NaN");
			else {
				b = buf;
				if (sign)
					*b++ = '-';
				b = strcp(b, "Infinity");
			}
			return b;
		}
		i = STRTOG_Normal;
	}
	else if (bits[0] | bits[1]) {
		i = STRTOG_Denormal;
		ex = 1;
	}
#endif
	else {
	/*	i = STRTOG_Zero; */
		b = buf;
#ifndef IGNORE_ZERO_SIGN
		if (sign)
			*b++ = '-';
#endif
		*b++ = '0';
		*b = 0;
		return b;
	}
	ex -= 0x3fff + 63;
	mode = 2;
	if (ndig <= 0) {
		if (bufsize < 32)
			return 0;
		mode = 0;
	}
	s = __gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
	return __g__fmt(buf, s, se, decpt, sign, bufsize);
}
示例#9
0
文件: uncap.c 项目: hyz/uncap
/**
Parse command line arguments.

@param argc Argument count
@param argv Argument vector

@return Next action to take based on whether parsing of command line
        arguments was successful or not. GOOD is returned if command
        line arguments were parsed successfully and the program should
        continue. EXIT is returned if command line arguments were parsed
        and processed successfully and the program should exit. FAIL is
        returned if an error was found in command line arguments.
*/
enum action parseArguments(int argc, const char **argv)
{
    int i;

    /* Set default values. */
    strcp(my.name, basename(argv[0]), sizeof my.name);

    for (i = 0; i < (int) (sizeof my.keymap / sizeof *my.keymap); i++)
        my.keymap[i] = (WORD) i;

    my.keymap[VK_CAPITAL] = VK_ESCAPE;

    my.console = 0;
    my.debug = 0;
    my.file = NULL;

    /* Parse command line options. */
    i = 1;
    while (i < argc) {
        const char *arg = argv[i];
        if (streq(arg, "-h") || streq(arg, "--help")) {
            showHelp();
            return EXIT;
        } else if (streq(arg, "-v") || streq(arg, "--version")) {
            showVersion();
            return EXIT;
        } else if (streq(arg, "--qtpi")) {
            qtpi();
            return EXIT;
        } else if (streq(arg, "-c") || streq(arg, "--console")) {
            my.console = 1;
            ++i;
        } else if (streq(arg, "-d") || streq(arg, "--debug")) {
            my.debug = 1;
            ++i;
        } else if (streq(arg, "-f") || streq(arg, "--file")) {
            if (i == argc - 1) {
                sprintf(my.error, "Option '%.*s' must be followed by "
                                  "file path", MAX_ARG_LEN, arg);
                return FAIL;
            }
            arg = argv[++i];
            if ((my.file = fopen(arg, "a")) == NULL) {
                sprintf(my.error, "Cannot open %.*s.", MAX_ARG_LEN, arg);
                return FAIL;
            }
            ++i;
        } else if (streq(arg, "-k") || streq(arg, "--kill")) {
            return kill();
        } else if (streq(arg, "--")) {
            ++i;
            break;
        } else if (arg[0] == '-' && arg[1] != 0) {
            sprintf(my.error, "Unknown option '%.*s'.", MAX_ARG_LEN, arg);
            return FAIL;
        } else {
            break;
        }
    }

    /* Parse command line options. */
    while (i < argc) {
        const char *arg = argv[i];
        char *colon;
        unsigned long int mapKey;
        unsigned long int toKey;

        if ((colon = strchr(arg, ':')) == NULL) {
            sprintf(my.error, "Colon is missing from argument '%.*s'.",
                    MAX_ARG_LEN, arg);
            return FAIL;
        }

        mapKey = strtoul(arg, NULL, 0);
        toKey = strtoul(colon + 1, NULL, 0);

        if (mapKey < 1 || mapKey > 254 || toKey > 254) {
            sprintf(my.error, "Invalid key code in argument '%.*s'.",
                    MAX_ARG_LEN, arg);
            return FAIL;
        }

        my.keymap[mapKey] = (WORD) toKey;
        ++i;
    }

    /* Command line arguments parsed successfully. */
    return GOOD;
}