ReactOS 0.4.15-dev-7953-g1f49173
readln.c File Reference
#include "syshdrs.h"
#include "shell.h"
#include "util.h"
#include "bookmark.h"
#include "cmds.h"
#include "pref.h"
#include "ls.h"
#include "readln.h"
#include "getline.h"
Include dependency graph for readln.c:

Go to the source code of this file.

Functions

void GetScreenColumns (void)
 
void InitTermcap (void)
 
static charFindStartOfCurrentCommand (void)
 
static FileInfoListPtr GetLsCacheFileList (const char *const item)
 
static charRemoteCompletionFunction (const char *text, int state, int fTypeFilter)
 
static charRemoteFileCompletionFunction (const char *text, int state)
 
static charRemoteDirCompletionFunction (const char *text, int state)
 
static charBookmarkCompletionFunction (const char *text, int state)
 
static charCommandCompletionFunction (const char *text, int state)
 
static charPrefOptCompletionFunction (const char *text, int state)
 
void ReCacheBookmarks (void)
 
static int HaveCommandNameOnly (char *cmdstart)
 
static charCompletionFunction (const char *text, int state)
 
void LoadHistory (void)
 
static size_t Vt100VisibleStrlen (const char *src)
 
void SaveHistory (void)
 
void InitReadline (void)
 
charReadline (char *prompt)
 
void AddHistory (char *line)
 
void DisposeReadline (void)
 
void SetXtermTitle (const char *const fmt,...)
 
void PrintStartupBanner (void)
 
void MakePrompt (char *dst, size_t dsize)
 

Variables

const chartcap_normal = ""
 
const chartcap_boldface = ""
 
const chartcap_underline = ""
 
const chartcap_reverse = ""
 
const chargTerm
 
int gXterm
 
int gXtermTitle
 
char gCurXtermTitleStr [256]
 
int gEventNumber
 
int gMaySetXtermTitle
 
LsCacheItem gLsCache [kLsCacheSize]
 
FTPConnectionInfo gConn
 
char gRemoteCWD [512]
 
char gOurDirectoryPath []
 
char gVersion []
 
int gNumBookmarks
 
BookmarkPtr gBookmarkTable
 
PrefOpt gPrefOpts []
 
int gNumPrefOpts
 
int gScreenColumns
 
int gIsTTYr
 
int gUid
 

Function Documentation

◆ AddHistory()

void AddHistory ( char line)

Definition at line 699 of file readln.c.

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

Referenced by CommandShell().

◆ BookmarkCompletionFunction()

static char * BookmarkCompletionFunction ( const char text,
int  state 
)
static

Definition at line 421 of file readln.c.

422{
423 char *cp;
424 size_t textlen;
425 int i, matches;
426
427 if ((gBookmarkTable == NULL) || (state >= gNumBookmarks))
428 return (NULL);
429
430 textlen = strlen(text);
431 if (textlen == 0) {
432 cp = StrDup(gBookmarkTable[state].bookmarkName);
433 } else {
434 cp = NULL;
435 for (i=0, matches=0; i<gNumBookmarks; i++) {
436 if (ISTRNCMP(gBookmarkTable[i].bookmarkName, text, textlen) == 0) {
437 if (matches >= state) {
438 cp = StrDup(gBookmarkTable[i].bookmarkName);
439 break;
440 }
441 matches++;
442 }
443 }
444 }
445 return cp;
446} /* BookmarkCompletionFunction */
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static int state
Definition: maze.c:121
#define NULL
Definition: types.h:112
const WCHAR * text
Definition: package.c:1799
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
POINT cp
Definition: magnifier.c:59
#define matches(FN)
Definition: match.h:70
#define ISTRNCMP
Definition: util.h:29
BookmarkPtr gBookmarkTable
Definition: bookmark.c:28
int gNumBookmarks
Definition: bookmark.c:27
#define StrDup
Definition: shlwapi.h:1533

Referenced by CompletionFunction().

◆ CommandCompletionFunction()

static char * CommandCompletionFunction ( const char text,
int  state 
)
static

Definition at line 452 of file readln.c.

