#ifndef APP_NAME #include "vibrant.h" #include "document.h" #ifdef VAR_ARGS #include #else #include #endif #include #include /* 1.1 30.10.1996 - 10.02.1997 */ /* 1.2 10.02.1997 - 01.04.1997 */ /* 1.3 01.04.1997 - 01.10.1997 */ /* 1.4 01.10.1997 - 08.09.1998 */ /* 1.5 08.09.1998 - xx.xx.199x */ #define VERSION "1.5" /*************/ /* Temporary */ #define LINKIN 0 /* to link window functions library with kernel */ #define LINKIN_3D 1 #define LINKIN_TAB 0 #define LINKIN_NUM 0 #define LINKIN_1S 0 #define LINKIN_2D 1 #define MYSWITCH 1 /* Use own Switch instead of SwitcH */ /* MUST be the same as in autodif.h */ #define ED 1 /* support External Differentiator (maple only) */ /******************/ /* Debug switches */ #define DEB 1 /* Main debug switch */ #ifdef INSTALL #undef DEB #define DEB 0 /* No debug */ #endif #define DEB_DL 1&DEB /* DataLib */ #define DEB_VIS 1&DEB /* Visual */ #define DEB_CT 1&DEB /* Curve Type */ #define DEB_PAR 1&DEB /* Parameters */ #define DEB_MEM 1&DEB /* Memory management */ #define DEB_LIB 1&DEB /* Libraries management */ #undef CS #define CS DEB /* see _linalg.c, _rdalg.c, etc */ #if DEB void Abend(void); void PrintRect(RectPtr pr, CharPtr t); #endif #if DEB_MEM void Debug_MemTrace(Int2 index); Boolean Debug_MemTrace_Status(Int2 index); void _InitDebMem(void); /* see utility.c */ void _TermDebMem(void); Pointer __MemNew(size_t size, CharPtr FileName, int Line); Pointer __MemGet(size_t size, unsigned int clear, CharPtr FileName, int Line); Pointer LIBCALL __MemFree(Pointer ptr, CharPtr FileName, int Line); Pointer LIBCALL __MemMore(Pointer ptr, size_t size, CharPtr FileName, int Line); Pointer LIBCALL __MemExtend(Pointer ptr, size_t size, size_t oldsize, CharPtr FileName, int Line); CharPtr LIBCALL __StringSave(const char FAR *ptr, CharPtr FileName, int Line); Pointer LIBCALL __BSMerge(ByteStorePtr bsp, Pointer buffer, CharPtr FileName, int Line); #define _MemNew(size) __MemNew(size,__FILE__,(int)__LINE__) #define _MemGet(size,clear) __MemGet(size,clear,__FILE__,(int)__LINE__) #define _MemFree(ptr) __MemFree(ptr,__FILE__,(int)__LINE__) #define _MemMore(ptr,size) __MemMore(ptr,size,__FILE__,(int)__LINE__) #define _MemExtend(ptr,size,old) __MemExtend(ptr,size,old,__FILE__,(int)__LINE__) #define _StringSave(ptr) __StringSave(ptr,__FILE__,(int)__LINE__) #define _BSMerge(bsp,buffer) __BSMerge(bsp,buffer,__FILE__,(int)__LINE__) void DebugMsg(CharPtr format,...); #else #define __MemNew MemNew #define __MemGet MemGet #define __MemFree MemFree #define __MemMore MemMore #define __MemExtend MemExtend #define __StringSave StringSave #define __BSMerge BSMerge #define _MemNew MemNew #define _MemGet MemGet #define _MemFree MemFree #define _MemMore MemMore #define _MemExtend MemExtend #define _StringSave StringSave #define _BSMerge BSMerge #endif #if DEB_LIB void _InitDebLib(void); void _TermDebLib(void); #endif /********************/ /* Temporary fixups */ #define ZAP1 0 /* UNIX. Error in ProcessAnEvent. See ____test.c #1 */ #define ZAP2 1 /* PC. Main window menu item creates a FixedWindow with a button. Its callback creates a ModalWindow with button. After its callback Removes the ModalWindow everything crushes. See ____test.c #2 */ #define ZAP3 1 /* ALL. GetTitle returns non null-terminated string if the length of title is not less than the buffer length in GetTitle call */ #if ZAP1 && defined(OS_UNIX) static char *event_names[]={ "", "", "KeyPress", "KeyRelease", "ButtonPress", "ButtonRelease", "MotionNotify", "EnterNotify", "LeaveNotify", "FocusIn", "FocusOut", "KeymapNotify", "Expose", "GraphicsExpose", "NoExpose", "VisibilityNotify", "CreateNotify", "DestroyNotify", "UnmapNotify", "MapNotify", "MapRequest", "ReparentNotify", "ConfigureNotify", "ConfigureRequest", "GravityNotify", "ResizeRequest", "CirculateNotify", "CirculateRequest", "PropertyNotify", "SelectionClear", "SelectionRequest", "SelectionNotify", "ColormapNotify", "ClientMessage", "MappingNotify" }; #undef Boolean #include extern XtAppContext Nlm_appContext; /* defined in Vibrant */ static void myProcessAnEvent(void) { XEvent event; if (XtAppPending(Nlm_appContext)&XtIMXEvent) { XtAppNextEvent(Nlm_appContext,&event); XtDispatchEvent(&event); } } #else #define myProcessAnEvent ProcessAnEvent #endif /*********************************************************************/ /*--------------------------------------------*/ /* Set appropriate platform-dependent symbols */ #ifdef WIN_MSWIN #define OS_DEF #define _WIN 1 #define _MAC 0 #define _UNIX 0 #endif #ifdef WIN_MAC #define OS_DEF #define _WIN 0 #define _MAC 1 #define _UNIX 0 #endif #ifdef OS_UNIX #define _WIN 0 #define _MAC 0 #define _UNIX 1 /* suffix _UNIX with ncbilcl's suffix (see corelib/ncbilcl.*) */ #if defined(OS_UNIX_IRIX) #define OS_DEF #define _UNIX_SGI #endif #if defined(PROC_SPARC) && defined(COMP_SUNPRO) #define OS_DEF #define _UNIX_SOL #endif #if defined(PROC_HPPA) #define OS_DEF #define _UNIX_HP #endif #if defined(PROC_ALPHA) && defined(OS_UNIX_OSF1) #define OS_DEF #define _UNIX_ALF #endif #if defined(PROC_I80X86) && defined(OS_UNIX_LINUX) #define OS_DEF #define _UNIX_LNX #endif #if defined(PROC_POWER) && defined(OS_UNIX_AIX) #define OS_DEF #define _UNIX_R6K /* AIX for RS 6000 */ #endif #endif #ifdef OS_DEF #undef OS_DEF #else #error Cannot determine kind of OS! #endif #if _WIN #include #endif /* Application's name */ #define APP_NAME "content" /****************************************/ /* Defenitions related to settings file */ /****************************************/ #define STR_NL "~" /* substituted by \n when read and replaces \n when write */ #define CHAR_NL '~' /* Unix: ~ cannot be used in dirnames */ #define STR_EMPTY "`" /* denotes empty string */ #define SFS_PATHS "Paths" /* Paths */ #define SFS_EXTENSIONS "Extensions" /* Extensions */ #define SFS_MAINWIN "MainWindow" /* Main Windows' attributes */ #define SFS_LIBRARIES "Libraries" /* Libraries names section */ #define SFS_FUNCTIONS "Functions" /* Names of functions in libraries */ #define SFS_FILES "Files" /* Files */ #define SFS_CURRENTS "Currents" /* Currents */ #define SFS_CURVES "Curves" #define SFS_COMPILER "Compiler" #define SFS_VISUAL "Visual" /* Visualizer's data */ #define SFS_PARAMS "Params" /* Numerical params manager's stuff */ #define SFS_KERNELERRORS "KernelErrors" /* Kernel error messages */ #define SFS_HELP "Help" /* Help */ /********************************/ /* Library-management functions */ /********************************/ /*--------------------------*/ /* OS-dependent definitions */ #if _WIN #define LibHandle Handle /* library handle */ #define Local(Type) static Type #define Global(Type) Type #define GlobalPtr(Type,Name,Params) Type (PNTR Name)Params #ifdef __DLL__ #define EntryPtr(Type,Name,Params) Type PASCAL (PNTR PASCAL _export Name)Params #define Entry(Type) Type FAR PASCAL _export /* If we are in a DLL we have to: - define LibMain function (which does nothing), and - resolve a refernce to _psp made by some NCBI routine. */ #pragma argsused int FAR PASCAL LibMain(Uint2 hinst, Uint2 wDataSeg, Uint2 cbHeap, CharPtr lpszCmdLine) { return 1; } unsigned _Cdecl _psp; #if defined(WIN32) #define Callback Local #else #define Callback Entry #endif /* defined(WIN32) */ #else /* __DLL__ */ #define EntryPtr(Type,Name,Params) Type PASCAL (PNTR Name)Params #define Entry(Type) Type #define Callback Local #endif /* __DLL__ */ #endif /* _WIN */ #if _MAC #error Interface to Dynamical Libraries management is not defined #endif #if _UNIX #define LibHandle VoidPtr #define Local(Type) static Type #define Global(Type) Type #define GlobalPtr(Type,Name,Params) Type (PNTR Name)Params #define EntryPtr(Type,Name,Params) Type (PNTR Name)Params #define Entry(Type) Type #define Callback Local #endif /* End of OS-dependent definitions */ /*---------------------------------*/ /* Locks a library in memory */ Global(LibHandle) LibraryLock(CharPtr Lib); /* Unlocks the library */ Global(LibHandle) LibraryUnlock(LibHandle hLib); /* Retrieves the address of the given library function */ GlobalPtr(void,LibraryFuncAddress(LibHandle hLib, CharPtr Name),()); GlobalPtr(void,LibraryFuncAddressCond(LibHandle hLib, CharPtr Name),()); /* Unlock support for DLLs */ enum { LH_HELP, /* conthelp */ LH_ }; /* List of libs whose handles must be set to 0 during unload */ extern Global(LibHandle) LibHandles[LH_]; /***typedef void (LIBCALLBACK *LibTermProc)();***/ typedef EntryPtr(void,LibTermProc,(void)); Global(void) LibraryUnlockRequest(LibHandle hLib, LibTermProc termproc); Global(void) LibraryUnlockRequested(void); Global(void) LibraryUnlockAll(void); /****************************/ /* Settings file management */ /****************************/ Global(Boolean) GetConfigFilePath(void); #define PAR_BUF 500 /* max line len in settings file */ extern Global(Char) ParBuf[PAR_BUF]; /* buffer */ /* Translates symbolical references to settings file */ Global(Boolean) Translate(CharPtr Buf, CharPtr Section, CharPtr Key); /* Reads a value from the settings file and put it into the buffer */ Global(CharPtr) GetParam(CharPtr Section, CharPtr Key,...); /* Reads a string from the settings file and put it to the buffer */ Global(CharPtr) GetParamString(CharPtr Section, CharPtr Key); /* Reads a value from the settings file and append it to the buffer */ Global(CharPtr) GetParamAppend(CharPtr,CharPtr); /* Writes a string to the settings file */ Global(void) SetParam(CharPtr Section, CharPtr Key, CharPtr Value); /***************************/ /* Error messages handling */ /***************************/ /* Issues a warning message. */ Global(Int2) Warning(CharPtr Key,...); /*******************/ /* Context support */ /*******************/ Global(void) PushContext(CharPtr HelpCode, KeyProc KeyAction, CharPtr Text); Global(void) PopContext(void); Global(CharPtr) GetHelpKey(void); /*******************/ /* Dialog routines */ /*******************/ Global(CharPtr) GetButtonTitle(CharPtr Title); Global(Int2) Spacing(Int2 len, Boolean horiz, ...); Global(Int2) Ask(CharPtr Prompt, CharPtr Buf, Int2 Len); Global(void) myMessageSetUser(void (*)(GrouP g)); Global(MsgAnswer) CDECL myMessage(Int2 sevkey, const CharPtr fmt, ...); Global(Int2) myWarning(CharPtr Key,...); /* uses myMessage */ typedef Int2 (PNTR EditorNotifyPtr)(CharPtr); Global(TexT) CreateEditor(GrouP parent, CharPtr dfault, Int2 width, Int2 height, EditorNotifyPtr notify, TxtActnProc check); Global(TexT) EditorText(void); Global(TexT) EditorActiveText(void); Global(void) EditTextSelect(TexT t); typedef Boolean (PNTR EditorRepCheck)(TexT t, CharPtr what, CharPtr by); Global(void) EditorSetRepCheck(EditorRepCheck checker); Global(void) GetTitleAndSave(TexT t, CharPtr PNTR indirptr); /* Menu item descriptor. Title is a Key name under given section (see CreateMenu). The value of the key has the following structure: [| - || any_text [| { || } |] |] where: - if any_text is the minus sign ('-') it means menu separator. any_text is visible title of the item. If the last character is '?' then it is a StatusItem, otherwise it is a CommandItem. { marks the begining of a submenu and any_test is a submenu name. } marks the end of a submeu (i.e. the item is the last one in a submenu). [ Similary, brackets mark the begining and the end ] of ChoiceGroup. */ typedef void (PNTR ActionPtr)(Int2 index); typedef Boolean (PNTR EnablePtr)(Int2 index); typedef enum { MENU_PULLDOWN, MENU_SUB, MENU_CHOICEGRP, MENU_COMMAND, MENU_CHOICE, MENU_STATUS, MENU_SEP } MenuItemKind; typedef struct { Int2 Title; ActionPtr Action; /* Does an action associated with the item */ EnablePtr EnableDisable; /* Determines status of the item (Enabled or Disabled) */ Int2 UserIndex; /* Creator's private data */ Int1 Flags; #define MNFL_ACTIVEINPAUSE 1 /* Activate in pause mode */ IteM ItemId; /* Stores Item's id */ MenuItemKind Kind; /* pulldown, submenu, etc. */ } MenuItem, PNTR MenuItemPtr; typedef struct { MenuItemPtr Menu; /* to array of MenuItems */ Char Num; /* dim of the array */ Char Lock; /* lock of the menu */ CharPtr PNTR Texts; /* used if texts==NULL in call to CreateMenu */ } MenuDesc, PNTR MenuDescPtr; Global(void) CreateMenu(WindoW win,CharPtr PNTR texts, MenuDescPtr pmd,ItmActnProc umbrella); extern Global(IteM) currentItem; Global(void) SetStatusOfItems(MenuDescPtr pmd); Global(void) DoMenuAction(MenuDescPtr pmd, IteM it); Global(void) ShowDuration(time_t begin); Global(time_t) StartDuration(void); extern Global(Int2) ListCurrentClass; /* abs index (counting irrelevant classes) */ extern Global(Int2) ListCurrentItem; /* rel index (ignoring irrelevant classes) */ typedef void (PNTR LstNotifyProc)(LisT List, Int2 VarIndex); typedef int (PNTR LstCountSelProc)(Int2 ClassIndex); Global(LisT) CreateNamesList(GrouP g, Int2 width, Int2 height, LstNotifyProc NorifyProc, LstCountSelProc CountProc); typedef struct { /* range of selected names */ Int2 from,num; } Pair, PNTR PairPtr; Global(LisT) MultiNamesList(GrouP g, PairPtr PNTR selection); Global(GrouP) TermButtons(WindoW win, GrouP samewidth, BtnActnProc OkProc, BtnActnProc CancelProc, BtnActnProc HelpProc); Global(void) myProcessAnyEvent(void); /* see utility.c */ #if MYSWITCH typedef PaneL Switch; Global(Switch) SwitchCreate(GrouP prnt, Int2 maxval, ChngProc actn); Global(void) SwitchSetValue(Switch s, Int2 val); Global(Int2) SwitchGetValue(Switch s); Global(void) SwitchSetMax(Switch s, Int2 maxv); Global(void) SwitchSetParams(Switch s, Int2 val, Int2 maxv); Global(Int2) SwitchHeight(void); #endif Global(void) ReadWindowPos(CharPtr id, Int2Ptr left, Int2Ptr top); Global(void) WriteWindowPos(CharPtr id, WindoW win); /***********************************************************************/ /* Lock/Unlock support. It is used to prevent another action */ /* associated with a menu item or a button being initiated by the user */ /* until the current action terminates. */ /***********************************************************************/ Global(Int2) Locked(MenuDescPtr pmd); Global(void) Lock(MenuDescPtr pmd); Global(Int2) Unlock(MenuDescPtr pmd); Global(void) PauseItems(MenuDescPtr pmd, Boolean enable); Global(void) ParamLock(Boolean lock); Global(void) LockAll(void); /* defined in visual.c */ Global(void) UnlockAll(void); /* defined in visual.c */ Global(void) RefreshMenus(void); /* defined in visual.c */ Global(Boolean) IncompleteAction(void); /* defined in visual.c */ /*******************************/ /* Suspend - Resume/Abort/Take */ /*******************************/ typedef enum { ENABLE_PAUSE, /* Show 'pause' item */ DISABLE_PAUSE, /* Hide 'pause' item */ ENABLE_RESUME, /* Show 'resume/abort/take' items */ DISABLE_RESUME /* Hide 'resume/abort/take' items */ } PauseService; enum { PS_SUSPEND=-1, PS_RESUME=-2, PS_ABORT=-3, PS_TAKE=-4 }; /**************************/ /* Main Window management */ /**************************/ extern Global(MenuDesc) MainMenu; Global(Int2) CreateMainWindow(void); extern Global(Boolean) TermFlag; Global(void) DestroyMainWindow(void); Global(Int2) ActivateClass(void); Global(void) DeactivateClass(void); Global(void) ClassRecordNewFunc(Boolean keep); enum ClassHelp { CH_CLASS, CH_TYPES }; Global(CharPtr) ClassHelpInfo(enum ClassHelp); extern Global(MenuDesc) ClassMenuDesc; Global(Boolean) SysClassInfo(Boolean Check, CharPtr Short, int PNTR Code); Global(CharPtr) SysClassFullName(int Code); typedef enum { MWI_CLASS, MWI_ARCHIVE, MWI_SYSTEM, MWI_DIAGRAM, MWI_CURVE, MWI_INITTYPE, MWI_CURVETYPE, MWI_DERIVATIVES, MWI_STATUS, MWI_DURATION, MWI_MESSAGE } MWInfoKind; Global(void) UpdateInfoInMainWindow(MWInfoKind ik, CharPtr sn); Global(void) PauseInMainWin(PauseService service, Boolean take); extern Global(FonT) SystemFont,ProgramFont; extern Global(Int2) sysLineHeight,sysCharWidth,sysDescent,sysAscent, sysFontHeight,sysLeading; extern Global(Int2) sysLineHeight2,sysCharWidth2,sysLineHeight4,sysCharWidth4; /*************************/ /* Directories and files */ /*************************/ Global(void) ChangeDirectory(CharPtr dir); Global(CharPtr) CurrentDirectory(void); Global(Boolean) TruncateFile(FILE PNTR stream, long size); /* Windows: GetInputFileName&GetOutputFileName change the current directory */ Global(Boolean) myGetInputFileName(CharPtr fileName, size_t maxsize, CharPtr extType); Global(Boolean) myGetOutputFileName(CharPtr fileName, size_t maxsize, CharPtr dfault); /***************************/ /* Useful string functions */ /***************************/ Global(CharPtr) StrSubstitute(CharPtr source, CharPtr what, CharPtr with, Boolean wholeid, Int2Ptr num); Global(CharPtr) StrInsert(CharPtr source, Int2 position, CharPtr what); Global(void) StrTrim(CharPtr source); /*****************/ /* File routines */ /*****************/ #define BL 350 /* max line len in any description file */ typedef Int4 DescPtr; Global(Boolean) DescOpen(CharPtr filename); Global(void) DescClose(void); Global(Boolean) DescEof(void); Global(void) DescRewind(void); Global(void) DescSeek(DescPtr fp); Global(CharPtr) GetLine(CharPtr b); Global(DescPtr) FindLine(CharPtr line); Global(Int2) CountLines(void); Global(Int2) mCountLines(Int2 variant); /* utility.h */ Global(CharPtr) mGetLine(CharPtr b, Int2 variant); /* utility.h */ Global(void) ImplReload(Int2 stagen, Int2 method); /* curve.c */ Global(Int2) FileLineMaxWidth(CharPtr file); /***********************/ /* Execute DOS command */ /***********************/ Global(Int2) ExecuteCommand(CharPtr cmd, Boolean (FAR *CheckProc)(void), Int2 (FAR *PostProc)(void)); /*********************************************/ /* dll -> application back calls for Windows */ /*********************************************/ #if _WIN /* We need DS to be loaded with the address of content's data segment. The _export keyword in an .exe (not in .dll!) produces 3 NOPs instead of mov ax,content_dataseg But fortunately, SS register still contains the address of content's data segment. So, we are forced to use it although this violates "preferred Windows programming practices". */ #ifdef WIN32 #define Prolog #define Epilog #else #define Prolog asm {push ds; push ss; pop ds;} #define Epilog asm {pop ds;} #endif #else #define Prolog #define Epilog #endif /***************************/ /* General-purpose defines */ /***************************/ /* Calculates size of memory needed for an array with arbitrary type of components. NOTE: it should not be calculated as num*sizeof(T) since if T A[5]; then it may be sizeof(T)!=sizeof(A[0]) on some computers due to alignment requirements. */ #define ARRAYSIZE(type,num) ((num)*(sizeof(type[2])>>1)) /********/ /* Misc */ /********/ #define VCL_UDF "UserFunc" /* visual class name for User Defined Functions */ /* Data passed to Starters and Generators by Kernel */ #include "stagen.h" /* also should be included in each starter-generator source */ /* Section prefix */ #define SECPRF "&" #if defined(COMP_GNU) && defined(OS_UNIX_SUN) /* There are no div_t and div in stdlib.h */ typedef struct { int quot; int rem; } div_t; Global(div_t) div(int numer, int denom); #endif /* defined(COMP_GNU) && defined(OS_UNIX_SUN) */ #define COMMENT_STR "%!" /* names with these chars at pos 1 are ignored by DataLibEnum */ #define fprintfFloatHi(file,num) fprintf(file," %.*g",DBL_DIG,num) Global(void) Redraw(PaneL p); /* Things for window.h included without visual.h */ typedef Int2 Color, PNTR ColorPtr; /* index to Palette */ typedef enum { VSA_RESET, VSA_DRAW, VSA_ERASE } VisualSpecAction; #if defined(WIN32) && defined(__DLL__) /* BC 5.1: something wrong with DBL_MAX when it is used in dll */ #undef DBL_MAX #define DBL_MAX 1.7976931348623157E+308 /* ANSI C 2.2.4.2.2 */ #endif /* defined(WIN32) && defined(__DLL_) */ #endif /* #ifndef APP_NAME */