ReactOS  0.4.14-dev-376-gaedba84
readln.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define kHistoryFileName   "history"
 

Functions

void GetScreenColumns (void)
 
void InitTermcap (void)
 
void InitReadline (void)
 
void ReCacheBookmarks (void)
 
charReadline (char *)
 
void AddHistory (char *)
 
void PrintStartupBanner (void)
 
void SetXtermTitle (const char *const fmt,...)
 
void MakePrompt (char *, size_t)
 
void SaveHistory (void)
 
void LoadHistory (void)
 
void DisposeReadline (void)
 

Macro Definition Documentation

◆ kHistoryFileName

#define kHistoryFileName   "history"

Definition at line 11 of file readln.h.

Function Documentation

◆ AddHistory()

void AddHistory ( char )

Definition at line 699 of file readln.c.

700 {
701  gl_histadd(line);
702 } /* AddHistory */
void gl_histadd(char *buf)
Definition: getline.c:1314
Definition: parser.c:48

Referenced by CommandShell().

◆ DisposeReadline()

void DisposeReadline ( void  )

Definition at line 707 of file readln.c.

708 {
709  SaveHistory();
710 } /* DisposeReadline */
void SaveHistory(void)
Definition: readln.c:642

Referenced by PostShell().

◆ GetScreenColumns()

void GetScreenColumns ( void  )

Definition at line 55 of file readln.c.

56 {
57 #if defined(WIN32) || defined(_WINDOWS)
59 
61  gScreenColumns = (int) csbi.dwSize.X;
62  if (gScreenColumns < 80)
63  gScreenColumns = 80;
64  }
65 #else /* Unix */
66 #ifdef BINDIR
67  char ncftpbookmarks[256];
68  FILE *infp;
69  vsigproc_t osigpipe;
70  int columns;
71 #endif /* BINDIR */
72  char *cp;
73 
74  if ((cp = (char *) getenv("COLUMNS")) == NULL) {
75  gScreenColumns = 80;
76  } else {
78  return;
79  }
80 
81 #ifdef TIOCGWINSZ
82  {
83  struct winsize felix;
84 
85  memset(&felix, 0, sizeof(felix));
86  if (ioctl(0, TIOCGWINSZ, &felix) == 0) {
87  columns = felix.ws_col;
88  if ((columns > 0) && (columns < GL_BUF_SIZE))
89  gScreenColumns = columns;
90  else
91  gScreenColumns = 80;
92  return;
93  }
94  }
95 #endif
96 
97 #ifdef BINDIR
98  /* Don't run things as root unless really necessary. */
99  if (gUid == 0)
100  return;
101 
102  /* This is a brutal hack where we've hacked a
103  * special command line option into ncftp_bookmarks
104  * (which is linked with curses) so that it computes
105  * the screen size and prints it to stdout.
106  *
107  * This function runs ncftp_bookmarks and gets
108  * that information. The reason we do this is that
109  * we may or may not have a sane installation of
110  * curses/termcap, and we don't want to increase
111  * NcFTP's complexity by the curses junk just to
112  * get the screen size. Instead, we delegate this
113  * to ncftp_bookmarks which already deals with the
114  * ugliness of curses.
115  */
116 
117  STRNCPY(ncftpbookmarks, BINDIR);
118  STRNCAT(ncftpbookmarks, "/");
119  STRNCAT(ncftpbookmarks, "ncftpbookmarks");
120 
121  if (access(ncftpbookmarks, X_OK) < 0)
122  return;
123 
124  STRNCAT(ncftpbookmarks, " --dimensions-terse");
125 
126  osigpipe = NcSignal(SIGPIPE, SIG_IGN);
127  infp = popen(ncftpbookmarks, "r");
128  if (infp != NULL) {
129  columns = 0;
130  (void) fscanf(infp, "%d", &columns);
131  while (getc(infp) != EOF) {}
132  (void) pclose(infp);
133 
134  if ((columns > 0) && (columns < GL_BUF_SIZE))
135  gScreenColumns = columns;
136  }
137  (void) NcSignal(SIGPIPE, (sigproc_t) osigpipe);
138 #endif /* BINDIR */
139 #endif /* Windows */
140 } /* GetScreenColumns */
#define GL_BUF_SIZE
Definition: getline.h:8
_Check_return_ _CRTIMP int __cdecl fscanf(_Inout_ FILE *_File, _In_z_ _Scanf_format_string_ const char *_Format,...)
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
volatile sigproc_t vsigproc_t
Definition: util.h:11
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE *_File)
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:152
#define ioctl
Definition: wintirpc.h:60
smooth NULL
Definition: ftsmooth.c:416
int gUid
Definition: util.c:13
#define X_OK
Definition: io.h:169
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:544
ULONG X
Definition: bl.h:1340
#define STRNCAT(d, s)
Definition: Strn.h:48
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define SIGPIPE
Definition: signal.h:35
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
#define pclose
Definition: syshdrs.h:73
#define NcSignal
Definition: ncftp.h:604
void(* sigproc_t)(int)
Definition: util.h:10
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
#define popen
Definition: syshdrs.h:72
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define EOF
Definition: stdio.h:24
POINT cp
Definition: magnifier.c:59
int gScreenColumns
Definition: main.c:34
#define SIG_IGN
Definition: signal.h:48
#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 PreInit().

