home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 137_01 / env.c < prev    next >
Text File  |  1985-03-10  |  2KB  |  79 lines

  1. /*
  2.     env.c                created: 25-Mar-84
  3.  
  4.     This package echoes the environment to the standard output.
  5.  
  6.     example of using long pointers with lsup package.
  7.  
  8.     This is set-up to work with Aztec C.
  9.  
  10.     by Anthony Skjellum. (C) 1984. All rights reserved.
  11.     Released for non-commercial purposes only.
  12.  
  13.     This program echoes the environment block to the console.
  14.     In effect, this is the same as the DOS 2.0 SET command.
  15.     Nevertheless, it illustrates the usefulness of long pointers.
  16.  
  17.     ---------------------------------------------
  18.  
  19.     The following changes were made to the $begin
  20.     routine of the Aztec C 1.05i module calldos.asm:
  21.  
  22.         i) a new global variable called envseg was created
  23.  
  24.             envseg_ segment word common 'data'
  25.             $envdat dw 0
  26.             $envseg dw ?
  27.             envseg_ ends
  28.  
  29.         ii) On entry to $begin, when es contains the 
  30.             program segment prefix (PSP), es:[2ch] contains
  31.             the segment address of the environment.  This
  32.             segment address is stored into the second word
  33.             of envseg_ (ie $envseg).
  34.  
  35.             The environment may now be referred to through
  36.             the external LPTR envseg.
  37.  
  38.            iii) If DOS 2.0 allocation is to be used, be sure to
  39.             shrink the program size using the SETBLOCK function.
  40.             This must also be done in $begin where the psp,
  41.             ds, segments are both available.
  42.  
  43. */
  44.  
  45. #include <stdio.h>
  46. #include "lsup.h"    /* support for long pointers */
  47.  
  48. extern    LPTR envseg;    /* envseg is a structure of type LPTR */
  49.  
  50. main(argc,argv)
  51. int argc;
  52. char *argv[];
  53. {
  54.     char chr;
  55.     int i;
  56.     LPTR lptr;
  57.  
  58.     lassign(lptr,envseg); /* get long pointer to environment */
  59.  
  60.     while(1)    /* loop */
  61.     {
  62.         chr = lchr(&lptr);    /* get the next byte */
  63.  
  64.         if(!chr) /* we have hit the end of the environment */
  65.             break;
  66.  
  67.         while((chr = lchr(&lptr))) /* get characters of string */
  68.         {
  69.             putchar(chr);     /* write them to console */
  70.             linc(&lptr);     /* increment pointer */
  71.         }
  72.  
  73.         linc(&lptr);    /* pass the zero byte just encountered */
  74.  
  75.         putchar('\n');  /* add new line between entries */
  76.  
  77.     } /* end while(1) */
  78.  
  79. }