Hi Phuc,

See my comments inline.

Regards, Vu

________________________________
From: Phuc Hoang Chau <phuc.h.c...@dektech.com.au>
Sent: Friday, February 28, 2020 2:01 PM
To: Vu Minh Nguyen <vu.m.ngu...@dektech.com.au>; Thuan Tran 
<thuan.t...@dektech.com.au>
Cc: opensaf-devel@lists.sourceforge.net <opensaf-devel@lists.sourceforge.net>; 
Phuc Hoang Chau <phuc.h.c...@dektech.com.au>
Subject: [PATCH 1/1] imm: imm_list tool add new option --delimiter [#3155]

Make delimiter of multiple attribute value from immlist configurable
Update option --pretty-print will not support print with option --atribute
[Vu] Update the usage saying --pretty-print=yes does not work with the options 
-a and -c
---
 src/imm/tools/imm_list.c | 78 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 64 insertions(+), 14 deletions(-)

diff --git a/src/imm/tools/imm_list.c b/src/imm/tools/imm_list.c
index d1dc422..09222de 100644
--- a/src/imm/tools/imm_list.c
+++ b/src/imm/tools/imm_list.c
@@ -72,13 +72,18 @@ static void usage(const char *progname)
         printf("\t-h, --help - display this help and exit\n");
         printf(
             "\t-p, --pretty-print=<yes|no> - select pretty print, default 
yes\n");
+       printf(
+           "\tdo not support pretty print with option -a, --attribute=NAME\n");
[Vu] "\t--pretty-print does not work with the options -a and -c\n");
+       printf(
+           "\t-d, --delimiter=<CHARACTER> - format multi attribute value\n");
[Vu] "\t-d,--delimiter=<char> - use <char> to separate values of multiple 
attribute\n"
         printf("\t-t, --timeout <sec>\n");
         printf("\t\tutility timeout in seconds\n");

         printf("\nEXAMPLE\n");
         printf("\timmlist -a saAmfApplicationAdminState safApp=OpenSAF\n");
         printf("\timmlist safApp=myApp1 safApp=myApp2\n");
-       printf("\timmlist --pretty-print=no -a saAmfAppType safApp=OpenSAF\n");
+       printf("\timmlist --pretty-print=no safApp=OpenSAF\n");
[Vu] Keep the original line.
+       printf("\timmlist -d '|' safApp=OpenSAF\n");
 }

 static void print_attr_value_raw(SaImmValueTypeT attrValueType,
@@ -141,19 +146,19 @@ static void print_attr_value(SaImmValueTypeT 
attrValueType,
 {
         switch (attrValueType) {
         case SA_IMM_ATTR_SAINT32T:
-               printf("%d (0x%x) ", *((SaInt32T *)attrValue),
+              printf("%d (0x%x)", *((SaInt32T *)attrValue),
                        *((SaInt32T *)attrValue));
                 break;
         case SA_IMM_ATTR_SAUINT32T:
-               printf("%u (0x%x) ", *((SaUint32T *)attrValue),
+               printf("%u (0x%x)", *((SaUint32T *)attrValue),
                        *((SaUint32T *)attrValue));
                 break;
         case SA_IMM_ATTR_SAINT64T:
-               printf("%lld (0x%llx) ", *((SaInt64T *)attrValue),
+               printf("%lld (0x%llx)", *((SaInt64T *)attrValue),
                        *((SaInt64T *)attrValue));
                 break;
         case SA_IMM_ATTR_SAUINT64T:
-               printf("%llu (0x%llx) ", *((SaUint64T *)attrValue),
+               printf("%llu (0x%llx)", *((SaUint64T *)attrValue),
                        *((SaUint64T *)attrValue));
                 break;
         case SA_IMM_ATTR_SATIMET: {
@@ -163,24 +168,24 @@ static void print_attr_value(SaImmValueTypeT 
attrValueType,

                 ctime_r(&time, buf);
                 buf[strlen(buf) - 1] = '\0'; /* Remove new line */
-               printf("%llu (0x%llx, %s) ", *((SaTimeT *)attrValue),
+               printf("%llu (0x%llx, %s)", *((SaTimeT *)attrValue),
                        *((SaTimeT *)attrValue), buf);
                 break;
         }
         case SA_IMM_ATTR_SAFLOATT:
-               printf("%.8g ", *((SaFloatT *)attrValue));
+               printf("%.8g", *((SaFloatT *)attrValue));
                 break;
         case SA_IMM_ATTR_SADOUBLET:
-               printf("%.17g ", *((SaDoubleT *)attrValue));
+               printf("%.17g", *((SaDoubleT *)attrValue));
                 break;
         case SA_IMM_ATTR_SANAMET: {
                 SaNameT *myNameT = (SaNameT *)attrValue;
-               printf("%s (%zu) ", saAisNameBorrow(myNameT),
+               printf("%s (%zu)", saAisNameBorrow(myNameT),
                        strlen(saAisNameBorrow(myNameT)));
                 break;
         }
         case SA_IMM_ATTR_SASTRINGT:
-               printf("%s ", *((char **)attrValue));
+               printf("%s", *((char **)attrValue));
                 break;
         case SA_IMM_ATTR_SAANYT: {
                 SaAnyT *anyp = (SaAnyT *)attrValue;
@@ -404,6 +409,8 @@ static void display_class_definition(const SaImmClassNameT 
className,
 static void display_object(const char *name,
                            SaImmAccessorHandleT accessorHandle,
                            int pretty_print,
+                          int delimiter_print,
+                          char *character,
                            const SaImmAttrNameT *attributeNames)
[Vu] Use this signature:
 static void display_object(const char *name,
                            SaImmAccessorHandleT accessorHandle,
                            int pretty_print,
                            char delimiter,
                            const SaImmAttrNameT *attributeNames)
  {
         int i = 0, j;
@@ -411,6 +418,7 @@ static void display_object(const char *name,
         SaNameT objectName;
         SaAisErrorT error;
         SaImmAttrValuesT_2 **attributes;
+       char *seperate_character = "";
 [Vu] Remove this
         saAisNameLend(name, &objectName);

@@ -428,6 +436,14 @@ static void display_object(const char *name,
                 exit(EXIT_FAILURE);
         }

+       if (delimiter_print)
+               seperate_character = character;
+       else
+               if (pretty_print)
+                       seperate_character = " ";
+               else
+                       seperate_character = ":";
+
[Vu] Remove these code
         if (pretty_print) {
                 printf("%-50s %-12s Value(s)\n", "Name", "Type");
                 printf(
@@ -436,9 +452,13 @@ static void display_object(const char *name,
                         printf("\n%-50s %-12s ", attr->attrName,
                                get_attr_type_name(attr->attrValueType));
                         if (attr->attrValuesNumber > 0) {
-                               for (j = 0; j < attr->attrValuesNumber; j++)
+                               for (j = 0; j < attr->attrValuesNumber; j++) {
                                         print_attr_value(attr->attrValueType,
                                                          attr->attrValues[j]);
+                                       if ((j + 1) < attr->attrValuesNumber)
+                                               printf("%s",
+                                                   seperate_character);
[Vu] printf("%c", delimiter);
+                               }
                         } else
                                 printf("<Empty>");
                 }
@@ -452,7 +472,8 @@ static void display_object(const char *name,
                                             attr->attrValueType,
                                             attr->attrValues[j]);
                                         if ((j + 1) < attr->attrValuesNumber)
-                                               printf(":");
+                                               printf("%s",
+                                                   seperate_character);
[Vu] printf("%c", delimiter);
                                 }
                                 printf("\n");
                         } else
@@ -470,6 +491,7 @@ int main(int argc, char *argv[])
             {"timeout", required_argument, 0, 't'},
             {"help", no_argument, 0, 'h'},
             {"pretty-print", required_argument, 0, 'p'},
+           {"delimiter", required_argument, 0, 'd'},
             {0, 0, 0, 0}};
         SaAisErrorT error;
         SaImmHandleT immHandle;
@@ -481,6 +503,9 @@ int main(int argc, char *argv[])
         int class_desc_print = 0;
         int rc = EXIT_SUCCESS;
         unsigned long timeoutVal = 60;
+       int delimiter_print = 0;
+       char *character = "";
+       int atribute_set = 0;
[Vu] Replace these 03 lines by this one:
char delimiter = ' ';

         /* Support for long DN */
         setenv("SA_ENABLE_EXTENDED_NAMES", "1", 1);
@@ -490,7 +515,7 @@ int main(int argc, char *argv[])
         osaf_extended_name_init();

         while (1) {
-               c = getopt_long(argc, argv, "a:p:t:ch", long_options, NULL);
+               c = getopt_long(argc, argv, "a:d:p:t:ch", long_options, NULL);

                 if (c ==
                     -1) /* have all command-line options have been parsed? */
@@ -502,6 +527,7 @@ int main(int argc, char *argv[])
                             attributeNames, ++len * sizeof(SaImmAttrNameT));
                         attributeNames[len - 2] = strdup(optarg);
                         attributeNames[len - 1] = NULL;
+                       atribute_set = 1;
[Vu] Change this line to:
delimiter = ':';
                         pretty_print = 0;
                         break;
                 case 'c':
@@ -517,6 +543,21 @@ int main(int argc, char *argv[])
                 case 'p':
                         if (!strcasecmp(optarg, "no"))
                                 pretty_print = 0;
+                       else
+                               pretty_print = 1;
+                       break;
[Vu] Keep the codes of this option as it is.

+               case 'd':
+                       character = optarg;
+                       size_t len = 0;
+                       len = strlen(character);
+                       if (len == 1) {
+                               delimiter_print = 1;
+                       } else {
+                               fprintf(
+                                   stderr, "Illegal delimiter argument."
+                                   " Valid value is one character\n");
+                               exit(EXIT_FAILURE);
+                       }
[Vu] Change to:
if (strlen(optarg) > 1) {
        fprintf(stderr, "The delimiter must be a single character\n");
        exit(EXIT_FAILURE);
}

delimiter = optarg[0];
break;
                         break;
                 default:
                         fprintf(stderr,
@@ -537,6 +578,14 @@ int main(int argc, char *argv[])
                 goto done;
         }

+       if (atribute_set && pretty_print) {
+               fprintf(
+                   stderr,
+                   "error - disallow --pretty-print=yes with option -a\n");
+               rc = EXIT_FAILURE;
+               goto done;
+       }
+
[Vu] Remove these codes.

         immutilWrapperProfile.errorsAreFatal = 0;
         immutilWrapperProfile.nTries = timeoutVal;
         immutilWrapperProfile.retryInterval = 1000;
@@ -570,7 +619,8 @@ int main(int argc, char *argv[])
                  * attributes for. */
                 while (optind < argc) {
                         display_object(argv[optind], accessorHandle,
-                                      pretty_print, attributeNames);
+                                      pretty_print, delimiter_print,
+                                      character, attributeNames);
[Vu] Calling this function by:
display_object(argv[optind], accessorHandle,
      pretty_print, delimiter, attributeNames);
                         optind++;
                 }

--
2.7.4


_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to