~ubuntu-branches/debian/squeeze/mksh/squeeze

« back to all changes in this revision

Viewing changes to histrap.c

  • Committer: Bazaar Package Importer
  • Author(s): Thorsten Glaser
  • Date: 2010-07-29 08:54:25 UTC
  • mfrom: (1.1.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20100729085425-s3kq56iv7xpg0kvz
Tags: 39.3.20100725-1
* The “Portability?” release
* Another new CVS snapshot:
  - [tg] More int → bool conversion
  - [tg] Fix window size not being checked during runtime
    of external programmes by not relying on SIGWINCH so
    much but instead checking before every interactive
    editing of a command line
* High urgency because 39.3.20100721-1 isn’t yet in testing
* Policy 3.9.1.0, no changes needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <sys/file.h>
27
27
#endif
28
28
 
29
 
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.97 2010/07/17 22:09:35 tg Exp $");
 
29
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.98 2010/07/24 17:08:29 tg Exp $");
30
30
 
31
31
/*-
32
32
 * MirOS: This is the default mapping type, and need not be specified.
50
50
#endif
51
51
 
52
52
static int hist_execute(char *);
53
 
static int hist_replace(char **, const char *, const char *, int);
 
53
static int hist_replace(char **, const char *, const char *, bool);
54
54
static char **hist_get(const char *, bool, bool);
55
55
static char **hist_get_oldest(void);
56
56
static void histbackup(void);
72
72
        struct temp *tf;
73
73
        const char *p;
74
74
        char *editor = NULL;
75
 
        int gflag = 0, lflag = 0, nflag = 0, sflag = 0, rflag = 0;
 
75
        bool gflag = false, lflag = false, nflag = false, rflag = false,
 
76
            sflag = false;
76
77
        int optc;
77
78
        const char *first = NULL, *last = NULL;
78
79
        char **hfirst, **hlast, **hp;
88
89
                case 'e':
89
90
                        p = builtin_opt.optarg;
90
91
                        if (ksh_isdash(p))
91
 
                                sflag++;
 
92
                                sflag = true;
92
93
                        else {
93
94
                                size_t len = strlen(p);
94
95
                                editor = alloc(len + 4, ATEMP);
97
98
                        }
98
99
                        break;
99
100
                case 'g': /* non-AT&T ksh */
100
 
                        gflag++;
 
101
                        gflag = true;
101
102
                        break;
102
103
                case 'l':
103
 
                        lflag++;
 
104
                        lflag = true;
104
105
                        break;
105
106
                case 'n':
106
 
                        nflag++;
 
107
                        nflag = true;
107
108
                        break;
108
109
                case 'r':
109
 
                        rflag++;
 
110
                        rflag = true;
110
111
                        break;
111
112
                case 's':       /* POSIX version of -e - */
112
 
                        sflag++;
 
113
                        sflag = true;
113
114
                        break;
114
115
                /* kludge city - accept -num as -- -num (kind of) */
115
116
                case '0': case '1': case '2': case '3': case '4':
186
187
                 * when range is specified; AT&T ksh and pdksh allow out of
187
188
                 * bounds for -l as well.
188
189
                 */
189
 
                hfirst = hist_get(first, (lflag || last) ? true : false,
190
 
                    lflag ? true : false);
 
190
                hfirst = hist_get(first, (lflag || last) ? true : false, lflag);
191
191
                if (!hfirst)
192
192
                        return (1);
193
 
                hlast = last ? hist_get(last, true, lflag ? true : false) :
 
193
                hlast = last ? hist_get(last, true, lflag) :
194
194
                    (lflag ? hist_get_newest(false) : hfirst);
195
195
                if (!hlast)
196
196
                        return (1);
325
325
}
326
326
 
327
327
static int
328
 
hist_replace(char **hp, const char *pat, const char *rep, int globr)
 
328
hist_replace(char **hp, const char *pat, const char *rep, bool globr)
329
329
{
330
330
        char *line;
331
331
 
338
338
                int len;
339
339
                XString xs;
340
340
                char *xp;
341
 
                int any_subst = 0;
 
341
                bool any_subst = false;
342
342
 
343
343
                Xinit(xs, xp, 128, ATEMP);
344
344
                for (s = *hp; (s1 = strstr(s, pat)) && (!any_subst || globr);
345
345
                    s = s1 + pat_len) {
346
 
                        any_subst = 1;
 
346
                        any_subst = true;
347
347
                        len = s1 - s;
348
348
                        XcheckN(xs, xp, len + rep_len);
349
349
                        memcpy(xp, s, len);             /* first part */