PDA

View Full Version : FREE UTILITY: AMS Code Pretty



CyberRBT
04-01-2007, 06:23 AM
A while back I posted a quick function in one of the threads in answer to a request for help. By hand, I highlighted the syntax of the code so that it was easily readable. Maybe you've had a similar experience.

I then searched for a utility that would do this automatically. When I couldn't find one, I wrote one (in AMS). This file, AMS Code Pretty, is my donation to the AMS community. It was put together over the last four days in my spare time (about 20 hours).

Once the lexer engine was coded, it was a small step to also provide a functionality to convert AMS/LUA code to HTML. The program does this as well, plus more.

The following is a sample output. Notice the line numbers; this is one of several user-definable features.



01
02 function appPathOriginal()
03 -- returns the original EXE's path ONLY (with trailing \)
04 -- this is useful for compressed single-file apps run from a CD
05 -- but, it also works with folder-based apps
06
07 local cdPath = "";
08 local findMarker = "SFXSOURCE:";
09 local cmdArgs = "";
10
11 if (Table.Count(_CommandLineArgs) > 0) then
12 for i = 1, Table.Count(_CommandLineArgs) do
13 if (String.Find(_CommandLineArgs[i], findMarker) > 0) then
14 cmdArgs = _CommandLineArgs[i];
15 break;
16 end
17 end
18 end
19
20 if (cmdArgs ~= "") then
21 if (String.Find(cmdArgs, findMarker) == 1) then
22 local fullPath = String.Replace(cmdArgs, findMarker, "", true);
23 local tblFullPath = String.SplitPath(fullPath);
24 cd_Path = tblFullPath.Drive .. tblFullPath.Folder;
25 end
26 else
27 cd_Path = _SourceFolder .. "\\";"
28 end
29 return cd_Path;
30 end
31




The download installs and starts it for you. I'm interested to know if anyone else finds this utility useful. Questions, comments, and suggestions are welcome.



AMS_Code_Pretty_1.0.3_Install.exe (http://66.34.42.62/downloads/applications/AMS_Code_Pretty_1.0.3_Install.exe)

RizlaUK
04-02-2007, 09:50 AM
Hey, nice work, :yes :yes :yes

this is something i can make good use of, and i urge anyone that posts code in the forum to use this well handy little tool


Nice Work CyberRBT, And Thanks ;)

CyberRBT
04-02-2007, 11:34 AM
Thank you. There is a LOT of code in the posts here. Maybe a utility like this will help make it easier to follow.

I have discovered a minor bug in the lexer engine. It is now fixed. Before, if you had two quoted backslashes alone, the output added an extra quote.

The current version is 1.0.3.2. If you were one of the two dozen or so who DL'd right after the above link was posted, you may want to grab this latest update. When you do, make sure that the older version is not running (exit from the system tray) and you may also want to uninstall it (not required though).

The link above is valid for the latest version.

Line #27 in the source code sample above reveals the minor bug. Now, look at the following which demonstrates the fix.



01
02 function appPathOriginal()
03 -- returns the original EXE's path ONLY (with trailing \)
04 -- this is useful for compressed single-file apps run from a CD
05 -- but, it also works with folder-based apps
06
07 local cdPath = "";
08 local findMarker = "SFXSOURCE:";
09 local cmdArgs = "";
10
11 if (Table.Count(_CommandLineArgs) > 0) then
12 for i = 1, Table.Count(_CommandLineArgs) do
13 if (String.Find(_CommandLineArgs[i], findMarker) > 0) then
14 cmdArgs = _CommandLineArgs[i];
15 break;
16 end
17 end
18 end
19
20 if (cmdArgs ~= "") then
21 if (String.Find(cmdArgs, findMarker) == 1) then
22 local fullPath = String.Replace(cmdArgs, findMarker, "", true);
23 local tblFullPath = String.SplitPath(fullPath);
24 cd_Path = tblFullPath.Drive .. tblFullPath.Folder;
25 end
26 else
27 cd_Path = _SourceFolder .. "\\";
28 end
29 return cd_Path;
30 end
31



Again, the link above is valid for the latest version. And, questions, comments, and suggestions are welcome.

RizlaUK
04-02-2007, 12:54 PM
thanks for the update :yes

iv just one small suggestion/request

when useing the bbcode setting the output is actual bbcode, could you add a button to switch between the actual bbcode and prazed bbocde so we could still see the ams type of code in the preview useing bbcode settings and click the button to see the actual bbocde

just for visual effect as i always like to check how the output will look b4 posting

CyberRBT
04-02-2007, 03:29 PM
Sure. I can put that feature in the next update.

