?? clib.arc
字號:
while(sz) {
str[--sz]=(nbr%10+'0');
if((nbr=nbr/10)==0) break;
}
if(sz) str[--sz]=sgn;
while(sz>0) str[--sz]=' ';
return str;
}
>>> ITOO.C 541
/*
** itoo -- converts nbr to octal string of length sz
** right adjusted and blank filled, returns str
**
** if sz > 0 terminate with null byte
** if sz = 0 find end of string
** if sz < 0 use last byte for data
*/
itoo(nbr, str, sz) int nbr; char str[]; int sz; {
int digit;
if(sz>0) str[--sz]=0;
else if(sz<0) sz = -sz;
else while(str[sz]!=0) ++sz;
while(sz) {
digit=nbr&7; nbr=(nbr>>3)&8191;
str[--sz]=digit+48;
if(nbr==0) break;
}
while(sz) str[--sz]=' ';
return str;
}
>>> ITOU.C 621
#include "stdio.h"
/*
** itou -- convert nbr to unsigned decimal string of width sz
** right adjusted, blank filled; returns str
**
** if sz > 0 terminate with null byte
** if sz = 0 find end of string
** if sz < 0 use last byte for data
*/
itou(nbr, str, sz) int nbr; char str[]; int sz; {
int lowbit;
if(sz>0) str[--sz]=NULL;
else if(sz<0) sz = -sz;
else while(str[sz]!=NULL) ++sz;
while(sz) {
lowbit=nbr&1;
nbr=(nbr>>1)&32767; /* divide by 2 */
str[--sz]=((nbr%5)<<1)+lowbit+'0';
if((nbr=nbr/5)==0) break;
}
while(sz) str[--sz]=' ';
return str;
}
>>> ITOX.C 596
/*
** itox -- converts nbr to hex string of length sz
** right adjusted and blank filled, returns str
**
** if sz > 0 terminate with null byte
** if sz = 0 find end of string
** if sz < 0 use last byte for data
*/
itox(nbr, str, sz) int nbr; char str[]; int sz; {
int digit, offset;
if(sz>0) str[--sz]=0;
else if(sz<0) sz = -sz;
else while(str[sz]!=0) ++sz;
while(sz) {
digit=nbr&15; nbr=(nbr>>4)&4095;
if(digit<10) offset=48; else offset=55;
str[--sz]=digit+offset;
if(nbr==0) break;
}
while(sz) str[--sz]=' ';
return str;
}
>>> LEFT.C 166
/*
** left -- left adjust and null terminate a string
*/
left(str) char *str; {
char *str2;
str2=str;
while(*str2==' ') ++str2;
while(*str++ = *str2++);
}
>>> LEXCMP.C 1380
char _lex[128] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* NUL - / */
10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47,
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, /* 0-9 */
48, 49, 50, 51, 52, 53, 54, /* : ; < = > ? @ */
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, /* A-Z */
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99,100,
55, 56, 57, 58, 59, 60, /* [ \ ] ^ _ ` */
75, 76, 77, 78, 79, 80, 81, 82, 83, 84, /* a-z */
85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
95, 96, 97, 98, 99,100,
61, 62, 63, 64, /* { | } ~ */
127}; /* DEL */
/*
** lexcmp(s, t) - Return a number <0, 0, or >0
** as s is <, =, or > t.
*/
lexcmp(s, t) char *s, *t; {
while(lexorder(*s, *t) == 0)
if(*s++) ++t;
else return (0);
return (lexorder(*s, *t));
}
/*
** lexorder(c1, c2)
**
** Return a negative, zero, or positive number if
** c1 is less than, equal to, or greater than c2,
** based on a lexicographical (dictionary order)
** colating sequence.
**
*/
lexorder(c1, c2) int c1, c2; {
return(_lex[c1] - _lex[c2]);
}
>>> MALLOC.C 237
#include "stdio.h"
/*
** Memory allocation of size bytes.
** size = Size of the block in bytes.
** Returns the address of the allocated block,
** else NULL for failure.
*/
malloc(size) unsigned size; {
return (_alloc(size, NO));
}
>>> OTOI.C 368
#include "stdio.h"
/*
** otoi -- convert unsigned octal string to integer nbr
** returns field size, else ERR on error
*/
otoi(octstr, nbr) char *octstr; int *nbr; {
int d,t; d=0;
*nbr=0;
while((*octstr>='0')&(*octstr<='7')) {
t=*nbr;
t=(t<<3) + (*octstr++ - '0');
if ((t>=0)&(*nbr<0)) return ERR;
d++; *nbr=t;
}
return d;
}
>>> PAD.C 123
/*
** Place n occurrences of ch at dest.
*/
pad(dest, ch, n) char *dest; unsigned n, ch; {
while(n--) *dest++ = ch;
}
>>> POLL.C 390
#include "stdio.h"
#include "clib.h"
/*
** Poll for console input or interruption
*/
poll(pause) int pause; {
int i;
if(i = _hitkey()) i = _getkey();
if(pause) {
if(i == PAUSE) {
i = _getkey(); /* wait for next character */
if(i == ABORT) exit(2); /* indicate abnormal exit */
return (0);
}
if(i == ABORT) exit(2);
}
return (i);
}
>>> PUTCHAR.C 122
#include "stdio.h"
/*
** Write character to standard output.
*/
putchar(ch) int ch; {
return (fputc(ch, stdout));
}
>>> PUTS.C 144
#include "stdio.h"
/*
** Write string to standard output.
*/
puts(string) char *string; {
fputs(string, stdout);
fputc('\n', stdout);
}
>>> RENAME.C 711
#include "stdio.h"
#include "clib.h"
/*
** Rename a file.
** from = address of old filename.
** to = address of new filename.
** Returns NULL on success, else ERR.
*/
rename(from, to) char *from, *to; {
if(_rename(from, to)) return (NULL);
return (ERR);
}
_rename(old, new) char *old, *new; {
#asm
push ds ; ds:dx points to old name
pop es ; es:di points to new name
mov di,[bp+4] ; get "new" offset
mov dx,[bp+6] ; get "old" offset
mov ah,56h ; rename function
int 21h ; call bdos
jnc __ren1 ; error?
xor ax,ax ; yes, return false
jmp __ren2
__ren1: ; no, set hi and lo
mov ax,1 ; return true
__ren2:
#endasm
}
>>> REVERSE.C 170
/*
** reverse string in place
*/
reverse(s) char *s; {
char *j;
int c;
j = s + strlen(s) - 1;
while(s < j) {
c = *s;
*s++ = *j;
*j-- = c;
}
}
>>> REWIND.C 89
/*
** Rewind file to beginning.
*/
rewind(fd) int fd; {
return(cseek(fd, 0, 0));
}
>>> SIGN.C 154
/*
** sign -- return -1, 0, +1 depending on the sign of nbr
*/
sign(nbr) int nbr; {
if(nbr > 0) return 1;
if(nbr == 0) return 0;
return -1;
}
>>> STRCAT.C 177
/*
** concatenate t to end of s
** s must be large enough
*/
strcat(s, t) char *s, *t; {
char *d;
d = s;
--s;
while (*++s) ;
while (*s++ = *t++) ;
return (d);
}
>>> STRCHR.C 177
/*
** return pointer to 1st occurrence of c in str, else 0
*/
strchr(str, c) char *str, c; {
while(*str) {
if(*str == c) return (str);
++str;
}
return (0);
}
>>> STRCMP.C 185
/*
** return <0, 0, >0 a_ording to
** s<t, s=t, s>t
*/
strcmp(s, t) char *s, *t; {
while(*s == *t) {
if(*s == 0) return (0);
++s; ++t;
}
return (*s - *t);
}
>>> STRCPY.C 113
/*
** copy t to s
*/
strcpy(s, t) char *s, *t; {
char *d;
d = s;
while (*s++ = *t++) ;
return (d);
}
>>> STRLEN.C 357
/*
** return length of string s (fast version)
*/
strlen(s) char *s; {
#asm
xor al,al ; set search value to zero
mov cx,65535 ; set huge maximum
mov di,[bp+4] ; get address of s
cld ; set direction flag forward
repne scasb ; scan for zero
mov ax,65534
sub ax,cx ; calc and return length
#endasm
}
>>> STRNCAT.C 255
/*
** concatenate n bytes max from t to end of s
** s must be large enough
*/
strncat(s, t, n) char *s, *t; int n; {
char *d;
d = s;
--s;
while(*++s) ;
while(n--) {
if(*s++ = *t++) continue;
return(d);
}
*s = 0;
return(d);
}
>>> STRNCMP.C 333
/*
** strncmp(s,t,n) - Compares two strings for at most n
** characters and returns an integer
** >0, =0, or <0 as s is >t, =t, or <t.
*/
strncmp(s, t, n) char *s, *t; int n; {
while(n && *s==*t) {
if (*s == 0) return (0);
++s; ++t; --n;
}
if(n) return (*s - *t);
return (0);
}
>>> STRNCPY.C 253
/*
** copy n characters from sour to dest (null padding)
*/
strncpy(dest, sour, n) char *dest, *sour; int n; {
char *d;
d = dest;
while(n-- > 0) {
if(*d++ = *sour++) continue;
while(n-- > 0) *d++ = 0;
}
*d = 0;
return (dest);
}
>>> STRRCHR.C 315
/*
** strrchr(s,c) - Search s for rightmost occurrance of c.
** s = Pointer to string to be searched.
** c = Character to search for.
** Returns pointer to rightmost c or NULL.
*/
strrchr(s, c) char *s, c; {
char *ptr;
ptr = 0;
while(*s) {
if(*s==c) ptr = s;
++s;
}
return (ptr);
}
>>> TOASCII.C 77
/*
** return ASCII equivalent of c
*/
toascii(c) int c; {
return (c);
}
>>> TOLOWER.C 131
/*
** return lower-case of c if upper-case, else c
*/
tolower(c) int c; {
if(c<='Z' && c>='A') return (c+32);
return (c);
}
>>> TOUPPER.C 137
/*
** return upper-case of c if it is lower-case, else c
*/
toupper(c) int c; {
if(c<='z' && c>='a') return (c-32);
return (c);
}
>>> UNGETC.C 295
#include "stdio.h"
extern _nextc[];
/*
** Put c back into file fd.
** Entry: c = character to put back
** fd = file descriptor
** Returns c if successful, else EOF.
*/
ungetc(c, fd) int c, fd; {
if(!_mode(fd) || _nextc[fd]!=EOF || c==EOF) return (EOF);
return (_nextc[fd] = c);
}
>>> UNLINK.C 473
#include "stdio.h"
#include "clib.h"
/*
** Unlink (delete) the named file.
** Entry: fn = Null-terminated DOS file path\name.
** Returns NULL on success, else ERR.
*/
unlink(fn) char *fn; {
fn; /* load fn into ax */
#asm
mov dx,ax ; put fn in its place
mov ah,41h ; delete function code
int 21h
mov ax,0
jnc __unlk ; return NULL
mov ax,-2 ; return ERR
__unlk:
#endasm
}
#asm
_delete: jmp _unlink
public _delete
#endasm
>>> UTOI.C 365
#include "stdio.h"
/*
** utoi -- convert unsigned decimal string to integer nbr
** returns field size, else ERR on error
*/
utoi(decstr, nbr) char *decstr; int *nbr; {
int d,t; d=0;
*nbr=0;
while((*decstr>='0')&(*decstr<='9')) {
t=*nbr;t=(10*t) + (*decstr++ - '0');
if ((t>=0)&(*nbr<0)) return ERR;
d++; *nbr=t;
}
return d;
}
>>> XTOI.C 729
#include stdio.h
/*
** xtoi -- convert hex string to integer nbr
** returns field size, else ERR on error
*/
xtoi(hexstr, nbr) char *hexstr; int *nbr; {
int d, b; char *cp;
d = *nbr = 0; cp = hexstr;
while(*cp == '0') ++cp;
while(1) {
switch(*cp) {
case '0': case '1': case '2':
case '3': case '4': case '5':
case '6': case '7': case '8':
case '9': b=48; break;
case 'A': case 'B': case 'C':
case 'D': case 'E': case 'F': b=55; break;
case 'a': case 'b': case 'c':
case 'd': case 'e': case 'f': b=87; break;
default: return (cp - hexstr);
}
if(d < 4) ++d; else return (ERR);
*nbr = (*nbr << 4) + (*cp++ - b);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -