Cleanup & optimisation

git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/branches/UNSTABLE@1029 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Luchezar Georgiev 2004-09-09 12:17:56 +00:00
parent fce371ba94
commit 9584e214f5
9 changed files with 160 additions and 289 deletions

View File

@ -334,6 +334,7 @@
- revision sequence now initialised along with DOS version in LoL - revision sequence now initialised along with DOS version in LoL
- CheckContinueBootFromHardDisk() function code and text cleaned up - CheckContinueBootFromHardDisk() function code and text cleaned up
* makefile: object files reordered to gain ~300B packed size * makefile: object files reordered to gain ~300B packed size
* newstuff.c, fatdir.c, blockio.c, chario.c, prf.c: cleanup & optimise
* portab.h: pragma aux default to gain ~800B unpacked size (Watcom) * portab.h: pragma aux default to gain ~800B unpacked size (Watcom)
(the last 2 changes proposed by Bart Oldeman) (the last 2 changes proposed by Bart Oldeman)
+ Changes Eduardo + Changes Eduardo

View File

@ -47,7 +47,7 @@ static BYTE *blockioRcsId =
/************************************************************************/ /************************************************************************/
/* #define DISPLAY_GETBLOCK */ /* #define DISPLAY_GETBLOCK */
STATIC BOOL flush1(struct buffer FAR * bp); STATIC VOID flush1(struct buffer FAR * bp);
/* /*
this searches the buffer list for the given disk/block. this searches the buffer list for the given disk/block.
@ -155,7 +155,7 @@ STATIC struct buffer FAR *searchblock(ULONG blkno, COUNT dsk)
return bp; return bp;
} }
BOOL DeleteBlockInBufferCache(ULONG blknolow, ULONG blknohigh, COUNT dsk, int mode) VOID DeleteBlockInBufferCache(ULONG blknolow, ULONG blknohigh, COUNT dsk, int mode)
{ {
struct buffer FAR *bp = firstbuf; struct buffer FAR *bp = firstbuf;
@ -176,8 +176,6 @@ BOOL DeleteBlockInBufferCache(ULONG blknolow, ULONG blknohigh, COUNT dsk, int mo
bp = b_next(bp); bp = b_next(bp);
} }
while (FP_OFF(bp) != FP_OFF(firstbuf)); while (FP_OFF(bp) != FP_OFF(firstbuf));
return FALSE;
} }
#if TOM #if TOM
@ -226,8 +224,7 @@ struct buffer FAR *getblk(ULONG blkno, COUNT dsk, BOOL overwrite)
/* available, and fill it with the desired block */ /* available, and fill it with the desired block */
/* take the buffer that lbp points to and flush it, then read new block. */ /* take the buffer that lbp points to and flush it, then read new block. */
if (!flush1(bp)) flush1(bp);
return NULL;
/* Fill the indicated disk buffer with the current track and sector */ /* Fill the indicated disk buffer with the current track and sector */
@ -262,30 +259,23 @@ VOID setinvld(REG COUNT dsk)
/* */ /* */
/* Flush all buffers for a disk */ /* Flush all buffers for a disk */
/* */ /* */
/* returns: */ VOID flush_buffers(REG COUNT dsk)
/* TRUE on success */
/* */
BOOL flush_buffers(REG COUNT dsk)
{ {
struct buffer FAR *bp = firstbuf; struct buffer FAR *bp = firstbuf;
REG BOOL ok = TRUE;
bp = firstbuf;
do do
{ {
if (bp->b_unit == dsk) if (bp->b_unit == dsk)
if (!flush1(bp)) flush1(bp);
ok = FALSE;
bp = b_next(bp); bp = b_next(bp);
} }
while (FP_OFF(bp) != FP_OFF(firstbuf)); while (FP_OFF(bp) != FP_OFF(firstbuf));
return ok;
} }
/* */ /* */
/* Write one disk buffer */ /* Write one disk buffer */
/* */ /* */
STATIC BOOL flush1(struct buffer FAR * bp) STATIC VOID flush1(struct buffer FAR * bp)
{ {
/* All lines with changes on 9/4/00 by BER marked below */ /* All lines with changes on 9/4/00 by BER marked below */
@ -320,31 +310,23 @@ STATIC BOOL flush1(struct buffer FAR * bp)
bp->b_flag &= ~BFR_DIRTY; /* even if error, mark not dirty */ bp->b_flag &= ~BFR_DIRTY; /* even if error, mark not dirty */
if (result != 0) /* otherwise system has trouble */ if (result != 0) /* otherwise system has trouble */
bp->b_flag &= ~BFR_VALID; /* continuing. */ bp->b_flag &= ~BFR_VALID; /* continuing. */
return (TRUE); /* Forced to TRUE...was like this before dskxfer() */
/* returned error codes...BER */
} }
/* */ /* */
/* Write all disk buffers */ /* Write all disk buffers */
/* */ /* */
BOOL flush(void) VOID flush(VOID)
{ {
REG struct buffer FAR *bp = firstbuf; REG struct buffer FAR *bp = firstbuf;
REG BOOL ok;
ok = TRUE;
do do
{ {
if (!flush1(bp)) flush1(bp);
ok = FALSE;
bp->b_flag &= ~BFR_VALID; bp->b_flag &= ~BFR_VALID;
bp = b_next(bp); bp = b_next(bp);
} }
while (FP_OFF(bp) != FP_OFF(firstbuf)); while (FP_OFF(bp) != FP_OFF(firstbuf));
network_redirector(REM_FLUSHALL); network_redirector(REM_FLUSHALL);
return (ok);
} }
/************************************************************************/ /************************************************************************/

