home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
dmenu1.zip
/
DM10SRC.ZIP
/
EXECUTE.C
< prev
next >
Wrap
Text File
|
1991-10-15
|
10KB
|
417 lines
/***************************************************************************/
byte Do_Query_Window(query)
Menu *query;
{
Win[win_index].event = QUERY;
if ( !Windowfy_Menu( query ) )
return(0);
Display_Menu(NULL);
Select(current_item);
for (;;){
Wait_For_Event();
switch ( event.action ){
case GOTO_ITEM:
Select( Number_To_Item( event.data ) );
break;
case MOVE_UP:
Select(Move_Up());
break;
case MOVE_DOWN:
Select(Move_Down());
break;
case GOTO_END:
Select(End_Item());
break;
case GOTO_TOP:
Select(Home_Item());
break;
case FUNCTION_KEY:
if (function_key[ event.data ]->first_line->text_line[0] == '%' ||
Compare(function_key[ event.data ]->first_line->text_line,"#ask"))
break;
current_item = function_key[ event.data ];
Win[win_index].event = FUNCTION_KEY+current_item->item_number;
Execute_Item();
break;
case ESCAPE:
return(0);
case DO_ITEM:
return(current_item->item_number);
}
}
}
/***************************************************************************/
void Exit_Query()
{
Item *yes,*no;
Menu *exit_query;
if (shadow) Remove_Shadow(left,right,top,bottom);
Display_Menu(current_item);
l_len = 12;
exit_query = Allocate_Menu();
strcpy(exit_query->title,"Exit Menu?");
yes = Allocate_Item();
strcpy(yes->title,"Yes");
no = Allocate_Item();
strcpy(no->title,"No");
exit_query->first_item=yes;
yes->next_item=no;
yes->last_item=NULL;
no->last_item=yes;
no->next_item=NULL;
/* make items choosable */
yes->first_line= current_item->first_line;
no->first_line= current_item->first_line;
yes->item_number=1;
no->item_number=2;
exit_query->number_of_items = 2;
exit_query->title_length = 10;
exit_query->longest_title = 10;
exit_query->offset_x = CENTER;
exit_query->offset_y = CENTER;
exit_query->palette = message_palette;
if ( Do_Query_Window(exit_query) == 1){
Clean_Up();
exit(1);
}
free(current_menu->first_item->next_item);
free(current_menu->first_item);
free(current_menu);
Remove_Window (1);
}
/**************************************************************************/
void Choice_Query(place,temp)
char *place,temp[];
{
Menu *choice_query;
Item *item=NULL;
Linked_Text *line = current_text;
byte i,j,longest, value;
l_len = MAX_LINE;
choice_query = Allocate_Menu();
for (i = 0; *place != ',' && *place!= '\0';i++)
choice_query->title[i] = *(place++);
choice_query->title[i] = '\0';
longest = choice_query->title_length = strlen(choice_query->title);
if (*place != '\0') place++;
choice_query->offset_x = Get_Value(place,default_x);
place = After_Comma(place);
choice_query->offset_y = Get_Value(place,default_y);
place = After_Comma(place);
choice_query->palette = Get_Palette(place,current_menu->palette);
line = line->next_line;
i=0;
while (line != NULL && line->text_line[0] == '"'){
if (item == NULL){
item = Allocate_Item();
choice_query->first_item = item;
item->last_item = NULL;
item->next_item = NULL;
}
else{
item->next_item = Allocate_Item();
item->next_item->last_item = item;
item = item->next_item;
item->next_item = NULL;
}
/* read title from quotes */
for (j=1; line->text_line[j] != '"' && line->text_line[j] != '\0'; j++)
item->title[j-1] = line->text_line[j];
item->title[j-1] = '\0';
if (longest < (byte)(j-1) )
longest = (byte)(j-1) ;
item->item_number = ++i;
/* make it a chooseable option */
item->first_line = line;
line = line->next_line;
}
choice_query->number_of_items = i;
choice_query->longest_title = longest;
value = Do_Query_Window(choice_query);
while (item->last_item != NULL){
item = item->last_item;
free (item->next_item);
}
free(item);
free(choice_query);
if ( value == 0){
*temp = LEAVE_QUERY_MODE;
return;
}
line = current_text; /* find chosen line */
for (;value>0;value--){
line = line->next_line;
}
strcpy( temp, After_Equals(line->text_line) );
while ( line->text_line[0] == '"')
line = line->next_line;
current_text = line;
}
/**************************************************************************/
void Get_Key_String(string,x,y,color)
char string[];
byte x,y,color;
{
byte input=0,length=0;
*string = '\0';
Show_Cursor();
for(;;){
Put_Cursor( (byte) (x+length) ,y);
input = getch();
/* deal with extended key codes */
while (input == 0){
input = getch();
/* change back arrow or del to back space */
if (input == 75 || input == 83 )
input = 8;
else{
if (input >58 && input < 69){
input -= 58;
if (function_key[input] != NULL &&
function_key[ input ]->first_line->text_line[0] != '%' &&
!Compare(function_key[ input ]->first_line->text_line,"#ask") ){
current_item = function_key[ input ];
Win[win_index].event = FUNCTION_KEY+current_item->item_number;
Execute_Item();
}
}
input = getch();
}
}
switch (input){
case 27:
*string = LEAVE_QUERY_MODE;
case 13:
Hide_Cursor();
return;
case 8:
if (length){
length--;
string[length] = '\0';
Draw( (byte)(x+length),y,' ',color);
}
break;
default:
if (length <56){
string[length] = input;
Draw( (byte)(x+length),y,input,color);
length++;
string[length] = '\0';
}
break;
}
}
}
/**************************************************************************/
void String_Query(place,temp)
char *place,temp[];
{
Menu *string_query;
Item *item;
Linked_Text *line = current_text;
byte i=0;
l_len = 10;
item = Allocate_Item();
item->first_line = current_item->first_line;
item->next_item = NULL;
strcpy(item->title," ");
l_len = 60;
string_query = Allocate_Menu();
for (i = 0; *place != ',' && *place!= '\0';i++)
string_query->title[i] = *(place++);
string_query->title[i] = '\0';
place = After_Comma(place);
string_query->offset_x = Get_Value(place,(byte)(max_screen_x>1-30) );
place = After_Comma(place);
string_query->offset_y = Get_Value(place,(byte)(max_screen_y>1+6) );
place = After_Comma(place);
string_query->palette = Get_Palette(place,current_menu->palette);
string_query->title_length = i;
string_query->longest_title = 56;
string_query->number_of_items = 1;
string_query->first_item = item;
if ( Windowfy_Menu(string_query) ){
Display_Menu(NULL);
Get_Key_String( temp, (byte)(left+2), (byte)(top+3),
(byte)(palette[string_query->palette][TEXT] | palette[string_query->palette][BACK]<<4) );
}
else
temp[0] = LEAVE_QUERY_MODE;
free(item);
free(string_query);
current_text = current_text->next_line;
}
/**************************************************************************/
void Make_Batch( void )
{
register char *place;
register byte i;
Vars vars[MAX_VARS];
char temp[MAX_LINE];
byte var_number;
FILE *Temp_Bat;
/* initialize variables */
current_text = current_item->first_line;
var_number = 0;
/* read in variables */
while ( Compare(current_text->text_line,"#ask ") ){
if (var_number == MAX_VARS)
Critical_Error(MEMORY,"Too many variables,");
/* mark place in text list */
vars[var_number].text = current_text;
/* find var.name and record it */
place = After_Space(current_text->text_line);
for (i=1; *place != ' ' && *place != ',' && *place != '\0'; i++ )
temp[i] = *(place++);
place = After_Comma(place);
temp[0] = '%';
temp[i] = '%';
temp[++i] = '\0';
vars[var_number].name = strdup(temp);
/* get value in temp[] */
if (current_text->next_line->text_line[0] == '"')
Choice_Query(place,temp);
else String_Query(place,temp);
/* remove query window */
if (shadow) Remove_Shadow(left,right,top,bottom);
Restore_Screen(Win[win_index].storage,left,right,top,bottom);
Last_Window_Globals();
/* did user request to leave? */
if (*temp == LEAVE_QUERY_MODE ){
free(vars[var_number].name);
for (var_number--;var_number!=255;var_number--){
free(vars[var_number].name);
free(vars[var_number].value);
}
return;
}
else{
vars[var_number].value = strdup(temp);
var_number++;
}
}
/**********************/
/* we're gonna do it! */
/**********************/
Clean_Up();
/* read file name from enviroment into temp */
for (i=0; *(temp_bat+i) != '\0';i++)
temp[i] = *(temp_bat+i);
temp[i]='\0';
/* open file to write */
if ( ( Temp_Bat = fopen(temp, "w" ) ) == NULL ){
Error_Box("Unable to create temporary batch file.","Aborting");
return;
}
/* write file header */
fputs("REM This is a temporary file for DougMenu\n",Temp_Bat);
fputs("REM return: ",Temp_Bat);
for (i=0;i<=win_index;i++){
fputc(Win[i].item->item_number+64,Temp_Bat);
if (i<win_index)
fputc(Win[i].event+64,Temp_Bat);
}
fputc('\n',Temp_Bat);
/* Write the batch file */
while (current_text != NULL){
place = current_text->text_line;
/* Check for special Commands */
if (Compare(place,"#exit") ){
fputs("set t=\n",Temp_Bat);
fclose (Temp_Bat);
exit(2);
}
/* check for variable names */
while (*place != '\0'){
if (*place == '%'){
for (i=0;i<var_number;i++){
if (Compare(place,vars[i].name)){
fputs(vars[i].value,Temp_Bat);
place += strlen(vars[i].name);
break;
}
}
}
if (*place != '\0'){
fputc(*place,Temp_Bat);
place++;
}
}
fputc('\n',Temp_Bat);
current_text = current_text->next_line;
}
fclose (Temp_Bat);
exit(0);
}