Interactive PowerBasic Forum

IT-Berater: Theo Gottwald (IT-Consultant) => Source Code and Discussions => Topic started by: Theo Gottwald on January 18, 2011, 07:58:28 AM

Title: Code-Formatter PB 10
Post by: Theo Gottwald on January 18, 2011, 07:58:28 AM
This is our first community project - a Code-Formatter for PB 9.
Of course it should be extended also to PB 10 immediately when its available.
But anyway - maybe its not yet perfect on your code?

Tweak it, and post the improved version and the List of changes you did.
Let's see if we can get this Project forward together.

Added: I Have changed the Title as it looksl ike that the Code-Formatter now is ready for PB 10.
I'LL also remove old versions now.
Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on May 07, 2011, 05:53:09 PM
Ok, here's my little contribution.

Added ability to split multiple Global/Local variables out to 1 per line and line up the AS info.
It could be expanded to handle DIM & STATIC but I wasn't worried about them.

Redid the TAB expansion as pointed out to me.

Think I semi-fixed the space problem with +=  -=  *=  OR=  AND= . They compile with a space
before the = but it just doesn't look right to me.

Not sure why the following got unfixed:
original at least 2 spaces on left

 s$ = $Title
  i = INSTR(s$, "(")
  s$ = LEFT$(s$, i - 1)
 Prgzqnam = s$


after no spaces on left

s$ = $TITLE
i = INSTR(s$, "(")
s$ = LEFT$(s$, i - 1)
Prgzqnam = s$


not sure if it matters but this is part of a Callback Function. reran original program and it does the
same output. so I didn't mess up something. just couldn't find out why.

05/09/2011  Please note: new zip is in message dated 05/09/2011. Small fixes.

Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on May 08, 2011, 05:19:59 PM
Found the problem but not the solution ( yet ).

It never allowed for Callback Function and thinks it's still in the middle of some construct which has
reset the indent level.

If someone else would care to handle this, I won't get upset.  ;)

Also noticed that "function" & "sub" are checked twice in a CASE statement. Should be fixed but
no hurry.

And if you figure out how to align the AS items of a Type that would be helpful.
Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on May 09, 2011, 07:15:11 PM
Fixed Callback Function not indenting the code of the function.

zip file updated as of 05/09/2011 01:09pm ( or around 7:10pm here ).

If you have downloaded the v2 zip from the previous message, you probably want this new one.

Not sure if I can delete it from the previous message or not.

Enjoy.
Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on June 21, 2011, 02:39:59 PM
Made some minor changes for v2a. Updated 6/21/2011 around 08:30am ( or 02:30pm here ).

Got Global/Regsiter/Dim/Local/Static all into 1 routine for splitting variables.

There are still some that I don't handle.
Multiple AS type on 1 line.
Multiple AS type  on line split with "_" on end.
Lines mixing old style ( w/ & ! $ ... ) on same lines with different AS type but this should show
up as compile error.

Am looking at Type/End Type to align the AS type. But this routine would also not really fit into
the way the program was originally structured.

Any  of the 18 who downloaded v2 should download v2a.
I'll see if I can remove v2 zip just to avoid confusion.

Any comments are welcome ( unless you're just going to yell at me  ;)  ).
   
Title: Re: Code-Formatter PB 9
Post by: Theo Gottwald on August 06, 2011, 07:11:46 AM
It should be adopted for PB 10, as I am only compiling with PB 10 actually.
Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on August 06, 2011, 12:05:11 PM
Theo,

If that last comment was to me, I'll have to pass. Don't have v10 and there doesn't seem like
there's much interest in my modifications.

Title: Re: Code-Formatter PB 9
Post by: Theo Gottwald on September 02, 2011, 07:55:47 AM
Paul, actually there is some interest (17 downloads is ok).
Also there are only some who like to contribute to the public, like Jose and others (we know their names).

Anyway let me recommend you PB 10. For me its the berst PB ever.
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 10, 2011, 06:07:37 AM
Ok, Peter Weiss made a PB 10 conversion as a next step!
If i understand Peter right, it eats now PB 10.
Testers welcome-

Thanks Peter!

(Attached file).
Title: Re: Code-Formatter PB 9
Post by: Peter Weis on November 10, 2011, 11:55:13 AM
Hi,
tests all come out, if something does not work tell me about it! :'(
regards Peter
Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on November 10, 2011, 04:04:10 PM
Sorry if I'm missing something but how does this new version handle PB 10?

Aside from the addition of a couple lines dealing with PBForms, I don't see anything new.
The MACROs are nice but it won't compile if you add %UNICODE = 1 before them.

Also won't there be a problem of passing BYREF w()  if it's defined as STRING
and the receiving function say BYREF w() as STRING or XSTRING?


Title: Re: Code-Formatter PB 9
Post by: Theo Gottwald on November 10, 2011, 04:25:28 PM
Paul, this is still "work in progress". If you want continue to contribute, you are welcome.
While at this time, maybe Peter is "on it" so it makes sense,  to wait until he says that he's done.
Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on November 10, 2011, 04:42:40 PM
Sorry, I guess I misunderstood what you meant by "it eats PB 10".

Frankly I couldn't understand why the program was adding UNICODE support for a source file.
The PB IDE/Compiler will only read ANSI text and not Unicode.

I'll wait for a higher version number before I test again.

Title: Re: Code-Formatter PB 9
Post by: Peter Weis on November 11, 2011, 09:23:36 AM
Hi Paul,
you are right when you say the source text is ANSI code. But to call the Windows API functions, it makes sense to work even with UNICODE.

Therefore, code with ANSI code.
API calls with Unicode.

I've changed it now so you can try it.

regards Peter
Title: Re: Code-Formatter PB 9
Post by: Norbert Spoerl on November 11, 2011, 11:44:19 AM
Hello Peter


I've tried the formatter. In principle it works. I like some of the results of the  structure not to 100%.

In addition I have the following questions.
Why do you want to have the opportunity to make the code to a DLL (your reference to global variables). Who should use it? I would prefer a good user interface. Selection of options for formatting, the benefit of the clipboard. Specifying a filename to save the formatted text. I find it problematic when the old source code is simply overwritten.


Greetings
Title: Re: Code-Formatter PB 9
Post by: Peter Weis on November 11, 2011, 01:32:43 PM
Hello Norbert,

I already turn a surface for the program to write. But only had time for the program are the core! The old file is not deleted but stored as a file Bak.

regards Peter
Title: Re: Code-Formatter PB 9
Post by: Norbert Spoerl on November 11, 2011, 03:09:10 PM
Hello Peter


that with the BAK I have not noticed, as previously there was already a BAK with the same name.

Because the surface - I might do something about it. But I have no problem with global variables, and would that use with.


Have a nice weekend!

Title: Re: Code-Formatter PB 9
Post by: Norbert Spoerl on November 14, 2011, 08:31:36 AM
I think PBNote2.bas from ...\Samples\SDK is a good start for a frame and surface. But at last weekend, I had no time for it.
Title: Re: Code-Formatter PB 9
Post by: Larry Charlton on November 14, 2011, 01:25:24 PM
Needs a small update for properties.  What's interesting is one of those looks right.

        Property Get Value() As String
            Property = value_
            End Property
            Property Set Value(value As String)
                value_ = value
            End Property

            Property Get ColorSize() As Long
                Property = colorSize_
                End Property
                Property Set ColorSize(ByVal value As Long)
                    colorSize_ = value
                End Property

                Property Get ColorIsRound() As Long


Commenting out line 536 seemed to fix the problem.

Construct( "PROPERTY", "END PROPERTY")

I liked the option of specifying the file on the command line or else getting an open file dialog.  Would be nice if I could enter multiple files or select multiple files.

Also saw the note about the settings being hardcoded for demo purposes.  Would be nice if those values were constants at the top of the program, it would make changing them until there's an alternative way, just a bit easier.

Probably too much effort but might be nice if one of the options was lower, upper, or mixed case PB keywords similar to the IDE.

I see you can split global/local variables, might be nice to have a pack global/local variables also

Along those lines, making three line IF THEN's, 1 line, or making 1 line IF THEN's 3 lines might be a nice option as well.

Removing extra blank lines (if there are two or more consecutive blank lines)

Also same for Case condition: statement
to
Case condition
    statement

Also statement:statement:statement to multi-line might be nice

Inserting blank lines (maybe before multi-line constructs, after Dim/local/global/instance line sets)

Flipping !, ', and ? back to REM, ASM, and PRINT might be a nice option

Adding or removing the [RE]DIM x(xxx) AS Instance/Global/Local Type might be nice.

It's a nice program as is, I was just thinking about the things I never did when writing a similar program.  Also while there are 3 or 4 source code formatters on the PB forums, might be nice to post or link from there.
Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on November 14, 2011, 02:59:01 PM
Larry,

I think it needs an update to handle Class and all that goes with that.
Seems to have a problem with Interface and End Interface and having
Method declares (?) between.

I don't know how to do Class code and don't want to start making changes
in the middle of code when someone else is already working on it.

I'm wondering if the problem you show has to do with the underline on the end.
Try adding something after it ( maybe even a remark ) just to see if it resets the
indentation back to where it should.

I took your test.bas from GDIPlus project and copied all the #Includes to the end of it.
Ran that thru the formatter and it started indenting at Interface IStream Guid$(.... and
never really reset to the left ( except for the constants which it did put in column 1 ).
By the way, what did you have the tab size set at? Was it 8?


Title: Re: Code-Formatter PB 9
Post by: Peter Weis on November 14, 2011, 04:08:37 PM
Hi Paul,

I'm glad that you like to do something. I am currently working on the dialogue to set the options and file names, and I'm still busy two days. If you want to do something at the core format. Feel free to you and do it! I have since the last release, no longer made ​​in this core!

regards Peter
Title: Re: Code-Formatter PB 9
Post by: Paul Elliott on November 14, 2011, 08:40:29 PM
Ok. I did a few things to format Class code a little better.
It may not be perfect but it works on Larry's GDIPlus project.

I renamed this to Code-Formatter v2c just to keep the different versions seperate.

Sorry it took so long but it took me a LONG time to remember that the formatting routine
only gets fed 1 line at a time. I had to move my inClass variable out of that function and
I put it in the fo UDT for convenience.

Hope I didn't mess up any other part. Tested with PB Win v10.
Title: Re: Code-Formatter PB 9
Post by: Peter Weis on November 14, 2011, 09:07:15 PM
Hi Paul,
  Thank you for your efforts. :) I will install it. I fucked up today have found that Phoenix had made ​​a mistake. Then I hand-written file Form.frm and have destroyed my dialogue! I could annoy me so! The program went so well. Was on target. And now, three days' work for the cat!  >:( But I get the point again!
regards Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 15, 2011, 08:04:42 AM
Hallo Peter,

did i get this right, this is yourfinal version, anybody else can now test it and
start adding to the project by changing the code?
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 15, 2011, 12:54:07 PM
Theo,

You're confusing me.

Did you see an attachment in Peter's latest post that I didn't?   ???

He had said before that he was working on the GUI for setting options and getting files to work on.
And that it was okay for me to see if I could fix the code dealing with Class. That's all I did.
I worked from the archive that he had previously posted.

As I inderstood his last post, there was a problem on his computer with Phoenix and he lost the work
he had done on the GUI. But he is working to re-create it.

Title: Re: Code-Formatter PB 10
Post by: Norbert Spoerl on November 15, 2011, 02:38:25 PM
Hello

This

  l_style_listbox       = %WS_CHILD OR %WS_VISIBLE OR %WS_VSCROLL OR %WS_TABSTOP OR _
                          %LBS_OWNERDRAWFIXED OR %LBS_HASSTRINGS OR %LBS_NOTIFY  'OR %LBS_NOINTEGRALHEIGHT

is after the formatting that.

l_style_listbox = %WS_CHILD OR %WS_VISIBLE OR %WS_VSCROLL OR %WS_TABSTOP OR _
'OR %LBS_NOINTEGRALHEIGHT
%LBS_OWNERDRAWFIXED OR %LBS_HASSTRINGS OR %LBS_NOTIFY

The code is too complex for me. I do not find personally the right place, to be able to undertake a change.

Regards
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 15, 2011, 02:54:44 PM
Norbert,

I admit that some of the adjustments need either some work or another option.

** just ignore the part about fo.lineupequates .... I didn't search far enough
**  but the part about length of line & fo.remcol is good
What happens if you set fo.lineupequates = 0  ?  With it set to 1 the program tries to put
any trailing comments at fo.remcol. If the line is already past that point it puts it on a new line.

A new choice might be to indent continuation lines. And if the first line has an equal sign  then
line up the following lines indented at least past the equal sign.

One of the considerations for modifications is that the program doesn't have any real Global
variables. Any change like the above will need either Global variables or additions to the fo UDT
( such as I did for inClass ) or maybe a new UDT that will hold line status information that needs
to be saved between input lines and passed back/forth between routines.

Just my thoughts and maybe Peter has better choices.    :-\

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 15, 2011, 05:50:59 PM
I am also confussed :-) . Who is actually working on it and who has the final version ?
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 15, 2011, 07:09:31 PM
If you start with the post by Larry Charlton on the 14th  you'll see that I then said where the problem
could be but didn't want to make changes when someone else was working on it.

Peter said he was working on the GUI and it was ok if I made changes to the core code.

I did and posted v2c ( based on Peter's v2a which I consider v2b ).
I only added 1 variable to the fo UDT and made changes to some of the rebuild function.

Peter then said he would take the code I posted. He said that he had an accident earlier in the day
and lost GUI code that he had worked on. But he was recreating it. This accident had to have happened
before I posted v2c as I changed the BAS file name and shouldn't have been able to cause any
trouble.

So, unless there is something that Peter wants me to help with,  Peter has the code and is working
on getting the GUI in place with the rest of the code.


Clear?

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 15, 2011, 07:39:21 PM
Hello,
Have written on my user interface. Despite that yesterday I had a total failure, they will again have the following problem identified during the formatting is not in me but!

original code

hWndChild = CreateWindowEx(%NULL, _                                             ' extended styles
                                 "SysTabControl32", _                                 ' class name
                                 "", _                                                ' caption
                                 %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR _           ' window styles
                                 %WS_TABSTOP OR _
                                 %TCS_TABS OR %TCS_SINGLELINE OR _                    ' class styles
                                 %TCS_RAGGEDRIGHT, _
                                 11, 18, _                                            ' left, top
                                 489, 303, _                                          ' width, height
                                 hWnd, %IDC_FORM1_TAB1, _                             ' handle of parent, control ID
                                 ghInstance, BYVAL %NULL)                             ' handle of instance, creation parameters
      SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE
       

Formatted code

hWndChild = CreateWindowEx(%NULL, _  ' extended styles
            "SysTabControl32", _                 ' class name
            "", _                                ' caption
            ' window styles
            %WS_CHILD OR %WS_VISIBLE OR %WS_GROUP OR _
            %WS_TABSTOP OR _
            %TCS_TABS OR %TCS_SINGLELINE OR _    ' class styles
            %TCS_RAGGEDRIGHT, _
            11, 18, _                            ' left, top
            489, 303, _                          ' width, height
            hWnd, %IDC_FORM1_TAB1, _             ' handle of parent, control ID
            ghInstance, BYVAL %NULL)             ' handle of instance, creation parameters
            SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE
                                                             


The code after formatting not only looks terrible, and still has an error, it does not compile anymore


     
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 15, 2011, 08:41:05 PM
Peter,

Yes, I agree that it does look ugly but that's what the original code produces.

It's moving the trailing remark to a new line but not taking into account that it is in the middle
of a bunch of continuation lines.

Increase fo.remcol by 15 to 20 and it should at least compile.

The code that produces this is

  IF LEN(comment) THEN
      IF LEN(stemp) < fo.remcol THEN
         stemp = LEFT$(stemp + SPACE$(fo.RemCol - 1), fo.RemCol - 1) + comment
      ELSE
         w(0) = SPACE$(fo.indent) + comment
      END IF
   END IF 


which is at the end of Function RebuildLine.

It might be easiest to just append the comment even if beyond the remcol.
The choice can be yours but if you change it then do it in all places.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 15, 2011, 08:58:38 PM
Peter,

CONGRATULATIONS!!!!!!!   IT COMPILES AND IT WORKS!!!!

Now for the little nit-picking things (  that you are probably already working on  )
1) some kind of option for different language on buttons.
2) put a progress bar on your form instead of that pop-up.
3) add inClass as long to formsoption UDT and use the Function RebuildLine from v2c that I posted.
I don't think I changed anything outside that function.
4) increase version number.

Haven't tried saving/loading options yet.

Once again, Congratulations.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 15, 2011, 09:02:25 PM
Looks like we'll soon have a good "Pretty Printer for PB 10" as our first community project.

Let's stay together and make more projects.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 15, 2011, 09:02:30 PM
Hi Paul,

What have you changed just let me know! So I can include it in my'm still busy with the IDE and have little time right now! Four things must change

Once the time stamp for files Bak

Call for the output file

And you can call it from another program with call

Secondly, I want to put the ProgressBar in the StatusBar

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 15, 2011, 09:06:40 PM
Hi Theo,
That's what we do hope that it will end well who do we work together
regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 16, 2011, 01:59:33 AM
Peter,

Aha! You snuck an update in while I was trying to remember how to set up Phoenix.

Still looking good.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 16, 2011, 05:52:13 PM
Hello,
small update

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 16, 2011, 06:53:26 PM
Peter,

A small suggestion.  Put comments at the top of the BAS file ( and maybe the FRM/INC ) as to
date/time updated and major changes.  Seems that Phoenix is updating the date/time stamp
on all files even if no changes made. Maybe even upping the version by .1 or .01 each time
you post a new archive.

Just so that we can tell we're all using the same version of the program & sources.
By the way, what is your time compared to the time at this forum?
For me, the forum is 6 hours ahead.

Thanks.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 16, 2011, 08:22:07 PM
Hello,
I just grabbed the folder, and because the order "CodeFormatter PB9 v2a" means the name is born!

I now only the error of the output file button changed


FUNCTION Form1_TextBtnOutoutFile_Clicked _
  ( _
  BYVAL hWndParent  AS DWORD, _ ' handle of parent window
  BYVAL hWndCtrl    AS DWORD _  ' handle of control
  ) AS LONG
  DISPLAY OpenFile hWndParent, 0, 0, "Format Powerbasic Code", "", _
      CHR$( "Basic Source [BAS, INC]", 0, "*.BAS;*.INC", 0), _
      "", "", %OFN_FILEMUSTEXIST TO fo.fspecout
  IF LEN(fo.fspecout) <> 0 THEN

    zSetCTLText(GetDlgItem(hWndParent, %IDC_FORM1_EDIT_FILE_OUTPUT), fo.fspecout)
    Control_Enable GetDlgItem (mainhWnd, %IDC_FORM1_TEXTBTNFORMAT)

  END IF

END FUNCTION





regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 16, 2011, 08:51:25 PM
Hello,
again little change.



FUNCTION Form1_TextBtnOutoutFile_Clicked _
  ( _
  BYVAL hWndParent  AS DWORD, _ ' handle of parent window
  BYVAL hWndCtrl    AS DWORD _  ' handle of control
  ) AS LONG
  DISPLAY OpenFile hWndParent, 0, 0, "Format Powerbasic Code", "", _
      CHR$( "Basic Source [BAS, INC]", 0, "*.BAS;*.INC", 0), _
      "", "", %OFN_FILEMUSTEXIST TO fo.fspecout
  IF LEN(fo.fspecout) <> 0 THEN

    zSetCTLText(GetDlgItem(hWndParent, %IDC_FORM1_EDIT_FILE_OUTPUT), fo.fspecout)
    IF LEN(fo.fspecin) THEN
      Control_Enable GetDlgItem (mainhWnd, %IDC_FORM1_TEXTBTNFORMAT)
    ELSE
      Control_Disable GetDlgItem (mainhWnd, %IDC_FORM1_TEXTBTNFORMAT) 
    END IF
  END IF

END FUNCTION



regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 16, 2011, 09:08:38 PM
Peter,

You do know you can easily change the directory name with Explorer? Just click then press F2.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 16, 2011, 09:38:46 PM
Hi Paul,
that's true and that's what I know. But then I have to look for the PHOENIX project again, whom I would like to open it.

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 17, 2011, 12:38:02 AM
Peter,

Finding the project in the new directory is a simple matter and only needs to be done once.
I setup a project in Phoenix for this & added the files/forms and moved the whole thing
3 times so far. Easy and I haven't used Phoenix  in around 4 years.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 17, 2011, 01:22:00 AM
Peter,

Back on a previous note, I added 6 lines to allow easy changing of text on the page 1 buttons.

Before PHNX_BEGIN_CONSTANTS


$TEXTBTN3      = "&Help"
$TEXTBTNFORMAT = "&Format"
$CANCEL        = "E&xit"


and down around line #770 or so where you create the 3 buttons
put 1 line of code after you set the font ( 1 for each button )


      SetWindowText hWndChild, $TEXTBTN3
      SetWindowText hWndChild, $TEXTBTNFORMAT
      SetWindowText hWndChild, $CANCEL


That way you can easily change the button labels for different languages.
Even though you did use English for all the rest of buttons & labels & such.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 17, 2011, 08:55:01 AM
Quote from: Jim Dunn on November 16, 2011, 07:10:34 PM
And the most recent file says "v2a"... but 3 posts back it says "v2d"...

Which is the latest?

Yes, and maybe can you also change the name in "Codeformatter PB 10"?
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 17, 2011, 04:53:55 PM
Hello,
have now added a new button to do so. Auserd I have some things changed in the source code

Hi Paul can not do that in line 770 as the Phoenix overwrites

      SetWindowText hWndChild, $TEXTBTN3
      SetWindowText hWndChild, $TEXTBTNFORMAT
      SetWindowText hWndChild, $CANCEL




It had the added in Form1.inc


FUNCTION Form1_OnCreate _
  ( _
  BYVAL hWnd        AS DWORD, _ ' window handle
  BYVAL lptcs       AS DWORD, _ ' address of CREATESTRUCT structure
        lMsgResult  AS LONG _   ' value returned to message
  ) AS LONG
  IF LEN(fo.fspecin)= 0 OR LEN(fo.fspecout) = 0 THEN
    Control_Disable GetDlgItem (hWnd, %IDC_FORM1_TEXTBTNFORMAT)

  END IF

  SetWindowText GetDlgItem(hWnd, %IDC_FORM1_TEXTBTN3), $TEXTBTN3
  SetWindowText GetDlgItem(hWnd, %IDC_FORM1_TEXTBTNFORMAT), $TEXTBTNFORMAT
  SetWindowText GetDlgItem(hWnd, %IDCANCEL), $CANCEL



END FUNCTION


regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 17, 2011, 05:11:28 PM
Peter,

Ok, I thought there was a better/different way but couldn't think of it at the time.
I didn't remember which parts Phoenix overwrites and which parts are user changeable.

Your way is better and opens up the possiblilty to redo ALL the buttons/labels in other languages
if you want to.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 17, 2011, 07:20:56 PM
Hello,
've done something a little more fine tuning.
Program have donated an icon, I've also removed minor bugs in the program.



regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 17, 2011, 08:07:30 PM
Peter,

I'm seeing something odd in the output file.

No matter which bak option I choose the program doesn't create a bak in my specified directory.
It is ignoring my output directory & file name. Keeps saying that it can't find the file.
Who cares? This file will be WRITTEN.

But it keeps overwriting my input file with the formatted output.
And with it NOT creating a backup  there is a chance that my input file will be lost.

Just found over 60 fmt*.tmp files in my TEMP directory. Why are they still there?




Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 17, 2011, 08:13:35 PM
Hello Paul
I also do not like the formatting to 100%, but I can not break, and work simultaneously on one hundred sites. Times tomorrow would only do it with Bak file with time stamp. Was hoping you can help me a bit! Because the formatting is still a huge mistake that I have described two days ago in Forum

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 17, 2011, 08:20:20 PM
I have not noticed because the temporary file will look but the morning after

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 17, 2011, 08:41:13 PM
Something very odd going on here ( maybe some setup on my computer but no clue what  ).

I can not get a msgbox or messagebox to display.
as in
msgbox "some message"
or
MessageBox %NULL,"backup of " & fo.fspecin, "bkup", %MB_OK

I've tried both right after backing up ( remarked out the IF so it always does it )
and after opening for output.
Nothing shows.

Will switch back to PB WINApi to see if it changes.


Nope, not a hint of a messagebox on screen either way.
Very strange.


Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 17, 2011, 08:47:33 PM
Try adding %MB_TOPMOST to the flags. Maybe that solves your problem :-).
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 17, 2011, 09:22:32 PM
Found at least part of the problem.

I was looking in the main BAS file where the DoFormat function is called.

BUT it is also called from over in Form1.inc under a button click.

Plus the file names are set & reset & reset & set to the other all over the place.

Sorry but I am NOT debugging this.  I will wait on Peter to straighten it out.
Too many options and I'm tired ( been up 12 hours already today ).

I'll check back in tomorrow.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 18, 2011, 12:51:13 PM
Peter,

Sorry about the nasty last response. I was tired and it had not been a good day.

I'll help as much as I can. It would help if you start putting modification comments at the beginning
of the source ( at least the main BAS but the form1.inc would be a good place also).

Now would be a good time to create a 2nd UDT with the variables needed to handle formatting
between the lines and the handles that are not user modifiable. If it's not on your user entry
pages then move it to this 2nd UDT. No need to save this 2nd UDT. BUT please zero it out when
entering DoFormat so you can run multiple files in 1 run of the program.

