[158] | 1 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : xml_parser.c |
---|
| 3 | // Date : 04/04/2012 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | // This program translate an xml file containing a MAPPING_INFO data structure |
---|
| 8 | // to a binary file that can be directly loaded in the boot ROM and used by the GIET. |
---|
| 9 | // The C strcutures are defined in the mapping_info.h file. |
---|
| 10 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 11 | |
---|
| 12 | #include <stdlib.h> |
---|
| 13 | #include <fcntl.h> |
---|
| 14 | #include <unistd.h> |
---|
| 15 | #include <stdio.h> |
---|
| 16 | #include <string.h> |
---|
| 17 | #include <libxml/xmlreader.h> |
---|
| 18 | #include <mapping_info.h> |
---|
| 19 | |
---|
| 20 | #define MAX_CLUSTERS 1024 |
---|
| 21 | #define MAX_PSEGS 4096 |
---|
| 22 | #define MAX_VSPACES 1024 |
---|
| 23 | #define MAX_TASKS 4096 |
---|
| 24 | #define MAX_MWMRS 4096 |
---|
| 25 | #define MAX_VSEGS 4096 |
---|
| 26 | |
---|
| 27 | #define XML_PARSER_DEBUG 0 |
---|
| 28 | |
---|
| 29 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 30 | // global variables used to store and index the data structures |
---|
| 31 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 32 | |
---|
| 33 | mapping_header_t* header; |
---|
| 34 | mapping_cluster_t* cluster[MAX_CLUSTERS]; // cluster array |
---|
| 35 | mapping_pseg_t* pseg[MAX_PSEGS]; // pseg array |
---|
| 36 | mapping_vspace_t* vspace[MAX_VSPACES]; // vspace array |
---|
| 37 | mapping_vseg_t* vseg[MAX_VSEGS]; // vseg array |
---|
| 38 | mapping_task_t* task[MAX_TASKS]; // task array |
---|
| 39 | |
---|
| 40 | unsigned int cluster_index = 0; |
---|
| 41 | unsigned int vspace_index = 0; |
---|
| 42 | unsigned int global_index = 0; |
---|
| 43 | unsigned int pseg_index = 0; |
---|
| 44 | unsigned int vseg_index = 0; |
---|
| 45 | unsigned int vseg_loc_index = 0; |
---|
| 46 | unsigned int task_index = 0; |
---|
| 47 | unsigned int task_loc_index = 0; |
---|
| 48 | unsigned int mwmr_index = 0; |
---|
| 49 | unsigned int mwmr_loc_index = 0; |
---|
| 50 | |
---|
| 51 | ////////////////////////////////////////////////// |
---|
| 52 | unsigned int getIntValue( xmlTextReaderPtr reader, |
---|
| 53 | const char* attributeName, |
---|
| 54 | unsigned int* ok ) |
---|
| 55 | { |
---|
| 56 | unsigned int value = 0; |
---|
| 57 | unsigned int i; |
---|
| 58 | char c; |
---|
| 59 | |
---|
| 60 | char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); |
---|
| 61 | |
---|
| 62 | if ( string == NULL ) // missing argument |
---|
| 63 | { |
---|
| 64 | *ok = 0; |
---|
| 65 | return 0; |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | if ( (string[0] == '0') && ((string[1] == 'x') || (string[1] == 'X')) ) // Hexa |
---|
| 70 | { |
---|
| 71 | for ( i = 2 ; (string[i] != 0) && (i < 10) ; i++ ) |
---|
| 72 | { |
---|
| 73 | c = string[i]; |
---|
| 74 | if ((c >= '0') && (c <= '9')) value = (value<<4) + string[i] - 48; |
---|
| 75 | else if ((c >= 'a') && (c <= 'f')) value = (value<<4) + string[i] - 87; |
---|
| 76 | else if ((c >= 'A') && (c <= 'F')) value = (value<<4) + string[i] - 55; |
---|
| 77 | else |
---|
| 78 | { |
---|
| 79 | *ok = 0; |
---|
| 80 | return 0; |
---|
| 81 | } |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | else // Decimal |
---|
| 85 | { |
---|
| 86 | for ( i = 0 ; (string[i] != 0) && (i < 9) ; i++ ) |
---|
| 87 | { |
---|
| 88 | c = string[i]; |
---|
| 89 | if ((c >= '0') && (c <= '9')) value = (value*10) + string[i] - 48; |
---|
| 90 | else |
---|
| 91 | { |
---|
| 92 | *ok = 0; |
---|
| 93 | return 0; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | } |
---|
| 97 | *ok = 1; |
---|
| 98 | return value; |
---|
| 99 | } |
---|
| 100 | } // end getIntValue() |
---|
| 101 | |
---|
| 102 | /////////////////////////////////////////////// |
---|
| 103 | char* getStringValue ( xmlTextReaderPtr reader, |
---|
| 104 | const char* attributeName, |
---|
| 105 | unsigned int* ok ) |
---|
| 106 | { |
---|
| 107 | char* string = (char*)xmlTextReaderGetAttribute(reader, (const xmlChar*)attributeName); |
---|
| 108 | |
---|
| 109 | if ( string == NULL ) // missing argument |
---|
| 110 | { |
---|
| 111 | *ok = 0; |
---|
| 112 | return NULL; |
---|
| 113 | } |
---|
| 114 | else |
---|
| 115 | { |
---|
| 116 | *ok = 1; |
---|
| 117 | return string; |
---|
| 118 | } |
---|
| 119 | } // end getStringValue() |
---|
| 120 | |
---|
| 121 | ////////////////////////// |
---|
| 122 | int getPsegId( char* str ) |
---|
| 123 | { |
---|
| 124 | unsigned int pseg_id; |
---|
| 125 | |
---|
| 126 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
| 127 | { |
---|
| 128 | if ( strcmp(pseg[pseg_id]->name, str) == 0 ) return pseg_id; |
---|
| 129 | } |
---|
| 130 | return -1; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | ////////////////////////////////////////// |
---|
| 134 | int getVsegLocId( unsigned int vspace_id, |
---|
| 135 | char* str ) |
---|
| 136 | { |
---|
| 137 | unsigned int vseg_id; |
---|
| 138 | unsigned int vseg_min = vspace[vspace_id]->vseg_offset; |
---|
| 139 | unsigned int vseg_max = vseg_min + vspace[vspace_id]->vsegs; |
---|
| 140 | |
---|
| 141 | for ( vseg_id = vseg_min ; vseg_id < vseg_max ; vseg_id++ ) |
---|
| 142 | { |
---|
| 143 | if ( strcmp(vseg[vseg_id]->name, str) == 0 ) return (vseg_id - vseg_min); |
---|
| 144 | } |
---|
| 145 | return -1; |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | ////////////////////////////////////////// |
---|
| 149 | void taskNode ( xmlTextReaderPtr reader ) |
---|
| 150 | { |
---|
| 151 | unsigned int ok; |
---|
| 152 | unsigned int value; |
---|
| 153 | char* str; |
---|
| 154 | |
---|
| 155 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 156 | |
---|
| 157 | if ( task_index >= MAX_TASKS ) |
---|
| 158 | { |
---|
| 159 | printf("[XML ERROR] The number of tasks is larger than %d\n", MAX_TASKS); |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | #if XML_PARSER_DEBUG |
---|
| 163 | printf(" task %d\n", task_loc_index); |
---|
| 164 | #endif |
---|
| 165 | |
---|
| 166 | task[task_index] = (mapping_task_t*)malloc(sizeof(mapping_task_t)); |
---|
| 167 | |
---|
| 168 | ////////// get name attribute |
---|
| 169 | str = getStringValue(reader, "name", &ok); |
---|
| 170 | if ( ok ) |
---|
| 171 | { |
---|
| 172 | #if XML_PARSER_DEBUG |
---|
| 173 | printf(" name = %s\n", str); |
---|
| 174 | #endif |
---|
| 175 | strncpy( task[task_index]->name, str, 31 ); |
---|
| 176 | } |
---|
| 177 | else |
---|
| 178 | { |
---|
| 179 | printf("[XML ERROR] illegal or missing <name> attribute for task (%d,%d)\n", |
---|
| 180 | vspace_index, task_loc_index); |
---|
| 181 | exit(1); |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | ///////// get clusterid attribute |
---|
| 185 | value = getIntValue(reader,"clusterid", &ok); |
---|
| 186 | if ( ok ) |
---|
| 187 | { |
---|
| 188 | #if XML_PARSER_DEBUG |
---|
| 189 | printf(" clusterid = %x\n", value); |
---|
| 190 | #endif |
---|
| 191 | task[task_index]->clusterid = value; |
---|
| 192 | } |
---|
| 193 | else |
---|
| 194 | { |
---|
| 195 | printf("[XML ERROR] illegal or missing <clusterid> attribute for task (%d,%d)\n", |
---|
| 196 | vspace_index, task_loc_index); |
---|
| 197 | exit(1); |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | ////////// get proclocid attribute |
---|
| 201 | value = getIntValue(reader,"proclocid", &ok); |
---|
| 202 | if ( ok ) |
---|
| 203 | { |
---|
| 204 | #if XML_PARSER_DEBUG |
---|
| 205 | printf(" proclocid = %x\n", value); |
---|
| 206 | #endif |
---|
| 207 | task[task_index]->proclocid = value; |
---|
| 208 | } |
---|
| 209 | else |
---|
| 210 | { |
---|
| 211 | printf("[XML ERROR] illegal or missing <locprocid> attribute for task (%d,%d)\n", |
---|
| 212 | vspace_index, task_loc_index); |
---|
| 213 | exit(1); |
---|
| 214 | } |
---|
| 215 | |
---|
| 216 | ////////// get stackname attribute |
---|
| 217 | str = getStringValue(reader, "stackname" , &ok); |
---|
| 218 | if ( ok ) |
---|
| 219 | { |
---|
| 220 | int index = getVsegLocId( vspace_index, str ); |
---|
| 221 | if ( index >= 0 ) |
---|
| 222 | { |
---|
| 223 | #if XML_PARSER_DEBUG |
---|
| 224 | printf(" stackname = %s\n", str); |
---|
| 225 | printf(" vsegid = %d\n", index); |
---|
| 226 | #endif |
---|
| 227 | task[task_index]->vseglocid = index; |
---|
| 228 | } |
---|
| 229 | else |
---|
| 230 | { |
---|
| 231 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
| 232 | vseg_loc_index); |
---|
| 233 | exit(1); |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | else |
---|
| 237 | { |
---|
| 238 | printf("[XML ERROR] illegal or missing <vsegname> for task (%d,%d)\n", |
---|
| 239 | vspace_index, task_loc_index); |
---|
| 240 | exit(1); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | ////////// get startid attribute |
---|
| 244 | value = getIntValue(reader,"startid", &ok); |
---|
| 245 | if ( ok ) |
---|
| 246 | { |
---|
| 247 | #if XML_PARSER_DEBUG |
---|
| 248 | printf(" startid = %x\n", value); |
---|
| 249 | #endif |
---|
| 250 | task[task_index]->startid = value; |
---|
| 251 | } |
---|
| 252 | else |
---|
| 253 | { |
---|
| 254 | printf("[XML ERROR] illegal or missing <startid> attribute for task (%d,%d)\n", |
---|
| 255 | vspace_index, task_loc_index); |
---|
| 256 | exit(1); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | /////////// get ttylocid attribute |
---|
| 260 | value = getIntValue(reader,"ttylocid", &ok); |
---|
| 261 | if ( ok ) |
---|
| 262 | { |
---|
| 263 | #if XML_PARSER_DEBUG |
---|
| 264 | printf(" ttylocid = %x\n", value); |
---|
| 265 | #endif |
---|
| 266 | if ( value >= vspace[vspace_index]->ttys ) |
---|
| 267 | { |
---|
| 268 | printf("[XML ERROR] The ttylocid value is too large for task (%d,%d)\n", |
---|
| 269 | vspace_index, task_loc_index); |
---|
| 270 | exit(1); |
---|
| 271 | } |
---|
| 272 | task[task_index]->ttylocid = value; |
---|
| 273 | } |
---|
| 274 | else |
---|
| 275 | { |
---|
| 276 | printf("[XML ERROR] illegal or missing <ttylocid> attribute for task (%d,%d)\n", |
---|
| 277 | vspace_index, task_loc_index); |
---|
| 278 | exit(1); |
---|
| 279 | } |
---|
| 280 | |
---|
| 281 | task_index++; |
---|
| 282 | task_loc_index++; |
---|
| 283 | } // end taskNode() |
---|
| 284 | |
---|
| 285 | /////////////////////////////////////////////////////////////// |
---|
| 286 | void vsegNode ( xmlTextReaderPtr reader ) |
---|
| 287 | { |
---|
| 288 | unsigned int ok; |
---|
| 289 | unsigned int value; |
---|
| 290 | char* str; |
---|
| 291 | |
---|
| 292 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 293 | |
---|
| 294 | if ( vseg_index >= MAX_VSEGS ) |
---|
| 295 | { |
---|
| 296 | printf("[XML ERROR] The number of vsegs is larger than %d\n", MAX_VSEGS); |
---|
| 297 | exit(1); |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | #if XML_PARSER_DEBUG |
---|
| 301 | printf(" vseg %d\n", vseg_loc_index); |
---|
| 302 | #endif |
---|
| 303 | |
---|
| 304 | vseg[vseg_index] = (mapping_vseg_t*)malloc(sizeof(mapping_vseg_t)); |
---|
| 305 | |
---|
| 306 | ///////// get name attribute |
---|
| 307 | str = getStringValue(reader, "name", &ok); |
---|
| 308 | if ( ok ) |
---|
| 309 | { |
---|
| 310 | #if XML_PARSER_DEBUG |
---|
| 311 | printf(" name = %s\n", str); |
---|
| 312 | #endif |
---|
| 313 | strncpy( vseg[vseg_index]->name, str, 31); |
---|
| 314 | } |
---|
| 315 | else |
---|
| 316 | { |
---|
| 317 | printf("[XML ERROR] illegal or missing <name> attribute for vseg (%d,%d)\n", |
---|
| 318 | vspace_index, vseg_loc_index); |
---|
| 319 | exit(1); |
---|
| 320 | } |
---|
| 321 | |
---|
| 322 | /////////// get vbase attribute |
---|
| 323 | value = getIntValue(reader,"vbase", &ok); |
---|
| 324 | if ( ok ) |
---|
| 325 | { |
---|
| 326 | #if XML_PARSER_DEBUG |
---|
| 327 | printf(" vbase = 0x%x\n", value); |
---|
| 328 | #endif |
---|
| 329 | vseg[vseg_index]->vbase = value; |
---|
| 330 | } |
---|
| 331 | else |
---|
| 332 | { |
---|
| 333 | printf("[XML ERROR] illegal or missing <vbase> attribute for vseg (%d,%d)\n", |
---|
| 334 | vspace_index, vseg_loc_index); |
---|
| 335 | exit(1); |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | ////////// get length attribute |
---|
| 339 | value = getIntValue(reader,"length", &ok); |
---|
| 340 | if ( ok ) |
---|
| 341 | { |
---|
| 342 | #if XML_PARSER_DEBUG |
---|
| 343 | printf(" length = 0x%x\n", value); |
---|
| 344 | #endif |
---|
| 345 | vseg[vseg_index]->length = value; |
---|
| 346 | } |
---|
| 347 | else |
---|
| 348 | { |
---|
| 349 | printf("[XML ERROR] illegal or missing <length> attribute for vseg (%d,%d)\n", |
---|
| 350 | vspace_index, vseg_loc_index); |
---|
| 351 | exit(1); |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | ////////// get ident attribute (0 if missing) |
---|
| 355 | value = getIntValue(reader,"ident", &ok); |
---|
| 356 | if ( ok ) |
---|
| 357 | { |
---|
| 358 | #if XML_PARSER_DEBUG |
---|
| 359 | printf(" ident = %d\n", value); |
---|
| 360 | #endif |
---|
| 361 | vseg[vseg_index]->ident = value; |
---|
| 362 | } |
---|
| 363 | else |
---|
| 364 | { |
---|
| 365 | vseg[vseg_index]->ident = 0; |
---|
| 366 | } |
---|
| 367 | |
---|
| 368 | ////////// get mwmr attribute (0 if missing) |
---|
| 369 | value = getIntValue(reader,"mwmr", &ok); |
---|
| 370 | if ( ok ) |
---|
| 371 | { |
---|
| 372 | #if XML_PARSER_DEBUG |
---|
| 373 | printf(" mwmr = %d\n", value); |
---|
| 374 | #endif |
---|
| 375 | vseg[vseg_index]->mwmr = value; |
---|
| 376 | if ( value ) |
---|
| 377 | { |
---|
| 378 | mwmr_index++; |
---|
| 379 | mwmr_loc_index++; |
---|
| 380 | } |
---|
| 381 | } |
---|
| 382 | else |
---|
| 383 | { |
---|
| 384 | vseg[vseg_index]->mwmr = 0; |
---|
| 385 | } |
---|
| 386 | |
---|
| 387 | ////////// get psegname attribute |
---|
| 388 | str = getStringValue(reader,"psegname", &ok); |
---|
| 389 | if ( ok ) |
---|
| 390 | { |
---|
| 391 | int index = getPsegId( str ); |
---|
| 392 | if ( index >= 0 ) |
---|
| 393 | { |
---|
| 394 | #if XML_PARSER_DEBUG |
---|
| 395 | printf(" psegname = %s\n", str); |
---|
| 396 | printf(" psegid = %d\n", index); |
---|
| 397 | #endif |
---|
| 398 | vseg[vseg_index]->psegid = index; |
---|
| 399 | } |
---|
| 400 | else |
---|
| 401 | { |
---|
| 402 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
| 403 | vseg_loc_index); |
---|
| 404 | exit(1); |
---|
| 405 | } |
---|
| 406 | } |
---|
| 407 | else |
---|
| 408 | { |
---|
| 409 | printf("[XML ERROR] illegal or missing <psegname> for vseg %d\n", |
---|
| 410 | vseg_loc_index); |
---|
| 411 | exit(1); |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | // get mode attribute |
---|
| 415 | str = getStringValue(reader,"mode", &ok); |
---|
| 416 | #if XML_PARSER_DEBUG |
---|
| 417 | printf(" mode = %s\n", str); |
---|
| 418 | #endif |
---|
| 419 | if (ok && (strcmp(str, "CXWU") == 0)) vseg[vseg_index]->mode = 0xF; |
---|
| 420 | else if (ok && (strcmp(str, "CXW_") == 0)) vseg[vseg_index]->mode = 0xE; |
---|
| 421 | else if (ok && (strcmp(str, "CX_U") == 0)) vseg[vseg_index]->mode = 0xD; |
---|
| 422 | else if (ok && (strcmp(str, "CX__") == 0)) vseg[vseg_index]->mode = 0xC; |
---|
| 423 | else if (ok && (strcmp(str, "C_WU") == 0)) vseg[vseg_index]->mode = 0xB; |
---|
| 424 | else if (ok && (strcmp(str, "C_W_") == 0)) vseg[vseg_index]->mode = 0xA; |
---|
| 425 | else if (ok && (strcmp(str, "C__U") == 0)) vseg[vseg_index]->mode = 0x9; |
---|
| 426 | else if (ok && (strcmp(str, "C___") == 0)) vseg[vseg_index]->mode = 0x8; |
---|
| 427 | else if (ok && (strcmp(str, "_XWU") == 0)) vseg[vseg_index]->mode = 0x7; |
---|
| 428 | else if (ok && (strcmp(str, "_XW_") == 0)) vseg[vseg_index]->mode = 0x6; |
---|
| 429 | else if (ok && (strcmp(str, "_X_U") == 0)) vseg[vseg_index]->mode = 0x5; |
---|
| 430 | else if (ok && (strcmp(str, "_X__") == 0)) vseg[vseg_index]->mode = 0x4; |
---|
| 431 | else if (ok && (strcmp(str, "__WU") == 0)) vseg[vseg_index]->mode = 0x3; |
---|
| 432 | else if (ok && (strcmp(str, "__W_") == 0)) vseg[vseg_index]->mode = 0x2; |
---|
| 433 | else if (ok && (strcmp(str, "___U") == 0)) vseg[vseg_index]->mode = 0x1; |
---|
| 434 | else if (ok && (strcmp(str, "____") == 0)) vseg[vseg_index]->mode = 0x0; |
---|
| 435 | else |
---|
| 436 | { |
---|
| 437 | printf("[XML ERROR] illegal or missing <mode> attribute for vseg (%d,%d)\n", |
---|
| 438 | vspace_index, vseg_loc_index); |
---|
| 439 | exit(1); |
---|
| 440 | } |
---|
| 441 | |
---|
| 442 | vseg_index++; |
---|
| 443 | vseg_loc_index++; |
---|
| 444 | } // end vsegNode() |
---|
| 445 | |
---|
| 446 | ////////////////////////////////////////// |
---|
| 447 | void vspaceNode( xmlTextReaderPtr reader ) |
---|
| 448 | { |
---|
| 449 | char* str; |
---|
| 450 | unsigned int ok; |
---|
| 451 | unsigned int value; |
---|
| 452 | |
---|
| 453 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 454 | |
---|
| 455 | // checking source file consistency |
---|
| 456 | if ( vspace_index >= header->vspaces ) |
---|
| 457 | { |
---|
| 458 | printf("[XML ERROR] The vspace index is too large : %d\n", |
---|
| 459 | vspace_index); |
---|
| 460 | exit(1); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | #if XML_PARSER_DEBUG |
---|
| 464 | printf(" vspace %d\n", vspace_index); |
---|
| 465 | #endif |
---|
| 466 | |
---|
| 467 | vspace[vspace_index] = (mapping_vspace_t*)malloc(sizeof(mapping_vspace_t)); |
---|
| 468 | |
---|
| 469 | ////////// set vseg_offset and task_offset attributes |
---|
| 470 | vspace[vspace_index]->vseg_offset = vseg_index; |
---|
| 471 | vspace[vspace_index]->task_offset = task_index; |
---|
| 472 | |
---|
| 473 | #if XML_PARSER_DEBUG |
---|
| 474 | printf("- vseg_offset = %d\n", vseg_index); |
---|
| 475 | printf("- task_offset = %d\n", task_index); |
---|
| 476 | #endif |
---|
| 477 | |
---|
| 478 | ////////// get name attribute |
---|
| 479 | str = getStringValue(reader, "name", &ok); |
---|
| 480 | if ( ok ) |
---|
| 481 | { |
---|
| 482 | #if XML_PARSER_DEBUG |
---|
| 483 | printf(" name = %s\n", str); |
---|
| 484 | #endif |
---|
| 485 | strncpy(vspace[vspace_index]->name, str, 31); |
---|
| 486 | } |
---|
| 487 | else |
---|
| 488 | { |
---|
| 489 | printf("[XML ERROR] illegal or missing <name> attribute for vspace %d", |
---|
| 490 | vspace_index); |
---|
| 491 | exit(1); |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | /////////// get binpath attribute |
---|
| 495 | str = getStringValue(reader, "binpath", &ok); |
---|
| 496 | if ( ok ) |
---|
| 497 | { |
---|
| 498 | #if XML_PARSER_DEBUG |
---|
| 499 | printf(" binpath = %s\n", str); |
---|
| 500 | #endif |
---|
| 501 | strncpy(vspace[vspace_index]->binpath, str, 63); |
---|
| 502 | } |
---|
| 503 | else |
---|
| 504 | { |
---|
| 505 | printf("[XML ERROR] illegal or missing <binpath> attribute for vspace %d", |
---|
| 506 | vspace_index); |
---|
| 507 | exit(1); |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | ////////// get vsegs attribute |
---|
| 511 | value = getIntValue(reader,"vsegs",&ok); |
---|
| 512 | if ( ok ) |
---|
| 513 | { |
---|
| 514 | #if XML_PARSER_DEBUG |
---|
| 515 | printf(" vsegs = %d\n", value); |
---|
| 516 | #endif |
---|
| 517 | vspace[vspace_index]->vsegs = value; |
---|
| 518 | } |
---|
| 519 | else |
---|
| 520 | { |
---|
| 521 | printf("[XML ERROR] illegal or missing <vsegs> attribute for vspace %d", |
---|
| 522 | vspace_index); |
---|
| 523 | exit(1); |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | // get tasks attribute |
---|
| 527 | value = getIntValue(reader,"tasks", &ok); |
---|
| 528 | if ( ok ) |
---|
| 529 | { |
---|
| 530 | #if XML_PARSER_DEBUG |
---|
| 531 | printf(" tasks = %d\n", value); |
---|
| 532 | #endif |
---|
| 533 | vspace[vspace_index]->tasks = value; |
---|
| 534 | } |
---|
| 535 | else |
---|
| 536 | { |
---|
| 537 | printf("[XML ERROR] illegal or missing <tasks> attribute for vspace %d", |
---|
| 538 | vspace_index); |
---|
| 539 | exit(1); |
---|
| 540 | } |
---|
| 541 | |
---|
| 542 | // get mwmrs attribute |
---|
| 543 | value = getIntValue(reader,"mwmrs", &ok); |
---|
| 544 | if ( ok ) |
---|
| 545 | { |
---|
| 546 | #if XML_PARSER_DEBUG |
---|
| 547 | printf(" mwmrs = %d\n", value); |
---|
| 548 | #endif |
---|
| 549 | vspace[vspace_index]->mwmrs = value; |
---|
| 550 | } |
---|
| 551 | else |
---|
| 552 | { |
---|
| 553 | vspace[vspace_index]->mwmrs = 0; |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | // get ttys attribute |
---|
| 557 | value = getIntValue(reader,"ttys", &ok); |
---|
| 558 | #if XML_PARSER_DEBUG |
---|
| 559 | printf(" ttys = %d\n", value); |
---|
| 560 | #endif |
---|
| 561 | if ( ok ) |
---|
| 562 | { |
---|
| 563 | vspace[vspace_index]->ttys = value; |
---|
| 564 | } |
---|
| 565 | else |
---|
| 566 | { |
---|
| 567 | printf("[XML ERROR] illegal or missing <ttys> attribute for vspace %d", |
---|
| 568 | vspace_index); |
---|
| 569 | exit(1); |
---|
| 570 | } |
---|
| 571 | |
---|
| 572 | int status = xmlTextReaderRead ( reader ); |
---|
| 573 | while ( status == 1 ) |
---|
| 574 | { |
---|
| 575 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 576 | |
---|
| 577 | if ( strcmp(tag,"vseg") == 0 ) vsegNode(reader); |
---|
| 578 | else if ( strcmp(tag,"task") == 0 ) taskNode(reader); |
---|
| 579 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
| 580 | else if ( strcmp(tag,"vspace") == 0 ) |
---|
| 581 | { |
---|
| 582 | // checking source file consistency |
---|
| 583 | if ( vseg_loc_index != vspace[vspace_index]->vsegs ) |
---|
| 584 | { |
---|
| 585 | printf("[XML ERROR] Wrong number of vsegs in vspace %d\n", vspace_index); |
---|
| 586 | exit(1); |
---|
| 587 | } |
---|
| 588 | else if ( task_loc_index != vspace[vspace_index]->tasks ) |
---|
| 589 | { |
---|
| 590 | printf("[XML ERROR] Wrong number of tasks in vspace %d\n", vspace_index); |
---|
| 591 | exit(1); |
---|
| 592 | } |
---|
| 593 | else if ( mwmr_loc_index != vspace[vspace_index]->mwmrs ) |
---|
| 594 | { |
---|
| 595 | printf("[XML ERROR] Wrong number of mwmrs in vspace %d\n", vspace_index); |
---|
| 596 | exit(1); |
---|
| 597 | } |
---|
| 598 | else |
---|
| 599 | { |
---|
| 600 | vseg_loc_index = 0; |
---|
| 601 | task_loc_index = 0; |
---|
| 602 | mwmr_loc_index = 0; |
---|
| 603 | vspace_index++; |
---|
| 604 | return; |
---|
| 605 | } |
---|
| 606 | } |
---|
| 607 | else |
---|
| 608 | { |
---|
| 609 | printf("[XML ERROR] Unknown tag %s",tag); |
---|
| 610 | exit(1); |
---|
| 611 | } |
---|
| 612 | status = xmlTextReaderRead ( reader ); |
---|
| 613 | } |
---|
| 614 | } // end vspaceNode() |
---|
| 615 | |
---|
| 616 | ////////////////////////////////////////// |
---|
| 617 | void psegNode ( xmlTextReaderPtr reader ) |
---|
| 618 | { |
---|
| 619 | unsigned int ok; |
---|
| 620 | unsigned int value; |
---|
| 621 | char* str; |
---|
| 622 | |
---|
| 623 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 624 | |
---|
| 625 | if ( pseg_index >= MAX_PSEGS ) |
---|
| 626 | { |
---|
| 627 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
| 628 | exit(1); |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | #if XML_PARSER_DEBUG |
---|
| 632 | printf(" pseg %d\n", pseg_index); |
---|
| 633 | #endif |
---|
| 634 | |
---|
| 635 | pseg[pseg_index] = (mapping_pseg_t*)malloc(sizeof(mapping_pseg_t)); |
---|
| 636 | |
---|
| 637 | // get name attribute |
---|
| 638 | str = getStringValue( reader, "name", &ok ); |
---|
| 639 | #if XML_PARSER_DEBUG |
---|
| 640 | printf(" - name = %s\n", str); |
---|
| 641 | #endif |
---|
| 642 | if ( ok ) |
---|
| 643 | { |
---|
| 644 | strncpy(pseg[pseg_index]->name, str, 31); |
---|
| 645 | } |
---|
| 646 | else |
---|
| 647 | { |
---|
| 648 | printf("[XML ERROR] illegal or missing <name> for pseg %d\n", pseg_index); |
---|
| 649 | exit(1); |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | // get base attribute |
---|
| 653 | value = getIntValue( reader, "base", &ok ); |
---|
| 654 | #if XML_PARSER_DEBUG |
---|
| 655 | printf(" - base = %x\n", value); |
---|
| 656 | #endif |
---|
| 657 | if ( ok ) |
---|
| 658 | { |
---|
| 659 | pseg[pseg_index]->base = value; |
---|
| 660 | } |
---|
| 661 | else |
---|
| 662 | { |
---|
| 663 | printf("[XML ERROR] illegal or missing <base> for pseg %d\n", pseg_index); |
---|
| 664 | exit(1); |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | // get length attribute |
---|
| 668 | value = getIntValue( reader, "length", &ok ); |
---|
| 669 | #if XML_PARSER_DEBUG |
---|
| 670 | printf(" - length = %x\n\n", value); |
---|
| 671 | #endif |
---|
| 672 | if ( ok ) |
---|
| 673 | { |
---|
| 674 | pseg[pseg_index]->length = value; |
---|
| 675 | } |
---|
| 676 | else |
---|
| 677 | { |
---|
| 678 | printf("[XML ERROR] illegal or missing <length> for pseg %d\n", pseg_index); |
---|
| 679 | exit(1); |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | pseg[pseg_index]->next_free_page = 0; |
---|
| 683 | pseg_index++; |
---|
| 684 | } // end psegNode() |
---|
| 685 | |
---|
| 686 | ///////////////////////////////////////////// |
---|
| 687 | void clusterNode ( xmlTextReaderPtr reader ) |
---|
| 688 | { |
---|
| 689 | unsigned int ok; |
---|
| 690 | unsigned int value; |
---|
| 691 | |
---|
| 692 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 693 | |
---|
| 694 | // checking source file consistency |
---|
| 695 | if ( cluster_index >= header->clusters ) |
---|
| 696 | { |
---|
| 697 | printf("[XML ERROR] The cluster index is too large : %d\n", cluster_index); |
---|
| 698 | exit(1); |
---|
| 699 | } |
---|
| 700 | |
---|
| 701 | #if XML_PARSER_DEBUG |
---|
| 702 | printf(" cluster %d :\n", cluster_index); |
---|
| 703 | #endif |
---|
| 704 | |
---|
| 705 | cluster[cluster_index] = (mapping_cluster_t*)malloc(sizeof(mapping_cluster_t)); |
---|
| 706 | |
---|
| 707 | // get procs attribute |
---|
| 708 | value = getIntValue(reader,"procs",&ok); |
---|
| 709 | #if XML_PARSER_DEBUG |
---|
| 710 | printf(" - procs = %d\n", value); |
---|
| 711 | #endif |
---|
| 712 | if ( ok ) |
---|
| 713 | { |
---|
| 714 | cluster[cluster_index]->procs = value; |
---|
| 715 | } |
---|
| 716 | else |
---|
| 717 | { |
---|
| 718 | printf("[XML ERROR] illegal or missing <procs> attribute for cluster %d", |
---|
| 719 | cluster_index); |
---|
| 720 | exit(1); |
---|
| 721 | } |
---|
| 722 | |
---|
| 723 | // get timers attribute |
---|
| 724 | value = getIntValue(reader,"timers",&ok); |
---|
| 725 | #if XML_PARSER_DEBUG |
---|
| 726 | printf(" - timers = %d\n", value); |
---|
| 727 | #endif |
---|
| 728 | if ( ok ) |
---|
| 729 | { |
---|
| 730 | cluster[cluster_index]->timers = value; |
---|
| 731 | } |
---|
| 732 | else |
---|
| 733 | { |
---|
| 734 | printf("[XML ERROR] illegal or missing <timers> attribute for cluster %d", |
---|
| 735 | cluster_index); |
---|
| 736 | exit(1); |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | // get dmas attribute |
---|
| 740 | value = getIntValue(reader,"dmas",&ok); |
---|
| 741 | #if XML_PARSER_DEBUG |
---|
| 742 | printf(" - dmas = %d\n\n", value); |
---|
| 743 | #endif |
---|
| 744 | if ( ok ) |
---|
| 745 | { |
---|
| 746 | cluster[cluster_index]->dmas = value; |
---|
| 747 | } |
---|
| 748 | else |
---|
| 749 | { |
---|
| 750 | printf("[XML ERROR] illegal or missing <dmas> attribute for cluster %d", |
---|
| 751 | cluster_index); |
---|
| 752 | exit(1); |
---|
| 753 | } |
---|
| 754 | |
---|
| 755 | cluster_index++; |
---|
| 756 | } // end clusterNode() |
---|
| 757 | |
---|
| 758 | ////////////////////////////////////////////// |
---|
| 759 | void clusterSetNode( xmlTextReaderPtr reader ) |
---|
| 760 | { |
---|
| 761 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 762 | |
---|
| 763 | #if XML_PARSER_DEBUG |
---|
| 764 | printf(" clusters set\n"); |
---|
| 765 | #endif |
---|
| 766 | |
---|
| 767 | int status = xmlTextReaderRead ( reader ); |
---|
| 768 | while ( status == 1 ) |
---|
| 769 | { |
---|
| 770 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 771 | |
---|
| 772 | if ( strcmp(tag,"cluster") == 0 ) clusterNode(reader); |
---|
| 773 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
| 774 | else if ( strcmp(tag,"clusterset") == 0 ) |
---|
| 775 | { |
---|
| 776 | // checking source file consistency |
---|
| 777 | if ( cluster_index != header->clusters ) |
---|
| 778 | { |
---|
| 779 | printf("[XML ERROR] Wrong number of clusters\n"); |
---|
| 780 | exit(1); |
---|
| 781 | } |
---|
| 782 | else |
---|
| 783 | { |
---|
| 784 | return; |
---|
| 785 | } |
---|
| 786 | } |
---|
| 787 | else |
---|
| 788 | { |
---|
| 789 | printf("[XML ERROR] Unknown tag in clusterset node : %s",tag); |
---|
| 790 | exit(1); |
---|
| 791 | } |
---|
| 792 | status = xmlTextReaderRead ( reader ); |
---|
| 793 | } |
---|
| 794 | } // end clusterSetNode() |
---|
| 795 | |
---|
| 796 | /////////////////////////////////////////// |
---|
| 797 | void psegSetNode( xmlTextReaderPtr reader ) |
---|
| 798 | { |
---|
| 799 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 800 | |
---|
| 801 | #if XML_PARSER_DEBUG |
---|
| 802 | printf(" psegs set\n"); |
---|
| 803 | #endif |
---|
| 804 | |
---|
| 805 | int status = xmlTextReaderRead ( reader ); |
---|
| 806 | while ( status == 1 ) |
---|
| 807 | { |
---|
| 808 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 809 | |
---|
| 810 | if ( strcmp(tag,"pseg") == 0 ) psegNode(reader); |
---|
| 811 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
| 812 | else if ( strcmp(tag,"psegset") == 0 ) |
---|
| 813 | { |
---|
| 814 | // checking source file consistency |
---|
| 815 | if ( pseg_index != header->psegs ) |
---|
| 816 | { |
---|
| 817 | printf("[XML ERROR] Wrong number of psegs\n"); |
---|
| 818 | exit(1); |
---|
| 819 | } |
---|
| 820 | else |
---|
| 821 | { |
---|
| 822 | return; |
---|
| 823 | } |
---|
| 824 | } |
---|
| 825 | else |
---|
| 826 | { |
---|
| 827 | printf("[XML ERROR] Unknown tag in psegset node : %s",tag); |
---|
| 828 | exit(1); |
---|
| 829 | } |
---|
| 830 | status = xmlTextReaderRead ( reader ); |
---|
| 831 | } |
---|
| 832 | } // end psegSetNode() |
---|
| 833 | |
---|
| 834 | ///////////////////////////////////////////// |
---|
| 835 | void globalSetNode( xmlTextReaderPtr reader ) |
---|
| 836 | { |
---|
| 837 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 838 | |
---|
| 839 | #if XML_PARSER_DEBUG |
---|
| 840 | printf(" global vsegs set\n"); |
---|
| 841 | #endif |
---|
| 842 | |
---|
| 843 | int status = xmlTextReaderRead ( reader ); |
---|
| 844 | while ( status == 1 ) |
---|
| 845 | { |
---|
| 846 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 847 | |
---|
| 848 | if ( strcmp(tag,"vseg") == 0 ) vsegNode(reader); |
---|
| 849 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
| 850 | else if ( strcmp(tag,"globalset") == 0 ) |
---|
| 851 | { |
---|
| 852 | // checking source file consistency |
---|
| 853 | if ( vseg_index != header->globals ) |
---|
| 854 | { |
---|
| 855 | printf("[XML ERROR] Wrong number of global vsegs\n"); |
---|
| 856 | exit(1); |
---|
| 857 | } |
---|
| 858 | else |
---|
| 859 | { |
---|
| 860 | vseg_loc_index = 0; |
---|
| 861 | return; |
---|
| 862 | } |
---|
| 863 | } |
---|
| 864 | else |
---|
| 865 | { |
---|
| 866 | printf("[XML ERROR] Unknown tag in globalset node : %s",tag); |
---|
| 867 | exit(1); |
---|
| 868 | } |
---|
| 869 | status = xmlTextReaderRead ( reader ); |
---|
| 870 | } |
---|
| 871 | } // end globalSetNode() |
---|
| 872 | |
---|
| 873 | ///////////////////////////////////////////// |
---|
| 874 | void vspaceSetNode( xmlTextReaderPtr reader ) |
---|
| 875 | { |
---|
| 876 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 877 | |
---|
| 878 | #if XML_PARSER_DEBUG |
---|
| 879 | printf(" vspaces set\n"); |
---|
| 880 | #endif |
---|
| 881 | |
---|
| 882 | int status = xmlTextReaderRead ( reader ); |
---|
| 883 | while ( status == 1 ) |
---|
| 884 | { |
---|
| 885 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 886 | |
---|
| 887 | if ( strcmp(tag,"vspace") == 0 ) vspaceNode(reader); |
---|
| 888 | else if ( strcmp(tag,"#text" ) == 0 ) { } |
---|
| 889 | else if ( strcmp(tag,"vspaceset") == 0 ) |
---|
| 890 | { |
---|
| 891 | // checking source file consistency |
---|
| 892 | if ( vspace_index != header->vspaces ) |
---|
| 893 | { |
---|
| 894 | printf("[XML ERROR] Wrong number of vspaces\n"); |
---|
| 895 | exit(1); |
---|
| 896 | } |
---|
| 897 | else |
---|
| 898 | { |
---|
| 899 | header->vsegs = vseg_index; |
---|
| 900 | header->tasks = task_index; |
---|
| 901 | return; |
---|
| 902 | } |
---|
| 903 | } |
---|
| 904 | else |
---|
| 905 | { |
---|
| 906 | printf("[XML ERROR] Unknown tag in vspaceset node : %s",tag); |
---|
| 907 | exit(1); |
---|
| 908 | } |
---|
| 909 | status = xmlTextReaderRead ( reader ); |
---|
| 910 | } |
---|
| 911 | } // end globalSetNode() |
---|
| 912 | |
---|
| 913 | ////////////////////////////////////////// |
---|
| 914 | void headerNode(xmlTextReaderPtr reader ) |
---|
| 915 | { |
---|
| 916 | char* name; |
---|
| 917 | unsigned int value; |
---|
| 918 | unsigned int ok; |
---|
| 919 | |
---|
| 920 | if ( xmlTextReaderNodeType(reader) == XML_READER_TYPE_END_ELEMENT ) return; |
---|
| 921 | |
---|
| 922 | #if XML_PARSER_DEBUG |
---|
| 923 | printf("mapping_info\n"); |
---|
| 924 | #endif |
---|
| 925 | |
---|
| 926 | header = (mapping_header_t*)malloc(sizeof(mapping_header_t)); |
---|
| 927 | |
---|
| 928 | // get name attribute |
---|
| 929 | name = getStringValue(reader, "name", &ok); |
---|
| 930 | if ( ok ) |
---|
| 931 | { |
---|
| 932 | #if XML_PARSER_DEBUG |
---|
| 933 | printf("- name = %s\n", name); |
---|
| 934 | #endif |
---|
| 935 | strncpy( header->name, name, 31); |
---|
| 936 | } |
---|
| 937 | else |
---|
| 938 | { |
---|
| 939 | printf("[XML ERROR] illegal or missing <name> attribute in header\n"); |
---|
| 940 | exit(1); |
---|
| 941 | } |
---|
| 942 | |
---|
| 943 | // get clusters attribute |
---|
| 944 | value = getIntValue(reader, "clusters", &ok); |
---|
| 945 | if ( ok ) |
---|
| 946 | { |
---|
| 947 | if ( value >= MAX_CLUSTERS ) |
---|
| 948 | { |
---|
| 949 | printf("[XML ERROR] The number of clusters is larger than %d\n", MAX_CLUSTERS); |
---|
| 950 | exit(1); |
---|
| 951 | } |
---|
| 952 | #if XML_PARSER_DEBUG |
---|
| 953 | printf("- clusters = %d\n", value); |
---|
| 954 | #endif |
---|
| 955 | header->clusters = value; |
---|
| 956 | } |
---|
| 957 | else |
---|
| 958 | { |
---|
| 959 | printf("[XML ERROR] illegal or missing <clusters> attribute in header\n"); |
---|
| 960 | exit(1); |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | // get psegs attribute |
---|
| 964 | value = getIntValue(reader, "psegs", &ok); |
---|
| 965 | if ( ok ) |
---|
| 966 | { |
---|
| 967 | if ( value >= MAX_PSEGS ) |
---|
| 968 | { |
---|
| 969 | printf("[XML ERROR] The number of psegs is larger than %d\n", MAX_PSEGS); |
---|
| 970 | exit(1); |
---|
| 971 | } |
---|
| 972 | #if XML_PARSER_DEBUG |
---|
| 973 | printf("- psegs = %d\n", value); |
---|
| 974 | #endif |
---|
| 975 | header->psegs = value; |
---|
| 976 | } |
---|
| 977 | else |
---|
| 978 | { |
---|
| 979 | printf("[XML ERROR] illegal or missing <psegs> attribute in header\n"); |
---|
| 980 | exit(1); |
---|
| 981 | } |
---|
| 982 | |
---|
| 983 | // get ttys attribute |
---|
| 984 | value = getIntValue(reader, "ttys", &ok); |
---|
| 985 | if ( ok ) |
---|
| 986 | { |
---|
| 987 | #if XML_PARSER_DEBUG |
---|
| 988 | printf("- ttys = %d\n", value); |
---|
| 989 | #endif |
---|
| 990 | header->ttys = value; |
---|
| 991 | } |
---|
| 992 | else |
---|
| 993 | { |
---|
| 994 | printf("[XML ERROR] illegal or missing <ttys> attribute in header\n"); |
---|
| 995 | exit(1); |
---|
| 996 | } |
---|
| 997 | |
---|
| 998 | // get vspaces attribute |
---|
| 999 | value = getIntValue(reader, "vspaces", &ok); |
---|
| 1000 | if ( ok ) |
---|
| 1001 | { |
---|
| 1002 | if ( value >= MAX_VSPACES ) |
---|
| 1003 | { |
---|
| 1004 | printf("[XML ERROR] The number of vspaces is larger than %d\n", MAX_VSPACES); |
---|
| 1005 | exit(1); |
---|
| 1006 | } |
---|
| 1007 | #if XML_PARSER_DEBUG |
---|
| 1008 | printf("- vspaces = %d\n", value); |
---|
| 1009 | #endif |
---|
| 1010 | header->vspaces = value; |
---|
| 1011 | } |
---|
| 1012 | else |
---|
| 1013 | { |
---|
| 1014 | printf("[XML ERROR] illegal or missing <vspaces> attribute in mapping\n"); |
---|
| 1015 | exit(1); |
---|
| 1016 | } |
---|
| 1017 | |
---|
| 1018 | // get globals attribute |
---|
| 1019 | value = getIntValue(reader, "globals", &ok); |
---|
| 1020 | if ( ok ) |
---|
| 1021 | { |
---|
| 1022 | if ( value >= MAX_VSEGS ) |
---|
| 1023 | { |
---|
| 1024 | printf("[XML ERROR] The number of globals is larger than %d\n", MAX_VSEGS); |
---|
| 1025 | exit(1); |
---|
| 1026 | } |
---|
| 1027 | #if XML_PARSER_DEBUG |
---|
| 1028 | printf("- globals = %d\n", value); |
---|
| 1029 | #endif |
---|
| 1030 | header->globals = value; |
---|
| 1031 | } |
---|
| 1032 | else |
---|
| 1033 | { |
---|
| 1034 | printf("[XML ERROR] illegal or missing <globals> attribute in mapping_info_header\n"); |
---|
| 1035 | exit(1); |
---|
| 1036 | } |
---|
| 1037 | |
---|
| 1038 | // get syspath attribute |
---|
| 1039 | name = getStringValue(reader, "syspath", &ok); |
---|
| 1040 | if ( ok ) |
---|
| 1041 | { |
---|
| 1042 | #if XML_PARSER_DEBUG |
---|
| 1043 | printf("- syspath = %s\n\n", name); |
---|
| 1044 | #endif |
---|
| 1045 | strncpy( header->syspath, name, 63); |
---|
| 1046 | } |
---|
| 1047 | else |
---|
| 1048 | { |
---|
| 1049 | printf("[XML ERROR] illegal or missing <syspath> attribute in header\n"); |
---|
| 1050 | exit(1); |
---|
| 1051 | } |
---|
| 1052 | |
---|
| 1053 | header->signature = IN_MAPPING_SIGNATURE; |
---|
| 1054 | |
---|
| 1055 | int status = xmlTextReaderRead ( reader ); |
---|
| 1056 | while ( status == 1 ) |
---|
| 1057 | { |
---|
| 1058 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1059 | |
---|
| 1060 | if ( strcmp(tag,"clusterset") == 0 ) clusterSetNode(reader); |
---|
| 1061 | else if ( strcmp(tag,"psegset") == 0 ) psegSetNode(reader); |
---|
| 1062 | else if ( strcmp(tag,"globalset") == 0 ) globalSetNode(reader); |
---|
| 1063 | else if ( strcmp(tag,"vspaceset") == 0 ) vspaceSetNode(reader); |
---|
| 1064 | else if ( strcmp(tag,"#text") == 0 ) { } |
---|
| 1065 | else if ( strcmp(tag,"mapping_info") == 0 ) |
---|
| 1066 | { |
---|
| 1067 | #if XML_PARSER_DEBUG |
---|
| 1068 | printf("end mapping_info\n"); |
---|
| 1069 | #endif |
---|
| 1070 | return; |
---|
| 1071 | } |
---|
| 1072 | else |
---|
| 1073 | { |
---|
| 1074 | printf("[XML ERROR] Unknown tag in header node : %s",tag); |
---|
| 1075 | exit(1); |
---|
| 1076 | } |
---|
| 1077 | status = xmlTextReaderRead ( reader ); |
---|
| 1078 | } |
---|
| 1079 | } // end headerNode() |
---|
| 1080 | |
---|
| 1081 | /////////////////////////// |
---|
| 1082 | void buildBin( int fdout ) |
---|
| 1083 | { |
---|
| 1084 | unsigned int cluster_id; |
---|
| 1085 | unsigned int pseg_id; |
---|
| 1086 | unsigned int vspace_id; |
---|
| 1087 | unsigned int vseg_id; |
---|
| 1088 | unsigned int task_id; |
---|
| 1089 | |
---|
| 1090 | unsigned int length; |
---|
| 1091 | |
---|
| 1092 | // write header to binary file |
---|
| 1093 | length = write(fdout, (char*)header, sizeof(mapping_header_t)); |
---|
| 1094 | |
---|
| 1095 | #if XML_PARSER_DEBUG |
---|
| 1096 | printf("\n*** write header\n"); |
---|
| 1097 | #endif |
---|
| 1098 | |
---|
| 1099 | if ( length != sizeof(mapping_header_t) ) |
---|
| 1100 | { |
---|
| 1101 | perror("write header"); |
---|
| 1102 | exit(1); |
---|
| 1103 | } |
---|
| 1104 | |
---|
| 1105 | // write clusters |
---|
| 1106 | for ( cluster_id = 0 ; cluster_id < header->clusters ; cluster_id++ ) |
---|
| 1107 | { |
---|
| 1108 | length = write(fdout, (char*)cluster[cluster_id], sizeof(mapping_cluster_t)); |
---|
| 1109 | |
---|
| 1110 | #if XML_PARSER_DEBUG |
---|
| 1111 | printf("\n*** write cluster %d\n", cluster_id); |
---|
| 1112 | #endif |
---|
| 1113 | |
---|
| 1114 | if ( length != sizeof(mapping_cluster_t) ) |
---|
| 1115 | { |
---|
| 1116 | perror("write cluster"); |
---|
| 1117 | exit(1); |
---|
| 1118 | } |
---|
| 1119 | } |
---|
| 1120 | |
---|
| 1121 | // write psegs |
---|
| 1122 | for ( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
| 1123 | { |
---|
| 1124 | length = write(fdout, (char*)pseg[pseg_id], sizeof(mapping_pseg_t)); |
---|
| 1125 | |
---|
| 1126 | #if XML_PARSER_DEBUG |
---|
| 1127 | printf("write pseg %d\n", pseg_id); |
---|
| 1128 | #endif |
---|
| 1129 | |
---|
| 1130 | if ( length != sizeof(mapping_pseg_t) ) |
---|
| 1131 | { |
---|
| 1132 | perror("write pseg"); |
---|
| 1133 | exit(1); |
---|
| 1134 | } |
---|
| 1135 | } |
---|
| 1136 | |
---|
| 1137 | // write vspaces |
---|
| 1138 | for ( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
| 1139 | { |
---|
| 1140 | length = write(fdout, (char*)vspace[vspace_id], sizeof(mapping_vspace_t)); |
---|
| 1141 | |
---|
| 1142 | #if XML_PARSER_DEBUG |
---|
| 1143 | printf("write vspace %d\n", vspace_id); |
---|
| 1144 | #endif |
---|
| 1145 | |
---|
| 1146 | if ( length != sizeof(mapping_vspace_t) ) |
---|
| 1147 | { |
---|
| 1148 | perror("write vspace"); |
---|
| 1149 | exit(1); |
---|
| 1150 | } |
---|
| 1151 | } |
---|
| 1152 | |
---|
| 1153 | // write vsegs |
---|
| 1154 | for ( vseg_id = 0 ; vseg_id < header->vsegs ; vseg_id++ ) |
---|
| 1155 | { |
---|
| 1156 | length = write(fdout, (char*)vseg[vseg_id], sizeof(mapping_vseg_t)); |
---|
| 1157 | |
---|
| 1158 | #if XML_PARSER_DEBUG |
---|
| 1159 | printf("write vseg %d\n", vseg_id); |
---|
| 1160 | #endif |
---|
| 1161 | |
---|
| 1162 | if ( length != sizeof(mapping_vseg_t) ) |
---|
| 1163 | { |
---|
| 1164 | perror("write vseg"); |
---|
| 1165 | exit(1); |
---|
| 1166 | } |
---|
| 1167 | } |
---|
| 1168 | |
---|
| 1169 | // write tasks |
---|
| 1170 | for ( task_id = 0 ; task_id < header->tasks ; task_id++ ) |
---|
| 1171 | { |
---|
| 1172 | length = write(fdout, (char*)task[task_id], sizeof(mapping_task_t)); |
---|
| 1173 | |
---|
| 1174 | #if XML_PARSER_DEBUG |
---|
| 1175 | printf("write task %d\n", task_id); |
---|
| 1176 | #endif |
---|
| 1177 | |
---|
| 1178 | if ( length != sizeof(mapping_task_t) ) |
---|
| 1179 | { |
---|
| 1180 | perror("write task"); |
---|
| 1181 | exit(1); |
---|
| 1182 | } |
---|
| 1183 | } |
---|
| 1184 | } // end buildBin() |
---|
| 1185 | |
---|
| 1186 | ///////////////////////////////////// |
---|
| 1187 | int main ( int argc, char* argv[] ) |
---|
| 1188 | { |
---|
| 1189 | if ( argc < 3 ) |
---|
| 1190 | { |
---|
| 1191 | printf("Usage: xml2bin <input_file_path> <output_file_path>\n"); |
---|
| 1192 | return 1; |
---|
| 1193 | } |
---|
| 1194 | |
---|
| 1195 | int fdout = open( argv[2], (O_CREAT | O_RDWR), S_IRWXU ); |
---|
| 1196 | if ( fdout < 0) |
---|
| 1197 | { |
---|
| 1198 | perror("open"); |
---|
| 1199 | exit(1); |
---|
| 1200 | } |
---|
| 1201 | |
---|
| 1202 | LIBXML_TEST_VERSION; |
---|
| 1203 | |
---|
| 1204 | int status; |
---|
| 1205 | xmlTextReaderPtr reader = xmlReaderForFile ( argv[1], NULL, 0 ); |
---|
| 1206 | |
---|
| 1207 | if ( reader != NULL ) |
---|
| 1208 | { |
---|
| 1209 | status = xmlTextReaderRead ( reader ); |
---|
| 1210 | while ( status == 1 ) |
---|
| 1211 | { |
---|
| 1212 | const char* tag = (const char*)xmlTextReaderConstName(reader); |
---|
| 1213 | if ( strcmp(tag,"mapping_info") == 0 ) |
---|
| 1214 | { |
---|
| 1215 | headerNode( reader ); |
---|
| 1216 | buildBin( fdout ); |
---|
| 1217 | } |
---|
| 1218 | else |
---|
| 1219 | { |
---|
| 1220 | printf("[XML ERROR] Wrong file type: \"%s\"\n", argv[1]); |
---|
| 1221 | return 1; |
---|
| 1222 | } |
---|
| 1223 | status = xmlTextReaderRead ( reader ); |
---|
| 1224 | } |
---|
| 1225 | xmlFreeTextReader ( reader ); |
---|
| 1226 | |
---|
| 1227 | if ( status != 0 ) |
---|
| 1228 | { |
---|
| 1229 | printf("[XML ERROR] Wrong Syntax in \"%s\" file\n", argv[1]); |
---|
| 1230 | return 1; |
---|
| 1231 | } |
---|
| 1232 | } |
---|
| 1233 | return 0; |
---|
| 1234 | } // end main() |
---|