Example #1
0
int main(void)
{
    char s[MAXSIZE] = "abc";
    char t[MAXSIZE] = "abracadabra";
    mystrncpy(s, t, 6);
    printf("%s\n", s);

    strncpy(t, "", MAXSIZE);
    mystrncpy(s, t, 6);
    printf("%s\n", s);

    strncpy(s, "foo", MAXSIZE);
    strncpy(t, "bar", MAXSIZE);
    mystrncat(s, t, 5);
    printf("%s\n", s);

    strncpy(s, "foobar", MAXSIZE);
    strncpy(t, "foobar", MAXSIZE);
    printf("%d\n", mystrncmp(s, t, 10));
    printf("%d\n", mystrncmp(s, t, 4));

    strncpy(t, "fooby", MAXSIZE);
    printf("%d\n", mystrncmp(s, t, 10));
    printf("%d\n", mystrncmp(s, t, 4));
    printf("%d\n", mystrncmp(s, t, 5));
    return 0;
}
Example #2
0
/* Compares the name of one lib with another. So, carp would match
/usr/lib/libcarp.so.1.3, Keeping in mind that the name of the library is
the full path on linux, but a name on windows, so long and short names can go
both ways. And it is preferable that the user specify a short name in
trusted_libs. */
static int
libcmp (const char *a, const char *b) {
    int an, bn;
    const char *as = canonical_lib(a, &an);
    const char *bs = canonical_lib(b, &bn);
    return mystrncmp(as, bs, MAX(an, bn));
}
Example #3
0
int picolParseString(picolParser *p) {
  int newword = (p->type == PT_SEP || p->type == PT_EOL || p->type == PT_STR);
  if(p->len >= 3 && !mystrncmp(p->p,"{*}",3)) {
    p->expand = 1;
    p->p += 3; p->len -= 3; /* skip the {*} expand indicator */
  }
  if (newword && *p->p == '{') {return picolParseBrace(p);}
  else if (newword && *p->p == '"') {
    p->insidequote = 1;
    p->p++; p->len--;
  }
  for(p->start = p->p; 1; p->p++, p->len--) {
    if (p->len == 0)       RETURN_PARSED(PT_ESC);
    switch(*p->p) {
    case '\\':             if (p->len >= 2) { p->p++; p->len--; }; break;
    case '$': case '[':    RETURN_PARSED(PT_ESC);
    case ' ': case '\t': case '\n': case '\r': case ';':
      if (!p->insidequote) RETURN_PARSED(PT_ESC);
      break;
    case '"':
      if (p->insidequote) {
        p->end = p->p-1;
        p->type = PT_ESC;
        p->p++; p->len--;
        p->insidequote = 0;
        return PICOL_OK;
      }
      break;
    }
  }
}
Example #4
0
uint16_t myip_telnetd_con_handler(uint8_t *in, uint16_t sz, uint8_t *out)
{
#ifndef ENABLE_PCL
    if(!mystrncmp((char*)in, "exit", 4))
    {
        myip_tcp_con_close();
        return 0;
    }
    else if(sz > 0)
    {
        if(in[0] != TELNET_IAC)
            enqueue_str(&tds.qo, telnetd_prompt, sizeof(telnetd_prompt));
    }
#else
    uint16_t i;
    for(i = 0; i < sz; i++)
    {
        if(in[i] == TELNET_IAC)
        {
            i += 2;
            continue;
        }
        enqueue(&tds.qi, in[i]);
    }
#endif
    return dequeue(&tds.qo, out, 0);
}
Example #5
0
int FindAnims(TxtNode *t)
{
	int i;
	for (i=0;i<nsNodes;i++)
	{
		sNodes[i].animat=0;
		sNodes[i].nanimat=0;
	}
	if (t->child)
	{
		TxtNode *sib=t->child;
		while (sib)
		{
			if (sib->text&&!mystrncmp("AnimationSet",sib->text,sib->length))
			{
				if (!sib->sibling)
					return 100;
				sib=sib->sibling;
				int err=FindSets(sib);
				if (err)
					return err;
			}
			sib=sib->sibling;
		}
	}
	return 0;
}
Example #6
0
/* Parser core - when encountering text, process appropriately. */
static const char *parse_value(cJSON *item,const char *value)
{
	if (!value)						return 0;	/* Fail on null. */
	if (!mystrncmp(value,"null",4))	{ item->type=cJSON_NULL;  return value+4; }
	if (!mystrncmp(value,"false",5))	{ item->type=cJSON_False; return value+5; }
	if (!mystrncmp(value,"true",4))	{ item->type=cJSON_True; item->valueint=1;	return value+4; }
	if (*value=='\"')				{ return parse_string(item,value); }
	if (*value=='-' || (*value>='0' && *value<='9'))
	{
		_hx_sprintf("parse_number call");		
		return parse_number(item,value); 
	}
	if (*value=='[')				{ return parse_array(item,value); }
	if (*value=='{')				{ return parse_object(item,value); }

	ep=value;return 0;	/* failure. */
}
Example #7
0
static char * match(struct line *l, const char *m)
{
    char *str = l->data;
    int len = strlen(m);
    while (isspace(*str))
	str++;

    if (mystrncmp(str, m, len) != 0)
	return NULL;
    return str + len;
}
Example #8
0
/* Returns the part of the library file name that is important, doesn't modify
or allocate anything so it will find its location and how long it is.  */
static const char *
canonical_lib (const char *f, int *n) {
    const char *fs = nstrip(f, 0, 1);
    *n = 0;
    if (!fs)
        return NULL;
    if (!mystrncmp(fs, "lib", 3))
        fs += 3;
    if (strstr(fs, "."))
        *n = strstr(fs, ".") - fs;
    return fs;
}
Example #9
0
File: rhdr.c Project: ombt/ombt
// main entry point
main(int argc, char **argv)
{
	// get comand line options
	for (int c = 0; (c = getopt(argc, argv, "?")) != EOF; )
	{
		switch (c)
		{
		case '?':
			usage(argv[0]);
			return(0);

		default:
			ERROR("invalid option", EINVAL);
			usage(argv[0]);
			return(2);
		}
	}

	// remove header from stream
	char inbuf[BUFSIZ+1];
	for (cin.getline(inbuf, BUFSIZ); 
	     ! cin.eof(); 
	     cin.getline(inbuf, BUFSIZ))
	{
		if (mystrncmp(inbuf, StartOfData) == 0)
		{
			// break out of options loop
			break;
		}
	}

	// check if out of data
	if (cin.eof())
	{
		ERROR("unexpected EOF. no data read in.", EINVAL);
		return(NOTOK);
	}


	// just read stdin and write to stdout.
	while ( ! cin.eof())
	{
		// read in x,y point
		double tmpx, tmpy;
		cin >> tmpx >> tmpy;

		// write out new points
		cout << tmpx << " " << tmpy << endl;
	}

	// all done
	return(0);
}
// This example is interresting, it contains many kind of 
// incorrect heap manipulations or corruptions
int	main()
{
  char *buf;
  char *buf2;	
  char *swp;	
  int	ret;

  buf  = (char *) malloc(BUFSIZ);
  while (1)
    {
      buf2 = (char *) malloc(BUFSIZ);
      buf[0] = '\0';

      if ((ret = read(0, buf, BUFSIZ - 1)) < 0)
	exit(-1);
      buf[ret - 1] = '\0';
      if ((ret = read(0, buf2, BUFSIZ - 1)) < 0)
	exit(-1);
      if (ret == 0)
	exit(0);

      buf2[ret - 1] = '\0';

      if (ret > 5 && buf[5] == 's')
	{
	  swp = buf;
	  buf = buf2;
	  buf2 = swp;
	}

      if (!mystrncmp(buf, "func1", 5))
	func1(buf);
      else if (!mystrncmp(buf, "func2", 5))
	func2(buf);
      else if (!mystrncmp(buf, "func3", 5))
	func3(&buf);

      free(buf2);
    }
}
Example #11
0
//-------------------------------------------------------------------------
void reply_ls_nodename(uint8_t * receivebuffer)
{
    uint8_t temp = receivebuffer[0] - 3;
    uint16_t randomsleep;

    if (mystrncmp((char *)receivebuffer, 3, (char *)networkid, 0, temp) == 0)
    {
        temp = mystrlen(filenameid);
        reply[0] = temp + 3;
        reply[1] = 102;
        reply[2] = nodeid;
        mystrncpy((char *)&reply[3], filenameid, temp);
        randomsleep = getRandomNumber() % 400;
        sleepThread(randomsleep);
        StandardSocketSend(0xefef, 0xffff, 32, reply);
        //printStringN(reply,32); 
    }
}
Example #12
0
volatile uint32_t* gpio_get_reg_ptr(GPIO_TypeDef *gpiox, const char *reg)
{
    if(!mystrncmp(reg, "moder", 5))
        return &(gpiox->MODER);
    if(!mystrncmp(reg, "otyper", 6))
        return &(gpiox->OTYPER);
    if(!mystrncmp(reg, "ospeedr", 7))
        return &(gpiox->OSPEEDR);
    if(!mystrncmp(reg, "pupdr", 5))
        return &(gpiox->PUPDR);
    if(!mystrncmp(reg, "idr", 3))
        return &(gpiox->IDR);
    if(!mystrncmp(reg, "odr", 3))
        return &(gpiox->ODR);
    if(!mystrncmp(reg, "afrl", 4))
        return &(gpiox->AFR[0]);
    if(!mystrncmp(reg, "afrh", 4))
        return &(gpiox->AFR[1]);
    return 0;
}
Example #13
0
int main() {
    char s1[MAX_LEN] = "abcdefg";
    char *t1 = "xxx";
    mystrncpy(s1, t1, 2);
    printf("%s\n", s1);
    printf("----\n");

    char s3[MAX_LEN] = "abcd";
    char *t3 = "efg";
    mystrncat(s3, t3, 3);
    printf("%s\n", s3);
    char s4[MAX_LEN] = "abcd";
    char *t4 = "efg";
    mystrncat(s4, t4, 1);
    printf("%s\n", s4);
    printf("----\n");

    char s5[MAX_LEN] = "abcdef";
    char *t5 = "abca";
    printf("%d\n", mystrncmp(s5, t5, 4));
}
Example #14
0
int main(int argc, char* argv[])
{
    int r;

    printf("1問目: expected 0\n");
    r = mystrncmp("abc", "abc", 3);
    printf("    Your answer %d\n\n", r);

    printf("2問目: expected 1\n");
    r = mystrncmp("zyy", "zwy", 2);
    printf("    Your answer %d\n\n", r);

    printf("3問目: expected -1\n");
    r = mystrncmp("ab", "aba", 3);
    printf("    Your answer %d\n\n", r);

    printf("4問目: expected 1\n");
    r = mystrncmp("abc", "ab", 3);
    printf("    Your answer %d\n\n", r);

    printf("5問目: expected -1\n");
    r = mystrncmp("", "abc", 3);
    printf("    Your answer %d\n\n", r);

    printf("6問目: expected 1\n");
    r = mystrncmp("abc", "", 3);
    printf("    Your answer %d\n\n", r);

    printf("7問目: expected 1\n");
    r = mystrncmp("abc", "", 4);
    printf("    Your answer %d\n\n", r);

    printf("8問目: expected -1\n");
    r = mystrncmp("", "abc", 4);
    printf("    Your answer %d\n", r);

    return 0;
}
Example #15
0
int FindSets(TxtNode *t)
{
	if (t->child)
	{
		TxtNode *sib=t->child;
		while (sib)
		{
			if (sib->text&&!mystrncmp("Animation",sib->text,sib->length))
			{
				if (!sib->sibling)
					return 101;
				sib=sib->sibling;
				if (!sib->sibling)
					return 102;
				sib=sib->sibling;
				int err=FindPKeys(sib);
				if (err)
					return err;
			}
			sib=sib->sibling;
		}
	}
	return 0;
}
Example #16
0
LPSTR
FindP1284Key(
    PINIPORT    pIniPort,
    LPSTR   lpKey
    )
