]> granicus.if.org Git - graphviz/commitdiff
Add kindOf function, plus functions to set and get default values
authorerg <devnull@localhost>
Thu, 9 Feb 2006 22:14:50 +0000 (22:14 +0000)
committererg <devnull@localhost>
Thu, 9 Feb 2006 22:14:50 +0000 (22:14 +0000)
cmd/gvpr/compile.c
cmd/gvpr/gprdata
cmd/gvpr/gvpr.1

index e89ce3d3a480688cb0a1d6ce8e2c9014c8d6d5d1..30c5e27d4c52011406ecae4bbdf93e3c93a43aff 100644 (file)
@@ -418,6 +418,65 @@ static char *getArg(int n, Gpr_t * state)
     return (state->argv[n]);
 }
 
+/* setDfltAttr:
+ */
+static int
+setDfltAttr (Agraph_t *gp, char* k, char* name, char* value)
+{
+    Agsym_t* sym;
+    int kind;
+
+    switch (*k) {
+    case 'G' :
+       kind = AGRAPH;
+       break;
+    case 'E' :
+       kind = AGEDGE;
+       break;
+    case 'N' :
+       kind = AGNODE;
+       break;
+    default :
+       error(ERROR_WARNING, "Unknown kind \"%s\" passed to setDflt()", k);
+       return 1;
+       break;
+    }
+    sym = agattr(gp, kind, name, 0);
+    if (!sym)
+       sym = agattr(gp, kind, name, "");
+
+    agattr(gp, kind, name, value);
+    return 0;
+}
+
+/* getDfltAttr:
+ */
+static char*
+getDfltAttr (Agraph_t *gp, char* k, char* name)
+{
+    int      kind;
+    Agsym_t* sym;
+
+    switch (*k) {
+    case 'G' :
+       kind = AGRAPH;
+       break;
+    case 'E' :
+       kind = AGEDGE;
+       break;
+    case 'N' :
+       kind = AGNODE;
+       break;
+    default :
+       error(ERROR_WARNING, "Unknown kind \"%s\" passed to getDflt()", k);
+       return 0;
+       break;
+    }
+    sym = agattr (gp, kind, name, 0);
+    if (sym) return sym->defval; 
+    else return 0;
+}
+
 /* getval:
  * Return value associated with gpr identifier.
  */
@@ -556,6 +615,24 @@ getval(Expr_t * pgm, Exnode_t * node, Exid_t * sym, Exref_t * ref,
            } else
                v.integer = PTR2INT(compOf(gp, np));
            break;
+       case F_kindof:
+           objp = INT2PTR(Agobj_t *, args[0].integer);
+           if (!objp) {
+               error(ERROR_WARNING, "NULL object passed to kindOf()");
+               v.string = 0;
+           } else switch (AGTYPE(objp)) {
+               case AGRAPH :
+                   v.string = "G";
+                   break;
+               case AGNODE :
+                   v.string = "N";
+                   break;
+               case AGINEDGE :
+               case AGOUTEDGE :
+                   v.string = "E";
+                   break;
+           }
+           break;
        case F_edge:
            key = args[2].string;
            if (*key == '\0')
@@ -826,13 +903,13 @@ getval(Expr_t * pgm, Exnode_t * node, Exid_t * sym, Exref_t * ref,
            objp = INT2PTR(Agobj_t *, args[0].integer);
            if (!objp) {
                error(ERROR_WARNING, "NULL object passed to aget()");
-               v.string = exstring(pgm, "");
+               v.string = 0;
            } else {
                char* name = args[1].string;
                if (name) v.string = agget(objp, name);
                else {
                    error(ERROR_WARNING, "NULL name passed to aget()");
-                   v.string = exstring(pgm, "");
+                   v.string = 0;
                }
             }
            break;
@@ -857,6 +934,53 @@ getval(Expr_t * pgm, Exnode_t * node, Exid_t * sym, Exref_t * ref,
                }
             }
            break;
+       case F_dset:
+           gp = INT2PTR(Agraph_t *, args[0].integer);
+           if (gp) {
+               char* kind = args[1].string;
+               char* name = args[2].string;
+               char* value = args[3].string;
+               if (!name) {
+                   error(ERROR_WARNING, "NULL name passed to setDflt()");
+                   v.integer = 1;
+               }
+               else if (!value) {
+                   error(ERROR_WARNING, "NULL value passed to setDflt()");
+                   v.integer = 1;
+               }
+               else if (!kind) {
+                   error(ERROR_WARNING, "NULL kind passed to setDflt()");
+                   v.integer = 1;
+               }
+               else {
+                   v.integer = setDfltAttr(gp, kind, name, value);
+               }
+           } else {
+               error(ERROR_WARNING, "NULL graph passed to node()");
+               v.integer = 0;
+           }
+           break;
+       case F_dget:
+           gp = INT2PTR(Agraph_t *, args[0].integer);
+           if (gp) {
+               char* kind = args[1].string;
+               char* name = args[2].string;
+               if (!name) {
+                   error(ERROR_WARNING, "NULL name passed to getDflt()");
+                   v.string = 0;
+               }
+               else if (!kind) {
+                   error(ERROR_WARNING, "NULL kind passed to getDflt()");
+                   v.string = 0;
+               }
+               else {
+                   v.string = getDfltAttr(gp, kind, name);
+               }
+           } else {
+               error(ERROR_WARNING, "NULL graph passed to node()");
+               v.string = 0;
+           }
+           break;
        case F_canon:
            v.string = canon(pgm, args[0].string);
            break;
