getstatus.c

来自「unix环境高级编程的源代码」· C语言 代码 · 共 39 行

C
39
字号
#include    "lprps.h"

/* Called by main() before printing job.
 * We send a Control-T to the printer to fetch its status.
 * If we timeout before reading the printer's status, something
 * is wrong. */

void
get_status(void)
{
    char    c;

    set_alrm(5);            /* 5 second timeout to fetch status */

    tty_flush();
    c = '\024';
    block_write(&c, 1);        /* send Control-T to printer */

    init_input(0);
    while (status == INVALID)
        proc_some_input();    /* wait for something back */

    switch (status) {
    case IDLE:        /* this is what we're looking for ... */
        clear_alrm();
        return;

    case WAITING:    /* printer thinks it's in the middle of a job */
        block_write(&eofc, 1);    /* send EOF to printer */
        sleep(5);
        exit(EXIT_REPRINT);

    case BUSY:
    case UNKNOWN:
        sleep(15);
        exit(EXIT_REPRINT);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?