ReactOS  0.4.15-dev-448-gd6c4411
getline.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GL_BUF_SIZE   1024
 
#define GL_OK   0 /* Valid line of input entered */
 
#define GL_EOF   (-1) /* End of input */
 
#define GL_INTERRUPT   (-2) /* User hit Ctrl+C */
 

Typedefs

typedef size_t(* gl_strwidth_proc) (char *)
 
typedef int(* gl_in_hook_proc) (char *)
 
typedef int(* gl_out_hook_proc) (char *)
 
typedef int(* gl_tab_hook_proc) (char *, int, int *, size_t)
 
typedef size_t(* gl_strlen_proc) (const char *)
 
typedef char *(* gl_tab_completion_proc) (const char *, int)
 

Functions

chargetline (char *)
 
void gl_setwidth (int)
 
void gl_setheight (int)
 
void gl_histadd (char *)
 
void gl_strwidth (gl_strwidth_proc)
 
void gl_tab_completion (gl_tab_completion_proc)
 
chargl_local_filename_completion_proc (const char *, int)
 
void gl_set_home_dir (const char *homedir)
 
void gl_histsavefile (const char *const path)
 
void gl_histloadfile (const char *const path)
 
chargl_getpass (const char *const prompt, char *const pass, int dsize)
 
int gl_get_result (void)
 

Variables

gl_in_hook_proc gl_in_hook
 
gl_out_hook_proc gl_out_hook
 
gl_tab_hook_proc gl_tab_hook
 
gl_strlen_proc gl_strlen
 
gl_tab_completion_proc gl_completion_proc
 
int gl_filename_quoting_desired
 
const chargl_filename_quote_characters
 
int gl_ellipses_during_completion
 
int gl_completion_exact_match_extra_char
 
char gl_buf [GL_BUF_SIZE]
 

Macro Definition Documentation

◆ GL_BUF_SIZE

#define GL_BUF_SIZE   1024

Definition at line 8 of file getline.h.

◆ GL_EOF

#define GL_EOF   (-1) /* End of input */

Definition at line 12 of file getline.h.

◆ GL_INTERRUPT

#define GL_INTERRUPT   (-2) /* User hit Ctrl+C */

Definition at line 13 of file getline.h.

◆ GL_OK

#define GL_OK   0 /* Valid line of input entered */

Definition at line 11 of file getline.h.

Typedef Documentation

◆ gl_in_hook_proc

typedef int(* gl_in_hook_proc) (char *)

Definition at line 16 of file getline.h.

◆ gl_out_hook_proc

typedef int(* gl_out_hook_proc) (char *)

Definition at line 17 of file getline.h.

◆ gl_strlen_proc

typedef size_t(* gl_strlen_proc) (const char *)

Definition at line 19 of file getline.h.

◆ gl_strwidth_proc

typedef size_t(* gl_strwidth_proc) (char *)

Definition at line 15 of file getline.h.

◆ gl_tab_completion_proc

typedef char*(* gl_tab_completion_proc) (const char *, int)

Definition at line 20 of file getline.h.

◆ gl_tab_hook_proc

typedef int(* gl_tab_hook_proc) (char *, int, int *, size_t)

Definition at line 18 of file getline.h.

Function Documentation

◆ getline()

char* getline ( char )

Definition at line 560 of file getline.c.

