char *dfntruename(const char * const fnam) { char *h; struct REGPACK r; DBG_ENTER("dfntruename", Suppl_dfn) assert(fnam); DBG_ARGUMENTS( ("fnam=\"%s\"", fnam) ) chkHeap if((h = eno_malloc(DFN_FILENAME_BUFFER_LENGTH)) != 0) { #ifdef FEATURE_LONG_FILENAMES r.r_ax = 0x7160; r.r_cx = 0x02; #else r.r_ax = 0x6000; #endif r.r_ds = FP_SEG(fnam); r.r_si = FP_OFF(fnam); r.r_es = FP_SEG(h); r.r_di = FP_OFF(h); chkHeap intr( 0x21, &r ); #ifdef FEATURE_LONG_FILENAMES if( ( r.r_flags & 1 ) || r.r_ax == 0x7100 ) { r.r_ax = 0x6000; intr( 0x21, &r ); #endif if(( r.r_flags & 1 ) ? r.r_ax : 0) { /* failed */ eno_setOSerror( r.r_ax); free(h); DBG_RETURN_S( 0) }
register char *StrConcat(int argcnt) { unsigned cnt, *poi; unsigned Xcnt, *Xpoi; unsigned length; char *h, *p; DBG_ENTER1 cnt = nargs(); DBG_ENTER2("StrConcat", "dynstr") DBG_ARGUMENTS( ("argcnt=%u cnt=%u", argcnt, cnt) ) Xpoi = poi = cnt * 2 - 2 + &argcnt; Xcnt = cnt = min(cnt, *poi); for(length = 1; cnt--;) if(*--poi) length += strlen(*poi); chkHeap if((h = p = eno_malloc(length)) == 0) DBG_RETURN_S( 0) chkHeap while(Xcnt--) if(*--Xpoi) p = stpcpy(p, *Xpoi); chkHeap DBG_RETURN_S( h) }
int invokeDOS(IREGS *prp) { DBG_ENTER("invokeDOS", Suppl_portable) assert(prp); DBG_ARGUMENTS( ("AX=0x%04x", prp->r_ax) ) int86(0x21, prp, prp); DBG_RETURN_BI( (prp->x.cflag)? prp->x.ax: 0) }
int eno_setOSerror(int errnr) { #ifdef __TURBOC__ int eno; #endif DBG_ENTER("eno_setOSerror", Suppl_error) DBG_ARGUMENTS( ("errnr=%u", errnr) ) #ifdef __TURBOC__ if((unsigned)errnr > 88) { DBG_INFO( ("Errnr exceeds range") ) eno = EFAULT; } else { eno = _dosErrorToSV[errnr]; } errno = eno; DBG_RETURN_BI(_doserrno = errnr) #elif __WATCOMC__ __set_errno_dos(errnr); DBG_RETURN_I( errnr) #endif }
int dfnmatchext(const char * const fnam , const char *pattern) { char *p; DBG_ENTER("dfnmatchext", Suppl_dfn) assert(fnam); assert(pattern); DBG_ARGUMENTS( ("fnam=\"%s\", pattern=\"%s\"", fnam, pattern) ) /* find extension in filename */ p = dfnfilenameext(fnam); assert(p); assert(*p == '\0' || *p == '.'); if(!*p) { /* No dot --> no extension */ DBG_RETURN_I(*pattern == 0); } if(*pattern == '.') /* one dot is optional */ ++pattern; #ifdef OS_DOS /* At most one extension in DOS mode */ DBG_RETURN_BI(dfnmatchcomponent(p + 1, pattern)) #else /* Try each extension as the pattern may include the asterisk */ do if(dfnmatchcomponent2(p + 1, pattern)) { DBG_RETURN_I(1) } while(0 != (p = strchr(p + 1, '.'))); DBG_RETURN_I(0) #endif }
void env_clear(word segm) { DBG_ENTER("env_clear", "env") DBG_ARGUMENTS( ("env=%u", segm) ) chkMem unless_segm(segm) DBG_EXIT /* no source environment */ DBG_ARGUMENTS( ("effective env=%u", segm) ) ENV_CLEAR_SEGM(segm); chkMem DBG_EXIT }
word nxtMCB(word mcb) { DBG_ENTER("nxtMCB", Suppl_mcb) DBG_ARGUMENTS( ("MCB=%u", mcb) ) assert(mcb); DBG_RETURN_BI( peekb(mcb, 0) == 'M' ? MCB2SEG(mcb) + peekw(mcb, MCB_OFF_SIZE) : 0) }
word env_freeCount(const word segm) { DBG_ENTER("env_firstCount", Suppl_env) DBG_ARGUMENTS( ("env=%u", segm) ) chkMem assert(segm != 0); DBG_RETURN_BU( mcb_length(segm) - env_firstFree(segm)) }
word env_firstFree(const word segm) { DBG_ENTER("env_firstFree", Suppl_env) DBG_ARGUMENTS( ("env=%u", segm) ) chkMem assert(segm != 0); DBG_RETURN_BU( env_string(segm, env_strings(segm))) }
void env_delete(word segm) { DBG_ENTER("env_delete", Suppl_env) DBG_ARGUMENTS( ("env=%u", segm) ) chkMem unless_segm(segm) DBG_EXIT DBG_ARGUMENTS( ("effective env=%u", segm) ) pokew(SEG2MCB(segm), MCB_OFF_OWNER, _psp); freeBlk(segm); chkMem /* Make sure the deleted segment won't be referenced */ env_relocateSegment(segm, 0); DBG_EXIT }
char *dfnsqueeze(const char * const fnam) { char *p, *h, *q; #ifdef SUPPORT_UNC_PATH DBG_ENTER("dfnusqueeze", Suppl_dfn) #else DBG_ENTER("dfnsqueeze", Suppl_dfn) #endif DBG_ARGUMENTS( ("fnam=\"%s\"", fnam) ) if(!fnam || (h = q = eno_strdup(fnam)) == 0) DBG_RETURN_S( 0) #ifdef SUPPORT_UNC_PATH if(isUNCpath(q)) /* keep the two backslashes */ q += 2; #endif p = q; /* where to begin to squeeze */ /* First: Flip the slashes */ while((q = strchr(q, '/')) != 0) *q = '\\'; /* Second: Squeeze & upcase */ q = p; chkHeap do { redo: if(*q == '\\') { /* possibly to be squeezed */ if(q[1] == '\\') { /* Squeeze '\\\\' -> '\\' */ ++q; goto redo; } if(q[1] == '.') { if(q[2] == '\\') { /* squeeze '\\.\\' -> '\\' */ q += 2; goto redo; } #if 0 /* this may lead to confusion -- 2000/06/07 ska*/ if(q[2] == '\0') { /* squeeze '\\.\0' -> '\\' */ *p = '\\'; *++p = NUL; break; } #endif } } } while((*p++ = toFUpper(*q++)) != 0); chkHeap DBG_RETURN_BS( StrTrim(h)) }
DFN_GLOB *dfnglobinit(const char * const pattern, unsigned flags) { const char *p; DFN_GLOB *g; DBG_ENTER("dfnglobinit", Suppl_dfn) DBG_ARGUMENTS( ("pattern=\"%s\", flags=0x%04x", pattern, flags) ) if(!pattern || !*pattern) { eno_set(EINVAL); DBG_RETURN_P(0) }
/* * Duplicate a portion of a string */ char *StrDupe(const char * const beg, const char * const end) { char *p; size_t len; DBG_ENTER("StrDupe", Suppl_dynstr) DBG_ARGUMENTS( ("begin=%p, end=%p", beg, end) ) if(!beg) { eno_set(EINVAL); DBG_RETURN_S( 0) }
char *dfnglobfilename(DFN_GLOB * const g) { struct ffblk *ff; DBG_ENTER("dfnglobfilename", Suppl_dfn) DBG_ARGUMENTS( ("glob=\"%p\"", g) ) if(!g) { eno_set(EINVAL); DBG_RETURN_S(0) }
char *dfnpath(int drive) { char *h; DBG_ENTER("dfnpath", Suppl_dfn) DBG_ARGUMENTS( ("drive=%u ('%c')", drive, drive < 32? '.': drive) ) if(isupper(drive)) drive -= 'A' - 1; else if(islower(drive)) drive -= 'a' - 1; else if((unsigned)drive > 32) { eno_set( ENODEV); DBG_RETURN_S( 0) }
int commit(int fd) { struct REGPACK r; DBG_ENTER("commit", "supplio") DBG_ARGUMENTS( ("fd=%d", fd) ) if(fd != -1) { r.r_ax = 0x6800; r.r_bx = fd; intr( 0x21, &r ); DBG_RETURN_BI( r.r_flags & 1 ? r.r_ax : 0 ) }
void *eno_malloc(const size_t len) { void *h; DBG_ENTER("eno_malloc", Suppl_error) DBG_ARGUMENTS( ("size=%u", len) ) chkHeap if(0 == (h = malloc(len))) eno_set( ENOMEM); chkHeap DBG_RETURN_P(h) }
/* * Reallocate a chunk of memory and terminate the application on failure */ void *Erealloc(void *p1, size_t size) { void *p; DBG_ENTER("Erealloc", Suppl_error) DBG_ARGUMENTS( ("poi=%p, new_len=%u", p1, size) ) chkHeap if((p = realloc(p1, size)) == 0 && size) Esuppl_noMem(); chkHeap DBG_RETURN_P( p) }
/* * Replace the contents of a string variable with another string */ char *Estrchg_(char ** const var, const char * const str) { DBG_ENTER("Estrchg_", Suppl_error) assert(var); DBG_ARGUMENTS( ("*var=%p, str=\"%s\"", *var, str) ) chkHeap free(*var); chkHeap DBG_RETURN_BS( *var = Estrdup(str)) }
/* * Allocate a chunk of memory * On failure: Terminate with an error message */ void *Emalloc(size_t size) { byte *h; DBG_ENTER("Emalloc", Suppl_error) DBG_ARGUMENTS( ("len=%u", size) ) chkHeap if((h = malloc(size)) == 0) Esuppl_noMem(); chkHeap DBG_RETURN_P( h) }
int env_nullStrings(word segm) { word ofs; DBG_ENTER("env_nullStrings", Suppl_env) DBG_ARGUMENTS( ("env=%u", segm) ) chkMem unless_segm(segm) DBG_RETURN_I( ESUPPL_NOENV) DBG_ARGUMENTS( ("effective env=%u", segm) ) ofs = env_endOfVars(segm) + 1; /* offset of string counter word */ if(mcb_length(segm) - 2 <= ofs) DBG_RETURN_I( ESUPPL_NOMEM) pokew(segm, ofs, 0); chkMem DBG_RETURN_I( ESUPPL_OK) }
char *StrChar(int ch) { char *h; DBG_ENTER("StrChar", Suppl_dynstr) DBG_ARGUMENTS( ("ch='%c' (0x02x)", ch > 32? ch: ' ', ch) ) chkHeap if((h = eno_strdup(" ")) != 0) *h = ch; chkHeap DBG_RETURN_S( h) }
char *dfnfilename(const char * const fnam) { const char *p; DBG_ENTER("dfnfilename", Suppl_dfn) if(!fnam) DBG_RETURN_S( 0) DBG_ARGUMENTS( ("fnam=\"%s\"", fnam) ) p = strchr(fnam, '\0'); while(--p >= fnam && !dfndelim2(*p)); DBG_RETURN_S( (char*)p + 1) }
word env_findVar(const word segm, const char * const var) { word offset; int len; DBG_ENTER("env_findVar", Suppl_env) DBG_ARGUMENTS( ("env=%u, var=\"%s\"", segm, var) ) chkMem /* for security reason, check if environment is present at all */ if(!segm || !var) { eno_set(EINVAL); DBG_RETURN_U( -1) /* No env --> no var can be found */ }
int mcb_allParents(word mcb, MCB_WALKFUNC fct, void *arg) { word mcb1; DBG_ENTER("mcb_allParents", Suppl_mcb) DBG_ARGUMENTS( ("mcb=%u", mcb) ) assert(fct); if(mcb) { if(!isPSP(mcb)) { DBG_STRING("Invalid MCB") DBG_RETURN_I( -1) } } else mcb = _psp;
word env_endOfVars(const word segm) { word offset; DBG_ENTER("env_endOfVars", Suppl_env) DBG_ARGUMENTS( ("env=%u", segm) ) chkMem assert(segm != 0); offset = 0; /* env starts always at location 0 */ while(peekb(segm, offset)) /* there is a variable */ offset += env_varlen(segm, offset); DBG_RETURN_U( offset) /* This is the terminator byte */ }
int MemiCmp(const byte *s, const byte *p, unsigned len) { int result; DBG_ENTER("MemiCmp", Suppl_nls) DBG_ARGUMENTS( ("s1=\"%s\", s2=\"%s\", len=%u", s, p, len) ) if(!len) DBG_RETURN_I(0) if(p == 0) DBG_RETURN_I(s != 0) if(s == 0) DBG_RETURN_I(-1) while((result = toUpper(*s++) - toUpper(*p++)) == 0 && --len); DBG_RETURN_I( result) }
int dfnwrdir(const char * const fnam) { char *p; /* temporary filename */ DBG_ENTER("dfnwrdir", Suppl_dfn) DBG_ARGUMENTS( ("fnam=\"%s\"", fnam) ) assert(fnam); chkHeap if((p = dfnmktmp(fnam, 0)) == 0) /* failed --> error */ DBG_RETURN_I( 1) remove(p); /* dfnmktmp() creates the file */ free(p); chkHeap DBG_RETURN_I( 0) }
void env_subVarOffset(word segm, word offset) { register unsigned moveStart; DBG_ENTER("env_subVarOffset", Suppl_env) DBG_ARGUMENTS( ("env=%u, ofs=%u", segm, offset) ) chkMem assert(segm); assert(offset < env_endOfVars(segm)); moveStart = offset + env_varlen(segm, offset); _fmemmove(MK_FP(segm, offset), MK_FP(segm, moveStart), env_firstFree(segm) - moveStart); chkMem DBG_EXIT }
word mcb_owner(word mcb) { word mcb1; DBG_ENTER("mcb_owner", Suppl_mcb) DBG_ARGUMENTS( ("mcb=%u", mcb) ) /* A PSP can be identified that the MCB has stored itself as the owner process. In some circumstances the "owner" field does not mention a process, but some other memory block allocated by a process. This loop resolves this situation and correctly returns a MCB of a PSP. Unused and system MCBs force this function to return with value "0" (zero) meaning "no owner found". */ do if((mcb1 = mcb) <= 0x40) { DBG_RETURN_I( 0) } while((mcb = peekw(mcb, MCB_OFF_OWNER)) != 0 && (mcb = SEG2MCB(mcb)) != mcb1); DBG_RETURN_I( mcb) }