| 2962 | */ |
| 2963 | |
| 2964 | int /* O - 1 on success, 0 on failure */ |
| 2965 | _ppdCacheWriteFile( |
| 2966 | _ppd_cache_t *pc, /* I - PPD cache and mapping data */ |
| 2967 | const char *filename, /* I - File to write */ |
| 2968 | ipp_t *attrs) /* I - Attributes to write, if any */ |
| 2969 | { |
| 2970 | int i, j, k; /* Looping vars */ |
| 2971 | cups_file_t *fp; /* Output file */ |
| 2972 | pwg_size_t *size; /* Current size */ |
| 2973 | pwg_map_t *map; /* Current map */ |
| 2974 | _pwg_finishings_t *f; /* Current finishing option */ |
| 2975 | cups_option_t *option; /* Current option */ |
| 2976 | const char *value; /* String value */ |
| 2977 | char newfile[1024]; /* New filename */ |
| 2978 | |
| 2979 | |
| 2980 | /* |
| 2981 | * Range check input... |
| 2982 | */ |
| 2983 | |
| 2984 | if (!pc || !filename) |
| 2985 | { |
| 2986 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(EINVAL), 0); |
| 2987 | return (0); |
| 2988 | } |
| 2989 | |
| 2990 | /* |
| 2991 | * Open the file and write with compression... |
| 2992 | */ |
| 2993 | |
| 2994 | snprintf(newfile, sizeof(newfile), "%s.N", filename); |
| 2995 | if ((fp = cupsFileOpen(newfile, "w9")) == NULL) |
| 2996 | { |
| 2997 | _cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0); |
| 2998 | return (0); |
| 2999 | } |
| 3000 | |
| 3001 | /* |
| 3002 | * Standard header... |
| 3003 | */ |
| 3004 | |
| 3005 | cupsFilePrintf(fp, "#CUPS-PPD-CACHE-%d\n", _PPD_CACHE_VERSION); |
| 3006 | |
| 3007 | /* |
| 3008 | * Output bins... |
| 3009 | */ |
| 3010 | |
| 3011 | if (pc->num_bins > 0) |
| 3012 | { |
| 3013 | cupsFilePrintf(fp, "NumBins %d\n", pc->num_bins); |
| 3014 | for (i = pc->num_bins, map = pc->bins; i > 0; i --, map ++) |
| 3015 | cupsFilePrintf(fp, "Bin %s %s\n", map->pwg, map->ppd); |
| 3016 | } |
| 3017 | |
| 3018 | /* |
| 3019 | * Media sizes... |
| 3020 | */ |
| 3021 | |