File: local.c

package info (click to toggle)
yafc 1.1.1.dfsg.1-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 3,248 kB
  • ctags: 1,679
  • sloc: ansic: 19,338; sh: 10,365; makefile: 155; perl: 38; ruby: 33
file content (99 lines) | stat: -rw-r--r-- 2,219 bytes parent folder | download | duplicates (4)
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
/* $Id: local.c,v 1.5 2003/07/12 10:25:41 mhe Exp $
 *
 * local.c -- local commands
 *
 * Yet Another FTP Client
 * Copyright (C) 1998-2001, Martin Hedenfalk <mhe@stacken.kth.se>
 *
 * 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. See COPYING for more details.
 */

#include "syshdr.h"
#include "input.h"
#include "commands.h"
#include "gvars.h"
#include "strq.h"
#include "utils.h"

/* print local working directory */
void cmd_lpwd(int argc, char **argv)
{
	char tmp[PATH_MAX+1];

	if(argv) {
		OPT_HELP("Print local working directory.  Usage:\n"
				 "  lpwd [options]\n"
				 "Options:\n"
				 "  -h, --help    show this help\n");

		maxargs(optind - 1);
	}

	if(getcwd(tmp, PATH_MAX) == 0) {
		fprintf(stderr, _("Couldn't get local working directory...\n"));
		return;
	}
	printf(_("local working directory is '%s'\n"), tmp);
}

/* local change directory */
void cmd_lcd(int argc, char **argv)
{
	char *e = 0, tmp[PATH_MAX+1];
	char *te;

	OPT_HELP("Change local working directory.  Usage:\n"
			 "  lcd [options] [directory]\n"
			 "Options:\n"
			 "  -h, --help    show this help\n"
			 "if [directory] is '-', lcd changes to the previous working directory\n"
			 "if omitted, changes to home directory\n");

	maxargs(optind);

	if(argc < optind + 1)
		e = gvLocalHomeDir;
	else {
		e = argv[optind];
		if(strcmp(e, "-") == 0)
			e = gvLocalPrevDir;
	}
	if(!e)
		return;
	getcwd(tmp, PATH_MAX);
	te = tilde_expand_home(e, gvLocalHomeDir);
	if(chdir(te) == -1)
		perror(te);
	else {
		free(gvLocalPrevDir);
		gvLocalPrevDir = xstrdup(tmp);
	}
	free(te);
	cmd_lpwd(0, 0);
}

/* FIXME: consider the following:
 *  shell wget -r -q %f
 * which expands to
 *  shell wget -r -q ftp://user:pass@site:port/dir
 * could be useful!?
 *
 * %f - full path ("ftp://user:pass@site:port/dir")
 * %h - hostname ("ftp.foo.bar")
 * %p - port number
 * %u - username
 * %d - current directory
 */

void cmd_shell(int argc, char **argv)
{
	char *e = 0;

	if(argc > 1)
		e = args_cat(argc, argv, 1);
	invoke_shell(e);
	free(e);
}