index 74b22af3b1686f9e3411715452ba18241cb2ea66..cbade5b7e57a425e53c4684a08b1be5abab06081 100644 (file)
@@ -45,6 +45,7 @@ F_nxtin     "nxtin"     FUNCTION E|A(1,E)
 F_fstedge   "fstedge"   FUNCTION E|A(1,V)
 F_nxtedge   "nxtedge"   FUNCTION E|A(1,E)|A(2,V)
 F_compof    "compOf"    FUNCTION G|A(1,G)|A(2,V)
+F_kindof    "kindOf"    FUNCTION S|A(1,O)
 F_index     "index"     FUNCTION I|A(1,S)|A(2,S)
 F_isedge    "isEdge"    FUNCTION E|A(1,V)|A(2,V)|A(3,S)
 F_length    "length"    FUNCTION I|A(1,S)
@@ -81,6 +82,8 @@ F_urof      "urOf"      FUNCTION S|A(1,S)
 F_canon     "canon"     FUNCTION S|A(1,S)
 F_get       "aget"      FUNCTION S|A(1,O)|A(2,S)
 F_set       "aset"      FUNCTION I|A(1,O)|A(2,S)|A(3,S)
+F_dget      "getDflt"   FUNCTION S|A(1,G)|A(2,S)|A(3,S)
+F_dset      "setDflt"   FUNCTION I|A(1,G)|A(2,S)|A(3,S)|A(4,S)
 C_flat      "TV_flat"   CONSTANT T_tvtyp
 C_dfs       "TV_dfs"    CONSTANT T_tvtyp
 C_bfs       "TV_bfs"    CONSTANT T_tvtyp
index 8510133e512393d3bcea3f45ecf8d5ac11f20bd8..31909ade8e108ef5d4c359472c58ee11d0d89abd 100644 (file)
@@ -451,11 +451,25 @@ extends \fIg\fP to its node-induced subgraph extension in its root graph.
 returns the value of attribute \fIname\fP in object \fIsrc\fP. This is
 useful for those cases when \fIname\fP conflicts with one of the keywords
 such as "head" or "root".
+Returns \fBNULL\fP on failure or if the attribute is not defined.
 .TP
 \fBaset\fP(\fIsrc\fP : \fBobj_t\fP, \fIname\fP : \fBstring\fP, \fIvalue\fP : \fBstring\fP) : \fBint\fP
 sets the value of attribute \fIname\fP in object \fIsrc\fP to \fIvalue\fP.
 Returns 0 on success, non-zero on failure. See \fBaget\fP above.
 .TP
+\fBgetDflt\fP(\fIg\fP : \fBgraph_t\fP, \fIkind\fP : \fBstring\fP, \fIname\fP : \fBstring\fP) : \fBstring\fP
+returns the default value of attribute \fIname\fP in objects in \fIg\fP of
+the given \fIkind\fP. For nodes, edges, and graphs, \fIkind\fP
+should be "N", "E", and "G", respectively.
+Returns \fBNULL\fP on failure or if the attribute is not defined.
+.TP
+\fBsetDflt\fP(\fIg\fP : \fBgraph_t\fP, \fIkind\fP : \fBstring\fP, \fIname\fP : \fBstring\fP, \fIvalue\fP : \fBstring\fP) : \fBint\fP
+sets the default value of attribute \fIname\fP to \fIvalue\fP in 
+objects in \fIg\fP of
+the given \fIkind\fP. For nodes, edges, and graphs, \fIkind\fP
+should be "N", "E", and "G", respectively.
+Returns 0 on success, non-zero on failure. See \fBsetDflt\fP above.
+.TP
 \fBcompOf\fP(\fIg\fP : \fBgraph_t\fP, \fIn\fP : \fBnode_t\fP) : \fBgraph_t\fP
 returns the connected component of the graph \fIg\fP containing node \fIn\fP,
 as a subgraph of \fIg\fP. The subgraph only contains the nodes. One can
@@ -463,6 +477,11 @@ use \fIinduce\fP to add the edges. The function fails and returns \fBNULL\fP
 if \fIn\fP is not in \fIg\fP. Connectivity is based on the underlying
 undirected graph of \fIg\fP.
 .TP
+\fBkindOf\fP(\fIobj\fP : \fBobj_t\fP) : \fBstring\fP
+returns an indication of what kind of graph object is the argument.
+For nodes, edges, and graphs, it returns
+should be "N", "E", and "G", respectively.
+.TP
 \fBlock\fP(\fIg\fP : \fBgraph_t\fP, \fIv\fP : \fBint\fP) : \fBint\fP
 implements graph locking on root graphs. If the integer \fIv\fP is positive, the
 graph is set so that future calls to \fBdelete\fP have no immediate effect.