rabbitkillrun2 Posted May 31, 2010 Posted May 31, 2010 (edited) I'm sure I'm not the first one to try this (everyone's tried making a command-line text-based program at some point, right?), but I couldn't find anything with the search, so I was wondering if anyone could help.I've found tutorials such as these:http://www.codeproject.com/KB/dotnet/TextQualifyingSplit.aspxhttp://www.codeproject.com/KB/dotnet/TextParser.aspxHowever, as I do not know C# or VB.NET, I'm having difficulty following them as I have to figure out what the code does as well as learn why it is doing what it does. I'm guessing (hoping) someone has already tried this in autoit and succeeded, so I'm wondering if I could get some basic help to start me off.I'm making a basic rpg type game, and all input will be text based. So far, I've just been separating the input after the first space, so if they typed in "attack lunge" (not from game, just example), then that could be easily split. The problem comes when there is more than one argument. Edited May 31, 2010 by rabbitkillrun2
jchd Posted May 31, 2010 Posted May 31, 2010 (edited) AutoIt helpfile is the key to success, glory, fame, hapiness, ... Using AutoIt >> Command line parameters will reveal you the Truth. Edited May 31, 2010 by jchd This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
rabbitkillrun2 Posted May 31, 2010 Author Posted May 31, 2010 Ah, yes, I know about them, but the thing is, I don't want parameters passed to the program. I'm using a GUI input box, so I need to parse them myself, with some sort of magic preferably.
jchd Posted May 31, 2010 Posted May 31, 2010 That's contradictory with both your title and the assesment made in the first post ("...making a command-line program..."). So your problem is parsing arguments in a string (that you get it from command-line or input box or TCP makes little difference). Since the only version of AutoIt including "some sort of magic" is reserved for distribution to corporate alien companies, you'd have to rely on what the standard version can offer What are your grammar rules for parsing? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
rabbitkillrun2 Posted May 31, 2010 Author Posted May 31, 2010 Sorry, it's been a busy day; my brain's not working at 100% of normal. I'll change it. I will probably end up using doublequotes for each argument. I would love to have it comma separated, but to ignore commas within double quotes, as that'd be easier for the user when each argument is only a word or number, and not a sentence etc, but as long as it works in some way, I'll be happy with that for now. I probably should have thoguht this out mroe before asking. I think I thought I'd just end up getting linked to some previous post that I'd missed, or some other tutorial on how to do it. Thanks for the help. I'm off to lie down.
jchd Posted May 31, 2010 Posted May 31, 2010 For a simple grammar you can probably go with a state engine and a few regexp, but it all depends on how flexible / complex you intend the thing to be. Also don't forget that you might want to expand it much further in the future so don't choose a too simplistic approach you'd probably have to refactor fully in some time. Get some rest, think twice and come ask again if you're stuck. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Ascend4nt Posted May 31, 2010 Posted May 31, 2010 (edited) I use this for parsing parameters in a string. It returns an array (or if nothing found, an @error):$aParsedArray=StringRegExp($sStringToParse,'("[^"]*"|[^\s"]+)',3)The PCRE can be altered to accommodate comma separated lists too, with this simple alteration:$aParsedArray=StringRegExp($sStringToParse,'("[^"]*"|[^\s",]+)',3)The array will include the quotations, so just use a StringReplace on the double-quotes for each entry.*edit: Oops, I forgot the comma-separated lists might allow spaces. In that case take out the \s from the 2nd PCRE. Edited May 31, 2010 by Ascend4nt My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now