Make cupstestppd legacy#6
Conversation
ppd/ppd-test.c
Outdated
| * Include necessary headers... | ||
| */ | ||
|
|
||
| #include <cups/cups-private.h> |
There was a problem hiding this comment.
Do not use any "private" interfaces from CUPS, they are no stable APIs and only valid for code inside the CUPS of the version you have taken the cupstestppd.c from. Please remove this line and do not use any functions whose name starts with _cups. Please check these functions and check whether libppd (or libcupsfilters) contains them (or at least similar ones). I have overtaken several of them into libppd (but then renamed them to start with ppd or _ppd).
There was a problem hiding this comment.
_cupsSetLocale, _cupsLangPuts and _cupsLangPrintf is in langprintf.c in cups, an alternative of which is not present in libppd. Should I migrate langprintf.c to libppd as well?
There was a problem hiding this comment.
These functions are to set the user's UI language and to output the translations of given strings into the selected UI language. This way cupstestppd outputs its report in the user language if CUPS has appropriate translations.
In a first approach one could remove the _cupsSetLocale() call and replace the other functions by fputs() and fprintf() and the report will always be in English (the strings in the source code which are supplied to the functions).
Actually you should replace the calls by calls of the log function (which you supply to ppdTest() in its parameter list). You will also not have translations with that, but by simply replacing the log function with a more sophisticated one one could easily add translation support later.
But generally, I think translations are not that important here. PPD files are deprecated and will go away in the future, especially when the New Architecture is finally in place. So we should no put too much work into libppd and also, the former cupstestppd, provided via your port into libppd will mainly be used by retro-fitting Printer Applications to check the integrity of PPD files or by developers/maintainers of such Printer Applications to handle bug reports and support requests. Developers and maintainers usually understand English and translated logs are even counter-productive for them.
ppd/ppd-test.c
Outdated
|
|
||
| #include <cups/cups-private.h> | ||
| #include <cups/dir.h> | ||
| #include <cups/ppd-private.h> |
There was a problem hiding this comment.
Also remove this line, and check where functions with names starting with _ppd are used. check through libppd whether I have overtaken them. Using "private" functions of libppd is no problem, by the way, as you are in libppd here.
ppd/ppd.h
Outdated
| int q_with_v, int v_with_q, int root_present, int files, | ||
| cups_array_t *file_array, cups_array_t *stdin_array); | ||
|
|
||
| typedef struct ignore_parameters_s |
There was a problem hiding this comment.
Please use real bit fields here, not structs. bitfields are integer variables where each bit represents one boolean state and the bits are accessed via bit-wise AND and OR operations. Use the bitfields which the ppdTest() function is suing internally also as parameter for it and let main() of testppdfile.c do the |= to add the bits according to the user-supplied command line arguments.
ppd/testppdfile.c
Outdated
| WARN_ALL = 255 | ||
| }; | ||
|
|
||
|
|
There was a problem hiding this comment.
Please move these enums into ppd/ppd.h, as everyone who wants to call ppdTest() needs them. Then ppdTest() itself can use them, testppfile.ccan use them and everyone who does #include <ppd/ppd.h> for using ppdTest() ...
|
Otherwise it looks all OK now for me. Did you also check that everything uses either public APIs or any public or private API of libppd? No use of private APIs oCUPS and also PPD-related functions onl;y of libppd, not of CUPS. Also no |
According to what I have checked, there is not any function of "-private.h" of cups used in it. Also logging fuction has been used for everything and fprintf() or fputs() has not been used in ppd-test.c. However, puts has been used in testppdfile.h to get the user readable output. |
ppd/ppd.h
Outdated
| int files, cups_array_t *file_array); | ||
|
|
||
| //Error warning overrides... | ||
| typedef enum overrides_e |
There was a problem hiding this comment.
Could you move this type definition to the type definition section (enums) of ppd/ppd.h.
Could you also change the names to start with PPD_TEST_ or ppd_test_.
ppd/testppdfile.c
Outdated
|
|
||
| if (argv[i][0] == '-') | ||
| { | ||
| _ppdArrayAddStrings(file_array,""); |
There was a problem hiding this comment.
For these simple additions you could use cupsArrayNew() and cupsArrayAdd() instead off the functions of libppd's private API, to keep the private API inside libppd. Then you could also remove #include <ppd/array-private.h> at the top of the file.
|
Could you also change all the comments from |
|
Thanks for the changes, but there are some issues:
Please also compile the code and test some PPDs with the new utility to check whether you get the same results as with the original utility from CUPS. |
ppd/ppd-test.c
Outdated
| struct lconv *loc; // Locale data | ||
| int i, j, k, m, n; // Looping vars | ||
| size_t len; // Length of option name | ||
| const char *ptr; // Pointer into string |
There was a problem hiding this comment.
Could you run a "// " -> "// " over the code?
ppd/ppd-test.c
Outdated
| @@ -82,48 +83,48 @@ static int valid_path(const char *keyword, const char *path, int errors, | |||
| static int valid_utf8(const char *s); | |||
|
|
|||
|
|
|||
| //'ppdTest()' - Test the correctness of PPD files. | |||
| // 'ppdTest()' - Test the correctness of PPD files. | |||
|
|
|||
|
|
|||
| cups_array_t *ppdTest(int ignore, int warn, char *rootdir, | |||
There was a problem hiding this comment.
Could you have one line for each parameter and add a short comment for each parameter what it is for? See the other functions in libppd. Also these comments are used for auto-generation of documentation.
Is it not possible to use cupsArrayAdd in ppdTest as I believe it will serve the purpose better as compared to _ppdArrayAddStrings? |
|
What we want is a CUPS array where each element contains one line of the output text. |
ppd/testppdfile.c
Outdated
|
|
||
| (cupsArrayFirst(output)); | ||
| for (int j = 1; j< len_output; j++) | ||
| for (int j = 0; j< len_output-1; j++) |
There was a problem hiding this comment.
Also wrong. It must be
for (int j = 0; j < len_output; j++)
There was a problem hiding this comment.
The len_output includes the initialization value of " " for the array, which we don't want to be printed in the output screen, so I am using len_output-1 times looping so that " " is not printed in output screen.
There was a problem hiding this comment.
You do not need to add a " " line to the array to initialize it. The array is already initialized and accepts regular lines right after creating it with cupsArrayNew3(), when it is still empty. So do not add this empty line at the furst place.
There was a problem hiding this comment.
Now, I have removed the " " line. However, j will loop till len_output-1 as I am using cupsArrayNext as well within the loop, so in I use len_output instead, the length of array will be exceeded when calling cupsArrayNext and will give errors.
There was a problem hiding this comment.
For outputting all element of a CUPS array I even do not define an integer variable to count the element. I simply do
char *line;
for (line = (char *)cupsArrayFirst(output);
line;
line = (char *)cupsArrayNext(output))
puts(line);
This outputs all the elements of the array, without needing to get the number of elements and without treating the first element differently. You find this way to treat a CUPS array at many places in CUPS, libcupsfilters, and other OpenPrinting projects.
ppd/testppdfile.c
Outdated
| int files; // Number of files | ||
| cups_array_t *output; // Output array | ||
| int len_output; // Length of the output array | ||
| char *line; // Length of the output array |
There was a problem hiding this comment.
This is not the length of the output array any more ...
|
A suggestion to improve the architecture of the
|
|
I have edited the code I have suggested in the previous comment, concerning the " Also with this it is easy for a developer to use the |
Instead of making a new report variable can't the output variable be modified to perform this functionality? |
|
I want to make the return value of |
If PPD-test does not return the output array( for this matter the report array), then how can it be accessed by the testppdfile to provide the human readable output if the user wants the report to be shown? |
|
I hope you know the difference between call-by-value and call-by-reference. For getting the report back I put |
|
You call |
|
Looks great! Thank you. Did you compile and test it? Will have another look and if all is fine I will merge it. |
Yes, I did compile and test it. |
|
OK. Could you do the following corrections:
|
|
Now it looks all correct, but could you have another look through the indentation? It is 2 spaces per level. The tab width is 8 spaces (tab character fills up to the next 8-char grid line). See |
|
Your code produces tons of warnings. Could you fix them ASAP (with a new PR)? |
Sure I'll do it. |
I see that the warnings have been taken care of by you. Sorry that I couldn't look into it. I had an exam today so didn't get the time to do it. |
Migrated cupstestppd.c from cups to ppd-test.c in libppd to make it legacy.