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

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