And somewhere in there, it would clean things up if you delete the temp file after you copy it to
the OUTPUT file name. It's not needed any more at that point.


I need to find a better source file comparer. I've been using ExamDiff but it's having problems
syncing up when there are lots of changes. Maybe I'll have to check on a source-code-control
system. No sure yet.

Title: Re: Code-Formatter PB 10
Post by: Norbert Spoerl on November 18, 2011, 02:29:28 PM
Hello Paul,

>>>
I need to find a better source file comparer.
<<<
-> http://kdiff3.sourceforge.net/ (http://kdiff3.sourceforge.net/)

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 18, 2011, 03:28:07 PM
Norbert,

Thanks. I like it and it syncs up much better than others that I've tried.

I had made many changes to field names and re-arranged the UDT and changed several routines
and it made the changes appear with no problem.

I think I'll uninstall the 2 others that are on my system and just use this one.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 18, 2011, 05:31:04 PM
Hello,
Today I've since added the following resolved problem Bak function!



SUB CopyBak()
  LOCAL p, f, fout, d, t AS STRING

  f = PATHNAME$(NAME, fo.fspecin)
  IF fo.backup THEN
    IF fo.backupTimeStamp = 0 THEN
       p = PATHNAME$(PATH, fo.fspecin)
       fout = p + f + ".BAK"

        CopyFile fo.fspecin, (fout), 0
       ELSE
         p = PATHNAME$(PATH, fo.fspecin) + "BAK"
         IF ISFOLDER(p) = 0 THEN
            MKDIR p
            p = p + "\"
         END IF
         d = Built.DateString
         REPLACE "." WITH "_" IN d
         t = Built.TimeString
         REPLACE ":" WITH "_" IN t
                 
         CopyFile fo.fspecin, p + "\" + f + "_"+ d + " " + t + " .BAK", 0


       END IF
   END IF
END SUB


Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 18, 2011, 06:26:29 PM
Halo Paul,
  but you wanted to help me or something, DoFormat still needs many improvements
regards Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 18, 2011, 06:48:44 PM
Hallo Peter,

du hast ein Code angehängt. Arbeitet da jetzt noch jemand dran oder ist das erstmal dein Endstand?

Is actually somebody working on the Code or do we have some soert of FINAL?
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 18, 2011, 06:58:48 PM
Peter,

If you change the code that copies the tmp file to copy it to the OUTPUT file ( not the INPUT file )
then you only need to create a BAK if the user put the same file name on BOTH file names.
And don't forget to delete the tmp file.

in your
FUNCTION Form1_TextBtnOutoutFile_Clicked _
this code needs changed

  DISPLAY OpenFile hWndParent, 0, 0, "Format Powerbasic Code", "", _
      CHR$( "Basic Source [BAS, INC]", 0, "*.BAS;*.INC", 0), _
      "", "", %OFN_FILEMUSTEXIST TO fo.fspecout
  IF LEN(fo.fspecout) <> 0 THEN



should be


  DISPLAY OpenFile hWndParent, 0, 0, "Format Powerbasic Code", "", _
      CHR$( "Basic Source [BAS, INC]", 0, "*.BAS;*.INC", 0), _
      "", "", %OFN_CREATEPROMPT OR %OFN_NOTESTFILECREATE TO fo.fspecout
  IF LEN(fo.fspecout) <> 0 THEN



otherwise you can't create a NEW output file. and you might want to allow any extension.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 18, 2011, 07:41:41 PM
Hi Theo,
'm not finished yet! Work of course it again. Wants to change but still so much to the program!

Let it not be my job! What I do I even begin to end

I thinking that Paul may participate

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 18, 2011, 07:50:00 PM
Hi Paul,
I thinking that it can overwrite another file. Moreover, everything is overwritten with Form1_TextBtn_InputFile_Clicked


FUNCTION Form1_TextBtn_InputFile_Clicked _
  ( _
  BYVAL hWndParent  AS DWORD, _ ' handle of parent window
  BYVAL hWndCtrl    AS DWORD _  ' handle of control
  ) AS LONG

  DISPLAY OpenFile hWndParent, 0, 0, "Format Powerbasic Code", "", _
      CHR$( "Basic Source [BAS, INC]", 0, "*.BAS;*.INC", 0), _
      "", "", %OFN_FILEMUSTEXIST TO fo.fspecin
  IF LEN(fo.fspecin) <> 0 THEN
    zSetCTLText(GetDlgItem(hWndParent, %IDC_FORM1_EDIT_FILE_INPUT), fo.fspecin)
    zSetCTLText(GetDlgItem(hWndParent, %IDC_FORM1_EDIT_FILE_OUTPUT), fo.fspecin)
    Control_Enable GetDlgItem (mainhWnd, %IDC_FORM1_TEXTBTNFORMAT)
    fo.fspecout = fo.fspecin
  END IF
END FUNCTION




regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 18, 2011, 08:08:41 PM
Peter,

Yes, that last line

fo.fspecout = fo.fspecin

has no reason to be there else why have 2 file names.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 18, 2011, 08:26:18 PM
Hi Paul,
I just tried it and you have not the right thing works as I had imagined! The file is not overwritten as I had imagined!

Does it matter!


GetTempPath %MAX_PATH, ztext
   GetTempFileName ztext, "fmt", 0, fo.fspecout
   fo.fhin = FREEFILE
   OPEN fo.fspecin FOR INPUT ACCESS READ AS fo.fhin
   fo.fhout = FREEFILE
   OPEN fo.fspecout FOR OUTPUT AS fo.fhout
   '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   'Create a simple progress control
   '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fo.hprogress = CaptionProgressWindow(0, "Format Source Code")
   DoFormat BYVAL VARPTR(fo)
   CLOSE fo.fhin, fo.fhout
   DestroyWindow fo.hprogress
   CopyFile fo.fspecout, fo.fspecin, 0


Thus, the file will always overwrite fo.fspecin. Let me think because what

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 18, 2011, 08:30:16 PM
Because somewhere in all those routines,  the tmp file name is being put in fo.fspecout.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 18, 2011, 08:38:08 PM
Let's sleep on it! Already find a solution! or you have an idea
fo.fspecout is a file Temporärere

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 18, 2011, 09:24:08 PM
I added a zOut variable to hold the tmp file name. Opened it as OUT and used it to copy to
fo.fspecout and did KILL zOut to remove file.

I hesitate to upload the files I've changed because of this being in Phoenix it is not as easy as making
a new directory & unpacking. And it is extremely easy to overwrite a file that wasn't meant to be
over-written ( I know as I've done it A LOT ).  And you might not like the changes ( especially the
naming changes ) but they made it easier for me to understand the form & variables.

Maybe I'll upload some things in the morning.

Good Night.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 18, 2011, 09:34:42 PM
Hi Paul,
send me or upload it there! I want to watch it! :)

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 19, 2011, 07:02:50 AM
Hi Peter,

Ok, attached is a zip with only 4 files.
Code Formatter.bas
Form1.frm
Form1.inc
Code Formatter.cfg

Save a copy of your version of these files.  Please be careful when unpacking it.
The CFG file has changed format and I haven't put in code to ignore older versions.

I made a new UDT with the variables that are not user adjustable. Most are needed to hold
values that permit multi-line formatting. The UDTs are NOT passed BYREF from function to
function. They are GLOBAL as they are needed in places that it is not easy to pass them.
The new UDT is cleared only on the Format button click.

I added a few comments to the top of the BAS file and added a date on some of the lines
I changed.
One of the changes deals with the ending comment of a line. Now if it would start past the
remcolumn position, I add tabsize spaces and append it to the line. It shouldn't show up
on a line by itself any more.

If you okay my changes then give me a list of what you want fixed in the formatting and
I'll try to do them. But I may not be able to or other people may be able to do them
better.

Have fun with it.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 19, 2011, 06:48:23 PM
Hi Paul good work! Works very well now!
But you have deleted from the function CodeFormatter_InitApplication these lines. The need to stay tuned!


  GetTempPath %MAX_PATH, ztext
   GetTempFileName ztext, "fmt", 0, zOut ' 11/18/2011 fo.fspecout
   fc.fhin = FREEFILE
   OPEN fo.fspecin FOR INPUT ACCESS READ AS fc.fhin
   fc.fhout = FREEFILE
   OPEN zOut FOR OUTPUT AS fc.fhout
   '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   'Create a simple progress control
   '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fc.hprogress = CaptionProgressWindow(0, "Format Source Code")
   DoFormat
   CLOSE fc.fhin, fc.fhout
   DestroyWindow fc.hprogress
   CopyFile zOut, fo.fspecout, 0
   KILL zOut
   FUNCTION = %TRUE


regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 19, 2011, 07:06:09 PM
No, you had moved it to Function Form1_Btn_Format_Clicked.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 19, 2011, 08:27:41 PM
Peter,

See my posts #52 & #54.  I had tried the code there but it didn't get executed.
Plus the code you put there doesn't match what Phoenix says should be there.
So I removed the excess code.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 19, 2011, 09:50:58 PM
Peter,

Still more strangeness.
In the InitApplication,
if %UNICODE is defined you get the command line but the program then ends right there.
if %UNICODE NOT defined  you get only the 1st char & file not found & program ends.

In CopyBak doing a date/time stamp you don't allow for "/" in date. Also the program ends
after making the copy.

Just more fun fun fun.    ;D

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 19, 2011, 11:20:51 PM
Peter,


More fun info.  Don't have Phoenix registered on this computer so I'm running from PB IDE.

If %UNICODE = 1 then it stops at the end of this saying it could not create form1 window


   ' Create the Form1 window
   hWnd = CreateWindowEx(%NULL, _                                                      ' extended styles
                         "Form1_Class", _                                              ' class name
                         "Code Formatter PB 10 v3e", _                                 ' caption
                         %WS_OVERLAPPED OR %WS_MINIMIZE OR %WS_VISIBLE OR _            ' window styles
                         %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, _
                         223, 170, _                                                   ' left, top
                         520, 445, _                                                   ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters
   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      MSGBOX "could not create form1 window"
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF
             


Any suggestions? I tried adding $$ to the string literals here but no luck.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 19, 2011, 11:21:36 PM
Hi Paul,

QuoteSee my posts #52 & #54.  I had tried the code there but it didn't get executed.
Plus the code you put there doesn't match what Phoenix says should be there.
So I removed the excess code.

The code is not superfluous, he is bulged whom a file is passed in the command. Then the dialogue should not be executed


Quote
Still more strangeness.
In the InitApplication,
if %UNICODE is defined you get the command line but the program then ends right there.
if %UNICODE NOT defined  you get only the 1st char & file not found & program ends.

You currently do not you allowed to use Unicode, since Phoenix is not able to cope. Only when the program is fully programmed. Then strings are XSTRING, and all through ASCIZ XASCIZ functions replaced in Phoenix, then it goes again

Quote
In CopyBak doing a date/time stamp you don't allow for "/" in date. Also the program ends
after making the copy.

'll Try that again yesterday, it has gone


regards Peter






Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 19, 2011, 11:40:56 PM
Peter,

Have you tested getting a command line? The routine as written isn't right for ASCII data.
Some comments as to why that extra code was in there would have helped.

What does Phoenix have to do with this? This is PB code and should be UNICODE safe.
I thought you handled the ASCII/UNICODE parts with your macros?
Or will you have to wait for Phoenix v3 before the program will work?

Just curious as I keep hitting a brick wall on getting things to work.
It's time to quit for the nite ( been up since 3am ). Be back sometime tomorrow.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 19, 2011, 11:49:56 PM
Hi Paul,
you do not have to wait until 3.0 comes out of Phoenix, just until I'm finished with the IDE, then I write about the parameters. One can then no longer go with Phoenix tuned!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Dominic Mitchell on November 20, 2011, 12:02:19 AM
Phoenix 2.0 does not support unicode.
Phoenix 3.0 does.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 20, 2011, 12:31:27 AM
Hi Dominic,

I know that Phoenix does not support Unicode 2.0. Hold me, but with macros but above water and then go Unicode!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 20, 2011, 08:13:51 AM
Hi Paul,
I changed the variables in CodeFormatter_InitApplication type so that command goes!
Command is always the case PowerBASIC 10 WSTRINGZ PTR


FUNCTION CodeFormatter_InitApplication _
  ( _
  BYVAL hInstance AS DWORD, _ ' handle of current instance
  BYVAL lParam    AS LONG _   ' address of command line
  ) AS LONG

  LOCAL lpszcmdline AS WSTRINGZ PTR                     '20.11.2011 Muss Bei PowerBasic 10 WStringz Ptr
  LOCAL filenum AS LONG
  LOCAL ztext , zOut AS XASCIZ * %MAX_PATH
  DIM Built AS GLOBAL IPOWERTIME

  LET Built = CLASS "PowerTime"

  Built.Now()

  REDIM tabhandle(0 TO 1)

  filenum = FREEFILE
  OPEN "Code Formatter.cfg" FOR BINARY AS filenum
  GET filenum,,fo
  CLOSE filenum

  lpszcmdline =  lParam

  'check the command line for a filespec
   IF LEN(@lpszcmdline) THEN
      IF ISFILE(@lpszcmdline) THEN
         fo.fspecin = @lpszcmdline               'assumes valid source file
         fo.fspecin = fo.fspecout
      ELSE
         MessageBox 0, "File not found" + $CR + @lpszcmdline, "", %MB_ICONINFORMATION
         FUNCTION = %TRUE
         EXIT FUNCTION
      END IF
   ELSE
     FUNCTION = %FALSE
     EXIT FUNCTION
   END IF

   CopyBak

   GetTempPath %MAX_PATH, ztext
   GetTempFileName ztext, "fmt", 0, zOut ' 11/18/2011 fo.fspecout
   fc.fhin = FREEFILE
   OPEN fo.fspecin FOR INPUT ACCESS READ AS fc.fhin
   fc.fhout = FREEFILE
   OPEN zOut FOR OUTPUT AS fc.fhout
   '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   'Create a simple progress control
   '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fc.hprogress = CaptionProgressWindow(0, "Format Source Code")
   DoFormat
   CLOSE fc.fhin, fc.fhout
   DestroyWindow fc.hprogress
   CopyFile zOut, fo.fspecout, 0
   KILL zOut
   FUNCTION = %TRUE
END FUNCTION
     



I also have a call to Form1_Btn_Format_Clicked GetOVars () are inserted so that the data is transferred from the Options fields


FUNCTION Form1_Btn_Format_Clicked _
  ( _
  BYVAL hWndParent  AS DWORD, _ ' handle of parent window
  BYVAL hWndCtrl    AS DWORD _  ' handle of control
  ) AS LONG

  LOCAL ztext AS XASCIZ * %MAX_PATH
  LOCAL zOut AS XASCIZ * %MAX_PATH
  LOCAL tmpFC AS fmtcommon
   GetOVars()  ' Get Contol vars 11/20/2011
   fc = tmpFC ' re-initialize all variables 11/18/2011

   CopyBak

   GetTempPath %MAX_PATH, ztext
   GetTempFileName ztext, "fmt", 0, zOut ' 11/18/2011 fo.fspecout
   fc.fhin = FREEFILE
   OPEN fo.fspecin FOR INPUT ACCESS READ AS fc.fhin
   fc.fhout = FREEFILE
   OPEN zOut FOR OUTPUT AS fc.fhout
   '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   'Create a simple progress control
   '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   fc.hprogress = CaptionProgressWindow(0, "Format Source Code")
   DoFormat
   CLOSE fc.fhin, fc.fhout
   DestroyWindow fc.hprogress
   CopyFile zOut, fo.fspecout, 0
   KILL zOut

END FUNCTION       


regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 20, 2011, 02:43:19 PM
Peter,

Do you see anything wrong with your code below?


  IF LEN(@lpszcmdline) THEN
      IF ISFILE(@lpszcmdline) THEN
         fo.fspecin = @lpszcmdline               'assumes valid source file
         fo.fspecin = fo.fspecout
      ELSE



For whatever work I do  I'm adding #OPTION ANSIAPI and commenting %UNICODE = 1.

Frankly for general user maintenance  it would have been better to go with DDT or plain SDK.
At least anybody who might want to make changes would have all the tools needed.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 20, 2011, 04:12:36 PM
Hi Paul,
must be of course different. How could this happen to me
must of course be like this!
I have not noticed during testing because the old one was sailed in fo.fspecout stores.
Mus course so hot

IF ISFILE(@lpszcmdline) THEN
         fo.fspecin = @lpszcmdline               'assumes valid source file
         fo.fspecout = fo.fspecin
      ELSE


Thank you Paul
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 20, 2011, 04:24:20 PM
Hi Paul,

Quote
Frankly for general user maintenance  it would have been better to go with DDT or plain SDK.
At least anybody who might want to make changes would have all the tools needed.

Perhaps it would have been better! But now Phoenix makes even the best code. And you have to make changes to only once at the end who I am done with the IDE

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 20, 2011, 05:54:18 PM
Does the commandline version force a backup? Or a date/time stamp backup?
Or does it risk overwriting a good backup produced by another program?

Maybe but the next revision to the GUI can't even be done in Phoenix according to what
you're saying. It will either have to be changed manually or ( more likely ) all ripped out and
started from scratch.

Why can't the SDK code produced by Phoenix handle UNICODE? I was under the impression
that PB is supposed to handle the conversion UNICODE <-> ANSI transparently to the
programmer.

Title: Re: Code-Formatter PB 10
Post by: Dominic Mitchell on November 20, 2011, 07:04:26 PM
The code Phoenix 2.0 generates is ANSI.
However, the code can be changed to unicode with the following modifications:

1. Define the unicode constant at this location.

' >>PHNX_END_OPTIONS

%UNICODE = 1

' >>PHNX_BEGIN_WINAPI


2. Replace All(Whole Word, Current Project) ASCIIZ to WSTRINGZ
3. Replace All(Whole Word, Current Project) STRING to WSTRING
4. If Tooltips control is used, Replace All(Whole Word, Current Project) %TTN_GETDISPINFO to %TTN_GETDISPINFOW

Steps 2, 3 and 4 will have to be done after every build.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 20, 2011, 07:15:44 PM
Hi Paul,
Quote
Does the commandline version force a backup? Or a date/time stamp backup?
Or does it risk overwriting a good backup produced by another program?

You need to make you not worry because the program makes a backup with time stamp, whom it is set in the options so! You put the program to the desktop, and drag the file you formatierst via drag and drop on the code format.

Quote
Maybe but the next revision to the GUI can't even be done in Phoenix according to what
you're saying. It will either have to be changed manually or ( more likely ) all ripped out and
started from scratch.

You need only few strings through XSTRING and ASCIZ XASCIZ by replacing the only concerns the functions WinMain CodeFormatter_RegisterClasses, Form1_WndProc. The way I see it are the only three variables

Quote
Why can't the SDK code produced by Phoenix handle UNICODE? I was under the impression
that PB is supposed to handle the conversion UNICODE <-> ANSI transparently to the
programmer.

So who then is true Unicode and Unicode functions are called. Phoenix writes:

FUNCTION WinMain _
  ( _
  BYVAL hInstance     AS DWORD, _       ' handle of current instance
  BYVAL hPrevInstance AS DWORD, _       ' handle of previous instance(not used in Win32)
  BYVAL pszCmdLine    AS ASCIIZ PTR, _  ' address of command line
  BYVAL nCmdShow      AS LONG _         ' show state of window
  ) AS LONG


pszCmdLine is no ASCIZ PTR PTR but a WSTRINGZ PTR


But most times you go with the program debugger you that you see the place where the program gets out!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 20, 2011, 07:36:07 PM
Hi Dominic
What did you write that does not work, you can not replace all the strings by wstring, the source of the format, I still want to ANSI. You have to select exactly what is and what string wstring. You can do so only time you'll try to get hieroglyphics! >:(

Also annoying is the produce after each of the source code to find out the places that need to be changed!
Dominic is it so hard to change these views of yours? Am also pleased with Phoenix 2.0

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Dominic Mitchell on November 20, 2011, 08:19:02 PM
In the case of ANSI unicode mix, the replace needs to be done only on the *.bas
and Utility.inc files generated by Phoenix.
Where can I find the files for the Code Formatter? I would like to have a look at the
location of your code relative to that generated by Phoenix.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 20, 2011, 08:27:39 PM
Hallo Dominic

Here again, the code for you to put Unicode one and you will have your problems

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 21, 2011, 03:45:11 PM
Dominic,

Thanks. That's cleared up some things I couldn't understand.

As far as I knew, the big push for this version of the program was to handle the new items
in PB v10. But at first all I saw were some MACROs switching between ANSI & UNICODE.
Which were not needed to handle the data files ( only plain BAS code usable by the IDE and
compiler ... NO UNICODE there ). And not needed in any of the existing functions of the program
and I couldn't see any need of them for future functions dealing with the programs main
purpose. They might have been useful in some way dealing with a GUI to handle setting/saving
the formatting options if the GUI needed to handle UNICODE. But as it is, I just don't see any
advantage to the program as it sits.

But I'll continue to do what I can to help.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 21, 2011, 10:48:14 PM
Hi Paul,

if you have time could sometimes look here. Here's another mistake! Have code formatter can go through and that's come out here

original code

FUNCTION CodeFormatter_InitApplication _
  ( _
  BYVAL hInstance AS DWORD, _ ' handle of current instance
  BYVAL lParam    AS LONG _   ' address of command line
  ) AS LONG

  LOCAL lpszcmdline AS WSTRINGZ PTR                     '20.11.2011 Muss Bei PowerBasic 10 WStringz Ptr
  LOCAL filenum AS LONG
  LOCAL ztext , zOut AS XASCIZ * %MAX_PATH
  DIM Built AS GLOBAL IPOWERTIME


code Formatter

FUNCTION CodeFormatter_InitApplication _
   (_
   BYVAL hInstance AS DWORD, _                   ' handle of current instance
   BYVAL lParam AS LONG _                        ' address of command line
   ) AS LONG

  LOCAL lpszcmdline AS WSTRINGZ PTR                     '20.11.2011 Muss Bei PowerBasic 10 WStringz Ptr
  LOCAL filenum AS LONG
*ERR LOCAL  0 but need  5
  LOCAL  AS XASCIZ * %MAX_PATH
*ERR LOCAL  0 but need  4       


I'm still working with Progress bar in status bar

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 22, 2011, 02:28:16 AM
Peter,

Simple fix.  Add fo.ascolumn = 40  after you  GET fo in FUNCTION CodeFormatter_InitApplication.

Better fix.  Add the ascolumn variable to the Options page.

Small variable that got lost in the shuffle.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 22, 2011, 12:37:07 PM
Hi Paul,
  ascolumn inserted in the Options page :)

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 22, 2011, 01:04:55 PM
Peter,

Close but ascolumn goes with split variables and should be next to it. and entry disabled when
split variables is unchecked.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 22, 2011, 10:16:48 PM
Hi Paul,
Here again an update that disabled split variable!

Did not have much time today!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 23, 2011, 02:18:12 PM
Hi Peter,

Not bad but I would have just inserted the As Column ( or Column AS ) below the split variable
check box and bumped the fields below it down. That way you wouldn't have had to increase
the tab/dialog size.

Did you realize that you can get the program's command line  via COMMAND$ and get a plain
string? No mucking about with wasciiz ptr. not sure if there is any difference in the result as
you're only dealing with 1 field ( source file name ).

Just to be doing something, I worked up a DDT version starting with PBForms and manually adding
controls to the tab pages. Not very difficult but I admit that Phoenix does a lot of the work for you.
Biggest trouble was putting in the event code & copying/modifying the Phoenix event functions.
Got most of it converted except for the progress bar and a few controls on the 2nd tab page.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 23, 2011, 10:38:57 PM
Hallo Paul,

Quote
Not bad but I would have just inserted the As Column ( or Column AS ) below the split variable
check box and bumped the fields below it down. That way you wouldn't have had to increase
the tab/dialog size.

IDE have reprogrammed again, hope you like it better

Quote
Did you realize that you can get the program's command line  via COMMAND$ and get a plain
string? No mucking about with wasciiz ptr. not sure if there is any difference in the result as
you're only dealing with 1 field ( source file name ).


But already I get the pointer function of delivered, why should I then command can generate a string again! Command reads out the pointer and generates a string!

Quote
Just to be doing something, I worked up a DDT version starting with PBForms and manually adding
controls to the tab pages. Not very difficult but I admit that Phoenix does a lot of the work for you.
Biggest trouble was putting in the event code & copying/modifying the Phoenix event functions.
Got most of it converted except for the progress bar and a few controls on the 2nd tab page.

Hi Paul, it remains open to you all the way! You can reprogram it to DDT! Send me the code but then! I want to watch it!

In addition, today I have the function reprogrammed DoFormat, possessions disappear all Goto I do not like in programs and I also have changed the format of local variables Variable Split who is turned on. The format has not voted namely

regards Peter


Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 24, 2011, 10:18:20 PM
Peter,

Old way or new way the GUI works. Just make sure you have the tab order matching the
natural order of the controls on screen.

Personally I like/use GOTOs to simplify a big block of code. For me it is much easier to make
major changes when needed without trying to figure out all the gotcha's when several levels
of if/then deep.

If you're going to indent the variables make sure you indent them correctly for all the functions/
methods/whatevers in a Class. And does that change the Column AS ? Because if you get
too many levels deep you will probably not have enough room between the variable and
the AS type.

I've noticed a couple errors in my splitting routine but am not sure it would fit in with your
programming structure now.
1) if there is something like   DIM A(1, 4) as LONG needs extra processing.
2) and  LOCAL a, b, c as LONG, d, e, f AS DWORD also need more work.
I got no responses either good/bad when I posted the code so I didn't do any further
work on this program. I made my changes in my program that all it does is split the
variables.

