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.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 122 insertions(+), 19 deletions(-) (limited to 'queue.c') diff --git a/queue.c b/queue.c index eed3cf8..3787236 100644 --- a/queue.c +++ b/queue.c @@ -1,13 +1,14 @@ #include "queue.h" #include -void queue_init(struct queue *q) +#if 0 +void w_queue_init(struct w_queue *q) { q->first = NULL; q->last = NULL; } -void queue_push(struct queue *q, char *word) +void w_queue_push(struct w_queue *q, char *word) { struct word_item *tmp = malloc(sizeof(struct word_item)); tmp->word = word; @@ -20,32 +21,19 @@ void queue_push(struct queue *q, char *word) q->last = q->last->next; } } - -void queue_clear(struct queue *q) +#endif +void w_queue_clear(struct w_queue *q) { struct word_item *tmp; while(q->first) { tmp = q->first; q->first = q->first->next; - free(tmp->word); free(tmp); } q->last = NULL; } -#if 0 -void queue_processing(const struct queue *q, void (*callback)(char*)) -{ - struct word_item *tmp; - tmp = q->first; - while(tmp) { - callback(tmp->word); - tmp = tmp->next; - } -} -#endif - -int queue_get_word_count(const struct queue *q) +int w_queue_get_word_count(const struct w_queue *q) { struct word_item *tmp; int counter; @@ -54,7 +42,7 @@ int queue_get_word_count(const struct queue *q) return counter; } -void queue_copy_words_to_args(const struct queue *q, char **cmdline) +void w_queue_copy_words_to_args(const struct w_queue *q, char **cmdline) { struct word_item *tmp; int mas_idx; @@ -62,3 +50,118 @@ void queue_copy_words_to_args(const struct queue *q, char **cmdline) cmdline[mas_idx] = tmp->word; cmdline[mas_idx] = NULL; } + +void c_queue_init(struct c_queue *q) +{ + q->first = NULL; + q->last = NULL; + q->last_extracted_item = NULL; +} + +#if 0 +void c_queue_push(struct c_queue *q, char **cmdline) +{ + struct cmdline_item *tmp = malloc(sizeof(struct cmdline_item)); + tmp->cmdline = cmdline; + tmp->next = NULL; + if(!q->first) { + q->first = tmp; + q->last = q->first; + } else { + q->last->next = tmp; + q->last = q->last->next; + } +} +#endif + +int c_queue_is_empty(struct c_queue *q) +{ + return q->last_extracted_item->next == NULL; +} + +char** c_queue_pop(struct c_queue *q) +{ + if(!q->last_extracted_item) { + if(q->first) { + q->last_extracted_item = q->first; + return q->last_extracted_item->cmdline; + } + return NULL; + } else { + if(q->last_extracted_item->next) { + q->last_extracted_item = q->last_extracted_item->next; + return q->last_extracted_item->cmdline; + } + return NULL; + } +} + +void c_queue_clear(struct c_queue *q) +{ + struct cmdline_item *tmp = NULL; + while(q->first) { + int i; + for(i = 0; q->first->cmdline[i]; ++i) + free(q->first->cmdline[i]); + free(q->first->cmdline); + tmp = q->first; + q->first = q->first->next; + free(tmp); + } + q->last = NULL; + q->last_extracted_item = NULL; +} +#if 0 +void p_queue_init(struct p_queue *q) +{ + q->first = NULL; + q->last = NULL; +} + +void p_queue_push(struct p_queue *q, int pid) +{ + struct pid_item *tmp = malloc(sizeof(struct pid_item)); + tmp->pid = pid; + tmp->next = NULL; + if(!q->first) { + q->first = tmp; + q->last = q->first; + } else { + q->last->next = tmp; + q->last = q->last->next; + } +} +#endif + +int p_queue_find_pid(struct p_queue *q, int pid) +{ + struct pid_item *tmp = q->first; + while(tmp) { + if(tmp->pid == pid) + return 1; + tmp = tmp->next; + } + return 0; +} + +int p_queue_get_process_quantity(struct p_queue *q) +{ + int counter = 0; + struct pid_item *tmp = q->first; + while(tmp) { + ++counter; + tmp = tmp->next; + } + return counter; +} + +void p_queue_clear(struct p_queue *q) +{ + struct pid_item *tmp = NULL; + while(q->first) { + tmp = q->first; + q->first = q->first->next; + free(tmp); + } + q->last = NULL; +} -- cgit v1.2.3