-/* Based on: "$Id: getline.c,v 1.1 2001/12/30 06:30:21 sedwards Exp $"; */
+/* Based on: "$Id$"; */
static const char copyright[] = "getline: Copyright (C) 1991, 1992, 1993, Chris Thewalt";
/*
* Copyright (C) 1991, 1992, 1993 by Chris Thewalt (thewalt@ce.berkeley.edu)
*
- * Permission to use, copy, modify, and distribute this software
+ * Permission to use, copy, modify, and distribute this software
* for any purpose and without fee is hereby granted, provided
* that the above copyright notices appear in all copies and that both the
* copyright notice and this permission notice appear in supporting
gl_char_cleanup(void) /* undo effects of gl_char_init */
{
#ifdef __unix__
-# ifdef HAVE_TERMIOS_H
+# ifdef HAVE_TERMIOS_H
tcsetattr(0, TCSANOW, &old_termios);
# elif defined(TIOCSETN) /* BSD */
ioctl(0, TIOCSETN, &old_tty);
static int
gl_getcx(int tlen)
-{
+{
int i, c;
c = (-2);
static void
gl_puts(const char *const buf)
{
- int len;
-
+ int len;
+
if (buf) {
len = (int) strlen(buf);
write(1, buf, len);
gl_check_inputrc_for_vi();
}
- gl_init();
+ gl_init();
gl_prompt = (prompt)? prompt : "";
gl_buf[0] = 0;
if (gl_in_hook)
static void
gl_addchar(int c)
-
+
/* adds the character c to the input buffer at current location */
{
int i;
len = (int) strlen(gl_killbuf);
if (len > 0) {
if (gl_overwrite == 0) {
- if (gl_cnt + len >= GL_BUF_SIZE - 1)
+ if (gl_cnt + len >= GL_BUF_SIZE - 1)
gl_error("\n*** Error: getline(): input buffer overflow\n");
for (i=gl_cnt; i >= gl_pos; i--)
gl_buf[i+len] = gl_buf[i];
gl_fixup(gl_prompt, gl_pos, gl_pos+len);
} else {
if (gl_pos + len > gl_cnt) {
- if (gl_pos + len >= GL_BUF_SIZE - 1)
+ if (gl_pos + len >= GL_BUF_SIZE - 1)
gl_error("\n*** Error: getline(): input buffer overflow\n");
gl_buf[gl_pos + len] = 0;
}
int len = gl_cnt;
int loc = gl_width - 5; /* shifts line back to start position */
- if (gl_cnt >= GL_BUF_SIZE - 1)
+ if (gl_cnt >= GL_BUF_SIZE - 1)
gl_error("\n*** Error: getline(): input buffer overflow\n");
if (gl_out_hook) {
change = gl_out_hook(gl_buf);
len = (int) strlen(gl_buf);
- }
+ }
if (loc > len)
loc = len;
gl_fixup(gl_prompt, change, loc); /* must do this before appending \n */
static void
gl_del(int loc, int killsave)
-
+
/*
* Delete a character. The loc variable can be:
* -1 : delete character to left of cursor
static void
gl_kill(int pos)
-
+
/* delete from pos to the end of line */
{
if (pos < gl_cnt) {
int i;
if (direction > 0) { /* forward */
- while (!isspace(gl_buf[pos]) && pos < gl_cnt)
+ while (!isspace(gl_buf[pos]) && pos < gl_cnt)
pos++;
while (isspace(gl_buf[pos]) && pos < gl_cnt)
pos++;
pos--;
while (isspace(gl_buf[pos]) && pos > 0)
pos--;
- while (!isspace(gl_buf[pos]) && pos > 0)
+ while (!isspace(gl_buf[pos]) && pos > 0)
pos--;
if (pos < gl_cnt && isspace(gl_buf[pos])) /* move onto word */
pos++;
static void
gl_word(int direction)
-
+
/* move forward or backword one word */
{
int pos = gl_pos;
if (direction > 0) { /* forward */
- while (!isspace(gl_buf[pos]) && pos < gl_cnt)
+ while (!isspace(gl_buf[pos]) && pos < gl_cnt)
pos++;
while (isspace(gl_buf[pos]) && pos < gl_cnt)
pos++;
pos--;
while (isspace(gl_buf[pos]) && pos > 0)
pos--;
- while (!isspace(gl_buf[pos]) && pos > 0)
+ while (!isspace(gl_buf[pos]) && pos > 0)
pos--;
if (pos < gl_cnt && isspace(gl_buf[pos])) /* move onto word */
pos++;
static void
gl_fixup(const char *prompt, int change, int cursor)
-
-
+
+
/*
* This function is used both for redrawing when input changes or for
* moving within the input line. The parameters are:
}
if (off_right || (off_left && cursor < gl_shift + gl_width - gl_scroll / 2))
extra = 2; /* shift the scrolling boundary */
- else
+ else
extra = 0;
new_shift = cursor + extra + gl_scroll - gl_width;
if (new_shift > 0) {
}
off_right = (gl_cnt > gl_shift + gl_width - 1)? 1 : 0;
right = (off_right)? gl_shift + gl_width - 2 : gl_cnt;
- new_right = (gl_extent && (right > left + gl_extent))?
+ new_right = (gl_extent && (right > left + gl_extent))?
left + gl_extent : right;
}
pad -= (off_right)? gl_width - 1 : gl_cnt - gl_shift;
if (off_right && new_right == right) {
gl_putc('$');
gl_pos++;
- } else {
+ } else {
for (i=0; i < pad; i++) /* erase remains of prev line */
gl_putc(' ');
gl_pos += pad;
hist_init();
gl_init_done = 0;
}
- while (*p == ' ' || *p == '\t' || *p == '\n')
+ while (*p == ' ' || *p == '\t' || *p == '\n')
p++;
if (*p) {
len = (int) strlen(buf);
if (strchr(p, '\n')) /* previously line already has NL stripped */
len--;
- if ((prev == 0) || ((int) strlen(prev) != len) ||
+ if ((prev == 0) || ((int) strlen(prev) != len) ||
strncmp(prev, buf, (size_t) len) != 0) {
hist_buf[hist_last] = hist_save(buf);
prev = hist_buf[hist_last];
if (hist_buf[hist_pos] != 0 && next != hist_last) {
hist_pos = next;
p = hist_buf[hist_pos];
- }
+ }
if (p == 0) {
p = hist_empty_elem;
gl_beep();
if (hist_pos != hist_last) {
hist_pos = (hist_pos+1) % HIST_SIZE;
p = hist_buf[hist_pos];
- }
+ }
if (p == 0) {
p = hist_empty_elem;
gl_beep();
static char *
hist_save(char *p)
-
+
/* makes a copy of the string */
{
char *s = 0;
strcpy(s, p);
}
}
- if (s == 0)
+ if (s == 0)
gl_error("\n*** Error: hist_save() failed on malloc\n");
return s;
}
fprintf(fp, "%s\n", p);
}
fclose(fp);
- }
+ }
} /* gl_histsavefile */
static int search_forw_flg = 0; /* search direction flag */
static int search_last = 0; /* last match found */
-static void
+static void
search_update(int c)
{
if (c == 0) {
}
}
-static void
+static void
search_addchar(int c)
{
char *loc;
}
}
-static void
+static void
search_term(void)
{
gl_search_mode = 0;
gl_fixup(gl_prompt, 0, gl_pos);
}
-static void
+static void
search_back(int new_search)
{
int found = 0;
search_forw_flg = 0;
if (gl_search_mode == 0) {
- search_last = hist_pos = hist_last;
- search_update(0);
+ search_last = hist_pos = hist_last;
+ search_update(0);
gl_search_mode = 1;
gl_buf[0] = 0;
gl_fixup(search_prompt, 0, 0);
if (new_search)
search_last = hist_pos;
found = 1;
- }
+ }
}
} else {
}
}
-static void
+static void
search_forw(int new_search)
{
int found = 0;
search_forw_flg = 1;
if (gl_search_mode == 0) {
- search_last = hist_pos = hist_last;
- search_update(0);
+ search_last = hist_pos = hist_last;
+ search_update(0);
gl_search_mode = 1;
gl_buf[0] = 0;
gl_fixup(search_prompt, 0, 0);
if (new_search)
search_last = hist_pos;
found = 1;
- }
+ }
}
} else {
gl_beep();
if (ncol < 1)
ncol = 1;
- colw = (gl_termw - 8) / ncol;
+ colw = (gl_termw - 8) / ncol;
nrow = nmax / ncol;
if ((nused % ncol) != 0)
nrow++;
if (nrow > (gl_termh - 4)) {
nrow = gl_termh - 4;
- nmax = ncol * nrow;
+ nmax = ncol * nrow;
}
for (i=0; i<(int) sizeof(buf2); i++)
gl_fixup(gl_prompt, gl_pos, gl_pos + 3);
memcpy(curposp, ellipsessave, (size_t) 4);
}
-
+
qmode = 0;
qstart = NULL;
lastspacestart = NULL;
startp = lastspacestart + 1;
else
startp = buf;
-
+
cp = startp;
mlen = (curposp - cp);
nalloced = ntoalloc;
for (i=nused; i<=nalloced; i++)
gl_matchlist[i] = NULL;
-
+
gl_completion_exact_match_extra_char = ' ';
for (nprocused = 0;; nprocused++) {
if (nused == nalloced) {
return;
}
}
-
+
wdir[0] = '\0';
if (GetWindowsDirectory(wdir, sizeof(wdir) - 1) < 1)
(void) strncpy(wdir, ".", sizeof(wdir));
memcpy(dirtoopen2 + len, "*.*", (size_t) 4);
else
memcpy(dirtoopen2 + len, "\\*.*", (size_t) 5);
-
+
/* "Open" the directory. */
memset(&ffd, 0, sizeof(ffd));
searchHandle = FindFirstFile(dirtoopen2, &ffd);
filepfx = start + filepfxoffset;
goto next;
}
-
+
for (;;) {
-
+
name = ffd.cFileName;
if ((name[0] == '.') && ((name[1] == '\0') || ((name[1] == '.') && (name[2] == '\0'))))
goto next; /* Skip . and .. */
-
+
if ((filepfxlen == 0) || (strnicmp(name, filepfx, filepfxlen) == 0)) {
/* match */
len = strlen(name);
searchHandle = NULL;
return NULL;
}
-
+
/* no more items */
FindClose(searchHandle);
searchHandle = NULL;
-
+
if (idx == 1) {
/* There was exactly one match.
* In this special case, we