help-gnats
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH]: FTYPINFO command


From: Yngve Svendsen
Subject: [PATCH]: FTYPINFO command
Date: Wed, 31 Oct 2001 00:35:22 +0100

Attached is a set of patches which implements the FTYPINFO command. See my comments below.

At 23:29 29.10.2001 +0100, Milan Zamazal wrote:
OK.  So the command format could be

  FTYPINFO <field> <option>

I changed this slightly to

FTYPINFO <field> <property>

as I already suggested.  As for the return values, I think we will cope
with basically two situations: A single one-line return value or a list
of one-line return values.  So the response should be in correspondence
with the description of the 3xx responses in the gnatsd command
protocol, distinguishing the two cases by return codes.

I can't see any reason why we should distinguish between the case when there is a single separator and cases when there are multiple? The attached set of patches makes gnatsd return a string og all the separators, enclosed in 'single quotes'.

I think that for now it would be sufficient to modify your FSEP patch.
A test for <option> depending on the field type should be added.  IMHO
we needn't add now more than the support for the `separators' option of
multi-enum fields.

The way I implemented this is not as elegant as it should be -- ideally, I would go for including supported properties for each field type in the FieldTypeInfo struct as that would make things far cleaner and more extensible. However, I opted for the simplest way this time round.

- Yngve

Index: cmds.c
===================================================================
RCS file: /cvs/gnats/gnats/gnats/cmds.c,v
retrieving revision 1.61
diff -u -p -r1.61 cmds.c
--- cmds.c      2001/10/14 20:32:22     1.61
+++ cmds.c      2001/10/30 23:18:57
@@ -1496,6 +1496,55 @@ GNATS_ftyp (int ac, char **av)
 }

 void
+GNATS_ftypinfo (int ac, char **av)
+{
+  if (ac == 2)
+    {
+      FieldIndex fnum = find_field_index (currentDatabase, av[0]);
+
+      if (fnum == InvalidFieldIndex)
+        {
+          printf ("%d No such field as `%s'.\r\n", CODE_INVALID_FIELD_NAME,
+                  av[0]);
+          return;
+        }
+
+      if (strcmp(av[1], "separators") == 0) {
+        if (fieldDefForIndex (fnum)->datatype == MultiEnum)
+          {
+            const char *sep = fieldDefForIndex (fnum)->multiEnumSeparator;
+
+            if (sep == NULL)
+              {
+                sep = ": ";
+              }
+
+            printf ("%d '%s'\r\n", CODE_INFORMATION, sep);
+          }
+        else if (fieldDefForIndex (fnum)->datatype != MultiEnum)
+          {
+            printf ("%d Property `%s' not defined for field type `%s'.\r\n",
+                    CODE_INVALID_FTYPE_PROPERTY, av[1],
+                    fieldTypeAsString (fieldDefForIndex (fnum)->datatype));
+          }
+      }
+
+      /* Unknown property: */
+      else
+        {
+          printf ("%d No such property as `%s'.\r\n",
+                  CODE_INVALID_FTYPE_PROPERTY, av[1]);
+        }
+    }
+
+  else
+    {
+      printf ("%d Need two arguments, fieldname and property.\r\n",
+              CODE_CMD_ERROR);
+    }
+}
+
+void
 GNATS_fdsc (int ac, char **av)
 {
   int x;
@@ -1675,6 +1724,12 @@ GNATS_help (int ac ATTRIBUTE_UNUSED, cha
          CODE_INFORMATION);
   printf ("%d-   FTYP <field>            return the datatype of <field>\r\n",
          CODE_INFORMATION);
+  printf ("%d-   FTYPINFO <field> <property>\r\n",
+      CODE_INFORMATION);
+ printf ("%d- return info about a property of the\r\n",
+      CODE_INFORMATION);
+  printf ("%d-                           specified field\r\n",
+      CODE_INFORMATION);
printf ("%d- FDSC <field> return the description of <field>\r\n",
          CODE_INFORMATION);
printf ("%d- FVLD <field> return a string or regexp describing the\r\n",
Index: gnatsd.c
===================================================================
RCS file: /cvs/gnats/gnats/gnats/gnatsd.c,v
retrieving revision 1.42
diff -u -p -r1.42 gnatsd.c
--- gnatsd.c    2001/10/14 20:32:22     1.42
+++ gnatsd.c    2001/10/30 23:18:57
@@ -156,7 +156,7 @@ static Command cmds[] =
      that matches the specified key.  If a subfield is also specified, only
      the data in that subfield is returned. */
   { "ADMV", GNATS_admv, ACCESS_VIEW, FALSE },
-
+  { "FTYPINFO", GNATS_ftypinfo, ACCESS_VIEW, FALSE},
   { NULL, NULL, -1, FALSE },
 };

Index: gnatsd.h
===================================================================
RCS file: /cvs/gnats/gnats/gnats/gnatsd.h,v
retrieving revision 1.25
diff -u -p -r1.25 gnatsd.h
--- gnatsd.h    2001/10/14 20:32:22     1.25
+++ gnatsd.h    2001/10/30 23:18:57
@@ -103,6 +103,7 @@ extern void GNATS_ftyp (int ac, char **a
 extern void GNATS_fdsc (int ac, char **av);
 extern void GNATS_fvld (int ac, char **av);
 extern void GNATS_admv (int ac, char **av);
+extern void GNATS_ftypinfo (int ac, char **av);
 extern void GNATS_editaddr (int ac, char **av);
 extern void GNATS_fieldflags (int ac, char **av);
 extern void GNATS_inputdefault (int ac, char **av);
Index: pcodes.h
===================================================================
RCS file: /cvs/gnats/gnats/gnats/pcodes.h,v
retrieving revision 1.9
diff -u -p -r1.9 pcodes.h
--- pcodes.h    2000/03/17 04:31:08     1.9
+++ pcodes.h    2001/10/30 23:18:57
@@ -57,6 +57,7 @@ Software Foundation, 59 Temple Place - S
 #define CODE_GNATS_NOT_LOCKED          432
 #define CODE_PR_NOT_LOCKED             433
 #define CODE_READONLY_FIELD            434
+#define CODE_INVALID_FTYPE_PROPERTY 435
 #define CODE_CMD_ERROR                 440
 #define CODE_WRITE_PR_FAILED           450




reply via email to

[Prev in Thread] Current Thread [Next in Thread]