Actual source code: prefix.c

  1: /*$Id: prefix.c,v 1.30 2001/03/23 23:20:38 balay Exp $*/
  2: /*
  3:      Provides utility routines for manulating any type of PETSc object.
  4: */
 5:  #include petsc.h

  9: /*
 10:    PetscObjectSetOptionsPrefix - Sets the prefix used for searching for all 
 11:    options of PetscObjectType in the database. 

 13:    Input Parameters:
 14: .  obj - any PETSc object, for example a Vec, Mat or KSP.
 15: .  prefix - the prefix string to prepend to option requests of the object.

 17:    Notes: 
 18:    A hyphen (-) must NOT be given at the beginning of the prefix name.
 19:    The first character of all runtime options is AUTOMATICALLY the
 20:    hyphen.

 22:    Concepts: prefix^setting

 24: */
 25: int PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[])
 26: {

 30:   PetscStrfree(obj->prefix);
 31:   if (!prefix) {
 32:     obj->prefix = PETSC_NULL;
 33:   } else {
 34:      if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
 35:     PetscStrallocpy(prefix,&obj->prefix);
 36:   }
 37:   return(0);
 38: }

 42: /*
 43:    PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all 
 44:    options of PetscObjectType in the database. 

 46:    Input Parameters:
 47: .  obj - any PETSc object, for example a Vec, Mat or KSP.
 48: .  prefix - the prefix string to prepend to option requests of the object.

 50:    Notes: 
 51:    A hyphen (-) must NOT be given at the beginning of the prefix name.
 52:    The first character of all runtime options is AUTOMATICALLY the
 53:    hyphen.

 55:    Concepts: prefix^setting

 57: */
 58: int PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])
 59: {
 60:   char *buf = obj->prefix ;
 61:   int  ierr,len1,len2;

 64:   if (!prefix) {return(0);}
 65:   if (!buf) {
 66:     PetscObjectSetOptionsPrefix(obj,prefix);
 67:     return(0);
 68:   }
 69:   if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");

 71:   PetscStrlen(prefix,&len1);
 72:   PetscStrlen(buf,&len2);
 73:   PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
 74:   PetscStrcpy(obj->prefix,buf);
 75:   PetscStrcat(obj->prefix,prefix);
 76:   PetscFree(buf);
 77:   return(0);
 78: }

 82: /*
 83:    PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject.

 85:    Input Parameters:
 86: .  obj - any PETSc object, for example a Vec, Mat or KSP.

 88:    Output Parameters:
 89: .  prefix - pointer to the prefix string used is returned

 91:    Concepts: prefix^getting

 93: */
 94: int PetscObjectGetOptionsPrefix(PetscObject obj,char *prefix[])
 95: {
 97:   *prefix = obj->prefix;
 98:   return(0);
 99: }

103: /*
104:    PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all 
105:    options of PetscObjectType in the database. 

107:    Input Parameters:
108: .  obj - any PETSc object, for example a Vec, Mat or KSP.
109: .  prefix - the prefix string to prepend to option requests of the object.

111:    Notes: 
112:    A hyphen (-) must NOT be given at the beginning of the prefix name.
113:    The first character of all runtime options is AUTOMATICALLY the
114:    hyphen.

116:    Concepts: prefix^setting

118: */
119: int PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])
120: {
121:   char *buf = obj->prefix ;
122:   int  ierr,len1,len2;

125:   if (!prefix) {return(0);}
126:   if (!buf) {
127:     PetscObjectSetOptionsPrefix(obj,prefix);
128:     return(0);
129:   }
130:   if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");

132:   PetscStrlen(prefix,&len1);
133:   PetscStrlen(buf,&len2);
134:   PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
135:   PetscStrcpy(obj->prefix,prefix);
136:   PetscStrcat(obj->prefix,buf);
137:   PetscFree(buf);
138:   return(0);
139: }