File: functions.c

package info (click to toggle)
cftp 0.12-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 968 kB
  • ctags: 853
  • sloc: ansic: 9,541; sh: 327; makefile: 92
file content (157 lines) | stat: -rw-r--r-- 2,581 bytes parent folder | download
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
  $NiH: functions.c,v 1.13 2002/09/16 12:42:34 dillo Exp $

  functions.c -- auxiliary functions for bindable function handling
  Copyright (C) 1996-2002 Dieter Baron

  This file is part of cftp, a fullscreen ftp client
  The author can be contacted at <dillo@giga.or.at>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/



#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "display.h"
#include "bindings.h"
#include "functions.h"
#include "options.h"

int prefix_arg, prefix_valid = 0;



void
void_prefix(void)
{
	prefix_valid = 0;
}



int
get_prefix(int deflt)
{
	return (prefix_valid ? prefix_arg : deflt);
}



int
get_prefix_args(char **args, int deflt)
{
    if (args)
	return atoi(args[0]);
    else
	return (prefix_valid ? prefix_arg : deflt);
}



void
add_prefix(int n)
{
	if (prefix_valid)
		prefix_arg = prefix_arg*10 + n;
	else {
		prefix_valid = 1;
		prefix_arg = n;
	}
	show_prefix();
}



void
set_prefix(int p)
{
    prefix_valid = 1;
    prefix_arg = p;
    show_prefix();
}



void
negate_prefix(void)
{
    return;
}



void
show_prefix(void)
{

	disp_status(DISP_STATUS, ": %d", prefix_arg);
}



int
find_function(char *f)
{
    int i;
    
    for (i=0; functions[i].name && strcmp(f, functions[i].name); i++)
	    ;

    return (functions[i].name ? i : -1);
}



enum state binding_state;

struct binding *
get_function(int nr, enum state state)
{
    struct binding *b;
    
    if (state == bs_none)
	state = binding_state;

    for (b=binding[nr].next; b; b=b->next)
	if (b->state == state)
	    return b;

    return &binding[nr];
}



char *binding_statename[] = {
    "<global>", "<remote>", "<local>", "<tag>", NULL
};

enum state
parse_state(char *name)
{
    int i;

    if (name[0] != '<' || name[strlen(name)-1] != '>')
	return bs_nostate;

    for (i=0; binding_statename[i]; i++)
	if (strcasecmp(name, binding_statename[i]) == 0)
	    return i;

    return bs_unknown;
}