I don't really think posting my DDT version would do anything but confuse people.
I left out everything but the basic clicking/text changing code. No re-sizing or other
things taken care of by Phoenix. And haven't even looked at the progress bar other than
to disable the simple one used in the original program.

I finally found out why you added the extra check for #PBFORM. It really only matters when
it is in the middle of a procedure.
I don't know if there are other keywords that need the same treatment or not.

Keep going.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 24, 2011, 11:06:40 PM
Hi Paul,

have new version. Can retrieve backup.
I answer your questions tomorrow!

Do not worry keep working :)
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 25, 2011, 08:26:21 AM
Hi Paul,

Quote
Just make sure you have the tab order matching the
natural order of the controls on screen.

I want to give the program a lot of possibilities. While many controls are needed. Tab Order point, I then finally one!


Quote
Personally I like/use GOTOs to simplify a big block of code. For me it is much easier to make
major changes when needed without trying to figure out all the gotcha's when several levels
of if/then deep.

It must always decide themselves whether to use goto! I use it for 20 years not only in an emergency who can not be done differently. If Then blocks can be read much better.
Quote

If you're going to indent the variables make sure you indent them correctly for all the functions/
methods/whatevers in a Class. And does that change the Column AS ? Because if you get
too many levels deep you will probably not have enough room between the variable and
the AS type.

The function DoFormat is simply not mature! They should only is the entire function, class method should read all read AS variable, and put it in the beginning of the function! Then there are no space problems with AS

Quote
I've noticed a couple errors in my splitting routine but am not sure it would fit in with your
programming structure now.
1) if there is something like   DIM A(1, 4) as LONG needs extra processing.
2) and  LOCAL a, b, c as LONG, d, e, f AS DWORD also need more work.
I got no responses either good/bad when I posted the code so I didn't do any further
work on this program. I made my changes in my program that all it does is split the
variables.

There are certainly still many errors in the split routine. Send me your. Have you already written one above approach.
So all read from file function. Could work by Function End Function then to be used only for the Collection Class

Quote
I finally found out why you added the extra check for #PBFORM. It really only matters when
it is in the middle of a procedure.
I don't know if there are other keywords that need the same treatment or not.

There are many exceptions, the determined, we must note. But which are to come up with the times already! We will solve this already, because I'm sure! The function DoFormat is bad but we still need to work to find ways

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 25, 2011, 01:51:22 PM
Peter,

Sorry. I understand that English is not your primary language. But some of your responses don't
make sense to me.

1) I think it get it.
2) Personally I have an extreme dislike of nesting so many levels deep. it is only understandable
when fully documented on each level.
3) not sure I understand. an additional problem occurs when tab is set to 8 and very long variable
names are used.
4) only the 2 that I know of and I've run several source files from the PB forums thru it. and indenting
for Class Method variables which I only saw for the first time a couple weeks ago and have admitted
that I know nothing about & my programs might not work with that code.
but did not understand at all the 2nd line.
5) seems to me as you add more exceptions that the nesting level ( and complexity ) also expands.


Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 25, 2011, 03:03:21 PM
Peter, i offer you tranlation here. Write it in german and drope me a note then I'll translate it for you into english.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 25, 2011, 07:13:20 PM
Hi Paul,
my English is very bad! But I think that we already manage! And who it was not supposed to go I take Theo's supply!

Greetings Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 26, 2011, 12:58:25 PM
Peter,

At least you're making an attempt. I can only speak English. Took 2 classes of French in school but
was never able to "think" in French.

Over the years, I've dealt with French, Spanish, Portugese, Italian and Singaporian people  and was always
amazed at their ability to not only speak English but to understand the culture.  Sorry to say I still
haven't learned anough of the culture of those people to understand some of their comments.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 26, 2011, 07:30:48 PM
Paul, the PowerBasic Code from Peter is understandable to you.
Thats what counts  ;D. PowerBasic connects cultures.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 26, 2011, 08:23:48 PM
Well, I thought I understood it.

But as there are really only a couple main routines  it makes no sense for me to make changes that
Peter may be working on. So I'll stop. It just takes too long to figure out exactly what got changed
and how that impacts what I was working on.

It would be helpful to know what Peter's plan is. What is being changed to cover PB 10 and hopefully
PB CC v6. Why the extra empty tab? Or just stop posting until it is finished.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 26, 2011, 08:38:22 PM
Paul,
Please do not stop with the program! But it is fun to program with you

I'm working on the function DoFormat

regards Peter

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 26, 2011, 09:37:59 PM
Paul,
of course with PBCC, it is clear
greetings Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 27, 2011, 08:31:52 AM
Peter,

Paul möchte wissen was dein Plan ist, damit er sich entsprechend einklinken kann.

Ok, got a Message from Peter to Paul. It contains a real truth.
The heart of a real good "Pretty Printer" must really know any keyword of PB.

Peter writes:

QuoteHallo Theo,
Habe schon geschrieben,

Like said before ...

Quotedass ich an der Funktion DoFormat  arbeite! Das Ausarbeiten der Funktion gestaltet sich im Moment noch recht schwierig weil es viele Ausnahmen gibt die ich alle mit einbeziehen möchte!

I am still busy with the "DoFormat Function". It needs a bit more time because it needs to include a lot of exceptions.

QuoteIch arbeite schon drei Tage daran! Deswegen hört man so wenig von mir!
Kannst es Paul ausrichten!

This is ongoing for the last three days and may take more time. Please tell it to Paul.

Which i wanted to do hereby.

Peter will tell us when he's done with the "DoFormat".
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 28, 2011, 03:20:47 PM
did some work but my new code won't fit with what Peter's working on. so here's the exe as I've got
it now. the program is tab.exe dimply because this is the 1st program I've done with PB v10 using a
tab control without creating extra overlay windows/dialogs. it's all created right on the tab page.

and some of the change listing

' tab ddt version of code formatter
' 11/23/2011 v3 re-arrange GUI again
'               don't have format_cliked yet
' 11/24/2011    got format_clicked in place
'               fixed problem with text_ascoumn
' 11/25/2011    changing string concats to & instead of +
'               changing concat/add/sub if left var is 1st on right to &=/+=/-=
' 11/26/2011    fix for DIM x(1, 4)
'               handle multiple AS type on 1 line
'               indents variables -- still need fix if it can't fit in space *ERR
' 11/27/2011    eliminated *ERR
'               add ENUM to list of auto-indent
'               process THREAD FUNCTION like CALLBACK FUNCTION
'               indent continued lines tabsize
'              * still need to process continued variable declares
'


later: added progress bar & fixed problem of not saving main dialog handle.

much later: put new archive on my post dated 12/5/2011.



Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 29, 2011, 05:54:15 PM
Does it mean, that you have a final result, and peter will produce another program?
I believe we should bring things together after all because only this will allow further developement.
There are plans to enhance functionality of the Pretty Printer more far then where its now.
For example:
- extraction of strings
- local variables processing (removal of unsused?)
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 29, 2011, 07:03:34 PM
Theo,

No, not a complete solution nor a competing program to Peter's.

Just have no idea exactly what Peter's complete plan of enhancements will be or
what changes he's currently making.

Not everybody will have Phoenix v2 to be able to rework the GUI or to easily understand
how the events are handled. I don't really have a problem as I've had Phoenix for years.

I was bored waiting so I did something.
I was just curious as to how easy it would be to do the same program in PB DDT ( which everyone
who wants to change/compile the source will have already ). For me it was very easy to go from
one to the other ( been doing that type of programming for many years ). Also it was easy for me
to make changes to the split variable section of code as I had coded it. As I explained earlier, I got
no feedback when I put the code out there. So I went ahead with my own program which did
nothing but split variables and have made changes that probably wouldn't fit easily into
CodeFormatter. It was bad enough with the way I originally coded it because it bypassed
the main part of the program ( which broke each line into individual elements and then put
them back together ). I figured that was why I got no feedback.

Some of the changes I've made are based on what I've coded for the call-tree/flowchart program
that I've been working on. That code is not ready for public viewing as I'm still getting the
call-tree/cross-reference part to handle most PB sources that I can find ( either on the PB forums
or my older programs ... still not that familiar with all the code for Classes ).

That's where things are as far as I'm concerned.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 29, 2011, 08:20:30 PM
Peter asks for the source code of what you have been doing so he can put it all together.
Can you make it available to him?
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on November 29, 2011, 10:05:33 PM
Not at this time.

I'm waiting to see what all Peter does. When will we see a final version?

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on November 30, 2011, 07:51:26 AM
Peter, Paul schreibt, dass er derzeit noch nicht seinen Quellcode weitergeben will, sondern erst sehen will was du machst,
Wir warten also auf deinen Stand.

@Paul: I have translated this for Peter.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on November 30, 2011, 09:39:55 AM
I am still working on the function DoFormat! The thing assumes shape. Is at testing

greetings Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 05, 2011, 03:26:17 PM
still bored so I reworked the variable indenting to better match rest of surrounding lines.

I'll see if I can remove the previously posted archive.

later: removed archive with executable. guess it wasn't wanted.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 05, 2011, 03:28:27 PM
Paul, can it be made into several Passes?
Then you get the full code into your pass, and its completely separate from what Peter is doing.

Peter kannst du das ding modular aufbauen dasses nacheinander in "Passes" arbeitet?
So könnte Paul parallel bestimmte dinge tun.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 05, 2011, 03:38:59 PM
Theo,

You've seen the code from v2.  What do you think?

It's obvious to me that you and Peter have been talking & planning but you have not shared
any details with the rest of the forum. Until that happens I don't plan on posting code.

I'm just testing things on my own and sharing the executable to see if anybody finds problems.
Still waiting to see what the plan is and what Peter has coded.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 05, 2011, 07:23:31 PM
Hello Paul kept bin still a few days, busy with the function DoFormat!  At the moment does not have very much time for Programmieren. In addition, the code is very complex. Please still some patience!

Greetings Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 06, 2011, 07:20:29 AM
Paul, to share executables is for me no option. Because for safety reasons i only download executables if it can not be avoided.
And i believe many others also hold it like that .I need code that i can compile myself.

Back to the topic. I have suggested Peter, to split the job into "Passes". Then any body (including me) could work on a part and later for example peter could put it all together.
For this to work, the whole sourcecode would have to be passed through the passes as string (BYREF).
Then we can make subprogramms that do parts of the task.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 06, 2011, 07:29:10 AM
Hello,
  new version for testing
regards Peter

added (Theo):
Peter has included the source code.
Now you can take part, if you want. Paul.
Add your stuff to Peters code.
Change the format in a way that the thing works in passes,so many people canwork on it at the same time.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 06, 2011, 01:00:44 PM
Hi,

Sorry to say this but  I can't help you.    :(

It's going to take me a couple weeks of study before I can figure out what it is doing now.
I can't recognize my code at all and have no idea how to correct the errors that I'm now seeing
in it.

I do wish you luck.

I'll go back and delete my archive with the executable. Just thought it would help to see another
output and didn't want to throw a lot of confusion around what Peter's doing.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 06, 2011, 01:24:47 PM
Not real sure about this but the PB v10 help file says

The underscore character must be preceded by at least one white space character and is not supported in the ASM statement.


Is a "(" considered a "white space character" ?  I noticed this "(_" in several of the Phoenix Function
statements. Probably the compiler handles it but it involves extra work in the formatter when
variables end with a "_"  to not flag as a continuation line but to flag the "(_" as a continuation
line.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 06, 2011, 03:36:35 PM
Proper indenting and comments wouldn't hurt. But would need English comments.



Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 06, 2011, 08:25:33 PM
I would prefer to restructure the project into passes so anybody can take a closed part without need to use the otehr persons code.
I know that it can be diffucult to use other peoples code.
In most cases i am just faster to make things from scratch.

Thats why i believe the project would need a cooperative concept.

Ok, actually it looks that the ball is with paul.

Take a look, even if its a challenge.
Thats one reason why we do it.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 06, 2011, 10:52:57 PM
Hello,

which will now be properly resolved

input:


LOCAL    xxx AS DWORD: pbword = "ABC":LOCAL xxc, yyc AS INTEGER, zzc AS INTEGER 'testvar     



output:

    LOCAL    xxx                        AS DWORD            'testvar
    pbword = "ABC"
    LOCAL    xxc                        AS INTEGER
    LOCAL    yyc                        AS INTEGER
    LOCAL    zzc                        AS INTEGER   


regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 07, 2011, 12:37:23 AM
I love to eliminate errors in programs

One more mistake away. The program now correctly detects whether it is in a function or sub

Variables that are outside a function are now formatted correctly

New function added


FUNCTION Is_Function_or_Sub(BYREF s AS STRING) AS INTEGER
    STATIC   X                          AS LONG
    LOCAL    s1                         AS STRING
    LOCAL    pbword                     AS STRING
    LOCAL    termstr                    AS STRING
    LOCAL    i                          AS INTEGER

    s1 = UCASE$(LTRIM$(s))
    IF LEFT$(s1, 9) = "FUNCTION " THEN
        IF x = 1 THEN EXIT IF
        FOR i = 9 TO LEN(s)
            termstr = MID$(s, i, 1)
            IF termstr = "=" THEN
                EXIT FOR
            ELSEIF termstr <> " " THEN
                x = 1
                EXIT FOR
            END IF
        NEXT i

        EXIT IF

    ELSEIF LEFT$(s1, 4) = "SUB " THEN
        IF x = 0 THEN x = 1
        EXIT IF

    ELSEIF LEFT$(s1, 4) = "END " THEN
        IF X = 1 THEN
            findPBWord s, 4, pbword, termstr
            pbword = UCASE$(pbword)
            IF pbword = "FUNCTION" OR pbword = "SUB" THEN x = 0

        END IF
    END IF
    FUNCTION = X

END FUNCTION
                             


regards Peter

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 07, 2011, 12:54:45 AM
What about Callback or Threaded Functions?

and where is EXIT SUB supposed to be?

            CASE "'"
                IF pstring = %FALSE THEN
                    pbword = MID$(s, p)
                    termstr = "'"
                    EXIT SUB
                    p = LEN(s) + 1
                ELSE
                    pbword = pbword + z
                END IF


Fine, I'll wait a month  AT LEAST before I even begin to look at anything.
No sense wasting my time on a program that isn't finished.

See you next year sometime.     :(

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 07, 2011, 09:50:03 AM
Hi Paul,

have expanded the function Is_Function_or_Sub () with FASTPROC, CALLBACK FUNCTION, THREAD FUNCTION

But they have not yet tested!

regards Peter

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 07, 2011, 12:58:42 PM
Peter and Theo,

I'm doing no more on this project until you post in the forums the documentation of the program,
the COMPLETE current/future plans of the program and all the off-line conversations about
the program.

I am a VERY good programmer who is capable of taking garbage spaghetti-code programs and
producing clean easily understood & maintainable programs. BUT I DO NOT enjoy working in
the dark when the specifications are hidden from me and constantly changing.   >:(

You have so far ignored my requests and just a couple posts ago claimed " the ball is with paul"
and then proceeded to spit out a couple untested updates with no documentation.

THE BALL ( with a very big hole in it ) is back to you.
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 07, 2011, 08:53:44 PM
Hallo Paul,
there is no doubt about your qualities as programmer.
While you seem to be a strange psychologist.

The only offline communication i have with peter, is that he telle me in skype from time to time "good morning" and "good evening".
Thats mostly all.

You are also invited to join my SKYPE-contacts and then we can even try to get a conference on the program with peter.

As there is no communication and no documentation, this is the only sollution i can offer.

My skype nick is no secret, its "theogott", just add me.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 07, 2011, 11:25:21 PM
Theo and Peter,

I'm just telling it like I see it based on forum posts and source code provided.

I'm withdrawing from doing any more programming for this project.
I will continue to point out things that need fixing from time-to-time ( the same as anybody is allowed )
but will not supply code for the fix.

Personally, I have nothing against you guys but our programming styles are very different.
I've been doing my style of coding for almost 40 years in many languages from mainframes to
PCs & Apple ][s. It is generally clean, easily understood and easily modified. The programs that
I wrote for the last company have been working without modifications or fixes for over 10 years.

Good luck. And don't forget to try the program on some large programs with lots of Class coding.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 08, 2011, 07:13:59 AM
Peter are you actually working on the project or is the final code available?

Peter, arbeitest du gerade an dem projekt oder ist der finale code verfügbar?

Wenn der verfügbar ist werde ich mir mal die struktur anschauen ob man es nicht in unabhängige Passes einteilen kann.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 08, 2011, 12:14:12 PM
Hi Theo,

The final code is at the top to download! I put the code but always pure whom I've changed something! Yesterday, I'm not sorry to come!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 08, 2011, 12:42:30 PM
QuoteIch arbeite immer noch an DoFormat jede andere Funktion kann im Moment geändert werden also am aussehen oder der Progressbar oder oder oder! Ich könnte auch manchmal ein Feedback brauchen was mit der Formatierung nicht Funktioniert!

Peter says that he is actually working on the "DoFormat", but that any other function in the provided code can be cahnged by anybody want to take part in the project.

However i suggest just to wait until peter gives the sign that he's done. This way we make step by step.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 08, 2011, 01:12:48 PM
Hello,
May have DoFormat and all the functions depend on it included in a separate #INCLUDE any work on it now!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 10, 2011, 03:25:41 PM
Hello,

A couple observations.

1) move the #PBFORMS check/reformat into RebuildLine where it belongs. that will remove a
major indent that isn't needed.

2) it doesn't seem to reformat a line with only 1 variable. did you mean to do this change?

3) I am seeing problems with DIM x(1, 2) as long   and DIM x(a - 1, b - 1) as long. see if it
works with TO or : instead of the , in the parens.

4) nothing seems to work under the Class. suggest you get Larry charlton's GDI Plus code
from the PB forums and include all the INCs into the main BAS file for testing. Unless you have
several Class programs from different programmers available.

5) I think there is a much simpler way to handle the split variable routine and adds no multiple
scans trying to figure out parts of the line but haven't been able to figure out exactly what
your function is doing.

6) how are you planning to handle:

dim x as long, _
     y, _
     z as dword

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 10, 2011, 05:05:34 PM
Hi Paul,
I will look at the issues and work through the points piece by piece!
But thank you that you have my attention!
regards Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 10, 2011, 05:37:58 PM
Peter asked me to translate it.

Quote from: Paul Elliott on December 10, 2011, 03:25:41 PM
Hello,

A couple observations.
[Einige Beobachtungen]

1) move the #PBFORMS check/reformat into RebuildLine where it belongs. that will remove a
major indent that isn't needed.

[Verschiebe das  #PBFORMS nach "RebuildLine" wo es hignehört. Das sollte einen wichtigen ungewollten Einzug entfernen.]

2) it doesn't seem to reformat a line with only 1 variable. did you mean to do this change?

[Eine Zeile mit nur einer Variable wird nicht formattiert - ist das Absicht?]

3) I am seeing problems with DIM x(1, 2) as long   and DIM x(a - 1, b - 1) as long. see if it
works with TO or : instead of the , in the parens.

[Ich sehe probleme mit DIM ... s.o.] Das scheint nicht zu gehen.
 
4) nothing seems to work under the Class.
[ Alles nach CLASS scheint nicht zu funktionieren.]

suggest you get Larry charlton's GDI Plus code from the PB forums and include all the INCs into the main BAS file for testing.
[Hol dir einfach Larry Charltons GDI Plus Code aus dem PB-Forum und include das mal in dein Testfile]

Unless you have  several Class programs from different programmers available.
[Ausser du hast schon genug CLASS-Testfiles von verschiedenen Programmierern]

5) I think there is a much simpler way to handle the split variable routine and adds no multiple
scans trying to figure out parts of the line but haven't been able to figure out exactly what
your function is doing.

[Ich denke dass es beim formattieren der Variablen auch einfacher gehen sollte. Aber ich habe da auch nicht alles verstanden was du da machst]

6) how are you planning to handle:

dim x as long, _
     y, _
     z as dword
[/color]


[Wie willst du so einen Fall (s.oben) handhaben?]
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 10, 2011, 08:57:26 PM
An added note to my #5 ( just so you know it is possible ) I added about 50 lines of code and
managed to handle the code fragment I posted. It may be possible that I can shrink it but it
works for me and I may just leave it as is. Half the battle of working on a new function is
knowing that it can be solved.


Question:  Isn't anyone else testing this? I saw that the latest source has been downloaded
14 times. I do admit that the code is tough to follow ( I never did understand the RebuildLine
routine when first working on the split variable ) but the more code by different programmers
that it gets run against then the better the program will be. Even if you don't use the split
variable function.


Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 11, 2011, 03:36:19 PM
Hi Paul,
I once fixed a bug.
The error in DIM x (1, 2)

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 11, 2011, 09:00:52 PM
Hi Paul,
I think that we should dissolve the or. What do you think?

from:

dim x as long, _
     y, _
     z as dword



to:


    dim x as long
    dim y as long
    dim z as long


regards Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 12, 2011, 09:03:37 AM
looks good to me.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 12, 2011, 02:31:19 PM
I take it that you wrote the output by hand? Notice the type of variables and spacing.

Don't forget to allow for multiple variables/types per individual line and remarks on each line.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 12, 2011, 08:07:21 PM
Hello,
've Added new button for the underscore! The function is not yet. Who should the button is selected, the out come of it!

input:

DIM a, _
B as integer


output

  Dim a as integer
  Dim b as integer

Who does not:


     Dim a, _
         B as integer


regards Peter

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 12, 2011, 08:54:01 PM
Why not have it as a normal part of "split variables" ?

I don't see the reason for a new option.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 12, 2011, 09:04:40 PM
Hi Paul,
I can have it too. Always comes out the Sun


    Dim a as integer       ' Test
    Dim b as integer


But there are people who like to underscore

regards Peter













Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 13, 2011, 09:12:31 PM
Hello,
  I got a bit further today! Wen Replace underscore is off! The result looks as follows!

input:

LOCAL a, b, _   'kdsjfjasdkfj
        c AS INTEGER           


output:


LOCAL    a, _                                           'kdsjfjasdkfj
         b, _
         c                          AS INTEGER   



regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 14, 2011, 05:08:28 PM
Hello,
new update. Replace underscore with AS when underscore option is turned on

Input:

LOCAL a, b, _   'kdsjfjasdkfj
        c, _        'abcde
         e AS INTEGER   'test   


Output:


    LOCAL    a                          AS INTEGER          'kdsjfjasdkfj
    LOCAL    b                          AS INTEGER
    LOCAL    c                          AS INTEGER          'abcde
    LOCAL    e                          AS INTEGER          'test       


regards Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 14, 2011, 07:13:16 PM
Good idea, Peter!
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 14, 2011, 08:27:33 PM
Isn't that what you said you had back on the 12th? Or were all those output lines hand-written?

I haven't tested it yet.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 14, 2011, 10:44:09 PM
Hi Paul,
that was dated 11/12/2011 were written by hand! Now things are really as far as I can see!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 15, 2011, 01:21:08 PM
Hi, Peter,

When you don't  reply to each question I can only guess that you haven't worked on it yet.
And with no remarks in the source as to the date/time of any changes I can only guess that
there have been no changes yet.

Doesn't look like anybody else is testing.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 15, 2011, 05:24:17 PM
Hi Paul,
that was a question of me on 11.12.2011. How do you want to have the formatting. After I received no answer from you. I Repace underline option programmed.

In addition, more and who file a new zip here, there is also an update.

Today I added multi-line macros

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 15, 2011, 06:30:48 PM
Peter,

The question was "Were you going to handle it or ignore it".  If you were going to handle it then
formatting would be exactly like the rest of split variables. If you were going to ignore it then
don't change the format in any way.

How are you handling continued lines? Is this going to be yet another option? If so then you better
make a much bigger form to handle all the different possibilities.

