home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_07 / 8n07122a < prev    next >
Text File  |  1990-06-19  |  3KB  |  102 lines

  1. /* Listing 7 */
  2. /*--------------------- PHLIST2.H ----------------------*/
  3. #include "pinlist.h"
  4.  
  5. typedef struct phone_entry {
  6.     char last_name[21], first_name[11], phone_no[14];
  7.  
  8. } PHONE_ENTRY;
  9.  
  10. #define PHONE_LIST_CLASS PINNACLE_LIST_CLASS \
  11.               PHONE_ENTRY pe; \
  12.               DBCOL last, first, phone, lastfirst;
  13.  
  14. typedef struct phone_list {
  15.     PHONE_LIST_CLASS
  16. } PHONE_LIST;
  17.  
  18. PHONE_LIST *new_phone_list();
  19. void destroy_phone_list(PHONE_LIST *);
  20. /*--------------------- PHLIST2.C -----------------------*/
  21. #include "phlist2.h"
  22. #include <string.h>
  23. #include <conio.h>
  24. #include <stdlib.h>
  25.  
  26. static void phone_list_memory_error(char *fun) {
  27. fprintf(stderr,
  28. "\nMemory Error in Function %s <Press a Key>\n", fun);
  29. getch(); exit(1);
  30. }
  31.  
  32. static unsigned find(PHONE_LIST *this, char *srch_l_name) {
  33. DBSEARCH sobj; unsigned found;
  34.  
  35. sobj = DB_SearchObject(this->db, String, srch_l_name, "==");
  36.  
  37. found = DB_FindNext(this->last,sobj,DBNEXT);
  38. DB_Free(sobj);
  39. return(found);
  40. }
  41.  
  42. static display(PHONE_LIST *this) {
  43.     strcpy(this->pe.last_name,DB_GetString(this->last));
  44.     strcpy(this->pe.first_name,DB_GetString(this->first));
  45.     strcpy(this->pe.phone_no,DB_GetString(this->phone));
  46.     printf("%-20s, %-10s  -  %-13s\n",this->pe.last_name,
  47.     this->pe.first_name, this->pe.phone_no);
  48. }
  49.  
  50. static void add_member(PHONE_LIST *this, PHONE_ENTRY *pe) {
  51.     DB_AddRow(this->table);
  52.     DB_PutString(this->last,pe->last_name);
  53.     DB_PutString(this->first,pe->first_name);
  54.     DB_PutString(this->phone,pe->phone_no);
  55. }
  56.  
  57. static void replace_member(PHONE_LIST *this,
  58. PHONE_ENTRY *pe) {
  59.     DB_PutString(this->last,pe->last_name);
  60.     DB_PutString(this->first,pe->first_name);
  61.     DB_PutString(this->phone,pe->phone_no);
  62. }
  63.  
  64. static PHONE_ENTRY *current(PHONE_LIST *this) {
  65.     strcpy(this->pe.last_name,DB_GetString(this->last));
  66.     strcpy(this->pe.first_name,DB_GetString(this->first));
  67.     strcpy(this->pe.phone_no,DB_GetString(this->phone));
  68.     return(&(this->pe));
  69. }
  70.  
  71. PHONE_LIST *new_phone_list() {
  72. PINNACLE_LIST *pl; PHONE_LIST *this;
  73.  
  74. pl = new_pinnacle_list("fonelist.db","PhoneList");
  75. if (pl == NULL)
  76.    return(NULL);
  77.  
  78. this = calloc(1,sizeof(PHONE_LIST));
  79. if (this == NULL) {
  80.     destroy_pinnacle_list(pl);
  81.     return(NULL);
  82. }
  83.  
  84. memmove(this,pl,sizeof(PINNACLE_LIST));
  85. free(pl);
  86.  
  87. this->last = DB_Column(this->table,"Last");
  88. this->first = DB_Column(this->table,"First");
  89. this->phone = DB_Column(this->table,"Phone");
  90. this->lastfirst =  DB_Column(this->table,"LastFirst");
  91. DB_OrderBy(this->lastfirst);
  92. this->find = find; this->display = display;
  93. this->add_member = add_member;
  94. this->replace_member = replace_member;
  95. this->current = current;
  96. return(this);
  97. }
  98.  
  99. void destroy_phone_list(PHONE_LIST *this) {
  100.     destroy_pinnacle_list(this);
  101. }
  102.