|
Post by GatorDog on Jul 25, 2011 19:04:08 GMT 1
If you use hug_imports.bac while developing and want the final app to use hug.bac, keyword_list...
Hug Keyword Parser - Parses a Bacon source.bak file for HUG keywords. Displays a new INCLUDE "/path/hug.bac", list_of_keywords In an Edit window. Then you can copy/paste the Include line into your program.
rod
|
|
|
Post by GatorDog on Jul 25, 2011 19:05:54 GMT 1
HUG Keyword Parser source. (I'm using BaCon GUI v 1.0.24beta / hug.bac v.61) Edit. Attachment for v1.0 r2 below. (Can't change attachment in this post?) Attachments:
|
|
|
Post by Pjot on Jul 26, 2011 0:51:45 GMT 1
Hi Rod, Wonderful! I have tested the program on a couple of my programs and it works Very handy. Indeed I sometimes add the HUG keywords taken from the source just by staring at it, but I always seem to forget something. This program actually grabs everything at once. Thanks for this contribution! Best regards Peter
|
|
|
Post by Pjot on Jul 26, 2011 11:15:35 GMT 1
BTW your other question about SELECT/CASE makes more sense to me now - in this program I see that there are almost 60 lines with the same IF INSTR() construct. There is a more effective way to achieve the check if a string appears in a bigger string. ... ' Each time start reading from the beginning RESTORE
' Get the keywords REPEAT READ keyword$ IF INSTR(Text$, keyword$) THEN CAT(keyword$) UNTIL keyword$ = "WINDOW("
' The data DATA "ATTACH(","BUTTON(","CALLBACK(","CALLBACKX(","CANVAS(","CHECK(","CIRCLE(" DATA "=CLIPBOARD","= CLIPBOARD","COMBO(","DISABLE(","DISPLAY","DRAW(","EDIT(" DATA "ENABLE(","ENTRY(","FILEDIALOG(","FOCUS(","FONT(","FRAME(","GET(","GRAB$(" DATA "HIDE(","HSEPARATOR(","HUGLIB$(","HUGOPTIONS(","IMAGE(","INIT","=KEY","= KEY" DATA "LINE(","LIST(","MARK(","METHOD(","MSGDIALOG(","MOUSE(","NOTEBOOK(","OUT(" DATA "PASSWORD(","PICTURE(","PIXEL(","PROGRESSBAR(","PROPERTY(","QUIT","RADIO(" DATA "REGISTER(","SCREENSIZE(","SET(","SHOW(","SPIN(","SQUARE(","STOCK(","SYNC" DATA "TEXT(","TIMEOUT(","TOGGLE(","UNFOCUS(","VSEPARATOR(","WINDOW(" ....
Regards Peter
|
|
|
Post by GatorDog on Jul 26, 2011 19:50:59 GMT 1
Hi Peter, Great idea. I briefly thought of the DATA statement, but didn't come up with the construct to use it. This sure compresses the code. The delimiters do need to be stripped off before adding them to string. REPEAT READ Keyword_match$ Keyword$ = REPLACE$(Keyword_match$, "= ", "") Keyword$ = REPLACE$(Keyword$, "=", "") Keyword$ = REPLACE$(Keyword$, "(", "") IF INSTR(Text$, Keyword_match$) THEN CAT(Keyword$) UNTIL Keyword$ = "WINDOW" I've thought of another feature to add to HKP. BaCon GUI has the FIND tool, so this would somewhat duplicate that capability. The feature would be this, add another edit widget and list the line number and the line of code that has the hug keyword in it. I'm not sure it would be all that useful and may just be "bloat". What do you think? rod (edit spelling ) Attachments:
|
|
|
Post by vovchik on Jul 26, 2011 22:16:32 GMT 1
Dear Rod,
Why not expand HKP to be a general xref for Bacon? You have the infrastructure there already - and you could add pretty printing (indentation and nesting). Just an idea...
With kind regards, vovchik
|
|
|
Post by GatorDog on Jul 27, 2011 4:37:50 GMT 1
Dear Rod, Why not expand HKP to be a general xref for Bacon? You have the infrastructure there already - and you could add pretty printing (indentation and nesting). Just an idea... With kind regards, vovchik Hey vovchik, I know what you mean by pretty printing, but I don't know what you mean by "xref". -------------- I was looking for a reason to work through the details of using the Notebook widget. So I started making a mock up and added a Tab for Line# and code text. I got the tabs setup and realized it was just a few lines of code to make it functional. Still don't know if this is really a "value added" feature. (but I did get tabs to work!) rod (source code to follow) Attachments:
|
|
|
Post by GatorDog on Jul 27, 2011 6:51:36 GMT 1
HKPx source rod Attachments:
|
|
|
Post by Pjot on Jul 27, 2011 11:44:40 GMT 1
Good idea, I saw you did it already with the NOTEBOOK widget - well done! Would the program also work with the GMP keywords? Probably it is just a matter of adding these to the DATA at the end of the program...? Regards Peter PS on line 43 I needed to add SET and NOTEBOOK.
|
|
|
Post by GatorDog on Jul 27, 2011 16:16:20 GMT 1
Peter, if you want to add the GMP feature, here are a few tips. - Add a Notebook Tab. Around line 475 - Clear the tabs edit-widget. Top of Function KEYWORD_PARSER ex. CLS(Edit_) - Just down from Clear tabs, add TEXT(tab-widget_, No_file$) (like I'm telling you how to program ) -------------------- Can individual EDIT() widgets be made no-wrap text? What is the difference between NUMBER and int? Do variable Declarations and CONSTs make a difference other than being more structured code? (Inquiring minds want to know ) ---------------------- vovchik, Is this program somewhat like you had in mind? ----------------------- Programming note: So that they don't show up in the REMarks report, I standardized on a string length of 20 characters for ' ------------------ Also for ' ****************** and ' ================== You don't have to use that length in your programs, but the lines will show up in the report. ex. ' ------------------ SUB YADA(YadaYadayada) ' ------------------ ;D rod Attachments:
|
|
|
Post by GatorDog on Jul 27, 2011 16:18:57 GMT 1
Source for BaconX - BaCon Xref program rod Attachments:
|
|
|
Post by vovchik on Jul 27, 2011 16:55:08 GMT 1
Dear Rod,
The cross-reference prog is brilliant. It saves a lot of time when coding and helps to get rid of silly errors. If you feel like it, you might try looking at variables, too, so that unused vars can be eliminated. Sometimes when you are coding, you forget that you have already used a var or failed to use an existing one which would have made the code cleaner. Thanks!
With kind regards, vovchik
|
|
|
Post by GatorDog on Jul 27, 2011 17:36:13 GMT 1
Dear Rod, The cross-reference prog is brilliant. It saves a lot of time when coding and helps to get rid of silly errors. If you feel like it, you might try looking at variables, too, so that unused vars can be eliminated. Sometimes when you are coding, you forget that you have already used a var or failed to use an existing one which would have made the code cleaner. Thanks! With kind regards, vovchik I think I'll have to rub the lamp pretty hard to get this genie out Let me stew on it a bit. Maybe Peter will have an approach for that. Added a coding feature. If you want BaconX to ignore a section of code, Precede it with '[x] and append '[/x] For example, use to ignore the info section at the top of a program. ' ================== ' Parse REMarks ' ================== IF Text$ = Rem_seperator1$ THEN CONTINUE IF Text$ = Rem_seperator2$ THEN CONTINUE IF Text$ = Rem_seperator3$ THEN CONTINUE IF LEFT$(Text$, 1) = Single_quote$ OR LEFT$(Text$, 3) = "REM" THEN '--- NEW --- ' Cut or ignore section IF LEFT$(Text$, 4) = "'[x]" THEN REPEAT READLN Text$ FROM File_handle_ INCR Linecount UNTIL LEFT$(Text$, 5) = "'[/x]" CONTINUE END IF '--- END NEW --- STRING_TO_EDIT_WINDOW(Remarks_edit_, Text$) CONTINUE END IF ' ================== ' END Parse REMarks ' ==================
Example: '[x] ' Some lines ' That I don't want ' BaconXref to process var = CHOP$(" Even a section of code. ") TEXT(widget, "here too") '[/x]
'[x] means cut , and since it's a comment, it won't effect program execution. rod Attachments:
|
|
|
Post by GatorDog on Jul 27, 2011 17:55:02 GMT 1
Forgot to update line count Attachments:
|
|
|
Post by Pjot on Jul 28, 2011 0:57:18 GMT 1
Hi Rod, Thanks for the improvements! For the first question, well, yes, but it is not obvious. The EDIT widget is kind of complicated. One would expect that the returned widgetID has a property to set the wrap mode, but this is not the case - the EDIT widget returns the ID of the window in which the multiline text widget is contained. Therefore, you cannot set a property on such an ID. There are more complicated widgets, like the LIST widget, which have the same problem. I need to think of a convenient way to set properties on such widgets (which actually combine multiple widgetID's). Anyway, for now there is a workaround; you can use the internal HUG administration arrays to determine the text view and set the correct property. It can be done as follows, for example on your REPORT: ... Report_edit_ = EDIT(Edit_width, Edit_height)
Report_view = hug_widget_focus(STR$(Report_edit_)) PROPERTY(Report_view, "wrap-mode", 0)
ATTACH(Hug_keyword_tab_, Report_edit_, Edit_x, Edit_y) ...
All the GTK wrap modes are mentioned here. For your second question, "what is the difference between NUMBER and int", the difference is that NUMBER converts to the C "long" type. A "long" has a larger range compared to "int". On most platforms an "int" has a range of 4 bytes while "long" has 8 bytes and therefore can contain larger numbers. Lastly, regarding variable declarations and CONST's, well, it depends. BaCon uses implicit variable declarations, and by default, such implicit declarations are global and based upon a "smart guess" - a variable always is NUMBER unless the variable name contains the "$"-sign, in which case a STRING is assumed. But sometimes you need floating numbers, and then it is necessary to explicitly declare a variable as a FLOATING type. Otherwise BaCon assumes NUMBER again. For the CONST, this makes sure a value in a variable never accidentally is changed in the program. Regards Peter
|
|