Annotation of coherent/g/usr/bin/uuinstall/main.c, revision 1.1

1.1     ! root        1: 
        !             2: #include <stdio.h>
        !             3: #include <fcntl.h>
        !             4: #include <curses.h>
        !             5: #include "uuinstall.h"
        !             6: 
        !             7: 
        !             8: main()
        !             9: {
        !            10:        char choice;
        !            11:        int position;                   /* position of entry within file,
        !            12:                                         * returned by get_entry.
        !            13:                                         */
        !            14: 
        !            15:        umask(0177);
        !            16:        init_curses();                  /* initialize our curses stuff */
        !            17: 
        !            18:        do{
        !            19:                dialflag = 0;           /* set our flags to a default condition */
        !            20:                sysflag = 0;
        !            21:                portflag = 0;
        !            22: 
        !            23:                prevrow = 0;            /* set up our coordinates to highlite */
        !            24:                prevcol = 1;            /* an entry */
        !            25:                newrow = 0;
        !            26:                newcol = 1;
        !            27: 
        !            28:                open_menu();            /* print our opening (main) menu */
        !            29: 
        !            30:                choice = get_main_opt();   /* get user's choice of file to
        !            31:                                            * work with or possibly exit.
        !            32:                                            */
        !            33: 
        !            34: /* Here's the scoop: Now that we have a file to work with, we need to find
        !            35:  * out what to do with it... modify, add, delete or view and entry. We call
        !            36:  * get_action() to determine this. get_action() will return a -1 if we're not
        !            37:  * going to do anything. If we're going to view, delete or edit a file, we
        !            38:  * call open_config() file to open the proper file and set up our selection
        !            39:  * screen, then we  call get_entry to get the entry number in the file we
        !            40:  * will work with. If we don't select an entry with get_entry(), a -1 is
        !            41:  * returned, else we display the record.
        !            42: 
        !            43:  * display_rec() does more than just display a record. From there, we delete
        !            44:  * an entry or modify and entry.
        !            45:  */
        !            46:                switch(choice){
        !            47:                        case 'd':       dialflag = 1;   /* work with dial file */
        !            48:                                        action = get_action();
        !            49:                                        if ((action != 'a') && (action != -1)){
        !            50:                                                open_config_file();
        !            51:                                                position = get_entry();
        !            52:                                                if (position != -1)
        !            53:                                                        display_rec(position,action);
        !            54:                                        }
        !            55:                                        if(action == 'a')
        !            56:                                                add_dial();
        !            57:                                        break;  
        !            58: 
        !            59:                        case 'p':       portflag = 1;   /* work with port file */
        !            60:                                        action = get_action();
        !            61:                                        if ((action != 'a') && (action != -1)){
        !            62:                                                open_config_file();
        !            63:                                                position = get_entry();
        !            64:                                                if (position != -1);
        !            65:                                                        display_rec(position,action);
        !            66:                                        }
        !            67:                                        if(action == 'a')
        !            68:                                                add_port();
        !            69:                                        break;
        !            70: 
        !            71:                        case 's':       sysflag = 1;    /* work with sys file */
        !            72:                                        action = get_action();
        !            73:                                        if ((action != 'a') && (action != -1)){
        !            74:                                                open_config_file();
        !            75:                                                position = get_entry();
        !            76:                                                if(position != -1)
        !            77:                                                        display_rec(position,action);
        !            78:                                        }
        !            79:                                        if (action == 'a')
        !            80:                                                add_sys();
        !            81:                                        break;
        !            82: 
        !            83:                        case 'q':       exit_program(0);
        !            84:                                        /* NOT REACHED */
        !            85:                }
        !            86:                choice = '\0';
        !            87:                action = '\0';
        !            88:                wclear(selwin);
        !            89:                wclear(promptwin);
        !            90:                wrefresh(selwin);
        !            91:                wrefresh(promptwin);
        !            92:        }
        !            93:        while (choice != 'q');
        !            94: }
        !            95: 
        !            96: 
        !            97: /* initialize curses stuff: allocate new windows, set up stdscr */
        !            98: 
        !            99: init_curses()
        !           100: {
        !           101: 
        !           102:        /* This is the window that will be used to display and highlight
        !           103:         * file entry selections.
        !           104:         */
        !           105:        if ((selwin = newwin(20, 80, 0 ,0)) == NULL)
        !           106:                fatal("Failed to allocate selection window.");
        !           107: 
        !           108:        /* this window will be used to display prompts and some help info */
        !           109:        if((promptwin = newwin(4, 40, 20, 0)) == NULL)
        !           110:                fatal("Failed to allocate prompt window.");
        !           111: 
        !           112:        /* this window will do the data entry and display work as well as
        !           113:         * some prompting and help functions.
        !           114:         */
        !           115:        if((portwin = newwin(24, 80, 0, 0)) == NULL)
        !           116:                fatal("Failed to allocate prompt window.");
        !           117: 
        !           118: 
        !           119:        initscr();
        !           120:        raw();
        !           121:        noecho();
        !           122:        clear();
        !           123:        refresh();
        !           124: }
        !           125: 
        !           126: 
        !           127: /* exit_program: resets curses stuff and exits program. */
        !           128: 
        !           129: exit_program(stat)
        !           130: int stat;              /* exit status passed by calling function */
        !           131: {
        !           132:        clear();
        !           133:        refresh();
        !           134:        echo();
        !           135:        noraw();
        !           136:        exit(stat);
        !           137: }
        !           138: 
        !           139: /* open_menu() prints our opening screen where we display the name of
        !           140:  * the system we happen to be and prompt to examine the port, sys or
        !           141:  * dial files.
        !           142:  */
        !           143: 
        !           144: open_menu()
        !           145: {
        !           146: 
        !           147:        move(3,25);
        !           148:        standout();
        !           149:        printw("UUCP Configuration: Main menu");
        !           150:        standend();
        !           151: 
        !           152:        move(SYSLINE,5);
        !           153:        printw("<s>ys file              Configuration information for specific systems");
        !           154:        move(PORTLINE,5);
        !           155:        printw("<p>ort file     Information for individual ports");
        !           156:        move(DIALLINE,5);
        !           157:        printw("<d>ial file     Configuration information for dialing modems");
        !           158:        
        !           159: 
        !           160:        move(20,5);
        !           161:        printw("Press the letter corresponding to the file you wish to examine");
        !           162:        move(21,27);
        !           163:        printw("or <q> to quit.");
        !           164:        refresh();
        !           165: }
        !           166: 
        !           167: 
        !           168: /* get_main_opt():     Gets the user's choice of which file to process,
        !           169:  *                     which is one of the uucp config files or to exit.
        !           170:  */
        !           171: 
        !           172: get_main_opt()
        !           173: {
        !           174: 
        !           175:        char ch;
        !           176: 
        !           177:        ch = ' ';
        !           178: 
        !           179:        while( (ch != 'q') && (ch != 'p') && (ch != 's') && (ch != 'd')){
        !           180:                ch = getch();
        !           181:        }
        !           182: 
        !           183:        return (ch);
        !           184: }
        !           185:                
        !           186: 
        !           187: /* get_action(): The user will have selected a configuration file to work
        !           188:  *             with by this time. This will prompt the user to perform
        !           189:  *             one of the following functions: ADD an entry, REMOVE an
        !           190:  *             existing entry or MODIFY an existing entry.
        !           191:  */
        !           192: 
        !           193: get_action()
        !           194: {
        !           195:        char ch;
        !           196:        char file[5];
        !           197:        clear();
        !           198: 
        !           199:        move(1,34);
        !           200:        standout();
        !           201:        printw("Action menu");
        !           202:        standend();
        !           203: 
        !           204:        move(5,17);
        !           205: 
        !           206:        /* determine which file we are working with from the flag(s) set and
        !           207:         * print a small message to reflect this as a cue to the user.
        !           208:         */
        !           209: 
        !           210:        if(dialflag)
        !           211:                strcpy(file,"dial");
        !           212:        if(sysflag)
        !           213:                strcpy(file,"sys");
        !           214:        if(portflag)
        !           215:                strcpy(file, "port");
        !           216: 
        !           217:        printw("You have selected to work with the %s file.",file);
        !           218:        move(7,17);
        !           219:        printw("Do you wish to:");
        !           220:        move(8,32);
        !           221:        printw("<a>dd an entry");
        !           222:        move(9,32);
        !           223:        printw("<d>elete an existing entry");
        !           224:        move(10,32);
        !           225:        printw("<m>odify an existing entry");
        !           226:        move(11,32);
        !           227:        printw("<v>iew an existing entry");
        !           228: 
        !           229:        move(15,12);
        !           230:        printw("Press the letter corresponding to the action you wish to");
        !           231:        move(16,18);
        !           232:        printw("perform or press <RETURN> for the main menu.");
        !           233: 
        !           234:        refresh();
        !           235: 
        !           236:        do{
        !           237:                ch = getch();
        !           238:        }
        !           239:        while( (ch!='\n') && (ch!='a') && (ch!='d') && (ch!='m') && (ch!='v'));
        !           240:        clear();
        !           241:        refresh();
        !           242: 
        !           243:        if (ch == '\n')
        !           244:                ch = -1;
        !           245: 
        !           246:        return (ch);
        !           247: }

unix.superglobalmegacorp.com

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