@@ -374,6 +374,67 @@ char* fgets(char* buf, int max_size, FILE* fp) {
374
374
return nullptr ;
375
375
}
376
376
377
+ /* *
378
+ * @brief to get an arbitrary long input line and cut off any
379
+ * comment part
380
+ *
381
+ * the getline function is exaly like the __get_delim function
382
+ * in GNU with '\n' delimiter. As a result, to make the function
383
+ * behaviour identical for Windows (\r\n) and Linux (\n) compiler
384
+ * macros for checking operating systems have been used.
385
+ *
386
+ * @note user need to take care of the given pointer,
387
+ * which will be dynamically allocated by getdelim
388
+ */
389
+ char * getline (char *& _lineptr, FILE* _stream) {
390
+ int i;
391
+ int ch;
392
+ size_t _n = 0 ;
393
+ ssize_t nread;
394
+
395
+ #if defined(__unix__)
396
+ nread = getdelim (&_lineptr, &_n, ' \n ' , _stream);
397
+ #elif defined(_WIN32)
398
+ # define __WIN_NLTK " \r\n "
399
+ nread = getdelim (&_lineptr, &_n, __WIN_NLTK, _stream);
400
+ #endif
401
+
402
+ if (nread == -1 ) {
403
+ int errsv = errno;
404
+ std::string error_msg;
405
+
406
+ if (errsv == EINVAL)
407
+ error_msg = string_fmt (" [%s] Bad arguments (_lineptr is NULL, or _stream is not valid)." , strerror (errsv));
408
+ else if (errsv == ENOMEM)
409
+ error_msg = string_fmt (" [%s] Allocation or reallocation of the line buffer failed." , strerror (errsv));
410
+ else
411
+ /* end of file so it will return null */
412
+ return nullptr ;
413
+
414
+ /* getline was unsuccessful, so error */
415
+ throw VtrError (string_fmt (" Error -- %s\n " ,
416
+ error_msg),
417
+ __FILE__, __LINE__);
418
+ return nullptr ;
419
+ }
420
+
421
+ cont = 0 ; /* line continued? */
422
+ file_line_number++; /* global variable */
423
+
424
+ for (i = 0 ; i < nread; i++) { /* Keep going until the line finishes */
425
+
426
+ ch = _lineptr[i];
427
+
428
+ if (ch == ' #' ) { /* comment */
429
+ _lineptr[i] = ' \0 ' ;
430
+ /* skip the rest of the line */
431
+ break ;
432
+ }
433
+ }
434
+
435
+ return (_lineptr);
436
+ }
437
+
377
438
// /@brief Returns line number of last opened and read file
378
439
int get_file_line_number_of_last_opened_file () {
379
440
return file_line_number;
0 commit comments