How to get more out of the HTML/JavaScript Combination and/or Akiva's WebBoard version 4.x/6.x with Rog's JavaScript MakeFile System (version 1.0)

This describes freeware that I wrote which allows any web developer as well as WebBoard customers to get the most out of dividing the client/server processing relationship up into the appropriate processing "chunks."

This system only works on "WinTel" machines, although the code should port with little trouble to Unix (if you know how to use a C compiler).  It will not work on an Amiga or a MacIntosh.

There are four basic facilities offered in this system:

  • Specify constants that are replaceable on a "cascading" basis.

  • Use "include" files (just as in a standard programming language) within JavaScript and/or HTML files.

  • "Compress" your JavaScript include files by eliminating comments, superfluous commands and/or punctuation: this can cut the size of the code delivered to the user's browser by as much as 80%, and reduce the amount of "work" that has to be done on the server.

  • "Build" a "tree" of dependent files, in the same manner as a typical "makefile" system.

Experienced web designers and ASP(+) programmers know that efficiency lies in "dividing the work" between the client and server side.

This system lets you "sculpt" applications to the precise degree required . . . in terms of the client-server relationship, and the resource allocations that you wish to provide to either side.

This code is freeware.  You use it at your own risk.  No warrany of fitness for use or any other form of guarantee inheres.

You may use it and/or the source code in whole or in part for any otherwise legal purpose that you deem fit; however you may not claim legal ownership of same for legal purposes against anyone who's obtained it from an "independent source" (such as this web page).


1:  Intended Audience

2:  Install (0): configuring your DOS environment size

3:  Install (1): getting the files

4:  Install (2): Where do you go from here?

5:  Making the DOS (or CMD) prompt into your "home away from the desktop"

6:  How to run the tutorial examples

7:  Tutorial example 1: Basics of "make" files: targets, dependencies, and actions

8:  Tutorial example 1, continued: "Phony" targets

9:  Tutorial example 1, almost finished: touching and making

10:  Tutorial example 1, comments and blank lines

11:  Tutorial example 2: Including files with JSM.Bat and the H and U subfolders

12:  Tutorial example 2: the treble-ballyhoo about backslashes

13:  Tutorial example 2: the straight dope about JSM.Bat

14:  Tutorial example 2: more on update times and efficiency

15:  Tutorial example 2: about action lines and running programs

16:  Tutorial example 3: Getting up to speed by using remarks, copying (and moving files), as well as automatic folder creation.

17:  Tutorial example 3: Digging deeper ... starting with remarks

18:  Tutorial example 3: Digging deeper ... what is an "executable"?

19:  Tutorial example 3: Digging deeper ... "make variables" and how to move/copy/delete files

20:  Tutorial example 3: Going professional ... using JSM_Chk and FMkDir

21:  Tutorial example 3: using FEcho and @-signs

22:  Tutorial example 4: introducing NoComJ, and bringing JavaScript into the picture

23:  Tutorial example 4: introducing batch files (jsm_Ex4.Bat)

24:  Tutorial example 4: batch file variables become make variables

25:  Tutorial example 4: using compressed JavaScript and the role of the H subfolder

26:  Tutorial example 4: using NoComJ in a make file (section D of jsm_Ex4.mak)

27:  Tutorial example 4: section C of jsm_Ex4.mak

28:  Tutorial example 4: sections A, B, and E of jsm_Ex4.mak

29:  Sharing files: conditional inclusion and variable H-subfolder "marker" files

30:  Idiosyncracies of the JavaScript code compressor (NoComJ)

31:  Command-line parms for the JavaScript code compressor (NoComJ)

32:  How to generate WebBoard files for one of my freeware systems

33:  More information about the executable programs, getting the source code for them, and how to do a Unix port

34:  Bug reports, comments, change requests, and how to hire me

35:  Other freeware products

36:  Version history information

37:  Acknowledgements


1:  Intended Audience

This documentation isn't for everyone.

If you've never worked with any computer language before, you're going to find this to be quite a challenge.

Let me try to be specific: if you're at the point where you can code "a little JavaScript" and edit HTML with a plain-text editor (such as Windows Notepad), then you probably know enough to get through this presentation.  If you apply yourself, you'll probably find that the results are worthwhile, because you'll be able to build more effective web pages.

