-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathezbuild.bat
More file actions
1239 lines (1049 loc) · 34.4 KB
/
Copy pathezbuild.bat
File metadata and controls
1239 lines (1049 loc) · 34.4 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
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
@goto main
rem Easy Compiler v1.4.2
rem Updated on 2018-03-31
rem Made by wthe22 - http://winscr.blogspot.com/
rem ======================================== About Script ========================================
:about_script
cls
title !SOFTWARE_NAME! !SOFTWARE_VERSION!
echo Compiling source code made easy
echo You don't need to type something like this anymore:
echo=
echo C gcc "helloWorld.c" -o "helloWorld.exe"
echo Java javac "helloWorld.java"
echo=
echo Just input the file name / drag and drop the file
echo Then this script will do the rest
echo=
echo=
echo Made by wthe22
echo Updated on !SOFTWARE_RELEASE_DATE!
echo=
echo ^>^> More scripts at http://winscr.blogspot.com/ ^<^<
pause > nul
goto :EOF
rem ======================================== Entry Point ========================================
:__ENTRY__ Entry Point
@rem These kinds of labels serves as a bookmark
:main
@echo off
prompt $s
setlocal EnableDelayedExpansion EnableExtensions
rem ======================================== Settings ========================================
rem ? searchPath order sensitive
rem Add this path to all language search path
rem You can also include your own (portable) SDK path here, each seperated by a semicolon (;)
set "lang_all_searchPath="
set "lang_all_searchPath=!lang_all_searchPath!;*:\Program*Files*"
set "lang_all_searchPath=!lang_all_searchPath!;*:"
rem If your SDK is not detected, you can try this:
:: set "lang_all_searchPath=!lang_all_searchPath!;!path!"
rem You can add / edit existing SDK configuration at the end of this file
rem ======================================== Script Setup ========================================
set "SOFTWARE_NAME=Easy Compiler"
set "SOFTWARE_VERSION=1.4.2"
set "SOFTWARE_RELEASE_DATE=03/31/2018"
title !SOFTWARE_NAME! !SOFTWARE_VERSION!
cd /d "%~dp0"
call :getScreenSize
set /a "screenWidth-=1"
set "border_line="
for /l %%n in (1,1,!screenWidth!) do set "border_line=!border_line!="
call :capchar LF
set NL=^^^%LF%%LF%^%LF%%LF%
rem Spaces!
set "spaces="
for /l %%n in (1,1,30) do set "spaces=!spaces! "
rem Initialize variables
set "lastUsed_action="
set "setup_done="
cls
echo Reading SDK configurations...
call :Config.parse
if not "%~1" == "" (
set ^"input_files=%*^"
call :debug_file.parse_type
cls
)
echo Finding all SDK files...
call :SDK.find
goto main_menu
rem ======================================== Menu ========================================
:__MENU__ Menu
:main_menu
set "user_input="
cls
echo 1. Compile / run file
echo 2. Change SDK
echo 3. Delete compiled files
echo 4. Repeat last action
echo=
echo A. About
echo 0. Exit
echo=
echo What do you want to do?
set /p "user_input="
echo=
if "!user_input!" == "0" exit
if "!user_input!" == "1" goto debug_file.input
if "!user_input!" == "2" goto lang_sdk.select
if "!user_input!" == "3" goto delete_files.select
if "!user_input!" == "4" goto repeat_action
if /i "!user_input!" == "A" call :about_script
goto main_menu
:repeat_action
if "!lastUsed_action!" == "compile/run" (
set ^"input_files=!lastUsed_input_files!^"
call :debug_file.parse_type
goto main_menu
)
if "!lastUsed_action!" == "delete_files" (
set "selected_ext=!lastUsed_delExt!"
goto delete_files.prompt
)
goto main_menu
rem ======================================== Input File ========================================
rem ======================================== Change SDK ========================================
:lang_sdk.select
set "user_input=?"
cls
call :Lang.get_used_sdk list
echo=
echo R. Show Registered SDK
echo 0. Back
echo=
echo Input the list number :
set /p "user_input="
echo=
if "!user_input!" == "0" goto main_menu
if /i "!user_input!" == "R" call :lang_sdk.show_registered
call :Lang.get_used_sdk !user_input!
if defined selected_lang goto lang_sdk.input_path
goto lang_sdk.select
:lang_sdk.show_registered
cls
call :Lang.get_reg_sdk
pause
goto :EOF
:lang_sdk.input_path
set "user_input="
cls
if defined lang_%selected_lang%_%selected_type%_used (
echo Current SDK:
echo !lang_%selected_lang%_%selected_type%_path!
echo=
echo=
)
echo All found !lang_%selected_lang%_name! !selected_type!s:
echo=
call :Lang.get_sdk_path !selected_lang! !selected_type! list
echo=
echo 0. Back
echo=
echo Input list number or a new file address:
set /p "user_input="
echo=
if "!user_input!" == "0" goto lang_sdk.select
call :Lang.get_sdk_path !selected_lang! !selected_type! !user_input!
if defined selected_file goto lang_sdk.change
call :strip_dquotes user_input
if not exist "!user_input!" (
echo File not found
pause > nul
goto lang_sdk.input_path
)
set "selected_sdk=Custom"
for %%f in ("!user_input!") do set "selected_file=%%~ff"
goto lang_sdk.change
:lang_sdk.change
set "lang_!selected_lang!_!selected_type!_used=!selected_sdk!"
set "lang_!selected_lang!_!selected_type!_path=!selected_file!"
echo Change successful
pause > nul
goto lang_sdk.select
rem ======================================== Delete Compiled Files ========================================
:delete_files.select
set "user_input="
cls
call :Ext.get_item Remove list
echo=
echo C. Custom
echo 0. Back
echo=
echo Choose which compiled files to delete:
set /p "user_input="
echo=
if "!user_input!" == "0" goto main_menu
call :Ext.get_item Remove !user_input!
if /i "!user_input!" == "C" call :delete_files.input_ext || goto delete_files.select
if defined selected_ext goto delete_files.prompt
goto delete_files.select
:delete_files.input_ext
cls
echo 0. Back
echo=
echo Seperate extensions by space
echo=
echo Input file extensions to delete:
set /p "selected_ext="
echo=
if "!selected_ext!" == "0" exit /b 1
exit /b 0
:delete_files.prompt
call :Ext.check_contains Source selected_ext
cd /d "%~dp0"
set "user_input=?"
cls
echo Current directory:
echo=!cd!
echo=
echo Extensions to delete:
echo=!selected_ext!
echo=
if defined ext_contains (
echo Source code extensions:
echo !ext_contains!
echo=
)
echo=
echo Files will be deleted permanently (not to the recycle bin)
echo=
if defined ext_contains (
call :input_yesno user_input "Source code extensions found. Continue?"
if /i "!user_input!" == "N" goto delete_files.select
)
call :input_yesno user_input "Delete files permanently?"
if /i "!user_input!" == "N" goto delete_files.select
set "lastUsed_action=delete_files"
set "lastUsed_delExt=!selected_ext!"
echo=
echo Deleting files...
echo=
set "delCount=0"
set "failCount=0"
for %%x in (!selected_ext!) do for %%f in ("*.%%x") do (
del /f /q "%%~ff" && (
set /a "delCount+=1"
echo Deleted %%~nxf
) || (
set /a "failCount+=1"
echo Failed %%~nxf
)
)
echo Successfully deleted !delCount! files (!failCount! failed)
pause > nul
goto main_menu
rem ======================================== Compile / Run File ========================================
:debug_file.input
cd /d "%~dp0"
set "input_files="
cls
dir /b /o:d "*" 2> nul
echo=
echo 0. Back
echo=
echo Input file address:
set /p "input_files="
echo=
if "!input_files!" == "0" goto main_menu
call :debug_file.parse_type && goto main_menu
echo=
pause
goto debug_file.input
:debug_file.parse_type
set "lastUsed_input_files=!input_files!"
set "lastUsed_action=compile/run"
:debug_file.parse_again
echo Determining file type...
call :File.parse || exit /b 1
if /i "!input_type!" == "Source" set "_tool=compiler"
if /i "!input_type!" == "Compiled" set "_tool=interpreter"
rem ? Initialize
if /i not defined lang_%input_lang%_%_tool%_init (
echo Finding !lang_%input_lang%_name! SDK files...
call :SDK.find !input_lang!
)
if not defined lang_!input_lang!_!_tool!_used (
echo=
echo error 4: could not find !_tool! for !lang_%input_lang%_name!
echo Please add search path or manually set SDK location
echo=
pause
exit /b 2
)
if /i "!input_type!" == "Compiled" call :debug_file.do run
if /i "!input_type!" == "Related" (
echo error 31: this type of file cannot be compiled or run
exit /b 1
)
if /i "!input_type!" == "Source" (
call :debug_file.do compile
if "!error_code!" == "0" goto debug_file.parse_again
)
goto :EOF
:debug_file.do compile|run
rem Input parameter
set "additional_parameter="
cls
call :File.display_info
echo=
echo Input %~1 parameter:
set /p "additional_parameter="
rem Confirm action
cls
call :File.display_info
echo=
echo Additional parameter:
echo=!additional_parameter!
echo=
echo Press any key to %~1...
pause > nul
echo=
if /i "%~1" == "run" (
title !input_display!
cls
)
call :File.%~1
set "input_files=!result_file!"
set "result_file="
title !SOFTWARE_NAME! !SOFTWARE_VERSION!
if not "!error_code!" == "0" (
echo Compile error occured. See above for more details.
echo=
)
echo Time taken : !time_taken!
echo Exit code : !error_code!
pause > nul
echo=
goto :EOF
rem ======================================== Class ========================================
:__CLASS__ Class Definition
rem ======================================== Config ========================================
rem Read SDK Configurations from file
rem Rewrite SDK list for each language, sorted descending order according to preferred SDKs
rem Rewrite list of extensions
rem List all extensions type for each language
rem List all language extensions for each type
rem List extensions to remove for each language
:Config.parse
rem Read SDK Configurations from file
set "data_type="
set "label_used="
for %%t in (lang sdk) do set "%%tList="
for /f "usebackq tokens=1* delims= " %%a in ("%~f0") do (
if /i "%%a" == "#end" set "data_type="
if /i "!data_type!" == "lang" (
if /i "%%a" == "require" (
for %%p in (%%b) do set "lang_!label_used!_require_%%p=True"
) else set "lang_!label_used!_%%a=%%b"
)
if /i "!data_type!" == "sdk" for %%s in (!label_used!) do (
set "isParsed="
for %%t in (compiler interpreter) do if /i "%%a" == "%%t" (
for /f "tokens=1* delims= " %%l in ("%%b") do (
set "sdk_%%s_%%t_%%l=%%m"
set "sdk_%%s_%%tList=!sdk_%%s_%%tList! %%l"
set "lang_%%l_sdkList=!lang_%%l_sdkList! %%s"
set "isParsed=True"
)
)
if not defined isParsed set "sdk_%%s_%%a=%%b"
)
for %%t in (lang sdk) do if /i "%%a" == "#%%t" (
set "data_type=%%t"
set "label_used=%%b"
set "sdk_%%t_canCompile="
set "sdk_%%t_canRun="
set "%%tList=!%%tList! %%b"
)
)
set "lang_all_name=All"
rem Rewrite SDK list for each language, sorted descending order according to preferred SDKs
for %%l in (!langList!) do (
set "_tempList= "
for %%s in (!lang_%%l_sdkList!) do set "_tempList=!_tempList: %%s = !%%s "
set "lang_%%l_sdkList=!_tempList!"
set "_tempList= "
for %%d in (!lang_%%l_sdkPreferred!) do for %%s in (!lang_%%l_sdkList!) do if "%%s" == "%%d" (
set "_tempList=!_tempList!%%s "
set "lang_%%l_sdkList=!lang_%%l_sdkList: %%s = !"
)
set "lang_%%l_sdkList=!_tempList!!lang_%%l_sdkList:~1!
)
rem Rewrite list of extensions
for %%l in (!langList!) do for %%t in (Compiled Related Source) do (
set "_ext= "
for %%x in (!lang_%%l_ext%%t!) do set "_ext=!_ext: %%x = !%%x "
set "lang_%%l_ext%%t=!_ext!"
)
rem List all extensions type for each language
set "lang_all_extRemove="
for %%l in (!langList!) do (
set "_tempList="
for %%t in (Compiled Related Source) do set "_tempList=!_tempList!!lang_%%l_ext%%t!"
set "_ext= "
for %%x in (!_tempList!) do set "_ext=!_ext: %%x = !%%x "
set "lang_%%l_extAll=!_ext!"
for %%x in (!lang_%%l_extSource!) do set "_ext=!_ext: %%x = !"
set "lang_%%l_extRemove=!_ext!"
set "lang_all_extRemove=!lang_all_extRemove!!_ext!"
)
rem List all language extensions for each type
for %%t in (Source Compiled Related) do (
set "_tempList="
for %%l in (!langList!) do set "_tempList=!_tempList!!lang_%%l_ext%%t!"
set "_ext= "
for %%x in (!_tempList!) do set "_ext=!_ext: %%x = !%%x "
set "lang_all_ext%%t=!_ext!"
)
rem List extensions to remove for each language
set "_ext= "
for %%x in (!lang_all_extRemove!) do set "_ext=!_ext: %%x = !%%x "
for %%x in (!lang_all_extSource!) do set "_ext=!_ext: %%x = !"
set "lang_all_extRemove=!_ext!"
goto :EOF
rem ======================================== SDK ========================================
:Lang.get_used_sdk
set "selected_lang="
set "selected_type="
set "_listCount=0"
if /i "%~1" == "list" (
echo # ^| Language ^| Type ^| SDK Used ^| Path
echo !border_line!
)
for %%l in (!langList!) do for %%t in (Compiler Interpreter) do if defined lang_%%l_require_%%t (
set /a "_listCount+=1"
if /i "%~1" == "list" (
set "_display= !_listCount!"
set "_display=!_display:~-3,3! ^| !lang_%%l_name!!spaces!"
set "_display=!_display:~0,18! ^| %%t!spaces!"
if defined lang_%%l_%%t_used (
for %%s in (!lang_%%l_%%t_used!) do set "_display=!_display:~0,32! ^| !sdk_%%s_shortName!!spaces!"
set "_display=!_display:~0,47! ^| !lang_%%l_%%t_path!"
) else (
set "_display=!_display:~0,32! ^| *NOT FOUND*!spaces!"
set "_display=!_display:~0,47! ^| *NOT FOUND*"
)
if not "!_display:~%screenWidth%!" == "" (
set "_display=!_display:~0,%screenWidth%!
set "_display=!_display:~0,-3!..."
)
echo=!_display!
) else if /i "%~1" == "!_listCount!" (
set "selected_lang=%%l"
set "selected_type=%%t"
)
)
goto :EOF
:Lang.get_reg_sdk
echo Language ^| Registered SDKs
echo !border_line!
for %%l in (!langList!) do (
set "_display=!lang_%%l_name!!spaces!"
set "_display= !_display:~0,12! | "
set "_display2= "
for %%s in (!lang_%%l_sdkList!) do set "_display2=!_display2!!sdk_%%s_shortName!, "
set "_display=!_display!!_display2:~1,-2!"
echo !_display!
)
echo=
echo Search Path: !lang_all_searchPath:;=%NL%!
echo=
goto :EOF
:Lang.get_sdk_path lang type list|number
set "_listCount=0"
set "selected_file="
if /i "%~3" == "list" (
set "all_found_files="
for %%s in (!lang_%~1_sdkList!) do (
call :SDK.get_file_list %%s %~2 %~1
for /f "tokens=*" %%a in ("!found_files!") do set "all_found_files=!all_found_files!%%s@%%a!LF!"
)
echo # ^| SDK Name ^| Path
echo !border_line!
)
for /f "tokens=* tokens=1* delims=@" %%s in ("!all_found_files!") do (
set /a "_listCount+=1"
if /i "%~3" == "list" (
set "_display= !_listCount!"
set "_display=!_display:~-3,3! ^| !sdk_%%s_shortName!!spaces!"
echo !_display:~0,18! ^| %%t
) else if /i "%~3" == "!_listCount!" (
set "selected_sdk=%%s"
set "selected_file=%%t"
)
)
goto :EOF
:SDK.find [lang1 [lang2 ...]]
set "_lang_to_find=!langList!"
if not "%~1" == "" set "_lang_to_find=%*"
for %%l in (!_lang_to_find!) do for %%t in (compiler interpreter) do if /i "!lang_%%l_require_%%t!" == "True" (
set "lang_%%l_%%t_init=True"
set "lang_%%l_%%t_used="
set "lang_%%l_%%t_path="
for %%s in (!lang_%%l_sdkList!) do if not defined lang_%%l_%%t_path if defined sdk_%%s_%%t_%%l (
call :SDK.get_file_list %%s %%t %%l
for /f "tokens=*" %%a in ("!found_files!") do set "lang_%%l_%%t_path=%%a"
if defined lang_%%l_%%t_path (
set "lang_%%l_%%t_used=%%s"
echo [+] !sdk_%%s_name! %%t for !lang_%%l_name!
) else echo [-] !sdk_%%s_name! %%t for !lang_%%l_name!
)
)
rem For files that does not need SDK to run
for %%l in (!_lang_to_find!) do (
if /i "!lang_%%l_require_defaultRun!" == "True" set "lang_%%l_interpreter_used=Default"
)
goto :EOF
sss
:SDK.get_file_list sdk_label type lang
rem Setup and format path
set "_path1=!lang_all_searchPath!;!sdk_%~1_searchPath!"
set "_path2=!sdk_%~1_rootFolder!\!sdk_%~1_%~2_%~3!"
for /f "delims=" %%f in ("!sdk_%~1_%~2_%~3!") do set "_path2=!_path2!;%%~nxf"
for %%p in (_path1 _path2) do set ^"%%p=!%%p:;=%NL%!^"
rem Eliminate duplicate paths in _path1
set "_temp="
for /f "tokens=*" %%a in ("!_path1!") do (
set "_is_listed="
for /f "tokens=*" %%b in ("!_temp!") do if "%%a" == "%%b" set "_is_listed=Y"
if not defined _is_listed set "_temp=!_temp!%%a!LF!"
)
set "_path1=!_temp!"
rem Find SDK
set "_found="
for /f "tokens=*" %%a in ("!_path1!") do for /f "tokens=*" %%b in ("!_path2!") do (
call :wcdir "%%a\%%b"
set "_found=!_found!!return!"
)
rem Eliminate duplicate SDK
set "found_files="
for /f "tokens=*" %%a in ("!_found!") do (
set "_is_listed="
for /f "tokens=*" %%b in ("!found_files!") do if "%%a" == "%%b" set "_is_listed=Y"
if not defined _is_listed set "found_files=!found_files!%%a!LF!"
)
goto :EOF
:File.display_info
echo File address:
echo !input_display!
echo=
echo Language : !lang_%input_lang%_name!
if "!selected_type!" == "Source" echo Compiler : !sdk_%selected_sdk%_name!
if "!selected_type!" == "Compiled" echo Interpreter : !sdk_%selected_sdk%_name!
goto :EOF
:File.parse
rem Initialize
set "input_display=!input_files!"
set "input_count=0"
for %%v in (input_files input_dir output_path) do set "%%v="
rem Detect if input is folder
call :expand_path _first !input_display!
if /i "!_firstA:~0,1!" == "d" (
set input_display="!_firstF!\*"
set "output_path=!_firstF!"
)
rem Rewrite as full paths
for %%f in (!input_display!) do if exist "%%~ff" (
set "input_files=!input_files! ^"%%~ff^""
set /a "input_count+=1"
if not defined input_dir set "input_dir=%%~dpf"
if not defined output_path set "output_path=!_firstDP!\%%~nf"
) else (
echo error 1: File not found 1>&2
exit /b 1
)
if /i not "!_firstA:~0,1!" == "d" set ^"input_display=!input_files!^"
rem Get extensions
set "input_extensions= "
for %%f in (!input_files!) do set "input_extensions=!input_extensions: %%~xf = !%%~xf "
set "input_extensions=!input_extensions:.=!"
rem Make sure each extension occur only once. Language detection may be affected
rem Detect language
set "input_lang= "
set "_lang_count=0"
for %%l in (!langList!) do (
set "_temp_ext=!input_extensions!"
for %%x in (!lang_%%l_extAll!) do set "_temp_ext=!_temp_ext: %%x = !"
if "!_temp_ext!" == " " (
set "input_lang=!input_lang! %%l"
set /a "_lang_count+=1"
)
)
set "input_lang=!input_lang:~2!"
if "!_lang_count!" == "0" (
echo error 2: input language is either unknown or mixed 1>&2
exit /b 2
)
for /f "tokens=1 delims= " %%l in ("!input_lang!") do set "input_lang=%%l"
rem Get input file type
set "input_type= "
set "_type_count=0"
for %%t in (Compiled Source Related) do (
set "_temp_ext=!input_extensions!"
for %%x in (!lang_%input_lang%_ext%%t!) do set "input_extensions=!input_extensions: %%x = !"
if not "!input_extensions!" == "!_temp_ext!" (
set "input_type=!input_type! %%t"
set /a "_type_count+=1"
)
)
set "input_extensions="
set "input_type=!input_type:~2!"
if not "!_type_count!" == "1" (
echo error 3: mixed file types. usually source code and executable 1>&2
exit /b 3
)
if /i "!input_type!" == "Compiled" if not "!input_count!" == "1" (
echo error 11: too many files to run 1>&2
exit /b 11
)
if /i "!input_type!" == "Source" if not "!_lang_count!" == "1" (
echo error 21: input matches multiple programming language 1>&2
exit /b 21
)
exit /b 0
:File.compile
setlocal
for %%c in ("!lang_%input_lang%_compiler_path!") do set "path=%%~dpc;!path!"
cd /d "!input_dir!"
call :expand_path compiler "!lang_%input_lang%_compiler_path!"
call :expand_multipath file !input_files!
call :expand_path output "!output_path!"
set "result_file="
set "startTime=!time!"
echo !border_line!
if "!lang_%input_lang%_compiler_used!" == "Custom" (
call :Custom.compile
) else call :!lang_%input_lang%_compiler_used!.compile.!input_lang!
set "error_code=!errorlevel!"
echo=
echo !border_line!
call :difftime !time! !startTime!
call :ftime !return!
for %%f in ("!result_file!") do (
endlocal
set "error_code=%error_code%"
set result_file="%%~ff"
set "time_taken=%return%"
)
goto :EOF
:File.run
setlocal
for %%c in ("!lang_%input_lang%_interpreter_path!") do set "path=%%~dpc;!path!"
cd /d "!input_dir!"
call :expand_path interpreter "!lang_%input_lang%_interpreter_path!"
call :expand_path file !input_files!
set "startTime=!time!"
if "!lang_%input_lang%_interpreter_used!" == "Custom" (
call :Custom.run
) else call :!lang_%input_lang%_interpreter_used!.run.!input_lang!
set "error_code=!errorlevel!"
echo=
echo !border_line!
call :difftime !time! !startTime!
call :ftime !return!
for %%f in (0) do (
endlocal
set "error_code=%error_code%"
set "time_taken=%return%"
)
set "result_file="
goto :EOF
:Ext.get_item type list|number
set "_listCount=0"
set "selected_lang="
for %%l in (all !langList!) do if not "!lang_%%l_ext%~1: =!" == "" (
set /a "_listCount+=1"
if /i "%~2" == "list" (
set "_display= !_listCount!"
set "_display=!_display:~-3,3!. !lang_%%l_name!!spaces!"
set "_display=!_display:~0,17! !lang_%%l_ext%~1!"
if not "!_display:~%screenWidth%!" == "" (
set "_display=!_display:~0,%screenWidth%!"
set "_display=!_display:~0,-3!..."
)
echo=!_display!
) else if "%~2" == "!_listCount!" set "selected_ext=!lang_%%l_ext%~1!"
)
goto :EOF
:Ext.check_contains type variable_name
set "_temp_ext=!%~2!"
set "%~2= "
for %%x in (!_temp_ext!) do set "%~2=!%~2: %%x = !%%x "
set "_ext_count=0"
for %%x in (!%~2!) do set /a "_ext_count+=1"
if "!_ext_count!" == "0" (
echo No extensions listed
pause
goto :EOF
)
set "ext_contains="
for %%l in (!langList!) do (
set "_temp_ext="
for %%x in (!lang_%%l_ext%~1!) do if not "!%~2: %%x =!" == "!%~2!" set "_temp_ext=!_temp_ext! %%x"
if defined _temp_ext (
set "_display=!lang_%%l_name!!spaces!"
set "ext_contains=!ext_contains!!_display:~0,12! ^| !_temp_ext!!LF!"
)
)
goto :EOF
rem ======================================== Script Functions ========================================
:__FUNCTIONS__ Functions only used in this script
:expand_multipath prefix file_path1 [file_path2 ...]
for %%a in (D P N X F DP NX) do set "%~1%%a="
set "_continue="
for %%f in (%*) do if defined _continue (
set ^"%~1Ds=!%~1Ds! "%%~df"^"
set ^"%~1Ps=!%~1Ps! "%%~pf"^"
set ^"%~1Ns=!%~1Ns! "%%~nf"^"
set ^"%~1Xs=!%~1Xs! "%%~xf"^"
set ^"%~1Fs=!%~1Fs! "%%~ff"^"
set ^"%~1DPs=!%~1DPs! "%%~dpf"^"
set ^"%~1NXs=!%~1NXs! "%%~nxf"^"
) else set "_continue=True"
exit /b
rem ======================================== Functions ========================================
:__FUNCTION_LIBRARY__ Collection of Functions
:difftime end_time [start_time] [/n]
set "return=0"
for %%t in (%1:00:00:00:00 %2:00:00:00:00) do for /f "tokens=1-4 delims=:." %%a in ("%%t") do (
set /a "return+=24%%a %% 24 *360000 +1%%b*6000 +1%%c*100 +1%%d -610100"
set /a "return*=-1"
)
if /i not "%3" == "/n" if !return! LSS 0 set /a "return+=8640000"
exit /b
:ftime time_in_centiseconds
set /a "_remainder=%~1 %% 8640000"
set "return="
for %%n in (360000 6000 100 1) do (
set /a "_result=!_remainder! / %%n"
set /a "_remainder%%= %%n"
set "_result=?0!_result!"
set "return=!return!!_result:~-2,2!:"
)
set "return=!return:~0,-4!.!return:~-3,2!"
exit /b
:strip_dquotes variable_name
if not "!%~1!" == "" (
set _tempvar="!%~1:~1,-1!"
if "!%~1!" == "!_tempvar!" set "%~1=!%~1:~1,-1!"
set "_tempvar="
)
exit /b
:wcdir [drive:][path]filename
set "return="
set "_findNext=%~1"
set "_isFile=Y"
if "!_findNext:~-1,1!" == "\" set "_isFile="
call :wcdir_loop
set "_findNext="
set "_isFile="
exit /b
:wcdir_loop
for /f "tokens=1* delims=\" %%a in ("!_findNext!") do if not "%%a" == "*:" (
if "%%b" == "" (
if defined _isFile (
for /f "delims=" %%f in ('dir /b /a:-d "%%a" 2^> nul') do set "return=!return!%%~ff!LF!"
) else for /f "delims=" %%f in ('dir /b /a:d "%%a" 2^> nul') do set "return=!return!%%~ff\!LF!"
) else for /d %%f in ("%%a") do pushd "%%~f\" 2> nul && (
set "_findNext=%%b"
call :wcdir_loop
popd
)
) else for %%l in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do pushd "%%l:\" 2> nul && (
set "_findNext=%%b"
call :wcdir_loop
popd
)
exit /b
:expand_path prefix file_path
set "%~1D=%~d2"
set "%~1A=%~a2"
set "%~1T=%~t2"
set "%~1Z=%~z2"
set "%~1N=%~n2"
set "%~1X=%~x2"
set "%~1P=%~p2"
set "%~1F=%~f2"
set "%~1DP=%~dp2"
set "%~1NX=%~nx2"
exit /b
:getScreenSize
set "_lineNum=0"
for /f "usebackq tokens=2 delims=:" %%a in (`mode con`) do (
set /a "_lineNum+=1"
if "!_lineNum!" == "1" set /a "screenHeight= 0 + %%a + 0"
if "!_lineNum!" == "2" set /a "screenWidth= 0 + %%a + 0"
)
set "_lineNum="
exit /b
:capchar character1 [character2] [...]
rem Capture backspace character
if /i "%~1" == "B" for /f %%a in ('"prompt $h & echo on & for %%b in (1) do rem"') do (
set "B=%%a"
)
rem Generate "backspace"
if /i "%~1" == "BS" call :capchar "B" && set "BS=!B! !B!"
rem Generate "base" for "set /p" output
if /i "%~1" == "BASE" call :capchar "BS" && set BASE="!BS!
rem Capture Carriage Return character
if /i "%~1" == "CR" for /f %%a in ('copy /Z "%~f0" nul') do set "CR=%%a"
rem Capture Line Feed character (2 empty lines requred)
if /i "%~1" == "LF" set LF=^
%=REQURED=%
%=REQURED=%
rem Shift parameter
shift /1
if "%~1" == "" exit /b 0
goto capchar
:input_yesno variable_name [description]
echo=
if "%~2" == "" (
set /p "%~1=%~1 Y/N? "
) else set /p "%~1=%~2 Y/N? "
if /i "!%~1!" == "Y" exit /b
if /i "!%~1!" == "N" exit /b
goto input_yesno
rem ================================================== Language List ==================================================
:__LANG_LIST__ Identify programming languages
================ Example ================
.#lang Specify beginning of list, fill this with label used in the script. Use this without the dot at front.
name Name of the programming language
extCompiled Run this kind of file. Will be cleaned/deleted unless it is also source code.
extRelated Cannot compile/run this kind of file. Will be cleaned/deleted unless it is also source code.
extSource Compile this kind of file. Will not be cleaned/deleted.
sdkPreferred Labels of your most preferred SDKs to the least preferred.
#end Specify end of definition. Don't forget to add this!
================ Unknown ================
#lang Unknown
name Unknown
extCompiled exe
extRelated obj
extSource
sdkPreferred
require defaultRun
#end
================ C ================
#lang C
name C
extCompiled exe
extRelated h
extSource c h
sdkPreferred MinGW
require compiler
#end
================ C++ ================
#lang Cpp
name C++
extCompiled exe
extRelated hpp h
extSource cpp hpp h
sdkPreferred MinGW
require compiler
#end
================ Java ================
#lang Java
name Java
extCompiled class jar
extRelated form
extSource java
sdkPreferred JDK
require compiler interpreter
#end
================ Python ================
#lang Python
name Python
extCompiled py
extRelated
extSource py
sdkPreferred Python3
require interpreter
#end
================ Assembly ================
#lang Assembly
name Assembly
extCompiled exe
extRelated
extSource asm
sdkPreferred
require compiler
#end
rem ================================================== SDK List ==================================================