home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 1.ddi / MWHC.001 / 6 < prev    next >
Encoding:
Text File  |  1992-03-02  |  32.1 KB  |  1,373 lines

  1. /*  Copyright (C) 1990 MetaWare Incorporated; All Rights Reserved. 90-Aug-07  */
  2.  
  3. /**** name=_inline ****/
  4. #define main() TEST__inline()
  5. #include <stdio.h>
  6. #define CLI _inline(0xfa)
  7. #define STI _inline(0xfb)
  8. int semafore;
  9.  
  10. void main() {
  11.    CLI;                                  /* Disable interrupts.          */
  12.    semafore++;                           /* Protect for reentrant usage. */
  13.    STI;                                  /* Enable interrupts.           */
  14.    puts("Multi-tasking semafore is set.");
  15.    }
  16. /* End _inline  */
  17. #undef main
  18. #undef  CLI
  19. #undef  STI
  20. /**** name=_int86 ****/
  21. #define main() TEST__int86()
  22.  
  23. /*
  24.    Display all 256 character codes in normal, bold, and blink modes.
  25. */
  26.  
  27. #include <dos.h>
  28. void main() {
  29.    int   j, k, l, m;
  30.    union REGS r;
  31.  
  32.    l = 0;
  33.    for (m = 0; m < 2; m++) {
  34.       for (k = 0; k < 4; k++) {
  35.          for (j = 0; j < 64; j++) {
  36.             r.h.ah = 2;
  37.             r.h.bh = 0;
  38.             r.h.dh = k + m + m + m + m;
  39.             r.h.dl = j;
  40.             _int86(16, &r, &r);
  41.             r.h.ah = 9;
  42.             r.h.al = l++;
  43.             r.h.bh = 0;
  44.             r.h.bl = 128 + j + m * 128;
  45.             r.x.cx = 1;
  46.             _int86(16, &r, &r);
  47.             }
  48.          }
  49.       }
  50.    }
  51.  
  52. /* End _int86  */
  53. #undef main
  54. /**** name=_int86x ****/
  55. #define main() TEST__int86x()
  56.  
  57. #include <stdio.h>
  58. #include <dos.h>
  59.  
  60. void main() {
  61.    union  REGS r;
  62.    struct SREGS s;
  63.    /* Call is as documented in                                           */
  64.    /*  The MS-DOS Encyclopedia on page 1242,                             */
  65.    /*  interrupt 21h function 0x1C.                                      */
  66.    r.h.ah = 0x1c;
  67.    r.l.dl = 0;
  68.    segread(&s);
  69.    /*   intdosx(&r, &r, &s);                                             */
  70.    _int86x(0x21, &r, &r, &s);
  71.    printf("Number of sectors per cluster is"
  72.           " %d\n", r.l.al);
  73.    printf("Number of bytes per sector is"
  74.           " %d\n", r.x.cx);
  75.    printf("Number of clusters is"
  76.           " %d\n", r.x.dx);
  77.    printf("Address of file allocation table is"
  78.           " %x:%x\n", s.ds, r.x.bx);
  79.    }
  80.  
  81. /* End _int86x  */
  82. #undef main
  83. /**** name=_intdos ****/
  84. #define main() TEST__intdos()
  85.  
  86. #include <dos.h>
  87. #include <stdio.h>
  88.  
  89. void main() {
  90.    union REGS r;
  91.  
  92.    r.h.ah = 0x33;
  93.    r.l.al = 0;
  94.    _intdos(&r, &r);
  95.    printf("The Control-C flag was ");
  96.    if (r.l.dl != 0)
  97.       printf("on.\n");
  98.    else {
  99.       printf("off.\n");
  100.       r.h.ah = 0x33;
  101.       r.l.al = 1;
  102.       r.l.dl = 1;
  103.       _intdos(&r, &r);
  104.       if (r.l.al != 255)
  105.           printf("The Control-C flag is now on!\n");
  106.       }
  107.    }
  108.  
  109. /* End _intdos  */
  110. #undef main
  111. /**** name=isalnum ****/
  112. #define main() TEST_isalnum()
  113.  
  114. #include <stdio.h>
  115. #include <ctype.h>
  116. #define True (1)
  117. #define False (0)
  118.  
  119. void main() {
  120.  
  121.    puts("Testing isalnum...\n");
  122.    if ((isalnum('A')) > 0)
  123.       puts("A is alphanumeric.");
  124.    else puts("A is not alphanumeric.");
  125.  
  126.    if ((isalnum('6')) > 0)
  127.       puts("6 is alphanumeric.");
  128.    else puts("6 is not alphanumeric.");
  129.  
  130.    if ((isalnum('o')) > 0)
  131.       puts("o is alphanumeric.");
  132.    else puts("o is not alphanumeric.");
  133.  
  134.    if ((isalnum('!')) > 0)
  135.       puts("! alphanumeric.");
  136.    else puts("! is not alphanumeric.");
  137.    }
  138.  
  139. /* End isalnum  */
  140. #undef main
  141. #undef  True
  142. #undef  False
  143. /**** name=isalpha ****/
  144. #define main() TEST_isalpha()
  145.  
  146. #include <stdio.h>
  147. #include <ctype.h>
  148. #define True  (1)
  149. #define False (0)
  150.  
  151. void main() {
  152.    puts("Testing isalpha...\n");
  153.    if ((isalpha('+')) > 0)
  154.       puts("+ is alphabetical.");
  155.    else puts("+ is not alphabetical.");
  156.    if ((isalpha('A')) > 0)
  157.       puts("A is alphabetical.");
  158.    else puts("A is not alphabetical.");
  159.    if ((isalpha('r')) > 0)
  160.       puts("r is alphabetical.");
  161.    else puts("r is not alphabetical.");
  162.    if ((isalpha('6')) > 0)
  163.       puts("6 is alphabetical.");
  164.    else puts("6 is not alphabetical.");
  165.    }
  166.  
  167. /* End isalpha  */
  168. #undef main
  169. #undef  True
  170. #undef  False
  171. /**** name=_isascii ****/
  172. #define main() TEST__isascii()
  173.  
  174. #include <stdio.h>
  175. #include <ctype.h>
  176. #define True  (1)
  177. #define False (0)
  178.  
  179. void main() {
  180.    puts("Testing _isascii...\n");
  181.    if ((_isascii(128)) > 0)                     /* ASCII codes are 0-127.*/
  182.       puts("128 is ascii.");
  183.    else puts("128 is not ascii.");
  184.  
  185.    if ((_isascii('~')) > 0)
  186.       puts("~ is ascii.");
  187.    else puts("~ is not ascii.");
  188.  
  189.    if ((_isascii('%')) > 0)
  190.       puts("% is ascii.");
  191.    else puts("% is not ascii.");
  192.  
  193.    if ((_isascii(7)) > 0)                     /* 7 is the ASCII for bell.*/
  194.       puts("Bell is ascii.");
  195.    else puts("Bell is not ascii.");
  196.    }
  197.  
  198. /* End _isascii  */
  199. #undef main
  200. #undef  True
  201. #undef  False
  202. /**** name=_isatty ****/
  203. #define main() TEST__isatty()
  204.  
  205. /*
  206.    This program determines if stdout is redirected.
  207. */
  208.  
  209. #include <stdio.h>
  210. #include <io.h>
  211.  
  212. void main() {
  213. /*
  214.       Run  this   program  with  stdout  redirected  and  with  stdout  not
  215.       redirected to observe the different results.
  216. */
  217.  
  218. (_isatty(fileno(stdout))) ?
  219.    puts("stdout is not redirected") :
  220.    puts("stdout is redirected");
  221.    }
  222.  
  223. /* End _isatty  */
  224. #undef main
  225. /**** name=iscntrl ****/
  226. #define main() TEST_iscntrl()
  227.  
  228. #include <stdio.h>
  229. #include <ctype.h>
  230. void main() {
  231.  
  232.    puts("Testing iscntrl...\n");
  233.    int c = 12;
  234.    if ((iscntrl(c)) > 0)
  235.       puts("\\12 is control.");
  236.    else puts("\\12 is not control.");
  237.    c = '$';
  238.    if ((iscntrl(c)) > 0)
  239.       puts("$ is control.");
  240.    else puts("$ is not control.");
  241.    c = 7;
  242.    if ((iscntrl(c)) > 0)
  243.       puts("\\7 is control.");
  244.    else puts("\\7 is not control.");
  245.    c = 'L';
  246.    if ((iscntrl(c)) > 0)
  247.       puts("L is control.");
  248.    else puts("L is not control.");
  249.    }
  250. /* End iscntrl  */
  251. #undef main
  252. /**** name=isgraph ****/
  253. #define main() TEST_isgraph()
  254.  
  255. #include <stdio.h>
  256. #include <ctype.h>
  257.  
  258. void main() {
  259.    int c = 7;
  260.  
  261.    if ((isgraph(c)) > 0)
  262.       puts("Test ok.");
  263.    else puts("Bell is not a printing character");
  264.    c = ']';
  265.    if ((isgraph(c)) > 0)
  266.       puts("Test ok.");
  267.    else puts("] is not a printing character.");
  268.    c = '&';
  269.    if ((isgraph(c)) > 0)
  270.       puts("Test ok.");
  271.    else puts("& is not a printing character.");
  272.    c = ' ';
  273.    if ((isgraph(c)) > 0)
  274.       puts("Test ok.");
  275.    else puts("Space is not a printing character.");
  276.    }
  277.  
  278. /* End isgraph  */
  279. #undef main
  280. /**** name=_isodigit ****/
  281. #define main() TEST__isodigit()
  282.  
  283. #include <stdio.h>
  284. #include <ctype.h>
  285.  
  286. void main() {
  287.    int c;
  288.  
  289.    c = '0';
  290.    if ((_isodigit(c)) > 0)
  291.       puts("0 is octal.");
  292.    else puts("0 is not octal.");
  293.    c = 'a';
  294.    if ((_isodigit(c)) > 0)
  295.       puts("a is octal.");
  296.    else puts("a is not octal.");
  297.    c = '8';
  298.    if ((_isodigit(c)) > 0)
  299.       puts("8 is octal.");
  300.    else puts("8 is not octal.");
  301.    c = '7';
  302.    if ((_isodigit(c)) > 0)
  303.       puts("7 is octal.");
  304.    else puts("7 is not octal.");
  305.    }
  306.  
  307. /* End _isodigit  */
  308. #undef main
  309. /**** name=isprint ****/
  310. #define main() TEST_isprint()
  311.  
  312. #include <stdio.h>
  313. #include <ctype.h>
  314.  
  315. void main() {
  316.    int c;
  317.    
  318.    c = '0';
  319.    if ((isprint(c)) > 0)
  320.       puts("0 is printable.");
  321.    else puts("0 is not printable.");
  322.    c = ' ';
  323.    if ((isprint(c)) > 0)
  324.       puts("space is printable.");
  325.    else puts("space is not printable.");
  326.    c = '~';
  327.    if ((isprint(c)) > 0)
  328.       puts("~ is printable.");
  329.    else puts("~ is not printable.");
  330.    c = '\t';
  331.    if ((isprint(c)) > 0)
  332.       puts("tab is printable.");
  333.    else puts("tab is not printable.");
  334.    c = 'D';
  335.    if ((isprint(c)) > 0)
  336.       puts("D is printable.");
  337.    else puts("D is not printable.");
  338.    }
  339.  
  340. /* End isprint  */
  341. #undef main
  342. /**** name=isxdigit ****/
  343. #define main() TEST_isxdigit()
  344.  
  345. #include <stdio.h>
  346. #include <ctype.h>
  347.  
  348. void main() {
  349.    int c;
  350.    
  351.    puts("Testing isxdigit...\n");
  352.    c = '0';
  353.    if ((isxdigit(c)) > 0)
  354.       puts("0 is hexdigit.");
  355.    else puts("0 is not hexdigit.");
  356.    c = 'g';
  357.    if ((isxdigit(c)) > 0)
  358.       puts("g is hexdigit.");
  359.    else puts("g is not hexdigit.");
  360.    c = 'A';
  361.    if ((isxdigit(c)) > 0)
  362.       puts("A is hexdigit.");
  363.    else puts("A is not hexdigit.");
  364.    c = 'f';
  365.    if ((isxdigit(c)) > 0)
  366.       puts("f is hexdigit.");
  367.    else puts("f is not hexdigit.");
  368.    c = '8';
  369.    if ((isxdigit(c)) > 0)
  370.       puts("8 is hexdigit.");
  371.    else puts("8 is not hexdigit.");
  372.    }
  373.  
  374. /* End isxdigit  */
  375. #undef main
  376. /**** name=_itoa ****/
  377. #define main() TEST__itoa()
  378. #include <stdio.h>
  379. #include <stdlib.h>
  380.  
  381. void main() {
  382.    char s[35],t[35];
  383.    int j;
  384.  
  385.    for (j=1;j != 0;) {                         /* Forever, until zero.   */
  386.       puts("Enter a number (ZERO to quit)");
  387.       gets(s);                                 /* Get a number.          */
  388.       j=atoi(&s[0]);                           /* Convert it to integer. */
  389.       puts(_itoa(j,t,10));                     /* Display it in decimal. */
  390.       puts(t);                                 /* Display it again.      */
  391.       puts(_itoa(j,t,2));                      /* Display it in binary.  */
  392.       puts(_itoa(j,t,16));                     /* Display it in hex.     */
  393.       puts(_itoa(j,t,36));                     /* Display it in base 36. */
  394.       }
  395.    }
  396.  
  397. /* End _itoa  */
  398. #undef main
  399. /**** name=_jX ****/
  400. #define main() TEST__jX()
  401.  
  402. /*
  403.    A program to demonstrate the Bessel functions:
  404.  
  405.       _j0       First kind, power 0.
  406.       _j1       First kind, power 1.
  407.       _jn       First kind, power n.
  408.       _y0       Second kind, power 0.
  409.       _y1       Second kind, power 1.
  410.       _yn       Second kind, power n.
  411. */
  412.  
  413. #include <math.h>
  414. #include <stdio.h>
  415. #include <errno.h>
  416. #include <float.h>
  417.  
  418. void main() {
  419.    double w, x, y, z;
  420.  
  421.    x = 2;
  422.    w = _j1(x);
  423.    y = _j0(x);
  424.    z = _jn(3, x);
  425.    printf("Low values for j, x = 2\n");
  426.    printf("_j0 = %22.18f \n_j1 = %22.18f \n"
  427.           "_jn(3) = %22.18f\n", y, w, z);
  428.    x = 11.5;
  429.    w = _j1(x);
  430.    y = _j0(x);
  431.    z = _jn(11,x);
  432.    printf("Higher values for j, x = 11.5\n");
  433.    printf("_j0 = %22.18f \n_j1 = %22.18f \n"
  434.           "_jn(11) = %22.18f\n", y, w, z);
  435.    x = 2;
  436.    w = _y1(x);
  437.    y = _y0(x);
  438.    z = _yn(3,x);
  439.  
  440.    printf("\nLow values for y, x = 2\n");
  441.    printf("_y0 = %22.18f \n_y1 = %22.18f \n"
  442.           "_yn(3) = %22.18f\n", y, w, z);
  443.  
  444.    x = 11.5;
  445.    w = _y1(x);
  446.    y = _y0(x);
  447.    z = _yn(11,x);
  448.    printf("\nHigher values for y, x = 11.5\n");
  449.    printf("_y0 = %22.18f \n_y1 = %22.18f \n"
  450.           "_yn(11) = %22.18f\n", y, w, z);
  451.    printf("\nNegative value for y\n");
  452.    w = _y0(-1.);
  453.    }
  454.  
  455. /* End _j*  */
  456. #undef main
  457. /**** name=_kbhit ****/
  458. #define main() TEST__kbhit()
  459.  
  460. #include <conio.h>
  461. void main() {
  462.    puts("Testing hardware for a malfunctioning ");
  463.    puts("cheap chip somewhere on the motherboard.  ");
  464.    puts("If this routine is interrupted, the machine ");
  465.    puts("will self-destruct in a cloud of smoke.  ");
  466.    puts("So, please");
  467.    puts("  ***   don't touch the keyboard...  ***\n");
  468.    while (!_kbhit()) ;                                    /* Do nothing. */
  469.    puts("I told you not to touch the keyboard.  ");
  470.    puts("Now your machine will be "
  471.    "\02\04\07\012\014\017\021\025\026\027\021\022\021\023");
  472.    }
  473.  
  474. /* End _kbhit  */
  475. #undef main
  476. /**** name=ldexp ****/
  477. #define main() TEST_ldexp()
  478.  
  479. #include <math.h>
  480. #include <stdio.h>
  481.  
  482. void main() {
  483.    double x = 2.0, result;
  484.    int  exp = 5;
  485.  
  486.    result = ldexp(x , exp);
  487.    printf("x = %.2f, exp = %d,\tResult =>"
  488.           " %.2f\n",x,exp,result);
  489.    x = 3.0;
  490.    exp = -3;
  491.    result = ldexp(x , exp);
  492.    printf("x = %.2f, exp = %d,\tResult =>"
  493.           " %.2f\n",x,exp,result);
  494.    x = 5.0;
  495.    exp = 0;
  496.    result = ldexp(x , exp);
  497.    printf("x = %.2f, exp = %d,\tResult =>"
  498.           " %.2f\n",x,exp,result);
  499.    }
  500.  
  501. /* End ldexp  */
  502. #undef main
  503. /**** name=_lfind_lsearch ****/
  504. #define main() TEST__lfind_lsearch()
  505. #include <search.h>
  506. #include <string.h>
  507. #include <stdio.h>
  508.  
  509. int compr(const char *a, const char *b) {
  510.    return(stricmp(*(char **)a, b));
  511.    }
  512.  
  513. void main() {
  514.    char *data[11] = {"alice",
  515.                      "fred",
  516.                      "frank",
  517.                      "carol",
  518.                      "anne",
  519.                      "larry",
  520.                      "becky"};
  521.    int kount = 7;
  522.    char **answer;
  523.    char *key = "Carol";
  524.  
  525.    answer =
  526.       (char **)_lfind(key, (char *)data,
  527.       &(unsigned)kount, sizeof(char *), compr);
  528.  
  529.    if(answer)
  530.       printf("Found: %s.\n", *answer);
  531.    else
  532.       printf("No match found for %s.\n", key);
  533.    }
  534.  
  535. /* End _lfind, _lsearch  */
  536. #undef main
  537. /**** name=__LINE__ ****/
  538. #define main() TEST___LINE__()
  539.  
  540. /*
  541.    This code is contained in file ttt.c
  542. */
  543.  
  544. #include <stdio.h>
  545.  
  546. void main() {
  547.    printf("Hello from file %s, line %d.\n",
  548.            __FILE__, __LINE__);
  549.    }
  550.  
  551. /* End __LINE__  */
  552. #undef main
  553. /**** name=localeconv ****/
  554. #define main() TEST_localeconv()
  555.  
  556. #include <locale.h>
  557. #include <stdio.h>
  558.  
  559. void main() {
  560.    struct lconv *loc;
  561.  
  562.    puts("Testing localeconv...\n");
  563.    loc = localeconv();
  564.    printf("decimal point =>%s\n",loc->decimal_point);
  565.    printf("thousands sep =>%s\n",loc->thousands_sep);
  566.    printf("currency symbol =>%s\n",loc->currency_symbol);
  567.    }
  568.  
  569. /* End localeconv  */
  570. #undef main
  571. /**** name=localtime ****/
  572. #define main() TEST_localtime()
  573. /* End localtime  */
  574. #undef main
  575. /**** name=_locking ****/
  576. #define main() TEST__locking()
  577.  
  578. #include <io.h>
  579. #include <fcntl.h>
  580. #include <stat.h>
  581. #include <locking.h>
  582. #include <stdio.h>
  583. #include <conio.h>
  584.  
  585. void main() {
  586.    int  pan;
  587.    char c;
  588.  
  589.    pan = open("test.dat",O_RDONLY|O_BINARY);
  590.    if (pan != -1) {
  591.       printf("File test.dat exists,"
  592.              " handle = %d.\n",pan);
  593.       if (0 != _locking(pan,LK_LOCK,50l))
  594.          printf("_locking failed.\n");
  595.       while(read(pan, &c, 1) > 0)
  596.          putch(c);
  597.       lseek(pan, 0l, SEEK_SET);
  598.       if (0 != _locking(pan, LK_UNLCK, 50l))
  599.          printf("Unlocking failed.\n");
  600.       }
  601.    else
  602.       printf("File test.dat cannot be opened,"
  603.              " error code = %d.\n",pan);
  604.    }
  605.  
  606. /* End _locking  */
  607. #undef main
  608. /**** name=log ****/
  609. #define main() TEST_log()
  610.  
  611. #include <math.h>
  612. #include <stdio.h>
  613.  
  614. void main() {
  615.    puts("Testing log...\n");
  616.    printf("log(100.0) = %lf.\n",log(100.0));
  617.    printf("log(10.0) = %lf.\n",log(10.0));
  618.    printf("log(256.1) = %lf.\n",log(256.1));
  619.    printf("log(2.718281828) = %lf.\n",
  620.           log(2.718281828));
  621.    }
  622. /* End log  */
  623. #undef main
  624. /**** name=log10 ****/
  625. #define main() TEST_log10()
  626.  
  627. #include <math.h>
  628. #include <stdio.h>
  629.  
  630. void main() {
  631.    puts("Testing log10...\n");
  632.    printf("log10(100.0) = %lf.\n",log10(100.0));
  633.    printf("log10(10.0) = %lf.\n",log10(10.0));
  634.    printf("log10(256.1) = %lf.\n",log10(256.1));
  635.    printf("log10(2.718281828) = %lf.\n",
  636.           log10(2.718281828));
  637.    }
  638.  
  639. /* End log10  */
  640. #undef main
  641. /**** name=longjmp ****/
  642. #define main() TEST_longjmp()
  643.  
  644. /*
  645.    This example illustrates the use of longjmp and setjmp.
  646. */
  647.  
  648. #include <setjmp.h>
  649. #include <stdio.h>
  650.  
  651. jmp_buf Buf; int loopcnt = 0;
  652. static void loop(j) {
  653.    if (++loopcnt < j)
  654.       loop(j);
  655.    else
  656.       longjmp(Buf,1);
  657.       /* Call to longjmp discards j invocations */
  658.    }  /* of loop() and returns to the switch.   */
  659.  
  660. void main() {
  661.    int j;
  662.    for (j = 1; j <= 10; j++) {
  663.       loopcnt = 0;
  664.       switch(setjmp(Buf)) {
  665.          case 0:  loop(j); break;
  666.          case 1:  printf("%d ",loopcnt); break;
  667.          default: printf("ERROR!");
  668.          }
  669.       }
  670.    }
  671.  
  672. /* End longjmp  */
  673. #undef main
  674. /**** name=_lrotX ****/
  675. #define main() TEST__lrotX()
  676.  
  677. #include <stdlib.h>
  678. #include <stdio.h>
  679.  
  680. void main() {
  681.    long int k1=1;
  682.    long int k7=1;
  683.    long int k8=1;
  684.    long int k9=1;
  685.    long int k15=1;
  686.    long int k17=1;
  687.    printf("Rotate bits left by\n     one        7"
  688.           "        8        9       15       17\n");
  689.    do {
  690.       printf("%8lx %8lx %8lx %8lx %8lx %8lx\n",
  691.                k1,  k7,  k8,  k9,  k15, k17);
  692.       k1=_lrotl(k1,1);
  693.       k7=_lrotl(k7,7);
  694.  
  695.       k8=_lrotl(k8,8);
  696.       k9=_lrotl(k9,9);
  697.       k15=_lrotl(k15,15);
  698.       k17=_lrotl(k17,17);
  699.       } while (k1!=1);
  700.    }
  701.  
  702. /* End _lrot*  */
  703. #undef main
  704. /**** name=_lseek ****/
  705. #define main() TEST__lseek()
  706.  
  707. #include <io.h>
  708. #include <fcntl.h>
  709. #include <sys/stat.h>
  710. #include <stdio.h>
  711. #include <conio.h>
  712.  
  713. void main() {
  714.    char     c;
  715.    int      pan;
  716.    long int k;
  717.  
  718.    pan = open("test.dat", O_RDONLY | O_BINARY);
  719.    if (pan != -1) {
  720.        printf("File test.dat exists,"
  721.               " handle = %d.\n", pan);
  722.       /* Start read before the end of file. */
  723.       k = _lseek(pan, -1l, SEEK_END);
  724.       while ((k = _lseek(pan,--k,SEEK_SET)) != -1l) {
  725.          read(pan, &c, 1);
  726.          printf("%c", c);
  727.          }
  728.       }
  729.    else
  730.       printf("File test.dat cannot be opened,"
  731.              " error code = %d.\n", pan);
  732.    }
  733.  
  734. /* End _lseek  */
  735. #undef main
  736. /**** name=L_tmpnam ****/
  737. #define main() TEST_L_tmpnam()
  738. /* End L_tmpnam  */
  739. #undef main
  740. /**** name=_ltoa ****/
  741. #define main() TEST__ltoa()
  742.  
  743. #include <stdlib.h>
  744. #include <stdio.h>
  745.  
  746. void main() {
  747.    char s[55], t[55];
  748.    long int j;
  749.  
  750.    for(j = 1;j != 0;) {
  751.       puts("Enter a number, (ZERO to quit)");
  752.       gets(s);
  753.       j = atol(s);
  754.       printf("The number you entered is: %ld\n"
  755.              "And in base 10, 10, 2, 16 and 36"
  756.              " it is\n", j);
  757.       puts(_ltoa(j, t, 10));
  758.       puts(t);
  759.  
  760.       puts(_ltoa(j, t, 2));
  761.       puts(_ltoa(j, t, 16));
  762.       puts(_ltoa(j, t, 36));
  763.       }
  764.    }
  765.  
  766. /* End _ltoa  */
  767. #undef main
  768. /**** name=_makepath ****/
  769. #define main() TEST__makepath()
  770.  
  771. /*
  772. This program constructs a full pathname from specified components.
  773. */
  774.  
  775. #include <stdio.h>
  776. #include <stdlib.h>
  777.  
  778. void main() {
  779.    char buffer[67];
  780.    char *drive = "c";
  781.    char *dir   = "highc\\inc";
  782.    char *fname = "stdio";
  783.    char *ext   = "h";
  784.  
  785.    _makepath(buffer, drive, dir, fname, ext);
  786.    printf("Path created with _makepath: %s\n\n",
  787.            buffer);
  788.    }
  789.  
  790. /* End _makepath  */
  791. #undef main
  792. /**** name=malloc ****/
  793. #define main() TEST_malloc()
  794.  
  795. /*
  796.    This example demonstrates that malloc allocates uninitialized storage.
  797. */
  798. #include <stdlib.h>
  799.  
  800. void main() {
  801.    typedef struct {
  802.       char *first, *last;
  803.       } names;
  804.    names *name_ptr = (names *)malloc(sizeof(names));
  805.    if (name_ptr == NULL) printf("Out of Memory!\n");
  806.    else
  807.       /* calloc initializes char to NULL. */
  808.       if (name_ptr->first == NULL)
  809.          printf("calloc was used to allocate space.\n");
  810.       else
  811.          /* malloc does not initialize                                   */
  812.          /*  and the space contains garbage.                             */
  813.          printf("malloc was used to allocate space.\n");
  814.    }
  815.  
  816. /* End malloc  */
  817. #undef main
  818. /**** name=_matherrX ****/
  819. #define main() TEST__matherrX()
  820.  
  821. /*
  822. Makes an erroneous call to _dieeetomsbin() using a large value as the input
  823. argument, causing an error.  The local declaration of _matherr() ensures
  824. fully descriptive exceptions.
  825. */
  826.  
  827. #include <math.h>
  828.  
  829. int _matherr(struct exception *s) {
  830.    return (_matherrx(s));
  831.    }
  832.  
  833. void main() {
  834.    double iput,oput;
  835.  
  836.    iput = 10.0E+100;
  837.    _dieeetomsbin(&iput, &oput);
  838.    }
  839.  
  840. /* End _matherr*  */
  841. #undef main
  842. /**** name=_max_min ****/
  843. #define main() TEST__max_min()
  844.  
  845. /*
  846.    This program tests the min and max functions.
  847. */
  848. float f;
  849. unsigned long ul;
  850. int i;
  851.  
  852. void main() {
  853.    float r1;
  854.    unsigned long r2;
  855.    f=20.0;
  856.    ul=29;
  857.    i=10;
  858.  
  859.    puts("Testing _min & _max...\n");
  860.    printf("Output of _min.\n");
  861.    r1 = _min(f, ul, i);                               /* Has type float. */
  862.    printf("r1 ==> %.1f.\n",r1);
  863.  
  864.    r2 = _min(ul, i);                      /* Has type unsigned long int. */
  865.    printf("r2 ==> %u.\n",r2);
  866.    r1 = _min(i, f);                                   /* Has type float. */
  867.    printf("r1 ==> %.1f.\n\n",r1);
  868.  
  869.    printf("output of _max.\n");
  870.    r1 = _max(f, ul, i);                               /* Has type float. */
  871.    printf("r1 ==> %.1f.\n",r1);
  872.    r2 = _max(ul, i);                      /* Has type unsigned long int. */
  873.    printf("r2 ==> %u.\n",r2);
  874.    r1 = _max(i, f);                                   /* Has type float. */
  875.    printf("r1 ==> %.1f.\n",r1);
  876.    }
  877. /* End _max, _min  */
  878. #undef main
  879. /**** name=_memccpy ****/
  880. #define main() TEST__memccpy()
  881.  
  882. #include <memory.h>
  883. #include <stdio.h>
  884.  
  885. void main() {
  886.    char a[] =
  887.       "This is a test!! of _memccpy - ignore this";
  888.    char x[100] = "this data will disappear";
  889.    char *b;
  890.    char *c;
  891.    b = &x[0];
  892.    c = _memccpy(b, a, '-', 50);
  893.    *(c + 15) = 0;
  894.    c = _memccpy(c, a, '-', 15);
  895.    /*  x[41] = 0;  */
  896.    puts(x);
  897.    }
  898.  
  899. /* End _memccpy  */
  900. #undef main
  901. /**** name=memchr ****/
  902. #define main() TEST_memchr()
  903.  
  904. /*
  905.    This  program uses memchr to find three occurrences of the letter F in a
  906.    string.
  907. */
  908. #include <stdio.h>
  909. #include <string.h>
  910.  
  911. void main() {
  912.    char *target =
  913.    "abcdefgFindMeabcdefghFindMetooabcdefghFindMealsoabc";
  914.    char *result;
  915.    char find = 'F';
  916.  
  917.    result = memchr(target, find, strlen(target));
  918.    printf("%s\n", result);
  919.  
  920.    result = memchr(result+1, find, strlen(result));
  921.    printf("%s\n", result);
  922.  
  923.    result = memchr(result+1, find, strlen(result));
  924.    printf("%s\n", result);
  925.    }
  926.  
  927. /* End memchr  */
  928. #undef main
  929. /**** name=memcmp ****/
  930. #define main() TEST_memcmp()
  931.  
  932. #include <string.h>
  933. #include <stdio.h>
  934.  
  935. void main() {
  936.    char s1[] = "This is testing 1 2 3 4 5";
  937.    char s2[] = "This is testing 1 2 3 4 5 6";
  938.    int res;
  939.    size_t len=0;
  940.  
  941.    puts("Testing memcmp...\n");
  942.    printf("Comparing Strings:\n1: '%s' and\n2:"
  943.           " '%.25s'\n", s1, s2);
  944.    len = strlen(s1);
  945.    res = (memcmp(s1, s2, len));
  946.    if (res == 0)
  947.       printf("s1 is equal to s2.\n\n");
  948.    else if (res < 0)
  949.       printf("s1 is less than s2.\n\n");
  950.  
  951.    
  952.    else
  953.       printf("s1 is greater than s2.\n\n");
  954.    printf("Comparing Strings:\n1: '%s' and\n2:"
  955.           " '%s'\n", s1, s2);
  956.    len = strlen(s2);
  957.    res = (memcmp(s1, s2, len));
  958.    if (res < 0)
  959.       printf("s1 is less than s2.\n\n");
  960.    else if (res > 0)
  961.       printf("s1 is greater than s2.\n\n");
  962.    else
  963.       printf("s1 is equal to s2.\n\n");
  964.    }
  965.  
  966. /* End memcmp  */
  967. #undef main
  968. /**** name=memcpy ****/
  969. #define main() TEST_memcpy()
  970.  
  971. #include <string.h>
  972. #include <stdio.h>
  973.  
  974. void main() {
  975.    char array1[50] =
  976.             "1234567890abcdefghijklmnopqrstuvwxyz";
  977.    char array2[50] =
  978.             "1234567890abcdefghijklmnopqrstuvwxyz";
  979.    char *source1 = &array1[10], *dest1 = array1;
  980.    char *source2 = &array2[10], *dest2 = array2;
  981.    int i;
  982.    memcpy  (dest2, source2, 27);
  983.    _rmemcpy(dest1, source1, 27);
  984.    for (i = 0; i <= 37; i++)
  985.       putchar(array1[i] == '\0'? '@' : array1[i]);
  986.    putchar('\n');
  987.    for (i = 0; i <= 37; i++)
  988.       putchar(array2[i] == '\0'? '@' : array2[i]);
  989.    }
  990.  
  991. /* End memcpy  */
  992. #undef main
  993. /**** name=memicmp ****/
  994. #define main() TEST_memicmp()
  995.  
  996. #include <string.h>
  997. #include <stdio.h>
  998.  
  999. void main() {
  1000.    char a[]  ="tHIS iS a tEST Z1";
  1001.    char b[]  ="This Is A Test z2";
  1002.    char aa[] ="tHIS iS a tEST ZA1";
  1003.    char bb[] ="This Is A Test za2";
  1004.    char c[]  ="[]";
  1005.    char d[]  ="{}";
  1006.    char e[]  ="1234";
  1007.    char f[]  ="5678";
  1008.  
  1009.    if (memicmp(a,b,(size_t)16)==0)
  1010.            puts("memicmp equal test ok");
  1011.       else puts("memicmp equal test failed");
  1012.    if (memicmp(c,d,(size_t)2)==0)
  1013.            puts("memicmp unequal test failed");
  1014.       else puts("memicmp unequal test ok");
  1015.    if (memicmp(e,e,(size_t)4)==0)
  1016.            puts("memicmp equal2 test ok");
  1017.       else puts("memicmp equal2 test failed");
  1018.    if (memicmp(e,f,(size_t)4)==0)
  1019.            puts("memicmp unequal test failed");
  1020.       else puts("memicmp unequal test ok");
  1021.    if (memicmp(a,b,(size_t)17)==0)
  1022.            puts("memicmp equal3 test failed");
  1023.       else puts("memicmp equal3 test ok");
  1024.    if (memicmp(a,b,(size_t)18)==0)
  1025.            puts("memicmp equal4 test failed");
  1026.       else puts("memicmp equal4 test ok");
  1027.    if (memicmp(aa,bb,(size_t)17)==0)
  1028.            puts("memicmp equal5 test ok");
  1029.       else puts("memicmp equal5 test failed");
  1030.    }
  1031.  
  1032. /* End memicmp  */
  1033. #undef main
  1034. /**** name=memset ****/
  1035. #define main() TEST_memset()
  1036.  
  1037. #include <stdio.h>
  1038. #include <string.h>
  1039.  
  1040. void strip (char *s1, char *s2) {
  1041.    int i;
  1042.    while (*s1 != 0) { /* Not the end of s1, so:                          */
  1043.       /*  Set s1 to point at the first character                         */
  1044.       /*   from s1 that is not in s2.                                    */
  1045.       s1 += strspn(s1, s2);
  1046.       /*  Set i to the length of the prefix of s1                        */
  1047.       /*   containing no characters from s2.                             */
  1048.       /*  Write NUL on each such character.                              */
  1049.       memset(s1, 0, i = strcspn(s1, s2));
  1050.       /*  Set s1 to point at the character after                         */
  1051.       /*   the last NUL just written.                                    */
  1052.       s1 += i;
  1053.       }
  1054.    }
  1055.  
  1056. void main() {
  1057.    char *s1 =
  1058.       "Those funny char's are leaving! --->!#$";
  1059.    char *s2 = "Those funny char's are leaving!";
  1060.  
  1061.    puts(s1);
  1062.    strip(s1, s2);
  1063.    puts(s1);
  1064.    }
  1065.  
  1066. /* End memset  */
  1067. #undef main
  1068. /**** name=_mkdir ****/
  1069. #define main() TEST__mkdir()
  1070.  
  1071. /*
  1072.    This program makes a directory.
  1073. */
  1074.  
  1075. #include <stdio.h>
  1076. #include <direct.h>
  1077.  
  1078. void main() {
  1079.    int retdir;
  1080.  
  1081.    retdir = _mkdir("c:\\testdir");
  1082.    if (retdir == -1)
  1083.       perror("error in _mkdir");
  1084.    else
  1085.       printf("directory c:\\testdir successfully"
  1086.              " created.\n");
  1087.    }
  1088.  
  1089. /* End _mkdir  */
  1090. #undef main
  1091. /**** name=_mktemp ****/
  1092. #define main() TEST__mktemp()
  1093.  
  1094. /*
  1095.    This program calls _mktemp to get a unique  file  name,  then  opens the
  1096.    file with a call to fopen.
  1097. */
  1098.  
  1099. #include <stdio.h>
  1100. #include <process.h>
  1101. #include <io.h>
  1102.  
  1103. FILE *stream1, *stream2;
  1104. char *tempname;
  1105.  
  1106. void main() {
  1107.    if ((tempname = _mktemp("myXXXXXX")) == NULL)
  1108.       printf("Couldn't open temp file 1\n");
  1109.    else {
  1110.       stream1 = fopen(tempname, "w");
  1111.       printf("Opened temp file %s\n", tempname);
  1112.  
  1113.       if ((tempname = _mktemp("myXXXXXX")) == NULL)
  1114.          printf("Couldn't open temp file 2\n");
  1115.       else {
  1116.          stream2 = fopen(tempname, "w");
  1117.          printf("Opened temp file %s\n", tempname);
  1118.          }
  1119.       }
  1120.    }
  1121.  
  1122. /* End _mktemp  */
  1123. #undef main
  1124. /**** name=mktime ****/
  1125. #define main() TEST_mktime()
  1126.  
  1127. #include <time.h>
  1128. #include <stdio.h>
  1129.  
  1130. void main() {
  1131.    struct tm p;
  1132.    p.tm_hour = 15;
  1133.    p.tm_min = 10;
  1134.    p.tm_sec = 59;
  1135.    p.tm_mon = 11;
  1136.    p.tm_mday = 23;
  1137.    p.tm_year = 88;
  1138.    p.tm_wday = 3;
  1139.    p.tm_yday = 45;
  1140.    printf("The time is %ld.\n",mktime(&p));
  1141.    }
  1142.  
  1143. /* End mktime  */
  1144. #undef main
  1145. /**** name=modf ****/
  1146. #define main() TEST_modf()
  1147.  
  1148. #include <stdio.h>
  1149. #include <math.h>
  1150.  
  1151. void main() {
  1152.    double x, i;
  1153.  
  1154.    x = modf(2.4, &i);
  1155.    printf("%e %e", x, i);
  1156.    }
  1157.  
  1158. /* End modf  */
  1159. #undef main
  1160. /**** name=_move ****/
  1161. #define main() TEST__move()
  1162.  
  1163. #include <string.h>
  1164. #include <stdio.h>
  1165.  
  1166. void main() {
  1167.    char array1[40] =
  1168.       "                          QRSTUVWXYZ";
  1169.    char array2[40] =
  1170.       "1234567890abcdefghijklmnopqrstuvwxyz";
  1171.    char *dest = &array2[0];
  1172.    char *source = array1;
  1173.    int i;
  1174.  
  1175.     puts("Testing _move...\n");
  1176.    _move  (dest, source, 26);
  1177.    puts("Array 2 is moved into Array 1.");
  1178.    puts("Now Array 1 looks like this:");
  1179.    for (i = 0; i <= 37; i++)
  1180.       putchar(array1[i]);
  1181.    printf("\n");
  1182.    }
  1183.  
  1184. /* End _move  */
  1185. #undef main
  1186. /**** name=_movedata ****/
  1187. #define main() TEST__movedata()
  1188.  
  1189. #include <memory.h>
  1190. void main() {
  1191.    unsigned int scrn;
  1192.  
  1193.    if(sizeof(int) == 2)
  1194.       scrn = 0xb000;
  1195.    else
  1196.       scrn = 0x1c;                                /* 386 protected mode. */
  1197.    _movedata(scrn, 0, scrn, 80 * 24, 80 * 12);
  1198.    }
  1199.  
  1200. /* End _movedata  */
  1201. #undef main
  1202. /**** name=_nfree ****/
  1203. #define main() TEST__nfree()
  1204.  
  1205. #include <stdio.h>
  1206. #include <malloc.h>
  1207.  
  1208. void main() {
  1209.    char *new_array;
  1210.    new_array = _nmalloc (5000 * sizeof(long));
  1211.  
  1212.    if (new_array == NULL) {
  1213.       printf("nfree: Not enough memory"
  1214.              " for 5,000 longs\n");
  1215.       }
  1216.    else {
  1217.       printf("nfree: Allocated 5,000 longs at %x \n",
  1218.              new_array);
  1219.       printf("nfree: Dellocating memory block at %x \n",
  1220.              new_array);
  1221.       _nfree(new_array);
  1222.       }
  1223.    }
  1224.  
  1225. /* End _nfree  */
  1226. #undef main
  1227. /**** name=_nmalloc ****/
  1228. #define main() TEST__nmalloc()
  1229.  
  1230. #include <stdio.h>
  1231. #include <malloc.h>
  1232.  
  1233. void main() {
  1234.    char *new_array;
  1235.  
  1236.    new_array = _nmalloc(15000 * sizeof(long));
  1237.  
  1238.    if (new_array == NULL) {
  1239.       printf("_nmalloc: Not enough memory"
  1240.              " for 15,000 longs\n");
  1241.       new_array = _nmalloc(5000 * sizeof(long));
  1242.  
  1243.       if (new_array == NULL) {
  1244.          printf("_nmalloc: Not enough memory"
  1245.                 " for 5,000 longs.\n");
  1246.          }
  1247.       else {
  1248.          printf("_nmalloc: Allocated 5000 longs"
  1249.                 " at %lx \n", new_array);
  1250.          }
  1251.       }
  1252.    else
  1253.       printf("_nmalloc: Allocated 15,000 longs"
  1254.              " at %lx \n", new_array);
  1255.    }
  1256.  
  1257. /* End _nmalloc  */
  1258. #undef main
  1259.  
  1260. /*****names*****/
  1261.  
  1262. char * names[]={
  1263.    "_inline",
  1264.    "_int86",
  1265.    "_int86x",
  1266.    "_intdos",
  1267.    "isalnum",
  1268.    "isalpha",
  1269.    "_isascii",
  1270.    "_isatty",
  1271.    "iscntrl",
  1272.    "isgraph",
  1273.    "_isodigit",
  1274.    "isprint",
  1275.    "isxdigit",
  1276.    "_itoa",
  1277.    "_jX",
  1278.    "_kbhit",
  1279.    "ldexp",
  1280.    "_lfind_lsearch",
  1281.    "__LINE__",
  1282.    "localeconv",
  1283.    "_locking",
  1284.    "log",
  1285.    "log10",
  1286.    "longjmp",
  1287.    "_lrotX",
  1288.    "_lseek",
  1289.    "_ltoa",
  1290.    "_makepath",
  1291.    "malloc",
  1292.    "_matherrX",
  1293.    "_max_min",
  1294.    "_memccpy",
  1295.    "memchr",
  1296.    "memcmp",
  1297.    "memcpy",
  1298.    "memicmp",
  1299.    "memset",
  1300.    "_mkdir",
  1301.    "_mktemp",
  1302.    "mktime",
  1303.    "modf",
  1304.    "_move",
  1305.    "_movedata",
  1306.    "_nfree",
  1307.    "_nmalloc",
  1308.    "",""};
  1309.    int nextfunum;
  1310. void main() {
  1311.    char ans[90];
  1312.    for (;;) {
  1313.       for (int j=0;j< 45;j++)
  1314.       if (j%3==2) printf("%4d %-21s\n",j+1,names[j]);
  1315.       else printf("%4d %-21s",j+1,names[j]);
  1316.       printf("\n\nPlease enter a number from the above list (enter=%d, exit=0): ",++nextfunum);
  1317.       gets(ans);
  1318.       if (ans[0] != 0) nextfunum=atoi(ans);
  1319.       printf("\n\n\n");
  1320.       switch(nextfunum) {
  1321.          case 0:exit(0);
  1322.          case 1:TEST__inline();break;
  1323.          case 2:TEST__int86();break;
  1324.          case 3:TEST__int86x();break;
  1325.          case 4:TEST__intdos();break;
  1326.          case 5:TEST_isalnum();break;
  1327.          case 6:TEST_isalpha();break;
  1328.          case 7:TEST__isascii();break;
  1329.          case 8:TEST__isatty();break;
  1330.          case 9:TEST_iscntrl();break;
  1331.          case 10:TEST_isgraph();break;
  1332.          case 11:TEST__isodigit();break;
  1333.          case 12:TEST_isprint();break;
  1334.          case 13:TEST_isxdigit();break;
  1335.          case 14:TEST__itoa();break;
  1336.          case 15:TEST__jX();break;
  1337.          case 16:TEST__kbhit();break;
  1338.          case 17:TEST_ldexp();break;
  1339.          case 18:TEST__lfind_lsearch();break;
  1340.          case 19:TEST___LINE__();break;
  1341.          case 20:TEST_localeconv();break;
  1342.          case 21:TEST__locking();break;
  1343.          case 22:TEST_log();break;
  1344.          case 23:TEST_log10();break;
  1345.          case 24:TEST_longjmp();break;
  1346.          case 25:TEST__lrotX();break;
  1347.          case 26:TEST__lseek();break;
  1348.          case 27:TEST__ltoa();break;
  1349.          case 28:TEST__makepath();break;
  1350.          case 29:TEST_malloc();break;
  1351.          case 30:TEST__matherrX();break;
  1352.          case 31:TEST__max_min();break;
  1353.          case 32:TEST__memccpy();break;
  1354.          case 33:TEST_memchr();break;
  1355.          case 34:TEST_memcmp();break;
  1356.          case 35:TEST_memcpy();break;
  1357.          case 36:TEST_memicmp();break;
  1358.          case 37:TEST_memset();break;
  1359.          case 38:TEST__mkdir();break;
  1360.          case 39:TEST__mktemp();break;
  1361.          case 40:TEST_mktime();break;
  1362.          case 41:TEST_modf();break;
  1363.          case 42:TEST__move();break;
  1364.          case 43:TEST__movedata();break;
  1365.          case 44:TEST__nfree();break;
  1366.          case 45:TEST__nmalloc();break;
  1367.          default:printf("I don't recognize that answer\n");nextfunum=-1;break;
  1368.          }
  1369.       printf("\n\npress enter to select another function\n");
  1370.       gets(ans);
  1371.       }
  1372.    }
  1373.