◆ InitReadline()

void InitReadline ( void  )

Definition at line 659 of file readln.c.

660 {
663  LoadHistory();
665 } /* InitReadline */
void gl_setwidth(int w)
Definition: getline.c:532
void LoadHistory(void)
Definition: readln.c:606
void ReCacheBookmarks(void)
Definition: readln.c:515
static char * CompletionFunction(const char *text, int state)
Definition: readln.c:537
int gScreenColumns
Definition: main.c:34
gl_tab_completion_proc gl_completion_proc
Definition: getline.c:84

Referenced by PostInit().

◆ InitTermcap()

void InitTermcap ( void  )

Definition at line 148 of file readln.c.

149 {
150 #if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE)
151  gXterm = gXtermTitle = 0;
152  gCurXtermTitleStr[0] = '\0';
153 
154  tcap_normal = "";
155  tcap_boldface = "";
156  tcap_underline = "";
157  tcap_reverse = "";
158 
159  gTerm = "MS-DOS Prompt";
160  ZeroMemory(gSavedConsoleTitle, (DWORD) sizeof(gSavedConsoleTitle));
161  GetConsoleTitle(gSavedConsoleTitle, (DWORD) sizeof(gSavedConsoleTitle) - 1);
162  SetConsoleTitle("NcFTP");
163  gXterm = gXtermTitle = 1;
164 #else
165  const char *term;
166 
167  gXterm = gXtermTitle = 0;
168  gCurXtermTitleStr[0] = '\0';
169 
170  if ((gTerm = getenv("TERM")) == NULL) {
171  tcap_normal = "";
172  tcap_boldface = "";
173  tcap_underline = "";
174  tcap_reverse = "";
175  return;
176  }
177 
178  term = gTerm;
179  if ( (strstr(term, "xterm") != NULL) ||
180  (strstr(term, "rxvt") != NULL) ||
181  (strstr(term, "dtterm") != NULL) ||
182  (ISTRCMP(term, "scoterm") == 0)
183  ) {
184  gXterm = gXtermTitle = 1;
185  }
186 
187  if ( (gXterm != 0) ||
188  (strcmp(term, "vt100") == 0) ||
189  (strcmp(term, "linux") == 0) ||
190  (strcmp(term, "vt220") == 0) ||
191  (strcmp(term, "vt102") == 0)
192  ) {
193  tcap_normal = "\033[0m"; /* Default ANSI escapes */
194  tcap_boldface = "\033[1m";
195  tcap_underline = "\033[4m";
196  tcap_reverse = "\033[7m";
197  } else {
198  tcap_normal = "";
199  tcap_boldface = "";
200  tcap_underline = "";
201  tcap_reverse = "";
202  }
203 #endif
204 } /* InitTermcap */
const char * tcap_boldface
Definition: readln.c:24
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
#define ZeroMemory
Definition: winbase.h:1642
smooth NULL
Definition: ftsmooth.c:416
#define GetConsoleTitle
Definition: wincon.h:763
#define ISTRCMP
Definition: util.h:28
char gCurXtermTitleStr[256]
Definition: readln.c:30
const char * tcap_reverse
Definition: readln.c:26
unsigned long DWORD
Definition: ntddk_ex.h:95
int gXtermTitle
Definition: readln.c:29
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
#define SetConsoleTitle
Definition: wincon.h:771
const char * gTerm
Definition: readln.c:27
const char * tcap_underline
Definition: readln.c:25
const char * tcap_normal
Definition: readln.c:23
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int gXterm
Definition: readln.c:28

Referenced by PostInit().

◆ LoadHistory()

void LoadHistory ( void  )

Definition at line 606 of file readln.c.