View File

@ -73,7 +73,7 @@ long BinaryCharIO(struct dhdr FAR **pdev, size_t n, void FAR * bp,
CharReqHdr.r_count = n; CharReqHdr.r_count = n;
CharReqHdr.r_trans = bp; CharReqHdr.r_trans = bp;
err = CharRequest(pdev, command); err = CharRequest(pdev, command);
} while (err == 1); } while (err > 0);
return err == SUCCESS ? (long)CharReqHdr.r_count : err; return err == SUCCESS ? (long)CharReqHdr.r_count : err;
} }
@ -89,10 +89,7 @@ STATIC int CharIO(struct dhdr FAR **pdev, unsigned char ch, unsigned command)
/* STATE FUNCTIONS */ /* STATE FUNCTIONS */
STATIC void CharCmd(struct dhdr FAR **pdev, unsigned command) #define CharCmd(pdev, command) while (CharRequest(pdev, command) > 0)
{
while (CharRequest(pdev, command) == 1);
}
STATIC int Busy(struct dhdr FAR **pdev) STATIC int Busy(struct dhdr FAR **pdev)
{ {
@ -138,103 +135,56 @@ int ndread(struct dhdr FAR **pdev)
/* OUTPUT FUNCTIONS */ /* OUTPUT FUNCTIONS */
#ifdef __WATCOMC__
void fast_put_char(char c);
#pragma aux fast_put_char = "int 29h" parm[al] modify exact [bx]
#else
/* writes a character in raw mode using int29 for speed */
STATIC void fast_put_char(unsigned char chr)
{
#if defined(__TURBOC__)
_AL = chr;
__int__(0x29);
#elif defined(I86)
asm
{
mov al, byte ptr chr;
int 0x29;
}
#endif
}
#endif
void update_scr_pos(unsigned char c, unsigned char count) void update_scr_pos(unsigned char c, unsigned char count)
{ {
unsigned char scrpos = scr_pos;
if (c == CR) if (c == CR)
scrpos = 0; scr_pos = 0;
else if (c == BS) { else if (c == BS) {
if (scrpos > 0) if (scr_pos > 0)
scrpos--; scr_pos--;
} else if (c != LF && c != BELL) { } else if (c != LF && c != BELL)
scrpos += count; scr_pos += count;
}
scr_pos = scrpos;
} }
STATIC int raw_get_char(struct dhdr FAR **pdev, BOOL check_break); STATIC int raw_get_char(struct dhdr FAR **pdev, BOOL check_break);
/* writes a character in cooked mode; maybe with printer echo;
handles TAB expansion */
STATIC int cooked_write_char(struct dhdr FAR **pdev,
unsigned char c,
unsigned char *fast_counter)
{
unsigned char count = 1;
if (c == HT) {
count = 8 - (scr_pos & 7);
c = ' ';
}
update_scr_pos(c, count);
do {
/* if not fast then < 0x80; always check
otherwise check every 32 characters */
if (*fast_counter <= 0x80 && check_handle_break(pdev) == CTL_S)
/* Test for hold char and ctl_c */
raw_get_char(pdev, TRUE);
*fast_counter += 1;
*fast_counter &= 0x9f;
if (PrinterEcho)
DosWrite(STDPRN, 1, &c);
if (*fast_counter & 0x80)
{
fast_put_char(c);
}
else
{
int err = CharIO(pdev, c, C_OUTPUT);
if (err < 0)
return err;
}
} while (--count != 0);
return SUCCESS;
}
long cooked_write(struct dhdr FAR **pdev, size_t n, char FAR *bp) long cooked_write(struct dhdr FAR **pdev, size_t n, char FAR *bp)
{ {
size_t xfer = 0; size_t xfer;
unsigned char fast_counter;
/* bit 7 means fastcon; low 5 bits count number of characters */ /* bit 7 means fastcon; low 5 bits count number of characters */
fast_counter = ((*pdev)->dh_attr & ATTR_FASTCON) << 3; unsigned char fast_counter = ((*pdev)->dh_attr & ATTR_FASTCON) << 3;
for (xfer = 0; xfer < n; xfer++) for (xfer = 0; xfer < n; xfer++)
{ {
int err; int err;
unsigned char c = *bp++; unsigned char count = 1, c = *bp++;
if (c == CTL_Z) if (c == CTL_Z)
break; break;
if (c == HT) {
err = cooked_write_char(pdev, c, &fast_counter); count = 8 - (scr_pos & 7);
if (err < 0) c = ' ';
return err; }
update_scr_pos(c, count);
do {
/* if not fast then < 0x80; always check
otherwise check every 32 characters */
if (fast_counter <= 0x80 && check_handle_break(pdev) == CTL_S)
raw_get_char(pdev, TRUE); /* Test for hold char and ctl_c */
fast_counter++;
fast_counter &= 0x9f;
if (PrinterEcho)
DosWrite(STDPRN, 1, &c);
if (fast_counter & 0x80)
put_console(c);
else
{
err = CharIO(pdev, c, C_OUTPUT);
if (err < 0)
return err;
}
} while (--count != 0);
} }
return xfer; return xfer;
} }
@ -271,16 +221,15 @@ void write_char_stdout(int c)
#define iscntrl(c) ((unsigned char)(c) < ' ') #define iscntrl(c) ((unsigned char)(c) < ' ')
/* this is for handling things like ^C, mostly used in echoed input */ /* this is for handling things like ^C, mostly used in echoed input */
STATIC int echo_char(int c, int sft_idx) STATIC VOID echo_char(int c, int sft_idx, unsigned i)
{ {
int out = c;
if (iscntrl(c) && c != HT && c != LF && c != CR) if (iscntrl(c) && c != HT && c != LF && c != CR)
{ {
write_char('^', sft_idx); write_char('^', sft_idx);
out += '@'; c += '@';
} }
write_char(out, sft_idx); write_char(c, sft_idx);
return c; local_buffer[i] = c;
} }
STATIC void destr_bs(int sft_idx) STATIC void destr_bs(int sft_idx)
@ -407,15 +356,13 @@ void read_line(int sft_in, int sft_out, keyboard FAR * kp)
write_char(CR, sft_out); write_char(CR, sft_out);
write_char(LF, sft_out); write_char(LF, sft_out);
} }
break;
case CTL_F: case CTL_F:
break; break;
case RIGHT: case RIGHT:
case F1: case F1:
if (stored_pos < stored_size && count < size - 1) if (stored_pos < stored_size && count < size - 1)
local_buffer[count++] = echo_char(kp->kb_buf[stored_pos++], sft_out); echo_char(kp->kb_buf[stored_pos++], sft_out, count++);
break; break;
case F2: case F2:
@ -441,7 +388,7 @@ void read_line(int sft_in, int sft_out, keyboard FAR * kp)
if (c != F4) /* not delete */ if (c != F4) /* not delete */
{ {
while (stored_pos < new_pos && count < size - 1) while (stored_pos < new_pos && count < size - 1)
local_buffer[count++] = echo_char(kp->kb_buf[stored_pos++], sft_out); echo_char(kp->kb_buf[stored_pos++], sft_out, count++);
} }
stored_pos = new_pos; stored_pos = new_pos;
break; break;
@ -513,12 +460,11 @@ void read_line(int sft_in, int sft_out, keyboard FAR * kp)
default: default:
if (count < size - 1 || c == CR) if (count < size - 1 || c == CR)
local_buffer[count++] = echo_char(c, sft_out); echo_char(c, sft_out, count++);
else else
write_char(BELL, sft_out); write_char(BELL, sft_out);
if (stored_pos < stored_size && !insert) if (stored_pos < stored_size && !insert)
stored_pos++; stored_pos++;
break;
} }
first = FALSE; first = FALSE;
} while (c != CR); } while (c != CR);
@ -545,7 +491,8 @@ size_t read_line_handle(int sft_idx, size_t n, char FAR * bp)
kb_buf.kb_size = LINEBUFSIZECON; kb_buf.kb_size = LINEBUFSIZECON;
} }
read_line(sft_idx, sft_idx, &kb_buf); read_line(sft_idx, sft_idx, &kb_buf);
kb_buf.kb_buf[kb_buf.kb_count + 1] = echo_char(LF, sft_idx); write_char(LF, sft_idx);
kb_buf.kb_buf[kb_buf.kb_count + 1] = LF;
inputptr = kb_buf.kb_buf; inputptr = kb_buf.kb_buf;
if (*inputptr == CTL_Z) if (*inputptr == CTL_Z)
{ {

View File

@ -12,7 +12,7 @@
db 0FFh,"COUNTRY",0,0,0,0,0,0,0,0,1,0,1 ; reserved and undocumented values db 0FFh,"COUNTRY",0,0,0,0,0,0,0,0,1,0,1 ; reserved and undocumented values
dd ent ; first entry dd ent ; first entry
ent dw 35; number of entries - don't forget to update when adding a new country ent dw 38; number of entries - don't forget to update when adding a new country
; entries ; entries
; (size, country, codepage, reserved(2), offset) ; (size, country, codepage, reserved(2), offset)
@ -65,12 +65,18 @@ __ar dw 12, 54,850,0,0
dd _ar dd _ar
__br dw 12, 55,850,0,0 __br dw 12, 55,850,0,0
dd _br dd _br
__my dw 12, 60,437,0,0
dd _my
__au dw 12, 61,437,0,0 __au dw 12, 61,437,0,0
dd _au dd _au
__sg dw 12, 65,437,0,0
dd _sg
__jp dw 12, 81,932,0,0 __jp dw 12, 81,932,0,0
dd _jp dd _jp
__kr dw 12, 82,934,0,0 __kr dw 12, 82,934,0,0
dd _kr dd _kr
__cn dw 12, 86,936,0,0
dd _cn
__tk dw 12, 90,850,0,0 __tk dw 12, 90,850,0,0
dd _tk dd _tk
__in dw 12, 91,437,0,0 __in dw 12, 91,437,0,0
@ -140,12 +146,18 @@ _ar dw 1,6,1
dd ar dd ar
_br dw 1,6,1 _br dw 1,6,1
dd br dd br
_my dw 1,6,1
dd my
_au dw 1,6,1 _au dw 1,6,1
dd au dd au
_sg dw 1,6,1
dd sg
_jp dw 1,6,1 _jp dw 1,6,1
dd np dd np
_kr dw 1,6,1 _kr dw 1,6,1
dd kr dd kr
_cn dw 1,6,1
dd cn
_tk dw 1,6,1 _tk dw 1,6,1
dd tk dd tk
_in dw 1,6,1 _in dw 1,6,1
@ -332,12 +344,24 @@ dw 55,850,DMY
db "Cr$",0,0 db "Cr$",0,0
dw ".",",", "/",":" dw ".",",", "/",":"
db 2,2,_24; Brazil db 2,2,_24; Brazil
my db 0FFh,"CTYINFO"
dw 22
dw 60,437,DMY
db "$",0,0,0,0
dw ",",".", "/",":"
db 0,2,_12; Malaysia
au db 0FFh,"CTYINFO" au db 0FFh,"CTYINFO"
dw 22 dw 22
dw 61,437,DMY dw 61,437,DMY
db "$",0,0,0,0 db "$",0,0,0,0
dw ",",".", "-",":" dw ",",".", "-",":"
db 0,2,_12; Australia db 0,2,_12; Australia
sg db 0FFh,"CTYINFO"
dw 22
dw 65,437,DMY
db "$",0,0,0,0
dw ",",".", "/",":"
db 0,2,_12; Singapore
np db 0FFh,"CTYINFO" np db 0FFh,"CTYINFO"
dw 22 dw 22
dw 81,932,YMD dw 81,932,YMD
@ -350,6 +374,12 @@ dw 82,934,YMD
db 5Ch,0,0,0,0 db 5Ch,0,0,0,0
dw ",",".", ".",":" dw ",",".", ".",":"
db 0,0,_24; Korea db 0,0,_24; Korea
cn db 0FFh,"CTYINFO"
dw 22
dw 86,936,YMD
db 0A3h,0A4h,0,0,0
dw ",",".", ".",":"
db 0,2,_12; China
tk db 0FFh,"CTYINFO" tk db 0FFh,"CTYINFO"
dw 22 dw 22
dw 90,850,DMY dw 90,850,DMY

View File

@ -486,35 +486,25 @@ COUNT dos_findnext(void)
{ {
++dmp->dm_entry; ++dmp->dm_entry;
++fnp->f_diroff; ++fnp->f_diroff;
if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED &&
&& !(fnp->f_dir.dir_attrib & D_VOLID)) !(fnp->f_dir.dir_attrib & D_VOLID) &&
{ fcmp_wild(dmp->dm_name_pat, fnp->f_dir.dir_name, FNAME_SIZE+FEXT_SIZE) &&
if (fcmp_wild(dmp->dm_name_pat, fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE)) /*
{
/*
MSD Command.com uses FCB FN 11 & 12 with attrib set to 0x16. MSD Command.com uses FCB FN 11 & 12 with attrib set to 0x16.
Bits 0x21 seem to get set some where in MSD so Rd and Arc Bits 0x21 seem to get set some where in MSD so Rd and Arc
files are returned. files are returned. RdOnly + Archive bits are ignored
RdOnly + Archive bits are ignored */
*/ /* Test the attribute as the final step */
!(~dmp->dm_attr_srch & (D_DIR|D_SYSTEM|D_HIDDEN) & fnp->f_dir.dir_attrib))
/* Test the attribute as the final step */ {
if (!(fnp->f_dir.dir_attrib & D_VOLID) && /* If found, transfer it to the dmatch structure */
!(~dmp->dm_attr_srch & (D_DIR | D_SYSTEM | D_HIDDEN) & dmp->dm_dircluster = fnp->f_dirstart;
fnp->f_dir.dir_attrib)) memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
{ /* return the result */
/* If found, transfer it to the dmatch structure */ release_f_node(fnp);
dmp->dm_dircluster = fnp->f_dirstart; return SUCCESS;
memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
/* return the result */
release_f_node(fnp);
return SUCCESS;
}
}
} }
} }
#ifdef DEBUG #ifdef DEBUG
printf("dos_findnext: %11s\n", fnp->f_dir.dir_name); printf("dos_findnext: %11s\n", fnp->f_dir.dir_name);
#endif #endif
@ -536,54 +526,22 @@ COUNT dos_findnext(void)
void ConvertName83ToNameSZ(BYTE FAR * destSZ, BYTE FAR * srcFCBName) void ConvertName83ToNameSZ(BYTE FAR * destSZ, BYTE FAR * srcFCBName)
{ {
int loop; int loop;
int noExtension = FALSE;
if (*srcFCBName == '.')
{
noExtension = TRUE;
}
fmemcpy(destSZ, srcFCBName, FNAME_SIZE); fmemcpy(destSZ, srcFCBName, FNAME_SIZE);
for (loop = FNAME_SIZE; --loop >= 0 && destSZ[loop] == ' '; )
srcFCBName += FNAME_SIZE; ;
destSZ += ++loop;
for (loop = FNAME_SIZE; --loop >= 0;) if (*srcFCBName != '.') /* not for ".", ".." */
{ {
if (destSZ[loop] != ' ') srcFCBName += FNAME_SIZE;
break; for (loop = FEXT_SIZE; --loop >= 0 && srcFCBName[loop] == ' '; )
} ;
destSZ += loop + 1; if (++loop > 0)
if (!noExtension) /* not for ".", ".." */
{
for (loop = FEXT_SIZE; --loop >= 0;)
{
if (srcFCBName[loop] != ' ')
break;
}
if (loop >= 0)
{ {
*destSZ++ = '.'; *destSZ++ = '.';
fmemcpy(destSZ, srcFCBName, loop + 1); fmemcpy(destSZ, srcFCBName, loop);
destSZ += loop + 1; destSZ += loop;
} }
} }
*destSZ = '\0'; *destSZ = '\0';
} }
#if 0
/*
returns the asciiSZ length of a 8.3 filename
*/
int FileName83Length(BYTE * filename83)
{
BYTE buff[13];
ConvertName83ToNameSZ(buff, filename83);
return strlen(buff);
}
#endif

