⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hplistc.c

📁 第3章-μCOS-II基础实验 3.2-GPIO实验 3.3-时器实验 3.4-PWM实验 3.5-RTC实验 3.6-信号量使用
💻 C
📖 第 1 页 / 共 2 页
字号:
    }
    ListcInit();                                                     /* Perform initializations        */
    strcpy(ListcFileName, argv[1]);                                  /* Get file name                  */
    ListcSrcFile = fopen(ListcFileName, "r");                        /* Open file to list              */
    if (ListcSrcFile == NULL) {                                      /* Make sure that file got opened */
        fprintf(stdout, "Cannot open %s.\n", ListcFileName);         /* Display error message          */
        return;
    }
    ListcHdr();                                                      /* Print page header              */
    while (fgets(ListcInStr, 250, ListcSrcFile) != NULL) {           /* Print code                     */
        if (ListcChkCmd(ListcInStr) == FALSE) {                      /* See if input line is a command */
            fprintf(stdout, "%04d  %s", ListcLineN, ListcInStr);
        }
        ListcLineN++;
    }
    fclose(ListcSrcFile);                                            /* Close input file               */
    fprintf(stdout, "%c", PRINTER_FORM_FEED);
    fprintf(stdout, "%s", PRINTER_NORMAL_MODE);                      /* Set printer to normal mode     */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                          INITIALIZE LISTC
*********************************************************************************************************
*/

static void ListcInit(void)
{
    ListcLineN = 1;
    ListcPageN = 1;
    strcpy(ListcTitle, "");                                /* No TITLE when we start                   */
    ListcGetDate(ListcDate);                               /* Get the current date 'Month day, year'   */
    ListcGetTime(ListcTime);                               /* Get the current time 'HH:MM:SS'          */
    fprintf(stdout, "%s", PRINTER_PAGE_LENGTH);            /* Set page length to 66 lines per page.    */
    fprintf(stdout, "%s", PRINTER_COMPRESSED_MODE);        /* Force printer into compressed mode       */
    if (ListcMode == LANDSCAPE) {
        fprintf(stdout, "%s", PRINTER_LANDSCAPE);          /* Force printer into LANDSCAPE  mode       */
    }
}


/*
*********************************************************************************************************
*                                      CHECK FOR LISTC COMMAND
*********************************************************************************************************
*/

static BOOLEAN ListcChkCmd(char *s)
{
    char  *p1;                                                  /* Pointer to command name             */
    char  *p2;                                                  /* Pointer to command buffer           */
    CMD   *ptr;                                                 /* Pointer to table of available cmds  */
    char  cmd[80];                                              /* Buffer to hold the command name     */


    cmd[0] = NUL;
    p1     = strchr(s, '$');                                    /* Look for '$' in string              */
    if (p1 != NULLPTR) {                                        /* See if we found a '$'               */
        p1++;                                                   /* We did, position on next character  */
        p2 = &cmd[0];                                           /* Set up to copy command to buffer    */
        while (*p1 != NUL && strchr(" =*", *p1) == NULLPTR) {   /* Copy cmd until '=', '*', ' ' or NUL */
            *p2++ = *p1++;
        }
        *p2 = NUL;                                              /* Append NUL at end of command        */
        ptr = &ListcCmdTable[0];                                /* Search for command in command table */
        while (ptr->CmdName[0] != NUL) {                        /* Go through the whole command table  */
            if (strcmp(ptr->CmdName, cmd) == 0) {               /* See if we found the cmd to execute  */
                ptr->CmdFnct(p1);                               /* We found the command name,          */
                return (TRUE);                                  /* ... execute the function            */
            } else {
                ptr++;                                          /* Look for next entry in cmd table    */
            }
        }
    }
    return (FALSE);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                    LISTC 'PAGE' COMMAND HANDLER
*********************************************************************************************************
*/

static void ListcNewPage(char *s)
{
    s[0] = s[0];                                           /* Prevent compiler warning                 */
    ListcPageN++;                                          /* Increment the page counter               */
    fprintf(stdout, "%c", PRINTER_FORM_FEED);              /* Issue a form feed                        */
    ListcHdr();                                            /* Make the page header                     */
}


/*
*********************************************************************************************************
*                                  LISTC 'TITLE' COMMAND HANDLER
*********************************************************************************************************
*/

static void ListcChangeTitle(char *s)
{
    char *p1;


    ListcTitle[0] = NUL;                                   /* Initialize the TITLE to empty            */
    p1           = &ListcTitle[0];                         /* Position at beginning of destination     */
    s++;                                                   /* Ignore the '='                           */
    while (*s != NUL && strchr("*", *s) == NULLPTR) {      /* Copy command until '*' or NUL            */
        *p1++ = *s++;
    }
    *p1 = NUL;                                             /* Append NUL terminator at end of command  */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                        PRINT PAGE HEADER
*********************************************************************************************************
*/

static void ListcHdr(void)
{
    fprintf(stdout, "              ");
    fprintf(stdout, "%-15s         ", ListcDate);
    fprintf(stdout, "%-15s         ", ListcTime);
    fprintf(stdout, "%-20s         ", ListcFileName);
    fprintf(stdout, "  Page: %03d\n", ListcPageN);
    if (ListcTitle[0] != NUL) {
        fprintf(stdout, "              %s\n", ListcTitle);      /* Output TITLE if we have a title     */
    }
    fprintf(stdout, "\n\n");
}


/*
*********************************************************************************************************
*                                          GET CURRENT DATE
*********************************************************************************************************
*/

static void ListcGetDate(char *str)
{
    struct date today;                                     /* Structure to hold current date           */


    getdate(&today);                                       /* Function to get the current DATE         */
    sprintf(str, "%s %2d, %4d", ListcMonths[today.da_mon], today.da_day, today.da_year);
}


/*
*********************************************************************************************************
*                                          GET CURRENT TIME
*********************************************************************************************************
*/

static void ListcGetTime(char *str)
{
    struct time now;                                       /* Structure to hold current time           */


    gettime(&now);                                         /* Function to get the current TIME         */
    sprintf(str, "%02d:%02d:%02d", now.ti_hour, now.ti_min, now.ti_sec);
}

⌨️ 快捷键说明

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