File: cmprecord.x

package info (click to toggle)
iraf-st4gem 1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 30,316 kB
  • sloc: fortran: 4,161; ansic: 2,564; pascal: 1,092; lisp: 1,046; yacc: 969; makefile: 89; python: 18; sh: 7
file content (88 lines) | stat: -rw-r--r-- 2,141 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
include "hdiff.h"

# CMP_RECORD -- Compare two record values and determine their ordering
#
# This procedure determines the ordering of the value fields of two keyword
# records. If the value in the first record is less than the value in the
# second, a negative number is returned. If the value in the first record
# is greater than the value in the second, a positive number is returned.
# If they are equal, a zero is returned. Trailing blanks in quoted fields
# are not considered significant in the comparison.
#
# B.Simon	25-Apr-90	Original

int procedure cmp_record (record1, record2)

char	record1[ARB]	# i: First record
char	record2[ARB]	# i: Second record
#--
char	delim1, delim2
int	ic, jc, order

begin
	# Skip over leading blanks and get the value delimeter
	# (either a blank or a single quote)

	for (ic = START_VALUE; record1[ic] == ' '; ic = ic + 1)
	    ;

	if (record1[ic] == '\'') {
	    ic = ic + 1
	    delim1 = '\''
	} else {
	    delim1 = ' '
	}

	for (jc = START_VALUE; record2[jc] == ' '; jc = jc + 1)
	    ;

	if (record2[jc] == '\'') {
	    jc = jc + 1
	    delim2 = '\''
	} else {
	    delim2 = ' '
	}

	# Find the first characters which do not compare
	# or fall off the end of the value

	while (record1[ic] == record2[jc]) {
	    if (record1[ic] == EOS || record1[ic] == delim1)
		break
	    ic = ic + 1
	    jc = jc + 1
	}

	# The two value strings are equal (order == 0) if:
	# Both strings have reached the closing delimeter or
	# One string has reached the closing delimeter and the
	# remaining characters in the other string are blank.
	# Blanks can only be part of a value if the delimeter
	# is a single quote.

	if (record1[ic] == delim1) {
	    if (delim2 == '\'') {
		while (record2[jc] == ' ')
		    jc = jc + 1
	    }
	    if (record2[jc] == delim2) {
		order = 0
	    } else {
		order = - record2[jc]
	    }			
	} else if (record2[jc] == delim2) {
	    if (delim1 == '\'') {
		while (record1[ic] == ' ')
		    ic = ic + 1
	    }
	    if (record1[ic] == delim1) {
		order = 0
	    } else {
		order = record1[ic]
	    }    	
	} else {
	   order = record1[ic] - record2[jc]
	}

	return (order)
end