ReactOS 0.4.15-dev-7958-gcd0bb1a
shell.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ArgvInfo
 
struct  Command
 

Macros

#define kIdleInterval   20
 
#define kIdleBatchLaunch   180
 
#define kBeepAfterCmdTime   15
 
#define kNoMax   (-1)
 
#define kNoMin   (-1)
 
#define kAbbreviatedMatchAllowed   0
 
#define kExactMatchRequired   1
 
#define kAmbiguousCommand   ((CommandPtr) -1)
 
#define kNoCommand   ((CommandPtr) 0)
 
#define kCmdHidden   00001
 
#define kCmdMustBeConnected   00002
 
#define kCmdMustBeDisconnected   00004
 
#define kCompleteRemoteFile   00010
 
#define kCompleteRemoteDir   00020
 
#define kCompleteLocalFile   00040
 
#define kCompleteLocalDir   00100
 
#define kCompleteBookmark   00200
 
#define kCompletePrefOpt   00400
 

Typedefs

typedef struct ArgvInfo ArgvInfo
 
typedef struct ArgvInfoArgvInfoPtr
 
typedef struct CommandCommandPtr
 
typedef void(* CmdProc) (const int argc, const char **const argv, const CommandPtr cmdp, const ArgvInfoPtr aip)
 
typedef struct Command Command
 

Functions

void InitCommandList (void)
 
CommandPtr GetCommandByIndex (const int)
 
CommandPtr GetCommandByName (const char *const, int)
 
void PrintCmdHelp (CommandPtr)
 
void PrintCmdUsage (CommandPtr)
 
int MakeArgv (char *, int *, const char **, int, char *, size_t, int *, int)
 
void XferCanceller (int)
 
void BackToTop (int)
 
void Cancel (int)
 
void CommandShell (void)
 

Macro Definition Documentation

◆ kAbbreviatedMatchAllowed

#define kAbbreviatedMatchAllowed   0

Definition at line 50 of file shell.h.

◆ kAmbiguousCommand

#define kAmbiguousCommand   ((CommandPtr) -1)

Definition at line 54 of file shell.h.

◆ kBeepAfterCmdTime

#define kBeepAfterCmdTime   15

Definition at line 26 of file shell.h.

◆ kCmdHidden

#define kCmdHidden   00001

Definition at line 58 of file shell.h.

◆ kCmdMustBeConnected

#define kCmdMustBeConnected   00002

Definition at line 59 of file shell.h.

◆ kCmdMustBeDisconnected

#define kCmdMustBeDisconnected   00004

Definition at line 60 of file shell.h.

◆ kCompleteBookmark

#define kCompleteBookmark   00200

Definition at line 65 of file shell.h.

◆ kCompleteLocalDir

#define kCompleteLocalDir   00100

Definition at line 64 of file shell.h.

◆ kCompleteLocalFile

#define kCompleteLocalFile   00040

Definition at line 63 of file shell.h.

◆ kCompletePrefOpt

#define kCompletePrefOpt   00400

Definition at line 66 of file shell.h.

◆ kCompleteRemoteDir

#define kCompleteRemoteDir   00020

Definition at line 62 of file shell.h.

◆ kCompleteRemoteFile

#define kCompleteRemoteFile   00010

Definition at line 61 of file shell.h.

◆ kExactMatchRequired

#define kExactMatchRequired   1

Definition at line 51 of file shell.h.

◆ kIdleBatchLaunch

#define kIdleBatchLaunch   180

Definition at line 21 of file shell.h.

◆ kIdleInterval

#define kIdleInterval   20

Definition at line 16 of file shell.h.

◆ kNoCommand

#define kNoCommand   ((CommandPtr) 0)

Definition at line 55 of file shell.h.

◆ kNoMax

#define kNoMax   (-1)

Definition at line 34 of file shell.h.

◆ kNoMin

#define kNoMin   (-1)

Definition at line 35 of file shell.h.

Typedef Documentation

◆ ArgvInfo

◆ ArgvInfoPtr

◆ CmdProc

typedef void(* CmdProc) (const int argc, const char **const argv, const CommandPtr cmdp, const ArgvInfoPtr aip)

