aboutsummaryrefslogtreecommitdiff
path: root/noao/astcat/src/agetcat/t_aclist.x
blob: 4c13e1edf7a344471fac53e8de601589e5014cf6 (plain) (blame)
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
103
104
105
106
107
108
109
110
111
112
# T_ACLIST -- List the supported catalogs.

procedure t_aclist() 

pointer	sp, str1, str2, line, cq
int	i, j, catlist, nquery, nheader, nfields
bool	verbose
pointer	cq_map()
int	at_catlist(), fntlenb(), fntrfnb(), cq_setcat(), cq_fgeti(), cq_scan()
bool	clgetb()
errchk	cq_fgeti()

begin
        # Allocate some working memory.
        call smark (sp)
        call salloc (str1, SZ_FNAME, TY_CHAR)
        call salloc (str2, SZ_FNAME, TY_CHAR)
        call salloc (line, SZ_LINE, TY_CHAR)

	# Get the parameters.
        call clgstr ("catalogs", Memc[str1], SZ_FNAME)
        call clgstr ("catdb", Memc[str2], SZ_FNAME)
        verbose = clgetb ("verbose")

        # Get the catalog list.
        catlist = at_catlist (Memc[str1],  Memc[str2])
        if (fntlenb (catlist) <= 0) {
	    if (verbose)
                call printf ("The catalog list is empty\n")
            call fntclsb (catlist)
            call sfree (sp)
            return
        }

        # Open the catalog database.
        cq = cq_map (Memc[str2], READ_ONLY)
	if (verbose) {
            call printf ("\nScanning catalog database %s\n")
                call pargstr (Memc[str2])
	}

	# Loop over the catalogs.
	if (verbose)
	    call printf ("Listing the supported catalogs\n")
        do i = 1, fntlenb (catlist) {

            # Get the catalog name and set the current catalog.
            if (fntrfnb (catlist, i, Memc[str1], SZ_FNAME) == EOF)
                break
            if (cq_setcat (cq, Memc[str1]) <= 0) {
                next
            } else {
                call printf ("%s\n")
                    call pargstr (Memc[str1])
            }

	    # Do a detailed listing.
	    if (verbose) {
		iferr (nquery = cq_fgeti (cq, "nquery"))
		    nquery = 0
		call printf ("nquery %d\n")
		    call pargi (nquery)
		if (nquery > 0) {
		    do j = 1, nquery {
			if (cq_scan (cq) == EOF)
			    break
			call gargstr (Memc[line], SZ_LINE)
			call printf ("%s\n")
			    call pargstr (Memc[line])
		    }
		}
		iferr (nheader = cq_fgeti (cq, "nheader"))
		    nheader = 0
		call printf ("nheader %d\n")
		    call pargi (nheader)
		if (nheader > 0) {
		    do j = 1, nheader {
			if (cq_scan (cq) == EOF)
			    break
			call gargstr (Memc[line], SZ_LINE)
			call printf ("%s\n")
			    call pargstr (Memc[line])
		    }
		}
		iferr (nfields = cq_fgeti (cq, "nfields"))
		    nfields = 0
		call printf ("nfields %d\n")
		    call pargi (nfields)
		if (nfields > 0) {
		    do j = 1, nfields {
			if (cq_scan (cq) == EOF)
			    break
			call gargstr (Memc[line], SZ_LINE)
			call printf ("%s\n")
			    call pargstr (Memc[line])
		    }
		}
		if (nquery > 0 || nheader > 0 || nfields > 0)
		    call printf ("\n")
	    }
	}


        # Close the catalog database.
        call cq_unmap (cq)

        # Close the catalog list.
        call fntclsb (catlist)

	# Free working memory.
	call sfree (sp)
end