int main(int argc, char **argv) { const char *filename = "pages.count"; int rc; unsigned long by = 1, count = 0; if (argc > 1) { if (sscanf(argv[1], "%lu", &by) != 1) { fprintf(stderr, ERRPREFIX "Illegal number: `%s'.\n", argv[1]); exit(EXIT_FAILURE); } if (argc > 2) filename = argv[2]; if (argc > 3) { fprintf(stderr, ERRPREFIX "Too many arguments.\n"); exit(EXIT_FAILURE); } } rc = pcf_getcount(filename, &count); if (rc == 0) printf("Initial count returned by pcf_getcount(): %lu.\n", count); else fprintf(stderr, "? Error from pcf_getcount(), return code is %d.\n", rc); rc = pcf_inccount(filename, by); exit(rc == 0? EXIT_SUCCESS: EXIT_FAILURE); }
int eprn_open_device(gx_device *device) { eprn_Eprn *eprn = &((eprn_Device *)device)->eprn; const char *epref = eprn->CUPS_messages? CUPS_ERRPREF: ""; int rc; #ifdef EPRN_TRACE if_debug0(EPRN_TRACE_CHAR, "! eprn_open_device()...\n"); #endif /* Checks on page size and determination of derived values */ if (eprn_set_page_layout((eprn_Device *)device) != 0) return_error(gs_error_rangecheck); /* Check the rendering parameters */ if (eprn_check_colour_info(eprn->cap->colour_info, &eprn->colour_model, &device->HWResolution[0], &device->HWResolution[1], &eprn->black_levels, &eprn->non_black_levels) != 0) { gs_param_string str; eprintf1("%s" ERRPREF "The requested combination of colour model (", epref); str.size = 0; if (eprn_get_string(eprn->colour_model, eprn_colour_model_list, &str) != 0) assert(0); /* Bug. No harm on NDEBUG because I've just set the size. */ errwrite(device->memory, (const char *)str.data, str.size * sizeof(str.data[0])); eprintf7("),\n" "%s resolution (%gx%g ppi) and intensity levels (%d, %d) is\n" "%s not supported by the %s.\n", epref, device->HWResolution[0], device->HWResolution[1], eprn->black_levels, eprn->non_black_levels, epref, eprn->cap->name); return_error(gs_error_rangecheck); } /* Initialization for colour rendering */ if (device->color_info.num_components == 4) { /* Native colour space is 'DeviceCMYK' */ set_dev_proc(device, map_rgb_color, NULL); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color_flex); else set_dev_proc(device, map_cmyk_color, &eprn_map_cmyk_color); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K); } else { set_dev_proc(device, map_cmyk_color, NULL); if (eprn->colour_model == eprn_DeviceRGB) { if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_max); else if (device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_RGB); } else { if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_max); else if (device->color_info.max_gray > 1 || device->color_info.max_color > 1) set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K_flex); else set_dev_proc(device, map_rgb_color, &eprn_map_rgb_color_for_CMY_or_K); } } eprn->output_planes = eprn_bits_for_levels(eprn->black_levels) + 3 * eprn_bits_for_levels(eprn->non_black_levels); #if !defined(GS_REVISION) || GS_REVISION >= 600 /* According to my understanding, the following call should be superfluous (because the colour mapping functions may not be called while the device is closed) and I am also not aware of any situation where it does make a difference. It shouldn't do any harm, though, and I feel safer with it :-) */ gx_device_decache_colors(device); #endif #ifndef EPRN_NO_PAGECOUNTFILE /* Read the page count value */ if (eprn->pagecount_file != NULL) { unsigned long count; if (pcf_getcount(eprn->pagecount_file, &count) == 0) device->PageCount = count; /* unsigned to signed. The C standard permits an implementation to generate an overflow indication if the value is too large. I consider this to mean that the type of 'PageCount' is inappropriate :-). Note that eprn does not use 'PageCount' for updating the file. */ else { /* pcf_getcount() has issued an error message. */ eprintf( " No further attempts will be made to access the page count file.\n"); gs_free(device->memory->non_gc_memory, eprn->pagecount_file, strlen(eprn->pagecount_file) + 1, sizeof(char), "eprn_open_device"); eprn->pagecount_file = NULL; } } #endif /* !EPRN_NO_PAGECOUNTFILE */ /* Open the "prn" device part */ if ((rc = gdev_prn_open(device)) != 0) return rc; /* Just in case a previous open call failed in a derived device (note that 'octets_per_line' is still the same as then): */ if (eprn->scan_line.str != NULL) gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->next_scan_line.str != NULL) { gs_free(device->memory->non_gc_memory, eprn->next_scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); eprn->next_scan_line.str = NULL; } /* Calls which might depend on prn having been initialized */ eprn->octets_per_line = gdev_prn_raster((gx_device_printer *)device); eprn->scan_line.str = (eprn_Octet *) gs_malloc(device->memory->non_gc_memory, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->intensity_rendering == eprn_IR_FloydSteinberg) { eprn->next_scan_line.str = (eprn_Octet *) gs_malloc(device->memory->non_gc_memory, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); if (eprn->next_scan_line.str == NULL && eprn->scan_line.str != NULL) { gs_free(device->memory->non_gc_memory, eprn->scan_line.str, eprn->octets_per_line, sizeof(eprn_Octet), "eprn_open_device"); eprn->scan_line.str = NULL; } } if (eprn->scan_line.str == NULL) { eprintf1("%s" ERRPREF "Memory allocation failure from gs_malloc() in eprn_open_device().\n", epref); return_error(gs_error_VMerror); } return rc; }