Added a tags file. I dunno if this is something that's really supposed to
be in a CVS repository, but for now, it is, so there. :)
This commit is contained in:
+543
-442
File diff suppressed because it is too large
Load Diff
+42
-44
@@ -118,66 +118,64 @@
|
||||
|
||||
// See LL.c for more detailed descriptions of these functions.
|
||||
|
||||
typedef struct LL_node
|
||||
{
|
||||
struct LL_node *next, *prev;
|
||||
void *data;
|
||||
typedef struct LL_node {
|
||||
struct LL_node *next, *prev;
|
||||
void *data;
|
||||
} LL_node;
|
||||
|
||||
typedef struct LL
|
||||
{
|
||||
LL_node head, tail;
|
||||
LL_node *current;
|
||||
typedef struct LL {
|
||||
LL_node head, tail;
|
||||
LL_node *current;
|
||||
} LL;
|
||||
|
||||
|
||||
|
||||
// Creates a new list...
|
||||
LL * LL_new();
|
||||
LL *LL_new ();
|
||||
// Destroying lists...
|
||||
int LL_Destroy(LL *list);
|
||||
int LL_node_Destroy(LL_node *node);
|
||||
int LL_node_Unlink(LL_node *node);
|
||||
int LL_node_DestroyData(LL_node *node);
|
||||
int LL_Destroy (LL * list);
|
||||
int LL_node_Destroy (LL_node * node);
|
||||
int LL_node_Unlink (LL_node * node);
|
||||
int LL_node_DestroyData (LL_node * node);
|
||||
|
||||
// Returns to the beginning of the list...
|
||||
int LL_Rewind(LL *list);
|
||||
int LL_Rewind (LL * list);
|
||||
// Goes to the end of the list...
|
||||
int LL_End(LL *list);
|
||||
int LL_End (LL * list);
|
||||
// Go to the next node
|
||||
int LL_Next(LL *list);
|
||||
int LL_Next (LL * list);
|
||||
// Go to the previous node
|
||||
int LL_Prev(LL *list);
|
||||
int LL_Prev (LL * list);
|
||||
|
||||
// Data manipulation
|
||||
void * LL_Get(LL *list);
|
||||
int LL_Put(LL *list, void *data);
|
||||
void *LL_Get (LL * list);
|
||||
int LL_Put (LL * list, void *data);
|
||||
// Don't use these next two unless you really know what you're doing.
|
||||
LL_node * LL_GetNode(LL *list);
|
||||
int LL_PutNode(LL *list, LL_node *node);
|
||||
LL_node *LL_GetNode (LL * list);
|
||||
int LL_PutNode (LL * list, LL_node * node);
|
||||
|
||||
void * LL_GetFirst(LL *list); // gets data from first node
|
||||
void * LL_GetNext (LL *list); // ... next node
|
||||
void * LL_GetPrev (LL *list); // ... prev node
|
||||
void * LL_GetLast (LL *list); // ... last node
|
||||
void *LL_GetFirst (LL * list); // gets data from first node
|
||||
void *LL_GetNext (LL * list); // ... next node
|
||||
void *LL_GetPrev (LL * list); // ... prev node
|
||||
void *LL_GetLast (LL * list); // ... last node
|
||||
|
||||
int LL_AddNode(LL *list, void * add); // Adds node AFTER current one
|
||||
int LL_InsertNode(LL *list, void * add);// Adds node BEFORE current one
|
||||
int LL_AddNode (LL * list, void *add); // Adds node AFTER current one
|
||||
int LL_InsertNode (LL * list, void *add); // Adds node BEFORE current one
|
||||
// Removes a node from the link; returns the data from the node
|
||||
void * LL_DeleteNode(LL *list);
|
||||
void *LL_DeleteNode (LL * list);
|
||||
// Removes a specific node...
|
||||
void * LL_Remove(LL *list, void * data);
|
||||
void *LL_Remove (LL * list, void *data);
|
||||
|
||||
// Stack operations
|
||||
int LL_Push(LL *list, void *add); // Add node to end of list
|
||||
void * LL_Pop(LL *list); // Remove node from end of list
|
||||
void * LL_Top(LL *list); // Peek at end node
|
||||
void * LL_Shift(LL *list); // Remove node from start of list
|
||||
void * LL_Look(LL *list); // Peek at first node
|
||||
int LL_Unshift(LL *list, void *add); // Add node to beginning of list
|
||||
int LL_Push (LL * list, void *add); // Add node to end of list
|
||||
void *LL_Pop (LL * list); // Remove node from end of list
|
||||
void *LL_Top (LL * list); // Peek at end node
|
||||
void *LL_Shift (LL * list); // Remove node from start of list
|
||||
void *LL_Look (LL * list); // Peek at first node
|
||||
int LL_Unshift (LL * list, void *add); // Add node to beginning of list
|
||||
|
||||
int LL_Roll(LL *list); // Make first node last
|
||||
int LL_UnRoll(LL *list);// Roll the other way...
|
||||
int LL_Roll (LL * list); // Make first node last
|
||||
int LL_UnRoll (LL * list); // Roll the other way...
|
||||
|
||||
// Queue operations...
|
||||
//int LL_Enqueue(LL *list, void *add);
|
||||
@@ -188,22 +186,22 @@ int LL_UnRoll(LL *list);// Roll the other way...
|
||||
|
||||
#define LL_Dequeue(list) LL_Shift(list)
|
||||
|
||||
int LL_PriorityEnqueue(LL *list, void *add, int compare(void *, void *));
|
||||
int LL_PriorityEnqueue (LL * list, void *add, int compare (void *, void *));
|
||||
|
||||
|
||||
int LL_SwapNodes(LL_node *one, LL_node *two); // Switch two nodes positions...
|
||||
int LL_nSwapNodes(int one, int two); // Switch two nodes positions...
|
||||
int LL_SwapNodes (LL_node * one, LL_node * two); // Switch two nodes positions...
|
||||
int LL_nSwapNodes (int one, int two); // Switch two nodes positions...
|
||||
|
||||
int LL_Length(LL *list); // Returns # of nodes in entire list
|
||||
int LL_Length (LL * list); // Returns # of nodes in entire list
|
||||
|
||||
// Searching...
|
||||
void * LL_Find(LL *list, int compare(void *, void *), void *value);
|
||||
void *LL_Find (LL * list, int compare (void *, void *), void *value);
|
||||
|
||||
// Sorts the list...
|
||||
int LL_Sort(LL *list, int compare(void *, void *));
|
||||
int LL_Sort (LL * list, int compare (void *, void *));
|
||||
|
||||
|
||||
// Debugging...
|
||||
void LL_dprint(LL *list);
|
||||
void LL_dprint (LL * list);
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
|
||||
#else
|
||||
|
||||
#define debug /* printf */
|
||||
#define debug /* printf */
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+147
-141
@@ -31,197 +31,203 @@
|
||||
typedef struct sockaddr_in sockaddr_in;
|
||||
|
||||
|
||||
static int sock_init_sockaddr (sockaddr_in *name,
|
||||
const char *hostname,
|
||||
unsigned short int port)
|
||||
static int
|
||||
sock_init_sockaddr (sockaddr_in * name, const char *hostname, unsigned short int port)
|
||||
{
|
||||
struct hostent *hostinfo;
|
||||
|
||||
name->sin_family = AF_INET;
|
||||
name->sin_port = htons (port);
|
||||
hostinfo = gethostbyname (hostname);
|
||||
if (hostinfo == NULL)
|
||||
{
|
||||
fprintf (stderr,"sock_init_sockaddr: Unknown host %s.\n", hostname);
|
||||
struct hostent *hostinfo;
|
||||
|
||||
name->sin_family = AF_INET;
|
||||
name->sin_port = htons (port);
|
||||
hostinfo = gethostbyname (hostname);
|
||||
if (hostinfo == NULL) {
|
||||
fprintf (stderr, "sock_init_sockaddr: Unknown host %s.\n", hostname);
|
||||
return -1;
|
||||
}
|
||||
name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
|
||||
}
|
||||
name->sin_addr = *(struct in_addr *) hostinfo->h_addr;
|
||||
|
||||
return 0;
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
// Client functions...
|
||||
int sock_connect(char *host, unsigned short int port)
|
||||
int
|
||||
sock_connect (char *host, unsigned short int port)
|
||||
{
|
||||
struct sockaddr_in servername;
|
||||
int sock;
|
||||
int err=0;
|
||||
|
||||
|
||||
debug("sock_connect: Creating socket\n");
|
||||
sock = socket(PF_INET, SOCK_STREAM, 0);
|
||||
if(sock < 0)
|
||||
{
|
||||
perror("sock_connect: Error creating socket");
|
||||
return sock;
|
||||
}
|
||||
debug("sock_connect: Created socket (%i)\n", sock);
|
||||
|
||||
sock_init_sockaddr(&servername, host, port);
|
||||
|
||||
err = connect (sock,
|
||||
(struct sockaddr *) &servername,
|
||||
sizeof (servername));
|
||||
if(err<0)
|
||||
{
|
||||
perror("sock_connect: connect failed");
|
||||
shutdown(sock, 2);
|
||||
return 0; // Normal exit if server doesn't exist...
|
||||
}
|
||||
|
||||
fcntl(sock, F_SETFL, O_NONBLOCK);
|
||||
struct sockaddr_in servername;
|
||||
int sock;
|
||||
int err = 0;
|
||||
|
||||
|
||||
return sock;
|
||||
|
||||
debug ("sock_connect: Creating socket\n");
|
||||
sock = socket (PF_INET, SOCK_STREAM, 0);
|
||||
if (sock < 0) {
|
||||
perror ("sock_connect: Error creating socket");
|
||||
return sock;
|
||||
}
|
||||
debug ("sock_connect: Created socket (%i)\n", sock);
|
||||
|
||||
sock_init_sockaddr (&servername, host, port);
|
||||
|
||||
err = connect (sock, (struct sockaddr *) &servername, sizeof (servername));
|
||||
if (err < 0) {
|
||||
perror ("sock_connect: connect failed");
|
||||
shutdown (sock, 2);
|
||||
return 0; // Normal exit if server doesn't exist...
|
||||
}
|
||||
|
||||
fcntl (sock, F_SETFL, O_NONBLOCK);
|
||||
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
int sock_close(int fd)
|
||||
int
|
||||
sock_close (int fd)
|
||||
{
|
||||
int err;
|
||||
|
||||
err=shutdown(fd, 2);
|
||||
if (!err) close (fd);
|
||||
|
||||
err = shutdown (fd, 2);
|
||||
if (!err)
|
||||
close (fd);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
// Send/receive lines of text
|
||||
int sock_send_string(int fd, char *string)
|
||||
int
|
||||
sock_send_string (int fd, char *string)
|
||||
{
|
||||
int len;
|
||||
int offset=0;
|
||||
int len;
|
||||
int offset = 0;
|
||||
|
||||
if (!string) return -1;
|
||||
if (!string)
|
||||
return -1;
|
||||
|
||||
len = strlen (string) + 1;
|
||||
while (offset != len) {
|
||||
// write isn't guaranteed to send the entire string at once,
|
||||
// so we have to sent it in a loop like this
|
||||
int sent = write (fd, string+offset, len-offset);
|
||||
if (sent == -1) {
|
||||
if (errno != EAGAIN) {
|
||||
perror ("sock_send_string: socket write error");
|
||||
printf("Message was: %s\n", string);
|
||||
//shutdown(fd, 2);
|
||||
return sent;
|
||||
}
|
||||
continue;
|
||||
} else if (sent == 0) {
|
||||
// when this returns zero, it generally means
|
||||
// we got disconnected
|
||||
return sent+offset;
|
||||
}
|
||||
len = strlen (string) + 1;
|
||||
while (offset != len) {
|
||||
// write isn't guaranteed to send the entire string at once,
|
||||
// so we have to sent it in a loop like this
|
||||
int sent = write (fd, string + offset, len - offset);
|
||||
if (sent == -1) {
|
||||
if (errno != EAGAIN) {
|
||||
perror ("sock_send_string: socket write error");
|
||||
printf ("Message was: %s\n", string);
|
||||
//shutdown(fd, 2);
|
||||
return sent;
|
||||
}
|
||||
continue;
|
||||
} else if (sent == 0) {
|
||||
// when this returns zero, it generally means
|
||||
// we got disconnected
|
||||
return sent + offset;
|
||||
}
|
||||
|
||||
offset += sent;
|
||||
}
|
||||
offset += sent;
|
||||
}
|
||||
|
||||
return offset;
|
||||
return offset;
|
||||
}
|
||||
|
||||
// Recv gives only one line per call...
|
||||
int sock_recv_string(int fd, char *dest, size_t maxlen)
|
||||
int
|
||||
sock_recv_string (int fd, char *dest, size_t maxlen)
|
||||
{
|
||||
char *ptr = dest;
|
||||
int recv = 0;
|
||||
char *ptr = dest;
|
||||
int recv = 0;
|
||||
|
||||
if (!dest) return -1;
|
||||
if (maxlen <= 0) return 0;
|
||||
if (!dest)
|
||||
return -1;
|
||||
if (maxlen <= 0)
|
||||
return 0;
|
||||
|
||||
while (1) {
|
||||
int err = read (fd, ptr, 1);
|
||||
if (err == -1) {
|
||||
if (errno == EAGAIN) {
|
||||
if (recv) {
|
||||
// We've begun to read a string, but no bytes are
|
||||
// available. Loop.
|
||||
continue;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
perror ("sock_recv_string: socket read error");
|
||||
return err;
|
||||
}
|
||||
} else if (err == 0) {
|
||||
return recv;
|
||||
}
|
||||
while (1) {
|
||||
int err = read (fd, ptr, 1);
|
||||
if (err == -1) {
|
||||
if (errno == EAGAIN) {
|
||||
if (recv) {
|
||||
// We've begun to read a string, but no bytes are
|
||||
// available. Loop.
|
||||
continue;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
perror ("sock_recv_string: socket read error");
|
||||
return err;
|
||||
}
|
||||
} else if (err == 0) {
|
||||
return recv;
|
||||
}
|
||||
|
||||
recv++;
|
||||
recv++;
|
||||
|
||||
if (recv == maxlen || *ptr == 0 || *ptr == 10) {
|
||||
*ptr = 0;
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
if (recv == maxlen || *ptr == 0 || *ptr == 10) {
|
||||
*ptr = 0;
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (recv == 1 && dest[0] == 0) {
|
||||
// Don't return a null string
|
||||
return 0;
|
||||
}
|
||||
if (recv == 1 && dest[0] == 0) {
|
||||
// Don't return a null string
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (recv < maxlen-1) {
|
||||
dest[recv] = 0;
|
||||
}
|
||||
if (recv < maxlen - 1) {
|
||||
dest[recv] = 0;
|
||||
}
|
||||
|
||||
return recv;
|
||||
return recv;
|
||||
}
|
||||
|
||||
// Send/receive raw data
|
||||
int sock_send(int fd, void *src, size_t size)
|
||||
int
|
||||
sock_send (int fd, void *src, size_t size)
|
||||
{
|
||||
int offset=0;
|
||||
int offset = 0;
|
||||
|
||||
if (!src) return -1;
|
||||
if (!src)
|
||||
return -1;
|
||||
|
||||
while (offset != size) {
|
||||
// write isn't guaranteed to send the entire string at once,
|
||||
// so we have to sent it in a loop like this
|
||||
int sent = write (fd, ((char*)src)+offset, size-offset);
|
||||
if (sent == -1) {
|
||||
if (errno != EAGAIN) {
|
||||
perror ("sock_send: socket write error");
|
||||
//shutdown(fd, 2);
|
||||
return sent;
|
||||
}
|
||||
continue;
|
||||
} else if (sent == 0) {
|
||||
// when this returns zero, it generally means
|
||||
// we got disconnected
|
||||
return sent+offset;
|
||||
}
|
||||
while (offset != size) {
|
||||
// write isn't guaranteed to send the entire string at once,
|
||||
// so we have to sent it in a loop like this
|
||||
int sent = write (fd, ((char *) src) + offset, size - offset);
|
||||
if (sent == -1) {
|
||||
if (errno != EAGAIN) {
|
||||
perror ("sock_send: socket write error");
|
||||
//shutdown(fd, 2);
|
||||
return sent;
|
||||
}
|
||||
continue;
|
||||
} else if (sent == 0) {
|
||||
// when this returns zero, it generally means
|
||||
// we got disconnected
|
||||
return sent + offset;
|
||||
}
|
||||
|
||||
offset += sent;
|
||||
}
|
||||
offset += sent;
|
||||
}
|
||||
|
||||
return offset;
|
||||
return offset;
|
||||
}
|
||||
|
||||
int sock_recv(int fd, void *dest, size_t maxlen)
|
||||
int
|
||||
sock_recv (int fd, void *dest, size_t maxlen)
|
||||
{
|
||||
int err;
|
||||
|
||||
if(!dest) return -1;
|
||||
if(maxlen <= 0) return 0;
|
||||
|
||||
|
||||
if (!dest)
|
||||
return -1;
|
||||
if (maxlen <= 0)
|
||||
return 0;
|
||||
|
||||
err = read (fd, dest, maxlen);
|
||||
if (err < 0)
|
||||
{
|
||||
if (err < 0) {
|
||||
//fprintf (stderr,"sock_recv: socket read error\n");
|
||||
//shutdown(fd, 2);
|
||||
return err;
|
||||
}
|
||||
//debug("sock_recv: Got message \"%s\"\n", (char *)dest);
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
+6
-6
@@ -22,15 +22,15 @@
|
||||
|
||||
|
||||
// Client functions...
|
||||
int sock_connect(char *host, unsigned short int port);
|
||||
int sock_close(int fd);
|
||||
int sock_connect (char *host, unsigned short int port);
|
||||
int sock_close (int fd);
|
||||
// Send/receive lines of text
|
||||
int sock_send_string(int fd, char *string);
|
||||
int sock_send_string (int fd, char *string);
|
||||
// Recv gives only one line per call...
|
||||
int sock_recv_string(int fd, char *dest, size_t maxlen);
|
||||
int sock_recv_string (int fd, char *dest, size_t maxlen);
|
||||
// Send/receive raw data
|
||||
int sock_send(int fd, void *src, size_t size);
|
||||
int sock_recv(int fd, void *dest, size_t maxlen);
|
||||
int sock_send (int fd, void *src, size_t size);
|
||||
int sock_recv (int fd, void *dest, size_t maxlen);
|
||||
|
||||
|
||||
// Er, ignore the rest of this file. I'll clean it up sometime...
|
||||
|
||||
+14
-13
@@ -5,30 +5,31 @@
|
||||
#include "debug.h"
|
||||
#include "str.h"
|
||||
|
||||
int get_args(char **argv, char *str, int max_args)
|
||||
int
|
||||
get_args (char **argv, char *str, int max_args)
|
||||
{
|
||||
char *delimiters = " \n\0";
|
||||
char *item;
|
||||
int i=0;
|
||||
int i = 0;
|
||||
|
||||
if(!argv) return -1;
|
||||
if(!str) return 0;
|
||||
if(max_args < 1) return 0;
|
||||
if (!argv)
|
||||
return -1;
|
||||
if (!str)
|
||||
return 0;
|
||||
if (max_args < 1)
|
||||
return 0;
|
||||
|
||||
//debug("get_args(%i): string=%s\n", max_args, str);
|
||||
|
||||
|
||||
// Parse the command line...
|
||||
for(item = strtok(str, delimiters); item; item=strtok(NULL, delimiters))
|
||||
{
|
||||
for (item = strtok (str, delimiters); item; item = strtok (NULL, delimiters)) {
|
||||
//debug("get_args: item=%s\n", item);
|
||||
if(i < max_args)
|
||||
{
|
||||
if (i < max_args) {
|
||||
argv[i] = item;
|
||||
i++;
|
||||
}
|
||||
else return i;
|
||||
} else
|
||||
return i;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
#ifndef STR_H
|
||||
#define STR_H
|
||||
|
||||
int get_args(char **argv, char *str, int max_args);
|
||||
int get_args (char **argv, char *str, int max_args);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user