~ubuntu-branches/debian/stretch/vifm/stretch

« back to all changes in this revision

Viewing changes to src/registers.c

  • Committer: Bazaar Package Importer
  • Author(s): Edelhard Becker
  • Date: 2005-08-09 15:15:09 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050809151509-0csu5v00b8gfvypy
Tags: 0.3-2
ACK NMU, thanks Blars (Closes: #320118)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vifm
 
2
 * Copyright (C) 2001 Ken Steen.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 
17
 */
 
18
 
 
19
#include<unistd.h>
 
20
#include<string.h>
 
21
 
 
22
#include"menus.h"
 
23
#include"registers.h"
 
24
#include"utils.h"
 
25
 
 
26
char valid_registers[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
 
27
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
 
28
'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 
 
29
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
 
30
 
 
31
int
 
32
is_valid_register(int key)
 
33
{
 
34
        int x = 0;
 
35
 
 
36
        for (x = 0; x < strlen(valid_registers); x++)
 
37
        {
 
38
                if (key == (int)valid_registers[x])
 
39
                        return 1;
 
40
        }
 
41
 
 
42
        return 0;
 
43
}
 
44
 
 
45
static int
 
46
check_for_duplicate_file_names(int pos, char *file)
 
47
{
 
48
        int z;
 
49
        int x = 0;
 
50
        for (z = 0; z < reg[pos].num_files; z++)
 
51
        {
 
52
                if (!strcmp(file, reg[pos].files[z]))
 
53
                        return ++x;
 
54
        }
 
55
        return x;
 
56
}
 
57
 
 
58
void
 
59
append_to_register(int key, char *file)
 
60
{
 
61
        int i = 0;
 
62
 
 
63
        if (access(file, F_OK))
 
64
                return;
 
65
 
 
66
        for (i = 0; i < NUM_REGISTERS; i++)
 
67
        {
 
68
                if (reg[i].name == key)
 
69
                {
 
70
                        if (check_for_duplicate_file_names(i, file))
 
71
                                break;
 
72
                        reg[i].num_files++;
 
73
                        reg[i].files = (char **)realloc(reg[i].files,
 
74
                                        reg[i].num_files  * sizeof(char *));
 
75
                        reg[i].files[reg[i].num_files - 1] = strdup(file);
 
76
                        break;
 
77
                }
 
78
 
 
79
        }
 
80
}
 
81
 
 
82
void
 
83
clear_register(int key)
 
84
{
 
85
        int i = 0;
 
86
 
 
87
        for (i = 0; i < NUM_REGISTERS; i++)
 
88
        {
 
89
                if (reg[i].name == key)
 
90
                {
 
91
                        int y = reg[i].num_files;
 
92
                        while (y)
 
93
                        {
 
94
                                y--;
 
95
                                my_free(reg[i].files[y]);
 
96
                        }
 
97
                        reg[i].num_files = 0;
 
98
                        break;
 
99
                }
 
100
        }
 
101
}