607 {
608  char pathName[256];
609 
610  if (gOurDirectoryPath[0] == '\0')
611  return;
612  (void) OurDirectoryPath(pathName, sizeof(pathName), kHistoryFileName);
613 
614  gl_histloadfile(pathName);
615 } /* LoadHistory */
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
#define kHistoryFileName
Definition: readln.h:11
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
char gOurDirectoryPath[]
Definition: util.c:17
void gl_histloadfile(const char *const path)
Definition: getline.c:1437

Referenced by InitReadline().

◆ MakePrompt()

void MakePrompt ( char ,
size_t   
)

Definition at line 802 of file readln.c.

803 {
804  char acwd[64];
805 
806 # ifdef HAVE_SNPRINTF
807  if (gConn.loggedIn != 0) {
808  AbbrevStr(acwd, gRemoteCWD, 25, 0);
809  snprintf(dst, dsize, "%sncftp%s %s %s>%s ",
810  tcap_boldface, tcap_normal, acwd,
812  } else {
813  snprintf(dst, dsize, "%sncftp%s> ",
815  }
816 # else /* HAVE_SNPRINTF */
817  (void) Strncpy(dst, tcap_boldface, dsize);
818  (void) Strncat(dst, "ncftp", dsize);
819  (void) Strncat(dst, tcap_normal, dsize);
820  if (gConn.loggedIn != 0) {
821  AbbrevStr(acwd, gRemoteCWD, 25, 0);
822  (void) Strncat(dst, " ", dsize);
823  (void) Strncat(dst, acwd, dsize);
824  (void) Strncat(dst, " ", dsize);
825  }
826  (void) Strncat(dst, tcap_boldface, dsize);
827  (void) Strncat(dst, ">", dsize);
828  (void) Strncat(dst, tcap_normal, dsize);
829  (void) Strncat(dst, " ", dsize);
830 # endif /* HAVE_SNPRINTF */
831 } /* MakePrompt */
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
const char * tcap_boldface
Definition: readln.c:24
void AbbrevStr(char *dst, const char *src, size_t max, int mode)
Definition: util.c:451
#define snprintf
Definition: wintirpc.h:48
char * Strncat(char *const, const char *const, const size_t)
Definition: Strncat.c:13
FTPConnectionInfo gConn
Definition: main.c:37
char * Strncpy(char *const, const char *const, const size_t)
Definition: Strncpy.c:11
GLenum GLenum dst
Definition: glext.h:6340
const char * tcap_normal
Definition: readln.c:23
char gRemoteCWD[512]
Definition: cmds.c:33

Referenced by CommandShell().

◆ PrintStartupBanner()

void PrintStartupBanner ( void  )

Definition at line 759 of file readln.c.

760 {
761  char v[80], *cp;
762  char vdate[32];
763 
764  /* Print selected information from the version ID. */
765  vdate[0] = '\0';
766  (void) STRNCPY(v, gVersion + 5);
767  cp = strchr(v, ',');
768  if (cp != NULL) {
769  *cp = '\0';
770  cp[-5] = '\0';
771  (void) STRNCPY(vdate, " (");
772  (void) STRNCAT(vdate, v + 16);
773  (void) STRNCAT(vdate, ", ");
774  (void) STRNCAT(vdate, cp - 4);
775  (void) STRNCAT(vdate, ")");
776  }
777 
778 #if defined(BETA) && (BETA > 0)
779  (void) fprintf(stdout, "%s%.11s beta %d%s%s by Mike Gleason (ncftp@ncftp.com).\n",
781  gVersion + 5,
782  BETA,
783  tcap_normal,
784  vdate
785  );
786 #else
787  (void) fprintf(stdout, "%s%.11s%s%s by Mike Gleason (ncftp@ncftp.com).\n",
789  gVersion + 5,
790  tcap_normal,
791  vdate
792  );
793 #endif
794  (void) fflush(stdout);
795 } /* PrintStartupBanner */
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
const char * tcap_boldface
Definition: readln.c:24
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
FILE * stdout
_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 STRNCAT(d, s)
Definition: Strn.h:48
char gVersion[]
Definition: init.c:22
const GLdouble * v
Definition: gl.h:2040
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
const char * tcap_normal
Definition: readln.c:23
char * strchr(const char *String, int ch)
Definition: utclib.c:501
POINT cp
Definition: magnifier.c:59

Referenced by PostInit().

◆ Readline()

char* Readline ( char )

Definition at line 671 of file readln.c.

672 {
673  char *linecopy, *line, *cp;
674  char lbuf[256];
675 
676  if (gIsTTYr) {
677  line = getline(prompt);
678  } else {
679  line = fgets(lbuf, sizeof(lbuf) - 1, stdin);
680  if (line != NULL) {
681  cp = line + strlen(line) - 1;
682  if (*cp == '\n')
683  *cp = '\0';
684  }
685  }
686 
687  if (line != NULL) {
688  if (line[0] == '\0')
689  return NULL; /* EOF */
690  linecopy = StrDup(line);
691  line = linecopy;
692  }
693  return (line);
694 } /* Readline */
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
FILE * stdin
#define StrDup
Definition: shlwapi.h:1533
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
char line[200]
Definition: main.c:97
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
POINT cp
Definition: magnifier.c:59
int gIsTTYr
Definition: main.c:33
#define getline
Definition: schily.h:567

Referenced by CommandShell().

◆ ReCacheBookmarks()

void ReCacheBookmarks ( void  )

Definition at line 515 of file readln.c.

516 {
518 }
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
int LoadBookmarkTable(void)
Definition: bookmark.c:524

Referenced by InitReadline(), and SaveCurrentAsBookmark().

◆ SaveHistory()

void SaveHistory ( void  )

Definition at line 642 of file readln.c.

643 {
644  char pathName[256];
645 
646  if (gOurDirectoryPath[0] == '\0')
647  return; /* Don't create in root directory. */
648  (void) OurDirectoryPath(pathName, sizeof(pathName), kHistoryFileName);
649 
651  gl_histsavefile(pathName);
652  (void) _chmod(pathName, 00600);
653 } /* SaveHistory */
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
gl_strlen_proc gl_strlen
#define kHistoryFileName
Definition: readln.h:11
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
char gOurDirectoryPath[]
Definition: util.c:17
_Check_return_ _CRTIMP int __cdecl _chmod(_In_z_ const char *_Filename, _In_ int _Mode)
static size_t Vt100VisibleStrlen(const char *src)
Definition: readln.c:620
void gl_histsavefile(const char *const path)
Definition: getline.c:1408

Referenced by DisposeReadline().

◆ SetXtermTitle()

void SetXtermTitle ( const char *const  fmt,
  ... 
)

Definition at line 718 of file readln.c.

719 {
720  va_list ap;
721  char buf[256];
722 
723  if ((gXtermTitle != 0) && (gMaySetXtermTitle != 0)) {
724  if ((fmt == NULL) || (ISTRCMP(fmt, "RESTORE") == 0)) {
725 #if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE)
726  STRNCPY(buf, gSavedConsoleTitle);
727 #else
728  STRNCPY(buf, gTerm);
729 #endif
730  } else if (ISTRCMP(fmt, "DEFAULT") == 0) {
731  (void) Strncpy(buf, gVersion + 5, 12);
732  } else {
733  va_start(ap, fmt);
734 #ifdef HAVE_VSNPRINTF
735  (void) vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
736  buf[sizeof(buf) - 1] = '\0';
737 #else
738  (void) vsprintf(buf, fmt, ap);
739 #endif
740  va_end(ap);
741  }
742  if (buf[0] != '\0') {
743 #if (defined(WIN32) || defined(_WINDOWS)) && defined(_CONSOLE)
745 #else
746  if (strcmp(gCurXtermTitleStr, buf) != 0) {
747  fprintf(stderr, "\033]0;%s\007", buf);
749  }
750 #endif
751  }
752  }
753 } /* SetXtermTitle */
#define vsnprintf
Definition: tif_win32.c:406
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
int gMaySetXtermTitle
Definition: pref.c:41
const char * fmt
Definition: wsprintf.c:30
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
#define va_end(ap)
Definition: acmsvcex.h:90
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
#define ISTRCMP
Definition: util.h:28
char gCurXtermTitleStr[256]
Definition: readln.c:30
char gVersion[]
Definition: init.c:22
int gXtermTitle
Definition: readln.c:29
#define SetConsoleTitle
Definition: wincon.h:771
const char * gTerm
Definition: readln.c:27
char * Strncpy(char *const, const char *const, const size_t)
Definition: Strncpy.c:11
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
#define va_start(ap, A)
Definition: acmsvcex.h:91
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
FILE * stderr
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
Definition: dsound.c:943

Referenced by BackToTop(), CommandShell(), PostShell(), PrPhilBar(), PrSizeAndRateMeter(), and PrStatBar().