home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / pbcode.zip / DWGCONTR.BAS < prev    next >
BASIC Source File  |  1994-08-03  |  14KB  |  331 lines

  1. ' PURPOSE:   Perry Drawing file management
  2. ' DATE:      1 August 1994
  3. ' CONCEPT:   
  4. '            At least once each day every CAD operator runs a BATCH
  5. '            file for the purpose of backing up the days work. The 
  6. '            idea here is to change that procedure to twice a day
  7. '            and to assit the CAD supervisor in manageing the CAD files.
  8. '
  9. '            This program will be called by the  Backup Batch file.
  10. '            This will allow the CAD Supervisor (and maybe the checker)
  11. '            to write a plain ASCII control file that will Copy, Move,
  12. '            Delete, Rename or List files at a given operators station.
  13. '--------------------------------------------------------------------------
  14. defint a-z
  15. $INCLUDE "AHNUTS.BAS"
  16. $INCLUDE "COPYFILE.BAS"
  17. DIM FileList$(1 to 1000)         ' array for matching files
  18. action%=0                        ' set default to do nothing
  19. Perry%=0
  20. SourPath$="C:\DATA\DWG\"
  21. DestPath$="Q:\RELEASE\"
  22.  
  23.  
  24. ' define two strings for stripping control characters from input
  25. for i%=1 to 31
  26.    m$=m$+chr$(i%)
  27. next i%
  28. n$=space$(31)
  29.  
  30. c$=command$
  31. replace ANY m$ with n$ in c$
  32. c$ = ucase$(ltrim$(rtrim$(c$)))
  33.  
  34. if c$="" then end
  35. if dir$(c$)="" then end
  36. ' NOW just for a little caution: THE CONTROL FILE EXTENSION MUST BE ".EVE"
  37. if right$(c$,4)<>".EVE" then print "NOT A VALID CONTROL FILE NAME": END
  38.  
  39. open c$ for input as #1
  40. Line Input #1, l$
  41. l$=Rtrim$(Ltrim$(Ucase$(l$)))
  42. if l$<>"@CONTROL FILE@" then
  43.    Print c$;" is not a valid CONTROL FILE --- Aborted"
  44.    BEEP: BEEP: BEEP
  45.    End
  46. End If
  47. close #1
  48.  
  49. ' now rename the file so that there is no chance that we process it twice
  50. p%=instr(c$,".EVE")
  51. t$=left$(c$,p%)+"VEV"
  52. name c$ as t$
  53. c$=t$
  54.  
  55. CLS
  56. Print "Drawing file maintainence with Control File: ";c$
  57. open c$ for input as #1
  58.  
  59. p%=instr(c$,".DEL")
  60. r$=left$(c$,p%)+"LOG"
  61. open r$ for append as #2
  62. print #2,"============================================================================"
  63. print #2,date$, time$, c$
  64. print #2,"============================================================================"
  65.  
  66.  
  67. START:
  68.    '-------------------------------------------------------------------------
  69.    kw$=""
  70.    ' get line from file and clean it up
  71.    if EOF(1) then goto FINISH:
  72.    Line Input #1, l$
  73.    if l$=""  then goto START:
  74.  
  75.    ' clean up the input
  76.    replace ANY m$ with n$ in l$
  77.    l$=ltrim$(rtrim$(l$))
  78.  
  79.    ' allow for comments
  80.    if left$(ltrim$(l$),1)=";" then goto START:
  81.    p%=instr(l$,";")
  82.    if p%>0 then l$=rtrim$(left$(l$,p-1))
  83.    if l$="" then goto START:
  84.  
  85.    '------------------------------------------------------------------------
  86.    ' check and handle in control keywords
  87.    ' All control statements begin with @ and end with a space or end of line
  88.    if left$(l$,1)="@" then
  89.         ' seperate keword and any parameters
  90.         p%=instr(l$," ")
  91.         if p%>0 then
  92.              kw$=ucase$(left$(l$,p%-1))
  93.              pr$=ltrim$(mid$(l$,p%))
  94.         else
  95.              kw$=ucase$(l$)
  96.              pr$=""
  97.         end if
  98.         select case kw$
  99.              case "@LOG"              ' add comment to LOG File
  100.                   print #2, pr$
  101.              case "@ECHO"             ' display message on console
  102.                   print pr$
  103.              case "@PAUSE"            ' allow for pause
  104.                   Print " Press any key to continue ...";
  105.                   while inkey$="" :wend
  106.                   print
  107.              case "@ESCAPE"           ' allow for escape
  108.                   Print " Press ESC key to abort, any other key to continue ...";
  109.                   k$=""
  110.                   while k$=""
  111.                        k$=inkey$
  112.                        if k$=chr$(27) then 
  113.                             print #2, "**** Operator aborted operation **** ";time$
  114.                             print
  115.                             print "***** OPERATOR ABBORTED ******"
  116.                             end
  117.                        end if
  118.                   wend
  119.              case "@LOGLOG"           ' set mode to log only
  120.                   action%=0
  121.                   Print #2,"----@LOG ONLY MODE-------------------------------------------"
  122.              case "@RENAME"           ' set mode to RENAME files
  123.                   action%=1
  124.                   Print #2,"----@RENAME MODE---------------------------------------------"
  125.              case "@DELETE"           ' set mode to DELETE files
  126.                   action%=2
  127.                   Print #2,"----@DELETE MODE---------------------------------------------"
  128.              case "@COPY"             ' set mode to COPY files
  129.                   action%=3
  130.                   Print #2,"----@COPY MODE-----------------------------------------------"
  131.              case "@MOVE"             ' set mode to MOVE files
  132.                   action%=4
  133.                   Print #2,"----@MOVE MODE-----------------------------------------------"
  134.              case "@DESTINATION"      ' set Destination Path
  135.                   if pr$="" then
  136.                        MajorError%=1
  137.                        Print #2, "***** NULL destination path --- Operation Abborted *****";time$
  138.                        end
  139.                   end if
  140.                   DestPath$=pr$
  141.                   if right$(DestPath$,1)<>"\" then DestPath$=SourPath$+"\"
  142.                   print #2, "-----DESTINATION PATH set to ";DestPath$;" -----------"
  143.              case "@SOURCE"      ' set source Path
  144.                   if pr$="" then
  145.                        MajorError%=1
  146.                        Print #2, "***** NULL SOURCE path --- Operation Abborted *****";time$
  147.                        end
  148.                   end if
  149.                   SourPath$=pr$
  150.                   if right$(SourPath$,1)<>"\" then SourPath$=SourPath$+"\"
  151.                   print #2, "-----SOURCE PATH set to ";SourPath$;" ------------------"
  152.              case "@PERRY"       ' confine operations to valid Perry File names
  153.                   Perry%=1
  154.                   print #2, "-----Valid Perry Documnet File Names Only -------------"
  155.  
  156.              case "@ANY"         ' operations on any File names
  157.                   Perry%=0
  158.                   print #2, "-----Any matching File names" --------------------------"
  159.              case else
  160.                   ' must be a comment ???
  161.         end select
  162.    end if
  163.    if kw$<>"" then goto start:
  164.    '------------------------------------------------------------------------
  165.    ' assume we have a valid file Mask
  166.    ' check for source path and spaces
  167.    p%=0
  168.    t$=""
  169.    if instr(l$,ANY ":\ ") then
  170.         for i%=1 to len(l$)
  171.              c$=mid$(l$,i,1)
  172.              if c$>chr$(32) then t$=t$+c$
  173.         next i%
  174.         l$=t$
  175.         for i%=1 to len(t$)
  176.              if mid$(l$,i%,1)=":" then p%=i
  177.              if mid$(l$,i%,1)="\" then p%=i
  178.         next i%
  179.         if p%>0 then 
  180.              SourPath$=left$(t$,p%)
  181.              if right$(SourPath$,1)<>"\" then SourPath$=SourPath$+"\"
  182.              print #2, "-----SOURCE PATH set to ";SourPath$;" -----------"
  183.              if p%<>len(t$) then
  184.                   l$=mid$(t$,p%+1)
  185.              else
  186.                   l$="Aint-No-Way-Man"
  187.              end if
  188.         end if
  189.    end if
  190.    '------------------------------------------------------------------------
  191.    if len(l$)>13 then goto START:
  192.  
  193.    count%=0
  194.    d$=dir$(l$)
  195.    while d$<>""
  196.         valid%=0
  197.         if Perry%=1 then
  198.              ' get the leading part of the file name
  199.              ' check for valid Perry Document file name
  200.              ' the Filename must be at least 8 characters
  201.              t$=ucase$(left$(d$,9))
  202.              if len(d$)<>9 then 
  203.                   valid%=1
  204.              else
  205.                   if right$(d$)<>"." then valid%=1
  206.                   ' the first 5 characters must be numeric
  207.                   for i%=1 to 5
  208.                        c$=mid$(t$,i%,1)
  209.                        if c$>"9" then valid%=1
  210.                        if c$<"0" then valid%=1
  211.                   next i%
  212.                   ' the next 3 characters must be alphanumeric
  213.                   for i%=6 to 8
  214.                        c$=mid$(t$,i%,1)
  215.                        if c$>"Z" then valid%=1
  216.                        if c$<"0" then valid%=1
  217.                        if c$>"9" and c$<"A" then valid%=1
  218.                   next i%
  219.              end if
  220.         end if
  221.         if valid%=0 then
  222.              count%=count%+1
  223.              FileList$(count%)=d$
  224.         end if
  225.         if count%<1000 then
  226.              d$=dir$
  227.         else
  228.              print #2, "**** MORE THAN 1000 MATCHES for ";l$;" Operation truncated *****"
  229.              d$=""
  230.         end if
  231.    Wend
  232.    '------------------------------------------------------------------------
  233.    ' Now we should have a list of up to 1000 valid file names
  234.    for FileIndex%=1 to Count%
  235.         d$=FileList$(FileIndex%)
  236.         Print #2, FileInfo$(SourPath$+d$);
  237.         Print d$
  238.         select case action%
  239.              case 0
  240.                   Print #2,""
  241.              case 1
  242.                   p%=instr(d$,".")
  243.                   t$=left$(d$,p%)+"DEL"
  244.                   if dir$(SourPath$+t$)<>"" then KILL (SourPath$+t$)
  245.                   name (SourPath$+D$) as T$
  246.                   Print #2, " Renamed to ";t$
  247.              case 2
  248.                   KILL SourPath$+D$
  249.                   Print #2, " Deleted"
  250.              case 3
  251.                   ' First we need to split out the file name
  252.                   '  add in the Release Dir Path.
  253.                   t$=DestPath$+t$
  254.                   if Dir$(t$)<>"" then
  255.                        ' It is assumed that we can not modify files in the destination directory
  256.                        Print #2,""
  257.                        Print #2, " ***** Drawing exist in destination directory *****"
  258.                        PRINT #2, " ***** COPY OF ";D$;" OPERATION ABORTED *****" 
  259.                        MajorError%=1
  260.                   Else
  261.                        if CopyFile%(SourPath$+d$,DestPath$+t$)=0 then
  262.                             Print #2, "Copied to ";T$
  263.                             If VerifyFile%(SourPath$+d$,DestPath$+t$)=0 then
  264.                                  Print #2, ", Verifyed Copy, ";
  265.                                  Print #2, DestPath$;FileInfo$(DestPath$+T$)
  266.                             else
  267.                                  Print #2, ", ***** Verify Error ****** "
  268.                                  Print #2, "******************************************************"
  269.                                  PRINT #2, "   ***** ***** COPY OF ";D$;" NOT VALID ***** *****" 
  270.                                  PRINT #2, "   ***** ***** COPY OF ";D$;" NOT VALID ***** *****" 
  271.                                  PRINT #2, "   ***** ***** COPY OF ";D$;" NOT VALID ***** *****" 
  272.                                  Print #2, "******************************************************"
  273.                                  PRINT "   ***** ***** COPY OF ";D$;" NOT VALID ***** *****" 
  274.                                  BEEP: BEEP: BEEP: BEEP: BEEP: BEEP: BEEP: BEEP: BEEP: BEEP: BEEP
  275.                                  MajorError%=1
  276.                             End if
  277.                        Else
  278.                             Print #2, ", ***** Copy Error ****** "
  279.                             PRINT #2, " ***** MOVE OF ";D$;" OPERATION ABORTED *****" 
  280.                             MajorError%=1
  281.                        End if
  282.                   End if
  283.                   Print #2,"---------------------------------------------------------------"
  284.  
  285.              case 4
  286.                   ' First we need to split out the file name
  287.                   '  add in the Release Dir Path.
  288.                   t$=DestPath$+t$
  289.                   if Dir$(t$)<>"" then
  290.                        ' It is assumed that we can not modify files in the destination directory
  291.                        Print #2,""
  292.                        Print #2, " ***** Drawing exist in destination directory *****"
  293.                        PRINT #2, " ***** MOVE OF ";D$;" OPERATION ABORTED *****" 
  294.                        MajorError%=1
  295.                   Else
  296.                        if CopyFile%(SourPath$+d$,DestPath$+t$)=0 then
  297.                             Print #2, "Copied to ";T$
  298.                             If VerifyFile%(SourPath$+d$,DestPath$+t$)=0 then
  299.                                  Print #2, ", Verifyed Copy, ";
  300.                                  Kill SourPath$+d$
  301.                                  Print #2, "Erased ";D$
  302.                                  Print #2, DestPath$;FileInfo$(DestPath$+T$)
  303.                             else
  304.                                  Print #2, ", ***** Verify Error ****** "
  305.                                  PRINT #2, " ***** MOVE OF ";D$;" OPERATION ABORTED *****" 
  306.                                  MajorError%=1
  307.                             End if
  308.                        Else
  309.                             Print #2, ", ***** Copy Error ****** "
  310.                             PRINT #2, " ***** MOVE OF ";D$;" OPERATION ABORTED *****" 
  311.                             MajorError%=1
  312.                        End if
  313.                   End if
  314.                   Print #2,"---------------------------------------------------------------"
  315.              case Else
  316.         end select
  317.    Next FileIndex%
  318.    goto START:
  319.  
  320.  
  321. FINISH:
  322. Close #1
  323. if MajorError%<>0 then 
  324.    Print #2, "***** MAJOR ERROR IN THIS SESION ********************************"
  325. else
  326.    print #2, "----- No major errors in this session ----------------------------"
  327. end if
  328. Print #2, "Normal Termination  ";time$
  329. Close #2
  330. End
  331.