Definition at line 29 of file shell.h.

◆ Command

◆ CommandPtr

Definition at line 28 of file shell.h.

Function Documentation

◆ BackToTop()

void BackToTop ( int  sigNum)

Definition at line 452 of file shell.c.

453{
454 gGotSig = sigNum;
455 if (sigNum == SIGPIPE) {
456 if (gRunningCommand == 1) {
457 (void) fprintf(stderr, "Unexpected broken pipe.\n");
458 gRunningCommand = 0;
459 } else {
460 SetXtermTitle("RESTORE");
461 exit(1);
462 }
463 } else if (sigNum == SIGINT) {
464 if (gRunningCommand == 0)
466 }
467 if (gMayBackToTopJmp > 0) {
468#ifdef HAVE_SIGSETJMP
470#else /* HAVE_SIGSETJMP */
471 longjmp(gBackToTopJmp, 1);
472#endif /* HAVE_SIGSETJMP */
473 }
474} /* BackToTop */
#define SIGINT
Definition: signal.h:23
#define SIGPIPE
Definition: signal.h:35
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
int gGotSig
Definition: shell.c:60
int gMayBackToTopJmp
Definition: shell.c:57
jmp_buf gBackToTopJmp
Definition: shell.c:50
int gDoneApplication
Definition: shell.c:21
int gRunningCommand
Definition: shell.c:63
void siglongjmp(sigjmp_buf buf, int val)
void SetXtermTitle(const char *const fmt,...)
Definition: readln.c:718
#define exit(n)
Definition: config.h:202

Referenced by CommandShell().

◆ Cancel()

void Cancel ( int  sigNum)

Definition at line 481 of file shell.c.

482{
483 if (gMayCancelJmp != 0) {
484 gGotSig = sigNum;
485 gMayCancelJmp = 0;
486#ifdef HAVE_SIGSETJMP
488#else /* HAVE_SIGSETJMP */
489 longjmp(gCancelJmp, 1);
490#endif /* HAVE_SIGSETJMP */
491 }
492} /* Cancel */
jmp_buf gCancelJmp
Definition: shell.c:45
int gMayCancelJmp
Definition: shell.c:54

Referenced by CreatePartitionPage(), DECLARE_INTERFACE_(), DECLSPEC_ALIGN(), ListCmd(), LocalListCmd(), PageCmd(), and ShowPartitionSizeInputBox().

◆ CommandShell()

void CommandShell ( void  )

Definition at line 499 of file shell.c.

