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); } }
int cd_dir(char *param, int cdd, const char * const fctname) { char **argv, *dir; int argc, opts; int rv, freeDir; if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0) return 1; freeDir = 0; rv = 1; /* if doing a CD and no parameters given, print out current directory */ if(argc == 0) { if((dir = cwd(0)) != 0) { puts(dir); freeDir = 1; goto okRet; } goto errRet; } else if(argc != 1) { error_syntax(0); goto errRet; } else { assert(argv[0]); #ifdef FEATURE_CDD_FNAME /* if path refers to an existing file and not directory, ignore filename portion */ if (cdd && (dfnstat(argv[0]) & DFN_FILE)) { dir = strrchr(argv[0], '\\'); if (dir == NULL) { dir = argv[0]; if (dir[1] == ':') dir[2]='\0'; /* change drive only, no path */ else goto okRet; /* no drive, no path, so exit early */ } else /* includes a path or refers to root dir */ { *(dir+1) = '\0'; } } #endif dir = strchr(argv[0], '\0'); /* take off trailing \ if any, but ONLY if dir is not the root dir */ while(dir > &argv[0][1] && *--dir == '\\' && dir[-1] != ':') *dir = '\0'; dir = argv[0]; #ifdef FEATURE_LAST_DIR if(strcmp(dir, "-") == 0) { assert(!freeDir); /* change to last directory */ lastDirGet(&dir); freeDir = 1; } lastDirSet(); if(!dir) /* "CD -" without a CD before at all */ goto okRet; #endif if(*dir && dir[1] == ':') { if(cdd) { if(changeDrive(*dir) != 0) goto errRet; if(!dir[2]) /* only change drive */ goto okRet; } else if(!dir[2]) { /* Real CHDIR displays CWD of specified drive */ assert(freeDir == 0); if((dir = cwd(*dir)) != 0) { puts(dir); freeDir = 1; goto okRet; } goto errRet; } } dprintf(("%s: '%s'\n", fctname, dir)); if(chdir(dir) != 0) { error_dirfct_failed(fctname, dir); goto errRet; } } okRet: rv = 0; errRet: freep(argv); if(freeDir) free(dir); return rv; }
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 ); }
/* * dir_print_header * * print the header for the dir command */ int dir_print_header(int drive) { /* one byte alignment */ #pragma -a- struct media_id { int info_level; int serial1; int serial2; char vol_id[11]; char file_sys[8]; } media; /* standard alignment */ #pragma -a. struct ffblk f; struct SREGS s; union REGS r; int currDisk; int rv; if (cbreak) return E_CBreak; if (optB) return 0; currDisk = getdisk(); if(changeDrive(drive+1) != 0) { setdisk(currDisk); return 1; } /* get the media ID of the drive */ /* Format of disk info: Offset Size Description (Table 01766) 00h WORD 0000h (info level) 02h DWORD disk serial number (binary) 06h 11 BYTEs volume label or "NO NAME " if none present 11h 8 BYTEs (AL=00h only) filesystem type (see #01767) */ r.x.ax = 0x6900; r.x.bx = drive + 1; s.ds = FP_SEG(&media); r.x.dx = FP_OFF(&media); int86x(0x21, &r, &r, &s); /* print drive info */ printf("\n Volume in drive %c", drive + 'A'); if (FINDFIRST("\\*.*", &f, FA_LABEL) == 0) { /* Added to remove "." from labels which are longer than 8 characters (as DOS does). */ char *dotptr = strchr(f.ff_name, '.'); if (dotptr != NULL) if(strlen(dotptr + 1)) memmove(dotptr, dotptr + 1, strlen(dotptr)); else *dotptr = '\0'; /* dot at end of name */ printf(" is %s\n", f.ff_name); } else { printf(" has no label\n"); } setdisk(currDisk); if ((rv = incline()) == 0) { /* print the volume serial number if the return was successful */ if (!r.x.cflag) { printf(" Volume Serial Number is %04X-%04X\n", media.serial2, media.serial1); rv = incline(); } } /* Added to exactly match DOS's formatting. */ if ( (optS) && (rv == 0) ) { printf("\n"); rv = incline(); } return rv; }
/* * dir_print_header * * print the header for the dir command */ int dir_print_header(int drive) { #pragma -a- struct media_id { int info_level; int serial1; int serial2; char vol_id[11]; char file_sys[8]; } media; #pragma -a. struct REGPACK r; struct ffblk f; int disk; int rv; if (cbreak) return E_CBreak; if (optB) return 0; disk = getdisk(); if(changeDrive(drive + 1) != 0) return 1; /* get the media ID of the drive */ /* Format of disk info: Offset Size Description (Table 01766) 00h WORD 0000h (info level) 02h DWORD disk serial number (binary) 06h 11 BYTEs volume label or "NO NAME " if none present 11h 8 BYTEs (AL=00h only) filesystem type (see #01767) */ r.r_ax = 0x6900; r.r_bx = 0; r.r_ds = FP_SEG(&media); r.r_dx = FP_OFF(&media); intr(0x21, &r); /* print drive info */ printf("\n Volume in drive %c", drive + 'A'); if (FINDFIRST("\\*.*", &f, FA_LABEL) == 0) { printf(" is %s\n", f.ff_name); } else { printf(" has no label\n"); } setdisk(disk); if ((rv = incline()) == 0) { /* print the volume serial number if the return was successful */ if (!r.r_flags & 1) { printf(" Volume Serial Number is %04X-%04X\n" , media.serial2, media.serial1); rv = incline(); } } return rv; }
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); } }