home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR36 / C7101.ZIP / FILE.TPX < prev    next >
Text File  |  1994-01-28  |  22KB  |  363 lines

  1. #!┌───────────────────────────┤Template Segment├───────────┬─────────────────┐
  2. #!│                                FILE.TPX                │Version: 3007.100│
  3. #!├───────────────────────────────┤Contents├───────────────┴─────────────────┤
  4. #!│Structure             Type       Description                              │
  5. #!│────────────────────  ─────────  ─────────────────────────────────────────│
  6. #!│File                  PROCEDURE  Select a file from a directory listing   │
  7. #!│SetFileSymbols        GROUP      Sets Code Generation Symbols             │
  8. #!│SetFileErrors         GROUP      Generates ?Cancel Button Missing Warning │
  9. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  10. #!│Version   Comments                                                        │
  11. #!│────────  ────────────────────────────────────────────────────────────────│
  12. #!│3007.000  Release of CDD3 version 3007 templates                          │
  13. #!│3007.100  Repaired File Template                                          │
  14. #!└──────────────────────────────────────────────────────────────────────────┘
  15. #!
  16. #PROCEDURE(File,'Select a file from a directory listing'),SCREEN
  17. #!
  18. #!┌──────────────────────────┤Procedure Template├──────────┬─────────────────┐
  19. #!│                                  File                  │Version: 3007.100│
  20. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  21. #!│ The File template creates a procedure to allow a user to select a file.  │
  22. #!│ The file name with its full path will be saved in the variable entered   │
  23. #!│ at the 'Filename Variable' prompt.  If this field is left blank the      │
  24. #!│ default of GLO:Filespec is used.  (GLO:Filespec has been entered in      │
  25. #!│ Clarion's Default Application file for your convenience.  It will be     │
  26. #!│ Smart-linked out of your final .EXE if not used.)                        │
  27. #!│                                                                          │
  28. #!│ If a Next Procedure is requested (ie: a procedure created with the View  │
  29. #!│ template) it will be called just prior to returning to the calling       │
  30. #!│ procedure.                                                               │
  31. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  32. #!│Version   Comments                                                        │
  33. #!│────────  ────────────────────────────────────────────────────────────────│
  34. #!│3007.000  Release of CDD3 version 3007 templates                          │
  35. #!│3007.100  In FillQueues ROUTINE, the call to SELECT(?FileList,1) was      │
  36. #!│          being made even if ?FileList was not defined.                   │
  37. #!└──────────────────────────────────────────────────────────────────────────┘
  38. #!
  39. #PROTOTYPE('')                                   #! No special prototype
  40. #INSERT(%StandardHeader)                         #! Procedure Comment Block
  41. #MAP('GETDIR.INC')                               #! Include Procs in MAP
  42. #DISPLAY(' ')                                    #! Blank Line on Props Scrn
  43. #PROMPT('Filename &Variable',FIELD),%SaveFilenameVar
  44. #PROMPT('Initial Directory',@S30),%StartDir
  45. #PROMPT('Beginning File Mask',@S12),%StartMask
  46. #PROMPT('Next Procedure',PROCEDURE),%NextProcedure
  47. #PROMPT('Reselect Upon Return',CHECK),%AllowReselect
  48. #PROMPT('Blank Name On Cancel',CHECK),%ClearOnCancel
  49. #PROMPT('Allow Drive Searches',CHECK),%AllowDriveSearch
  50. #INSERT(%SetFileSymbols)                         #! Set Generation Flags
  51. #INSERT(%SetFileErrors)                          #! Warn Developer, if needed
  52. %Procedure       PROCEDURE                       #<!%ProcedureDescription
  53. %LocalData                                       #! Declare Local Data
  54. %ScreenStructure                                 #! Declare Screen Structure
  55. DirString   CSTRING(64)                          #<! Used for Directory to search
  56. SaveDir     LIKE(DirString)                      #<! Used to hold beginning path
  57. SaveSelect  LONG                                 #<! Used to hold selected field
  58. DirInfo     GROUP                                #<! Necessary DOS file group
  59.               BYTE,DIM(21)                       #<! Used by findfirst
  60. Attrib        BYTE                               #<! Attribute in DOS format
  61. DosTime       SHORT                              #<! Time in DOS format
  62. DosDate       SHORT                              #<! Date in DOS format
  63. Filesize      LONG                               #<! Size in BYTES
  64. FileName      CSTRING(13)                        #<! File name
  65.             END                                  #<! End GROUP
  66. #IF(%AllowDriveSearch)                           #! IF allowing to search drives
  67. DriveNumber USHORT                               #<! Used for Drive search
  68. CheckReady  STRING(3)                            #<! Used to check if Drive is ready
  69. #ENDIF                                           #! END (IF allowing...)
  70. #EMBED('Data Section')                           #! Embedded Source Code
  71.   CODE                                           #<! Begin Processing Code
  72.   #EMBED('Setup Procedure')                      #! Embedded Source Code
  73.   OPEN(%Screen)                                  #<! Open the screen
  74.   #EMBED('Setup Screen')                         #! Embedded Source Code
  75.   #IF(%StartMask)                                #! IF Initial File Mask
  76.   FileMask = '%StartMask'                        #<!Set the begining file mask
  77.   #ELSE
  78.   FileMask = '*.*'                               !Set the begining file mask
  79.   #ENDIF
  80.   SaveDir = PATH()                               !Save the Starting Directory
  81.   IF SUB(SaveDir,LEN(CLIP(SaveDir)),1) <> '\'    ! Last character not backslash?
  82.     SaveDir = CLIP(SaveDir) & '\'                ! Add the trailing '\'
  83.   END
  84.   #IF(%StartDir)
  85.   Directory = UPPER(%StartDir)                   #<!Change to the requested
  86.   SETPATH(Directory)                             ! Starting directory
  87.   Directory = PATH()                             ! Reread the current path
  88.   IF SUB(Directory,LEN(CLIP(Directory)),1) <> '\' ! Last character not backslash?
  89.     Directory = CLIP(Directory) & '\'            ! Add the trailing '\' for display
  90.   END
  91.   #ELSE
  92.   Directory = SaveDir                            !Set to the Current Directory
  93.   #ENDIF
  94.   DO FillQueues                                  !Fill the screen queues
  95.   LOOP                                           !Main ACCEPT loop
  96.     #INSERT(%GenerateFormulas)
  97.     #EMBED('Top of Accept Loop')                 #! Embedded Source Code
  98.     CASE SELECTED()                              #<! Jump to field setup routine
  99.     #INSERT(%ScreenSetupRoutines)
  100.     END                                          #<! End CASE
  101.     ACCEPT                                       ! ACCEPT keyboard input
  102.     #INSERT(%HotKeyRoutines)
  103.     CASE FIELD()                                 ! Jump to field edit routine
  104.   #FOR(%ScreenField)
  105.     #IF(%ScreenField = '?FileMask')
  106.     OF ?FileMask                                 ! Completed file mask field
  107.     #IF(%ScreenFieldEdit)
  108.       %ScreenFieldEdit                           #<! File mask edit routine
  109.     #ENDIF
  110.       IF REFER()                                 !  If something was entered
  111.         Do FillQueues                            !   Fill queues with new mask
  112.       END                                        !  End IF
  113.     #ELSIF(%ScreenField = '?FileList')
  114.     OF ?FileList                                 ! FileList field edit
  115.       GET(FileQueue,CHOICE())                    !  Get selected file entry
  116.   #IF(%ScreenFieldEdit)
  117.       %ScreenFieldEdit                           #<! File list edit routine
  118.   #ENDIF
  119.       IF KEYCODE() = MouseLeft2 OR |             !  On mouse double click
  120.          KEYCODE() = EnterKey                    !    Or the Enter Key
  121.         SELECT(?OK)                              !   Select the OK button and
  122.         PRESS(EnterKey)                          !   Press Enter to complete
  123.       END                                        !  End IF
  124.     #ELSIF(%ScreenField = '?DirList')
  125.     OF ?DirList                                  ! Directory list field edit
  126.     #IF(%ScreenFieldEdit)
  127.       %ScreenFieldEdit                           #<! Directory edit routine
  128.     #ENDIF
  129.       IF SELECTED() = ?DirList                   !  If staying on this field
  130.         IF KEYCODE() = MouseLeft2 OR |           !   On mouse double click
  131.            KEYCODE() = EnterKey                  !     or the Enter Key
  132.           GET(DirQueue,CHOICE())                 !    Get the selected entry
  133.     #IF(%AllowDriveSearch)
  134.           IF LEN(CLIP(DirLine)) = 5 AND |        !  Are we looking at a drive?
  135.             SUB(DirLine,1,2) = '[-' AND |
  136.             SUB(DirLine,4,2) = '-]' AND |
  137.             SUB(DirLine,3,1) >= 'A' AND |
  138.             SUB(DirLine,3,1) <= 'Z'
  139.             CheckReady = SUB(DirLine,3,1) & ':'  ! Specify drive letter designation
  140.             IF STATUS(CheckReady) = 0            ! If drive not ready
  141.               CYCLE                              !   Don't change to it
  142.             END
  143.             Directory = CLIP(CheckReady)         ! Assign drive letter as new directory
  144.           ELSE
  145.             Directory = CLIP(Directory) & DirLine ! Create a new directory string
  146.           END
  147.     #ELSE
  148.           Directory = CLIP(Directory) & DirLine  ! Create a new directory string
  149.     #ENDIF
  150.           IF SUB(Directory,LEN(CLIP(Directory)),1) = '\' ! Last character a backslash?
  151.             Directory = SUB(Directory,1,LEN(CLIP(Directory))-1) ! Get rid of it before SETPATH
  152.           END
  153.           SETPATH(Directory)                     ! Set to current directory
  154.           Directory = PATH()                     ! Reread the current directory
  155.           IF SUB(Directory,LEN(CLIP(Directory)),1) <> '\' ! Last character not backslash?
  156.             Directory = CLIP(Directory) & '\'    ! Add the trailing '\' for display
  157.           END
  158.           Do FillQueues                          !    Fill the screen queues
  159.         END                                      !   End IF
  160.       END                                        !  End IF
  161.     #ELSIF(UPPER(%ScreenField) = '?OK')
  162.     OF ?Ok                                       ! Ok button field Edit
  163.   #IF(%ScreenFieldEdit)
  164.       %ScreenFieldEdit                           #<! OK button edit routine
  165.   #ENDIF
  166.       IF FileLine = '  NO MATCH     '            !  If no FileName selected
  167.   #IF(%DirQueueExists)
  168.         SELECT(?DirList)                         !   Select directory list
  169.   #ELSE
  170.         SELECT(?Cancel)                          !   Select cancel button
  171.   #ENDIF
  172.         CYCLE                                    !   Cycle to ACCEPT.
  173.       END                                        !  End IF
  174.       %SaveFilenameVar = CLIP(Directory) & FileLine #<! Save the Filename
  175.   #IF(%NextProcedure)
  176.       SETPATH(SaveDir)                           !  Return to starting path
  177.     #IF(%DirQueueExists)
  178.       FREE(DirQueue)                             !  Free the DirQueue memory
  179.     #ENDIF
  180.       FREE(FileQueue)                            !  Free the FileQueue memory
  181.       %NextProcedure                             #<! Call the Next procedure
  182.     #IF(%AllowReselect)
  183.       DO FillQueues                              !  Fill the screen queues
  184.       SELECT(?FileList)                          !  Select the file list
  185.       CYCLE                                      !  Return to ACCEPT input
  186.     #ELSE
  187.       DO ProcedureReturn                         #<! And leave the Procedure
  188.     #ENDIF
  189.   #ELSE
  190.       DO ProcedureReturn                         #<! And leave the Procedure
  191.   #ENDIF
  192.     #ELSIF(%ScreenField = '?Cancel')
  193.     OF ?Cancel                                   ! Cancel button field Edit
  194.   #IF(%ScreenFieldEdit)
  195.       %ScreenFieldEdit                           #<! Cancel button edit routine
  196.   #ENDIF
  197.       SETPATH(SaveDir)                           !  Return to starting path
  198.   #IF(%DirQueueExists)
  199.       FREE(DirQueue)                             !  Free the DirQueue memory
  200.   #ENDIF
  201.       FREE(FileQueue)                            !  Free the FileQueue memory
  202.   #IF(%ClearOnCancel)
  203.       CLEAR(%SaveFilenameVar)                    #<! Clear the filename variable
  204.   #ENDIF
  205.       DO ProcedureReturn                         #<! And leave the Procedure
  206.     #ELSIF(%ScreenFieldEdit)                     #!
  207.     OF %ScreenField                              #<! Completed %ScreenField
  208.       %ScreenFieldEdit                           #<! %ScreenField edit routine
  209.     #ENDIF                                       #!
  210.   #ENDFOR                                        #!
  211.     #INSERT(%PulldownEditRoutines)               #!
  212.     END                                          #<! End CASE FIELD()
  213.   END                                            #<! End LOOP
  214.   DO ProcedureReturn                             #<! And leave the Procedure
  215. !─────────────────────────────────────────────────────────────────────────────
  216. ProcedureReturn ROUTINE                          #<! return from the PROC
  217.   SETPATH(SaveDir)                               !Return to starting path
  218.   #IF(%DirQueueExists)
  219.   FREE(DirQueue)                                 !Free the DirQueue memory
  220.   #ENDIF
  221.   FREE(FileQueue)                                !Free the FileQueue memory
  222.   DO EndOfProcedureEmbed                         #<! Process the final EMBED
  223.   RETURN                                         #<! END exit the PROC
  224. !─────────────────────────────────────────────────────────────────────────────
  225. EndOfProcedureEmbed ROUTINE                      #<! Process the final EMBED
  226. #EMBED('End of Procedure')                       #! Embedded Source Code
  227. !─────────────────────────────────────────────────────────────────────────────
  228. #EMBED('Custom Routines')                        #! Embedded Source Code
  229. !─────────────────────────────────────────────────────────────────────────────
  230. FillQueues ROUTINE
  231.   SaveSelect = SELECTED()                        !Save the current selected field
  232.   FREE(FileQueue)                                !Free the FileQueue
  233. #IF(%FileListExists)
  234.   SELECT(?FileList,1)                            !Reset file list box
  235. #ENDIF
  236. #IF(%DirQueueExists)
  237.   FREE(DirQueue)                                 !Free the DirQueue
  238.   SELECT(?DirList,1)                             !Reset Dir List box
  239.   DirString = CLIP(Directory) & '*.*'            !Set the subdirectory mask
  240.   IF NOT LEN(CLIP(DirString)) = 6                !If not in the root directory
  241.     DirLine = '..\'                              ! Make prior directory entry
  242.     ADD(DirQueue)                                ! Add to the DirQueue
  243.   END                                            !End IF
  244.   IF FindFirst(DirString,DirInfo,FA_DIREC) <> 0  !If unexpected error
  245.     FREE(DirQueue)                               ! Clear the DirQueue
  246.     FREE(FileQueue)                              ! Clear the FileQueue
  247.     DISPLAY                                      ! Redisplay the lists
  248.     RETURN                                       ! Return
  249.   END                                            !End IF
  250.   LOOP                                           !While entries found
  251.     IF FileName = '.' OR FileName = '..'         ! If the dot entries
  252.       IF FindNext(DirInfo) <> 0                  !  Get the next entry
  253.         BREAK                                    !   Break if unexpected error
  254.       END                                        !  End IF
  255.       CYCLE                                      !  Return to dot entry check
  256.     END                                          ! End IF
  257.     IF BAND(ATTRIB,10H)                          ! If a subdirectory is found
  258.       DirLine = FileName                         !  Fill the queue field
  259.       ADD(DirQueue)                              !  Add to the DirQueue
  260.       IF ERRORCODE() THEN BREAK.                 !  Break if unexpected error
  261.     END                                          ! End IF
  262.     IF FindNext(DirInfo) <> 0                    ! Get the next entry
  263.       BREAK                                      !  Break if unexpected error
  264.     END                                          ! End IF
  265.   END                                            !End LOOP
  266.   SORT(DirQueue,+DirLine)                        !Sort the directory listing
  267.   #IF(%AllowDriveSearch)
  268.   LOOP DriveNumber = 1 TO 26                     !Loop through drive numbers
  269.     IF IsAValidDrive(DriveNumber)                !Validate drive number
  270.        DirLine = '[-' & CLIP(CHR(DriveNumber-1+VAL('A'))) & '-]' !Format drive letter
  271.        ADD(DirQueue)                             ! Add to the DirQueue
  272.     END
  273.   END
  274.   #ENDIF
  275. #ENDIF
  276.   FileLine = 'Searching...'                      !Search message
  277.   ADD(FileQueue)                                 !Add to the FileQueue
  278.   DISPLAY                                        !Display new directory and message
  279.   FREE(FileQueue)                                !Free the FileQueue
  280.   DirString=CLIP(Directory) & FileMask           !Set the file mask
  281.   IF FindFirst(DirString,DirInfo,FA_NORMAL) <> 0 !If no matching files found
  282.     FileLine = '  NO MATCH  '                    ! Fill queue with message
  283.     ADD(FileQueue)                               ! Add to the FileQueue
  284.   Else                                           !Else matching file found
  285.     LOOP                                         ! While entries are found
  286.       IF BAND(ATTRIB,10H) = 0                    !  If entry is a file
  287.         FileLine = FileName                      !   Fill the queue field and
  288.         ADD(FileQueue)                           !   Add to the FileQueue
  289.         IF ERRORCODE() THEN BREAK.               !   Break if unexpected error
  290.       END                                        !  End IF
  291.       IF FindNext(DirInfo) <> 0                  !  Get the next entry
  292.         BREAK                                    !   Break if unexpected error
  293.       END                                        !  End IF
  294.     END                                          ! End LOOP
  295.   END                                            !End IF
  296.   SORT(FileQueue,+FileLine)                      !Sort the file listing
  297.   DISPLAY                                        !Display the new lists
  298.   SELECT(SaveSelect)                             !Reselect the previous selected field
  299. #!***************************************************************************
  300. #GROUP(%SetFileSymbols)
  301. #!
  302. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  303. #!│                            %SetFileSymbols             │Version: 3007.000│
  304. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  305. #!│Purpose:      To setup symbols for generation of a procedure with the     │
  306. #!│              File template.                                              │
  307. #!│Called From:  PROCEDURE: File                                             │
  308. #!│Assumptions:  None                                                        │
  309. #!│Inserts:      None                                                        │
  310. #!│Symbols Set:  None                                                        │
  311. #!│Notes:        None                                                        │
  312. #!└──────────────────────────────────────────────────────────────────────────┘
  313. #!
  314. #IF(%SaveFilenameVar = %Null)
  315.   #SET(%SaveFilenameVar, 'GLO:FileSpec')
  316. #ENDIF
  317.   #SET(%DirQueueExists,%Null)
  318.   #SET(%FileMaskExists,%Null)
  319.   #SET(%FileListExists,%Null)
  320.   #SET(%DirectoryExists,%Null)
  321.   #SET(%FileOkExists,%Null)
  322.   #SET(%FileCancelExists,%Null)
  323.   #FOR(%ScreenField)
  324.     #IF(UPPER(%ScreenField) = '?DIRLIST')
  325.       #SET(%DirQueueExists,'YES')
  326.     #ELSIF(UPPER(%ScreenField) = '?FILEMASK')
  327.       #SET(%FileMaskExists,'YES')
  328.     #ELSIF(UPPER(%ScreenField) = '?FILELIST')
  329.       #SET(%FileListExists,'YES')
  330.     #ELSIF(UPPER(%ScreenField) = '?DIRECTORY')
  331.       #SET(%DirectoryExists,'YES')
  332.     #ELSIF(UPPER(%ScreenField) = '?OK')
  333.       #SET(%FileOkExists,'YES')
  334.     #ELSIF(UPPER(%ScreenField) = '?CANCEL')
  335.       #SET(%FileCancelExists,'YES')
  336.     #ENDIF
  337.   #ENDFOR
  338. #!***************************************************************************
  339. #GROUP(%SetFileErrors)
  340. #!
  341. #!┌────────────────────────────┤Template Group├────────────┬─────────────────┐
  342. #!│                             %SetFileErrors             │Version: 3007.000│
  343. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  344. #!│Purpose:      To warn the developer of any template errors                │
  345. #!│Called From:  PROCEDURE: File                                             │
  346. #!│Assumptions:  None                                                        │
  347. #!│Inserts:      None                                                        │
  348. #!│Symbols Set:  None                                                        │
  349. #!│Notes:        None                                                        │
  350. #!└──────────────────────────────────────────────────────────────────────────┘
  351. #!
  352. #IF(%FileCancelExists <> 'YES')
  353.   #SET(%ErrorMessage,(%Procedure & ' WARNING:'))
  354.   #ERROR(%ErrorMessage)
  355.   #SET(%ErrorMessage,'   ?Cancel button is not found in the screen structure,')
  356.   #ERROR(%ErrorMessage)
  357.   #SET(%ErrorMessage,'   Exit code may not have been generated.')
  358.   #ERROR(%ErrorMessage)
  359.   #SET(%ErrorMessage,%Null)
  360.   #ERROR(%ErrorMessage)
  361. #ENDIF
  362. #CHAIN('Screen.tpx')
  363.