IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Opened 21 years ago

Closed 21 years ago

Last modified 20 years ago

#506 closed defect (fixed)

psArgument prototype code

Reported by: Paul Price Owned by: David.Robbins@…
Priority: high Milestone:
Component: sys Version: unspecified
Severity: normal Keywords:
Cc:

Description

I will attach here prototype code for psArgument. There is a memory leak in
psArgumentParse that I haven't been able to put my finger on.

I don't think the definitions for these are in the SDRS for the current cycle,
but they will be in the next one. The idea is to provide some simple handling
of command-line arguments using psLib.

An example use case follows:

int main(int argc, char *argv[])
{

Parse optional command-line arguments
psMetadata *arguments = psMetadataAlloc();
The arguments, with default values
psMetadataAdd(arguments, PS_LIST_TAIL, "-string", PS_META_STR, "Test

string", "SomeString");

psMetadataAdd(arguments, PS_LIST_TAIL, "-bool", PS_META_BOOL, "Test bool",

false);

psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 |

PS_META_DUPLICATE_OK, "Test integer 1", 1);

psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 |

PS_META_DUPLICATE_OK, "Test integer 2", 2);

psMetadataAdd(arguments, PS_LIST_TAIL, "-int", PS_META_S32 |

PS_META_DUPLICATE_OK, "Test integer 3", 3);

psMetadataAdd(arguments, PS_LIST_TAIL, "-float", PS_META_F32, "Test float",

1.234567);

if (! psArgumentParse(arguments, &argc, argv)
argc != 3) {

printf("\nName of the program here\n\n");
printf("Usage: %s INPUT OUTPUT\n\n", argv[0]);
psArgumentHelp(arguments);
psFree(arguments);
exit(EXIT_FAILURE);

}
const char *inputName = argv[1]; Name of input
const char *outputName = argv[2];
Name of output
printf("Success: %s %s\n", inputName, outputName);

psString string = psMetadataLookupString(NULL, arguments, "-string");
float floating = psMetadataLookupF32(NULL, arguments, "-float");
bool boolean = psMetadataLookupBool(NULL, arguments, "-truth");
printf("String: %s\n", string);
printf("Float: %f\n", floating);
printf("Boolean: %d\n", boolean);

psMetadataItem *intItem = psMetadataLookup(arguments, "-int");
if (intItem->type == PS_META_MULTI) {

psList *intMulti = intItem->data.V;
psListIterator *intIter = psListIteratorAlloc(intMulti, PS_LIST_HEAD, false);
psMetadataItem *intMultiItem = NULL;
while (intMultiItem = psListGetAndIncrement(intIter)) {

printf("Integer: %d\n", intMultiItem->data.S32);

}
psFree(intIter);

}

...

Attachments (1)

psAdditionals.c (14.7 KB ) - added by Paul Price 21 years ago.
psAdditionals.c

Download all attachments as: .zip

Change History (7)

by Paul Price, 21 years ago

Attachment: psAdditionals.c added

psAdditionals.c

comment:1 by robert.desonia@…, 21 years ago

Owner: changed from robert.desonia@… to David.Robbins@…

comment:2 by David.Robbins@…, 21 years ago

Resolution: fixed
Status: newclosed

comment:3 by Paul Price, 21 years ago

How was this bug fixed?

comment:4 by David.Robbins@…, 21 years ago

I'm sorry, I didn't realize at the time that I was suppose to post the fix too
and I've forgotten exactly what I did. I have a strong inclination to say that
the memory leak was simply due to a missing psFree call or two. I have tests
implemented to check these functions and there are no memory leaks. That being
said, if you'd like me to spend some time testing this code segment again just
let me know. Sorry about the confusion.

comment:5 by Paul Price, 20 years ago

Keywords: VERIFIED added

Bug has been resolved.... closing.

comment:6 by Paul Price, 20 years ago

Keywords: VERIFIED removed

Bugs have been fixed... closing.

Note: See TracTickets for help on using tickets.