예제 #1
0
static WORD ClearItemChunks(WORD wType)
{
    WORD wSize;
    GLOBALHANDLE hChunk, hChunk1; 

    GetHandle(wType, (GLOBALHANDLE *) &hChunk, (WORD FAR *) &wSize, 
              (BOOL) GET_CHUNK);

    while (hChunk && (hChunk1 = hChunk)) {
        FIXCHUNKHDR lpChunk = (FIXCHUNKHDR) GLOBALLOCK(hChunk);
        
        if (!lpChunk)
            return ERROR;
        
        if (lpChunk->hTable)
            GLOBALFREE(lpChunk->hTable);
        if (lpChunk->hChunkTable)
            GLOBALFREE(lpChunk->hChunkTable);

        hChunk = lpChunk->hNext;
        GLOBALUNLOCK(hChunk1);
        GLOBALFREE(hChunk1);
    }

    return TRUE;
}
예제 #2
0
void EnumItemsFromBottom(BOOL (*fn)(LPBRTABLE, LPSTR), LPSTR lpData)
{
    BRDATA lpBrData = (BRDATA) GLOBALLOCK(hClBrData);
    LPBRTABLE lpBrowser = (LPBRTABLE) GLOBALLOCK(lpBrData->hBrowser);
    
	LPBRTABLE lpLevel;
    LEVEL_TYPE level = lpBrData->lDepth;

	while (level >= lpBrData->lFocusedLevel &&
           FindLevel_BrTable(lpBrowser, level--, &lpLevel, FALSE)) {
        WORD wCount = LEVELCOUNT((lpLevel - SIZE_BRLEVEL));
        WORD wLevelSize = lpBrData->sItemSize * wCount;
        GLOBALHANDLE hCopy = GLOBALALLOC(GHND, wLevelSize);
        
        if (hCopy)
        {
            LPBRTABLE lpItem = GLOBALLOCK(hCopy);

            _fmemcpy(lpItem, lpLevel, wLevelSize);
            while (wCount--) {
                (*fn)(lpItem, lpData);
                lpItem = MOVE_TO_NEXT_ITEM(lpItem, lpBrData->sItemSize);
            }
            
            GLOBALUNLOCK(hCopy);
            GLOBALFREE(hCopy);
        }
        else
            break;
    }

    GLOBALUNLOCK(lpBrData->hBrowser);
    GLOBALUNLOCK(hClBrData);
}
예제 #3
0
HANDLE RLDecode(char *szFileName)
{
    FILE *In;
    long length;
    HANDLE hMemory;
    LPSTR lpMemory;

    In = fopen(szFileName, "rb");
    if (!In)
        return FALSE;

    fread(&length, sizeof(long), 1, In);

    hMemory = GLOBALALLOC(GHND, length);
    if (!hMemory)
        return NULL;
    
    lpMemory = GLOBALLOCK(hMemory);
    if (!lpMemory)
    {
        GLOBALFREE(hMemory);
        return NULL;
    }
    
    rle_decomp(In, lpMemory);

    fclose(In);
    GLOBALUNLOCK(hMemory);
    
    return hMemory;
}
예제 #4
0
/* Returns TRUE if an empty expression of just a semicolon */
WORD WndCheckExpEmpty(HWND hWnd)
{
    GLOBALHANDLE hBody = NULL;
    LPSTR lpBody;
    WORD wCheck, wBodyLen;

    wBodyLen = (WORD) SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0L);
    wBodyLen += 1;
    if (wBodyLen <= RET_BUFFER_LEN)
        lpBody = return_buffer;
    else
    {
        hBody = GLOBALALLOC(GHND, wBodyLen);
        lpBody = (LPSTR) GLOBALLOCK(hBody);
    }

    GetWindowText(hWnd, lpBody, wBodyLen);
    wCheck = EmptyBody(lpBody) || IsSemiColon(lpBody);
    
    if (hBody)
    {
        GLOBALUNLOCK(hBody);
        GLOBALFREE(hBody);
    }

    return wCheck;
}
예제 #5
0
WORD WndCheckExp(HWND hWnd, LPSTR lpTitle, WORD wType)
{
    GLOBALHANDLE hBody;
    LPSTR lpBody;
    WORD wCheck = FALSE, wLoc = 0, wBodyLen;

    wBodyLen = (WORD) SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0L);
    wBodyLen += 1;
    hBody = GLOBALALLOC(GHND, wBodyLen);
    lpBody = GLOBALLOCK(hBody);
    GetWindowText(hWnd, lpBody, wBodyLen);
    RegisterKappaMessage(IDE_ERROR, NULLID, NULLID, NULLID);

    if (!KppCalculateExpSize(lpBody, &wLoc))
    {
        char stBuffer[RET_BUFFER_LEN];
        WORD wStr1, wStr2;

        wStr1 = wStr2 = KppGetParserErrorLoc();
        KppKappaGetWord(0, lpBody, (LPWORD) &wStr2, stBuffer,
                        RET_BUFFER_LEN);
        while (lpBody[wStr1] != stBuffer[0])
            wStr1++;
        SendMessage(hWnd, EM_SETSEL, 0, MAKELONG(wStr1, wStr2));
        KppIncrementPopupCountCB(EDITW);
        PostKappaMessageWithTitle(lpTitle);
        KppDecrementPopupCountCB(EDITW);
        SetFocus(hWnd);
        wCheck = TRUE;
    }
    else
    {
        lpBody += KppCheckStatement(lpBody);
        while (*lpBody)
        {
            if (!isspace(*lpBody++))
            {
                RegisterKappaMessage(IDE_MORETHANONEEXP,
                                     NULLID, NULLID, NULLID);
                KppIncrementPopupCountCB(EDITW);
                PostKappaMessageWithTitle(lpTitle);
                KppDecrementPopupCountCB(EDITW);
                wCheck = TRUE;
                break;
            }
        }
    }

    GLOBALUNLOCK(hBody);
    GLOBALFREE(hBody);

    return wCheck;
}
예제 #6
0
파일: DLL.C 프로젝트: thearttrooper/KappaPC
/* clean up dll libraries when exiting kappa */ 
void KppDLLExit(void)
{
    short i;
    kppDLLTABLE FAR *kppDLLTable;
    
#ifndef MAC
    kppDLLTable = (kppDLLTABLE FAR *) GLOBALLOCK(hdlkppDLLTable);
    for (i = 0; i <= lib_table_index; i++)
        if (kppDLLTable[i].LibHandle)
            FreeLibrary(kppDLLTable[i].LibHandle);
        
    GLOBALUNLOCK(hdlkppDLLTable);
    GLOBALFREE(hdlkppDLLTable);
#endif    
}
예제 #7
0
///	free all memory allocations for database
///	\param	dbInfo - pointer to database information
void CDatabaseManager::ReleaseDatabase(DATABASEINFO *dbInfo)
{
	DATABASEDATA *data = dbInfo->m_DatabaseData;
	if (data != NULL)
	{
		for_each(data, data + dbInfo->m_nItems, mem_fun_ref(&DATABASEDATA::Release));
		GLOBALFREE(data);
	}
	// free up the alloc CHashString*
	delete dbInfo->m_SchemaName;
	delete dbInfo->m_FileName;
	// TODO: Check that name is owned by DATABASEINFO structure also
	//delete dbInfo->m_DatabaseName;
	//delete dbInfo->m_SchemaFile;
}
예제 #8
0
/*************************************************************************
            KppDestroyRuleRelations
 *************************************************************************/