561 {
562  int c, loc, tmp, lastch;
563  int vi_count, count;
564  int vi_delete;
565  char vi_countbuf[32];
566  char *cp;
567 
568 #ifdef __unix__
569  int sig;
570 #endif
571 
572  /* We'll change the result code only if something happens later. */
573  gl_result = GL_OK;
574 
575  /* Even if it appears that "vi" is preferred, we
576  * don't start in gl_vi_mode. They need to hit
577  * ESC to go into vi command mode.
578  */
579  gl_vi_mode = 0;
580  vi_count = 0;
581  vi_delete = 0;
582  if (gl_vi_preferred < 0) {
583  gl_vi_preferred = 0;
584  cp = (char *) getenv("EDITOR");
585  if (cp != NULL)
586  gl_vi_preferred = (strstr(cp, "vi") != NULL);
587  if (gl_vi_preferred == 0)
589  }
590 
591  gl_init();
592  gl_prompt = (prompt)? prompt : "";
593  gl_buf[0] = 0;
594  if (gl_in_hook)
597  lastch = 0;
598 
599 #ifdef __windows__
601 #endif
602 
603  while ((c = gl_getc()) != (-1)) {
604  gl_extent = 0; /* reset to full extent */
605  /* Note: \n may or may not be considered printable */
606  if ((c != '\t') && ((isprint(c) != 0) || ((c & 0x80) != 0))) {
607  if (gl_vi_mode > 0) {
608  /* "vi" emulation -- far from perfect,
609  * but reasonably functional.
610  */
611 vi:
612  for (count = 0; ; ) {
613  if (isdigit(c)) {
614  if (vi_countbuf[sizeof(vi_countbuf) - 2] == '\0')
615  vi_countbuf[strlen(vi_countbuf)] = (char) c;
616  } else if (vi_countbuf[0] != '\0') {
617  vi_count = atoi(vi_countbuf);
618  memset(vi_countbuf, 0, sizeof(vi_countbuf));
619  }
620  switch (c) {
621  case 'b':
622  gl_word(-1);
623  break;
624  case 'w':
625  if (vi_delete) {
626  gl_killword(1);
627  } else {
628  gl_word(1);
629  }
630  break;
631  case 'h': /* left */
632  if (vi_delete) {
633  if (gl_pos > 0) {
634  gl_fixup(gl_prompt, -1, gl_pos-1);
635  gl_del(0, 1);
636  }
637  } else {
638  gl_fixup(gl_prompt, -1, gl_pos-1);
639  }
640  break;
641  case ' ':
642  case 'l': /* right */
643  if (vi_delete) {
644  gl_del(0, 1);
645  } else {
646  gl_fixup(gl_prompt, -1, gl_pos+1);
647  }
648  break;
649  case 'k': /* up */
650  strcpy(gl_buf, hist_prev());
651  if (gl_in_hook)
654  break;
655  case 'j': /* down */
656  strcpy(gl_buf, hist_next());
657  if (gl_in_hook)
660  break;
661  case 'd':
662  if (vi_delete == 1) {
663  gl_kill(0);
664  vi_count = 1;
665  vi_delete = 0;
666  gl_vi_mode = 0;
667  goto vi_break;
668  }
669  vi_delete = 1;
670  goto vi_break;
671  case '^': /* start of line */
672  if (vi_delete) {
673  vi_count = gl_pos;
674  gl_fixup(gl_prompt, -1, 0);
675  for (c = 0; c < vi_count; c++) {
676  if (gl_cnt > 0)
677  gl_del(0, 0);
678  }
679  vi_count = 1;
680  vi_delete = 0;
681  } else {
682  gl_fixup(gl_prompt, -1, 0);
683  }
684  break;
685  case '$': /* end of line */
686  if (vi_delete) {
687  gl_kill(gl_pos);
688  } else {
689  loc = (int) strlen(gl_buf);
690  if (loc > 1)
691  loc--;
692  gl_fixup(gl_prompt, -1, loc);
693  }
694  break;
695  case 'p': /* paste after */
696  gl_fixup(gl_prompt, -1, gl_pos+1);
697  gl_yank();
698  break;
699  case 'P': /* paste before */
700  gl_yank();
701  break;
702  case 'r': /* replace character */
703  gl_buf[gl_pos] = (char) gl_getc();
705  vi_count = 1;
706  break;
707  case 'R':
708  gl_overwrite = 1;
709  gl_vi_mode = 0;
710  break;
711  case 'i':
712  case 'I':
713  gl_overwrite = 0;
714  gl_vi_mode = 0;
715  break;
716  case 'o':
717  case 'O':
718  case 'a':
719  case 'A':
720  gl_overwrite = 0;
721  gl_fixup(gl_prompt, -1, gl_pos+1);
722  gl_vi_mode = 0;
723  break;
724  }
725  count++;
726  if (count >= vi_count)
727  break;
728  }
729  vi_count = 1;
730  vi_delete = 0;
731 vi_break:
732  continue;
733  } else if (gl_search_mode) {
734  search_addchar(c);
735  } else {
736  gl_addchar(c);
737  }
738  } else {
739  if (gl_search_mode) {
740  if (c == '\033' || c == '\016' || c == '\020') {
741  search_term();
742  c = 0; /* ignore the character */
743  } else if (c == '\010' || c == '\177') {
744  search_addchar(-1); /* unwind search string */
745  c = 0;
746  } else if (c != '\022' && c != '\023') {
747  search_term(); /* terminate and handle char */
748  }
749  }
750  switch (c) {
751  case '\n': case '\r': /* newline */
752  gl_newline();
753  gl_cleanup();
754  return gl_buf;
755  case '\001': gl_fixup(gl_prompt, -1, 0); /* ^A */
756  break;
757  case '\002': gl_fixup(gl_prompt, -1, gl_pos-1); /* ^B */
758  break;
759  case '\004': /* ^D */
760  if (gl_cnt == 0) {
761  gl_buf[0] = 0;
762  gl_cleanup();
763  gl_putc('\n');
764  gl_result = GL_EOF;
765  return gl_buf;
766  } else {
767  gl_del(0, 1);
768  }
769  break;
770  case '\005': gl_fixup(gl_prompt, -1, gl_cnt); /* ^E */
771  break;
772  case '\006': gl_fixup(gl_prompt, -1, gl_pos+1); /* ^F */
773  break;
774  case '\010': case '\177': gl_del(-1, 0); /* ^H and DEL */
775  break;
776  case '\t': /* TAB */
777  if (gl_completion_proc) {
778  tmp = gl_pos;
779  gl_buf[sizeof(gl_buf) - 1] = '\0';
780  loc = gl_do_tab_completion(gl_buf, &tmp, sizeof(gl_buf), (lastch == '\t'));
781  gl_buf[sizeof(gl_buf) - 1] = '\0';
782  if (loc >= 0 || tmp != gl_pos)
783  gl_fixup(gl_prompt, /* loc */ -2, tmp);
784  if (lastch == '\t') {
785  c = 0;
786  lastch = 0;
787  }
788  } else if (gl_tab_hook) {
789  tmp = gl_pos;
790  gl_buf[sizeof(gl_buf) - 1] = '\0';
791  loc = gl_tab_hook(gl_buf, (int) gl_strlen(gl_prompt), &tmp, sizeof(gl_buf));
792  gl_buf[sizeof(gl_buf) - 1] = '\0';
793  if (loc >= 0 || tmp != gl_pos)
794  gl_fixup(gl_prompt, loc, tmp);
795  }
796  break;
797  case '\013': gl_kill(gl_pos); /* ^K */
798  break;
799  case '\014': gl_redraw(); /* ^L */
800  break;
801  case '\016': /* ^N */
802  strcpy(gl_buf, hist_next());
803  if (gl_in_hook)
806  break;
807  case '\017': gl_overwrite = !gl_overwrite; /* ^O */
808  break;
809  case '\020': /* ^P */
810  strcpy(gl_buf, hist_prev());
811  if (gl_in_hook)
814  break;
815  case '\022': search_back(1); /* ^R */
816  break;
817  case '\023': search_forw(1); /* ^S */
818  break;
819  case '\024': gl_transpose(); /* ^T */
820  break;
821  case '\025': gl_kill(0); /* ^U */
822  break;
823  case '\027': gl_killword(-1); /* ^W */
824  break;
825  case '\031': gl_yank(); /* ^Y */
826  break;
827  case '\033': /* ansi arrow keys */
828  c = gl_getcx(3);
829  if ((c == '[') || (c == 'O')) {
830 ansi:
831  switch(c = gl_getc()) {
832  case 'A': /* up */
833  strcpy(gl_buf, hist_prev());
834  if (gl_in_hook)
837  break;
838  case 'B': /* down */
839  strcpy(gl_buf, hist_next());
840  if (gl_in_hook)
843  break;
844  case 'C':
845  gl_fixup(gl_prompt, -1, gl_pos+1); /* right */
846  break;
847  case 'D':
848  gl_fixup(gl_prompt, -1, gl_pos-1); /* left */
849  break;
850  case '0':
851  case '1':
852  goto ansi;
853  default: gl_beep(); /* who knows */
854  break;
855  }
856  } else if ((gl_vi_preferred == 0) && ((c == 'f') || (c == 'F'))) {
857  gl_word(1);
858  } else if ((gl_vi_preferred == 0) && ((c == 'b') || (c == 'B'))) {
859  gl_word(-1);
860  } else if (c != (-1)) {
861  /* enter vi command mode */
862 #if defined(__windows__) || defined(MSDOS)
863  if (gl_vi_preferred == 0) {
864  /* On Windows, ESC acts like a line kill,
865  * so don't use vi mode unless they prefer
866  * vi mode.
867  */
868  gl_kill(0);
869  } else
870 #endif
871  if (gl_vi_mode == 0) {
872  gl_vi_mode = 1;
873  vi_count = 1;
874  vi_delete = 0;
875  memset(vi_countbuf, 0, sizeof(vi_countbuf));
876  if (gl_pos > 0)
877  gl_fixup(gl_prompt, -2, gl_pos-1); /* left 1 char */
878  /* Don't bother if the line is empty and we don't
879  * know for sure if the user wants vi mode.
880  */
881  if ((gl_cnt > 0) || (gl_vi_preferred == 1)) {
882  /* We still have to use the char read! */
883  goto vi;
884  }
885  gl_vi_mode = 0;
886  } else {
887  gl_beep();
888  }
889  }
890  break;
891  default: /* check for a terminal signal */
892  if (c > 0) { /* ignore 0 (reset above) */
893  if (c == gl_intrc) {
895  gl_buf[0] = 0;
896  gl_cleanup();
897 #ifdef SIGINT
898  raise(SIGINT);
899  gl_init();
900  gl_redraw();
901 #endif
902  return gl_buf;
903  }
904 
905  if (c == gl_quitc) {
907  gl_buf[0] = 0;
908  gl_cleanup();
909 #ifdef SIGQUIT
910  raise(SIGQUIT);
911  gl_init();
912  gl_redraw();
913 #endif
914  return gl_buf;
915  }
916 
917 #ifdef __unix__
918  if (c == gl_suspc || c == gl_dsuspc) {
919 #ifdef SIGTSTP
921  gl_buf[0] = 0;
922  gl_cleanup();
923  sig = SIGTSTP;
924  kill(0, sig);
925  gl_init();
926  gl_redraw();
927  return gl_buf;
928 #endif
929  }
930 #endif /* __unix__ */
931  }
932  if (c > 0)
933  gl_beep();
934  break;
935  }
936  }
937  if (c > 0)
938  lastch = c;
939  }
940  gl_buf[0] = 0;
941  gl_cleanup();
942  return gl_buf;
943 }
#define GL_BUF_SIZE
Definition: getline.h:8
static int gl_overwrite
Definition: getline.c:100
static int gl_vi_mode
Definition: getline.c:112
static void gl_beep(void)
Definition: getline.c:1608
static void gl_transpose(void)
Definition: getline.c:998
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define GL_INTERRUPT
Definition: getline.h:13
gl_tab_hook_proc gl_tab_hook
Definition: getline.c:82
GLuint GLuint GLsizei count
Definition: gl.h:1545
static void search_back(int new_search)
Definition: getline.c:1540
static void gl_kill(int pos)
Definition: getline.c:1064
static void gl_del(int loc, int)
Definition: getline.c:1039
static void gl_word(int direction)
Definition: getline.c:1114
BOOL WINAPI FlushConsoleInputBuffer(IN HANDLE hConsoleInput)
Definition: console.c:217
static void gl_cleanup(void)
Definition: getline.c:466
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
struct msdos_volume_info vi
Definition: mkdosfs.c:435
#define SIGQUIT
Definition: signal.h:24
#define SIGINT
Definition: signal.h:23
static int gl_pos
Definition: getline.c:101
#define GL_EOF
Definition: getline.h:12
static const char * gl_prompt
Definition: getline.c:103
static void gl_putc(int c)
Definition: getline.c:403
static char gl_intrc
Definition: getline.c:104
smooth NULL
Definition: ftsmooth.c:416
unsigned char
Definition: typeof.h:29
char gl_buf[GL_BUF_SIZE]
Definition: getline.c:89
#define STD_INPUT_HANDLE
Definition: winbase.h:264
#define isdigit(c)
Definition: acclib.h:68
static void search_forw(int new_search)
Definition: getline.c:1574
size_t gl_strlen(const char *s)
Definition: getline.c:83
static int gl_do_tab_completion(char *buf, int *loc, size_t bufsize, int tabtab)
Definition: getline.c:1731
static void gl_fixup(const char *prompt, int change, int cursor)
Definition: getline.c:1149
const GLubyte * c
Definition: glext.h:8905
gl_in_hook_proc gl_in_hook
Definition: getline.c:80
static void gl_redraw(void)
Definition: getline.c:1139
static char * hist_prev(void)
Definition: getline.c:1346
static int gl_cnt
Definition: getline.c:101
#define GL_OK
Definition: getline.h:11
static void search_term(void)
Definition: getline.c:1529
static int gl_vi_preferred
Definition: getline.c:111
static int gl_getc(void)
Definition: getline.c:282
static int gl_search_mode
Definition: getline.c:108
static int gl_getcx(int)
Definition: getline.c:374
static void search_addchar(int c)
Definition: getline.c:1501
static void gl_init(void)
Definition: getline.c:438
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
static void gl_newline(void)
Definition: getline.c:1014
static void gl_yank(void)
Definition: getline.c:967
static char * hist_next(void)
Definition: getline.c:1364
static void gl_check_inputrc_for_vi(void)
Definition: getline.c:480
static void gl_addchar(int c)
Definition: getline.c:946
#define isprint(c)
Definition: acclib.h:73
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
POINT cp
Definition: magnifier.c:59
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define c
Definition: ke_i.h:80
static char gl_quitc
Definition: getline.c:105
static int gl_result
Definition: getline.c:113
#define memset(x, y, z)
Definition: compat.h:39
static int gl_extent
Definition: getline.c:99
gl_tab_completion_proc gl_completion_proc
Definition: getline.c:84
static void gl_killword(int direction)
Definition: getline.c:1077
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

