home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_04 / v7n4022a.txt < prev    next >
Text File  |  1989-02-28  |  4KB  |  194 lines

  1. Listing 1 *******************************
  2.  
  3. #include <stdio.h>
  4.  
  5. main(argc, argv)
  6. int argc;
  7. char *argv[];
  8.    {
  9.    char cmd_str[81];
  10.    if (argc > 1)
  11.        {
  12.        /* Fill in the length byte with the length of variable 
  13.        plus "set" */
  14.  
  15.        cmd_str[0] = (char ) (strlen(argv[1]) + 4);
  16.        strcpy(&cmd_str[1],"SET ");
  17.  
  18.        /* Add the command */
  19.        strcat(&cmd_str[1], argv[1]);
  20.         /* Put on the carriage return */
  21.        cmd_str[cmd_str[0] + 1] = 0X0D; 
  22.  
  23.        /* 
  24.            Call the 0X2E interrupt.
  25.  
  26.            ds:si should point to the string.
  27.  
  28.            The first byte contains the length and 
  29.            excludes the first byte
  30.  
  31.            The byte which follows the command is a carriage 
  32.            return
  33.        */
  34.         int_2e(cmd_str);
  35.        }
  36.    else
  37.        printf("\n Usage:  test  environ_variable=value\n\n No spaces");
  38.    exit(0);
  39.    } 
  40.  
  41. ; This is the assembly language routine for the small model
  42. .model small
  43. .data
  44. save_ss    dw    ?
  45. save_sp dw    ?
  46.  
  47. .code
  48. ;
  49. public _int_2e
  50. _int_2e proc
  51.     push    bp
  52.     mov bp,sp
  53.     push    si
  54.     push    di
  55.     push    ds
  56.     push    es
  57.     mov     ax,DGROUP
  58.     mov        ds,ax
  59.     mov        save_sp,sp
  60.     mov        save_ss,ss
  61.     mov        si,[bp+4]
  62.     int        2eh
  63.     mov        ax,DGROUP
  64.     mov        ds,ax
  65.     cli
  66.     mov        sp,save_sp
  67.     mov        ss,save_ss
  68.     sti
  69.     pop        es
  70.     pop        ds
  71.     pop        di
  72.     pop        si
  73.     pop        bp
  74.     ret
  75. _int_2e    endp
  76. end
  77.  
  78.             
  79. Listing 2 ***********************************
  80.  
  81. /*  This is how you could call the interrupt without assembly */
  82.  
  83. #include <stdio.h>
  84.  
  85. struct sregs
  86.     {
  87.     int ax;
  88.     int bx;
  89.     int cx;
  90.     int dx;
  91.     int si;
  92.     int di;
  93.     int ds;
  94.     int es;
  95.     } ;
  96.  
  97. char cmd_str[81];
  98.  
  99. main(argc, argv)
  100. int argc;
  101. char *argv[];
  102.    {
  103.    struct sregs reg;
  104.    union {
  105.            unsigned long long_number;
  106.            char *pc;
  107.            } u;                /* For picking apart the address */
  108.    if (argc > 1)
  109.        {
  110.        /* Fill in the length byte with the length of variable 
  111.            plus "set" */
  112.  
  113.        cmd_str[0] = (char ) (strlen(argv[1]) + 5);
  114.        strcpy(&cmd_str[1],"SET ");
  115.        /* Add the command */
  116.        strcat(&cmd_str[1], argv[1]);
  117.         /* Put on the carriage return */
  118.        cmd_str[cmd_str[0] + 1] = 0X0D; 
  119.  
  120.        /* 
  121.            Call the 0X2E interrupt.
  122.  
  123.            ds:si should point to the string.
  124.  
  125.            The first byte contains the length and 
  126.            excludes the first byte
  127.  
  128.            The byte which follows the command is a carriage 
  129.            return
  130.        */
  131.  
  132.  
  133.            /* Pick apart the address into segment/offset */
  134.         u.pc = cmd_str;
  135.         reg.ds = u.long_number >> 16;
  136.         reg.si = u.long_number & 0XFFFF;
  137.         reg.es = reg.ds;
  138.         reg.di = reg.di;
  139.  
  140.         sysint(0X2E, ®, ®);
  141.  
  142.        }
  143.    else
  144.        printf("\n Usage:  test  environ_variable=value\n\n No spaces");
  145.    exit(0);
  146.    } 
  147.  
  148.  
  149.  
  150.  
  151.  
  152.        #include <stdio.h>
  153.  
  154.        FILE *file_out;
  155.        FILE *printer;
  156.        FILE *disk_file;
  157.        #define SCREEN 0
  158.        #define PRINTER 1
  159.        #define DISK 2
  160.  
  161.        initialize()
  162.             {
  163.             printer = fopen("PRN","w");                
  164.             disk_file = fopen("TEMP","w");
  165.            ...
  166.            }
  167.  
  168.        switch_output(to_where)
  169.        int to_where;           /* Where to go to */
  170.            {
  171.            switch(to_where)
  172.                {
  173.            case PRINTER:
  174.                file_out = printer;
  175.                break;
  176.            case DISK:
  177.                file_out = disk_file;
  178.                break;
  179.            case SCREEN:
  180.                file_out = stdout;      /* This is the screen */
  181.                break;
  182.                }
  183.            return;
  184.            }
  185.  
  186.        /*  Somewhere in your program */
  187.  
  188.            printf("\n Going to printer");
  189.            switch_output(PRINTER);
  190.                ....
  191.            fprintf(file_out, "Output");
  192.                
  193.  
  194.