View File

@ -221,8 +221,8 @@ BOOL init_device(struct dhdr FAR *, PCStr cmdLine, int mode, VFP *top);
/* prf.c */ /* prf.c */
int VA_CDECL init_printf(const char * fmt, ...); VOID VA_CDECL init_printf(const char * fmt, ...);
int VA_CDECL init_sprintf(char * buff, const char * fmt, ...); VOID VA_CDECL init_sprintf(char * buff, const char * fmt, ...);
/* procsupt.asm */ /* procsupt.asm */
VOID ASMCFUNC FAR got_cbreak(void); VOID ASMCFUNC FAR got_cbreak(void);

View File

@ -43,27 +43,20 @@ int SetJFTSize(UWORD nHandles)
psp FAR *ppsp = MK_FP(cu_psp, 0); psp FAR *ppsp = MK_FP(cu_psp, 0);
UBYTE FAR *newtab; UBYTE FAR *newtab;
if (nHandles <= ppsp->ps_maxfiles) if (nHandles > ppsp->ps_maxfiles)
{ {
ppsp->ps_maxfiles = nHandles; if ((DosMemAlloc
return SUCCESS; ((nHandles + 0xf) >> 4, mem_access_mode, &block, &maxBlock)) < 0)
return DE_NOMEM;
++block;
newtab = MK_FP(block, 0);
i = ppsp->ps_maxfiles;
/* copy existing part and fill up new part by "no open file" */
fmemcpy(newtab, ppsp->ps_filetab, i);
fmemset(newtab + i, 0xff, nHandles - i);
ppsp->ps_filetab = newtab;
} }
if ((DosMemAlloc
((nHandles + 0xf) >> 4, mem_access_mode, &block, &maxBlock)) < 0)
return DE_NOMEM;
++block;
newtab = MK_FP(block, 0);
i = ppsp->ps_maxfiles;
/* copy existing part and fill up new part by "no open file" */
fmemcpy(newtab, ppsp->ps_filetab, i);
fmemset(newtab + i, 0xff, nHandles - i);
ppsp->ps_maxfiles = nHandles; ppsp->ps_maxfiles = nHandles;
ppsp->ps_filetab = newtab;
return SUCCESS; return SUCCESS;
} }
@ -89,12 +82,6 @@ long DosMkTmp(BYTE FAR * pathname, UWORD attr)
for(i = 7; i >= 0; tmp >>= 4, i--) for(i = 7; i >= 0; tmp >>= 4, i--)
ptmp[i] = ((char)tmp & 0xf) + 'A'; ptmp[i] = ((char)tmp & 0xf) + 'A';
/* DOS versions: > 5: characters A - P
< 5: hex digits */
if (os_major < 5)
for (i = 0; i < 8; i++)
ptmp[i] -= (ptmp[i] < 'A' + 10) ? '0' - 'A' : 10;
/* only create new file -- 2001/09/22 ska*/ /* only create new file -- 2001/09/22 ska*/
rc = DosOpen(pathname, O_LEGACY | O_CREAT | O_RDWR, attr); rc = DosOpen(pathname, O_LEGACY | O_CREAT | O_RDWR, attr);
} while (rc == DE_FILEEXISTS && loop++ < 0xfff); } while (rc == DE_FILEEXISTS && loop++ < 0xfff);

