IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38984


Ignore:
Timestamp:
Oct 27, 2015, 4:27:02 PM (11 years ago)
Author:
eugene
Message:

handle \n\r EOL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20150625/Ohana/src/opihi/cmd.data/read_vectors.c

    r38980 r38984  
    190190  ALLOCATE (buffer, char, 0x10001);
    191191  bzero (buffer, 0x10001);
     192
     193  /*
    192194  for (i = 0; i < Nskip; i++) {
    193195    if (scan_line_maxlen (f, buffer, 0x10000) == EOF) {
     
    197199    }
    198200  }
     201  */
     202
     203  int Nline_read = 0; // track number of lines read so far (use to skip lines as well)
    199204
    200205  // we have a working buffer read from the file. we parse the lines in the working buffer
    201206  // until we reach the last chunk without an EOL char.  at that point, we shift the start
    202207  // of the last (partial) line to the start of the buffer and re-fill.
     208
     209  // we treat \n\r pair as a single EOL char to handle mac files:
    203210
    204211  Nstart = 0; // location of the last valid byte in the buffer (start filling here)
     
    218225    c0 = buffer; // c0 always marks the start of a line
    219226    while (bufferStatus) {
    220       c1 = strchr (c0, '\n'); // find the end of this current line
     227      c1 = strchr (c0, '\n'); // find the end of this current line (also valid for a Mac: \r\n)
    221228      if (!c1) {
    222         c1 = strchr (c0, '\r'); // try \r for non-UNIX files (what do we do about a Mac? \n\r?)
     229        c1 = strchr (c0, '\r'); // try \r for non-UNIX files
    223230      }
    224231      if (c1 == (char *) NULL) {
     
    229236      }
    230237      *c1 = 0; // mark the end of the line
     238      Nline_read ++;
     239
     240      if (Nline_read <= Nskip) { c0 = c1 + 1; continue; }
    231241
    232242      if (*c0 == '#') { c0 = c1 + 1; continue; }
Note: See TracChangeset for help on using the changeset viewer.