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

📄 transfer.cpp

📁 串行通信编程源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:

        case 1:                             // file not found
        case 2:                             // user cancelled transfer
        case 3:                             // fatal protocol error
        case 4:                             // receiver cancelled download
        case 5:                             // file error
        case 14:                            // user cancelled upload
            ul_win.Display(dl_msg[rc]);     // give user a message
            loop = 0;                       // ..clear loop control
            break;                          // ..and exit loop
        }
    }

free(filename);                             // release memory
wait_ms(3000L);                             // ..wait a bit
return(ESC);                                // ..then return to caller

}



/* ******************************************************************** *
 *
 *  ul_ymodem() -- ymodem upload menu routine
 *
 * ******************************************************************** */


int     ul_ymodem(int c, int r)             // column and row for window
{
Window  ul_win(c, r,                        // define temporary window
            c + 45, r + 7,                  // ..to hold message
            menu_cn, menu_cr);              // ..using system colors

char   *st[5] = { 0, 0, 0, 0, 0},           // send table
       *wc,                                 // work pointer
       *blanks = "            ";            // blanks

YModem  ymodem(comm, ym_stat, &ul_win);     // define YMODEM instance

int     idx = 0,                            // current index
        i,                                  // work variable
        k,                                  // keystroke
        loop = 1;                           // loop indicator


ul_win.Open(double_line);                   // open window with a border
ul_win.Display(dl_msg[16]);                 // initialize the window
idx = 2;                                    // initial entry ..


while (loop)                                // loop till user exits
    {
    for (i = 0; i < 5; i++)                 // for each entry
        {
        ul_win.GotoXY(3, i+2);              // position the cursor

        if (st[i])                          // q. entry filled in?
            touppers(st[i]);                // a. yes .. uppercase it

        if ((i + 2) == idx)                 // q. current entry?
             ul_win.DisplayReverse(         // a. yes .. in reverse
                st[i] ? st[i] : blanks);    // .. display field or blanks
         else
             ul_win.Display(                // else .. in normal
                st[i] ? st[i] : blanks);    // .. display field or blanks
        }

    while (NOT (k = get_key(NO_ALT)))       // wait for a key
        ;                                   // ..before continuing

    switch (k)                              // based on keyboard input
        {
        case SPACE:                         // edit selected entry
            field_edit(&ul_win, 3, idx,     // edit the field
               &st[idx - 2], 12);

            if (! first_nonblank(st[idx-2]))// q. empty string?
                {
                free(st[idx-2]);            // a. yes .. release memory
                st[idx-2] = NULL;           // .. kill the pointer
                }
            break;


        case CR:                            // send the files
            loop = 0;                       // ..exit the loop
            break;

        case UP:                            // move up list
            if (--idx < 2)                  // q. already at top of list?
                idx = 6;                    // a. yes .. go to bottom
            break;                          // wait for next key

        case DOWN:                          // move down list
            if (++idx == 7)                 // q. already at bottom?
                idx = 2;                    // a. yes .. goto top of list
            break;                          // wait for next key

        case ESC:                           // escape from this menu
            k = 0;                          // set key value to zero
                                            // ..and fall into next case

        case LEFT:                          // move left
        case RIGHT:                         // ..or move right
            for (i = 0; i < 5; i++)         // for each entry in SendTable
                if (st[i])                  // q. entry used?
                    {                       // a. yes ..
                    free(st[i]);            // .. free the memory
                    st[i] = NULL;           // .. clear the pointer
                    }

            return(k);                      // just rtn with the keystroke

        default:                            // error case
            printf(BELL);                   // ..just ring the bell
        }
    }

for (i = 0; i < 5; i++)                     // remove trailing blanks
    if ((wc = strchr(st[i], ' ')) != 0)     // q. blank found?
        *wc = 0;                            // a. yes .. end string there

ul_win.Clear();                             // clear upload window
ul_win.GotoXY(1, 1);                        // start from new position

ymodem.Send(st);                            // perform the upload

for (i = 0; i < 5; i++)                     // for each entry in SendTable
    if (st[i])                              // q. entry used?
       {                                    // a. yes ..
       free(st[i]);                         // .. free the memory
       st[i] = NULL;                        // .. clear the pointer
       }


wait_ms(3000L);                             // ..and wait a bit
return(ESC);                                // ..and return to caller

}


/* ******************************************************************** *
 *
 *  fax_list() -- select phone book entry for fax number
 *
 * ******************************************************************** */