But, for now you can preview as HTML to see the results. The visual output for the end-user is the same whether it's HTML or BB Code.

Worm
04-02-2007, 03:33 PM
Sure is purty ;)

very nice!

Adam
04-02-2007, 03:55 PM
Nice App. I like it

For a future version I wonder if it would be possible to insert the proper indenting? It drives me nuts when code is not indented at if, for statements.

Adam Kapilik

Worm
04-02-2007, 04:00 PM
I agree, it makes the code so much easier to read.

RizlaUK
04-02-2007, 04:44 PM
But, for now you can preview as HTML to see the results. The visual output for the end-user is the same whether it's HTML or BB Code.

yeah good point, but how about putting the checkbox for the output setting on the main interface, that way i could view as html and quickly view as bbcode without haveing to go in to the settings, that would proberly be easyer that way


I agree, it makes the code so much easier to read.

ditto, i only recently learned the importance of indenting my code, also i only just found that i could put small blocks on one line :



01 if something then dosomething else dont_dosomething end


makes things look a lot more tidy

Intrigued
04-02-2007, 05:05 PM
You're getting feedback, suggestions. Good sign. :yes

:)

CyberRBT
04-02-2007, 06:57 PM
Intrigued:
You're getting feedback, suggestions. Good sign.

Hey. This post went live today around 10:30 a.m.; it took about a day for the staff to approve it. And ... i've had 37 DL's in first few hours with 100 views here. Thanks, one and all, for trying it ... and for your suggestions.


RizlaUK:
...but how about putting the checkbox for the output setting on the main interface...

That is exactly how I envisioned doing what you'd suggested earlier. That update will be available soon.


Adam:
For a future version I wonder if it would be possible to insert the proper indenting? It drives me nuts when code is not indented at if, for statements.

Programming keeps my in touch with my inner Type-A. These days, I'm a fanatic about indenting blocks ... and about naming conventions ... all Label names begin with 'lbl_', all ComboBox names begin with 'cbo_', etc. I also comment liberally (after debuging). Over the years, I've learned (the hard way) that following these guidelines makes updating later SO much easier.

Nonetheless, with the lexer engine the focus is on isolating keywords and syntax, then highlighting them accordingly. Indention, like naming conventions, is a choice of style. Although, I may add an indention feature, at this juncture I'm not quite sure how to properly handle nested blocks.

Intrigued
04-02-2007, 09:03 PM
How do you feel about sharing an exported version of this utility (.apz)?

CyberRBT
04-03-2007, 06:51 AM
Well ... the project is still in development. But, the help file does give clues on how to get the source code. Nonetheless, I wouldn't want the lexer engine source posted at this time. However, clever programmers (such as yourself Intrigued) could acquire it and use it in their own projects (as long as the AMS lexer engine source is not disclosed).

BTW, writing this type of code using regular expressions and a RichEdit control takes a few dozen lines of code. Using AMS to syntax highlight AMS code took over 300 lines.

Here is a list of the functions in the latest update. You can use these prototypes after you load the bytecode compiled script (code_pretty.luac). The parameter for the 'pretty_lines()' function is a table of source code lines.



function isCharAlpha(char_test)
function isKeyword(str_test)
function prefix_lineNbr(nbr, maxlines)
function prep_punctuation_all(in_str) -- the easy punctuation
function pretty_comment(in_str)
function pretty_keyword(in_str)
function pretty_lines(this_lua)
function pretty_lines_function_list(this_lua)
function pretty_lines_ini_file(this_ini)
function pretty_lines_xml_file(this_xml)
function pretty_one_line(str_in) -- the big one
function pretty_punctuation(in_str)
function pretty_quoted(in_str)
function pretty_xml_tag_left(in_str)
function pretty_xml_tag_right(in_str)
function sort_no_case(v1, v2)
function StringToTable(DelimitedString, Delimiter)
function xlate_FShtmlToBB()


BTW, alphabetic function list output as displayed (to HTML or BB Code) is a new feature.

And, here are the global variables required by the engine:




function restore_defaults()
convert_to_html = true;
html_fontsize = "9";
number_lines = true;

comment_color = "#008000";
comment_italic = true;
comment_bold = false;

quoted_color = "#800080";
quoted_italic = false;
quoted_bold = false;

keyword_color = "#0000FF";
keyword_italic = false;
keyword_bold = true;

punctuation_color = "#FF0000";
punctuation_italic = false;
punctuation_bold = false;

settings_save();
end

CyberRBT
04-03-2007, 07:10 AM
Okay. Here is another update. Now i'm going to wait for a while before updating the application while collecting a list of suggested improvements. Help / About apprises you of your installed version number.

