Attachment 'tags.c'
Download 1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "fio.h"
6 #include "error.h"
7 #include "tags.h"
8
9 /* $Id : $Exp */
10
11 int
12 TAGskip(FILE *fp, int tag, long long len)
13 {
14 #if 1
15 unsigned char *buf ;
16 int ret ;
17
18 buf = (unsigned char *)calloc(len, sizeof(unsigned char)) ;
19 if (buf==NULL)
20 ErrorExit(ERROR_NOMEMORY,
21 "TAGskip: failed to calloc %u bytes!\n",len);
22 ret = fread(buf, sizeof(unsigned char), len, fp) ;
23 free(buf) ;
24 return(ret) ;
25 #else
26 return(fseek(fp, len, SEEK_CUR)) ; // doesn't work for gzipped files
27 #endif
28 }
29 int
30 TAGreadStart(FILE *fp, long long *plen)
31 {
32 int tag ;
33
34 tag = freadInt(fp) ;
35 if (feof(fp))
36 return(0) ;
37 switch (tag)
38 {
39 case TAG_OLD_MGH_XFORM:
40 *plen = (long long)freadInt(fp) ; /* sorry - backwards compatibility
41 with Tosa's stuff */
42 *plen = *plen -1 ; // doesn't include null
43 break ;
44 case TAG_OLD_SURF_GEOM: // these don't take lengths at all
45 case TAG_OLD_USEREALRAS:
46 case TAG_OLD_COLORTABLE:
47 *plen = 0 ;
48 break ;
49 default:
50 *plen = freadLong(fp) ;
51 }
52
53 return(tag) ;
54 }
55
56 int
57 TAGwriteStart(FILE *fp, int tag, long long *phere, long long len)
58 {
59 long here ;
60
61 fwriteInt(tag, fp) ;
62
63 here = ftell(fp) ;
64 *phere = (long long)here ;
65 fwriteLong(len, fp) ;
66
67 return(NO_ERROR) ;
68 }
69
70 int
71 TAGwrite(FILE *fp, int tag, void *buf, long long len)
72 {
73 long long here ;
74
75 TAGwriteStart(fp, tag, &here, len) ;
76 fwrite(buf, sizeof(char), len, fp) ;
77 TAGwriteEnd(fp, here) ;
78 return(NO_ERROR) ;
79 }
80
81 int
82 TAGwriteEnd(FILE *fp, long long there)
83 {
84 long long here ;
85
86 here = ftell(fp) ;
87 #if 0
88 fseek(fp, there, SEEK_SET) ;
89 fwriteLong((long long)(here-(there+sizeof(long long))), fp) ;
90 fseek(fp, here, SEEK_SET) ;
91 #endif
92
93 return(NO_ERROR) ;
94 }
95
96 int
97 TAGmakeCommandLineString(int argc, char **argv, char *cmd_line)
98 {
99 int i ;
100
101 cmd_line[0] = 0 ;
102 for (i = 0 ; i < argc ; i++)
103 {
104 strcat(cmd_line, argv[i]) ;
105 strcat(cmd_line, " ") ;
106 }
107 return(NO_ERROR) ;
108 }
109
110 int
111 TAGwriteCommandLine(FILE *fp, char *cmd_line)
112 {
113 long long here ;
114
115 TAGwriteStart(fp, TAG_CMDLINE, &here, strlen(cmd_line)+1) ;
116 fprintf(fp, "%s", cmd_line) ;
117 TAGwriteEnd(fp, here) ;
118 return(NO_ERROR) ;
119 }
120
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.- [get | view] (2009-01-26 22:35:32, 12.9 KB) [[attachment:fio.c]]
- [get | view] (2009-01-26 22:35:32, 1.3 KB) [[attachment:fio.h]]
- [get | view] (2009-01-26 22:35:32, 5.9 KB) [[attachment:load_mgh.m]]
- [get | view] (2009-01-26 22:35:32, 9.3 KB) [[attachment:matrix.h]]
- [get | view] (2009-01-26 22:35:32, 390.2 KB) [[attachment:mri.c]]
- [get | view] (2009-01-26 22:35:32, 48.5 KB) [[attachment:mri.h]]
- [get | view] (2009-01-26 22:35:32, 94.4 KB) [[attachment:mri_convert.c]]
- [get | view] (2009-01-26 22:35:32, 14.1 KB) [[attachment:mri_info.c]]
- [get | view] (2009-01-26 22:35:32, 395.4 KB) [[attachment:mriio.c]]
- [get | view] (2009-01-26 22:35:32, 2.4 KB) [[attachment:save_mgh.m]]
- [get | view] (2009-01-26 22:35:32, 2.2 KB) [[attachment:tags.c]]
- [get | view] (2009-01-26 22:35:32, 0.9 KB) [[attachment:tags.h]]
You are not allowed to attach a file to this page.