◆ gl_get_result()

int gl_get_result ( void  )

Definition at line 224 of file getline.c.

225 {
226  return (gl_result);
227 } /* gl_get_result */
static int gl_result
Definition: getline.c:113

◆ gl_getpass()

char* gl_getpass ( const char *const  prompt,
char *const  pass,
int  dsize 
)

Definition at line 2051 of file getline.c.

2052 {
2053 #ifdef __unix__
2054  char *cp;
2055  int c;
2056 
2057  memset(pass, 0, (size_t) sizeof(dsize));
2058  dsize--;
2059  gl_init();
2060 
2061  /* Display the prompt first. */
2062  if ((prompt != NULL) && (prompt[0] != '\0'))
2063  gl_puts(prompt);
2064 
2065  cp = pass;
2066  while ((c = gl_getc()) != (-1)) {
2067  if ((c == '\r') || (c == '\n'))
2068  break;
2069  if ((c == '\010') || (c == '\177')) {
2070  /* ^H and DEL */
2071  if (cp > pass) {
2072  *--cp = '\0';
2073  gl_putc('\010');
2074  gl_putc(' ');
2075  gl_putc('\010');
2076  }
2077  } else if (cp < (pass + dsize)) {
2078  gl_putc('*');
2079  *cp++ = c;
2080  }
2081  }
2082  *cp = '\0';
2083  gl_putc('\n');
2084  gl_cleanup();
2085  return (pass);
2086 #else
2087 #ifdef __windows__
2088  char *cp;
2089  int c;
2090 
2092  ZeroMemory(pass, (DWORD) sizeof(dsize));
2093  dsize--;
2094 
2095  if ((prompt != NULL) && (prompt[0] != '\0'))
2096  _cputs(prompt);
2097 
2098  for (cp = pass;;) {
2099  c = (int) _getch();
2100  if ((c == '\r') || (c == '\n'))
2101  break;
2102  if ((c == '\010') || (c == '\177')) {
2103  /* ^H and DEL */
2104  if (cp > pass) {
2105  *--cp = '\0';
2106  _putch('\010');
2107  _putch(' ');
2108  _putch('\010');
2109  }
2110  } else if (cp < (pass + dsize)) {
2111  _putch('*');
2112  *cp++ = c;
2113  }
2114  }
2115  _putch('\r');
2116  _putch('\n');
2117  Sleep(40);
2119 
2120  *cp = '\0';
2121  return (pass);
2122 #endif /* __windows__ */
2123 #endif /* ! __unix__ */
2124 } /* gl_getpass */
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOL WINAPI FlushConsoleInputBuffer(IN HANDLE hConsoleInput)
Definition: console.c:217
#define ZeroMemory
Definition: winbase.h:1648
static void gl_cleanup(void)
Definition: getline.c:466
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:200
pass
Definition: typegen.h:24
static void gl_putc(int c)
Definition: getline.c:403
smooth NULL
Definition: ftsmooth.c:416
int __cdecl _cputs(const char *)
Definition: cputs.c:8
#define STD_INPUT_HANDLE
Definition: winbase.h:264
const GLubyte * c
Definition: glext.h:8905
unsigned long DWORD
Definition: ntddk_ex.h:95
static int gl_getc(void)
Definition: getline.c:282
static void gl_puts(const char *const buf)
Definition: getline.c:417
_CRTIMP int __cdecl _putch(_In_ int _Ch)
static void gl_init(void)
Definition: getline.c:438
POINT cp
Definition: magnifier.c:59
#define c
Definition: ke_i.h:80
int _getch()
Definition: getch.c:16
#define memset(x, y, z)
Definition: compat.h:39
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by DoOpen(), NcFTPGetPassphraseProc(), and OpenCmd().