char   *fax_list(int c, int r)              // column and row for window
{
int     i,                                  // loop counter
        k,                                  // keyboard input
        idx;                                // line index

char    b[40],                              // work buffer
       *p;                                  // work pointer

Window  faxno_win(c, r, c + 35,             // define temporary window
            r + COUNT(phonebook) + 1,       // ..to hold fax number list
            menu_cn, menu_cr);              // ..using system colors


faxno_win.Open(double_line);                // open window with a border
idx = 0;                                    // set up for first entry

while(1)                                    // loop till user exits
    {
    for (i = 0; i < COUNT(phonebook); i++)  // walk thru phonebook
        {
        if ((p = phonebook[i].PB_NAME) == 0)// q. name available?
            p = "";                         // a. no .. point at null str

        sprintf(b, "%2d. %-27.27s",         // format a buffer with name
                i + 1, p);                  // ..and line number
        faxno_win.GotoXY(2, i + 1);         // position to start of line

        if (i == idx)                       // q. selected line?
            faxno_win.DisplayReverse(b);    // a. yes .. highlight line
         else
            faxno_win.Display(b);           // else .. just display it
        }

    while (NOT (k = get_key(NO_ALT)))       // wait for a key
        ;                                   // ..before continuing

    switch (k)                              // based on keyboard input
        {
        case CR:                            // entry selected
            return(phonebook[idx].PB_FAX);  // ..return the fax number

        case UP:                            // move up list
            if (--idx < 0)                  // q. already at top of list?
                idx = COUNT(phonebook) - 1; // a. yes .. goto bottom

            break;                          // wait for next key

        case DOWN:                          // move down list
            if (++idx == COUNT(phonebook))  // q. already at bottom?
                idx = 0;                    // a. yes .. goto top of list

            break;                          // wait for next key

        case ESC:                           // escape from this menu
            return(NULL);                   // set key value to zero
                                            // ..and fall into next case

        default:                            // error case
            printf(BELL);                   // ..just ring the bell
        }
    }
}



/* ******************************************************************** *
 *
 *  rcv_fax() -- receive a fax
 *
 * ******************************************************************** */

int     rcv_fax(int c, int r)               // column and row for window
{
Window  fax_win(c-20, r,                    // define temporary window
            c + 25, r + 18,                 // ..to hold message
            menu_cn, menu_cr);              // ..using system colors

Fax     fax(comm,                           // define Fax instance
            user_commands.Find("SID"),
            fax_stat, &fax_win);

char   *filename = 0,                       // file to receive
        msgbuf[50];                         // message buffer

fax_win.Open(double_line);                  // open window with a border
fax_win.Display(fax_msgs[40]);              // give filename prompt

if (field_edit(&fax_win,                    // q. prompt for the filename
            strlen(dl_msg[0]) + 1, 1,       // ..on the 1st row, did we
            &filename, 12) == 0)            // ..get a good user response?
    return(ESC);                            // a. no .. return to caller

if (NOT first_nonblank(filename))           // q. empty string?
    {
    free(filename);                         // a. yes .. release memory
    return(ESC);                            // ..and return to caller
    }

touppers(filename);                         // uppercase the file name

fax_win.Clear();                            // clear the window
sprintf(msgbuf, fax_msgs[0], "Receiving",   // format initial message
                             filename);
fax_win.DisplayReverse(msgbuf);             // display initial message

fax.Receive(filename);                      // receive a fax
free(filename);                             // free the file name buffer

fax_win.DisplayReverse(                     // display request for a key
    " -- Press any key to continue -- ");

while (NOT get_key(NO_ALT))                 // wait for a key
    ;                                       // ..before closing down

return(ESC);                                // ..and return to caller

}



/* ******************************************************************** *
 *
 *  send_fax() -- send a fax
 *
 * ******************************************************************** */

int     send_fax(int c, int r)              // column and row for window
{
Window  fax_win(c-20, r,                    // define temporary window
            c + 25, r + 18,                 // ..to hold message
            menu_cn, menu_cr);              // ..using system colors
Fax     fax(comm,                           // define Fax instance
            user_commands.Find("SID"),
            fax_stat, &fax_win);
char   *faxno,                              // pointer to fax telephone no.
       *filename = 0,                       // file to receive
        msgbuf[50];                         // message buffer


faxno = fax_list(c, r);                     // select an entry

if (faxno)                                  // q. any fax number?
    {                                       // a. yes ..
    fax_win.Open(double_line);              // open window with a border
    fax_win.Display(fax_msgs[40]);          // give filename prompt

    if (field_edit(&fax_win,                // q. prompt for the filename
            strlen(dl_msg[0]) + 1, 1,       // ..on the 1st row, did we
            &filename, 12) == 0)            // ..get a good user response?
        return(ESC);                        // a. no .. return to caller

    if (NOT first_nonblank(filename))       // q. empty string?
        {                                   // a. yee ..
        free(filename);                     // .. release memory
        return(ESC);                        // ..and return to caller
        }

    touppers(filename);                     // uppercase the file name

    fax_win.Clear();                        // clear the window

    sprintf(msgbuf, fax_msgs[0], "Sending", // format initial message
                    filename);

    fax_win.DisplayReverse(msgbuf);         // display initial message

    sprintf(msgbuf, "Calling: %s\r\n",      // format calling message
                    faxno);

    fax_win.Display(msgbuf);                // display calling message

    fax.Send(filename, faxno);              // send a fax
    free(filename);                         // free the file name buffer

    fax_win.DisplayReverse(                 // display request for a key
       " -- Press any key to continue -- ");

    while (NOT get_key(NO_ALT))             // wait for a key
        ;                                   // ..before closing down
    }

return(ESC);                                // ..and return to caller

}

⌨️ 快捷键说明

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