int loadPostInfo(struct website * configuration,unsigned int postNum) { char filename[FILENAME_MAX]={0}; snprintf(filename,FILENAME_MAX,"src/Services/MyBlog/res/posts/info%u.html",postNum); fprintf(stderr," Loading post info %u (%s) .. \n",postNum,filename); ssize_t read; FILE * fp = fopen(filename,"r"); if (fp!=0) { struct InputParserC * ipc = InputParser_Create(512,4); InputParser_SetDelimeter(ipc,1,'('); InputParser_SetDelimeter(ipc,2,','); InputParser_SetDelimeter(ipc,3,')'); struct tagItemList tags; char * line = NULL; size_t len = 0; while ((read = getline(&line, &len, fp)) != -1) { //printf("Retrieved line of length %zu :\n", read); //printf("%s", line); InputParser_SeperateWords(ipc,line,0); if ( InputParser_WordCompareNoCaseAuto(ipc,0,"TITLE") ) { InputParser_GetWord(ipc,1,configuration->post.item[postNum].title ,MAX_STR); } else if ( InputParser_WordCompareNoCaseAuto(ipc,0,"DATE") ) { InputParser_GetWord(ipc,1,configuration->post.item[postNum].dateStr,MAX_STR); } else if ( InputParser_WordCompareNoCaseAuto(ipc,0,"AUTHOR") ) { InputParser_GetWord(ipc,1,configuration->post.item[postNum].author ,MAX_STR); } //if ( InputParser_WordCompareNoCaseAuto(ipc,0,"TAGS") ) { InputParser_GetWord(ipc,0,configuration->post.item[postNum].tags ,MAX_STR); } else //if ( InputParser_WordCompareNoCaseAuto(ipc,0,"COMMENTS") ) { InputParser_GetWord(ipc,0,line,MAX_STR); } } fprintf(stderr," Post Info %u --------------\n",postNum); fprintf(stderr," Title : %s \n",configuration->post.item[postNum].title); fprintf(stderr," Date : %s \n",configuration->post.item[postNum].dateStr); fprintf(stderr," Author : %s \n",configuration->post.item[postNum].author); fclose(fp); if (line) { free(line); } InputParser_Destroy(ipc); return 1; } return 0; }
int loadPageInfo(struct website * configuration,unsigned int postNum) { char filename[FILENAME_MAX]={0}; snprintf(filename,FILENAME_MAX,"src/Services/MyBlog/res/pages/info%u.html",postNum); fprintf(stderr," Loading widget info %u (%s) .. \n",postNum,filename); ssize_t read; FILE * fp = fopen(filename,"r"); if (fp!=0) { struct InputParserC * ipc = InputParser_Create(512,4); InputParser_SetDelimeter(ipc,1,'('); InputParser_SetDelimeter(ipc,2,','); InputParser_SetDelimeter(ipc,3,')'); struct tagItemList tags; char * line = NULL; size_t len = 0; while ((read = getline(&line, &len, fp)) != -1) { InputParser_SeperateWords(ipc,line,0); if ( InputParser_WordCompareNoCaseAuto(ipc,0,"TITLE") ) { InputParser_GetWord(ipc,1,configuration->pages.item[postNum].title ,MAX_STR); } } fprintf(stderr," Page Title %u --------------\n",postNum); fprintf(stderr," Title : %s \n",configuration->pages.item[postNum].title); fclose(fp); if (line) { free(line); } InputParser_Destroy(ipc); return 1; } return 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; }
void InputParser::SetDelimeter(int num,char tmp) { InputParser_SetDelimeter(ipc,num,tmp); }