Source code of file mvdocrun.dpr
from the Sleep Dummy Shell.

1   program mvdocrun;
2   
3   {$APPTYPE CONSOLE}
4   
5   uses
6     SysUtils,
7     StrUtils,
8     ShellAPI,
9     Windows;
10  
11  CONST
12    mvdrC_maxfiles = 10;
13    mvdrC_maxfilesstr = '10';
14    mvdrC_Valid_IntChars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'];
15    mvdrC_swname = 'MV Document Run (MVDOCRUN)';
16    mvdrC_swshortname = 'mvdocrun';
17    mvdrC_version = 'version 1.0.0';
18    mvdrC_author = 'Mario A. Valdez-Ramirez (mario@mariovaldez.org)';
19    mvdrC_CRdata = 'Copyright 2005-2006 by';
20    mvdrC_license = 'This program is free software; you can redistribute it and/or modify'#13#10
21      + 'it under the terms of the GNU General Public License as published by'#13#10
22      + 'the Free Software Foundation; either version 2 of the License, or (at'#13#10
23      + 'your option) any later version.'#13#10#13#10
24      + 'This program is distributed in the hope that it will be useful, but'#13#10
25      + 'WITHOUT ANY WARRANTY; without even the implied warranty of'#13#10
26      + 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU'#13#10
27      + 'General Public License for more details.'#13#10#13#10
28      + 'You should have received a copy of the GNU General Public License'#13#10
29      + 'along with this program; if not, write to the Free Software'#13#10
30      + 'Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307'#13#10
31      + 'USA'#13#10;
32    mvdrC_usage = mvdrC_swshortname + ' loads one or more documents or executables.'#13#10
33      + 'Usage: ' + mvdrC_swshortname + ' [-v] [-l] [-q] [-a] [-dnn] file [file...]'#13#10
34      + '"file" is the program(s) you want to run or the document(s) you want'#13#10
35      + '       to open. You can specify up to ' + mvdrC_maxfilesstr + ' files.'#13#10
36      + ' -l    display the license of ' + mvdrC_swshortname + ' and exit.'#13#10
37      + ' -v    be verbose (default: no details).'#13#10
38      + ' -q    be quiet (default: print summary).'#13#10
39      + ' -a    invoke all files (default: invoke only one file).'#13#10
40      + ' -dnn  wait "nn" number of seconds before starting.'#13#10#13#10
41      + 'The exit code is equal to the number of successfully invoked files.'#13#10;
42    mvdrC_separator = '=========================================================';
43  
44  VAR
45    mvdr_filename_list, mvdr_dirname_list : ARRAY [1..mvdrC_maxfiles] OF STRING;
46    mvdr_exec_exitcode : LONGINT;                 { Exit code of invoked file }
47    mvdr_file_count, mvdr_param_count : LONGINT;  { General counters }
48    mvdr_param_str : STRING;                      { Parameter buffer }
49    mvdr_total_proc : LONGINT;                    { Total files to invoke }
50    mvdr_total_good : LONGINT;                    { Count of total files successfully invoked }
51    mvdr_beverbose : BOOLEAN;                     { To be verbose or not }
52    mvdr_bequiet : BOOLEAN;                       { To be quiet or not }
53    mvdr_runall : BOOLEAN;                        { To run all files or not }
54    mvdr_waittime : LONGINT;                      { Number of seconds to wait before starting }
55  
56  
57  {$R *.res}
58  
59  
60  
61  {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
62  {%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%}
63  FUNCTION FNmvdr_StrToInt (SourceValue : STRING) : LONGINT;
64  VAR
65    CurrChar : WORD;
66    TargetStr : STRING;
67    TargetInt : LONGINT;
68  BEGIN
69    TargetStr := '';
70    SourceValue := TRIM (SourceValue);
71    FOR CurrChar := 1 TO LENGTH (SourceValue) DO
72      IF (SourceValue[CurrChar] IN mvdrC_Valid_IntChars) THEN TargetStr := TargetStr + SourceValue[CurrChar] ELSE BREAK;
73    TRY
74      TargetInt := STRTOINT (TargetStr);
75    EXCEPT
76      TargetInt := 0;
77    END;
78    FNmvdr_StrToInt := TargetInt;
79  END;
80  
81  
82  
83  BEGIN
84    { If no parameters are found, display help text. }
85    IF (ParamCount = 0) THEN
86      BEGIN
87        WRITELN (mvdrC_separator);
88        WRITELN (mvdrC_swname + ' ' + mvdrC_version);
89        WRITELN (mvdrC_CRdata + ' ' + mvdrC_author);
90        WRITELN (mvdrC_separator);
91        WRITELN (mvdrC_usage);
92        WRITELN ('Press <ENTER> key to exit...');
93        READLN;
94        ExitCode := 0;
95        EXIT;
96      END;
97    { Look for known switches: help, license, verbose, quiet, run-all. }
98    mvdr_beverbose := FALSE;
99    mvdr_bequiet := FALSE;
100   mvdr_runall := FALSE;
101   mvdr_waittime := 0;
102   FOR mvdr_file_count := 1 TO ParamCount DO
103     BEGIN
104       mvdr_param_str := UPPERCASE (TRIM (ParamStr (mvdr_file_count)));
105       { Display help text. }
106       IF ((mvdr_param_str = '-H') OR (mvdr_param_str = '/H') OR (mvdr_param_str = '/?')) THEN
107         BEGIN
108           WRITELN (mvdrC_separator);
109           WRITELN (mvdrC_swname + ' ' + mvdrC_version);
110           WRITELN (mvdrC_CRdata + ' ' + mvdrC_author);
111           WRITELN (mvdrC_separator);
112           WRITELN (mvdrC_usage);
113           ExitCode := 0;
114           EXIT;
115         END
116       { Display license text. }
117       ELSE IF ((mvdr_param_str = '-L') OR (mvdr_param_str = '/L')) THEN
118         BEGIN
119           WRITELN (mvdrC_separator);
120           WRITELN (mvdrC_swname + ' ' + mvdrC_version);
121           WRITELN (mvdrC_CRdata + ' ' + mvdrC_author);
122           WRITELN (mvdrC_separator);
123           WRITELN (mvdrC_license);
124           ExitCode := 0;
125           EXIT;
126         END
127       { Enable verbose mode. }
128       ELSE IF ((mvdr_param_str = '-V') OR (mvdr_param_str = '/V')) THEN
129         BEGIN
130           mvdr_beverbose := TRUE;
131           mvdr_bequiet := FALSE;
132         END
133       { Enabled quiet mode. }
134       ELSE IF ((mvdr_param_str = '-Q') OR (mvdr_param_str = '/Q')) THEN
135         BEGIN
136           mvdr_beverbose := FALSE;
137           mvdr_bequiet := TRUE;
138         END
139       { Enabled run-all mode. }
140       ELSE IF ((mvdr_param_str = '-A') OR (mvdr_param_str = '/A')) THEN
141         BEGIN
142           mvdr_runall := TRUE;
143         END
144       { Enabled run-all mode. }
145       ELSE IF ((LEFTSTR (mvdr_param_str, 2) = '-D') OR (LEFTSTR (mvdr_param_str, 2) = '/D')) THEN
146         BEGIN
147           mvdr_waittime := FNmvdr_StrToInt (COPY (mvdr_param_str, 3, 3));
148         END;
149     END;
150   { Load and normalize all filenames and directories. }
151   mvdr_file_count := 0;
152   FOR mvdr_param_count := 1 TO ParamCount DO
153     BEGIN
154       mvdr_param_str := TRIM (ParamStr (mvdr_param_count));
155       IF ((mvdr_param_str[1] <> '-') AND (mvdr_param_str[1] <> '/') AND (mvdr_file_count < mvdrC_maxfiles)) THEN
156         BEGIN
157           INC (mvdr_file_count);
158           mvdr_filename_list[mvdr_file_count] := ExpandFileName (mvdr_param_str);
159           mvdr_dirname_list[mvdr_file_count] := ExtractFilePath (mvdr_filename_list[mvdr_file_count]);
160         END;
161     END;
162   { Invoke each loaded filename. If verbose mode enabled, display the details. }
163   { If run-all mode enabled, try all files, if not, try until one is successful. }
164   mvdr_total_proc := mvdr_file_count;
165   mvdr_total_good := 0;
166   IF (mvdr_beverbose = TRUE) THEN WRITELN (mvdrC_separator);
167   IF (mvdr_waittime > 0) THEN
168     BEGIN
169       IF (mvdr_bequiet = FALSE) THEN WRITELN ('Waiting ' + INTTOSTR (mvdr_waittime) + ' seconds.');
170       SLEEP (mvdr_waittime * 1000);
171     END;
172   FOR mvdr_file_count := 1 TO mvdr_total_proc DO
173     BEGIN
174       IF (mvdr_filename_list[mvdr_file_count] <> '') THEN
175         BEGIN
176           IF (mvdr_beverbose = TRUE) THEN
177             BEGIN
178               WRITELN ('File: ' + mvdr_filename_list[mvdr_file_count]);
179               WRITELN ('Dir: ' + mvdr_dirname_list[mvdr_file_count]);
180             END;
181           mvdr_exec_exitcode := ShellExecute (0, NIL, PCHAR (mvdr_filename_list[mvdr_file_count]), NIL, PCHAR (mvdr_dirname_list[mvdr_file_count]), SW_SHOWNORMAL);
182           IF (mvdr_exec_exitcode < 32) THEN
183             BEGIN
184               IF (mvdr_beverbose = TRUE) THEN WRITELN ('Error! (Code = ' + INTTOSTR (mvdr_exec_exitcode) + ').'#13#10);
185             END
186           ELSE
187             BEGIN
188               IF (mvdr_beverbose = TRUE) THEN WRITELN ('Success! (Code = ' + INTTOSTR (mvdr_exec_exitcode) + ').'#13#10);
189               INC (mvdr_total_good);
190               IF (mvdr_runall = FALSE) THEN BREAK;
191             END;
192         END;
193     END;
194   { Display summary if quiet mode is disabled. }
195   IF (mvdr_bequiet = FALSE) THEN
196     BEGIN
197       WRITELN (mvdrC_separator);
198       WRITELN ('Total processed = ' + INTTOSTR (mvdr_total_proc) + '.');
199       WRITELN ('Total executed = ' + INTTOSTR (mvdr_total_good) + '.');
200     END;
201   { Set exit code to the total files successfully invoked. }
202   ExitCode := mvdr_total_good;
203   EXIT;
204 END.
205 
206 
207 
 
 
NA fum/lmd: 2006.01.16
Copyright ©1994-2017 by Mario A. Valdez-Ramírez.
no siga este enlace / do not follow this link