home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_06_08 / v6n8010a.txt < prev    next >
Text File  |  1989-09-28  |  6KB  |  209 lines

  1. Listing one:
  2.  
  3.     menu = menu_Open();
  4.  
  5.      /* This are simply outputs to the screen */
  6.     menu_Printf(menu, "@p[3,0]Customer data");
  7.     menu_Printf(menu, "@p[5,0]Last name:");
  8.     menu_Printf(menu, "@p[7,0]Phone number:");
  9.     menu_Printf(menu, "@p[7,43]Date of birth:");
  10.     menu_Printf(menu, "@p[12,0]Item purchased:");
  11.     menu_Printf(menu, "@p[14,0]Unit cost:");
  12.  
  13.  
  14.      /* These are the field functions */
  15.     menu_Printf(menu, "@p[5,11]@fd[@[17,#]]",
  16.       lname, &string_funcs, "The customer's last name");
  17.     menu_Printf(menu, "@p[7,14]@fd[(###) ###-####]",
  18.       phone, &digit_funcs, "The customer's phone number");
  19.     menu_Printf(menu, "@p[7,58]@fd[##/##/##]",
  20.       &dob, &date_funcs, "The customer's date of birth (MM/DD/YY)");
  21.     menu_Printf(menu, "@p[12,16]@fd[@[16,#]]",
  22.       &item, &select_funcs, 
  23.           "The item purchased (press space bar to change)");
  24.     menu_Printf(menu, "@p[14,16]@fd2[@[9,#]]",
  25.       &amount, &cmoney_funcs, "The unit cost of the item", "(0,)");
  26.     menu_Printf(menu, "@p[19,62]@fp[####]",
  27.       &pnum, &int_funcs);
  28.     menu_Flush(menu);
  29.  
  30.         /* This opens a window using the fields in menu */
  31.     sed = sed_Open(menu);
  32.  
  33.         /* This does the actual input */
  34.     sed_Go(sed);
  35.  
  36.     menu_Close(menu);
  37.     sed_Close(sed);
  38.  
  39.  
  40.  
  41.      #include <dos.h>
  42.  
  43.      int int86(interrupt, in_regs, out_regs)
  44.      int interrupt;           /* Interrupt number */
  45.      union REGS *in_regs;     /* Values to set registers to */
  46.      union REGS *out_regs;    /* Values returned from interrupt 
  47.  
  48.                                  function */
  49.  
  50.  
  51.  
  52. struct sregs
  53.     {
  54.     int ax, bx, cx, dx, si, di, ds, es;
  55.     };
  56. struct sregs reg;
  57.  
  58. #define PRINT_SCREEN_INT 0X5
  59.  
  60. print_screen()
  61.     {
  62.     sysint(PRINT_SCREEN_INT, ®, ®);
  63.     }
  64.  
  65.      ret                 ; return
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.      struct Symbol {
  73.           char *name;     /* Name of the symbol */
  74.           short type;     /* Type:
  75.                             VAR  (variable names)
  76.  
  77.                             BLTIN (built-in function)
  78.                             UNDEF (a variable without a value)
  79.                           */
  80.           union {
  81.               double val;    /* Value , if type == VAR */
  82.               double (*ptr); /* Pointer to function, if type == BLTIN*/         
  83.               }  u;
  84.          struct Symbol *next; /* Pointer to next link */
  85.          };
  86.  
  87.           Init() is a function that adds the built-in 
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.      struct {                      /*  Constant symbols */
  95.           char *name;              /*  Name of symbol */
  96.           double cval;             /*  Value */
  97.           } consts[] = {
  98.                    {"PI", 3.14159265358979323846},
  99.                    {"E",  2.71828182845904523536},
  100.                    {0, 0},         /* End of list */
  101.                    };
  102.  
  103.      struct {                      /* Built in functions */
  104.           char *name;              /* Name of function */
  105.           double (*func)()         /* Pointer to function */
  106.           } builtins[] = {
  107.                     { "sin", sin},
  108.                     {"sqrt", sqrt},
  109.                     {0, 0},        /* End oflist */
  110.                     }; 
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.      init()
  118.           {
  119.           int i;
  120.           struct Symbol *s;
  121.  
  122.           /* Install the constants */
  123.           for (i = 0; consts[i].name; i++)
  124.                     {
  125.                     install(consts[i].name, VAR, consts[i].cval);
  126.                     }
  127.  
  128.           /* Install the functions */
  129.           for (i = 0; builtins[i].name; i++)
  130.                     {
  131.                     s = install(builtins[i].name, BLTIN, 0.0);
  132.                     s->u.ptr = builtins[i].func;
  133.                     }
  134.           }
  135.   
  136.  
  137.  
  138.  
  139.  
  140.  
  141.      struct Symbol *install(s, t, d)
  142.      char *s;       /* Symbol name */
  143.      int t;         /* Type (VAR, BLTIN) */
  144.      double d;      /* Value of Symbol */
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.      #include <stdio.h>
  152.      FILE *file;              /* File to read */
  153.      int no_of_names;         /* Number of names to read */     
  154.      int i;                        
  155.      int *count;              /* Will be array of values read */
  156.  
  157.      file = fopen ("FILENAME","rb");
  158.      fread(&no_of_names, sizeof(int), 1, file);
  159.  
  160.      /* Allocate the necessary space */
  161.      count = calloc(no_of_names, sizeof(int));
  162.  
  163.      /* Read the values       */
  164.      for (i = 0; i < no_of_names; i++)
  165.           {
  166.           fread(&count[i], sizeof(int), 1, file);
  167.           }
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.      #include <stdio.h>
  175.      FILE *file;              /* File to read */
  176.      int no_of_names;         /* Number of names to read */     
  177.      int i;
  178.      char *strings;           /* Will be array of pointers to 
  179.                                  string that were read  */     
  180.      char *ret;               /* For return value from fgets
  181.                                  should be checked for NULL (EOF)*/     
  182.      int length;              /* Length of string */
  183.  
  184.      #define MAX_STRING 256   /* Maximum size for a string */
  185.  
  186.      char string_buffer[MAX_STRING];    /* Buffer for strings */
  187.  
  188.      /* Get the count */
  189.      file = fopen ("FILENAME","r");
  190.      ret = fgets(string_buffer,MAX_STRING,file);
  191.      fscanf(string_buffer,"%d",&no_of_names);
  192.  
  193.      /* Allocate a array of pointers */
  194.  
  195.      strings = calloc(no_of_names, sizeof(char *));
  196.  
  197.      /* Read each string */
  198.      for (i = 0; i < no_of_names; i++)
  199.           {
  200.           ret = fgets(string_buffer,MAX_STRING,file);
  201.  
  202.           /* Determine length, allocate for that much and copy  it */
  203.           length = strlen(string_buffer);
  204.           strings[i] = calloc(length + 1, 1);
  205.           strcpy(strings[i], string_buffer);
  206.           }
  207.  
  208.  
  209.