View File

@ -36,7 +36,6 @@
#ifdef _INIT #ifdef _INIT
#define handle_char init_handle_char #define handle_char init_handle_char
#define put_console init_put_console #define put_console init_put_console
#define ltob init_ltob
#define do_printf init_do_printf #define do_printf init_do_printf
#define printf init_printf #define printf init_printf
#define sprintf init_sprintf #define sprintf init_sprintf
@ -132,9 +131,8 @@ typedef char *va_list;
static BYTE *charp = 0; static BYTE *charp = 0;
STATIC VOID handle_char(COUNT); STATIC VOID handle_char(COUNT);
STATIC void ltob(LONG, BYTE *, COUNT);
STATIC void do_printf(const char *, REG va_list); STATIC void do_printf(const char *, REG va_list);
int VA_CDECL printf(const char * fmt, ...); VOID VA_CDECL printf(const char * fmt, ...);
/* special handler to switch between sprintf and printf */ /* special handler to switch between sprintf and printf */
STATIC VOID handle_char(COUNT c) STATIC VOID handle_char(COUNT c)
@ -145,57 +143,21 @@ STATIC VOID handle_char(COUNT c)
*charp++ = c; *charp++ = c;
} }
/* ltob -- convert an long integer to a string in any base (2-16) */
STATIC void ltob(LONG n, BYTE * s, COUNT base)
{
ULONG u;
BYTE *p, *q;
int c;
u = n;
if (base == -10) /* signals signed conversion */
{
base = 10;
if (n < 0)
{
u = -n;
*s++ = '-';
}
}
p = s;
do
{ /* generate digits in reverse order */
*p++ = "0123456789abcdef"[(UWORD) (u % base)];
}
while ((u /= base) > 0);
*p = '\0'; /* terminate the string */
for (q = s; q < --p; q++)
{ /* reverse the digits */
c = *q;
*q = *p;
*p = c;
}
}
#define LEFT 0 #define LEFT 0
#define RIGHT 1 #define RIGHT 1
#define ZEROSFILL 2 #define ZEROSFILL 2
#define LONGARG 4 #define LONGARG 4
/* printf -- short version of printf to conserve space */ /* printf -- short version of printf to conserve space */
int VA_CDECL printf(const char *fmt, ...) VOID VA_CDECL printf(const char *fmt, ...)
{ {
va_list arg; va_list arg;
va_start(arg, fmt); va_start(arg, fmt);
charp = 0; charp = 0;
do_printf(fmt, arg); do_printf(fmt, arg);
return 0;
} }
int VA_CDECL sprintf(char * buff, const char * fmt, ...) VOID VA_CDECL sprintf(char * buff, const char * fmt, ...)
{ {
va_list arg; va_list arg;
@ -203,15 +165,13 @@ int VA_CDECL sprintf(char * buff, const char * fmt, ...)
charp = buff; charp = buff;
do_printf(fmt, arg); do_printf(fmt, arg);
handle_char('\0'); handle_char('\0');
return 0;
} }
STATIC void do_printf(CONST BYTE * fmt, va_list arg) STATIC void do_printf(CONST BYTE * fmt, va_list arg)
{ {
int base; int base, size;
BYTE s[11], FAR * p; char s[13]; /* long enough for a 32-bit octal number string with sign */
int size; char flags, FAR *p;
unsigned char flags;
for (;*fmt != '\0'; fmt++) for (;*fmt != '\0'; fmt++)
{ {
@ -302,17 +262,33 @@ STATIC void do_printf(CONST BYTE * fmt, va_list arg)
lprt: lprt:
{ {
long currentArg; long n;
ULONG u;
BYTE *t = s + sizeof(s) - 1;
if (flags & LONGARG) if (flags & LONGARG)
currentArg = va_arg(arg, long); n = va_arg(arg, long);
else else
{ {
currentArg = va_arg(arg, int); n = va_arg(arg, int);
if (base >= 0) if (base >= 0)
currentArg = (long)(unsigned)currentArg; n = (long)(unsigned)n;
} }
ltob(currentArg, s, base); /* convert a long integer to a string in any base (2-16) */
p = s; u = n;
if (base < 0) /* signals signed conversion */
{
base = -base;
if (n < 0)
u = -n;
}
*t = '\0'; /* terminate the number string */
do /* generate digits in reverse order */
*--t = "0123456789ABCDEF"[(UWORD)u % base];
while ((u /= base) > 0);
if (n < 0)
*--t = '-';
p = t;
} }
break; break;
@ -378,19 +354,15 @@ void hexd(char *title, UBYTE FAR * p, COUNT numBytes)
/* put_unsigned -- print unsigned int in base 2--16 */ /* put_unsigned -- print unsigned int in base 2--16 */
void put_unsigned(unsigned n, int base, int width) void put_unsigned(unsigned n, int base, int width)
{ {
char s[6]; char s[6]; /* CAUTION: width must be [0..5] and is not checked! */
int i;
for (i = 0; i < width; i++) s[width] = '\0'; /* terminate the number string */
while (--width >= 0)
{ /* generate digits in reverse order */ { /* generate digits in reverse order */
s[i] = "0123456789abcdef"[(UWORD) (n % base)]; s[width] = "0123456789ABCDEF"[n % base];
n /= base; n /= base;
} }
put_string(s);
while(i != 0)
{ /* print digits in reverse order */
put_console(s[--i]);
}
} }
void put_string(const char *s) void put_string(const char *s)
@ -408,19 +380,14 @@ void put_string(const char *s)
compile like (note -DTEST !) compile like (note -DTEST !)
c:\tc\tcc -DTEST -DI86 -I..\hdr prf.c c:\tc\tcc -DTEST -DI86 -Ihdr kernel\prf.c
and run. if strings are wrong, the program will wait for the ANYKEY and run. If strings are wrong, the program will wait for ENTER
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
void cso(char c)
{
putchar(c);
}
struct { struct {
char *should; char *should;
char *format; char *format;

View File

@ -38,10 +38,10 @@ struct buffer FAR *getblk(ULONG blkno, COUNT dsk, BOOL overwrite);
#define getblock(blkno, dsk) getblk(blkno, dsk, FALSE); #define getblock(blkno, dsk) getblk(blkno, dsk, FALSE);
#define getblockOver(blkno, dsk) getblk(blkno, dsk, TRUE); #define getblockOver(blkno, dsk) getblk(blkno, dsk, TRUE);
VOID setinvld(REG COUNT dsk); VOID setinvld(REG COUNT dsk);
BOOL flush_buffers(REG COUNT dsk); VOID flush_buffers(REG COUNT dsk);
BOOL flush(void); VOID flush(void);
BOOL fill(REG struct buffer FAR * bp, ULONG blkno, COUNT dsk); BOOL fill(REG struct buffer FAR * bp, ULONG blkno, COUNT dsk);
BOOL DeleteBlockInBufferCache(ULONG blknolow, ULONG blknohigh, COUNT dsk, int mode); VOID DeleteBlockInBufferCache(ULONG blknolow, ULONG blknohigh, COUNT dsk, int mode);
/* *** Changed on 9/4/00 BER */ /* *** Changed on 9/4/00 BER */
UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks, UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks,
COUNT mode); COUNT mode);
@ -60,7 +60,6 @@ void handle_break(struct dhdr FAR **pdev, int sft_out);
struct dhdr FAR *sft_to_dev(sft FAR *sft); struct dhdr FAR *sft_to_dev(sft FAR *sft);
long BinaryCharIO(struct dhdr FAR **pdev, size_t n, void FAR * bp, long BinaryCharIO(struct dhdr FAR **pdev, size_t n, void FAR * bp,
unsigned command); unsigned command);
int echo_char(int c, int sft_idx);
int ndread(struct dhdr FAR **pdev); int ndread(struct dhdr FAR **pdev);
int StdinBusy(void); int StdinBusy(void);
void con_flush(struct dhdr FAR **pdev); void con_flush(struct dhdr FAR **pdev);
@ -295,8 +294,8 @@ UWORD ASMCFUNC syscall_MUX14(DIRECT_IREGS);
/* prf.c */ /* prf.c */
#ifdef DEBUG #ifdef DEBUG
int VA_CDECL printf(const char * fmt, ...); VOID VA_CDECL printf(const char * fmt, ...);
int VA_CDECL sprintf(char * buff, const char * fmt, ...); VOID VA_CDECL sprintf(char * buff, const char * fmt, ...);
#endif #endif
VOID hexd(char *title, VOID FAR * p, COUNT numBytes); VOID hexd(char *title, VOID FAR * p, COUNT numBytes);
void put_unsigned(unsigned n, int base, int width); void put_unsigned(unsigned n, int base, int width);