Add full compiler toolchain, libc, examples and reference docs

First substantive commit: the entire Sprinter C compiler tree on top of
the bare README+gitignore initial commit.

What's in here:
  bin/sprinter-cc        — driver script invoking SDCC + linker + mkexe
  libc/                  — Sprinter-specific libc layer over ESTEX/BIOS
                           (conio, gfx, io, mem, stdio + headers)
  runtime/               — crt0 variants (default/small/banked/minimal)
                           + heap + bank trampolines
  toolchain/             — mkexe (SprintEXE packer, C + tests)
  examples/              — 30 demo programs (gfx, file I/O, env, time, …)
  lib/Makefile           — builds the libc archive (sprinter.lib)
  docs/                  — converted Sprinter manuals + asm reference samples
  third_party/           — solid-c reference compiler dump + sdcc setup script
  release_docs/          — packaging / release notes

gitignore overhaul:
  • Drop dangerous blanket patterns: *.asm (would hide docs/samples/*.asm)
    and *.exe (case-insensitive match was hiding third_party/solid-c/*.EXE
    on macOS APFS).  Replaced with examples/*/*.{asm,exe,…} and lib/*.lib.
  • Restore tracking of toolchain/mkexe/tests/{one,big}.bin — those are
    INPUT fixtures, not build outputs.
  • Collapse the duplicated SDCC/C/Sdcc sections into one section per
    concern (build outputs / vendored / OS-junk).
  • Add .sprinter-cc-*/, build/ (catches lib/build/ too), .claude/.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-03 16:13:21 +03:00
parent f542608b3f
commit c71e249a4e
404 changed files with 75155 additions and 58 deletions
+28
View File
@@ -0,0 +1,28 @@
#include <stdio.h>
void func1();
void func2();
void main()
{
atexit(func1); // "Exit Function 1 called"
atexit(func2); // "Exit Function 2 called"
printf("\tMain quitting ...\n");
/*
* ‚뢥¤¥âáï:
* Main quitting ...
* Exit Function 2 called ...
* Exit Function 1 called ...
*/
}
void func1()
{
printf("\tExit Function 1 called ...\n");
}
void func2()
{
printf("\tExit Function 2 called ...\n");
}
+98
View File
@@ -0,0 +1,98 @@
/*
* BIN2C V1.0 CODED BY CHRISTIAN PADOVANO ON 17-MAY-1995
*
* this little utility translates a binary file in a useful C structure
* that can be included in a C source.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>
#define BUF_LEN 1
#define LINE 9
FILE *fp, *fp1;
f_point *pos;
/* lower chars --> upper chars */
void upper_chars(buff)
char *buff;
{
char c;
for(c=0; c <= strlen(buff)-1; c++)
*(buff+c) = toupper(*(buff+c));
}
void main(argc, argv)
int argc;
char *argv[];
{
char buffer[BUF_LEN], dummy[20];
char c;
if((argc < 4))
{
puts("- <<< BIN2C V1.0 >>> by Christian Padovano -\n");
puts("Usage: Bin2C <BINARY file name> <TARGET file name> <STRUCT name>\n");
puts(" <STRUCT > = name of the C structure in the destination file name");
puts(" <TARGET > = without extension '.h' it will be added by program");
exit(0);
}
if((fp=fopen(argv[1], "rb")) == NULL)
{
cprintf("ERROR: I can't find source file %s\n", argv[1]);
exit(1);
}
strcpy(dummy, argv[2]);
strcat(dummy, ".H"); /* add suffix .h to target name */
if((fp1=fopen(dummy, "w+")) == NULL)
{
cprintf("ERROR: I can't open destination file %s\n", dummy);
exit(1);
}
strcpy(dummy, argv[3]);
upper_chars(dummy); /* lower to upper chars */
strcat(dummy, "_LEN"); /* add the suffix _LEN to the struct name */
/* for the #define stantment */
/* file size in bytes */
fseek(fp, 0, 0, SEEK_END);
pos = ftell(fp);
fseek(fp, 0, 0, SEEK_SET);
/* It writes the header information */
fprintf(fp1, "#define %s %u\n\n", dummy, pos->low);
fprintf(fp1, " static unsigned char %s[]={\n ", argv[3]);
if(ferror(fp1))
{
cprintf("ERROR writing on target file: %s\n", argv[2]);
exit(1);
}
do {
for(c=0; ((c <= LINE) && (! feof(fp))); c++)
{
fread(buffer, 1, 1, fp);
fprintf(fp1,"0x%02X", (char *) *buffer);
if(! feof(fp))
fputc(',', fp1);
}
fprintf(fp1,"\n ");
} while(! feof(fp));
fprintf(fp1,"};\n");
fclose(fp);
fclose(fp1);
}
+10
View File
@@ -0,0 +1,10 @@
#include <io.h>
FD fd;
void main()
{
fd = open("test.txt", O_RDONLY);
if((close(fd)) == -1)
perror("close failed on file");
}
+6
View File
@@ -0,0 +1,6 @@
#include <conio.h>
void main()
{
cprintf("Hello, world!\n");
}
+8
View File
@@ -0,0 +1,8 @@
#include <conio.h>
char *buffer = "Insert data disk in drive A:\n";
void main()
{
cputs(buffer);
}
+12
View File
@@ -0,0 +1,12 @@
#include <io.h>
FD fd;
void main()
{
fd = creat("test.txt", O_RDWR | O_CREAT);
if(fd == -1)
perror("create failed on file");
else
close(fd);
}
+10
View File
@@ -0,0 +1,10 @@
#include <stdio.h>
FILE *fp;
void main()
{
fp = fopen("test.txt", "r");
if((fclose(fp)) == -1)
perror("close failed on file");
}
+21
View File
@@ -0,0 +1,21 @@
#include <stdio.h>
#include <io.h>
FILE *fp;
FD fd;
main()
{
fd = open("test.txt", O_WRONLY);
if(fd == -1)
fprintf(stderr, "File test.txt not found\n");
fp = fdopen(fd, "a");
if(fp == NULL)
fprintf(stderr, "Errors in function fdopen\n");
else
{
fprintf(fp, "Hello, world !\n");
fclose(fp);
}
}
+28
View File
@@ -0,0 +1,28 @@
FEOF
#include <stdio.h> ¤«ï ®¡ê¥­¨ï ä㭪樨
int feof(FILE *fp);
ã­ªæ¨ï (ॠ«¨§®¢ ­­ ï ª ª ¬ ªà®) ®¯à¥¤¥«ï¥â, ¤®á⨣­ãâ «¨ ª®­¥æ § ¤ ­-
­®£® ä ©« . ᫨ ª®­¥æ ä ©«  (EOF) ¤®á⨣­ãâ, â® áâ ­®¢ïâáï ­¥¤®áâ㯭묨
®¯¥à æ¨¨ ç⥭¨ï, â.¥. ¯à¨ ª ¦¤®© ®¯¥à æ¨¨ ç⥭¨ï, ¡ã¤¥â ¢®§¢à é âìáï ¯à¨§-
­ ª ª®­æ  ä ©« , ¯®ª  ä ©« ­¥ ¡ã¤¥â § ªàëâ ¨«¨ ¢ë§¢ ­ë ä㭪樨 rewind,
fsetpos, fseek ¨«¨ clearerr.
᫨ ⥪ãé ï ¯®§¨æ¨ï ï¥âáï ª®­æ®¬ ä ©«  (EOF), äã­ªæ¨ï ¢®§¢à é ¥â ­¥­ã-
«¥¢®¥ §­ ç¥­¨¥. ᫨ ⥪ãé ï ¯®§¨æ¨ï ­¥ ï¥âáï ª®­æ®¬ ä ©«  - ¢®§¢à é -
¥âáï §­ ç¥­¨¥ 0. ã­ªæ¨ï feof ®è¨¡®ª ­¥ ¢®§¢à é ¥â.
#include <stdio.h>
FILE *fp;
main()
{
if((fp=fopen("file.dat", "r")) == NULL)
{
printf("Žè¨¡ª  ®âªàëâ¨ï ä ©« \n");
exit(1);
}
while(!feof(fp))
fgetc(fp);
printf("\n” ©« ¯à®ç¨â ­, ¢áâà¥â¨«áï EOF\n");
fclose(fp);
}
+22
View File
@@ -0,0 +1,22 @@
ã­ªæ¨ï ferror ¯à®¢¥àï¥â ®è¨¡ª¨ ç⥭¨ï ¨ § ¯¨á¨ § ¤ ­­®£® ä ©« .
ਠ¢®§­¨ª­®¢¥­¨¨ ®è¨¡ª¨, ¨­¤¨ª â®à ®è¨¡ª¨ ä ©«  fp ®áâ ¥âáï ãáâ -
­®¢«¥­­ë¬ ¤® â¥å ¯®à, ¯®ª  ä ©« ­¥ § ªà®¥âáï ¨«¨ ¡ã¤ã⠢맢 ­ë
ä㭪樨 rewind ¨«¨ clearerr.
á«ãç ¥ ®¡­ à㦥­¨ï ®è¨¡ª¨ ¢ ä ©«¥, äã­ªæ¨ï ferror ¢®§¢à é ¥â ­¥­ã-
«¥¢®¥ §­ ç¥­¨¥. ®§¢à é ¥¬®¥ §­ ç¥­¨¥ 0 ᢨ¤¥â¥«ìáâ¢ã¥â ®¡ ®âáãâá⢨¨
®è¨¡ª¨.
#include <stdio.h>
FILE *fp;
char *string;
/* á«¥¤ãî騩 ¯à¨¬¥à ¢¢®¤¨â ¤ ­­ë¥ ¢ ä ©« ¨ ¯à®¢¥àï¥â,
­¥ ¢®§­¨ª«  «¨ ®è¨¡ª  ¯à¨ § ¯¨á¨. ¥à¥¤ § ¯¨áìî
¤ ­­ëå ¢ ä ©«, ®­ ¤®«¦¥­ ¡ëâì ¯à¥¤¢ à¨â¥«ì­® ®âªàëâ. */
fprintf(fp, "%s\n", string);
if(ferror(fp))
{
fprintf(stderr, "Write error\n");
clearerr(fp);
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <dos.h>
FIND p;
char done;
void main()
{
printf("List of directory: *.*\n");
done = ffirst("*.*", &p, FA_NORMAL | FA_ARCH | FA_DIREC);
while(!done)
{
printf("%s\n", p.ff_name);
done = fnext(&p);
}
}
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
void main()
{
FILE *fp;
fpos_t position;
char buffer[80];
fp = fopen("test.txt", "r");
if(fp != NULL)
{
fgetpos(fp, &position); /* get position */
fgets(buffer, 80, fp); /* read record */
fsetpos(fp, &position); /* set position */
fgets(buffer, 80, fp); /* read same record */
fclose(fp); /* close file */
}
else
printf("can't open file\n");
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <dos.h>
struct ffblk p;
char done;
void main()
{
printf("List of directory: *.*\n");
done = findfirst("*.*", &p, FA_NORMAL | FA_ARCH | FA_DIREC);
while(!done)
{
printf("%s\n", p.ff_name);
done = findnext(&p);
}
}
+14
View File
@@ -0,0 +1,14 @@
#include <stdio.h>
FILE *fp;
void main(argc, argv)
int argc;
char *argv[];
{
if((fp=fopen(argv[0], "r")) == NULL)
{
fprintf(stderr,"can't open file: %s\n", argv[0]);
exit(1);
}
}
+11
View File
@@ -0,0 +1,11 @@
#include <stdio.h>
FILE *fp;
char *s = "This is string.";
void main()
{
fp = fopen("test.txt", "w");
fprintf(fp,"%s",s);
fclose(fp);
}
+21
View File
@@ -0,0 +1,21 @@
#include <stdio.h>
FILE *fp;
char *s = "Hello, world ! ;)";
main()
{
fp = fopen("test.txt", "r");
if(fp == NULL)
fprintf(stderr, "File test.txt not found\n");
fp = freopen("file.dat", "w+", fp);
if(fp == NULL)
fprintf(stderr, "Errors in function freopen\n");
else
{
fprintf(stderr, "Now data will go in file.dat\n");
fprintf(fp, "%s\n", s);
}
fclose(fp);
}
+17
View File
@@ -0,0 +1,17 @@
#include <stdio.h>
FILE *fp;
f_point *pos;
void main()
{
fp=fopen("test.txt", "r");
pos->high = 0;
pos->low = 20;
if((pos=fseek(fp, pos->high, pos->low, SEEK_SET)) == -1)
printf("Žè¨¡ª  ¯¥à¥¬¥é¥­¨ï\n");
fprintf(stdout,"\n%04X %04X", pos->high, pos->low);
fclose(fp);
}
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
void main()
{
FILE *fp;
fpos_t position;
char buffer[80];
fp = fopen("test.txt", "r");
if(fp != NULL)
{
fgetpos(fp, &position); /* get position */
fgets(buffer, 80, fp); /* read record */
fsetpos(fp, &position); /* set position */
fgets(buffer, 80, fp); /* read same record */
fclose(fp); /* close file */
}
else
printf("can't open file\n");
}
+18
View File
@@ -0,0 +1,18 @@
#include <stdio.h>
FILE *fp;
f_point *pos;
void main()
{
fp=fopen("test.txt", "r");
pos->high = 0;
pos->low = 20;
if((fseek(fp, pos->high, pos->low, SEEK_SET)) == -1)
printf("Žè¨¡ª  ¯¥à¥¬¥é¥­¨ï\n");
pos=ftell(fp);
fprintf(stdout,"\n%04X %04X", pos->high, pos->low);
fclose(fp);
}
+7
View File
@@ -0,0 +1,7 @@
@echo off
cc1 -m hello.c
cc2 hello.tmc
as hello.asm
ld hello,clib/l/gXMAIN /x
del hello.rel
del hello.asm
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
main()
{
printf("\nHello world !\n");
fprintf(stdout,"ਢ¥â ¬¨à !\n");
// fprintf(stderr,"ਢ¥â ¬¨à !\n");
}
+15
View File
@@ -0,0 +1,15 @@
#include <conio.h>
#include <dos.h>
union REGS inregs, outregs;
void main()
{
/* á«¥¤ãî騥 ®¯¥à â®àë ¢ë¡¨à îâ ⥪ãéãî ¤ âã,
¨á¯®«ì§ãï ¢ë§®¢ ä㭪樨 DOS 21h. */
inregs.h.c = 0x21;
intdos(&inregs, &outregs);
cprintf("date is %02d/%02d/%04d\n", outregs.h.d,
outregs.h.e,
outregs.x.ix);
}
+19
View File
@@ -0,0 +1,19 @@
#include <stdio.h>
#include <io.h>
FD fd;
f_point *pos;
void main()
{
fd=open("test.txt", O_RDONLY);
pos->high = 0;
pos->low = 10;
if((pos=lseek(fd, pos->high, pos->low, SEEK_SET)) == -1)
printf("Žè¨¡ª  ¯¥à¥¬¥é¥­¨ï\n");
printf("\n%04X %04X", pos->high, pos->low);
close(fd);
}
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <io.h>
FD fd;
f_point *pos;
void main()
{
fd=open("test.txt", O_RDONLY);
pos->high = 0;
pos->low = 10;
if((lseek(fd, pos->high, pos->low, SEEK_SET)) == -1)
printf("Žè¨¡ª  ¯¥à¥¬¥é¥­¨ï\n");
pos=ltell(fd);
printf("\n%04X %04X", pos->high, pos->low);
close(fd);
}
+601
View File
@@ -0,0 +1,601 @@
/**************************************************************
lzhuf.c
written by Haruyasu Yoshizaki 11/20/1988
some minor changes 4/6/1989
comments translated by Haruhiko Okumura 4/7/1989
MSX-C PROFI adaptation by MaxWolf, Aug-Sep 1992
EOF bugfix 1st April 1993
Š®¬¯¨«ïæ¨ï:
cc1 -m -c lzh3.c
cc2 lzh3
**************************************************************/
#define EOF (-1)
int getc(), putc();
char encount(), deinc(), decount(), memmove();
#pragma nonrec
/********** LZSS compression *************/
#define N 4096 /* à §¬¥à ¡ãä¥à  */
#define F 60 /* ¯à¥¤¢ à¨â¥«ì­ë© à §¬¥à ¡ãä¥à  */
#define THRESHOLD 2
#define NIL N /* «¨áâ ¤¥à¥¢  */
extern char text_buf[N + F - 1];
static int matchposition, matchlength;
extern int lson[N + 1], rson[N + 257], dad[N + 1];
/* ¨­¨æ¨ «¨§ æ¨ï ¤¥à¥¢ (¥¢) */
static int InitTree()
{
int *i, n;
for(i = &rson[N + 1], n = 256; n--;)
*i++ = NIL; /* ª®à¥­ì */
for(i = dad, n = N; n--;)
*i++ = NIL; /* ã§¥« */
}
/* § ­¥á⨠(¢áâ ¢¨âì) ¢ ¤¥à¥¢® */
static int InsertNode(r)
int r;
{
int i, p, cmp;
char *key;
unsigned c;
cmp = 1;
key = &text_buf[r];
p = N + 1 + (int)key[0];
rson[r] = lson[r] = NIL;
matchlength = 0;
for (;;) {
if (cmp >= 0) {
if (rson[p] != NIL)
p = rson[p];
else {
rson[p] = r;
goto i1;
}
} else {
if (lson[p] != NIL)
p = lson[p];
else {
lson[p] = r;
i1: dad[r] = p;
return;
}
}
for (i = 1; i < F; i++)
if ((cmp = (int)key[i] - (int)text_buf[p + i]) != 0)
break;
if (i > THRESHOLD) {
if (i > matchlength) {
matchposition = ((r - p) & (N - 1)) - 1;
if ((matchlength = i) >= F)
break;
}
if (i == matchlength) {
if ((c = ((r - p) & (N - 1)) - 1) < matchposition) {
matchposition = c;
}
}
}
}
dad[r] = dad[p];
dad[ lson[r] = lson[p] ] = r;
dad[ rson[r] = rson[p] ] = r;
if (rson[ i = dad[p] ] == p)
rson[i] = r;
else
lson[i] = r;
dad[p] = NIL; /* 㤠«¨âì p */
}
/* 㤠«¨âì ¨§ ¤¥à¥¢  */
static int DeleteNode(p) int p;
{
int q, i;
if (dad[p] == NIL)
return; /* not registered */
if (rson[p] == NIL)
q = lson[p];
else
if (lson[p] == NIL)
q = rson[p];
else {
q = lson[p];
if (rson[q] != NIL) {
do {
q = rson[q];
} while (rson[q] != NIL);
dad[ rson[dad[q]] = lson[q] ] = dad[q];
;
dad[ lson[q] = lson[p] ] = q;
}
dad[ rson[q] = rson[p] ] = q;
}
if (rson[ i = dad[q] = dad[p] ] == p)
rson[i] = q;
else
lson[i] = q;
dad[p] = NIL;
}
/* Š®¤¨à®¢ ­¨¥ • ä䬠­  */
#define N_CHAR (256 - THRESHOLD + F)
/* kinds of characters (character code = 0..N_CHAR-1) */
#define T (N_CHAR * 2 - 1) /* à §¬¥à â ¡«¨æë */
#define R (T - 1) /* ¯®§¨æ¨ï ª®à­ï */
#define MAX_FREQ 0x8000 /* updates tree when the */
/* root frequency comes to this value */
typedef char uchar;
/* ’ ¡«¨æë ª®¤¨à®¢ ­¨ï ¨ ¤¥ª®¤¨à®¢ ­¨ï 6-⨠¢¥àå­¨å (upper) ¡¨â ¯®§¨æ¨¨ */
/* ¤«ï ª®¤¨à®¢ ­¨ï */
static uchar p_len[64] = {
0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
};
static uchar p_code[64] = {
0x00, 0x20, 0x30, 0x40, 0x50, 0x58, 0x60, 0x68,
0x70, 0x78, 0x80, 0x88, 0x90, 0x94, 0x98, 0x9C,
0xA0, 0xA4, 0xA8, 0xAC, 0xB0, 0xB4, 0xB8, 0xBC,
0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE,
0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE,
0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEA, 0xEC, 0xEE,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
/* ¤«ï ¤¥ª®¤¨à®¢ ­¨ï */
static uchar d_code[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A,
0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B,
0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D,
0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F,
0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11,
0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13,
0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15,
0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17,
0x18, 0x18, 0x19, 0x19, 0x1A, 0x1A, 0x1B, 0x1B,
0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
0x20, 0x20, 0x21, 0x21, 0x22, 0x22, 0x23, 0x23,
0x24, 0x24, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27,
0x28, 0x28, 0x29, 0x29, 0x2A, 0x2A, 0x2B, 0x2B,
0x2C, 0x2C, 0x2D, 0x2D, 0x2E, 0x2E, 0x2F, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
};
static uchar d_len[256] = {
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
};
extern unsigned freq[T + 1]; /* â ¡«¨æ  ç áâ®âë */
extern int prnt[T + N_CHAR]; /* pointers to parent nodes, except for the */
/* elements [T..T + N_CHAR - 1] which are used to get */
/* the positions of leaves corresponding to the codes. */
extern int son[T]; /* pointers to child nodes (son[], son[] + 1) */
static unsigned getbuf;
static uchar getlen;
#define GetBit() _GetBit((char)0)
#define GetByte() _GetBit((char)1)
/* ¯®«ãç¨âì ®¤¨­/¢®á¥¬ì ¡¨â */
/* get one/eight bit(s) */
static int _GetBit(f)
char f;
{
unsigned i;
while (getlen <= 8) {
if ((int)(i = getc()) == EOF) break; /* i = 0; */
getbuf |= i << (8 - getlen);
getlen += 8;
}
i = getbuf;
if (f) {
getbuf <<= 8;
getlen -= 8;
return i >> 8;
} else {
getbuf <<= 1;
--getlen;
return ((int)i < 0);
}
}
/*int GetByte()
{
unsigned i;
while (getlen <= 8) {
if ((i = getc()) == EOF) i = 0;
getbuf |= i << (8 - getlen);
getlen += 8;
}
i = getbuf;
getbuf <<= 8;
getlen -= 8;
return i >> 8;
}*/
static unsigned putbuf;
static uchar putlen;
static int Putcode(l,c) int l;unsigned c; /* output c bits of code */
{
putbuf |= c >> putlen;
if ((putlen += l) >= 8) {
putc(putbuf >> 8);
if ((putlen -= 8) >= 8) {
putc(putbuf);
putlen -= 8;
putbuf = c << (l - putlen);
} else {
putbuf <<= 8;
}
}
}
/* initialization of tree */
static int StartHuff()
{
int i, j;
for (i = 0; i < N_CHAR; i++) {
freq[i] = 1;
son[i] = i + T;
prnt[i + T] = i;
}
i = 0; j = N_CHAR;
while (j <= R) {
freq[j] = freq[i] + freq[i + 1];
son[j] = i;
prnt[i] = prnt[i + 1] = j;
i += 2; j++;
}
freq[T] = 0xFFFF;
prnt[R] = 0;
}
/* reconstruction of tree */
static int reconst()
{
int i, j, k;
unsigned f, l;
/* collect leaf nodes in the first half of the table */
/* and replace the freq by (freq + 1) / 2. */
j = 0;
for (i = 0; i < T; i++) {
if (son[i] >= T) {
freq[j] = (freq[i] + 1) / 2;
son[j] = son[i];
j++;
}
}
/* begin constructing tree by connecting sons */
for (i = 0, j = N_CHAR; j < T; i += 2, j++) {
k = i + 1;
f = freq[j] = freq[i] + freq[k];
for (k = j - 1; f < freq[k]; k--);
k++;
l = (j - k) * 2;
memmove(&freq[k + 1], &freq[k], l);
freq[k] = f;
memmove(&son[k + 1], &son[k], l);
son[k] = i;
}
/* connect prnt */
for (i = 0; i < T; i++) {
if ((k = son[i]) >= T) {
prnt[k] = i;
} else {
prnt[k] = prnt[k + 1] = i;
}
}
}
/* increment frequency of given code by one, and update tree */
static int update(c) int c;
{
int i, j, k, l;
if (freq[R] == MAX_FREQ) {
reconst();
}
c = prnt[c + T];
do {
k = ++freq[c];
/* if the order is disturbed, exchange nodes */
if (k > freq[l = c + 1]) {
while (k > freq[++l]);
l--;
freq[c] = freq[l];
freq[l] = k;
i = son[c];
prnt[i] = l;
if (i < T) prnt[i + 1] = l;
j = son[l];
son[l] = i;
prnt[j] = c;
if (j < T) prnt[j + 1] = c;
son[c] = j;
c = l;
}
} while ((c = prnt[c]) != 0); /* repeat up to root */
}
static EncodeChar(c) unsigned c;
{
unsigned i;
int j, k;
#ifdef DEBUG
printf("char[%x]\n",c);
#endif
i = j = 0;
k = prnt[c + T];
/* travel from leaf to root */
do {
i >>= 1;
/* if node's address is odd-numbered, choose bigger brother node */
if (k & 1) i += 0x8000;
j++;
} while ((k = prnt[k]) != R);
Putcode(j, i);
update(c);
}
static EncodePosition(c) unsigned c;
{
unsigned i;
#ifdef DEBUG
printf("pos[%x]\n",c);
#endif
/* output upper 6 bits by table lookup */
i = c >> 6;
Putcode((int)p_len[i], (unsigned)p_code[i] << 8);
/* output lower 6 bits verbatim */
Putcode(6, (c & 0x3f) << 10);
}
static EncodeEnd()
{
if (putlen) {
putc(putbuf >> 8);
}
}
static int DecodeChar()
{
unsigned c;
c = son[R];
/* travel from root to leaf, */
/* choosing the smaller child node (son[]) if the read bit is 0, */
/* the bigger (son[]+1} if 1 */
while (c < T) {
c += GetBit();
c = son[c];
}
c -= T;
update(c);
#ifdef DEBUG
printf("char[%x]\n",c);
#endif
return c;
}
static int DecodePosition()
{
unsigned i, j, c;
/* recover upper 6 bits from table */
i = GetByte();
c = (unsigned)d_code[i] << 6;
j = d_len[i] - 2;
/* read lower 6 bits verbatim */
while (j--) {
i = (i << 1) + GetBit();
}
c |= (i & 0x3F);
#ifdef DEBUG
printf("pos[%x]\n",c);
#endif
return c;
}
/*-- “¯ ª®¢ª / á¯ ª®¢ª  --*/
/* “¯ ª®¢ª  */
char Encode()
{
int i, c, len, r, s, last_matchlength;
StartHuff();
InitTree();
putbuf = putlen = 0;
s = 0;
r = N - F;
for (i = s; i < r; i++)
text_buf[i] = ' ';
for (len = 0; len < F && (c = getc()) != EOF; len++)
text_buf[r + len] = c;
encount(len);
for (i = 1; i <= F; i++)
InsertNode(r - i);
InsertNode(r);
do {
if (matchlength > len)
matchlength = len;
if (matchlength <= THRESHOLD) {
matchlength = 1;
EncodeChar((int)text_buf[r]);
} else {
EncodeChar(255 - THRESHOLD + matchlength);
EncodePosition(matchposition);
}
last_matchlength = matchlength;
for (i = 0; i < last_matchlength &&
(c = getc()) != EOF; i++) {
DeleteNode(s);
text_buf[s] = c;
if (s < F - 1)
text_buf[s + N] = c;
s = (s + 1) & (N - 1);
r = (r + 1) & (N - 1);
InsertNode(r);
}
encount(i);
while (i++ < last_matchlength) {
DeleteNode(s);
s = (s + 1) & (N - 1);
r = (r + 1) & (N - 1);
if (--len) InsertNode(r);
}
} while (len > 0);
EncodeEnd();
}
/*  á¯ ª®¢ª  */
char Decode()
{
int i, j, k, r, c;
StartHuff();
getbuf = getlen = 0;
for (i = 0; i < N - F; i++)
text_buf[i] = ' ';
r = N - F;
while (decount() || getlen) {
c = DecodeChar();
if (c < 256) {
putc(c);
text_buf[r++] = c;
r &= (N - 1);
deinc();
} else {
i = (r - DecodePosition() - 1) & (N - 1);
j = c - 255 + THRESHOLD;
for (k = 0; k < j; k++) {
c = text_buf[(i + k) & (N - 1)];
putc(c);
text_buf[r++] = c;
r &= (N - 1);
deinc();
}
}
}
}
+19
View File
@@ -0,0 +1,19 @@
#include <conio.h>
#include <mouse.h>
MSSTAT *p;
void main()
{
initMouse();
showMouse();
while(!kbhit())
{
p = getStatMouse();
cprintf("BUTTON: %d Col: %02d Line: %02d\r",
(char *)p->button,
(char *)p->x,
(char *)p->y);
}
}
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <mouse.h>
void main()
{
MSSENS *p;
p = getSensMouse();
printf("X: %x Y: %x\n", (char*)p->xsens, (char *)p->ysens);
p->xsens = 2;
p->ysens = 3;
setSensMouse(p);
p = getSensMouse();
printf("X: %x Y: %x\n", (char*)p->xsens, (char *)p->ysens);
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <mouse.h>
void main()
{
MSSENS *p;
p->xsens = 2;
p->ysens = 3;
setSensMouse(p);
p = getSensMouse();
printf("X: %x Y: %x\n", (char*)p->xsens, (char *)p->ysens);
}
+12
View File
@@ -0,0 +1,12 @@
#include <io.h>
FD fd;
void main()
{
fd = open("test.txt", O_RDONLY);
if(fd == -1)
perror("open failed on input file");
else
close(fd);
}
+8
View File
@@ -0,0 +1,8 @@
#include <stdio.h>
int num = 0x07D4;
void main()
{
printf("Year: %d\n",num);
}
+1
View File
@@ -0,0 +1 @@
ਬ¥ΰλ ¨α―®«μ§®Ά ­¨ο ­¥®β®ΰλε δγ­ζ¨©.
+15
View File
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <io.h>
FD fd;
uint pos,i;
void main()
{
fd=open("test.txt", O_RDONLY);
i = 10;
if((pos=seek(fd, i, SEEK_SET)) == -1)
printf("Žè¨¡ª  ¯¥à¥¬¥é¥­¨ï\n");
printf("\n%04X",pos);
close(fd);
}
+7
View File
@@ -0,0 +1,7 @@
@echo off
cc1 -m sort2.c
cc2 sort2.tmc
as sort2.asm
ld sort2,clib/l/gXMAIN /x
del sort2.rel
del sort2.asm
+393
View File
@@ -0,0 +1,393 @@
/*
MM> ®á¬®âà¨â¥, ¯«¨§ ã ᥡï, ¬®¦¥â ã ª®£®-­¨âì ¥áâì ®¯¨á ­¨¥ ¬¥â®¤®¢
MM> á®àâ¨à®¢ª¨ (quick sort, buble sort, ŠŒ ¨ â.¤.). ˆå â ¬ ¯à¨¬¥à­® 6
MM> ¥áâì. ˆ­â¥à¥áãîâ ¨¬¬¥­®  «£®à¨â¬ë á ®¯¨á ­¨¥¬, ª®â®àë¥ ï ¨á¯®«ì§ãî
MM> ¯®â®¬ ¤«ï ªãàᮢ®© à ¡®âë. Ѝ­â¥ ¬­¥, ¯¦ «áâ , ¨«¨ ¯®¤¥«¨â¥áì url¨ª®¬.
MM> ‘¯ á¨¡®!
EI> ޝ¨è¨â¥ c ¯p¨¬¥p ¬¨ ­  ¯ cª «¥, ¯®¦ «ã©câ , ®c­®¢­ë¥ ¬¥â®¤ë
EI> c®pâ¨p®¢ª¨,
EI> 祬 ¡®«ìè¥ â¥¬ «ãçè¥, ¢c¥¬ § p ­¥¥ ®£p®¬­®¥ c¯ c¨¡®«
H . H® ­  C (â ¬ ­  ᪮«ìª® ï ¯®­ï« £« ¢­®¥  «£®à¨â¬ë ­ã¦­ë). Ÿ ¯¨á « ¨
ª®¬¯¨«¨« ¯®¤ BC3.1. ।áâ ¢«ï¥â ᮡ®© ¯à®£ã ¯® á¡®àã áâ â¨á⨪¨ íä䥪⨢-
­®á⨠ «£®à¨â¬®¢.
à®èã ¯®ªà¨â¨ª®¢ âì :) (å®âï ®¯ïâì ¦¥ á ¡¦ ¡ë« ­  ¯¥à¢®¬ ªãàá¥).
----------------
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define SIZE 15
/* Prototypes */
void Binsort();
void Choise();
void Include();
void Bubble();
void Quick();
void Shell();
void Join();
void Prn();
void Test();
unsigned ITERATION, // Š®«¨ç¥á⢮ ¯à®©¤¥­ëå æ¨ª«®¢
EXCHANGES, // ®¡¬¥­®¢ ï祥ª
CONDITIONS; // ¯à®©¤¥­ëå ãá«®¢¨©
int Mass[SIZE];
int i, NumElem;
char key;
/* ÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞÞ */
int main()
{
NumElem = sizeof(Mass) / sizeof(Mass[0]);
clrscr();
do {
for(i=0; i < NumElem; i++) Mass[i] = rand() % 100 - 50;
clrscr();
puts("Œ¥­î:\n");
puts(" 1. ‘®àâ¨à®¢ª  ®¡¬¥­ ¬¨ (¬¥â®¤ ¯ã§ëà쪠)");
puts(" 2. ‘®àâ¨à®¢ª  ¢ë¡®à®¬");
puts(" 3. ‘®àâ¨à®¢ª  ¯à®áâ묨 ¢áâ ¢ª ¬¨");
puts(" 4. ‘®àâ¨à®¢ª  ¡¨­ à­ë¬¨ ¢áâ ¢ª ¬¨ (¢áâ ¢ª  ¤¥«¥­¨¥¬ ¯®¯®« ¬)");
puts(" 5. ‘®àâ¨à®¢ª  ¬¥â®¤®¬ ˜¥«« ");
puts(" 6. ‘®àâ¨à®¢ª  ¡ëáâàë¬ ¬¥â®¤®¬\n");
puts(" 7. ‘«¨ï­¨¥ á®àâ¨à®¢ ­­ëå ¬ áᨢ®¢");
puts(" 8. ’¥áâ ­  ¯à®¨§¢®¤¨â¥«ì­®áâì\n");
puts(" ESC. ‚ë室\n\n->");
if ((key=getch()) == 27)
goto done;
clrscr();
if (key >= '0' && key <= '6')
{
cprintf("\nŒ áᨢ (®à¨£¨­ «):");
Prn(Mass, NumElem);
}
ITERATION=EXCHANGES=CONDITIONS=0;
switch(key)
{
case '1': Bubble(Mass, NumElem); break;
case '2': Choise(Mass, NumElem); break;
case '3': Include(Mass, NumElem); break;
case '4': Binsort(Mass, NumElem); break;
case '5': Shell(Mass, NumElem); break;
case '6': Quick(Mass, 0, NumElem); break;
case '7': Join(); continue;
case '8': Test(Mass, NumElem); continue;
default : continue;
}
cprintf("\n(á®àâ¨à®¢ ­­ë©):");
Prn(Mass, NumElem);
cprintf("\n\n\nਠá®àâ¨à®¢ª¥ ¯®âॡ®¢ «®áì ¨â¥à æ¨©: %d\n",ITERATION);
cprintf(" ¯à®¨§¢¥¤¥­® ®¡¬¥­®¢ ï祥ª: %d\n",EXCHANGES);
cprintf(" ¯à®©¤¥­® ãá«®¢¨©: %d\n",CONDITIONS);
puts("\n\n\nAny key...");
getch();
} while(1);
done:
puts("\n\nSee you... ;)");
return 0;
}
/*.......................................................................*/
void Prn(PtrMass, count)
int *PtrMass, count;
{
int i;
cprintf("\n[");
for (i=0; i < count; i++)
cprintf(" %3d", PtrMass[i]);
puts("]");
}
/*.......................................................................*/
void Test(PtrMass, count)
int *PtrMass, count;
{
uint ITERATION1, EXCHANGES1, CONDITIONS1, ITERATION2,
EXCHANGES2, CONDITIONS2, ITERATION3, EXCHANGES3,
CONDITIONS3, ITERATION4, EXCHANGES4, CONDITIONS4,
ITERATION5, EXCHANGES5, CONDITIONS5, i, j;
ITERATION1=EXCHANGES1=CONDITIONS1=ITERATION2=EXCHANGES2=CONDITIONS2=0;
ITERATION3=EXCHANGES3=CONDITIONS3=ITERATION4=EXCHANGES4=CONDITIONS4=0;
ITERATION5=EXCHANGES5=CONDITIONS5=0;
clrscr();
puts("‘®àâ¨à®¢ª  ®¡¬¥­ ¬¨: ¯à®©¤¥­ëå æ¨ª«®¢ =");
puts(" ®¡¬¥­®¢ ï祩ª ¬¨ =");
puts(" ¯®áâ ¢«¥­­ëå ãá«®¢¨© =\n");
puts("‘®àâ¨à®¢ª  ¢ë¡®à®¬: ¯à®©¤¥­ëå æ¨ª«®¢ =");
puts(" ®¡¬¥­®¢ ï祩ª ¬¨ =");
puts(" ¯®áâ ¢«¥­­ëå ãá«®¢¨© =\n");
puts("‘®àâ¨à®¢ª  ¯à®áâ묨 ¢áâ ¢ª ¬¨: ¯à®©¤¥­ëå æ¨ª«®¢ =");
puts(" ®¡¬¥­®¢ ï祩ª ¬¨ =");
puts(" ¯®áâ ¢«¥­­ëå ãá«®¢¨© =\n");
puts("‘®àâ¨à®¢ª  ¡¨­ à­ë¬¨ ¢áâ ¢ª ¬¨: ¯à®©¤¥­ëå æ¨ª«®¢ =");
puts(" ®¡¬¥­®¢ ï祩ª ¬¨ =");
puts(" ¯®áâ ¢«¥­­ëå ãá«®¢¨© =\n");
puts("‘®àâ¨à®¢ª  ¬¥â®¤®¬ ˜¥«« : ¯à®©¤¥­ëå æ¨ª«®¢ =");
puts(" ®¡¬¥­®¢ ï祩ª ¬¨ =");
puts(" ¯®áâ ¢«¥­­ëå ãá«®¢¨© =\n");
puts("‘®àâ¨à®¢ª  ¡ëáâàë¬ ¬¥â®¤®¬: ¯à®©¤¥­ëå æ¨ª«®¢ =");
puts(" ®¡¬¥­®¢ ï祩ª ¬¨ =");
puts(" ¯®áâ ¢«¥­­ëå ãá«®¢¨© =");
for(j=1; j <= 100; j++)
{
ITERATION=EXCHANGES=CONDITIONS=0;
for (i=0; i < count; i++) PtrMass[i] = rand() % 100 - 50;
Bubble(PtrMass ,count);
ITERATION1+=ITERATION; EXCHANGES1+=EXCHANGES; CONDITIONS1+=CONDITIONS;
gotoxy(52,1); cprintf("%d ",ITERATION1/j);
gotoxy(52,2); cprintf("%d ",EXCHANGES1/j);
gotoxy(52,3); cprintf("%d ",CONDITIONS1/j);
ITERATION=EXCHANGES=CONDITIONS=0;
for (i=0; i < count; i++) PtrMass[i] = rand() % 100 - 50;
Choise(PtrMass ,count);
ITERATION2+=ITERATION; EXCHANGES2+=EXCHANGES; CONDITIONS2+=CONDITIONS;
gotoxy(52,5); cprintf("%d ",ITERATION2/j);
gotoxy(52,6); cprintf("%d ",EXCHANGES2/j);
gotoxy(52,7); cprintf("%d ",CONDITIONS2/j);
ITERATION=EXCHANGES=CONDITIONS=0;
for (i=0; i < count; i++) PtrMass[i] = rand() % 100 - 50;
Include(PtrMass ,count);
ITERATION3+=ITERATION; EXCHANGES3+=EXCHANGES; CONDITIONS3+=CONDITIONS;
gotoxy(52,9); cprintf("%d ",ITERATION3/j);
gotoxy(52,10); cprintf("%d ",EXCHANGES3/j);
gotoxy(52,11); cprintf("%d ",CONDITIONS3/j);
ITERATION=EXCHANGES=CONDITIONS=0;
for (i=0; i < count; i++) PtrMass[i] = rand() % 100 - 50;
Binsort(PtrMass ,count);
ITERATION4+=ITERATION; EXCHANGES4+=EXCHANGES; CONDITIONS4+=CONDITIONS;
gotoxy(52,13); cprintf("%d ",ITERATION4/j);
gotoxy(52,14); cprintf("%d ",EXCHANGES4/j);
gotoxy(52,15); cprintf("%d ",CONDITIONS4/j);
ITERATION=EXCHANGES=CONDITIONS=0;
for (i=0; i < count; i++) PtrMass[i] = rand() % 100 - 50;
Shell(PtrMass ,count);
ITERATION5+=ITERATION; EXCHANGES5+=EXCHANGES; CONDITIONS5+=CONDITIONS;
gotoxy(52,17); cprintf("%d ",ITERATION5/j);
gotoxy(52,18); cprintf("%d ",EXCHANGES5/j);
gotoxy(52,19); cprintf("%d ",CONDITIONS5/j);
ITERATION=EXCHANGES=CONDITIONS=0;
for (i=0; i < count; i++) PtrMass[i] = rand() % 100 - 50;
Quick(PtrMass , 0, count);
ITERATION5+=ITERATION; EXCHANGES5+=EXCHANGES; CONDITIONS5+=CONDITIONS;
gotoxy(52,21); cprintf("%d ",ITERATION5/j);
gotoxy(52,22); cprintf("%d ",EXCHANGES5/j);
gotoxy(52,23); cprintf("%d ",CONDITIONS5/j);
}
puts("\n\n\nOk...");
getch();
}
/*.......................................................................*/
void Include(PtrMass, count)
int *PtrMass, count;
{
int i, j, temp;
for (i=1; i< count; ++i)
{
temp=PtrMass[i];
for (j=i-1; j>=0 && temp<PtrMass[j]; j--)
{
ITERATION++;
EXCHANGES++;
PtrMass[j+1]=PtrMass[j];
}
ITERATION++;
PtrMass[j+1]=temp;
}
ITERATION -= count-1;
}
/*.......................................................................*/
void Binsort(PtrMass, count)
int *PtrMass, count;
{
int i, j, pos, a, b, middle, num;
for (i=1; i < count; i++)
{
a=0; /* H¨¦­ïï £à ­¨æ  ¯®¨áª  = 1-¬ã í«-âã */
b=i; /* ‚¥àå­ïï = á® 2 ¯® count */
EXCHANGES++;
num=PtrMass[i]; /* —¨á«® ¤«ï ª®â. ­ã¦­® ­ ©â¨ ¬¥áâ® */
while ( a!=b ) /* ...¯®ª  £à ­¨æë ­¥ ᫨«¨áì... */
{
middle=(a+b)/2; /* –¥« ï ç áâì áà. à¨ä¬. áã¬¬ë £à ­¨æ */
if (num > PtrMass[middle]) /* ..¥á«¨ ç¨á«® >ç¨á«  áâ®ïé.¯®¤ */
{ /* ­®¬¥à®¬ middle â®: */
a=middle+1; /* ­¨¦. £à ­. = 業âàã+1 */
} /* */
else /* ¨«¨ */
{ /* */
b = middle; /* ¢¥àå­ïï £à ­¨æ  = 業âàã... */
}
CONDITIONS++;
ITERATION++;
}
pos=a; /* ‘®¤¥à¦¨â ­ ©¤¥­­ãî ¯®§¨æ¨î ­  ª®â. */
/* ­ã¦­® ¯®áâ ¢¨âì ç¨á«® */
for (j=i; j > pos; j--)
{ /* ®¤¢¨£ ¥¬ (­  1 ¢¯à ¢®) í«-âë */
PtrMass[j]=PtrMass[j-1]; /* ¬ áᨢ  «¥¦ é¨¥ ¯¥à¥¤ í«¥¬¥­â®¬, */
EXCHANGES++;
ITERATION++; /* ¤«ï ª®â®à®£® ¨é¥âáï ¬¥áâ® ®á¢®- */
} /* ¡®¦¤ ï 1 ¬¥áâ® */
PtrMass[pos]=num; /* “áâ ­ ¢«¨¢ ¥¬ í«¥¬¥­â ­  ¬¥áâ® */
}
}
/*.......................................................................*/
void Bubble(PtrMass, count)
int *PtrMass, count;
{
int i,j;
for (i=0; i<count; i++)
for (j=i+1; j<count; j++)
{
if (PtrMass[i] > PtrMass[j])
{
PtrMass[i]+=PtrMass[j];
PtrMass[j]= PtrMass[i] - PtrMass[j];
PtrMass[i]-=PtrMass[j];
EXCHANGES++;
CONDITIONS++;
}
ITERATION++;
}
}
/*.......................................................................*/
void Choise(PtrMass, count)
int *PtrMass, count;
{
int i,j;
for (i=0; i<count; i++)
for (j=0; j<count-1; j++)
{
if(PtrMass[j]>PtrMass[j+1])
{
PtrMass[j]+=PtrMass[j+1];
PtrMass[j+1]=PtrMass[j]-PtrMass[j+1];
PtrMass[j]-=PtrMass[j+1];
EXCHANGES++;
CONDITIONS++;
}
ITERATION++;
}
}
int A[]={-1,1,2,3,3}, B[]={-2,0,2,4,4};
/*.......................................................................*/
/* ‘«¨ï­¨¥ ¤¢ãå ®âá®àâ¨à®¢ ­­ëå ¢¥ªâ®à®¢ ¢ ®¤¨­ */
void Join()
{
int C[10], i,j,k;
for (i=j=k=0; k < 10; k++)
{
if (A[i] <= B[j])
{ C[k]=A[i]; i++; }
else
{ C[k]=B[j]; j++; }
}
cprintf("\nŒ áᨢ A[]:");
Prn(A, sizeof(A) / sizeof(A[0]));
cprintf("\nŒ áᨢ B[]:");
Prn(B, sizeof(B) / sizeof(B[0]));
cprintf("\nŒ áᨢ C[]:");
Prn(C, sizeof(C) / sizeof(C[0]));
puts("\n\n\nAny key...");
getch();
}
int aa[]={9,5,3,2,1};
/*.......................................................................*/
void Shell(PtrMass, count)
int *PtrMass, count;
{
int i, j, gap, k, x;
for(k=0; k < 5; k++)
{
gap = aa[k];
for(i=gap; i < count; ++i)
{
x=PtrMass[i];
for(j=i-gap; x < PtrMass[j] && j >= 0; j = j-gap)
{
PtrMass[j+gap]=PtrMass[j];
ITERATION++;
EXCHANGES++;
}
PtrMass[j+gap]=x;
}
}
}
/*.......................................................................*/
void Quick(PtrMass, left, right)
int *PtrMass, left, right;
{
int x, y, i, j;
i = left;
j = right;
x = PtrMass[(left+right) / 2];
do {
while(PtrMass[i] < x && i < right) { i++; ITERATION++; }
while(x < PtrMass[j] && j > left) { j--; ITERATION++; }
if(i <= j)
{
y=PtrMass[i];
PtrMass[i]=PtrMass[j];
PtrMass[j]=y;
i++;
j--;
EXCHANGES++;
CONDITIONS++;
}
} while(i <= j);
if(left < j) Quick(PtrMass,left,j);
if(i < right) Quick(PtrMass,i,right);
}
+9
View File
@@ -0,0 +1,9 @@
#include <stdio.h>
char buffer[20];
char *s = "computer";
void main()
{
sprintf(buffer,"%s",s);
}
+16
View File
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <io.h>
FD fd;
uint pos,i;
void main()
{
fd=open("test.txt", O_RDONLY);
i = 10;
if((seek(fd, i, SEEK_SET)) == -1)
printf("Žè¨¡ª  ¯¥à¥¬¥é¥­¨ï\n");
pos=tell(fd);
printf("\n%04X",pos);
close(fd);
}