Annotation of coherent/e/bin/uuinstall/add_port.c, revision 1.1.1.1

1.1       root        1: /* add_port.c: add a port entry to the port file. This will get the
                      2:  *             info from a curses screen and write an entry to the
                      3:  *             port file.
                      4:  */
                      5: 
                      6: #include <string.h>
                      7: #include "uuinstall.h"
                      8: 
                      9: /* add_port merely calls up a template and then calls a function to
                     10:  * position the cursor to get data. If the user chooses to save the
                     11:  * entered data, it is saved to the port file.
                     12:  */
                     13: 
                     14: add_port()
                     15: {
                     16:        char z;
                     17:        FILE *portfd;
                     18: 
                     19:        port_template();
                     20:        z = get_port_data();
                     21:        if (z == 'y'){
                     22:                if( (portfd = fopen(PORTFILE,"a")) == NULL){
                     23:                        mvwaddstr(portwin,7,5,"ERROR opening file for writing!    ");
                     24:                        wrefresh(portwin);
                     25:                        sleep(5);
                     26:                        return;
                     27:                }
                     28:                wclear(portwin);
                     29:                mvwaddstr(portwin,12,32,"Adding entry...");
                     30:                wrefresh(portwin);
                     31:                sleep(1);
                     32: 
                     33:                fprintf(portfd, "\n%s\n",portname);
                     34:                fprintf(portfd, "%s\n", porttype);
                     35:                fprintf(portfd, "%s\n",portdev);
                     36:                fprintf(portfd, "%s\n",portspeed);
                     37: 
                     38:                if(strstr(porttype,"modem")){
                     39:                        fprintf(portfd, "%s\n",portdial);
                     40:                }
                     41: 
                     42:                fclose(portfd);
                     43:        }
                     44:        wclear(portwin);
                     45:        wrefresh(portwin);
                     46: }
                     47: 
                     48: 
                     49: /* draw a template on the data entry screen */
                     50: port_template()
                     51: {
                     52:        wclear(portwin);
                     53:        mvwaddstr(portwin,9,10,"port");
                     54:        mvwaddstr(portwin,10,10,"type");
                     55:        mvwaddstr(portwin,11,10,"device");
                     56:        mvwaddstr(portwin,12,10,"baud");
                     57:        mvwaddstr(portwin,13,10,"dialer");
                     58: 
                     59:        wstandout(portwin);
                     60:        mvwaddstr(portwin,0,29,"Port File Entry Screen");
                     61:        mvwaddstr(portwin,9,17,"              ");
                     62:        mvwaddstr(portwin,10,17,"      ");
                     63:        mvwaddstr(portwin,11,17,"/dev/              ");
                     64:        mvwaddstr(portwin,12,17,"     ");
                     65:        mvwaddstr(portwin,13,17,"              ");
                     66:        wstandend(portwin);
                     67:        wrefresh(portwin);
                     68: }
                     69: 
                     70: 
                     71: /* get the data for this port */
                     72: get_port_data()
                     73: {
                     74: 
                     75:        char mdm;                       /* flag for modem or direct connect */
                     76:        char * workstring;
                     77: 
                     78:        /* initialize the fields we will fill */
                     79:        strcpy(portname,"port ");
                     80:        strcpy(porttype,"type ");
                     81:        strcpy(portdev,"device /dev/");
                     82:        strcpy(portspeed,"baud ");
                     83:        strcpy(portdial,"dialer ");
                     84: 
                     85: 
                     86:        /* get a port name */
                     87:        wmove(portwin,20,0);
                     88:        wclrtobot(portwin);
                     89:        mvwaddstr(portwin,20,0,"Enter the name that you want");
                     90:        mvwaddstr(portwin,21,0,"associated with  the  device");
                     91:        mvwaddstr(portwin,22,0,"that this entry will define.");
                     92:        mvwaddstr(portwin,23,0,"Enter nothing to cancel.");
                     93:        wrefresh(portwin);
                     94: 
                     95:        workstring = get_data(portwin,9,17,14,0,1);             /* get port name */
                     96:        if (strlen(workstring) == 0)
                     97:                return('n');
                     98: 
                     99:        strcat(portname,workstring);
                    100: 
                    101:        /* now find out if this is a direct or modem connection */
                    102: 
                    103:        wmove(portwin,20,0);
                    104:        wclrtobot(portwin);
                    105:        mvwaddstr(portwin,20,0,"This  port  must  be  a  direct");
                    106:        mvwaddstr(portwin,21,0,"data line connection or used by");
                    107:        mvwaddstr(portwin,22,0,"a modem.  You must specify this.");
                    108:        wrefresh(portwin);
                    109: 
                    110:        strcpy(workstring,"");
                    111:        mvwaddstr(portwin,15,5,"Is this a <d>irect or <m>odem connection?");
                    112:        wrefresh(portwin);
                    113:        do{
                    114:                mvwaddstr(portwin,17,12,"Press 'd' or 'm'.");
                    115:                wrefresh(portwin);
                    116:                mdm = wgetch(portwin);
                    117:        }
                    118:        while ((mdm != 'd') && (mdm != 'm'));
                    119: 
                    120:        wmove(portwin, 10, 17);
                    121:        if (mdm == 'd'){
                    122:                wstandout(portwin);
                    123:                wprintw(portwin,"direct");
                    124:                wstandend(portwin);
                    125:                strcat(porttype,"direct");
                    126:        }else{
                    127:                wstandout(portwin);
                    128:                wprintw(portwin,"modem");
                    129:                wstandend(portwin);
                    130:                strcat(porttype,"modem");
                    131:        }
                    132: 
                    133:        wmove(portwin,15,4);
                    134:        wclrtoeol(portwin);
                    135:        wmove(portwin,17,1);
                    136:        wclrtoeol(portwin);
                    137:        wrefresh(portwin);
                    138:        strcpy(workstring,"");
                    139: 
                    140: 
                    141:        /* Now get the device associated with this port */
                    142: 
                    143:        wmove(portwin,20,0);
                    144:        wclrtobot(portwin);
                    145:        mvwaddstr(portwin,20,0,"Enter  the name  of the  actual");
                    146:        mvwaddstr(portwin,21,0,"device. Examples: com2l, com1fl.");
                    147:        wrefresh(portwin);
                    148: 
                    149:        workstring = get_data(portwin,11,22,14,1,1);
                    150:        strcat(portdev,workstring);
                    151:        strcpy(workstring,"");
                    152: 
                    153:        /* now get the speed of this port */
                    154: 
                    155:        wmove(portwin,20,0);
                    156:        wclrtobot(portwin);
                    157:        mvwaddstr(portwin,20,0,"Enter baud rate that communications");
                    158:        mvwaddstr(portwin,21,0,"will take place with via this port.");
                    159:        mvwaddstr(portwin,22,0,"Examples: 1200, 2400, 9600, 19200.");
                    160:        wrefresh(portwin);
                    161: 
                    162:        workstring = get_data(portwin,12,17,5,1,1);
                    163:        strcat(portspeed,workstring);
                    164:        strcpy(workstring,"");
                    165: 
                    166:        /* now get a dialer name. This will only be needed if
                    167:         * this is a modem connection.
                    168:         */
                    169: 
                    170:        if (strstr(porttype,"modem")){
                    171: 
                    172:                wmove(portwin,20,0);
                    173:                wclrtobot(portwin);
                    174:                mvwaddstr(portwin,20,0,"Enter the name of the dialer entry");
                    175:                mvwaddstr(portwin,21,0,"from  the dial file  that will  be");
                    176:                mvwaddstr(portwin,22,0,"used to dial this modem.");
                    177:                wrefresh(portwin);
                    178: 
                    179:                workstring = get_data(portwin,13,17,14,1,1);
                    180:                strcat(portdial, workstring);
                    181:                strcpy(workstring,"");
                    182:        }
                    183: 
                    184:        wmove(portwin,20,0);
                    185:        wclrtobot(portwin);
                    186:        mvwaddstr(portwin,7,5,"Do you wish to write this entry? (y/n)");
                    187:        wrefresh(portwin);
                    188:        do{
                    189:                mdm = wgetch(portwin);
                    190:        }
                    191:        while ((mdm != 'y') && (mdm != 'n'));
                    192: 
                    193:        wmove(portwin,7,1);
                    194:        wclrtoeol(portwin);
                    195:        wrefresh(portwin);
                    196:        return(mdm);
                    197: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.