void PEXPORT KppDestroyRuleRelations (GLOBALHANDLE hRuleRel)
{
#ifdef INFERENCE
#ifndef RUNTIME
  LPRULEREL lpRuleRel;

  if (!hRuleRel)
    return;

  lpRuleRel = (LPRULEREL) GLOBALLOCK (hRuleRel);
  GLOBALUNLOCK (RRHIF(lpRuleRel));
  GLOBALFREE (RRHIF(lpRuleRel));
  GLOBALUNLOCK (RRHTHEN(lpRuleRel));
  GLOBALFREE (RRHTHEN(lpRuleRel));

  while (GLOBALUNLOCK (hRuleRel));
  /* Do it twice 
  GLOBALUNLOCK (hRuleRel);
*/
  GLOBALFREE (hRuleRel);

#endif
#endif
}
예제 #9
0
BOOL PEXPORT KppDeleteBuffer(OBJECTID idObject, ATOMID idSlot)
{
    ATOMID       idBuffer;
    GLOBALHANDLE hBuffer;
    
    idBuffer = Kpp_Get_SlotValue (OBJECT_TYPE(idObject), idObject, idSlot);
    if (!idBuffer)
        return ERROR;
    
    if (!KappaGetInt (idBuffer, hBuffer))
        return ERROR;
    
    GLOBALUNLOCK (hBuffer);
    GLOBALFREE (hBuffer);

    return kpc_reset_value (OBJECT_TYPE (idObject), idObject, idSlot);
}
예제 #10
0
BOOL PEXPORT KppInterpretKalFile(LPSTR lpTrpFile, BOOL bMode, ATOMID idAsk)
{
    BOOL bRet;
    FILE *fpFile;
    GLOBALHANDLE hComment;
    LPSTR lpComment;
    OFSTRUCT of;

    if (!KppBeforeInterpretFileCB(lpTrpFile))
        return FALSE;

    if (OpenFile(lpTrpFile, &of, OF_EXIST) != HFILE_ERROR)
    {
        lpTrpFile = of.szPathName;
        if (!(fpFile = fopen_share(of.szPathName, "r")))
            return FALSE;
    }
    else
        return KppRegisterKappaMessage(hResThisDll, IDE_FILENOTFOUND,
                                       KppAddAtom(of.szPathName), 
                                       NULLID, NULLID);

    hComment = GLOBALALLOC(GHND | GMEM_SHARE, MAX_COMMENT_SIZE);
    lpComment = GLOBALLOCK(hComment);
#ifdef RUNTIME
    bRet = InterpretKal(fpFile, lpTrpFile, lpComment, FALSE, idAsk);
#else
    bRet = InterpretKal(fpFile, lpTrpFile, lpComment, bMode, idAsk);
#endif
    fclose(fpFile);

    bRet = KppAfterInterpretFileCB(lpTrpFile, lpComment, bRet);

    GLOBALUNLOCK(hComment);
    GLOBALFREE(hComment);

    return bRet;
}
예제 #11
0
TANY W_CALLBACK KpiVBXPictureBC(OBJECTID self, LPSTR ap)
{
    WORD wType = OBJECT_TYPE(self);
    ATOMID idWidget = KppGetItemName(wType, self);
    HWND hWnd = KpsGetWindowFromWidget(idWidget);
    LPVBXINFO lpVBXInfo = GetVBXInfo(hWnd);
    ATOMID idSlot = va_far_arg(ap, ATOMID);
    ATOMID idValue = va_far_arg(ap, ATOMID);
    ATOMID idPic = Kpp_GetOption(wType, self, idSlot, OPT_DATA);
    TANY res;
    PIC pic;
    
    if (lpVBXInfo && idPic && idPic != lpIDs->idNull)
    {
        long lOldPic;
            
        if (KppGetAtomLong(idPic, &lOldPic))
            lpVBXInfo->lpDisp->FreePicture(lpVBXInfo, (HPIC) lOldPic);
    }
        
    res.type = T_ATOM;
    res.data.atom = idValue;
    
    if (!lpVBXInfo || !IsWindow(hWnd) || !idValue || idValue == lpIDs->idNull)
        return res;
    
    pic.picType = PICTYPE_ICON;
    if (idValue == _SYM(Application))
        pic.picData.icon.hicon = LoadIcon(NULL, IDI_APPLICATION);
    else if (idValue == _SYM(Asterisk))
        pic.picData.icon.hicon = LoadIcon(NULL, IDI_ASTERISK);
    else if (idValue == _SYM(Exclamation))
        pic.picData.icon.hicon = LoadIcon(NULL, IDI_EXCLAMATION);
    else if (idValue == _SYM(Hand))
        pic.picData.icon.hicon = LoadIcon(NULL, IDI_HAND);
    else if (idValue == _SYM(Question))
        pic.picData.icon.hicon = LoadIcon(NULL, IDI_QUESTION);
    else 
    {
        HANDLE hDIB = KpiLoadDIBFromFile(NULLID, idValue);
        HBITMAP hBitmap = NULL;
        
        if (hDIB)
            hBitmap = KpiBitmapFromDib(hDIB, GetStockObject(DEFAULT_PALETTE));
        if (!hBitmap)
        {
            if (hDIB)
                GLOBALFREE(hDIB);
            pic.picType = PICTYPE_NONE;
        }
        else
        {
            pic.picType = PICTYPE_BITMAP;
            pic.picData.bmp.hpal = GetStockObject(DEFAULT_PALETTE);
            pic.picData.bmp.hbitmap = hBitmap;
        }
    }
    
    if (pic.picType != PICTYPE_NONE)
    {
        HPIC hPic = lpVBXInfo->lpDisp->CreatePicture(lpVBXInfo, &pic);

        if (hPic)
            idPic = KppAddAtomLong((long) hPic);
        else
            idPic = lpIDs->idNull;
        
        Kpp_SetOption(wType, self, idSlot, OPT_DATA, idPic);
    }    
    
    return res;
}    
예제 #12
0
void PEXPORT KlwPop(BOOL bDisplay)
{
    GLOBALHANDLE hCtx, hPrev, hWatches;
    WORD active, i;
  
    if (hWndStack)
    {
        SendMessage(hWndStack, LB_DELETESTRING, 0, 0L);
        SendMessage(hWndStack, LB_SETCURSEL, 0, 0L);
    }
    
    if (varstack)
    {
        if (varstack->pops)
            varstack->pops--;
        else
        {
            GLOBALHANDLE hPrev = varstack->hPrev;
            GLOBALHANDLE hCtx = varstack->hCtx;
            
            if (varstack->idVarList)
                KppDeleteList(varstack->idVarList);
            GLOBALUNLOCK(hCtx);
            GLOBALFREE(hCtx);
            
            if (hPrev)
                varstack = (varctx) GLOBALLOCK(hPrev);
            else
                varstack = NULL;
            
            if (varstack)
                KlwUpdateWatches(varstack->lpBody, varstack->idVarList);
        }
    }        

    if (!dbgstack)
        return;
    
    if (dbgstack->pops)
    {
        dbgstack->pops--;
        return;
    }
    
    for (i = 0; i < MAX_WATCHES; ++i) {
        watch wtc = &dbgstack->wtcs[i];
        
        if (!wtc->bPerm)
        {
            if (wtc->idSlot)
            {
                LPSLOT lpSlot = (LPSLOT) KppGetItem(SLOT, wtc->idSlot);
            
                if (lpSlot)
                {
                    SLOTFLAGS(lpSlot) &= ~SLOTWATCHED;
                    KppReleaseItem(SLOT, wtc->idSlot);
                }
            }
        
            if (wtc->idNames)
                KppDeleteList(wtc->idNames);
        }
    }
        
    hCtx = dbgstack->hCtx;
    hPrev = dbgstack->hPrev;
    hWatches = dbgstack->hWatches;
    active = dbgstack->active;
    if (dbgstack->hWatches)
        SetWindowText(hWndWatches, "");
    
    if (hPrev)
    {
        dbgctx ctx = (dbgctx) GLOBALLOCK(hPrev);
        
        KlwTransferWatches(dbgstack, ctx);
        dbgstack = ctx;

        if (active == CTX_ABORT)
            ctx->active = CTX_ABORT;
        else if (bDisplay && ctx->active == CTX_STEP)
        {
            KlwShowExp(hWndSource, ctx->wType, ctx->idCode, ctx->idObj);
            ShowCurLine(hWndSource, NULL, FALSE);
            if (ctx->hWatches)
            {
                LPSTR lpWatches = GLOBALLOCK(ctx->hWatches);
                
                SetWindowText(hWndWatches, lpWatches);
                GLOBALUNLOCK(ctx->hWatches);
            }
        }
    }        
    else
    {
        HMENU hMenu = GetMenu(hWndKalView);
        
        EnableMenuItem(hMenu, KLW_CLEAR, MF_BYCOMMAND | MF_ENABLED);
        EnableMenuItem(hMenu, KLW_STACK, MF_BYCOMMAND | MF_GRAYED);
        EnableMenuItem(hMenu, KLW_SELECTION, MF_BYCOMMAND | MF_GRAYED);
        EnableMenuItem(hMenu, KLW_WTCSEL, MF_BYCOMMAND | MF_GRAYED);
        EnableMenuItem(hMenu, KLW_WTCSLOT, MF_BYCOMMAND | MF_GRAYED); 
        EnableMenuItem(hMenu, KLW_RUN, MF_BYCOMMAND | MF_ENABLED); 
        EnableMenuItem(hMenu, KLW_CLOSE, MF_BYCOMMAND | MF_ENABLED);
        GetSystemMenu(hWndKalView, TRUE);

        dbgstack = NULL;
        SendMessage(hWndSource, EM_SETSEL, 0, 0L);
        ShowWindow(hWndStack, SW_HIDE);
    }
    
    GLOBALUNLOCK(hCtx);
    GLOBALFREE(hCtx);
    if (hWatches)
        GLOBALFREE(hWatches);
}
예제 #13
0
WORD EditorCheckRulePattern(HWND hWndDlg, WORD wChild) 
{
    GLOBALHANDLE hPattern;
    LPSTR lpPattern;
    WORD i = 0, wCheck = FALSE, wFirst = TRUE;
    char stBuffer[NAME_BUFFER_LEN];
    HWND hWnd;

    hPattern = GLOBALALLOC(GHND, (DWORD) BODY_LEN);
    lpPattern = (LPSTR) GLOBALLOCK(hPattern);

    hWnd = GetDlgItem(hWndDlg, wChild);
    GetWindowText(hWnd, lpPattern, BODY_LEN - 1);

    i = KppGetWordFromString(lpPattern, i, stBuffer, NAME_BUFFER_LEN);
    while (i) {
        if (!stBuffer[0])
            break;
        if (!wFirst && stBuffer[0] == ',')
        {
            KppIncrementPopupCountCB(EDITW);
            MessageBox(GetActiveWindow(), "Not Needed Between Patterns",
                       "COMMA", MB_OK | MB_ICONEXCLAMATION);
            KppDecrementPopupCountCB(EDITW);
            wCheck = TRUE;
            break;
        }
        if (!KppIsGoodName(stBuffer))
        {
            sprintf(return_buffer, "Found \"%s\"", stBuffer);
            KppIncrementPopupCountCB(EDITW);
            MessageBox(GetActiveWindow(), return_buffer,
                       "Bad Dummy Name", MB_OK | MB_ICONEXCLAMATION);
            KppDecrementPopupCountCB(EDITW);
            wCheck = TRUE;
            break;
        }
        i = KppGetWordFromString(lpPattern, i, stBuffer, NAME_BUFFER_LEN);
        if (i == 0 || stBuffer[0] == '\0' || stBuffer[0] != '|')
        {
            sprintf(return_buffer, "Found \"%s\"", stBuffer);
            KppIncrementPopupCountCB(EDITW);
            MessageBox(GetActiveWindow(), return_buffer,
                       "Expecting '|'", MB_OK | MB_ICONEXCLAMATION);
            KppDecrementPopupCountCB(EDITW);
            wCheck = TRUE;
            break;
        }
        i = KppGetWordFromString(lpPattern, i, stBuffer, NAME_BUFFER_LEN);
        if ((i == 0) && (!KppIsGoodName(stBuffer)))
        {
            sprintf(return_buffer, "Found \"%s\"", stBuffer);
            KppIncrementPopupCountCB(EDITW);
            MessageBox(GetActiveWindow(), return_buffer,
                       "Bad Class Name", MB_OK | MB_ICONEXCLAMATION);
            KppDecrementPopupCountCB(EDITW);
            wCheck = TRUE;
            break;
        }
        wFirst = FALSE;
        i = KppGetWordFromString(lpPattern, i, stBuffer, NAME_BUFFER_LEN);
    }

    GLOBALUNLOCK(hPattern);
    GLOBALFREE(hPattern);

    return wCheck;
}
예제 #14
0
int ExitObjectClassEditor(HWND hWndDlg, WORD wType, GLOBALHANDLE hObj)
{
    LPOBJECT lpTempObj;
    LISTID idRenamedNewNames, idRenamedOldNames, idDeletedSlots;

    /* See if item need to be saved */
    if (!QueryEditorSaveItem(hWndDlg, wType, hObj, EXIT))
        return FALSE;

    /* Clean up left over items on the temporary object */
    lpTempObj = (LPOBJECT) GLOBALLOCK(hObj);
    Kpp__ResetCO(wType, (LPCLASS) lpTempObj);
    GLOBALUNLOCK(hObj);
    GLOBALFREE(hObj);

    /* Take care of deleteslots and renamed ones */
    if (idDeletedSlots = GetProp(hWndDlg, (LPSTR) pDeletedSlots))
    {
        KppDeleteList(idDeletedSlots);
        SetProp(hWndDlg, (LPSTR) pDeletedSlots, NULLID);
    }

    if (idRenamedOldNames = GetProp(hWndDlg, (LPSTR) pRenamedOldNames))
    {
        KppDeleteList(idRenamedOldNames);
        SetProp(hWndDlg, (LPSTR) pRenamedOldNames, NULLID);
    }

    if (idRenamedNewNames = GetProp(hWndDlg, (LPSTR) pRenamedNewNames))
    {
        KppDeleteList(idRenamedNewNames);
        SetProp(hWndDlg, (LPSTR) pRenamedNewNames, NULLID);
    }

    /* Update the list of currently open object/class editors */
    if (wType == OBJECT && idObjectEditors)
    {
        KppDeleteElem(idObjectEditors, hWndDlg, 0);
        if (!KppListLen(idObjectEditors))
        {
            KppDeleteList(idObjectEditors);
            idObjectEditors = NULLID;
        }
    }
    else if (idClassEditors)
    {
        KppDeleteElem(idClassEditors, hWndDlg, 0);
        if (!KppListLen(idClassEditors))
        {
            KppDeleteList(idClassEditors);
            idClassEditors = NULLID;
        }
    }

    KppRemoveFromWindowMenuCB(hWndDlg);

    /* Remove all properties */
    if (wType == OBJECT)
        RemoveProp(hWndDlg, (LPSTR) "hObj");
    else
        RemoveProp(hWndDlg, (LPSTR) "hClass");
    RemoveProp(hWndDlg, (LPSTR) pActualItem);
    RemoveProp(hWndDlg, (LPSTR) pModified);
    RemoveProp(hWndDlg, (LPSTR) pSlotEditors);
    RemoveProp(hWndDlg, (LPSTR) pMethodEditors);
    RemoveProp(hWndDlg, (LPSTR) pDeletedSlots);
    RemoveProp(hWndDlg, (LPSTR) pRenamedOldNames);
    RemoveProp(hWndDlg, (LPSTR) pRenamedNewNames);

    return TRUE;
}
예제 #15
0
BOOL HandleCtrlKeys(HWND hWnd, WORD wKey)
{
    if (!BrSelection.idObj)
        return FALSE;
    
#ifndef RUNTIME            
    switch ((char) wKey + 0x40) {
      case 'B':
          if (OBJECT_TYPE(BrSelection.idObj) == CLASS)
              ShowSubNodesCB(CLASS, BrSelection.idObj, CLASS, BR_TOGGLE);
          return TRUE;
        
      case 'C':
          if (OBJECT_TYPE(BrSelection.idObj) == CLASS)
          {
              ATOMID idName;
              WORD wType;
              
              while (TRUE) {
                  sprintf(return_buffer, "Anon%d", ++wAnonCounter);
                  idName = KppAddAtom(return_buffer);
                  if (!KppGetObjectId(idName, &wType))
                      break;
              }
              
              KppMakeCO(CLASS, KppAddAtom(return_buffer), BrSelection.idObj);
          }
          return TRUE;
          
      case 'D':
          if (BrSelection.wCount > 1)
              EnumItemsFromBottom(DeleteSelectedItem, FALSE);
          else
              Kpp_DeleteCO(OBJECT_TYPE(BrSelection.idObj), BrSelection.idObj);

          return TRUE;
          
      case 'E':
      case 'X':
        {
            OBJECTID idObj = BrSelection.idObj;
            WORD wType = OBJECT_TYPE(idObj);
            ATOMID idName = KppGetItemName(wType, idObj);
              
            KppEditItemCB(hWnd, wType, idName);
            return TRUE;
        }

      case 'F':
          if (OBJECT_TYPE(BrSelection.idObj) == CLASS)
              SetClBrowserFocusCB(CLASS, BrSelection.idObj);
          return TRUE;
          
      case 'I':
          if (OBJECT_TYPE(BrSelection.idObj) == CLASS)
          {
              ATOMID idName;
              WORD wType;
              
              while (TRUE) {
                  sprintf(return_buffer, "Anon%d", ++wAnonCounter);
                  idName = KppAddAtom(return_buffer);
                  if (!KppGetObjectId(idName, &wType))
                      break;
              }
              
              KppMakeCO(OBJECT, idName, BrSelection.idObj);
          }
          return TRUE;
          
      case 'G':
          if (DialogBox(hInstKappa, "ISearchObject", 
                        hWndBrowser, (FARPROC) SearchObjDlg) &&
              SearchedObject)
          {
              WORD wType = OBJECT_TYPE(SearchedObject);
              
              if (wType == CLASS)
                  SetClBrowserFocusCB(CLASS, SearchedObject);
              else
                  SetClBrowserFocusCB(CLASS, 
                                      Kpp_Get_Super(OBJECT, SearchedObject));
              SelectBrowserObjectCB(SearchedObject, TRUE, FALSE, FALSE);
          }
          if (hSearchTable)
          {
              GLOBALUNLOCK(hSearchTable);
              GLOBALFREE(hSearchTable);
              hSearchTable = NULLID;
          }
          break;
          
      case 'N':
          if (OBJECT_TYPE(BrSelection.idObj) == CLASS)
              ShowSubNodesCB(CLASS, BrSelection.idObj, OBJECT, BR_TOGGLE);
          return TRUE;
          
      case 'R':
          RenameSelectedObject(hWnd);
          return TRUE;
        
      case 'U':
          SetClBrowserFocusCB(CLASS, lpIDs->idRootClass);
          return TRUE;
          
      case 'W':
          SaveSelectedItems();
          return TRUE;
    }
#endif
    
    return FALSE;
}
예제 #16
0
static BOOL FillSearchArray(HWND hWnd, char c)
{
    switch (c) {
      case VK_DELETE:
      case VK_BACK:
          c = VK_DELETE;
          if (cCount)
              SearchedName[--cCount] = '\0';
          break;
      case VK_RETURN:
          PostMessage(GetParent(hWnd), WM_COMMAND, IDOK, 0L);
          break;
      case VK_CLEAR:
      case VK_HOME:
          cCount = 0;
          SearchedName[0] = '\0';
          SetWindowText(hFind, "");
          break;
      case VK_SPACE:
          if (SearchedMin[0] != 127)
          {
              cCount = strlen(SearchedMin);
              strcpy(SearchedName, SearchedMin);
              SetWindowText(hFind, SearchedName);
              SendMessage(hFind, WM_KEYDOWN, VK_END, 0L);
              SendMessage(hFind, WM_KEYUP, VK_END, 0L);
          }
          break;
      default:
          if (cCount < NAME_LEN)
          {
              SearchedName[cCount++] = c;
              SearchedName[cCount] = '\0';
          }
    }
    
    if (cCount == 1 && c != VK_DELETE)
    {
        memset(SearchedMin, 127, NAME_LEN);
        SearchedMin[NAME_LEN] = '\0';
        SearchedObject = NULLID;
        KppEnumItem(CLASS, AddObject, NULL);
        KppEnumItem(OBJECT, AddObject, NULL);
    }
    else if (cCount && c != VK_DELETE && cCount < NAME_LEN && hSearchTable)
        MarkObjects();
    else if (!cCount && hSearchTable)
    {
        memset(SearchedMin, 127, NAME_LEN);
        SearchedObject = NULLID;
        SetWindowText(hName, "");
        GLOBALUNLOCK(hSearchTable);
        GLOBALFREE(hSearchTable);
        hSearchTable = NULL;
    }
    else if (c == VK_DELETE && hSearchTable)
        UnmarkObjects();
    
    if (SearchedMin[0] != 127)
    {
        WORD wType;
        
        SetWindowText(hName, SearchedMin);
        SearchedObject = KppGetObjectId(KppAddAtom(SearchedMin), &wType);
    }
    else if (cCount)
        MessageBeep(0);
    
    return c != VK_SPACE;
}
예제 #17
0
BOOL PEXPORT KppWriteKalFile(LPSTR lpPathName)
{
    FARFILE interpFile, saved_value = outFile;
    BOOL bRet;
    LPSTR lpComment;
    GLOBALHANDLE hComment;
    char tempname[FILENAME_MAX];
    OFSTRUCT of;
    
    if (KppGetWriteFile())
    {
        KppRegisterKappaMessage(hResThisDll, IDE_FALREADYOPEN, lpIDs->idError,
                                lpIDs->idNull, NULLID);
        PostKappaMessage();

        return FALSE;
    }

    OpenFile(lpPathName, &of, OF_PARSE);
    
    hComment = GLOBALALLOC(GHND | GMEM_SHARE, (DWORD) MAX_COMMENT_SIZE);
    lpComment = GLOBALLOCK(hComment);

    if (!KppBeforeWriteKalFileCB(of.szPathName, lpComment, MAX_COMMENT_SIZE))
    {
        GLOBALUNLOCK(hComment);
        GLOBALFREE(hComment);
        return FALSE;
    }
    
    GetTmpFileNameOnDrive(of.szPathName[0], tempname);
    interpFile = fopen_share(tempname, "w");
    if (!CheckFreeSpace(of.szPathName))
        return FALSE;
    
    if (!interpFile)
    {
        KppRegisterKappaMessage(hResThisDll, IDE_FCANTOPEN, lpIDs->idError,
                                KppAddAtom("Temp Save File"), NULLID);
        PostKappaMessage();

        return FALSE;
    }

    UnwindProtect(cleanup);
    outFile = interpFile;
    bRet = WriteKalFile(interpFile, lpComment);
  cleanup:
    outFile = saved_value;
    GLOBALUNLOCK(hComment);
    GLOBALFREE(hComment);
    EndProtect();

    /* Check for any potential write errors and delete the file if any *
     * occurred.                                                       */
    if (!bRet && ferror(interpFile))
    {
        KppRegisterKappaMessage(hResThisDll,
                                IDE_WRITEERROR, KppAddAtom(lpPathName),
                                NULLID, NULLID);
        KppPostKappaErrorMessageCB();
        KppRegisterKappaMessage(hResThisDll, IDE_WRITEERROR2,
                                NULLID, NULLID, NULLID);
        KppPostKappaErrorMessageCB();
        fclose(interpFile);
        remove(tempname);

        return KppAfterWriteKalFileCB(lpPathName, FALSE);
    }

    if (fclose(interpFile))
    {
        KppRegisterKappaMessage(hResThisDll, IDE_FOUTOFDISK,
                                KppAddAtom(of.szPathName), NULLID, NULLID);
        KppPostKappaErrorMessageCB();
        remove(tempname);

        return FALSE;
    }
        
    if (remove(lpPathName) && errno != ENOENT ||
        rename(tempname, lpPathName))
    {
        KppRegisterKappaMessage(hResThisDll, IDE_PERMISSION,
                                KppAddAtom(of.szPathName), NULLID, NULLID);
        KppPostKappaErrorMessageCB();
        remove(tempname);

        return FALSE;
    }
    else        
    {
        ATOMID idFile = KppAddAtom(lpPathName);
        
        KppEnumItem(FUNC, KppSetItemSavedInfo, (LPSTR) (long) idFile);
        KppEnumItem(METHOD, KppSetItemSavedInfo, (LPSTR) (long) idFile);
        remove_temp_save_file();

        KppDeleteList(idTimeStamps);
        idTimeStamps = NULLID;
        SaveFileTimeStamp(idFile, NULL, lpPathName);
    }

    return KppAfterWriteKalFileCB(lpPathName, TRUE);
}
예제 #18
0
GLOBALHANDLE PEXPORT KppGetBodyFromFile(int idFile, 
                                        unsigned long lBegin,
                                        WORD wLen, LPSTR lpMode, BOOL bWarn)
{
    FILE *fp;
    GLOBALHANDLE hMem;
    LPSTR lpMem;
    BOOL bRes;
    
    if (idFile == -1)
        fp = fopen_share(KppGetTmpSaveFileName(), lpMode);
    else if (!idFile)
        return NULL;
    else
    {
        char filename[FILENAME_MAX];
        
        KppGetAtomName(idFile, filename, FILENAME_MAX);

        fp = fopen_share(filename, lpMode);
        if (fp)
        {
            struct stat fpstat;
            long st_atime = GetFileTimeStamp(idFile);
            
            fstat(fileno(fp), &fpstat);
            if (fpstat.st_atime != st_atime)
            {
                fclose(fp);
                return NULL;
            }
        }
        else if (bWarn)
            KppPostKappaMessageCB(NULL);
    }
    if (!fp)
        return NULL;
    
    if (fseek(fp, lBegin, SEEK_SET))
    {
        fclose(fp);
        return NULL;
    }

    hMem = GLOBALALLOC(GHND, wLen + 2);
    if (!hMem)
    {
        fclose(fp);
        return NULL;
    }
    lpMem = GLOBALLOCK(hMem);
    
    fread(lpMem, 1, wLen, fp);
    bRes = !ferror(fp);
    
    fclose(fp);
    
    if (lpMode[1] != 'b')
    {
        WORD i = 0;
        LPSTR s = NULL;
        LPSTR p = lpMem;
        
        while ((s = strchr(p + 1, '\n')) && (s - lpMem) + ++i < wLen) p = s;
        p[wLen - ((p - lpMem) + i - (s != NULL))] = '\0';
    }
    
    GLOBALUNLOCK(hMem);
    
    if (bRes)
        return hMem;
    
    GLOBALFREE(hMem);
    
    return NULL;
}
예제 #19
0
HDDEDATA W_CALLBACK KapDDECallBack(WORD wTran, WORD wFmt, HCONV hConv,
				   HSZ hsz1, HSZ hsz2, HDDEDATA hData,
				   DWORD dwData1, DWORD dwData2)
{
    switch (wTran) {
      case XTYP_ADVSTART:
      case XTYP_ADVSTOP:
      {
          BOOL bRes = FALSE;
    
          if (wFmt == CF_TEXT)
          {
              char *cl;
              
              if (!DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                                  RET_BUFFER_LEN, CP_WINANSI))
                  return (HDDEDATA) FALSE;
              
              cl = strchr(return_buffer, ':');
              if (cl)
              {
                  DDEINFO ddeInfo;
                  ATOMID idName;
                  WORD wType;
                  
                  cl[0] = '\0';
                  idName = KppAddAtom(return_buffer);
                  ddeInfo.idSlot = KppAddAtom(cl + 1);
                  ddeInfo.idObj = KppGetObjectId(idName, &wType);
                  ddeInfo.idApp = ddeInfo.idItem = NULLID;
                  ddeInfo.idTopic = HszToAtom(hsz1);
                  ddeInfo.hConv = hConv;
                  
                  if (ddeInfo.idObj)
                  {
                      UnwindProtect(cleanup1);
                      requests++;
                      switch (wTran) {
                        case XTYP_ADVSTART:
                            if (CreateLink(&ddeInfo))
                                bRes = TRUE;
                            break;
                        case XTYP_ADVSTOP:
                            if (CloseServerLink(&ddeInfo, idName))
                                bRes = TRUE;
                            break;
                      }
                    cleanup1:
                      requests--;
                      EndProtect();
                  }
              }
          }

          return (HDDEDATA) bRes;                  
      }

      case XTYP_EXECUTE:
      {
          DWORD dwLen;
          LPBYTE lpByte = DdeAccessData(hData, &dwLen);
          
          if (lpByte)
          {
              BOOL bFree = FALSE;
              LPBYTE lpCopy;

              if (dwLen < RET_BUFFER_LEN)
              {
                  strcpy(return_buffer, lpByte);
                  lpCopy = return_buffer;
              }
              else
              {
                  lpCopy = strdup(lpByte);
                  bFree = TRUE;
              }
              DdeUnaccessData(hData);
          
              if (lpCopy)
              {
                  UnwindProtect(cleanup2);
                  requests++;
                  if (!KppEvalExpString(lpCopy))
                      KppPostKappaErrorMessageCB();
                cleanup2:
                  requests--;
                  if (bFree)
                      free(lpCopy);
                  EndProtect();
                  
                  return (HDDEDATA) DDE_FACK;
              }
          }
           
          return (HDDEDATA) DDE_FNOTPROCESSED;
      }
          
      case XTYP_CONNECT:
          if (DdeQueryString(dwDDEInst, hsz1, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))
          {
              char *dot = strrchr(return_buffer, '.');

              if (dot)
                  dot[0] = '\0';
              
              if (!stricmp(DDETopicName, return_buffer) ||
#ifdef MULTI
                  !stricmp(DDEKappaName, return_buffer) ||
                  S_ILOC == 0 &&
#endif
                  !stricmp("KAPPA", return_buffer))
                  return TRUE;
          }
          
          return (HDDEDATA) FALSE;
          
      case XTYP_DISCONNECT:
          UnwindProtect(cleanup3);
          requests++;
          DeleteDDETasks(hConv);
        cleanup3:
          requests--;
          EndProtect();
          return (HDDEDATA) NULL;
          
      case XTYP_WILDCONNECT:
      {
          HSZPAIR hszPair[3];
              
          hszPair[0].hszSvc = 
              DdeCreateStringHandle(dwDDEInst, DDEAppName, CP_WINANSI);
          hszPair[0].hszTopic = 
              DdeCreateStringHandle(dwDDEInst, DDETopicName, CP_WINANSI);
          hszPair[1].hszSvc = 
              DdeCreateStringHandle(dwDDEInst, DDEAppName, CP_WINANSI);
          hszPair[1].hszTopic = 
              DdeCreateStringHandle(dwDDEInst, DDEKappaName, CP_WINANSI);
          hszPair[2].hszSvc = hszPair[2].hszTopic = NULL;
          
          return DdeCreateDataHandle(dwDDEInst, (LPVOID) hszPair,
                                     sizeof(HSZPAIR) * 3, 0, 
                                     hszPair[0].hszSvc, CF_TEXT, 0);
      }
          
      case XTYP_POKE:
      {
          UINT flag = DDE_FNOTPROCESSED;
          
          if (wFmt == CF_TEXT &&
              DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))              
          {
              ATOMID idSlot;
              OBJECTID idObj;
              
              UnwindProtect(cleanup4);
              requests++;
              idObj = ObjSlotFromItem(return_buffer, &idSlot);
              if (idObj && StoreData(lpIDs->idNull, hData, idObj, idSlot))
                  flag = DDE_FACK;
            cleanup4:
              requests--;
              EndProtect();
          }

          return (HDDEDATA) flag;
      }
          
      case XTYP_REQUEST:
      case XTYP_ADVREQ:
          hData = (HDDEDATA) DDE_FNOTPROCESSED;
          if (wFmt == CF_TEXT &&
              DdeQueryString(dwDDEInst, hsz2, return_buffer, 
                             RET_BUFFER_LEN, CP_WINANSI))              
          {
              ATOMID idSlot;
              OBJECTID idObj;
              
              UnwindProtect(cleanup5);
              requests++;
              idObj = ObjSlotFromItem(return_buffer, &idSlot);
              if (idObj)
              {
                  BOOL bMulti = FALSE;
                  ITEMID idValue =
                      Kpp_Get_SlotAnyValue(OBJECT_TYPE(idObj),
                                           idObj, idSlot, (LPWORD) &bMulti);
                  GLOBALHANDLE hMem = NULL;
                  LPBYTE lpBytes = NULL;
                  DWORD dwLen = ValueToString(idValue, bMulti, 
                                              &hMem, &lpBytes);
                  
                  if (dwLen)
                  {
                      hData = DdeCreateDataHandle(dwDDEInst, lpBytes, dwLen,
                                                  0, hsz2, CF_TEXT, 0);
                      if (hMem)
                      {
                          GLOBALUNLOCK(hMem);
                          GLOBALFREE(hMem);
                      }
                      if (!hData)
                          hData = (HDDEDATA) DDE_FNOTPROCESSED;
                  }
              }
            cleanup5:
              requests--;
              EndProtect();
          }
          return hData;              
        
      case XTYP_REGISTER:
      {
          ATOMID idApp = HszToAtom(hsz2);
          
          UnwindProtect(cleanup6);
          requests++;
          if (idApp)
          {
              WORD wType;
              OBJECTID idService = KppGetObjectId(idApp, &wType);
              
              if (!idService)
              {
                  idService = KppMakeCO(OBJECT, idApp, idDDEService);
                  wType = OBJECT;
              }
              if (idService)
              {
                  if (DdeQueryString(dwDDEInst, hsz1, return_buffer, 
                                     RET_BUFFER_LEN, CP_WINANSI))
                      Kpp_Set_SlotValue(wType, idService, Slot(idService),
                                        KppAddAtom(return_buffer), EXPATOM);
                  else
                      Kpp_Set_SlotValue(wType, idService, Slot(idService),
                                        lpIDs->idNull, EXPATOM);
              }
          }
        cleanup6:
          requests--;
          EndProtect();
          
          return (HDDEDATA) NULL;
      }
        
      case XTYP_ADVDATA:
          UnwindProtect(cleanup7);
          requests++;
          if (wFmt == CF_TEXT)
          {
              CONVINFO ci;
              ATOMID idApp, idItem, idName;
              OBJECTID idLink;
              
              memset(&ci, 0, sizeof(CONVINFO));
              ci.cb = sizeof(CONVINFO);
              DdeQueryConvInfo(hConv, QID_SYNC, &ci);
              idApp = HszToAtom(ci.hszSvcPartner);
              idItem = HszToAtom(hsz2);
              idName = LinkName(idApp, idItem);
              idLink = FindLink(idName);
              
              if (idLink)
              {
                  WORD wDestType;
                  ATOMID idDest = Kpp_Get_SlotValue(OBJECT, idLink,
                                                    Slot(idDDEObject));
                  ATOMID idSlot = Kpp_Get_SlotValue(OBJECT, idLink,
                                                    Slot(idDDESlot));
                  OBJECTID idDestObj = KppGetObjectId(idDest, &wDestType);
              
                  StoreData(lpIDs->idNull, hData, idDestObj, idSlot);
              }
          }
        cleanup7:
          requests--;
          EndProtect();
          
          return (HDDEDATA) DDE_FACK;
          
      case XTYP_XACT_COMPLETE:
      {
          char name[20];
          OBJECTID idTask;
          ATOMID idName;
          WORD wType;
          
          UnwindProtect(cleanup8);
          requests++;
          task_name(name, hConv, dwData1);
          idName = KppAddAtom(name);
          idTask = KppGetObjectId(idName, &wType);
          
          if (idTask)
          {
              CONVINFO ci;

              memset(&ci, 0, sizeof(CONVINFO));
              ci.cb = sizeof(CONVINFO);
              DdeQueryConvInfo(hConv, dwData1, &ci);
          
              switch (ci.wType) {
                case XTYP_REQUEST:
                    if (wFmt == CF_TEXT)
                    {
                        WORD wDestType;
                        ATOMID idDest = Kpp_Get_SlotValue(wType, idTask, 
                                                          Slot(idDDEObject));
                        ATOMID idSlot = Kpp_Get_SlotValue(wType, idTask, 
                                                          Slot(idDDESlot));
                        OBJECTID idDestObj = KppGetObjectId(idDest, 
                                                            &wDestType);
              
                        StoreData(lpIDs->idNull, hData, idDestObj, idSlot);
                        DdeDisconnect(hConv);              
                    }
                    break;
                    
                case XTYP_POKE:
                case XTYP_EXECUTE:
                    DdeDisconnect(hConv);              
                    break;
                    
                case (XTYP_ADVSTART | XTYPF_ACKREQ):
                {
                    ATOMID idDest =
                        Kpp_Get_SlotValue(wType, idTask, Slot(idDDEObject));
                    WORD wDestType;
                    DDEINFO ddeInfo;

                    ddeInfo.hConv = hConv;
                    ddeInfo.idApp = Kpp_Get_SlotValue(wType, idTask, 
                                                      Slot(idService));
                    ddeInfo.idTopic = Kpp_Get_SlotValue(wType, idTask, 
                                                        Slot(idTopic));
                    ddeInfo.idItem = Kpp_Get_SlotValue(wType, idTask, 
                                                       Slot(idItem));
                    ddeInfo.idObj = KppGetObjectId(idDest, &wDestType);
                    ddeInfo.idSlot = Kpp_Get_SlotValue(wType, idTask, 
                                                       Slot(idDDESlot));
              
                    CreateLink(&ddeInfo);
                    break;
                }
              }

              DeleteDDETask(lpIDs->idNull, wType, idTask, (LPVOID) &hConv);
          }
        cleanup8:
          requests--;
          EndProtect();
          
          return (HDDEDATA) NULL;
      }
          
      default:
          return (HDDEDATA) NULL;
    }
}
예제 #20
0
void PEXPORT KppReplaceAtomInText(LPFUNC lpFunc,
				  ATOMID idAtom, LPREPLACEKEY rk)
{
    int idFile = BFILE(lpFunc);
    unsigned long lBegin = BFPOS(lpFunc);
    WORD wLen = BFLEN(lpFunc);
    GLOBALHANDLE hMem;
    LPSTR lpMem, lpAtom, lpBegin, lpEnd, lpPrev;
    FILE *fp = NULL;
    char atom[RET_BUFFER_LEN];
    WORD wAtomLen;
    
    if (!rk->wLen)
        return;
    wAtomLen = KppGetAtomName(idAtom, atom, RET_BUFFER_LEN);
    if (!wAtomLen)
        return;
    
    hMem = KppGetBodyFromFile(idFile, lBegin, wLen, "rb", TRUE);
    if (!hMem)
        return;
    
    lpMem = GLOBALLOCK(hMem);
    
    if (idFile != -1)
    {
        lpMem = KppExtractBody(lpMem, TRUE);
        if (!lpMem)
        {
            GLOBALUNLOCK(hMem);
            GLOBALFREE(hMem);
            return;
        }
    }
    
    lpPrev = NULL;
    lpBegin = lpMem;
    while (lpAtom = find_match(rk, lpMem, atom, &lpEnd, wAtomLen)) {
        if (is_atom_match(lpMem, &lpAtom, &lpEnd, &lpPrev, rk, wAtomLen))
        {
            if (!fp)
            {
                fp = fopen_share(KppGetTmpSaveFileName(), "ab");
                if (!fp)
                {
                    GLOBALUNLOCK(hMem);
                    GLOBALFREE(hMem);
                    return;
                }
                else
                {
                    fputc('\r', fp);
                    fputc('\n', fp);
                    lBegin = ftell(fp);
                }
            }

            if (lpAtom > lpBegin)
                fwrite(lpBegin, 1, lpAtom - lpBegin, fp);
                
            if (rk->rx)
            {
                char replace[RET_BUFFER_LEN];
                BOOL bTruncated;
                
                KppRegsub(rk->rx, rk->lpReplace, replace, RET_BUFFER_LEN,
                          &bTruncated);
                fputs(replace, fp);
            }
            else
                fputs(rk->lpReplace, fp);
            
            lpBegin = lpEnd;
        }
        else if (fp)
        {
            fwrite(lpMem, 1, (lpAtom - lpMem) + wAtomLen, fp);
            lpBegin = lpEnd;
        }

        lpMem = lpEnd;
    }
                           
    if (fp)
    {
        fputs(lpMem, fp);
        BFILE(lpFunc) = -1;
        BFPOS(lpFunc) = lBegin;
        BFLEN(lpFunc) = ftell(fp) - lBegin;
        fclose(fp);
    }
    
    GLOBALUNLOCK(hMem);
    GLOBALFREE(hMem);
}