How are you aligning the continued lines under the first line? Indenting  a tab size, indenting to the
= sign or the ( or to the right of the last of the first line?

I'm not sure what you are doing with Macros ( especially multi-line ) as changing the spacing within
them might change the output results. You do not want to be replacing the macro name with the
macro text within the main body of the program.

Are you documenting any of this in the source code?

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 16, 2011, 07:07:29 AM
Paul, Peter told me that he has currently a bit problems with understanding what you write.
And i am not always availabe to translate.

Anyway i would like to implement this scheme:
- Paul makes ready until he really says "I am done"
- Then we take a look and you can then get the code and make improvements.

Under the current babylonic situation, together with the fact that Peter is not yet ready,
a discussion will waist our time. Let's just wait until Peter says "I am ready".


Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 16, 2011, 01:02:28 PM
Theo,

That goes both ways. Most times I have to guess at what Peter is saying. I don't speak a word of
German.

I'll wait until Peter or you say he's got all the bugs worked out and all the points that I mentioned
are taken care of. Probably shouldn't take more than a week.
This posting of incomplete code is a waste of time.

Ok?



Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 16, 2011, 05:06:42 PM
Peter and Theo,

I was curious about noname1.bas and tried it thru the current program.
Indenting went way off the screen.

Ran it thru my flowcharting program and got the following.
Seems that most of the Macro Function parts are incomplete ( at least according to PB Help ).
Or else I have a problem but there aren't a lot of extra End Macros at the end.

Just thought it might help.

LATER:

guess there's a limit that's different between Preview & Post.
Preview was fine.

attached is a zip of the pikx.big file.



   
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 16, 2011, 06:31:14 PM
Hi Paul,
send me the source as a zip file. Then I can watch me break this down

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 17, 2011, 07:29:55 PM
Hi Paul,
I wanted to test out your file. I was however not possible because I do not remove the numbers at the left side wanted!
I told you but a new update added for testing

The new version can Class

see output


#COMPILE DLL
#DIM ALL
#RESOURCE "collection.pbr"
#COM DOC "Dies ist ein Test"
#COM NAME "Collection", 1.1
#COM GUID GUID$( "{85AF93DB-EF37-4916-BE38-CE32985B9C63}")
#COM TLIB ON



#IF NOT %DEF(%CCOLLECTIONINC)
%CCOLLECTIONINC                   = 1


    INTERFACE ICollectionEvent GUID$( "{BC0DA08D-A429-42E7-BEC2-0FC5C56C131F}") AS EVENT
        INHERIT IAUTOMATION
        METHOD BevoreAdd(BYVAL nCount AS DWORD)


        METHOD AfterAdd(BYVAL nCount AS DWORD)


        METHOD ItemRemoved(oKey AS VARIANT)


        METHOD ERROR(BYVAL nNumber AS DWORD)

    END INTERFACE


    CLASS CCollection GUID$( "{BE08C50D-1D02-4A0A-8FA6-514E365B848F}") AS COM
        INSTANCE arObj() AS VARIANT
        INSTANCE arKey() AS STRING
        INSTANCE nCounter AS DWORD

        CLASS METHOD DESTROY()
            ERASE arObj()
            ERASE arKey()
        END METHOD

        CLASS METHOD GetArIndex(sKey AS STRING) AS DWORD
            LOCAL    i                  AS DWORD
            ARRAY SCAN arKey(), COLLATE UCASE, = sKey, TO i
            METHOD = i
        END METHOD

        CLASS METHOD RemoveFromObjAr(BYVAL nIndex AS DWORD)
            LOCAL    i                  AS DWORD

            FOR i = nIndex TO UBOUND(arObj())
                IF nIndex > 0 THEN
                    SWAP arobj(i - 1), arobj(i)
                    SWAP arKey(i - 1), arkey(i)
                ELSE
                    IF i < UBOUND(arObj()) THEN
                        SWAP arobj(i), arobj(i + 1)
                        SWAP arKey(i), arKey(i + 1)
                    END IF
                END IF
            NEXT

            IF nCounter - 1 = 0 THEN
                REDIM    arobj(nCounter - 1)
                REDIM    arKey(nCounter - 1)
            ELSE
                REDIM    PRESERVE arobj(nCounter - 1)
                REDIM    PRESERVE arKey(nCounter - 1)
            END IF
        END METHOD

        INTERFACE ICollection GUID$( "{F975C92B-988F-4FA8-9BBA-6762C27014A7}")
            INHERIT IDISPATCH

            PROPERTY GET COUNT() AS DWORD
                PROPERTY = nCounter
            END PROPERTY

            PROPERTY GET GetKey(BYVAL nIndex AS DWORD) AS STRING
                IF nIndex < LBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(3)
                    EXIT PROPERTY
                END IF
                IF nIndex > UBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(4)
                    EXIT PROPERTY
                END IF
                PROPERTY = arKey(nIndex)
            END PROPERTY

            PROPERTY GET GetItemDirect(BYVAL nIndex AS DWORD) AS VARIANT
                IF nIndex < LBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(3)
                    EXIT PROPERTY
                END IF
                IF nIndex > UBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(4)
                    EXIT PROPERTY
                END IF
                PROPERTY = arObj(nIndex)
            END PROPERTY


            METHOD ADD(BYVAL obj AS VARIANT, OPT BYVAL oKey AS VARIANT) AS DWORD
                LOCAL    s              AS STRING

                RAISEEVENT ICollectionEvent.BevoreAdd(nCounter)
                IF ISMISSING(oKey) THEN oKey = STR$(nCounter + 1)

                SELECT CASE VARIANTVT(oKey)
                    CASE %VT_BSTR: s = UCASE$(VARIANT$(oKey))
                    CASE ELSE: s = STR$(VARIANT#(oKey))
                END SELECT

                IF me.GetArIndex(s) > 0 THEN
                    RAISEEVENT ICollectionEvent.Error(1)
                    EXIT METHOD
                END IF

                nCounter += 1
                REDIM    PRESERVE arObj(nCounter)
                REDIM    PRESERVE arKey(nCounter)
                arObj(nCounter) = obj
                arKey(nCounter) = s

                RAISEEVENT ICollectionEvent.AfterAdd(nCounter)
                METHOD = nCounter
            END METHOD

            METHOD Remove(BYVAL nItemOrKey AS VARIANT) AS DWORD
                LOCAL    s              AS STRING
                LOCAL    n              AS DWORD

                SELECT CASE VARIANTVT(nItemOrKey)
                    CASE 8: s = UCASE$(VARIANT$(nItemOrKey))
                    CASE ELSE
                        n = VARIANT#(nItemOrKey)
                        Me.RemoveFromObjAr(n)
                        nCounter -= 1
                        METHOD = n
                        RAISEEVENT ICollectionEvent.ItemRemoved(nItemOrKey)
                        EXIT METHOD
                END SELECT
                n = me.GetArIndex(s)
                IF n < 1 THEN
                    RAISEEVENT ICollectionEvent.Error(1)
                    EXIT METHOD
                END IF
                Me.RemoveFromObjAr(n)
                nCounter -= 1

                RAISEEVENT ICollectionEvent.ItemRemoved(nItemOrKey)
                METHOD = n
            END METHOD

            METHOD ITEM(BYVAL nItemOrKey AS VARIANT) AS VARIANT
                LOCAL    s              AS STRING
                LOCAL    n              AS DWORD

                SELECT CASE VARIANTVT(nItemOrKey)
                    CASE 8:
                        s = UCASE$(VARIANT$(nItemOrKey))
                        n = Me.GetArIndex(s) - 1
                        IF n > 0 THEN METHOD = arObj(n)
                        EXIT METHOD
                    CASE ELSE
                        METHOD = arObj(VARIANT#(nItemOrKey))
                        EXIT METHOD
                END SELECT
                RAISEEVENT ICollectionEvent.Error(2)
            END METHOD


        END INTERFACE

        EVENT SOURCE ICollectionEvent
    END CLASS
#ENDIF


regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 17, 2011, 08:27:16 PM
Theo,

I'm sorry I posted that file.

Please explain to Peter:
Noname1.bas is his file. It was in the RAR that he posted.
I was curious to see if his program could handle it but it did not.
The indenting ran way to the right and never reset to the left.

The file I posted just pointed out where single line macros were and where
multi-line macros started and ended.

Macro Functions are only multi-line according to PB Help file.
There are many of them in that file that are really single line macro and have
no End Macro line.

I will not download or test anything for at least a week. Hopefully by then Peter
will have the program complete & tested. If not then I'll wait longer.

Sorry.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 17, 2011, 08:52:22 PM
Hi Paul,
Even multi-line macros will be formatted! See here!
File by Theo!

input File:

'##################################################################################################
'
'##################################################################################################
MACRO G_REG()
REGISTER R01 AS LONG,R02 AS LONG
END MACRO

MACRO G_S01()
LOCAL S01 AS STRING
END MACRO

MACRO G_S02()
LOCAL S01,S02 AS STRING
END MACRO

MACRO G_S03()
LOCAL S01,S02,S03 AS STRING
END MACRO

MACRO G_S04()
LOCAL S01,S02,S03,S04 AS STRING
END MACRO

MACRO G_S05()
LOCAL S01,S02,S03,S04,S05 AS STRING
END MACRO

MACRO G_S06()
LOCAL S01,S02,S03,S04,S05,S06 AS STRING
END MACRO

MACRO G_S07()
LOCAL S01,S02,S03,S04,S05,S06,S07 AS STRING
END MACRO

MACRO G_S08()
LOCAL S01,S02,S03,S04,S05,S06,S07,S08 AS STRING
END MACRO

MACRO G_S09()
LOCAL S01,S02,S03,S04,S05,S06,S07,S08,S09 AS STRING
END MACRO

MACRO G_S10()
LOCAL S01,S02,S03,S04,S05,S06,S07,S08,S09,S10 AS STRING
END MACRO

MACRO G_S11()
LOCAL S01,S02,S03,S04,S05,S06,S07,S08,S09,S10,S11 AS STRING
END MACRO

MACRO G_S12()
LOCAL S01,S02,S03,S04,S05,S06,S07,S08,S09,S10,S11,S12 AS STRING
END MACRO

MACRO G_T01()
LOCAL T01 AS LONG
END MACRO

MACRO G_T02()
LOCAL T01,T02 AS LONG
END MACRO

MACRO G_T03()
LOCAL T01,T02,T03 AS LONG
END MACRO

MACRO G_T04()
LOCAL T01,T02,T03,T04 AS LONG
END MACRO

MACRO G_T05()
LOCAL T01,T02,T03,T04,T05 AS LONG
END MACRO

MACRO G_T06()
LOCAL T01,T02,T03,T04,T05,T06 AS LONG
END MACRO

MACRO G_T07()
LOCAL T01,T02,T03,T04,T05,T06,T07 AS LONG
END MACRO

MACRO G_T08()
LOCAL T01,T02,T03,T04,T05,T06,T07,T08 AS LONG
END MACRO

MACRO G_T09()
LOCAL T01,T02,T03,T04,T05,T06,T07,T08,T09 AS LONG
END MACRO

MACRO G_T10()
LOCAL T01,T02,T03,T04,T05,T06,T07,T08,T09,T10 AS LONG
END MACRO

MACRO G_T11()
LOCAL T01,T02,T03,T04,T05,T06,T07,T08,T09,T10,T11 AS LONG
END MACRO

MACRO G_T12()
LOCAL T01,T02,T03,T04,T05,T06,T07,T08,T09,T10,T11,T12 AS LONG
END MACRO

MACRO EXIF() =EXIT FUNCTION
MACRO EXIC() =EXIT SELECT
MACRO EXIS() =EXIT SUB

MACRO ENDS() =END SUB

MACRO ENDF_R01()
   FUNCTION=R01
   END FUNCTION
END MACRO

MACRO ENDF_R02()
   FUNCTION=R02
   END FUNCTION
END MACRO

MACRO ENDF_S01()
   FUNCTION=S01
   END FUNCTION
END MACRO
'##################################################################################################
'
'##################################################################################################

FUNCTION How_got_here() AS STRING
  REGISTER R01 AS LONG
   LOCAL S01 AS STRING
  FOR R01 = CALLSTKCOUNT TO 1 STEP -1
S01+=$CRLF+CALLSTK$(R01)
  NEXT
S01+="---------------------------------------"+$CRLF
FUNCTION=S01
END FUNCTION
'##################################################################################################
'
'##################################################################################################
MACRO G_ERM(P1)
ero:
G_ERO$="ERL: "+STR$(ERL)+" * "+P1+":"+ERROR$(ERR)+" * ("+STR$(ERR)+"). ERAPI="+STR$(ERRAPI): G_AA G_ERO$:ERRCLEAR:RESUME NEXT
END MACRO

SUB G_AA(BYVAL a$)
MSGBOX "An Error happened:"+$CRLF+a$,,"http://www.it-berater.org - Software Library"
EXIT SUB
END SUB


#ENDIF
'##################################################################################################
'
'##################################################################################################


MACRO MAXVALUE_DL =  1.7976931348623157E+308#      'max value for a double
MACRO MINVALUE_DL = -1.7976931348623157E+308#      'min value for a double

MACRO MAXVALUE_SN =  3.402823e+38!                 'max value for a single
MACRO MINVALUE_SN = -3.402823e+38!                 'min value for a single

MACRO MAXVALUE_SQ =  9,223,372,036,854,775,807&&   'max value for a signed quad (64 bits)
MACRO MINVALUE_SQ = -9,223,372,036,854,775,808&&   'min value for a signed quad (64 bits)

MACRO MAXVALUE_UQ =  18446744073709551615    'max value for a unsigned quad (64 bits)
MACRO MINVALUE_UQ =  0                             'min value for a unsigned quad (64 bits)

MACRO MAXVALUE_LN =  2147483647&                'max value for a long
MACRO MINVALUE_LN = -2147483648&                'min value for a long

MACRO MAXVALUE_DW =  4294967295???              'min value for a dword
MACRO MINVALUE_DW =  0???                          'min value for a dword

MACRO MAXVALUE_SW =  32767%                        'max value for a signed word
MACRO MINVALUE_SW = -32768%                        'min value for a signed word

MACRO MAXVALUE_UW =  65535??                       'max value for an unsigned word
MACRO MINVALUE_UW =  0??                           'min value for an unsigned word

MACRO MAXVALUE_SB =  127?                          'min value for a signed byte
MACRO MINVALUE_SB = -128?                          'min value for a signed byte

MACRO MAXVALUE_UB =  255                           'max value for a unsigned byte
MACRO MINVALUE_UB =  0                             'min value for a unsigned byte
'##################################################################################################
'
'##################################################################################################
%MAX_DW=4294967295
%MAX_LW=2147483647
%MIN_LW=-2147483648

%MAX_BYTE = 255?
%MAXIMUM_INT = 32767%
%MAXIMUM_DWORD = &HFFFFFFFF???
%MAXIMUM_LONG = &H7FFFFFFF&
%MINIMUM_LONG = &H80000000&

%ONE_FILETIME_DAY     =   600000000&& * 60&& * 24&&
%ONE_FT_DAY           =   864000000000&&   ' 864,000,000,000
%ONE_FILETIME_HOUR    =   %ONE_FILETIME_DAY \ 24
%ONE_FILETIME_MINUTE  =   %ONE_FILETIME_HOUR \ 60
%ONE_FILETIME_SECOND  =   %ONE_FILETIME_MINUTE \ 60

MACRO T_SECOND = (10000000)
MACRO T_MINUTE = (60 * T_SECOND)
MACRO T_HOUR   = (60 * T_MINUTE)
MACRO T_DAY    = (24 * T_HOUR)
MACRO T_1970   = (T_DAY * 134774)
'##################################################################################################
'
'##################################################################################################

MACRO UINT8 = BYTE
MACRO SINT16 = INTEGER
MACRO UINT16 = WORD
MACRO SINT32 = LONG
MACRO UINT32 = DWORD
MACRO SINT64 = QUAD

'##################################################################################################
'
'##################################################################################################
#IF NOT %DEF(%G_AK_INC)
%G_AK_INC=1

' Includes für X_BG und X_BF (DateToNumber und NumberToDate)

%MAXYEAR = 11734883???  'yes, the functions will handle dates up to December 31 of this year
%MAXDAY = 4285493616??? 'the maximum number of days allowed by the
'"NumberToDate" function. Corresponds to 12-31-%MAXYEAR

#ENDIF


MACRO PI1=3.141592653589793238462643383279#
MACRO PI2 = 6.2831853071796#

$G_TXT="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZüöäÜÖÄß[]{}@<>.1234567890_\-;:*+#§%&/()=!"
$G_Largeletter_engl="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$G_Num="0123456789"
$G_HEXNum="0123456789ABCDEF"

#IF NOT %DEF(%D_NUM_INC)
%D_NUM_INC=1

$D_NUM="0123456789"
$D_LET="abcdefghijklmnopqrstuvwxyzöüäßABCDEFGHIJKLMNOPQRSTUVWXYZÄÜÖ"
$D_FLA="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZüöäÜÖÄß'[]{}@|<>.1234567890_\-;:*+#§%&/()=! "
$D_FLB="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZüöäÜÖÄß'´`[]{}@.1234567890_-;+#§%&()=! "
$D_FLC="\/:*?<>|"+$DQ
$D_FLD=":\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZüöäÜÖÄß'[]{}@.1234567890_-;+#§%&()=! "
$D_FLE="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.1234567890_\ "
#ENDIF

'%MAX_QUAD=2^63-1&&
'##################################################################################################
'
'##################################################################################################
#IF NOT %DEF(%A_AU_FData_INC)
%A_AU_FData_INC=1
TYPE A_AU_FData
files AS QUAD ' Found Files muss auf 0 gesetzt werden
dirs AS QUAD  ' found dirs, muss auf 0 gesetzt werden
MODE AS DWORD ' 1 - pause, 2 - cancel operation 0 - normal
bytes AS QUAD ' enthält die Bytes die zurückgegeben werden
total AS QUAD ' Gesamtanzahl gefundener Items
END TYPE
#ENDIF

#IF NOT %DEF(%Type_D_List)
%Type_D_List=1

TYPE D_List
U AS LONG ' In Use = %True, Empty=%False
N AS DWORD ' Nr of Elements (0 - Liste ist leer)
D AS DWORD ' actual maximum Dimension
END TYPE
#ENDIF
'##################################################################################################
'
'##################################################################################################
MACRO A_AU_Reset(p1)
p1.files=0:p1.dirs=0:p1.mode=0:p1.bytes=0:p1.total=0
END MACRO
'##################################################################################################
'
'##################################################################################################
#IF NOT %DEF(%Prop_MACROS)
%Prop_MACROS = 1
MACRO PropGet(PropName,PropType)=PROPERTY GET PropName() AS PropType:PROPERTY=PropName:END PROPERTY
MACRO PropSet(PropName,PropType)=PROPERTY SET PropName(BYVAL param AS PropType):PropName=param:END PROPERTY
MACRO PropSetBR(PropName,PropType)=PROPERTY SET PropName(BYREF param AS PropType):PropName=param:END PROPERTY

' P1 - Unteres Limit, P2 - oberes Limit
MACRO PropSetCheck(PropName,PropType,P1,P2)
PROPERTY SET PropName(BYVAL param AS PropType)
IF (param>P2) THEN param=P2
IF (param<P1) THEN param=P1
PropName=param
END PROPERTY
END MACRO
MACRO PropGS(PropN,PropT)=PropGet(PropN,PropT):PropSet(PropN,PropT)
MACRO PropGSR(PropN,PropT)=PropGet(PropN,PropT):PropSetBR(PropN,PropT)
MACRO PropGSC(PropN,PropT,P1,P2)
PropGet(PropN,PropT)
PropSetCheck(PropN,PropT,P1,P2)
END MACRO

MACRO INST = INSTANCE
' P1 - Interfacevariable, P2 - Variable mit Objektpointer aus BYVAL Threadfunktion, P3 = "ThreadP" (Name der Klasse inkl. "")
' Beispiel: OpenClass(E1,T01,"ThreadP")
MACRO OpenClass(P1,P2,P3) = P1 = CLASS P3:POKE DWORD, VARPTR(P1),P2: P1.AddRef

' P1 - Threadhandle
MACRO WaitForThread(P1) =  WaitForSingleObject(P1,%INFINITE)

' P1 erstes Element eines Feldes mit Threadhandles, zum Beispiel "hThread(0)"
' P2 - Anzahl Threads
MACRO WaitForThreads(P1,P2) = WaitForMultipleObjects(P2,BYVAL VARPTR(P1), %TRUE, %INFINITE)

' Create a Non-Signaled, manual Reset Event - Needs later a  CloseHandle(P1)
' P1 = Long-Variable
MACRO MakeEventN(P1)
  P1=CreateEvent($NUL,%True,%False,$NUL)
END MACRO

' Create a Signaled, manual Reset Event - Needs later a  CloseHandle(P1)
' P1 = Long-Variable
MACRO MakeEventS(P1)
  P1=CreateEvent($NUL,%True,%True,$NUL)
END MACRO

' Create a Non-Signaled, Auto-Reset (Pulsed) Event - Needs later a  CloseHandle(P1)
' P1 = Long-Variable
MACRO MakeEventNP(P1)
  P1=CreateEvent($NUL,%False,%False,$NUL)
END MACRO

' Create a Signaled, manual Reset Event - Needs later a  CloseHandle(P1)
' P1 = Long-Variable
MACRO MakeEventSP(P1)
  P1=CreateEvent($NUL,%False,%True,$NUL)
END MACRO

MACRO WaitForEvent(P1)
   WaitForSingleObject(P1,%INFINITE)
END MACRO

' Dazu gehört noch  API: "SetEvent(X) und ResetEvent(X)

#ENDIF
' Signal-Events
' SetEvent(hEvent)
' ResetEvent (hEvent)
' PulseEvent(
' WaitForSingleObject(WR_HV_EH(T01),%INFINITE)
' WR_HV_EH(R01)=CreateEvent($NUL,0,0,$NUL)   -> CloseHandle(WR_HV_EH(R01))
' WaitForMultipleObjects T04+1, BYVAL VARPTR(hThread(0)), %TRUE, %INFINITE
'##################################################################################################
'
'##################################################################################################
' PowerBasic builtin Clases Construction
MACRO Make_StringbuilderA(P1) = LOCAL P1 AS ISTRINGBUILDERA: P1 = CLASS "StringbuilderA"
MACRO Make_StringbuilderW(P1) = LOCAL P1 AS ISTRINGBUILDERW: P1 = CLASS "StringbuilderW"
MACRO Make_Powertime(P1) = LOCAL P1 AS IPOWERTIME: P1 = CLASS "Powertime"
MACRO Make_Collection(P1) = LOCAL P1 AS IPOWERCOLLECTION: P1 = CLASS "PowerCollection"
MACRO Make_LinkedList(P1) = LOCAL P1 AS ILINKLISTCOLLECTION: P1 = CLASS "LinkListCollection"
MACRO Make_Stack(P1) = LOCAL P1 AS ISTACKCOLLECTION:P1 = CLASS "StackCollection"
MACRO Make_Que(P1) = LOCAL P1 AS IQUEUECOLLECTION:P1 = CLASS "QueueCollection"
MACRO Make_PowerThread(P1,P2) = LOCAL P1 AS IPOWERTHREAD: P1 = CLASS P2
'##################################################################################################
'
'##################################################################################################
' X_AQ() DoEventsAPI
#IF NOT %DEF(%X_AQ_INC)
%X_AQ_INC=1
SUB X_AQ()
ON ERROR RESUME NEXT
STATIC Msg AS tagMsg
IF PeekMessage(Msg,%NULL, 0, 0, %PM_REMOVE) THEN
TranslateMessage Msg:DispatchMessage Msg
END IF
END SUB
#ENDIF
'##################################################################################################
'
'##################################################################################################
#IF NOT %DEF(%X_GV_INC)
%X_GV_INC=1
' DoQueryEvents for Hwnd
'
SUB X_GV(hDlg AS LONG)
LOCAL Msg AS tagMsg
WHILE PeekMessage(Msg, %NULL, %NULL, %NULL, %PM_REMOVE)
  IF (IsDialogMessage(hDlg, Msg)=0) THEN
TranslateMessage Msg
DispatchMessage Msg
  END IF
WEND
END SUB
#ENDIF

'##################################################################################################
'
'##################################################################################################





output file

'##################################################################################################
'
'##################################################################################################
MACRO G_REG()
    REGISTER R01                        AS LONG
    REGISTER R02                        AS LONG
END MACRO

MACRO G_S01()
    LOCAL    S01                        AS STRING
END MACRO

MACRO G_S02()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
END MACRO

MACRO G_S03()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
END MACRO

MACRO G_S04()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
END MACRO

MACRO G_S05()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
    LOCAL    S05                        AS STRING
END MACRO

MACRO G_S06()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
    LOCAL    S05                        AS STRING
    LOCAL    S06                        AS STRING
END MACRO

MACRO G_S07()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
    LOCAL    S05                        AS STRING
    LOCAL    S06                        AS STRING
    LOCAL    S07                        AS STRING
END MACRO

MACRO G_S08()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
    LOCAL    S05                        AS STRING
    LOCAL    S06                        AS STRING
    LOCAL    S07                        AS STRING
    LOCAL    S08                        AS STRING
END MACRO

MACRO G_S09()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
    LOCAL    S05                        AS STRING
    LOCAL    S06                        AS STRING
    LOCAL    S07                        AS STRING
    LOCAL    S08                        AS STRING
    LOCAL    S09                        AS STRING
END MACRO

MACRO G_S10()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
    LOCAL    S05                        AS STRING
    LOCAL    S06                        AS STRING
    LOCAL    S07                        AS STRING
    LOCAL    S08                        AS STRING
    LOCAL    S09                        AS STRING
    LOCAL    S10                        AS STRING
END MACRO

MACRO G_S11()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
    LOCAL    S05                        AS STRING
    LOCAL    S06                        AS STRING
    LOCAL    S07                        AS STRING
    LOCAL    S08                        AS STRING
    LOCAL    S09                        AS STRING
    LOCAL    S10                        AS STRING
    LOCAL    S11                        AS STRING
END MACRO

MACRO G_S12()
    LOCAL    S01                        AS STRING
    LOCAL    S02                        AS STRING
    LOCAL    S03                        AS STRING
    LOCAL    S04                        AS STRING
    LOCAL    S05                        AS STRING
    LOCAL    S06                        AS STRING
    LOCAL    S07                        AS STRING
    LOCAL    S08                        AS STRING
    LOCAL    S09                        AS STRING
    LOCAL    S10                        AS STRING
    LOCAL    S11                        AS STRING
    LOCAL    S12                        AS STRING
END MACRO

MACRO G_T01()
    LOCAL    T01                        AS LONG
END MACRO

MACRO G_T02()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
END MACRO

MACRO G_T03()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
END MACRO

MACRO G_T04()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
END MACRO

MACRO G_T05()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
    LOCAL    T05                        AS LONG
END MACRO

MACRO G_T06()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
    LOCAL    T05                        AS LONG
    LOCAL    T06                        AS LONG
END MACRO

MACRO G_T07()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
    LOCAL    T05                        AS LONG
    LOCAL    T06                        AS LONG
    LOCAL    T07                        AS LONG
END MACRO

MACRO G_T08()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
    LOCAL    T05                        AS LONG
    LOCAL    T06                        AS LONG
    LOCAL    T07                        AS LONG
    LOCAL    T08                        AS LONG
END MACRO

MACRO G_T09()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
    LOCAL    T05                        AS LONG
    LOCAL    T06                        AS LONG
    LOCAL    T07                        AS LONG
    LOCAL    T08                        AS LONG
    LOCAL    T09                        AS LONG
END MACRO

MACRO G_T10()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
    LOCAL    T05                        AS LONG
    LOCAL    T06                        AS LONG
    LOCAL    T07                        AS LONG
    LOCAL    T08                        AS LONG
    LOCAL    T09                        AS LONG
    LOCAL    T10                        AS LONG
END MACRO

MACRO G_T11()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
    LOCAL    T05                        AS LONG
    LOCAL    T06                        AS LONG
    LOCAL    T07                        AS LONG
    LOCAL    T08                        AS LONG
    LOCAL    T09                        AS LONG
    LOCAL    T10                        AS LONG
    LOCAL    T11                        AS LONG
END MACRO

MACRO G_T12()
    LOCAL    T01                        AS LONG
    LOCAL    T02                        AS LONG
    LOCAL    T03                        AS LONG
    LOCAL    T04                        AS LONG
    LOCAL    T05                        AS LONG
    LOCAL    T06                        AS LONG
    LOCAL    T07                        AS LONG
    LOCAL    T08                        AS LONG
    LOCAL    T09                        AS LONG
    LOCAL    T10                        AS LONG
    LOCAL    T11                        AS LONG
    LOCAL    T12                        AS LONG
END MACRO

MACRO EXIF() = EXIT FUNCTION
MACRO EXIC() = EXIT SELECT
MACRO EXIS() = EXIT SUB

MACRO ENDS() = END SUB

MACRO ENDF_R01()
    FUNCTION = R01
END FUNCTION
END MACRO

MACRO ENDF_R02()
    FUNCTION = R02
END FUNCTION
END MACRO

MACRO ENDF_S01()
    FUNCTION = S01
END FUNCTION
END MACRO
'##################################################################################################
'
'##################################################################################################

FUNCTION How_got_here() AS STRING
    REGISTER R01                        AS LONG
    LOCAL    S01                        AS STRING
    FOR R01 = CALLSTKCOUNT TO 1 STEP - 1
        S01 += $CRLF + CALLSTK$(R01)
    NEXT
    S01 += "---------------------------------------" + $CRLF
    FUNCTION = S01
END FUNCTION
'##################################################################################################
'
'##################################################################################################
MACRO G_ERM(P1)
ero:
    G_ERO$ = "ERL: " + STR$(ERL) + " * " + P1 + ":" + ERROR$(ERR) + " * (" + STR$(ERR) + "). ERAPI=" + STR$(ERRAPI): G_AA G_ERO$: ERRCLEAR: RESUME NEXT
END MACRO

SUB G_AA(BYVAL a$)
    MSGBOX "An Error happened:" + $CRLF + a$,, "http://www.it-berater.org - Software Library"
    EXIT SUB
END SUB



#ENDIF
'##################################################################################################
'
'##################################################################################################


MACRO MAXVALUE_DL = 1.7976931348623157E + 308#             'max value for a double
MACRO MINVALUE_DL = - 1.7976931348623157E + 308#           'min value for a double

MACRO MAXVALUE_SN = 3.402823e + 38!                        'max value for a single
MACRO MINVALUE_SN = - 3.402823e + 38!                      'min value for a single

MACRO MAXVALUE_SQ = 9, 223, 372, 036, 854, 775, 807&&      'max value for a signed quad (64 bits)
MACRO MINVALUE_SQ = - 9, 223, 372, 036, 854, 775, 808&&    'min value for a signed quad (64 bits)

MACRO MAXVALUE_UQ = 18446744073709551615                   'max value for a unsigned quad (64 bits)
MACRO MINVALUE_UQ = 0                                      'min value for a unsigned quad (64 bits)

MACRO MAXVALUE_LN = 2147483647&                            'max value for a long
MACRO MINVALUE_LN = - 2147483648&                          'min value for a long

MACRO MAXVALUE_DW = 4294967295???                          'min value for a dword
MACRO MINVALUE_DW = 0???                                   'min value for a dword

MACRO MAXVALUE_SW = 32767%                                 'max value for a signed word
MACRO MINVALUE_SW = - 32768%                               'min value for a signed word

MACRO MAXVALUE_UW = 65535??                                'max value for an unsigned word
MACRO MINVALUE_UW = 0??                                    'min value for an unsigned word

MACRO MAXVALUE_SB = 127?                                   'min value for a signed byte
MACRO MINVALUE_SB = - 128?                                 'min value for a signed byte

MACRO MAXVALUE_UB = 255                                    'max value for a unsigned byte
MACRO MINVALUE_UB = 0                                      'min value for a unsigned byte
'##################################################################################################
'
'##################################################################################################
%MAX_DW                           = 4294967295
%MAX_LW                           = 2147483647
%MIN_LW                           = -2147483648

%MAX_BYTE                         = 255?
%MAXIMUM_INT                      = 32767%
%MAXIMUM_DWORD                    = &HFFFFFFFF???
%MAXIMUM_LONG                     = &H7FFFFFFF&
%MINIMUM_LONG                     = &H80000000&

%ONE_FILETIME_DAY                 = 600000000&&*60&&*24&&
%ONE_FT_DAY                       = 864000000000&&         ' 864,000,000,000
%ONE_FILETIME_HOUR                = %ONE_FILETIME_DAY\24
%ONE_FILETIME_MINUTE              = %ONE_FILETIME_HOUR\60
%ONE_FILETIME_SECOND              = %ONE_FILETIME_MINUTE\60


MACRO T_SECOND = (10000000)
MACRO T_MINUTE = (60 * T_SECOND)
MACRO T_HOUR = (60 * T_MINUTE)
MACRO T_DAY = (24 * T_HOUR)
MACRO T_1970 = (T_DAY * 134774)
'##################################################################################################
'
'##################################################################################################

MACRO UINT8 = BYTE
MACRO SINT16 = INTEGER
MACRO UINT16 = WORD
MACRO SINT32 = LONG
MACRO UINT32 = DWORD
MACRO SINT64 = QUAD

'##################################################################################################
'
'##################################################################################################
#IF NOT %DEF(%G_AK_INC)
%G_AK_INC                         = 1

    ' Includes für X_BG und X_BF (DateToNumber und NumberToDate)

%MAXYEAR                          = 11734883???            'yes, the functions will handle dates up to December 31 of this year
%MAXDAY                           = 4285493616???          'the maximum number of days allowed by the
    '"NumberToDate" function. Corresponds to 12-31-%MAXYEAR

#ENDIF



MACRO PI1 = 3.141592653589793238462643383279#
MACRO PI2 = 6.2831853071796#

$G_TXT                            = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZüöäÜÖÄß[]{}@<>.1234567890_\-;:*+#§%&/()=!"
$G_LARGELETTER_ENGL               = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$G_NUM                            = "0123456789"
$G_HEXNUM                         = "0123456789ABCDEF"

#IF NOT %DEF(%D_NUM_INC)
%D_NUM_INC                        = 1

$D_NUM                            = "0123456789"
$D_LET                            = "abcdefghijklmnopqrstuvwxyzöüäßABCDEFGHIJKLMNOPQRSTUVWXYZÄÜÖ"
$D_FLA                            = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZüöäÜÖÄß'[]{}@|<>.1234567890_\-;:*+#§%&/()=! "
$D_FLB                            = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZüöäÜÖÄß'´`[]{}@.1234567890_-;+#§%&()=! "
$D_FLC                            = "\/:*?<>|"+$DQ
$D_FLD                            = ":\abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZüöäÜÖÄß'[]{}@.1234567890_-;+#§%&()=! "
$D_FLE                            = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.1234567890_\ "
#ENDIF

'%MAX_QUAD=2^63-1&&
'##################################################################################################
'
'##################################################################################################
#IF NOT %DEF(%A_AU_FDATA_INC)
%A_AU_FDATA_INC                   = 1
    TYPE A_AU_FData
        files AS QUAD                                      ' Found Files muss auf 0 gesetzt werden
        dirs AS QUAD                                       ' found dirs, muss auf 0 gesetzt werden
        MODE AS DWORD                                      ' 1 - pause, 2 - cancel operation 0 - normal
        bytes AS QUAD                                      ' enthält die Bytes die zurückgegeben werden
        total AS QUAD                                      ' Gesamtanzahl gefundener Items
    END TYPE
#ENDIF

#IF NOT %DEF(%TYPE_D_LIST)
%TYPE_D_LIST                      = 1

    TYPE D_List
        U AS LONG                                          ' In Use = %True, Empty=%False
        N AS DWORD                                         ' Nr of Elements (0 - Liste ist leer)
        D AS DWORD                                         ' actual maximum Dimension
    END TYPE

#ENDIF
'##################################################################################################
'
'##################################################################################################
MACRO A_AU_Reset(p1)
    p1.files = 0: p1.dirs = 0: p1.mode = 0: p1.bytes = 0: p1.total = 0
END MACRO
'##################################################################################################
'
'##################################################################################################
#IF NOT %DEF(%PROP_MACROS)
%PROP_MACROS                      = 1
MACRO PropGet(PropName, PropType) = PROPERTY GET PropName() AS PropType: PROPERTY = PropName: END PROPERTY
MACRO PropSet(PropName, PropType) = PROPERTY SET PropName(BYVAL param AS PropType): PropName = param: END PROPERTY
MACRO PropSetBR(PropName, PropType) = PROPERTY SET PropName(BYREF param AS PropType): PropName = param: END PROPERTY




' P1 - Unteres Limit, P2 - oberes Limit
MACRO PropSetCheck(PropName, PropType, P1, P2)
    PROPERTY SET PropName(BYVAL param AS PropType)

        IF (param > P2) THEN param = P2
        IF (param < P1) THEN param = P1
        PropName = param
    END PROPERTY
END MACRO
MACRO PropGS(PropN, PropT) = PropGet(PropN, PropT): PropSet(PropN, PropT)
MACRO PropGSR(PropN, PropT) = PropGet(PropN, PropT): PropSetBR(PropN, PropT)
MACRO PropGSC(PropN, PropT, P1, P2)
    PropGet(PropN, PropT)
    PropSetCheck(PropN, PropT, P1, P2)
END MACRO

MACRO INST = INSTANCE
' P1 - Interfacevariable, P2 - Variable mit Objektpointer aus BYVAL Threadfunktion, P3 = "ThreadP" (Name der Klasse inkl. "")
' Beispiel: OpenClass(E1,T01,"ThreadP")
MACRO OpenClass(P1, P2, P3) = P1 = CLASS P3: POKE DWORD, VARPTR(P1), P2: P1.AddRef

' P1 - Threadhandle
MACRO WaitForThread(P1) = WaitForSingleObject(P1, %INFINITE)

' P1 erstes Element eines Feldes mit Threadhandles, zum Beispiel "hThread(0)"
' P2 - Anzahl Threads
MACRO WaitForThreads(P1, P2) = WaitForMultipleObjects(P2, BYVAL VARPTR(P1), %TRUE, %INFINITE)

' Create a Non-Signaled, manual Reset Event - Needs later a  CloseHandle(P1)
' P1 = Long-Variable
MACRO MakeEventN(P1)
    P1 = CreateEvent($NUL, %TRUE, %FALSE, $NUL)
END MACRO

' Create a Signaled, manual Reset Event - Needs later a  CloseHandle(P1)
' P1 = Long-Variable
MACRO MakeEventS(P1)
    P1 = CreateEvent($NUL, %TRUE, %TRUE, $NUL)
END MACRO

' Create a Non-Signaled, Auto-Reset (Pulsed) Event - Needs later a  CloseHandle(P1)
' P1 = Long-Variable
MACRO MakeEventNP(P1)
    P1 = CreateEvent($NUL, %FALSE, %FALSE, $NUL)
END MACRO

' Create a Signaled, manual Reset Event - Needs later a  CloseHandle(P1)
' P1 = Long-Variable
MACRO MakeEventSP(P1)
    P1 = CreateEvent($NUL, %FALSE, %TRUE, $NUL)
END MACRO

MACRO WaitForEvent(P1)
    WaitForSingleObject(P1, %INFINITE)
END MACRO

' Dazu gehört noch  API: "SetEvent(X) und ResetEvent(X)

#ENDIF
' Signal-Events
' SetEvent(hEvent)
' ResetEvent (hEvent)
' PulseEvent(
' WaitForSingleObject(WR_HV_EH(T01),%INFINITE)
' WR_HV_EH(R01)=CreateEvent($NUL,0,0,$NUL)   -> CloseHandle(WR_HV_EH(R01))
' WaitForMultipleObjects T04+1, BYVAL VARPTR(hThread(0)), %TRUE, %INFINITE
'##################################################################################################
'
'##################################################################################################
' PowerBasic builtin Clases Construction
MACRO Make_StringbuilderA(P1) = LOCAL P1 AS ISTRINGBUILDERA: P1 = CLASS "StringbuilderA"
MACRO Make_StringbuilderW(P1) = LOCAL P1 AS ISTRINGBUILDERW: P1 = CLASS "StringbuilderW"
MACRO Make_Powertime(P1) = LOCAL P1 AS IPOWERTIME: P1 = CLASS "Powertime"
MACRO Make_Collection(P1) = LOCAL P1 AS IPOWERCOLLECTION: P1 = CLASS "PowerCollection"
MACRO Make_LinkedList(P1) = LOCAL P1 AS ILINKLISTCOLLECTION: P1 = CLASS "LinkListCollection"
MACRO Make_Stack(P1) = LOCAL P1 AS ISTACKCOLLECTION: P1 = CLASS "StackCollection"
MACRO Make_Que(P1) = LOCAL P1 AS IQUEUECOLLECTION: P1 = CLASS "QueueCollection"
MACRO Make_PowerThread(P1, P2) = LOCAL P1 AS IPOWERTHREAD: P1 = CLASS P2
'##################################################################################################
'
'##################################################################################################
' X_AQ() DoEventsAPI
#IF NOT %DEF(%X_AQ_INC)
%X_AQ_INC                         = 1
    SUB X_AQ()
        ON ERROR RESUME NEXT
        STATIC   Msg                    AS tagMsg
        IF PeekMessage(Msg, %NULL, 0, 0, %PM_REMOVE) THEN
            TranslateMessage Msg: DispatchMessage Msg
        END IF
    END SUB
#ENDIF
'##################################################################################################
'
'##################################################################################################
#IF NOT %DEF(%X_GV_INC)
%X_GV_INC                         = 1
    ' DoQueryEvents for Hwnd
    '
    SUB X_GV(hDlg AS LONG)
        LOCAL    Msg                    AS tagMsg
        WHILE PeekMessage(Msg, %NULL, %NULL, %NULL, %PM_REMOVE)
            IF (IsDialogMessage(hDlg, Msg) = 0) THEN
                TranslateMessage Msg
                DispatchMessage Msg
            END IF
        WEND
    END SUB
#ENDIF

'##################################################################################################
'
'##################################################################################################

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on December 18, 2011, 08:59:01 AM
Ok, I'll try to translate that.

Quoteheo,

I'm sorry I posted that file.
> Ich entschuldige mich, die Datei gepostet zu haben.

Please explain to Peter:
> Bitte erkläre Peter

Noname1.bas is his file. It was in the RAR that he posted.
>Noname 1 ist seine Datei. Sie war in dem RAR File.

I was curious to see if his program could handle it but it did not.
>I Ich wolltesehen was sein Programm daraus macht, aber es hat damit nicht funktioniert.

The indenting ran way to the right and never reset to the left.
> Der Einzug lief nach rechts und kam nicht mehr nach links zurück.

The file I posted just pointed out where single line macros were and where multi-line macros started and ended.
> Die Datei die ich gepostet habe zeigt wo Single- und Multi-Line Macros anfangen und enden.

Macro Functions are only multi-line according to PB Help file.
> Macro Functionen sind immer Multi-Line Macros (PB Help File).

There are many of them in that file that are really single line macro and have no End Macro line.
> Es gibt in der Datei viele Single-Line Macros.

I will not download or test anything for at least a week. Hopefully by then Peter will have the program complete & tested.
> Ich werde in einer Woche nochmal vorbeischauen, vielleicht ist Peter dann ja schon weiter.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 18, 2011, 03:40:50 PM
Hello,
INSTANCE have built in Split Line

input:

INSTANCE arObj() AS VARIANT: INSTANCE arKey() AS STRING   


output:

        INSTANCE arObj()                AS VARIANT
        INSTANCE arKey()                AS STRING       

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 21, 2011, 03:35:11 PM
Hello,
A new error removed

old input:

%LIST_MODULES_ALL = %LIST_MODULES_32BIT OR% LIST_MODULES_64BIT         


old output:

%LIST_MODULES_ALL = %LIST_MODULES_32BITOR%LIST_MODULES_64BIT         


new output:

%LIST_MODULES_ALL                 = %LIST_MODULES_32BIT OR %LIST_MODULES_64BIT         
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 22, 2011, 08:10:46 PM
Hello,
have added new check button. There are therefore no longer blanks inserted. Because there are problems with macros to make this!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 23, 2011, 11:51:04 AM
Hello,
have errors in formatting removed with a new check button.

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 23, 2011, 08:58:59 PM
Hello,

new fixup. with IF Then Block

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 24, 2011, 09:37:19 PM
Hello,
I can not resist, even at Christmas. I have two little mistakes now eliminated!

You can test all'm grateful for any feedback! :)

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 25, 2011, 04:20:10 PM
Peter,

In the short time that I've looked at your latest code, it is my opinion that you have
WAY over complicated the program. It seems that every new glitch that you find causes
you to rework a large section of code and that introduces more glitches.

With no comments within the code as to exactly what is going on and why.  This leads
to errors in other sections caused by the new changes.

Your new options make changes in output of sections that are unrelated to what they
are meant to affect. Sometimes in a single run of your program  some variables are split
up and aligned  and in the next procedure all variables are pretty much as they were in
the source. Sometimes code gets indented way to the right as if you can not find the end
of a section. Other times it gets set to the left margin for dozens of sections or variables get
outdented 2 or 3 tab stops. And all this within 1 run.

LATER:
tried running in PB Debugger but kept getting error 9 array subscript error in
Function splitline.
END LATER

As near as I can tell you still haven't responded to all the points I made earlier.

You need to put a check on the reading of the .CFG file to make sure that it matches the
current UDT. And make sure that you update the current UDT from all the screen options
before doing any work.

And yes, it is very possible to do almost everything based on the original Line2Words arrays
with only 3 or 4 very small extra routines to handle the odd bit of coding.

I'll check back in about a month to see how you are getting along.

Happy New Year!!

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 25, 2011, 10:26:52 PM
Hi Paul,
occurred give me the line in your source code where the error is. So I can then look at what is the problem
Thank you!
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 25, 2011, 10:53:28 PM
small reference even for today

The thing Formatted at least now have super built today still TRY, CATCH, FINAL

Moreover FOR Next, DO LOOP WHILE WEND and whom in a row!
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 25, 2011, 11:03:33 PM
As I said, I'm not doing any more until at least the end of January 2012.

Too bad you tossed out so much code. All those PB keywords you mentioned were working
perfectly before you messed them up. They all are working perfectly in the code I've got.

Why don't you try TESTING the program before you post?



Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 25, 2011, 11:10:36 PM
Hi Paul,
Then you just go on time!

Mine is too stupid

I'm only time away from the project
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on December 29, 2011, 02:31:48 PM
Hi,

Found another thing we have to consider.

ALIGN BLOAT COM COMPILE COMPILER DEBUG DIM
ELSE ELSEIF ENDIF EXPORT IF INCLUDE MESSAGES
OPTION PBFORMS REGISTER RESOURCE STACK TOOLS UTILITY

are 21 PB keywords that normally start with # but have synonyms
that start with $.  At least in PB Win v10 & CC v6.
And that would cause them to be classed as string equates and may be
reformatted incorrectly.

How about changing the $ to # in the source as it gets processed after
Line2Words but before RebuildLine? Or maybe before Line2Words?
And maybe appending a small statement about the change to the
end of the output file?
That way it is taken care of once and we don't have to perform a check
every place to make sure we're not dealing with a string equate.

Just a thought as I'm not sure if anyone will actually use the $ form.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on December 29, 2011, 07:34:30 PM
Paul, 
you has quite that must be changed.  In Is_Space I have so rewritten which it it recognize!  In Line2Words and RebuildLine is there somewhat more work has unfortunately no time for it!
In Is_Space only one role plays $IF, $ELSE, $ELSEIF, $ENDIF, the remainder plays also no role for it!


FUNCTION Is_Space(BYREF s AS STRING) AS INTEGER

    STATIC cclass AS INTEGER
    STATIC cinterface AS INTEGER
    STATIC cmacro AS INTEGER
    STATIC cflag AS INTEGER
    STATIC cselect AS INTEGER

    LOCAL s1 AS STRING
    LOCAL pbword AS STRING
    LOCAL termstr AS STRING
    LOCAL i AS INTEGER
    LOCAL p AS LONG


    p = 1
    s1 = UCASE$(LTRIM$(s))
    findPBWord s1, p, pbword, termstr

    IF eflag THEN
        Einzug+=1
        eflag = 0
    END IF


    SELECT CASE pbword
        CASE "#ENDIF", "$ENDIF"
            Einzug+=-1

        CASE "END"
            findPBWord s1, p, pbword, termstr
            SELECT CASE pbword
                CASE "FUNCTION", "SUB", "FASTPROC", "METHOD", "PROPERTY", "IF", "TYPE", "UNION", "TRY"
                    Einzug+=-1

                CASE "SELECT"
                    IF cflag THEN
                        einzug+=-2
                    ELSE
                        Einzug+=-1
                    END IF

                CASE "MACRO"
                    Einzug+=-1
                    cmacro = %False
                CASE "INTERFACE"
                    Einzug+=-1
                    cinterface = 0
                CASE "CLASS"
                    Einzug+= -1
                    cclass = %False
            END SELECT
        CASE "ELSE", "ELSEIF", "#ELSE", "$ELSE", "#ELSEIF", "$ELSEIF", "CATCH", "FINALLY"
            eflag = %TRue
            einzug+=-1

        CASE "IF"
            IF find_Then(s1) THEN
                eflag = %true
            END IF

        CASE "SELECT"
            eflag = %TRUE
            cselect = %True
            cflag = %False
        CASE "CASE"
            IF cselect THEN
            IF cflag = %False THEN
                eflag =%TRUE
                cflag = %True
            ELSE
                Einzug+=-1
                eflag =%TRUE
            END IF
            END IF

        CASE "SUB", "#IF", "$IF", "TRY"
            eflag = %True
        CASE "FOR"
            IF FindBefehl("NEXT") = 0 THEN
                EFlag = %True
            END IF
        CASE "NEXT"
            Einzug+=-1
        CASE "TYPE"
            eflag = %TRUE
        CASE "DO"
            IF FindBefehl("LOOP") = 0 THEN
                eFlag = %TRUE
            END IF
        CASE "LOOP"
            Einzug+=-1


        CASE "WHILE"
            IF FindBefehl("WEND") = 0 THEN
                eFlag = %TRUE
            END IF
        CASE "WEND"
            Einzug+=-1
        CASE "CLASS"
            EFlag = %True
            cclass = %True



        CASE "INTERFACE"
            IF cclass THEN
                Eflag = %True
            ELSEIF cinterface = 0 THEN
                EFlag = %True
                cinterface = 1
            END IF


        CASE "FUNCTION", "FASTPROC", "CLASS"
            FOR i = p TO LEN(s1)
                termstr = MID$(s1, i, 1)
                IF termstr = "=" THEN
                    EXIT FOR
                ELSEIF termstr <> " " THEN
                    EFlag = %True
                    EXIT FOR
                END IF
            NEXT i
        CASE "MACRO"
            IF INSTR(s1, "=") = 0 THEN
                EFlag = %True
                cmacro = %True
            END IF


        CASE "METHOD", "PROPERTY"

            IF (cclass AND cinterface = 0) OR cmacro = %True THEN
                FOR i = p TO LEN(s1)
                    termstr = MID$(s1, i, 1)
                    IF termstr = "=" THEN
                        EXIT FOR
                    ELSEIF termstr <> " " THEN
                        EFlag = %True
                        EXIT FOR
                    END IF
                NEXT i
            END IF
        CASE "THREAD", "CALLBACK"
            findPBWord s1, p, pbword, termstr
            IF pbword = "FUNCTION" THEN
                EFlag = %True
            END IF
        CASE ELSE
    END SELECT
    IF Einzug < 0 THEN Einzug = 0

    FUNCTION = Einzug

END FUNCTION                           



Greet Peter 
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 06, 2012, 03:33:57 PM
Hello,
has small errors in Is_Space removes
TYPE SET has no introduction!


FUNCTION Is_Space(BYREF s AS STRING) AS INTEGER

    STATIC   cclass                     AS INTEGER
    STATIC   cinterface                 AS INTEGER
    STATIC   cmacro                     AS INTEGER
    STATIC   cflag                      AS INTEGER
    STATIC   cselect                    AS INTEGER

    LOCAL    s1                         AS STRING
    LOCAL    pbword                     AS STRING
    LOCAL    termstr                    AS STRING
    LOCAL    i                          AS INTEGER
    LOCAL    p                          AS LONG


    p = 1
    s1 = UCASE$(LTRIM$(s))
    findPBWord s1, p, pbword, termstr

    IF eflag THEN
        Einzug+=1
        eflag = 0
    END IF


    SELECT CASE pbword
        CASE "#ENDIF", "$ENDIF"
            Einzug+=-1

        CASE "END"
            findPBWord s1, p, pbword, termstr
            SELECT CASE pbword
                CASE "FUNCTION", "SUB", "FASTPROC", "METHOD", "PROPERTY", "IF", "TYPE", "UNION", "TRY"
                    Einzug+=-1

                CASE "SELECT"
                    IF cflag THEN
                        einzug+=-2
                    ELSE
                        Einzug+=-1
                    END IF
                    cflag = %True

                CASE "MACRO"
                    Einzug+=-1
                    cmacro = %False
                CASE "INTERFACE"
                    Einzug+=-1
                    cinterface = 0
                CASE "CLASS"
                    Einzug+= -1
                    cclass = %False
            END SELECT
        CASE "ELSE", "ELSEIF", "#ELSE", "$ELSE", "#ELSEIF", "$ELSEIF", "CATCH", "FINALLY"
            eflag = %TRue
            einzug+=-1

        CASE "IF"
            IF find_Then(s1) THEN
                eflag = %true
            END IF

        CASE "SELECT"
            eflag = %TRUE
            cselect = %True
            cflag = %False
        CASE "CASE"
            IF cselect THEN
                IF cflag = %False THEN
                    eflag =%TRUE
                    cflag = %True
                ELSE
                    Einzug+=-1
                    eflag =%TRUE
                END IF
            END IF

        CASE "SUB", "#IF", "$IF", "TRY"
            eflag = %True
        CASE "FOR"
            IF FindBefehl("NEXT") = 0 THEN
                EFlag = %True
            END IF
        CASE "NEXT"
            Einzug+=-1
        CASE "TYPE"
            findPBWord s1, p, pbword, termstr
            IF pbword <> "SET" THEN                                   ' 06.01.2012 TYPE Set does no Type
                eflag = %TRUE

            END IF
        CASE "DO"
            IF FindBefehl("LOOP") = 0 THEN
                eFlag = %TRUE
            END IF
        CASE "LOOP"
            Einzug+=-1


        CASE "WHILE"
            IF FindBefehl("WEND") = 0 THEN
                eFlag = %TRUE
            END IF
        CASE "WEND"
            Einzug+=-1
        CASE "CLASS"
            EFlag = %True
            cclass = %True



        CASE "INTERFACE"
            IF cclass THEN
                Eflag = %True
            ELSEIF cinterface = 0 THEN
                EFlag = %True
                cinterface = 1
            END IF


        CASE "FUNCTION", "FASTPROC", "CLASS"
            FOR i = p TO LEN(s1)
                termstr = MID$(s1, i, 1)
                IF termstr = "=" THEN
                    EXIT FOR
                ELSEIF termstr <> " " THEN
                    EFlag = %True
                    EXIT FOR
                END IF
            NEXT i
        CASE "MACRO"
            IF INSTR(s1, "=") = 0 THEN
                EFlag = %True
                cmacro = %True
            END IF


        CASE "METHOD", "PROPERTY"

            IF (cclass AND cinterface = 0) OR cmacro = %True THEN
                FOR i = p TO LEN(s1)
                    termstr = MID$(s1, i, 1)
                    IF termstr = "=" THEN
                        EXIT FOR
                    ELSEIF termstr <> " " THEN
                        EFlag = %True
                        EXIT FOR
                    END IF
                NEXT i
            END IF
        CASE "THREAD", "CALLBACK"
            findPBWord s1, p, pbword, termstr
            IF pbword = "FUNCTION" THEN
                EFlag = %True
            END IF
        CASE ELSE
    END SELECT
    IF Einzug < 0 THEN Einzug = 0

    FUNCTION = Einzug

END FUNCTION                         



Greet Peter 
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 07, 2012, 04:49:32 PM
Hello,
added $IF, $ELSEIF, $ENDIF in function RebuildLine () now! But I had to change also the function Line2Words ()!

New funktion  RebuildLine:

FUNCTION RebuildLine(BYREF w() AS STRING, BYREF wordcount AS LONG) AS STRING    ' 11/18/2011
    '----------------------------------------------------------------
    'Reassemble a source line from the individual tokens in string
    'array Words() standardize puncuation, spacing and indentation.
    '  w()         [in/out] array of source words/tokens
    '  wordcount   [in/out] # words/tokens in array
    ' NOPE   fo          [in/out] udt of formatting options
    'Returns the formatted source code line
    '----------------------------------------------------------------
    LOCAL    i&                                  ' NASTY HABIT
    LOCAL    stemp                      AS STRING
    LOCAL    comment                    AS STRING
    LOCAL    schr                       AS STRING
    LOCAL    spacer                     AS LONG  'helper with indenting
    LOCAL    WordNo                     AS LONG

    schr = LEFT$(w(1), 1)
    IF schr = "'" THEN
        m_ExitFunction(SPACE$(fc.indent) + w(1)) 'return full comment line
    ELSEIF UCASE$(LEFT$(w(1), 5)) = "DATA" THEN  'line is data
        m_ExitFunction(w(1))                     'return unmodified
    ELSEIF schr = "!" THEN
        IF LEN(w(2)) > 1 THEN                    'inline assembler comment
            stemp = LSET$(SPACE$(fc.indent) + w(1), fo.remcol - 1) + w(2)
        ELSE
            stemp = SPACE$(fc.indent) + w(1)
        END IF
        m_ExitFunction(stemp)
    END IF
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'If last item in token array is a inline comment, save it to
    'be inserted later.
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    schr = LEFT$(w(WordCount), 1)
    IF schr = "'" OR schr = ";" THEN
        comment = w(WordCount)
        IF LEN(comment) <= 1 THEN
            comment = ""                         'make blank line
        END IF
        DECR WordCount
    END IF
    IF w(1) = "ELSEIF" THEN

    END IF

    IF fo.lineupequates THEN
        schr = LEFT$(w(1), 1)
        IF (schr = "%" OR schr = "$") AND w(2) = "=" THEN    'test 1
            IF fo.capequates THEN
                w(1) = UCASE$(w(1))
            END IF
            i& = MAX&(LEN(w(1)) + 2, fo.equatescolumn - fc.indent)
            stemp = LSET$(w(1), i& - 2) + " ="
            FOR i& = 3 TO wordcount
                stemp = stemp + " " + TRIM$(w(i&))
            NEXT
            IF LEN(comment) AND LEN(stemp) < fo.remcol - 1 THEN
                stemp = SPACE$(fc.indent) + LSET$(stemp, fo.remcol - 1) + TRIM$(comment)
            ELSE
                'w(0) = comment
                stemp = SPACE$(fc.indent) + RTRIM$(stemp) & SPACE$(fo.tabsize) & comment    ' 11/18/2011 PDE
                comment = ""
            END IF
            m_ExitFunction(stemp)
        END IF
    END IF
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'process each token in array w()
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    stemp = ""
    DO
        INCR WordNo                              'first/next word
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'Is word abreviated print statement ?. Expand and capitilize
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        schr = LEFT$(w(WordNo), 1)
        IF w(WordNo) = "?" THEN                  'expand to PRINT (PBCC)
            w(WordNo) = "PRINT"
        ELSEIF schr = $DQ THEN                   'string literal
            stemp = stemp + w(WordNo) + " "      'simply add it
            ITERATE DO
        ELSEIF schr = "%" OR schr = "$" THEN     'equates
            IF fo.capequates THEN
                w(WordNo) = UCASE$(w(WordNo))
            END IF
        ELSEIF schr = "!" THEN
            stemp = stemp + w(WordNo)            'assembler line
            spacer = fc.indent
            fc.indent = 0
            EXIT DO
        END IF

        SELECT CASE UCASE$(w(WordNo))            'process the token
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                'Check to see if token is a label (wordcount = 2), only thing
                'allowed on a line with a label is a comment and that was
                'removed above. Should it fail this test its assumed to be
                'part of a multi-statement line. Labels always start in col 1
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CASE ":"                             'check for label
                stemp = RTRIM$(stemp)
                IF WordCount = 2 THEN            'we assume a label (name + :)
                    spacer = fc.indent           'save indent value
                    fc.indent = 0                'move label to left margin
                END IF
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                'Try to distinguish between array and something else as to
                'whether or not there should be a space preecding these. Need
                'to test for a PB intrinsic function like ATTRIB(xxx) vs OR
                '(xx + yy).
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CASE "(", "["
                IF INSTR( "+-*/\=><", w(WordNo - 1)) = 0 THEN
                    stemp = RTRIM$(stemp)
                END IF
                SELECT CASE UCASE$(w(WordNo - 1))
                    CASE "IF", "ELSEIF", "AND", "OR", "NOT", "ISFALSE", "ISTRUE", "XOR", "TO"
                        stemp = stemp + " "      'add spacing
                END SELECT
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                'We never want any space to proceed these delimiters
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CASE ")", ",", "]", "[", ";", "."
                stemp = RTRIM$(stemp)            'no preceding space
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                'Catch <>, >=, <= combinations to eliminate < >, > =,. etc.
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CASE "<", ">", "="
                IF INSTR( "<>=+-*ORAND", w(WordNo - 1)) THEN    ' 05/06/2011 PDE added + - * not sure how to handle OR AND
                    stemp = RTRIM$(stemp)
                END IF
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                'Compare last token to THEN, nothing else on line means started
                'a multi-line IF block. Any comment already removed above.
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CASE "THEN"
                IF WordNo = WordCount THEN
                    spacer = spacer + fo.tabsize 'change for next line
                END IF
            CASE "TYPE"                          '06.01.2012   for TYPE SET
                IF (WordNo = 1) AND (w(WordNo + 1) <> "SET") THEN spacer = spacer + fo.tabsize

            CASE "UNION", "TRY", "FUNCTION", "SUB", "INTERFACE", "PROPERTY"
                IF (WordNo = 1) AND (w(WordNo + 1) <> "=") THEN spacer = spacer + fo.tabsize

            CASE "CLASS"
                IF WordNo = 1 AND UCASE$(w(WordNo + 1)) <> "METHOD" THEN
                    INCR fc.inClass
                END IF
                IF WordNo = 1 AND w(WordNo + 1) <> "=" THEN spacer = spacer + fo.tabsize

            CASE "METHOD"
                IF WordNo = 1 AND fc.inClass > 0 THEN
                    IF INSTR(ztext(CurrentLine), "=") = 0 THEN
                        spacer = spacer + fo.tabsize    ' next line
                    END IF
                END IF

                '         case "FOR"
                '          if Is_there(w(),"NEXT",WordCount) then
                '             IF (WordNo = 1) THEN spacer = spacer + fo.tabsize
                '          end if
                Construct( "FOR", "NEXT")
                Construct( "WHILE", "WEND")
                Construct( "DO", "LOOP")

            CASE "MACRO"
                IF WordNo = 1 AND UCASE$(w(2)) = "FUNCTION" OR (wordNo = 1 AND INSTR(zText(currentline), "=") = 0) THEN
                    spacer = spacer + fo.tabsize
                END IF
            CASE "CALLBACK"                      ' 05/09/2011 PDE need to indent same as normal FUNCTION
                IF WordNo = 1 AND UCASE$(w(2)) = "FUNCTION" THEN
                    spacer = spacer + fo.tabsize
                END IF
            CASE "SELECT"
                IF WordNo = 1 THEN spacer = spacer + (fo.tabsize * 2)
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                'Handle ELSEIF seperately since it appears on same line with THEN
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CASE "#IF", "$IF"                    'these require no line ending THEN   06.01.2012 $IF
                spacer = spacer + fo.tabsize
            CASE "ELSEIF"
                fc.indent = fc.indent - fo.tabsize    'change for this line


            CASE "#ELSEIF", "$ELSEIF", "#ELSE", "$ELSE"    '06.01.2012 for $ELSEIF or $ELSE
                fc.indent = fc.indent - fo.tabsize    'change for this line

            CASE "#ENDIF", "$ENDIF"              '06.01,2012  for $ENDIF
                fc.indent = fc.indent - fo.tabsize

            CASE "ELSE", "CASE"
                IF WordNo = 1 THEN               'first word?
                    spacer = spacer + fo.tabsize 'change for next line
                    fc.indent = fc.indent - fo.tabsize    'change for this line
                END IF
            CASE "END"
                SELECT CASE UCASE$(w(WordNo + 1))
                    CASE "TYPE", "IF", "UNION", "SUB", "FUNCTION", "INTERFACE", "TRY", "MACRO", "METHOD", "PROPERTY"
                        fc.indent = fc.indent - fo.tabsize
                    CASE "CLASS"
                        DECR fc.inClass
                        spacer = 0               ' next line
                        fc.indent = fc.indent - fo.tabsize    ' this line
                    CASE "SELECT"
                        fc.indent = fc.indent - (fo.tabsize * 2)
                END SELECT
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                'Check for the close of a looping block. If its on the same
                'line as loop start, keep same indent.
                '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CASE "WEND", "NEXT", "LOOP"
                IF wordno = 1 THEN
                    schr = UCASE$(stemp)         'standardize
                    spacer = 0                   'be sure this = 0
                    fc.indent = fc.indent - fo.tabsize    'default is close loop
                    IF INSTR(schr, "DO ") THEN   'test
                        fc.indent = fc.indent + fo.tabsize
                    ELSEIF INSTR(schr, "WHILE ") THEN
                        fc.indent = fc.indent + fo.tabsize
                    ELSEIF INSTR(schr, "ITERATE") THEN
                        fc.indent = fc.indent + fo.tabsize
                    END IF
                END IF
        END SELECT

        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'No space following "([]"
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        IF w(wordno) = "." THEN
            stemp = RTRIM$(stemp) + "."
        ELSEIF INSTR( "(][", w(WordNo - 1)) THEN
            stemp = RTRIM$(stemp) + w(WordNo) + " "
        ELSE
            stemp = stemp + w(WordNo) + " "
        END IF
    LOOP WHILE WordNo < WordCount
    IF fc.indent < 0 THEN fc.indent = 0          'stay at left margin
    stemp = SPACE$(fc.indent) + RTRIM$(stemp)    'final formated line
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'Add any line comment preserved above. Fit failure returns
    'inline comment in w(0)
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    w(0) = ""
    IF LEN(comment) THEN
        IF LEN(stemp) < fo.remcol THEN
            stemp = LEFT$(stemp + SPACE$(fo.RemCol - 1), fo.RemCol - 1) + comment
        ELSE
            ' w(0) = SPACE$(fo.indent) + comment
            stemp = RTRIM$(stemp) & SPACE$(fo.tabsize) & comment    ' 11/18/2011
            comment = ""
        END IF
    END IF
    fc.indent = fc.indent + spacer               'new indent value
    FUNCTION = stemp                             'return formatted source line
END FUNCTION                                                                     


New function Line2Words

FUNCTION Line2Words(BYREF work AS ASCIZ * %MAX_LINELEN, BYREF w() AS STRING) AS LONG    ' 11/18/2011
    '-------------------------------------------------------------------
    'Parse source line into word/token array w(). Handle special cases for
    'REM, DATA, string literals, ASM, !, '.
    '  work     [in/out] source code line text
    '  w()      [in/out] array of words/tokens
    ' NOPE  fo       [in/out] udt of formatting options
    'Returns count of words/tokens found
    '-------------------------------------------------------------------
    LOCAL    stemp                      AS STRING
    LOCAL    ncount                     AS LONG  'word/token count
    LOCAL    pchr                       AS BYTE PTR
    LOCAL    s1                         AS LONG

    ' REPLACE $TAB WITH SPACE$(fo.tabsize) IN work *** replaced with following 05/06/2011 PDE
    work = TAB$(work, fo.tabsize)

    work = S_TRIMBA(work)
    'X_AU "-----------------------------------"+$CRLF+TRIM$(work)+$CRLF+"--------------------------"
    stemp = UCASE$(TRIM$(work))                            'standardize incomming text
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'These need no or limited processing
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    IF LEFT$(stemp, 1) = "'" OR _                          'remark
        LEN(stemp) = 0 OR _                                    'blank line
        LEFT$(stemp, 5) = "DATA " THEN                         'DATA statments ignored
        w(1) = TRIM$(work)
        m_ExitFunction(1)
    ELSEIF LEFT$(stemp, 4) = "REM " THEN
        w(1) = "'" + TRIM$(MID$(work, 5))                  'replace REM with '
        m_ExitFunction(1)
    ELSEIF LEFT$(stemp, 4) = "ASM " THEN                   'replace ASM with !
        w(1) = "!" + RTRIM$(EXTRACT$(MID$(work, 5), ANY "';"))
        w(2) = ";" + TRIM$(REMAIN$(work, ANY ";'"))
        m_ExitFunction(2)
    ELSEIF LEFT$(stemp, 1) = "!" THEN
        w(1) = TRIM$(EXTRACT$(work, ANY "';"))             'up to any comment
        w(2) = ";" + TRIM$(REMAIN$(work, ANY ";'"))
        m_ExitFunction(2)                                  'two words/tokens
    END IF
    stemp = ""                                             'clear for reuse
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    'Parse remainder
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    pchr = VARPTR(work)                                    'point to first byte
    DO
        IF @pchr = 34 THEN                                 'quote start?
            GOSUB SaveWord                                 'save any current word/token
            s1 = pchr                                      'save string start
            DO
                INCR pchr                                  'next string character
            LOOP UNTIL @pchr = 34                          'quoted string finished
            stemp = PEEK$(s1, pchr - s1 + 1)
            GOSUB SaveWord
            INCR pchr                                      'next byte/character
            ITERATE DO
        END IF
        IF @pchr = 39 THEN                                 'inline "'" remark
            GOSUB SaveWord
            'balance of line
            stemp = MID$(work, pchr - VARPTR(work) + 1)
            EXIT DO                                        'line done
        END IF
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        'Check for one of the standard delimters
        '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        IF INSTR( " ,\=+-/^*)(:[];><.", CHR$(@pchr)) THEN
            GOSUB SaveWord
            IF @pchr <> 32 THEN
                stemp = CHR$(@pchr)
                GOSUB SaveWord
            END IF
        ELSE
            stemp = stemp + CHR$(@pchr)                    'add char to current token
        END IF
        INCR pchr
    LOOP WHILE @pchr <> 0                                  'check for line end
    GOSUB SaveWord
    m_ExitFunction(ncount)                                 'return token count

    SaveWord:
    IF LEN(stemp) THEN                                     'anything to do?
        INCR ncount                                        'next array element
        w(ncount) = stemp                                  'save it
        w(ncount+1) =""                                    'kill next Element    07.01.2012
        '   X_AU STR$(ncount)+"-"+stemp
        stemp = ""                                         'erase working string
    END IF
    RETURN

END FUNCTION                           


Greet Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 12, 2012, 09:10:45 PM
Hello
here times a picture of new version.  Become the source code however only post whom everything well runs

greetings Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 13, 2012, 12:14:59 PM
Hello, 
changed the functions Is_Space, RebuildLine and inserted the keyword ASMDATA. That was not considered up to now!

However not yet the version is 3. Still the old version is 2. With it can be worked however already well!

Greet Peter   
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 13, 2012, 03:04:18 PM
Peter,

I do not mean to belittle your programming skills. That is NOT my intention.
As we can never meet face to face or talk, the only way I can try to motivate you is via this forum.
If I had never made the type of remarks that I made,  would you have worked on a better version?
Or would you have sat back and waited for someone else to fix the problems?

I do have a couple hints for you.
Move all your static variables in DoFormat.inc into the fmtcommon udt.
Where you set them to 1  try incrementing them. This will allow for nested conditions.
Where you set them to 0  try decrmenting them but don't go lower than 0 as that means
you have a logic error and the reason should be fixed.
Make sure that if you increment a variable for a specific reason that you have a check that
is the end of that specific reason and decrment it.
..  for example if you flag the start of a Class then you must check for End of Class.

It is still a good idea to move the check for #PBForms down into RebuildLine. No need to
clutter up a huge section of code for a simple check.

Good programming!

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 13, 2012, 04:29:11 PM
Hello Paul,
you can change it at any time the program code. Put the changed code then simply on the forum! Then we can find a common basis! Isolating the functions Is_Space and and RebuildLine must be! Because some macros with RebuildLine not to go can. Whom I take and into RebuildLine am #PBForms from DoFormat! then I must write it also once again in Is_Space!
And on the topic Class! The end of the Class is tested! See here


CASE "END"
            findPBWord s1, p, pbword, termstr
            SELECT CASE pbword
                CASE "FUNCTION", "SUB", "FASTPROC", "METHOD", "PROPERTY", "IF", "TYPE", "UNION", "TRY", "ASMDATA"
                    Einzug += - 1
                CASE "SELECT"
                    IF cflag THEN
                        einzug += - 2
                    ELSE
                        Einzug += - 1
                    END IF
                    cflag = %TRUE
                CASE "MACRO"
                    Einzug += - 1
                    cmacro = %FALSE
                CASE "INTERFACE"
                    Einzug += - 1
                    cinterface = 0
                CASE "CLASS"
                    Einzug += - 1
                    cclass = %FALSE
            END SELECT                 


in addition is the result crucial! See here!



#COMPILE DLL
#DIM ALL
#RESOURCE "collection.pbr"
#COM DOC "Dies ist ein Test"
#COM NAME "Collection", 1.1
#COM GUID GUID$( "{85AF93DB-EF37-4916-BE38-CE32985B9C63}")
#COM TLIB ON

%LIST_MODULES_ALL                 = %LIST_MODULES_32BIT AND %LIST_MODULES_64BIT



#IF NOT %DEF(%CCOLLECTIONINC)
    %CCOLLECTIONINC               = 1


    INTERFACE ICollectionEvent GUID$( "{BC0DA08D-A429-42E7-BEC2-0FC5C56C131F}") AS EVENT
        INHERIT IAUTOMATION
        METHOD BevoreAdd(BYVAL nCount AS DWORD)


        METHOD AfterAdd(BYVAL nCount AS DWORD)


        METHOD ItemRemoved(oKey AS VARIANT)


        METHOD ERROR(BYVAL nNumber AS DWORD)

    END INTERFACE


    CLASS CCollection GUID$( "{BE08C50D-1D02-4A0A-8FA6-514E365B848F}") AS COM
        INSTANCE arObj()                AS VARIANT
        INSTANCE arKey()                AS STRING
        INSTANCE nCounter               AS DWORD

        CLASS METHOD DESTROY()
            ERASE arObj()
            ERASE arKey()
        END METHOD

        CLASS METHOD GetArIndex(sKey AS STRING) AS DWORD
            LOCAL    i                  AS DWORD
            ARRAY SCAN arKey(), COLLATE UCASE, = sKey, TO i
            METHOD = i
        END METHOD

        CLASS METHOD RemoveFromObjAr(BYVAL nIndex AS DWORD)
            LOCAL    i                  AS DWORD

            FOR i = nIndex TO UBOUND(arObj())
                IF nIndex > 0 THEN
                    SWAP arobj(i - 1), arobj(i)
                    SWAP arKey(i - 1), arkey(i)
                ELSE
                    IF i < UBOUND(arObj()) THEN
                        SWAP arobj(i), arobj(i + 1)
                        SWAP arKey(i), arKey(i + 1)
                    ELSE
                        i = 1
                    END IF
                END IF
            NEXT

            IF nCounter - 1 = 0 THEN
                REDIM    arobj(nCounter - 1)
                REDIM    arKey(nCounter - 1)
            ELSE
                REDIM    PRESERVE arobj(nCounter - 1)
                REDIM    PRESERVE arKey(nCounter - 1)
            END IF
        END METHOD

        INTERFACE ICollection GUID$( "{F975C92B-988F-4FA8-9BBA-6762C27014A7}")
            INHERIT IDISPATCH

            PROPERTY GET COUNT() AS DWORD
                PROPERTY = nCounter
            END PROPERTY

            PROPERTY GET GetKey(BYVAL nIndex AS DWORD) AS STRING
                IF nIndex < LBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(3)
                    EXIT PROPERTY
                END IF
                IF nIndex > UBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(4)
                    EXIT PROPERTY
                END IF
                PROPERTY = arKey(nIndex)
            END PROPERTY

            PROPERTY GET GetItemDirect(BYVAL nIndex AS DWORD) AS VARIANT
                IF nIndex < LBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(3)
                    EXIT PROPERTY
                END IF
                IF nIndex > UBOUND(arKey()) THEN
                    RAISEEVENT ICollectionEvent.Error(4)
                    EXIT PROPERTY
                END IF
                PROPERTY = arObj(nIndex)
            END PROPERTY


            METHOD ADD(BYVAL obj AS VARIANT, OPT BYVAL oKey AS VARIANT) AS DWORD
                LOCAL    s              AS STRING

                RAISEEVENT ICollectionEvent.BevoreAdd(nCounter)
                IF ISMISSING(oKey) THEN oKey = STR$(nCounter + 1)

                SELECT CASE VARIANTVT(oKey)
                    CASE %VT_BSTR: s = UCASE$(VARIANT$(oKey))
                    CASE ELSE: s = STR$(VARIANT#(oKey))
                END SELECT

                IF me.GetArIndex(s) > 0 THEN
                    RAISEEVENT ICollectionEvent.Error(1)
                    EXIT METHOD
                END IF

                nCounter += 1
                REDIM    PRESERVE arObj(nCounter)
                REDIM    PRESERVE arKey(nCounter)
                arObj(nCounter) = obj
                arKey(nCounter) = s

                RAISEEVENT ICollectionEvent.AfterAdd(nCounter)
                METHOD = nCounter
            END METHOD

            METHOD Remove(BYVAL nItemOrKey AS VARIANT) AS DWORD
                LOCAL    s              AS STRING
                LOCAL    n              AS DWORD

                SELECT CASE VARIANTVT(nItemOrKey)
                    CASE %VT_BSTR: s = UCASE$(VARIANT$(nItemOrKey))
                    CASE ELSE
                        n = VARIANT#(nItemOrKey)
                        Me.RemoveFromObjAr(n)
                        nCounter -= 1
                        METHOD = n
                        RAISEEVENT ICollectionEvent.ItemRemoved(nItemOrKey)
                        EXIT METHOD
                END SELECT
                n = me.GetArIndex(s)
                IF n < 1 THEN
                    RAISEEVENT ICollectionEvent.Error(1)
                    EXIT METHOD
                END IF
                Me.RemoveFromObjAr(n)
                nCounter -= 1

                RAISEEVENT ICollectionEvent.ItemRemoved(nItemOrKey)
                METHOD = n
            END METHOD

            METHOD ITEM(BYVAL nItemOrKey AS VARIANT) AS VARIANT
                LOCAL    s              AS STRING
                LOCAL    n              AS DWORD

                SELECT CASE VARIANTVT(nItemOrKey)
                    CASE %VT_BSTR
                        s = UCASE$(VARIANT$(nItemOrKey))
                        n = Me.GetArIndex(s) - 1
                        IF n > 0 THEN METHOD = arObj(n)
                        EXIT METHOD
                    CASE ELSE
                        METHOD = arObj(VARIANT#(nItemOrKey))
                        EXIT METHOD
                END SELECT
                RAISEEVENT ICollectionEvent.Error(2)
            END METHOD


        END INTERFACE

        EVENT SOURCE ICollectionEvent
    END CLASS
#ENDIF

                                                             


Greet Peter 
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 13, 2012, 05:03:39 PM
Peter,

#PBForms should not change any other line or indentation or function.
Plain & simple it starts in column 1. Print it & forget it.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 13, 2012, 06:12:12 PM
Hello Paul
#PBFORMS begins in the first column.  Therefore in function in DoFormat and not in Is_Space and RebuildLine!

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 13, 2012, 07:47:45 PM
It only needs to be in 1 routine RebuildLine along with ALL the other PB keywords.
Otherwise you must document every exception and where they are found and why.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 13, 2012, 08:17:58 PM
Hello Paul,
that I to also wish however it not function not, with all macros that already tested myself I!
Line2Words deletes all blanks!  And RebuildLine does not add blanks in addition where to be may.  That cannot be done with some macros any longer and the compilers brings then an error!
Therefore also the option inserts blanks!


Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 13, 2012, 08:58:31 PM
Hello Paul, 

has now macro searched with the RebuildLine does not go and also not to go cannot! It does not insert a blank where be may!

MACRO WR_MM(P1,P2,P3)=P2=P1.nRight:P3=P1.nBottom

RebuildLine inserts a blank after after comma of P1. That macro does not function thereafter any longer! Ask Theo. Therefore also the option with inserts blanks. Around to go around the function Is_Space was inserted

greetings Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 14, 2012, 12:42:58 PM
Peter,

If you need to bypass rebuilding a certain line then look at the top part of Line2Words and
RebuildLine.
There are already a couple others that skip rebuilding.
That makes it neat & clean and easily understood.

BUT beware. For MACROs you might need to do several lines and not all will start with Macro.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 14, 2012, 01:29:38 PM
Paul, 
is a good idea! then make that times! But the introduction must remain! Only the blanks may not be worked on!

I am busy straight with the IDE of Version 3!

Greet Peter 
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 14, 2012, 02:50:49 PM
Peter,

It is up to you to make the changes. Not me.

You don't like the way that I program.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 14, 2012, 04:54:50 PM
By the way this code works spaced out or without spaces.
I just tried it in PB v10.


TYPE dotit
   a AS LONG
   b AS LONG
END TYPE

MACRO ab(p1 , p2 , p3) = p2 = p1.a: p3 = p1.b
FUNCTION PBMAIN () AS LONG
   LOCAL dots AS dotit
   LOCAL a AS LONG
   LOCAL b AS LONG

   dots.a = 5
   dots.b = 7
   ab(dots,a,b)
   ? "a =" & STR$(a) & "  b =" & STR$(b)     

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 14, 2012, 10:04:39 PM
Paul, 
you errs! That   Macro does not go! RebuildLine adds after the comma   a blank with the call!

You have the blank simply out calmly then already function it!

Attention blank with the call macros and not in the macro!!


#COMPILE EXE
#DIM ALL

MACRO ab(p1 , p2 , p3) = p2 = p1.a: p3 = p1.b

TYPE dotit
   a AS LONG
   b AS LONG
END TYPE

FUNCTION PBMAIN () AS LONG

   LOCAL dots AS dotit
   LOCAL a AS LONG
   LOCAL b AS LONG

   dots.a = 5
   dots.b = 7
   ab(dots,a,b)    ' this go
   
   ab(dots, a, b)  ' this not    Compiler Error

END FUNCTION

                               

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 14, 2012, 10:55:02 PM
Then it is up to you to keep track of every Macro and make sure that where they are used
is not reformatted. Don't forget to check for multiple macros within a line and nested macro
definitions.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 14, 2012, 11:16:02 PM
And just to be picky, YOU were the one that said it caused a problem with
the MACRO line. Nothing about the regular source line where the macro
is used.    ;D
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 15, 2012, 12:24:49 AM
Hello Paul,
you should look sometimes more deeply purely and not not always only grumble if you the background understands!

I do not have you the opportunity given it to change however you wanted!

You grumble only in this forum at each contribution all the same from whom it are!

Greet Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 15, 2012, 12:47:13 AM
Peter,

I don't fully understand what you just said.

But you were the one who said that there was a problem with Macro.
And as you are the one changing the code  I said it was up to you to fix it.
Not really grumbling ... just stating fact.

Here I am just trying to be helpful and my karma points keep getting lower.
Guess I'm going to be going thru a few more rebirths just to break even.

Oh well. So be it.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 15, 2012, 10:08:15 PM
Hallo,

ENUM added in addition. Version 2

greetings Peter

Title: Re: Code-Formatter PB 10
Post by: Plamen Chobanov on January 18, 2012, 09:20:25 PM
Hello,
i test it !

Source:
LOCAL s AS STRING, s1 AS STRING, s2 AS STRING, _
          n AS LONG, n1 AS LONG


Format:
    LOCAL    s                          AS STRING
    LOCAL    s1                        AS STRING
    LOCAL    s2                        AS STRING
    LOCAL                                  AS LONG
    LOCAL    n1                        AS LONG


___
Plamen
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 18, 2012, 11:10:09 PM
Hello Plamen Chobanov,

thanks that it me on it made attentive.

I will eliminate the error

greetings Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 18, 2012, 11:21:41 PM
Hello Plamen Chobanov,
I has it straight tested with me looks so out!

input:

LOCAL s AS STRING, s1 AS STRING, s2 AS STRING, _
          n AS LONG, n1 AS LONG


output:


    LOCAL    s                          AS STRING
    LOCAL    s1                         AS STRING
    LOCAL    s2                         AS STRING
    LOCAL    n                          AS LONG
    LOCAL    n1                         AS LONG       




Can it be it the last version code of the Formater does not have?

Greet Peter

Here is the current version!
Title: Re: Code-Formatter PB 10
Post by: Plamen Chobanov on January 19, 2012, 01:59:44 PM
Hello Peter Weis,
I located problem !

In row i have <Tab>=[09]:
hex: 20 5F 0D 0A 09 20 6E 20 41 53
txt:     _  .  .  ?     n     A  S


___
Plamen
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 19, 2012, 06:23:49 PM
Peter,

Easy way is to move this line
work = Tab$(work, fo.tabsize)
                                   
from Line2Words to the loop where you load the array in DoFormat

    FileScan fc.fhin, Records To TotalLines                'total source code lines
    ReDim    zText(1 To TotalLines)

    For currentline = 1 To totallines
        Line Input #fc.fhin, ztext(currentline)
    Next


It needs a little changing to work there.

See ... no growling or grumbling.


             
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 19, 2012, 08:32:45 PM
Peter,

Plus you can load the array without going thru the loop by

Line Input #fc.fhin, zText() 

and just use the loop to expand the tab characters.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 19, 2012, 10:50:24 PM
Hello Paul,
that was also my first thought with TAB$, but formatting must also with Tab in the source code functioning.  And I have that today made additionally I an option inserted. Tabs out pour to code far away!


FOR currentline = 1 TO totallines
        LINE INPUT #fc.fhin, ztext(currentline)
        IF fo.reblacetabs THEN
            ztext(currentline) = TAB$(ztext(currentline), fo.removetabsize)
        END IF
    NEXT



Greet Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 19, 2012, 11:24:32 PM
Hello Plamen Chobanov,
tomorrow, gets the new version! Thanks still for tap! With me w. the error not arisen, because I did not have a Tab in the source code!

Greet Peter 
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 20, 2012, 06:39:15 AM
Hello,
version 2 changed it with tab goes in such a way!

Greet Peter
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 21, 2012, 12:56:16 AM
Hello,
here times a picture of new version V3 beta.

Greet Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on January 21, 2012, 09:52:22 PM
Looks good to me.
Anyway, the final test is when its ready.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 22, 2012, 07:06:15 PM
Peter,

Got curious output from your last version. Sources & output attached.
Tabs in input.

o1 - no Insert Blank  no Replace _

o2 - no Insert Blank   yes Replace _

o3 - yes Insert Blank  yes Replace _

o4 - also checked your last option and got slightly different from o3

Am I doing something wrong? A little explanation for Insert Blanks & Replace _ would help.

I am not growling or yelling. Just asking.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 22, 2012, 08:34:28 PM
Hello Paul,

is straight again to it at working. We go through times point by point!

First is correct!


Option insert Blank is Off, Repace Underline is Off

input

local a, b, c _
d, e, f as long


outut:

local    a, _
         b, _
         c, _
d, e, f as long



Not beautifully however correct is one could

it in such a way make with variables according to option


local    a, _
          b, _
          c, _
          d, _
          e, _
          f _
          as long



Are straight at working the whole with AS or with underlined to replace 

I will piece by piece process the other points!

Greet Peter



Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 22, 2012, 11:10:49 PM
Peter,

I must have not understood your reply to  Plamen Chobanov.

There was something about leaving the tab characters in the output lines.
The last version you posted didn't leave the tab characters in any formatted line.

What is the purpose of the 2 new options dealing with tab spaces?
Is this something that is not quite ready?

Again, I'm not growling or yelling. I just do not understand.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 23, 2012, 06:12:08 AM
Hallo Paul,

Quote
There was something about leaving the tab characters in the output lines.
The last version you posted didn't leave the tab characters in any formatted line.

What is the purpose of the 2 new options dealing with tab spaces?


All Tabs with blanks in the spring become code replaces!

That works!

Greetings Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 23, 2012, 01:02:45 PM
Sorry but I did not understand that answer.

I'll wait for the final version to see what is being done.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on January 31, 2012, 03:35:52 PM
no use posting as it is ignored.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on January 31, 2012, 05:28:50 PM
Hi Paul,
I am not come to this week to program something. Try it then it will find out what it is!  ;D
regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 02, 2012, 10:50:02 PM

no use posting this.


Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 06, 2012, 07:06:06 PM

no use posting.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 07, 2012, 12:59:02 PM
Rats!

Seems that no matter what I do or post, someone gets offended and there go my karma points.


Title: Re: Code-Formatter PB 10
Post by: Peter Weis on February 07, 2012, 03:41:57 PM
Hello Paul,

I have not taken points from you!!!
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on February 09, 2012, 03:57:23 PM
Hello

A small update to version 2

I removed bug with # ELSE!

The progressbar I finally put in the status bar!

Also, I put in a DoFormat SLL or DLL

In version 3 I'm working on a completely redesigned format!

As you shall see what. And should test it, I published the source code again!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 09, 2012, 10:52:41 PM
I refuse to reply as I've only got 1 karma point left.

Come on.

Hasn't anybody else looked at this? 

Seems that 5 people downloaded it.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 10, 2012, 03:43:16 PM
Oh well.  So someone gets ticked at me ( again ).

Peter,
A couple hints to make things go easier.
1) move all Global numeric variables into the fmtcommon UDT.
2) move all Static numeric/string variables into the fmtcommon UDT.
unless they are really needed in the procedure for one-time-only processing that is not
affected by repeated calls to the DoFormat routines.

These 2 changes will enable you to reset all the variables at the beginning of DoFormat
procedure. No chance of any variable left with a value from a previous pass.
You will need to pass the fmtcommon UDT to DoFormat. Update both the fmtoption
and fmtcommon that were passed when leaving DoFormat if using the SLL/DLL version.

3) move the open/closing/backup/copying of processed files into the DoFormat procedure.
saves headaches when file numbers are not shareable between main EXE & SLL & DLL
via FreeFile.

4) create 3 procedures in your main BAS program for dealing with the progress bar.
Something like Show_ProgressBar, Update_ProgressBar, & Hide_ProgressBar.
Don't forget that you need to create a stand-alone progress bar if running with
a command-line file instead of from the GUI.

5) it might be easier to create a tiny program whose only purpose is to create the SLL/DLL.
It would only need a couple lines dealing with the compile and would include Doformat.inc.