This documentation is also for those users of my WebBoard freeware systems who might wish to further modify them, or fix bugs themselves (if you do fix a bug, I'd really appreciate it if you contact me).

If you're a "sysadmin" who feels comfortable with IIS and relatively minor software configuration tasks, the degree to which you'll find this documentation to be challenging is . . . directly proportional to your level of experience with a "near-standard" programming language (JavaScript and VBS do indeed "fit" the definition that I have in mind, however WORD, WordPerfect or Excel "macros" don't).

Anyone who's programmed in a standard compiled language such as C[++], or VB[++], or a complex interpreted language such any of the scripting languages (JS, PerlScript), or Java should have no trouble at all.

Those of you in the latter category will find this system particularly useful, as I'm offering the only "portable" freeware file-inclusion and "makefile" system that I know of for a WinTel environment.  Although the specific focus here is on integrating client-side JavaScript into web pages (server-side will also run faster, due to the source code compression), my approach could be extended to a number of other contexts.

(One might quibble around the edges here . . . in observing that the GNU Windows utilities do indeed constitute a "makefile" environment.  Unfortunately, they presume that the user is already working in a Unix-like context: much of the work I've done for you here is simply to extract the critical GNU utilities and show you how to hand them over to a client or end-user without forcing them to install the entire GNU package.)

Return to table of contents

2:  Install (0): configuring your DOS environment size

It's very difficult to "trap" errors involving a too-small amount of space for DOS "environmental variables" (it's not important if you don't know what those are).

For Windows 9x machines, put these lines in the file C:\Config.Sys:


SHELL = C:\COMMAND.COM C:\ /e:4096 /p

For Windows NT (or 2K, or XP), you need to put this line in ..\SYSTEM32\CONFIG.NT:


SHELL=%SYSTEMROOT%\SYSTEM32\COMMAND.COM /E:4096

Make sure you use a text editor, such as DOS Edit, TextPad, DEdit (included in this package). Do not use a word processor like MS-WORD (unless you use the option to save as "DOS text" or "plain text." Windows Wordpad is all right too, provided you save all files as "DOS Text." And if you want to use Windows Notepad, be sure that the Edit | Word Wrap option is off.

Return to table of contents

3:  Install (1): getting the files

Create a fresh folder on your hard drive, and use WinZip to unzip JSM.Zip.

If you wish to follow the tutorial, you should then unzip JSM_Ex.Zip.  You'll find that file in your folder (it's contained within JSM.Zip).

Return to table of contents

4:  Install (2): Where do you go from here?

This documentation has two main purposes:

Return to table of contents

5:  Making the DOS (or CMD) prompt into your "home away from the desktop"

If you're a Unix user, you already recognize the value of having a "command line".

If not, let me ask you to consider the following analogy.

Suppose you like a particular national/regional style of cooking. Ethiopian, Indian, Italian . . . Korean, Mexican, American Southern, . . .  pick your favorite(s).

Now: would you rather live in an area where there are many fine restaurants of this sort, or would you rather learn how to buy the ingredients, maintain a well-stocked pantry, and have a kitchen that was well-equipped to make the recipies involved?

Obviously the answer to the question depends on a lot of variables.

But there's no question that you'll be able to enjoy the most satisfying culinary pleasures if you learn the art of cusine, as understood by the various cultural models that you wish to partake.

Becoming "at home" with the DOS command line is rather like bringing a different kind of cuisine to your kitchen.  There are quite a few new tools that you need to aquire, especially if you're a committed Windows GUI interface user.

You may feel that too much time and energy is needed to make these adjustments.

It's really up to you.

I've included the basics that you need in JSM_DOS.Zip.

  • TurboKey.Com: The keyboard "whizzer" (Windows 9x only)

    TurboKey's a great freeware keyboard accelerator, far beyond anything offered by MS.

    Evidently Misrosoft just doesn't think your arrow keys should move the cursor too quickly.  <sigh>

    To install it, put it in your autoexec.bat  (for Windows 9x users), or the appropriate startup folder  (for Windows NT, 2K, or XP users).

  • A DOS command line editor: Anarkey (Windows 9x only)

    A good DOS command line editor should allow you to use the arrow keys to "recall" previous entries that you've done at the DOS command line, and to "edit" (i.e. change) them.  DOSEdit is a fair command line editor.

    I've also included my personal favorite, Anarkey.Com  (it's in AnarkeyS.Zip, which is itself contained in the main DOS zip, JSM_DOS.Zip.)  Anarkey is shareware, so you will need to spend $30 to buy it.  IMO, it's well worth the price.

    If you don't wish to use Anarkey or you have NT, 2K, or XP, then the DOSKey program may be a suitable replacement.

  • A DOS editor, with mutliple windows support, a file manager, a DOS command prompt ("shelling") and binary file support.

    If you've never "flipped" back-and-forth between multiple windows in a DOS editor, nor scrolled through a 2,000 line file in just a fraction of a second, you have no idea how fast, easy, and supple "text only" interfaces truly are (by comparison to GUI).

    (While my favorite DOS editor is Boreland's SideKick Plus, this is no longer available to the public, and won't work with any Windows OS beyond 98 (it's incompatible with NT, 2K, and XP).  You may still be able to get the successor, called SideKick II.  I find it much more difficult to use, due to the dearth of configuration options.)

    Windows 9x users may enjoy a piece of shareware called "Breeze" (it's Breeze56.Zip in the main DOS zip, JSM_DOS.Zip).  Unfortunately, Breeze doesn't work with 32-bit FATs.

    I've also supplied a piece of freeware called DEdit (in DEdt0942.Zip).  DEdit is Windows-based, i.e. it will run from your desktop.  It doesn't have as many nice features as Breeze, but it will handle 32-bit FATs (file allocation tables).

    Finally, you might look into a package called TextPad, which I've never used (although I've heard good things about it).

    Whatever editor you choose, make sure that line and column numbers are shown, and that it will let you insert "hard tabs."

    You can get along with DOS's EDIT if you don't wish to install either of the editors that I've supplied.  However, EDIT won't let you insert "hard tabs," so you'll have to do those with Windows Notepad (hold down the left alt key, turn off "num lock", and then type a 0 and then a 9 on the numeric keypad).  Alas, Notepad won't show line numbers, so you'll have to use both: your best solution is to create a file that consists of just one hard tab, and paste it in.

  • A keyboard "key-swapper" that lets you switch control and caps lock.

    I've included a piece of freeware from PC Magazine in the JSM_DOS.Zip file: it's called PCMZKM32.Zip.  I haven't tried it on anything besides Windows 98: for all I know, it may not work on other versions of Windows.  If you're running NT, 2K, or XP, you might want to look around for a piece of freeware that does this - I'm sure one exists.

Finally, you should know how to customize the DOS prompt (use the "Cmd" prompt instead on NT, 2K, and XP), as well as how to create shortcuts to DOS (or Cmd) on your desktop.  I assume that you know that much about how to use Windows.

If you have a large monitor (say: 17" or more), you may wish to run the DOS command line on your windows desktop (instead of in full screen mode).  Unless your computer is very fast (i.e., 700MZ or more), you may find that the GUI interface slows you down considerably.  Nevertheless, this will allow you to have multiple-window editing as well as the command line on your desktop--all at once, without installing an additional editing package.

Make sure you use a "fixed space" rather than a proportional font in your DOS window(s).  You might also consider upgrading your computer's fonts at: http://www.microsoft.com/truetype.

(It's crucial for you to have a highly readable font with "fixed" spacing.)


Suffice to say that you can have multiple DOS (or Cmd) icons on your desktop for a variety of purposes.  You can also create them for your users, in order to make it easier for them to run multiple processes.

(The DOS/Cmd icon is relatively unique in this one regard: every time you create a "shortcut", you can right-click on that shortcut to change the icon's properties.)


If none of the products in the list of editors (above) seem suitable, I recommend that you go to:

http://oak.oakland.edu/.

Once there, look for the "Simtel" DOS archives.  These are archives of freeware and shareware which have been maintained for some decades by the U.S. Government in coooperation with Oakland University and other pubilc-spirited organizations.

Most of the software there is excellent ... however beware that many of the DOS editing packages will not work with a "FAT 32" file system.


For another fabulous source of free software, consider FSF (AKA "Free Software Foundation"--the "GNU" folks): http://www.gnu.org/software/.

In fact, if your budget isn't too limited, I'd recommend that you order the CD-ROM entitled "GNU Software for MS Windows and MS DOS" at: http://www.gnu.org/order/order.html.

(Note: the above URL will take you to the main ordering page for GNU.  As of this writing, the following one will take you directly to the CD-ROM that I just mentioned: http://www.gnu.org/order/windows.html.

This is an incredbly useful tool for consultants, because GNU software can be distributed with your packages; it's also excellent for organizations, because you don't need a license for each machine on which it runs.  In fact, you can get the very same software via FTP, but having the CD is an excellent way to save time.

Unix users should note that the CD-ROM contains GNU's own version of BASH (the "Born-again Bourne Shell").

If you work for a corporation, I'd like to make a personal plea to you: spend the $140 for the corporate CD.  The folks at GNU are making the world a better place to live.  Kindly help them out.


I'd strongly encourage you to learn more about DOS batch files and the DOS command-line environment.  You might wish to take a look at my DOS primer.

Return to table of contents

6:  How to run the tutorial examples

There are four tutorial examples.

Presumably, you've already created a new folder and unzipped JSM.Zip into it (that was what I asked you to do in section 3).

To run the tutorials, you need to unzip JSM_Ex.Zip into that very same folder.

Return to table of contents

7:  Tutorial example 1: Basics of "make" files: targets, dependencies, and actions

Suppose you're maintaining a web site that has two different pages.

One page announces a daily contest winner.

Another page is for birthday announcements.

If someone has birthday, your customer/client/user insists that this person is also automatically the same person as the contest winner.

The first web page looks like this (jsm_Ex1A.Txt is the same as the first line below):


<P>And the winner is: <BR>
(Name and photo of winner goes here)

The second web page looks like this (jsm_Ex1B.Txt is the same as the first line below):


<P>Happy birthday to: <BR>
(Name and photo of person with birthday goes here)

Instead of manually changing both web pages, we'd like to set up a process that allows both to simultaneously set the name and photo of the contest winner/birthday-person on the days when they're the same person.

So we'll set up the following "make file," and put the person's name in the file jsm_Ex1.Inc.

The goal here is to make sure that every time there's a change to any of the three files, we'll build the corresponding HTML file.

For the contest winner, the HTML file will be jsm_Ex1A.Htm.

For the birthday announcement, the HTML file will be jsm_Ex1B.Htm.


So let's think about what we need to do here, in order to keep both pages updated.

First, if the "include" file (the name of the person, i.e. jsm_Ex1.Inc) gets updated, then we have a new birthday person/contest winner.

At that point, both the contest winner HTML file (jsm_Ex1A.Htm) and the birthday announcement HTML file (jsm_Ex1B.Htm) have to be updated.

What if jsm_Ex1A.Txt gets updated?  That's the file containing the first line of the contest winner announcement.

In that case, then the corresponding HTML file (jsm_Ex1A.Htm) needs to be updated.

What if jsm_Ex1B.Txt gets updated?  That's the file containing the first line of the birthday announcement.

In that case, then the corresponding HTML file (jsm_Ex1B.Htm) needs to be updated.


The following "make file" does precisely that: however there's just a little bit of "overhead" needed to ensure that everything gets updated properly.  You should find it in JSM_Ex.Zip under the name: jsm_Ex1.Mak.

1.  .PHONY:  all
2.
3.   all:jsm_Ex1A.Htm  jsm_Ex1B.Htm
4.
5.  jsm_Ex1A.Htm:jsm_Ex1A.txt  jsm_Ex1.inc
6.  <tab> Cat.Exe  jsm_Ex1A.txt  jsm_Ex1.inc  >  jsm_Ex1A.Htm
7.
8.  jsm_Ex1B.Htm:jsm_Ex1B.txt  jsm_Ex1.inc
9.  <tab> Cat.Exe  jsm_Ex1B.txt  jsm_Ex1.inc  >  jsm_Ex1B.Htm

Lines 5-6 are the two lines that tell us how to keep the contest winner file updated.

Let's focus on Line 5.

On the left of line 5, (preceeding the colon), we see the name of the final contest winner HTML file.  On the right, we see the two files that can "trigger" a change to it on the left.  As you recall, jsm_Ex1A.Txt contains the "core" of the file (i.e. without the name of the contest winner); whereas jsm_Ex1.Inc contains the contest winner's name.

In the language of "make files," the thing on the left is called the "target" . . . it's what needs to be "made" (or "built").  The items on the right of the colon are the "dependencies"--they're the files on which the target "depends."

The golden rule of make files:

If a target is "older" than any of the files on which it depends, then "make" the target by performing the "actions" required to build it.


"actions??"  What are those?

Take a look at line 6, in context:

5.  jsm_Ex1A.Htm:jsm_Ex1A.txt  jsm_Ex1.inc
6.  <tab> Cat.Exe  jsm_Ex1A.txt  jsm_Ex1.inc  >  jsm_Ex1A.Htm
7.

This is the sole "action" line that corresponds to line 5.

(If there were other "actions," they would follow line 6, until a blank line was encountered.)

The "action" in this case amounts to calling the program "Cat.Exe", and telling it to copy the contents of jsm_Ex1A.Txt and jsm_Ex1.inc to jsm_Ex1A.Htm.

If you're not a Unix user, you may not be familiar with Cat. This program simply takes one or more files, and concatensates them to the standard output.  In this case, these three files are simply merged together, and copied to the file on the end of that line.  (It's not important that you understand how to use Cat: it just happens to make this example a little simpler; and we'll be dispensing with it later.)

As you may recall, jsm_Ex1A.Txt is the main part of the contest winner announcement HTML file:


<P>And the winner is: <BR>

Whereas jsm_Ex1.Inc contains the actual name (and photo) of the person who won the contest, e.g.:


<table cellpadding=5>
<tr><td align=center>
<img src="jsm_al_e.jpg"></td></tr>
<tr><td align=center>
<nobr>Alfred E. Neumann</nobr>
</td></tr>
</table>

What happens when you put jsm_Ex1A.Txt together with jsm_Ex1.Inc (respectively) to form jsm_Ex1A.Htm?

Of course, we get the required:


<P>And the winner is: <BR>
<table cellpadding=5>
<tr><td align=center>
<img src="jsm_ex_al.jpg"></td></tr>
<tr><td align=center>
<nobr>Alfred E. Neumann</nobr>
</td></tr>
</table>

Before we go on, I should clarify a few points about the syntax for "actions:"

The (golden) syntax rule of actions:

Action lines follow the line(s) that specify targets and dependencies: each action line MUST begin with a "hard tab".  Actions are terminated by a blank line.

What's a "hard tab?"

It's a specific binary character (decimal 9), and if your word processor doesn't allow you to put it in, you'll need to consider getting one that does.  WordPerfect has a specific option designed for "hard tabs."  Windows Notepad will put one in if you hold down the left alt key and press a "0", followed by a "9" in the numeric keypad (of course you'll have to first make sure that the "num lock" is off).  Regrettably, DOS Edit won't let you put in hard tabs, so you'll have to choose between having line numbers (which DOS Edit will give you), and having hard tabs (which Notepad will give you).

Note that I've supplied two editors with this package that do allow you to put in hard tabs: Breeze (which won't work with a 32-bit file allocation table), and DEdit.  In both cases, you simply use the tab key.


What happens if a target file depends on a file that doesn't exist?  How does make determine whether the target is "older" than the target's "dependencies?"

The answer is that make will look for another target/dependency pair in which the file is the target.

If that file isn't found, then make will "complain" (i.e.: you'll get an error message.)

In short, make builds targets "recursively" (if that word means nothing to you, just take it for granted that make "does the needful").

We are ready for yet another "rule:"

The golden rule of dependencies:

Any file listed as a "dependency" MUST either be listed as a target somewhere else, or already exist.

Return to table of contents

8:  Tutorial example 1, continued: "Phony" targets

Let's see that "make" file from example 1 again:

1.  .PHONY:  all
2.
3.   all:jsm_Ex1A.Htm  jsm_Ex1B.Htm
4.
5.  jsm_Ex1A.Htm:jsm_Ex1A.txt  jsm_Ex1.inc
6.  <tab> Cat.Exe  jsm_Ex1A.txt  jsm_Ex1.inc  >  jsm_Ex1A.Htm
7.
8.  jsm_Ex1B.Htm:jsm_Ex1B.txt  jsm_Ex1.inc
9.  <tab> Cat.Exe  jsm_Ex1B.txt  jsm_Ex1.inc  >  jsm_Ex1B.Htm

We've talked about lines 5-7 (and the analogous lines 8-10,) but not about lines 1-4.


For simplicity, let's start by pretending that lines 1-2 weren't there.

Given what we know so far, lines 3-4 appear to be a fairly straightforward case of a target (all), and two "dependencies" (i.e. files on which the target depends).

But there is no file named "all", is there?

This appears to violate the golden rule of dependencies, right?

(Gotcha!  ;-)

Well . . . maybe not.  The golden rule of dependencies refers to nonexistent files that are listed on the right, not the left.

So-o, in fact, there's no problem here.  Make will simply assume that the nonexistent file "all" is "newer" than the two files listed on the right of line 3, and then go about its business.

In fact, if there is no file named "all," and you simply remove line 1, nothing will change.

What if there is a file named "all"?

Ah.  Then we have a problem.  If the file called "all" is "newer" (more recently modified) than either of jsm_Ex1A.Htm or jsm_Ex1B.Htm, then nothing would happen.

That's not what we want.

Line #1's sole purpose in life is to declare that "all" is a "phony" target, i.e. a target that doesn't actually correspond to a bona fide file.


Hold it.

The analysis I just provided is insufficient: why have lines 1-4 at all?  What's wrong with just having lines 5-10?

This is because:

The "first target" rule of make:

Only the first "target" listed in a makefile will be built.  Any targets that aren't directly or indirectly referenced will be ignored.

Return to table of contents

9:  Tutorial example 1, almost finished: touching and making

To run example 1, simply type the following (capitalization doesn't matter, except that the "-f" has to be in lower case):


fmake -f jsm_ex1.mak
(Don't forget to press the enter key afterwards.)


Note that you don't always have to type something quite as elaborate to invoke make.  You could create a DOS batch file called "mk.bat" which looked like this:


fmake -f %1.mak

At that point, you could then run the make process by typing:


mk jsm_ex1

(Don't forget to press the enter key afterwards.  Alternatively, you could make this command into a shortcut).

What if you decide that you need to override what GNU make ("FMake") normally does?  That is, you want to "force" it to update certain files.

The solution is to use the utility "FTouch". FTouch will alter the update-date of any file ... and change it to the current date.

You need only type this from the DOS prompt (or the Cmd prompt, if you're running NT, 2K, or XP):


ftouch filename

If you wish to include multiple file names on the command line, you can do so.  E.g.:


ftouch filename1 filename2

As with all GNU utilities, you can type the name of the executable, followed by a space, and --help to get more information.  I.e.:


ftouch --help

Return to table of contents

10:  Tutorial example 1, comments and blank lines

You can put blank lines anywhere in a make file, except between a pair of action/target lines.  I strongly recommend that you use blank lines in order to clarify the "nature, purpose, and effect" of your commands.

You can also use a comment-line anywhere that a blank line is allowed.

Simply put a pound-sign ("#") in the first column of the line.  You'll see examples of comments and blank lines in jsm_Ex1.mak.

Comments are like investments: the 10 seconds you spend today, may save you 10 minutes (or even 10 hours) tomorrow.  Or, it may save someone else 10 hours.  Unlike investments, comments rarely lose their value.  The downside is that misleading or obsolete comments can be a "booby trap."  On balance, most programmers prefer to use lots of comments, just as most folks tend to invest ... rather than sewing their money into their matresses.  And as with investments, comments should be religiously updated and examined, in order to make sure that they still have value.

Return to table of contents

11:  Tutorial example 2: Including files with JSM.Bat and the H and U subfolders

Before running this example, you should create two subfolders on the folder that you're using for the tutorial.  One should be called H, and the other U.

In writing my system, I've assumed that your goal is to "build" complex HTML files, which will then be uploaded to a given site.

The U folder is for the resulting files, i.e. those that are to be uploaded.  The H folder will hold a very special kind of file, known as a "marker" file.  These files will be of length 0, which means that they won't take up any "space" on your hard disk.  (I'll say more about these files in a moment.)

To run example 2, simply type the following from the DOS prompt (don't forget to press the enter key afterwards):


fmake -f jsm_ex2.mak

Let's get down to business ... here's jsm_Ex2.mak:

1.  .PHONY:  all
2.
3.   all:h\\jsm_Ex2A.Htm  \
4.    h\\jsm_Ex2A.Htm  \
5.    h\\jsm_Ex2A.Htm
6.
7.  h\\jsm_Ex2A.Htm:jsm_Ex2A.txt  \
8.  h\\jsm_Ex2A.htm:jsm_Ex2.inc
9.  <tab> JSM.Bat  jsm_Ex2A  jsm_Ex2B
10.
11.  h\\jsm_Ex2B.Htm:jsm_Ex2B.txt  jsm_Ex2.inc
12.  <tab> JSM.Bat  jsm_Ex2B  jsm_Ex2B

Return to table of contents

12:  Tutorial example 2: the treble-ballyhoo about backslashes

Before I get into the finer details of this example, notice that there are backslashes at the end of lines 3, 4, and 7.

You can use backslashes to continue lines ... they're particularly valuable for at least two reasons.

First, you may wish to separate one list of files from another.  For example, suppose there are actually two or three separate subsystems that are being updated by the same "make file" (i.e. something that gets run through fmake, like jsm_Ex1.mak or jsm_Ex2.mak).

Let's see jsm_Ex2.mak again - this time, just the first part:

1.  .PHONY:  all
2.
3.   all:h\\jsm_Ex2A.Htm  \
4.    h\\jsm_Ex2A.Htm  \
5.    h\\jsm_Ex2B.Htm

Notice how line 3 ends in a backslash, and line 4 appears to be nothing other than a "separator" line.  If there were 15 files in one subsystem updated by this make file, and another 20 files in a second subsystem, the "separator" line would make things a lot easier to read.

Warning:
You can't have any spaces after the backslash.  If you do, the make program (fmake) won't recognize the backslash as being at the "end of the line."  Many text editors will automatically remove spaces at the end of the line when you save the file, but not all will.


But backslashes aren't just being ballyhooed for that reason: there's another justification for using them.

Take a look at line 7 of jsm_Ex2.mak:

1.  .PHONY:  all
2.
3.   all:h\\jsm_Ex2A.Htm  \
4.    h\\jsm_Ex2A.Htm  \
5.    h\\jsm_Ex2B.Htm
6.
7.  h\\jsm_Ex2A.Htm:jsm_Ex2A.txt  \
8.  h\\jsm_Ex2A.htm:jsm_Ex2.inc
9.  <tab> JSM.Bat  jsm_Ex2A  jsm_Ex2B

Line 7 says that the target ("h\\jsm_Ex2aA.htm") is depending on two files: jsm_Ex2A.txt, and jsm_Ex2.inc.

What if you had a target that depended on a whole lot of files, say 5, 6, or even a dozen?

The backslash can be used to list these files in a way that limits the length of each line.  Why is this important?

Because we're not working with typical "word processors" here.  Physical lines matter to GNU make.  This is why I've been so careful to recommend that you use editors that recognize "DOS text."  By using backslashes in this context, you can keep all your lines relatively short, so that the files can be edited without horizontal scrolling.


Good things come in threes, or so they say.  (Maybe things that are merely annoying come in twos.)

So the backslash appears again, yet, this time in a pair.  Twins, so-to-speak.

The golden rule of subfolders:

Within a "make file," every file on a subfolder must be referenced with double back slashes.

In simple terms: the double-backslashes simply say "this is a subfolder".  Normally, in Windows, one would use a single backslash to reference a subfolder.  But GNU Make ("fmake.exe") is special: because it's designed for Unix programmers, the backslash has to occur twice, in order to satisfy Windows.

We'll return to the Golden Rule Of Subfolders again, after we examine JSM_Bat more closely ... in order to lay bare the hidden truth about the H and U subfolders, for all the world to see!

Return to table of contents

13:  Tutorial example 2: the straight dope about JSM.Bat

The first thing to remember about example 2, is that we're creating files that end in ".html", instead of ".htm".  So the file called jsm_ex2a.html is the contest winner, and the file called jsm_ex2b.html is the birthday person.

(Since example #1 involved files that ended in ".htm", you may wonder why I'm being inconsistent: the answer has to do with how MS operating systems handle "long" file names.  It's probably best to ignore it.)


JSM.Bat is used in lines 9 and 12 of this example:

7.  h\\jsm_Ex2A.Htm:jsm_Ex2A.txt  \
8.  h\\jsm_Ex2A.htm:jsm_Ex2.inc
9.  <tab> JSM.Bat  jsm_Ex2A  jsm_Ex2A
10.
11.  h\\jsm_Ex2B.Htm:jsm_Ex2B.txt  jsm_Ex2.inc
12.  <tab> JSM.Bat  jsm_Ex2B  jsm_Ex2B

It's important to understand what lines 9 and 12 actually do:

  • The first file name listed after JSM.Bat is the input.

    It's presumed to be a text file (i.e., it ends in ".txt" - but you don't actually write the ".txt" portion) ... and it must exist on the current folder.  (The current folder is what the DOS or Cmd prompt shows you.)

  • The second file name listed after JSM.Bat is the output.

    It's an .html file name, which will be created on the U folder (remember "U" is a short hand for "upload").  "Long" file names are allowed here, but don't actually write the ".html" part.  You must also not include a folder name.

  • Why are the last portions of the file names (".txt" and ".inc") shown on lines 7-8 and 11, but not on lines 9 and 12?

    This is a critical question to ask.  The reason has a lot to do with the fundamental nature of "actions" and "targets/dependencies":

    The (golden) distinction between actions and targets/dependencies:

    Action lines follow the line(s) that specify targets and dependencies: each action line consists of a "call" to a program or DOS batch file.  The rules for each action line depend on the nature of the program or DOS batch file that you're calling.  So, if that program or DOS batch file assumes a certain ending portion of a file name (such as ".txt"), you shouldn't include it.  In contrast, targets and dependencies are processed by "fmake" itself.  The ending part of the file name is always required.

  • JSM.Bat expands the INC@filename@ specifications.

    Let's take a look at JSM_Ex2a.Txt:

    
    <P>And the winner is:<BR>
    INC@jsm_Ex2.inc@  *** Name/photo of the winner ***
    <P>Congratulations!!</P>
    

    If you compare this with JSM_Ex1a.Txt, you'll notice that we actually added the last line after the table that shows the winner's name and photo (this table is contained in the "include" file, jsm_Ex2.Inc).

    You can have as many include files as you like, the only restriction is that they must have DOS ("8 and 3") file names.  The INC@ prefix must begin in the leftmost column of the line, and the file name must be immediately followed by an @-sign.  You can type whatever you like after the second @-sign  (it's a really good idea to put a comment there!).  You can even put include files on a different folder, but the folder name must be a DOS ("8 and 3") name.

    You can even have include files that are inside other include files!  But be careful: the system will not automatically detect a "loop" (for example, if you include a file within itself.)

  • JSM.Bat also creates a "marker" file on the H subfolder.  The name of the marker file is the same as the name of the input file, plus a ".htm" on the end.

    A "marker" file is a special kind of file that has no data in it.  This is a very efficient way of setting a "flag," and/or specifying a time+date.  Why do this?

    Well, remember that the "fmake" program will only update the files that it believes it must update.  Remember the golden rule of make files?

    The golden rule of make files:

    If a target is "older" than any of the files on which it depends, then "make" the target by performing the "actions" required to build it.

    Now in this case, jsm_Ex2a.html is going to be created on the U subfolder.  It will be the complete birthday announcement file.  And presumably, you're going to upload it to another site.

    Suppose you have hundreds of such files ... but perhaps only a few will change at any one time.  For efficiency, you'll probably want to remove those files after you've uploaded them, right?  After all, if only three or four files have changed (out of a system with hundreds of files), why upload the whole system every time?  This is certainly the case if you have a telephone modem, or the server is slow.  (Or if you get charged for "bandwidth".)

    So the "marker" files tell the program fmake which files need to be updated.  This point deserves a bit more emphasis.

Return to table of contents

14:  Tutorial example 2: more on update times and efficiency

Let's try a little experiment.  Open up jsm_Ex2a.txt with your favorite editor (how about Windows Notepad?) and then save it.  You don't have to make any changes.

Now run example 2's make file again, e.g.:


fmake -f jsm_ex2.mak

Take a look at the file dates and times on the U subfolder.  Observe that only jsm_Ex2a.html got rebuilt.

Now look at the H subfolder.  The file update time for jsm_Ex2a.htm is the same as the update time for jsm_Ex2a.html ... but it's after the update time for jsm_Ex2b.htm.

So what's really going on here is that the "marker" file preserves a record of which HTML files were built, and when.  You can FTP the files on the U folder to your web site, and delete them afterwards.

This makes it particularly easy and efficient to maintain a web site with hundreds, or even thousands of HTML files that depend on one another.  You rebuild and upload only the HTML files what you need.  At the same time, the "marker" files don't take up any space on your computer.

What if some hacker attacks your web site, and you need to rebuild all the files?

Easy: just delete the "marker" files on the H subfolder, and everything will be rebuilt!  

All these benefits arise because the marker files are the "targets" for the golden rule of make files:

The golden rule of make files:

If a target is "older" than any of the files on which it depends, then "make" the target by performing the "actions" required to build it.

Return to table of contents

15:  Tutorial example 2: about action lines and running programs

If you're a longtime Windows (or Mac) user, example 2 may be rather confusing to you.  You're probably used to clicking on icons, and having them "do" something, in conjuction with a particular program.  If you're a windows user, you may know about about the View | Folder Options | File Types capbility ... this lets you associate a file "extension" (i.e. the last part of a file name, after the dot) with a particular program.

An "action line" in a make file does just one thing: it calls a program (or a "DOS batch file"), in order to accomplish an objective.

The first word (including an ".exe" or ".bat" part) of the action line is what determines the "actor".  (I.e. the name of program or DOS batch file). nbsp;The rest of the line is used to display the information needed to perform the action.

In line 9 of this example, JSM.Bat is the program (or, specifically -- the DOS batch file).  The additional information consists of: JSM_Ex2A repeated twice.

Return to table of contents

16:  Tutorial example 3: Getting up to speed by using remarks, copying (and moving files), as well as automatic folder creation.

The previous example isn't ready for commercial use, is it?

If you browsed to the 2 HTML files that were created in the last example (jsm_Ex2a.html and jsm_Ex2b.html on the U subfolder) ... you'd have discovered that they don't work properly, because the image file isn't there.

And if you've designed even a small web site, you'll be aware that files are normally kept on multiple folders.  It's not going to be very convenient if every "built" file is placed on the U subfolder, is it?

Clearly, there's a need to be able to create separate subfolders, and to pick and choose which files get moved to which folders.

You may also wish to determine the names of certain folders, and other "variable information" ... in a dynamic way (i.e. "on-the-spot").

And finally: for a realistic development cycle, you need to be able to "document" these files that create complex systems.

This next example handles these two cases.  As usual, you run it by typing:


fmake -f jsm_ex3.mak
from the DOS prompt, and pressing the enter key afterwards (of course, if you're running 2K, NT, or XP, you should use the "Cmd" prompt).

Return to table of contents

17:  Tutorial example 3: Digging deeper ... starting with remarks

Let's take a look at jsm_Ex3.Mak:

1. #   Here are two variable assignments:
2.  DEST=u\\special
3.  IMAGE=jsm_ex_d.jpg
4.
5.  .PHONY:  all  check
6.
7.   all:check  h\\jsm_Ex3A.Htm  h\\jsm_Ex3A.Htm  
8.
9.   check:  
10.  <tab> JSM_Chk
11.  <tab> FMkDir  -p  $(DEST)
12.  <tab> @FEcho  DEST is $(DEST), and IMAGE is $(IMAGE).
13.  <tab> @FEcho  If these are the last lines you see,
14.  <tab> @FEcho  then all files were up-to-date.
15.
16.  h\\jsm_Ex3A.Htm:jsm_Ex3A.txt  jsm_Ex3.inc
17.  <tab> JSM  jsm_Ex3A  jsm_Ex3A
18.  <tab> JSM_Copy  $(IMAGE)  $(DEST)\\$(IMAGE)
19.  <tab> JSM_Copy  u\\jsm_Ex3a.html  $(DEST)\\winner.html
20.  <tab> JSM_Del  u\\jsm_Ex3a.html
21.
22.  h\\jsm_Ex3B.Htm:jsm_Ex3B.txt  jsm_Ex3.inc
23.  <tab> JSM  jsm_Ex3B  jsm_Ex3B
24.  <tab> JSM_Copy  u\\jsm_Ex3b.html  $(DEST)\\birthday.html  Move

Notice line 1: it begins with a pound sign (i.e. the character #: sometimes called a "number sign").

The program fmake automatically ignores any line that begins with that special character.  So you can type whatever you want.  If you'd looked at the previous examples' files, this may already be evident.  Blank lines are also ignored.

Remarks and blank lines can't be defined as "action" lines, but must instead occur in "free space" (i.e. outside of action/target sequences).

Return to table of contents

18:  Tutorial example 3: Digging deeper ... what is an "executable"?

Notice that there are no ".bat" or ".exe" parts on the ends of any of the file names that occur in the "action lines."  This is because these parts of the file names are assumed.  In every case of an action line, the first part must be a ".bat" (DOS batch) or a ".exe" (windows program) file.  (Other ending portions may be allowed, depending on what version of Windows you're running).

Since this documentation only describes the use of very specific programs and DOS batch files, all you need to know is that: you needn't specify the ending part of the first file name listed on an "action" line.

Return to table of contents

19:  Tutorial example 3: Digging deeper ... "make variables" and how to move/copy/delete files

Lines 2 and 3 specify a variable.  You define a variable by typing the name, followed by an equals sign, and a value.

Variables can't be defined as "action" lines, but must instead occur in "free space" (i.e. outside of action/target sequences).

In line 2, we specify the destination folder for the two resulting html files.  This will be be special subfolder of the U subfolder.  Note the double-backslashes!

In line 3, we specify the name of the image file.  This is the photo of the contest winner (and "birthday person").

As you can see, variables are actually used ("referenced") by enclosing them in parentheses, and putting a dollar-sign in front of them.  Technically, a variable name can include a few special characters ... but you're best off limiting them to letters, digits, and underscores.

Specifically, we use these variables in order to specify which files are to be moved, copied, and deleted ... along with the help of a few handy utilities.

(For the curious: the reason why I need to call DOS batch files to do simple operations such as a move, copy, or delete is that Windows NT "hobbled" the DOS command processor: you can't manipulate "long" file names from command.com - instead, you have to use the Cmd prompt.  Unfortunately, GNU make automatically invokes the DOS command processor to perform its "actions."  So these extra DOS batch files ensure that everything will work properly on all Windows operating systems.)

Return to table of contents

20:  Tutorial example 3: Going professional ... using JSM_Chk and FMkDir

If you're going to give this system to another software professional, and/or a user, you're going to have some other capabilities.

First, you'll have to be sure that they have all the programs (etc.) needed to run this system.

The DOS batch file called JSM_Chk, does precisely that, and one other thing: it checks to make sure that their DOS "environment" can hold at least 900 bytes of variables and values.  (If you don't know what that is, don't worry about it: you set your DOS environment size earlier, when you did the first install step in section 2).

Before we go on, it's important to understand how JSM_Chk is actually used.

The critical lines are:

5.  .PHONY:  all  check
...
8.
9.   check:  
10.  <tab> JSM_Chk
11.  <tab> FMkDir  -p  $(DEST)

Notice that there's no dependency for the target of "check" (line 9).

This leads us to yet another principle:

The correllary of the golden rule of make files:

If a target doesn't depend on anything, then that target is always "made," and it's made before targets that depend on something.


In line 11, you see that FMkDir is called.  This is a special program that can create folders (also known as "directories").  The -p that preceeds the name of the folder tells FMkDir not to complain if the folder already exists.

In this case, the folder name is u\special.  Just as with the calls to JSM_Copy, the folder name is actually described by the variable $(DEST).  (Remember, when you use a make file variable, you must preceed it with a dollar sign, and then enclose it in parentheses.)


Note that if you were going to give this system to someone else, you'd probably want to include these two lines after JSM_Chk, and before the FMkDir:


FMkDir -p U
FMkDir -p H

These would absolutely ensure that the H and U subfolders are already in existence.  I asked you to create these folders by hand only because I wanted to describe examples 1 and 2 without introducing FMkDir.

Return to table of contents

21:  Tutorial example 3: using FEcho and @-signs

To complete our transition to a more "professional" approach, we'll need to have some way of communicating with the person who's running the system.

Let's see that check target again:

9.   check:  
10.  <tab> JSM_Chk
11.  <tab> FMkDir  -p  $(DEST)
12.  <tab> @FEcho  DEST is $(DEST), and IMAGE is $(IMAGE).
13.  <tab> @FEcho  If these are the last lines you see,
14.  <tab> @FEcho  then all files were up-to-date.

In line 12, we actually tell the user what the destination folder and image names are.  We do so by calling the program FEcho, which is essentially the same as DOS's built-in Echo command.

FEcho is a fairly simple beast: it simply "echos" whatever you put after it.

Lines 13 and 14 will be the last lines that the user sees, if all the files are up-to-date.  However, if something has changed, then the user will see that JSM, JSM_Copy, etc. are being run.

To see this for yourself, try editing jsm_Ex3a.txt.  Open it up with (say) windows Notepad, and save it again.

As you can see, what's printed by lines 13 and 14 is followed by other stuff.  Indeed, these are the actions specified in lines 16 through 20, i.e. the lines that rebuild the winner.html file.


A word of warning about FEcho: it behaves rather oddly if you use certain special characters, such as the asterisk, the backslash, the less-than or greater-than signs, and the bar ("pipe").  I recommend that you avoid all characters that aren't used in normal punctuation.  Also, if you need to use a double-quote, put a backslash immediately in front of it, e.g.:


FEcho \"this is a quote\"


Notice that the invocations of FEcho in lines 13 and 14 are preceeded by an @-sign.  In simple terms, the @-sign prevents the command from appearing on your screen.

(In not-so-simple terms: the program fmake calls an instance of the DOS command processor to execute every action.  The @-sign tells DOS not to print the command on the screen, just as it would in a DOS batch file.)

Why would you want to prevent an action from being printed on the screen?  The answer depends on what you want the person running the make file to see.  Since the purpose of the FEcho commands are to tell the user something: we want to print what FEcho echos, not the entire command itself.

In general, I don't use an @-sign on any action that could possibly fail.  This is because I want the user to see precisely which action actually failed, so that they can diagnose the problem as quickly as possible.  However, if you prefer to conceal the complexity of the processing from the user, then you should put an @-sign before each action.  Don't forget that the first character of any action line must still be a hard tab.

Return to table of contents

22:  Tutorial example 4: introducing NoComJ, and bringing JavaScript into the picture

(This first section describes the rationale behind NoComJ, the JavaScript code compressor.  You can skip it, if you wish.)

In this final example, I'm going to assume that you're capable of writing a few lines of JavaScript: i.e., that you're a programmer, or at least someone who's comfortable with computer code.

In this example, I'm going to introduce NoComJ.Exe: which is my "JavaScript code compressor"  (the source C code is available as NoComJ.C).

"NoCom" is a shorthand for "no comments," and of course the "J" part stands for "JavaScript."

Based on those naming conventions, one might assume that NoComJ simply strips out remarks in JavaScript.  That's true, but it also does several other things:
(1) it removes unncessary punctuation, including spaces;
(2) it combines lines up to a certain maximum length (the default is 240);
(3) allows you to use very simple macros; and
(4) it detects certain common errors related to quoted strings (such as not including a matching quotation mark on the end of a string) and comments (such as illegally "nesting" "/* ... */" remark sequences).

So-o, why did I write this program?

Most good programmers will write prolific remarks.  This is because most of them (and many of the rest of us) have had the experience of coming back to our work several years later, and realized that we had no idea what a particular line or routine does, or why it's there.  This is not to mention any bad experiences that we've had in attempting to read someone else's code.

If JavaScript is to be executed on the client side (i.e. run from the user's browser), then it won't use the server's computational resources, except to deliver the code (as plain text) to the user's browser.  And therein lies the rub: to keep the size of code as small as possible, one might ideally write client-side JavaScript in a way that's difficult to read and debug: i.e. by using a minimum of remarks, no excess spaces or punctuation, and the shortest possible names for variables and functions.

However, I make sure to write comments that declare the purpose of the short variable and parameter names.  Since these comments are stripped by NoComJ, I can be as verbose as I like - and save time for the readers of my code, without being limited by the fact that the server will send these remarks to the client browser (and thus: waste resources).

The "code compressor" isn't going to shorten the length of your variable and function names.  But at least, it will let you use short variable names and include plenty of remarks so that the reader of the code knows what they're for.  (My strategy is to use short parameter names and local variable names, but to make global variable and function names longer.)

Also, the compressor allows you to use excess punctionation (such as unncessary curly braces) and plenty of spaces in order to clarify the structure of your code.

So the point here is that you can now write client-side JavaScript almost as if you were coding in a compiled language: i.e. with little or no concern for the source code's physical size ... at the same time, the use of "includes" allows you to insert the compressed JS into HTML files in all the correct places, and to re-use the same block of code on multiple HTML pages.  Finally, the "make" discpline ensures that you can make incremental changes without having to rebuild or upload unncessary files.

Return to table of contents

23:  Tutorial example 4: introducing batch files (jsm_Ex4.Bat)

Tutorial example 4 is the only example that gets run from a DOS batch file.  It's not essential that you know how to write these files, but they can be very helpful.  I have a primer on DOS batch files at: http://www.rs-freeware.org/adb/adbdos.htm.

However, this example is enough for you to be able to write a few simple ones that will benefit your systems:

1. Set IMAGE=jsm_ex_N.jpg
2. Set NAME=Nancy
3. @If Exist jsm_Ex4.Ma1 Del jsm_Ex4.Ma1
4. @Copy jsm_Ex4.Ma0 jsm_Ex4.Ma1 > NUL
5. @Echo $IMAGE_NAME$ %IMAGE% /* Photo */ >> jsm_Ex4.Ma1
6. @Echo $PERSON_NAME$ %NAME% /* Name */ >> jsm_Ex4.Ma1
7. fmake -f jsm_Ex4.mak
8. @Set IMAGE=
9. @Set NAME=
10. @FEcho jsm_Ex4.Bat is finished!

Most lines in this file aren't shown: these are the ones that begin with @Rem.  These are (obviously) remarks.  You should avoid the pipe ("|") as well as greater-than or less-than signs in your remarks.

The @-sign plays a similiar role in a DOS batch file: it prevents the line from being "echoed" to the user.  It goes without saying (but I'll say it anyway): all lines in a DOS batch file are "action" lines.


Lines 1 and 2 set the variables IMAGE and NAME.  Of course, these are the photo file name and the name of the birthday person/contest winner (respectively).

Line 3 deletes the file jsm_Ex4.Ma1, if it exists.  This file is going to become the "macro" file name that will be used by the JavaScript compressor.  (I'll say more about this shortly).


Line 4 simply rebuilds jsm_Ex4.Ma1 from jsm_Ex0.Ma1.

jsm_Ex0.Ma1 consists entirely of remarks, and is there to help explain how macros to NoComJ actually work.  You might want to take a look at it now.

Lines 5 and 6 actually construct the macros themselves. The result of these first 6 lines is that the macros file contains these two lines:


$IMAGE_NAME$ jsm_ex_N.jpg /* Photo */
$PERSON_NAME$ Nancy /* Name */

That's really all there is to a macro for NoComJ: you have a macro name, followed by one or more spaces, followed by a value.  The value goes until the end of the line, or until a /* ... */ (comment) sequence is encountered.  Note that "//" comments aren't supported ("line" comments are allowable, but only if a semicolon is used as the first character in the line ... and therefore, these sorts of remarks can't be used in a line in which a macro is being defined.)

Now take a look at jsm_Ex4.js.  As you can see, it's got a lot comments in it, but all it really does is to print out the table with the photo and name.  The code is also convoluted: I wrote it that way in order to illustrate the manner in which NoComJ compresses code.


Line 7 of the batch file should be rather familiar by now: it calls the program fmake to build the files.

Lines 8 and 9 are purely administrative: they reset the DOS variables to nothing, which is a way of getting rid of them.  You can find out more about DOS variables by reading my DOS primer.

Return to table of contents

24:  Tutorial example 4: batch file variables become make variables

Please open up jsm_Ex4.mak with Windows Notepad (or your favorite editor).

Notice that the variable IMAGE is never declared in that file!

This leads us to:the Golden Rule of DOS batch variables and make file variables:

The Golden Rule of DOS batch variables and make file variables:

If a variable has been defined in the "DOS environment," i.e. by a DOS batch file, then this variable can be used inside a "make file," as if it were already defined.

I can't overstate the benefits here: the DOS batch file actually controls the processing!  I.e., to update the web site, all you need to do is to change the DOS batch file.  This will alter the person's name and their photo JPEG in both HTML files!

Return to table of contents

25:  Tutorial example 4: using compressed JavaScript and the role of the H subfolder

jsm_Ex4a.Txt consists of just these few lines:


<P>And the winner is:<BR>
<script language='JavaScript'>
<// !--
INC@jsm_Ex4.tmp@  *** JS to write the Name/photo of the winner ***
// -->
</script>
<P>Congratulations!!</P>

All we really have is an announcement line (the first one), a JavaScript code section, and a closing line.

Remember example 3?  We included the file jsm_Ex3.inc there, and the contest winner name/photo name were "hard coded" in that example.

So every time a new contest winner/birthday person was announced, you had to update that file.  Furthermore, you had to update the "make" file (jsm_Ex3.mak), in order to make sure that the image file was copied to the proper folder - so it could be uploaded.

In this case, we're doing the whole thing with JavaScript and DOS batch files.

That would be interesting enough, but there's quite a bit more.


Go ahead and run the batch file.  Simply go to the DOS prompt (use the "Cmd" prompt if you're on NT, 2K, or XP), and type jsm_Ex4  (Don't forget to press enter afterwards.)

Here's what you should see:


Set IMAGE=jsm_ex_N.jpg
Set NAME=Nancy
fmake -f jsm_Ex4.mak
JSM_Chk is done ... everything's okay, if you see no error messages!
DEST is u\special, IMAGE IS jsm_ex_N.jpg, and NAME is Nancy
If these are the last lines you see, (aside from
the termination announcement), then all files were
up-to-date).
jsm_Ex4.Mak is finished!!
jsm_Ex4.Bat is finished!

Note that the first three lines come from the batch file, as does the last one.  The fourth line comes from JSM_Chk.Bat, and it lets you know that all the prerequisites are satisfied for the JSM system.

You'll find the remaining lines in sections C and B of the make file (jsm_Ex4.mak).


Now, take a look at the file h\jsm_ex4.tmp.  Compare it with jsm_Ex4.js.

What you should notice is that the JavaScript has been "compressed": remarks have been removed, and macro replacements (as specified in JSM_Ex4.Ma1) have been done.  The lines are very long: this is due to the fact that the default line length for NoComJ is 240.


What's this file doing on the H subfolder?  One would think that this folder is for the "marker" files that I described earlier.

Well, that's right: but like many things in the JSM system, the H subfolder serves a dual purpose: it also holds the compressed JavaScript files that are part of your systems.

The goal here is to use the "Golden Rule of Make Files" in a way that lets you minimize the execution time of a cycle: JavaScript files are "compressed," only if they've changed since the last time a system was "made" (i.e. built with a make file).

In fact, if JSM_Bat doesn't find included files on the current folder, it will include files from the H subfolder  (the current folder is what the DOS prompt shows).


This leaves us with two questions.

Why put compressed JavaScript files on the H subfolder?

The answer's easy: we don't want them cluttering up the files on our main folder.  We don't want to be editing the compressed JavaScript files ... we don't even want to know that they exist!

But there's a deeper question: how did jsm_Ex4.js get compressed into jsm_Ex4.tmp on the h subfolder?

Return to table of contents

26:  Tutorial example 4: using NoComJ in a make file (section D of jsm_Ex4.mak)

Here's section D in jsm_Ex4.Mak  (the lines are numbered from the start of that section):

1.  h\\jsm_Ex4.tmp:jsm_Ex4.js  jsm_Ex4.bat
2.  <tab> JSM_Copy  $(IMAGE)  $(DEST)\\$(IMAGE)
3.  <tab> NoComJ  -ijsm_Ex4.js  -oh\\jsm_Ex4.tmp  -nb  -snb  -lc  -mjsm_Ex4.ma1

First: notice that the compressed JavaScript file on the h subfolder, jsm_Ex4.tmp, depends on jsm_Ex4.js  (as we expect),  but also on the DOS batch file (jsm_Ex4.Bat).

What this means is that if the DOS batch file is modified, then the compressed JavaScript file must be regenerated!  That makes sense, given that the DOS batch file will build the NoComJ macro file, which in turn will determine what's inside the compressed JavaScript file.

Line 2 copies the image file to the appropriate subfolder.  This copy operation might not be required in all cases, but it's a fairly good bet that it's needed, most of the time.

Line 3 shows an actual call to NoComJ, the JavaScript code compressor.

The -i part is followed immediately by the name of the input JavaScript file: in this case, that's jsm_Ex4.js.

The -o part is followed by the name of the output (compressed) JavaScript file: in this case, that's jsm_Ex4.tmp.  It's important to note that we used double-backslashes to put the output on the H subfolder!

Finally, at the end, the -m part is followed by the name of the macro file.  If you have no macro file, you can simply remove this portion.

For more detailed information about the operands to NoComJ, simply type "NoComJ" from the DOS prompt.

Return to table of contents

27:  Tutorial example 4: section C of jsm_Ex4.mak

Here's section C in jsm_Ex4.Mak  (the lines are numbered from the start of that section):

1.   check:
2.  <tab> @JSM_Chk
3.  <tab> @FEcho  DEST  is  $(DEST),  IMAGE  IS  $(IMAGE),  and  NAME  is  $(NAME)
4.  <tab> @FMkDir  -p  H
5.  <tab> @FMkDir  -p  U
6.  <tab> @FMkDir  -p  $(DEST)
7.  <tab> @FileStat  -Q  %IMAGE  <  NUL
8.  <tab> @FEcho  If  these  are  the  last  lines  you  see,  (aside  from
9.  <tab> @FEcho  the  termination  announcement),  then  all  files  were
10.  <tab> @FEcho  up-to-date).

Before we go on, I want to emphasize that check is a target with no dependencies:

The correllary of the golden rule of make files:

If a target doesn't depend on anything, then that target is always "made," and it's made before targets that depend on something. it.


First, line 2 calls JSM_Chk, to make sure that the required conditions are present, in order to run the system.

The next "@FEcho"  (line 3)  actually informs the user about the status of the variables: note that IMAGE and NAME were set by the DOS batch file  (jsm_Ex4.Bat)  whereas DEST was set in the make file  (jsm_Ex4.Mak).

Lines 4 through 6 make sure that all the relevant subfolders are created.  Note that if you provide this system to a user, they need not actually create these subfolders before running the system.

Lines 8-10 provide the announcement; this may be important, if you're running the program fmake from a DOS batch file.  They'll inform the user about the beginning and end of the "make file" processing.


So far, I haven't said anything about line 7.  This line calls my program FileStat.

FileStat lets you do a lot of stuff: you might want to simply type "FileStat" from the DOS prompt, in order to get more information.  You may also wish to view my DOS primer.

In this case, FileStat will check for the existence of the DOS variable IMAGE, to ensure that it's always defined, when the make file is executed.

To see what happens when the variable isn't defined, type the following, from the DOS (or Cmd) prompt:


fmake -f jsm_Ex4.mak

You'll see the following:


File `IMAGE': ERROR - DOS environmental var. not defined! [DOS environmental
variable, must be assigned, arg. #2 on command line]
fmake.exe: *** [check] Error 1

This indicates that the variable IMAGE wasn't defined, and stops a user from executing the "make file" directly  (i.e., without running the DOS batch file).

Return to table of contents

28:  Tutorial example 4: sections A, B, and E of jsm_Ex4.mak

Section A defines the variable INCL.  You could use this variable as a list of all your important included compressed JavaScript files.  Simply list their compressed file names, one after another, separated by a space.  Then add $(INCL) to each relevant dependency list.  (Just as I've done, in sections D and E of the make file for this example.


Section B has an FEcho command as its only action line.  This informs the user that the make file has completed execution ... this nessage can often be helpful for debugging.


Section E demonstrates how to produce an output file name with a space  (or other special characters)  in it.

If you want the best possible level of "browser compatibility," I recommend that you avoid such file names.

Return to table of contents

29:  Sharing files: conditional inclusion and variable H-subfolder "marker" files

You may never need to read this section, because you won't ever have to use the same file in two different systems.

But if you do, you should know that FI.Exe can handle "variable" inclusions, and "variable" lines:

If FI.Exe sees a line then begins with a percent-sign (it must be in the first column), it will then check to see whether there's an equals sign, followed by a single character, and a percent sign.

For example, it will look for something like this:


%VARNAME=X%This is the rest of the line

If it finds that a line begins with a percent sign, and the remainder of the line contains at least one character following the initial percent sign, followed by an equals sign, one more character, and a second percent sign ... then it will then check to see whether VARNAME is a defined (DOS) variable, with the value of "X" (only single-character values will be recognized).

If VARNAME doesn't exist, or it isn't equal to "X", then the rest of the line will be ignored.  Otherwise, the rest of the line (after the second percent sign) will be included.  Both VARNAME and the value will be converted to upper case, prior to any comparison.

This method is a primitive substitute for "conditional inclusion."


This feature has been incorporated into JSM.Bat: if JSM.Bat is called with a third operand, it will assume that this is the name of a DOS variable, which should be set to 1.

For example, if I want a file to be used in two different systems, I'll use this sort of make file syntax:

1.  h\\SYS2_f.Htm:SYS1_f.txt
2.  <tab> JSM  SYS1_f  SYS1_f  SYS2  SYS2_f

The third operand to JSM.Bat tells it to set the variable SYS2 to a value of 1.  The fourth operand tells it to create the "marker" file Sys2_F.htm on the H subfolder (note that this is the "target" for the make action.

Within the source file, SYS1_f.txt, I could have lines like this:


%SYS1=1%This line appears IFF the DOS variable SYS1 is 1
%SYS2=1%This line appears IFF the DOS variable SYS2 is 1

Either or both of these lines could specify file inclusions; so in effect I get two versions of the resulting file: one will be "instantiated" if the DOS variable SYS1 is 1, and the other if the DOS variable SYS2 is 1.

The third and fourth operands to JSM.Bat are optional.

Return to table of contents

30:  Idiosyncracies of the JavaScript code compressor (NoComJ)

The JavaScript code compressor (NoComJ) isn't perfect.  It has quite a few known "idiosyncracies".  Please contact me if you find that this list is inaccurate, or misleading.