MCPcopy Create free account
hub / github.com/OpenPrinting/cups / write_file

Method write_file

ppdc/ppdc-source.cxx:3423–3801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3421//
3422
3423int // O - 0 on success, -1 on error
3424ppdcSource::write_file(const char *f) // I - File to write
3425{
3426 cups_file_t *fp; // Output file
3427 char bckname[1024]; // Backup file
3428 ppdcDriver *d; // Current driver
3429 ppdcString *st; // Current string
3430 ppdcAttr *a; // Current attribute
3431 ppdcConstraint *co; // Current constraint
3432 ppdcFilter *fi; // Current filter
3433 ppdcFont *fo; // Current font
3434 ppdcGroup *g; // Current group
3435 ppdcOption *o; // Current option
3436 ppdcChoice *ch; // Current choice
3437 ppdcProfile *p; // Current color profile
3438 ppdcMediaSize *si; // Current media size
3439 float left, // Current left margin
3440 bottom, // Current bottom margin
3441 right, // Current right margin
3442 top; // Current top margin
3443 int dtused[PPDC_DRIVER_MAX];// Driver type usage...
3444
3445
3446 // Rename the current file, if any, to .bck...
3447 snprintf(bckname, sizeof(bckname), "%s.bck", f);
3448 rename(f, bckname);
3449
3450 // Open the output file...
3451 fp = cupsFileOpen(f, "w");
3452
3453 if (!fp)
3454 {
3455 // Can't create file; restore backup and return...
3456 rename(bckname, f);
3457 return (-1);
3458 }
3459
3460 cupsFilePuts(fp, "// CUPS PPD Compiler " CUPS_SVERSION "\n\n");
3461
3462 // Include standard files...
3463 cupsFilePuts(fp, "// Include necessary files...\n");
3464 cupsFilePuts(fp, "#include <font.defs>\n");
3465 cupsFilePuts(fp, "#include <media.defs>\n");
3466
3467 memset(dtused, 0, sizeof(dtused));
3468
3469 for (d = (ppdcDriver *)drivers->first(); d; d = (ppdcDriver *)drivers->next())
3470 if (d->type > PPDC_DRIVER_PS && !dtused[d->type])
3471 {
3472 cupsFilePrintf(fp, "#include <%s.h>\n", driver_types[d->type]);
3473 dtused[d->type] = 1;
3474 }
3475
3476 // Output each driver...
3477 for (d = (ppdcDriver *)drivers->first(); d; d = (ppdcDriver *)drivers->next())
3478 {
3479 // Start the driver...
3480 cupsFilePrintf(fp, "\n// %s %s\n", d->manufacturer->value,

Callers 1

mainFunction · 0.80

Calls 6

cupsFileOpenFunction · 0.85
cupsFilePutsFunction · 0.85
cupsFilePrintfFunction · 0.85
cupsFileCloseFunction · 0.85
firstMethod · 0.80
nextMethod · 0.80

Tested by

no test coverage detected