@@ -509,6 +509,51 @@ static status_code_t read_parameter (char *line, uint_fast8_t *char_counter, flo
509
509
return status ;
510
510
}
511
511
512
+ static void substitute_parameters (char * comment , char * * message ) {
513
+ size_t len = 0 ;
514
+ float value ;
515
+ char * s3 ;
516
+ uint_fast8_t char_counter = 0 ;
517
+ char c = * (comment + char_counter );
518
+
519
+ // Trim leading spaces
520
+ while (* comment == ' ' )
521
+ comment ++ ;
522
+
523
+ // Calculate length of substituted string
524
+ while ((c = comment [char_counter ++ ])) {
525
+ if (c == '#' ) {
526
+ char_counter -- ;
527
+ if (read_parameter (comment , & char_counter , & value ) == Status_OK )
528
+ len += strlen (trim_float (ftoa (value , ngc_float_decimals ())));
529
+ else
530
+ len += 3 ; // "N/A"
531
+ } else
532
+ len ++ ;
533
+ }
534
+
535
+ // Perform substitution
536
+ if ((s3 = * message = malloc (len + 1 ))) {
537
+
538
+ * s3 = '\0' ;
539
+ char_counter = 0 ;
540
+
541
+ while ((c = comment [char_counter ++ ])) {
542
+ if (c == '#' ) {
543
+ char_counter -- ;
544
+ if (read_parameter (comment , & char_counter , & value ) == Status_OK )
545
+ strcat (s3 , trim_float (ftoa (value , ngc_float_decimals ())));
546
+ else
547
+ strcat (s3 , "N/A" );
548
+ s3 = strchr (s3 , '\0' );
549
+ } else {
550
+ * s3 ++ = c ;
551
+ * s3 = '\0' ;
552
+ }
553
+ }
554
+ }
555
+ }
556
+
512
557
#endif // NGC_EXPRESSIONS_ENABLE
513
558
514
559
#if NGC_PARAMETERS_ENABLE
@@ -596,63 +641,24 @@ char *gc_normalize_block (char *block, char **message)
596
641
597
642
if (message && * message == NULL && !strncmp (comment , "(MSG," , 5 ) && (* message = malloc (len ))) {
598
643
comment += 5 ;
599
- // Trim leading spaces
644
+ #if NGC_EXPRESSIONS_ENABLE
645
+ substitute_parameters (comment , message );
646
+ #else
600
647
while (* comment == ' ' ) {
601
648
comment ++ ;
602
649
len -- ;
603
650
}
604
651
memcpy (* message , comment , len );
652
+ #endif
605
653
}
606
654
607
655
#if NGC_EXPRESSIONS_ENABLE
608
656
// Debug message string substitution
609
657
if (message && * message == NULL && !strncmp (comment , "(DEBUG," , 7 )) {
610
658
611
659
if (settings .flags .ngc_debug_out ) {
612
-
613
- float value ;
614
- char * s3 ;
615
- uint_fast8_t char_counter = 0 ;
616
-
617
- len = 0 ;
618
660
comment += 7 ;
619
-
620
- // Trim leading spaces
621
- while (* comment == ' ' )
622
- comment ++ ;
623
-
624
- // Calculate length of substituted string
625
- while ((c = comment [char_counter ++ ])) {
626
- if (c == '#' ) {
627
- char_counter -- ;
628
- if (read_parameter (comment , & char_counter , & value ) == Status_OK )
629
- len += strlen (trim_float (ftoa (value , ngc_float_decimals ())));
630
- else
631
- len += 3 ; // "N/A"
632
- } else
633
- len ++ ;
634
- }
635
-
636
- // Perform substitution
637
- if ((s3 = * message = malloc (len + 1 ))) {
638
-
639
- * s3 = '\0' ;
640
- char_counter = 0 ;
641
-
642
- while ((c = comment [char_counter ++ ])) {
643
- if (c == '#' ) {
644
- char_counter -- ;
645
- if (read_parameter (comment , & char_counter , & value ) == Status_OK )
646
- strcat (s3 , trim_float (ftoa (value , ngc_float_decimals ())));
647
- else
648
- strcat (s3 , "N/A" );
649
- s3 = strchr (s3 , '\0' );
650
- } else {
651
- * s3 ++ = c ;
652
- * s3 = '\0' ;
653
- }
654
- }
655
- }
661
+ substitute_parameters (comment , message );
656
662
}
657
663
658
664
* comment = '\0' ; // Do not generate grbl.on_gcode_comment event!
0 commit comments