Copyright 1988-2016 by Kevin G. Barkes All rights reserved. This article may be duplicated or redistributed provided no alterations of any kind are made to this file. This edition of DCL Dialogue is sponsored by Networking Dynamics, developers and marketers of productivity software for OpenVMS systems. Contact our website www.networkingdynamics.com to download free demos of our software and see how you will save time, money and raise productivity! Be sure to mention DCL Dialogue! DCL DIALOGUE Originally Published March, 1988 By Kevin G. Barkes Cookies for the Masses As an independent consultant, you never know what type of challenges await you. Clients want the darndest things. One of them asked for a DCL-based fortune cookie program. He was tiring of the messages in his current public-domain COOKIE, but as a MicroVAX user in an office environment, he had no "languages" available to him except DCL. Charging a client to produce something this "frivolous" was a bit distressing to me, so I produced it on my own time, made it public domain, and stuck it out on my BBS system where it can be freely copied and distributed. It's on ARIS now, too, so feel free to download it and have fun. The Concept: A fortune cookie program produces a random qutotation when invoked. This posed two interesting problems for the DCL version; how to store the quotations, and how to access them in a random manner. I dismissed the use of indexed files because of their susceptibility to damage; I had visions of getting all sorts of calls when unwitting users edited the indexed quote file with a text editor and totally whacked the file structure. Of course, the same thing is possible if the library file is edited, but a user is more likely to recognize a VMS file in text library format to be something other than a normal file. I settled on using a text library, with module names being simply numbers; 1, 2, 3, etc. The module would be called by the randomly-generated number. Using lexical functions, I generated the library module number by extracting the "ones" and hundredths seconds fields of the current time. This approach permits modules numbered from 0 to 999, or 1,000 possible quotes. BAKE.COM: Cookies have to be prepared before being consumed, and the DCL variety is no different. BAKE.COM reads in a plain text file containing the quotes and produces a text library. To run BAKE.COM, you need to do three things: assign the name COOKIE_JAR to the file which will contain the library; assign the name OLDCOOKIES to the file where old COOKIE_JARs will be copied; and be certain the quote file, COOKIE.IN, exists in the directory where BAKE.COM is invoked. Make certain to give full file specifications (device, directory, name and extension) to the files. COOKIE.IN, the quote file, requires no special formatting. Just be certain that blanks lines separate each quote. When invoked, BAKE.COM sets up its environmental conditions and checks for the existence of needed files. The present cookie library is copied to another file for safekeeping, and is then deleted. BAKE reads COOKIE.IN, generates temporary files one at a time, assigns them numerical module numbers, and adds them to the text library file. This is not a particularly efficient procedure, but its infrequent use did not warrant spending an enormous amount of time on optimization. Besides, the price is right (grin). COOKIE.COM: COOKIE extracts a quote from the library and displays it on the user's terminal. If it can't find the "cookie jar", it exits immediately. Otherwise, it generates its "random" number, and tries to pull a quote from the library. This method has one major drawback... what if the cookie jar has less than 1,000 quotes or, somehow, a gap exists in the module numbers? COOKIE circumvents this problem by checking the status of the LIBRARY/EXTRACT command. If it fails, it divides the COOKIE number by two and trying again; it will continue to do this for five iterations, then give up. For example, assume the random number generated is 840. You don't have 840 quotes in your library; the extract fails. COOKIE divides 840 by 2, producing 420, 210, 105, 52 and 26 before giving up. You can make COOKIE run faster by dividing by a larger number (3 or 4 are probably more efficient). You can also increase the size of your library by duplicating entries if you're short on pithy sayings. ****** The months ahead will feature some nifty user-submitted procedures. If you'd like to join in the fun, feel free to send your submissions to me at the address above or to the DEC Pro's main office. We prefer submissions on magtape, since we don't have the time to rekey all the material we get. And please... no more default-changing command files. I received a letter from a reader who boasted the ultimate utility, requiring only a single parameter in order to operate. The command file: $ SET DEFAULT 'P1' $ EXIT Easy to debug, and it works! ---------- Kevin G. Barkes is an independent consultant. He publishes the KGB Report newsletter, operates the www.kgbreport.com website, lurks on comp.os.vms, and can be reached at kgbarkes@gmail.com.