453{
454 char *cp;
455 size_t textlen;
456 int i, matches;
457 CommandPtr cmdp;
458
459 textlen = strlen(text);
460 if (textlen == 0) {
461 cp = NULL;
462 } else {
463 cp = NULL;
464 for (i=0, matches=0; ; i++) {
465 cmdp = GetCommandByIndex(i);
466 if (cmdp == kNoCommand)
467 break;
468 if (ISTRNCMP(cmdp->name, text, textlen) == 0) {
469 if (matches >= state) {
470 cp = StrDup(cmdp->name);
471 break;
472 }
473 matches++;
474 }
475 }
476 }
477 return cp;
478} /* CommandCompletionFunction */
CommandPtr GetCommandByIndex(const int i)
Definition: shell.c:140
#define kNoCommand
Definition: shell.h:55
Definition: shell.h:41
const char * name
Definition: shell.h:42

Referenced by CompletionFunction().

◆ CompletionFunction()

static char * CompletionFunction ( const char text,
int  state 
)
static

Definition at line 537 of file readln.c.

538{
539 char *cp;
540 char *cmdstart;
541 ArgvInfo ai;
542 int bUsed;
543 CommandPtr cmdp;
544 static int flags;
545
546 if (state == 0) {
547 flags = -1;
548 cmdstart = FindStartOfCurrentCommand();
549 if (cmdstart == NULL)
550 return NULL;
551 if (HaveCommandNameOnly(cmdstart)) {
552 flags = -2; /* special case */
554 return cp;
555 }
556
557 (void) memset(&ai, 0, sizeof(ai));
558 bUsed = MakeArgv(cmdstart, &ai.cargc, ai.cargv,
559 (int) (sizeof(ai.cargv) / sizeof(char *)),
560 ai.argbuf, sizeof(ai.argbuf),
561 ai.noglobargv, 1);
562 if (bUsed <= 0)
563 return NULL;
564 if (ai.cargc == 0)
565 return NULL;
566
567 cmdp = GetCommandByName(ai.cargv[0], 0);
568 if (cmdp == kAmbiguousCommand) {
569 return NULL;
570 } else if (cmdp == kNoCommand) {
571 return NULL;
572 }
573 flags = cmdp->flags;
574 }
575 if (flags == (-2)) {
577 return cp;
578 }
579 if (flags < 0)
580 return NULL;
583 return cp;
584 } else if ((flags & kCompleteRemoteFile) != 0) {
587 return cp;
588 } else if ((flags & kCompleteRemoteDir) != 0) {
591 return cp;
592 } else if ((flags & kCompleteBookmark) != 0) {
594 return cp;
595 } else if ((flags & kCompletePrefOpt) != 0) {
597 return cp;
598 }
599 return NULL;
600} /* CompletionFunction */
char * gl_local_filename_completion_proc(const char *start, int idx)
Definition: getline.c:2258
int gl_filename_quoting_desired
Definition: getline.c:85
GLbitfield flags
Definition: glext.h:7161
int MakeArgv(char *line, int *cargc, const char **cargv, int cargcmax, char *dbuf, size_t dbufsize, int *noglobargv, int readlineHacks)
Definition: shell.c:221
CommandPtr GetCommandByName(const char *const name, int wantExactMatch)
Definition: shell.c:156
static char * RemoteFileCompletionFunction(const char *text, int state)
Definition: readln.c:397
static char * PrefOptCompletionFunction(const char *text, int state)
Definition: readln.c:484
static char * CommandCompletionFunction(const char *text, int state)
Definition: readln.c:452
static int HaveCommandNameOnly(char *cmdstart)
Definition: readln.c:523
static char * FindStartOfCurrentCommand(void)
Definition: readln.c:210
static char * RemoteDirCompletionFunction(const char *text, int state)
Definition: readln.c:409
static char * BookmarkCompletionFunction(const char *text, int state)
Definition: readln.c:421
#define memset(x, y, z)
Definition: compat.h:39
#define kCompleteRemoteDir
Definition: shell.h:62
#define kCompleteRemoteFile
Definition: shell.h:61
#define kAmbiguousCommand
Definition: shell.h:54
#define kCompleteLocalDir
Definition: shell.h:64
#define kCompleteLocalFile
Definition: shell.h:63
#define kCompleteBookmark
Definition: shell.h:65
#define kCompletePrefOpt
Definition: shell.h:66
Definition: shell.h:8
int cargc
Definition: shell.h:11
int noglobargv[64]
Definition: shell.h:10
const char * cargv[64]
Definition: shell.h:9
char argbuf[256]
Definition: shell.h:12
int flags
Definition: shell.h:45

◆ 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().

◆ FindStartOfCurrentCommand()

