int lh_lf(char *args) { int rc = err_out_of_memory; char *fullname, *fnam; assert(args); if (initialise() == OK) { if ((rc = parseArgs(args, &fnam, &args)) == OK) { /* command line was OK - try to find the file */ fullname = find_which(fnam); free(fnam); if (fullname) { /* a file was found - allocate the memory */ if (loadfix_flag) rc = loadfix_prepare(); else rc = loadhigh_prepare(); /* finally, execute the file */ if (!rc) rc = exec(fullname, args, 0); } else rc = err_file_not_found; } } cleanup(); /* if any error occurred, rc will hold the error code */ if (rc) lh_error(rc); return rc; }
static void execute(char *first, char *rest) { /* * This command (in first) was not found in the command table * * * first - first word on command line * rest - rest of command line * */ char *fullname; assert(first); assert(rest); /* check for a drive change */ if ((strcmp(first + 1, ":") == 0) && isalpha(*first)) { changeDrive(*first); return; } if (strchr(first,'?') || strchr(first,'*')) { error_bad_command(); return; } /* search through %PATH% for the binary */ errno = 0; fullname = find_which(first); dprintf(("[find_which(%s) returned %s]\n", first, fullname)); if (!fullname) { error_bad_command(); return; } /* check if this is a .BAT file */ assert(strrchr(fullname, '.')); if (stricmp(strrchr(fullname, '.'), ".bat") == 0) { dprintf(("[BATCH: %s %s]\n", fullname, rest)); batch(fullname, first, rest); } else /* exec the program */ { int result; dprintf(("[EXEC: %s %s]\n", fullname, rest)); if (strlen(rest) > MAX_EXTERNAL_COMMAND_SIZE) { error_line_too_long(); return; } /* Prepare to call an external program */ /* Unload the message block if not loaded persistently */ if(!persistentMSGs) unloadMsgs(); /* Execute the external program */ #ifdef FEATURE_KERNEL_SWAP_SHELL if(swapOnExec == TRUE && kswapMkStruc(fullname, rest)) { /* The Criter and ^Break handlers has been installed within the PSP in kswapRegister() --> nothing to do here */ dprintf(("[EXEC: exiting to kernel swap support]\n")); exit(123); /* Let the kernel swap support do the rest */ } #ifdef DEBUG if(swapOnExec == TRUE) dprintf(("KSWAP: failed to save context, proceed without swapping\n")); #endif #endif /* Install the dummy (always abort) handler */ setvect(0x23, (void interrupt(*)()) kswapContext->cbreak_hdlr); result = exec(fullname, rest, 0); setvect(0x23, cbreak_handler); /* Install local CBreak handler */ perform_exec_result(result); } }
static void execute(char *first, char *rest) { /* * This command (in first) was not found in the command table * * * first - first word on command line * rest - rest of command line * */ char *fullname; char *extension; assert(first); assert(rest); /* check for a drive change */ if ((strcmp(first + 1, ":") == 0) && isalpha(*first)) { changeDrive(*first); return; } if(strchr(first,'?') || strchr(first,'*')) { error_bad_command(first); return; } /* search through %PATH% for the binary */ errno = 0; fullname = find_which(first); dprintf(("[find_which(%s) returned %s]\n", first, fullname)); if(!fullname) { error_bad_command(first); return; } /* check if this is a .BAT file */ extension = strrchr(dfnfilename(fullname), '.'); assert(extension); if(stricmp(extension, ".bat") == 0) { dprintf(("[BATCH: %s %s]\n", fullname, rest)); batch(fullname, first, rest); } else if(stricmp(extension, ".exe") == 0 || stricmp(extension, ".com") == 0) { /* exec the program */ int result; dprintf(("[EXEC: %s %s]\n", fullname, rest)); if(strlen(rest) > MAX_EXTERNAL_COMMAND_SIZE) { char *fullcommandline = malloc( strlen( first ) + strlen( rest ) + 2 ); error_line_too_long(); if( fullcommandline == NULL ) return; sprintf( fullcommandline, "%s%s", first, rest ); if( chgEnv( "CMDLINE", fullcommandline ) != 0 ) { free( fullcommandline ); return; } free( fullcommandline ); } /* Prepare to call an external program */ /* Unload the message block if not loaded persistently */ if(!persistentMSGs) unloadMsgs(); /* Execute the external program */ #ifdef FEATURE_KERNEL_SWAP_SHELL if(swapOnExec == TRUE && kswapMkStruc(fullname, rest)) { /* The Criter and ^Break handlers has been installed within the PSP in kswapRegister() --> nothing to do here */ dprintf(("[EXEC: exiting to kernel swap support]\n")); exit(123); /* Let the kernel swap support do the rest */ } #ifdef DEBUG if(swapOnExec == TRUE) dprintf(("KSWAP: failed to save context, proceed without swapping\n")); #endif #endif /* Install the dummy (always abort) handler */ #ifdef FEATURE_XMS_SWAP set_isr(0x23, (void interrupt(*)()) MK_FP(FP_SEG(lowlevel_cbreak_handler)-0x10, FP_OFF(lowlevel_cbreak_handler)+0x100)); /* * some tools expect this interrupt to have the same segment as the * command.com PSP, but FreeCOM is an exe... */ #else set_isr(0x23, (void interrupt(*)()) kswapContext->cbreak_hdlr); #endif #ifdef FEATURE_XMS_SWAP { isr v; get_isr(0x2e, v); if( *(unsigned char far *)v == 0xCF && !canexit) /* IRET? */ set_isr( 0x2E, ( void interrupt(*)() ) MK_FP(FP_SEG(lowlevel_int_2e_handler)-0x10, FP_OFF(lowlevel_int_2e_handler)+0x100)); } #endif result = exec(fullname, rest, 0); set_isrfct(0x23, cbreak_handler); /* Install local CBreak handler */ /* The external command might has killed the string area. */ env_nullStrings(0); setErrorLevel(result); } else error_bad_command(first); chgEnv( "CMDLINE", NULL ); }
/* syntax for arguments: [which.]object */ OBJECT_DATA *find_obj(CHAR_DATA *ch, char *arguments, char *order) { OBJECT_DATA *match = 0; OBJECT_DATA *inexact = 0; OBJECT_DATA *other; char *p; char *w; char where; long limit = 0; p = 0; if (arguments[0] == 0) return NULL; arguments[127] = 0; w = find_which(arguments, &which, &where); if (w == 0) return 0; cur = 1; if (where) { for (p = order; *p; p++) if (*p == where) { p = &where; break; } } if (p == 0) p = order; for (; *p; p++) { /* NOTE: if you want to check inv 14 million times, it will */ switch (*p) { case 'a': /* armor */ if (find_in_arm(ch, w, &match, (inexact == 0) ? &inexact : &other) >= 2) return match; break; case 'i': /* inventory */ if (find_in_inv(ch, w, &match, (inexact == 0) ? &inexact : &other) >= 2) return match; break; case 'f': /* floor */ p++; /* find the limit */ if (*p == '*') limit = ch->sightradius; else if (*p) limit = strtol(p, 0, 10); if (find_in_flr(ch, w, &match, (inexact == 0) ? &inexact : &other, limit) >= 2) return match; break; case 'w': /* weapon */ if (find_in_wpn(ch, w, &match, (inexact == 0) ? &inexact : &other) >= 2) return match; break; default: if (*p < '0' && *p > '9') syslog("WARNING", "[find_obj] Unknown order parameter: %c, from [%s]", *p, order); break; } } return inexact; }
static void execute(char *first, char *rest) { /* * This command (in first) was not found in the command table * * * first - first word on command line * rest - rest of command line * */ char *fullname; assert(first); assert(rest); if (strlen(first) + strlen(rest) + 1 > MAX_EXTERNAL_COMMAND_SIZE) { error_line_too_long(); return; } /* check for a drive change */ if ((strcmp(first + 1, ":") == 0) && isalpha(*first)) { changeDrive(*first); return; } if (strchr(first,'?') || strchr(first,'*')) { error_bad_command(); return; } /* search through %PATH% for the binary */ fullname = find_which(first); dprintf(("[find_which(%s) returned %s]\n", first, fullname)); if (!fullname) { error_bad_command(); return; } /* check if this is a .BAT file */ assert(strrchr(fullname, '.')); if (stricmp(strrchr(fullname, '.'), ".bat") == 0) { dprintf(("[BATCH: %s %s]\n", fullname, rest)); batch(fullname, first, rest); } else /* exec the program */ { int result; dprintf(("[EXEC: %s %s]\n", fullname, rest)); if(!saveSession()) { error_save_session(); exit_all_batch(); return; /* Don't invoke the program in this case */ } #ifdef FEATURE_KERNEL_SWAP_SHELL if(swapOnExec == TRUE && kswapMkStruc(fullname, rest)) { dprintf(("[EXEC: exiting to kernel swap support]\n")); exit(123); /* Let the kernel swap support do the rest */ } #ifdef DEBUG if(swapOnExec == TRUE) dprintf(("KSWAP: failed to save context, proceed without swapping\n")); #endif #endif result = exec(fullname, rest, 0); perform_exec_result(result); } }