File: mgeti.c

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (210 lines) | stat: -rw-r--r-- 4,409 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* Copyright INRIA */
#include <stdio.h>
#include <string.h>

#ifdef __STDC__
#include <stdlib.h>
#endif
#include "../machine.h"
#include "../fileio/st.h"

int SWAP(char type[],integer *fd); /* Defined at the end of this file */

struct soundstream ftf;
extern FILE *GetFile();
extern int GetSwap();
extern void sciprint __PARAMS ((char *fmt,...));
extern int islittle_endian(void); /* Defined in SCI/routines/fileio/sound.c */

#define MGETI(Type,Fswap) {\
Type *RES;\
Type val; \
RES=(Type *)res;\
for ( i=0; i< *n; i++)  { \
  if ( fread(&val,sizeof(Type),1,fa) != 1) {items= i;break;};\
  if ( swap) val = Fswap(val);\
  *RES++ = val; }\
}

/*****************************************************************
 * read n items of type type 
 * if read fails *ierr contains the number of properly read items 
 ****************************************************************/



void C2F(mgeti) (fd,res,n,type,ierr)
     integer *res;
     integer *n,*ierr,*fd;
     char type[];
{  
  char c1,c2;
  int i,items=-1,nc,swap;
  ft_t ft;
  FILE *fa;
  char *RES_c;
  unsigned char *RES_uc;
  unsigned long *RES_ul;
  unsigned short *RES_us;

  RES_c=(char *)res;
  RES_uc=(unsigned char *)res;
  RES_ul=(unsigned long *)res;
  RES_us=(unsigned short *)res;

  fa = GetFile(fd);
  swap = GetSwap(fd);
  ft = &ftf; 
  ft->fp = fa;
  nc=strlen(type);
  if ( nc == 0) 
    {
      sciprint("mgeti : format is of 0 length  \r\n",type);
      *ierr=1;
      return;
    }

  if (fa)
    { 
      switch ( type[0] ) {
	case 'l' : 
	  swap=SWAP(type,fd);
	  if(swap<0) {*ierr=1;return;}
	  MGETI(long,swapl);
	  break;
	case 's' : 
	  swap=SWAP(type,fd); 
	  if(swap<0) {*ierr=1;return;}
	  MGETI(short,swapw);
	  break;
	case 'c' :
	  for ( i=0; i< *n; i++) 
	    {
	      char val;
	      if ( fread(&val,sizeof(char),1,fa) != 1) 
		 {items= i;break;}
	      *RES_c++ = val;
	    }
	  break;
	case 'u' :
	  if ( strlen(type) > 1) c1=type[1] ;
	  else c1=' ';

	  switch ( c1 )
	    {
	    case 'b' :
	      if ( strlen(type) > 2) c2=type[2];
	      else c2=' ';
	      switch ( c2)
		{
		case 'l' :
		  /* Read long, big-endian: big end first. 
		     68000/SPARC style. */
		  for ( i=0; i< *n; i++) 
		    {
		      unsigned long val;
		      val = rblong(ft);
		      if ( feof(fa) != 0)  {items= i;break;}
		      *RES_ul ++ = val ;
		    }
		  break;
		case 's' :
		  /* Read short, big-endian: big end first. 
		     68000/SPARC style. */
		  for ( i=0; i< *n; i++) 
		    {
		      unsigned short val;
		      val = rbshort(ft);
		      if ( feof(fa) != 0)  {items= i;break;}
		      *RES_us++ = val;
		    }
		  break;
		}
	      break;
	    case 'l' : 
	      if ( strlen(type) > 2) c2=type[2];
	      else c2=' ';
	      switch ( c2 )
		{
		case 'l' :
		  /* Read long, little-endian: little end first. 
		     VAX/386 style.*/
		  for ( i=0; i< *n; i++) 
		      {
			unsigned long val;
			val = rllong(ft);
			if ( feof(fa) != 0)  {items= i;break;}
			*RES_ul++ = val;
		      }
		  break;
		case 's' :
		  /* Read short, little-endian: little end first. 
		     VAX/386 style.*/
		  for ( i=0; i< *n; i++) 
		    {
		      unsigned short val;
		      val = rlshort(ft);
		      if ( feof(fa) != 0)  {items= i;break;}
		      *RES_us++ = val;
		    }
		  break;
		default: 
		  MGETI(unsigned long,swapl);
		  break;
		}
	      break;
	    case 's' : 
	      MGETI(unsigned short,swapw);
	      break;
	    case 'c' :
	      for ( i=0; i< *n; i++) 
		{
		  unsigned char  val;
		  if ( fread(&val,sizeof(unsigned char),1,fa)!= 1) 
		    {items= i;break;};
		  *RES_uc++ = val;
		}
	      break;
	    default :
	      sciprint("mget : %s format not recognized \r\n",type);
	      *ierr=1;
	      return;
	    }
	  break;
	default :
	  sciprint("mget : %s format not recognized \r\n",type);
	  *ierr=1;
	  return;
	}
      if ( items != -1 ) 
	{
	  *ierr = -(items) -1 ;
	  /** sciprint("Read %d out of \r\n",items,*n); **/
	}
      return;
    }
  sciprint("No input file \r\n");
  *ierr=1;
}
int SWAP(type,fd)
char type[];
integer *fd;
{
int nc,swap;
  nc=strlen(type);
  swap = GetSwap(fd);
  if ( nc > 1) {
    switch (type[1])  {
    case 'b': 
      if (islittle_endian()==1) swap=1;else swap=0; 
      break; 
    case 'l': 
      if (islittle_endian()==1) swap=0;else swap=1; 
      break; 
    default:
      sciprint("mgeti : unknown format %s  \r\n",type);
      swap=-1;
    }
  }
return swap;
}