* [patch 2/6] statistics infrastructure - prerequisite: parser enhancement
@ 2005-12-14 16:13 Martin Peschke
0 siblings, 0 replies; 5+ messages in thread
From: Martin Peschke @ 2005-12-14 16:13 UTC (permalink / raw)
To: linux-kernel; +Cc: akpm
[patch 2/6] statistics infrastructure - prerequisite: parser enhancement
This patch adds two match_* derivates for 64 bit operands to the parser
library.
Signed-off-by: Martin Peschke <mp3@de.ibm.com>
---
include/linux/parser.h | 2 +
lib/parser.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff -Nurp b/include/linux/parser.h c/include/linux/parser.h
--- b/include/linux/parser.h 2005-10-28 02:02:08.000000000 +0200
+++ c/include/linux/parser.h 2005-12-14 13:44:09.000000000 +0100
@@ -31,3 +31,5 @@ int match_octal(substring_t *, int *resu
int match_hex(substring_t *, int *result);
void match_strcpy(char *, substring_t *);
char *match_strdup(substring_t *);
+int match_u64(substring_t *, u64 *result, int);
+int match_s64(substring_t *, s64 *result, int);
diff -Nurp b/lib/parser.c c/lib/parser.c
--- b/lib/parser.c 2005-10-28 02:02:08.000000000 +0200
+++ c/lib/parser.c 2005-12-14 13:44:09.000000000 +0100
@@ -140,6 +140,64 @@ static int match_number(substring_t *s,
}
/**
+ * match_u64: 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 u64 represented
+ * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
+int match_u64(substring_t *s, u64 *result, int base)
+{
+ char *endp;
+ char *buf;
+ int ret;
+
+ buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+ memcpy(buf, s->from, s->to - s->from);
+ buf[s->to - s->from] = '\0';
+ *result = simple_strtoull(buf, &endp, base);
+ ret = 0;
+ if (endp == buf)
+ ret = -EINVAL;
+ kfree(buf);
+ return ret;
+}
+
+/**
+ * match_s64: 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 s64 represented
+ * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
+int match_s64(substring_t *s, s64 *result, int base)
+{
+ char *endp;
+ char *buf;
+ int ret;
+
+ buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+ memcpy(buf, s->from, s->to - s->from);
+ buf[s->to - s->from] = '\0';
+ *result = simple_strtoll(buf, &endp, base);
+ ret = 0;
+ if (endp == buf)
+ ret = -EINVAL;
+ kfree(buf);
+ 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
@@ -218,3 +276,5 @@ EXPORT_SYMBOL(match_octal);
EXPORT_SYMBOL(match_hex);
EXPORT_SYMBOL(match_strcpy);
EXPORT_SYMBOL(match_strdup);
+EXPORT_SYMBOL(match_u64);
+EXPORT_SYMBOL(match_s64);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Patch 2/6] statistics infrastructure - prerequisite: parser enhancement
@ 2006-05-24 12:30 Martin Peschke
0 siblings, 0 replies; 5+ messages in thread
From: Martin Peschke @ 2006-05-24 12:30 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
This patch adds a match_* derivate for 64 bit operands to the parser library.
Signed-off-by: Martin Peschke <mp3@de.ibm.com>
---
include/linux/parser.h | 1 +
lib/parser.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff -Nurp a/lib/parser.c b/lib/parser.c
--- a/lib/parser.c 2006-03-20 06:53:29.000000000 +0100
+++ b/lib/parser.c 2006-05-19 16:01:48.000000000 +0200
@@ -140,6 +140,35 @@ static int match_number(substring_t *s,
}
/**
+ * match_s64: 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 s64 represented
+ * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
+int match_s64(substring_t *s, s64 *result, int base)
+{
+ char *endp;
+ char *buf;
+ int ret;
+
+ buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+ memcpy(buf, s->from, s->to - s->from);
+ buf[s->to - s->from] = '\0';
+ *result = simple_strtoll(buf, &endp, base);
+ ret = 0;
+ if (endp == buf)
+ ret = -EINVAL;
+ kfree(buf);
+ 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
@@ -218,3 +247,4 @@ EXPORT_SYMBOL(match_octal);
EXPORT_SYMBOL(match_hex);
EXPORT_SYMBOL(match_strcpy);
EXPORT_SYMBOL(match_strdup);
+EXPORT_SYMBOL(match_s64);
diff -Nurp a/include/linux/parser.h b/include/linux/parser.h
--- a/include/linux/parser.h 2006-03-20 06:53:29.000000000 +0100
+++ b/include/linux/parser.h 2006-05-19 16:01:48.000000000 +0200
@@ -31,3 +31,4 @@ int match_octal(substring_t *, int *resu
int match_hex(substring_t *, int *result);
void match_strcpy(char *, substring_t *);
char *match_strdup(substring_t *);
+int match_s64(substring_t *, s64 *result, int);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch 2/6] statistics infrastructure - prerequisite: parser enhancement
2006-05-23 12:54 ` Balbir Singh
@ 2006-05-23 13:13 ` Martin Peschke
0 siblings, 0 replies; 5+ messages in thread
From: Martin Peschke @ 2006-05-23 13:13 UTC (permalink / raw)
To: Balbir Singh; +Cc: Andrew Morton, linux-kernel
Balbir Singh wrote:
> On 5/19/06, Martin Peschke <mp3@de.ibm.com> wrote:
>> This patch adds a match_* derivate for 64 bit operands to the parser
>> library.
>>
>> Signed-off-by: Martin Peschke <mp3@de.ibm.com>
>> ---
>>
>> include/linux/parser.h | 1 +
>> lib/parser.c | 30 ++++++++++++++++++++++++++++++
>> 2 files changed, 31 insertions(+)
>>
>> diff -Nurp a/lib/parser.c b/lib/parser.c
>> --- a/lib/parser.c 2006-03-20 06:53:29.000000000 +0100
>> +++ b/lib/parser.c 2006-05-19 16:01:48.000000000 +0200
>> @@ -140,6 +140,35 @@ static int match_number(substring_t *s,
>> }
>>
>> /**
>> + * match_s64: 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 s64
>> represented
>> + * by the string and returns 0. Returns either -ENOMEM or -EINVAL on
>> failure.
>> + */
>> +int match_s64(substring_t *s, s64 *result, int base)
>> +{
>> + char *endp;
>> + char *buf;
>> + int ret;
>> +
>> + buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
>> + if (!buf)
>> + return -ENOMEM;
>> + memcpy(buf, s->from, s->to - s->from);
>> + buf[s->to - s->from] = '\0';
>> + *result = simple_strtoll(buf, &endp, base);
>> + ret = 0;
>> + if (endp == buf)
>> + ret = -EINVAL;
>> + kfree(buf);
>> + 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
>> @@ -218,3 +247,4 @@ EXPORT_SYMBOL(match_octal);
>> EXPORT_SYMBOL(match_hex);
>> EXPORT_SYMBOL(match_strcpy);
>> EXPORT_SYMBOL(match_strdup);
>> +EXPORT_SYMBOL(match_s64);
>> diff -Nurp a/include/linux/parser.h b/include/linux/parser.h
>> --- a/include/linux/parser.h 2006-03-20 06:53:29.000000000 +0100
>> +++ b/include/linux/parser.h 2006-05-19 16:01:48.000000000 +0200
>> @@ -31,3 +31,4 @@ int match_octal(substring_t *, int *resu
>> int match_hex(substring_t *, int *result);
>> void match_strcpy(char *, substring_t *);
>> char *match_strdup(substring_t *);
>> +int match_s64(substring_t *, s64 *result, int);
>>
>
> Sorry for the delay in reviewing. I am just catching up with pending items.
> I wonder if makes sense to fold this along with match_u64(). 90% of
> their code is common. We can avoid text replication by folding the
> code and the common code is easier to maintain.
>
> Regards,
> Balbir
> Linux Technology Center,
> India Software Labs,
> Bangalore
I guess, match_s64 can be used for u64 as well. Maybe renaming is all that's
needed.
Martin
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Patch 2/6] statistics infrastructure - prerequisite: parser enhancement
2006-05-19 16:10 [Patch " Martin Peschke
@ 2006-05-23 12:54 ` Balbir Singh
2006-05-23 13:13 ` Martin Peschke
0 siblings, 1 reply; 5+ messages in thread
From: Balbir Singh @ 2006-05-23 12:54 UTC (permalink / raw)
To: Martin Peschke; +Cc: Andrew Morton, linux-kernel
On 5/19/06, Martin Peschke <mp3@de.ibm.com> wrote:
> This patch adds a match_* derivate for 64 bit operands to the parser library.
>
> Signed-off-by: Martin Peschke <mp3@de.ibm.com>
> ---
>
> include/linux/parser.h | 1 +
> lib/parser.c | 30 ++++++++++++++++++++++++++++++
> 2 files changed, 31 insertions(+)
>
> diff -Nurp a/lib/parser.c b/lib/parser.c
> --- a/lib/parser.c 2006-03-20 06:53:29.000000000 +0100
> +++ b/lib/parser.c 2006-05-19 16:01:48.000000000 +0200
> @@ -140,6 +140,35 @@ static int match_number(substring_t *s,
> }
>
> /**
> + * match_s64: 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 s64 represented
> + * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
> + */
> +int match_s64(substring_t *s, s64 *result, int base)
> +{
> + char *endp;
> + char *buf;
> + int ret;
> +
> + buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
> + if (!buf)
> + return -ENOMEM;
> + memcpy(buf, s->from, s->to - s->from);
> + buf[s->to - s->from] = '\0';
> + *result = simple_strtoll(buf, &endp, base);
> + ret = 0;
> + if (endp == buf)
> + ret = -EINVAL;
> + kfree(buf);
> + 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
> @@ -218,3 +247,4 @@ EXPORT_SYMBOL(match_octal);
> EXPORT_SYMBOL(match_hex);
> EXPORT_SYMBOL(match_strcpy);
> EXPORT_SYMBOL(match_strdup);
> +EXPORT_SYMBOL(match_s64);
> diff -Nurp a/include/linux/parser.h b/include/linux/parser.h
> --- a/include/linux/parser.h 2006-03-20 06:53:29.000000000 +0100
> +++ b/include/linux/parser.h 2006-05-19 16:01:48.000000000 +0200
> @@ -31,3 +31,4 @@ int match_octal(substring_t *, int *resu
> int match_hex(substring_t *, int *result);
> void match_strcpy(char *, substring_t *);
> char *match_strdup(substring_t *);
> +int match_s64(substring_t *, s64 *result, int);
>
Sorry for the delay in reviewing. I am just catching up with pending items.
I wonder if makes sense to fold this along with match_u64(). 90% of
their code is common. We can avoid text replication by folding the
code and the common code is easier to maintain.
Regards,
Balbir
Linux Technology Center,
India Software Labs,
Bangalore
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Patch 2/6] statistics infrastructure - prerequisite: parser enhancement
@ 2006-05-19 16:10 Martin Peschke
2006-05-23 12:54 ` Balbir Singh
0 siblings, 1 reply; 5+ messages in thread
From: Martin Peschke @ 2006-05-19 16:10 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel
This patch adds a match_* derivate for 64 bit operands to the parser library.
Signed-off-by: Martin Peschke <mp3@de.ibm.com>
---
include/linux/parser.h | 1 +
lib/parser.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff -Nurp a/lib/parser.c b/lib/parser.c
--- a/lib/parser.c 2006-03-20 06:53:29.000000000 +0100
+++ b/lib/parser.c 2006-05-19 16:01:48.000000000 +0200
@@ -140,6 +140,35 @@ static int match_number(substring_t *s,
}
/**
+ * match_s64: 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 s64 represented
+ * by the string and returns 0. Returns either -ENOMEM or -EINVAL on failure.
+ */
+int match_s64(substring_t *s, s64 *result, int base)
+{
+ char *endp;
+ char *buf;
+ int ret;
+
+ buf = kmalloc(s->to - s->from + 1, GFP_KERNEL);
+ if (!buf)
+ return -ENOMEM;
+ memcpy(buf, s->from, s->to - s->from);
+ buf[s->to - s->from] = '\0';
+ *result = simple_strtoll(buf, &endp, base);
+ ret = 0;
+ if (endp == buf)
+ ret = -EINVAL;
+ kfree(buf);
+ 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
@@ -218,3 +247,4 @@ EXPORT_SYMBOL(match_octal);
EXPORT_SYMBOL(match_hex);
EXPORT_SYMBOL(match_strcpy);
EXPORT_SYMBOL(match_strdup);
+EXPORT_SYMBOL(match_s64);
diff -Nurp a/include/linux/parser.h b/include/linux/parser.h
--- a/include/linux/parser.h 2006-03-20 06:53:29.000000000 +0100
+++ b/include/linux/parser.h 2006-05-19 16:01:48.000000000 +0200
@@ -31,3 +31,4 @@ int match_octal(substring_t *, int *resu
int match_hex(substring_t *, int *result);
void match_strcpy(char *, substring_t *);
char *match_strdup(substring_t *);
+int match_s64(substring_t *, s64 *result, int);
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-05-24 12:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-14 16:13 [patch 2/6] statistics infrastructure - prerequisite: parser enhancement Martin Peschke
2006-05-19 16:10 [Patch " Martin Peschke
2006-05-23 12:54 ` Balbir Singh
2006-05-23 13:13 ` Martin Peschke
2006-05-24 12:30 Martin Peschke
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).