Skip to content

Commit 28bd508

Browse files
committed
Fix #6: Implement --show-sizes.
And hey, this fixes an unmarked TODO!
1 parent b30a263 commit 28bd508

1 file changed

Lines changed: 17 additions & 7 deletions

File tree

main.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,12 @@ int count(struct argblock *pbptr) {
663663
return 0;
664664
}
665665
int list(struct argblock *pbptr) {
666+
bool showSizes = false;
667+
if (pbptr->argc > 0) {
668+
if (compare_argument('s', "show-sizes", pbptr->argv, &pbptr->argv, /*out_args_consumed*/ NULL, /*option_arg_optional*/ false, /*out_option_arg*/ NULL) & option_comparison_eitheropt) {
669+
showSizes = true;
670+
}
671+
}
666672
ItemCount num;
667673
OSStatus err = PasteboardGetItemCount(pbptr->pasteboard, &num);
668674
if(err != noErr) {
@@ -698,20 +704,24 @@ int list(struct argblock *pbptr) {
698704
void (*tag_deallocator)(const char *ptr) = null_deallocator;
699705
const char *tag_c = tag ? make_cstr_for_CFStr(tag, kCFStringEncodingUTF8, &tag_deallocator) : NULL;
700706

701-
//Make this next step optional! (list --verbose, maybe)
702-
//If verbose...
703707
CFDataRef flavorData = NULL;
704-
err = PasteboardCopyItemFlavorData(pbptr->pasteboard, item, flavor, &flavorData);
708+
if (showSizes) {
709+
err = PasteboardCopyItemFlavorData(pbptr->pasteboard, item, flavor, &flavorData);
710+
}
705711

706712
printf("\t%s ", flavor_c);
707713
if (tag_c != NULL && *tag_c != '\0') {
708714
printf("'%s' ", tag_c);
709715
}
710-
if(err == noErr) {
711-
printf("(%lli bytes)\n", (long long)CFDataGetLength(flavorData));
712-
CFRelease(flavorData);
716+
if (showSizes) {
717+
if(err == noErr) {
718+
printf("(%lli bytes)\n", (long long)CFDataGetLength(flavorData));
719+
CFRelease(flavorData);
720+
} else {
721+
printf("(??? bytes; PasteboardCopyItemFlavorData returned %li (%s))\n", (long)err, GetMacOSStatusCommentString(err));
722+
}
713723
} else {
714-
printf("(??? bytes; PasteboardCopyItemFlavorData returned %li (%s))\n", (long)err, GetMacOSStatusCommentString(err));
724+
printf("\n");
715725
}
716726
//else...
717727
// printf("\t%s\n", flavor_c);

0 commit comments

Comments
 (0)