home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_getpa.prg < prev    next >
Text File  |  1993-10-14  |  2KB  |  97 lines

  1. /*
  2.     File......: GT_GetPath.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 05/02/93
  8.     Revision..: 1.0
  9.  
  10.     This is an original work by Martin Bryant and is placed
  11.     in the public domain.
  12.  
  13.     Modification history:
  14.     ---------------------
  15.  
  16.     Rev 1.0 05/02/93
  17.     PD Revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_GETPATH()
  23.  *  $CATEGORY$
  24.  *      General
  25.  *  $ONELINER$
  26.  *      Check a path to see that it is of a legal format
  27.  *  $SYNTAX$
  28.  *      GT_GetPath(<oGet>)
  29.  *  $ARGUMENTS$
  30.  *      <oGet> is the Get object passed in the :Postblock.
  31.  *  $RETURNS$
  32.  *      lValid
  33.  *  $DESCRIPTION$
  34.  *      Function to act as a validation clause on a get. It
  35.  *      checks the path specification to see that it is of a
  36.  *      legal format.
  37.  *  $EXAMPLES$
  38.  *  $SEEALSO$
  39.  *
  40.  *  $INCLUDE$
  41.  *
  42.  *  $END$
  43.  */
  44.  
  45. #include "GT_LIB.ch"
  46.  
  47. FUNCTION GT_GetPath(oGet,cPath)
  48.  
  49. LOCAL cCharacter := ''
  50. LOCAL cLegalString := ;
  51.     'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_\:'
  52.  
  53. LOCAL lSuccess := .T.
  54. LOCAL nLength := 0
  55. LOCAL nCount := 0
  56.  
  57. Default oGet to NIL
  58. Default cPath to ''
  59.  
  60. //  Get Path if from a get
  61. IF oGet != NIL
  62.     cPath := EVAL(oGet:block,NIL)
  63. ENDIF
  64.  
  65. nLength :=  LEN(cPath)
  66. lSuccess := (AT(':',cPath) = RAT(':',cPath)) .AND. .NOT. ;
  67.     ('\\' $ cPath)
  68.  
  69. IF lSuccess
  70.     FOR nCount := 1 TO nLength
  71.         cCharacter := SUBSTR(cPath,nCount,1)
  72.         IF .NOT. (cCharacter $ cLegalString)
  73.             lSuccess := .F.
  74.             EXIT
  75.         ENDIF
  76.     NEXT
  77. ENDIF
  78.  
  79. IF lSuccess
  80.  
  81.     IF (SUBSTR(cPath,nLength,1) != '\') .AND. (oGet != NIL)
  82.         EVAL(oGet:Block,cPath + '\')
  83.     ENDIF
  84.  
  85. ELSE
  86.  
  87.     GT_Error('Invalid Path. Must be of the form  C:\  or  ' + ;
  88.         'D:\DOS\  or  A:\DIR\TEST\')
  89.  
  90. ENDIF
  91.  
  92. /*
  93.     End of GT_GetPath()
  94. */
  95. RETURN(lSuccess)
  96.  
  97.