/*++

Routine Description:
    Find the 1284 key identifying the device id

Arguments:
    status  : status

Return Value:
    Pointer to the command string, NULL if not found.

--*/
{
    LPSTR   lpValue;                // Pointer to the Key's value
    WORD    wKeyLength;             // Length for the Key (for stringcmps)
    LPSTR   ret = NULL;

    // While there are still keys to look at.
#ifdef DEBUG
    OutputDebugStringA("PJLMon!DeviceId : <");
    OutputDebugStringA(lpKey);
    OutputDebugStringA(">\n");
#endif

    while (lpKey && *lpKey) {

        //
        // Is there a terminating COLON character for the current key?
        //
        if (!(lpValue = mystrchr(lpKey, COLON)) ) {

            //
            // N: OOPS, somthing wrong with the Device ID
            //
            return ret;
        }

        //
        // The actual start of the Key value is one past the COLON
        //
        ++lpValue;

        //
        // Compute the Key length for Comparison, including the COLON
        // which will serve as a terminator
        //
        wKeyLength = (WORD)(lpValue - lpKey);

        //
        // Compare the Key to the Know quantities.  To speed up the comparison
        // a Check is made on the first character first, to reduce the number
        // of strings to compare against.
        // If a match is found, the appropriate lpp parameter is set to the
        // key's value, and the terminating SEMICOLON is converted to a NULL
        // In all cases lpKey is advanced to the next key if there is one.
        //
        if ( *lpKey == 'C' ) {

            //
            // Look for COMMAND SET or CMD
            //
            if ( !mystrncmp(lpKey, COMMAND, wKeyLength) ||
                 !mystrncmp(lpKey, CMD, wKeyLength) ) {

                ret = lpValue;
            }
        }

        // Go to the next Key

        if ( lpKey = mystrchr(lpValue, SEMICOLON) ) {

            *lpKey = '\0';
            ++lpKey;
        }
    }

    return ret;
}
Example #17
0
DWORD
ProcessPJLString(
    PINIPORT    pIniPort,
    LPSTR       pInString,
    LPDWORD     lpcbProcessed
)
/*++

Routine Description:
    Process a PJL string read from the printer

Arguments:
    pIniPort        : Ini port
    pInString       : Input string to process
    lpcbProcessed   : On return set to the amount of data processed

Return Value:
    Status value of the processing

--*/
{
    TOKENPAIR tokenPairs[NTOKEN];
    DWORD nTokenParsedRet;
    LPSTR lpRet;
    DWORD status;

    lpRet = pInString;

#ifdef DEBUG
    OutputDebugStringA("String to process: <");
    OutputDebugStringA(pInString);
    OutputDebugStringA(">\n");
#endif

    for (*lpcbProcessed = 0; *pInString != 0; pInString = lpRet) {

        //
        // hack to determine if printer is bi-di.  LJ 4 does not have p1284
        // device ID so we do PCL memory query and see if it returns anything
        //
        if (!(pIniPort->status & PP_IS_PJL) &&
            !mystrncmp(pInString, "PCL\015\012INFO MEMORY", 16) )
            pIniPort->status |= PP_IS_PJL;

        status = GetPJLTokens(pInString, NTOKEN, tokenPairs,
                              &nTokenParsedRet, &lpRet);

        if (status == STATUS_REACHED_END_OF_COMMAND_OK) {

            pIniPort->status |= PP_IS_PJL;
            InterpreteTokens(pIniPort, tokenPairs, nTokenParsedRet);
        } else {

            ProcessParserError(status);
        }

        //
        // if a PJL command straddles between buffers
        //
        if (status == STATUS_END_OF_STRING)
            break;

        *lpcbProcessed += lpRet - pInString;
    }

    return status;
}
Example #18
0
int main(int argc, char **argv)
{
    FILE *infile = stdin;
    char tmp[4096];

#ifdef __mc68000__
    if(system("perl machdep/cpuopti")==-1) {
       perror("perl machdep/cpuopti");
       return 10;
   } else return 0;
#endif

    /* For debugging... */
    if (argc == 2)
	infile = fopen (argv[1], "r");

    for(;;) {
	char *s;

	if ((fgets(tmp, 4095, infile)) == NULL)
	    break;

	s = strchr (tmp, '\n');
	if (s != NULL)
	    *s = 0;

	if (mystrncmp(tmp, ".globl op_", 10) == 0) {
	    struct line *first_line = NULL, *prev = NULL;
	    struct line **nextp = &first_line;
	    struct func f;
	    int nr_rets = 0;
	    int can_opt = 1;

	    do {
		struct line *current;

		if (strcmp (tmp, "#APP") != 0 && strcmp (tmp, "#NO_APP") != 0) {
		    current = *nextp = (struct line *)malloc(sizeof (struct line));
		    nextp = &current->next;
		    current->prev = prev; prev = current;
		    current->next = NULL;
		    current->delet = 0;
		    current->data = my_strdup (tmp);
		    if (match (current, "movl %esp,%ebp") || match (current, "enter")) {
			fprintf (stderr, "GCC failed to eliminate fp: %s\n", first_line->data);
			can_opt = 0;
		    }

		    if (match (current, "ret"))
			nr_rets++;
		}
		if ((fgets(tmp, 4095, infile)) == NULL)
		    oops();
		s = strchr (tmp, '\n');
		if (s != NULL)
		    *s = 0;
	    } while (strncmp (tmp,".Lfe", 4) != 0);

	    f.first_line = first_line;
	    f.last_line = prev;

	    if (nr_rets == 1 && can_opt)
		do_function(&f);
	    /*else
		fprintf(stderr, "Too many RET instructions: %s\n", first_line->data);*/
	    output_function(&f);
	}
	printf("%s\n", tmp);
    }
    return 0;
}
Example #19
0
int FindNodes(SceneNodes *parent,TxtNode *t)
{
	static char tmp[1000];
	if (t->child)
	{
		TxtNode *sib=t->child;
		while (sib)
		{
			if (sib->text&&!mystrncmp("Frame",sib->text,sib->length))
			{
				SceneNodes tmpNode;
				Matrix4 tm,tmBase;
				tm.Identity();
				sib=sib->sibling;
				if (!sib)
					return 1;
				assert(sib->length<100);
				if (!strncmp("frm-",sib->text,4))
					mystrncpy(tmpNode.name,sib->text+4,sib->length-4);
				else
					mystrncpy(tmpNode.name,sib->text,sib->length);

				sib=sib->sibling;
				if (!sib)
					return 2;
				{
					TxtNode *FrameLook=sib;
					TxtNode *sub=sib->child;
					if (!sub)
						return 3;
					if (!sub->text)
						return 4;
					if (mystrncmp("FrameTransformMatrix",sub->text,sub->length))
						return 5;
					sub=sub->sibling;
					{
						TxtNode *xf=sub->child;
						int r,c;
#if 0
	OutputDebugString("matrix\n");
#endif
						for (r=0;r<4;r++)
						{
							int rr=r;
							float sign=1.0f;
							if (r==1)
								rr=2;
							if (r==2)
							{
								sign=-1.0f;
								rr=1;
							}
							for (c=0;c<4;c++)
							{
								if (!xf||!xf->text)
									return 6;
								if (c==0)
									tm[rr][0]=sign*(float)myatof(xf->text,xf->length);
								else if (c==1)
									tm[rr][2]=sign*(float)myatof(xf->text,xf->length);
								else if (c==2)
									tm[rr][1]=-sign*(float)myatof(xf->text,xf->length);
								xf=xf->sibling;
							}
						}
#if 0
						for (r=0;r<4;r++)
						{
							sprintf(tmp,"%6f %6f %6f\n",tm[r][0],tm[r][1],tm[r][2]);
							OutputDebugString(tmp);
						}
#endif
						tm.CalcFlags();
					}
					tmBase=tm;
					sub=sub->sibling;
					while (sub)
					{
						if (sub->text&&!mystrncmp("SI_FrameBasePoseMatrix",sub->text,sub->length))
						{
							sub=sub->sibling;
							{
								TxtNode *xf=sub->child;
								int r,c;
#if 0
	OutputDebugString("pose matrix\n");
#endif
								for (r=0;r<4;r++)
								{
									int rr=r;
									float sign=1.0f;
									if (r==1)
										rr=2;
									if (r==2)
									{
										sign=-1.0f;
										rr=1;
									}
									for (c=0;c<4;c++)
									{
										if (!xf||!xf->text)
											return 6;
										if (c==0)
											tmBase[rr][0]=sign*(float)myatof(xf->text,xf->length);
										else if (c==1)
											tmBase[rr][2]=sign*(float)myatof(xf->text,xf->length);
										else if (c==2)
											tmBase[rr][1]=-sign*(float)myatof(xf->text,xf->length);
										xf=xf->sibling;
									}
								}
								tmBase.CalcFlags();
#if 0
						for (r=0;r<4;r++)
						{
							sprintf(tmp,"%6f %6f %6f\n",tmBase[r][0],tmBase[r][1],tmBase[r][2]);
							OutputDebugString(tmp);
						}
#endif
							}
						}
						sub=sub->sibling;
					}
					tmpNode.parent=parent;
					tmpNode.mat=tm;
					Matrix4 par,tmat;
					if (parent)
						tmat.Concat(tmBase,parent->BaseMat);
					else
						tmat=tmBase;
					tmpNode.BaseMat=tmat;
					SceneNodes *newparent=sNodes+nsNodes;
					tmpNode.animat=0;
					tmpNode.nanimat=0;
					sNodes[nsNodes++]=tmpNode;
					int err=FindNodes(newparent,FrameLook);
					if (err)
						return err;
				}
			}
			sib=sib->sibling;
		}
	}
	return 0;
}
Example #20
0
int FindPKeys(TxtNode *t)
{
	if (t->child)
	{
		TxtNode *sib=t->child;
		if (!sib)
			return 200;
		char framename[100];
		{
			if (!sib->child)
				return 201;
			if (!sib->child->text)
				return 202;
			if (!strncmp("frm-",sib->child->text,4))
				mystrncpy(framename,sib->child->text+4,sib->child->length-4);
			else
			{
				if (!strncmp("SCENE",sib->child->text,4))
					return 0;
				mystrncpy(framename,sib->child->text,sib->child->length);
			}
			sib=sib->sibling;
		}
		int foundkeys=0;
		maxmatframe=0;
		while (sib)
		{
			if (sib->text&&!mystrncmp("SI_AnimationKey",sib->text,sib->length))
			{
				if (!sib->sibling)
					return 103;
				sib=sib->sibling;
				int err=ProcNKeys(sib,foundkeys);
				if (err)
					return err;
			}
			sib=sib->sibling;
		}
		{
			if (maxmatframe>maxframe)
				maxframe=maxmatframe;
			int i;
			for (i=0;i<nsNodes;i++)
			{
				if (!strcmp(sNodes[i].name,framename))
				{
					int j;
					if (sNodes[i].nanimat<maxmatframe+1)
					{
						delete[] sNodes[i].animat;
						sNodes[i].nanimat=maxmatframe+1;
						sNodes[i].animat=new Matrix4[maxmatframe+1];
						for (j=0;j<=maxmatframe;j++)
							sNodes[i].animat[j].Identity();
					}
					for (j=0;j<=maxmatframe;j++)
					{
						Matrix4 xf;
						xf=sNodes[i].mat;
						Vect3 tt,t2;
						if (foundkeys&1)
						{
							mats[j].GetRow(3,tt);
							xf.SetRow(3,tt);
						}
						if (foundkeys&2)
						{
							float l;
							xf.GetRow(0,t2);
							l=t2.Len();
							mats[j].GetRow(0,tt);
							tt*=l;
							xf.SetRow(0,tt);

							xf.GetRow(1,t2);
							l=t2.Len();
							mats[j].GetRow(1,tt);
							tt*=l;
							xf.SetRow(1,tt);

							xf.GetRow(2,t2);
							l=t2.Len();
							mats[j].GetRow(2,tt);
							tt*=l;
							xf.SetRow(2,tt);
						}
						if (foundkeys&4)
						{
							xf.GetRow(0,tt);
							tt.Norm();
							tt*=scales[j].x();
							xf.SetRow(0,tt);

							xf.GetRow(1,tt);
							tt.Norm();
							tt*=scales[j].x();
							xf.SetRow(1,tt);

							xf.GetRow(2,tt);
							tt.Norm();
							tt*=scales[j].x();
							xf.SetRow(2,tt);

						}
						xf.CalcFlags();
						Matrix4 par,tmat;
						if (sNodes[i].parent)
						{
							if (j<sNodes[i].parent->nanimat)
								par=sNodes[i].parent->animat[j];
							else
								par=sNodes[i].parent->BaseMat;
							tmat.Concat(xf,par);
						}
						else
							tmat=xf;
						sNodes[i].animat[j]=tmat;

#if 0
						par.Inverse(sNodes[i].BaseMat);
						tmat.Concat(par,sNodes[i].animat[j]);
	char tmp[1000];
	int r;
	sprintf(tmp,"final frame %d %s\n",j,sNodes[i].name);
	OutputDebugString(tmp);
	for (r=0;r<4;r++)
	{
		sprintf(tmp,"%6f %6f %6f\n",tmat[r][0],tmat[r][1],tmat[r][2]);
		OutputDebugString(tmp);
	}
	sprintf(tmp,"baseinv frame %d %s\n",j,sNodes[i].name);
	OutputDebugString(tmp);
	for (r=0;r<4;r++)
	{
		sprintf(tmp,"%6f %6f %6f\n",par[r][0],par[r][1],par[r][2]);
		OutputDebugString(tmp);
	}
	sprintf(tmp,"bone frame %d %s\n",j,sNodes[i].name);
	OutputDebugString(tmp);
	for (r=0;r<4;r++)
	{
		sprintf(tmp,"%6f %6f %6f\n",sNodes[i].animat[j][r][0],sNodes[i].animat[j][r][1],sNodes[i].animat[j][r][2]);
		OutputDebugString(tmp);
	}
#endif
					}
				}
			}
		}
	}
	return 0;
}
Example #21
0
File: mygraph.c Project: ombt/ombt
// read in data
int
getdata(int argc, char **argv, int nextarg)
{
	FILE *infd;
	char inbuf[BUFSIZ+1];

	// where to get data?
	if (nextarg >= argc)
	{
		// get data from stdin
		infd = stdin;
	}
	else
	{
		// get data from a file
		infd = fopen(argv[nextarg], "r");
		if (infd == NULL)
		{
			fprintf(stderr, "unable to read file %s.\n", 
				argv[nextarg]);
			return(NOTOK);
		}
	}

	// read in data: first any options
	while (fgets(inbuf, BUFSIZ, infd) != NULL && !feof(infd))
	{
		if (*inbuf == '#')
		{
			// skip comments
			continue;
		}
		else if (mystrncmp(inbuf, StartOfOptions) == 0)
		{
			continue;
		}
		else if (mystrncmp(inbuf, StartOfData) == 0)
		{
			// break out of options loop
			break;
		}
		else if (mystrncmp(inbuf, MinimumXValue) == 0)
		{
			mystrncpy(minxval, inbuf, MinimumXValue);
		}
		else if (mystrncmp(inbuf, MaximumXValue) == 0)
		{
			mystrncpy(maxxval, inbuf, MaximumXValue);
		}
		else if (mystrncmp(inbuf, MinimumYValue) == 0)
		{
			mystrncpy(minyval, inbuf, MinimumYValue);
		}
		else if (mystrncmp(inbuf, MaximumYValue) == 0)
		{
			mystrncpy(maxyval, inbuf, MaximumYValue);
		}
		else if (mystrncmp(inbuf, XAxisPlotType) == 0)
		{
			mystrncpy(xplottype, inbuf, XAxisPlotType);
		}
		else if (mystrncmp(inbuf, YAxisPlotType) == 0)
		{
			mystrncpy(yplottype, inbuf, YAxisPlotType);
		}
		else if (mystrncmp(inbuf, XAxisLabel) == 0)
		{
			mystrncpy(xlabel, inbuf, XAxisLabel);
		}
		else if (mystrncmp(inbuf, YAxisLabel) == 0)
		{
			mystrncpy(ylabel, inbuf, YAxisLabel);
		}
		else if (mystrncmp(inbuf, GraphTitle) == 0)
		{
			mystrncpy(graph_title, inbuf, GraphTitle);
		}
		else
		{
			// unknown option
			fprintf(stderr, "SKIPPING unknown option in graph [%s].\n",
				inbuf);
		}
	}

	// check if out of data
	if (feof(infd))
	{
		fprintf(stderr, "unexpected EOF. no data read in.\n");
		return(NOTOK);
	}

	// allocate space for a 100 points, first.
	x = new double[allocpts];
	MustBeTrue(x != NULL);
	y = new double[allocpts];
	MustBeTrue(y != NULL);

	// now read in data
	for (npts = 0; fgets(inbuf, BUFSIZ, infd) != NULL && !feof(infd); )
	{
		// read in x,y point
		double tmpx, tmpy;
		sscanf(inbuf, "%lg%lg", &tmpx, &tmpy);
	
		// store x,y point
		if (npts >= allocpts)
		{
			// need to reallocate 
			allocpts *= 2;
			double *px = new double [allocpts];
			MustBeTrue(px != NULL);
			double *py = new double [allocpts];
			MustBeTrue(py != NULL);
			for (int ipt = 0; ipt < npts; ipt++)
			{
				px[ipt] = x[ipt];
				py[ipt] = y[ipt];
			}
			delete [] x;
			delete [] y;
			x = px;
			y = py;
		}
		x[npts] = tmpx;
		y[npts++] = tmpy;
	}

	// find min and max limits for x values.
	getmin(x, npts, rminxval, minxval);
	getmax(x, npts, rmaxxval, maxxval);
	getmin(y, npts, rminyval, minyval);
	getmax(y, npts, rmaxyval, maxyval);

	// save values in case of reset
	reset_rminxval = rminxval;
	reset_rmaxxval = rmaxxval;
	reset_rminyval = rminyval;
	reset_rmaxyval = rmaxyval;

	// close file
	if (infd != stdin)
		fclose(infd);

	// all done
	return(OK);
}