Annotation of pmsdk/samples/newcard/cffind.c, revision 1.1.1.1

1.1       root        1: #include "cardfile.h"
                      2: 
                      3: /*********************************************************************/
                      4: /*  Windows/PM Cardfile Shared Code                                  */
                      5: /*                                                                   */
                      6: /*  (c) Copyright Microsoft Corp. 1987,1988 - All Rights Reserved    */
                      7: /*********************************************************************/
                      8: 
                      9: /*********************************************************************/
                     10: /*    The following shared code was developed from the original      */
                     11: /* Cardfile application.  This code can be compiled to run under     */
                     12: /* either the Windows or the PM manager environment.  All            */
                     13: /* functionality associated with bitmaps or printing has been        */
                     14: /* deleted.  Some comments refering to these functions may still be  */
                     15: /* present in the code and should be disregarded. jw.                */
                     16: /*********************************************************************/
                     17: 
                     18: /*********************************************************************/
                     19: /* DoGoto -                                                          */
                     20: /*    Searches through the headers of the cards to find a card with  */
                     21: /* the same pattern as pchBuf                                        */
                     22: /*                                                                   */
                     23: /*    Same for PM and Windows                                        */
                     24: /*********************************************************************/
                     25: 
                     26: void FAR DoGoto(pchBuf)
                     27: PSTR pchBuf;
                     28:     {
                     29:     int i;
                     30:     LPCARDHEADER lpCards;
                     31:     LPCARDHEADER lpCardsTmp;
                     32:     char buf[80];
                     33:     int iNextFirst;
                     34: 
                     35:     /* get the header information */
                     36:     lpCards = (LPCARDHEADER) GlobalLock(hCards);
                     37: 
                     38:     /* for each card starting with the one after the front card */
                     39:     lpCardsTmp = lpCards+iFirstCard+1;
                     40:     for (i = 1; i <= cCards; ++i)
                     41:         {
                     42:         if (i + iFirstCard == cCards)
                     43:             lpCardsTmp = lpCards;
                     44: 
                     45:         /* look for the pattern */
                     46:         if (AnsiFind(lpCardsTmp->line, pchBuf, LINELENGTH))
                     47:                 goto DoneSearching;
                     48:         lpCardsTmp++;
                     49:         }
                     50: 
                     51: DoneSearching:
                     52:     GlobalUnlock(hCards);
                     53:     if (i <= cCards)     /* found it */
                     54:         {
                     55:         iNextFirst = iFirstCard + i;
                     56:         if (iNextFirst >= cCards)
                     57:             iNextFirst -= cCards;
                     58:         GetNewCard(iFirstCard, iNextFirst);
                     59:         }
                     60:     else
                     61:         {
                     62:         /* couln't find pattern */
                     63:         Mylstrcpy((LPSTR)buf, (LPSTR)"\"");
                     64:         Mylstrcat((LPSTR)buf, (LPSTR)pchBuf);
                     65:         Mylstrcat((LPSTR)buf, (LPSTR)"\"");
                     66:         MyMessageBox(IDS_ECANTFIND, buf, MB_OK | MB_ICONEXCLAMATION);
                     67:         }
                     68:     }
                     69: 
                     70: /*********************************************************************/
                     71: /* FindStrCard -                                                     */
                     72: /*    Looks through the body of each card to find the pattern        */
                     73: /*                                                                   */
                     74: /*    Slightly different for PM and Windows                          */
                     75: /*********************************************************************/
                     76: 
                     77: void FAR FindStrCard()
                     78:     {
                     79:     int i;
                     80:     int fFound;
                     81:     LPSTR lpch1;
                     82:     LPSTR lpText;
                     83:     int iCard;
                     84:     char buf[80];
                     85:     HANDLE hText;
                     86:     int ichStart;
                     87:     CARDHEADER CardHead;
                     88:     CARD Card;
                     89:     LPCARDHEADER lpCards;
                     90: 
                     91:     /* get a buffer for reading in each card's text */
                     92:     hText = GlobalAlloc(GHND, (long)CARDTEXTSIZE);
                     93:     if (!hText)
                     94: FSC_INSMEM:
                     95:         {
                     96:         CardfileOkError(IDS_EINSMEMORY);
                     97:         return;
                     98:         }
                     99:     lpText = GlobalLock(hText);
                    100:     fFound = FALSE;
                    101: 
                    102:     /* get the front card's text */
                    103:     GetWindowText(hCardWnd, lpText, CARDTEXTSIZE);
                    104: 
                    105:     /* get the current selection (and the starting spot for the search */
                    106:     ichStart = HIWORD(SendMessage(hCardWnd, EM_GETSEL, 0, 0L));
                    107:     iCard = iFirstCard;
                    108: 
                    109:     /* look in for the pattern */
                    110:     if (lpch1 = AnsiFind(lpText+ichStart, CurIFind, -1))
                    111:         {
                    112:         fFound = TRUE;
                    113:         goto FS_DONE;
                    114:         }
                    115: 
                    116:     /* try following cards */
                    117:     iCard++;
                    118:     if (iCard == cCards)
                    119:         iCard = 0;
                    120: 
                    121:     /* for each card back to current card */
                    122:     for (i = 0; i < cCards-1; ++i)
                    123:         {
                    124:         /* get text */
                    125:         lpCards = (LPCARDHEADER) GlobalLock(hCards);
                    126:         lpCards += iCard;
                    127:         CardHead = *lpCards;
                    128:         GlobalUnlock(hCards);
                    129:         ReadCurCardData(&CardHead, &Card, lpText);
                    130: 
                    131:         /* look for text */
                    132:         if (lpch1 = AnsiFind(lpText, CurIFind, -1))
                    133:             {
                    134:             fFound = TRUE;
                    135:             goto FS_DONE;
                    136:             }
                    137:         iCard++;
                    138:         if (iCard == cCards)
                    139:             iCard = 0;
                    140:         }
                    141: 
                    142:     /* if we still haven't found it, get current text again */
                    143:     GetWindowText(hCardWnd, lpText, CARDTEXTSIZE);
                    144: 
                    145:     /* look up to beginning of selection */
                    146:     if (lpch1 = AnsiFind(lpText, CurIFind, ichStart))
                    147:         {
                    148:         fFound = TRUE;
                    149:         goto FS_DONE;
                    150:         }
                    151: 
                    152: FS_DONE:
                    153:     /* if we found it */
                    154:     if (fFound)
                    155:         {
                    156: 
                    157:         /* and not on font card, get new data */
                    158:         if (iCard != iFirstCard && !GetNewCard(iFirstCard, iCard))
                    159:             goto FSC_INSMEM;
                    160: 
                    161:         /* set selection */
                    162: #ifdef   IN_WINDOWS
                    163:         /* Unfortunately the order of the parameters for the SETSEL  */
                    164:         /* message are reversed in PM.  The easiest way to handle this */
                    165:         /* having separate SendMessages. jw  */ 
                    166: 
                    167:         SendMessage(hCardWnd, EM_SETSEL, 0, MAKELONG((int)(lpch1-lpText), 
                    168:                     (int)(lpch1-lpText)+Mylstrlen((LPSTR)CurIFind)));
                    169: #else
                    170:         SendMessage(hCardWnd, EM_SETSEL, MAKEULONG((int)(lpch1-lpText), 
                    171:                    (int)(lpch1-lpText)+Mylstrlen((PSZ)CurIFind)), 0L);
                    172: #endif
                    173:         }
                    174:     else
                    175:         {
                    176:         /* couldn't find it */
                    177:         Mylstrcpy((LPSTR)buf, (LPSTR)"\"");
                    178:         Mylstrcat((LPSTR)buf, (LPSTR)CurIFind);
                    179:         Mylstrcat((LPSTR)buf, (LPSTR)"\"");
                    180:         MyMessageBox(IDS_ECANTFIND, buf, MB_OK | MB_ICONEXCLAMATION);
                    181:         }
                    182:     GlobalUnlock(hText);
                    183:     GlobalFree(hText);
                    184:     }
                    185: 
                    186: 
                    187: /*********************************************************************/
                    188: /* DoCutCopy -                                                       */
                    189: /*    Finds the pKey string within lpSrc.                            */
                    190: /* SrcLen specifies the length of the lpSrc to be searched.          */
                    191: /* Returns LPSTR to where the Key is if pKey is found in lpSrc,      */
                    192: /* FALSE otherwise.                                                  */
                    193: /*                                                                   */
                    194: /*    Same for PM and Windows                                        */
                    195: /*********************************************************************/
                    196: 
                    197: LPSTR NEAR AnsiFind(lpSrc, pKey, SrcLen)
                    198: LPSTR lpSrc;
                    199: PSTR  pKey;
                    200: short SrcLen;
                    201: {
                    202:     register LPSTR lpch;
                    203:     register PSTR  pKeyTmp;
                    204: 
                    205:     for (; *lpSrc && SrcLen; lpSrc++, SrcLen--)
                    206:         {
                    207:         for (lpch = lpSrc, pKeyTmp = pKey; *pKeyTmp; pKeyTmp++, lpch++)
                    208:             {
                    209:             if (ANSICHARUP(CHAR_STR(lpch)) != ANSICHARUP(CHAR_STR(pKeyTmp)))
                    210:                 break;
                    211:             if (((PSTR)AnsiNext(pKeyTmp)) - pKeyTmp > 1)
                    212:                 {
                    213:                 if (pKeyTmp[1] != lpch[1])
                    214:                     break;
                    215:                 pKeyTmp++;
                    216:                 lpch++;
                    217:                 }
                    218:             }
                    219:         if (!*pKeyTmp)
                    220:             return lpSrc;
                    221:         if (AnsiNext(lpSrc) - lpSrc > 1)
                    222:             {
                    223:             lpSrc++;
                    224:             SrcLen--;
                    225:             }
                    226:         }
                    227:     return FALSE;
                    228: }
                    229: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.