11#! /bin/bash
22#
3- # A script for compiling MQL4.0, MQL4.5 and MQL5 source files. Supports batch-processing of multiple files and directories.
3+ # A script for compiling MQL4.0, MQL4.5 and MQL5 source files. Supports batch-processing of multiple files and directories.
44# Prints results to STDOUT and follows standard rules for the exit status. The syntax is backward compatible to MetaEditor.
55#
66# Configuration via environment and/or config file.
3434#
3535set -eEuo pipefail
3636
37+ NL=$' \n '
38+
3739
3840# --- functions ----------------------------------------------------------------------------------------------------------------------------
3941
@@ -50,8 +52,8 @@ Usage: mqlc [options] [--] SOURCES...
5052
5153Arguments:
5254 SOURCES One or more MQL files or source directories to compile. Supports wildcards.
53-
54- Options:
55+
56+ Options:
5557 -h, --help This screen.
5658 /compile:FILE Source file to compile. Doesn't support wildcards.
5759 /compile:DIR Source directory to compile. Recompiles new and modified sources (not in subdirectories).
@@ -355,38 +357,6 @@ function compileMql40() {
355357}
356358
357359
358- #
359- # Format a log message produced by the MQL4.0 compiler.
360- #
361- # @param _InOut_ $1 - named reference to the log message
362- # @param _In_ $2 - source file of the compilation
363- # @param _In_ $3 - number of errors during the compilation
364- # @param _In_ $4 - number of warnings during the compilation
365- #
366- function formatCompiler40Msg() {
367- (( BASH_SUBSHELL)) && fail " ${FUNCNAME[0]} () can't write to outer scope from subshell"
368- local -n msg=" $1 "
369- local srcFile=" $2 " errors=" $3 " warnings=" $4 " cols type level levelS file location=' ' descr len
370-
371- readarray -t cols < <( printf ' %s\n' " ${msg// ;/ $' \n ' } " )
372- (( ${# cols[@]} != 5 )) && fail " unexpected number of fields (${# cols[@]} ) in compiler message: \" $msg \" "
373-
374- type=" ${cols[0]} "
375- [[ " $type " == [12] ]] || fail " unexpected message type ($type ) in compiler message: \" $msg \" "
376- (( type == 1 )) && level=' warn' || level=' error'
377- (( errors)) && len=6 || len=5
378- levelS=" $level : "
379- levelS=" ${levelS: 0: $len } "
380-
381- file=" ${cols[2]} "
382- [[ -n " ${cols[3]} " ]] && location=" (${cols[3]} )"
383- descr=" ${cols[4]} "
384-
385- msg=" ${levelS} ${file}${location} : ${descr} "
386- # msg="${file}${location}: ${level}: ${descr}"
387- }
388-
389-
390360#
391361# Compile an MQL4.5 or MQL5 source file.
392362#
@@ -466,39 +436,72 @@ function compileMql5() {
466436
467437
468438#
469- # Format a log message produced by the MQL4.5 or MQL5 compiler.
439+ # Reformat a single log message produced by the MQL4.0 compiler.
470440#
471441# @param _InOut_ $1 - named reference to the log message
472442# @param _In_ $2 - source file of the compilation
473443# @param _In_ $3 - number of errors during the compilation
474444# @param _In_ $4 - number of warnings during the compilation
475445#
476- function formatCompiler5Msg () {
446+ function formatCompiler40Msg () {
477447 (( BASH_SUBSHELL)) && fail " ${FUNCNAME[0]} () can't write to outer scope from subshell"
478- local -n msg=" $1 "
479- [[ -z " $msg " ]] && { unset " $1 " ; return ; }
480- local srcFile=" $2 " errors=" $3 " warnings=" $4 " cols level levelS file location=' ' descr len
448+ local -n logmsg=" $1 "
449+ local srcFile=" $2 " errors=" $3 " warnings=" $4 " type code level levelS file location message len
481450
482- [[ " $msg " =~ ^(.* ):\ (info| warn| error)[^:]* :\ (.+)$ ]] || fail " unexpected format of compiler message: \" $msg \" "
451+ [[ " $logmsg " =~ ^([0-9]+)\; ([0-9]+)\; (.+)\; ([0-9]+:[0-9]+)? \; (.* )$ ]] || fail " unexpected format of compiler message:$NL \" $logmsg \" "
452+ type=" ${BASH_REMATCH[1]} "
453+ code=" ${BASH_REMATCH[2]} "
454+ file=" ${BASH_REMATCH[3]} "
455+ location=" ${BASH_REMATCH[4]} "
456+ message=" ${BASH_REMATCH[5]} "
483457
484- descr=" ${BASH_REMATCH[3]} "
485-
486- level=" ${BASH_REMATCH[2]} "
458+ [[ " $type " == [12] ]] || fail " unexpected message type $type in compiler message:$NL \" $logmsg \" "
459+ (( type == 1 )) && level=' warn' || level=' error'
487460 (( errors)) && len=6 || len=5
488461 levelS=" $level : "
489462 levelS=" ${levelS: 0: $len } "
490463
464+ [[ -n " $location " ]] && location=" ($location )"
465+
466+ logmsg=" ${levelS} ${file}${location} : ${message} "
467+ # logmsg="${file}${location}: ${level}: ${message}"
468+ }
469+
470+
471+ #
472+ # Reformat a single log message produced by the MQL4.5 or MQL5 compiler.
473+ #
474+ # @param _InOut_ $1 - named reference to the log message
475+ # @param _In_ $2 - source file of the compilation
476+ # @param _In_ $3 - number of errors during the compilation
477+ # @param _In_ $4 - number of warnings during the compilation
478+ #
479+ function formatCompiler5Msg() {
480+ (( BASH_SUBSHELL)) && fail " ${FUNCNAME[0]} () can't write to outer scope from subshell"
481+ local -n logmsg=" $1 "
482+ [[ -z " $logmsg " ]] && { unset " $1 " ; return ; }
483+ local srcFile=" $2 " errors=" $3 " warnings=" $4 " level levelS file location=' ' message len
484+
485+ [[ " $logmsg " =~ ^(.* ):\ (info| warn| error)[^:]* :\ (.+)$ ]] || fail " unexpected format of compiler message:$NL \" $logmsg \" "
486+
491487 file=" ${BASH_REMATCH[1]} "
492488 file=" ${file% " ${file##* [![:space:]]} " } " # trim trailing white space
493489 if [[ " $file " =~ \( [0-9,]+\) $ ]]; then
494490 file=" ${file% " ${BASH_REMATCH[0]} " } "
495491 location=" ${BASH_REMATCH[0]} "
496492 fi
497493
494+ level=" ${BASH_REMATCH[2]} "
495+ (( errors)) && len=6 || len=5
496+ levelS=" $level : "
497+ levelS=" ${levelS: 0: $len } "
498+
499+ message=" ${BASH_REMATCH[3]} "
500+
498501 if [[ -z " $file " ]]; then
499- msg =" $levelS $descr "
502+ logmsg =" $levelS $message "
500503 else
501- msg =" $levelS ${file}${location} : $descr "
504+ logmsg =" $levelS ${file}${location} : $message "
502505 fi
503506}
504507
@@ -1230,7 +1233,7 @@ metaeditor64.exe
12301233
12311234UltraEdit
12321235---------
1233- If a tool returns errors to the output window, UltraEdit and UEStudio will open the referenced file at the specified line on double-click.
1236+ If a tool returns errors to the output window, UltraEdit and UEStudio will open the referenced file at the specified line on double-click.
12341237For this to work the error message must in the following format "FULL PATH(Line Number,Column Number): Error Message" i.e.:
12351238
12361239 C:\Development Path\ProjectDev\EditWindow.c(341): some error message
0 commit comments