500{
501 int tUsed, bUsed;
502 ArgvInfo ai;
503 char prompt[64];
504 char *lineRead;
505#if defined(WIN32) || defined(_WINDOWS)
506#else
507 int sj;
508#endif
510
511 /* Execution may jump back to this point to restart the shell. */
512#if defined(WIN32) || defined(_WINDOWS)
513
514#elif defined(HAVE_SIGSETJMP)
515 sj = sigsetjmp(gBackToTopJmp, 1);
516#else /* HAVE_SIGSETJMP */
517 sj = setjmp(gBackToTopJmp);
518#endif /* HAVE_SIGSETJMP */
519
520#if defined(WIN32) || defined(_WINDOWS)
521#else
522 if (sj != 0) {
523 Trace(0, "Caught signal %d, back at top.\n", gGotSig);
524 if (gGotSig == SIGALRM) {
525 (void) printf("\nRemote host was not responding, closing down the session.");
527 } else{
528 (void) printf("\nInterrupted.\n");
529 if (gCancelCtrl != 0) {
530 gCancelCtrl = 0;
531 (void) printf("Closing down the current FTP session: ");
533 (void) sleep(1);
534 (void) printf("done.\n");
535 }
536 }
537 }
538
540#endif
541
542
543 ++gEventNumber;
544
545 while (gDoneApplication == 0) {
546#if defined(WIN32) || defined(_WINDOWS)
547#else
550 (void) NcSignal(SIGALRM, BackToTop);
551#endif
552
553 MakePrompt(prompt, sizeof(prompt));
554
555 if (gConn.connected == 0) {
556 SetXtermTitle("DEFAULT");
557 } else {
558 SetXtermTitle("%s - NcFTP", gConn.host);
559 }
560
561 lineRead = Readline(prompt);
562 if (lineRead == NULL) {
563 /* EOF, Control-D */
564 (void) printf("\n");
565 break;
566 }
567 Trace(0, "> %s\n", lineRead);
568 AddHistory(lineRead);
569 for (tUsed = 0;;) {
570 (void) memset(&ai, 0, sizeof(ai));
571 bUsed = MakeArgv(lineRead + tUsed, &ai.cargc, ai.cargv,
572 (int) (sizeof(ai.cargv) / sizeof(char *)),
573 ai.argbuf, sizeof(ai.argbuf),
574 ai.noglobargv, 0);
575 if (bUsed <= 0)
576 break;
577 tUsed += bUsed;
578 if (ai.cargc == 0)
579 continue;
580 gRunningCommand = 1;
581 (void) time(&cmdStart);
582 if (DoCommand(&ai) < 0) {
583 (void) time(&cmdStop);
584 gRunningCommand = 0;
585 break;
586 }
587 (void) time(&cmdStop);
588 gRunningCommand = 0;
590 /* Let the user know that a time-consuming
591 * operation has completed.
592 */
593#if defined(WIN32) || defined(_WINDOWS)
595#else
596 (void) fprintf(stderr, "\007");
597#endif
598 }
599 ++gEventNumber;
600 }
601
602 free(lineRead);
603 }
604
605 CloseHost();
607} /* Shell */
INT cmdStart(INT argc, WCHAR **argv)
Definition: cmdStart.c:172
INT cmdStop(INT argc, WCHAR **argv)
Definition: cmdStop.c:12
#define setjmp
Definition: setjmp.h:209
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
#define Trace(x)
Definition: inflate.c:42
__kernel_time_t time_t
Definition: linux.h:252
#define printf
Definition: freeldr.h:97
#define sleep
Definition: syshdrs.h:37
__u16 time
Definition: mkdosfs.c:8
void CloseHost(void)
Definition: main.c:153
FTPConnectionInfo gConn
Definition: main.c:37
int MakeArgv(char *line, int *cargc, const char **cargv, int cargcmax, char *dbuf, size_t dbufsize, int *noglobargv, int readlineHacks)
Definition: shell.c:221
int gEventNumber
Definition: shell.c:27
void BackToTop(int sigNum)
Definition: shell.c:452
int gCancelCtrl
Definition: shell.c:66
static int DoCommand(const ArgvInfoPtr aip)
Definition: shell.c:381
int sigsetjmp(sigjmp_buf buf, int savesigs)
void FTPShutdownHost(const FTPCIPtr cip)
Definition: open.c:564
#define NcSignal
Definition: ncftp.h:604
void AddHistory(char *line)
Definition: readln.c:699
char * Readline(char *prompt)
Definition: readln.c:671
void MakePrompt(char *dst, size_t dsize)
Definition: readln.c:802
#define memset(x, y, z)
Definition: compat.h:39
#define kBeepAfterCmdTime
Definition: shell.h:26
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
char host[64]
Definition: ncftp.h:136
BOOL WINAPI MessageBeep(_In_ UINT uType)
#define MB_OK
Definition: winuser.h:790

Referenced by main().

◆ GetCommandByIndex()

CommandPtr GetCommandByIndex ( const int  i)

Definition at line 140 of file shell.c.

141{
142 if ((i < 0) || (i >= (int) gNumCommands))
143 return (kNoCommand);
144 return (&gCommands[i]);
145} /* GetCommandByIndex */
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
size_t gNumCommands
Definition: cmdlist.c:525
Command gCommands[]
Definition: cmdlist.c:16
#define kNoCommand
Definition: shell.h:55

Referenced by CommandCompletionFunction().

◆ GetCommandByName()

CommandPtr GetCommandByName ( const char * const  name,
int  wantExactMatch 
)

Definition at line 156 of file shell.c.

