v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Difference between revisions of "v0.34:Cleaning up macros"

From Dwarf Fortress Wiki
Jump to navigation Jump to search
m (av, minor fix)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{av}}
 +
 +
This page is dedicated to help with cleaning up [[macro]]s. This is useful because a recorded macro contains quite a lot of other interface interaction, which can really slow down the execution of a macro.
 +
 
== Cleaning up Macros ==
 
== Cleaning up Macros ==
 +
Because DF caches macros, you must change at least the name of the macro (for example, incrementing a counter); otherwise, the oldest loaded version will be used.
  
This page is dedicated, on to describe, and help in cleaning macros. This is needed, because a recorded macro contains quite a lot of other interface interaction, what can really slow the executing.  
+
If you make macros that do a repetitive job in a single menu, you can easily use [http://gnuwin32.sourceforge.net/packages/grep.htm grep] and a menu macro file. Grep is a GNU utility, that process an input (text) file, and only returns lines that match the filtering options. It's a very powerful utility, and more information can be found in its [http://unixhelp.ed.ac.uk/CGI/man-cgi?grep manual]. Be warned that grep is case-sensitive - you will either need to specify the case correctly (usually uppercase for macros) or use the <code>-i</code> flag to ignore case.
  
Because DF has a cache for the macros, you must change at least the name of the macro inside it (use a counter, and increment it), otherwise, the oldest loaded version will be used :(
+
=== Using grep ===
 +
Because using grep to filter out unwanted lines also filters out the name of the macro, you have to prepend it manually. This can be done by using <code>echo macro_name > macro_name.mak</code>.
  
If you make your macros to do a repetative job in a single menu, you can easily use grep and a menu macro file. Grep[http://gnuwin32.sourceforge.net/packages/grep.htm] is a GNU utility, that process an input (text) file, and throws everything, that doesn't match the filtering options. It's a very powerful utility, so if you would like to know better, look into manual[http://unixhelp.ed.ac.uk/CGI/man-cgi?grep]. Because grep is case sensitive (CAPITAL non capital), you have to watch out for this, or use a -i (in-case sensitive) mode.
+
Grep can read patterns from a file or from command-line options. Files should have one pattern per line (see [[#Useful Filters|below]] for examples). For example, a file to only return scrolling commands could look like this:
 +
SCROLL_
 +
SECONDSCROLL_
 +
To use this method, create a file with the appropriate patterns (for example, build_menu.txt), and then:
 +
echo my1 > my1.mak
 +
grep -f build_menu.txt my.mak >> my1.mak
  
=== How to use them ===
+
(my.mak is the original macro and my1.mak is the "cleaned" macro.)
Because grep is not saving the first line (name of macro), you have to make it manually.
+
Don't forget to clean up any empty lines from the pattern file; otherwise, nothing will be filtered out.
You have two choices. You can create a file, with the appropriate menu name, for example build.menu, and then:
+
 
echo my1 > my1.mak
+
Alternatively, each pattern can be specified on the command line with <code>-e</code>:
grep -f build.menu my.mak >> my1.mak
 
Don't forget, to clean up any empty lines from the '''.menu''' file, otherwise, nothing will then filtered out.
 
Second method, use a bunch of patterns
 
 
  echo my2 > my2.mak
 
  echo my2 > my2.mak
 
  grep -e line_1_from_file -e line_2_from_file -e line_3_from_file my.mak >> my2.mak
 
  grep -e line_1_from_file -e line_2_from_file -e line_3_from_file my.mak >> my2.mak
  
For both cases the first line is writing my2 (the name of the macro) into the file. This operation will overwrite the existing content of the file. The second line is actually doing the filtering, and appending the file. (Don't run, otherwise you wish to double the macro, you will still have to delete the '''End of macro''' line from the middle of the file)).
+
In both cases, the first line is writing "my2" (the name of the macro) into the file. '''This operation will overwrite the existing content of the file if it exists''', so make sure this file doesn't exist or is unimportant. The second line is actually doing the filtering and writing the macro to the file. (This command can be run multiple times &mdash; since it appends to the file, it can be used to make multiple copies of the macro in a file. It may be necessary to delete the "End of macro" lines in the middle of the file.)
=== Some useful filter ===
+
== Useful Filters ==
====Build menu====
+
=== Build Menu ===
If you wish to build anything, and you are not intended to leave the build menu, and the macro is not selecting the building type, you can use the following file / listing to filter your macro. (so, for 'you manually select the first position, and the building type, and then run the macro' type of macros).
+
If you wish to build anything, and you are not intending to leave the build menu, and the macro is not selecting the building type, you can use the following file to filter your macro. (Essentially, you manually select the first position, and the building type, and then run the macro.)
 
  SELECT
 
  SELECT
 
  End of group
 
  End of group
Line 26: Line 34:
 
  End of macro
 
  End of macro
  
====Resizing menu====
+
=== Resizing Menu ===
If you wish to resize some building, you should use this filter, to speed things up. It will leave all the resizing commands, so it will be still valid for other building resizing. (If you recorded for bedrooms, you still can use for stone gardens...)
+
If you wish to resize some building, you can use this filter to speed things up. It will leave all the resizing commands, so it will be still valid for other building resizing (e.g. a macro recorded for bedrooms will still work for statue gardens).
 
  SELECT
 
  SELECT
 
  SECONDSCROLL_
 
  SECONDSCROLL_

Latest revision as of 20:29, 16 September 2013

This article is about an older version of DF.

This page is dedicated to help with cleaning up macros. This is useful because a recorded macro contains quite a lot of other interface interaction, which can really slow down the execution of a macro.

Cleaning up Macros[edit]

Because DF caches macros, you must change at least the name of the macro (for example, incrementing a counter); otherwise, the oldest loaded version will be used.

If you make macros that do a repetitive job in a single menu, you can easily use grep and a menu macro file. Grep is a GNU utility, that process an input (text) file, and only returns lines that match the filtering options. It's a very powerful utility, and more information can be found in its manual. Be warned that grep is case-sensitive - you will either need to specify the case correctly (usually uppercase for macros) or use the -i flag to ignore case.

Using grep[edit]

Because using grep to filter out unwanted lines also filters out the name of the macro, you have to prepend it manually. This can be done by using echo macro_name > macro_name.mak.

Grep can read patterns from a file or from command-line options. Files should have one pattern per line (see below for examples). For example, a file to only return scrolling commands could look like this:

SCROLL_
SECONDSCROLL_

To use this method, create a file with the appropriate patterns (for example, build_menu.txt), and then:

echo my1 > my1.mak
grep -f build_menu.txt my.mak >> my1.mak

(my.mak is the original macro and my1.mak is the "cleaned" macro.) Don't forget to clean up any empty lines from the pattern file; otherwise, nothing will be filtered out.

Alternatively, each pattern can be specified on the command line with -e:

echo my2 > my2.mak
grep -e line_1_from_file -e line_2_from_file -e line_3_from_file my.mak >> my2.mak

In both cases, the first line is writing "my2" (the name of the macro) into the file. This operation will overwrite the existing content of the file if it exists, so make sure this file doesn't exist or is unimportant. The second line is actually doing the filtering and writing the macro to the file. (This command can be run multiple times — since it appends to the file, it can be used to make multiple copies of the macro in a file. It may be necessary to delete the "End of macro" lines in the middle of the file.)

Useful Filters[edit]

Build Menu[edit]

If you wish to build anything, and you are not intending to leave the build menu, and the macro is not selecting the building type, you can use the following file to filter your macro. (Essentially, you manually select the first position, and the building type, and then run the macro.)

SELECT
End of group
CURSOR_
End of macro

Resizing Menu[edit]

If you wish to resize some building, you can use this filter to speed things up. It will leave all the resizing commands, so it will be still valid for other building resizing (e.g. a macro recorded for bedrooms will still work for statue gardens).

SELECT
SECONDSCROLL_
CURSOR_
_SIZE
End of group
End of macro