/* Get the BuildChar and/or BuildGlyph routines from a (base) font. */ int build_gs_font_procs(os_ptr op, build_proc_refs * pbuild) { int ccode, gcode; ref *pBuildChar; ref *pBuildGlyph; check_type(*op, t_dictionary); ccode = dict_find_string(op, "BuildChar", &pBuildChar); gcode = dict_find_string(op, "BuildGlyph", &pBuildGlyph); if (ccode <= 0) { if (gcode <= 0) return_error(e_invalidfont); make_null(&pbuild->BuildChar); } else { check_proc(*pBuildChar); pbuild->BuildChar = *pBuildChar; } if (gcode <= 0) make_null(&pbuild->BuildGlyph); else { check_proc(*pBuildGlyph); pbuild->BuildGlyph = *pBuildGlyph; } return 0; }
static int zpathforall(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_path_enum *penum; int code; check_proc(op[-3]); check_proc(op[-2]); check_proc(op[-1]); check_proc(*op); check_estack(8); if ((penum = gs_path_enum_alloc(imemory, "pathforall")) == 0) return_error(e_VMerror); code = gs_path_enum_init(penum, igs); if (code < 0) { ifree_object(penum, "path_cleanup"); return code; } /* Push a mark, the four procedures, and the path enumerator. */ push_mark_estack(es_for, path_cleanup); /* iterator */ memcpy(esp + 1, op - 3, 4 * sizeof(ref)); /* 4 procs */ esp += 5; make_istruct(esp, 0, penum); push_op_estack(path_continue); pop(4); op -= 4; return o_push_estack; }
static void check_proc(Lextok *now, int m) { if (!now) return; if (now->ntyp == '@' || now->ntyp == RUN) { fprintf(tb, ";\n\t\t"); undostmnt(now, m); } check_proc(now->lft, m); check_proc(now->rgt, m); }
/* <proc> <string> kshow - */ static int zkshow(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_text_enum_t *penum; int code; check_read_type(*op, t_string); check_proc(op[-1]); /* * Per PLRM Section xx.x, kshow is illegal if the current font is a * composite font. The graphics library does not have this limitation, * so we check for it here. */ if (gs_currentfont(igs)->FontType == ft_composite) return_error(e_invalidfont); if ((code = op_show_setup(i_ctx_p, op)) != 0 || (code = gs_kshow_begin(igs, op->value.bytes, r_size(op), imemory, &penum)) < 0) return code; *(op_proc_t *)&penum->enum_client_data = zkshow; if ((code = op_show_finish_setup(i_ctx_p, penum, 2, finish_show)) < 0) { ifree_object(penum, "op_show_enum_setup"); return code; } sslot = op[-1]; /* save kerning proc */ return op_show_continue_pop(i_ctx_p, 2); }
/* <redproc> <greenproc> <blueproc> <grayproc> setcolortransfer - */ static int zsetcolortransfer(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; check_proc(op[-3]); check_proc(op[-2]); check_proc(op[-1]); check_proc(*op); check_ostack(zcolor_remap_one_ostack * 4 - 4); check_estack(1 + zcolor_remap_one_estack * 4); istate->transfer_procs.red = op[-3]; istate->transfer_procs.green = op[-2]; istate->transfer_procs.blue = op[-1]; istate->transfer_procs.gray = *op; if ((code = gs_setcolortransfer_remap(igs, gs_mapped_transfer, gs_mapped_transfer, gs_mapped_transfer, gs_mapped_transfer, false)) < 0 ) return code; /* Use osp rather than op here, because zcolor_remap_one pushes. */ pop(4); push_op_estack(zcolor_reset_transfer); if ((code = zcolor_remap_one(i_ctx_p, &istate->transfer_procs.red, igs->set_transfer.red, igs, zcolor_remap_one_finish)) < 0 || (code = zcolor_remap_one(i_ctx_p, &istate->transfer_procs.green, igs->set_transfer.green, igs, zcolor_remap_one_finish)) < 0 || (code = zcolor_remap_one(i_ctx_p, &istate->transfer_procs.blue, igs->set_transfer.blue, igs, zcolor_remap_one_finish)) < 0 || (code = zcolor_remap_one(i_ctx_p, &istate->transfer_procs.gray, igs->set_transfer.gray, igs, zcolor_remap_one_finish)) < 0 ) return code; return o_push_estack; }
/* <bool> <proc_true> <proc_false> ifelse - */ int zifelse(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_proc(*op); check_proc(op[-1]); check_type(op[-2], t_boolean); check_estack(1); ++esp; if (op[-2].value.boolval) { ref_assign(esp, op - 1); } else { ref_assign(esp, op); } esfile_check_cache(); pop(3); return o_push_estack; }
int zfor(i_ctx_t *i_ctx_p) { os_ptr op = osp; register es_ptr ep; int code; float params[3]; /* Mostly undocumented, and somewhat bizarre Adobe behavior discovered */ /* with the CET (28-05) and FTS (124-01) is that the proc is not run */ /* if BOTH the initial value and increment are zero. */ if ((code = float_params(op - 1, 3, params)) < 0) return code; if ( params[0] == 0.0 && params[1] == 0.0 ) { pop(4); /* don't run the proc */ return 0; } check_estack(7); ep = esp + 6; check_proc(*op); /* Push a mark, the control variable set to the initial value, */ /* the increment, the limit, and the procedure, */ /* and invoke the continuation operator. */ if (r_has_type(op - 3, t_integer) && r_has_type(op - 2, t_integer) ) { make_int(ep - 4, op[-3].value.intval); make_int(ep - 3, op[-2].value.intval); switch (r_type(op - 1)) { case t_integer: make_int(ep - 2, op[-1].value.intval); break; case t_real: make_int(ep - 2, (long)op[-1].value.realval); break; default: return_op_typecheck(op - 1); } if (ep[-3].value.intval >= 0) make_op_estack(ep, for_pos_int_continue); else make_op_estack(ep, for_neg_int_continue); } else { make_real(ep - 4, params[0]); make_real(ep - 3, params[1]); make_real(ep - 2, params[2]); make_op_estack(ep, for_real_continue); } make_mark_estack(ep - 5, es_for, no_cleanup); ref_assign(ep - 1, op); esp = ep; pop(4); return o_push_estack; }
/* * <proc> .isencapfunction <bool> * * This routine checks if a given Postscript procedure is an "encapsulated" * function of the type made by .buildfunction. These functions can then * be executed without executing the interpreter. These functions can be * executed directly from within C code inside the graphics library. */ static int zisencapfunction(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_function_t *pfn; check_proc(*op); pfn = ref_function(op); make_bool(op, pfn != NULL); return 0; }
/* Get parameters for a single screen. */ int zscreen_params(os_ptr op, gs_screen_halftone * phs) { double fa[2]; int code = num_params(op - 1, 2, fa); if (code < 0) return code; check_proc(*op); phs->frequency = fa[0]; phs->angle = fa[1]; return 0; }
static int zloop(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_proc(*op); check_estack(4); /* Push a mark and the procedure, and invoke */ /* the continuation operator. */ push_mark_estack(es_for, no_cleanup); *++esp = *op; make_op_estack(esp + 1, loop_continue); pop(1); return loop_continue(i_ctx_p); }
static int zforall(i_ctx_t *i_ctx_p) { os_ptr op = osp; os_ptr obj = op - 1; es_ptr ep = esp; es_ptr cproc = ep + 4; check_estack(6); check_proc(*op); switch (r_type(obj)) { default: return_op_typecheck(obj); case t_array: check_read(*obj); make_op_estack(cproc, array_continue); break; case t_dictionary: check_dict_read(*obj); make_int(cproc, dict_first(obj)); ++cproc; make_op_estack(cproc, dict_continue); break; case t_string: check_read(*obj); make_op_estack(cproc, string_continue); break; case t_mixedarray: case t_shortarray: check_read(*obj); make_op_estack(cproc, packedarray_continue); break; } /* * Push: * - a mark; * - the composite object; * - the procedure; * - the iteration index (only for dictionaries, done above); * and invoke the continuation operator. */ make_mark_estack(ep + 1, es_for, forall_cleanup); ep[2] = *obj; ep[3] = *op; esp = cproc - 1; pop(2); return (*real_opproc(cproc))(i_ctx_p); }
/* <bool> <proc> if - */ int zif(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_proc(*op); check_type(op[-1], t_boolean); if (op[-1].value.boolval) { check_estack(1); ++esp; ref_assign(esp, op); esfile_check_cache(); } pop(2); return o_push_estack; }
int init_process_iterator(struct process_iterator *it, struct process_filter *filter) { if (!check_proc()) { fprintf(stderr, "procfs is not mounted!\nAborting\n"); exit(-2); } //open a directory stream to /proc directory if ((it->dip = opendir("/proc")) == NULL) { perror("opendir"); return -1; } it->filter = filter; it->boot_time = get_boot_time(); return 0; }
/* * Get a procedure from a dictionary. If the key is missing, * defaultval = false means substitute t__invalid; * defaultval = true means substitute an empty procedure. * In either case, return 1. */ int dict_proc_param(const ref * pdict, const char *kstr, ref * pproc, bool defaultval) { ref *pdval; if (pdict == 0 || dict_find_string(pdict, kstr, &pdval) <= 0) { if (defaultval) make_empty_const_array(pproc, a_readonly + a_executable); else make_t(pproc, t__invalid); return 1; } check_proc(*pdval); *pproc = *pdval; return 0; }
int zrepeat(i_ctx_t *i_ctx_p) { os_ptr op = osp; check_proc(*op); check_type(op[-1], t_integer); if (op[-1].value.intval < 0) return_error(e_rangecheck); check_estack(5); /* Push a mark, the count, and the procedure, and invoke */ /* the continuation operator. */ push_mark_estack(es_for, no_cleanup); *++esp = op[-1]; *++esp = *op; make_op_estack(esp + 1, repeat_continue); pop(2); return repeat_continue(i_ctx_p); }
/* <proc> setblackgeneration - */ static int zsetblackgeneration(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; check_proc(*op); check_ostack(zcolor_remap_one_ostack - 1); check_estack(1 + zcolor_remap_one_estack); code = gs_setblackgeneration_remap(igs, gs_mapped_transfer, false); if (code < 0) return code; istate->black_generation = *op; pop(1); push_op_estack(zcolor_remap_color); return zcolor_remap_one(i_ctx_p, &istate->black_generation, igs->black_generation, igs, zcolor_remap_one_finish); }
/* <proc> setundercolorremoval - */ static int zsetundercolorremoval(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; check_proc(*op); check_ostack(zcolor_remap_one_ostack - 1); check_estack(1 + zcolor_remap_one_estack); code = gs_setundercolorremoval_remap(igs, gs_mapped_transfer, false); if (code < 0) return code; istate->undercolor_removal = *op; pop(1); push_op_estack(zcolor_remap_color); return zcolor_remap_one(i_ctx_p, &istate->undercolor_removal, igs->undercolor_removal, igs, zcolor_remap_one_signed_finish); }
static int zfilenameforall(i_ctx_t *i_ctx_p) { os_ptr op = osp; file_enum *pfen; gx_io_device *iodev = NULL; gs_parsed_file_name_t pname; int code = 0; check_write_type(*op, t_string); check_proc(op[-1]); check_read_type(op[-2], t_string); /* Push a mark, the iodev, devicenamelen, the scratch string, the enumerator, */ /* and the procedure, and invoke the continuation. */ check_estack(7); /* Get the iodevice */ code = parse_file_name(op - 2, &pname, i_ctx_p->LockFilePermissions); if (code < 0) return code; iodev = (pname.iodev == NULL) ? iodev_default : pname.iodev; /* Check for several conditions that just cause us to return success */ if (pname.len == 0 || iodev->procs.enumerate_files == iodev_no_enumerate_files) { pop(3); return 0; /* no pattern, or device not found -- just return */ } pfen = iodev->procs.enumerate_files(iodev, (const char *)pname.fname, pname.len, imemory); if (pfen == 0) return_error(e_VMerror); push_mark_estack(es_for, file_cleanup); ++esp; make_istruct(esp, 0, iodev); ++esp; make_int(esp, r_size(op-2) - pname.len); *++esp = *op; ++esp; make_istruct(esp, 0, pfen); *++esp = op[-1]; pop(3); code = file_continue(i_ctx_p); return (code == o_pop_estack ? o_push_estack : code); }
/* <function_proc> <array> .scalefunction <function_proc> */ static int zscalefunction(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_function_t *pfn; gs_function_t *psfn; gs_range_t *ranges; int code; uint i; check_proc(op[-1]); pfn = ref_function(op - 1); if (pfn == 0 || !r_is_array(op)) return_error(gs_error_typecheck); if (r_size(op) != 2 * pfn->params.n) return_error(gs_error_rangecheck); ranges = (gs_range_t *) gs_alloc_byte_array(imemory, pfn->params.n, sizeof(gs_range_t), "zscalefunction"); if (ranges == 0) return_error(gs_error_VMerror); for (i = 0; i < pfn->params.n; ++i) { ref rval[2]; float val[2]; if ((code = array_get(op, 2 * i, &rval[0])) < 0 || (code = array_get(op, 2 * i + 1, &rval[1])) < 0 || (code = float_params(rval + 1, 2, val)) < 0) return code; ranges[i].rmin = val[0]; ranges[i].rmax = val[1]; } code = gs_function_make_scaled(pfn, &psfn, ranges, imemory); gs_free_object(imemory, ranges, "zscalefunction"); if (code < 0 || (code = make_function_proc(i_ctx_p, op - 1, psfn)) < 0) { gs_function_free(psfn, true, imemory); return code; } pop(1); return 0; }
int32 check_file_type( byte *data, dword data_len ) { int ret; int i; ASSERT( NULL != data ); ASSERT( 0 <= data_len ); for( i = 0; i < sizeof( g_check_file_funcs ) / sizeof( void* ); i ++ ) { check_this_file_type *check_proc; check_proc = ( check_this_file_type* )g_check_file_funcs[ i ]; ret = check_proc( data, data_len ); if( 0 <= ret ) { return ret; } } return -1; }
/* <name> <proc> .makeoperator <oper> */ static int zmakeoperator(i_ctx_t *i_ctx_p) { os_ptr op = osp; op_array_table *opt; uint count; ref *tab; check_type(op[-1], t_name); check_proc(*op); switch (r_space(op)) { case avm_global: opt = &i_ctx_p->op_array_table_global; break; case avm_local: opt = &i_ctx_p->op_array_table_local; break; default: return_error(e_invalidaccess); } count = opt->count; tab = opt->table.value.refs; /* * restore doesn't reset op_array_table.count, but it does * remove entries from op_array_table.table. Since we fill * the table in order, we can detect that a restore has occurred * by checking whether what should be the most recent entry * is occupied. If not, we scan backwards over the vacated entries * to find the true end of the table. */ while (count > 0 && r_has_type(&tab[count - 1], t_null)) --count; if (count == r_size(&opt->table)) return_error(e_limitcheck); ref_assign_old(&opt->table, &tab[count], op, "makeoperator"); opt->nx_table[count] = name_index(imemory, op - 1); op_index_ref(imemory, opt->base_index + count, op - 1); opt->count = count + 1; pop(1); return 0; }
/* <first> <count> <last> <proc> %for_samples - */ int zfor_samples(i_ctx_t *i_ctx_p) { os_ptr op = osp; es_ptr ep; check_type(op[-3], t_real); check_type(op[-2], t_integer); check_type(op[-1], t_real); check_proc(*op); check_estack(8); ep = esp + 7; make_mark_estack(ep - 6, es_for, no_cleanup); make_int(ep - 5, 0); memcpy(ep - 4, op - 3, 3 * sizeof(ref)); ref_assign(ep - 1, op); make_op_estack(ep, for_samples_continue); esp = ep; pop(4); return o_push_estack; }
/* * Collect data for a type 0 (sampled data) function * <dict> .buildsampledfunction <function_struct> * * The following keys are used from the dictionary: * Function (required) * Domain (required) * Range (required) * Size (optional) If Size is not specified then a default value is determined * based upon the number of inputs and outputs. * BitsPerSample (required) Only 8, 16, 24, and 32 accepted, * The remaining keys are ignored. */ static int zbuildsampledfunction(i_ctx_t *i_ctx_p) { os_ptr op = osp; const ref * pdict = op; ref * pfunc; int code = 0; gs_function_t *pfn; gs_function_Sd_params_t params = {0}; check_type(*pdict, t_dictionary); /* * Check procedure to be sampled. */ if (dict_find_string(pdict, "Function", &pfunc) <= 0) return_error(e_rangecheck); check_proc(*pfunc); /* * Set up the hyper cube function data structure. */ code = cube_build_func0(pdict, ¶ms, imemory); if (code < 0) return code; /* * This is temporary. We will call gs_function_Sd_init again after * we have collected the cube data. We are doing it now because we need * a function structure created (along with its GC enumeration stuff) * that we can use while collecting the cube data. We will call * the routine again after the cube data is collected to correctly * initialize the function. */ code = gs_function_Sd_init(&pfn, ¶ms, imemory); if (code < 0) return code; /* * Now setup to collect the sample data. */ return sampled_data_setup(i_ctx_p, pfn, pfunc, sampled_data_finish, imemory); }
static int do_test (int argc, char **argv) { int fails; get_cpuinfo (); fails = check_proc ("avx", HAS_AVX, "HAS_AVX"); fails += check_proc ("fma4", HAS_FMA4, "HAS_FMA4"); fails += check_proc ("sse4_2", HAS_SSE4_2, "HAS_SSE4_2"); fails += check_proc ("sse4_1", HAS_SSE4_1, "HAS_SSE4_1"); fails += check_proc ("ssse3", HAS_SSSE3, "HAS_SSSE3"); fails += check_proc ("popcnt", HAS_POPCOUNT, "HAS_POPCOUNT"); printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails); return (fails != 0); }
static int do_test (int argc, char **argv) { int fails; get_cpuinfo (); fails = check_proc ("avx", HAS_ARCH_FEATURE (AVX_Usable), "HAS_ARCH_FEATURE (AVX_Usable)"); fails += check_proc ("fma4", HAS_ARCH_FEATURE (FMA4_Usable), "HAS_ARCH_FEATURE (FMA4_Usable)"); fails += check_proc ("sse4_2", HAS_CPU_FEATURE (SSE4_2), "HAS_CPU_FEATURE (SSE4_2)"); fails += check_proc ("sse4_1", HAS_CPU_FEATURE (SSE4_1) , "HAS_CPU_FEATURE (SSE4_1)"); fails += check_proc ("ssse3", HAS_CPU_FEATURE (SSSE3), "HAS_CPU_FEATURE (SSSE3)"); fails += check_proc ("popcnt", HAS_CPU_FEATURE (POPCOUNT), "HAS_CPU_FEATURE (POPCOUNT)"); printf ("%d differences between /proc/cpuinfo and glibc code.\n", fails); return (fails != 0); }
void undostmnt(Lextok *now, int m) { Lextok *v; int i, j; if (!now) { fprintf(tb, "0"); return; } lineno = now->ln; Fname = now->fn; switch (now->ntyp) { case CONST: case '!': case UMIN: case '~': case '/': case '*': case '-': case '+': case '%': case LT: case GT: case '&': case '|': case LE: case GE: case NE: case EQ: case OR: case AND: case LSHIFT: case RSHIFT: case TIMEOUT: case LEN: case NAME: case FULL: case EMPTY: case 'R': case NFULL: case NEMPTY: case ENABLED: case '?': case PC_VAL: case '^': case C_EXPR: case GET_P: case NONPROGRESS: putstmnt(tb, now, m); break; case RUN: fprintf(tb, "delproc(0, now._nr_pr-1)"); break; case 's': if (Pid == eventmapnr) break; if (m_loss) fprintf(tb, "if (_m == 2) "); putname(tb, "_m = unsend(", now->lft, m, ")"); break; case 'r': if (Pid == eventmapnr) break; for (v = now->rgt, i=j=0; v; v = v->rgt, i++) if (v->lft->ntyp != CONST && v->lft->ntyp != EVAL) j++; if (j == 0 && now->val >= 2) break; /* poll without side-effect */ { int ii = 0, jj; for (v = now->rgt; v; v = v->rgt) if ((v->lft->ntyp != CONST && v->lft->ntyp != EVAL)) ii++; /* nr of things bupped */ if (now->val == 1) { ii++; jj = multi_oval - ii - 1; fprintf(tb, "XX = trpt->bup.oval"); if (multi_oval > 0) { fprintf(tb, "s[%d]", jj); jj++; } fprintf(tb, ";\n\t\t"); } else { fprintf(tb, "XX = 1;\n\t\t"); jj = multi_oval - ii - 1; } if (now->val < 2) /* not for channel poll */ for (v = now->rgt, i = 0; v; v = v->rgt, i++) { switch(v->lft->ntyp) { case CONST: case EVAL: fprintf(tb, "unrecv"); putname(tb, "(", now->lft, m, ", XX-1, "); fprintf(tb, "%d, ", i); if (v->lft->ntyp == EVAL) undostmnt(v->lft->lft, m); else undostmnt(v->lft, m); fprintf(tb, ", %d);\n\t\t", (i==0)?1:0); break; default: fprintf(tb, "unrecv"); putname(tb, "(", now->lft, m, ", XX-1, "); fprintf(tb, "%d, ", i); if (v->lft->sym && !strcmp(v->lft->sym->name, "_")) { fprintf(tb, "trpt->bup.oval"); if (multi_oval > 0) fprintf(tb, "s[%d]", jj); } else putstmnt(tb, v->lft, m); fprintf(tb, ", %d);\n\t\t", (i==0)?1:0); if (multi_oval > 0) jj++; break; } } jj = multi_oval - ii - 1; if (now->val == 1 && multi_oval > 0) jj++; /* new 3.4.0 */ for (v = now->rgt, i = 0; v; v = v->rgt, i++) { switch(v->lft->ntyp) { case CONST: case EVAL: break; default: if (!v->lft->sym || strcmp(v->lft->sym->name, "_") != 0) { nocast=1; putstmnt(tb,v->lft,m); nocast=0; fprintf(tb, " = trpt->bup.oval"); if (multi_oval > 0) fprintf(tb, "s[%d]", jj); fprintf(tb, ";\n\t\t"); } if (multi_oval > 0) jj++; break; } } multi_oval -= ii; } break; case '@': fprintf(tb, "p_restor(II);\n\t\t"); break; case SET_P: fprintf(tb, "((P0 *)pptr((trpt->o_priority >> 8)))"); fprintf(tb, "->_priority = trpt->o_priority & 255"); break; case ASGN: if (check_track(now) == STRUCT) { break; } nocast=1; putstmnt(tb,now->lft,m); nocast=0; fprintf(tb, " = trpt->bup.oval"); if (multi_oval > 0) { multi_oval--; fprintf(tb, "s[%d]", multi_oval-1); } check_proc(now->rgt, m); break; case 'c': check_proc(now->lft, m); break; case '.': case GOTO: case ELSE: case BREAK: break; case C_CODE: fprintf(tb, "sv_restor();\n"); break; case ASSERT: case PRINT: check_proc(now, m); break; case PRINTM: break; default: printf("spin: bad node type %d (.b)\n", now->ntyp); alldone(1); } }
/* The current color space is the alternate space for the DeviceN space. */ static int zsetdevicenspace(i_ctx_t *i_ctx_p) { os_ptr op = osp; const ref *pcsa; gs_separation_name *names; gs_device_n_map *pmap; uint num_components; gs_color_space *pcs; gs_color_space *pacs; ref_colorspace cspace_old; gs_function_t *pfn; int code; /* Verify that we have an array as our input parameter */ check_read_type(*op, t_array); if (r_size(op) < 4 || r_size(op) > 5) return_error(e_rangecheck); /* pcsa is a pointer to the color names array (element 1 in input array) */ pcsa = op->value.const_refs + 1; if (!r_is_array(pcsa)) return_error(e_typecheck); num_components = r_size(pcsa); if (num_components == 0) return_error(e_rangecheck); if (num_components > GS_CLIENT_COLOR_MAX_COMPONENTS) return_error(e_limitcheck); /* Check tint transform procedure. Note: Cheap trick to get pointer to it. The tint transform procedure is element 3 in the input array */ check_proc(pcsa[2]); /* The alternate color space has been selected as the current color space */ pacs = gs_currentcolorspace(igs); code = gs_cspace_new_DeviceN(&pcs, num_components, pacs, imemory); if (code < 0) return code; names = pcs->params.device_n.names; pmap = pcs->params.device_n.map; pcs->params.device_n.get_colorname_string = gs_get_colorname_string; /* Pick up the names of the components */ { uint i; ref sname; for (i = 0; i < num_components; ++i) { array_get(imemory, pcsa, (long)i, &sname); switch (r_type(&sname)) { case t_string: code = name_from_string(imemory, &sname, &sname); if (code < 0) { rc_decrement(pcs, ".setdevicenspace"); return code; } /* falls through */ case t_name: names[i] = name_index(imemory, &sname); break; default: rc_decrement(pcs, ".setdevicenspace"); return_error(e_typecheck); } } } /* Now set the current color space as DeviceN */ cspace_old = istate->colorspace; /* * pcsa is a pointer to element 1 (2nd element) in the DeviceN * description array. Thus pcsa[2] is element #3 (4th element) * which is the tint transform. */ istate->colorspace.procs.special.device_n.layer_names = pcsa[0]; istate->colorspace.procs.special.device_n.tint_transform = pcsa[2]; pfn = ref_function(pcsa + 2); /* See comment above */ if (!pfn) code = gs_note_error(e_rangecheck); if (code < 0) { istate->colorspace = cspace_old; rc_decrement_only(pcs, "zsetdevicenspace"); return code; } gs_cspace_set_devn_function(pcs, pfn); code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only(pcs, "zsetdevicenspace"); if (code < 0) { istate->colorspace = cspace_old; return code; } pop(1); return 0; }
/* The current color space is the alternate space for the separation space. */ static int zsetseparationspace(i_ctx_t *i_ctx_p) { os_ptr op = osp; const ref *pcsa; gs_color_space *pcs; gs_color_space * pacs; ref_colorspace cspace_old; ref sname, name_none, name_all; gs_function_t *pfn = NULL; separation_type sep_type; int code; const gs_memory_t * mem = imemory; /* Verify that we have an array as our input parameter */ check_read_type(*op, t_array); if (r_size(op) != 4) return_error(e_rangecheck); /* The alternate color space has been selected as the current color space */ pacs = gs_currentcolorspace(igs); if (!pacs->type->can_be_alt_space) return_error(e_rangecheck); /* * pcsa is a pointer to element 1 (2nd element) in the Separation colorspace * description array. Thus pcsa[2] is element #3 (4th element) which is the * tint transform. */ pcsa = op->value.const_refs + 1; sname = *pcsa; switch (r_type(&sname)) { default: return_error(e_typecheck); case t_string: code = name_from_string(mem, &sname, &sname); if (code < 0) return code; /* falls through */ case t_name: break; } if ((code = name_ref(mem, (const byte *)"All", 3, &name_all, 0)) < 0) return code; if ((code = name_ref(mem, (const byte *)"None", 4, &name_none, 0)) < 0) return code; sep_type = ( name_eq(&sname, &name_all) ? SEP_ALL : name_eq(&sname, &name_none) ? SEP_NONE : SEP_OTHER); /* Check tint transform procedure. */ /* See comment above about psca */ check_proc(pcsa[2]); pfn = ref_function(pcsa + 2); if (pfn == NULL) return_error(e_rangecheck); cspace_old = istate->colorspace; /* Now set the current color space as Separation */ code = gs_cspace_new_Separation(&pcs, pacs, imemory); if (code < 0) return code; pcs->params.separation.sep_type = sep_type; pcs->params.separation.sep_name = name_index(mem, &sname); pcs->params.separation.get_colorname_string = gs_get_colorname_string; istate->colorspace.procs.special.separation.layer_name = pcsa[0]; istate->colorspace.procs.special.separation.tint_transform = pcsa[2]; if (code >= 0) code = gs_cspace_set_sepr_function(pcs, pfn); if (code >= 0) code = gs_setcolorspace(igs, pcs); /* release reference from construction */ rc_decrement_only(pcs, "zsetseparationspace"); if (code < 0) { istate->colorspace = cspace_old; return code; } pop(1); return 0; }
int main(int argc, char **argv) { //argument variables const char *exe = NULL; int perclimit = 0; int exe_ok = 0; int pid_ok = 0; int limit_ok = 0; pid_t pid = 0; int ignore_children = 0; //get program name char *p=(char*)memrchr(argv[0],(unsigned int)'/',strlen(argv[0])); program_name = p==NULL?argv[0]:(p+1); //get current pid cpulimit_pid = getpid(); //get cpu count NCPU = get_ncpu(); //parse arguments int next_option; int option_index = 0; //A string listing valid short options letters const char* short_options = "+p:e:l:vzih"; //An array describing valid long options const struct option long_options[] = { { "pid", required_argument, NULL, 'p' }, { "exe", required_argument, NULL, 'e' }, { "limit", required_argument, NULL, 'l' }, { "verbose", no_argument, NULL, 'v' }, { "lazy", no_argument, NULL, 'z' }, { "ignore-children", no_argument, NULL, 'i' }, { "help", no_argument, NULL, 'h' }, { 0, 0, 0, 0 } }; do { next_option = getopt_long(argc, argv, short_options,long_options, &option_index); switch(next_option) { case 'p': pid = atoi(optarg); pid_ok = 1; break; case 'e': exe = optarg; exe_ok = 1; break; case 'l': perclimit = atoi(optarg); limit_ok = 1; break; case 'v': verbose = 1; break; case 'z': lazy = 1; break; case 'i': ignore_children = 1; break; case 'h': print_usage(stdout, 1); break; case '?': print_usage(stderr, 1); break; case -1: break; default: abort(); } } while(next_option != -1); if (pid_ok && (pid<=1 || pid>=65536)) { fprintf(stderr,"Error: Invalid value for argument PID\n"); print_usage(stderr, 1); exit(1); } if (pid!=0) { lazy = 1; } if (!limit_ok) { fprintf(stderr,"Error: You must specify a cpu limit percentage\n"); print_usage(stderr, 1); exit(1); } double limit = perclimit/100.0; if (limit<0 || limit >NCPU) { fprintf(stderr,"Error: limit must be in the range 0-%d00\n", NCPU); print_usage(stderr, 1); exit(1); } int command_mode = optind<argc; if (exe_ok + pid_ok + command_mode == 0) { fprintf(stderr,"Error: You must specify one target process, either by name, pid, or command line\n"); print_usage(stderr, 1); exit(1); } if (exe_ok + pid_ok + command_mode > 1) { fprintf(stderr,"Error: You must specify exactly one target process, either by name, pid, or command line\n"); print_usage(stderr, 1); exit(1); } //all arguments are ok! signal(SIGINT, quit); signal(SIGTERM, quit); //print the number of available cpu if (verbose) printf("%d cpu detected\n", NCPU); #ifdef __linux__ if (!check_proc()) { fprintf(stderr, "procfs is not mounted!\nAborting\n"); exit(-2); } #endif if (command_mode) { int i; //executable file const char *cmd = argv[optind]; //command line arguments char **cmd_args = (char**)malloc((argc-optind+1)*sizeof(char*)); if (cmd_args==NULL) exit(2); for (i=0; i<argc-optind; i++) { cmd_args[i] = argv[i+optind]; } cmd_args[i] = NULL; if (verbose) { printf("Running command: '%s", cmd); for (i=1; i<argc-optind; i++) { printf(" %s", cmd_args[i]); } printf("'\n"); } int child = fork(); if (child < 0) { exit(EXIT_FAILURE); } else if (child > 0) { //parent code int limiter = fork(); if (limiter < 0) { exit(EXIT_FAILURE); } else if (limiter > 0) { //parent int status_process; int status_limiter; waitpid(child, &status_process, 0); waitpid(limiter, &status_limiter, 0); if (WIFEXITED(status_process)) { if (verbose) printf("Process %d terminated with exit status %d\n", child, (int)WEXITSTATUS(status_process)); exit(WEXITSTATUS(status_process)); } printf("Process %d terminated abnormally\n", child); exit(status_process); } else { //limiter code if (verbose) printf("Limiting process %d\n",child); limit_process(child, limit, ignore_children); exit(0); } } else { //target process code int ret = execvp(cmd, cmd_args); //if we are here there was an error, show it perror("Error"); exit(ret); } } while(1) { //look for the target process..or wait for it pid_t ret = 0; if (pid_ok) { //search by pid ret = look_for_process_by_pid(pid); if (ret == 0) { printf("No process found\n"); } else if (ret < 0) { printf("Process found but you aren't allowed to control it\n"); } } else { //search by file or path name ret = look_for_process_by_name(exe); if (ret == 0) { printf("No process found\n"); } else if (ret < 0) { printf("Process found but you aren't allowed to control it\n"); } else { pid = ret; } } if (ret > 0) { if (ret == cpulimit_pid) { printf("Process %d is cpulimit itself! Aborting to avoid deadlock\n", ret); exit(1); } printf("Process %d found\n", pid); //control limit_process(pid, limit, ignore_children); } if (lazy) break; sleep(2); }; exit(0); }
static int zimage_data_setup(i_ctx_t *i_ctx_p, const gs_pixel_image_t * pim, gx_image_enum_common_t * pie, const ref * sources, int npop) { int num_sources = pie->num_planes; int inumpush = NUM_PUSH(num_sources); int code; gs_image_enum *penum; int px; const ref *pp; bool string_sources = true; check_estack(inumpush + 2); /* stuff above, + continuation + proc */ make_int(EBOT_NUM_SOURCES(esp), num_sources); /* * Note that the data sources may be procedures, strings, or (Level * 2 only) files. (The Level 1 reference manual says that Level 1 * requires procedures, but Adobe Level 1 interpreters also accept * strings.) The sources must all be of the same type. * * The Adobe documentation explicitly says that if two or more of the * data sources are the same or inter-dependent files, the result is not * defined. We don't have a problem with the bookkeeping for * inter-dependent files, since each one has its own buffer, but we do * have to be careful if two or more sources are actually the same file. * That is the reason for the aliasing information described above. */ for (px = 0, pp = sources; px < num_sources; px++, pp++) { es_ptr ep = EBOT_SOURCE(esp, px); make_int(ep + 1, 1); /* default is no aliasing */ switch (r_type(pp)) { case t_file: if (!level2_enabled) return_error(e_typecheck); /* Check for aliasing. */ { int pi; for (pi = 0; pi < px; ++pi) if (sources[pi].value.pfile == pp->value.pfile) { /* Record aliasing */ make_int(ep + 1, -pi); EBOT_SOURCE(esp, pi)[1].value.intval++; break; } } string_sources = false; /* falls through */ case t_string: if (r_type(pp) != r_type(sources)) { if (pie != NULL) gx_image_end(pie, false); /* Clean up pie */ return_error(e_typecheck); } check_read(*pp); break; default: if (!r_is_proc(sources)) { static const char ds[] = "DataSource"; if (pie != NULL) gx_image_end(pie, false); /* Clean up pie */ gs_errorinfo_put_pair(i_ctx_p, ds, sizeof(ds) - 1, pp); return_error(e_typecheck); } check_proc(*pp); string_sources = false; } *ep = *pp; } /* Always place the image enumerator into local memory, because pie may have local objects inherited from igs, which may be local when the current allocation mode is global. Bug 688140. */ if ((penum = gs_image_enum_alloc(imemory_local, "image_setup")) == 0) return_error(e_VMerror); code = gs_image_enum_init(penum, pie, (const gs_data_image_t *)pim, igs); if (code != 0 || (pie->skipping && string_sources)) { /* error, or empty image */ int code1 = gs_image_cleanup_and_free_enum(penum, igs); if (code >= 0) /* empty image */ pop(npop); if (code >= 0 && code1 < 0) code = code1; return code; } push_mark_estack(es_other, image_cleanup); esp += inumpush - 1; make_int(ETOP_PLANE_INDEX(esp), 0); make_int(ETOP_NUM_SOURCES(esp), num_sources); make_struct(esp, avm_local, penum); switch (r_type(sources)) { case t_file: push_op_estack(image_file_continue); break; case t_string: push_op_estack(image_string_continue); break; default: /* procedure */ push_op_estack(image_proc_process); break; } pop(npop); return o_push_estack; }