Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*/**/*.swp
*/**/.DStore
.DStore
*/**/*.dSYM
*.dSYM
*.swp
16 changes: 16 additions & 0 deletions Common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CC = gcc
CFLAGS = -g -o
LDFLAGS = -lncurses
EXECS = exec
FILE = *.c

all: compile clean

compile: $(FILE)
$(CC) $(CFLAGS) $(EXECS) $(FILE) $(LDFLAGS)

clean:
-rm -rf *.dSYM

spotless:
-rm $(EXECS)
134 changes: 134 additions & 0 deletions Common/Queue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"

/* initialize a Queue data structure */
int init(Queue_t *queue)
{
int all_ok = 0;

if (queue != NULL)
{
queue->head = NULL;
queue->tail = NULL;
queue->size = 0;
all_ok = 1;
}
return all_ok;
}

/* delete all elements in a queue */

void destroy(Queue_t *queue)
{
Node_t *tmp = NULL;

if (queue->head != NULL)
{
while (queue->head != NULL)
{
tmp = queue->head;
queue->head = queue->head->next;
free(tmp);
}
queue->head = NULL;
queue->tail = NULL;
}
}

/* add an element to the end of the queue */
int enqueue(Queue_t *queue, void *data)
{
int all_ok = 0;
if (queue != NULL)
{
Node_t *n= (Node_t *) malloc(sizeof(Node_t));
n->next = NULL;
n->prev = NULL;
n->data = data;
if (queue != NULL && n != NULL)
{
n->next = NULL;
n->prev = queue->tail;

if (queue->tail == NULL)
queue->head = n;
else
queue->tail->next = n;
queue->size += 1;
all_ok = 1;
}
}
return all_ok;
}

/* remove the first element in a queue */
int dequeue(Queue_t *queue, void **data)
{
int all_ok = 0;

Node_t *tmp = NULL;

if (queue != NULL && data != NULL)
{
if (queue->head != NULL)
{
/* get the data */
*data = queue->head->data;

/* remove the node */
tmp = queue->head;
queue->head = queue->head->next;
if (queue->head == NULL)
queue->tail = NULL;
else
queue->head->prev = NULL;

free(tmp);
all_ok = 1;
}
else
*data = NULL;
queue->size -= 1;
}

return all_ok;
}

/* Allow code to traverse through a queue linearly. The context
parameter is state that the calling program stores for the
traversal. It indicates the last node in the queue that was
reported by the traversal. To begin a traversal, pass a NULL
value as the context content (but not the context variable itself). */

int next(Queue_t *queue, void **context, void **data)
{
int all_ok = 1;

Node_t **curr = (Node_t **) context;

/* determine the next node to report in the queue */
if (*curr == NULL)
*curr = queue->head;
else
*curr = (*curr)->next;

/* if we haven't hit the end of the queue, report the data */

*data = NULL;
if (*curr != NULL)
*data = (*curr)->data;

return all_ok;
}

/* return the size of the queue */
int size(Queue_t *queue) { return queue->size; }

/* determine if the queue is empty */
int isEmpty(Queue_t *queue) { return (queue->size == 0); }




26 changes: 26 additions & 0 deletions Common/Queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _Queue_h_
#define _Queue_h_

typedef struct Node_t {
void *data;
struct Node_t *prev, *next;
} Node_t;

typedef struct Queue_t {
Node_t *head;
Node_t *tail;
int size;
} Queue_t;


int init(Queue_t *);
void destroy(Queue_t *);
int enqueue(Queue_t *, void *);
int dequeue(Queue_t *, void **);
int next(Queue_t *, void **, void **);
int size(Queue_t *);
int ieEmpty(Queue_t *);


#endif

40 changes: 40 additions & 0 deletions Common/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef _common_h_
#define _common_h_

#include <stdio.h>
#include <stdlib.h>
#define MAXCRS 7
#define MAXLEN 20
#define MAXQUERY 1024

/* Queue Data Structure */
typedef struct Node_t {
void *data;
struct Node_t *prev, *next;
} Node_t;

typedef struct Queue_t {
Node_t *head;
Node_t *tail;
int size;
} Queue_t;


int init(Queue_t *);
void destroy(Queue_t *);
int enqueue(Queue_t *, void *);
int dequeue(Queue_t *, void **);
int next(Queue_t *, void **, void **);
int size(Queue_t *);
int ieEmpty(Queue_t *);
/* End of Queue Data Structure */


/* Database Integration */

/* End of Database Itegration */




#endif
Binary file added Iteration_1_Report/Project_Report.pdf
Binary file not shown.
23 changes: 23 additions & 0 deletions Queue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Accessing the inside of the queue
--------------------------------

- `next` -- for iterating over the queue
where the position was found using `next`

The function use a "context" parameter to let the queue.c
functions remember where they are within the queue. `next`
changes the context variable.

To iterate through the linked queue, begin with the context as a
NULL value. Sample iteration code is:

Queue_t the_queue;
void *context = NULL;
void *mydata;

/* Assume that the queue has been inialized and data has been added to it. */

while ( next( &the_queue, &context, &mydata ) && (mydata != NULL)) {
/* Do something with the data pointed to by mydata. */
}

55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,58 @@
===============

CSCI 3431 Project: Creating A Shell

This is the reporsitory for our CSCI 3134 project.

The header files are all in the headers folder, all other header files in other folders are symbolic links.

***

Group Members
-------------

Tsubasa Hirooka (Pipe)

Lianzhu Shi

Yucheng Liu

Yiying Zhang

***

Functions
---------

In this projcet we want to implement a simple shell which has basically 4 functions.

1. History

2. Pipe

3. Tab Completion Function

4. Database

***

Usage
---------

When first use this program, use the command `make`, it will compile the program and create an executable call "exec". When you want to delete the executable, use the command `make spotless`.

TBA

***

Data Structure
---------
- Queue:
- For more information, please refer to [Queue.md] [1]


TBA



[1]: Queue.md
16 changes: 16 additions & 0 deletions Sample Codes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

EXECS = pipe1 pipe2 popen1 popen2
CC = gcc

all: $(EXECS)

pipe1: pipe1.c
pipe2: pipe2.c
popen1: popen1.c
popen2: popen2.c

clean:

spotless: clean
-rm $(EXECS)

28 changes: 28 additions & 0 deletions Sample Codes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
Sample Code Folder
===

This folder contains the sample codes for various libraries, function, etc. It now only have codes for pipes, which can be later used for implementing pipe-like commands in the shell we are to implement.

***

Sample codes
------

- `pipe1.c`: The parent process closes the pipe after the child process is terminated.

- `pipe2.c`: The parent process closes the pipe before the child process is terminated and after the message is sent.

- `popen1.c`: Execute `ls` command in another process

- `popen2.c`: Execute `sort` command in another process
1. create a file with words
2. open a pipe and sort the words in the file
3. get rid of the file now that it's done

***

Know Issues
------

TBA

Loading