The link in the intial post will DL the latest version.

The current version is now 1.0.3.4. When you install this update, make sure that the older version is not running (exit from the system tray) and you may also want to uninstall it (not required though).

Since AMS supports INI and XML files, I added a feature to open them and syntax highlight to HTML or BB Code. The HTML conversion is good for placing in the BODY of a Web page or in a help file.

Here are the updates:

1.0.3.4 (2007-04-03)

- HTML font sizes now alter BB Code too: HTML '7' is BB 1, HTML '8' is BB 2, HTML '9' is BB 3 (the defaults), HTML '10' is BB 4, and so on.

- New feature. In addition to conversion styles (HTML or BB Code), conversion types are now supported. They include: (1) All LUA Code,
(2) Function List, (3) Function List Sorted, (4) INI File, and (5) XML File.

1.0.3.3 (2007-04-02)

- enhanced the visual contrast between active and inactive wizard tabs

- added an HTML checkbox to the “Output Preview” page (suggested by RizlaUK above)

- implemented minor design enhancements to the “Output Settings” page

- to the “Help” page added Reference Sections: “AMS Sites” and “Coding Style” (the Coding Style topic was broached by Adam above)

Intrigued
04-03-2007, 05:47 PM
BTW, writing this type of code using regular expressions and a RichEdit control takes a few dozen lines of code. Using AMS to syntax highlight AMS code took over 300 lines.

These may come in handy, as I noticed your comment:

http://lua-users.org/wiki/ExpressionsTutorial
http://lua-users.org/wiki/StringInterpolation
http://lua-users.org/wiki/StringLibraryTutorial


Thanks for sharing the parts you did. I like to see how others are coding. This helps me to make sure I'm coding the best I can and to find some new insights, tips that others are using.

:yes

CyberRBT
04-04-2007, 05:46 AM
Thanks for the links. Interesting reading!

RizlaUK
04-04-2007, 06:45 AM
Hey CyberRBT :yes Thanks for the update

CyberRBT
04-04-2007, 06:48 AM
Cool. You guys keep me motivated.

And, your idea about putting an HTML/BB toggle on the Output Preview tab has turned out to be quite useful to me too.

CyberRBT
04-11-2007, 12:22 AM
Here is another update. Help / About apprises you of your installed version number.

The link in the intial post will DL the latest version.

The current version is now 1.0.3.5. When you install this update, make sure that the older version is not running (exit from the system tray) and you may also want to uninstall it (not required though).

RizlaUK
04-11-2007, 12:12 PM
And, your idea about putting an HTML/BB toggle on the Output Preview tab has turned out to be quite useful to me too.

:D yeah it makes it a lot easer, thanks for that and thanks for the update :yes


Iv a little suggestion for you to chew over

first I'll explain, i use metapad on my laptop to write code when im not at home when something springs to mind, and ams dosent run to well (i realy should upgrade the ram) and i often make typos and have to load the code into ams to sort out.

The idea, could this engine be used to format the code in real time ie as its typed. like have a input on the bottom half of the window and a web object on the top half, and as you type the code in the input the ams formatted code will apear in the web object, allowing me to see where and when i go wrong with out haveing to stare at all black text trying to pick up on the typo

maybe it could be a addon to this or a compleatly new app

anyway, like i say, just a idea to chew over ;)

CyberRBT
04-11-2007, 05:08 PM
@RizlaUK:

Actually, i had thought of something like this too. But, the AMS input control to HTML preview is not instantaneous.

In fact, right now, i'm about two months away from completing a commerical suite of plug-ins for AMS. Most of these will be non-visual ... just lots of action commands. But, after this is released my next planned project is a visual RichEdit control for AMS. When, that's done ... at LOT of other opportunities will present themselves ... including a revision to AMS Code Pretty as a real-time editor.

TristanD
04-16-2007, 05:20 AM
if you close the ams code pretty on windows vista . vista gives me an error : The program has stopped working....

CyberRBT
04-16-2007, 05:22 AM
Has anyone else experienced this?

Dermot
04-16-2007, 11:13 AM
I have seen it with other AMS apps that use the Lua MySQL dlls. Didn't narrow it down to one file. I just removed them all and the error went away.

CyberRBT
04-16-2007, 06:51 PM
I have seen it with other AMS apps that use the Lua MySQL dlls. Didn't narrow it down to one file. I just removed them all and the error went away.

AMS Code Pretty doesn't use MySQL. In fact, there are no 3rd party add-ons. It's coded in straight AMS.

