[OPENSM] make formatting & whitespace use consistent in getopt_long_only().
authorstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 29 Mar 2010 18:34:11 +0000 (18:34 +0000)
committerstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 29 Mar 2010 18:34:11 +0000 (18:34 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2759 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/opensm/user/libvendor/winosm_common.c

index c046336..a5d71c6 100644 (file)
@@ -187,12 +187,12 @@ static int iArg=1;
 int getopt_long_only(int argc, char *const*argv, const char *optstring,
                        const struct option *longopts, int *longindex)
 {
 int getopt_long_only(int argc, char *const*argv, const char *optstring,
                        const struct option *longopts, int *longindex)
 {
-  char chOpt;
-  char tmp_str[256];
-  char* tmp_arg = NULL;
-  char* tok=NULL;
-  int i;
-  char tokens[2] = {'='};
+    char chOpt;
+    char tmp_str[256];
+    char* tmp_arg = NULL;
+    char* tok=NULL;
+    int i;
+    char tokens[2] = {'='};
 
     if (optind == 0) {
        optind = iArg = opterr = 1;
 
     if (optind == 0) {
        optind = iArg = opterr = 1;
@@ -202,8 +202,7 @@ int getopt_long_only(int argc, char *const*argv, const char *optstring,
     if (iArg == argc)
         return (EOF);
 
     if (iArg == argc)
         return (EOF);
 
-    if (argv[iArg][0] != '-')
-    {
+    if (argv[iArg][0] != '-') {
         /* Does not start with a '-' we are done scanning */
         return (EOF);
     }
         /* Does not start with a '-' we are done scanning */
         return (EOF);
     }
@@ -213,7 +212,6 @@ int getopt_long_only(int argc, char *const*argv, const char *optstring,
         return EOF;
     }
     
         return EOF;
     }
     
-  
     /* char option : -d 5 */
     if ((argv[iArg][0] == '-') && (argv[iArg][1] != '-') ) {
         optarg = get_char_option(optstring, argv, argc, iArg, &optind, &chOpt);
     /* char option : -d 5 */
     if ((argv[iArg][0] == '-') && (argv[iArg][1] != '-') ) {
         optarg = get_char_option(optstring, argv, argc, iArg, &optind, &chOpt);
@@ -227,62 +225,50 @@ int getopt_long_only(int argc, char *const*argv, const char *optstring,
     /*get the option */
     tok = strtok(tmp_str,tokens);
     
     /*get the option */
     tok = strtok(tmp_str,tokens);
     
-    for (i = 0; longopts[i].name; i++)
-       {
-        if (strcmp (tok, longopts[i].name) == 0)
-               {
+    for (i = 0; longopts[i].name; i++) {
+        if (strcmp (tok, longopts[i].name) == 0) {
             /* We have a match */             
              if (longindex != NULL )
                 *longindex = i;
               
             /* We have a match */             
              if (longindex != NULL )
                 *longindex = i;
               
-                if (longopts[i].flag != NULL) {
-                 *(longopts[i].flag) = longopts[i].val;
-                }
+             if (longopts[i].flag != NULL)
+                *(longopts[i].flag) = longopts[i].val;
               
               
-                
-                
-                if (longopts[i].has_arg != no_argument) 
-                  {
-                    /*get the argument */
-                    
-                    if (strchr(argv[iArg],'=') != NULL)
-                    {
-                        optarg = strtok(NULL,tokens);
-                    }else { /*the next arg in cmd line is the param */ 
-                        tmp_arg = argv[iArg+1];
-                        if (*tmp_arg == '-') {
-                        
-                            /*no param is found */
-                            chOpt = '?';
-                            if ((longopts[i].has_arg == required_argument) && opterr)
-                           {
-                             fprintf (stderr,
+             if (longopts[i].has_arg != no_argument) {
+                /*get the argument */
+                if (strchr(argv[iArg],'=') != NULL) {
+                    optarg = strtok(NULL,tokens);
+                }
+                else { /* the next arg in cmd line is the param */ 
+                    tmp_arg = argv[iArg+1];
+                    if (!tmp_arg || *tmp_arg == '-') {
+                        /* no param is found */
+                        if ((longopts[i].has_arg == required_argument) && opterr) {
+                            fprintf (stderr,
                                     "Option '--%s' requires an argument\n",tok);
                                     "Option '--%s' requires an argument\n",tok);
-                             iArg++;
-                             optind++;
-                             break;
-                           }
-
-                        }else 
-                        {
-                            optarg = tmp_arg;
                             iArg++;
                             optind++;
                             iArg++;
                             optind++;
+                            break;
                         }
                         }
+
+                    } else {
+                        optarg = tmp_arg;
+                        iArg++;
+                        optind++;
                     }
                     }
+                }
                                      
                                      
-                 }/*longopts */
+            } /* longopts */
                                 
                                 
-                iArg++;
-                optind++;
-                if (longopts[i].flag == 0)
-                    return (longopts[i].val);
-                else return 0; 
-              
-            }/*end if strcmp */
-           }
-
-  return ('?');
+            iArg++;
+            optind++;
+            if (longopts[i].flag == 0)
+                return (longopts[i].val);
+            else
+                return 0; 
+        } /* end if strcmp */
+    }
+    return ('?');
 }
  
 /******************************************************************************/
 }
  
 /******************************************************************************/