home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / A86LKMEM.ZIP / A86LKMEM.PRG
Encoding:
Text File  |  1987-03-18  |  4.2 KB  |  120 lines

  1. *
  2. * CLIPPER AUTUMN 86 LOCK .MEM FILE WORK AROUND FUNCTION
  3. *
  4. * Released into the public domain 03/18/87
  5. *
  6. * Author: Henry J. Franzoni III
  7. *
  8. * Trademark Notice: Clipper is a trademark of Nantucket, Inc.
  9. *
  10. * This function is a work around for the lack
  11. * of a way to lock .MEM files in Autumn 86 Clipper.
  12. * I use .MEM files to store system wide options such as
  13. * printer codes, default directories, sequentially numbered orders, etc.
  14. * If two users access the same .MEM file at the same time
  15. * the network will return an error.  I asked Nantucket how to do this
  16. * and they suggested that I create a dummy database with one record,
  17. * and use it exclusively before I access a .MEM file.
  18. *
  19. * So I did.  The following function assumes that there exists
  20. * a .DBF file with the same name root as a related .MEM file.
  21. * For Example:  USERCONF.DBF and USERCONF.MEM have the same name
  22. * root.  The .DBF file has one field and one record.  The name
  23. * of the field or its datatype does not matter. It can be anything
  24. * you wish.
  25. *
  26. * The other assumption made is that there is at least one
  27. * user area free for the use of this routine.
  28. * This function uses the SELE 0 option in clipper to find the first
  29. * unused user area.
  30. *
  31. * Five parameters are passed to the routine, which is called like this:
  32. *
  33. *             MEM_LOCK("memfile",.T.,5,"*.*","A")
  34. *
  35. * The first parameter is the name of the .MEM/.DBF file pair.
  36. *
  37. * The second parameter is .T. if you are SAVING TO, and .F. if you
  38. * are RESTORING FROM.
  39. *
  40. * The third parameter is the length of time you wish to try to
  41. * lock the .MEM file, a 0 will try forever, and any other number
  42. * will try to lock the .MEM for that many seconds.
  43. *
  44. * The fourth parameter is a dummy parameter when you are
  45. * RESTORING FROM, and is used only when SAVING TO.
  46. * It is the memory variable spec for the ALL LIKE clause of
  47. * the save to command. Entering "*" will save all of the memory
  48. * variables.  Entering "U*" will save all of the memory variables
  49. * that start with the letter U.  When the second parameter is
  50. * .F. enter " " for this parameter.  The RESTORE FROM clause
  51. * doesn't accept a memory variable spec.
  52. *
  53. * The fifth parameter is the user area that you started from
  54. * so that when the routine is done, it can find its way back
  55. * to the user area you were in.
  56. *
  57. * Example:
  58. *
  59. *        IF MEM_LOCK("USERCONF",.T.,5,"PR*","A")
  60. *        ELSE
  61. *        ? "Unable to lock mem file"
  62. *        ENDI
  63. *
  64. * This will try to lock USERCONF.DBF(.MEM) for five seconds
  65. * and if it is successful, it will SAVE TO USERCONF ALL LIKE PR*.
  66. * At the end of the function, it will return to user area A.
  67. *
  68. *        MEM_LOCK("USERCONF",.F.,0," ","A")
  69. *
  70. * This will attempt to lock USERCONF.DBF forever and upon success,
  71. * it will RESTORE FROM USERCONF ADDITIVE and return to user area A.
  72. *
  73. * And now the usual stuff.
  74. *
  75. * Henry J. Franzoni III distributes this function solely on an "as is"
  76. * basis and offers no warranties at all for anything having to do with it.
  77. * Henry J. Franzoni III makes no warranties, either expressed or
  78. * implied regarding this software product, it't merchantibility, and/or
  79. * fitness for any particular purpose.  The user agrees that
  80. * Henry J. Franzoni III shall not be held liable for any consequential
  81. * damages, including but not limited to interruption of services,
  82. * and loss of business or anticipitory profits.
  83. *
  84. * By using this function, you acknowledge your agreement with the
  85. * above conditions.
  86. *
  87. * Any comments positive or negative, as well as any improvements
  88. * can be addressed to me, HENRY FRANZONI on the BOSS BBS in the
  89. * Clipper conference moderated by Dirk Lesko. (201)568-7293
  90. *
  91. * You may incorporate this function into software applications
  92. * that you develop, and you may distribute copies to anyone you wish
  93. * as long as no fee is charged, and this notice is left intact.
  94. *
  95. FUNCTION MEM_LOCK
  96. PARA MEMFILE,SAVE_REST,WAIT,MEMSPEC,SELECTED
  97. PRIV FOREVER
  98. FOREVER = (WAIT = 0)
  99. SELE 0
  100. DO WHIL (FOREVER .OR. WAIT > 0)
  101. USE &MEMFILE EXCLUSIVE
  102. IF .NOT. NETERR()
  103. IF SAVE_REST
  104. SAVE TO &MEMFILE ALL LIKE &MEMSPEC
  105. ELSE
  106. REST FROM &MEMFILE ADDITIVE
  107. ENDI
  108. USE
  109. SELE &SELECTED
  110. RETURN(.T.)
  111. ELSE
  112. ENDI
  113. INKEY(.9)
  114. WAIT = WAIT - 1
  115. ENDDO
  116. USE
  117. SELE &SELECTED
  118. RETURN (.F.)
  119. * End - MEM_LOCK
  120.