Plus, it's been used extensively with XP and to a smaller extent with Vista. It works on Vista Ultimate. Has anyone else with Vista (any version) had the exit error mentioned by TristanD?

RizlaUK
04-16-2007, 07:12 PM
i cant say about vista as i dont have it yet, but i use it all the time on xp and havent had any error at all

CyberRBT
04-17-2007, 11:00 PM
Here is another update. Help / About apprises you of your installed version number.

The link in the intial post will DL the latest version.

The current version is now 1.0.3.6. When you install this update, make sure that the older version is not running (exit from the system tray) and you may also want to uninstall it (not required though).

Among minor improvements, this version fixes the bug with (" that prettified to ( " <--- it added an extra space.

Dermot
04-18-2007, 12:29 AM
Just tested your latest version on Vista Premium and I get the "Has stopped working" error when I close it. I only opened it and closed it. I did not actually use it.

I noticed that it plays a sound when it closes on XP but it does not play on Vista. This could be the problem. Maybe try removing that.

CyberRBT
04-18-2007, 12:41 AM
Thanks Dermot. That may be the key to resolving the issue. I removed the exit sound, recompiled, built the installer, and uploaded. I did not change the version #. Let me know if this fixes it.

Also, was Vista an upgrade or a clean install?

Thanks again.

Dermot
04-18-2007, 12:53 AM
Nope! that wasn't it. Still get the error.


Also, was Vista an upgrade or a clean install?
It's an upgrade but the computer is brand new and was Vista ready. Actually come to think of it, when I installed Vista I chose to do a clean install rather than upgrade XP.

CyberRBT
04-18-2007, 01:01 AM
Mine is Ultimate upgrade ... don't know what difference could cause this.

Anyway, I've now removed some variable clean-up code that executes prior to exit; wasn't really needed though.

Same version (with this fix) ready to DL. Let me know...

Dermot
04-18-2007, 01:15 AM
Sorry, no change. Not sure why there would be a difference between Premiun and Ultimate. I had quit a few people report this problem. In my case it was the MySQL files.

CyberRBT
04-18-2007, 01:31 AM
Hmmmm.

Now, my ONLY exit code is: Application.Exit();

There is no code in the On Shutdown event and no other code is processed by pressing the exit button. That's it: Application.Exit();

There is no MySQL access.

This leads me to believe that it is either AMS (with a custom window issue) or a loaded plug-in not unloading properly. Here's the list: Clipboard, ColorDialog, RunSilent, and xDialog. But ... if you just start the app and immediately exit, none of these is ever invoked ... which is what you did.

I am bewildered. I'll reinstate the previous code since that wasn't the problem.

If anyone has an idea, let me know.

Thanks Dermot and TristanD for pointing this out.

Dermot
04-18-2007, 01:52 AM
I found your problem. It is ColorDialog. I created a test app with nothing in it and added one plugin at a time and tested. When I added ColorDialog, I got the eroor, when I removed it, no error. Even though your app does not make use of any plugins when it starts up, proper plugins like ColorDialog will still be loaded. A dll like xDialog will only be loaded when you call the dll.

CyberRBT
04-18-2007, 01:59 AM
THANK YOU Dermot. As it turns out now, your hard work will be valuable to many of us.

BTW, I've had both versions of ColorDialog in the app ... this is the first version with the screen color picker option. But, the error has happened with both. What really seems odd is that this error only occurs on 'clean' Vista installations.

And ... it was that freeware DLL by Worm that actually convinced me that I could do Code Pretty.

BTW, i understand late-binding DLL's; i just didn't want to leave anything out.

I'll see if Worm can take a look at it before i attempt to code a new color picker.

CyberRBT
04-24-2007, 11:53 PM
Here is another update. Help / About apprises you of your installed version number.

The link in the intial post will DL the latest version.

The current version is now 1.0.3.7. When you install this update, make sure that the older version is not running (exit from the system tray) and you may also want to uninstall it (not required though).

This version fixes a couple of very minor bugs in the code pretty engine and corrects the Vista issue with the Choose Color dialog.

RizlaUK
04-25-2007, 09:48 AM
nice, thanks for the update, iv been waiting for this :yes


at frist hand i see one small fault still, nothing big, check the attachment, "true" is not being highlighted, other than that its perfect :yes :yes :yes

CyberRBT
04-25-2007, 07:11 PM
interesting ... true ... i'll check on it ...

Teqskater
01-02-2008, 09:44 PM
Man this is a nice app and i had it before but i lost it. now i want to download it again and there is no download link. please reupload. :huh

rexzooly
01-11-2008, 09:44 AM
i would also like to have a look at this program please reupload it please also if you need the file hosting please send it me and i will be happy to host it via my
site @ http://jonny6.pap3rback.net

dorkauf89
01-21-2008, 11:29 AM
This program looks awesome... I wish you could upload the file again.... THANKS!!!

sebalius
01-31-2008, 05:06 AM
I went to download this wonderfull appliance and found the link DEAD. Can you please upload it I would be gratefull.
ps I am only a learner.
sebalius ;)