157{
158 CommandPtr canp, canp2;
159
160 /* First check for an exact match. Otherwise if you if asked for
161 * 'cd', it would match both 'cd' and 'cdup' and return an
162 * ambiguous name error, despite having the exact name for 'cd.'
163 */
165
166 if (canp == kNoCommand && !wantExactMatch) {
167 /* Now see if the user typed an abbreviation unique enough
168 * to match only one name in the list.
169 */
171
172 if (canp != kNoCommand) {
173 /* Check the entry above us and see if the name we're looking
174 * for would match that, too.
175 */
176 if (canp != &gCommands[0]) {
177 canp2 = canp - 1;
178 if (CommandSubSearchCmp(name, canp2) == 0)
179 return kAmbiguousCommand;
180 }
181 /* Check the entry below us and see if the name we're looking
182 * for would match that one.
183 */
184 if (canp != &gCommands[gNumCommands - 1]) {
185 canp2 = canp + 1;
186 if (CommandSubSearchCmp(name, canp2) == 0)
187 return kAmbiguousCommand;
188 }
189 }
190 }
191 return canp;
192} /* GetCommandByName */
static int CommandExactSearchCmp(const char *const key, const CommandPtr b)
Definition: shell.c:102
static int CommandSubSearchCmp(const char *const key, const CommandPtr a)
Definition: shell.c:116
int(* bsearch_proc_t)(const void *, const void *)
Definition: util.h:9
#define kAmbiguousCommand
Definition: shell.h:54
struct Command * CommandPtr
Definition: shell.h:28
Definition: shell.h:41
Definition: name.c:39
#define bsearch

Referenced by CompletionFunction(), DoCommand(), and HelpCmd().

◆ InitCommandList()

void InitCommandList ( void  )

Definition at line 90 of file shell.c.

91{
93} /* InitCommandList */
static int CommandSortCmp(const CommandPtr a, const CommandPtr b)
Definition: shell.c:80
int(* qsort_proc_t)(const void *, const void *)
Definition: util.h:8
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))

Referenced by PreInit().

◆ MakeArgv()

int MakeArgv ( char line,
int cargc,
const char **  cargv,
int  cargcmax,
char dbuf,
size_t  dbufsize,
int noglobargv,
int  readlineHacks 
)

Definition at line 221 of file shell.c.

