📄 menudrv.c
字号:
if ( ! ((ch=='Y') || (ch=='N')) ) putch(7);
} while ( ! ((ch=='Y') || (ch=='N')) );
if ( ch == 'Y' ) {
/*adding a submenu reference*/
cdescription[0] = 0;
ctomenu = ' ';
editmenu();
ctomenu = toupper(ctomenu);
citem = toupper(citem);
{
item[j]->id = cmenu;
item[j]->prompt = citem;
strcpy(item[j]->description,cdescription);
item[j]->tomenu = ctomenu;
item[j]->firstline = NULL;
}
/*check to see if target menu exists*/
n = 1;
while ( (item[n]->id != ctomenu)
&& (n < items) ) n++;
if ( item[n]->id != ctomenu ) {
/*add one item for the new menu*/
item[items + 1] =
(menuptr) calloc(1,sizeof(*item[items + 1]));
items++;
{
item[items]->id = ctomenu;
item[items]->tomenu = 'M';
item[items]->prompt = 'X';
strcpy(item[items]->description,
"Return to Main Menu");
item[items]->firstline = NULL;
}
}
datachanged = TRUE;
goto L90;
} /*if new menu entry*/
}
else { /*old item*/
if ( item[j]->tomenu != '*' ) {
strcpy(cdescription,item[j]->description);
ctomenu = item[j]->tomenu;
editmenu(); /* ** */
strcpy(item[j]->description,cdescription);
item[j]->tomenu = ctomenu;
item[j]->prompt = citem;
datachanged = TRUE;
goto L90;
}
/*load the item's data*/
for ( n = 1; n <= 19; n++ ) {
edscreen[n][0]=0;
pad(edscreen[n],77);
}
cp = item[j]->firstline;
i = 1;
while ( (cp != NULL) && (i <= 19) ) {
strcpy(edscreen[i],cp->line);
pad(edscreen[i],77);
cp = cp->next;
i++;
}
strcpy(cdescription,item[j]->description);
}
edit();
/*save results*/
strcpy(item[j]->description,cdescription);
cp = item[j]->firstline;
i = 1;
op = NULL; /* op holds last valid pointer */
while ( (cp != NULL) && (i <= 19) ) {
strcpy(cp->line,edscreen[i]);
op = cp;
cp = cp->next;
i++;
}
cp = op; /*restore last pointer*/
/*catch any added lines*/
for ( n = i; n <= 19; n++ ) {
if ( nonblank(edscreen[n]) ) {
np = (lineptr) calloc(1,sizeof(*np));
strcpy(np->line,edscreen[n]);
if ( item[j]->firstline == NULL ) {
item[j]->firstline = np;
}
else {
cp->next = np;
}
np->next = NULL;
cp = np;
}
}
datachanged = TRUE;
goto L90;
}
case '\x3C': /*F2-delete item*/
{
gotoxy(1,22);
clreol();
cprintf("%s", "Delete which item? ");
citem=getch();
cprintf("%c", citem);
citem = toupper(citem);
j = i;
/*look for match*/
while ( (item[j]->prompt != citem) && (j < items)
&& (item[j]->id == cmenu) ) j++;
if ( item[j]->prompt != citem ) {
cprintf("%c", '\x07');
restorescreen(1);
goto L10;
}
gotoxy(1,22);
clreol();
cprintf("%s%s%s", "Delete ",
item[j]->description, " (Y/N)? ");
ch=getch();
ch = toupper(ch);
if ( ch == 'Y' ) {
/* free storage for deleted item's lines */
cp = item[j]->firstline;
while (cp != NULL) {
op=cp->next;
free(cp);
cp=op;
}
/* shift everything down 1 */
for ( n = j; n < items; n++) {
*item[n] = *item[n + 1];
}
/* free storage for previous last item */
free(item[items]);
item[items]=NULL;
items--;
datachanged = TRUE;
}
goto L90;
}
case '\x3D': /*F3 - move item*/
{
gotoxy(1,22);
clreol();
cprintf("%s", "Move which item? ");
citem=getch();
cprintf("%c", citem);
citem = toupper(citem);
j = i;
/*look for match*/
while ( (item[j]->prompt != citem) && (j < items)
&& (item[j]->id == cmenu) ) {
j = j + 1;
}
if ( item[j]->prompt != citem ) {
/*item not found*/
gotoxy(1,22);
cprintf("%s%s", "Item not found. ",
"Press a key to continue.");
ch=getch();
restorescreen(1);
goto L10;
}
gotoxy(1,22);
clreol();
cprintf("%s",
"Which item should this one follow? ");
ch=getch();
ch = toupper(ch);
if ( ch == '\x0D' ) {
/*top of menu*/
n = 1;
while ( (item[n]->id != cmenu) ) n++;
}
else {
n = i;
/*look for match*/
while ( (item[n]->prompt != ch) && (n < items)
&& (item[n]->id == cmenu) ) n++;
if ( item[n]->prompt != ch ) {
cprintf("%c", '\x07');
restorescreen(1);
goto L10;
}
n++; /*position for new item*/
}
/*item being moved is item[j]; we are */
/* moving it to position [n]*/
tempitem = *item[j]; /*save item*/
if ( n < j ) {
for ( k = j; k >= n + 1; --k ) {
*item[k] = *item[k - 1];
}
*item[n] = tempitem;
}
else {
if ( j < n ) {
n--;
for ( k = j; k <= n - 1; ++k ) {
*item[k] = *item[k + 1];
}
*item[n] = tempitem;
}
}
goto L90;
}
#endif
case '\x3E': /*F4-edit colors*/
{
editcolor(); /* ** */
parmchanged = TRUE;
goto L90;
}
default:
goto L10;
} /*case*/
} /*if #0*/
cprintf("%c", ch);
ch = toupper(ch);
j = i; /*look for match*/
while ( (item[j]->prompt != ch) && (j < items)
&& (item[j]->id == cmenu) ) j++;
if ( (item[j]->prompt != ch) || (item[j]->id != cmenu) ) {
cprintf("%c", '\x07');
}
else {
good = TRUE;
}
} /*while not good*/
/*user has selected item[j]*/
if ( item[j]->tomenu != '*' ) cmenu = item[j]->tomenu;
else { /*doing action for the '*' item*/
cp = item[j]->firstline;
/*determine whether background job requested or not*/
if ( cp->line[0] == '&' ) gotchild = TRUE;
else gotchild = FALSE;
if ( ! gotchild ) batfile = fopen(bfname,"w");
while ( cp != NULL ) {
if ( strstr(cp->line,"[") == NULL ) {
if ( gotchild ) strcpy(temp2,cp->line);
else fprintf(batfile,"%s\n", cp->line);
}
else { /*handle [xx] parameter passing*/
strcpy(temp, cp->line);
otline[0] = 0;
do {
cptr = strstr(temp,"[");
if ( cptr == NULL ) strcat(otline,temp);
else {
*cptr=0;
strcat(otline,temp);
*cptr=' ';
strdel(temp,0,cptr-temp+1);
gotoxy(1,22);
clreol();
cptr = strstr(temp,"]");
*cptr=0;
cprintf("%s%c", temp, ' ');
*cptr=' ';
resp[0]=0;
col=1;
getstring(wherex(),wherey(),&col,resp,78-wherex());
trim(resp);
strcat(otline,resp);
strdel(temp,0,cptr-temp+1);
cptr = strstr(temp,"[");
} /*else*/
} while ( cptr != NULL );
if ( gotchild ) strcpy(temp2,otline);
else fprintf(batfile,"%s\n",otline);
} /*else*/
if ( gotchild ) { /*performing as a child process*/
if ( temp2[0] == '&' ) strdel(temp2,0,1);
for ( r = 23; r <= 25; ++r ) {
gotoxy(1,r);
clreol();
}
gotoxy(1,23);
r = system(temp2);
switch ( r ) {
case 0:
break; /*ok*/
case 1:
{
cprintf("%s%c","Invalid function", '\x07');
cprintf("%s", "..Press a key to continue..");
ch=getch();
}
break;
case 2:
{
cprintf("%s%c","File/path not found", '\x07');
cprintf("%s", "..Press a key to continue..");
ch=getch();
}
break;
case 8:
{
cprintf("%s%c","Not enough memory to load program", '\x07');
cprintf("%s", "..Press a key to continue..");
ch=getch();
}
break;
case 10:
{
cprintf("%s%c", "Bad environment (greater than 32K)", '\x07');
cprintf("%s", "..Press a key to continue..");
ch=getch();
}
break;
case 11:
{
cprintf("%s%c", "Illegal .EXE file format", '\x07');
cprintf("%s", "..Press a key to continue..");
ch=getch();
}
break;
default:
cprintf("%c", '\x07');
break;
} /*case*/
} /*if gotchild*/
cp = cp->next; /*follow linked list*/
} /*while*/
if ( ! gotchild ) {
fclose(batfile);
done = TRUE; /*exit and execute batch file*/
} /*if not gotchild*/
} /*else doing action*/
} /*else got good menu*/
L90:
;
} while ( ! (done) );
if ( color(back3) > 7 ) {
textcolor(color(fore3) + blink);
}
else {
textcolor(color(fore3));
}
textbackground(color(back3));
border(color(back3));
clrscr();
if ( datachanged ) savemenu();
if ( parmchanged ) saveparm();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -