static PLI_INT32 sys_fscanf_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name) { vpiHandle callh = vpi_handle(vpiSysTfCall, 0); vpiHandle argv = vpi_iterate(vpiArgument, callh); s_vpi_value val; struct byte_source src; FILE *fd; errno = 0; val.format = vpiIntVal; vpi_get_value(vpi_scan(argv), &val); fd = vpi_get_file(val.value.integer); if (!fd) { vpi_printf("ERROR: %s:%d: ", vpi_get_str(vpiFile, callh), (int)vpi_get(vpiLineNo, callh)); vpi_printf("invalid file descriptor (0x%x) given to %s.\n", (int)val.value.integer, name); errno = EBADF; val.format = vpiIntVal; val.value.integer = EOF; vpi_put_value(callh, &val, 0, vpiNoDelay); vpi_free_object(argv); return 0; } src.str = 0; src.fd = fd; scan_format(callh, &src, argv, name); return 0; }
static PLI_INT32 sys_sscanf_calltf(ICARUS_VPI_CONST PLI_BYTE8 *name) { vpiHandle callh = vpi_handle(vpiSysTfCall, 0); vpiHandle argv = vpi_iterate(vpiArgument, callh); s_vpi_value val; struct byte_source src; char *str; val.format = vpiStringVal; vpi_get_value(vpi_scan(argv), &val); str = strdup(val.value.str); src.str = str; src.fd = 0; scan_format(callh, &src, argv, name); free(str); return 0; }
int main(int argc, char **argv) { int show_other = 0; /* processes outside my session */ int show_leader = 1; /* process group leaders */ int show_interactive = 1; /* processes associated with terminals */ int show_daemon = 0; /* processes with no associated terminal */ char *match_pid = 0; /* process id to match */ char *match_pgrp = 0; /* group id to match */ char *match_sid = 0; /* session id to match */ char *match_state = 0; /* process state to match */ char *match_tty = 0; /* terminal id to match */ char *match_uid = 0; /* user id to match */ char *format = 0; /* output format string */ char detail[132]; /* detail line buffer */ time_t boot; /* boot time (kludge for image modules) */ long nid; int euid = geteuid(); int ch; time(&utc); progname = basename(argv[0]); while ((ch = getopt(argc, argv, "aAdF:g:p:s:t:u:**efjln:S:x")) != EOF) { switch (ch) { case 'a': /* all processes associated with terminals except pgrp leaders */ show_other = 1; show_leader = 0; show_interactive = 1; show_daemon = 0; break; case 'A': /* all accessible processes */ case 'f': case 'x': show_other = 1; show_leader = 1; show_interactive = 1; show_daemon = 1; break; case 'd': /* all processes except pgrp leaders */ show_other = 1; show_leader = 0; show_interactive = 1; show_daemon = 1; break; case 'F': /* specify output format */ if (format) message("more than one format string?"); format = optarg; break; case 'g': /* processes whose group ID numbers match */ show_other = 1; match_pgrp = optarg; break; case 'p': /* processes whose process ID numbers match */ show_other = 1; match_pid = optarg; break; case 's': /* sessions whose session ID numbers match */ show_other = 1; match_sid = optarg; break; case 't': /* processes whose terminal names match */ show_other = 1; match_tty = optarg; break; case 'u': /* processes whose user names/IDs match */ show_other = 1; match_uid = optarg; break; case 'e': format = FMT_ELAPSED; break; case 'l': format = FMT_LONG; break; case 'j': format = FMT_JOBS; break; case 'n': nid = strtonid(optarg, 0); if (nid == -1 || nid == 0) { message("invalid node specified (-n %s)\n", optarg); return EXIT_FAILURE; } if ((pm = qnx_vc_attach(nid, PROC_PID, sizeof ps, 1)) == -1) { message("unable to connect to node %s. (%s)\n", nidtostr(nid, 0, 0), strerror(errno)); return EXIT_FAILURE; } break; case 'S': match_state = optarg; break; } } setpwent(); if (format == 0) format = getenv("POSIX_STRICT") ? FMT_POSIX : FMT_QNX; scan_format(format, detail); print_format(detail); for (ps.pid = PROC_PID; qnx_psinfo(pm, ps.pid, &ps, 0, 0) >= 0; ps.pid++) { /* skip proxies and virtual circuits */ if ((ps.flags & _PPF_MID) || (ps.flags & _PPF_VID)) continue; /* save start time of Proc */ if (ps.pid == PROC_PID) boot = ps.un.proc.start_time; /* skip other users' processes */ if (!show_other && ps.euid != euid) continue; /* skip process group leaders */ if (!show_leader && ps.pid == ps.pgrp) continue; /* check for specific processes */ if (match_state && !match(match_state, procstate)) continue; if (match_pid && !match(match_pid, procpid)) continue; if (match_pgrp && !match(match_pgrp, procgrp)) continue; if (match_sid && !match(match_sid, procsid)) continue; if (match_tty && !match(match_tty, proctty)) continue; if (match_uid && !match(match_uid, procuser)) continue; /* kludge start time for image modules */ if (ps.un.proc.start_time == 0) ps.un.proc.start_time = boot; print_format(detail); } return EXIT_SUCCESS; }