6) move all the Macros down into DoFormat.inc. they are not needed in the GUI part of the
program.

See? Just a bunch of helpful hints. No screaming or yelling ( from my end ).

Peace!

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on February 10, 2012, 09:14:59 PM
Hello Paul,

Quote
A couple hints to make things go easier.
1) move all Global numeric variables into the fmtcommon UDT.
2) move all Static numeric/string variables into the fmtcommon UDT.
unless they are really needed in the procedure for one-time-only processing that is not
affected by repeated calls to the DoFormat routines.


Because I'm just about to transfer all global variables to DoFormat!

Quote
These 2 changes will enable you to reset all the variables at the beginning of DoFormat
procedure. No chance of any variable left with a value from a previous pass.
You will need to pass the fmtcommon UDT to DoFormat. Update both the fmtoption
and fmtcommon that were passed when leaving DoFormat if using the SLL/DLL version.

You should watch it once before you write something. When calling DoFormat is passed to the UDT.

SUB DoFormat (BYREF fo fmtoptions AS)

Quote
move the open/closing/backup/copying of processed files into the DoFormat procedure.
saves headaches when file numbers are not shareable between main EXE & SLL & DLL
via FreeFile.

After, you want to program anything! But I want to program all alone, and in my work I have to go. It just takes a little time to be taken to file numbers from the main program! Also, I have not programmed.

