| 712 | */ |
| 713 | |
| 714 | char * /* O - Line read or @code NULL@ on end of file or error */ |
| 715 | cupsFileGetConf(cups_file_t *fp, /* I - CUPS file */ |
| 716 | char *buf, /* O - String buffer */ |
| 717 | size_t buflen, /* I - Size of string buffer */ |
| 718 | char **value, /* O - Pointer to value */ |
| 719 | int *linenum) /* IO - Current line number */ |
| 720 | { |
| 721 | char *ptr; /* Pointer into line */ |
| 722 | |
| 723 | |
| 724 | /* |
| 725 | * Range check input... |
| 726 | */ |
| 727 | |
| 728 | DEBUG_printf(("2cupsFileGetConf(fp=%p, buf=%p, buflen=" CUPS_LLFMT ", value=%p, linenum=%p)", (void *)fp, (void *)buf, CUPS_LLCAST buflen, (void *)value, (void *)linenum)); |
| 729 | |
| 730 | if (!fp || (fp->mode != 'r' && fp->mode != 's') || !buf || buflen < 2 || !value) |
| 731 | { |
| 732 | if (value) |
| 733 | *value = NULL; |
| 734 | |
| 735 | return (NULL); |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | * Read the next non-comment line... |
| 740 | */ |
| 741 | |
| 742 | *value = NULL; |
| 743 | |
| 744 | while (cupsFileGets(fp, buf, buflen)) |
| 745 | { |
| 746 | (*linenum) ++; |
| 747 | |
| 748 | /* |
| 749 | * Handle escaped characters and strip any comments... |
| 750 | */ |
| 751 | |
| 752 | for (ptr = buf; *ptr; ptr ++) |
| 753 | { |
| 754 | if (*ptr == '#') |
| 755 | { |
| 756 | // Strip comment text... |
| 757 | *ptr = '\0'; |
| 758 | break; |
| 759 | } |
| 760 | else if (*ptr == '\\' && (ptr[1] == '\\' || ptr[1] == '#' || ptr[1] == 'n' || ptr[1] == 'r')) |
| 761 | { |
| 762 | /* |
| 763 | * \\, \#, \n, or \r, remove backslash and update the escaped char as |
| 764 | * needed... |
| 765 | */ |
| 766 | |
| 767 | _cups_strcpy(ptr, ptr + 1); |
| 768 | |
| 769 | if (*ptr == 'n') |
| 770 | *ptr = '\n'; |
| 771 | else if (*ptr == 'r') |