File: ls_groups.c

package info (click to toggle)
grass 6.0.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 40,044 kB
  • ctags: 31,303
  • sloc: ansic: 321,125; tcl: 25,676; sh: 11,176; cpp: 10,098; makefile: 5,025; fortran: 1,846; yacc: 493; lex: 462; perl: 133; sed: 1
file content (135 lines) | stat: -rw-r--r-- 3,293 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*************************************************************
* I_list_groups (full)
* I_list_subgroups (group, full)
*************************************************************/
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "imagery.h"

static char *tempfile = NULL;

int I_list_groups (int full)
{
    char *element;
    int i;

    char buf[1024];
    char title[50];
    FILE *ls, *temp, *popen();
    struct Ref ref;
    int any;

    if (tempfile == NULL)
	tempfile = G_tempfile();

    element = "group";
    G__make_mapset_element (element);

    temp = fopen (tempfile, "w");
    if (temp == NULL)
	G_fatal_error ("can't open any temp files");
    fprintf (temp, "Available groups\n");
    fprintf (temp, "---------------------------------\n");

    any = 0;
    strcpy (buf, "cd ");
    G__file_name (buf+strlen(buf), element, "", G_mapset());
    strcat (buf, ";ls");
    if (!full) strcat (buf, " -C");
    if(ls = popen (buf, "r"))
    {
	while (G_getl(buf, sizeof buf, ls))
	{
	    any=1;
	    fprintf (temp, "%s", buf);
	    if (full)
	    {
		I_get_group_title (buf, title, sizeof title);
		if (*title)
		    fprintf (temp, " (%s)", title);
		fprintf (temp, "\n");
		I_get_group_ref (buf, &ref);
		for (i = 0; i < ref.nfiles; i++)
		    fprintf (temp, "\t%s in %s\n", ref.file[i].name, ref.file[i].mapset);
		if (ref.nfiles <= 0)
		    fprintf (temp, "\t** empty **\n");
		I_free_group_ref (&ref);
	    }
	    else 
		fprintf (temp, "\n");
	}
	pclose (ls);
    }
    if (!any)
	fprintf (temp, "no group files available\n");
    fprintf (temp, "---------------------------------\n");
    fclose (temp);
    sprintf (buf, "$GRASS_PAGER %s", tempfile);
    G_system(buf);
    remove ( tempfile );
    fprintf (stdout,"hit RETURN to continue -->");
    fflush(stdout);
    G_gets(buf);

    return 0;
}

int I_list_subgroups (char *group,int full)
{
    char element[100];
    int i;

    char buf[1024];
    FILE *ls, *temp, *popen();
    struct Ref ref;
    int any;

    if (tempfile == NULL)
	tempfile = G_tempfile();

    sprintf (element, "group/%s/subgroup", group);
    G__make_mapset_element (element);

    temp = fopen (tempfile, "w");
    if (temp == NULL)
	G_fatal_error ("can't open any temp files");
    fprintf (temp, "Available subgroups in group %s\n", group);
    fprintf (temp, "---------------------------------\n");

    any = 0;
    strcpy (buf, "cd ");
    G__file_name (buf+strlen(buf), element, "", G_mapset());
    strcat (buf, ";ls");
    if (!full) strcat (buf, " -C");
    if(ls = popen (buf, "r"))
    {
	while (G_getl(buf, sizeof buf, ls))
	{
	    any=1;
	    fprintf (temp, "%s\n", buf);
	    if (full)
	    {
		I_get_subgroup_ref (group, buf, &ref);
		for (i = 0; i < ref.nfiles; i++)
		    fprintf (temp, "\t%s in %s\n", ref.file[i].name, ref.file[i].mapset);
		if (ref.nfiles <= 0)
		    fprintf (temp, "\t** empty **\n");
		I_free_group_ref (&ref);
	    }
	}
	pclose (ls);
    }
    if (!any)
	fprintf (temp, "no subgroup files available\n");
    fprintf (temp, "---------------------------------\n");
    fclose (temp);
    sprintf (buf, "$GRASS_PAGER %s", tempfile);
    G_system(buf);
    remove ( tempfile );
    fprintf (stdout,"hit RETURN to continue -->");
    fflush(stdout);
    G_gets(buf);

    return 0;
}