Quote
) create 3 procedures in your main BAS program for dealing with the progress bar.
Something like Show_ProgressBar, Update_ProgressBar, & Hide_ProgressBar.
Don't forget that you need to create a stand-alone progress bar if running with
a command-line file instead of from the GUI.

Since I'm still working! The'll see how I do it!


And now I look just unbend a little bit of TV time for anything

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 10, 2012, 09:57:45 PM
Peter,

I'm not sure I understood most of what you wrote.

Just because you move the Global variables to DoFormat does not mean that they are
reset each time it gets called. Consider what happens if you process 2 or more files in
1 run.

Yes, I saw you were passing fmtoption. But you need to also pass fmtcommon and should
reset it on entry to DoFormat. If you move your Global numeric variables into the fmtcommon
UDT then they can easily be reset.

I was under the impression from what you wrote that it was complete.
Why post code that doesn't work? It just seems to be a waste of time.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on February 10, 2012, 11:17:03 PM
Hi Paul,
The functions which require fmtcommon I will carry doformat piece by piece after so that I can no longer be transferred from the main program!
However, it takes some time! 'm Alone and I have to do other things!

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 10, 2012, 11:41:03 PM
Peter,

If you move all the open/close/copy/etc of processed files into the DoFormat procedure then
there should be no need of fmtcommon in the main GUI program.

