source: gsdl/trunk/runtime-src/packages/d2m/M2Mconv.c@ 18879

Last change on this file since 18879 was 10365, checked in by kjdon, 19 years ago

changed my mind, now adding these all individually instead of in a tar file

  • Property svn:keywords set to Author Date Id Revision
File size: 1.5 KB
Line 
1/* ------------------------------------------------------------------- */
2/* M2Mconv : Convert an ISO 2709 record into MARC format */
3/* Author : Ole Husby, BIBSYS */
4/* Updated : 1998-09-30 */
5/* ------------------------------------------------------------------- */
6
7#include <stdlib.h>
8#include <string.h>
9#include <stdio.h>
10#include <ctype.h>
11#include <unistd.h>
12
13
14
15
16int M2Mconv(char *dfile, char *buffer, char *tfile, int format)
17{
18 char mtype[16], line[50000];
19 char *l, *p, *bf;
20 int lines;
21 FILE *df, *tf;
22
23 tf = (FILE *) NULL;
24 strcpy(mtype, "bibsys");
25
26
27/* Open inputfile */
28
29 df = fopen(dfile, "r");
30 if (!df)
31 return 0; /* Error: Unable to read data */
32
33
34
35/* Open tracefile */
36
37 if (*tfile)
38 {
39 tf = fopen(tfile, "w");
40 if (!tf)
41 {
42 fclose(df);
43 return 0; /* Error: Unable to create trace */
44 }
45 }
46
47
48/* Reads the file */
49
50 lines = 0;
51
52 while (l = fgets(line, 49999, df))
53 {
54/* Remove trailing lf or cr */
55
56 while ( (l[strlen(l) - 1] == '\n') || (l[strlen(l) - 1] == '\r') )
57 l[strlen(l) -1] = '\0';
58
59 lines++;
60 if (lines > 1)
61 break; /* Error: Not a 2709 file */
62 p = l;
63 }
64
65
66/* Close files */
67
68 fclose(df);
69
70 if (tf)
71 fclose(tf);
72
73 if ( lines > 1 )
74 return 0;
75
76
77/* Convert to line format */
78
79 bf = (char *) marc2line(p, mtype);
80
81 strcpy(buffer, bf);
82
83 return 1;
84}
Note: See TracBrowser for help on using the repository browser.