1. petsc
  2. PETSc
  3. petsc

Commits

Jed Brown  committed b19a531

Allow keys starting with --, handle prefixes as --prefix_option instead of -prefix_-option.

(cherry picked from commit 7cd08cec2432658160c70b3c529f243c3b7cdafe at
the request of Alex Matveev <alexei.matveev@gmail.com> for Debian Wheezy)

  • Participants
  • Parent commits 6a4bb4b
  • Branches master

Comments (0)

Files changed (1)

File src/sys/objects/options.c

View file
  • Ignore whitespace
 #undef __FUNCT__  
 #define __FUNCT__ "PetscOptionsValidKey"
 /*@
-    PetscOptionsValidKey - PETSc Options database keys must begin with a - followed by a letter.
+    PetscOptionsValidKey - PETSc Options database keys must begin with one or two dashes (-) followed by a letter.
 
    Input Parameter:
 .    in_str - string to check if valid
   *key = PETSC_FALSE;
   if (!in_str) PetscFunctionReturn(0);
   if (in_str[0] != '-') PetscFunctionReturn(0);
-  if (!(isalpha(in_str[1]))) PetscFunctionReturn(0);
+  if (in_str[1] == '-') in_str++;
+  if (!isalpha(in_str[1])) PetscFunctionReturn(0);
   if ((!strncmp(in_str+1,"inf",3) || !strncmp(in_str+1,"INF",3)) && !(in_str[4] == '_' || isalnum(in_str[4]))) PetscFunctionReturn(0);
   *key = PETSC_TRUE;
   PetscFunctionReturn(0);
 
   if (name[0] != '-') SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Name must begin with -: Instead %s",name);
 
-  /* append prefix to name */
+  /* append prefix to name, if prefix="foo_" and option='--bar", prefixed option is --foo_bar */
   if (pre) {
+    char *ptr = tmp;
     if (pre[0] == '-') SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Prefix should not begin with a -");
-    ierr = PetscStrncpy(tmp,pre,256);CHKERRQ(ierr);
+    if (name[1] == '-') {
+      *ptr++ = '-';
+      name++;
+    }
+    ierr = PetscStrncpy(ptr,pre,tmp+sizeof tmp-ptr);CHKERRQ(ierr);
+    tmp[sizeof tmp-1] = 0;
     ierr = PetscStrlen(tmp,&len);CHKERRQ(ierr);
-    ierr = PetscStrncat(tmp,name+1,256-len-1);CHKERRQ(ierr);
+    ierr = PetscStrncat(tmp,name+1,sizeof tmp-len-1);CHKERRQ(ierr);
   } else {
-    ierr = PetscStrncpy(tmp,name+1,256);CHKERRQ(ierr);
+    ierr = PetscStrncpy(tmp,name+1,sizeof tmp);CHKERRQ(ierr);
+    tmp[sizeof tmp-1] = 0;
   }
 
   /* slow search */