Index: libabac/abac_term.c
===================================================================
--- libabac/abac_term.c	(revision 8bd77b59df89993868555d3b87f91fc241b09228)
+++ libabac/abac_term.c	(revision d037f549d30de12f67357bdeb76c05f548342399)
@@ -30,8 +30,15 @@
 };
 
+/* termtype_t/name pair for the data terms
+   idtype_t/name/p_name pair for the named principal term
+*/
+   
 struct _abac_term_t {
     int type;
     char *name;
-    char *cn;
+    // e_TERM_PRINCIPAL isnamed
+    int isnamed;
+    char *p_name; 
+    char *cn; //XXX ?? might not need this at all
     abac_condition_t *constraint;
 }; 
@@ -48,5 +55,5 @@
     if(i>_condname_cnt)
         panic("abac_condtype_name: went out of range on condname");
-    return _condname[i];
+    return (char *) _condname[i];
 }
 
@@ -155,6 +162,15 @@
 /******************************************************************/
 
+int abac_term_isnamed(abac_term_t *term)
+{
+    if(term->isnamed) return 1;
+       else return 0;
+}
+
 char *abac_term_name(abac_term_t *term)
 {
+    if(ABAC_IN_PROLOG && term->p_name) {
+        return term->p_name;
+    }
     return term->name;
 }
@@ -170,14 +186,16 @@
 }
 
-char *abac_termtype_name(int i)
+char *abac_termtype_string(int i)
 {
     if(i>_termname_cnt)
-        panic("abac_termtype_name: went out of range on termname");
-    return _termname[i];
+        panic("abac_termtype_string: went out of range on termname");
+    return (char *) _termname[i];
 }
 
 char *abac_term_type_name(abac_term_t *term)
 {
-    return abac_termtype_name(term->type);
+    if(term->isnamed)
+        return abac_idtype_string(term->type);
+    return abac_termtype_string(term->type);
 }
 
@@ -262,5 +280,5 @@
      if(debug) {
          printf("abac_term_new: \n");
-         printf("  type is %d(%s)\n", type, abac_termtype_name(type));
+         printf("  type is %d(%s)\n", type, abac_termtype_string(type));
          printf("  name is (%s)\n", name);
          if(cond)
@@ -283,5 +301,7 @@
      }
      abac_term_t *ptr=abac_xmalloc(sizeof(abac_term_t));
+     ptr->isnamed=0;
      ptr->type=type;
+     ptr->p_name=NULL;
      /* reformat the term name if it is a time type */
      if((!constraint) && _abac_termtype_is_time_type(type) && isdigit(name[0])) {
@@ -292,4 +312,5 @@
      }
      ptr->constraint=constraint;
+     ptr->cn=NULL;
      return ptr;
 }
@@ -299,5 +320,5 @@
      if(debug) {
          printf("abac_term_create: \n");
-         printf("  type is %d(%s)\n", type, abac_termtype_name(type));
+         printf("  type is %d(%s)\n", type, abac_termtype_string(type));
          printf("  name is (%s)\n", name);
          if(cptr)
@@ -307,5 +328,7 @@
 
      abac_term_t *ptr=abac_xmalloc(sizeof(abac_term_t));
+     ptr->isnamed=0;
      ptr->type=type;
+     ptr->p_name=NULL;
      /* reformat the term name if it is a time type */
      if((!cptr) && _abac_termtype_is_time_type(type) && isdigit(name[0])) {
@@ -316,4 +339,47 @@
      }
      ptr->constraint=(cptr==NULL)?NULL:abac_condition_dup(cptr);
+     ptr->cn=NULL;
+     return ptr;
+}
+
+/* called from yy, named principal type */
+abac_term_t *abac_term_named_new(int idtype, char *name)
+{
+     if(debug) {
+         printf("abac_term_named_new: \n");
+         printf("  type is %d(%s)\n", idtype, abac_idtype_string(idtype));
+         printf("  name is (%s)\n", name);
+     }
+     abac_term_t *ptr=abac_xmalloc(sizeof(abac_term_t));
+     ptr->isnamed=1;
+     ptr->type=idtype;
+     ptr->name=abac_xstrdup(name);
+     ptr->p_name=NULL;
+     /* if ABAC_CN, no need to attach p */
+     if(!USE("ABAC_CN"))
+         asprintf(&ptr->p_name,"p%s",name);
+     ptr->constraint=NULL;
+     ptr->cn=NULL;
+     return ptr;
+}
+
+abac_term_t *abac_term_named_create(int idtype, char *name)
+{
+     if(debug) {
+         printf("abac_term_named_create: \n");
+         printf("  type is %d(%s)\n", idtype, abac_idtype_string(idtype));
+         printf("  name is (%s)\n", name);
+     }
+
+     abac_term_t *ptr=abac_xmalloc(sizeof(abac_term_t));
+     ptr->isnamed=1;
+     ptr->type=idtype;
+     ptr->name=abac_xstrdup(name);
+     ptr->p_name=NULL;
+     /* if ABAC_CN, no need to attach p */
+     if(!USE("ABAC_CN"))
+         asprintf(&ptr->p_name,"p%s",name);
+     ptr->constraint=NULL;
+     ptr->cn=NULL;
      return ptr;
 }
@@ -323,9 +389,13 @@
      assert(ptr);
      abac_term_t *nptr=abac_xmalloc(sizeof(abac_term_t));
+     nptr->isnamed=ptr->isnamed;
      nptr->type=ptr->type;
      nptr->name=abac_xstrdup(ptr->name);
+     nptr->p_name=(ptr->p_name==NULL)?NULL:abac_xstrdup(ptr->p_name);
      if(ptr->constraint!=NULL)
         nptr->constraint=abac_condition_dup(ptr->constraint);
         else nptr->constraint=NULL;
+     nptr->cn=(ptr->cn)==NULL?NULL:abac_xstrdup(ptr->cn);
+        nptr->cn=abac_xstrdup(ptr->cn);
      return nptr;
 }
@@ -337,4 +407,6 @@
     }
     free(ptr->name);
+    if(ptr->p_name) free(ptr->p_name);
+    if(ptr->cn) free(ptr->cn);
     free(ptr);
 }
@@ -384,33 +456,7 @@
 }
 
-/* len of name or name:cond */
-static int abac_term_len_with_condition(abac_term_t *ptr)
-{
-    char *cond=NULL;
-    char *name=ptr->name;
-    int len=strlen(name);
-    if(ptr->constraint) {
-       cond=abac_condition_string(ptr->constraint);
-       len=len+strlen(cond)+1;
-       free(cond); 
-    }
-    return len;
-}
-
-/* just name */
 char *abac_term_string(abac_term_t *ptr)
 {
-    return abac_xstrdup(ptr->name);
-}
-
-/* just len of name */
-static int abac_term_len(abac_term_t *ptr)
-{
-    /* including the 2 's */
-    if(ptr->type == abac_term_verify_term_type("urn") ||
-              ptr->type == abac_term_verify_term_type("string") ) {
-        return strlen(ptr->name)+2; 
-    }
-    return strlen(ptr->name);
+    return abac_xstrdup(abac_term_name(ptr));
 }
 
