[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/classdef classdef.c classdef.h gc...
From: |
Reinhard Mueller |
Subject: |
gnue/geas/src/classdef classdef.c classdef.h gc... |
Date: |
Sat, 29 Sep 2001 13:16:10 -0400 |
CVSROOT: /cvsroot/gnue
Module name: gnue
Changes by: Reinhard Mueller <address@hidden> 01/09/29 13:16:10
Modified files:
geas/src/classdef: classdef.c classdef.h gcdinfo.c parse.y
Log message:
Included datatype and format information.
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/classdef.c.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/classdef.h.diff?tr1=1.12&tr2=1.13&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/gcdinfo.c.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/gnue/geas/src/classdef/parse.y.diff?tr1=1.14&tr2=1.15&r1=text&r2=text
Patches:
Index: gnue/geas/src/classdef/classdef.c
diff -u gnue/geas/src/classdef/classdef.c:1.15
gnue/geas/src/classdef/classdef.c:1.16
--- gnue/geas/src/classdef/classdef.c:1.15 Sat Sep 29 10:26:44 2001
+++ gnue/geas/src/classdef/classdef.c Sat Sep 29 13:16:10 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: classdef.c,v 1.15 2001/09/29 14:26:44 reinhard Exp $
+ $Id: classdef.c,v 1.16 2001/09/29 17:16:10 reinhard Exp $
*/
#include "config.h"
@@ -506,10 +506,10 @@
f->parent = c->fields;
f->name = g_strdup (name);
f->name_full = g_strconcat (m->name, "::", name, NULL);
- f->name_db = g_strconcat (m->name, "__", name, NULL);
if (type)
{
+ f->name_db = g_strconcat (m->name, "__", name, NULL);
f->datatype = type->datatype;
f->format = type->format;
f->refclass = type->refclass;
@@ -642,39 +642,6 @@
}
/* ------------------------------------------------------------------------- *\
- * Get the datatype of a type
-\* ------------------------------------------------------------------------- */
-geas_cd_datatype
-geas_cd_type_get_datatype (const geas_cd_type *t)
-{
- g_return_val_if_fail (t, GEAS_CD_DATATYPE_UNKNOWN);
-
- return (t->datatype);
-}
-
-/* ------------------------------------------------------------------------- *\
- * Get the format of a type (the length if it is a char, zero otherwise)
-\* ------------------------------------------------------------------------- */
-int
-geas_cd_type_get_format (const geas_cd_type *t)
-{
- g_return_val_if_fail (t, 0);
-
- return (t->format);
-}
-
-/* ------------------------------------------------------------------------- *\
- * Get the class a type references, or NULL if it is not a reference or list
-\* ------------------------------------------------------------------------- */
-geas_cd_class *
-geas_cd_type_get_refclass (const geas_cd_type *t)
-{
- g_return_val_if_fail (t, NULL);
-
- return (t->refclass);
-}
-
-/* ------------------------------------------------------------------------- *\
* Allocate a new field as a member of a type
* One of the parameters type, reference or list must be filled in
\* ------------------------------------------------------------------------- */
@@ -853,6 +820,18 @@
\* ========================================================================= */
/* ------------------------------------------------------------------------- *\
+ * Set the format of a char field
+\* ------------------------------------------------------------------------- */
+void
+geas_cd_field_set_format (geas_cd_field *f, int format)
+{
+ g_return_if_fail (f);
+ g_return_if_fail (format > 0);
+
+ f->format = format;
+}
+
+/* ------------------------------------------------------------------------- *\
* Get the name of the field without module prefix
\* ------------------------------------------------------------------------- */
const char *
@@ -872,6 +851,39 @@
g_return_val_if_fail (f, NULL);
return (f->name_full);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Get the datatype of a field
+\* ------------------------------------------------------------------------- */
+geas_cd_datatype
+geas_cd_field_get_datatype (const geas_cd_field *f)
+{
+ g_return_val_if_fail (f, GEAS_CD_DATATYPE_UNKNOWN);
+
+ return (f->datatype);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Get the format of a field (the length if it is a char, zero otherwise)
+\* ------------------------------------------------------------------------- */
+int
+geas_cd_field_get_format (const geas_cd_field *f)
+{
+ g_return_val_if_fail (f, 0);
+
+ return (f->format);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Get the class a field references, or NULL if it is not a reference or list
+\* ------------------------------------------------------------------------- */
+geas_cd_class *
+geas_cd_field_get_refclass (const geas_cd_field *f)
+{
+ g_return_val_if_fail (f, NULL);
+
+ return (f->refclass);
}
/* ------------------------------------------------------------------------- *\
Index: gnue/geas/src/classdef/classdef.h
diff -u gnue/geas/src/classdef/classdef.h:1.12
gnue/geas/src/classdef/classdef.h:1.13
--- gnue/geas/src/classdef/classdef.h:1.12 Sat Sep 29 10:26:44 2001
+++ gnue/geas/src/classdef/classdef.h Sat Sep 29 13:16:10 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: classdef.h,v 1.12 2001/09/29 14:26:44 reinhard Exp $
+ $Id: classdef.h,v 1.13 2001/09/29 17:16:10 reinhard Exp $
*/
/* ------------------------------------------------------------------------- *\
@@ -122,9 +122,6 @@
const char *geas_cd_type_get_name (const geas_cd_type *t);
const char *geas_cd_type_get_name_full (const geas_cd_type *t);
const char *geas_cd_type_get_filename (const geas_cd_type *t);
-geas_cd_datatype geas_cd_type_get_datatype (const geas_cd_type *t);
-int geas_cd_type_get_format (const geas_cd_type *t);
-geas_cd_class *geas_cd_type_get_refclass (const geas_cd_type *t);
geas_cd_field *geas_cd_type_field_new (geas_cd_type *t, const char *name,
const geas_cd_type *type,
geas_cd_class *reference,
@@ -137,7 +134,6 @@
* Fieldlists
\* ------------------------------------------------------------------------- */
-geas_cd_fieldlist *geas_cd_fieldlist_new (void);
geas_cd_field *geas_cd_fieldlist_next (geas_cd_fieldlist *fl);
void geas_cd_fieldlist_free (geas_cd_fieldlist *fl);
@@ -148,6 +144,10 @@
#define GEAS_CD_FPROP_NOTNULL 0x0001;
#define GEAS_CD_FPROP_READONLY 0x0002;
-const char *geas_cd_field_get_name (const geas_cd_field *f);
-const char *geas_cd_field_get_name_full (const geas_cd_field *f);
-void geas_cd_field_free (geas_cd_field *f);
+void geas_cd_field_set_format (geas_cd_field *f, int format);
+const char *geas_cd_field_get_name (const geas_cd_field *f);
+const char *geas_cd_field_get_name_full (const geas_cd_field *f);
+geas_cd_datatype geas_cd_field_get_datatype (const geas_cd_field *f);
+int geas_cd_field_get_format (const geas_cd_field *f);
+geas_cd_class *geas_cd_field_get_refclass (const geas_cd_field *f);
+void geas_cd_field_free (geas_cd_field *f);
Index: gnue/geas/src/classdef/gcdinfo.c
diff -u gnue/geas/src/classdef/gcdinfo.c:1.3
gnue/geas/src/classdef/gcdinfo.c:1.4
--- gnue/geas/src/classdef/gcdinfo.c:1.3 Fri Sep 28 17:44:58 2001
+++ gnue/geas/src/classdef/gcdinfo.c Sat Sep 29 13:16:10 2001
@@ -19,13 +19,16 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: gcdinfo.c,v 1.3 2001/09/28 21:44:58 reinhard Exp $
+ $Id: gcdinfo.c,v 1.4 2001/09/29 17:16:10 reinhard Exp $
*/
#include <stdio.h>
#include "classdef.h"
#include "read-gcd.h"
+/* ------------------------------------------------------------------------- *\
+ * Main program
+\* ------------------------------------------------------------------------- */
int main (void)
{
geas_cd_classlist *cl;
@@ -39,15 +42,72 @@
cl = geas_cd_classlist_new ();
while ((c = geas_cd_classlist_next (cl)))
{
- printf ("===========================================================\n");
+ printf ("==============================================================="
+ "================\n");
printf ("CLASS %s [%s]\n(file %s)\n", geas_cd_class_get_name_full (c),
geas_cd_class_get_name_db (c), geas_cd_class_get_filename (c));
- printf ("-----------------------------------------------------------\n");
+ printf ("---------------------------------------------------------------"
+ "----------------\n");
+ printf ("Field name Field Type "
+ " \n");
+ printf ("---------------------------------------------------------------"
+ "----------------\n");
fl = geas_cd_class_fieldlist_new (c);
while ((f = geas_cd_fieldlist_next (fl)))
{
- printf ("FIELD %s\n", geas_cd_field_get_name_full (f));
+ printf ("%-32s ", geas_cd_field_get_name_full (f));
+ switch (geas_cd_field_get_datatype (f))
+ {
+ case GEAS_CD_DATATYPE_CHAR:
+ printf ("char<%3d> ",
+ geas_cd_field_get_format (f));
+ break;
+ case GEAS_CD_DATATYPE_TEXT:
+ printf ("text ");
+ break;
+ case GEAS_CD_DATATYPE_INT16:
+ printf ("int16 ");
+ break;
+ case GEAS_CD_DATATYPE_INT32:
+ printf ("int32 ");
+ break;
+ case GEAS_CD_DATATYPE_INT64:
+ printf ("int64 ");
+ break;
+ case GEAS_CD_DATATYPE_FLOAT:
+ printf ("float ");
+ break;
+ case GEAS_CD_DATATYPE_BOOL:
+ printf ("bool ");
+ break;
+ case GEAS_CD_DATATYPE_DATE:
+ printf ("date ");
+ break;
+ case GEAS_CD_DATATYPE_TIME:
+ printf ("time ");
+ break;
+ case GEAS_CD_DATATYPE_DATETIME:
+ printf ("datetime ");
+ break;
+ case GEAS_CD_DATATYPE_REFERENCE:
+ printf ("ref. to %-32s",
+ geas_cd_class_get_name_full (geas_cd_field_get_refclass (f)));
+ break;
+ case GEAS_CD_DATATYPE_LIST:
+ printf ("list of %-32s",
+ geas_cd_class_get_name_full (geas_cd_field_get_refclass (f)));
+ break;
+ case GEAS_CD_DATATYPE_COMPOUND:
+ printf ("compound field ");
+ break;
+ default:
+ printf ("unknown field type ");
+ }
+ printf ("\n");
}
+ printf ("==============================================================="
+ "================\n");
+ printf ("\n");
geas_cd_fieldlist_free (fl);
}
geas_cd_classlist_free (cl);
Index: gnue/geas/src/classdef/parse.y
diff -u gnue/geas/src/classdef/parse.y:1.14 gnue/geas/src/classdef/parse.y:1.15
--- gnue/geas/src/classdef/parse.y:1.14 Sat Sep 29 10:26:44 2001
+++ gnue/geas/src/classdef/parse.y Sat Sep 29 13:16:10 2001
@@ -19,7 +19,7 @@
along with GEAS; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- $Id: parse.y,v 1.14 2001/09/29 14:26:44 reinhard Exp $
+ $Id: parse.y,v 1.15 2001/09/29 17:16:10 reinhard Exp $
*/
%{
@@ -77,6 +77,9 @@
static void _set_type_list (geas_cd_class *clss);
static gboolean _new_field (const gchar *name);
+
+static gboolean _set_field_format (int format);
+
%}
/* ========================================================================= *\
@@ -267,7 +270,11 @@
;
format: /* */
- | '<' INTEGER '>' { /* TODO */ }
+ | '<' INTEGER '>' {
+ gboolean result;
+ result = _set_field_format ($2);
+ if (!result) YYERROR
+ }
;
fdefault: /* */
@@ -813,6 +820,34 @@
}
}
break;
+
+ default:
+ g_assert_not_reached ();
+ return (FALSE);
+ }
+}
+
+/* ------------------------------------------------------------------------- *\
+ * Set the format of the current field
+\* ------------------------------------------------------------------------- */
+static gboolean
+_set_field_format (int format)
+{
+ switch (_current_pass)
+ {
+ case 1:
+ return (TRUE);
+ break;
+
+ case 2:
+ if ((geas_cd_field_get_datatype (_current_field) !=
GEAS_CD_DATATYPE_CHAR)
+ || (geas_cd_field_get_format (_current_field) != 0))
+ {
+ yyerror ("no format allowed for this type");
+ return (FALSE);
+ }
+ geas_cd_field_set_format (_current_field, format);
+ return (TRUE);
default:
g_assert_not_reached ();