Ejemplo n.º 1
0
int main()
{
    //InputParserC is a library to tokenize words from a string "zero,one,two,three(four)" -> "zero" "one" "two" "three" "four"..!
    printf("Hello World , InputParserC linked version is %s \n",InputParserC_Version());

    //To use it you must first allocate a InputParserC structure!
     struct InputParserC * ipc=0;
    //After you declared the structure you will have to initialize it to accomodate the data you want to input
    //The next command initializes our input parser to accomodate a max of 512 different words , which result from 5 seperating delimeters
    //In the example "zero,one,two,three(four)" the delimeters used are  , ( ) and \0
     ipc = InputParser_Create(512,5);


    // The default delimiters are..
    printf("The default delimiters are.. ");
    int i=0;
    for ( i = 0; i< ipc->max_delimeter_count; i++ )
    {
      printf("%u ascii or   %c  ",InputParser_GetDelimeter(ipc,i),InputParser_GetDelimeter(ipc,i));
    }

     //We will now tokenize the string "zero,one,two,three(four)" , we set the last parameter to zero to indicate that
     //input parser should keep a copy of the string , because after the call is done it will be disposed of..!
     //The return value ( res ) is the number of tokens extracted!
     int res = InputParser_SeperateWords(ipc,"zero,one,2,three(four)",1);
     printf("\nInput Parser tokenized a total of %u tokens \n",res);

     //To retrieve the tokens as a string you will need some memory to store the strings in!
     //The following word_space has space for a string with up to 128 characters
     char word_space[128]={0};

     //We now want to get the token with number 1 and store it in word_space!
     //Please note that the tokens are counted from 0 to n-1 where n is the total number of tokens..
    /*
       "zero,one,two,three(four)"
          0   1   2    3     4    = a total of n=5 tokens !
    */

     // The following command will return the second token ( token with number 1 ) and store it to the word_space
     // that contains up to 128 character strings
     InputParser_GetWord(ipc,1,word_space,128);
     printf("InputParser_GetWord returns %s\n",word_space);

     //If you want you can retrieve an upcase/lowercase version of the string
     InputParser_GetUpcaseWord(ipc,1,word_space,128);
     printf("InputParser_GetUpcaseWord returns %s\n",word_space);

     //If the token is a number you can return an integer! :)
     i = InputParser_GetWordInt(ipc,2);
     printf("InputParser_GetWordInt(ipc,2) should return 2 , our build returns %u\n",i);

     // After you are finished with the InputParser , you should deallocate it to free memory..!
     InputParser_Destroy(ipc);

     printf("\n\nThat concludes the rationale tutorial \n Press any key to start XP bug check.. \n\n");
     getchar();
    // Now run some tests to find bugs , if they return 0 SeperateWordsC should be working ok!
  return IntermediateTests();

}
Ejemplo n.º 2
0
int processCommand(struct InputParserC * ipc , struct motionStats * st ,char * line , unsigned int words_count , unsigned int startAtFrame)
{

  if (InputParser_WordCompareAuto(ipc,0,"MOVE"))
   {
      int frameNum = InputParser_GetWordInt(ipc,2);
      if (frameNum<startAtFrame) { return 0; }

      float x = InputParser_GetWordFloat(ipc,3);
      float y = InputParser_GetWordFloat(ipc,4);
      float z = InputParser_GetWordFloat(ipc,5);

      float qW = InputParser_GetWordFloat(ipc,6);
      float qX = InputParser_GetWordFloat(ipc,7);
      float qY = InputParser_GetWordFloat(ipc,8);
      float qZ = InputParser_GetWordFloat(ipc,9);

      updatePosition(st,x,y,z,qW,qX,qY,qZ);
   }
    else
  if (InputParser_WordCompareAuto(ipc,0,"POSE"))
   {
    int frameNum = InputParser_GetWordInt(ipc,2);
    if (frameNum<startAtFrame) { return 0; }

    //fprintf(stdout,"Found Frame %u \n",InputParser_GetWordInt(ipc,1));
    char str[128];
    if (InputParser_GetWord(ipc,3,str,128)!=0)
    {//Flush next frame
      float x = InputParser_GetWordFloat(ipc,4);
      float y = InputParser_GetWordFloat(ipc,5);
      float z = InputParser_GetWordFloat(ipc,6);

      unsigned int where2work=0;
      if  ( getJointMemoryID(st,str,&where2work) )
      {
        updateJoint(st,where2work,x,y,z);
      }


      //fprintf(stdout," %0.2f %0.2f %0.2f \n",x,y,z);
      return 1;
    }
   }

  return 0;
}
Ejemplo n.º 3
0
int loadPostHeader(char * postHeaderFilename , struct post * ourPost)
{
   FILE * fp = fopen(postHeaderFilename,"r");
   if (fp == 0 ) { fprintf(stderr,"Cannot open loadPostHeader file %s \n",postHeaderFilename); return 0; }


    char line [LINE_MAX_LENGTH]={0};
    //Allocate a token parser
    struct InputParserC * ipc=0;
    ipc = InputParser_Create(LINE_MAX_LENGTH,5);
    if (ipc==0) { fprintf(stderr,"Cannot allocate memory for new loadBoardSettings parser\n"); return 0; }

    while (!feof(fp))
       {
         //We get a new line out of the file
         unsigned int readOpResult = (fgets(line,LINE_MAX_LENGTH,fp)!=0);
         if ( readOpResult != 0 )
           {
             //We tokenize it
             unsigned int words_count = InputParser_SeperateWords(ipc,line,0);
             if ( words_count > 0 )
              {
                if (InputParser_WordCompareNoCaseAuto(ipc,0,(char*)"OP")==1)
                {
                   InputParser_GetWord(ipc,1,ourPost->op,MAX_STRING_SIZE);
                } else
                if (InputParser_WordCompareNoCaseAuto(ipc,0,(char*)"IMAGENAME")==1)
                {
                   ourPost->hasFile=1;
                   InputParser_GetWord(ipc,1,ourPost->fileOriginalName,MAX_STRING_SIZE);
                } else
                if (InputParser_WordCompareNoCaseAuto(ipc,0,(char*)"TIMESTAMP")==1)
                {
                   ourPost->creation.year   =  InputParser_GetWordInt(ipc,1);
                   ourPost->creation.month  =  InputParser_GetWordInt(ipc,2);
                   ourPost->creation.day    =  InputParser_GetWordInt(ipc,3);
                   ourPost->creation.hour   =  InputParser_GetWordInt(ipc,4);
                   ourPost->creation.minute =  InputParser_GetWordInt(ipc,5);
                   ourPost->creation.second =  InputParser_GetWordInt(ipc,6);
                }
              }
          }
       }

    InputParser_Destroy(ipc);
    fclose(fp);
    return 1;
}
Ejemplo n.º 4
0
void ParseString(struct InputParserC * ipc,char * thestr)
{
    int i,z;
    char word_space[max_ret_word]={0};


    printf("\n\nParsing a string..  ( %s ) \n",thestr);
    time_t msec = time(NULL) * 1000;
    int res = InputParser_SeperateWords(ipc,thestr,0);
    time_t msec2 = time(NULL) * 1000;
    printf("Words Seperated ( %u ) at %u msec.. ",res,(unsigned int) (msec2-msec));

    printf("Int Check ");
    for (i=0; i<res; i++) {  z=InputParser_GetWordInt(ipc,i); printf(" %u = %u ",i,z); } printf("\n\n");

    printf("Length Check ");
    for (i=0; i<res; i++) { printf(" %u = %u ",i,InputParser_GetWordLength(ipc,i)); } printf("\n\n");


    printf("String Check ");
    for (i=0; i<res; i++) { InputParser_GetWord(ipc,i,word_space,max_ret_word);
                           printf(" %u = %s ",i,word_space); } printf("\n\n");

    printf("Upcase String Check ");
    for (i=0; i<res; i++) { InputParser_GetUpcaseWord(ipc,i,word_space,max_ret_word);
                           printf(" %u = %s ",i,word_space); } printf("\n\n");

    printf("Lowercase String Check ");
    for (i=0; i<res; i++) { InputParser_GetLowercaseWord(ipc,i,word_space,max_ret_word);
                           printf(" %u = %s ",i,word_space); } printf("\n\n");


    printf("Erroneous String Check ");
    strcpy(word_space,"");
    for (i=res; i<res+2; i++) { InputParser_GetWord(ipc,i,word_space,max_ret_word);
                           printf(" %u = %s ",i,word_space); } printf("\n\n");


}
Ejemplo n.º 5
0
int readVirtualStream(struct VirtualStream * newstream)
{
  #if USE_FILE_INPUT

  #if PRINT_DEBUGGING_INFO
  fprintf(stderr,"readVirtualStream(%s) called \n",newstream->filename);
  #endif

  //Our stack variables ..
  unsigned int readOpResult = 0;
  char line [LINE_MAX_LENGTH]={0};

  //Try and open filename
  FILE * fp = fopen(newstream->filename,"r");
  if (fp == 0 ) { fprintf(stderr,"Cannot open trajectory stream %s \n",newstream->filename); return 0; }

  //Find out the size of the file..!
  fseek (fp , 0 , SEEK_END);
  unsigned long lSize = ftell (fp);
  rewind (fp);
  fprintf(stderr,"Opening a %lu byte file %s \n",lSize,newstream->filename);

  //Allocate a token parser
  struct InputParserC * ipc=0;
  ipc = InputParser_Create(LINE_MAX_LENGTH,5);
  if (ipc==0)  { fprintf(stderr,"Cannot allocate memory for new stream\n"); return 0; }

  newstream->fileSize = lSize;

  //Add a dummy CAMERA Object here!
  growVirtualStreamObjectsTypes(newstream,OBJECT_TYPES_TO_ADD_STEP);
  strcpy( newstream->objectTypes[0].name , "camera" );
  strcpy( newstream->objectTypes[0].model , "camera" );
  ++newstream->numberOfObjectTypes;

  growVirtualStreamObjects(newstream,OBJECTS_TO_ADD_STEP);
  strcpy( newstream->object[0].name, "camera");
  strcpy( newstream->object[0].typeStr, "camera");
  strcpy( newstream->object[0].value, "camera");
  newstream->object[0].type = 0; //Camera
  newstream->object[0].R =0;
  newstream->object[0].G =0;
  newstream->object[0].B =0;
  newstream->object[0].Transparency=0;
  ++newstream->numberOfObjects;
  // CAMERA OBJECT ADDED

  newstream->debug=0;
 //Everything is set , Lets read the file!
  while (!feof(fp))
  {
   //We get a new line out of the file
   readOpResult = (fgets(line,LINE_MAX_LENGTH,fp)!=0);
   if ( readOpResult != 0 )
    {
      //We tokenize it
      unsigned int words_count = InputParser_SeperateWords(ipc,line,0);
      if ( words_count > 0 )
         {
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"DEBUG",5)==1)
            {
              fprintf(stderr,"DEBUG Mode on\n");
              newstream->debug=1;
            } else

            /*! REACHED AN AUTO REFRESH DECLERATION ( AUTOREFRESH(1500) )
              argument 0 = AUTOREFRESH , argument 1 = value in milliseconds (0 = off ) */
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"AUTOREFRESH",11)==1)
            {
                newstream->autoRefresh = InputParser_GetWordInt(ipc,1);
            } else
            /*! REACHED AN INTERPOLATE TIME SWITCH DECLERATION ( INTERPOLATE_TIME(1) )
              argument 0 = INTERPOLATE_TIME , argument 1 = (0 = off ) ( 1 = on )*/
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"INTERPOLATE_TIME",16)==1)
            {
                //The configuration INTERPOLATE_TIME is the "opposite" of this flag ignore time
                newstream->ignoreTime = InputParser_GetWordInt(ipc,1);
                // so we flip it here.. , the default is not ignoring time..
                if (newstream->ignoreTime == 0 ) { newstream->ignoreTime=1; } else
                                                 { newstream->ignoreTime=0; }
            } else
              /*! REACHED AN BACKGROUND DECLERATION ( BACKGROUND(0,0,0) )
              argument 0 = BACKGROUND , argument 1 = R , argument 2 = G , argument 3 = B , */
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"BACKGROUND",10)==1)
            {
                //The configuration INTERPOLATE_TIME is the "opposite" of this flag ignore time
                newstream->backgroundR = (float) InputParser_GetWordInt(ipc,1) / 255;
                newstream->backgroundG = (float) InputParser_GetWordInt(ipc,2) / 255;
                newstream->backgroundB = (float) InputParser_GetWordInt(ipc,3) / 255;
                // so we flip it here.. , the default is not ignoring time..
            } else
            /*! REACHED AN OBJECT TYPE DECLERATION ( OBJECTTYPE(spatoula_type,"spatoula.obj") )
              argument 0 = OBJECTTYPE , argument 1 = name ,  argument 2 = value */
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"OBJECTTYPE",10)==1)
            {
               char name[MAX_PATH]={0};
               char model[MAX_PATH]={0};
               InputParser_GetWord(ipc,1,name,MAX_PATH);
               InputParser_GetWord(ipc,2,model,MAX_PATH);

               addObjectTypeToVirtualStream( newstream , name, model );

            } else
            /*! REACHED AN OBJECT DECLERATION ( OBJECT(something,spatoula_type,0,255,0,0,0,1.0,spatoula_something) )
              argument 0 = OBJECT , argument 1 = name ,  argument 2 = type ,  argument 3-5 = RGB color  , argument 6 Transparency , argument 7 = No Color , argument 8 = Scale
              argument 9 = String Freely formed Data */
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"OBJECT",6)==1)
            {
               char name[MAX_PATH]={0} , typeStr[MAX_PATH]={0};
               InputParser_GetWord(ipc,1,name,MAX_PATH);
               InputParser_GetWord(ipc,2,typeStr,MAX_PATH);

               unsigned char R = (unsigned char) InputParser_GetWordInt(ipc,3);
               unsigned char G = (unsigned char)  InputParser_GetWordInt(ipc,4);
               unsigned char B = (unsigned char)  InputParser_GetWordInt(ipc,5);
               unsigned char Alpha = (unsigned char)  InputParser_GetWordInt(ipc,6) ;
               unsigned char nocolor = (unsigned char) InputParser_GetWordInt(ipc,7);
               float scale = (float) InputParser_GetWordFloat(ipc,8);

               //Value , not used : InputParser_GetWord(ipc,8,newstream->object[pos].value,15);
               addObjectToVirtualStream(newstream ,name,typeStr,R,G,B,Alpha,nocolor,0,0,scale);

            } else
            /*! REACHED A POSITION DECLERATION ( POS(hand,0,   0.0,0.0,0.0 , 0.0,0.0,0.0,0.0 ) )
              argument 0 = POS , argument 1 = name ,  argument 2 = time in MS , argument 3-5 = X,Y,Z , argument 6-9 = Rotations*/
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"POS",3)==1)
            {
               char name[MAX_PATH];
               InputParser_GetWord(ipc,1,name,MAX_PATH);
               unsigned int time = InputParser_GetWordInt(ipc,2);

               float pos[7]={0};
               pos[0] = InputParser_GetWordFloat(ipc,3);
               pos[1] = InputParser_GetWordFloat(ipc,4);
               pos[2] = InputParser_GetWordFloat(ipc,5);
               pos[3] = InputParser_GetWordFloat(ipc,6);
               pos[4] = InputParser_GetWordFloat(ipc,7);
               pos[5] = InputParser_GetWordFloat(ipc,8);
               pos[6] = InputParser_GetWordFloat(ipc,9);
               int coordLength=7;

              addPositionToObject( newstream , name  , time , (float*) pos , coordLength );
            }
             else
            /*! REACHED A PROJECTION MATRIX DECLERATION ( PROJECTION_MATRIX( ... 16 values ... ) )
              argument 0 = PROJECTION_MATRIX , argument 1-16 matrix values*/
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"PROJECTION_MATRIX",17)==1)
            {
               newstream->projectionMatrixDeclared=1;
               int i=1;
               for (i=1; i<=16; i++) { newstream->projectionMatrix[i-1] = (double)  InputParser_GetWordFloat(ipc,i); }
               fprintf(stderr,"Projection Matrix given to TrajectoryParser\n");
            }
             else
            /*! REACHED A MODELVIEW MATRIX DECLERATION ( MODELVIEW_MATRIX( ... 16 values ... ) )
              argument 0 = MODELVIEW_MATRIX , argument 1-16 matrix values*/
            if (InputParser_WordCompareNoCase(ipc,0,(char*)"MODELVIEW_MATRIX",16)==1)
            {
               newstream->modelViewMatrixDeclared=1;
               int i=1;
               for (i=1; i<=16; i++) { newstream->modelViewMatrix[i-1] = (double) InputParser_GetWordFloat(ipc,i); }
               fprintf(stderr,"ModelView Matrix given to TrajectoryParser\n");
            }
         } // End of line containing tokens
    } //End of getting a line while reading the file
  }

  fclose(fp);
  InputParser_Destroy(ipc);

  return 1;
  #else
    fprintf(stderr,RED "This build of Trajectory parser does not have File Input compiled in!\n" NORMAL);
    fprintf(stderr,YELLOW "Please rebuild after setting USE_FILE_INPUT to 1 on file TrajectoryParser.cpp or .c\n" NORMAL);
    fprintf(stderr,YELLOW "also note that by enabling file input you will also need to link with InputParser_C.cpp or .c \n" NORMAL);
    fprintf(stderr,YELLOW "It can be found here https://github.com/AmmarkoV/InputParser/ \n" NORMAL);
  #endif

 return 0;
}
Ejemplo n.º 6
0
int IntermediateTests()
{
   time_t startmsec = time(NULL) * 1000;

    printf("Testing InputParserC ");
    struct InputParserC * ipc=0;
    printf(", linked version is %s \n",InputParserC_Version());


    printf("Creating a new instance of the parser\n");

    printf("Starting memory point of IPC struct is %p , and afterwards",ipc);
    ipc = InputParser_Create(256,5);
    if ( ipc == 0 ) { fprintf(stderr,"\nError Commiting InputParser Context \n"); return(1); }
    printf(" %p \n",ipc);


    struct InputParserC * ipc2=0;
    printf("Starting memory point of second IPC struct is %p , and afterwards",ipc2);
    ipc2 = InputParser_Create(256,5);
    if ( ipc2 == 0 ) { fprintf(stderr,"\nError Commiting InputParser Context \n"); return(1); }
    printf(" %p \n",ipc2);


    printf("SelfChecking\n");
    if ( InputParser_SelfCheck(ipc) == 0 ) { fprintf(stderr,"\nInputParser Self Check Returns erroneous state \n"); return(1); }
     printf("SelfChecking2\n");
    if ( InputParser_SelfCheck(ipc2) == 0 ) { fprintf(stderr,"\nInputParser2 Self Check Returns erroneous state \n"); return(1); }


    printf("Checking if default delimiters work correctly\n");
    InputParser_DefaultDelimeters(ipc);


    char * parsemessage = "0,1,2,3,4,5,,6,7,8,9,10\0";
    ParseString(ipc,parsemessage);


    char * parsemessage2 = "miden,ena,dyo,tria,tessera,pente,eksi,epta,okto,ennea,deka\0";
    ParseString(ipc,parsemessage2);
    if (InputParser_WordCompare(ipc,0,"miden",5)!=1) { fprintf(stderr,"\n\n\n!!!!!!!!!!!!!!!!!! CATCHED COMPARISON ERROR !!!!!!!!!!!!!!!!!!\n\n\n");} else
                                                     { fprintf(stderr,"Comparison check ok..\n");}
    if (InputParser_WordCompare(ipc,1,"ena",3)!=1) { fprintf(stderr,"\n\n\n!!!!!!!!!!!!!!!!!! CATCHED COMPARISON ERROR !!!!!!!!!!!!!!!!!!\n\n\n");} else
                                                   { fprintf(stderr,"Comparison check ok..\n");}
    if (InputParser_WordCompare(ipc,2,"dy",2)!=0) { fprintf(stderr,"\n\n\n!!!!!!!!!!!!!!!!!! CATCHED COMPARISON ERROR !!!!!!!!!!!!!!!!!!\n\n\n");} else
                                                  { fprintf(stderr,"Comparison check ok..\n");}

    char * parsemessage3 = "010\0";
    ParseString(ipc,parsemessage3);

    char * parsemessage4 = "\0";
    ParseString(ipc2,parsemessage4);


    char * parsemessage5 = ",,,,(),\0";
    ParseString(ipc,parsemessage5);

    char * parsemessage6 = "FORWARD(45)\0";
    ParseString(ipc,parsemessage6);


    char * parsemessage7 = "0,1,2,-45,-0.0,1,1000000000000000\0";
    ParseString(ipc2,parsemessage7);


    // MINI DATE TEST
        struct InputParserC * ipc3=0;
        ipc3 = InputParser_Create(50,2);
        InputParser_SetDelimeter(ipc3,1,'/');
        int res = InputParser_SeperateWords(ipc3,"0/0/0",0);
         if ( res >= 3 )
         {
           int year=InputParser_GetWordInt(ipc3,2);
           int month=InputParser_GetWordInt(ipc3,1);
           int day=InputParser_GetWordInt(ipc3,0);
           year = month + day;
         }
         InputParser_Destroy(ipc3);
    // MINI DATE TEST


    printf("Deleting the new instance of the parser\n");
    InputParser_Destroy(ipc);
    InputParser_Destroy(ipc2);
    printf("InputParser Instances destructed.. \n");

    time_t endmsec = time(NULL) * 1000;
    printf("\n%u total msec.. \n",(unsigned int) (endmsec-startmsec));

    return 0;
}
Ejemplo n.º 7
0
signed int InputParser::GetWordInt(int num)
{
 return InputParser_GetWordInt(ipc,num);
}