Take your time and test it this time around. I'll check back in a week or 2 ( or at most
by spring ).

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 18, 2012, 03:17:32 PM
Peter,

Something as simple as the following will work to create the SLL.
Just need to add Common to the end of the Function DoFormat line.
And call the ProgressBar_Update routine in the main bas file.
And a couple small changes based on %AM_SLL to handle differences if needed.
Then you only need the 1 DoFormat.inc and you can use either the inc or sll.


' SLLDoFormat
'

#Dim All
#Register None
#Compile SLL "DoFormat.SLL"
#Option Version5
#Debug Error On

#Include Once "WIN32API.INC"
#Include Once "Code Formatter.inc"

%MAX_LINELEN                      = 400                    'maximum source code line length

Global   ztext()                        As String'source code line
Global   foDoFormat                  As fmtoptions
Global   fc                              As fmtcommon

%AM_SLL = 1

#Include "DoFormat.inc"
                           

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on February 18, 2012, 10:12:14 PM
In case anyone is interested.

Just a minor re-working of Peter's code to produce a SLL for DoFormat.
I don't think I messed anything up. I just moved most of the Global & Static variables
into the fmtcommon UDT and moved the input/output file handling into the DoFormat
routine. Had to add a ProgressBar_Update routine in the main bas.

I'm using PB Win v10.03 & Jose's includes v3. Just compile SLLDoFormat.bas to produce the SLL.
In the main program Code Formatter.bas, you can have #Include DoFormat.inc or
#Link DoFormat.sll and it should work the same.

It is not the only way to do the job but it was quick. I'm sure that Peter will probably have
a better version. And I can hardly wait to see his v3.

No this is NOT a replacement for Peter's version. This is still HIS code.
I merely moved around a couple routines.
If this offends him ( or anyone ) then I'll remove it.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on March 09, 2012, 07:26:20 AM
Actually Peter is working on something else. Therefore looks like your version is now the last version, Paul.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 09, 2012, 01:01:37 PM
Theo,

Does this mean no v3? What exactly is/was going to be in v3?

His v2 still has some rough edges that need fixing but I was under the impression that all would be
fixed in v3.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on March 09, 2012, 01:18:30 PM
Peter has posted his last changes. Now the next contributor can take the code and change it and post it then.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 09, 2012, 02:35:47 PM
What I last posted was Peter's code. I just moved a few routines around to allow for an SLL. The code
he supplied couldn't produce an SLL or DLL.

His last post clearly stated that he was still working on it AND on v3. but we might not see anything
until Spring. This last part I'm not too sure about. When is Spring in Germany?

Just curious.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on March 09, 2012, 10:05:13 PM
Hi Paul,
  You can get the latest version V3 of me if you like! I'll send them to you in email! I'm unfortunately not at the moment to do so. Must'm not even work even in retirement
regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 10, 2012, 12:11:00 AM
Hi Peter,

Sorry to see you stop work on it, I really am.

But if you are not going to finish it then why not post all the code that you have and
let the next person work on it. I would like to look at your code at least to see the
direction you were going in.

That next person probably will not be me. I have a tough time figuring out another
programmer's variables and functions and logic when they are in English. I'm not
sure I could handle German ( let alone German abbreviations ). I'm not up to trying
to think in another language.  I'm still in awe of those who can think in more than
1 language.

Good luck.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on March 10, 2012, 05:02:39 AM
Hi Paul,
I will not stop but I do (make a break).
Because I do the new common project with wide Unicode files.
If you want, just carry the project on!
I have provided all of the code of V3.
regards Peter

(Translation changed Theo)
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 10, 2012, 04:43:22 PM
Theo,

I question either your translation or what Peter wrote:
Quote
I have provided all of the code of V3.
regards Peter

(Translation changed Theo)

I can not see any v3 source posted anywhere.
I did send Peter a PM this morning but haven't heard back yet.
From what you posted on March 9th, I took it that Peter was completely done.



Title: Re: Code-Formatter PB 10
Post by: Peter Weis on March 10, 2012, 07:42:26 PM
Hi Paul,
take it easy, I w. This morning at work! Could you also post why do not I'll have to work up a little!
Please be patient :)

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 10, 2012, 08:11:38 PM
Peter,

Sorry. I didn't know you were busy working.

I just got confused from what Theo said and then what you said and then what Theo translated
what you said.

I'll try to calm down. and I'm already drinking decaf tea.   ;D

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on March 11, 2012, 09:50:17 AM
Hi Paul,

sending you here the code of all three versions in which the last time I =
was working!

code formater PB10e V2 is the latest version 2, or have already been?


code formater PB10e V3 with old format

There are only two buttons you can work with it

code formater PB10e V3 with new format does not go

I wanted to revise the format completely. I not gotten this version run run!
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 13, 2012, 01:51:43 AM
Hi Peter,

How did you produce the RES & PBR? The PB v10 RC complains about 2 of the ICO files and
them aborts before finishing and the new PBR isn't complete.

Also where are icon_1.ico & test2.ico?

Did you use a newer version of RC.exe than PB supplies?

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on March 13, 2012, 07:26:10 AM
Hi Paul,
to write to file Codeformatter.rc!
line:

//IDI_ICON_1                  ICON DISCARDABLE  "F:\\PBWin10\\bin\\Icon_1.ico"
//IDI_TEST2                   ICON DISCARDABLE  "F:\\PBCC60\\bin\\test2.ico"   


replace with:


//IDI_ICON_1                  ICON DISCARDABLE  "ResDll\\Icon_1.ico"
//IDI_TEST2                   ICON DISCARDABLE   "ResDll\\test2.ico" 


Extract the icons that I'm sending to ResDll!

Get yourself a new resource compiler. Copy it into the bin directory of PowerBASIC

Resource Compiler-Update:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa381042(v=vs.85).aspx
   
regards Peter


(Minor changes/Theo)
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 13, 2012, 03:01:27 PM
Peter,

Thanks for that last file.

I pulled the 2 missing icons. But instead of manually changing the RC file ( which Phoenix keeps
changing back ), it was easier to name to two icons to their right names then fix the imagelist
and remove the extra code that replaced the old icons with the new ones at run time.

I'm using RC v6.1 but will have to remember to swap back to PB original RC when doing any
update.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 14, 2012, 01:36:45 AM
Peter,

It only took an hour or so to put in the DoFormat.inc from 02/18/2012 ( that can produce SLL or
plain include ) with the changes you made to the file in v3 old. Most of the time was getting all
the files open in 1 place & the differences hi-lited.

Seems to work the same as before. I commented out some parts instead of deleting them. Mostly
to do with all the file handling being moved to the DoFormat.inc file.

So it is possible.

But the big question I have is Are you rewriting all the DoFormat routines for your new v3?
Or is it way to early to be asking?

Just curious.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on March 14, 2012, 07:04:21 AM
Hi Paul,
I kicked everything here because I wanted to make the totally new! But I have not gotten around! Have nothing new. Have you all been

FOR currentline = 1 TO totallines

            IF LEFT$(ztext(currentline), 9) = "#PBFORMS " THEN
                PRINT #fc.fhout, ztext(currentline)
            ELSE

                LineAnzahl = splitVarLine(Zeilen(), zeilenNummer, ztext(), remstr(), currentline)
                FOR lineStart = 0 TO lineAnzahl
                    ftab = is_space(Zeilen(lineStart)) * FoDoFormat.tabsize
                    p = 1

                        findPBWord(Zeilen(lineStart), p, statement, termstr)
                        SELECT CASE UCASE$(statement)
                        CASE "GLOBAL", "LOCAL", "REGISTER", "DIM", "REDIM", "STATIC", "INSTANCE"
                            IF FoDoFormat.splitvariables THEN
                                Build = BuildVars (statement, Zeilen(), remstr(), lineStart, LineAnzahl)
                                work = %TRUE
                            END IF
                        CASE ELSE
                        END SELECT

                        IF Work = %False THEN
                           IF FoDoFormat.insertblanks = 1 AND work = %False THEN
                              WordCount = Line2Words(Zeilen(lineStart) + remstr(lineStart), w())    ' , @fo)
                              build = RebuildLine(w(), WordCount)
                           ELSE
                              build = SPACE$(ftab) + LTRIM$(Zeilen(lineStart))
                           END IF
                           PRINT #fc.fhout, zeilenNummer + build


                        END IF

                NEXT lineb

            END IF
            IF (currentline MOD 10) = 0 THEN     'update the progress control
                SendMessage fc.hProgress, %PBM_SETPOS, 100 * (CurrentLine / TotalLines), 0
            END IF
    NEXT                   


  Best regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 14, 2012, 01:24:22 PM
Peter,

I do not understand. Is that little bit of code supposed to replace everything you had in the
DoFormat routine?

Maybe it's best if I just wait until you decide to show your new v3.

Until then.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on March 14, 2012, 01:35:56 PM
Peter erklär mir das und ich poste es dann. Dein aktuelles DEnglisch ist nicht gut verständlich.
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on March 14, 2012, 03:21:37 PM
(Translated/ Theo)

I just wanted tell Paul that i have3 removed all stuff that i believe to be useless for the next version.
However i could not yet start with it. THe code above just shows a part of all.


Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 14, 2012, 05:51:13 PM
Ok, that probably explains a few things.
Such as  :
some options not saved  or wiped out based on some unrelated option
input file loaded into output tab
duplicated output lines
indenting that gets really large if Format run multiple times without exiting

I think I'll check the v3 old to see if it needs fixed.

Just something to do ( instead of waxing the car ).


Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 18, 2012, 11:48:24 PM
In case anyone is interested, I've attached the version of Code Formatter that I've been working
on ( based on v2 ). It's written using Jose's CWindow for the GUI and with enhancements to the
original RebuildLine along with some extra routines to handle specific keywords.

NO source included ( I don't really want to compete in any way with what Peter's doing ) but did
this just to see what I could do.

If you don't feel comfortable using an EXE without the source then DO NOT download.
As far as I know there is nothing bad in the code.

