[go: up one dir, main page]

Menu

[2e205f]: / scripts / hlp.bat  Maximize  Restore  History

Download this file

376 lines (306 with data), 10.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
@ECHO Off
SETLOCAL EnableDelayedExpansion
:: Dos9 - A Free, Cross-platform command prompt - The Dos9 project
:: Copyright (C) 2010-2017 Romain GARBI
:: Copyright (C) 2016 Teddy Astie
::
:: This program is free software: you can redistribute it and/or modify
:: it under the terms of the GNU General Public License as published by
:: the Free Software Foundation, either version 3 of the License, or
:: (at your option) any later version.
::
:: This program is distributed in the hope that it will be useful,
:: but WITHOUT ANY WARRANTY; without even the implied warranty of
:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
:: GNU General Public License for more details.
::
:: You should have received a copy of the GNU General Public License
:: along with this program. If not, see <http://www.gnu.org/licenses/>.
set hlp_data_dir=%DOS9_SHARE%/dos9/hlp
set hlp_base_dir=%USERPROFILE%/.dos9/hlp
:: Cd to the appropriate directory
if not exist !hlp_base_dir! MKDIR !hlp_base_dir!
cd !hlp_base_dir!
if not exist hlp.conf.bat (
echo No hlp.conf.bat
call :config
)
call hlp.conf.bat
if /i "%~1" equ "/l" goto :list
if /i "%~1" equ "/b" goto :build
if /i "%~1" equ "/c" goto :config
if /i "%~1" neq "/?" goto :show
:: if nothing has been selected, goto show
ECHO Hlp 1.0 - Manual page viewier
ECHO Copyright ^(C^) 2013-2016 Romain Garbi ^(Darkbatcher^)
ECHO Copyright ^(C^) 2016 Teddy Astie ^(TSnake41^)
ECHO This program comes with ABSOLUTELY NO WARRANTY; This is free software,
ECHO and you are welcome to redistribute it under the terms of the GNU CPL.
ECHO.
ECHO Hlp [page-name ^| /b [language [charset]] ^| /c ^| /d]
ECHO.
ECHO - page-name : The page to be opened
ECHO.
ECHO - /b : build the manual pages using given charset and language:
ECHO.
ECHO - charset : The charset to be used to build the manual pages. If no
ECHO charset is given, then it will use the default charset ^(basically,
ECHO the utf-8 charset^). This require the ICONV command to support. Use
ECHO this parameter if your terminal does not support basic utf-8 encoding
ECHO ^(like windows^).
ECHO.
ECHO - language : The language to be used to build the manual page.
ECHO.
ECHO - /c : configures option for the manual page maker.
ECHO.
ECHO - /d : download the manual package from the repository at
ECHO ^<http://www.dos9.org^>. [not functional yet]
GOTO:EOF
:build
ECHO Hlp 1.0 - Manual page viewier Copyright ^(C^) 2013-2016 Romain Garbi ^(Darkbatcher^)
ECHO This program comes with ABSOLUTELY NO WARRANTY; This is free software,
ECHO and you are welcome to redistribute it under the terms of the GNU CPL.
ECHO.
ECHO first param "%~1"
shift /1
IF "%~1" equ "" (
SET lang_build=%locale%
) else (
SET lang_build=%~1
shift /1
)
IF "%~1" equ "" (
SET charset_build=%charset%
) else (
SET charset_build=%~1
)
ECHO *** Building manual pages for %lang_build% with charset %charset_build% ***
ECHO.
ECHO 1] Remove content of the documentation folder.
ECHO.
for %%A in (ansi html txt) do (
if exist %%A RMDIR /Q /S %%A
)
ECHO 2] Creating subdirectories.
ECHO.
:: create static directory
for %%A in (
ansi
html
txt
) do (
IF not exist %%A (
echo * Creating %%A
mkdir %%A
)
)
:: browse the directory and make subirectories that
:: are not existing.
FOR /F "tokens=*" %%A in ('cd %hlp_data_dir%/%lang_build%
dir /b /s /a:d') do (
ECHO * Creating %%A
SET path_ansi=ansi/%%A
SET path_html=html/%%A
SET path_txt=txt/%%A
IF not exist !path_ansi! mkdir !path_ansi!
IF not exist !path_html! mkdir !path_html!
IF not exist !path_txt! mkdir !path_txt!
)
ECHO.
ECHO. 3] Produce the output :
:: browse the directory and use tea to produce the output.
FOR /F "tokens=*" %%A in ('cd %hlp_data_dir%/%lang_build%
dir /b /s /a:-d') do (
:: unfortunately, we used %~dpnA before to get all the stuff
:: this is no longer possible since %~d gets absolute path ...
:: we need a little hack then
SET name=%%~A
SET ansi_build=ansi/!name:.tea=!.ansi
SET html_build=html/!name:.tea=!.html
SET txt_build=txt/!name:.tea=!.txt
ECHO [*] Building "!name:.tea=!" :
ECHO - file : !txt_build!
tea "%hlp_data_dir%/%lang_build%/%%A" !txt_build!.tmp /E:UTF-8 /O:TEXT-PLAIN
ECHO - file : !ansi_build!
tea "%hlp_data_dir%/%lang_build%/%%A" !ansi_build!.tmp /E:UTF-8 /O:TEXT-ANSI
ECHO - file : !html_build!
tea "%hlp_data_dir%/%lang_build%/%%A" !html_build! /E:UTF-8 /O:html /M "%hlp_data_dir%/meta" /H "%hlp_data_dir%/header" /F "%hlp_data_dir%/footer" /T "The Dos9 Project :: "
ECHO - converting output from UTF-8 to %charset_build%
:: just convert .ansi file, it is not needed for html document
:: which were generated using tea, that means to change encoding
:: and tag <meta charset="utf-8" />
if /i !charset_build! NEQ UTF-8 (
iconv -f UTF-8 -t %charset_build% !ansi_build!.tmp > !ansi_build!
iconv -f UTF-8 -t %charset_build% !txt_build!.tmp > !txt_build!
) else (
move !ansi_build!.tmp !ansi_build! > NUL
move !txt_build!.tmp !txt_build! > NUL
)
)
:: Now, create the hlpdb file
ECHO.
ECHO.4] Create title search system
FOR /F "tokens=*" %%A in ('dir /b /s /a:-D txt/*.txt') do (
SET /p title= < "%%A" > NUL
ECHO !title!%%A
) > hlpdb
ECHO.
ECHO.5] Cleanning temporary files
:: del /s /q ./*.tmp > NUL
GOTO:EOF
:show
if not exist hlpdb (
echo HLP : Unable to find any compiled manual page. Running "hlp /b"...
call :build
ECHO HLP : Built with success
)
if "%~1" equ "" (
if exist txt/commands.txt (
%view_cmd% %mode%/commands.%mode%
exit /b 0
) else (
echo Unable to find default manual page. Is the man page database really built ?
echo If not, try to compile it using the /b switch.
exit /b 1
)
)
SET i=0
FOR /F "tokens=1,* delims=" %%A IN ('type hlpdb | find /i /e "*%~1**" ') DO (
SET /a:I i+=1
SET tmp=%%B
SET HlpPath[!i!]=!tmp:txt=%mode%!
SET HlpPath[!i!].name=%%A
)
if %i%==1 (
%view_cmd% %HlpPath[1]%
EXIT
) else if %i%==0 (
ECHO Error: no manual page available for "%~1"
ECHO.
exit /b 1
) else (
ECHO Looking for manual page "%~1"
ECHO.
ECHO There are many pages that match the name you gave.
ECHO Choose the one you want to browse on the following menu:
ECHO.
FOR /L %%A in (1,1,%i%) do (
ECHO %%A. !HlpPath[%%A].name!
)
ECHO.
)
:retry
SET /P choice=Your choice (either 'q' to quit or a number to select the page^) :
if /i !choice! equ q GOTO:EOF
if not defined HlpPath[!choice!] goto :retry
%view_cmd% !HlpPath[%choice%]!
GOTO:EOF
:config
if exist hlp.conf.bat call hlp.conf.bat
ECHO Hlp - Manual page viewier
ECHO Copyright ^(C^) 2013-2016 Romain Garbi ^(Darkbatcher^)
ECHO Copyright ^(C^) 2016-2017 Teddy Astie ^(TSnake41^)
ECHO This program comes with ABSOLUTELY NO WARRANTY; This is free software,
ECHO and you are welcome to redistribute it under the terms of the GNU CPL.
ECHO.
ECHO Setting Hlp Options :
ECHO.
ECHO. 1] Setting mode :
ECHO.
ECHO The mode option determines the file type that will be displayed by Hlp.
ECHO There is three different values possible : ansi, txt and html.
ECHO.
ECHO * html mode permits to browse allmost all document through the use of html
ECHO files and a browser. This mode is pretty convenient, altough it requieres a
ECHO functional web browser.
ECHO.
ECHO * ansi mode allows little less interaction. It consists of text files that are
ECHO formatted to be coloured when using a ANSI terminal. In this mode, you can't
ECHO easily surf through links
ECHO.
ECHO * txt mode consists of pure text files. It consists of text files, with little
ECHO or no formatting. The text files generated are designed to be read on a
ECHO terminal. You may choose this options if you have neither any functional web
ECHO browser nor any ANSI-compatible terminal.
ECHO.
:mode_retry
set /p conf_mode=Please choose a mode (html/ansi/txt) :
if not defined conf_mode (
set conf_mode=html
) else if [ !conf_mode! neq html and !conf_mode! neq ansi and !conf_mode! neq txt ] goto :mode_retry
ECHO.
ECHO 2] Choosing locale :
ECHO.
ECHO The locale option determines the language you want to use for manual pages.
ECHO The following list of locales is available :
ECHO.
cd %hlp_data_dir%
dir /b /A:D
cd %hlp_base_dir%
ECHO.
:locale_retry
set /p conf_locale=Please choose a locale :
if not defined conf_locale (
if defined LANGUAGE (
set conf_locale=!LANGUAGE!
) else (
set conf_locale=en_US
)
)
if not exist !hlp_data_dir!/!conf_locale! goto :locale_retry
ECHO. 3] Chose charset :
ECHO.
ECHO The charset is used to determine how to print language-specific characters
ECHO on your terminal device.
ECHO.
ECHO By default, we recommend to use the UTF-8 encoding. However, if your
ECHO terminal does not support UTF-8 natively, you can set the charset to the
ECHO encoding your terminal supports.
ECHO.
ECHO This option does not affect manual pages viewed in HTML format, since any
ECHO decent browser supports UTF-8 nowadays
ECHO.
set /p conf_charset=Please choose a charset : [default UTF-8] :
if not defined conf_charset (
set conf_charset=UTF-8
)
ECHO.
ECHO 4] Config file generation.
ECHO.
ECHO You entered the following configuration :
ECHO.
ECHO * mode : %conf_mode%
ECHO * locale : %conf_locale%
ECHO * charset : %conf_charset%
ECHO.
ECHO If you are using a UNIX-based system that does not include the xdg-open
ECHO program, You will probably need to edit the configuration file hlp.conf.bat
ECHO to set the correct path to program to be used when opening html files.
:Ok_retry
set /p Ok=Do you really want to continue and save configuration (y/N) :
if /i [ not defined Ok or !Ok! equ N ] (
GOTO :show_quit
) else if /i !Ok! neq Y (
GOTO :Ok_retry
)
(ECHO :: Hlp Configuration file
ECHO set mode=%conf_mode%
ECHO :: The mode to use
ECHO set view_cmd=%conf_prg%
ECHO :: The command to view the stream
ECHO set locale=%conf_locale%
ECHO :: The locale to use when compiling
ECHO set charset=%conf_charset%
ECHO :: The charset to use when compiling
ECHO set html_prg=start
ECHO set txt_prg=more
ECHO set ansi_prg=more
ECHO set view_cmd=!!%%mode%%_prg!!) > hlp.conf.bat
ECHO 5] Deleting outdated files :
:: If we either change locale or encoding, we must regen files
IF [ !conf_locale! neq !locale! or !conf_charset! neq !charset! ] (
if exist hlpdb del hlpdb
)
ECHO.
ECHO *** Configuration file successfully generated. ***
:show_quit