File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include "command_queue.h"
2+
3+ // Delete first command queue, return head
4+ struct command_queue * pop_command (struct command_queue * head ) {
5+ struct command_queue * new_head = NULL ;
6+ if (!head )
7+ return NULL ;
8+ else if (!head -> next ) {
9+ if (head -> data )
10+ free (head -> data );
11+ free (head );
12+ return NULL ;
13+ } else {
14+ new_head = head -> next ;
15+ if (head -> data )
16+ free (head -> data );
17+ free (head );
18+ return new_head ;
19+ }
20+ }
21+
22+ // Push command in queue, return head, can have head=NULL for init queue
23+ struct command_queue * push_command (struct command_queue * head , struct command_queue * new_elt ) {
24+ if (!head ) {
25+ return new_elt ;
26+ }
27+ struct command_queue * iter = head ;
28+ while (iter -> next ) {
29+ iter = iter -> next ;
30+ }
31+ iter -> next = new_elt ;
32+ return head ;
33+ }
34+
35+ // Get command queue data, you should known how to cast it
36+ void * peek_command (struct command_queue * head ) {
37+ if (head )
38+ return head -> data ;
39+ return NULL ;
40+ }
41+
42+ // Get user command enum of the first of the queue
43+ enum user_command peek_user_command (struct command_queue * head ) {
44+ if (head )
45+ return head -> command ;
46+ return NONE ;
47+ }
You can’t perform that action at this time.
0 commit comments