home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-08-28 | 2.7 KB | 124 lines | [TEXT/PJMM] |
- unit aCommand;
-
- { ================================================== }
-
- { date.p - an examle of a simple nShell (tm) command. }
-
- { Copyright ( c ) 1994 Newport Software Development }
-
- { You may distribute unmodified copies of this file for noncommercial }
- { purposes . You may use this file as a reference when writing your }
- { own nShell ( tm ) commands . }
-
- { All other rights are reserved . }
-
- { ================================================== }
-
- interface
-
- { The NSHC unit defines the interfaces nshell to callbacks. See "nshc.p" }
-
- uses
- NSHC;
-
- { The routine "theCommand" is called by the nShell.lib to to the work of the command. }
-
- procedure theCommand (nshc_parms: t_nshc_parms; nshc_calls: t_nshc_calls);
-
- { ================================================== }
-
- implementation
-
- { ================================================== }
-
- { utility commands }
-
- function got_option (nshc_parms: t_nshc_parms; option: char): boolean;
- var
- found: boolean;
- arg, argc: integer;
- i: integer;
- c: char;
- begin
- found := false;
-
- arg := 1;
- argc := nshc_parms^.argc;
-
- while not found and (arg < argc) do
- begin
- i := nshc_parms^.argv[arg];
- c := nshc_parms^.arg_buf[i];
- if c = '-' then
- while (c <> chr(0)) and not found do
- begin
- i := succ(i);
- c := nshc_parms^.arg_buf[i];
- found := c = option;
- end;
- arg := succ(arg);
- end;
-
- got_option := found;
-
- end;
-
- { ================================================== }
-
- { display the date in the specified format }
-
- procedure DoDate (nshc_parms: t_nshc_parms; nshc_calls: t_nshc_calls);
- var
- seconds: Boolean;
- secs: LONGINT;
- s: Str255;
- date_fmt: DateForm;
- i: integer;
- begin
- if (got_option(nshc_parms, 's')) then
- date_fmt := shortDate
- else if (got_option(nshc_parms, 'a')) then
- date_fmt := abbrevDate
- else
- date_fmt := longDate;
-
- GetDateTime(secs);
- IUDateString(secs, date_fmt, s);
- NSH_putStr(nshc_calls, s);
-
- if (not got_option(nshc_parms, 'd')) then
- begin
- NSH_putchar(nshc_calls, ' ');
- seconds := not got_option(nshc_parms, 'm');
- IUTimeString(secs, seconds, s);
- NSH_putStr(nshc_calls, s);
- end;
-
- NSH_putchar(nshc_calls, RETURN_CHAR);
- end;
-
- { ================================================== }
-
- { pascal 'main' for commands }
-
- procedure theCommand (nshc_parms: t_nshc_parms; nshc_calls: t_nshc_calls);
- var
- s: Str255;
- begin
-
- nshc_parms^.action := nsh_idle;
- nshc_parms^.result := 0;
-
- if nshc_parms^.version <> nshc_version then
- begin
- s := 'This command is not of a compatible version.';
- NSH_putStr_err(nshc_calls, s);
- NSH_putchar_err(nshc_calls, RETURN_CHAR);
- nshc_parms^.result := NSHC_ERR_VERSION;
- end
- else
- DoDate(nshc_parms, nshc_calls);
-
- end;
-
- end.