home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l408 / 2.img / EXAMPLES.EXE / EXAMPLES / INCLUTIL / INCLUTIL.SUB < prev    next >
Encoding:
Text File  |  1992-10-12  |  7.8 KB  |  259 lines

  1. DefInt A-Z
  2.  
  3. Sub BadDriveMessage ()
  4.  
  5.     MsgBox "Invalid Drive or Drive Not Ready", 16
  6.  
  7. End Sub
  8.  
  9. Sub BadPathMessage ()
  10.  
  11.     MsgBox "Invalid path specified", 16
  12.  
  13. End Sub
  14.  
  15. Function IncludeExist% (Temp$)
  16.  
  17.     ' Function returns True if a file exists, else MhFalse
  18.     ' First we check the current directory. If not found,
  19.     ' we prepend the name of the INCLUDE paths, one at a
  20.     ' time.
  21.     Dim F As Integer
  22.     WorkPath$ = IncludePath$
  23.     TestPath$ = ""
  24. TryAgain:
  25.     On Error GoTo NotExist
  26.     F = FreeFile
  27.     If Len(TestPath$) Then
  28.        If Right$(TestPath$, 1) <> "\" Then
  29.           TestName$ = TestPath$ + "\" + Temp$
  30.        Else
  31.           TestName$ = TestPath$ + Temp$
  32.        End If
  33.     Else
  34.        TestName$ = Temp$
  35.     End If
  36.     Open TestName$ For Input As #F
  37.     Close F
  38.     ' If we get here, then the file exists
  39.     Temp$ = TestName$  'Reset the name to include the path
  40.     IncludeExist% = True
  41.     Exit Function
  42. NotExist:
  43.     If Len(WorkPath$) Then  ' If INCLUDE path not exhausted
  44.        ' If the include file name already has a colon or backslash,
  45.        ' there's no sense checking with prepended paths.
  46.        If InStr(Temp$, ":") > 0 Or InStr(Temp$, "\") > 0 Then
  47.           Resume Getout
  48.        End If
  49.        F = InStr(WorkPath$, ";")
  50.        If F = 0 Then
  51.           F = Len(WorkPath$) + 1
  52.        End If
  53.        TestPath$ = Left$(WorkPath$, F - 1)
  54.        WorkPath$ = Mid$(WorkPath$, F + 1)
  55.        Resume TryAgain
  56.     Else
  57.        Resume Getout
  58.     End If
  59. Getout:
  60.     IncludeExist% = MhFalse
  61.  
  62. End Function
  63.  
  64. Function ConvertToQ$ (Temp$)
  65.  
  66.     ' This function takes a string with '*' and converts
  67.     ' the asterisk to ?'s for comparison purposes with
  68.     ' wildcard matches.
  69.  
  70.     Dim I As Integer, A As Integer, Count As Integer
  71.     MainName$ = Temp$   ' in case no separators found
  72.     ' Separate into main filename and extension
  73.     For I = Len(Temp$) To 1 Step -1
  74.         A = Asc(Mid$(Temp$, I, 1))
  75.         Select Case A
  76.             Case 46      ' Period - found extension
  77.                 MainName$ = Left$(Temp$, I - 1)
  78.                 Extension$ = Mid$(Temp$, I + 1)
  79.                 Exit For   ' Done
  80.             Case 47, 58, 92 ' Forw slash, colon or backslash
  81.                 Exit For   ' Done
  82.         End Select
  83.     Next
  84.     A = InStr(MainName$, "*")
  85.     If A Then
  86.         Count = 8
  87.         For I = A - 1 To 1 Step -1
  88.             ' Find first separator so we know how many ?'s to add
  89.             A = Asc(Mid$(MainName$, I, 1))
  90.             Select Case A
  91.                 Case 47, 58, 92 ' Forw slash, colon or backslash
  92.                 Exit For
  93.                 Case Else
  94.                 Count = Count - 1
  95.             End Select
  96.         Next
  97.         MainName$ = Left$(MainName$, A - 1) + String$(Count, "?")
  98.     End If
  99.     A = InStr(Extension$, "*")
  100.     If A Then
  101.         Extension$ = Left$(Extension$, A - 1) + String$(3, "?")
  102.         Extension$ = Left$(Extension$, 3)' Shorten to 3
  103.     End If
  104.     Extension$ = Left$(Extension$ + Question$, 3)' Fill out to 3
  105.     MainName$ = Left$(MainName$ + Question$, 8)' Fill out to 8
  106.     ConvertToQ$ = UCase$(MainName$ + "." + Extension$)
  107.  
  108. End Function
  109.  
  110. Function WildCardCompare% (S1$, S2$)
  111.  
  112.     ' This routine compares two strings, either one of
  113.     ' which (or both) has the wildcard characters "?".
  114.  
  115.     ' Function returns True if they match, MhFalse if not
  116.     Dim I As Integer, A As Integer, B As Integer
  117.     If Len(S1$) = Len(S2$) Then
  118.        For I = 1 To Len(S1$)
  119.            A = Asc(Mid$(S1$, I, 1))
  120.            If A <> 63 Then  ' If not a question mark
  121.               B = Asc(Mid$(S1$, I, 1))
  122.               ' If not a question mark, and they're not equal
  123.               If (B <> 63) And (A <> B) Then
  124.                  WildCardCompare% = MhFalse
  125.                  Exit Function
  126.               End If
  127.            End If
  128.        Next
  129.        ' If we got here, then all chars compare
  130.        WildCardCompare% = True
  131.     Else
  132.        WildCardCompare% = MhFalse    ' Can't match if lengths not same
  133.     End If
  134.  
  135. End Function
  136.  
  137. Function IsIncludeFile$ (CodeLine$)
  138.  
  139.     ' This function examines CodeLine$ for either
  140.     ' '$INCLUDE or Rem $Include statements. If it finds
  141.     ' such a line, with a valid file name, then the
  142.     ' function result is the name of the file, else
  143.     ' the function result is null.
  144.  
  145.     ' It also compares dates and times of files, if you
  146.     ' have checked that option button.
  147.  
  148.     ' On entry, CodeLine$ must be uppercase
  149.     
  150.     Dim IsRem As Integer, A As Integer
  151.     If Len(CodeLine$) < 13 Then
  152.        ' Can't be '$INCLUDE:'x' or longer
  153.        IsInclude$ = ""
  154.        Exit Function
  155.     End If
  156.     IsRem = MhFalse
  157.     ' If line begins with apostrophe
  158.     If Asc(CodeLine$) = 39 Then
  159.         IsRem = True
  160.         CodeLine$ = StripWhiteSpace$(Mid$(CodeLine$, 2))
  161.     ElseIf InStr(CodeLine$, Remark1$) = 1 Or InStr(CodeLine$, Remark2$) = 1 Then
  162.         IsRem = True
  163.         CodeLine$ = StripWhiteSpace$(Mid$(CodeLine$, 4))
  164.     End If
  165.     If IsRem Then  ' See if it's $INCLUDE
  166.         If InStr(CodeLine$, Include$) = 1 Then
  167.             ' Isolate file name
  168.             CodeLine$ = StripWhiteSpace$(Mid$(CodeLine$, Len(Include$) + 1))
  169.             If Asc(CodeLine$) = 39 Then '  file name is surrounded by apostrope
  170.                 ' Search for second apostrophe
  171.                 A = InStr(2, CodeLine$, Apostrophe$)
  172.                 If A Then
  173.                     IncludeFileName$ = Mid$(CodeLine$, 2, A - 2)
  174.                     If IncludeExist(IncludeFileName$) Then
  175.                         If MainForm.IncOption(0).Value Then ' Forced update
  176.                            IsIncludeFile$ = IncludeFileName$
  177.                         ElseIf MainForm.IncOption(1).Value Then
  178.                            If MhFileDateCompare%(IncludeFileName$, OldFileName$) = -1 Then
  179.                               IsIncludeFile$ = IncludeFileName$
  180.                            Else
  181.                               SkippedFiles = SkippedFiles + 1
  182.                            End If
  183.                         End If
  184.                     End If
  185.                 End If
  186.             End If
  187.         End If
  188.     End If
  189.  
  190. End Function
  191.  
  192. Function StripWhiteSpace$ (Temp$)
  193.  
  194.     ' This function strips leading spaces and tabs
  195.     ' from a string.
  196.     Dim WhiteSpace As Integer
  197.     WhiteSpace = 0
  198.     For J = 1 To Len(Temp$)
  199.         A = Asc(Mid$(Temp$, J, 1))
  200.         Select Case A
  201.             Case 9, 32     ' Tabs & spaces
  202.             WhiteSpace = WhiteSpace + 1
  203.             Case Else
  204.             Exit For     ' Done
  205.         End Select
  206.     Next
  207.     ' Strip leading whitespace
  208.     StripWhiteSpace$ = Mid$(Temp$, WhiteSpace + 1)
  209.  
  210. End Function
  211.  
  212. Sub FormatPath (YourForm As Form, Temp$, Divisor)
  213.  
  214.     ' This procedure formats the path so it fits
  215.     ' into the textbox.
  216.     Do
  217.        A& = GetTextExtent(YourForm.hDC, Temp$, Len(Temp$)) Mod 65536
  218.        If A& <= YourForm.FileOpenCurDir.Width \ Divisor Then
  219.           ' If text will fit into our label, then get out
  220.           Exit Do
  221.        End If
  222.        ' Get rid of everything between 1st/last backslash
  223.        For I = Len(Temp$) To 1 Step -1
  224.            If Asc(Mid$(Temp$, I, 1)) = 92 Then ' found backslash
  225.               J = I
  226.               Exit For
  227.            End If
  228.        Next
  229.        I = InStr(Temp$, "\")
  230.        Temp$ = Left$(Temp$, I) + "..." + Mid$(Temp$, J)
  231.     Loop
  232.  
  233.     YourForm.FileOpenCurDir.Caption = Temp$
  234.     YourForm.FileOpenCurDir.Refresh
  235.  
  236. End Sub
  237.  
  238. Function FileExist% (Temp$)
  239.  
  240.     ' Determines if a file exists.
  241.  
  242.     ' Returns True if file exists, else MhFalse
  243.     Dim NextFile As Integer
  244.     NextFile = FreeFile
  245.     On Error GoTo ExistError
  246.     Open Temp$ For Input As #NextFile
  247.     Close #NextFile
  248.     FileExist% = True
  249.     Exit Function
  250.  
  251. ExistError:
  252.     On Error GoTo 0
  253.     FileExist% = MhFalse
  254.     Resume EE2
  255. EE2:
  256.  
  257. End Function
  258.  
  259.