◆ gl_histadd()

void gl_histadd ( char )

Definition at line 1314 of file getline.c.

1315 {
1316  static char *prev = 0;
1317  char *p = buf;
1318  int len;
1319 
1320  /* in case we call gl_histadd() before we call getline() */
1321  if (gl_init_done < 0) { /* -1 only on startup */
1322  hist_init();
1323  gl_init_done = 0;
1324  }
1325  while (*p == ' ' || *p == '\t' || *p == '\n')
1326  p++;
1327  if (*p) {
1328  len = (int) strlen(buf);
1329  if (strchr(p, '\n')) /* previously line already has NL stripped */
1330  len--;
1331  if ((prev == 0) || ((int) strlen(prev) != len) ||
1332  strncmp(prev, buf, (size_t) len) != 0) {
1334  prev = hist_buf[hist_last];
1335  hist_last = (hist_last + 1) % HIST_SIZE;
1336  if (hist_buf[hist_last] && *hist_buf[hist_last]) {
1338  }
1340  }
1341  }
1342  hist_pos = hist_last;
1343 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define free
Definition: debug_ros.c:5
static char * hist_save(char *p)
Definition: getline.c:1381
#define HIST_SIZE
Definition: getline.c:1296
static void hist_init(void)
Definition: getline.c:1304
static int hist_pos
Definition: getline.c:1299
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
static int hist_last
Definition: getline.c:1299
GLenum GLsizei len
Definition: glext.h:6722
static int gl_init_done
Definition: getline.c:94
char * strchr(const char *String, int ch)
Definition: utclib.c:501
static char hist_empty_elem[2]
Definition: getline.c:1301
static char * hist_buf[HIST_SIZE]
Definition: getline.c:1300
GLfloat GLfloat p
Definition: glext.h:8902
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by AddHistory(), and gl_histloadfile().

◆ gl_histloadfile()

void gl_histloadfile ( const char *const  path)

Definition at line 1437 of file getline.c.

1438 {
1439  FILE *fp;
1440  char line[256];
1441 
1442  fp = fopen(path,
1443 #if defined(__windows__) || defined(MSDOS)
1444  "rt"
1445 #else
1446  "r"
1447 #endif
1448  );
1449  if (fp != NULL) {
1450  memset(line, 0, sizeof(line));
1451  while (fgets(line, sizeof(line) - 2, fp) != NULL) {
1452  gl_histadd(line);
1453  }
1454  fclose(fp);
1455  }
1456 } /* gl_histloadfile */
void gl_histadd(char *buf)
Definition: getline.c:1314
#define __windows__
Definition: getline.c:60
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
#define memset(x, y, z)
Definition: compat.h:39

Referenced by LoadHistory().

◆ gl_histsavefile()

void gl_histsavefile ( const char *const  path)

Definition at line 1408 of file getline.c.

1409 {
1410  FILE *fp;
1411  const char *p;
1412  int i, j;
1413 
1414  fp = fopen(path,
1415 #if defined(__windows__) || defined(MSDOS)
1416  "wt"
1417 #else
1418  "w"
1419 #endif
1420  );
1421  if (fp != NULL) {
1422  for (i=2; i<HIST_SIZE; i++) {
1423  j = (hist_pos+i) % HIST_SIZE;
1424  p = hist_buf[j];
1425  if ((p == NULL) || (*p == '\0'))
1426  continue;
1427  fprintf(fp, "%s\n", p);
1428  }
1429  fclose(fp);
1430  }
1431 } /* gl_histsavefile */
#define __windows__
Definition: getline.c:60
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
#define HIST_SIZE
Definition: getline.c:1296
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static int hist_pos
Definition: getline.c:1299
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
static char * hist_buf[HIST_SIZE]
Definition: getline.c:1300
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by SaveHistory().

◆ gl_local_filename_completion_proc()

char* gl_local_filename_completion_proc ( const char ,
int   
)

Definition at line 2258 of file getline.c.

2259 {
2260  static HANDLE searchHandle = NULL;
2261  static int filepfxoffset;
2262  static size_t filepfxlen;
2263 
2264  WIN32_FIND_DATA ffd;
2265  DWORD dwErr;
2266  char *cp, *c2, ch;
2267  const char *filepfx;
2268  const char *dirtoopen, *name;
2269  char *dirtoopen1, *dirtoopen2;
2270  size_t len, len2;
2271 
2272  if (idx == 0) {
2273  if (searchHandle != NULL) {
2274  /* shouldn't get here! */
2275  FindClose(searchHandle);
2276  searchHandle = NULL;
2277  }
2278  }
2279 
2280 
2281  if (searchHandle == NULL) {
2282  dirtoopen1 = NULL;
2283  dirtoopen2 = NULL;
2285  if (cp == start) {
2286  dirtoopen = LOCAL_PATH_DELIM_STR; /* root dir */
2287  filepfxoffset = 1;
2288  } else if (cp == NULL) {
2289  dirtoopen = ".";
2290  filepfxoffset = 0;
2291  } else {
2292  len = strlen(start) + 1;
2293  dirtoopen1 = (char *) malloc(len);
2294  if (dirtoopen1 == NULL)
2295  return NULL;
2296  memcpy(dirtoopen1, start, len);
2297  len = (cp - start);
2298  dirtoopen1[len] = '\0';
2299  dirtoopen = dirtoopen1;
2300  filepfxoffset = (int) ((cp + 1) - start);
2301  }
2302 
2303  if (strcmp(dirtoopen, "~") == 0) {
2304  if (gl_home_dir == NULL)
2306  if (gl_home_dir == NULL)
2307  return (NULL);
2308  dirtoopen = gl_home_dir;
2309  }
2310 
2311  len = strlen(dirtoopen);
2312  dirtoopen2 = (char *) malloc(len + 8);
2313  if (dirtoopen2 == NULL) {
2314  if (dirtoopen1 != NULL)
2315  free(dirtoopen1);
2316  return NULL;
2317  }
2318 
2319  memcpy(dirtoopen2, dirtoopen, len + 1);
2320  if (dirtoopen2[len - 1] == LOCAL_PATH_DELIM)
2321  memcpy(dirtoopen2 + len, "*.*", (size_t) 4);
2322  else
2323  memcpy(dirtoopen2 + len, "\\*.*", (size_t) 5);
2324 
2325  /* "Open" the directory. */
2326  memset(&ffd, 0, sizeof(ffd));
2327  searchHandle = FindFirstFile(dirtoopen2, &ffd);
2328 
2329  free(dirtoopen2);
2330  if (dirtoopen1 != NULL)
2331  free(dirtoopen1);
2332 
2333  if (searchHandle == INVALID_HANDLE_VALUE) {
2334  return NULL;
2335  }
2336 
2337  filepfx = start + filepfxoffset;
2338  filepfxlen = strlen(filepfx);
2339  } else {
2340  /* assumes "start" is same for each iteration. */
2341  filepfx = start + filepfxoffset;
2342  goto next;
2343  }
2344 
2345  for (;;) {
2346 
2347  name = ffd.cFileName;
2348  if ((name[0] == '.') && ((name[1] == '\0') || ((name[1] == '.') && (name[2] == '\0'))))
2349  goto next; /* Skip . and .. */
2350 
2351  if ((filepfxlen == 0) || (_strnicmp(name, filepfx, filepfxlen) == 0)) {
2352  /* match */
2353  len = strlen(name);
2354  cp = (char *) malloc(filepfxoffset + len + 4 /* spare */ + 1 /* NUL */);
2355  *cp = '\0';
2356  if (filepfxoffset > 0)
2357  memcpy(cp, start, filepfxoffset);
2358  memcpy(cp + filepfxoffset, name, len + 1);
2359  if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
2360  /* Embed file type with name. */
2361  c2 = cp + filepfxoffset + len + 1;
2362  *c2++ = '\0';
2363  *c2++ = 'd';
2364  *c2 = '\0';
2365  } else {
2366  c2 = cp + filepfxoffset + len + 1;
2367  *c2++ = '\0';
2368  *c2++ = '-';
2369  *c2 = '\0';
2370  }
2371  return (cp);
2372  }
2373 
2374 next:
2375  if (!FindNextFile(searchHandle, &ffd)) {
2376  dwErr = GetLastError();
2377  if (dwErr != ERROR_NO_MORE_FILES) {
2378  FindClose(searchHandle);
2379  searchHandle = NULL;
2380  return NULL;
2381  }
2382 
2383  /* no more items */
2384  FindClose(searchHandle);
2385  searchHandle = NULL;
2386 
2387  if (idx == 1) {
2388  /* There was exactly one match.
2389  * In this special case, we
2390  * want to append a \ instead
2391  * of a space.
2392  */
2393  cp = gl_matchlist[0];
2394  ch = (char) cp[strlen(cp) + 2];
2395  if (ch == (char) 'd')
2397 
2398  if ((cp[0] == '~') && ((cp[1] == '\0') || (IsLocalPathDelim(cp[1])))) {
2399  len = strlen(cp + 1) + /* NUL */ 1;
2400  len2 = strlen(gl_home_dir);
2401  if (IsLocalPathDelim(gl_home_dir[len2 - 1]))
2402  len2--;
2403  cp = (char *) realloc(gl_matchlist[0], len + len2 + 4);
2404  if (cp == NULL) {
2405  cp = gl_matchlist[0];
2406  } else {
2407  memmove(cp + len2, cp + 1, len);
2408  memcpy(cp, gl_home_dir, len2);
2409  c2 = cp + len + len2;
2410  *c2++ = '\0';
2411  *c2++ = ch;
2412  *c2 = '\0';
2413  gl_matchlist[0] = cp;
2414  }
2415  }
2416  }
2417  break;
2418  }
2419  }
2420  return (NULL);
2421 } /* gl_local_filename_completion_proc */
#define realloc
Definition: debug_ros.c:6
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define free
Definition: debug_ros.c:5
#define IsLocalPathDelim(c)
Definition: getline.c:57
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
int gl_completion_exact_match_extra_char
Definition: getline.c:88
static char ** gl_matchlist
Definition: getline.c:109
_Check_return_ _CRTIMP int __cdecl _strnicmp(_In_reads_or_z_(_MaxCount) const char *_Str1, _In_reads_or_z_(_MaxCount) const char *_Str2, _In_ size_t _MaxCount)
unsigned int idx
Definition: utils.c:41
smooth NULL
Definition: ftsmooth.c:416
unsigned char
Definition: typeof.h:29
#define FindFirstFile
Definition: winbase.h:3622
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
DWORD dwErr
Definition: service.c:36
static char * _StrRFindLocalPathDelim(const char *src)
Definition: getline.c:1963
#define FindNextFile
Definition: winbase.h:3628
unsigned long DWORD
Definition: ntddk_ex.h:95
#define LOCAL_PATH_DELIM_STR
Definition: getline.c:55
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
static unsigned __int64 next
Definition: rand_nt.c:6
GLuint start
Definition: gl.h:1545
#define LOCAL_PATH_DELIM
Definition: getline.c:54
void gl_set_home_dir(const char *homedir)
Definition: getline.c:1985
POINT cp
Definition: magnifier.c:59
Definition: name.c:38
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define malloc
Definition: debug_ros.c:4
#define memset(x, y, z)
Definition: compat.h:39
static char * gl_home_dir
Definition: getline.c:110
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by CompletionFunction(), gl_do_tab_completion(), and gl_tab_completion().

