[tracker/crawling-interval] tracker-extract, libtracker-extract: GB#579051, Provide a tracker_getline
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/crawling-interval] tracker-extract, libtracker-extract: GB#579051, Provide a tracker_getline
- Date: Tue, 1 Jun 2010 15:19:31 +0000 (UTC)
commit be2746941ffe7983b67c66703c1a49402b8655ce
Author: Philip Van Hoof <philip codeminded be>
Date: Wed Apr 28 14:07:37 2010 +0200
tracker-extract, libtracker-extract: GB#579051, Provide a tracker_getline
For platforms that miss the getline() function.
src/libtracker-extract/tracker-utils.c | 93 +++++++++++++++++++++++++++++
src/libtracker-extract/tracker-utils.h | 7 ++-
src/tracker-extract/tracker-extract-abw.c | 3 +-
src/tracker-extract/tracker-extract-ps.c | 82 +-------------------------
4 files changed, 102 insertions(+), 83 deletions(-)
---
diff --git a/src/libtracker-extract/tracker-utils.c b/src/libtracker-extract/tracker-utils.c
index 687861b..1b2e051 100644
--- a/src/libtracker-extract/tracker-utils.c
+++ b/src/libtracker-extract/tracker-utils.c
@@ -20,14 +20,34 @@
#include "config.h"
#define _XOPEN_SOURCE
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include <time.h>
#include <string.h>
+#include <stdio.h>
#include <libtracker-common/tracker-utils.h>
#include <libtracker-common/tracker-date-time.h>
#include "tracker-utils.h"
+#ifndef HAVE_GETLINE
+
+#include <stddef.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <errno.h>
+
+#undef getdelim
+#undef getline
+
+#define GROW_BY 80
+
+#endif /* HAVE_GETLINE */
+
#define DATE_FORMAT_ISO8601 "%Y-%m-%dT%H:%M:%S%z"
/**
@@ -752,3 +772,76 @@ tracker_date_guess (const gchar *date_string)
return g_strdup (date_string);
}
+
+#ifndef HAVE_GETLINE
+static gint
+my_igetdelim (gchar **linebuf,
+ guint *linebufsz,
+ gint delimiter,
+ FILE *file)
+{
+ gint ch;
+ gint idx;
+
+ if ((file == NULL || linebuf == NULL || *linebuf == NULL || *linebufsz == 0) &&
+ !(*linebuf == NULL && *linebufsz == 0)) {
+ errno = EINVAL;
+ return -1;
+ }
+
+ if (*linebuf == NULL && *linebufsz == 0) {
+ *linebuf = g_malloc (GROW_BY);
+
+ if (!*linebuf) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ *linebufsz += GROW_BY;
+ }
+
+ idx = 0;
+
+ while ((ch = fgetc (file)) != EOF) {
+ /* Grow the line buffer as necessary */
+ while (idx > *linebufsz - 2) {
+ *linebuf = g_realloc (*linebuf, *linebufsz += GROW_BY);
+
+ if (!*linebuf) {
+ errno = ENOMEM;
+ return -1;
+ }
+ }
+ (*linebuf)[idx++] = (gchar) ch;
+
+ if ((gchar) ch == delimiter) {
+ break;
+ }
+ }
+
+ if (idx != 0) {
+ (*linebuf)[idx] = 0;
+ } else if ( ch == EOF ) {
+ return -1;
+ }
+
+ return idx;
+}
+
+gint
+tracker_getline (gchar **lineptr,
+ guint *n,
+ FILE *stream)
+{
+ return my_igetdelim (lineptr, n, '\n', stream);
+}
+
+#else
+gint
+tracker_getline (gchar **lineptr,
+ guint *n,
+ FILE *stream)
+{
+ return getline (lineptr, n, stream);
+}
+#endif /* HAVE_GETLINE */
diff --git a/src/libtracker-extract/tracker-utils.h b/src/libtracker-extract/tracker-utils.h
index 052b2dd..50e7f2a 100644
--- a/src/libtracker-extract/tracker-utils.h
+++ b/src/libtracker-extract/tracker-utils.h
@@ -17,6 +17,8 @@
* Boston, MA 02110-1301, USA.
*/
+#include <stdio.h>
+
#ifndef __LIBTRACKER_EXTRACT_UTILS_H__
#define __LIBTRACKER_EXTRACT_UTILS_H__
@@ -42,9 +44,12 @@ gchar* tracker_date_format_to_iso8601 (const gchar *date_string,
const gchar *format);
const gchar* tracker_coalesce_strip (gint n_values,
...);
-gchar* tracker_merge_const (const gchar *delimiter,
+gchar* tracker_merge_const (const gchar *delimiter,
gint n_values,
...);
+gint tracker_getline (gchar **lineptr,
+ guint *n,
+ FILE *stream);
G_END_DECLS
diff --git a/src/tracker-extract/tracker-extract-abw.c b/src/tracker-extract/tracker-extract-abw.c
index 19b60f8..6be54e2 100644
--- a/src/tracker-extract/tracker-extract-abw.c
+++ b/src/tracker-extract/tracker-extract-abw.c
@@ -46,6 +46,7 @@ static TrackerExtractData data[] = {
{ NULL, NULL }
};
+
static void
extract_abw (const gchar *uri,
TrackerSparqlBuilder *preupdate,
@@ -69,7 +70,7 @@ extract_abw (const gchar *uri,
tracker_sparql_builder_predicate (metadata, "a");
tracker_sparql_builder_object (metadata, "nfo:Document");
- while ((read_char = getline (&line, &length, f)) != -1) {
+ while ((read_char = tracker_getline (&line, &length, f)) != -1) {
if (g_str_has_suffix (line, "</m>\n")) {
line[read_char - 5] = '\0';
}
diff --git a/src/tracker-extract/tracker-extract-ps.c b/src/tracker-extract/tracker-extract-ps.c
index 7ec62c0..9ff0242 100644
--- a/src/tracker-extract/tracker-extract-ps.c
+++ b/src/tracker-extract/tracker-extract-ps.c
@@ -38,20 +38,6 @@
#include <libtracker-extract/tracker-extract.h>
-#ifndef HAVE_GETLINE
-
-#include <stddef.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <errno.h>
-
-#undef getdelim
-#undef getline
-
-#define GROW_BY 80
-
-#endif /* HAVE_GETLINE */
-
#ifdef USING_UNZIPPSFILES
static void extract_ps_gz (const gchar *uri,
TrackerSparqlBuilder *preupdate,
@@ -69,72 +55,6 @@ static TrackerExtractData data[] = {
{ NULL, NULL }
};
-#ifndef HAVE_GETLINE
-
-static ssize_t
-igetdelim (gchar **linebuf,
- size_t *linebufsz,
- gint delimiter,
- FILE *file)
-{
- gint ch;
- gint idx;
-
- if ((file == NULL || linebuf == NULL || *linebuf == NULL || *linebufsz == 0) &&
- !(*linebuf == NULL && *linebufsz == 0)) {
- errno = EINVAL;
- return -1;
- }
-
- if (*linebuf == NULL && *linebufsz == 0) {
- *linebuf = g_malloc (GROW_BY);
-
- if (!*linebuf) {
- errno = ENOMEM;
- return -1;
- }
-
- *linebufsz += GROW_BY;
- }
-
- idx = 0;
-
- while ((ch = fgetc (file)) != EOF) {
- /* Grow the line buffer as necessary */
- while (idx > *linebufsz - 2) {
- *linebuf = g_realloc (*linebuf, *linebufsz += GROW_BY);
-
- if (!*linebuf) {
- errno = ENOMEM;
- return -1;
- }
- }
- (*linebuf)[idx++] = (gchar) ch;
-
- if ((gchar) ch == delimiter) {
- break;
- }
- }
-
- if (idx != 0) {
- (*linebuf)[idx] = 0;
- } else if ( ch == EOF ) {
- return -1;
- }
-
- return idx;
-}
-
-static gint
-getline (gchar **s,
- guint *lim,
- FILE *stream)
-{
- return igetdelim (s, lim, '\n', stream);
-}
-
-#endif /* HAVE_GETLINE */
-
static gchar *
hour_day_str_day (const gchar *date)
{
@@ -234,7 +154,7 @@ extract_ps_from_filestream (FILE *f,
* b) No more lines to read
*/
while ((accum < max_bytes) &&
- (read_char = getline (&line, &length, f)) != -1) {
+ (read_char = tracker_getline (&line, &length, f)) != -1) {
gboolean pageno_atend = FALSE;
gboolean header_finished = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]