summaryrefslogtreecommitdiffstats
path: root/Source/CursesDialog/form/fty_ipv4.c
diff options
context:
space:
mode:
authorBerk Geveci <berk.geveci@kitware.com>2001-11-05 16:53:05 (GMT)
committerBerk Geveci <berk.geveci@kitware.com>2001-11-05 16:53:05 (GMT)
commitcd7297781d13d8a99c58fbb301cf32b69fd8fb14 (patch)
tree1ba7adade9196e8575ac73399f78bbf2c711b6f2 /Source/CursesDialog/form/fty_ipv4.c
parentc09d072be3726ed3727d2154cfd031772d01ecf6 (diff)
downloadCMake-cd7297781d13d8a99c58fbb301cf32b69fd8fb14.zip
CMake-cd7297781d13d8a99c58fbb301cf32b69fd8fb14.tar.gz
CMake-cd7297781d13d8a99c58fbb301cf32b69fd8fb14.tar.bz2
Adding form library.
Diffstat (limited to 'Source/CursesDialog/form/fty_ipv4.c')
-rw-r--r--Source/CursesDialog/form/fty_ipv4.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/Source/CursesDialog/form/fty_ipv4.c b/Source/CursesDialog/form/fty_ipv4.c
new file mode 100644
index 0000000..d7f2296
--- /dev/null
+++ b/Source/CursesDialog/form/fty_ipv4.c
@@ -0,0 +1,81 @@
+
+/*
+ * THIS CODE IS SPECIFICALLY EXEMPTED FROM THE NCURSES PACKAGE COPYRIGHT.
+ * You may freely copy it for use as a template for your own field types.
+ * If you develop a field type that might be of general use, please send
+ * it back to the ncurses maintainers for inclusion in the next version.
+ */
+/***************************************************************************
+* *
+* Author : Per Foreby, perf@efd.lth.se *
+* *
+***************************************************************************/
+
+#include "form.priv.h"
+
+MODULE_ID("$Id$")
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_IPV4_Field(
+| FIELD * field,
+| const void * argp)
+|
+| Description : Validate buffer content to be a valid IP number (Ver. 4)
+|
+| Return Values : TRUE - field is valid
+| FALSE - field is invalid
++--------------------------------------------------------------------------*/
+static bool Check_IPV4_Field(FIELD * field, const void * argp)
+{
+ char *bp = field_buffer(field,0);
+ int num = 0, len;
+ unsigned int d1, d2, d3, d4;
+
+ if(isdigit(*bp)) /* Must start with digit */
+ {
+ num = sscanf(bp, "%u.%u.%u.%u%n", &d1, &d2, &d3, &d4, &len);
+ if (num == 4)
+ {
+ bp += len; /* Make bp point to what sscanf() left */
+ while (*bp && isspace(*bp))
+ bp++; /* Allow trailing whitespace */
+ }
+ }
+ return ((num != 4 || *bp || d1 > 255 || d2 > 255
+ || d3 > 255 || d4 > 255) ? FALSE : TRUE);
+}
+
+/*---------------------------------------------------------------------------
+| Facility : libnform
+| Function : static bool Check_IPV4_Character(
+| int c,
+| const void *argp )
+|
+| Description : Check a character for unsigned type or period.
+|
+| Return Values : TRUE - character is valid
+| FALSE - character is invalid
++--------------------------------------------------------------------------*/
+static bool Check_IPV4_Character(int c, const void * argp)
+{
+ return ((isdigit(c) || (c=='.')) ? TRUE : FALSE);
+}
+
+static FIELDTYPE typeIPV4 = {
+ _RESIDENT,
+ 1, /* this is mutable, so we can't be const */
+ (FIELDTYPE *)0,
+ (FIELDTYPE *)0,
+ NULL,
+ NULL,
+ NULL,
+ Check_IPV4_Field,
+ Check_IPV4_Character,
+ NULL,
+ NULL
+};
+
+FIELDTYPE* TYPE_IPV4 = &typeIPV4;
+
+/* fty_ipv4.c ends here */