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

« back to all changes in this revision

Viewing changes to src/lib/libpsio/init.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 init.c
 
3
   \ingroup (PSIO)
 
4
*/
 
5
 
 
6
#include <stdio.h>
 
7
#include <stdlib.h>
 
8
#include "psio.h"
 
9
#include <libipv1/ip_lib.h>
 
10
#include <libciomr/libciomr.h>
 
11
#include <psifiles.h>
 
12
 
 
13
/* Definitions of global structs */
 
14
psio_ud *psio_unit;
 
15
psio_address PSIO_ZERO = {0,0};
 
16
 
 
17
/* Library state variable */
 
18
int _psi3_libpsio_state_ = 0;
 
19
 
 
20
#ifdef PSIO_STATS
 
21
ULI *psio_readlen;
 
22
ULI *psio_writlen;
 
23
#endif
 
24
 
 
25
/*!
 
26
** PSIO_INIT(): Allocates global memory needed by the I/O routines.
 
27
**
 
28
** No arguments.
 
29
**
 
30
** \ingroup (PSIO)
 
31
*/
 
32
 
 
33
int psio_init(void)
 
34
{
 
35
  int i,j;
 
36
  char *userhome;
 
37
  char filename[PSIO_MAXSTR];
 
38
  FILE *psirc;
 
39
 
 
40
  psio_unit = (psio_ud *) malloc(sizeof(psio_ud)*PSIO_MAXUNIT);
 
41
 
 
42
#ifdef PSIO_STATS
 
43
  psio_readlen = (ULI *) malloc(sizeof(ULI) * PSIO_MAXUNIT);
 
44
  psio_writlen = (ULI *) malloc(sizeof(ULI) * PSIO_MAXUNIT);
 
45
#endif
 
46
 
 
47
  if(psio_unit == NULL) {
 
48
    fprintf(stderr, "Error in PSIO_INIT()!\n");
 
49
    exit(PSI_RETURN_FAILURE);
 
50
  }
 
51
 
 
52
  for(i=0; i < PSIO_MAXUNIT; i++) {
 
53
#ifdef PSIO_STATS
 
54
    psio_readlen[i] = psio_writlen[i] = 0;
 
55
#endif      
 
56
    psio_unit[i].numvols = 0;
 
57
    for(j=0; j < PSIO_MAXVOL; j++) {
 
58
      psio_unit[i].vol[j].path = NULL;
 
59
      psio_unit[i].vol[j].stream = -1;
 
60
    }
 
61
    psio_unit[i].tocaddress.page = 0;
 
62
    psio_unit[i].tocaddress.offset = 0;
 
63
    psio_unit[i].toclen = 0;
 
64
    psio_unit[i].toc = NULL;
 
65
  }
 
66
 
 
67
  /* Open user's general .psirc file, if extant */
 
68
  userhome = getenv("HOME");
 
69
  sprintf(filename, "%s%s", userhome, "/.psirc");
 
70
  psirc = fopen(filename, "r");
 
71
  if(psirc != NULL) {
 
72
    ip_append(psirc, stdout);
 
73
    fclose(psirc);
 
74
  }
 
75
 
 
76
  /* Set library's state variable to initialized value (1) */
 
77
  _psi3_libpsio_state_ = 1;
 
78
 
 
79
  return(0);
 
80
}
 
81
 
 
82
/*!
 
83
** PSIO_STATE(): Returns state of the library (1=initialized, 0=noninitialized).
 
84
**
 
85
** No arguments.
 
86
**
 
87
** \ingroup (PSIO)
 
88
*/
 
89
 
 
90
int psio_state()
 
91
{
 
92
  return _psi3_libpsio_state_;
 
93
}
 
94