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
7: /*
8: PetscObjectSetOptionsPrefix - Sets the prefix used for searching for all
9: options of PetscObjectType in the database.
11: Input Parameters:
12: . obj - any PETSc object, for example a Vec, Mat or KSP.
13: . prefix - the prefix string to prepend to option requests of the object.
15: Notes:
16: A hyphen (-) must NOT be given at the beginning of the prefix name.
17: The first character of all runtime options is AUTOMATICALLY the
18: hyphen.
20: Concepts: prefix^setting
22: */
23: int PetscObjectSetOptionsPrefix(PetscObject obj,const char prefix[])
24: {
28: PetscStrfree(obj->prefix);
29: if (!prefix) {
30: obj->prefix = PETSC_NULL;
31: } else {
32: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
33: ierr = PetscStrallocpy(prefix,&obj->prefix);
34: }
35: return(0);
36: }
38: /*
39: PetscObjectAppendOptionsPrefix - Sets the prefix used for searching for all
40: options of PetscObjectType in the database.
42: Input Parameters:
43: . obj - any PETSc object, for example a Vec, Mat or KSP.
44: . prefix - the prefix string to prepend to option requests of the object.
46: Notes:
47: A hyphen (-) must NOT be given at the beginning of the prefix name.
48: The first character of all runtime options is AUTOMATICALLY the
49: hyphen.
51: Concepts: prefix^setting
53: */
54: int PetscObjectAppendOptionsPrefix(PetscObject obj,const char prefix[])
55: {
56: char *buf = obj->prefix ;
57: int ierr,len1,len2;
60: if (!prefix) {return(0);}
61: if (!buf) {
62: PetscObjectSetOptionsPrefix(obj,prefix);
63: return(0);
64: }
65: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
67: ierr = PetscStrlen(prefix,&len1);
68: ierr = PetscStrlen(buf,&len2);
69: ierr = PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
70: ierr = PetscStrcpy(obj->prefix,buf);
71: ierr = PetscStrcat(obj->prefix,prefix);
72: ierr = PetscFree(buf);
73: return(0);
74: }
76: /*
77: PetscObjectGetOptionsPrefix - Gets the prefix of the PetscObject.
79: Input Parameters:
80: . obj - any PETSc object, for example a Vec, Mat or KSP.
82: Output Parameters:
83: . prefix - pointer to the prefix string used is returned
85: Concepts: prefix^getting
87: */
88: int PetscObjectGetOptionsPrefix(PetscObject obj,char *prefix[])
89: {
91: *prefix = obj->prefix;
92: return(0);
93: }
95: /*
96: PetscObjectPrependOptionsPrefix - Sets the prefix used for searching for all
97: options of PetscObjectType in the database.
99: Input Parameters:
100: . obj - any PETSc object, for example a Vec, Mat or KSP.
101: . prefix - the prefix string to prepend to option requests of the object.
103: Notes:
104: A hyphen (-) must NOT be given at the beginning of the prefix name.
105: The first character of all runtime options is AUTOMATICALLY the
106: hyphen.
108: Concepts: prefix^setting
110: */
111: int PetscObjectPrependOptionsPrefix(PetscObject obj,const char prefix[])
112: {
113: char *buf = obj->prefix ;
114: int ierr,len1,len2;
117: if (!prefix) {return(0);}
118: if (!buf) {
119: PetscObjectSetOptionsPrefix(obj,prefix);
120: return(0);
121: }
122: if (prefix[0] == '-') SETERRQ(PETSC_ERR_ARG_WRONG,"Options prefix should not begin with a hypen");
124: PetscStrlen(prefix,&len1);
125: PetscStrlen(buf,&len2);
126: PetscMalloc((1+len1+len2)*sizeof(char),&obj->prefix);
127: PetscStrcpy(obj->prefix,prefix);
128: PetscStrcat(obj->prefix,buf);
129: PetscFree(buf);
130: return(0);
131: }