static char * FindStartOfCurrentCommand ( void  )
static

Definition at line 210 of file readln.c.

211{
212 char *scp;
213 char *start;
214 int qc;
215
216 for (scp = gl_buf;;) {
217 start = scp;
218 for (;;) {
219 if (*scp == '\0')
220 goto done;
221 if (!isspace((int) *scp))
222 break;
223 scp++;
224 }
225 start = scp;
226
227 for (;;) {
228 if (*scp == '\0') {
229 goto done;
230 } else if ((*scp == '"') || (*scp == '\'')) {
231 qc = *scp++;
232
233 for (;;) {
234 if (*scp == '\0') {
235 goto done;
236 } else if (*scp == '\\') {
237 scp++;
238 if (*scp == '\0')
239 goto done;
240 scp++;
241 } else if (*scp == qc) {
242 scp++;
243 break;
244 } else {
245 scp++;
246 }
247 }
248 } else if (*scp == '\\') {
249 scp++;
250 if (*scp == '\0')
251 goto done;
252 scp++;
253 } else if ((*scp == ';') || (*scp == '\n')) {
254 /* command ended */
255 scp++;
256 if (*scp == '\0')
257 goto done;
258 break;
259 } else {
260 scp++;
261 }
262 }
263 }
264done:
265 return (start);
266} /* FindStartOfCurrentCommand */
#define isspace(c)
Definition: acclib.h:69
char gl_buf[GL_BUF_SIZE]
Definition: getline.c:89
GLuint start
Definition: gl.h:1545

Referenced by CompletionFunction().

◆ GetLsCacheFileList()

static FileInfoListPtr GetLsCacheFileList ( const char *const  item)
static

Definition at line 271 of file readln.c.

272{
273 int ci;
274 int sortBy;
275 int sortOrder;
276 FileInfoListPtr filp;
277
278 ci = LsCacheLookup(item);
279 if (ci < 0) {
280 /* This dir was not in the
281 * cache -- go get it.
282 */
283 Ls(item, 'l', "", NULL);
284 ci = LsCacheLookup(item);
285 if (ci < 0)
286 return NULL;
287 }
288
289 sortBy = 'n'; /* Sort by filename. */
290 sortOrder = 'a'; /* Sort in ascending order. */
291 filp = &gLsCache[ci].fil;
292 SortFileInfoList(filp, sortBy, sortOrder);
293 return filp;
294} /* GetLsCacheFileList */
void SortFileInfoList(FileInfoListPtr list, int sortKey, int sortOrder)
Definition: linelist.c:353
void Ls(const char *const item, int listmode, const char *const options, FILE *stream)
Definition: ls.c:465
int LsCacheLookup(const char *const itempath)
Definition: ls.c:110
static ATOM item
Definition: dde.c:856
LsCacheItem gLsCache[kLsCacheSize]
Definition: ls.c:26
FileInfoList fil
Definition: ls.h:12

Referenced by RemoteCompletionFunction().

◆ 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 STRNCAT(d, s)
Definition: Strn.h:48
#define STRNCPY(dst, src, n)
Definition: rdesktop.h:168
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI GetConsoleScreenBufferInfo(IN HANDLE hConsoleOutput, OUT PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo)
Definition: console.c:595
#define SIGPIPE
Definition: signal.h:35
#define SIG_IGN
Definition: signal.h:48
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define GL_BUF_SIZE
Definition: getline.h:8
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE *_File)
#define EOF
Definition: stdio.h:24
_Check_return_ _CRTIMP int __cdecl fscanf(_Inout_ FILE *_File, _In_z_ _Scanf_format_string_ const char *_Format,...)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
_Check_return_ char *__cdecl getenv(_In_z_ const char *_VarName)
if(dx< 0)
Definition: linetemp.h:194
volatile sigproc_t vsigproc_t
Definition: util.h:11
void(* sigproc_t)(int)
Definition: util.h:10
#define popen
Definition: syshdrs.h:72
#define pclose
Definition: syshdrs.h:73
#define NcSignal
Definition: ncftp.h:604
int gScreenColumns
Definition: cmds.c:78
int gUid
Definition: util.c:13
#define X_OK
Definition: io.h:169
SHORT X
Definition: blue.h:26
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
#define ioctl
Definition: wintirpc.h:60

Referenced by PreInit().

◆ HaveCommandNameOnly()

