File: headerline.c

package info (click to toggle)
garlic 1.6-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,516 kB
  • sloc: ansic: 52,465; makefile: 2,254
file content (102 lines) | stat: -rw-r--r-- 3,041 bytes parent folder | download | duplicates (6)
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
/* Copyright (C) 2000 Damir Zucic */

/*=============================================================================

				headerline.c

Purpose:
	Check the input line;  if recognized  as mandatory record,  copy
	the line to HeaderS structure,  which is  member of  MolComplexS
	structure.  The trailing newline is removed (if present at all).
	The PDB header contains,  among others, a keyword called HEADER.
	Don't get confused with the usage of word "header"!

Input:
	(1) Pointer to HeaderS structure,  where line should be added if
	    recognized as mandatory record.
	(2) Input line.
	(3) The first character in the line.

Output:
	(1) If line is mandatory, it will be added to HeaderS structure.
	(2) Return value.

Return value:
	(1) Positive if line added to HeaderS structure.
	(2) Zero if line does not contain mandatory record.
	(3) Negative  if line does  contain  mandatory record,  but  the
	    maximal number of  records of this type is  reached already.

========includes:============================================================*/

#include <stdio.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>

#include "defines.h"
#include "typedefs.h"

/*======check line, copy it if contains mandatory record:====================*/

int CopyHeaderLine_ (HeaderS *hSP, char *lineP, int first_char)
{
char		*P;

P = hSP->dataP;

/* Check is there a mandatory record in input line: */
switch (first_char)
	{
	case 'H':
		if (strstr (lineP, "HEADER") != lineP) return 0;
		if (hSP->header_linesN >= MAXHEADERLINES) return -1;
		hSP->header_linesN++;
		P += hSP->header_offset + hSP->header_linesN * HEADERLINESIZE;
		break;
	case 'T':
		if (strstr (lineP, "TITLE")  != lineP) return 0;
		if (hSP->title_linesN  >= MAXTITLELINES)  return -2;
		hSP->title_linesN++;
		P += hSP->title_offset  + hSP->title_linesN  * HEADERLINESIZE; 
		break;
	case 'C':
		if (strstr (lineP, "COMPND") != lineP) return 0;
		if (hSP->compnd_linesN >= MAXCOMPNDLINES) return -3;
		hSP->compnd_linesN++;
		P += hSP->compnd_offset + hSP->compnd_linesN * HEADERLINESIZE;
		break;
	case 'S':
		if (strstr (lineP, "SOURCE") != lineP) return 0;
		if (hSP->source_linesN >= MAXSOURCELINES) return -4;
		hSP->source_linesN++;
		P += hSP->source_offset + hSP->source_linesN * HEADERLINESIZE;
		break;
	case 'E':
		if (strstr (lineP, "EXPDTA") != lineP) return 0;
		if (hSP->expdta_linesN >= MAXEXPDTALINES) return -5;
		hSP->expdta_linesN++;
		P += hSP->expdta_offset + hSP->expdta_linesN * HEADERLINESIZE;
		break;
	case 'A':
		if (strstr (lineP, "AUTHOR") != lineP) return 0;
		if (hSP->author_linesN >= MAXAUTHORLINES) return -6;
		hSP->author_linesN++;
		P += hSP->author_offset + hSP->author_linesN * HEADERLINESIZE;
		break;
	default:
		return 0;
	}

/* If this point is reached, line contains mandatory record - copy it: */
strncpy (P, lineP, HEADERLINESIZE - 1);
*(P + HEADERLINESIZE - 1) = '\0';

return 1;
}

/*===========================================================================*/