aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2003-12-29 05:47:59 -0800
committerLinus Torvalds <torvalds@home.osdl.org>2003-12-29 05:47:59 -0800
commitadf9a351f27edbaf434ab450f8c09e784ca1cf78 (patch)
tree7f68340bdab95a2df4d8ee8c3a2db8b99dccd70d /lib
parentcb8d8fe991409fd5c017e35c68274e2967451247 (diff)
downloadhistory-adf9a351f27edbaf434ab450f8c09e784ca1cf78.tar.gz
[PATCH] Add lib/parser.c kernel-doc
From: Will Dyson <will_dyson@pobox.com> Add documentation and comments to lib/parser.c and include/linux/parser.h
Diffstat (limited to 'lib')
-rw-r--r--lib/parser.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/lib/parser.c b/lib/parser.c
index 790ec2a858d7e8..761a57a6e9db58 100644
--- a/lib/parser.c
+++ b/lib/parser.c
@@ -11,6 +11,17 @@
#include <linux/slab.h>
#include <linux/string.h>
+/**
+ * match_one: - Determines if a string matches a simple pattern
+ * @s: the string to examine for presense of the pattern
+ * @p: the string containing the pattern
+ * @args: array of %MAX_OPT_ARGS &substring_t elements. Used to return match
+ * locations.
+ *
+ * Description: Determines if the pattern @p is present in string @s. Can only
+ * match extremely simple token=arg style patterns. If the pattern is found,
+ * the location(s) of the arguments will be returned in the @args array.
+ */
static int match_one(char *s, char *p, substring_t args[])
{
char *meta;
@@ -74,6 +85,20 @@ static int match_one(char *s, char *p, substring_t args[])
}
}
+/**
+ * match_token: - Find a token (and optional args) in a string
+ * @s: the string to examine for token/argument pairs
+ * @table: match_table_t describing the set of allowed option tokens and the
+ * arguments that may be associated with them. Must be terminated with a
+ * &struct match_token whose pattern is set to the NULL pointer.
+ * @args: array of %MAX_OPT_ARGS &substring_t elements. Used to return match
+ * locations.
+ *
+ * Description: Detects which if any of a set of token strings has been passed
+ * to it. Tokens can include up to MAX_OPT_ARGS instances of basic c-style
+ * format identifiers which will be taken into account when matching the
+ * tokens, and whose locations will be returned in the @args array.
+ */
int match_token(char *s, match_table_t table, substring_t args[])
{
struct match_token *p;
@@ -84,6 +109,16 @@ int match_token(char *s, match_table_t table, substring_t args[])
return p->token;
}
+/**
+ * match_number: scan a number in the given base from a substring_t
+ * @s: substring to be scanned
+ * @result: resulting integer on success
+ * @base: base to use when converting string
+ *
+ * Description: Given a &substring_t and a base, attempts to parse the substring
+ * as a number in that base. On success, sets @result to the integer represented
+ * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
static int match_number(substring_t *s, int *result, int base)
{
char *endp;
@@ -103,27 +138,71 @@ static int match_number(substring_t *s, int *result, int base)
return ret;
}
+/**
+ * match_int: - scan a decimal representation of an integer from a substring_t
+ * @s: substring_t to be scanned
+ * @result: resulting integer on success
+ *
+ * Description: Attempts to parse the &substring_t @s as a decimal integer. On
+ * success, sets @result to the integer represented by the string and returns 0.
+ * Returns either -ENOMEM or -EINVAL on failure.
+ */
int match_int(substring_t *s, int *result)
{
return match_number(s, result, 0);
}
+/**
+ * match_octal: - scan an octal representation of an integer from a substring_t
+ * @s: substring_t to be scanned
+ * @result: resulting integer on success
+ *
+ * Description: Attempts to parse the &substring_t @s as an octal integer. On
+ * success, sets @result to the integer represented by the string and returns
+ * 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
int match_octal(substring_t *s, int *result)
{
return match_number(s, result, 8);
}
+/**
+ * match_hex: - scan a hex representation of an integer from a substring_t
+ * @s: substring_t to be scanned
+ * @result: resulting integer on success
+ *
+ * Description: Attempts to parse the &substring_t @s as a hexadecimal integer.
+ * On success, sets @result to the integer represented by the string and
+ * returns 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
int match_hex(substring_t *s, int *result)
{
return match_number(s, result, 16);
}
+/**
+ * match_strcpy: - copies the characters from a substring_t to a string
+ * @to: string to copy characters to.
+ * @s: &substring_t to copy
+ *
+ * Description: Copies the set of characters represented by the given
+ * &substring_t @s to the c-style string @to. Caller guarantees that @to is
+ * large enough to hold the characters of @s.
+ */
void match_strcpy(char *to, substring_t *s)
{
memcpy(to, s->from, s->to - s->from);
to[s->to - s->from] = '\0';
}
+/**
+ * match_strdup: - allocate a new string with the contents of a substring_t
+ * @s: &substring_t to copy
+ *
+ * Description: Allocates and returns a string filled with the contents of
+ * the &substring_t @s. The caller is responsible for freeing the returned
+ * string with kfree().
+ */
char *match_strdup(substring_t *s)
{
char *p = kmalloc(s->to - s->from + 1, GFP_KERNEL);