1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
|
/*
Copyright (C) 1993, 1994, RSNA and Washington University
The software and supporting documentation for the Radiological
Society of North America (RSNA) 1993, 1994 Digital Imaging and
Communications in Medicine (DICOM) Demonstration were developed
at the
Electronic Radiology Laboratory
Mallinckrodt Institute of Radiology
Washington University School of Medicine
510 S. Kingshighway Blvd.
St. Louis, MO 63110
as part of the 1993, 1994 DICOM Central Test Node project for, and
under contract with, the Radiological Society of North America.
THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND NEITHER RSNA NOR
WASHINGTON UNIVERSITY MAKE ANY WARRANTY ABOUT THE SOFTWARE, ITS
PERFORMANCE, ITS MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
USE, FREEDOM FROM ANY COMPUTER DISEASES OR ITS CONFORMITY TO ANY
SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND PERFORMANCE OF
THE SOFTWARE IS WITH THE USER.
Copyright of the software and supporting documentation is
jointly owned by RSNA and Washington University, and free access
is hereby granted as a license to use this software, copy this
software and prepare derivative works based upon this software.
However, any distribution of this software source code or
supporting documentation or derivative works (source code and
supporting documentation) must include the three paragraphs of
the copyright notice.
*/
/*
+-+-+-+-+-+-+-+-+-
*/
/*
** Electronic Radiology Laboratory
** Mallinckrodt Institute of Radiology
** Washington University School of Medicine
**
** Module Name(s): dcm_modify_object (main)
** makeElement
** usageError
** addPixels
** fileSize
** Author, Date: Aniruddha Gokhale, 24-May-1995
** Intent: This program allows us to build a DICOM object.
** The user will provide the input in the form of
** triplets (Group, Element, Value) for "non" DCM_SQ
** elements. Whenever an attribute is of the type,
** SEQUENCE, the Value parameter can be recusively defined
** using parentheses as shown:
**
** group# element# (
** group# element# value
** .... ...... ....
** )
**
** other elements
**
** Last Update: $Author: smm $, $Date: 2007-03-16 02:18:15 $
** Source File: $RCSfile: dcm_modify_object.c,v $
** Revision: $Revision: 1.21 $
** Status: $State: Exp $
*/
static char rcsid[] = "$Revision: 1.21 $ $RCSfile: dcm_modify_object.c,v $";
#include "modify.h"
LST_HEAD
* modlist; /* stores the list of modifications */
DCM_OBJECT
* object; /* stores the the object to which
* modifications need to be done. */
CTNBOOLEAN
verbose = FALSE;
static void usageerror();
static void addPixels(DCM_OBJECT ** object, char *pixelfile);
static int fileSize(int fd);
static void parseNumericString(char *, DCM_ELEMENT **);
void yyparse(void);
DCM_VALUEREPRESENTATION contextVR = DCM_CTX;
main(int argc, char **argv)
{
CONDITION
cond;
char
*pixelfile = NULL, /* file with pixel data */
*modfile = NULL; /* input file with data that consists of
* elements that need to be modified in the
* input object */
long
options = DCM_ORDERLITTLEENDIAN; /* default */
long
outputOptions = DCM_ORDERLITTLEENDIAN; /* default */
CTNBOOLEAN pixelsOnly = FALSE;
yyin = stdin; /* default input file */
while (--argc > 0 && (*++argv)[0] == '-') {
switch (*(argv[0] + 1)) {
case 'b': /* use BIG ENDIAN */
options &= ~DCM_ORDERMASK;
options |= DCM_ORDERBIGENDIAN;
break;
case 'c': /* Set type for context values */
case 'C':
argc--; argv++;
if (argc < 1) /* must have an output file */
usageerror();
if (strcmp(*argv, "SS") == 0) {
contextVR = DCM_SS;
} else if (strcmp(*argv, "US") == 0) {
contextVR = DCM_SS;
} else {
usageerror();
}
break;
case 'i': /* use input file */
case 'I':
argc--;
argv++;
modfile = *argv;
yyin = fopen(modfile, "r");
if (yyin == NULL) {
perror("fopen failed opening input file");
exit(1);
}
break;
case 'p': /* pixel data exists */
case 'P':
argc--;
argv++;
pixelfile = *argv;
break;
case 't':
options &= ~DCM_FILEFORMATMASK;
options |= DCM_PART10FILE;
break;
case 'T':
outputOptions &= ~DCM_FILEFORMATMASK;
outputOptions |= DCM_PART10FILE;
break;
case 'v': /* verbose option */
case 'V':
verbose = TRUE;
break;
case 'x':
pixelsOnly = TRUE;
break;
default:
fprintf(stderr, "Unrecognized option: %c\n", *(argv[0] + 1));
break;
}
}
if (argc < 2) /* must have an input and output file */
usageerror();
THR_Init();
/* open the input file that needs to be modified */
cond = DCM_OpenFile(*argv, options, &object);
if (cond != DCM_NORMAL) {
fprintf(stderr, "DCM_OpenFile: failed: %s\n", *argv);
COND_DumpConditions();
if ((options & DCM_FILEFORMATMASK) != DCM_PART10FILE) {
fprintf(stderr, "Now trying part 10 format\n");
options &= ~DCM_FILEFORMATMASK;
options |= DCM_PART10FILE;
cond = DCM_OpenFile(*argv, options, &object);
if (cond != DCM_NORMAL) {
fprintf(stderr, "DCM_OpenFile: failed: %s\n", *argv);
COND_DumpConditions();
}
}
}
if (cond != DCM_NORMAL) {
THR_Shutdown();
exit(1);
}
argv++;
/*
* parse the input and build the list of elements to be added to an
* object
*/
if (!pixelsOnly) {
yyparse();
if (verbose) {
printf("*****In main program, after parse*****\n");
APP_DumpModList(&modlist, 0);
}
/* make modifications to the object as per the mod list */
cond = makeModifications(&modlist, &object);
if (cond != APP_NORMAL) {
printf("makeModifications: failed to make modifications\n");
COND_DumpConditions();
THR_Shutdown();
exit(1);
}
}
/* make modifications to pixel data */
if (pixelfile != NULL)
addPixels(&object, pixelfile);
if (verbose) {
(void) DCM_DumpElements(&object, 0);
}
/* finally, write the modified object to output file */
cond = DCM_WriteFile(&object, outputOptions, *argv);
(void) DCM_CloseObject(&object);
if (cond != DCM_NORMAL) {
printf("DCM_WriteFile: failed to write modified object to file\n");
COND_DumpConditions();
THR_Shutdown();
exit(1);
}
THR_Shutdown();
exit(0);
}
/* usageError
**
** Purpose:
** Displays the correct usage of the command
**
** Parameter Dictionary:
** None
**
** Return Values:
** None
**
** Notes:
**
** Algorithm:
** Description of the algorithm (optional) and any other notes.
*/
static void
usageerror()
{
char msg[] = "\
Usage: dcm_modify_object [-b] [-i modfile] [-p pixels] [-t] [-v] [-x] filein fileout\n\
\n\
-b Use Big-Endian order to store the object (not Part 10) \n\
-i Use input file for the ASCII modifications instead of standard input\n\
-p Read raw pixel data from the file pixels \n\
-t Files are processed in DICOM Part 10 format \n\
-v Verbose mode; place DCM facility in verbose mode \n\
-x Only process pixel data; there are no other modifications to make \n\
\n\
filein File that contains original DICOM object \n\
fileout FIle that stores the modified DICOM object \n";
fprintf(stdout, "%s", msg);
exit(1);
}
/* makeElement
**
** Purpose:
** Make an element out of the given group#, element# and value
**
** Parameter Dictionary:
** group Group number of the element to be added
** element Element number
** vdata Actual data to be added
** elem Handle to the element to be returned
**
** Return Values:
**
** DCM_ILLEGALOBJECT
** DCM_ILLEGALREPRESENTATION
** DCM_INSERTFAILED
** DCM_NORMAL
** DCM_NULLOBJECT
** DCM_UNRECOGNIZEDELEMENT
** DCM_UNRECOGNIZEDGROUP
**
** Notes:
**
** Algorithm:
*/
CONDITION
makeElement(int group, int element, void *vdata,
DCM_ELEMENT ** elem)
{
CONDITION
cond = DCM_NORMAL;
DCM_ELEMENT
* e;
char
*data = (char *) vdata;
e = (DCM_ELEMENT *) malloc(sizeof(DCM_ELEMENT));
if (e == NULL) {
printf("malloc: cannot allocate memory for DCM_ELEMENT\n");
return DCM_ELEMENTCREATEFAILED;
}
e->tag = DCM_MAKETAG(group, element);
cond = DCM_LookupElement(e);
if (cond != DCM_NORMAL)
return cond;
if (e->representation == DCM_CTX) {
e->representation = contextVR;
}
switch (e->representation) {
case DCM_DD: /* Data set */
case DCM_FD: /* Floating double */
case DCM_FL: /* Float */
case DCM_OT: /* Other binary value */
case DCM_UN: /* Unknown/unspecified */
case DCM_RET: /* Retired */
case DCM_CTX: /* Context sensitive */
printf("The representation for (%04x %04x) is unimplemented\n",
group, element);
e->d.ot = NULL;
break;
case DCM_AE: /* Application Entity */
case DCM_AS: /* Age String */
case DCM_CS: /* Control string */
case DCM_DA: /* Date */
case DCM_DT: /* Date/Time */
case DCM_DS: /* Decimal string */
case DCM_IS: /* Integer string */
case DCM_LT: /* Long text */
case DCM_LO: /* Long string */
case DCM_PN: /* Person Name */
case DCM_SH: /* Short string */
case DCM_ST: /* Short text */
case DCM_TM: /* Time */
case DCM_UI: /* Unique identifier (UID) */
if (strcmp(data, "#") == 0) {
e->length = 0;
e->d.string = "";
} else {
e->length = strlen(data);
e->d.string = data;
}
break;
case DCM_AT: /* Attribute tag */
case DCM_SL: /* Signed long */
case DCM_SS: /* Signed short */
case DCM_UL: /* Unsigned long */
case DCM_US: /* Unsigned short */
if (strcmp(data, "#") == 0) {
e->length = 0;
e->d.string = NULL;
} else {
parseNumericString(data, &e);
}
break;
case DCM_SQ: /* Sequence of items */
{
char* xxx = "####";
if (memcmp(vdata, xxx, 4) == 0) {
e->d.sq = LST_Create();
} else {
e->d.sq = vdata;
}
}
break;
default:
fprintf(stderr,
"Should not reach default for element (%04x %04x)\n",
group, element);
e->d.ot = NULL;
}
*elem = e;
return cond;
}
/* addPixels
**
** Purpose:
** Add pixel data to the DICOM object
**
** Parameter Dictionary:
** object Handle to object to which pixel data is to be added
** pixelfile Name of file containing pixel data
**
** Return Values:
** None
**
** Notes:
**
** Algorithm:
** Description of the algorithm (optional) and any other notes.
*/
static void
addPixels(DCM_OBJECT ** obj, char *pixelfile)
{
int
fd,
size,
bytesRead,
remainingBytes;
unsigned char
*p;
DCM_ELEMENT e = {DCM_PXLPIXELDATA, DCM_OT, "", 0, 0, NULL};
CONDITION
cond;
/* Remove pixel data if already there, ignoring errors */
(void) DCM_RemoveElement(obj, DCM_PXLPIXELDATA);
(void) COND_PopCondition(TRUE);
#ifdef _WIN32
fd = open(pixelfile, O_RDONLY | O_BINARY);
#else
fd = open(pixelfile, O_RDONLY);
#endif
if (fd < 0) {
perror(pixelfile);
exit(1);
}
size = fileSize(fd);
if (size < 0) {
perror(pixelfile);
exit(1);
}
p = (unsigned char *) malloc(size);
if (p == NULL) {
perror("");
exit(1);
}
e.length = (unsigned long) size;
e.d.ot = p;
remainingBytes = size;
while (remainingBytes > 0) {
bytesRead = read(fd, p, remainingBytes);
if (bytesRead <= 0) {
perror(pixelfile);
exit(1);
}
remainingBytes -= bytesRead;
p += bytesRead;
}
cond = DCM_AddElement(obj, &e);
if (cond != DCM_NORMAL) {
COND_DumpConditions();
exit(1);
}
}
/* fileSize
**
** Purpose:
** Returns file size on success
**
** Parameter Dictionary:
** fd File descriptor
**
** Return Values:
** file size on success, else error status code
**
** Notes:
**
** Algorithm:
** Description of the algorithm (optional) and any other notes.
*/
static int
fileSize(int fd)
{
int
status;
struct stat
im_stat;
status = fstat(fd, &im_stat);
if (status < 0) {
return status;
} else
return im_stat.st_size;
}
void
APP_DumpModList(LST_HEAD ** lh, int level)
{
APP_ELEMLIST
* ael;
APP_ITEMSEQ
* ais;
DCM_ELEMENT
* e;
CONDITION
cond;
ael = LST_Position(lh, LST_Head(lh));
while (ael) {
e = ael->e;
cond = DCM_LookupElement(e);
if (cond != DCM_NORMAL) {
printf("DCM_LookupElement: failed\n");
COND_DumpConditions();
exit(1);
}
printf("%*sTag = %x, Description = %s\n", level * 2, "", e->tag, e->description);
switch (e->representation) {
case DCM_SQ:
printf("%*s-----SEQUENCE---------\n", (level + 1) * 2, "");
ais = LST_Position(&e->d.sq, LST_Head(&e->d.sq));
while (ais) {
printf("%*s===NEXT ITEM IN SEQUENCE===\n", (level + 1) * 2, "");
APP_DumpModList(&ais->ael, level + 1);
ais = LST_Next(&e->d.sq);
}
printf("%*s-----END SEQUENCE---------\n", (level + 1) * 2, "");
break;
default:
break;
}
ael = LST_Next(lh);
}
}
CONDITION
makeModifications(LST_HEAD ** lh, DCM_OBJECT ** obj)
{
DCM_ELEMENT
elem,
*e;
DCM_SEQUENCE_ITEM
* dsi = NULL;
APP_ELEMLIST
* ael;
APP_ITEMSEQ
* ais;
unsigned long
rtnLength;
void
*ctx = NULL;
CONDITION
cond;
LST_HEAD
* l;
LST_NODE* node;
if (*lh == NULL) {
/*
* no modifications were necessary in this object obj. We just
* return.
*/
return APP_NORMAL;
}
ael = LST_Position(lh, LST_Head(lh));
while (ael) {
e = ael->e;
cond = DCM_LookupElement(e);
if (cond != DCM_NORMAL) {
printf("makeModifications: DCM_LookupElement failed\n");
return cond;
}
switch (e->representation) {
case DCM_SQ:
/* get the element from the main object */
memset(&elem, 0, sizeof(DCM_ELEMENT));
elem.tag = e->tag;
elem.representation = e->representation;
cond = DCM_GetSequenceList(obj, e->tag, &l);
if (cond == DCM_NORMAL) {
/*
* l points to a list maintained in the object. A call to
* RemoveElement below will also indirectly screw up l that
* we maintain. Hence we must make a copy of that list
*/
elem.d.sq = LST_Create();
if (elem.d.sq == NULL) {
printf("makeModifications: LST_Create failed\n");
return APP_FAILURE;
}
dsi = LST_Dequeue(&l);
while (dsi != NULL) {
cond = LST_Enqueue(&elem.d.sq, dsi);
if (cond != LST_NORMAL) {
printf("makeModifications: LST_Enqueue failed\n");
return cond;
}
dsi = LST_Dequeue(&l);
}
/*
* now remove that element from the object so that we don't
* add it twice
*/
cond = DCM_RemoveElement(obj, e->tag);
if (cond != DCM_NORMAL) {
printf("makeModifications: DCM_RemoveElement failed\n");
printf("\telement tag (%x, %x), decription (%s)\n",
DCM_TAG_GROUP(e->tag), DCM_TAG_ELEMENT(e->tag),
e->description);
return cond;
}
#ifdef ASG
#endif
} else if (cond == DCM_ELEMENTNOTFOUND) {
(void) COND_PopCondition(TRUE);
elem.d.sq = LST_Create();
if (elem.d.sq == NULL) {
printf("makeModifications: LST_Create failed\n");
return APP_FAILURE;
}
} else {
printf("makeModifications: DCM_GetElementValue failed\n");
printf("\telement tag (%x, %x), decription (%s)\n",
DCM_TAG_GROUP(e->tag), DCM_TAG_ELEMENT(e->tag),
e->description);
return cond;
}
node = LST_Head(&e->d.sq);
if (node != NULL) {
ais = LST_Position(&e->d.sq, node);
} else {
ais = NULL;
}
/*ais = LST_Position(&e->d.sq, LST_Head(&e->d.sq));*/
dsi = LST_Position(&elem.d.sq, LST_Head(&elem.d.sq));
while (ais) {
if (dsi == NULL) {
/*
* no more sequence items in the original object. So the
* next list of mod items is just to be inserted in the
* object
*/
dsi = (DCM_SEQUENCE_ITEM *) malloc(sizeof(DCM_SEQUENCE_ITEM));
if (dsi == NULL) {
printf("makeModifications: Out of memory for SQ item\n");
return APP_FAILURE;
}
cond = DCM_CreateObject(&dsi->object, 0);
if (cond != DCM_NORMAL) {
printf("makeModifications: DCM_CreateObject failed\n");
return cond;
}
cond = makeModifications(&ais->ael, &dsi->object);
if (cond != APP_NORMAL) {
printf("makeModifications: failed to recursively modify\n");
return cond;
}
cond = DCM_GetObjectSize(&dsi->object, &rtnLength);
if (rtnLength != 0) {
elem.length += 8 + rtnLength;
/* enqueue this seq item into the element sequence */
cond = LST_Enqueue(&elem.d.sq, dsi);
if (cond != LST_NORMAL) {
printf("makeModifications: LST_Enqueue failed\n");
return cond;
}
}
dsi = NULL;
} else {
/* modify elements in the current sequence */
cond = makeModifications(&ais->ael, &dsi->object);
if (cond != APP_NORMAL) {
printf("makeModifications: failed to recursively modify\n");
return cond;
}
cond = DCM_GetObjectSize(&dsi->object, &rtnLength);
elem.length += 8 + rtnLength;
dsi = LST_Next(&elem.d.sq);
}
ais = LST_Next(&e->d.sq);
}
/* Add the element to the object */
cond = DCM_AddElement(obj, &elem);
if (cond != DCM_NORMAL) {
printf("makeModifications: DCM_AddElement failed\n");
return cond;
}
#ifdef ASG
cond = DCM_ModifyElements(obj, &elem, 1, NULL, 0, NULL);
if (cond != DCM_NORMAL) {
printf("makeModifications: DCM_ModifyElements failed\n");
return cond;
}
#endif
break;
default:
/*
* for any other element, simply modify the element in the object
* directly
*/
cond = DCM_ModifyElements(obj, e, 1, NULL, 0, NULL);
if (cond != DCM_NORMAL) {
printf("makeModifications: DCM_ModifyElements failed\n");
printf("\telement tag (%x, %x), decription (%s)\n",
DCM_TAG_GROUP(e->tag), DCM_TAG_ELEMENT(e->tag),
e->description);
return cond;
}
break;
}
ael = LST_Next(lh);
}
return APP_NORMAL;
}
void
parseNumericString(char *data, DCM_ELEMENT ** elem)
{
DCM_ELEMENT
* e = *elem;
char *token,
*sep = "\\";
int
i[100]; /* assume that multiplicity can atmost be 100 */
int
j,
count = 0;
/* assume that the incoming data is of multiplicity >= 1 */
token = strtok(data, sep);
while (token != NULL) {
if (sscanf(token, "%d", &i[count]) != 1) {
fprintf(stderr, "Error parsing %s as a numeric quantity\n", token);
exit(1);
}
count++;
/* get next token */
token = strtok(NULL, sep);
}
if (count == 0) {
e->length = 0;
e->d.string = NULL;
return;
}
/* now fill the data in the element */
switch (e->representation) {
case DCM_AT:
e->d.at = (DCM_TAG *) malloc(sizeof(DCM_TAG) * count);
if (e->d.at == NULL) {
fprintf(stderr, "malloc: Out of memory\n");
exit(1);
}
e->length = sizeof(DCM_TAG) * count;
for (j = 0; j < count; j++) {
e->d.at[j] = (DCM_TAG) i[j];
}
break;
case DCM_SL:
e->d.sl = (S32 *) malloc(sizeof(S32) * count);
if (e->d.sl == NULL) {
fprintf(stderr, "malloc: Out of memory\n");
exit(1);
}
e->length = sizeof(S32) * count;
for (j = 0; j < count; j++) {
e->d.sl[j] = (S32) i[j];
}
break;
case DCM_SS:
e->d.ss = (S16 *) malloc(sizeof(S16) * count);
if (e->d.ss == NULL) {
fprintf(stderr, "malloc: Out of memory\n");
exit(1);
}
e->length = sizeof(S16) * count;
for (j = 0; j < count; j++) {
e->d.ss[j] = (S16) i[j];
}
break;
case DCM_UL:
e->d.ul = (U32 *) malloc(sizeof(U32) * count);
if (e->d.ul == NULL) {
fprintf(stderr, "malloc: Out of memory\n");
exit(1);
}
e->length = sizeof(U32) * count;
for (j = 0; j < count; j++) {
e->d.ul[j] = (U32) i[j];
}
break;
case DCM_US:
e->d.us = (U16 *) malloc(sizeof(U16) * count);
if (e->d.us == NULL) {
fprintf(stderr, "malloc: Out of memory\n");
exit(1);
}
e->length = sizeof(U16) * count;
for (j = 0; j < count; j++) {
e->d.us[j] = (U16) i[j];
}
break;
default:
return; /* unknown. Better not come here because we
* invoked this proc only for the obove 4
* cases */
}
}
void
yyerror(const char *err)
{
printf("Parsing Error: (msg = %s)\n", err);
printf("Exiting\n");
exit(1);
}
|