◆ gl_set_home_dir()

void gl_set_home_dir ( const char homedir)

Definition at line 1985 of file getline.c.

1986 {
1987  size_t len;
1988 #ifdef __windows__
1989  const char *homedrive, *homepath;
1990  char wdir[64];
1991 #else
1992  struct passwd *pw;
1993  char *cp;
1994 #endif
1995 
1996  if (gl_home_dir != NULL) {
1997  free(gl_home_dir);
1998  gl_home_dir = NULL;
1999  }
2000 
2001  if (homedir == NULL) {
2002 #ifdef __windows__
2003  homedrive = getenv("HOMEDRIVE");
2004  homepath = getenv("HOMEPATH");
2005  if ((homedrive != NULL) && (homepath != NULL)) {
2006  len = strlen(homedrive) + strlen(homepath) + 1;
2007  gl_home_dir = (char *) malloc(len);
2008  if (gl_home_dir != NULL) {
2009  strcpy(gl_home_dir, homedrive);
2010  strcat(gl_home_dir, homepath);
2011  return;
2012  }
2013  }
2014 
2015  wdir[0] = '\0';
2016  if (GetWindowsDirectory(wdir, sizeof(wdir) - 1) < 1)
2017  (void) strncpy(wdir, ".", sizeof(wdir));
2018  else if (wdir[1] == ':') {
2019  wdir[2] = '\\';
2020  wdir[3] = '\0';
2021  }
2022  homedir = wdir;
2023 #else
2024  cp = (char *) getlogin();
2025  if (cp == NULL) {
2026  cp = (char *) getenv("LOGNAME");
2027  if (cp == NULL)
2028  cp = (char *) getenv("USER");
2029  }
2030  pw = NULL;
2031  if (cp != NULL)
2032  pw = getpwnam(cp);
2033  if (pw == NULL)
2034  pw = getpwuid(getuid());
2035  if (pw == NULL)
2036  return; /* hell with it */
2037  homedir = pw->pw_dir;
2038 #endif
2039  }
2040 
2041  len = strlen(homedir) + /* NUL */ 1;
2042  gl_home_dir = (char *) malloc(len);
2043  if (gl_home_dir != NULL) {
2044  memcpy(gl_home_dir, homedir, len);
2045  }
2046 } /* gl_set_home_dir */
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
#define free
Definition: debug_ros.c:5
smooth NULL
Definition: ftsmooth.c:416
char * getlogin(void)
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
uid_t getuid()
Definition: uid.c:27
POINT cp
Definition: magnifier.c:59
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
#define GetWindowsDirectory
Definition: winbase.h:3697
static char * gl_home_dir
Definition: getline.c:110

