home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0090 - 0099 / ibm0090-0099 / ibm0099.tar / ibm0099 / SAMV11-1.ZIP / API / SAMLOGIC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-23  |  4.0 KB  |  198 lines

  1. /*
  2.  * samlogic.c
  3.  *
  4.  * This program takes a callsign from the command line and searches
  5.  * the sam database for a match.  If found the call data is
  6.  * displayed in a 1 line comma delimited format:
  7.  *
  8.  * call,class,first m,last,address,city,state,zip,yearborn,[,county]
  9.  *
  10.  * If /c follows the call then the county is displayed if possible
  11.  *
  12.  * findcall depends on the API to the sam db provided by SAMAPI.EXE.  
  13.  *
  14.  * Any error messagess are 1 line long and start with "***" (in case
  15.  * some other program wants to use the output of this program).
  16.  *
  17.  * to compile with Turbo-C
  18.  *  tcc findcall.c samlib.c
  19.  *
  20.  * Other C compilers can be used, but a "pack structs" option may be
  21.  * required.
  22.  *
  23.  * Copyright 1991 by Tom Thompson, Athens, AL and by RT Systems
  24.  *                   [n4yos]
  25.  */
  26.  
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <dos.h>
  32.  
  33. #include "samapi.h"            /* samapi interface spec */
  34.  
  35. /*
  36.  * functions in samlib.c
  37.  */
  38.  
  39. int LocateSam(void);
  40. int CallSam(int cmd, void far *cmdbuf, void far *rspbuf);
  41.  
  42. /*
  43.  * decls for functions contained here
  44.  */
  45.  
  46. void display_call(datarec_t * d, int wantcty, char *county);
  47.  
  48.  
  49. /*******************
  50.  * main
  51.  *******************
  52.  *
  53.  * in: argv[1] is callsign
  54.  *
  55.  * returns (or exits()) non-zero if error, zero if call found and displayed
  56.  */
  57.  
  58. main(int argc, char *argv[])
  59. {
  60.     int err;
  61.     int wantcty = 0, callarg;
  62.     cmdfindcall_t sam_in;    /* buffer for samapi find command */
  63.     rspdatarec_t sam_out;    /* buffer for result of samapi find command */
  64.     cmdfindcounty_t cty_in;    /* buffer for find county command */
  65.     rspfindcounty_t cty_out;    /* buffer for find county response */
  66.  
  67.     /*
  68.      * make sure got arg
  69.      */
  70.  
  71.     if (argc < 2)
  72.     {
  73.         printf("*** No call specified");
  74.         exit(3);
  75.     }
  76.  
  77.     /*
  78.      * make sure the resident code (SAMAPI.EXE)
  79.      * has been installed
  80.      */
  81.  
  82.     if (LocateSam())
  83.     {
  84.         printf("*** SAMAPI not loaded\n");
  85.         exit(2);
  86.     }
  87.  
  88.     /*
  89.      * check for county requested
  90.      */
  91.  
  92.     callarg = 1;
  93.     if (argc > 2)
  94.     {
  95.         if (!stricmp(argv[1], "/c"))
  96.         {
  97.             wantcty = 1;
  98.             callarg = 2;
  99.         }
  100.         else if (!stricmp(argv[2], "/c"))
  101.         {
  102.             wantcty = 1;
  103.         }
  104.     }
  105.             
  106.  
  107.     /*
  108.      * build command block and call SAMAPI, function SamFindCall
  109.      */
  110.  
  111.     sam_in.packflags = 0;    /* 0 to unpack all data record fields */
  112.     strncpy(sam_in.call, argv[callarg], 6);
  113.     sam_in.call[6] = 0;
  114.     err = CallSam(SamFindCall, &sam_in, &sam_out);
  115.  
  116.     /*
  117.      * check for unusual error
  118.      * something other that plain ole not found
  119.      */
  120.  
  121.     if (err != 0 && err != SerrNotFound)
  122.     {
  123.         printf("*** SAMAPI error %d\n", err);
  124.         exit(2);
  125.     }
  126.  
  127.     /*
  128.      * check for just not found
  129.      */
  130.  
  131.     if (err == SerrNotFound)
  132.     {
  133.         printf("*** Call not found\n");
  134.         exit(1);
  135.     }
  136.  
  137.  
  138.     /* try to get county if /c option */
  139.     if (wantcty)
  140.     {
  141.         cty_out.county[0] = 0;
  142.         if (sam_out.d.Call[sam_out.d.Call[0] == ' '] != 'V')
  143.         {
  144.             /* it's a US call */
  145.             strcpy(cty_in.zip, sam_out.d.Zip);
  146.             memset(cty_in.reserved, 0, sizeof(cty_in.reserved));
  147.             err = CallSam(SamFindCounty, &cty_in, &cty_out);
  148.             if (err)
  149.                 cty_out.county[0] = 0;
  150.         }
  151.     }
  152.  
  153.     /*
  154.      * got a match, display the call data
  155.      */
  156.  
  157.     display_call(&sam_out.d, wantcty, cty_out.county);
  158.  
  159.     /*
  160.      * exit with 0 for success
  161.      */
  162.     return 0;
  163. }
  164.  
  165. /*******************
  166.  * display_call
  167.  *******************
  168.  *
  169.  * displays call format:
  170.  * call,class,first m,last,address,city,state,zip,yearborn,[,county]
  171.  * county shown only if 
  172.  * input is pointer to data record
  173.  *
  174.  * returns nothing
  175.  */
  176.  
  177. void display_call(datarec_t * d, int wantcty, char *county)
  178. {
  179.     /*
  180.      * display call and class
  181.      */
  182.     printf("%s,%s,", d->Call + (d->Call[0] == ' '), d->Class);
  183.  
  184.     /* display first middle */
  185.     printf("%s", d->FirstName);
  186.     if (d->MidInitial[0] != ' ')
  187.         printf(" %s", d->MidInitial);
  188.     /*
  189.      * display last,addr,city,st,zip,yearborn
  190.      */
  191.     printf(",%s,%s,%s,%s,%s,%s",
  192.                 d->LastName, d->Address, d->City, d->State, d->Zip,
  193.                 d->Dob);
  194.     if (wantcty)
  195.         printf(",%s", county);
  196.     printf("\n");
  197. }
  198.