gambit
02-01-2008, 06:10 AM
yes please reupload it again...it would be a big help for us...

TIA

RizlaUK
02-17-2008, 03:10 PM
grrr, add me to the list

Has any one seen CyberRBT on the forum, i havent had words for ages

Dermot, do you still have a copy of AMS Code Pretty, i need to put a help file together for a ams plugin and i was looking for this tool to save me weeks of html

Dermot
02-17-2008, 03:45 PM
grrr, add me to the list

Has any one seen CyberRBT on the forum, i havent had words for ages

Dermot, do you still have a copy of AMS Code Pretty, i need to put a help file together for a ams plugin and i was looking for this tool to save me weeks of html

Havn't heard from him in ages. I searched my system for Code Pretty but can't find it. Someone must have a copy though.

RizlaUK
02-17-2008, 05:13 PM
ok nevermind, i'll just have to do it the old fashion way, or just forget the highlighting for now

Thanks Anyway :yes

DaSoulRed
02-18-2008, 02:40 PM
I wonder if i can Use this for something.

Cheers:)

rexzooly
03-14-2008, 06:21 PM
shame this seems to be dead in the water :(

Ham
03-14-2008, 11:26 PM
Maby i can help (again:lol).

(zip)
http://home.tiscali.nl/hamserver/AMS_Code_Pretty_1.0.3_Install.zip

(exe)
http://home.tiscali.nl/hamserver/AMS_Code_Pretty_1.0.3_Install.exe

ShadowUK
03-15-2008, 02:54 AM
And I'll help as well.

http://shadowuk.net/AMS/AMS_Code_Pretty_1.0.3_Install.exe

rexzooly
03-15-2008, 06:52 AM
your stars thanks dudes i will make a back up to my servers later on soon as my domains are set up


:yes

Intrigued
03-15-2008, 10:16 AM
AMS_Code_Pretty_1.0.3_Install is now mirrored on amsuser.com as well, thank you guys for finding and posting it:

http://www.amsuser.com/ams/examples/AMS_Code_Pretty_1.0.3_Install.zip

ShadowUK
03-15-2008, 10:48 AM
AMS_Code_Pretty_1.0.3_Install is now mirrored on amsuser.com as well, thank you guys for finding and posting it:

http://www.amsuser.com/ams/examples/AMS_Code_Pretty_1.0.3_Install.zip

Now hopefully we won't lose it.

rexzooly
03-15-2008, 11:50 AM
Also mirrored at Jonny 6 Mini Media

http://jonny6.pap3rback.net/AMS/AMS_Code_Pretty_1.0.3_Install.zip

:yes

RizlaUK
03-15-2008, 12:08 PM
Thanks Guys :yes

rexzooly
03-15-2008, 12:45 PM
Thanks Guys :yes

What are we here for but to love coding and share hosting :D yay

P.S can host almost any AMS file for nothing just email me the file and i will
email you back the link.

Good look to all Members in there projects, but please remeber if the project will fit here please add it here first as we will happy rehost it if its a good peace of kit lol :P Intrigued as been doing it for some time and i was going to do wit when i got a razershare clone what didn't work right to i just FTP the files now :)


:yes

Teqskater
03-24-2008, 05:25 PM
A big thanks people! Thank you very much for reuploading and mirroring!

rexzooly
03-26-2008, 07:18 AM
This is now hosted on my new AMS Mirror service via this link below or going
to my site and clicking C and Click CyberRBT

http://jonny6.pap3rback.net/AMS/?page=CyberRBT


:yes

Imagine Programming
06-28-2008, 10:33 AM
Has someone found those three eastereggs already?:P i really can't find 'm

ShadowUK
07-03-2008, 12:53 AM
I'll mirror this later.

RizlaUK
07-05-2008, 09:53 PM
Has someone found those three eastereggs already?:P i really can't find 'm

lol, not yet

anyone seen cyber, he had a really cool plugin in the works and just dissapeared.

Imagine Programming
07-06-2008, 05:49 AM
lol, not yet

anyone seen cyber, he had a really cool plugin in the works and just dissapeared.

Now you say it, havn't seen him for a while :huh

startup
06-12-2013, 02:39 PM
all links are not valid
can any one re-upload this utility please ?