Introduction to CMAC. 1: Hello World

Home Forums Multi-Edit User Created Macros Introduction to CMAC. 1: Hello World

This topic contains 14 replies, has 34,141 voices, and was last updated by  edelwater 9 years, 11 months ago.

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #1016

    deleyd
    Participant

    Introduction to CMAC. 1: Hello World

    Here’s my intro to the powerful CMAC language which comes with Multi-Edit. I’ve recently learned it so I’m passing the knowledge on.

    We’ll start with the usual "Hello World" program. In Multi-Edit, type in the following code in a new window and save it as file "test.s":
    [code:2wglp582]void test()
    {
    TEXT("Hello World");
    }
    [/code:2wglp582]
    Now compile this program by either selecting the menu option TOOLS -> EXECUTE COMPILER… or by clicking on the toolbar button. The following window should come up (NOTE: If instead you get a window titled "Enter Compiler/Program Command" it’s probably because you haven’t saved it as file "test.s" yet. Multi-Edit uses the filename extention to determine what compiler to use.)

    {If you can’t see the image above, all images are stored on my private website, the image above is [url:2wglp582]http://members.cox.net/multiedit/mewimages/compile.gif[/url:2wglp582] check if your server is blocking this site.}

    (SPECIAL INSTRUCTION: There’s one setting here I suggest changing. It only needs to be changed once. Select "Compile CMACWIN macro". Then click the "Edit" button. In the "Compiler/Program Setup" window which comes up, I suggest changing "Reset Original Line Number" from "Special" to "Current". This way when the CMAC compiler says there’s an error on a certain line number it will go to the correct line where the error is.)

    Select "Compile CMACWIN macro" and click "Select". Multi-Edit compiles the code and pops up the Tool Pane window with the Output information. (If instead you get the error "Exec Error: Program ‘C:\….\cmacwin.exe’ could not be found." then see reply to this thread below.)


    Note the last line in the Tool Pane window at bottom tells you where the compiled output file TEST.mac went.

    You may open or close this Tool Pane window on the bottom either by selecting the menu option VIEW -> TOOL PANE or by clicking on the button in the lower right corner of the Multi-Edit screen.

    Now run the program either by selecting the menu option MACRO -> RUN… or by clicking on the toolbar button. The following window pops up. Type in "test" and click "OK":

    This will run your program. The text "Hello World" will be entered into your window as if you typed it in.

    The CMAC language documentation is obtained by going to HELP->Cmac Language

    #3757

    deleyd
    Participant

    Oops, forgot to mention, to run the program we just compiled, go to MACRO -> RUN… or click on the toolbar button. The following window pops up. Type in "test" and click "OK":

    This will run your program.

    The CMAC language documentation is obtained by going to HELP->Cmac Language

    #3758

    bdesilva
    Participant

    When I do this I ge the message :Exec Error: Program “”C:\….\cmacwin.exe”” could not be found. I have a recent full install of 9.1

    So I guess I need help installing the compiler and stuff. Do I just reinstall MEW with those options or is there a cleaner/easier way?

    Bryan

    #3762

    deleyd
    Participant

    Good point! by default the CMAC compiler is not included in the install. You will need to reinstall Multi-Edit and check the box "Macro Compiler, Headers and Help". I also highly recommend checking the box below that, "Macro Source", as that’s a great source of real CMAC code you can browse and use as a reference. (I’ll mention the "Multi-Edit\src" folder in a later lesson.) (I also recommend checking the box below that, "HTML Reference Help", if you plan to edit any HTML code, such as for a web site.)

    You do not need to reinstall Multi-Edit from scratch. Just install Multi-Edit on top of itself, uncheck all the boxes, then check the boxes for only the things you want to add (e.g. just check the boxes for "Macro Compiler, Headers and Help" and "Macro Source (Registered Version Only)"

    #3774

    bdesilva
    Participant

    I’m not at home this week so don’t have my full copy. What should I d/’l to overwrite the install I have and not lose any functionality… I understand the demo isn’t complete.

    Bryan

    #3777

    ReidSweatman
    Participant

    The Multi-Edit 9.10 demo doesn’t include the CMac source code, so you wouldn’t be able to recompile any of the native system macros. It does, however, include the header files, which are necessary to compile macros of your own, and, obviously, the CMacWin compiler. It isn’t installed by default in the demo merely to keep the disk footprint down, as trial users aren’t all that likely to learn the macro language. However, as David points out, it is a selectable option during the install.

    If the compiler is actually present in the root directory of the installation, check to see exactly what the compiler command-line entry looks like. For example, for the basic “compile the current file” command, Compile CMACWIN Macro, the command line should be:

    “<ME_PATH>CMACWIN.EXE” “<FILE>.<EXT>” -P”<ME_PATH>Mac” -I”<ME_PATH>SRC” -O”<MEERR>” -W

    If all this is present and correct, and the headers (files with the extension .sh) are actually present in the <ME_PATH>\Src directory, then either you have insufficient rights to Multi-Edit’s installation directories, or the installation is corrupt. In the former case, grant yourself the appropriate rights (just as a temporary expedient, try Full Access); in the latter, uninstall Multi-Edit, make sure its directory is deleted, and reinstall it, being careful to install the compiler.

    #7018

    deleyd
    Participant

    REBUILD MACRO LIBRARY
    If you are making changes to Multi-Edit system files in the Multi-Edit\src folder, sometimes you have to rebuild the macro library to make the change permanent. This is easy to do:

    1. Exit Multi-Edit
    2. Go to START -> ALL PROGRAMS -> MULTI-EDIT -> REBUILD MACRO LIBARAY

    You need to do this only if you are making a change to one of the files listed in the Multi-Edit\Utils\mewmcl32.lst file.

    #7519

    deleyd
    Participant

    New starting with ME2006 10.04

    Compiled *.mac files are now stored in two places:

    1. Multi-Edit system *.mac files are stored in:C:\Program Files\Multi-Edit 2006\Mac\

    2. User *.mac files are stored:

    2a. On Windows XP, 2000, ME, 98, 95: C:\Documents and Settings\<username>\Application Data\Multi Edit Software\Multi-Edit\10\Mac\

    2b. On Windows Vista:
    C:\Users\<username>\AppData\Roaming\Multi Edit Software\Multi-Edit\10\Mac\

    Note that these are hidden folders. To view:

      [*:29cvgj24]Open Windows Explorer[/*:m:29cvgj24]
      [*:29cvgj24]TOOLS -> FOLDER OPTIONS[/*:m:29cvgj24]
      [*:29cvgj24]Select the VIEW tab[/*:m:29cvgj24]
      [*:29cvgj24]Under ‘Advanced settings:’, select "Show hidden files and folders"
      (Later you may set this back to "Do not show hidden files and folders")[/*:m:29cvgj24][/list:o:29cvgj24]

      COMPILING CMAC ON ME2006 10.04 AND ABOVE

      There are 2 options in the TOOLS -> EXECUTE COMPILER dialog:

      [*:29cvgj24]Compile CMacWin Macro
      For user macros. *.mac file will go to C:\Documents and Settings\<username>\Application Data\Multi Edit Software\Multi-Edit\10\Mac\
      or
      C:\Users\<username>\AppData\Roaming\Multi Edit Software\Multi-Edit\10\Mac\[/*:m:29cvgj24]
      [*:29cvgj24]Compile CMacWin Macro (admin)
      For Multi-Edit system macros (all *.s files stored in C:\Program Files\Multi-Edit 2006\Src\). *.mac files will go to
      C:\Program Files\Multi-Edit 2006\Mac\[/*:m:29cvgj24][/list:o:29cvgj24]
    #8713

    edelwater
    Participant

    [n00b] I tried to run this. I do get it compiled but when I try to run it, it says:

    [code:1c258nxj]Macro or Macro file "DOCUMENTS.mac" NOT Found in C:\app\0082_Multi-Edit\ nor C:\app\0082_Multi-Edit\MAC[/code:1c258nxj]

    This is because the output is in [code:1c258nxj]C:\Documents and Settings\private\Application Data\Multi Edit Software\Multi-Edit\11\Config.04\Mac\whatever.mac[/code:1c258nxj]

    and it probably freezes at the space. When I put quotes around it in the run window it also gives the same message.

    So either I have to find out how to use the run macro window and entering somehow the full paht or change the default macro locations to include my user directory.

    #8710

    ChadW
    Participant

    When working with files that have spaces in the path, try using as noted in the sample below

    "C:\Program Files\Multi-Edit 2008\mew32.exe" "%1"

    #8711

    edelwater
    Participant

    When working with files that have spaces in the path, try using as noted in the sample below

    "C:\Program Files\Multi-Edit 2008\mew32.exe" "%1"[/quote:24wn2qyu]

    I click on "Macro" > "Run" enter the following:

    [code:24wn2qyu]"C:\Documents and Settings\private\Application Data\Multi Edit Software\Multi-Edit\11\Config.04\Mac\whatever.mac"[/code:24wn2qyu]

    (the default location where the mac files are generated) and get the same 5001 error. So I am using the quotes.

    p.s. I also note that I can not copy and paste from this window in the Macro > Run window, I have to paste it first in a MultiEdit window and only then I can past it in the Macro > Run window.

    #8708

    ChadW
    Participant

    Try using the "%1" at the end of the line as noted in the example

    #8709

    edelwater
    Participant

    Like this:

    ? I tried:

    Did you try this yourself?

    #8715

    deleyd
    Participant

    The error message is incomplete. Even though it only says it’s looking in C:\app\0082_Multi-Edit\ and C:\app\0082_Multi-Edit\MAC, it also looks in the user directory.

    (I think this was added in,… version 10.04? It was added when Windows Vista came out and made our lives difficult. I think this error message was never updated.)

    Still, let’s see, you have an output file whatever.mac in:
    C:\Documents and Settings\private\Application Data\Multi Edit Software\Multi-Edit\11\Config.04\Mac\whatever.mac

    Ahh, but the macro name itself you’re trying to run is called documents, so your code looks something like this?
    [code:2unwd5iq]macro_file whatever

    void documents()
    {
    make_message("Hello Documents");
    }
    [/code:2unwd5iq]

    When you compile this it compiles successfully and you get a message that the output file is:
    C:\Documents and Settings\private\Application Data\Multi Edit Software\Multi-Edit\11\Config.04\Mac\whatever.mac

    And now to run this macro we specify the file and the macro within that file. The file is whatever.mac, and the macro is documents. So in the Run Macro window we would put:
    [code:2unwd5iq]whatever^documents[/code:2unwd5iq]

    See if that works. Post your code if it’s different.

    #8719

    edelwater
    Participant

    It works! (i did not have documents or whatever just "test", documents and/or whatever were just to paste here as example).

    so:

    a) in the Macro > Run window you can not use path names.
    b) i did something I can not reproduce because i switched to path names after just "test" did not work. I did it right after the installation maybe I had to reboot once as I have now?

    Thanks guys!, I now finished http://wiki.multiedit.com/doku.php/doc/tutorial/cmac_1
    and am going to do http://wiki.multiedit.com/doku.php/doc/tutorial/cmac_2

    =D>

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.