char *com_getenv(char *keyword) { struct PSP *psp = COM_PSP_ADDR; char *env = SEG2LINEAR(psp->envir_frame); char key[128]; int len; len = strlen(keyword); memcpy(key, keyword, len+1); strupperDOS(key); while (*env) { if (!strncmp(key, env, len) && (env[len] == '=')) { return env + len + 1; } env += strlen(env) + 1; } return 0; }
static int GetDirectoryEntry(int drive, int copyFlag, char *pathname, Bit32u buffer) { char searchName[256]; int error, dirSize; unsigned char defBuffer[CD_FRAMESIZE]; unsigned dirEntrySector, entryLength, index; char *searchPos = searchName; size_t searchlen; /* skip initial \ */ MEMCPY_2UNIX(searchName, pathname + 1, 255); searchName[255] = '\0'; strupperDOS(searchName); //strip of tailing . (XCOM APOCALIPSE) searchlen = strlen(searchName); if (searchlen > 1 && strcmp(searchName, "..")) if (searchName[searchlen - 1] == '.') searchName[searchlen - 1] = 0; C_printf("MSCDEX: Get DirEntry : Find : %s\n", searchName); // read vtoc error = ReadSectors(drive, 16, 1, defBuffer); if (error) return error; // TODO: has to be iso 9660 if (memcmp("CD001", defBuffer + 1, 5) != 0) return MSCDEX_ERROR_BAD_FORMAT; // get directory position dirEntrySector = *(unsigned *)(defBuffer + 156 + 2); dirSize = *(int *)(defBuffer + 156 + 10); do { // Get string part char *useName = searchPos; size_t useNameLength; searchPos = strchr(searchPos, '\\'); if (searchPos) { useNameLength = searchPos - useName; searchPos++; } else useNameLength = strlen(useName); while (1) { error = ReadSectors(drive, dirEntrySector, 1, defBuffer); if (error) return error; index = 0; do { char *entryName, *longername; unsigned nameLength; entryLength = defBuffer[index]; C_printf("MSCDEX: entryLength=%u, index=%d\n", entryLength, index); if (entryLength == 0) break; nameLength = defBuffer[index + 32]; entryName = defBuffer + index + 33; if (namecomp (entryName, nameLength, useName, useNameLength)) break; /* Xcom Apocalipse searches for MUSIC. * and expects to find MUSIC;1 * All Files on the CDROM are of the kind * blah;1 */ longername = memchr(entryName, ';', nameLength); if (longername && namecomp(entryName, longername - entryName, useName, useNameLength)) break; index += entryLength; } while (index + 33 <= CD_FRAMESIZE); if (index + 33 <= CD_FRAMESIZE) break; // continue search in next sector dirSize -= 2048; if (dirSize <= 0) return 2; // file not found dirEntrySector++; } // directory wechseln dirEntrySector = *(unsigned *)(defBuffer + index + 2); dirSize = *(unsigned *)(defBuffer + index + 10); } while (searchPos); return fill_buffer(copyFlag, buffer, defBuffer + index, entryLength); };
int commands_plugin_inte6(void) { #define MAX_ARGS 63 char *args[MAX_ARGS + 1]; struct PSP *psp; struct MCB *mcb; struct com_program_entry *com; int argc; if (pool_used >= MAX_NESTING) { com_error("Cannot invoke more than %i builtins\n", MAX_NESTING); return 0; } if (!pool_used) { if (!(lowmem_pool = lowmem_heap_alloc(LOWMEM_POOL_SIZE))) { error("Unable to allocate memory pool\n"); return 0; } sminit(&mp, lowmem_pool, LOWMEM_POOL_SIZE); } pool_used++; BMEM(allocated) = 0; BMEM(retcode) = 0; if (HI(ax) != BUILTINS_PLUGIN_VERSION) { com_error("builtins plugin version mismatch: found %i, required %i\n", HI(ax), BUILTINS_PLUGIN_VERSION); com_error("You should update your generic.com, ems.sys, isemu.com and other utilities\n" "from the latest dosemu package!\n"); commands_plugin_inte6_done(); return 0; } psp = COM_PSP_ADDR; mcb = LOWMEM(SEGOFF2LINEAR(COM_PSP_SEG - 1,0)); /* first parse commandline */ args[0] = strdup(com_getarg0()); strupperDOS(args[0]); argc = com_argparse((char *)&psp->cmdline_len, &args[1], MAX_ARGS - 1) + 1; /* DOS 4 and up */ strncpy(builtin_name, mcb->name, sizeof(builtin_name) - 1); builtin_name[sizeof(builtin_name) - 1] = 0; strupperDOS(builtin_name); com = find_com_program(builtin_name); /* DOS 3.0->3.31 construct the program name from the environment */ if(!com) { char *p = strrchr(args[0],'\\'); strncpy(builtin_name, p+1, sizeof(builtin_name) - 1); builtin_name[sizeof(builtin_name) - 1] = 0; p = strchr(builtin_name, '.'); if(p) *p = '\0'; com = find_com_program(builtin_name); } if (com) { int err = com->program(argc, args); if (!err) { NOCARRY; } else { CARRY; _AL = err; } } else { com_error("inte6: unknown builtin: %s\n",builtin_name); CARRY; _AL = 1; } free(args[0]); return 1; }