static int HaveCommandNameOnly ( char cmdstart)
static

Definition at line 523 of file readln.c.

524{
525 char *cp;
526 for (cp = cmdstart; *cp != '\0'; cp++) {
527 if (isspace((int) *cp))
528 return (0); /* At least one argument in progress. */
529 }
530 return (1);
531} /* HaveCommandNameOnly */

Referenced by CompletionFunction().

◆ InitReadline()

void InitReadline ( void  )

Definition at line 659 of file readln.c.

660{
663 LoadHistory();
665} /* InitReadline */
gl_tab_completion_proc gl_completion_proc
Definition: getline.c:84
void gl_setwidth(int w)
Definition: getline.c:532
void ReCacheBookmarks(void)
Definition: readln.c:515
void LoadHistory(void)
Definition: readln.c:606
_In_ UCHAR _In_ POWER_STATE _In_opt_ PREQUEST_POWER_COMPLETE CompletionFunction
Definition: pofuncs.h:44

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 */
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ISTRCMP
Definition: util.h:28
char gCurXtermTitleStr[256]
Definition: readln.c:30
const char * tcap_reverse
Definition: readln.c:26
const char * tcap_normal
Definition: readln.c:23
int gXtermTitle
Definition: readln.c:29
const char * tcap_underline
Definition: readln.c:25
int gXterm
Definition: readln.c:28
const char * tcap_boldface
Definition: readln.c:24
const char * gTerm
Definition: readln.c:27
#define ZeroMemory
Definition: winbase.h:1712
#define SetConsoleTitle
Definition: wincon.h:783
#define GetConsoleTitle
Definition: wincon.h:775

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 */
void gl_histloadfile(const char *const path)
Definition: getline.c:1437
char * OurDirectoryPath(char *const dst, const size_t siz, const char *const fname)
Definition: util.c:486
char gOurDirectoryPath[]
Definition: util.c:17
#define kHistoryFileName
Definition: readln.h:11

Referenced by InitReadline().

◆ MakePrompt()

void MakePrompt ( char dst,
size_t  dsize 
)

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 ",
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 */
char * Strncat(char *const, const char *const, const size_t)
Definition: Strncat.c:13
char * Strncpy(char *const, const char *const, const size_t)
Definition: Strncpy.c:11
GLenum GLenum dst
Definition: glext.h:6340
void AbbrevStr(char *dst, const char *src, size_t max, int mode)
Definition: util.c:451
FTPConnectionInfo gConn
Definition: main.c:37
char gRemoteCWD[512]
Definition: cmds.c:33
#define snprintf
Definition: wintirpc.h:48

Referenced by CommandShell().

◆ PrefOptCompletionFunction()

static char * PrefOptCompletionFunction ( const char text,
int  state 
)
static

Definition at line 484 of file readln.c.

485{
486 char *cp;
487 size_t textlen;
488 int i, matches;
489
490 if (state >= gNumPrefOpts)
491 return (NULL);
492
493 textlen = strlen(text);
494 if (textlen == 0) {
495 cp = StrDup(gPrefOpts[state].varname);
496 } else {
497 cp = NULL;
498 for (i=0, matches=0; i<gNumPrefOpts; i++) {
499 if (ISTRNCMP(gPrefOpts[i].varname, text, textlen) == 0) {
500 if (matches >= state) {
501 cp = StrDup(gPrefOpts[i].varname);
502 break;
503 }
504 matches++;
505 }
506 }
507 }
508 return cp;
509} /* PrefOptCompletionFunction */
PrefOpt gPrefOpts[]
Definition: pref.c:73
int gNumPrefOpts
Definition: pref.c:113

Referenced by CompletionFunction().

◆ 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,
784 vdate
785 );
786#else
787 (void) fprintf(stdout, "%s%.11s%s%s by Mike Gleason (ncftp@ncftp.com).\n",
789 gVersion + 5,
791 vdate
792 );
793#endif
794 (void) fflush(stdout);
795} /* PrintStartupBanner */
char * strchr(const char *String, int ch)
Definition: utclib.c:501
const GLdouble * v
Definition: gl.h:2040
#define stdout
Definition: stdio.h:99
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
char gVersion[]
Definition: init.c:22

Referenced by PostInit().

◆ Readline()

char * Readline ( char prompt)

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 */
#define stdin
Definition: stdio.h:98
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
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}
int LoadBookmarkTable(void)
Definition: bookmark.c:524

