home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / 94 < prev    next >
Encoding:
Text File  |  1992-04-14  |  31.9 KB  |  1,365 lines

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