%ģ VAX-11 Librarian V04-00ą N“€ ĢN“HJ   II‘(«  DISPLAY_DATAZ DISPLAY_FLOATN DISPLAY_FRAME#` DISPLAY_INT%ZDISPLAY_PRCCNT&:DISPLAY_STRING'² GET_INTERVAL*( GET_USER_DATA8ŽQWATCH ­€ŁEN“/* * NAME: * DISPLAY_DATA.C * * DESCRIPTION:E * This routine is called to display one buffer full of process data.D * If the data item to be displayed is the same as the previous timeD * it was displayed, it is shown in normal text, if it is different, * it is shown in reverse video. * * CONTENTS:* * display_data - display a whole buffer) * check_display_count - display a count* * check_display_time - display the time0 * check_display_image - display the image name) * check_display_quota - display a quota3 * check_display_state - display the process state * * HISTORY: * DATE AUTHOR DESCRIPTION* * 8-APR-1990 18:47 Marc Picard Creation. * */#include #include #include "qwatch_jpi.h"#include "statedef.h"=extern void display_int (int, int, int, int, int, char *);>extern void display_float (int, int, int, int, float, char *);8extern void display_string (int, int, int, int, char *);display_data ( int display, struct user_buffer *current, struct user_buffer *old){static int write_ast = TRUE; static int write_biocnt = TRUE; static int write_diocnt = TRUE; static int write_bytcnt = TRUE; static int write_enqcnt = TRUE; static int write_filcnt = TRUE; static int write_prccnt = TRUE;static int write_tqcnt = TRUE;"static int write_pagfilcnt = TRUE;,int rend; /* reverse video or normal */>display_string(display, 1, 30, SMG$M_NORMAL, current->pname); @check_display_state(display, current->state, old->state, 1, 53);%if (current->astcnt != old->astcnt) { rend = SMG$M_REVERSE;H check_display_quota(display, rend, current->astcnt, current->astlm, 4); write_ast = TRUE; }else { if (write_ast) { rend = SMG$M_NORMAL; write_ast = FALSE;I check_display_quota(display, rend, current->astcnt, current->astlm, 4); } }%if (current->biocnt != old->biocnt) { rend = SMG$M_REVERSE; write_biocnt = TRUE;H check_display_quota(display, rend, current->biocnt, current->biolm, 5); }else { if (write_biocnt) { rend = SMG$M_NORMAL; write_biocnt = FALSE;I check_display_quota(display, rend, current->biocnt, current->biolm, 5); } }%if (current->diocnt != old->diocnt) { rend = SMG$M_REVERSE; write_diocnt = TRUE;H check_display_quota(display, rend, current->diocnt, current->diolm, 6); }else { if (write_diocnt) { rend = SMG$M_NORMAL; write_diocnt = FALSE;I check_display_quota(display, rend, current->diocnt, current->diolm, 6); } }%if (current->bytcnt != old->bytcnt) { rend = SMG$M_REVERSE; write_bytcnt = TRUE;H check_display_quota(display, rend, current->bytcnt, current->bytlm, 7); }else { if (write_bytcnt) { rend = SMG$M_NORMAL; write_bytcnt = FALSE;I check_display_quota(display, rend, current->bytcnt, current->bytlm, 7); } }%if (current->enqcnt != old->enqcnt) { rend = SMG$M_REVERSE; write_enqcnt = TRUE;H check_display_quota(display, rend, current->enqcnt, current->enqlm, 8); }else { if (write_enqcnt) { rend = SMG$M_NORMAL; write_enqcnt = FALSE;I check_display_quota(display, rend, current->enqcnt, current->enqlm, 8); } }%if (current->filcnt != old->filcnt) { rend = SMG$M_REVERSE; write_filcnt = TRUE;H check_display_quota(display, rend, current->filcnt, current->fillm, 9); }else { if (write_filcnt) { rend = SMG$M_NORMAL; write_filcnt = FALSE;I check_display_quota(display, rend, current->filcnt, current->fillm, 9); } }%if (current->prccnt != old->prccnt) { rend = SMG$M_REVERSE; write_prccnt = TRUE;D display_prccnt(display, rend, current->prccnt, current->prclm, 10); }else { if (write_prccnt) { rend = SMG$M_NORMAL; write_prccnt = FALSE;E display_prccnt(display, rend, current->prccnt, current->prclm, 10); } }#if (current->tqcnt != old->tqcnt) { rend = SMG$M_REVERSE; write_tqcnt = TRUE;I check_display_quota(display, rend, current->tqcnt, current->tqlm, 11); }else { if (write_tqcnt) { rend = SMG$M_NORMAL; write_tqcnt = FALSE;J check_display_quota(display, rend, current->tqcnt, current->tqlm, 11); } }+if (current->pagfilcnt != old->pagfilcnt) { rend = SMG$M_REVERSE; write_pagfilcnt = TRUE;P check_display_quota(display, rend, current->pagfilcnt, current->pgflquota, 12); }else { if (write_pagfilcnt) { rend = SMG$M_NORMAL; write_pagfilcnt = FALSE;Q check_display_quota(display, rend,  current->pagfilcnt, current->pgflquota, 12); } }Bcheck_display_count(display, current->bufio, old->bufio, 14, 20);Ccheck_display_count(display, current->dirio, old->dirio, 15, 20);Jcheck_display_count(display, current->freptecnt, old->freptecnt, 16, 20);Echeck_display_count(display, current->gpgcnt, old->gpgcnt, 17, 20);Echeck_display_count(display, current->ppgcnt, old->ppgcnt, 18, 20);Hcheck_display_count(display, current->pageflts, old->pageflts, 19, 20);Hcheck_display_ count(display, current->shrfillm, old->shrfillm, 20, 20);Hcheck_display_time(display, current->cpu_time, old->cpu_time, 14, 45);Echeck_display_count(display, current->wsauth, old->wsauth, 15, 48);Jcheck_display_count(display, current->wsauthext, old->wsauthext, 16, 48);Hcheck_display_count(display, current->wsextent, old->wsextent, 17, 48);Echeck_display_count(display, current->wspeak, old->wspeak, 18, 48);Gcheck_display_count(display, current->wsquota, old->wsquota, 19, 48);Echeck_display_count(display, current->wssize, old->wssize, 20, 48);Kcheck_display_image(display, current->imagname, old->imagname, 22, 10, 79);} /* end of display_data */ check_display_count( int display, int cur_cnt,  int old_cnt, int row, int col){if (cur_cnt != old_cnt ) B display_int(display, row, col, SMG$M_REVERSE, cur_cnt, "%8d");else@ display_int(display, row, col, SMG$M_NORMAL, cur_cnt,"%8d");"} /* end of check_display_count */ check_ display_time ( int display, int cur_cnt,  int old_cnt, int row, int col){ int hours; int minutes; int seconds; int thous; int rendition; char output_string[20]; if (cur_cnt != old_cnt ) rendition = SMG$M_REVERSE; else rendition = SMG$M_NORMAL; thous = cur_cnt % 100; cur_cnt = cur_cnt / 100; seconds = cur_cnt % 60; cur_cnt = cur_cnt / 60; minutes = cur_cnt % 60; cur_cnt = cur_cnt / 60; hours = cur_cnt % 60;1 sprintf(&output_string, "%02d:%02d:%02d\.%02d", " hours, minutes, seconds, thous);? display_string (display, row, col, rendition, output_string);!} /* end of check_display_time */ check_display_image( int display, char *cur_str, char *old_str, int row, int col_start, int col_end){ int number_of_rows; int status;% if (strcmp(cur_str, old_str) != 0) {+ number_of_rows = col_end - col_start + 1;6 status = SMG$ERASE_CHARS(&display, &number_of_rows,  &row, &col_start);, if ((status & 1) == 0) lib$signal(status);A display_string(display, row, col_start, SMG$M_NORMAL, cur_str); }"} /* end of check_display_image */ check_display_quota( int display, int rendition, int cur_avail, int limit, int row){ auto float percent; auto int used; if (limit == 0) percent = 000.0; else6 percent = ((float)cur_avail / (float)limit * 100.0); used = (limit - cur_avail);: display_int(display, row, 10, rendition, limit, "%8d");9 display_int(display, row, 20, rendition, used, "%8d");> display_int(display, row, 30, rendition, cur_avail, "%8d");? display_float(display, row, 40, rendition, percent, "%10.2f");"} /* end of check_display_quota */ check_display_state ( int display, int cur_state,  int old_state, int row, int col){ static char *state_name[] =  {% "UNKNOWN", "COLPG", "MWAIT", "CEF",! "PFW", "LEF", "LEFO", "HIB",# "HIBO", "SUSP", "SUSPO", "FPG", "COM", "COMO", "CUR" };# if (cur_state > 14) cur_state = 0; if (cur_state != old_state )3 display_string(display, row, col, SMG$M_REVERSE,  state_name[cur_state]); else 2 display_string(display, row, col, SMG$M_NORMAL,  state_name[cur_state]);"} /* end of check_display_state *//* end of display_data.c */ww­ąńhN“#include #include #include void display_float ( int display, /* display id */ int row, /* row number  */ int col, /* starting column */) int rendition, /* bold, reverse, etc */' float num, /* numberto be displayed */( char *format) /* format for sprintf */{ int status; char ascii_float[25]; struct dsc$descriptor line;$ sprintf(&ascii_float, format, num);) line.dsc$w_length = strlen(ascii_float);" line.dsc$b_dtype = DSC$K_DTYPE_T;" line.dsc$b_class = DSC$K_CLASS_S;# line.dsc$a_pointer = &ascii_float;D status = SMG$PUT_CHARS(&display, &line, &row, &col, 0, &rendition );+ if ((status & 1) == 0) lib$signal(status);} /* end of */ww­ą&uN“#include void display_frame (int display){1void display_string (int, int, int, int, char *);Mdisplay_string(display, 01, 03, SMG$M_NORMAL, "At: : : Process:");:display_string(display, 01, 46, SMG$M_NORMAL, "State: ");:display_string(display, 3, 03, SMG$M_UNDERLINE, "QUOTA");;display_string(display, 3, 12, SMG$M_UNDERLINE, "AVAIL.");9display_string(display, 3, 24, SM !G$M_UNDERLINE, "USED");;display_string(display, 3, 32, SMG$M_UNDERLINE, "REMAIN");;display_string(display, 3, 44, SMG$M_UNDERLINE, "% LEFT");Fdisplay_string(display, 4, 03, SMG$M_NORMAL, "AST: ");Fdisplay_string(display, 5, 03, SMG$M_NORMAL, "BIO: ");Fdisplay_string(display, 6, 03, SMG$M_NORMAL, "DIO: ");Fdisplay_string(display, 7, 03, SMG$M_NORMAL, "BYTE: ");Fdisplay_string(display, 8, 03, SMG$M_NORMAL, "ENQ: " ");Fdisplay_string(display, 9, 03, SMG$M_NORMAL, "FILES: ");Fdisplay_string(display, 10, 03, SMG$M_NORMAL, "PRC: ");Fdisplay_string(display, 11, 03, SMG$M_NORMAL, "TQE: ");Fdisplay_string(display, 12, 03, SMG$M_NORMAL, "PAGEF: ");Fdisplay_string(display, 14, 03, SMG$M_NORMAL, "Buffered IO: ");Fdisplay_string(display, 15, 03, SMG$M_NORMAL, "Direct IO: ");Fdisplay_string(display, 16, 03, SMG$M_NORMAL, "Free Pages: " #);Fdisplay_string(display, 17, 03, SMG$M_NORMAL, "Global Pages: ");Fdisplay_string(display, 18, 03, SMG$M_NORMAL, "Process Pages: ");Fdisplay_string(display, 19, 03, SMG$M_NORMAL, "Page Faults: ");Fdisplay_string(display, 20, 03, SMG$M_NORMAL, "Open Shared limit: ");:display_string(display, 22, 03, SMG$M_NORMAL, "Image: ");@display_string(display, 14, 32, SMG$M_NORMAL, "CPU Time: ");@display_string(display, 15, 32, SMG$M_NORMAL, "WS Auth: ");@display_string(displ$ay, 16, 32, SMG$M_NORMAL, "WS Auth Ext: ");@display_string(display, 17, 32, SMG$M_NORMAL, "WS Extent: ");@display_string(display, 18, 32, SMG$M_NORMAL, "WS Peak: ");@display_string(display, 19, 32, SMG$M_NORMAL, "WS Quota: ");@display_string(display, 20, 32, SMG$M_NORMAL, "WS Size: ");} /* end of display_frame */ww­Č|N“#include stdio#include smgdef#include descripvoid display_int ( int display, /* display id */ int row, /* row number */ i%nt col, /* starting column */) int rendition, /* bold, reverse, etc */) int number, /* number to be displayed */. char *format) /* format for use in sprintf */{ struct dsc$descriptor line; char ascii_int[25]; int status;% sprintf(&ascii_int, format, number);' line.dsc$w_length = strlen(ascii_int);" line.dsc$b_dtype = DSC$K_DTYPE_T;" line.dsc$b_class = DSC$K_CLASS_S;! line.dsc$a_pointer = &ascii_int;D status = SMG$PUT_CHARS(&display, &line, &row, &col, 0, &rendition&);+ if ((status & 1) == 0) lib$signal(status);} /* end of display_int */ww­`v‡N“#include stdio#include smgdef display_prccnt( int display, int rendition, int used, int limit, int row){7void display_float (int, int, int, int, float, char *);5void display_int (int, int, int, int, int, char *);auto float percent;auto int cur_avail;cur_avail = limit - used;if (limit == 0) percent = 000.0;else5 percent = ((float)cur_avail / (floa't)limit * 100.0);9display_int(display, row, 10, rendition, limit, "%8d");8display_int(display, row, 20, rendition, used, "%8d");=display_int(display, row, 30, rendition, cur_avail, "%8d");>display_float(display, row, 40, rendition, percent, "%10.2f");} /* end of display_prccnt.c */ww­`«“N“#include stdio#include descrip#include smgdefvoid display_string ( int display, /* display id */ int row, /* row number */ int col, /* starting column */) i(nt rendition, /* bold, reverse, etc */( char *str) /* string to be displayed */{ int status; struct dsc$descriptor line;! line.dsc$w_length = strlen(str);" line.dsc$b_dtype = DSC$K_DTYPE_T;" line.dsc$b_class = DSC$K_CLASS_S; line.dsc$a_pointer = str;D status = SMG$PUT_CHARS(&display, &line, &row, &col, 0, &rendition);+ if ((status & 1) == 0) lib$signal(status);} /* end of display_string */ww­ ķ¢N“#include #include 7#define chec)k_status(x) if ((x & 1) == 0) lib$signal(x)#define MAX_INTERVAL_STRING 1004void get_interval(int dpid, int kbid, int *interval){/ char interval_string[MAX_INTERVAL_STRING+1]; short int interval_len; int status;; $DESCRIPTOR(prompt_desc, "Please enter a new interval: ");( struct dsc$descriptor interval_desc = {& MAX_INTERVAL_STRING, DSC$K_DTYPE_T, ! DSC$K_CLASS_S, &interval_string };! status = SMG$READ_COMPOSED_LINE( &kbid, /* keyboard id */ 0, /* k*ey table id */) &interval_desc, /* string descriptor */' &prompt_desc, /* prompt descriptor */& &interval_len, /* returned length */ &dpid, /* display id */ 0, /* flags */ 0, /* initial string */ 0, /* timeout */ 0, /* rendition set */! 0, /* rendition complement */ 0 /* terminator code */ ); check_status ( status );= interval_string[interval_len] = '\0'; /* make a C string */> sscanf(interval_string, "%d", interval); /* convert to int */+} /* end of get_interval */ww­ą/²N“#include #include #include #include &#include "qwatch_include:qwatch_jpi.h""#include "qwatch_include:qwatch.h"int get_user_data( int pid, char *pname, struct user_buffer out_buffer){ int dummy; int status;# static struct JPI_ITEM_LIST items;! struct user_buffer temp_buffer;# struct dsc$descriptor pname_desc;! static int first_time = TRUE; /* Clear th,e output buffer */@ LIB$MOVC5(&0, &0, &'\0', &(sizeof(temp_buffer)), &temp_buffer); if (first_time) { first_time = FALSE;. items.astcnt.pbuff = &(temp_buffer.astcnt);# items.astcnt.code = JPI$_ASTCNT; items.astcnt.length = 4;# items.astcnt.pbuff_len = &dummy; , items.astlm.pbuff = &(temp_buffer.astlm);! items.astlm.code = JPI$_ASTLM; items.astlm.length = 4;" items.astlm.pbuff_len = &dummy;. items.biocnt.pbuff = &(temp_buffer.biocnt);# items.biocnt.code - = JPI$_BIOCNT; items.biocnt.length = 4;# items.biocnt.pbuff_len = &dummy;, items.biolm.pbuff = &(temp_buffer.biolm);! items.biolm.code = JPI$_BIOLM; items.biolm.length = 4;" items.biolm.pbuff_len = &dummy;, items.bufio.pbuff = &(temp_buffer.bufio);! items.bufio.code = JPI$_BUFIO; items.bufio.length = 4;" items.bufio.pbuff_len = &dummy;. items.bytcnt.pbuff = &(temp_buffer.bytcnt);# items.bytcnt.code = JPI$_BYTCNT; items.bytcnt.length = 4;# item.s.bytcnt.pbuff_len = &dummy;, items.bytlm.pbuff = &(temp_buffer.bytlm);! items.bytlm.code = JPI$_BYTLM; items.bytlm.length = 4;" items.bytlm.pbuff_len = &dummy;. items.diocnt.pbuff = &(temp_buffer.diocnt);# items.diocnt.code = JPI$_DIOCNT; items.diocnt.length = 4;# items.diocnt.pbuff_len = &dummy;, items.diolm.pbuff = &(temp_buffer.diolm);! items.diolm.code = JPI$_DIOLM; items.diolm.length = 4;" items.diolm.pbuff_len = &dummy;, items.dirio.pbuff / = &(temp_buffer.dirio);! items.dirio.code = JPI$_DIRIO; items.dirio.length = 4;" items.dirio.pbuff_len = &dummy;. items.enqcnt.pbuff = &(temp_buffer.enqcnt);# items.enqcnt.code = JPI$_ENQCNT; items.enqcnt.length = 4;# items.enqcnt.pbuff_len = &dummy;, items.enqlm.pbuff = &(temp_buffer.enqlm);! items.enqlm.code = JPI$_ENQLM; items.enqlm.length = 4;" items.enqlm.pbuff_len = &dummy;. items.filcnt.pbuff = &(temp_buffer.filcnt);# items.filcnt.code = JPI0$_FILCNT; items.filcnt.length = 4;# items.filcnt.pbuff_len = &dummy;, items.fillm.pbuff = &(temp_buffer.fillm);! items.fillm.code = JPI$_FILLM; items.fillm.length = 4;" items.fillm.pbuff_len = &dummy;4 items.freptecnt.pbuff = &(temp_buffer.freptecnt);) items.freptecnt.code = JPI$_FREPTECNT; items.freptecnt.length = 4;& items.freptecnt.pbuff_len = &dummy;. items.gpgcnt.pbuff = &(temp_buffer.gpgcnt);# items.gpgcnt.code = JPI$_GPGCNT; items.gpgcnt.len1gth = 4;# items.gpgcnt.pbuff_len = &dummy;2 items.imagname.pbuff = &(temp_buffer.imagname);' items.imagname.code = JPI$_IMAGNAME;* items.imagname.length = MAX_IMAGE_NAME;9 items.imagname.pbuff_len = &(temp_buffer.imagname_len);2 items.pageflts.pbuff = &(temp_buffer.pageflts);' items.pageflts.code = JPI$_PAGEFLTS; items.pageflts.length = 4;$ items.pageflts.pbuff_len = &dummy;4 items.pagfilcnt.pbuff = &(temp_buffer.pagfilcnt);) items.pagfilcnt.code = JPI$_PAG2FILCNT; items.pagfilcnt.length = 4;% items.pagfilcnt.pbuff_len = &dummy;4 items.pgflquota.pbuff = &(temp_buffer.pgflquota);) items.pgflquota.code = JPI$_PGFLQUOTA; items.pgflquota.length = 4;% items.pgflquota.pbuff_len = &dummy;. items.ppgcnt.pbuff = &(temp_buffer.ppgcnt);# items.ppgcnt.code = JPI$_PPGCNT; items.ppgcnt.length = 4;# items.ppgcnt.pbuff_len = &dummy;. items.prccnt.pbuff = &(temp_buffer.prccnt);# items.prccnt.code = JPI$_PRCCNT; items.3prccnt.length = 4;# items.prccnt.pbuff_len = &dummy;, items.prclm.pbuff = &(temp_buffer.prclm);! items.prclm.code = JPI$_PRCLM; items.prclm.length = 4;" items.prclm.pbuff_len = &dummy;2 items.shrfillm.pbuff = &(temp_buffer.shrfillm);' items.shrfillm.code = JPI$_SHRFILLM; items.shrfillm.length = 4;$ items.shrfillm.pbuff_len = &dummy;, items.tqcnt.pbuff = &(temp_buffer.tqcnt);! items.tqcnt.code = JPI$_TQCNT; items.tqcnt.length = 4;" items.tqcnt.pbuff_4len = &dummy;* items.tqlm.pbuff = &(temp_buffer.tqlm); items.tqlm.code = JPI$_TQLM; items.tqlm.length = 4;! items.tqlm.pbuff_len = &dummy;, items.pname.pbuff = &(temp_buffer.pname);" items.pname.code = JPI$_PRCNAM;" items.pname.length = MAX_PNAME;4 items.pname.pbuff_len = &(temp_buffer.pname_len);2 items.cpu_time.pbuff = &(temp_buffer.cpu_time);% items.cpu_time.code = JPI$_CPUTIM; items.cpu_time.length = 4;$ items.cpu_time.pbuff_len = &dummy;, item5s.state.pbuff = &(temp_buffer.state);! items.state.code = JPI$_STATE; items.state.length = 4;" items.state.pbuff_len = &dummy;. items.wsauth.pbuff = &(temp_buffer.wsauth);# items.wsauth.code = JPI$_WSAUTH; items.wsauth.length = 4;# items.wsauth.pbuff_len = &dummy;4 items.wsauthext.pbuff = &(temp_buffer.wsauthext);) items.wsauthext.code = JPI$_WSAUTHEXT; items.wsauthext.length = 4;% items.wsauthext.pbuff_len = &dummy;2 items.wsextent.pbuff = &(temp_buf6fer.wsextent);' items.wsextent.code = JPI$_WSEXTENT; items.wsextent.length = 4;$ items.wsextent.pbuff_len = &dummy;. items.wspeak.pbuff = &(temp_buffer.wspeak);# items.wspeak.code = JPI$_WSPEAK; items.wspeak.length = 4;# items.wspeak.pbuff_len = &dummy;0 items.wsquota.pbuff = &(temp_buffer.wsquota);% items.wsquota.code = JPI$_WSQUOTA; items.wsquota.length = 4;$ items.wsquota.pbuff_len = &dummy;. items.wssize.pbuff = &(temp_buffer.wssize);# items.wssi7ze.code = JPI$_WSSIZE; items.wssize.length = 4;# items.wssize.pbuff_len = &dummy; items.terminator = 0; } if (strlen(pname) == 0) 4 status = SYS$GETJPIW(0, &pid, 0, &items, 0, 0, 0); else {# pname_desc.dsc$a_pointer = pname;+ pname_desc.dsc$w_length = strlen(pname);+ pname_desc.dsc$b_class = DSC$K_CLASS_S;+ pname_desc.dsc$b_dtype = DSC$K_DTYPE_T;' STR$UPCASE(&pname_desc, &pname_desc);; status = SYS$GETJPIW(0, 0, &pname_desc, &items, 0, 0, 0); }38 if (lib$match_cond(&status, &(SS$_NONEXPR)) == 1)  return(GET_DATA_NO_PROCESS);5 if (lib$match_cond(&status, &(SS$_SUSPENDED)) == 1)  return(GET_DATA_SUSPENDED);+ if ((status & 1) == 0) lib$signal(status);9 temp_buffer.pname[(temp_buffer.pname_len < MAX_PNAME) ? / temp_buffer.pname_len : (MAX_PNAME-1)] = '\0';D temp_buffer.imagname[(temp_buffer.imagname_len < MAX_IMAGE_NAME) ? 7 temp_buffer.imagname_len : (MAX_IMAGE_NAME-1)] = '\0';+ /* Move the output to the output buff9er */= LIB$MOVC3(&(sizeof(temp_buffer)), &temp_buffer, out_buffer);  return(GET_DATA_OK);} /* end of get_user_data */ww­€ ĢN“/* * NAME: * QWATCH.C * * DESCRIPTION:F * This program is used to watch a process' quota usage. When a validE * process id specified, the system will display that process' quotasG * along with a few other details such as the process state, I/O counts% * and the image currently being run. */ * There control keys can be typed a:t any time: * ^Z will halt the progam. * ^W will re-draw the screen.@ * ^I will prompt the user for a new interval and then set it.5 * By default, the screen will be refreshed every 3 * seconds. * * USAGE: * $ QWATCH pid * * NOTES:& * (1) next_command is set as follows:@ * CMD_NONE: (the initial state) when this is true, we wait for: * interval seconds and then display the next batch of * process data.C * CMD_STOP: set when the SYS$GETJPI does not ret ;urn valid process * data.B * CMD_EXIT: set when the user types ^Z. Stop the loop, clear the * screen and stop.B * CMD_INTERVAL: set when the user types ^I. Prompt the user for< * a new interval, restore the display, and set variable * interval.@ * CMD_REDISPLAY: set the user types ^W. Clear the screen, re- * display current data. *H * (2) the normal loop is to wait for 'interval' seconds, call getjpi toB * get the target's current process information and <diplay it. *F * (3) ^W, ^I, and ^Z cancel the current scheduled wakeup time so that2 * response to control keys will be immidiate. */ * (4) get_user_data returns one of two values:5 * GET_DATA_OK: valid process data is in the buffer.B * GET_DATA_NO_PROCESS: either the process stopped or the process; * does not exist. The onpy thing left to do is clean up * and stop. * GET_DATA_SUSPENDED:  * * HISTORY: * DATE AUTHOR DESCRIPTION* * 30-OCT-1989 18:01 Marc Picard= Creation. */ #include #include #include #include #include &#include "qwatch_include:qwatch_jpi.h"(#include "qwatch_include:qwatch_cmd.h" I#include "qwatch_include:qwatch_masks.h" /* masks to define ctrl chars */"#include "qwatch_include:qwatch.h"7#define check_status(x) if ((x & 1) == 0) lib$signal(x)0int interval; /* time between screen writes */int next_command;int wake_time[2];int dpid; /* displa>y id */*int int_dpid; /* interval display id */!int pbid; /* pasteboard id */ int kbid; /* keyboard id */int pasteboard_setup;unsigned int ast_mask;char delta_string[20];!struct dsc$descriptor delta_desc;struct user_buffer current;struct user_buffer old; /*! * C a l l e d R o u t i n e s  */void ctrl_char_trap# (struct OUT_OF_BAND_TABLE *table);void display_frame (int); /* display id */void display_data (int, /* display id? */* struct user_buffer *, /* old buffer */* struct user_buffer *); /* new buffer */void update_current_time (int); /* display id */void get_interval (int, /* display id */ int, /* keyboard id */ int *); /* new interval */int get_user_data (int, /* process id */" char *pname, /* process name */) struct user_buffer *); /* new buffer */void check_display_state (int, /* display id */ int, /* current state */ int, /* old state @*/ int, /* screen row */ int); /* screen column */ main (argc, argv) int argc; char *argv[];{( int pid; /* process id of victim */. int status; /* status of last rtl call */ static int first_time = TRUE;0 int got_data; /* Return from get_user_data */' char pname[16]; /* process name */+ sprintf(delta_string, "0 ::%d", interval);) delta_desc.dsc$a_pointer = delta_string;) delta_desc.dsc$b_class = DSC$K_CLASS_S;) delta_desc.dsc$b_dtype = DSC$K_DATYPE_T;1 delta_desc.dsc$w_length = strlen(delta_string);. status = sys$bintim(&delta_desc, &wake_time);* interval = 3; /* start at 3 seconds */ next_command = CMD_NONE; pasteboard_setup = FALSE;9 if (argc < 2 || argc > 3 || strcmp(argv[1], "?") == 0) {) fprintf(stderr, "Usage: QWATCH pid\n"); exit(1); }. /* convert the parameter into a hex number */" if (strcmp(argv[1], "-i") == 0) { pname[0] = '\0';' status = sscanf(argv[2], "%x", &pid); if (!status) {6 fprBintf(stderr,"watch, invalid pid %s\n", argv[1]); exit(1); } } else {3 /* we have a process name, convert it to a pid */ pid = 0; strcpy(pname, argv[1]); } pbid = 0;? while (next_command != CMD_EXIT && next_command != CMD_STOP) { sleep(interval);1 got_data = get_user_data(pid, pname, ¤t);( if (got_data != GET_DATA_NO_PROCESS) { if (first_time) { initialize_all(); next_command = CMD_NONE; first_time = FALSE; }( if (next_command == C CMD_REDISPLAY ) {. check_status(SMG$ERASE_PASTEBOARD(&pbid)); display_frame(dpid);3 LIB$MOVC5(&0, &0, &'\0', &(sizeof(old)), &old); next_command = CMD_NONE; }' if (next_command == CMD_INTERVAL ) {+ check_status(SMG$PASTE_VIRTUAL_DISPLAY(! &int_dpid, &pbid, &24, &1));, get_interval(int_dpid, kbid, &interval);. sprintf(delta_string, "0 ::%d", interval);3 delta_desc.dsc$w_length = strlen(delta_string);1 status = sys$bintim(&delta_desc, &wake_time);D- check_status(SMG$UNPASTE_VIRTUAL_DISPLAY( &int_dpid, &pbid)); next_command = CMD_NONE; } update_current_time(dpid);! if (got_data == GET_DATA_OK) {' display_data(dpid, ¤t, &old);2 LIB$MOVC3(&(sizeof(current)), ¤t, &old); }( if (got_data == GET_DATA_SUSPENDED) {- check_display_state(dpid, current.state,  old.state, 1, 53); } } else  next_command = CMD_STOP; } if (pasteboard_setup) {, check_status(SMG$ERASE_PEASTEBOARD(&pbid));- check_status(SMG$DELETE_PASTEBOARD(&pbid));3 check_status(SMG$DELETE_VIRTUAL_KEYBOARD(&kbid)); } if (next_command == CMD_STOP), printf("Process %s not found\n", argv[1]); exit(1);} /* end of main */ 5void ctrl_char_trap (struct OUT_OF_BAND_TABLE *table){= if (table->SMG$R_CHAR_OVERLAY.SMG$B_CHAR == SMG$K_TRM_CTRLI) next_command = CMD_INTERVAL;= if (table->SMG$R_CHAR_OVERLAY.SMG$B_CHAR == SMG$K_TRM_CTRLW) next_command = CMD_REDISPLAY;F= if (table->SMG$R_CHAR_OVERLAY.SMG$B_CHAR == SMG$K_TRM_CTRLZ) next_command = CMD_EXIT;M/* this system call cancels the current wait and re-displays right away. */M/* without this a user could set the interval to 10000 and be left waiting */3/* almost forever until the next response. */ SYS$WAKE(0, 0);} /* end of ctrl_char_trap */ #void update_current_time (int dpid){6 void display_int (int, int, int, int, int, char *);' time_t time_now; /* binary timGe */* struct tm *now; /* broken down time */ time_now = time(0); now = localtime(&time_now);> display_int(dpid, 1, 7, SMG$M_NORMAL, now->tm_hour, "%02d");> display_int(dpid, 1, 10, SMG$M_NORMAL, now->tm_min, "%02d");> display_int(dpid, 1, 13, SMG$M_NORMAL, now->tm_sec, "%02d");"} /* end of update_current_time */ initialize_all() {, check_status(SMG$CREATE_PASTEBOARD(&pbid));3 check_status(SMG$CREATE_VIRTUAL_DISPLAY(&22, &78,  &dpid, &SMG$M_BORDER));- check_staHtus(SMG$CREATE_VIRTUAL_DISPLAY(&1,  &80, &int_dpid, 0));0 check_status(SMG$CREATE_VIRTUAL_KEYBOARD(&kbid, 0, 0, 0, 0)); pasteboard_setup = TRUE;1 ast_mask = QWATCH_M_I + QWATCH_M_W + QWATCH_M_Z;M check_status(SMG$SET_OUT_OF_BAND_ASTS(&pbid, &ast_mask, ctrl_char_trap, 1)); display_frame(dpid);? check_status(SMG$PASTE_VIRTUAL_DISPLAY(&dpid, &pbid, &2, &2)); /* Clear the output buffer */0 LIB$MOVC5(&0, &0, &'\0', &(sizeof(old)), &old);} /* end of initialize_all *//* end of QWATCH.C */wwŗ«pŽN“  PICARD DISPLAY_DATA DISPLAY_FLOAT DISPLAY_FRAME DISPLAY_INTDISPLAY_PRCCNTDISPLAY_STRING GET_INTERVAL GET_USER_DATAQWATCH