Exemple #1
0
int AmmCaptcha_loadDictionary(char * dictFilename)
{
 captchaStrings = hashMap_Create(32889,1000,0);
 if (captchaStrings==0) { fprintf(stderr,"Could not loadDictionary %s \n",dictFilename); return 0; }
 FILE *fd=0;
 fd = fopen(dictFilename,"r");
 if (fd!=0)
 {
  char str[256]={0};
  while (!feof(fd))
  {
    fscanf (fd, "%s", str);
    hashMap_Add(captchaStrings,str,0,0);
  }
  fclose(fd);
  return 1;
 }
 return 0;
}
int main(int argc, const char* argv[])
{
  int i=0;

  if (argc==1)
    {
      displayHelp();
      return 0;
    }
  for (i=0; i<argc; i++)
  {
    if (
         (strcmp(argv[i],"--help")==0) ||
         (strcmp(argv[i],"-h")==0) ||
         (strcmp(argv[i],"?")==0)
        )
    {
      displayHelp();
      return 0;
    }  else
    if (strcmp(argv[i],"-n")==0)    { printNotFoundLibs=1; printFoundLibs=0; } else
    if (strcmp(argv[i],"-f")==0)    { printNotFoundLibs=0; printFoundLibs=1; }
    if (strcmp(argv[i],"-link")==0) {  printFoundLibs=0; printNotFoundLibs=1; linkToLibraries=1; }
    if (strcmp(argv[i],"-maxDepth")==0)  {
                                          maxDepth = atoi(argv[i+1]);
                                         }
  }

  hm = hashMap_Create(2000,1000,0);
  if ( hm == 0 ) { fprintf(stderr,"Could not create hashMap\n"); return 1; }

  runLdd((char*) argv[argc-1],0);


  hashMap_Destroy(hm);
  return 0;
}
Exemple #3
0
int loadSite( char * filename )
{
  boardHashMap = hashMap_Create( 100 , 100 , 0 , 1 /*We should have sorting enabled..!*/ );
  threadHashMap = hashMap_Create( 10000 , 1000 , 0 , 1 /*We should have sorting enabled..!*/ );

    unsigned int numberOfElements=0;
    char what2GetBack[1024]={0};
    AmmServer_ExecuteCommandLine("ls data/board -al | cut -d ' ' -f10 | wc -l ", what2GetBack , 1024 );
    numberOfElements = atoi(what2GetBack);

    ourSite.boards = (struct board * ) malloc(sizeof(struct board) * MAX_BOARDS);
    if (ourSite.boards == 0 ) { fprintf(stderr,"Cannot allocate memory to hold boards , failed to load "); return 0; }

    ourSite.maxNumberOfBoards = MAX_BOARDS;
    ourSite.numberOfBoards = 0;
    strncpy(ourSite.siteName ,filename  ,MAX_STRING_SIZE  );


    threadIndexPage      = AmmServer_ReadFileToMemoryHandler("data/simple.html");

   //------------------------------------------------------

   char line [LINE_MAX_LENGTH]={0};
   //Try and open filename
   FILE * fp = fopen(filename,"r");
   if (fp == 0 ) { fprintf(stderr,"Cannot open trajectory stream %s \n",filename); return 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 stream\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_WordCompareNoCase(ipc,0,(char*)"SITENAME",8)==1)
                {
                     InputParser_GetWord(ipc,1, ourSite.siteName , MAX_STRING_SIZE );
                } else
                if (InputParser_WordCompareNoCase(ipc,0,(char*)"SITEDESCRIPTION",8)==1)
                {
                     InputParser_GetWord(ipc,1, ourSite.siteDescription , MAX_STRING_SIZE );
                }
              }
          }
       }

    InputParser_Destroy(ipc);
    fclose(fp);




   DIR *dp;
   struct dirent *ep;
   dp = opendir ("data/board");
   if (dp != NULL)
    {
      while (ep = readdir (dp))
       {
         if (strcmp(ep->d_name,".")==0)  { } else
         if (strcmp(ep->d_name,"..")==0) { } else
            {
              //fprintf(stderr,"Adding board %s \n",ep->d_name);
              addBoardToSite( &ourSite , ep->d_name );
            }
       }
      closedir (dp);
    } else
    {
     fprintf(stderr,"Cannot open directory to list channels \n");
    }



  return 1;
}