There is a text file included in the zip that documents some of the changes I've made. I started
out creating a DDT version of the GUI and then created a CWindow version. They both use
exactly the save DoFormat routines ( either via an INC or SLL ).

There is also a "Code Formatter.cfg" included and you'll probably want to change the input &
output file names.

If you do use it and find something that doesn't work the way you think it should, Please let me
know. I'll try to change it or explain why not.

(Executable removed / Theo)
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on March 19, 2012, 05:20:05 PM
@Paul, this is a Source-Code Forum.
Please do not publish executables unless in the third party forum.
Here i want (also for safety reasons) only compilable Source code.

This is true for anybody, posting here.

The problem is that there are multiple viruses out there, some of them not even known by AV-Programs.
And we do not want them to have platform to spread here.
Sourcecode is safe, and is welcome from anybody.

If you have reasons not to share your sourcecode, please explain them.
Executables can be posted as Sollutions in the Third Party Forum.
In that case i will run them through Virustotal to have a maximum, safety for our Forum Members.

PS: I personally never use executables from public places unless i have tested them hardly.
Therefore i have removed the executable, and hope that you will provide the source-code that will be the newest version here.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 19, 2012, 06:53:40 PM
Theo,

Ok, have it your way.

I stated the main reason that I won't publish my source ( did NOT want to interfere with what
Peter is doing ).

The last time I contributed a hunk of code for this project, Peter reworked it. The revision didn't
work. Personally I could barely recognise any of my code. Then you both stepped back and
said the "ball was in my court" to fix it. Maybe I didn't understand exactly what you two were
saying but the implication was there that I was responsible for it being wrong.

My code worked then and is still working. I am not going to post code just to have it hacked
to pieces until it fails to work. Having looked at Peter's code, I still can not understand what
it is doing. All I do know is that it doesn't always work.

My program works on everything I can find to run thru it. And hasn't shown any anti-viral
activity on 2 different ant-virus program.

As it is, I can see there is no use in my coming back here for several months.

So Long.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on March 19, 2012, 07:02:58 PM
Paul, most people come here to get sollutions to their problems.
And we have the finest sollutions here, therefore its up to you to come here or not.

Besides i have not sted new rules but just told you my practise,
and thats for your and our safety.

I will not force you to post source code, but please do not poste executables.
If i see them I'll remove them. People can compile them if the source code is there.

The things you tell from the past are strories from the past.
I don't know why you warm these up, as i told you to post the source code.

Now do it and it will be the new version. Or leave it, then somebody else will make a new version.

We are all not employees whatever we do, that we do in our freetime.
And we do not get paid for it. Not me (even though i have expenses with the forum),
and not Jose (who works like an one man army here to provide us with highes quality code).

Please note that i, as the moderator of this Subforum, take the right to delete all postings that do not contribute to a subject at a later time.
This is a practice to clean up the forum and keep it a place of experts knowledge.

Generally said:
We do not need people explaining us their problems of psychological character,  and we do not need men whining like girls (because somebody did something to them).
But you are welcome to be a part of our experts network, if you can leave emotions behind and, start sharing your programming knowledge. And source-code.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 19, 2012, 08:52:31 PM
Theo,

Quit the name calling. You asked for my reason and I told you. The facts as I saw them.
Delete any or all of my posts that you want.

Meanwhile, here's the DDT source that matches the zip you deleted.
Using PB Win v10.03 & Jose's WinAPI v3.

Or just delete this one too.

03/24/2012 new zip file -- updated DoFormat.bas

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 19, 2012, 11:05:04 PM
One of the benefits of my way is the GUI does not make a difference.
As long as the FmtOption UDT is identical  and there are 3 routines for the progressbar,
the SLL can be called & produce the same output.

Or if you still feel than I'm a whining girl then GO AHEAD AND DELETE THE WHOLE THING!!!!!
And make sure that no one keeps a copy of it.


Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on March 20, 2012, 11:12:35 AM
Hallo Paul, how do you feel emotionally today?
I hope fine.
Here the sun is shinig, and the fact that you posted the source code shows me, that after all,
you have accepted the rules in the board like anybody else.

Ok, your source code is now the new version.

If i understand you right, somebody could take your "formatter SLL" and - for example - add it to his PB Editor,
or to Jose's Editor (where the Source code is public).

Sounds interesting to me.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 21, 2012, 12:57:15 PM
Still roughly the same.

It seems that some people are allowed to call others defaming names.

So how soon are you going to clean up the messages?
Title: Re: Code-Formatter PB 10
Post by: Jon Eskdale on March 24, 2012, 11:37:34 AM
Hi Paul,

Many Thanks for all your work on this  - Very much appreciated

I have found one thing that doesn't quite work this is the
PRINT #3, JOIN$(s(), """,""") this gets converted to PRINT #3, JOIN$(s(), "" "," "")
which no longer compiles

Taken from the JOIN$ help
"If the delimiter expression is the 3-byte value of "," (which may be expressed in your source code as the string literal ""","""), a leading and trailing double-quote is added to each string section."

Thanks
Jon
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on March 24, 2012, 03:11:42 PM
Jon,

It's nice to hear that someone likes the program.

Easy fix. And for the record, the original program had the same problem.
Now allows multi-quoted string as long as there are an even number of them.

Updated in post #255. Only the DoFormat.bas file was updated.

Title: Re: Code-Formatter PB 10
Post by: Jon Eskdale on March 24, 2012, 08:05:14 PM
Hi Paul,

That Fixed it.  Thanks for the very quick fix.
:)

Appreciated

Jon
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on June 10, 2012, 04:48:43 PM
Hi Paul,

what about code formatter? Hear nothing more of it. Is the project dead?

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on June 10, 2012, 07:06:43 PM
Its not dead as long as the forum lives.
We can continue with it, if you want, when the actual project is in a good state.
As far as i know the final version of codeformatter was not yet completely usable.
As long as its not guaranteed, that it doesn't destroy peoples code, many will not use it.
Title: Re: Code-Formatter PB 10
Post by: Jon Eskdale on June 11, 2012, 06:30:09 PM
It is certainly in a usable state - I use it regularly without any problems.

If there was to be an issue then you can always revert to the backup

Can I say thank you to those that have created this excellent tool

Jon
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 16, 2012, 10:15:01 PM
Theo,

Where do you get these ideas?

As far as I know, there has only been 1 problem with the code I posted and it was a very
minor problem ( nothing to corrupt anything ). The problem was in the original code ( not
in any part that I changed ).

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on June 17, 2012, 05:59:25 AM
My code is very complex, Paul.
Much above average.
Thats because i heavily use MACROS.

For example sometimes i have used a MACRO like:

MACRO ENDS = END SELECT
MACRO ENDF = END FUNCTION

just as example. Maybe because of such constructs, Code formatters are unable to handle my source code?
In my tests, the code formatter could not handle the things properly, while it was not the last version i have tested.

If you or Peter have a version and you state "Thats the final and gug-free version", then i'll make a posting under "Third Party" and tell people that we have a Code-Formatter for PB 10.

However, it should be able to format any Sourcecode (other then mine).
And the GUI should also be complete. Last version i saw, the GUI was incomplete.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 18, 2012, 10:46:31 PM
Theo,

You were the one resorting to "name calling" to force me to post what I had.
Considering that Peter's last version was not working nor finished and he had
quit for a few months.

As far as I knew, everything was complete & worked. Including the GUI.
If someone has made changes since then that's not really my problem.

Surely anyone who uses a program to "reformat" the source would have enough
sense not to use it on the ONLY copy of their source code.

How's come it has taken you so long to voice any concern?


Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on June 18, 2012, 10:52:03 PM
Paul, your version is the last version.
If it works really fine and has no bugs, tell me then i'll give it  a try and make it the final.

Are you really READY with it?

If you say "yes", i will test it and see if there are bug.
My sourcecode is the ultimate killing code for all formatting tools.  ;D
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 19, 2012, 12:56:20 AM
Got an almighty high opinion of your code, don't you? Or is it just convuluted?

It's been 3 months and obviously you never bothered to test anything of mine.  ???

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on June 19, 2012, 07:08:21 AM
Are we discussing my opinion here?
Lets stay with discussion about coding, Paul.
I hope you have the same high opinion about your own code, because then it wilöl be really bug free when I test it.
Would you say that it is?
Title: Re: Code-Formatter PB 10
Post by: Peter Weis on June 19, 2012, 10:50:20 PM
Paul,

I'll try it once promised the next day!

regards Peter
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 19, 2012, 11:13:00 PM
Theo,

You're the one going off target of code. Check most of your "comments" when you
bullied me into posting my code.

As near as I can tell ( after months of testing ), my code is bug free.

When I commented about the problems with other versions, you kept yelling at me.
Too bad there is not a "system monitor" around to keep you honest.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 20, 2012, 12:31:15 AM
By the way, how can a Macro confuse a reformatter program?
There is always the possibility of altering the spaces within a Macro to the point
that the compiler won't produce what was originally intended (unless you bypass
formatting Macros ). but the formatter program isn't really doing anything with
the Macro definition nor with the macro within the regular code.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on June 23, 2012, 07:59:06 PM
Hi Paul,

I have now used the code formatter found the following error!
See that the #IF has been removed and some lines are now doubled.

Therefrom.

TYPE FILE_NOTIFY_INFORMATIONX
    NextEntryOffset AS LONG
    Action          AS LONG
    FileNameLength  AS LONG
    #IF %DEF(%WIDE_UNICODE)
        Filename        AS WSTRINGZ * 32000
    #ELSE
        Filename        AS WSTRINGZ * 1000
    #ENDIF
END TYPE   

Is that!


TYPE FILE_NOTIFY_INFORMATIONX
    NextEntryOffset    AS LONG
    Action             AS LONG
    FileNameLength     AS LONG
    FileNameLength     AS LONG
    Filename           AS WSTRINGZ * 32000
    Filename           AS WSTRINGZ * 32000
    Filename           AS WSTRINGZ * 1000
    Filename           AS WSTRINGZ * 1000
END TYPE
                   


regards Peter

In short: We're not yet ready with this.
Title: Re: Code-Formatter PB 10
Post by: Larry Charlton on June 25, 2012, 03:32:06 PM
I'm not sure what the goals of the project are, but here's a valid source from hell.  A couple of things I've discovered in my own wanderings on this topic is A) It's not possible to indent all source files correctly.  Consider the case where a single file is included at two different points each of which have different indent values.  It is possible to format source streams correctly. B) It's not possible to correctly indent/format a single source file, consider structures or functions that start in one file and end in another either by being included or by running off the end of an included file. C) It's not possible to format code by looking at a physical line, instead a logical line needs to be evaluated.  D) Some formatting probabbly needs some human intervention, consider aligning Dim's, =, Multiple single line statements, one parameter per line, etc.  Somethings humans look at and say, this would look best this way (maybe compact), others they look at and think, this would be better aligned.  Sometimes it has to do with context or purpose of the statements.  So in the long run, it would be nice if automatic formatting could be applied and then a human could change localized formatting when browsing through the file easily. and finally F) Not all whitespace is created equal.  It can be spaces, tabs, continuations, cr's, lf's, and in some cases missing. 

As side effect of these considerations I decided tokenizing the input stream was preferable to other approaches.

I've included one possible correct indented example.  My formatter is not there yet either, I need to fix statements and routines that start with continuation lines and AsmData blocks.  It would probabbly be useful to the project to maintain a sample of all valid quirks and then running the app against the quirks file.  The included file is not a sample of all oddities in the PB language but some things it took me a while to get right. 

Hope it helps, and keep up the great work.
Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on June 25, 2012, 03:41:21 PM
I guess we would need somebody to collect versions here and bring things together, we need a project Master.
For the code-Formatter. Anybody interested to take that hat?

With the right to test, collect codes and always post the last version?
if so mail me ...
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 25, 2012, 04:41:59 PM
Larry C.,

I agree that it may not be possible to please everybody at all times.
Frankly I used your GDIPlus program ( combined with all its Includes ) as a major test
case for my version. I learned a LOT about the COM parts/formatting from your code.
But found that it needed ALL the code in 1 file to make any sense for formatting.
You might consider putting all that code into 1 file & running it thru the latest formatter
and seeing if there are any parts that need tweaking.

Also found a problem in another program I'm working on by using your code. I have to
flag Type/End Type lines because you had an entry of argb in a Type and a Function ARGB()
that was giving me fits.

Will check out this latest code.

Thanks.

Title: Re: Code-Formatter PB 10
Post by: Larry Charlton on June 25, 2012, 05:13:38 PM
Here's a quirks file with a few more quirks.  It's a single compilable source file (doesn't do anything).  Another source that suprised me early on was zxRef by Patrice.  Had a few interesting things in there I hadn't seen before.  Quirks2.bas is my attempt at formatting.  Was interesting to note how you handle Try Catch blocks differently than I do, might have to change the way I indent them :)
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 25, 2012, 06:13:50 PM
Larry,

Ouch! Your quirks files are problems for the program ( if Split Variables option checked ).

Not really sure how to handle continuation lines in a Type first line or the End Type/Union.
Nor continuation lines that are nothing but continuations. Formatting that cross over
multiple continued lines ( especially that breaks up keyword pairs ) is tricky.

I've attached the output from another program that shows continued lines as 1 line.
It does no formatting but does interpret #IF/#ENDIF and handles #Include files ( even
nested ones ). But would be tricky to recreate all sources with formatting to make sure
that any #Includes have backups ( would proabably be easiest to create a new output
directory ). It already creates an output file with all sources and would just need to break
out the different files.

Haven't looked at zxRef yet.

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 27, 2012, 12:11:59 AM
Larry,

Most of the problems with your quirks programs are because the formatter hasn't found
the end of the Type structure. It doesn't handle splitting the END TYPE onto 2 lines.

How would you like them indented? Especially if you add 2 or 3 continuation lines between
them. It probably could be done by first combining all continuation lines ( & removing the
parts from consideration ) then doing the formatting. But that would throw off all the
regular lines that splitting doesn't mess up. Might be able to just do it for the Type & Union
structures. Then again it would have to process any code-pair that started with END.

This needs way more thought.

Didn't see anything really strange after formatting zXRef.  Was there something you saw
that I missed?





Title: Re: Code-Formatter PB 10
Post by: Larry Charlton on June 27, 2012, 04:13:27 AM
Probabbly not in your code, but there were two things that were unusual after I'd run through a lot of other source code without problems.  I think one of them was:
IF nRemaining = 0 GOTO BufEnd
Hadn't seen that in a loooong time, don't recall the other, but it's what started me looking at the language spec instead of just opc.

Really the line continuation thing is weird.  I think as long as parameters are working in 99.999% of the code you won't see any of those.  I just opted to try and understand the language, block structures, and indenting and implement based on variations I could think of.  It's when I realized there were impossible indenting scenarios.  I think what you have is a valid formatter, might be just a matter of noting things like: x or y not implemented.  Someone else could always do them later if they felt the need.

Anyway the rule I used was, the first continuation _ adds an additional indent to subsequent lines.  When you reach a line without a continuation _ and you previously had one, remove an indent.  Note I said adds, because if you're doing a block sub for example, I also add an indent after emitting the sub if it's not a single line definition (for the body).  The net result is single line constructs got indented once, block continuations such as parameters get two indents and then pop's back out an indent when the body starts up and then again at the end of the sub if that made any sense.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 27, 2012, 11:56:27 PM
Ok, I think I understood that about the continuation lines but am not sure.
Kinda busy figuring out some other problem at the moment tho.

Does it currently work the way you want? Except for splitting keyword pairs, I mean.
Personally I don't want to handle keyword pairs on different lines. Just looks too weird
and raises questions of how to output it. You haven't said how you want it output yet.
Should I ALWAYS combine split lines with keyword pairs? that will involve extra checking.

I definitely need to work on those single-line functions/subs. Need to check on having
beginning & end pairs without extra routines within them. also then need to allow for
multiple single-line routines on a single line followed by the beginning of another routine
with the end on a subsequent line.

Also need to do something about the single-line IF with GOTO without THEN.
got the same problem in another program I'm working on.

Title: Re: Code-Formatter PB 10
Post by: Larry Charlton on June 29, 2012, 08:52:19 PM
I'm not sure what you mean.  So far it's working as expected except for when things start with continuations.

Currently the indenting isn't messing with formatting.  I treat split keywords like anything else with a continuation.  i.e. the second word will be indented on the next line.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on June 29, 2012, 11:08:59 PM
Larry,

For my version, that 2nd part is what causes problems. There are a couple special routines
that work on blocks of code ( types & unions & variable definitions & macros are some ).
once the program starts processing a block it needs to find the end of the block so that
it can go back to normal formatting. but it needs the ending keywords to be on the same
line. parts of the program work with the original method of breaking a line into individual
pieces and other parts work on the line via instr or mid. I use the method that makes it
easiest to do the work.

Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on June 30, 2012, 08:02:35 AM
Peter told me yesterday that there are things that do not yet work. Maybe try his Library code from the other post. He said that after formatting the code woild not be usable anymore.

Means to me: "There is quite something to do left".
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on July 01, 2012, 11:05:30 PM
Larry,

I think I tried to get the continuated lines to be indented 1 tab stop UNLESS it was under
one of your blocks of multi-line assign. If you would combine all of your GDI Plus code & Includes
into 1 file and run it, you will probably see what I'm talking about ( as your code was what
I based it on ).

Title: Re: Code-Formatter PB 10
Post by: Jon Eskdale on July 02, 2012, 05:22:54 PM
Hi Paul
I have come across a problem where I am getting
Untrapped Error #5 (Illegal function call) has occurred following execution of AGN2

I've narrowed it down to this bit of source which it doesn't like.  I've edited it to make it short to demonstrate the problem


SELECT CASE wMsg
     ' MLGDEBUG HEX$(wMsg)
     CASE %WM_CREATE  'Allocate storage for the vGridData structure.
        LOCAL tm   AS TEXTMETRIC, ps AS PAINTSTRUCT,_
              si   AS SCROLLINFO, _'lp AS POINTAPI, _
              rc   AS RECT, wRect AS RECT, _
              hdc  AS DWORD, hPen AS DWORD, hBrush AS DWORD, _
              hBrushSel AS DWORD, _
              y AS LONG, x AS LONG, I AS LONG, J AS LONG , iVscrollInc AS LONG, hScrlInc AS LONG
       STATIC MyPoint AS POINTAPI      'the rightclick menu uses this.  Needs to be static
End Select


It seems to be the Array Scan that is generating the error while it is processing the line y as LONG, x as LONG....

Any Ideas - Thanks
Jon

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on July 09, 2012, 10:18:31 PM
Ok, the attached replacement DoFormat.bas should fix the few things found.   ;)


Title: Re: Code-Formatter PB 10
Post by: Theo Gottwald on July 10, 2012, 08:42:48 AM
Paul, prefer to post complete Sourcecode, Paul. So anybody can use the actual final version.
Also it would be good if you add a statement how you think the project state is, "ready .. finsihed ... in work ... lot to do ..."
something like that.
I'll wait with own tests until i get something which you tell me that you think its really good.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on August 07, 2012, 06:04:09 PM
Jon,

Did that fix your problem? It should have ( it did in my tests of the code you posted ).

Just curious. I don't get on he internet a lot lately.

Paul

Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on August 13, 2012, 10:38:12 PM
Larry,

I spent several hours looking into seeing how hard it would be to handle all those split
keyword pairs and I've got a big headache.

I think the only way to do that is to do everything via the token method and have a lot
of flags to specify what part of a PB statement has been done & which part is being worked
on. But I may be wrong. If you can figure out a way of doing it ( either in the current version
or the original version or in your own version ) then please let us know.

I also did some work on the Remark handling. Seems that it is not necessary to have a colon
before a REM after a PB statement.

Had never seen a continuation char as the first & only thing on a line. thought that it needed
a space before it.

Still looking at having the full sub/function code on a single line and the possibility of having
multiple sets of them on 1 line. and the possibilty of having that AND having the last one
ending on subsequent lines. this not only affects the formatting program but also the
flowcharting program I'm working on. this last program then get complicated because it
flags each line as to start or end of sub/function. things were much simpler before you
threw those quirks into the mix.

Thanks a lot (  I think? ).

Paul
Title: Re: Code-Formatter PB 10
Post by: Larry Charlton on August 22, 2012, 12:48:21 AM
:) I wouldn't sweat it too much.

I did solve it with the tokenizer I wrote.  What I did was implement a get next statement token.  Essentially is skips over _ to the next line until it hits a colon, comment, or CR/LF.  When it hits the end of statement it returns false.  Calling it again returns the next token until there are no more tokens.  The source code is sitting in PbSlice2 if you want to look at it, it's public domain if anything in there would help you.  It's a bit of a different approach though and all based off interfaces.  No reason it couldn't be functionized though.  The primary files are in src\support called Indent.inc and TokenizeLine.inc.  Code still feels a bit clunky so I might take another crack at it, this is a rewrite of this routine from PbSlice which I also published for reference.  Same idea, bit different logic.

FWIW I started out looking at statements on lines also until I came to the conclusion you have to look at source as a stream of tokens.  I did cheat a bit for my indenter and just ignored includes which causes a few quirks.  Once you realize it's impossible to "correctly" indent every file in a stream, it seems like a reasonable compromize to me.  It also allows indenting a single file and more importantly allows mutliple threads to indent different source files if needed.  For me if I don't have keystroke response to everything reguardless of size it needs work...  Clearly I'll have to give at some point.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on August 22, 2012, 03:25:54 PM
Larry,

How do you format all the lines in-between the current token ( beginning of a keyword pair ) and  the line with the ending
token of the keyword pair?  without combining the continued lines which would alter the original structure.

the current problem is because the program is in the middle of a structure/function and needs to know when it ends so that
it can go back to normal formatting.

still need more work on REM handling. forgot to handle being enclosed in double-quotes.
but I don't get much internet time any more.

speaking of PBSlice2, should it be kicking out all those messages about <1> is not <1> ( or something like that ... I'm not
at the computer that I ran it on ) ?

for this formatter, tokenizing the whole file would be possible as it now reads the whole file into an array and could output
to another array for further processing before finally outputting to a file.  it might be possible to completely tokenize the
whole file at once ( adding cr/lf markers ). but then you must keep all the continued lines as continued lines ( or at least
have that as an option ) as that is what the original programmer wanted. but then you need to keep track of where in the
token array that lines start so that block structures can be formatted ( lining up parts based maximum size of names within
the structure ).
but I've done a few specialized routines that work much easier when dealing with the whole line.  and the original formatting
code only dealt with reading 1 line at a time.

Title: Re: Code-Formatter PB 10
Post by: Peter Weis on August 22, 2012, 06:01:18 PM
Hallo Paul,

du wirst nicht herum kommen ganze Blöcke zu lesen,  und nicht nur eine Zeile und dann zu formatieren,  was ich ja schon ansatzweiße versucht habe!

Grüße Peter

[Translation/Theo]

Paul, Peter assumes that it may be needed to work on blocks instead of on lines.
He assumes taht you will have to read the whole block instead of a single line.

(I just translate, ...)

Title: Re: Code-Formatter PB 10
Post by: Larry Charlton on August 23, 2012, 01:58:01 AM
Probabbly the same way everyone else does.  I just have an indent level.  Whenever I come across a line that changes the indent level I either adjust the indent level before or after I output the line.  Starting blocks I indent after, ending blocks I outdent before.  You can search for left character _, space_, and tab_, the only downside was finding that embeded in a string or comment was a bit difficult, luckily I had a tokenizer already for other reasons that did away with the need to worry about it.

It probabbly will.  Most of the messages (I did find 3 bugs so far based) are due to the file paths changing.  I may work on that to eliminate it, but I'm also working on a nano sized unit testing framework that should help fix all that.

What I did was a blend.  I realized that one use of the tokenizer might be to create coloring for tokens in a viewer/editor.  The viewer/editor couldn't display all the lines at once so I probabbly didn't want to tokenize the whole file.  Also adjusting token positions and stuff could get tedious if I ever edited.

What I ended up doing was splitting a file into an array of lines.  The tokenizer only works on a single line.  i.e. it splits all the tokens in a line and lets me loop through them rapidly.  Gives me benefits of rapidly inserting new lines in large files, changing text in any way on one or more lines rapidly and gives me quick access to tokens for a line when I need them.  Now I can work with files, lines, or tokens, whichever is best for a problem.
Title: Re: Code-Formatter PB 10
Post by: Paul Elliott on August 23, 2012, 03:19:46 PM
Larry,

the current version does that ( sorta ). it loads the file into an array and for the most part runs top to bottom, splitting the line
up into tokens & rebuilding the line for output. indenting works much as you describe. 

the parts that I wrote to format certain structures do loop thru from a given starting point ( the beginning keyword of the
structure ) and look for the ending keyword.  the problem is that it currently needs the ending keyword pair ( ie End Type or
End Enum or End whatever ) to be on a single line. your quirks file shows that the keyword pair can be separated by many
lines and if there are options following them those can also be many lines removed.

my first thought is to loop thru the whole array and build a 2nd array of just the combined lines from the ones that are continued.
would also need to keep track of which lines were used to create the combined line.
my question is how would you like the continued lines to be indented relative to the 1st line? would just a simple 1 tab stop
indent be okay?

I realize that this probably wouldn't show up very often ( except in your code .. you seem to come up with lots of new styles
that I've never seen or considered ... I'm NOT complaining ).
did you ever run your GDI Plus code thru this program to see if I handled your array loading to your liking? or the Class code?

Title: Re: Code-Formatter PB 10
Post by: Larry Charlton on August 23, 2012, 07:08:07 PM
That's what I did.  A continuation added 1indent to the next line.  End of continue uation subtracted one after.