Referenced by InitReadline(), and SaveCurrentAsBookmark().

◆ RemoteCompletionFunction()

static char * RemoteCompletionFunction ( const char text,
int  state,
int  fTypeFilter 
)
static

Definition at line 300 of file readln.c.

301{
302 char rpath[256];
303 char *cp;
304 char *cp2;
305 const char *textbasename;
306 int fType;
307 FileInfoPtr diritemp;
308 FileInfoListPtr filp;
309 int textdirlen;
310 size_t tbnlen;
311 size_t flen, mlen;
312 static FileInfoVec diritemv;
313 static int i;
314
315 textbasename = strrchr(text, '/');
316 if (textbasename == NULL) {
317 textbasename = text;
318 textdirlen = -1;
319 } else {
320 textdirlen = (int) (textbasename - text);
321 textbasename++;
322 }
323 tbnlen = strlen(textbasename);
324
325 if (state == 0) {
326 if (text[0] == '\0') {
327 /* Special case when they do "get <TAB><TAB> " */
328 STRNCPY(rpath, gRemoteCWD);
329 } else {
330 PathCat(rpath, sizeof(rpath), gRemoteCWD, text);
331 if (text[strlen(text) - 1] == '/') {
332 /* Special case when they do "get /dir1/dir2/<TAB><TAB>" */
333 STRNCAT(rpath, "/");
334 }
335 cp2 = strrchr(rpath, '/');
336 if (cp2 == NULL) {
337 return NULL;
338 } else if (cp2 == rpath) {
339 /* Item in root directory. */
340 cp2++;
341 }
342 *cp2 = '\0';
343 }
344
345 filp = GetLsCacheFileList(rpath);
346 if (filp == NULL)
347 return NULL;
348
349 diritemv = filp->vec;
350 if (diritemv == NULL)
351 return NULL;
352
353 i = 0;
354 }
355
356 for ( ; ; ) {
357 diritemp = diritemv[i];
358 if (diritemp == NULL)
359 break;
360
361 i++;
362 fType = (int) diritemp->type;
363 if ((fTypeFilter == 0) || (fType == fTypeFilter) || (fType == /* symlink */ 'l')) {
364 if (strncmp(textbasename, diritemp->relname, tbnlen) == 0) {
365 flen = strlen(diritemp->relname);
366 if (textdirlen < 0) {
367 mlen = flen + 2;
368 cp = (char *) malloc(mlen);
369 if (cp == NULL)
370 return (NULL);
371 (void) memcpy(cp, diritemp->relname, mlen);
372 } else {
373 mlen = textdirlen + 1 + flen + 2;
374 cp = (char *) malloc(mlen);
375 if (cp == NULL)
376 return (NULL);
377 (void) memcpy(cp, text, (size_t) textdirlen);
378 cp[textdirlen] = '/';
379 (void) strcpy(cp + textdirlen + 1, diritemp->relname);
380 }
381 if (fType == 'd') {
383 } else {
385 }
386 return cp;
387 }
388 }
389 }
390 return NULL;
391} /* RemoteCompletionFunction */
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
int gl_completion_exact_match_extra_char
Definition: getline.c:88
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void PathCat(char *const dst, const size_t dsize, const char *const cwd, const char *const src)
Definition: util.c:368
static FileInfoListPtr GetLsCacheFileList(const char *const item)
Definition: readln.c:271
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
FileInfoVec vec
Definition: ncftp.h:266
int type
Definition: ncftp.h:258
char * relname
Definition: ncftp.h:253

Referenced by RemoteDirCompletionFunction(), and RemoteFileCompletionFunction().

◆ RemoteDirCompletionFunction()

static char * RemoteDirCompletionFunction ( const char text,
int  state 
)
static

Definition at line 409 of file readln.c.

410{
411 char *cp;
412
414 return cp;
415} /* RemoteDirCompletionFunction */
static char * RemoteCompletionFunction(const char *text, int state, int fTypeFilter)
Definition: readln.c:300

Referenced by CompletionFunction().

◆ RemoteFileCompletionFunction()

static char * RemoteFileCompletionFunction ( const char text,
int  state 
)
static

Definition at line 397 of file readln.c.

398{
399 char *cp;
400
402 return cp;
403} /* RemoteFileCompletionFunction */

Referenced by CompletionFunction().

