mirror of
https://github.com/FDOS/kernel.git
synced 2025-04-08 17:15:17 +02:00
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:
parent
fce371ba94
commit
9584e214f5
@ -334,6 +334,7 @@
|
||||
- revision sequence now initialised along with DOS version in LoL
|
||||
- CheckContinueBootFromHardDisk() function code and text cleaned up
|
||||
* 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)
|
||||
(the last 2 changes proposed by Bart Oldeman)
|
||||
+ Changes Eduardo
|
||||
|
@ -47,7 +47,7 @@ static BYTE *blockioRcsId =
|
||||
/************************************************************************/
|
||||
/* #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.
|
||||
@ -155,7 +155,7 @@ STATIC struct buffer FAR *searchblock(ULONG blkno, COUNT dsk)
|
||||
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;
|
||||
|
||||
@ -176,8 +176,6 @@ BOOL DeleteBlockInBufferCache(ULONG blknolow, ULONG blknohigh, COUNT dsk, int mo
|
||||
bp = b_next(bp);
|
||||
}
|
||||
while (FP_OFF(bp) != FP_OFF(firstbuf));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if TOM
|
||||
@ -226,8 +224,7 @@ struct buffer FAR *getblk(ULONG blkno, COUNT dsk, BOOL overwrite)
|
||||
/* available, and fill it with the desired block */
|
||||
|
||||
/* take the buffer that lbp points to and flush it, then read new block. */
|
||||
if (!flush1(bp))
|
||||
return NULL;
|
||||
flush1(bp);
|
||||
|
||||
/* 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 */
|
||||
/* */
|
||||
/* returns: */
|
||||
/* TRUE on success */
|
||||
/* */
|
||||
BOOL flush_buffers(REG COUNT dsk)
|
||||
VOID flush_buffers(REG COUNT dsk)
|
||||
{
|
||||
struct buffer FAR *bp = firstbuf;
|
||||
REG BOOL ok = TRUE;
|
||||
|
||||
bp = firstbuf;
|
||||
do
|
||||
{
|
||||
if (bp->b_unit == dsk)
|
||||
if (!flush1(bp))
|
||||
ok = FALSE;
|
||||
flush1(bp);
|
||||
bp = b_next(bp);
|
||||
}
|
||||
while (FP_OFF(bp) != FP_OFF(firstbuf));
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* */
|
||||
/* 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 */
|
||||
|
||||
@ -320,31 +310,23 @@ STATIC BOOL flush1(struct buffer FAR * bp)
|
||||
bp->b_flag &= ~BFR_DIRTY; /* even if error, mark not dirty */
|
||||
if (result != 0) /* otherwise system has trouble */
|
||||
bp->b_flag &= ~BFR_VALID; /* continuing. */
|
||||
return (TRUE); /* Forced to TRUE...was like this before dskxfer() */
|
||||
/* returned error codes...BER */
|
||||
}
|
||||
|
||||
/* */
|
||||
/* Write all disk buffers */
|
||||
/* */
|
||||
BOOL flush(void)
|
||||
VOID flush(VOID)
|
||||
{
|
||||
REG struct buffer FAR *bp = firstbuf;
|
||||
REG BOOL ok;
|
||||
|
||||
ok = TRUE;
|
||||
do
|
||||
{
|
||||
if (!flush1(bp))
|
||||
ok = FALSE;
|
||||
flush1(bp);
|
||||
bp->b_flag &= ~BFR_VALID;
|
||||
bp = b_next(bp);
|
||||
}
|
||||
while (FP_OFF(bp) != FP_OFF(firstbuf));
|
||||
|
||||
network_redirector(REM_FLUSHALL);
|
||||
|
||||
return (ok);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
|
137
kernel/chario.c
137
kernel/chario.c
@ -73,7 +73,7 @@ long BinaryCharIO(struct dhdr FAR **pdev, size_t n, void FAR * bp,
|
||||
CharReqHdr.r_count = n;
|
||||
CharReqHdr.r_trans = bp;
|
||||
err = CharRequest(pdev, command);
|
||||
} while (err == 1);
|
||||
} while (err > 0);
|
||||
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 */
|
||||
|
||||
STATIC void CharCmd(struct dhdr FAR **pdev, unsigned command)
|
||||
{
|
||||
while (CharRequest(pdev, command) == 1);
|
||||
}
|
||||
#define CharCmd(pdev, command) while (CharRequest(pdev, command) > 0)
|
||||
|
||||
STATIC int Busy(struct dhdr FAR **pdev)
|
||||
{
|
||||
@ -138,103 +135,56 @@ int ndread(struct dhdr FAR **pdev)
|
||||
|
||||
/* 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)
|
||||
{
|
||||
unsigned char scrpos = scr_pos;
|
||||
|
||||
if (c == CR)
|
||||
scrpos = 0;
|
||||
scr_pos = 0;
|
||||
else if (c == BS) {
|
||||
if (scrpos > 0)
|
||||
scrpos--;
|
||||
} else if (c != LF && c != BELL) {
|
||||
scrpos += count;
|
||||
}
|
||||
scr_pos = scrpos;
|
||||
if (scr_pos > 0)
|
||||
scr_pos--;
|
||||
} else if (c != LF && c != BELL)
|
||||
scr_pos += count;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
size_t xfer = 0;
|
||||
unsigned char fast_counter;
|
||||
size_t xfer;
|
||||
|
||||
/* 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++)
|
||||
{
|
||||
int err;
|
||||
unsigned char c = *bp++;
|
||||
unsigned char count = 1, c = *bp++;
|
||||
|
||||
if (c == CTL_Z)
|
||||
break;
|
||||
|
||||
err = cooked_write_char(pdev, c, &fast_counter);
|
||||
if (err < 0)
|
||||
return err;
|
||||
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)
|
||||
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;
|
||||
}
|
||||
@ -271,16 +221,15 @@ void write_char_stdout(int c)
|
||||
#define iscntrl(c) ((unsigned char)(c) < ' ')
|
||||
|
||||
/* 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)
|
||||
{
|
||||
write_char('^', sft_idx);
|
||||
out += '@';
|
||||
c += '@';
|
||||
}
|
||||
write_char(out, sft_idx);
|
||||
return c;
|
||||
write_char(c, sft_idx);
|
||||
local_buffer[i] = c;
|
||||
}
|
||||
|
||||
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(LF, sft_out);
|
||||
}
|
||||
break;
|
||||
|
||||
case CTL_F:
|
||||
break;
|
||||
|
||||
case RIGHT:
|
||||
case F1:
|
||||
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;
|
||||
|
||||
case F2:
|
||||
@ -441,7 +388,7 @@ void read_line(int sft_in, int sft_out, keyboard FAR * kp)
|
||||
if (c != F4) /* not delete */
|
||||
{
|
||||
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;
|
||||
break;
|
||||
@ -513,12 +460,11 @@ void read_line(int sft_in, int sft_out, keyboard FAR * kp)
|
||||
|
||||
default:
|
||||
if (count < size - 1 || c == CR)
|
||||
local_buffer[count++] = echo_char(c, sft_out);
|
||||
echo_char(c, sft_out, count++);
|
||||
else
|
||||
write_char(BELL, sft_out);
|
||||
if (stored_pos < stored_size && !insert)
|
||||
stored_pos++;
|
||||
break;
|
||||
}
|
||||
first = FALSE;
|
||||
} 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;
|
||||
}
|
||||
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;
|
||||
if (*inputptr == CTL_Z)
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
db 0FFh,"COUNTRY",0,0,0,0,0,0,0,0,1,0,1 ; reserved and undocumented values
|
||||
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
|
||||
; (size, country, codepage, reserved(2), offset)
|
||||
@ -65,12 +65,18 @@ __ar dw 12, 54,850,0,0
|
||||
dd _ar
|
||||
__br dw 12, 55,850,0,0
|
||||
dd _br
|
||||
__my dw 12, 60,437,0,0
|
||||
dd _my
|
||||
__au dw 12, 61,437,0,0
|
||||
dd _au
|
||||
__sg dw 12, 65,437,0,0
|
||||
dd _sg
|
||||
__jp dw 12, 81,932,0,0
|
||||
dd _jp
|
||||
__kr dw 12, 82,934,0,0
|
||||
dd _kr
|
||||
__cn dw 12, 86,936,0,0
|
||||
dd _cn
|
||||
__tk dw 12, 90,850,0,0
|
||||
dd _tk
|
||||
__in dw 12, 91,437,0,0
|
||||
@ -140,12 +146,18 @@ _ar dw 1,6,1
|
||||
dd ar
|
||||
_br dw 1,6,1
|
||||
dd br
|
||||
_my dw 1,6,1
|
||||
dd my
|
||||
_au dw 1,6,1
|
||||
dd au
|
||||
_sg dw 1,6,1
|
||||
dd sg
|
||||
_jp dw 1,6,1
|
||||
dd np
|
||||
_kr dw 1,6,1
|
||||
dd kr
|
||||
_cn dw 1,6,1
|
||||
dd cn
|
||||
_tk dw 1,6,1
|
||||
dd tk
|
||||
_in dw 1,6,1
|
||||
@ -332,12 +344,24 @@ dw 55,850,DMY
|
||||
db "Cr$",0,0
|
||||
dw ".",",", "/",":"
|
||||
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"
|
||||
dw 22
|
||||
dw 61,437,DMY
|
||||
db "$",0,0,0,0
|
||||
dw ",",".", "-",":"
|
||||
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"
|
||||
dw 22
|
||||
dw 81,932,YMD
|
||||
@ -350,6 +374,12 @@ dw 82,934,YMD
|
||||
db 5Ch,0,0,0,0
|
||||
dw ",",".", ".",":"
|
||||
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"
|
||||
dw 22
|
||||
dw 90,850,DMY
|
||||
|
@ -486,35 +486,25 @@ COUNT dos_findnext(void)
|
||||
{
|
||||
++dmp->dm_entry;
|
||||
++fnp->f_diroff;
|
||||
if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED
|
||||
&& !(fnp->f_dir.dir_attrib & D_VOLID))
|
||||
{
|
||||
if (fcmp_wild(dmp->dm_name_pat, fnp->f_dir.dir_name, FNAME_SIZE + FEXT_SIZE))
|
||||
{
|
||||
/*
|
||||
if (fnp->f_dir.dir_name[0] != '\0' && fnp->f_dir.dir_name[0] != DELETED &&
|
||||
!(fnp->f_dir.dir_attrib & D_VOLID) &&
|
||||
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.
|
||||
Bits 0x21 seem to get set some where in MSD so Rd and Arc
|
||||
files are returned.
|
||||
RdOnly + Archive bits are ignored
|
||||
*/
|
||||
|
||||
/* Test the attribute as the final step */
|
||||
if (!(fnp->f_dir.dir_attrib & D_VOLID) &&
|
||||
!(~dmp->dm_attr_srch & (D_DIR | D_SYSTEM | D_HIDDEN) &
|
||||
fnp->f_dir.dir_attrib))
|
||||
{
|
||||
/* If found, transfer it to the dmatch structure */
|
||||
dmp->dm_dircluster = fnp->f_dirstart;
|
||||
memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
|
||||
/* return the result */
|
||||
release_f_node(fnp);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
files are returned. 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))
|
||||
{
|
||||
/* If found, transfer it to the dmatch structure */
|
||||
dmp->dm_dircluster = fnp->f_dirstart;
|
||||
memcpy(&SearchDir, &fnp->f_dir, sizeof(struct dirent));
|
||||
/* return the result */
|
||||
release_f_node(fnp);
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("dos_findnext: %11s\n", fnp->f_dir.dir_name);
|
||||
#endif
|
||||
@ -536,54 +526,22 @@ COUNT dos_findnext(void)
|
||||
void ConvertName83ToNameSZ(BYTE FAR * destSZ, BYTE FAR * srcFCBName)
|
||||
{
|
||||
int loop;
|
||||
int noExtension = FALSE;
|
||||
|
||||
if (*srcFCBName == '.')
|
||||
{
|
||||
noExtension = TRUE;
|
||||
}
|
||||
|
||||
fmemcpy(destSZ, srcFCBName, FNAME_SIZE);
|
||||
|
||||
srcFCBName += FNAME_SIZE;
|
||||
|
||||
for (loop = FNAME_SIZE; --loop >= 0;)
|
||||
for (loop = FNAME_SIZE; --loop >= 0 && destSZ[loop] == ' '; )
|
||||
;
|
||||
destSZ += ++loop;
|
||||
if (*srcFCBName != '.') /* not for ".", ".." */
|
||||
{
|
||||
if (destSZ[loop] != ' ')
|
||||
break;
|
||||
}
|
||||
destSZ += loop + 1;
|
||||
|
||||
if (!noExtension) /* not for ".", ".." */
|
||||
{
|
||||
|
||||
for (loop = FEXT_SIZE; --loop >= 0;)
|
||||
{
|
||||
if (srcFCBName[loop] != ' ')
|
||||
break;
|
||||
}
|
||||
if (loop >= 0)
|
||||
srcFCBName += FNAME_SIZE;
|
||||
for (loop = FEXT_SIZE; --loop >= 0 && srcFCBName[loop] == ' '; )
|
||||
;
|
||||
if (++loop > 0)
|
||||
{
|
||||
*destSZ++ = '.';
|
||||
fmemcpy(destSZ, srcFCBName, loop + 1);
|
||||
destSZ += loop + 1;
|
||||
fmemcpy(destSZ, srcFCBName, loop);
|
||||
destSZ += loop;
|
||||
}
|
||||
}
|
||||
*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
|
||||
|
||||
|
@ -221,8 +221,8 @@ BOOL init_device(struct dhdr FAR *, PCStr cmdLine, int mode, VFP *top);
|
||||
|
||||
/* prf.c */
|
||||
|
||||
int VA_CDECL init_printf(const char * fmt, ...);
|
||||
int VA_CDECL init_sprintf(char * buff, const char * fmt, ...);
|
||||
VOID VA_CDECL init_printf(const char * fmt, ...);
|
||||
VOID VA_CDECL init_sprintf(char * buff, const char * fmt, ...);
|
||||
|
||||
/* procsupt.asm */
|
||||
VOID ASMCFUNC FAR got_cbreak(void);
|
||||
|
@ -43,27 +43,20 @@ int SetJFTSize(UWORD nHandles)
|
||||
psp FAR *ppsp = MK_FP(cu_psp, 0);
|
||||
UBYTE FAR *newtab;
|
||||
|
||||
if (nHandles <= ppsp->ps_maxfiles)
|
||||
if (nHandles > ppsp->ps_maxfiles)
|
||||
{
|
||||
ppsp->ps_maxfiles = nHandles;
|
||||
return SUCCESS;
|
||||
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_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_filetab = newtab;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -89,12 +82,6 @@ long DosMkTmp(BYTE FAR * pathname, UWORD attr)
|
||||
for(i = 7; i >= 0; tmp >>= 4, i--)
|
||||
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*/
|
||||
rc = DosOpen(pathname, O_LEGACY | O_CREAT | O_RDWR, attr);
|
||||
} while (rc == DE_FILEEXISTS && loop++ < 0xfff);
|
||||
|
103
kernel/prf.c
103
kernel/prf.c
@ -36,7 +36,6 @@
|
||||
#ifdef _INIT
|
||||
#define handle_char init_handle_char
|
||||
#define put_console init_put_console
|
||||
#define ltob init_ltob
|
||||
#define do_printf init_do_printf
|
||||
#define printf init_printf
|
||||
#define sprintf init_sprintf
|
||||
@ -132,9 +131,8 @@ typedef char *va_list;
|
||||
static BYTE *charp = 0;
|
||||
|
||||
STATIC VOID handle_char(COUNT);
|
||||
STATIC void ltob(LONG, BYTE *, COUNT);
|
||||
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 */
|
||||
STATIC VOID handle_char(COUNT c)
|
||||
@ -145,57 +143,21 @@ STATIC VOID handle_char(COUNT 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 RIGHT 1
|
||||
#define ZEROSFILL 2
|
||||
#define LONGARG 4
|
||||
|
||||
/* 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_start(arg, fmt);
|
||||
charp = 0;
|
||||
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;
|
||||
|
||||
@ -203,15 +165,13 @@ int VA_CDECL sprintf(char * buff, const char * fmt, ...)
|
||||
charp = buff;
|
||||
do_printf(fmt, arg);
|
||||
handle_char('\0');
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC void do_printf(CONST BYTE * fmt, va_list arg)
|
||||
{
|
||||
int base;
|
||||
BYTE s[11], FAR * p;
|
||||
int size;
|
||||
unsigned char flags;
|
||||
int base, size;
|
||||
char s[13]; /* long enough for a 32-bit octal number string with sign */
|
||||
char flags, FAR *p;
|
||||
|
||||
for (;*fmt != '\0'; fmt++)
|
||||
{
|
||||
@ -302,17 +262,33 @@ STATIC void do_printf(CONST BYTE * fmt, va_list arg)
|
||||
|
||||
lprt:
|
||||
{
|
||||
long currentArg;
|
||||
long n;
|
||||
ULONG u;
|
||||
BYTE *t = s + sizeof(s) - 1;
|
||||
|
||||
if (flags & LONGARG)
|
||||
currentArg = va_arg(arg, long);
|
||||
n = va_arg(arg, long);
|
||||
else
|
||||
{
|
||||
currentArg = va_arg(arg, int);
|
||||
n = va_arg(arg, int);
|
||||
if (base >= 0)
|
||||
currentArg = (long)(unsigned)currentArg;
|
||||
n = (long)(unsigned)n;
|
||||
}
|
||||
ltob(currentArg, s, base);
|
||||
p = s;
|
||||
/* convert a long integer to a string in any base (2-16) */
|
||||
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;
|
||||
|
||||
@ -378,19 +354,15 @@ void hexd(char *title, UBYTE FAR * p, COUNT numBytes)
|
||||
/* put_unsigned -- print unsigned int in base 2--16 */
|
||||
void put_unsigned(unsigned n, int base, int width)
|
||||
{
|
||||
char s[6];
|
||||
int i;
|
||||
char s[6]; /* CAUTION: width must be [0..5] and is not checked! */
|
||||
|
||||
for (i = 0; i < width; i++)
|
||||
s[width] = '\0'; /* terminate the number string */
|
||||
while (--width >= 0)
|
||||
{ /* generate digits in reverse order */
|
||||
s[i] = "0123456789abcdef"[(UWORD) (n % base)];
|
||||
s[width] = "0123456789ABCDEF"[n % base];
|
||||
n /= base;
|
||||
}
|
||||
|
||||
while(i != 0)
|
||||
{ /* print digits in reverse order */
|
||||
put_console(s[--i]);
|
||||
}
|
||||
put_string(s);
|
||||
}
|
||||
|
||||
void put_string(const char *s)
|
||||
@ -408,19 +380,14 @@ void put_string(const char *s)
|
||||
|
||||
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 <string.h>
|
||||
|
||||
void cso(char c)
|
||||
{
|
||||
putchar(c);
|
||||
}
|
||||
|
||||
struct {
|
||||
char *should;
|
||||
char *format;
|
||||
|
@ -38,10 +38,10 @@ struct buffer FAR *getblk(ULONG blkno, COUNT dsk, BOOL overwrite);
|
||||
#define getblock(blkno, dsk) getblk(blkno, dsk, FALSE);
|
||||
#define getblockOver(blkno, dsk) getblk(blkno, dsk, TRUE);
|
||||
VOID setinvld(REG COUNT dsk);
|
||||
BOOL flush_buffers(REG COUNT dsk);
|
||||
BOOL flush(void);
|
||||
VOID flush_buffers(REG COUNT dsk);
|
||||
VOID flush(void);
|
||||
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 */
|
||||
UWORD dskxfer(COUNT dsk, ULONG blkno, VOID FAR * buf, UWORD numblocks,
|
||||
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);
|
||||
long BinaryCharIO(struct dhdr FAR **pdev, size_t n, void FAR * bp,
|
||||
unsigned command);
|
||||
int echo_char(int c, int sft_idx);
|
||||
int ndread(struct dhdr FAR **pdev);
|
||||
int StdinBusy(void);
|
||||
void con_flush(struct dhdr FAR **pdev);
|
||||
@ -295,8 +294,8 @@ UWORD ASMCFUNC syscall_MUX14(DIRECT_IREGS);
|
||||
|
||||
/* prf.c */
|
||||
#ifdef DEBUG
|
||||
int VA_CDECL printf(const char * fmt, ...);
|
||||
int VA_CDECL sprintf(char * buff, const char * fmt, ...);
|
||||
VOID VA_CDECL printf(const char * fmt, ...);
|
||||
VOID VA_CDECL sprintf(char * buff, const char * fmt, ...);
|
||||
#endif
|
||||
VOID hexd(char *title, VOID FAR * p, COUNT numBytes);
|
||||
void put_unsigned(unsigned n, int base, int width);
|
||||
|
Loading…
x
Reference in New Issue
Block a user