Date: Thu, 4 Sep 2008 11:27:30 GMT From: Gabor Kovesdan <gabor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 149185 for review Message-ID: <200809041127.m84BRUP8076383@repoman.freebsd.org>
index | next in thread | raw e-mail
http://perforce.freebsd.org/chv.cgi?CH=149185 Change 149185 by gabor@gabor_server on 2008/09/04 11:27:30 - Use sys/queue.h to implement queue functions - Fix a bug Submitted by: ed Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/Makefile#14 edit .. //depot/projects/soc2008/gabor_textproc/grep/grep.h#42 edit .. //depot/projects/soc2008/gabor_textproc/grep/queue.c#7 edit .. //depot/projects/soc2008/gabor_textproc/grep/util.c#75 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/Makefile#14 (text+ko) ==== ==== //depot/projects/soc2008/gabor_textproc/grep/grep.h#42 (text+ko) ==== @@ -136,7 +136,6 @@ void printline(struct str *line, int sep, regmatch_t *matches, int m); /* queue.c */ -void initqueue(void); void enqueue(struct str *x); void printqueue(void); void clearqueue(void); ==== //depot/projects/soc2008/gabor_textproc/grep/queue.c#7 (text+ko) ==== @@ -40,73 +40,60 @@ #endif /* not lint */ #include <sys/param.h> +#include <sys/queue.h> #include <stdlib.h> #include <string.h> #include "grep.h" -struct queue { - struct queue *next; - struct str data; +struct qentry { + STAILQ_ENTRY(qentry) list; + struct str data; }; -static struct queue *q_head, *q_tail; -static int count; +static STAILQ_HEAD(, qentry) queue = STAILQ_HEAD_INITIALIZER(queue); +static int count; -static struct queue *dequeue(void); - -void -initqueue(void) -{ - q_head = q_tail = NULL; -} +static struct qentry *dequeue(void); void enqueue(struct str *x) { - struct queue *item; + struct qentry *item; - item = grep_malloc(sizeof(struct queue)); + item = grep_malloc(sizeof(struct qentry)); item->data.dat = grep_malloc(sizeof(char) * x->len); item->data.len = x->len; item->data.line_no = x->line_no; item->data.off = x->off; memcpy(item->data.dat, x->dat, x->len); item->data.file = x->file; - item->next = NULL; - if (!q_head) { - q_head = q_tail = item; - } else { - q_tail->next = item; - q_tail = item; - } + STAILQ_INSERT_TAIL(&queue, item, list); if (++count > Bflag) free(dequeue()); } -static struct queue * +static struct qentry * dequeue(void) { - struct queue *item; + struct qentry *item; - if (q_head == NULL) + item = STAILQ_FIRST(&queue); + if (item == NULL) return (NULL); + STAILQ_REMOVE_HEAD(&queue, list); --count; - item = q_head; - q_head = item->next; - if (q_head == NULL) - q_tail = NULL; return (item); } void printqueue(void) { - struct queue *item; + struct qentry *item; while ((item = dequeue()) != NULL) { printline(&item->data, '-', (regmatch_t *)NULL, 0); @@ -117,7 +104,7 @@ void clearqueue(void) { - struct queue *item; + struct qentry *item; while ((item = dequeue()) != NULL) free(item); ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#75 (text+ko) ==== @@ -175,8 +175,6 @@ tail = 0; ln.off = -1; - if (Bflag > 0) - initqueue(); for (c = 0; c == 0 || !(lflag || qflag); ) { ln.off += ln.len + 1; if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL) { @@ -293,7 +291,7 @@ size = mbstowcs(NULL, l->dat, pmatch.rm_so); - if (size = -1) + if (size == -1) r = REG_NOMATCH; else { wbegin = grep_malloc(size);help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200809041127.m84BRUP8076383>
