home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / testzip.zip / queue.c < prev    next >
C/C++ Source or Header  |  1997-02-25  |  3KB  |  97 lines

  1. /*****************************************************************
  2.  * Testzip version 1.13                                          *
  3.  * Test zip file integrity, Nuke Bad Zips                        *
  4.  * Also prints a list of what it deleted in optional logfile.    *
  5.  *                                                               *
  6.  * Programmer: Madman, with suggestions from Pantera             *
  7.  * Date: 12/6/96     Version 1.0                                 *
  8.  *                                                               *
  9.  * Modified by: Jeff Hamilton, hjeffrey@wam.umd.edu              *
  10.  * Date: 12/8/96     Version 1.01                                *
  11.  * Date: 12/12/96    Version 1.02                                *
  12.  * Date: 12/13/96    Version 1.03                                *
  13.  * Date: 12/15/96    Version 1.04                                *
  14.  * Date: 1/5/97      Version 1.1                                 *
  15.  *                                                               *
  16.  * Queue functions by John Dowdal (queue.c and queue.h)          *
  17.  *                                                               *
  18.  * See the readme.txt included with this source code for more    *
  19.  * information, and instructions for compiling and using this    *
  20.  * program.                                                      *
  21.  *                                                               *
  22.  * Disclaimer:   DISCLAIM THIS!!!!                               *
  23.  * This program and source code are distributed as is.  There is *
  24.  * NO guarantee that it will work on all systems.  Please test   *
  25.  * it out before using.  The programmers take no responsibilty   *
  26.  * for lost or damaged files, or any other problems that use of  *
  27.  * this software might cause.                                    *
  28.  *                                                               *
  29.  * Bug Reports:                                                  *
  30.  * If you find a bug, please e-mail a description of your        *
  31.  * operating system, what the bug does, and how to reproduce it  *
  32.  * to hjeffrey@wam.umd.edu  I will make every effort to find and *
  33.  * correct the bug.                                              *
  34.  *****************************************************************/
  35.  
  36. #include<stdio.h>
  37. #include<stdlib.h>
  38. #include<assert.h>
  39. #include<string.h>
  40. #include<sys/types.h>
  41. #include<sys/stat.h>
  42. #include "queue.h"
  43.  
  44. void initq(queue *q) {
  45.   assert(q!=NULL);
  46.   if(q) {
  47.     q->first=q->last=NULL;
  48.   }
  49. }
  50.  
  51. qeltt *newqelt() {
  52.   qeltt *ret;
  53.  
  54.   if ( (  ret=malloc(sizeof (qeltt)))==NULL ) {
  55.     fprintf(stderr," Out of memory.\n");
  56.     exit(1);
  57.   }
  58.  
  59.   return ret;
  60. }
  61.  
  62. void addq(queue *q,char *data) {
  63.   qeltt *newelt = newqelt();
  64.  
  65.   assert(q!=NULL);
  66.   assert(data!=NULL);
  67.  
  68.   newelt->data=strdup(data);
  69.   newelt->next=NULL;
  70.  
  71.   if(q->first==NULL) {
  72.     q->last=q->first=newelt;
  73.   } else {
  74.     q->last->next=newelt;
  75.     q->last=newelt;
  76.   }
  77. }
  78.  
  79. qeltt *delq(queue *q) {
  80.   qeltt *ret;
  81.  
  82.   assert(q!=NULL);
  83.   assert(q->first!=NULL);
  84.  
  85.   ret=q->first;
  86.   q->first=q->first->next;
  87.   if(q->first==NULL)
  88.     q->last=NULL;
  89.   return ret;
  90. }
  91.  
  92. int emptyq(queue *q) {
  93.   assert (q!=NULL);
  94.  
  95.   return q->first==NULL;
  96. }
  97.