Referenced by gl_check_inputrc_for_vi(), and gl_local_filename_completion_proc().

◆ gl_setheight()

void gl_setheight ( int  )

Definition at line 547 of file getline.c.

548 {
549  if (w > 10) {
550  gl_termh = w;
551  } else {
552  gl_error("\n*** Error: minimum screen height is 10\n");
553  }
554 } /* gl_setheight */
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
static int gl_termh
Definition: getline.c:96
static void gl_error(const char *const buf)
Definition: getline.c:428

Referenced by gl_init().

◆ gl_setwidth()

void gl_setwidth ( int  )

Definition at line 532 of file getline.c.

533 {
534  if (w > 250)
535  w = 250;
536  if (w > 20) {
537  gl_termw = w;
538  gl_scroll = w / 3;
539  } else {
540  gl_error("\n*** Error: minimum screen width is 21\n");
541  }
542 } /* gl_setwidth */
static int gl_termw
Definition: getline.c:95
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
static void gl_error(const char *const buf)
Definition: getline.c:428
static int gl_scroll
Definition: getline.c:97

Referenced by gl_init(), and InitReadline().

◆ gl_strwidth()

void gl_strwidth ( gl_strwidth_proc  )

◆ gl_tab_completion()

void gl_tab_completion ( gl_tab_completion_proc  )

