home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-03-02 | 32.1 KB | 1,373 lines |
- /* Copyright (C) 1990 MetaWare Incorporated; All Rights Reserved. 90-Aug-07 */
-
- /**** name=_inline ****/
- #define main() TEST__inline()
- #include <stdio.h>
- #define CLI _inline(0xfa)
- #define STI _inline(0xfb)
- int semafore;
-
- void main() {
- CLI; /* Disable interrupts. */
- semafore++; /* Protect for reentrant usage. */
- STI; /* Enable interrupts. */
- puts("Multi-tasking semafore is set.");
- }
- /* End _inline */
- #undef main
- #undef CLI
- #undef STI
- /**** name=_int86 ****/
- #define main() TEST__int86()
-
- /*
- Display all 256 character codes in normal, bold, and blink modes.
- */
-
- #include <dos.h>
- void main() {
- int j, k, l, m;
- union REGS r;
-
- l = 0;
- for (m = 0; m < 2; m++) {
- for (k = 0; k < 4; k++) {
- for (j = 0; j < 64; j++) {
- r.h.ah = 2;
- r.h.bh = 0;
- r.h.dh = k + m + m + m + m;
- r.h.dl = j;
- _int86(16, &r, &r);
- r.h.ah = 9;
- r.h.al = l++;
- r.h.bh = 0;
- r.h.bl = 128 + j + m * 128;
- r.x.cx = 1;
- _int86(16, &r, &r);
- }
- }
- }
- }
-
- /* End _int86 */
- #undef main
- /**** name=_int86x ****/
- #define main() TEST__int86x()
-
- #include <stdio.h>
- #include <dos.h>
-
- void main() {
- union REGS r;
- struct SREGS s;
- /* Call is as documented in */
- /* The MS-DOS Encyclopedia on page 1242, */
- /* interrupt 21h function 0x1C. */
- r.h.ah = 0x1c;
- r.l.dl = 0;
- segread(&s);
- /* intdosx(&r, &r, &s); */
- _int86x(0x21, &r, &r, &s);
- printf("Number of sectors per cluster is"
- " %d\n", r.l.al);
- printf("Number of bytes per sector is"
- " %d\n", r.x.cx);
- printf("Number of clusters is"
- " %d\n", r.x.dx);
- printf("Address of file allocation table is"
- " %x:%x\n", s.ds, r.x.bx);
- }
-
- /* End _int86x */
- #undef main
- /**** name=_intdos ****/
- #define main() TEST__intdos()
-
- #include <dos.h>
- #include <stdio.h>
-
- void main() {
- union REGS r;
-
- r.h.ah = 0x33;
- r.l.al = 0;
- _intdos(&r, &r);
- printf("The Control-C flag was ");
- if (r.l.dl != 0)
- printf("on.\n");
- else {
- printf("off.\n");
- r.h.ah = 0x33;
- r.l.al = 1;
- r.l.dl = 1;
- _intdos(&r, &r);
- if (r.l.al != 255)
- printf("The Control-C flag is now on!\n");
- }
- }
-
- /* End _intdos */
- #undef main
- /**** name=isalnum ****/
- #define main() TEST_isalnum()
-
- #include <stdio.h>
- #include <ctype.h>
- #define True (1)
- #define False (0)
-
- void main() {
-
- puts("Testing isalnum...\n");
- if ((isalnum('A')) > 0)
- puts("A is alphanumeric.");
- else puts("A is not alphanumeric.");
-
- if ((isalnum('6')) > 0)
- puts("6 is alphanumeric.");
- else puts("6 is not alphanumeric.");
-
- if ((isalnum('o')) > 0)
- puts("o is alphanumeric.");
- else puts("o is not alphanumeric.");
-
- if ((isalnum('!')) > 0)
- puts("! alphanumeric.");
- else puts("! is not alphanumeric.");
- }
-
- /* End isalnum */
- #undef main
- #undef True
- #undef False
- /**** name=isalpha ****/
- #define main() TEST_isalpha()
-
- #include <stdio.h>
- #include <ctype.h>
- #define True (1)
- #define False (0)
-
- void main() {
- puts("Testing isalpha...\n");
- if ((isalpha('+')) > 0)
- puts("+ is alphabetical.");
- else puts("+ is not alphabetical.");
- if ((isalpha('A')) > 0)
- puts("A is alphabetical.");
- else puts("A is not alphabetical.");
- if ((isalpha('r')) > 0)
- puts("r is alphabetical.");
- else puts("r is not alphabetical.");
- if ((isalpha('6')) > 0)
- puts("6 is alphabetical.");
- else puts("6 is not alphabetical.");
- }
-
- /* End isalpha */
- #undef main
- #undef True
- #undef False
- /**** name=_isascii ****/
- #define main() TEST__isascii()
-
- #include <stdio.h>
- #include <ctype.h>
- #define True (1)
- #define False (0)
-
- void main() {
- puts("Testing _isascii...\n");
- if ((_isascii(128)) > 0) /* ASCII codes are 0-127.*/
- puts("128 is ascii.");
- else puts("128 is not ascii.");
-
- if ((_isascii('~')) > 0)
- puts("~ is ascii.");
- else puts("~ is not ascii.");
-
- if ((_isascii('%')) > 0)
- puts("% is ascii.");
- else puts("% is not ascii.");
-
- if ((_isascii(7)) > 0) /* 7 is the ASCII for bell.*/
- puts("Bell is ascii.");
- else puts("Bell is not ascii.");
- }
-
- /* End _isascii */
- #undef main
- #undef True
- #undef False
- /**** name=_isatty ****/
- #define main() TEST__isatty()
-
- /*
- This program determines if stdout is redirected.
- */
-
- #include <stdio.h>
- #include <io.h>
-
- void main() {
- /*
- Run this program with stdout redirected and with stdout not
- redirected to observe the different results.
- */
-
- (_isatty(fileno(stdout))) ?
- puts("stdout is not redirected") :
- puts("stdout is redirected");
- }
-
- /* End _isatty */
- #undef main
- /**** name=iscntrl ****/
- #define main() TEST_iscntrl()
-
- #include <stdio.h>
- #include <ctype.h>
- void main() {
-
- puts("Testing iscntrl...\n");
- int c = 12;
- if ((iscntrl(c)) > 0)
- puts("\\12 is control.");
- else puts("\\12 is not control.");
- c = '$';
- if ((iscntrl(c)) > 0)
- puts("$ is control.");
- else puts("$ is not control.");
- c = 7;
- if ((iscntrl(c)) > 0)
- puts("\\7 is control.");
- else puts("\\7 is not control.");
- c = 'L';
- if ((iscntrl(c)) > 0)
- puts("L is control.");
- else puts("L is not control.");
- }
- /* End iscntrl */
- #undef main
- /**** name=isgraph ****/
- #define main() TEST_isgraph()
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- int c = 7;
-
- if ((isgraph(c)) > 0)
- puts("Test ok.");
- else puts("Bell is not a printing character");
- c = ']';
- if ((isgraph(c)) > 0)
- puts("Test ok.");
- else puts("] is not a printing character.");
- c = '&';
- if ((isgraph(c)) > 0)
- puts("Test ok.");
- else puts("& is not a printing character.");
- c = ' ';
- if ((isgraph(c)) > 0)
- puts("Test ok.");
- else puts("Space is not a printing character.");
- }
-
- /* End isgraph */
- #undef main
- /**** name=_isodigit ****/
- #define main() TEST__isodigit()
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- int c;
-
- c = '0';
- if ((_isodigit(c)) > 0)
- puts("0 is octal.");
- else puts("0 is not octal.");
- c = 'a';
- if ((_isodigit(c)) > 0)
- puts("a is octal.");
- else puts("a is not octal.");
- c = '8';
- if ((_isodigit(c)) > 0)
- puts("8 is octal.");
- else puts("8 is not octal.");
- c = '7';
- if ((_isodigit(c)) > 0)
- puts("7 is octal.");
- else puts("7 is not octal.");
- }
-
- /* End _isodigit */
- #undef main
- /**** name=isprint ****/
- #define main() TEST_isprint()
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- int c;
-
- c = '0';
- if ((isprint(c)) > 0)
- puts("0 is printable.");
- else puts("0 is not printable.");
- c = ' ';
- if ((isprint(c)) > 0)
- puts("space is printable.");
- else puts("space is not printable.");
- c = '~';
- if ((isprint(c)) > 0)
- puts("~ is printable.");
- else puts("~ is not printable.");
- c = '\t';
- if ((isprint(c)) > 0)
- puts("tab is printable.");
- else puts("tab is not printable.");
- c = 'D';
- if ((isprint(c)) > 0)
- puts("D is printable.");
- else puts("D is not printable.");
- }
-
- /* End isprint */
- #undef main
- /**** name=isxdigit ****/
- #define main() TEST_isxdigit()
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- int c;
-
- puts("Testing isxdigit...\n");
- c = '0';
- if ((isxdigit(c)) > 0)
- puts("0 is hexdigit.");
- else puts("0 is not hexdigit.");
- c = 'g';
- if ((isxdigit(c)) > 0)
- puts("g is hexdigit.");
- else puts("g is not hexdigit.");
- c = 'A';
- if ((isxdigit(c)) > 0)
- puts("A is hexdigit.");
- else puts("A is not hexdigit.");
- c = 'f';
- if ((isxdigit(c)) > 0)
- puts("f is hexdigit.");
- else puts("f is not hexdigit.");
- c = '8';
- if ((isxdigit(c)) > 0)
- puts("8 is hexdigit.");
- else puts("8 is not hexdigit.");
- }
-
- /* End isxdigit */
- #undef main
- /**** name=_itoa ****/
- #define main() TEST__itoa()
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- char s[35],t[35];
- int j;
-
- for (j=1;j != 0;) { /* Forever, until zero. */
- puts("Enter a number (ZERO to quit)");
- gets(s); /* Get a number. */
- j=atoi(&s[0]); /* Convert it to integer. */
- puts(_itoa(j,t,10)); /* Display it in decimal. */
- puts(t); /* Display it again. */
- puts(_itoa(j,t,2)); /* Display it in binary. */
- puts(_itoa(j,t,16)); /* Display it in hex. */
- puts(_itoa(j,t,36)); /* Display it in base 36. */
- }
- }
-
- /* End _itoa */
- #undef main
- /**** name=_jX ****/
- #define main() TEST__jX()
-
- /*
- A program to demonstrate the Bessel functions:
-
- _j0 First kind, power 0.
- _j1 First kind, power 1.
- _jn First kind, power n.
- _y0 Second kind, power 0.
- _y1 Second kind, power 1.
- _yn Second kind, power n.
- */
-
- #include <math.h>
- #include <stdio.h>
- #include <errno.h>
- #include <float.h>
-
- void main() {
- double w, x, y, z;
-
- x = 2;
- w = _j1(x);
- y = _j0(x);
- z = _jn(3, x);
- printf("Low values for j, x = 2\n");
- printf("_j0 = %22.18f \n_j1 = %22.18f \n"
- "_jn(3) = %22.18f\n", y, w, z);
- x = 11.5;
- w = _j1(x);
- y = _j0(x);
- z = _jn(11,x);
- printf("Higher values for j, x = 11.5\n");
- printf("_j0 = %22.18f \n_j1 = %22.18f \n"
- "_jn(11) = %22.18f\n", y, w, z);
- x = 2;
- w = _y1(x);
- y = _y0(x);
- z = _yn(3,x);
-
- printf("\nLow values for y, x = 2\n");
- printf("_y0 = %22.18f \n_y1 = %22.18f \n"
- "_yn(3) = %22.18f\n", y, w, z);
-
- x = 11.5;
- w = _y1(x);
- y = _y0(x);
- z = _yn(11,x);
- printf("\nHigher values for y, x = 11.5\n");
- printf("_y0 = %22.18f \n_y1 = %22.18f \n"
- "_yn(11) = %22.18f\n", y, w, z);
- printf("\nNegative value for y\n");
- w = _y0(-1.);
- }
-
- /* End _j* */
- #undef main
- /**** name=_kbhit ****/
- #define main() TEST__kbhit()
-
- #include <conio.h>
- void main() {
- puts("Testing hardware for a malfunctioning ");
- puts("cheap chip somewhere on the motherboard. ");
- puts("If this routine is interrupted, the machine ");
- puts("will self-destruct in a cloud of smoke. ");
- puts("So, please");
- puts(" *** don't touch the keyboard... ***\n");
- while (!_kbhit()) ; /* Do nothing. */
- puts("I told you not to touch the keyboard. ");
- puts("Now your machine will be "
- "\02\04\07\012\014\017\021\025\026\027\021\022\021\023");
- }
-
- /* End _kbhit */
- #undef main
- /**** name=ldexp ****/
- #define main() TEST_ldexp()
-
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- double x = 2.0, result;
- int exp = 5;
-
- result = ldexp(x , exp);
- printf("x = %.2f, exp = %d,\tResult =>"
- " %.2f\n",x,exp,result);
- x = 3.0;
- exp = -3;
- result = ldexp(x , exp);
- printf("x = %.2f, exp = %d,\tResult =>"
- " %.2f\n",x,exp,result);
- x = 5.0;
- exp = 0;
- result = ldexp(x , exp);
- printf("x = %.2f, exp = %d,\tResult =>"
- " %.2f\n",x,exp,result);
- }
-
- /* End ldexp */
- #undef main
- /**** name=_lfind_lsearch ****/
- #define main() TEST__lfind_lsearch()
- #include <search.h>
- #include <string.h>
- #include <stdio.h>
-
- int compr(const char *a, const char *b) {
- return(stricmp(*(char **)a, b));
- }
-
- void main() {
- char *data[11] = {"alice",
- "fred",
- "frank",
- "carol",
- "anne",
- "larry",
- "becky"};
- int kount = 7;
- char **answer;
- char *key = "Carol";
-
- answer =
- (char **)_lfind(key, (char *)data,
- &(unsigned)kount, sizeof(char *), compr);
-
- if(answer)
- printf("Found: %s.\n", *answer);
- else
- printf("No match found for %s.\n", key);
- }
-
- /* End _lfind, _lsearch */
- #undef main
- /**** name=__LINE__ ****/
- #define main() TEST___LINE__()
-
- /*
- This code is contained in file ttt.c
- */
-
- #include <stdio.h>
-
- void main() {
- printf("Hello from file %s, line %d.\n",
- __FILE__, __LINE__);
- }
-
- /* End __LINE__ */
- #undef main
- /**** name=localeconv ****/
- #define main() TEST_localeconv()
-
- #include <locale.h>
- #include <stdio.h>
-
- void main() {
- struct lconv *loc;
-
- puts("Testing localeconv...\n");
- loc = localeconv();
- printf("decimal point =>%s\n",loc->decimal_point);
- printf("thousands sep =>%s\n",loc->thousands_sep);
- printf("currency symbol =>%s\n",loc->currency_symbol);
- }
-
- /* End localeconv */
- #undef main
- /**** name=localtime ****/
- #define main() TEST_localtime()
- /* End localtime */
- #undef main
- /**** name=_locking ****/
- #define main() TEST__locking()
-
- #include <io.h>
- #include <fcntl.h>
- #include <stat.h>
- #include <locking.h>
- #include <stdio.h>
- #include <conio.h>
-
- void main() {
- int pan;
- char c;
-
- pan = open("test.dat",O_RDONLY|O_BINARY);
- if (pan != -1) {
- printf("File test.dat exists,"
- " handle = %d.\n",pan);
- if (0 != _locking(pan,LK_LOCK,50l))
- printf("_locking failed.\n");
- while(read(pan, &c, 1) > 0)
- putch(c);
- lseek(pan, 0l, SEEK_SET);
- if (0 != _locking(pan, LK_UNLCK, 50l))
- printf("Unlocking failed.\n");
- }
- else
- printf("File test.dat cannot be opened,"
- " error code = %d.\n",pan);
- }
-
- /* End _locking */
- #undef main
- /**** name=log ****/
- #define main() TEST_log()
-
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- puts("Testing log...\n");
- printf("log(100.0) = %lf.\n",log(100.0));
- printf("log(10.0) = %lf.\n",log(10.0));
- printf("log(256.1) = %lf.\n",log(256.1));
- printf("log(2.718281828) = %lf.\n",
- log(2.718281828));
- }
- /* End log */
- #undef main
- /**** name=log10 ****/
- #define main() TEST_log10()
-
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- puts("Testing log10...\n");
- printf("log10(100.0) = %lf.\n",log10(100.0));
- printf("log10(10.0) = %lf.\n",log10(10.0));
- printf("log10(256.1) = %lf.\n",log10(256.1));
- printf("log10(2.718281828) = %lf.\n",
- log10(2.718281828));
- }
-
- /* End log10 */
- #undef main
- /**** name=longjmp ****/
- #define main() TEST_longjmp()
-
- /*
- This example illustrates the use of longjmp and setjmp.
- */
-
- #include <setjmp.h>
- #include <stdio.h>
-
- jmp_buf Buf; int loopcnt = 0;
- static void loop(j) {
- if (++loopcnt < j)
- loop(j);
- else
- longjmp(Buf,1);
- /* Call to longjmp discards j invocations */
- } /* of loop() and returns to the switch. */
-
- void main() {
- int j;
- for (j = 1; j <= 10; j++) {
- loopcnt = 0;
- switch(setjmp(Buf)) {
- case 0: loop(j); break;
- case 1: printf("%d ",loopcnt); break;
- default: printf("ERROR!");
- }
- }
- }
-
- /* End longjmp */
- #undef main
- /**** name=_lrotX ****/
- #define main() TEST__lrotX()
-
- #include <stdlib.h>
- #include <stdio.h>
-
- void main() {
- long int k1=1;
- long int k7=1;
- long int k8=1;
- long int k9=1;
- long int k15=1;
- long int k17=1;
- printf("Rotate bits left by\n one 7"
- " 8 9 15 17\n");
- do {
- printf("%8lx %8lx %8lx %8lx %8lx %8lx\n",
- k1, k7, k8, k9, k15, k17);
- k1=_lrotl(k1,1);
- k7=_lrotl(k7,7);
-
- k8=_lrotl(k8,8);
- k9=_lrotl(k9,9);
- k15=_lrotl(k15,15);
- k17=_lrotl(k17,17);
- } while (k1!=1);
- }
-
- /* End _lrot* */
- #undef main
- /**** name=_lseek ****/
- #define main() TEST__lseek()
-
- #include <io.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <stdio.h>
- #include <conio.h>
-
- void main() {
- char c;
- int pan;
- long int k;
-
- pan = open("test.dat", O_RDONLY | O_BINARY);
- if (pan != -1) {
- printf("File test.dat exists,"
- " handle = %d.\n", pan);
- /* Start read before the end of file. */
- k = _lseek(pan, -1l, SEEK_END);
- while ((k = _lseek(pan,--k,SEEK_SET)) != -1l) {
- read(pan, &c, 1);
- printf("%c", c);
- }
- }
- else
- printf("File test.dat cannot be opened,"
- " error code = %d.\n", pan);
- }
-
- /* End _lseek */
- #undef main
- /**** name=L_tmpnam ****/
- #define main() TEST_L_tmpnam()
- /* End L_tmpnam */
- #undef main
- /**** name=_ltoa ****/
- #define main() TEST__ltoa()
-
- #include <stdlib.h>
- #include <stdio.h>
-
- void main() {
- char s[55], t[55];
- long int j;
-
- for(j = 1;j != 0;) {
- puts("Enter a number, (ZERO to quit)");
- gets(s);
- j = atol(s);
- printf("The number you entered is: %ld\n"
- "And in base 10, 10, 2, 16 and 36"
- " it is\n", j);
- puts(_ltoa(j, t, 10));
- puts(t);
-
- puts(_ltoa(j, t, 2));
- puts(_ltoa(j, t, 16));
- puts(_ltoa(j, t, 36));
- }
- }
-
- /* End _ltoa */
- #undef main
- /**** name=_makepath ****/
- #define main() TEST__makepath()
-
- /*
- This program constructs a full pathname from specified components.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- char buffer[67];
- char *drive = "c";
- char *dir = "highc\\inc";
- char *fname = "stdio";
- char *ext = "h";
-
- _makepath(buffer, drive, dir, fname, ext);
- printf("Path created with _makepath: %s\n\n",
- buffer);
- }
-
- /* End _makepath */
- #undef main
- /**** name=malloc ****/
- #define main() TEST_malloc()
-
- /*
- This example demonstrates that malloc allocates uninitialized storage.
- */
- #include <stdlib.h>
-
- void main() {
- typedef struct {
- char *first, *last;
- } names;
- names *name_ptr = (names *)malloc(sizeof(names));
- if (name_ptr == NULL) printf("Out of Memory!\n");
- else
- /* calloc initializes char to NULL. */
- if (name_ptr->first == NULL)
- printf("calloc was used to allocate space.\n");
- else
- /* malloc does not initialize */
- /* and the space contains garbage. */
- printf("malloc was used to allocate space.\n");
- }
-
- /* End malloc */
- #undef main
- /**** name=_matherrX ****/
- #define main() TEST__matherrX()
-
- /*
- Makes an erroneous call to _dieeetomsbin() using a large value as the input
- argument, causing an error. The local declaration of _matherr() ensures
- fully descriptive exceptions.
- */
-
- #include <math.h>
-
- int _matherr(struct exception *s) {
- return (_matherrx(s));
- }
-
- void main() {
- double iput,oput;
-
- iput = 10.0E+100;
- _dieeetomsbin(&iput, &oput);
- }
-
- /* End _matherr* */
- #undef main
- /**** name=_max_min ****/
- #define main() TEST__max_min()
-
- /*
- This program tests the min and max functions.
- */
- float f;
- unsigned long ul;
- int i;
-
- void main() {
- float r1;
- unsigned long r2;
- f=20.0;
- ul=29;
- i=10;
-
- puts("Testing _min & _max...\n");
- printf("Output of _min.\n");
- r1 = _min(f, ul, i); /* Has type float. */
- printf("r1 ==> %.1f.\n",r1);
-
- r2 = _min(ul, i); /* Has type unsigned long int. */
- printf("r2 ==> %u.\n",r2);
- r1 = _min(i, f); /* Has type float. */
- printf("r1 ==> %.1f.\n\n",r1);
-
- printf("output of _max.\n");
- r1 = _max(f, ul, i); /* Has type float. */
- printf("r1 ==> %.1f.\n",r1);
- r2 = _max(ul, i); /* Has type unsigned long int. */
- printf("r2 ==> %u.\n",r2);
- r1 = _max(i, f); /* Has type float. */
- printf("r1 ==> %.1f.\n",r1);
- }
- /* End _max, _min */
- #undef main
- /**** name=_memccpy ****/
- #define main() TEST__memccpy()
-
- #include <memory.h>
- #include <stdio.h>
-
- void main() {
- char a[] =
- "This is a test!! of _memccpy - ignore this";
- char x[100] = "this data will disappear";
- char *b;
- char *c;
- b = &x[0];
- c = _memccpy(b, a, '-', 50);
- *(c + 15) = 0;
- c = _memccpy(c, a, '-', 15);
- /* x[41] = 0; */
- puts(x);
- }
-
- /* End _memccpy */
- #undef main
- /**** name=memchr ****/
- #define main() TEST_memchr()
-
- /*
- This program uses memchr to find three occurrences of the letter F in a
- string.
- */
- #include <stdio.h>
- #include <string.h>
-
- void main() {
- char *target =
- "abcdefgFindMeabcdefghFindMetooabcdefghFindMealsoabc";
- char *result;
- char find = 'F';
-
- result = memchr(target, find, strlen(target));
- printf("%s\n", result);
-
- result = memchr(result+1, find, strlen(result));
- printf("%s\n", result);
-
- result = memchr(result+1, find, strlen(result));
- printf("%s\n", result);
- }
-
- /* End memchr */
- #undef main
- /**** name=memcmp ****/
- #define main() TEST_memcmp()
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char s1[] = "This is testing 1 2 3 4 5";
- char s2[] = "This is testing 1 2 3 4 5 6";
- int res;
- size_t len=0;
-
- puts("Testing memcmp...\n");
- printf("Comparing Strings:\n1: '%s' and\n2:"
- " '%.25s'\n", s1, s2);
- len = strlen(s1);
- res = (memcmp(s1, s2, len));
- if (res == 0)
- printf("s1 is equal to s2.\n\n");
- else if (res < 0)
- printf("s1 is less than s2.\n\n");
-
-
- else
- printf("s1 is greater than s2.\n\n");
- printf("Comparing Strings:\n1: '%s' and\n2:"
- " '%s'\n", s1, s2);
- len = strlen(s2);
- res = (memcmp(s1, s2, len));
- if (res < 0)
- printf("s1 is less than s2.\n\n");
- else if (res > 0)
- printf("s1 is greater than s2.\n\n");
- else
- printf("s1 is equal to s2.\n\n");
- }
-
- /* End memcmp */
- #undef main
- /**** name=memcpy ****/
- #define main() TEST_memcpy()
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char array1[50] =
- "1234567890abcdefghijklmnopqrstuvwxyz";
- char array2[50] =
- "1234567890abcdefghijklmnopqrstuvwxyz";
- char *source1 = &array1[10], *dest1 = array1;
- char *source2 = &array2[10], *dest2 = array2;
- int i;
- memcpy (dest2, source2, 27);
- _rmemcpy(dest1, source1, 27);
- for (i = 0; i <= 37; i++)
- putchar(array1[i] == '\0'? '@' : array1[i]);
- putchar('\n');
- for (i = 0; i <= 37; i++)
- putchar(array2[i] == '\0'? '@' : array2[i]);
- }
-
- /* End memcpy */
- #undef main
- /**** name=memicmp ****/
- #define main() TEST_memicmp()
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[] ="tHIS iS a tEST Z1";
- char b[] ="This Is A Test z2";
- char aa[] ="tHIS iS a tEST ZA1";
- char bb[] ="This Is A Test za2";
- char c[] ="[]";
- char d[] ="{}";
- char e[] ="1234";
- char f[] ="5678";
-
- if (memicmp(a,b,(size_t)16)==0)
- puts("memicmp equal test ok");
- else puts("memicmp equal test failed");
- if (memicmp(c,d,(size_t)2)==0)
- puts("memicmp unequal test failed");
- else puts("memicmp unequal test ok");
- if (memicmp(e,e,(size_t)4)==0)
- puts("memicmp equal2 test ok");
- else puts("memicmp equal2 test failed");
- if (memicmp(e,f,(size_t)4)==0)
- puts("memicmp unequal test failed");
- else puts("memicmp unequal test ok");
- if (memicmp(a,b,(size_t)17)==0)
- puts("memicmp equal3 test failed");
- else puts("memicmp equal3 test ok");
- if (memicmp(a,b,(size_t)18)==0)
- puts("memicmp equal4 test failed");
- else puts("memicmp equal4 test ok");
- if (memicmp(aa,bb,(size_t)17)==0)
- puts("memicmp equal5 test ok");
- else puts("memicmp equal5 test failed");
- }
-
- /* End memicmp */
- #undef main
- /**** name=memset ****/
- #define main() TEST_memset()
-
- #include <stdio.h>
- #include <string.h>
-
- void strip (char *s1, char *s2) {
- int i;
- while (*s1 != 0) { /* Not the end of s1, so: */
- /* Set s1 to point at the first character */
- /* from s1 that is not in s2. */
- s1 += strspn(s1, s2);
- /* Set i to the length of the prefix of s1 */
- /* containing no characters from s2. */
- /* Write NUL on each such character. */
- memset(s1, 0, i = strcspn(s1, s2));
- /* Set s1 to point at the character after */
- /* the last NUL just written. */
- s1 += i;
- }
- }
-
- void main() {
- char *s1 =
- "Those funny char's are leaving! --->!#$";
- char *s2 = "Those funny char's are leaving!";
-
- puts(s1);
- strip(s1, s2);
- puts(s1);
- }
-
- /* End memset */
- #undef main
- /**** name=_mkdir ****/
- #define main() TEST__mkdir()
-
- /*
- This program makes a directory.
- */
-
- #include <stdio.h>
- #include <direct.h>
-
- void main() {
- int retdir;
-
- retdir = _mkdir("c:\\testdir");
- if (retdir == -1)
- perror("error in _mkdir");
- else
- printf("directory c:\\testdir successfully"
- " created.\n");
- }
-
- /* End _mkdir */
- #undef main
- /**** name=_mktemp ****/
- #define main() TEST__mktemp()
-
- /*
- This program calls _mktemp to get a unique file name, then opens the
- file with a call to fopen.
- */
-
- #include <stdio.h>
- #include <process.h>
- #include <io.h>
-
- FILE *stream1, *stream2;
- char *tempname;
-
- void main() {
- if ((tempname = _mktemp("myXXXXXX")) == NULL)
- printf("Couldn't open temp file 1\n");
- else {
- stream1 = fopen(tempname, "w");
- printf("Opened temp file %s\n", tempname);
-
- if ((tempname = _mktemp("myXXXXXX")) == NULL)
- printf("Couldn't open temp file 2\n");
- else {
- stream2 = fopen(tempname, "w");
- printf("Opened temp file %s\n", tempname);
- }
- }
- }
-
- /* End _mktemp */
- #undef main
- /**** name=mktime ****/
- #define main() TEST_mktime()
-
- #include <time.h>
- #include <stdio.h>
-
- void main() {
- struct tm p;
- p.tm_hour = 15;
- p.tm_min = 10;
- p.tm_sec = 59;
- p.tm_mon = 11;
- p.tm_mday = 23;
- p.tm_year = 88;
- p.tm_wday = 3;
- p.tm_yday = 45;
- printf("The time is %ld.\n",mktime(&p));
- }
-
- /* End mktime */
- #undef main
- /**** name=modf ****/
- #define main() TEST_modf()
-
- #include <stdio.h>
- #include <math.h>
-
- void main() {
- double x, i;
-
- x = modf(2.4, &i);
- printf("%e %e", x, i);
- }
-
- /* End modf */
- #undef main
- /**** name=_move ****/
- #define main() TEST__move()
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char array1[40] =
- " QRSTUVWXYZ";
- char array2[40] =
- "1234567890abcdefghijklmnopqrstuvwxyz";
- char *dest = &array2[0];
- char *source = array1;
- int i;
-
- puts("Testing _move...\n");
- _move (dest, source, 26);
- puts("Array 2 is moved into Array 1.");
- puts("Now Array 1 looks like this:");
- for (i = 0; i <= 37; i++)
- putchar(array1[i]);
- printf("\n");
- }
-
- /* End _move */
- #undef main
- /**** name=_movedata ****/
- #define main() TEST__movedata()
-
- #include <memory.h>
- void main() {
- unsigned int scrn;
-
- if(sizeof(int) == 2)
- scrn = 0xb000;
- else
- scrn = 0x1c; /* 386 protected mode. */
- _movedata(scrn, 0, scrn, 80 * 24, 80 * 12);
- }
-
- /* End _movedata */
- #undef main
- /**** name=_nfree ****/
- #define main() TEST__nfree()
-
- #include <stdio.h>
- #include <malloc.h>
-
- void main() {
- char *new_array;
- new_array = _nmalloc (5000 * sizeof(long));
-
- if (new_array == NULL) {
- printf("nfree: Not enough memory"
- " for 5,000 longs\n");
- }
- else {
- printf("nfree: Allocated 5,000 longs at %x \n",
- new_array);
- printf("nfree: Dellocating memory block at %x \n",
- new_array);
- _nfree(new_array);
- }
- }
-
- /* End _nfree */
- #undef main
- /**** name=_nmalloc ****/
- #define main() TEST__nmalloc()
-
- #include <stdio.h>
- #include <malloc.h>
-
- void main() {
- char *new_array;
-
- new_array = _nmalloc(15000 * sizeof(long));
-
- if (new_array == NULL) {
- printf("_nmalloc: Not enough memory"
- " for 15,000 longs\n");
- new_array = _nmalloc(5000 * sizeof(long));
-
- if (new_array == NULL) {
- printf("_nmalloc: Not enough memory"
- " for 5,000 longs.\n");
- }
- else {
- printf("_nmalloc: Allocated 5000 longs"
- " at %lx \n", new_array);
- }
- }
- else
- printf("_nmalloc: Allocated 15,000 longs"
- " at %lx \n", new_array);
- }
-
- /* End _nmalloc */
- #undef main
-
- /*****names*****/
-
- char * names[]={
- "_inline",
- "_int86",
- "_int86x",
- "_intdos",
- "isalnum",
- "isalpha",
- "_isascii",
- "_isatty",
- "iscntrl",
- "isgraph",
- "_isodigit",
- "isprint",
- "isxdigit",
- "_itoa",
- "_jX",
- "_kbhit",
- "ldexp",
- "_lfind_lsearch",
- "__LINE__",
- "localeconv",
- "_locking",
- "log",
- "log10",
- "longjmp",
- "_lrotX",
- "_lseek",
- "_ltoa",
- "_makepath",
- "malloc",
- "_matherrX",
- "_max_min",
- "_memccpy",
- "memchr",
- "memcmp",
- "memcpy",
- "memicmp",
- "memset",
- "_mkdir",
- "_mktemp",
- "mktime",
- "modf",
- "_move",
- "_movedata",
- "_nfree",
- "_nmalloc",
- "",""};
- int nextfunum;
- void main() {
- char ans[90];
- for (;;) {
- for (int j=0;j< 45;j++)
- if (j%3==2) printf("%4d %-21s\n",j+1,names[j]);
- else printf("%4d %-21s",j+1,names[j]);
- printf("\n\nPlease enter a number from the above list (enter=%d, exit=0): ",++nextfunum);
- gets(ans);
- if (ans[0] != 0) nextfunum=atoi(ans);
- printf("\n\n\n");
- switch(nextfunum) {
- case 0:exit(0);
- case 1:TEST__inline();break;
- case 2:TEST__int86();break;
- case 3:TEST__int86x();break;
- case 4:TEST__intdos();break;
- case 5:TEST_isalnum();break;
- case 6:TEST_isalpha();break;
- case 7:TEST__isascii();break;
- case 8:TEST__isatty();break;
- case 9:TEST_iscntrl();break;
- case 10:TEST_isgraph();break;
- case 11:TEST__isodigit();break;
- case 12:TEST_isprint();break;
- case 13:TEST_isxdigit();break;
- case 14:TEST__itoa();break;
- case 15:TEST__jX();break;
- case 16:TEST__kbhit();break;
- case 17:TEST_ldexp();break;
- case 18:TEST__lfind_lsearch();break;
- case 19:TEST___LINE__();break;
- case 20:TEST_localeconv();break;
- case 21:TEST__locking();break;
- case 22:TEST_log();break;
- case 23:TEST_log10();break;
- case 24:TEST_longjmp();break;
- case 25:TEST__lrotX();break;
- case 26:TEST__lseek();break;
- case 27:TEST__ltoa();break;
- case 28:TEST__makepath();break;
- case 29:TEST_malloc();break;
- case 30:TEST__matherrX();break;
- case 31:TEST__max_min();break;
- case 32:TEST__memccpy();break;
- case 33:TEST_memchr();break;
- case 34:TEST_memcmp();break;
- case 35:TEST_memcpy();break;
- case 36:TEST_memicmp();break;
- case 37:TEST_memset();break;
- case 38:TEST__mkdir();break;
- case 39:TEST__mktemp();break;
- case 40:TEST_mktime();break;
- case 41:TEST_modf();break;
- case 42:TEST__move();break;
- case 43:TEST__movedata();break;
- case 44:TEST__nfree();break;
- case 45:TEST__nmalloc();break;
- default:printf("I don't recognize that answer\n");nextfunum=-1;break;
- }
- printf("\n\npress enter to select another function\n");
- gets(ans);
- }
- }
-