home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / quot210s.zip / src / athreads.c < prev    next >
C/C++ Source or Header  |  1998-06-07  |  4KB  |  179 lines

  1. /*
  2.  * athreads.c
  3.  *
  4.  * Threads for use with author databases.
  5.  *
  6.  *      Created: 27th January, 1997
  7.  * Version 1.00: 19th March, 1997
  8.  * Version 2.00: 18th December, 1997
  9.  *
  10.  * (C) 1997 Nicholas Paul Sheppard
  11.  *
  12.  * This file is distributed under the GNU General Public License. See the
  13.  * file copying.txt for details.
  14.  */
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include "authors.h"
  19. #include "threads.h"
  20. #include "types.h"
  21.  
  22.  
  23. void ThreadFindAllAuthors(THREADINFO *pti)
  24. /*
  25.  * Start a thread to find all authors in the open database. 
  26.  */
  27. {
  28.     HAB        hab;
  29.     HMQ        hmq;
  30.     AUTHORSEARCH    as;
  31.  
  32.     /* set up a message queue */
  33.     if ((hab = WinInitialize(0)) == NULLHANDLE)
  34.         return;
  35.     hmq = WinCreateMsgQueue(hab, 0);
  36.  
  37.     /* perform the search */
  38.     if (AuthorFullSearchInit(&(pti->pps->adb), &as)) {
  39.         WinSendMsg(pti->hwndCaller, QM_FOUND, MPFROMP(as.szLastCode), 0);
  40.         while (AuthorFullSearchNext(&as))
  41.             WinSendMsg(pti->hwndCaller, QM_FOUND, MPFROMP(as.szLastCode), 0);
  42.     }
  43.     WinSendMsg(pti->hwndCaller, QM_DONE, 0, 0);
  44.  
  45.     /* clean up */
  46.     AuthorFullSearchEnd(&as);
  47.     WinDestroyMsgQueue(hmq);
  48.     WinTerminate(hab);
  49.     _endthread();
  50. }
  51.  
  52.  
  53. void ThreadFindDescription(THREADINFO *pti)
  54. /*
  55.  * Start a thread to find all authors in the open database with a given string
  56.  * in their description.
  57.  */
  58. {
  59.     HAB        hab;
  60.     HMQ        hmq;
  61.     AUTHORSEARCH    as;
  62.  
  63.     /* set up a message queue */
  64.     if ((hab = WinInitialize(0)) == NULLHANDLE)
  65.         return;
  66.     hmq = WinCreateMsgQueue(hab, 0);
  67.  
  68.     /* perform the search */
  69.     switch (AuthorDescSearchInit(&(pti->pps->adb), (char *)(pti->pData), &as)) {
  70.         case -1:
  71.             WinSendMsg(pti->hwndCaller, QM_ERROR, 0, 0);
  72.             break;
  73.  
  74.         case 1:
  75.             WinSendMsg(pti->hwndCaller, QM_FOUND, MPFROMP(as.szLastCode), 0);
  76.             while (AuthorDescSearchNext(&as))
  77.                 WinSendMsg(pti->hwndCaller, QM_FOUND, MPFROMP(as.szLastCode), 0);
  78.  
  79.         case 0:
  80.             WinSendMsg(pti->hwndCaller, QM_DONE, 0, 0);
  81.             break;
  82.     }
  83.  
  84.     /* clean up */
  85.     AuthorDescSearchEnd(&as);
  86.     WinDestroyMsgQueue(hmq);
  87.     WinTerminate(hab);
  88.     _endthread();
  89. }
  90.  
  91.  
  92. void ThreadFindAuthorName(THREADINFO *pti)
  93. /*
  94.  * Start a thread to find all authors in the open database with a given name.
  95.  */
  96. {
  97.     HAB        hab;
  98.     HMQ        hmq;
  99.     AUTHORSEARCH    as;
  100.  
  101.     /* set up a message queue */
  102.     if ((hab = WinInitialize(0)) == NULLHANDLE)
  103.         return;
  104.     hmq = WinCreateMsgQueue(hab, 0);
  105.  
  106.     /* perform the search */
  107.     switch (AuthorNameSearchInit(&(pti->pps->adb), (char *)(pti->pData), &as)) {
  108.         case -1:
  109.             WinSendMsg(pti->hwndCaller, QM_ERROR, 0, 0);
  110.             break;
  111.  
  112.         case 1:
  113.             WinSendMsg(pti->hwndCaller, QM_FOUND, MPFROMP(as.szLastCode), 0);
  114.             while (AuthorNameSearchNext(&as))
  115.                 WinSendMsg(pti->hwndCaller, QM_FOUND, MPFROMP(as.szLastCode), 0);
  116.  
  117.         case 0:
  118.             WinSendMsg(pti->hwndCaller, QM_DONE, 0, 0);
  119.             break;
  120.     }
  121.  
  122.     /* clean up */
  123.     AuthorNameSearchEnd(&as);
  124.     WinDestroyMsgQueue(hmq);
  125.     WinTerminate(hab);
  126.     _endthread();
  127. }
  128.  
  129.  
  130. void ThreadImportAuthors(THREADINFO *pti)
  131. /*
  132.  * Import a quote database in pti->pps->padb. The pData entry in pti should
  133.  * point to an IMPORTINFO structure describing the import parameters.
  134.  */
  135. {
  136.     HAB        hab;
  137.     HMQ        hmq;
  138.     AUTHORSEARCH    as;
  139.     IMPORTINFO    *pii;
  140.     BOOL        bOkay;
  141.     char        szString[100];
  142.     AUTHORINFO    *pai;
  143.     char        *pszDesc;
  144.  
  145.     /* set up a message queue */
  146.     if ((hab = WinInitialize(0)) == NULLHANDLE)
  147.         return;
  148.     hmq = WinCreateMsgQueue(hab, 0);
  149.  
  150.     /* import, quote by quote */
  151.     pii = (IMPORTINFO *)pti->pData;
  152.     if (AuthorFullSearchInit((AUTHORDB *)pii->pdb, &as)) {
  153.         do {
  154.             bOkay = !AuthorExists(&(pti->pps->adb), as.szLastCode);
  155.             if (!bOkay) {
  156.                 if (pii->bAsk) {
  157.                     sprintf(szString, "%s exists. Replace it?", as.szLastCode);
  158.                     if (WinMessageBox(HWND_DESKTOP, pti->hwndCaller, szString, "Confirmation", 0, MB_QUERY | MB_YESNO) == MBID_YES)
  159.                         bOkay = TRUE;
  160.                 } else if (pii->bReplace)
  161.                         bOkay = TRUE;
  162.             }
  163.             if (bOkay) {
  164.                 AuthorGetAuthor((AUTHORDB *)pii->pdb, as.szLastCode, &pai, &pszDesc);
  165.                 AuthorAddAuthor(&(pti->pps->adb), as.szLastCode, pai, pszDesc);
  166.                 AuthorFreeAuthor(&pai, &pszDesc);
  167.             }
  168.         } while (AuthorFullSearchNext(&as));
  169.     }
  170.  
  171.     /* tell the calling window that we're finished */
  172.     WinSendMsg(pti->hwndCaller, QM_DONE, NULL, NULL);
  173.  
  174.     /* clean up */
  175.     WinDestroyMsgQueue(hmq);
  176.     WinTerminate(hab);
  177.     _endthread();
  178. }
  179.