~ubuntu-branches/ubuntu/intrepid/clex/intrepid

« back to all changes in this revision

Viewing changes to src/exec.c

  • Committer: Bazaar Package Importer
  • Author(s): Gabriel Puliatti
  • Date: 2006-10-10 21:00:45 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061010210045-ffvd59e6r74moead
Tags: 3.15-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 * CLEX File Manager
4
4
 *
5
 
 * Copyright (C) 2001-2005 Vlado Potisk <vlado_potisk@clex.sk>
 
5
 * Copyright (C) 2001-2006 Vlado Potisk <vlado_potisk@clex.sk>
6
6
 *
7
7
 * CLEX is free software without warranty of any kind; see the
8
8
 * GNU General Public License as set out in the "COPYING" document
53
53
extern int errno;
54
54
 
55
55
#define MAX_SHELL_ARGS  8
56
 
static char *shell_argv[MAX_SHELL_ARGS + 1];
 
56
static char *shell_argv[MAX_SHELL_ARGS + 2 + 1];
57
57
static int cmd_index;           /* which parameter is the command
58
58
                                                           to be executed */
59
59
 
68
68
}
69
69
 
70
70
static int
 
71
shelltype(const char *shell)
 
72
{
 
73
        size_t len;
 
74
 
 
75
        shell = base_name(shell);
 
76
        len = strlen(shell);
 
77
        if (len >= 2 && strcmp(shell + len - 2,"sh") == 0)
 
78
                return (len >= 3 && shell[len - 3] == 'c');
 
79
        return 2;
 
80
}
 
81
 
 
82
static int
71
83
parse_shellprog(const char *shellprog)
72
84
{
73
85
        char *pch;
74
 
        int i;
 
86
        int i, ac;
75
87
        FLAG arg_end;
76
88
        static USTRING dup = { 0,0 };
77
89
 
92
104
                        }
93
105
                        shell_argv[i++] = pch;
94
106
                }
95
 
        shell_argv[i] = 0;
 
107
        shell_argv[ac = i] = 0;
96
108
 
97
 
        while (--i >= 1)
 
109
        for (cmd_index = 0, i = 1; i < ac; i++)
98
110
                if (strcmp(shell_argv[i],"<COMMAND>") == 0) {
99
111
                        cmd_index = i;  /* real command belongs here */
100
 
                        return 0;               /* success */
 
112
                        break;
101
113
                }
102
114
 
103
 
        txt_printf("CONFIG: Incorrect SHELLPROG: missing \"<COMMAND>\"\n");
104
 
        return -1;
 
115
        /* append: -c <COMMAND> */
 
116
        if (cmd_index == 0) {
 
117
                shell_argv[ac] = "-c";
 
118
                cmd_index = ac + 1;
 
119
                shell_argv[ac + 2] = 0;
 
120
        }
 
121
 
 
122
        clex_data.shelltype = shelltype(shell_argv[0]);
 
123
 
 
124
        return 0;
105
125
}
106
126
 
107
127
/* prepare to execute commands according to "SHELLPROG" */
116
136
        }
117
137
 
118
138
        /* SHELLPROG = AUTO: loginshell -c <COMMAND> */
119
 
        ((const char **)shell_argv)[0] = clex_data.shell;
120
 
        shell_argv[1] = "-c";
121
 
        cmd_index = 2;
122
 
        shell_argv[3] = 0;
 
139
        parse_shellprog(clex_data.shell);
123
140
}
124
141
 
125
142
void
126
143
exec_prompt_reconfig(void)
127
144
{
128
 
        int len;
129
145
        const char *prompt, *chars;
130
146
        static USTRING cmd_prompt = { 0,0 };
131
147
        static char prompt_char[4] = " ? ";
135
151
        if (prompt[0] == '\0') {
136
152
                /* PROMPT=AUTO */
137
153
                prompt = base_name(shell_argv[0]);
138
 
                len = strlen(prompt);
139
 
                if (len >= 2 && strcmp(prompt + len - 2,"sh") == 0)
140
 
                        if (len >= 3 && prompt[len - 3] == 'c')
141
 
                                chars = "%#";   /* looks like C-shell */
142
 
                        else
143
 
                                chars = "$#";   /* looks like Bourne shell */
144
 
                else
145
 
                        chars = ">>";           /* some other shell */
 
154
                switch (clex_data.shelltype) {
 
155
                case 0:
 
156
                        chars = "$#";   /* Bourne shell or similar */
 
157
                        break;
 
158
                case 1:
 
159
                        chars = "%#";   /* C-shell or similar */
 
160
                        break;
 
161
                default:
 
162
                        chars = ">>";   /* some other shell */
 
163
                        break;
 
164
                }
146
165
                prompt_char[1] = chars[clex_data.isroot];
147
166
        }
148
167
        else
218
237
                        puts(
219
238
                                "\r\n"
220
239
                                "\r\n"
221
 
                                "EXEC: CLEX does not support job control\r\n"
 
240
                                "EXEC: CLEX does not provide job control\r\n"
222
241
                                "EXEC: suspended command will be resumed shortly\r\n"
223
242
                                "\r\n");
224
243
                        fflush(stdout);
264
283
        }
265
284
 
266
285
        /*
267
 
         * list directory while the user stares at the screen
268
 
         * reading the command output, CLEX appears to restart
269
 
         * very much faster. All output routines called from
270
 
         * list_directory() must check if curses mode is active,
271
 
         * win_warning() is the only function designed for this
272
 
         * situation.
 
286
         * List the directory while the user stares at the screen
 
287
         * reading the command output. This way CLEX appears to
 
288
         * restart much faster. All output routines called from
 
289
         * list_directory() must check if curses mode is active.
273
290
         */
274
291
        xterm_title_set(0,command);
275
292
        list_directory();
388
405
 
389
406
        tilde = *str == '~';
390
407
        quote = needs_dq = 0;
391
 
        for (real_len = i = 0; (ch = str[i]); i++) {
 
408
        for (real_len = 0, i = tilde /* 0 or 1 */; (ch = str[i]); i++) {
392
409
                if (quote)
393
410
                        quote = 0;
394
411
                else if (ch == '\\')
397
414
                        if (real_len == 0)
398
415
                                real_len = i;
399
416
                }
400
 
                else if (real_len || edit_isspecial(ch))
401
 
                        return 0;       /* not a simple 'cd' command */
 
417
                else if (real_len || edit_isspecial((unsigned char)ch))
 
418
                        return 0;       /*  not a simple 'cd' command */
402
419
        }
403
420
 
404
421
        if (needs_dq) {
414
431
                us_copyn(&dir,str,real_len);
415
432
                dirstr = USTR(dir);
416
433
        }
417
 
        else dirstr = str;
 
434
        else
 
435
                dirstr = str;
418
436
 
419
437
        return tilde ? dir_tilde(dirstr) : dirstr;
420
438
}