]> git.itanic.dy.fi Git - rrdd/commitdiff
Move string manipulation functions to string.c
authorTimo Kokkonen <kaapeli@ee.oulu.fi>
Thu, 3 Apr 2008 19:36:25 +0000 (22:36 +0300)
committerTimo Kokkonen <kaapeli@ee.oulu.fi>
Thu, 3 Apr 2008 19:36:25 +0000 (22:36 +0300)
Makefile
parser.c
string.c [new file with mode: 0644]
string.h [new file with mode: 0644]

index 7f888b7b88a21d129d507686541058186b5c47d0..dcaf6571820d465ad6de81e6c2a136d9388603b4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CC=gcc
 LD=ld
 CFLAGS=-Wall -O2 -g
 
-RRDD_OBJS= main.o process.o draw_graphs.o parser.o scheduler.o
+RRDD_OBJS= main.o process.o draw_graphs.o parser.o scheduler.o string.o
 
 rrdd: $(RRDD_OBJS)
        @echo -e "\tLD\t" rrdd
index bfdf04b6b82dd646cf7520ee9b82363d9af32a2e..02f7afd021ce9a70368f82d2fb3850549e49a00c 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5,73 +5,7 @@
 
 #include "parser.h"
 #include "process.h"
-
-static int dec_to_int(char *src, char **dst)
-{
-       int ret;
-
-       while(((*src < '0') || (*src > '9')) && *src)
-               src++;
-
-       ret = atoi(src);
-
-       if (dst) {
-               while(((*src >= '0') && (*src <= '9')) && *src)
-                       src++;
-               *dst = src;
-       }
-
-       return ret;
-}
-
-static float dec_to_float(char *src, char **dst)
-{
-       float ret;
-
-       while(((*src < '0') || (*src > '9')) && *src)
-               src++;
-
-       ret = atof(src);
-
-       if (dst) {
-               while((((*src >= '0') && (*src <= '9')) || (*src =='.')) && *src)
-                       src++;
-               *dst = src;
-       }
-
-       return ret;
-}
-
-/*
- * Copy white space separated stirng from *src to *word
- *
- * src:  source
- * dst:  place where store the end of word pointer from source string
- * word: destination where to copy the string
- * size: maximum size of bytes to copy to the output buffer
- *
- * return the number of bytes copied
- */
-
-static int get_word(char *src, char **dst, char *word, int size)
-{
-       int ret = 0;
-       while(((*src == ' ') || (*src == '\t') || (*src == '\n')) && *src)
-               src++;
-
-       while(((*src != ' ') && (*src != '\t') && (*src != '\n')) && *src && (ret < (size - 1))) {
-               *word = *src;
-               word++;
-               src++;
-               ret++;
-       }
-       *word = 0;
-
-       if (dst)
-               *dst = src;
-
-       return ret;
-}
+#include "string.h"
 
 #define STATFILE "/proc/stat"
 
diff --git a/string.c b/string.c
new file mode 100644 (file)
index 0000000..2ae3678
--- /dev/null
+++ b/string.c
@@ -0,0 +1,69 @@
+#include "string.h"
+
+int dec_to_int(char *src, char **dst)
+{
+       int ret;
+
+       while(((*src < '0') || (*src > '9')) && *src)
+               src++;
+
+       ret = atoi(src);
+
+       if (dst) {
+               while(((*src >= '0') && (*src <= '9')) && *src)
+                       src++;
+               *dst = src;
+       }
+
+       return ret;
+}
+
+float dec_to_float(char *src, char **dst)
+{
+       float ret;
+
+       while(((*src < '0') || (*src > '9')) && *src)
+               src++;
+
+       ret = atof(src);
+
+       if (dst) {
+               while((((*src >= '0') && (*src <= '9')) || (*src =='.')) && *src)
+                       src++;
+               *dst = src;
+       }
+
+       return ret;
+}
+
+/*
+ * Copy white space separated stirng from *src to *word
+ *
+ * src:  source
+ * dst:  place where store the end of word pointer from source string
+ * word: destination where to copy the string
+ * size: maximum size of bytes to copy to the output buffer
+ *
+ * return the number of bytes copied
+ */
+
+int get_word(char *src, char **dst, char *word, int size)
+{
+       int ret = 0;
+       while(((*src == ' ') || (*src == '\t') || (*src == '\n')) && *src)
+               src++;
+
+       while(((*src != ' ') && (*src != '\t') && (*src != '\n')) && *src && (ret < (size - 1))) {
+               *word = *src;
+               word++;
+               src++;
+               ret++;
+       }
+       *word = 0;
+
+       if (dst)
+               *dst = src;
+
+       return ret;
+}
+
diff --git a/string.h b/string.h
new file mode 100644 (file)
index 0000000..d882c05
--- /dev/null
+++ b/string.h
@@ -0,0 +1,11 @@
+#ifndef __STRING_H
+#define __STRING_H
+
+#include <string.h>
+#include <stdlib.h>
+
+int dec_to_int(char *src, char **dst);
+float dec_to_float(char *src, char **dst);
+int get_word(char *src, char **dst, char *word, int size);
+
+#endif