~ubuntu-branches/debian/squeeze/alpine/squeeze

« back to all changes in this revision

Viewing changes to pico/osdep/shell.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if !defined(lint) && !defined(DOS)
 
2
static char rcsid[] = "$Id: shell.c 165 2006-10-04 01:09:47Z jpf@u.washington.edu $";
 
3
#endif
 
4
 
 
5
/*
 
6
 * ========================================================================
 
7
 * Copyright 2006 University of Washington
 
8
 *
 
9
 * Licensed under the Apache License, Version 2.0 (the "License");
 
10
 * you may not use this file except in compliance with the License.
 
11
 * You may obtain a copy of the License at
 
12
 *
 
13
 *     http://www.apache.org/licenses/LICENSE-2.0
 
14
 *
 
15
 * ========================================================================
 
16
 */
 
17
 
 
18
 
 
19
#include <system.h>
 
20
#include <general.h>
 
21
 
 
22
#include "../estruct.h"
 
23
#include "../mode.h"
 
24
#include "../pico.h"
 
25
#include "../edef.h"
 
26
#include "../efunc.h"
 
27
#include "../keydefs.h"
 
28
 
 
29
#include "shell.h"
 
30
 
 
31
 
 
32
 
 
33
/* internal prototypes */
 
34
#ifdef  SIGCONT
 
35
RETSIGTYPE rtfrmshell(int);
 
36
#endif
 
37
 
 
38
 
 
39
 
 
40
#ifdef  SIGTSTP
 
41
/*
 
42
 *  bktoshell - suspend and wait to be woken up
 
43
 */
 
44
int
 
45
bktoshell(void)         /* suspend MicroEMACS and wait to wake up */
 
46
{
 
47
    if(!(gmode&MDSSPD)){
 
48
        emlwrite("\007Unknown command: ^Z", NULL);
 
49
        return(0);
 
50
    }
 
51
 
 
52
    if(Pmaster){
 
53
        if(!Pmaster->suspend){
 
54
            emlwrite("\007Unknown command: ^Z", NULL);
 
55
            return(0);
 
56
        }
 
57
 
 
58
        if((*Pmaster->suspend)() == NO_OP_COMMAND){
 
59
            int rv;
 
60
        
 
61
            if(km_popped){
 
62
                term.t_mrow = 2;
 
63
                curwp->w_ntrows -= 2;
 
64
            }
 
65
 
 
66
            clearcursor();
 
67
            mlerase();
 
68
            rv = (*Pmaster->showmsg)('x');
 
69
            ttresize();
 
70
            picosigs();
 
71
            if(rv)              /* Did showmsg corrupt the display? */
 
72
              pico_refresh(0, 1);       /* Yes, repaint */
 
73
 
 
74
            mpresf = 1;
 
75
            if(km_popped){
 
76
                term.t_mrow = 0;
 
77
                curwp->w_ntrows += 2;
 
78
            }
 
79
        }
 
80
        else{
 
81
            ttresize();
 
82
            pclear(0, term.t_nrow);
 
83
            pico_refresh(0, 1);
 
84
        }
 
85
 
 
86
        return(1);
 
87
    }
 
88
 
 
89
    if(gmode&MDSPWN){
 
90
        char *shell;
 
91
        int   dummy;
 
92
 
 
93
        vttidy();
 
94
        movecursor(0, 0);
 
95
        (*term.t_eeop)();
 
96
        printf("\n\n\nUse \"exit\" to return to Pi%s\n",
 
97
               (gmode & MDBRONLY) ? "lot" : "co");
 
98
        system((shell = (char *)getenv("SHELL")) ? shell : "/bin/csh");
 
99
        rtfrmshell(dummy);      /* fixup tty */
 
100
    }
 
101
    else {
 
102
        movecursor(term.t_nrow-1, 0);
 
103
        peeol();
 
104
        movecursor(term.t_nrow, 0);
 
105
        peeol();
 
106
        movecursor(term.t_nrow, 0);
 
107
        printf("\n\n\nUse \"fg\" to return to Pi%s\n",
 
108
               (gmode & MDBRONLY) ? "lot" : "co");
 
109
        ttclose();
 
110
        movecursor(term.t_nrow, 0);
 
111
        peeol();
 
112
        (*term.t_flush)();
 
113
 
 
114
        signal(SIGCONT, rtfrmshell);    /* prepare to restart */
 
115
        signal(SIGTSTP, SIG_DFL);                       /* prepare to stop */
 
116
        kill(0, SIGTSTP);
 
117
    }
 
118
 
 
119
    return(1);
 
120
}
 
121
#else
 
122
#ifdef _WINDOWS
 
123
int
 
124
bktoshell(void)
 
125
{
 
126
    if(!(gmode&MDSSPD)){
 
127
        emlwrite("\007Unknown command: ^Z", NULL);
 
128
        return(0);
 
129
    }
 
130
    if(Pmaster){
 
131
        if(!Pmaster->suspend){
 
132
            emlwrite("\007Unknown command: ^Z", NULL);
 
133
            return(0);
 
134
        }
 
135
        (*Pmaster->suspend)();
 
136
        return(1);
 
137
    }
 
138
                         
 
139
    mswin_minimize();
 
140
    return(1);
 
141
}
 
142
#endif /* _WINDOWS */
 
143
 
 
144
#endif /* SIGTSTP */
 
145
 
 
146
#ifdef  SIGCONT
 
147
/* 
 
148
 * rtfrmshell - back from shell, fix modes and return
 
149
 */
 
150
RETSIGTYPE
 
151
rtfrmshell(int sig)
 
152
{
 
153
    signal(SIGCONT, SIG_DFL);
 
154
    ttopen();
 
155
    ttresize();
 
156
    pclear(0, term.t_nrow);
 
157
    pico_refresh(0, 1);
 
158
}
 
159
#endif /* SIGCONT */