1 /*****************************************************************************
2 *
3 *   indexpub.c
4 *      indexes a Pub-set by Medline UID
5 *
6 *****************************************************************************/
7 #include "allpub.h"
8 
9 #define NUMARGS 3
10 Args myargs[NUMARGS] = {
11 	{ "Input data", "medline.val", "Pub-set", NULL, FALSE, 'i', ARG_DATA_IN, 0.0,0,NULL},
12 	{ "Input data is binary", "T", NULL, NULL, TRUE , 'b', ARG_BOOLEAN, 0.0,0,NULL},
13 	{ "Output index table", "medline.idx", NULL, NULL, FALSE, 't', ARG_FILE_OUT, 0.0,0,NULL}};
14 
15 
Main(void)16 Int2 Main(void)
17 {
18 	AsnIoPtr aip;
19 	AsnTypePtr atp;
20 	DataVal value;
21 	Int4 seekptr, tempseek, uid;
22 	static CharPtr intypes[2] = { "r", "rb" };
23 	Int2 intype;
24 	FILE *fp;
25 
26     if (! AsnLoad())
27         Message(MSG_FATAL, "Unable to load allpub parse tree.");
28 
29 	if (! GetArgs("IndexPub 1.0", NUMARGS, myargs))
30 		return 1;
31 
32 	if (myargs[1].intvalue)        /* binary input is TRUE */
33 		intype = 1;
34 	else
35 		intype = 0;
36 
37 	if ((aip = AsnIoOpen(myargs[0].strvalue, intypes[intype])) == NULL)
38 	{
39 		Message(MSG_ERROR, "Couldn't open %s", myargs[0].strvalue);
40 		return 1;
41 	}
42 
43 	if ((fp = FileOpen(myargs[2].strvalue, "w")) == NULL)
44 	{
45 		Message(MSG_ERROR, "Couldn't open %s", myargs[2].strvalue);
46 		return 1;
47 	}
48 
49 	atp = PUB_SET;
50 	tempseek = 0L;
51 
52 	while ((atp = AsnReadId(aip, amp, atp)) != NULL)
53 	{
54 		if (atp == PUB_SET_medline_E)
55 			seekptr = tempseek;
56 		if (atp == MEDLINE_ENTRY_uid)
57 		{
58 			AsnReadVal(aip, atp, &value);
59 			uid = value.intvalue;
60 			fprintf(fp, "%d %d\n", uid, seekptr);
61 		}
62 		else
63 			AsnReadVal(aip, atp, NULL);
64 		tempseek = AsnIoTell(aip);
65 	}
66 
67 	aip = AsnIoClose(aip);
68 	FileClose(fp);
69 	return 0;
70 
71 }
72 
73