This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DC.CREATE.FILE
executable file
·114 lines (99 loc) · 3.08 KB
/
DC.CREATE.FILE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Name: DC.DREATE.FILE
* Type: Program
* Author: dreller
* Date: Apr 13, 2020
* Git: mvDevCore
* System: openQM 3.4.18
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Create files in the account. Pass to DC.CREATE.FILE.SUBR.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Calling methods:
* - DC.CREATE.FILE
* Will create files defined in 'dcArtifFiles.txt' file.
* - DC.CREATE.FILE {filename}
* Will create files defined in {/path/to/file}
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
EQU EQU$MYNAME TO "DC.CREATE.FILE"
! Pre-actions
HEAD = ""
HEAD<1> = "File creator"
CALL DC.HEAD(HEAD)
! Program mainline
GOSUB 1000 ;* Get the file from sentence
GOSUB 2000 ;* Validate the file
GOSUB 3000 ;* Open the file
! Post-actions
!undefined
RETURN
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
! Get the file from sentence
1000:
FILE.PATH = ""
ERR.TEMP = ""
CALL DC.SENTENCE.SUBR(SENTENCE(), EQU$MYNAME, FILE.PATH, ERR.TEMP)
!---- If no file is passed, use the default one
IF FILE.PATH = "" THEN
FILE.PATH = @PATH:@DS:"DEVCORE.PGM":@DS:"dcArtifFiles.txt"
END
RETURN
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! Validate the target file
2000:
!-- Is the file exists ?
VALID.FLAG = OSPATH(FILE.PATH, 2)
IF NOT(VALID.FLAG) THEN
DISPLAY "Path not found: ":FILE.PATH
RETURN
END
!-- If it's a real file (not a directory)
VALID.FLAG = OSPATH(FILE.PATH, 16)
IF NOT(VALID.FLAG) THEN
DISPLAY "This is not a file: ":FILE.PATH
RETURN
END
RETURN
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! Open the file
3000:
OPENSEQ FILE.PATH TO SOURCE.FILE THEN GOTO 3010
DISPLAY "Unable to open file: ":FILE.PATH
RETURN
3010:
LOOP
READSEQ SOURCE.ITEM FROM SOURCE.FILE ELSE GOTO 3020
GOSUB 4000
REPEAT
3020:
CLOSE SOURCE.FILE
RETURN
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! Create the file
4000:
!-- Validate if entry should be treated as a comment
SOURCE.ITEM = TRIM(SOURCE.ITEM)
IS.COMMENT = (SOURCE.ITEM[1,1]="*")
IS.EMPTY = (LEN(SOURCE.ITEM)<2)
IF IS.COMMENT OR IS.EMPTY THEN
RETURN
END
!-- Transform SOURCE.ITEM to the required MV for CD.CREATE.FILE.SUBR
RESPONSE = ""
PARMS = ""
PARMS<1> = FIELD(SOURCE.ITEM,"|", 1, 1)
PARMS<2> = FIELD(SOURCE.ITEM,"|", 2, 1)
PARMS<3> = FIELD(SOURCE.ITEM,"|", 3, 1)
PARMS<4> = FIELD(SOURCE.ITEM,"|", 4, 1)
DISPLAY "Creating file, ":PARMS<1>:"-Type, Name '":PARMS<2>:"'... ":
CALL DC.CREATE.FILE.SUBR(PARMS, RESPONSE)
RESPONSE.TEXT = "OK"
ERROR.FLAG = (RESPONSE # "0")
IF ERROR.FLAG THEN
CALL !ERRTEXT(RESPONSE.TEXT, RESPONSE)
END
DISPLAY RESPONSE.TEXT
RETURN
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
END