• Welcome to Theos PowerBasic Museum 2017.

Code-Formatter PB 10

Started by Theo Gottwald, January 18, 2011, 07:58:28 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Paul Elliott

#60
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.


Peter Weis

#61
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

Peter Weis

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

Paul Elliott

Peter,

Yes, that last line

fo.fspecout = fo.fspecin

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


Peter Weis

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

Paul Elliott

Because somewhere in all those routines,  the tmp file name is being put in fo.fspecout.


Peter Weis

Let's sleep on it! Already find a solution! or you have an idea
fo.fspecout is a file Temporärere

regards Peter

Paul Elliott

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.


Peter Weis

#68
Hi Paul,
send me or upload it there! I want to watch it! :)

regards Peter

Paul Elliott

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.


Peter Weis

#70
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

Paul Elliott

No, you had moved it to Function Form1_Btn_Format_Clicked.


Paul Elliott

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.

Paul Elliott

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


Paul Elliott

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.