105 type(
context),
intent(inout) :: ctx
106 character(*),
intent(in) :: token
108 character(:),
allocatable :: temp, num_str, fname
109 integer :: pos, iostat, new_line, closing
110 logical :: has_filename
113 pos = index(lowercase(ctx%content), token) + len(token)
114 temp = trim(adjustl(ctx%content(pos:)))
116 if (len_trim(temp) == 0)
then
118 message=
'Syntax error', &
119 label=
label_type(
'#line directive with no arguments', index(token, lowercase(ctx%content)) + len(token) + 1, 1)&
122 trim(ctx%content), ctx%line))
127 pos = index(temp,
' ')
129 num_str = temp(:pos - 1)
130 fname = trim(adjustl(temp(pos:)))
131 has_filename = .true.
134 has_filename = .false.
138 read(num_str, *, iostat=iostat) new_line
139 if (iostat /= 0 .or. new_line < 1)
then
141 message=
'Syntax error', &
142 label=
label_type(
'Invalid line number in #line directive', index(token, lowercase(ctx%content)) + len(token) + &
145 trim(ctx%content), ctx%line))
150 ctx%line = new_line - 1
153 if (has_filename)
then
154 if (fname(1:1) ==
'"' .and. len(fname) > 1)
then
155 closing = index(fname(2:),
'"')
156 if (closing == 0)
then
158 message=
'Malformed #line directive', &
159 label=
label_type(
'Missing closing quotation mark', &
160 index(ctx%content,
'"'),1), &
161 source=trim(ctx%path)), &
162 ctx%content, ctx%line))
164 fname = fname(2:closing)
166 if (len_trim(fname) > 0)
then
167 ctx%path = trim(fname)
Snapshot of a source location within the preprocessing stream.