~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/lib/libpsio/tocclean.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
   \file tocclean.c
 
3
   \ingroup (PSIO)
 
4
*/
 
5
 
 
6
#include <string.h>
 
7
#include <stdlib.h>
 
8
#include "psio.h"
 
9
 
 
10
/*!
 
11
** PSIO_TOCCLEAN(): Delete all TOC entries after the given key.
 
12
** If a blank key is given, the entire TOC will be wiped.
 
13
**
 
14
** \ingroup (PSIO)
 
15
*/
 
16
 
 
17
int psio_tocclean(unsigned int unit, char *key)
 
18
{
 
19
  psio_tocentry *this_entry, *last_entry, *prev_entry;
 
20
 
 
21
  /* Check the key length first */
 
22
  if((strlen(key)+1) > PSIO_KEYLEN) psio_error(unit,PSIO_ERROR_KEYLEN);
 
23
 
 
24
  this_entry = psio_tocscan(unit, key);
 
25
  if(this_entry == NULL) {
 
26
      if(!strcmp(key,"")) this_entry = psio_unit[unit].toc;
 
27
      else {
 
28
          fprintf(stderr, "PSIO_ERROR: Can't find TOC Entry %s\n", key);
 
29
          psio_error(unit,PSIO_ERROR_NOTOCENT);
 
30
      }
 
31
    }
 
32
  else this_entry = this_entry->next;
 
33
 
 
34
  /* Get the end of the TOC and work backwards */
 
35
  last_entry = psio_toclast(unit);
 
36
 
 
37
  while((last_entry != this_entry) && (last_entry != NULL)) { 
 
38
      /* Now free all the remaining members */
 
39
      prev_entry = last_entry->last;
 
40
      free(last_entry);
 
41
      last_entry = prev_entry;
 
42
    }
 
43
  return(0);
 
44
}