Leaderboard
Popular Content
Showing content with the highest reputation on 06/25/2020 in all areas
-
OnDebugMsgBox
Burgaud reacted to argumentum for a file
Version 2.2024.1.26
591 downloads
..a more flexible way to handle a This UDF, declared as the first ( or close to the top ) in a script, will catch the dreaded "AutoIt Error" MsgBox and prettify it, or just plain hide it. Is optional. Also add an EventLog Entry ( or not, is optional ). Add an entry in a log file ( or not, is optional ). Run another program to do something about the mishap ( or not, is optional ). There is an example of usage in the ZIP along with an example of the other program that handles the aftermath.1 point -
In help file, in example of _GUICtrlListView_GetItemParam, there is a comment saying : ; Warning do not use SetItemParam on items created with GUICtrlCreateListViewItem ; Param is the controlID for items created with built-in function Always in help file, now with _GUICtrlListView_SetItemParam, remarks says :1 point
-
A cross-platform implementation of the AutoIt language
seadoggie01 reacted to TheDcoder for a topic
Hello again, I apologize for the delay, life got in the way again... as it always does Today I made some good progress, I redesigned my code to handle one token at a time, instead of all tokens at once, this has made things simpler. I now have a tangible scanner framework, and I have added support for quite a few types of tokens! enum TokenType { TOK_UNKNOWN, TOK_WHITESPACE, TOK_COMMENT, TOK_DIRECTIVE, TOK_NUMBER, TOK_WORD, TOK_OPERATOR, TOK_BRACKET, TOK_COMMA, }; I still have to add support for macros, variables, strings etc. but that shouldn't be very hard. I also forgot to mention that handling multi-line comments turns out to be not as simple as I thought, it requires special handling and it has unique behavior, I believe it is the only multi-line (pre-processor) directive. Anyway, here is the complete code of the parser: /* * This file is part of EasyCodeIt. * * Copyright (C) 2020 TheDcoder <TheDcoder@protonmail.com> * * EasyCodeIt is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <ctype.h> #include <stdbool.h> #include <stdio.h> #include "parse.h" #include "utils.h" const char CHR_COMMENT = ';'; const char CHR_DIRECTIVE = '#'; const char CHR_COMMA = ','; char CHRSET_WHITESPACE[] = {' ', '\t', '\n'}; char CHRSET_OPERATOR[] = { '+', '-', '*', '/', '^', '&', '=', '<', '>', '?', ':', }; char CHRSET_OPERATOR_EQUABLE[] = {'+', '-', '*', '/', '^', '&', '='}; char CHRSET_BRACKET[] = {'(', ')'}; struct TokenCharMapElem { enum TokenType type; union { const char chr; const char *chr_arr; }; }; static void print_token(struct Token *token) { puts("---### TOKEN ###---"); char *token_type; switch (token->type) { case TOK_UNKNOWN: token_type = "Unknown"; break; case TOK_WHITESPACE: token_type = "Whitespace"; break; case TOK_COMMENT: token_type = "Comment"; break; case TOK_DIRECTIVE: token_type = "Directive"; break; case TOK_NUMBER: token_type = "Number"; break; case TOK_WORD: token_type = "Word"; break; case TOK_OPERATOR: token_type = "Operator"; break; case TOK_BRACKET: token_type = "Bracket"; break; case TOK_COMMA: token_type = "Comma"; break; default: token_type = "Unnamed"; break; } fputs("Type: ", stdout); puts(token_type); fputs("Data: ", stdout); for (size_t c = 0; c < token->data_len; c++) putchar(token->data[c]); putchar('\n'); } void parse(char *code) { while (true) { struct Token token = token_get(code, &code); if (!code) break; if (token.type != TOK_WHITESPACE) print_token(&token); if (token.type == TOK_UNKNOWN) die("!!! Unknown token encountered !!!"); } return; } struct Token token_get(char *code, char **next) { struct Token token = { .type = TOK_UNKNOWN, .data = NULL, .data_len = 0, }; size_t length; // Identify the token if (length = scan_string(code, char_is_whitespace)) { // Whitespace token.type = TOK_WHITESPACE; token.data = code; token.data_len = length; } else if (*code == CHR_COMMENT || *code == CHR_DIRECTIVE) { // Comments and Directives token.type = *code == CHR_COMMENT ? TOK_COMMENT : TOK_DIRECTIVE; token.data = code; token.data_len = scan_string(code, char_is_not_eol); } else if (length = scan_string(code, char_is_num)){ // Numbers token.type = TOK_NUMBER; token.data = code; token.data_len = length; } else if (length = scan_string(code, char_is_alphanum)){ // Words token.type = TOK_WORD; token.data = code; token.data_len = length; } else if (char_is_opsym(*code)) { // Operator token.type = TOK_OPERATOR; token.data = code; // Include the trailing `=` if possible token.data_len = code[1] == '=' && chrcmp(*code, CHRSET_OPERATOR_EQUABLE, sizeof CHRSET_OPERATOR_EQUABLE) ? 2 : 1; } else if (char_is_bracket(*code)) { // Bracket (Parenthesis) token.type = TOK_BRACKET; token.data = code; token.data_len = 1; } else if (*code == CHR_COMMA) { // Comma token.type = TOK_COMMA; token.data = code; token.data_len = 1; } else { // Unknown token.data = code; token.data_len = 1; } // Set the next code *next = *code == '\0' ? NULL : code + token.data_len; // Return the token return token; } size_t scan_string(char *str, bool (cmpfunc)(char)) { size_t len = 0; while (true) { if (!cmpfunc(*str)) break; ++len; ++str; } return len; } bool char_is_whitespace(char chr) { return chrcmp(chr, CHRSET_WHITESPACE, sizeof CHRSET_WHITESPACE); } bool char_is_alpha(char chr) { return isalpha(chr); } bool char_is_num(char chr) { return isdigit(chr); } bool char_is_alphanum(char chr) { return char_is_alpha(chr) || char_is_num(chr); } bool char_is_opsym(char chr) { return chrcmp(chr, CHRSET_OPERATOR, sizeof CHRSET_OPERATOR); } bool char_is_bracket(char chr) { return chrcmp(chr, CHRSET_BRACKET, sizeof CHRSET_BRACKET); } bool char_is_not_eol(char chr) { return chr != '\n' && chr != '\0'; } Example output from my test: J:\Projects\EasyCodeIt\build_win>eci test.au3 ---### TOKEN ###--- Type: Directive Data: #include <Motivation.au3> ---### TOKEN ###--- Type: Comment Data: ; This is a single line comment ---### TOKEN ###--- Type: Comment Data: ; Mary had a little lamb ---### TOKEN ###--- Type: Comment Data: ; Hello from EasyCodeIt! ---### TOKEN ###--- Type: Word Data: MsgBox ---### TOKEN ###--- Type: Bracket Data: ( ---### TOKEN ###--- Type: Number Data: 0 ---### TOKEN ###--- Type: Comma Data: , ---### TOKEN ###--- Type: Number Data: 0 ---### TOKEN ###--- Type: Comma Data: , ---### TOKEN ###--- Type: Number Data: 1 ---### TOKEN ###--- Type: Operator Data: + ---### TOKEN ###--- Type: Number Data: 2 ---### TOKEN ###--- Type: Operator Data: - ---### TOKEN ###--- Type: Number Data: 3 ---### TOKEN ###--- Type: Operator Data: * ---### TOKEN ###--- Type: Number Data: 4 ---### TOKEN ###--- Type: Operator Data: / ---### TOKEN ###--- Type: Number Data: 5 ---### TOKEN ###--- Type: Operator Data: ^ ---### TOKEN ###--- Type: Number Data: 6 ---### TOKEN ###--- Type: Bracket Data: ) ---### TOKEN ###--- Type: Comment Data: ; The result is 2.999232 if anyone is wondering And here is the script that I tested with: #include <Motivation.au3> ; This is a single line comment ; Mary had a little lamb ; Hello from EasyCodeIt! MsgBox(0, 0, 1 + 2 - 3 * 4 / 5 ^ 6) ; The result is 2.999232 if anyone is wondering I hope to have more updates soon and hopefully the scanner/tokenizer will be completed! The next step would be actually analyzing the tokens and constructing a source tree from it (syntactic analysis is the buzz word)1 point -
use #RequireAdmin and Global $_CLASS_TITLE_MAGNIFIER = '[CLASS:MagUIClass]' Works both win7 and win101 point
-
Great, also, you can use _GUICtrlListView_MapIndexToID if the controls were created with non-native functions (_GUICtrlListView_AddItem and _GUICtrlListView_SubAddItem)1 point
-
Listview row background color
pixelsearch reacted to Nine for a topic
GUICtrlSetBkColor ($idItem3, 0x00FF00) ? or more precisely : #include <GUIConstantsEx.au3> #include <GuiListView.au3> GUICreate("listview items", 220, 250, 100, 200) Local $idListview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 230) For $i = 1 to 10 GUICtrlCreateListViewItem("item" & $i & "|col" & $i & "2|col" & $i & "3", $idListview) Next LVBK ($idListview, 2, 0x00ff00) LVBK ($idListview, 5, 0x00ff00) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func LVBK ($ListView, $row, $color) GUICtrlSetBkColor (_GUICtrlListView_GetItemParam($ListView, $row),$color) EndFunc1 point -
Yes, it would be painted every time a drawing event occurs (e.g. LV was covered and is uncovered again). On the other hand that's necessary, as otherwise no table at all would be drawn. Look at the helpfile example for _GUIImageList_BeginDrag(), at the bottom you'll find the line "If BitAND($iItemSpec, 1) = 1 Then", that's where the item number is checked and it's either painted in white or blue. You can add a test there for id = 1 and set it to green, then you realize how it works, Edit: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> GUICreate("listview items", 220, 250, 100, 200) Local $idListview = GUICtrlCreateListView("col1 |col2|col3 ", 10, 10, 200, 230) ;,$LVS_SORTDESCENDING) Global $g_hListView = GUICtrlGetHandle($idListview) Local $idItem1 = GUICtrlCreateListViewItem("item1|col22|col23", $idListview) Local $idItem2 = GUICtrlCreateListViewItem("item2|col12|col13", $idListview) Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview) Local $idItem4 = GUICtrlCreateListViewItem("item4|col22|col23", $idListview) Local $idItem5 = GUICtrlCreateListViewItem("item5|col12|col13", $idListview) Local $idItem6 = GUICtrlCreateListViewItem("item6|col32|col33", $idListview) Local $idItem7 = GUICtrlCreateListViewItem("item7|col12|col13", $idListview) Local $idItem8 = GUICtrlCreateListViewItem("item8|col32|col33", $idListview) Global $s_Rows_to_Paint_Green = ";2;;5;" ; 0-based GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWndGUI, $iMsgID, $wParam, $lParam) #forceref $hWndGUI, $iMsgID, $wParam Local $tNMHDR, $iCode, $x, $y, $tNMLISTVIEW, $hWndFrom, $tDraw, $iDrawStage, $iItemSpec $tNMHDR = DllStructCreate($tagNMHDR, $lParam) If @error Then Return $iCode = DllStructGetData($tNMHDR, "Code") $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") Switch $hWndFrom Case $g_hListView Switch $iCode Case $NM_CUSTOMDRAW $tDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) $iDrawStage = DllStructGetData($tDraw, "dwDrawStage") $iItemSpec = DllStructGetData($tDraw, "dwItemSpec") Switch $iDrawStage Case $CDDS_PREPAINT Return $CDRF_NOTIFYITEMDRAW Case $CDDS_ITEMPREPAINT If StringInStr($s_Rows_to_Paint_Green, ";" & $iItemSpec & ";") Then DllStructSetData($tDraw, "clrTextBk", 0x00ff00) Return $CDRF_NEWFONT EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY1 point
-
Is it possible for Autoit to log errors to text file?
Burgaud reacted to argumentum for a topic
..and I made a UDFish out of it1 point -
Posting when Mods are working in a thread
tarretarretarre reacted to Melba23 for a topic
And just in case you were wondering, we were not joking: M230 points