-
Notifications
You must be signed in to change notification settings - Fork 0
/
pub.cmd
2212 lines (2068 loc) · 68.2 KB
/
pub.cmd
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
@echo off
:: Title: pub.cmd
:: Title Description: VimodPub batch file with menus and tasklist processing
:: Author: Ian McQuay
:: Created: 2012-03
:: Last Modified: 2016-06-10
:: Source: projects.palaso.org
:: Optional command line parameter:
:: projectpath - absolute or relative path.
:main
:: Description: Starting point of pub.cmd
:: Class: command - internal - startup
:: Optional parameters:
:: projectpath or debugfunc - project path must contain a sub folder setup containing a project.menu or dubugfunc must be "debug"
:: functiontodebug
:: * - more debug parameters
:: Required functions:
:: funcdebugstart
:: funcdebugend
:: choosegroup
rem set the codepage to unicode to handle special characters in parameters
set debugstack=00
if "%PUBLIC%" == "C:\Users\Public" (
rem if "%PUBLIC%" == "C:\Users\Public" above is to prevent the following command running on Windows XP
if not defined skipsettings chcp 65001
)
echo.
if not defined skipsettings echo Vimod-Pub
if not defined skipsettings echo Various inputs multiple outputs digital publishing
if not defined skipsettings echo http://projects.palaso.org/projects/vimod-pub
echo ----------------------------------------------------
if defined echofromstart echo on
set overridetype=%1
set projectpath=%2
set debugfunc=%2
set functiontodebug=%2
set inputtasklist=%3
set params=%3 %4 %5 %6 %7 %8 %9
if defined projectpath set drive=%~d2
if not defined projectpath set drive=c:
if "%overridetype%" == "tasklist" (
rem @echo on
set count=0
if defined projectpath %drive%
cd %~p0
call :setup
set setuppath=%projectpath%\setup
call :tasklist %inputtasklist%
echo Finished running %inputtasklist%
)
call :setup
if not defined overridetype (
rem default option with base menu
rem call :choosegroup
call :menu data\%projectsetupfolder%\project.menu "Choose Group?"
) else if "%overridetype%" == "menu" (
rem this option when a valid menu is chosen
if exist "%projectpath%\%projectsetupfolder%\project.menu" (
call :menu "%projectpath%\%projectsetupfolder%\project.menu" "Choose project action?"
) else (
rem debugging option
echo on
@echo debugging %functiontodebug%
call :%functiontodebug% %params%
)
)
goto :eof
rem Menuing and control functions ==============================================
:menu
:: Description: starts a menu
:: Revised: 2016-05-04
:: Class: command - menu
:: Required parameters:
:: newmenulist
:: title
:: forceprojectpath
:: Required functions:
:: funcdebugstart
:: variableslist
:: checkifvimodfolder
:: menuwriteoption
set debugstack=0
if defined masterdebug call :funcdebug %0
set newmenulist=%~1
set title=%~2
set errorlevel=
set forceprojectpath=%~3
set skiplines=%~4
set defaultprojectpath=%~dp1
set defaultjustprojectpath=%~p1
set prevprojectpath=%projectpath%
set prevmenu=%menulist%
set letters=%lettersmaster%
set tasklistnumb=
set count=0
set varvalue=
if defined echomenuparams echo menu params=%~0 "%~1" "%~2" "%~3" "%~4"
::call :ext %newmenulist%
rem detect if projectpath should be forced or not
if defined forceprojectpath (
if defined echoforceprojectpath echo forceprojectpath=%forceprojectpath%
set setuppath=%forceprojectpath%\%projectsetupfolder%
set projectpath=%forceprojectpath%
if exist "setup-pub\%newmenulist%" (
set menulist=setup-pub\%newmenulist%
set menutype=settings
) else (
set menulist=%commonmenufolder%\%newmenulist%
set menutype=commonmenutype
)
) else (
if defined echoforceprojectpath echo forceprojectpath=%forceprojectpath%
set projectpathbackslash=%defaultprojectpath:~0,-6%
set projectpath=%defaultprojectpath:~0,-7%
if defined userelativeprojectpath call :removeCommonAtStart projectpath "%projectpathbackslash%"
set setuppath=%defaultprojectpath:~0,-1%
rem echo off
if exist "%newmenulist%" (
set menulist=%newmenulist%
set menutype=projectmenu
) else (
set menutype=createdynamicmenu
set menulist=created
)
)
if defined breakpointmenu1 pause
if defined echomenulist echo menulist=%menulist%
if defined echomenutype echo menutype=%menutype%
if defined echoprojectpath echo %projectpath%
rem ==== start menu layout =====
set title= %~2
set menuoptions=
echo.
echo %title%
if defined echomenufile echo menu=%~1
if defined echomenufile echo menu=%~1
echo.
rem process the menu types to generate the menu items.
if "%menutype%" == "projectmenu" FOR /F "eol=# tokens=1,2 delims=;" %%i in (%menulist%) do set action=%%j&call :menuwriteoption "%%i" %%j
if "%menutype%" == "commonmenutype" FOR /F "eol=# tokens=1,2 delims=;" %%i in (%menulist%) do set action=%%j&call :menuwriteoption "%%i" %%j
if "%menutype%" == "settings" call :writeuifeedback "%menulist%" %skiplines%
if "%menutype%" == "createdynamicmenu" for /F "eol=# delims=" %%i in ('dir "%projectpath%" /b/ad') do (
set action=menu "%projectpath%\%%i\%projectsetupfolder%\project.menu" "%%i project"
call :checkifvimodfolder %%i
if not defined skipwriting call :menuwriteoption %%i
)
if "%menulist%" neq "utilities.menu" (
if defined echoutilities echo.
if defined echoutilities echo %utilityletter%. Utilities
)
echo.
if defined breakpointmenu2 pause
if "%newmenulist%" == "data\%projectsetupfolder%\project.menu" (
echo %exitletter%. Exit batch menu
) else (
if "%newmenulist%" == "%commonmenufolder%\utilities.menu" (
echo %exitletter%. Return to Groups menu
) else (
echo %exitletter%. Return to calling menu
)
)
echo.
:: SET /P prompts for input and sets the variable to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
IF /I '%Choice%' == '%utilityletter%' call :menu utilities.menu "Utilities Menu" "%projectpath%"
IF /I '%Choice%'=='%exitletter%' (
if "%menulist%" == "%commonmenufolder%\utilities.menu" (
set skipsettings=on
pub
) else (
echo ...exit menu &exit /b
)
)
:: Loop to evaluate the input and start the correct process.
:: the following line processes the choice
if defined breakpointmenu3 pause
FOR /D %%c IN (%menuoptions%) DO call :menueval %%c
if defined masterdebug call :funcdebug %0 end
goto :menu
:menuwriteoption
:: Description: writes menu option to screen
:: Class: command - internal - menu
:: Required preset variable: 1
:: letters
:: action
:: Required parameters: 1
:: menuitem
:: checkfunc
:: submenu
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set menuitem=%~1
set checkfunc=%~2
set submenu=%~3
rem check for common menu
if /%checkfunc%/ == /commonmenu/ (
call :%action%
exit /b
) else if /%checkfunc%/ == /menublank/ (
rem check for menublank
call :%action%
exit /b
)
rem write the menu item
set let=%letters:~0,1%
if "%let%" == "%stopmenubefore%" goto :eof
echo %let%. %menuitem%
set letters=%letters:~1%
rem set the option letter
set option%let%=%action%
rem make the letter list
set menuoptions=%let% %menuoptions%
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:commonmenu
:: Description: Will write menu lines from a menu file in the %commonmenufolder% folder
:: Class: command - menu
:: Used by: menu
:: Required parameters:
:: commonmenu
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set commonmenu=%~1
FOR /F "eol=# tokens=1,2 delims=;" %%i in (%commonmenufolder%\%commonmenu%) do set action=%%j&call :menuwriteoption "%%i" %%j
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:menuvaluechooser
:: Description: Will write menu lines from a menu file in the commonmenu folder
:: Class: command - internal - menu
:: Used by: menu
:: Required parameters:
:: commonmenu
rem echo on
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set list=%~1
set menuoptions=
set option=
set letters=%lettersmaster%
echo.
echo %title%
echo.
FOR /F %%i in (%commonmenupath%\%list%) do call :menuvaluechooseroptions %%i
echo.
:: SET /P prompts for input and sets the variable to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
:: Loop to evaluate the input and start the correct process.
:: the following line processes the choice
rem echo on
FOR /D %%c IN (%menuoptions%) DO call :menuvaluechooserevaluation %%c
echo off
echo outside loop
rem call :menuevaluation %%c
echo %valuechosen%
pause
if "%varvalue%" == "set" exit /b
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:menuvaluechooseroptions
:: Description: Processes the choices
:: Class: command - internal - menu
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set menuitem=%~1
set let=%letters:~0,1%
set value%let%=%~1
if "%let%" == "%stopmenubefore%" goto :eof
echo %let%. %menuitem%
set letters=%letters:~1%
rem set the option letter
rem make the letter list
set menuoptions=%menuoptions% %let%
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:menuvaluechooserevaluation
:: Class: command - internal - menu
rem echo on
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
if defined varvalue goto :eof
set let=%~1
IF /I '%Choice%'=='a' set valuechosen=%valuea%& set varvalue=set& exit /b
IF /I '%Choice%'=='b' set valuechosen=%valueb%& set varvalue=set& exit /b
IF /I '%Choice%'=='c' set valuechosen=%valuec%& set varvalue=set& exit /b
IF /I '%Choice%'=='d' set valuechosen=%valued%& set varvalue=set& exit /b
IF /I '%Choice%'=='e' set valuechosen=%valuee%& set varvalue=set& exit /b
IF /I '%Choice%'=='f' set valuechosen=%valuef%& set varvalue=set& exit /b
IF /I '%Choice%'=='g' set valuechosen=%valueg%& set varvalue=set& exit /b
IF /I '%Choice%'=='h' set valuechosen=%valueh%& set varvalue=set& exit /b
IF /I '%Choice%'=='i' set valuechosen=%valuei%& set varvalue=set& exit /b
IF /I '%Choice%'=='j' set valuechosen=%valuej%& set varvalue=set& exit /b
IF /I '%Choice%'=='k' set valuechosen=%valuek%& set varvalue=set& exit /b
IF /I '%Choice%'=='l' set valuechosen=%valuel%& set varvalue=set& exit /b
IF /I '%Choice%'=='m' set valuechosen=%valuem%& set varvalue=set& exit /b
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:menueval
:: Description: resolves the users entered letter and starts the appropriate function
:: run through the choices to find a match then calls the selected option
:: Required preset variable: 1
:: choice
:: Required parameters: 1
:: let
if defined masterdebug call :funcdebug %0
if defined varvalue exit /b
set let=%~1
set option=option%let%
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='%let%' call :%%%option%%%
if defined masterdebug call :funcdebug %0 end
goto :eof
rem inc is included so that an xslt transformation can also process this tasklist. Not all tasklists may need processing into params.
:inc
:tasklist
:: Discription: Processes a tasks file.
:: Required preset variables: 3
:: projectlog
:: setuppath
:: commontaskspath
:: Required parameters: 1
:: tasklistname
:: Func calls:
:: funcdebugstart
:: funcdebugend
:: nameext
:: * - tasks from tasks file
if defined breaktasklist1 echo on
if defined masterdebug call :funcdebug %0
set tasklistname=%~1
set /A tasklistnumb=%tasklistnumb%+1
if "%tasklistnumb%" == "1" set errorsuspendprocessing=
if defined breaktasklist1 pause
call :checkdir "%projectpath%\xml"
call :checkdir "%projectpath%\logs"
set projectlog="%projectpath%\logs\%curdate%-build.log"
set projectbat="%projectpath%\logs\%curdate%-build.bat"
:: checks if the list is in the commontaskspath, setuppath (default), if not then tries what is there.
if exist "%setuppath%\%tasklistname%" (
set tasklist=%setuppath%\%tasklistname%
if defined echotasklist call :echolog "[---- tasklist%tasklistnumb% project %tasklistname% ---- %time% ---- "
if defined echotasklist echo.
) else (
if exist "%commontaskspath%\%tasklistname%" (
set tasklist=%commontaskspath%\%tasklistname%
if defined echotasklist call :echolog "[---- tasklist%tasklistnumb% common %tasklistname% ---- %time% ----"
if defined echotasklist echo.
) else (
echo tasklist "%tasklistname%" not found
pause
exit /b
)
)
if exist "%setuppath%\project.variables" (
call :variableslist "%setuppath%\project.variables"
)
if defined breaktasklist2 pause
FOR /F "eol=# tokens=2 delims=;" %%i in (%tasklist%) do call :%%i %errorsuspendprocessing%
if defined breaktasklist3 pause
if defined echotasklistend call :echolog " ------------------- tasklist%tasklistnumb% ended. %time%]"
@if defined masterdebug call :funcdebug %0 end
set /A tasklistnumb=%tasklistnumb%-1
goto :eof
:setup
:: Description: sets variables for the batch file
:: Revised: 2016-05-04
:: Required rerequisite variables
:: projectpath
:: htmlpath
:: localvar
:: Func calls: 1
:: checkdir
set beginfuncstring=++ masterdebug is on ++++++++++++ starting func
set beginfuncstringtail=++++++++++++++
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set basepath=%cd%
set endfuncstring=-------------------------------------- end func
rem check if logs directory exist and create if not there DO NOT change to checkdir
if not exist "%cd%\logs" md "%cd%\logs"
rem Get the date format from the Registery: 0=US 1=AU 2=iso
set KEY_DATE="HKCU\Control Panel\International"
FOR /F "usebackq skip=2 tokens=3" %%A IN (`REG QUERY %KEY_DATE% /v iDate`) DO set dateformat=%%A
rem get the date separator: / or -
FOR /F "usebackq skip=2 tokens=3" %%A IN (`REG QUERY %KEY_DATE% /v sDate`) DO set dateseparator=%%A
rem get the time separator: : or ?
FOR /F "usebackq skip=2 tokens=3" %%A IN (`REG QUERY %KEY_DATE% /v sTime`) DO set timeseparator=%%A
rem set project log file name by date
call :date
set projectlog=logs\%curdate%-build.log
rem set the predefined variables
call :variableslist setup-pub\vimod.variables
rem selfvalue is set so the list of path installed tools will become: set ccw32=ccw32. They are used this way so that if an absolute path is needed it can be set in user_installed.tools
rem the following line is removed as path tools moved back into user_installed.tools
rem set selfvalue=on
rem remove this for now
rem if exist setup-pub\user_path_installed.tools call :variableslist setup-pub\user_path_installed.tools
rem test if essentials exist
call :variableslist setup-pub\essential_installed.tools fatal
rem added to aid new users in setting up
if exist setup-pub\user_installed.tools call :variableslist setup-pub\user_installed.tools
if exist setup-pub\user_feedback.settings if not defined skipsettings call :variableslist setup-pub\user_feedback.settings
if exist setup-pub\functiondebug.settings if not defined skipsettings call :variableslist setup-pub\functiondebug.settings
rem if not defined java call :testjava
set classpath=%classpath%;%extendclasspath%
call :checkdir %cd%\data\logs
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:checkdir
:: Description: checks if dir exists if not it is created
:: See also: ifnotexist
:: Required preset variabes: 1
:: projectlog
:: Optional preset variables:
:: echodirnotfound
:: Required parameters: 1
:: dir
:: Required functions:
:: funcdebugstart
:: funcdebugend
if defined masterdebug call :funcdebug %0
set dir=%~1
if not defined dir echo missing required directory parameter & goto :eof
set report=Checking dir %dir%
if exist "%dir%" (
echo . . . Found! %dir% >>%projectlog%
) else (
call :removecommonatstart dirout "%dir%"
if defined echodirnotfound echo Creating . . . %dirout%
echo . . . not found. %dir% >>%projectlog%
echo mkdir %dir% >>%projectlog%
mkdir "%dir%"
)
if defined masterdebug call :funcdebug %0 end
goto :eof
:validatevar
:: validate variables passed in
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set testvar=%~1
if not defined %testvar:"=% (
echo No %~1 var found defined
echo Please add this to the setup-pub\user_installed.tools
echo The program will exit after this pause.
pause
exit /b
)
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
rem built in commandline functions =============================================
:command
:: Description: A way of passing any commnand from a tasklist. It does not use infile and outfile.
:: Usage: call :usercommand "copy /y 'c:\patha\file.txt' 'c:\pathb\file.txt'" ["path to run command in" "output file to test for"]
:: Limitations: When command line needs single quote.
:: Required parameters:
:: curcommand
:: Optional parameters:
:: commandpath
:: testoutfile
:: Required functions:
:: funcdebugstart
:: funcdebugend
:: inccount
:: echolog
if defined errorsuspendprocessing goto :eof
if defined masterdebug call :funcdebug %0
call :inccount
set curcommand=%~1
if not defined curcommand echo missing curcommand & goto :eof
set commandpath=%~2
set testoutfile=%~3
if defined testoutfile set outfile=%testoutfile%
set curcommand=%curcommand:'="%
echo %curcommand%>>%projectlog%
set drive=%~d2
if not defined drive set drive=c:
if defined testoutfile (
rem the next line 'if "%commandpath%" neq "" %drive%'' must be set with a value even if it is not used or cmd fails. Hence the two lines before this if statement
if "%commandpath%" neq "" %drive%
if defined commandpath cd "%commandpath%"
call :before
call %curcommand%
call :after
if defined commandpath cd "%basepath%"
) else (
if defined echousercommand echo %curcommand%
%curcommand%
)
if defined masterdebug call :funcdebug %0 end
goto :eof
:spaceremove
set string=%~1
set spaceremoved=%string: =%
if defined masterdebug call :funcdebug %0
goto :eof
rem External tools functions ===================================================
:cct
:: Description: Privides interface to CCW32.
:: Required preset variables:
:: ccw32
:: Optional preset variables:
:: Required parameters:
:: script - can be one script.cct or serial comma separated "script1.cct,script2.cct,etc"
:: Optional parameters: 2
:: infile
:: outfile
:: Required functions:
:: infile
:: outfile
:: inccount
:: before
:: after
if defined errorsuspendprocessing goto :eof
if defined masterdebug call :funcdebug %0
set script=%~1
if not defined script echo missing script & goto :eof
call :infile "%~2"
if defined missinginput echo missing input file & goto :eof
if not exist "%ccw32%" echo missing ccw32.exe file & goto :eof
set scriptout=%script:.cct,=_%
call :inccount
call :outfile "%~3" "%projectpath%\xml\%pcode%-%count%-%scriptout%.xml"
set basepath=%cd%
rem if not defined ccw32 set ccw32=ccw32
set curcommand="%ccw32%" %cctparam% -t "%script%" -o "%outfile%" "%infile%"
call :before
cd %cctpath%
%curcommand%
cd %basepath%
call :after "Consistent Changes"
::
if defined masterdebug call :funcdebug %0 end
goto :eof
:xslt
:: Description: Provides interface to xslt2 by saxon9.jar
:: Required preset variables: 1
:: java
:: saxon9
:: Required parameters: 1
:: scriptname
:: Optional parameters: 3
:: allparam
:: infile
:: outfile
:: Func calls:
:: inccount
:: infile
:: outfile
:: quoteinquote
:: before
:: after
if defined errorsuspendprocessing goto :eof
if defined masterdebug call :funcdebug %0
call :inccount
set script=%xsltpath%\%~1.xslt
set param=
set allparam=
set allparam=%~2
if defined allparam set param=%allparam:'="%
call :infile "%~3"
call :outfile "%~4" "%projectpath%\xml\%pcode%-%count%-%~1.xml"
set trace=
if defined echojavatrace set trace=-t
if not defined resolvexhtml (
set curcommand="%java%" -jar "%cd%\%saxon9%" -o:"%outfile%" "%infile%" "%script%" %param%
) else (
set curcommand="%java%" %loadcat%=%cat% net.sf.saxon.Transform %trace% %usecatalog1% %usecatalog2% -o:"%outfile%" "%infile%" "%script%" %param%
)
call :before
%curcommand%
call :after "XSLT transformation"
if defined masterdebug call :funcdebug %0 end
goto :eof
rem replaces getvar
:projectvar
:: Description: get the variables from project.tasks file
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
call :ifexist "%projectpath%\setup\project.tasks" utf-8
call :tasklist project.tasks
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:projectxslt
:: Description: make project.xslt from project.tasks
:: Required preset variables: 1
:: projectpath
:: Required functions:
:: getdatetime
:: xslt
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
call :getfiledatetime tasksdate "%projectpath%\setup\project.tasks"
call :getfiledatetime xsltdate "%cd%\scripts\xslt\project.xslt"
call :getfiledatetime xsltscriptdate "%cd%\scripts\xslt\vimod-projecttasks2variable.xslt"
rem firstly check if this is the last project run
if "%lastprojectpath%" == "%projectpath%" (
rem then check if the project.tasks is newer than the project.xslt
set /A tasksdate-=%xsltdate%
if %tasksdate% GTR %xsltdate% (
rem if the project.tasks is newer then remake the project.xslt
echo project.tasks newer: remaking project.xslt %tasksdate% ^> %xsltdate%
echo.
set makenewprojectxslt=on
) else (
if "%xsltscriptdate%" GTR "%xsltdate%" (
echo.
echo vimod-projecttasks2variable.xslt is newer. %xsltscriptdate% ^> %xsltdate% project.xslt
echo Remaking project.xslt
echo.
set makenewprojectxslt=on
) else (
call :inccount
rem nothing has changed so don't remake project.xslt
echo 1 project.xslt is newer. %xsltdate% ^> %tasksdate% project.tasks
rem echo Project.tasks ^< %xsltdate% project.xslt.
echo.
)
)
) else (
rem the project is not the same as the last one or Vimod has just been started. So remake project.xslt
if defined lastprojectpath echo Project changed from "%lastprojectpath:~37%" to "%projectpath:~37%"
if not defined lastprojectpath echo New session for project: %projectpath:~37%
echo.
echo Remaking project.xslt
echo.
set makenewprojectxslt=on
)
if defined makenewprojectxslt call :xslt vimod-projecttasks2variable "projectpath='%projectpath%'" blank.xml "%cd%\scripts\xslt\project.xslt"
set lastprojectpath=%projectpath%
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:copy
:: Description: Provides copying with exit on failure
:: Required preset variables:
:: ccw32
:: Optional preset variables:
:: Required parameters:
:: script - can be one script.cct or serial comma separated "script1.cct,script2.cct,etc"
:: Optional parameters: 2
:: infile
:: outfile
:: Required functions:
:: infile
:: outfile
:: inccount
:: before
:: after
if defined masterdebug call :funcdebug %0
call :infile "%~1"
if defined missinginput echo missing input file & goto :eof
call :inccount
call :outfile "%~2"
set curcommand=copy /y "%infile%" "%outfile%"
call :before
%curcommand%
call :after Copy Changes"
::
if defined masterdebug call :funcdebug %0 end
goto :eof
:md5compare
:: no current use
:: Description: Compares the MD5 of the current project.tasks with the previous one, if different then the project.xslt is remade
:: Purpose: to see if the project.xslt needs remaking
:: Required preset variables: 1
:: cd
:: projectpath
:: Required parameters: 0
:: Required functions:
:: md5create
:: getline
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set md5check=diff
if exist "%cd%\logs\project-tasks-cur-md5.txt" del "%cd%\logs\project-tasks-cur-md5.txt"
call :md5create "%projectpath%\setup\project.tasks" "%cd%\logs\project-tasks-cur-md5.txt"
if exist "%cd%\logs\project-tasks-last-md5.txt" (
call :getline 4 "%cd%\logs\project-tasks-last-md5.txt"
set lastmd5=%getline%
call :getline 4 "%cd%\logs\project-tasks-cur-md5.txt"
rem clear getline var
set getline=
if "%lastmd5%" == "%getline%" (
set md5check=same
)
)
del "%cd%\logs\project-tasks-last-md5.txt"
ren "%cd%\logs\project-tasks-cur-md5.txt" "project-tasks-last-md5.txt"
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:md5create
:: no current use
:: Description: Make a md5 check file
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
call fciv "%~1" >"%~2"
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:xquery
:: Description: Provides interface to xquery by saxon9.jar
:: Required preset variables: 1
:: java
:: saxon9
:: Required parameters: 1
:: scriptname
:: Optional parameters: 3
:: allparam
:: infile
:: outfile
:: Func calls: 6
:: inccount
:: infile
:: outfile
:: quoteinquote
:: before
:: after
:: created: 2013-08-20
if defined masterdebug call :funcdebug %0
set scriptname=%~1
set allparam=%~2
call :infile "%~3"
call :outfile "%~4" "%projectpath%\xml\%pcode%-%writecount%-%scriptname%.xml"
call :inccount
set script=scripts\xquery\%scriptname%.xql
call :quoteinquote param "%allparam%"
set curcommand="%java%" net.sf.saxon.Query -o:"%outfile%" -s:"%infile%" "%script%" %param%
call :before
%curcommand%
call :after "XQuery transformation"
if defined masterdebug call :funcdebug %0 end
goto :eof
:testjava
:: Description: Test if java is installed. Attempt to use local java.exe otherwise it will exit with a warning.
if defined masterdebug call :funcdebug %0
set javainstalled=
where java /q
if "%errorlevel%" == "0" set javainstalled=yes
rem if defined JAVA_HOME set javainstalled=yes
if not defined javainstalled (
if exist %altjre% (
set java=%altjre%
) else (
echo No java found installed nor was java.exe found inVimod-Pub tools\java folder.
echo Please install Java on your machine.
echo Get it here: http://www.java.com/en/download/
echo The program will exit after this pause.
pause
exit /b
)
) else (
set java=java
)
if defined masterdebug call :funcdebug %0 end
goto :eof
:manyparam
:: Description: Allows spreading of long commands accross many line in a tasks file. Needed for wkhtmltopdf.
:: Class: command - exend
:: Required preset variables: 1
:: first - set for all after the first of manyparam
:: Optional preset variables:
:: first - Not required for first of a series
:: Required parameters: 1
:: newparam
if defined masterdebug call :funcdebug %0
set newparam=%~1
if not defined newparam echo Missing newparam parameter & goto :eof
set param=%param% %newparam%
if defined masterdebug call :funcdebug %0 end
goto :eof
:manyparamcmd
:: Description: places the command before all the serial parameters Needed for wkhtmltopdf.
:: Class: command - exend
:: Required preset variables: 1
:: param
:: Optional preset variables:
:: Required parameters: 1
:: command
if defined masterdebug call :funcdebug %0
set command=%~1
if not defined command echo Missing command parameter & goto :eof
rem this can't work here: call :quoteinquote param %param%
if defined param set param=%param:'="%
call :echolog "%command%" %param%
"%command%" %param%
rem clear the first variable
set param=
if defined masterdebug call :funcdebug %0 end
goto :eof
rem Tools sub functions ========================================================
:before
:: Description: Checks if outfile exists, renames it if it does. Logs actions.
:: Class: command - internal
:: Required preset variables:
:: projectlog
:: projectbat
:: Optional preset variables:
:: outfile
:: curcommand
:: writebat
:: Optional variables:
:: echooff
:: Func calls:
:: funcdebugstart
:: funcdebugend
:: nameext
rem @echo on
set echooff=%~1
if defined masterdebug call :funcdebug %0
if defined echocommandtodo echo Command to be attempted:
if defined echocommandtodo echo %curcommand%
if not defined echooff echo "Command to be attempted:" >>%projectlog%
echo "%curcommand%" >>%projectlog%
if defined writebat echo %curcommand%>>%projectbat%
echo. >>%projectlog%
if exist "%outfile%" call :nameext "%outfile%"
if exist "%outfile%.pre.txt" del "%outfile%.pre.txt"
if exist "%outfile%" ren "%outfile%" "%nameext%.pre.txt"
set echooff=
rem @echo off
if defined masterdebug call :funcdebug %0 end
goto :eof
:after
:: Description: Checks if outfile is created. Reports failures logs actions. Restors previous output file on failure.
:: Class: command - internal
:: Required preset variables: 3
:: outfile
:: projectlog
:: writecount
:: Optional parameters:
:: report3
:: message
:: Func calls:
:: nameext
if defined masterdebug call :funcdebug %0
@rem @echo on
set message=%~1
call :nameext "%outfile%"
if not exist "%outfile%" (
set errorlevel=1
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx >>%projectlog%
echo %message% failed to create %nameext%. >>%projectlog%
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx >>%projectlog%
echo. >>%projectlog%
echo.
color E0
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo %message% failed to create %nameext%.
if not defined nopauseerror (
echo.
echo Read error above and resolve issue then try again.
echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
echo.
pause
echo.
set errorsuspendprocessing=true
)
if defined nopauseerror echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
color 07
) else (
if defined echoafterspacepre echo.
call :echolog %writecount% Created: %nameext%
if defined echoafterspacepost echo.
echo ---------------------------------------------------------------- >>%projectlog%
rem echo. >>%projectlog%
if exist "%outfile%.pre.txt" del "%outfile%.pre.txt"
)
@rem @echo off
if defined masterdebug call :funcdebug %0 end
goto :eof
:nameext
:: Description: returns name and extension from a full drive:\path\filename
:: Class: command - parameter manipulation
:: Required parameters: 1
:: drive:\path\name.ext or path\name.ext or name.ext
:: created variable:
:: nameext
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set nameext=%~nx1
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:ext
:: Description: returns file extension from a full drive:\path\filename
:: Class: command - parameter manipulation
:: Required parameters: 1
:: drive:\path\name.ext or path\name.ext or name.ext
:: created variable:
:: nameext
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set ext=%~x1
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:name
:: Description: Gets the name of a file (no extension) from a full drive:\path\filename
:: Class: command - parameter manipulation
:: Required parameters: 1
:: drive:\path\name.ext or path\name.ext or name.ext
:: created variable:
:: name
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set name=%~n1
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:drivepath
:: Description: returns the drive and path from a full drive:\path\filename
:: Class: command - parameter manipulation
:: Required parameters:
:: Group type: parameter manipulation
:: drive:\path\name.ext or path\name.ext
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set drivepath=%~dp1
if defined echodrivepath echo %drivepath%
if defined masterdebug echo %endfuncstring% %0 %debugstack%
goto :eof
:file2uri
:: Description: transforms dos path to uri path. i.e. c:\path\file.ext to file:///c:/path/file.ext not needed for XSLT
:: Class: command - parameter manipulation
:: Required parameters: 1
:: pathfile
:: Optional parameters:
:: number
:: created variables: 1
:: uri%number%
if defined masterdebug call :funcdebug %0
call :setvar pathfile "%~1"
set numb=%~2
set uri%numb%=file:///%pathfile:\=/%
set return=file:///%pathfile:\=/%
if defined echofile2uri call :echolog uri%numb%=%return:~0,25% . . . %return:~-30%
if defined masterdebug call :funcdebug %0 end
goto :eof
:inccount
:: Description: iIncrements the count variable
:: Class: command - internal - parameter manipulation
:: Required preset variables:
:: space
:: count - on second and subsequent use
:: Optional preset variables: 1
:: count - on first use
if defined masterdebug echo %beginfuncstring% %0 %debugstack% %beginfuncstringtail%
set /A count=%count%+1
set writecount=%count%
if %count% lss 10 set writecount=%space%%count%