From 1ee0911f2def54f1b63d18b0924ac65c2db92f11 Mon Sep 17 00:00:00 2001 From: scratko Date: Wed, 12 Jun 2024 18:52:28 +0300 Subject: version shell-V with commented out code --- queue.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 9 deletions(-) (limited to 'queue.h') diff --git a/queue.h b/queue.h index fedcd0b..325706e 100644 --- a/queue.h +++ b/queue.h @@ -1,23 +1,71 @@ #ifndef QUEUE_H_SENTRY #define QUEUE_H_SENTRY +#define MAKE_QUEUE_INIT(NAME) \ + void NAME ## _init(struct NAME *q) \ +{ \ + q->first = NULL; \ + q->last = NULL; \ +} + +#define MAKE_QUEUE_PUSH(NAME, VALUE, TYPE) \ + void NAME ## _push(struct NAME *q, TYPE VALUE) \ +{ \ + struct VALUE ## _item *tmp = malloc(sizeof(struct VALUE ## _item)); \ + tmp-> VALUE = VALUE; \ + tmp->next = NULL; \ + if(!q->first) { \ + q->first = tmp; \ + q->last = q->first; \ + } else { \ + q->last->next = tmp; \ + q->last = q->last->next; \ + } \ +} + struct word_item { char *word; struct word_item *next; }; -struct queue { +struct cmdline_item { + char **cmdline; + struct cmdline_item *next; +}; + +struct pid_item { + int pid; + struct pid_item *next; +}; + +struct w_queue { struct word_item *first; struct word_item *last; }; -void queue_init(struct queue *q); -void queue_push(struct queue *q, char *word); -void queue_clear(struct queue *q); -#if 0 -void queue_processing(const struct queue *q, void (*callback)(char*)); -#endif -int queue_get_word_count(const struct queue *q); -void queue_copy_words_to_args(const struct queue *q, char **cmdline); +struct c_queue { + struct cmdline_item *first; + struct cmdline_item *last; + struct cmdline_item *last_extracted_item; +}; + +struct p_queue { + struct pid_item *first; + struct pid_item *last; +}; + +void w_queue_clear(struct w_queue *q); +int w_queue_get_word_count(const struct w_queue *q); +void w_queue_copy_words_to_args(const struct w_queue *q, char **cmdline); + +void c_queue_init(struct c_queue *q); +void c_queue_push(struct c_queue *q, char **cmdline); +char** c_queue_pop(struct c_queue *q); +void c_queue_clear(struct c_queue *q); +int c_queue_is_empty(struct c_queue *q); + +int p_queue_find_pid(struct p_queue *q, int pid); +void p_queue_clear(struct p_queue *q); +int p_queue_get_process_quantity(struct p_queue *q); #endif -- cgit v1.2.3