Old 1st August 2018, 01:41   #1
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Question break line control

Hi everyone
ive been experimenting with blank/break line control,
the goal is to parse a file prior to editing to assure consistent spacing between data blocks,
the data blocks are just some text instructions in segments separated by a line break or sometimes two or more,

i want create a unified 2 line break between each block,

i thought a simple search and replace for "$\r$\n" replacing with "$\r$\n$\r$\n"
and than passing again replacing "$\r$\n$\r$\n$\r$\n" with "$\r$\n$\r$\n"
should do the trick; but as i found out i was wrong

any suggestion how i should go about it?

TIA
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 1st August 2018, 01:55   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
Are you editing in-place or from one file to another?

I would do it in one pass, add if needed and ignore if too many when writing to the other file.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 1st August 2018, 02:00   #3
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thank you Anders <3
yes i am appending in place,

im currently having a hard time capturing the pattern of two line breaks,
atm my attempts only add never subtract

ATB
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 1st August 2018, 09:31   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
I would recommend that you write to a temp file instead, in-place editing is much harder.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 1st August 2018, 17:28   #5
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thumbs up

Thank you Anders <3


ATB
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 3rd August 2018, 07:09   #6
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
even from one file to another still no go
i can only replace a single line but not two,
as soon as the second line comes to play the it cant be found,
when only capturing a single line; this basically closes all gaps,

any advice?

TIA
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 3rd August 2018, 09:55   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
Are you keeping a count of empty lines in your loop? And reset the count when you hit a non-empty line?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd August 2018, 10:04   #8
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Red face

i am not; this is my last attempt which delete all spaces,

PHP Code:
Section

ClearErrors
FileOpen 
$"test.txt" "r"
GetTempFileName $R0
FileOpen 
$1 $R0 "w"
loop:
   
FileRead $$2
   IfErrors done

   StrCmp 
$"$\r$\n" +2
      StrCpy 
$""
   
FileWrite $$2
   
Goto loop

done
:
   
FileClose $0
   FileClose 
$1
   Delete 
"test.txt"
   
CopyFiles /SILENT $R0 "test.txt"
   
Delete $R0

SectionEnd 

ATB
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 3rd August 2018, 21:02   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
PHP Code:
Section
FileOpen 
$"test.txt" "w"
FileWrite $"Hello$\r$\n"
FileWrite $"World$\r$\n"
FileWrite $"$\r$\n"
FileWrite $"One$\r$\n"
FileWrite $"Two$\r$\n$\r$\n"
FileWrite $"333$\r$\n$\r$\n$\r$\n"
FileWrite $"EOF$\r$\n"
FileClose $0

ClearErrors
FileOpen 
$"test.txt" "r"
GetTempFileName $R0
FileOpen 
$1 $R0 "w"
loop:
   
FileRead $$2
   IfErrors done
   
   
${If} $!= "$\r$\n"
   
${AndIf} $!= "$\r"
   
${AndIf} $!= "$\n"
      
FileWrite $$2
      FileWrite 
$"$\r$\n"
   
${EndIf}
   Goto 
loop

done
:
   
FileClose $0
   FileClose 
$1
   Delete 
"test.txt"
   
CopyFiles /SILENT $R0 "test.txt"
   
Delete $R0
   ExecShellWait 
"" "test.txt"
   
Delete "test.txt"

SectionEnd 
?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 3rd August 2018, 21:34   #10
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thank you Anders <3

it doesn't seem to like the first loop ${If},
i changed to !If and it moved on to not liking the next ${AndIf}

Edit:
adding !include LogicLib.nsh fixed the stop above,
trying to figure out why its now stopping here ExecShellWait "" "test.txt"

ATB
Chris
MyPC8MyBrain is offline   Reply With Quote
Old 3rd August 2018, 22:18   #11
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thumbs up

YaY \ o / its working

i bow to your expertise Master <3

TIA
Chris

Last edited by MyPC8MyBrain; 4th August 2018 at 00:00.
MyPC8MyBrain is offline   Reply With Quote
Old 4th August 2018, 01:29   #12
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
Quote:
Originally Posted by MyPC8MyBrain View Post
trying to figure out why its now stopping here ExecShellWait "" "test.txt"
This only works in recent NSIS v3.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 4th August 2018, 01:41   #13
MyPC8MyBrain
Member
 
Join Date: Nov 2015
Posts: 96
Thumbs up

adding both
PHP Code:
!include LogicLib.nsh
!include StdUtils.nsh 
and changing from
PHP Code:
   ExecShellWait "" "test.txt" 
to
PHP Code:
   StdUtils::ExecShellWait "" "test.txt" 
had your code working fully (custom build based 3.02)

i ended with commenting out last two lines as the last deletes our file and the one before kept giving me error,
something about "this file has no handle" or something,

PHP Code:
   #ExecShellWait "" "test.txt" 
   #Delete "test.txt" 
ATB
Chris
MyPC8MyBrain is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump