File tree Expand file tree Collapse file tree 1 file changed +39
-3
lines changed Expand file tree Collapse file tree 1 file changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -595,13 +595,49 @@ char *gc_normalize_block (char *block, char **message)
595
595
size_t len = s1 - comment - 4 ;
596
596
597
597
if (message && * message == NULL && !strncmp (comment , "(MSG," , 5 ) && (* message = malloc (len ))) {
598
+ float value ;
599
+ char * s3 ;
600
+ uint_fast8_t char_counter = 0 ;
601
+
602
+ len = 0 ;
598
603
comment += 5 ;
604
+
599
605
// Trim leading spaces
600
- while (* comment == ' ' ) {
606
+ while (* comment == ' ' )
601
607
comment ++ ;
602
- len -- ;
608
+
609
+ // Calculate length of substituted string
610
+ while ((c = comment [char_counter ++ ])) {
611
+ if (c == '#' ) {
612
+ char_counter -- ;
613
+ if (read_parameter (comment , & char_counter , & value ) == Status_OK )
614
+ len += strlen (trim_float (ftoa (value , ngc_float_decimals ())));
615
+ else
616
+ len += 3 ; // "N/A"
617
+ } else
618
+ len ++ ;
619
+ }
620
+
621
+ // Perform substitution
622
+ if ((s3 = * message = malloc (len + 1 ))) {
623
+
624
+ * s3 = '\0' ;
625
+ char_counter = 0 ;
626
+
627
+ while ((c = comment [char_counter ++ ])) {
628
+ if (c == '#' ) {
629
+ char_counter -- ;
630
+ if (read_parameter (comment , & char_counter , & value ) == Status_OK )
631
+ strcat (s3 , trim_float (ftoa (value , ngc_float_decimals ())));
632
+ else
633
+ strcat (s3 , "N/A" );
634
+ s3 = strchr (s3 , '\0' );
635
+ } else {
636
+ * s3 ++ = c ;
637
+ * s3 = '\0' ;
638
+ }
639
+ }
603
640
}
604
- memcpy (* message , comment , len );
605
641
}
606
642
607
643
#if NGC_EXPRESSIONS_ENABLE
You can’t perform that action at this time.
0 commit comments