2 $Header: /cvs/src/tdl/narrow.c,v 1.2.2.1 2004/01/07 00:09:05 richard Exp $
4 tdl - A console program for managing to-do lists
5 Copyright (C) 2001-2004 Richard P. Curnow
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
24 static struct node *narrow_top = NULL;
25 static char *narrow_prefix = NULL;
27 struct node *get_narrow_top(void)/*{{{*/
32 char *get_narrow_prefix(void)/*{{{*/
37 static char *generate_prefix(struct node *x, char *suffix)
40 struct node *y, *parent;
42 int suffix_len, count_len;
50 for (y = parent->kids.next; y != x; y = y->chain.next) count++;
52 for (y = top.next; y != x; y = y->chain.next) count++;
54 sprintf(buffer, "%d", count);
55 count_len = strlen(buffer);
56 suffix_len = strlen(suffix);
57 total_len = count_len + suffix_len;
58 if (suffix_len) ++total_len; /* allow for '.' */
60 new_suffix = new_array(char, 1+total_len);
61 strcpy(new_suffix, buffer);
62 if (suffix_len) strcat(new_suffix, ".");
63 strcat(new_suffix, suffix);
66 result = generate_prefix(parent, new_suffix);
74 static void setup_narrow_prefix(void)/*{{{*/
81 narrow_prefix = generate_prefix(narrow_top, "");
84 int process_narrow(char **x)/*{{{*/
92 fprintf(stderr, "Usage : narrow <entry_index>\n");
96 n = lookup_node(x[0], 0, NULL);
101 /* Compute prefix string. */
102 setup_narrow_prefix();
107 int process_widen(char **x)/*{{{*/
112 struct node *new_narrow_top;
114 argc = count_args(x);
116 fprintf(stderr, "Usage : widen [<n_levels>]\n");
120 if (sscanf(x[0], "%d", &n_levels) != 1) {
121 fprintf(stderr, "Usage : widen [<n_levels>]\n");
128 new_narrow_top = narrow_top;
129 if (!new_narrow_top) goto widen_to_top;
131 for (i=0; i<n_levels; i++) {
132 new_narrow_top = new_narrow_top->parent;
133 if (!new_narrow_top) goto widen_to_top;
136 narrow_top = new_narrow_top;
137 setup_narrow_prefix();
140 /* Widen back to top level */
145 narrow_prefix = NULL;