home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / comms / x_sun_psio / code / psbackupexclude.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-20  |  4.1 KB  |  161 lines

  1. /* (C) Tim Graves 20th April 1994
  2.    This code is supplied AS IS. no warrantee either expressed or implied 
  3.    is provided. This code may be freeley modified and modified as long as my
  4.    origional authorship is acknowledged. 
  5.    
  6.    Tim Graves
  7.     Sun Microsystems
  8.      
  9.      */
  10. /* this file contains the excludelist for the backup subsystem, it is used to 
  11. remove files from the backup */
  12. /* it can also be used by the restore sub system as the format of the path 
  13.    names are different, i.e. m:\wrd\tim.wrd and wrd/tim.wrd, note the path 
  14.    separator is different */
  15. #include <stdio.h>
  16. #include "psion.h"
  17. #include "psbackupexclude.h"
  18. #include <ctype.h>
  19. #include <string.h>
  20. extern int debugcall ;
  21. static char vsn[]="@(#) psbackupexclude.c 3.3@(#)" ;
  22. /* the structures to hold the exclude entries */
  23. struct excludestruct * exclude;
  24. initexclude()
  25. {
  26.     if (debugcall >= EXCLUDECALLDEBUG)
  27.         fprintf(stderr, "CALL: initexclude()\n") ;
  28.     exclude == NULL ;
  29. }
  30.  
  31. setupexclude (path)
  32. char * path ;
  33. {
  34.     struct excludestruct * current;
  35.     if (debugcall >= EXCLUDECALLDEBUG)
  36.         fprintf(stderr, "CALL: setupexclude (path = %s)\n",path) ;
  37.     current = exclude ;
  38.     /* first of all does the exclude already ? if so ignore it */
  39.     while (current != NULL)
  40.     {
  41.         if (strcmp(current->path, path) == 0)
  42.         {
  43.             return  ;
  44.         }
  45.         current = current->nextexclude ;
  46.     }
  47.     /* we've got here and not found a exclude, install at the end 
  48.        of the list */
  49.     return (newexclude(path)) ;
  50. }
  51. removeexclude (path)
  52. char * path ;
  53. {
  54.     struct excludestruct * current, *prev;
  55.     if (debugcall >= EXCLUDECALLDEBUG)
  56.         fprintf(stderr, "CALL: removeexclude (path = %s)\n",path) ;
  57.     if (exclude == NULL) 
  58.         return(OK) ;
  59.     current = exclude ;
  60.     /* check if the exclude is the first in the list */
  61.     if (strcmp(exclude->path, path) == 0)
  62.     {
  63.         /* make sure we have a start pointer */
  64.         exclude = exclude->nextexclude ;
  65.         /* free the path pointer */
  66.         free (current->path) ;
  67.         /* free the structure */
  68.         free(current) ;
  69.         return(OK) ;
  70.     }
  71.     prev = exclude ;
  72.     while (current != NULL)
  73.     {
  74.         if (strcmp(current->path, path) == 0)
  75.         {
  76.             /* remove from the list */
  77.             prev->nextexclude = current->nextexclude ;
  78.             /* free the path pointer */
  79.             free (current -> path) ;
  80.             /* free the structure */
  81.             free (current);
  82.             return (OK);
  83.         }
  84.         /* next item on the list */
  85.         prev = current ;
  86.         current = current->nextexclude ;
  87.     }
  88. }
  89.     
  90. /* install a exclude into list */
  91. installexclude (path, current)
  92. struct excludestruct *current ;
  93. char * path ;
  94. {
  95.     if (debugcall >= EXCLUDECALLDEBUG)
  96.         fprintf(stderr, "CALL: installexclude (path = %s, current = (OMITED))\n",path) ;
  97.     /* lets do the setup */
  98.     current->path = (char *) calloc(1, strlen(path) +1) ; /* length plus the \0 */
  99.     strcpy(current->path, path) ;
  100.     return (OK) ;
  101. }
  102.  
  103. /* newexclude, create a exclude add it to the list then fill it */
  104. newexclude(path)
  105. char * path ;
  106. {
  107.     struct excludestruct *new ;
  108.     if (debugcall >= EXCLUDECALLDEBUG)
  109.         fprintf(stderr, "CALL: newexclude (path = %s, )\n",path) ;
  110.     new = (struct excludestruct *) calloc (1, sizeof (struct excludestruct)) ;
  111.     /* add it to the head of the list */
  112.     new->nextexclude = exclude ;
  113.     exclude = new ;
  114.     /* create the exclude */
  115.     return (installexclude(path, exclude));
  116. }
  117. /* print each item in the exclude list */
  118. printexclude()
  119. {
  120.     struct excludestruct *current ;
  121.     if (debugcall >= EXCLUDECALLDEBUG)
  122.         fprintf(stderr, "CALL: printexclude ()\n") ;
  123.     /* initialise to the head of the list */
  124.     current = exclude ;
  125.     if (exclude == NULL) 
  126.     {
  127.         printf("No backup excludes currently installed\n") ;
  128.         return(OK) ;
  129.     }
  130.     printf("Current installed backup excludes\n") ;
  131.     /* run through the list */
  132.     while (current != NULL)
  133.     {
  134.         printf("%s\n", current->path)  ;
  135.         /* next item on the list */
  136.         current = current->nextexclude ;
  137.     }
  138. }
  139.  
  140.  
  141. /* if the exclude is set return TRUE, otherwise return FALSE */
  142. findexclude(path)
  143. char * path ;
  144. {
  145.     struct excludestruct * current;
  146.     if (debugcall >= EXCLUDECALLDEBUG)
  147.         fprintf(stderr, "CALL: findexclude (path = %s)\n",path) ;
  148.     current = exclude ;
  149.     /* lets doit */
  150.     while (current != NULL)
  151.     {
  152.         if  (strcmp(current->path, path) == 0)
  153.         {
  154.             return (TRUE) ;
  155.         }
  156.         current = current->nextexclude ;
  157.     }
  158.     /* we've got here and not found a exclude return FALSE*/
  159.     return (FALSE) ;
  160. }
  161.