Esempio n. 1
0
char parseAndSave(char* line){
	char* strPointer;
	char* descriptionStartPointer;
	char* key=NULL;
	char* description=NULL;
	strPointer=line;
	while(*strPointer!='\0'){
		if(*strPointer=='\t'){
			if(key!=NULL){
				//tabulation is ok only once, so key should not be setted
				perror("Invalid file structure");
				return -1;
			}
			*strPointer='\0';	
			key=line;
			if(validateString(key)==STRING_UNVALID){
				perror("Invalid file structure");
				return -1;
			}
			descriptionStartPointer=strPointer+1;
		}
		if(*strPointer=='\n'){
			*strPointer='\0';
			description=descriptionStartPointer;
			if(validateString(description)==STRING_UNVALID){
				perror("Invalid file structure");
				return -1;
			}
		}
		strPointer++;
	}
	if (key==NULL||description==NULL){
		perror("Invalid file structure");
		return -1;
	}
	
	if(DictionaryAdd(dictionary,key, description)!=0)
		return -1;
	return 0;
}
Esempio n. 2
0
int main(int argc, char **argv)
{
  Handle dict;
  Word rv;

  dict = DictionaryCreate(MMStartUp(), 0);
  if (!dict)
  {
    fprintf(stderr, "Error: DictionaryCreate() == NULL\n");
    exit(1);
  }

  rv = DictionaryAdd(dict, "key",3,"value",5, 0);
  if (!rv)
  {
    fprintf(stderr, "Error: DictionaryAdd() == 0\n");
    DisposeHandle(dict);
    exit(1);
  }

  rv = DictionaryContains(dict, "key",3);
  if (!rv)
  {
    fprintf(stderr, "Error: DictionaryContains() == 0\n");
    DisposeHandle(dict);
    exit(1);
  }

  rv = DictionaryCount(dict);
  if (rv != 1)
  {
    fprintf(stderr, "Error: DictionaryCount() != 1\n");
    DisposeHandle(dict);
    exit(1);
  }

  rv = DictionaryAdd(dict, "key2",4, "value2", 6, false);
  if (!rv)
  {
    fprintf(stderr, "Error: DictionaryAdd() == 0\n");
    DisposeHandle(dict);
    exit(1);
  }

  {
    Word cookie = 0;
    DictionaryEnumerator e;

    while ((cookie = DictionaryEnumerate(dict, &e, cookie)) != 0)
    {
      fwrite(e.key, 1, e.keySize, stdout);
      fwrite(" -> ", 1, 4, stdout);
      fwrite(e.value, 1, e.valueSize, stdout);
      fputc('\n', stdout);
    }
  }



  DisposeHandle(dict);
  exit(0);
  return 0;
}
Esempio n. 3
0
char Add(char* key, char* description){
	return DictionaryAdd(dictionary,key, description);
}