Changeset 880


Ignore:
Timestamp:
Apr 21, 2007, 9:47:39 AM (18 years ago)
Author:
bird
Message:

hacking...

Location:
trunk/src/ash-messup
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/ash-messup/bltin/bltin.h

    r626 r880  
    8484#endif
    8585
    86 pointer stalloc(int);
    87 void error(const char *, ...);
    88 void sh_warnx(const char *, ...);
    89 void sh_exit(int) __attribute__((__noreturn__));
     86pointer stalloc(struct shinstance *, int);
     87void error(struct shinstance *, const char *, ...);
     88void sh_warnx(struct shinstance *, const char *, ...);
     89void sh_exit(struct shinstance *, int) __attribute__((__noreturn__));
    9090
    91 int echocmd(int, char **);
     91int echocmd(struct shinstance *, int, char **);
    9292
    9393
    94 extern const char *commandname;
     94/*extern const char *commandname;*/
  • trunk/src/ash-messup/main.c

    r879 r880  
    8181#define PROFILE 0
    8282
    83 int rootpid;
    84 int rootshell;
     83/*int rootpid;
     84int rootshell;*/
    8585STATIC union node *curcmd;
    8686STATIC union node *prevcmd;
     
    8989STATIC char *find_dot_file(char *);
    9090int main(int, char **);
     91int shell_main(shinstance *, int, char **);
     92#ifdef _MSC_VER
     93extern void init_syntax(void);
     94#endif
    9195
    9296/*
     
    103107        shinstance *psh;
    104108
     109        /*
     110         * Global initializations.
     111         */
    105112        setlocale(LC_ALL, "");
    106 
     113#ifdef _MSC_VER
     114        init_syntax();
     115#endif
    107116        /*
    108117         * Create the root shell instance.
     
    111120        if (!psh)
    112121                return 2;
     122        shthread_set_shell(psh);
    113123        return shell_main(psh, argc);
    114124}       
     
    129139                 * the shell procedure.
    130140                 */
    131                 switch (exception) {
     141                switch (psh->exception) {
    132142                case EXSHELLPROC:
    133                         rootpid = getpid();
    134                         rootshell = 1;
    135                         minusc = NULL;
    136                         state = 3;
     143                        psh->rootpid = /*getpid()*/ psh->pid;
     144                        psh->rootshell = 1;
     145                        psh->minusc = NULL;
     146                        psh->state = 3;
    137147                        break;
    138148
    139149                case EXEXEC:
    140                         exitstatus = exerrno;
     150                        psh->exitstatus = psh->exerrno;
    141151                        break;
    142152
    143153                case EXERROR:
    144                         exitstatus = 2;
     154                        psh->exitstatus = 2;
    145155                        break;
    146156
     
    149159                }
    150160
    151                 if (exception != EXSHELLPROC) {
    152                         if (state == 0 || iflag == 0 || ! rootshell)
    153                                 exitshell(exitstatus);
    154                 }
    155                 reset();
    156                 if (exception == EXINT
     161                if (psh->exception != EXSHELLPROC) {
     162                        if (state == 0 || iflag == 0 || ! psh->rootshell)
     163                                exitshell(psh, exitstatus);
     164                }
     165                reset(psh);
     166                if (psh->exception == EXINT
    157167#if ATTY
    158                  && (! attyset() || equal(termval(), "emacs"))
     168                 && (! attyset(psh) || equal(termval(psh), "emacs"))
    159169#endif
    160170                 ) {
    161                         out2c('\n');
     171                        out2c(psh, '\n');
    162172                        flushout(&errout);
    163173                }
    164                 popstackmark(&smark);
     174                popstackmark(psh, &smark);
    165175                FORCEINTON;                             /* enable interrupts */
    166176                if (state == 1)
     
    174184        }
    175185        psh->handler = &jmploc;
     186        psh->rootpid = /*getpid()*/ psh->pid;
     187        psh->rootshell = 1;
    176188#ifdef DEBUG
    177189#if DEBUG == 2
    178190        debug = 1;
    179191#endif
    180         opentrace();
     192        opentrace(psh);
    181193        trputs("Shell args:  ");  trargs(argv);
    182194#endif
    183         psh->rootpid = getpid();
    184         psh->rootshell = 1;
    185 #ifdef _MSC_VER
    186     {
    187         extern void init_syntax(void);
    188         init_syntax();
    189     }
    190 #endif
    191         init();
    192         setstackmark(&smark);
    193         procargs(argc, argv);
     195
     196        init(psh);
     197        setstackmark(psh, &smark);
     198        procargs(psh, argc, argv);
    194199        if (argv[0] && argv[0][0] == '-') {
    195200                state = 1;
     
    209214state3:
    210215        state = 4;
    211         if (sflag == 0 || minusc) {
     216        if (psh->sflag == 0 || psh->minusc) {
    212217                static int sigs[] =  {
    213218                    SIGINT, SIGQUIT, SIGHUP,
     
    242247
    243248void
    244 cmdloop(int top)
     249cmdloop(struct shinstance *psh, int top)
    245250{
    246251        union node *n;
     
    250255
    251256        TRACE(("cmdloop(%d) called\n", top));
    252         setstackmark(&smark);
     257        setstackmark(psh, &smark);
    253258        for (;;) {
    254                 if (pendingsigs)
    255                         dotrap();
     259                if (psh->pendingsigs)
     260                        dotrap(psh);
    256261                inter = 0;
    257                 if (iflag && top) {
     262                if (psh->iflag && top) {
    258263                        inter = 1;
    259                         showjobs(out2, SHOW_CHANGED);
    260                         chkmail(0);
    261                         flushout(&errout);
    262                 }
    263                 n = parsecmd(inter);
     264                        showjobs(psh, psh->out2, SHOW_CHANGED);
     265                        chkmail(psh, 0);
     266                        flushout(&psh->errout);
     267                }
     268                n = parsecmd(psh, inter);
    264269                /* showtree(n); DEBUG */
    265270                if (n == NEOF) {
    266271                        if (!top || numeof >= 50)
    267272                                break;
    268                         if (!stoppedjobs()) {
    269                                 if (!Iflag)
     273                        if (!stoppedjobs(psh)) {
     274                                if (!psh->Iflag)
    270275                                        break;
    271                                 out2str("\nUse \"exit\" to leave shell.\n");
     276                                out2str(psh, "\nUse \"exit\" to leave shell.\n");
    272277                        }
    273278                        numeof++;
    274                 } else if (n != NULL && nflag == 0) {
    275                         job_warning = (job_warning == 2) ? 1 : 0;
     279                } else if (n != NULL && psh->nflag == 0) {
     280                        psh->job_warning = (psh->job_warning == 2) ? 1 : 0;
    276281                        numeof = 0;
    277                         evaltree(n, 0);
    278                 }
    279                 popstackmark(&smark);
    280                 setstackmark(&smark);
    281                 if (evalskip == SKIPFILE) {
    282                         evalskip = 0;
     282                        evaltree(psh, n, 0);
     283                }
     284                popstackmark(psh, &smark);
     285                setstackmark(psh, &smark);
     286                if (psh->evalskip == SKIPFILE) {
     287                        psh->evalskip = 0;
    283288                        break;
    284289                }
    285290        }
    286         popstackmark(&smark);
     291        popstackmark(psh, &smark);
    287292}
    288293
     
    294299
    295300STATIC void
    296 read_profile(const char *name)
     301read_profile(struct shinstance *psh, const char *name)
    297302{
    298303        int fd;
     
    301306
    302307        INTOFF;
    303         if ((fd = open(name, O_RDONLY)) >= 0)
    304                 setinputfd(fd, 1);
     308        if ((fd = shfile_open(psh, name, O_RDONLY)) >= 0)
     309                setinputfd(psh, fd, 1);
    305310        INTON;
    306311        if (fd < 0)
    307312                return;
    308313        /* -q turns off -x and -v just when executing init files */
    309         if (qflag)  {
    310             if (xflag)
    311                     xflag = 0, xflag_set = 1;
    312             if (vflag)
    313                     vflag = 0, vflag_set = 1;
    314         }
    315         cmdloop(0);
    316         if (qflag)  {
     314        if (psh->qflag)  {
     315            if (psh->xflag)
     316                    psh->xflag = 0, xflag_set = 1;
     317            if (psh->vflag)
     318                    psh->vflag = 0, vflag_set = 1;
     319        }
     320        cmdloop(psh, 0);
     321        if (psh->qflag)  {
    317322            if (xflag_set)
    318                     xflag = 1;
     323                    psh->xflag = 1;
    319324            if (vflag_set)
    320                     vflag = 1;
    321         }
    322         popfile();
     325                    psh->vflag = 1;
     326        }
     327        popfile(psh);
    323328}
    324329
     
    330335
    331336void
    332 readcmdfile(char *name)
     337readcmdfile(struct shinstance *psh, char *name)
    333338{
    334339        int fd;
     
    336341        INTOFF;
    337342        if ((fd = open(name, O_RDONLY)) >= 0)
    338                 setinputfd(fd, 1);
     343                setinputfd(psh, fd, 1);
    339344        else
    340345                error("Can't open %s", name);
    341346        INTON;
    342         cmdloop(0);
    343         popfile();
     347        cmdloop(psh, 0);
     348        popfile(psh);
    344349}
    345350
     
    353358
    354359STATIC char *
    355 find_dot_file(char *basename)
     360find_dot_file(struct shinstance *psh, char *basename)
    356361{
    357362        char *fullname;
    358         const char *path = pathval();
     363        const char *path = pathval(psh);
    359364        struct stat statb;
    360365
     
    363368                return basename;
    364369
    365         while ((fullname = padvance(&path, basename)) != NULL) {
     370        while ((fullname = padvance(psh, &path, basename)) != NULL) {
    366371                if ((stat(fullname, &statb) == 0) && S_ISREG(statb.st_mode)) {
    367372                        /*
     
    371376                        return fullname;
    372377                }
    373                 stunalloc(fullname);
     378                stunalloc(psh, fullname);
    374379        }
    375380
     
    380385
    381386int
    382 dotcmd(int argc, char **argv)
    383 {
    384         exitstatus = 0;
     387dotcmd(struct shinstance *psh, int argc, char **argv)
     388{
     389        psh->exitstatus = 0;
    385390
    386391        if (argc >= 2) {                /* That's what SVR2 does */
     
    388393                struct stackmark smark;
    389394
    390                 setstackmark(&smark);
    391                 fullname = find_dot_file(argv[1]);
    392                 setinputfile(fullname, 1);
    393                 commandname = fullname;
    394                 cmdloop(0);
    395                 popfile();
    396                 popstackmark(&smark);
    397         }
    398         return exitstatus;
     395                setstackmark(psh, &smark);
     396                fullname = find_dot_file(psh, argv[1]);
     397                setinputfile(psh, fullname, 1);
     398                psh->commandname = fullname;
     399                cmdloop(psh, 0);
     400                popfile(psh);
     401                popstackmark(psh, &smark);
     402        }
     403        return psh->exitstatus;
    399404}
    400405
    401406
    402407int
    403 exitcmd(int argc, char **argv)
    404 {
    405         if (stoppedjobs())
     408exitcmd(struct shinstance *psh, int argc, char **argv)
     409{
     410        if (stoppedjobs(psh))
    406411                return 0;
    407412        if (argc > 1)
    408                 exitstatus = number(argv[1]);
    409         exitshell(exitstatus);
     413                psh->exitstatus = number(argv[1]);
     414        exitshell(psh, exitstatus);
    410415        /* NOTREACHED */
    411416}
     417
     418/*
     419 * Local Variables:
     420 *   c-file-style: bsd
     421 * End:
     422 */
  • trunk/src/ash-messup/options.h

    r879 r880  
    6969
    7070DEF_OPT( "errexit",     'e' )   /* exit on error */
    71 #define eflag psh->optlist[0].val
     71#define eflag optlist[0].val
    7272DEF_OPT( "noglob",      'f' )   /* no pathname expansion */
    73 #define fflag psh->optlist[1].val
     73#define fflag optlist[1].val
    7474DEF_OPT( "ignoreeof",   'I' )   /* do not exit on EOF */
    75 #define Iflag psh->optlist[2].val
     75#define Iflag optlist[2].val
    7676DEF_OPT( "interactive",'i' )    /* interactive shell */
    77 #define iflag psh->optlist[3].val
     77#define iflag optlist[3].val
    7878DEF_OPT( "monitor",     'm' )   /* job control */
    79 #define mflag psh->optlist[4].val
     79#define mflag optlist[4].val
    8080DEF_OPT( "noexec",      'n' )   /* [U] do not exec commands */
    81 #define nflag psh->optlist[5].val
     81#define nflag optlist[5].val
    8282DEF_OPT( "stdin",       's' )   /* read from stdin */
    83 #define sflag psh->optlist[6].val
     83#define sflag optlist[6].val
    8484DEF_OPT( "xtrace",      'x' )   /* trace after expansion */
    85 #define xflag psh->optlist[7].val
     85#define xflag optlist[7].val
    8686DEF_OPT( "verbose",     'v' )   /* trace read input */
    87 #define vflag psh->optlist[8].val
     87#define vflag optlist[8].val
    8888DEF_OPTS( "vi",         'V', 'V' )      /* vi style editing */
    89 #define Vflag psh->optlist[9].val
     89#define Vflag optlist[9].val
    9090DEF_OPTS( "emacs",      'E', 'V' )      /* emacs style editing */
    91 #define Eflag psh->optlist[10].val
     91#define Eflag optlist[10].val
    9292DEF_OPT( "noclobber",   'C' )   /* do not overwrite files with > */
    93 #define Cflag psh->optlist[11].val
     93#define Cflag optlist[11].val
    9494DEF_OPT( "allexport",   'a' )   /* export all variables */
    95 #define aflag psh->optlist[12].val
     95#define aflag optlist[12].val
    9696DEF_OPT( "notify",      'b' )   /* [U] report completion of background jobs */
    97 #define bflag psh->optlist[13].val
     97#define bflag optlist[13].val
    9898DEF_OPT( "nounset",     'u' )   /* error expansion of unset variables */
    99 #define uflag psh->optlist[14].val
     99#define uflag optlist[14].val
    100100DEF_OPT( "quietprofile", 'q' )
    101 #define qflag psh->optlist[15].val
     101#define qflag optlist[15].val
    102102DEF_OPT( "nolog",       0 )     /* [U] no functon defs in command history */
    103 #define nolog psh->optlist[16].val
     103#define nolog optlist[16].val
    104104DEF_OPT( "cdprint",     0 )     /* always print result of cd */
    105 #define cdprint psh->optlist[17].val
     105#define cdprint optlist[17].val
    106106DEF_OPT( "tabcomplete", 0 )     /* <tab> causes filename expansion */
    107 #define tabcomplete psh->optlist[18].val
     107#define tabcomplete optlist[18].val
    108108#ifdef DEBUG
    109109DEF_OPT( "debug",       0 )     /* enable debug prints */
    110 #define debug psh->optlist[19].val
     110#define debug optlist[19].val
    111111#endif
    112112
  • trunk/src/ash-messup/output.h

    r879 r880  
    7575int xioctl(int, unsigned long, char *);
    7676
    77 #define outc(c, file)   (--(file)->nleft < 0? (emptyoutbuf(psh, file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
    78 #define out1c(c)        outc(c, psh->out1);
    79 #define out2c(c)        outc(c, psh->out2);
     77#define outc(c, file)   (--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
     78#define out1c(psh, c)   outc(c, (psh)->out1);
     79#define out2c(psh, c)   outc(c, (psh)->out2);
    8080
    8181#define OUTPUT_INCL
  • trunk/src/ash-messup/shinstance.h

    r879 r880  
    153153    int                 funcnest;
    154154    int                 evalskip;
     155
     156    /* builtins.h */
     157    const char         *commandname;
     158
    155159} shinstance;
    156160
  • trunk/src/ash-messup/show.h

    r879 r880  
    4242void trputc(int);
    4343void trputs(const char *);
    44 void opentrace(void);
     44void opentrace(struct shinstance *);
    4545#endif
  • trunk/src/ash-messup/var.h

    r879 r880  
    100100 */
    101101
    102 #define ifsval()        (psh->vifs.text + 4)
    103 #define ifsset()        ((psh->vifs.flags & VUNSET) == 0)
    104 #define mailval()       (psh->vmail.text + 5)
    105 #define mpathval()      (psh->vmpath.text + 9)
     102#define ifsval(psh)     ((psh)->vifs.text + 4)
     103#define ifsset(psh)     (((psh)->vifs.flags & VUNSET) == 0)
     104#define mailval(psh)    ((psh)->vmail.text + 5)
     105#define mpathval(psh)   ((psh)->vmpath.text + 9)
    106106#ifdef _MSC_VER
    107 #define pathval()       (psh->vpath.text[5] ? &psh->vpath.text[5] : &psh->vpath2.text[5])
     107#define pathval(psh)    ((psh)->vpath.text[5] ? &(psh)->vpath.text[5] : &(psh)->vpath2.text[5])
    108108#else
    109 #define pathval()       (psh->vpath.text + 5)
     109#define pathval(psh)    ((psh)->vpath.text + 5)
    110110#endif
    111 #define ps1val()        (psh->vps1.text + 4)
    112 #define ps2val()        (psh->vps2.text + 4)
    113 #define ps4val()        (psh->vps4.text + 4)
    114 #define optindval()     (psh->voptind.text + 7)
     111#define ps1val(psh)     ((psh)->vps1.text + 4)
     112#define ps2val(psh)     ((psh)->vps2.text + 4)
     113#define ps4val(psh)     ((psh)->vps4.text + 4)
     114#define optindval(psh)  ((psh)->voptind.text + 7)
    115115#ifndef SMALL
    116 #define histsizeval()   (psh->vhistsize.text + 9)
    117 #define termval()       (psh->vterm.text + 5)
     116#define histsizeval(psh) ((psh)->vhistsize.text + 9)
     117#define termval(psh)    ((psh)->vterm.text + 5)
    118118#endif
    119119
    120120#if ATTY
    121 #define attyset()       ((psh->vatty.flags & VUNSET) == 0)
     121#define attyset(psh)    (((psh)->vatty.flags & VUNSET) == 0)
    122122#endif
    123 #define mpathset()      ((psh->vmpath.flags & VUNSET) == 0)
     123#define mpathset(psh)   (((psh)->vmpath.flags & VUNSET) == 0)
    124124
    125125void initvar(struct shinstance *);
Note: See TracChangeset for help on using the changeset viewer.