Search the web
Sign In
New User? Sign Up
ClearSilver
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Show off your group to the world. Share a photo of your group with us.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Attribute retrieving function for templates   Message List  
Reply | Forward Message #1171 of 1347 |
Hello All,

As you all probably know there is no HDF node attribute manipulating
facilities for templates. It may be so because nobody needs them, but, well,
it seems we need them. So I've just implemented a prototype function for
retrieving HDF node attributes.

I'm not sure if it is the most proper way of doing this, and I'm not
proposing it for inclusion in the project, but it works. So in case somebody
else needs it, here is the patch.

---:<---
Index: cs/csparse.c
===================================================================
--- cs/csparse.c (revision 48632)
+++ cs/csparse.c (working copy)
@@ -3636,6 +3636,57 @@
return STATUS_OK;
}

+
+/* Retrieve variable attribute */
+static NEOERR * _builtin_attr(CSPARSE *parse, CS_FUNCTION *csf, CSARG *arg,
CSARG *result)
+{
+ NEOERR *err;
+ CSARG node;
+ char *attr_name;
+ HDF *obj;
+ HDF_ATTR *attr;
+
+ /* Evaluate first (node) argument */
+ memset(&node, 0, sizeof(node));
+ err = eval_expr(parse, arg, &node);
+ if (err) return nerr_pass(err);
+
+ /* Evaluate second (attribute name) argument and convert to string */
+ memset(&attr, 0, sizeof(attr));
+ err = cs_arg_parse(parse, arg->next, "s", &attr_name);
+ if (err)
+ {
+ if (node.alloc) free(node.s);
+ return nerr_pass(err);
+ }
+
+ /* NOTE: assuming "result" is zeroed for us */
+ result->op_type = CS_TYPE_STRING;
+ result->s = "";
+
+ /* If the node argument is a node name and there is an attribute name */
+ if ((node.op_type & CS_TYPE_VAR) && attr_name != NULL)
+ {
+ /* Lookup node */
+ obj = var_lookup_obj(parse, node.s);
+
+ /* Lookup node attribute */
+ for (attr = hdf_obj_attr(obj); attr != NULL; attr = attr->next)
+ if (strcmp(attr->key, attr_name) == 0)
+ {
+ if (attr->value != NULL)
+ result->s = attr->value;
+ break;
+ }
+ }
+
+ free(attr_name);
+ if (node.alloc) free(node.s);
+
+ return STATUS_OK;
+}
+
+
/* Check to see if a local variable is the first in an each/loop sequence */
static NEOERR * _builtin_first(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args,
CSARG *result)
@@ -3987,6 +4038,7 @@
{ "len", 1, _builtin_subcount },
{ "subcount", 1, _builtin_subcount },
{ "name", 1, _builtin_name },
+ { "attr", 2, _builtin_attr },
{ "first", 1, _builtin_first },
{ "last", 1, _builtin_last },
{ "abs", 1, _builtin_abs },
--->:---

Sincerely,
Nick



Fri Mar 28, 2008 6:59 am

nikolai.kond...
Offline Offline
Send Email Send Email

Forward
Message #1171 of 1347 |
Expand Messages Author Sort by Date

Hello All, As you all probably know there is no HDF node attribute manipulating facilities for templates. It may be so because nobody needs them, but, well, it...
Nikolai Kondrashov
nikolai.kond...
Offline Send Email
Mar 28, 2008
7:00 am

... Oh, and here is how you use it: <?cs var:attr(variable, "attr_name") ?> Sincerely, Nick...
Nikolai Kondrashov
nikolai.kond...
Offline Send Email
Mar 28, 2008
7:02 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help