From 92be41a815c3123adfc7ebcbc64b65d0714b47b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Sun, 14 Jul 2013 23:03:37 +0200 Subject: [PATCH] Removed dummy GNU function declarations. Used coding style in queue --- src/int/queue.c | 211 +++++++++++++++++++++++++----------------------- src/int/queue.h | 7 +- 2 files changed, 116 insertions(+), 102 deletions(-) diff --git a/src/int/queue.c b/src/int/queue.c index 35ae2fd..cbb91bc 100644 --- a/src/int/queue.c +++ b/src/int/queue.c @@ -1,112 +1,125 @@ -#include "depend.h" -#include "genint.h" -#include "int.h" -#include "process.h" -#include "intproto.h" +#include "depend.h" +#include "genint.h" +#include "int.h" +#include "process.h" +#include "intproto.h" /* Queue management */ /* Single linked circular lists with queue represented as pointer to rear */ -queue qinit() /* Initialize empty queue */ +/** + * Initialize empty queue + */ +queue qinit() { - return (NULL); -} /* end qinit */ + return NULL; +} - -stack push(q, e) /* Insert element into the queue */ -stack q; -selem e; +/** + * Insert element into the queue + */ +stack push(stack q, selem e) { - stack p; - - p = (stack) ballocate(sizeof(struct queuelem)); - if (p == NULL) errsignal(RTEMEMOV); - p->elem = e; - if (q == NULL) - { - p->next = p; /* the lonely element of the queue */ - q = p; - } - else - { - p->next = q->next; /* insert at rear */ - q->next = p; - } - return(q); -} /* end push */ - - -qelem qfront(q) /* Get first element of the queue */ -queue q; + stack p; + + p = (stack) ballocate(sizeof(struct queuelem)); + if (p == NULL) + errsignal(RTEMEMOV); + p->elem = e; + /* the lonely element of the queue */ + if (q == NULL) { + p->next = p; + q = p; + } else {/* insert at rear */ + p->next = q->next; + q->next = p; + } + return q; +} + +/** + * Get first element of the queue + */ +qelem qfront(queue q) { - if (qempty(q)){ - fprintf( stderr, "getting first element from empty queue\n"); - errsignal(RTESYSER); - } - return (q->next->elem); -} /* end qfront */ - - -queue qremove(q) /* Remove front element from the queue */ -queue q; + if (qempty(q)){ + fprintf(stderr, "getting first element from empty queue\n"); + errsignal(RTESYSER); + } + return q->next->elem; +} + +/** + * Remove front element from the queue + */ +queue qremove(queue q) { - queue p; - - if (qempty(q)){ - fprintf( stderr, "removing first element from empty queue\n"); - errsignal(RTESYSER); - } - p = q->next; - q->next = q->next->next; - if (p == q) q = NULL; /* removing last element of the queue */ - free(p); - return(q); -} /* end qremove */ - - -queue qdelete(q, e) /* Delete arbitrary element */ -queue q; -qelem e; + queue p; + + if (qempty(q)){ + fprintf(stderr, "removing first element from empty queue\n"); + errsignal(RTESYSER); + } + p = q->next; + q->next = q->next->next; + /* removing last element of the queue */ + if (p == q) + q = NULL; + free(p); + return q; +} + +/** + * Delete arbitrary element + */ +queue qdelete(queue q, qelem e) { - queue p, r, s; - - if (qempty(q)) return(q); - r = q; - p = r->next; - while (p->elem != e) - { - if (p == q) return(q); - r = p; - p = p->next; - } - r->next = p->next; - if (r == p) s = NULL; - else - if (p == q) s = r; - else s = q; - free(p); - return(s); -} /* end qdelete */ - - -queue qrotate(q) /* Remove front and insert at rear */ -queue q; + queue p; + queue r; + queue s; + + if (qempty(q)) + return q; + r = q; + p = r->next; + while (p->elem != e) { + if (p == q) + return q; + r = p; + p = p->next; + } + r->next = p->next; + if (r == p) + s = NULL; + else if (p == q) + s = r; + else + s = q; + free(p); + return s; +} + +/** + * Remove front and insert at rear + */ +queue qrotate(queue q) { - if (qempty(q)){ - fprintf( stderr, "rotating empty queue\n"); - errsignal(RTESYSER); - } - return (q->next); -} /* end qrotate */ - - -void qfree(q) -queue q; + if (qempty(q)){ + fprintf(stderr, "rotating empty queue\n"); + errsignal(RTESYSER); + } + return q->next; +} + + +/** + * + */ +void qfree(queue q) { - while (!qempty(q)) - { - free(qfront(q)); - q = qremove(q); - } -} /* end qfree */ + while (!qempty(q)) { + free(qfront(q)); + q = qremove(q); + } +} diff --git a/src/int/queue.h b/src/int/queue.h index 7682c00..49cbd1a 100644 --- a/src/int/queue.h +++ b/src/int/queue.h @@ -2,9 +2,10 @@ typedef lword qelem; typedef qelem selem; -struct queuelem { qelem elem; - struct queuelem *next; - }; +struct queuelem { + qelem elem; + struct queuelem *next; +}; typedef struct queuelem *queue; typedef queue stack; -- 2.30.2