_EdGetEnv( ) API Library Routine Example

The following example opens an editing session for a file specified by a parameter and displays each field of the EDENV structure for that file as returned by _EdGetEnv( ).

Visual FoxPro Code

SET LIBRARY TO EDGETENV
= EDGETENV("x")

C Code

#include <pro_ext.h>

void putLong(unsigned long n)
{
   Value val;

   val.ev_type = 'I';
   val.ev_long = n;
   val.ev_width = 6;

   _PutValue(&val);
}

FAR Example(ParamBlk FAR *parm)
{
#define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle))

   WHANDLE wh;
   EDENV EdEnv;
   EDPOS edpos;

   if (!_SetHandSize(parm->p[0].val.ev_handle,
      parm->p[0].val.ev_length+1))
   {
      _Error(182); // "Insufficient memory"
   }
   pFILENAME[parm->p[0].val.ev_length] = '\0';

   _HLock(parm->p[0].val.ev_handle);
   wh = _EdOpenFile(pFILENAME, FO_READONLY);
   _HUnLock(parm->p[0].val.ev_handle);

   _EdGetEnv(wh, &EdEnv);

   _PutStr("\nfilename: ");    _PutStr(EdEnv.filename);
   _PutStr("\nlength: ");    putLong(EdEnv.length);
   _PutStr("\nlenLimit: ");    putLong(EdEnv.lenLimit);
   _PutStr("\ndirty: ");     putLong(EdEnv.dirty);
   _PutStr("\nautoIndent: ");  putLong(EdEnv.autoIndent);
   _PutStr("\nbackup: ");    putLong(EdEnv.backup);
   _PutStr("\naddLineFeeds: ");  putLong(EdEnv.addLineFeeds);
   _PutStr("\nautoCompile: ");   putLong(EdEnv.autoCompile);
   _PutStr("\naddCtrlZ: ");    putLong(EdEnv.addCtrlZ);
   _PutStr("\nsavePrefs: ");   putLong(EdEnv.savePrefs);
   _PutStr("\ndragAndDrop: ");   putLong(EdEnv.dragAndDrop);
   _PutStr("\nreadOnly: ");    putLong(EdEnv.readOnly);
   _PutStr("\nstatus: ");    putLong(EdEnv.status);
   _PutStr("\nlockPrefs: ");   putLong(EdEnv.lockPrefs);
   _PutStr("\ninsertMode: ");  putLong(EdEnv.insertMode);
   _PutStr("\nwrap: ");    putLong(EdEnv.wrap);
   _PutStr("\nselStart: ");    putLong(EdEnv.selStart);
   _PutStr("\nselEnd: ");    putLong(EdEnv.selEnd);
   _PutStr("\nselAnchor: ");   putLong(EdEnv.selAnchor);
   _PutStr("\njustMode: ");    putLong(EdEnv.justMode);
   _PutStr("\ntabWidth: ");    putLong(EdEnv.tabWidth);
   _PutStr("\nfontName: ");    _PutStr(EdEnv.fontName);
   _PutStr("\nfontSize: ");    putLong(EdEnv.fontSize);
   _PutStr("\nfontStyle: ");   putLong(EdEnv.fontStyle);
   _PutStr("\nkind: ");    putLong(EdEnv.kind);
}

FoxInfo myFoxInfo[] = {
   {"EDGETENV", (FPFI) Example, 1, "C"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};