home *** CD-ROM | disk | FTP | other *** search
- *
- * CLIPPER AUTUMN 86 LOCK .MEM FILE WORK AROUND FUNCTION
- *
- * Released into the public domain 03/18/87
- *
- * Author: Henry J. Franzoni III
- *
- * Trademark Notice: Clipper is a trademark of Nantucket, Inc.
- *
- * This function is a work around for the lack
- * of a way to lock .MEM files in Autumn 86 Clipper.
- * I use .MEM files to store system wide options such as
- * printer codes, default directories, sequentially numbered orders, etc.
- * If two users access the same .MEM file at the same time
- * the network will return an error. I asked Nantucket how to do this
- * and they suggested that I create a dummy database with one record,
- * and use it exclusively before I access a .MEM file.
- *
- * So I did. The following function assumes that there exists
- * a .DBF file with the same name root as a related .MEM file.
- * For Example: USERCONF.DBF and USERCONF.MEM have the same name
- * root. The .DBF file has one field and one record. The name
- * of the field or its datatype does not matter. It can be anything
- * you wish.
- *
- * The other assumption made is that there is at least one
- * user area free for the use of this routine.
- * This function uses the SELE 0 option in clipper to find the first
- * unused user area.
- *
- * Five parameters are passed to the routine, which is called like this:
- *
- * MEM_LOCK("memfile",.T.,5,"*.*","A")
- *
- * The first parameter is the name of the .MEM/.DBF file pair.
- *
- * The second parameter is .T. if you are SAVING TO, and .F. if you
- * are RESTORING FROM.
- *
- * The third parameter is the length of time you wish to try to
- * lock the .MEM file, a 0 will try forever, and any other number
- * will try to lock the .MEM for that many seconds.
- *
- * The fourth parameter is a dummy parameter when you are
- * RESTORING FROM, and is used only when SAVING TO.
- * It is the memory variable spec for the ALL LIKE clause of
- * the save to command. Entering "*" will save all of the memory
- * variables. Entering "U*" will save all of the memory variables
- * that start with the letter U. When the second parameter is
- * .F. enter " " for this parameter. The RESTORE FROM clause
- * doesn't accept a memory variable spec.
- *
- * The fifth parameter is the user area that you started from
- * so that when the routine is done, it can find its way back
- * to the user area you were in.
- *
- * Example:
- *
- * IF MEM_LOCK("USERCONF",.T.,5,"PR*","A")
- * ELSE
- * ? "Unable to lock mem file"
- * ENDI
- *
- * This will try to lock USERCONF.DBF(.MEM) for five seconds
- * and if it is successful, it will SAVE TO USERCONF ALL LIKE PR*.
- * At the end of the function, it will return to user area A.
- *
- * MEM_LOCK("USERCONF",.F.,0," ","A")
- *
- * This will attempt to lock USERCONF.DBF forever and upon success,
- * it will RESTORE FROM USERCONF ADDITIVE and return to user area A.
- *
- * And now the usual stuff.
- *
- * Henry J. Franzoni III distributes this function solely on an "as is"
- * basis and offers no warranties at all for anything having to do with it.
- * Henry J. Franzoni III makes no warranties, either expressed or
- * implied regarding this software product, it't merchantibility, and/or
- * fitness for any particular purpose. The user agrees that
- * Henry J. Franzoni III shall not be held liable for any consequential
- * damages, including but not limited to interruption of services,
- * and loss of business or anticipitory profits.
- *
- * By using this function, you acknowledge your agreement with the
- * above conditions.
- *
- * Any comments positive or negative, as well as any improvements
- * can be addressed to me, HENRY FRANZONI on the BOSS BBS in the
- * Clipper conference moderated by Dirk Lesko. (201)568-7293
- *
- * You may incorporate this function into software applications
- * that you develop, and you may distribute copies to anyone you wish
- * as long as no fee is charged, and this notice is left intact.
- *
- FUNCTION MEM_LOCK
- PARA MEMFILE,SAVE_REST,WAIT,MEMSPEC,SELECTED
- PRIV FOREVER
- FOREVER = (WAIT = 0)
- SELE 0
- DO WHIL (FOREVER .OR. WAIT > 0)
- USE &MEMFILE EXCLUSIVE
- IF .NOT. NETERR()
- IF SAVE_REST
- SAVE TO &MEMFILE ALL LIKE &MEMSPEC
- ELSE
- REST FROM &MEMFILE ADDITIVE
- ENDI
- USE
- SELE &SELECTED
- RETURN(.T.)
- ELSE
- ENDI
- INKEY(.9)
- WAIT = WAIT - 1
- ENDDO
- USE
- SELE &SELECTED
- RETURN (.F.)
- * End - MEM_LOCK