- if(strlen(ptr) == 0) g_error("Not a valid file: %s\n", pathname);
- if(strncmp("<system",ptr,7) !=0)g_error("Not a valid file: %s\n", pathname);
-
- for(i=0;i<entry_number;i++){
- if(fgets(buf,DIR_NAME_SIZE, fp)== NULL)
- g_error("Not a valid file: %s\n", pathname);
- ptr = buf;
- while(isspace(*ptr)) ptr++;
- switch(i){
- case 0:
- if(strncmp("node_name=",ptr,10)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->node_name = g_strdup(ptr+10);
- break;
- case 1:
- if(strncmp("domainname=",ptr,11)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->domain_name = g_strdup(ptr+11);
- break;
- case 2:
- if(strncmp("cpu=",ptr,4)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->nb_cpu = (unsigned)atoi(ptr+4);
- break;
- case 3:
- if(strncmp("arch_size=",ptr,10)!=0)
- g_error("Not a valid file: %s\n", pathname);
- if(strcmp(ptr+10,"\"LP32\"") == 0) des->size = LTT_LP32;
- else if(strcmp(ptr+10,"\"ILP32\"") == 0) des->size = LTT_ILP32;
- else if(strcmp(ptr+10,"\"LP64\"") == 0) des->size = LTT_LP64;
- else if(strcmp(ptr+10,"\"ILP64\"") == 0) des->size = LTT_ILP64;
- else if(strcmp(ptr+10,"\"UNKNOWN\"") == 0) des->size = LTT_UNKNOWN;
- break;
- case 4:
- if(strncmp("endian=",ptr,7)!=0)
- g_error("Not a valid file: %s\n", pathname);
- if(strcmp(ptr+7,"\"LITTLE_ENDIAN\"") == 0)
- des->endian = LTT_LITTLE_ENDIAN;
- else if(strcmp(ptr+7,"\"BIG_ENDIAN\"") == 0)
- des->endian = LTT_BIG_ENDIAN;
- break;
- case 5:
- if(strncmp("kernel_name=",ptr,12)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->kernel_name = g_strdup(ptr+12);
- break;
- case 6:
- if(strncmp("kernel_release=",ptr,15)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->kernel_release = g_strdup(ptr+15);
- break;
- case 7:
- if(strncmp("kernel_version=",ptr,15)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->kernel_version = g_strdup(ptr+15);
- break;
- case 8:
- if(strncmp("machine=",ptr,8)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->machine = g_strdup(ptr+8);
- break;
- case 9:
- if(strncmp("processor=",ptr,10)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->processor = g_strdup(ptr+10);
- break;
- case 10:
- if(strncmp("hardware_platform=",ptr,18)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->hardware_platform = g_strdup(ptr+18);
- break;
- case 11:
- if(strncmp("operating_system=",ptr,17)!=0)
- g_error("Not a valid file: %s\n", pathname);
- des->operating_system = g_strdup(ptr+17);
- break;
- case 12:
- if(strncmp("ltt_major_version=",ptr,18)!=0)
- g_error("Not a valid file: %s\n", pathname);
- ptr += 18;
- ptr++;//skip begining "
- ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
- des->ltt_major_version = (unsigned)atoi(ptr);
- break;
- case 13:
- if(strncmp("ltt_minor_version=",ptr,18)!=0)
- g_error("Not a valid file: %s\n", pathname);
- ptr += 18;
- ptr++;//skip begining "
- ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
- des->ltt_minor_version = (unsigned)atoi(ptr);
- break;
- case 14:
- if(strncmp("ltt_block_size=",ptr,15)!=0)
- g_error("Not a valid file: %s\n", pathname);
- ptr += 15;
- ptr++;//skip begining "
- ptr[strlen(ptr)-1] = '\0'; //get rid of the ending "
- des->ltt_block_size = (unsigned)atoi(ptr);
- break;
- default:
- g_error("Not a valid file: %s\n", pathname);
- }
+ context = g_markup_parse_context_new(&markup_parser, 0, des,NULL);
+
+ //while(fgets(buf,DIR_NAME_SIZE, fp) != NULL){
+ while(g_io_channel_read_line(iochan, &buf, &length, NULL, &error)
+ != G_IO_STATUS_EOF) {
+
+ if(error != NULL) {
+ g_warning("Can not read xml file: \n%s\n", error->message);
+ g_error_free(error);
+ }
+ if(!g_markup_parse_context_parse(context, buf, length, &error)){
+ if(error != NULL) {
+ g_warning("Can not parse xml file: \n%s\n", error->message);
+ g_error_free(error);
+ }
+ g_markup_parse_context_free(context);
+
+ g_io_channel_shutdown(iochan, FALSE, &error); /* No flush */
+ if(error != NULL) {
+ g_warning("Can not close file: \n%s\n", error->message);
+ g_error_free(error);
+ }
+
+ close(fd);
+ return -1;
+ }