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
/
Copy pathDC.CREATE.RECORD
executable file
·141 lines (118 loc) · 3.48 KB
/
DC.CREATE.RECORD
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Name: DC.CREATE.RECORD
* Type: Program
* Author: dreller
* Date: Apr 13, 2020
* Git: mvDevCore
* System: openQM 3.4.18
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* Create records. Pass to DC.CREATE.RECORD.SUBR.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
* Calling methods:
* - DC.CREATE.RECORD
* Will create records defined in 'dcArtifRecs.txt' file.
* - DC.CREATE.RECORD {filename}
* Will create records defined in {/path/to/file}
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
EQU EQU$MYNAME TO "DC.CREATE.RECORD"
! Pre-actions
HEAD = ""
HEAD<1> = "Record 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:"dcArtifRecs.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:
NEW.RECORD = ""
DESTINATION.FILE = ""
DESTINATION.ID = ""
ATTR.NO = 1
LOOP
READSEQ SOURCE.ITEM FROM SOURCE.FILE ELSE GOTO 3020
GOSUB 4000
REPEAT
3020:
CLOSE SOURCE.FILE
RETURN
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
! Create the records
4000:
IS.COMMENT = (SOURCE.ITEM[1,1]="*")
IS.EMPTY = (LEN(SOURCE.ITEM)<2)
IF IS.COMMENT OR IS.EMPTY THEN
RETURN
END
IF SOURCE.ITEM[1,5] = "$$NEW" THEN
NEW.RECORD = ""
DESTINATION.FILE = ""
DESTINATION.ID = ""
ATTR.NO = 1
RETURN
END
IF SOURCE.ITEM[1,6] = "$$FILE" THEN
DESTINATION.FILE = TRIM(SOURCE.ITEM[7,999])
RETURN
END
IF SOURCE.ITEM[1,4] = "$$ID" THEN
DESTINATION.ID = TRIM(SOURCE.ITEM[5,999])
RETURN
END
IF SOURCE.ITEM[1,5] = "$$END" THEN
GOSUB 5000
RETURN
END
ATTR.VALUE = TRIM(SOURCE.ITEM)
ATTR.VALUE = CHANGE(ATTR.VALUE, "@VM", @VM)
ATTR.VALUE = CHANGE(ATTR.VALUE, "@SM", @SM)
ATTR.VALUE = TRIM(ATTR.VALUE)
ATTR.VALUE = TRIMS(ATTR.VALUE)
NEW.RECORD<-1> = ATTR.VALUE
RETURN
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Write record to file
5000:
DISPLAY "Write record ":DESTINATION.ID:" to file ":DESTINATION.FILE:"... "
OPEN DESTINATION.FILE TO DEST.FILE ELSE STOP "UNABLE TO OPEN ":DESTINATION.FILE
WRITE NEW.RECORD TO DEST.FILE, DESTINATION.ID
CLOSE DEST.FILE
RETURN
END