-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the functionality of Preserved Comments in cupsd.conf when cups… #640
base: master
Are you sure you want to change the base?
Changes from 1 commit
4d13be6
b9c57d1
ccf71a9
d999b0d
1c0ae05
d08c54f
0a6b3b3
d351867
d92236a
f241386
952fd3f
7470d73
d9c1986
04b6730
07e9450
5150a47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -841,6 +841,142 @@ cupsFileGetConf(cups_file_t *fp, /* I - CUPS file */ | |
return (NULL); | ||
} | ||
|
||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the function definition to an alphabetically correct place in the file (under _cupsFileCheckFilter()) |
||
* 'cupsFileGetConfAndComments()' - Get a line and Comments from a configuration file. | ||
*/ | ||
|
||
char * /* O - Line read or @code NULL@ on end of file or error */ | ||
_cupsFileGetConfAndComments( | ||
cups_file_t *fp, /* I - CUPS file */ | ||
char *buf, /* O - String buffer */ | ||
size_t buflen, /* I - Size of string buffer */ | ||
char **value, /* O - Pointer to value */ | ||
int *linenum, /* IO - Current line number */ | ||
char *comment, /* I - Comment */ | ||
size_t commentlen) /* I - Size of comment buffer */ | ||
{ | ||
char *ptr; /* Pointer into line */ | ||
|
||
/* | ||
* Range check input... | ||
*/ | ||
|
||
DEBUG_printf(("2cupsFileGetConfAndComments(fp=%p, buf=%p, buflen=" CUPS_LLFMT | ||
", value=%p, linenum=%p, comment=%p, commentlen=" CUPS_LLFMT ", comment_linenum=%p)", (void *)fp, (void *)buf, CUPS_LLCAST buflen, (void *)value, (void *)linenum, (void *)comment, CUPS_LLCAST commentlen)); | ||
|
||
if (!fp || (fp->mode != 'r' && fp->mode != 's') || | ||
!buf || buflen < 2 || !value || !comment || commentlen<2) | ||
{ | ||
if (value) | ||
*value = NULL; | ||
|
||
return (NULL); | ||
} | ||
|
||
/* | ||
* Read the next non-comment line... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy&paste remain... |
||
*/ | ||
|
||
*value = NULL; | ||
|
||
while (cupsFileGets(fp, buf, buflen)) | ||
{ | ||
(*linenum) ++; | ||
|
||
/* | ||
* Strip any comments... | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy and paste leftover. |
||
*/ | ||
|
||
if ((ptr = strchr(buf, '#')) != NULL) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we go with passing comments via There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zdohnal I made the changes as you requested. Now I 'm using line variable to get comments. Please review them. |
||
if (ptr > buf && ptr[-1] == '\\') | ||
{ | ||
// Unquote the #... | ||
_cups_strcpy(ptr - 1, ptr); | ||
} | ||
else | ||
{ | ||
// Strip the comment and any trailing whitespace... | ||
while (ptr > buf) | ||
{ | ||
if (!_cups_isspace(ptr[-1])) | ||
break; | ||
|
||
ptr --; | ||
} | ||
|
||
_cups_strcpy(comment, buf); | ||
*ptr = '\0'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will become a dead code if we return before that. Additionally I've realized we should deal with inline comments in case they appear (even though they are prohibited by cupsd.conf man page) in a way. So I propose:
So the block |
||
} | ||
} | ||
|
||
/* | ||
* Strip leading whitespace... | ||
*/ | ||
|
||
for (ptr = buf; _cups_isspace(*ptr); ptr ++); | ||
|
||
if (ptr > buf) | ||
_cups_strcpy(buf, ptr); | ||
|
||
/* | ||
* See if there is anything left... | ||
*/ | ||
|
||
if (buf[0]) | ||
{ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we could check whether the first char is # and if so, return buf. With appropriate comment. |
||
* Yes, grab any value and return... | ||
*/ | ||
|
||
for (ptr = buf; *ptr; ptr ++) | ||
if (_cups_isspace(*ptr)) | ||
break; | ||
|
||
if (*ptr) | ||
{ | ||
/* | ||
* Have a value, skip any other spaces... | ||
*/ | ||
|
||
while (_cups_isspace(*ptr)) | ||
*ptr++ = '\0'; | ||
|
||
if (*ptr) | ||
*value = ptr; | ||
|
||
/* | ||
* Strip trailing whitespace and > for lines that begin with <... | ||
*/ | ||
|
||
ptr += strlen(ptr) - 1; | ||
|
||
if (buf[0] == '<' && *ptr == '>') | ||
*ptr-- = '\0'; | ||
else if (buf[0] == '<' && *ptr != '>') | ||
{ | ||
/* | ||
* Syntax error... | ||
*/ | ||
|
||
*value = NULL; | ||
return (buf); | ||
} | ||
|
||
while (ptr > *value && _cups_isspace(*ptr)) | ||
*ptr-- = '\0'; | ||
} | ||
|
||
/* | ||
* Return the line... | ||
*/ | ||
|
||
return (buf); | ||
} | ||
} | ||
|
||
return (NULL); | ||
} | ||
|
||
/* | ||
* 'cupsFileGetLine()' - Get a CR and/or LF-terminated line that may | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about returning the comment via
line
parameter and remove the new additional parameters? Then the comment printout can happen via last cupsFilePrintf(). WDYT?