Silverfrost Forums

Welcome to our forums

Unexpected %ws behavior

21 Jun 2017 9:44 #19792

I am building a display dialog dynamically and ran across an odd behavior with %ws.

It would appear that the character string being output is first being truncated (using something like trim()) and then that result is being used and subjected to the width parameter for %ws. The code below will demonstrate this behavior.

As a temp fix, I am examining the last character being output and, if it is a blank, then using '%ws ' versus the simple '%ws'. Not a perfect fix, but workable for now.

	use mswin
	integer k
    character*40:: text1='Start of text',text2='end of text '
	k = winio@('%ww[topmost,no_maxminbox,no_sysmenu,independent]%fn[Courier New]%bg&',rgb@(255L,255L,255L)) ! very small border ! casts_shadow,topmost,thin_border,no_caption
	k = winio@('1::%ws::This is as expected, displayed=as selected%nl&',text1(1:13))
	k = winio@('2::%ws::This should have 80 characters between ::%nl&',text1)
	k = winio@('3::%13ws::As expected%nl&',text1(1:13))
	k = winio@('4::%14ws::As expected%nl&',text1(1:12))
	k = winio@('5::%-14ws::Not left justified%nl&',text1(1:14))
    k = winio@('6::%-12ws::Not left justified%nl&',text2(1:12))
    k = winio@('%bt[Done]')
    end
22 Jun 2017 4:40 #19799

I have made a note of this.

Is it possible to get what you want by other means?

%ws is based on the C function printf and %s but I think that the author of ClearWin+ assumed that trailing spaces in a Fortran character string ought to be removed.

At first glance I am not sure about the 'left justify'. Is this not what one would expect?

23 Jun 2017 1:02 #19801

Yes, my temporary fix will do fine, just not in the general case (specifically handles a single space at the end of a string).

I can try some other possible fixes.

As far as the left-justify, no. this is not what would be expected. Looking at the %lv control as an example, left-justified text would never have a space at the front, unless one was in the string to begin with.

23 Jun 2017 1:07 #19802

I can 'fool' it by placing a CHAR(0) at the end of the string to be output, thus forcing the issue.

   use mswin 
   integer k 
    character*40:: text1='Start of text',text2='end of text ' 
   k = winio@('%ww[topmost,no_maxminbox,no_sysmenu,independent]%fn[Courier New]%bg&',rgb@(255L,255L,255L)) ! very small border ! casts_shadow,topmost,thin_border,no_caption 
   k = winio@('1::%ws::This is as expected, displayed=as selected%nl&',text1(1:13)) 
   k = winio@('2::%ws::This should have 80 characters between ::%nl&',text1) 
   k = winio@('3::%13ws::As expected%nl&',text1(1:13)) 
   k = winio@('4::%14ws::As expected%nl&',text1(1:12)) 
   k = winio@('5::%-14ws::Not left justified%nl&',text1(1:14)) 
   k = winio@('6::%-12ws::Not left justified%nl&',text2(1:12)) 
   k = winio@('7::%-14ws::Not left justified%nl&',text1(1:16)//char(0)) 
   k = winio@('8::%-12ws::Not left justified%nl&',text2(1:14)//char(0)) 
    k = winio@('%bt[Done]') 
    end 

The newly added 7 and 8 examples respond exactly as expected because the width specifier is the minimum size.

Please login to reply.