Example #1
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;
}
Example #2
0
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;
}
Example #3
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;
}