fortrangoingonforty/ferp / f31f4ea

Browse files

Preserve CRLF line endings like grep

- Remove CR stripping from mmap line reading
- Remove CR stripping from regular file I/O
- Grep preserves carriage returns in output; ferp now matches
Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
f31f4ea826ea715c510cd3ec5a601eb807944a6b
Parents
d312f5c
Tree
1e08739

2 changed files

StatusFile+-
M src/ferp_io.f90 1 6
M src/ferp_mmap.f90 2 14
src/ferp_io.f90modified
@@ -176,13 +176,8 @@ contains
176
       return
176
       return
177
     end if
177
     end if
178
 
178
 
179
-    ! Strip trailing carriage return for Windows line endings (\r\n)
179
+    ! Get line length (preserve CR like grep)
180
     line_len = len_trim(buffer)
180
     line_len = len_trim(buffer)
181
-    if (line_len > 0) then
182
-      if (buffer(line_len:line_len) == char(13)) then
183
-        line_len = line_len - 1
184
-      end if
185
-    end if
186
 
181
 
187
     ! Allocate result string trimmed to actual length
182
     ! Allocate result string trimmed to actual length
188
     if (line_len > 0) then
183
     if (line_len > 0) then
src/ferp_mmap.f90modified
@@ -248,14 +248,8 @@ contains
248
       end_pos = int(newline_pos, c_size_t) + 1
248
       end_pos = int(newline_pos, c_size_t) + 1
249
     end if
249
     end if
250
 
250
 
251
-    ! Calculate line length (excluding newline)
251
+    ! Calculate line length (excluding newline, but preserving CR like grep)
252
     line_len = end_pos - start_pos
252
     line_len = end_pos - start_pos
253
-    if (line_len > 0 .and. end_pos > start_pos) then
254
-      ! Check for CR before LF (Windows line ending)
255
-      if (file_data(end_pos - 1) == char(13)) then
256
-        line_len = line_len - 1
257
-      end if
258
-    end if
259
 
253
 
260
     ! Allocate and copy line
254
     ! Allocate and copy line
261
     if (line_len > 0) then
255
     if (line_len > 0) then
@@ -323,14 +317,8 @@ contains
323
         end_pos = int(newline_pos, c_size_t)
317
         end_pos = int(newline_pos, c_size_t)
324
       end if
318
       end if
325
 
319
 
326
-      ! Calculate line length (excluding newline and CR)
320
+      ! Calculate line length (excluding newline, but preserving CR like grep)
327
       line_len = end_pos - start_pos
321
       line_len = end_pos - start_pos
328
-      if (line_len > 0 .and. end_pos > start_pos) then
329
-        ! Check for CR before LF (Windows line ending)
330
-        if (file_data(end_pos) == char(13)) then
331
-          line_len = line_len - 1
332
-        end if
333
-      end if
334
 
322
 
335
       ! Store line info
323
       ! Store line info
336
       batch%count = batch%count + 1
324
       batch%count = batch%count + 1