222{
223 int c;
224 int retval;
225 char *dlim;
226 char *dcp;
227 char *scp;
228 char *arg;
229
230 *cargc = 0;
231 scp = line;
232 dlim = dbuf + dbufsize - 1;
233 dcp = dbuf;
234
235 for (*cargc = 0; *cargc < cargcmax; ) {
236 /* Eat preceding junk. */
237 for ( ; ; scp++) {
238 c = *scp;
239 if (c == '\0')
240 goto done;
241 if (isspace(c))
242 continue;
243 if ((c == ';') || (c == '\n')) {
244 scp++;
245 goto done;
246 }
247 break;
248 }
249
250 arg = dcp;
251 cargv[*cargc] = arg;
252 noglobargv[*cargc] = 0;
253 (*cargc)++;
254
255 /* Special hack so that "!cmd" is always split into "!" "cmd" */
256 if ((*cargc == 1) && (*scp == '!')) {
257 if (scp[1] == '!') {
258 scp[1] = '\0';
259 } else if ((scp[1] != '\0') && (!isspace((int) scp[1]))) {
260 cargv[0] = "!";
261 scp++;
262 arg = dcp;
263 cargv[*cargc] = arg;
264 noglobargv[*cargc] = 0;
265 (*cargc)++;
266 }
267 }
268
269 /* Add characters to the new argument. */
270 for ( ; ; ) {
271 c = *scp;
272 if (c == '\0')
273 break;
274 if (isspace(c))
275 break;
276 if ((c == ';') || (c == '\n')) {
277 break;
278 }
279
280 scp++;
281
282 if (c == '\'') {
283 for ( ; ; ) {
284 c = *scp++;
285 if (c == '\0') {
286 if (readlineHacks != 0)
287 break;
288 /* Syntax error */
289 (void) fprintf(stderr, "Error: Unbalanced quotes.\n");
290 return (-1);
291 }
292 if (c == '\'')
293 break;
294
295 /* Add char. */
296 if (dcp >= dlim)
297 goto toolong;
298 *dcp++ = c;
299
300 if (strchr(kGlobChars, c) != NULL) {
301 /* User quoted glob characters,
302 * so mark this argument for
303 * noglob.
304 */
305 noglobargv[*cargc - 1] = 1;
306 }
307 }
308 } else if (c == '"') {
309 for ( ; ; ) {
310 c = *scp++;
311 if (c == '\0') {
312 if (readlineHacks != 0)
313 break;
314 /* Syntax error */
315 (void) fprintf(stderr, "Error: Unbalanced quotes.\n");
316 return (-1);
317 }
318 if (c == '"')
319 break;
320
321 /* Add char. */
322 if (dcp >= dlim)
323 goto toolong;
324 *dcp++ = c;
325
326 if (strchr(kGlobChars, c) != NULL) {
327 /* User quoted glob characters,
328 * so mark this argument for
329 * noglob.
330 */
331 noglobargv[*cargc - 1] = 1;
332 }
333 }
334 } else
335#if defined(WIN32) || defined(_WINDOWS)
336 if (c == '|') {
337#else
338 if (c == '\\') {
339#endif
340 /* Add next character, verbatim. */
341 c = *scp++;
342 if (c == '\0')
343 break;
344
345 /* Add char. */
346 if (dcp >= dlim)
347 goto toolong;
348 *dcp++ = c;
349 } else {
350 /* Add char. */
351 if (dcp >= dlim)
352 goto toolong;
353 *dcp++ = c;
354 }
355 }
356
357 *dcp++ = '\0';
358 }
359
360 (void) fprintf(stderr, "Error: Argument list too long.\n");
361 *cargc = 0;
362 cargv[*cargc] = NULL;
363 return (-1);
364
365done:
366 retval = (int) (scp - line);
367 cargv[*cargc] = NULL;
368 return (retval);
369
370toolong:
371 (void) fprintf(stderr, "Error: Line too long.\n");
372 *cargc = 0;
373 cargv[*cargc] = NULL;
374 return (-1);
375} /* MakeArgv */
#define isspace(c)
Definition: acclib.h:69
char * strchr(const char *String, int ch)
Definition: utclib.c:501
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
#define kGlobChars
Definition: ncftp.h:357
Definition: parser.c:49
void * arg
Definition: msvc.h:10

Referenced by CommandShell(), and CompletionFunction().

◆ PrintCmdHelp()

void PrintCmdHelp ( CommandPtr  c)

Definition at line 200 of file shell.c.

201{
202 (void) printf("%s: %s.\n", c->name, c->help);
203} /* PrintCmdHelp */

Referenced by HelpCmd().

◆ PrintCmdUsage()

void PrintCmdUsage ( CommandPtr  c)

Definition at line 210 of file shell.c.

211{
212 if (c->usage != NULL)
213 (void) printf("Usage: %s %s\n", c->name, c->usage);
214} /* PrintCmdUsage */

Referenced by ChdirCmd(), DeleteCmd(), DoCommand(), GetCmd(), HelpCmd(), ListCmd(), LocalListCmd(), LookupCmd(), MkdirCmd(), MlsCmd(), OpenCmd(), PutCmd(), RmdirCmd(), SpoolGetCmd(), and SpoolPutCmd().

◆ XferCanceller()

void XferCanceller ( int  sigNum)

Definition at line 419 of file shell.c.

420{
421 gGotSig = sigNum;
422 if (gConn.cancelXfer > 0) {
423#if defined(WIN32) || defined(_WINDOWS)
425#else
426 /* User already tried it once, they
427 * must think it's locked up.
428 *
429 * Jump back to the top, and
430 * close down the current session.
431 */
432 gCancelCtrl = 1;
433 if (gMayBackToTopJmp > 0) {
434#ifdef HAVE_SIGSETJMP
436#else /* HAVE_SIGSETJMP */
437 longjmp(gBackToTopJmp, 1);
438#endif /* HAVE_SIGSETJMP */
439 }
440#endif
441 }
443} /* XferCanceller */
#define SIG_DFL
Definition: signal.h:47
int signal
Definition: except.c:82

Referenced by GetCmd(), and PutCmd().