Definition at line 1951 of file getline.c.

1952 {
1953  if (proc == NULL)
1954  proc = gl_local_filename_completion_proc; /* default proc */
1956 } /* gl_tab_completion */
char * gl_local_filename_completion_proc(const char *start, int idx)
Definition: getline.c:2258
static HANDLE proc()
Definition: pdb.c:32
smooth NULL
Definition: ftsmooth.c:416
gl_tab_completion_proc gl_completion_proc
Definition: getline.c:84

Variable Documentation

◆ gl_buf

◆ gl_completion_exact_match_extra_char

int gl_completion_exact_match_extra_char

◆ gl_completion_proc

gl_tab_completion_proc gl_completion_proc

Definition at line 84 of file getline.c.

Referenced by getline(), gl_do_tab_completion(), gl_tab_completion(), and InitReadline().

◆ gl_ellipses_during_completion

int gl_ellipses_during_completion

Definition at line 87 of file getline.c.

Referenced by gl_do_tab_completion(), and gl_fixup().

◆ gl_filename_quote_characters

const char* gl_filename_quote_characters

Definition at line 86 of file getline.c.

Referenced by gl_do_tab_completion().

◆ gl_filename_quoting_desired

int gl_filename_quoting_desired

Definition at line 85 of file getline.c.

Referenced by CompletionFunction(), and gl_do_tab_completion().

◆ gl_in_hook

gl_in_hook_proc gl_in_hook

Definition at line 80 of file getline.c.

Referenced by getline(), and search_term().

◆ gl_out_hook

gl_out_hook_proc gl_out_hook

Definition at line 81 of file getline.c.

Referenced by gl_newline().

◆ gl_strlen

gl_strlen_proc gl_strlen

Referenced by SaveHistory().

◆ gl_tab_hook

gl_tab_hook_proc gl_tab_hook

Definition at line 82 of file getline.c.

Referenced by getline().