◆ 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 */
void gl_histsavefile(const char *const path)
Definition: getline.c:1408
gl_strlen_proc gl_strlen
static size_t Vt100VisibleStrlen(const char *src)
Definition: readln.c:620
_Check_return_ _CRTIMP int __cdecl _chmod(_In_z_ const char *_Filename, _In_ int _Mode)

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 */
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define stderr
Definition: stdio.h:100
int __cdecl vsprintf(char *_Dest, const char *_Format, va_list _Args)
Definition: sprintf.c:733
int gMaySetXtermTitle
Definition: pref.c:41
Definition: dsound.c:943
#define vsnprintf
Definition: tif_win32.c:406
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

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

◆ Vt100VisibleStrlen()

static size_t Vt100VisibleStrlen ( const char src)
static

Definition at line 620 of file readln.c.

621{
622 const char *cp;
623 size_t esc;
624
625 for (esc = 0, cp = src; *cp != '\0'; cp++) {
626 if (*cp == '\033')
627 esc++;
628 }
629
630 /* The VT100 escape codes we use are all in the form "\033[7m"
631 * These aren't visible, so subtract them from the count.
632 */
633 return ((size_t) (cp - src) - (esc * 4));
634} /* Vt100VisibleStrlen */
GLenum src
Definition: glext.h:6340

Referenced by SaveHistory().

Variable Documentation

◆ gBookmarkTable

◆ gConn

FTPConnectionInfo gConn
extern

Definition at line 37 of file main.c.

Referenced by MakePrompt().

◆ gCurXtermTitleStr

char gCurXtermTitleStr[256]

Definition at line 30 of file readln.c.

Referenced by InitTermcap(), and SetXtermTitle().

◆ gEventNumber

int gEventNumber
extern

Definition at line 27 of file shell.c.

Referenced by CommandShell().

◆ gIsTTYr

int gIsTTYr
extern

Definition at line 33 of file main.c.

Referenced by PreInit(), and Readline().

◆ gLsCache

◆ gMaySetXtermTitle

int gMaySetXtermTitle
extern

Definition at line 41 of file pref.c.

Referenced by InitPrefs(), SetXtermTitle(), and SetXtTitle().

◆ gNumBookmarks

int gNumBookmarks
extern

◆ gNumPrefOpts

int gNumPrefOpts
extern

Definition at line 113 of file pref.c.

Referenced by PrefOptCompletionFunction(), ProcessPrefsFile(), SavePrefs(), and Set().

◆ gOurDirectoryPath

char gOurDirectoryPath[]
extern

Definition at line 17 of file util.c.

Referenced by LoadHistory(), and SaveHistory().

◆ gPrefOpts

PrefOpt gPrefOpts[]
extern

Definition at line 73 of file pref.c.

Referenced by PrefOptCompletionFunction(), ProcessPrefsFile(), SavePrefs(), Set(), and Show1().

◆ gRemoteCWD

◆ gScreenColumns

int gScreenColumns
extern

Definition at line 78 of file cmds.c.

Referenced by GetScreenColumns(), InitReadline(), and OpenMsg().

◆ gTerm

const char* gTerm

Definition at line 27 of file readln.c.

Referenced by InitTermcap(), and SetXtermTitle().

◆ gUid

int gUid
extern

Definition at line 13 of file util.c.

Referenced by GetScreenColumns(), and InitUserInfo().

◆ gVersion

char gVersion[]
extern

Definition at line 22 of file init.c.

Referenced by PrintStartupBanner(), and SetXtermTitle().

◆ gXterm

int gXterm

Definition at line 28 of file readln.c.

Referenced by InitTermcap().

◆ gXtermTitle

int gXtermTitle

Definition at line 29 of file readln.c.

Referenced by InitTermcap(), and SetXtermTitle().

◆ tcap_boldface

const char* tcap_boldface = ""

Definition at line 24 of file readln.c.

Referenced by InitTermcap(), MakePrompt(), and PrintStartupBanner().

◆ tcap_normal

const char* tcap_normal = ""

Definition at line 23 of file readln.c.

Referenced by InitTermcap(), MakePrompt(), PrintStartupBanner(), and PrPhilBar().

◆ tcap_reverse

const char* tcap_reverse = ""

Definition at line 26 of file readln.c.

Referenced by InitTermcap(), and PrPhilBar().

◆ tcap_underline

const char* tcap_underline = ""

Definition at line 25 of file readln.c.

Referenced by InitTermcap().