/* Copyright 1991,1992,1993,1994,1995,1996,1997,1998,1999 Y&Y, Inc. Copyright 2007 TeX Users Group This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef _WINDOWS #define _WINDOWS #endif #define NOCOMM #define NOSOUND #define NODRIVERS #define STRICT #include "windows.h" #include "windowsx.h" #include #include #include #include #include "dviwindo.h" #include "winextra.h" #include "winhead.h" #include "winbased.h" #pragma hdrstop #include /* #include */ /* for getenv / _environ */ #include /* for GetOpenFileName */ #include /* for _getcwd WIN32 ? */ #include "atm.h" #include "atmpriv.h" #pragma warning(disable:4100) // unreferenced formal parameters #define YANDYTEXDLL // #define DEBUGATM // #define DEBUGENCODING // #define DEBUGHEAP // #define DEBUGMAPPING #define DEBUGMRU // #define DEBUGOPENFILE #define DEBUGPATTERN #define DEBUGSEARCH #define DEBUGMETAFILE #define USEMEMCPY /********************************************************************** * * DVI search function * * Copyright (C) 1991, 1992 Y&Y. All Rights Reserved. * * DO NOT COPY OR DISTRIBUTE! * * This is the part that finds the page with the desired text * **********************************************************************/ BOOL bMetaTopLeft=0; /* current point top left of MetaFile image */ /* now hard-wired to use bottom left ... */ BOOL bCustomEncoding=0; /* using ENCODING=... */ /* if ENCODING=ansinew and bTeXANSI=1 actually reencode to ansinew 96/Aug/28 */ /* which will cause bitmapped partial fonts in printed output 96/Aug/28 */ /* otherwise ENCODING=ansinew will mean *no* reencoding right ? */ int nEncodingBytes=0; /* have many bytes compressed table takes up */ int nWidthBytes=512; /* bytes for bogus width table 256 WORD */ /* 256 * sizeof(WORD) */ /* ------------------------------------------------------------------------ */ #ifdef ATMSOLIDTABLE char encodefont[MAXFONTS]; /* non-zero if encoding already set up */ #else HGLOBAL hATMTables[MAXFONTS]; /* non-NULL if encoding already set up */ #endif WORD DefaultChar = (WORD) -1; /* -1 default char for text font */ WORD BreakChar = 0; /* 0 or 32 break char for text font */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ BOOL bATMShowRefresh=1; /* non-zero if bATMShow has to be (re)set up */ /* set from winfonts.c when in `Show Font' */ /* #define HOWOFTEN 512 */ /* how often to check for mouse clicks - 2^n */ BOOL bMarkFlag=0; /* scan dvi page for marks */ int marknumber=-1; /* number of mark or -1 */ long lastsearch=-1; /* position in file that last search ended */ long buttonpos=0; /* position of button last pressed */ int buttondvipage; /* page of button last pressed 95/Mar/10 */ long oldbuttonpos=0; /* position of button last pressed */ int oldbuttondvipage; /* page of button last pressed 95/Mar/10 */ int lastdvipage=0; /* dvipage corresponding to lastsearch */ /* DEBUG */ long startposition=0; /* position in file that this search started at */ long pagestart; /* position in file at last bop */ /* not used */ BOOL partwayflag = 0; /* adjust screen position only part way */ BOOL wrapped; /* non-zero if wrapped around once */ int pagenumber; /* dvipage of page searching on */ int textlength; /* length of text to search for */ int textindex=0; /* pointer to next character to match */ /* #define MAXSEARCHTEXT 80 */ /* maximum length of search text */ /* #define MAXKEY 64 */ /* maximum length of key in dviwindo.ini */ char findtext[MAXSEARCHTEXT]; /* string searched for (no white space) */ int nkeybuffer=MAXKEYBUFFER; /* keep global so it ratchets up only */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ #define HYPERFILE /* Simple hypertext state push down stack */ /* push graphics state also ? */ static char *modname = "WINSEARC"; /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* put up error message in box - with byte count if relevant */ /* #define MAXMESSAGE 256 */ static void winerror(char *buff) { HWND hFocus; char errmess[MAXMESSAGE]; if (strlen(buff) > (MAXMESSAGE - 32)) buff = "Error Message too long!"; if (filepos > 0) { sprintf(errmess, "%s at byte %ld", buff, filepos-1); /* (LPSTR) buff, filepos-1); */ } else strcpy(errmess, buff); if ((hFocus = GetFocus()) == NULL) hFocus = hwnd; (void) MessageBox(hFocus, errmess, modname, MB_ICONSTOP | MB_OK); } static void wincancel(char *message) { HWND hFocus; int flag; if ((hFocus = GetFocus()) == NULL) hFocus = hwnd; flag = MessageBox(hFocus, message, modname, MB_ICONSTOP | MB_OKCANCEL); if (flag == IDCANCEL) { bShowFlag = 0; /* turn off displaying */ finish = -1; /* set early termination */ bUserAbort = 1; /* stop printing */ } } void WriteError (char *msg) { /* char buffer[128]; */ char *s; strcpy (debugstr, msg); s = debugstr + strlen(debugstr) - 1; while (s > debugstr && *s <= ' ') *s-- = '\0'; /* strip \n at end */ // WritePrivateProfileString("Window", "LastError", msg, "dviwindo.ini"); // WritePrivateProfileString(achPr, "LastError", debugstr, achFile); WritePrivateProfileString(achDiag, "LastError", debugstr, achFile); WriteTime(achDiag, "LastErrorTime"); /* show date and time */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ #define FINDDLGORD 1540 /* from dlg.h */ FINDREPLACE fr; /* needs to be static ! */ /* Following added 95/Aug/14 to support bDismissFlag */ UINT APIENTRY SearchHook (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) /* UINT CALLBACK _export SearchHook (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) */ { WORD id; switch (msg) { case WM_COMMAND: id = (WORD) GET_WM_COMMAND_ID(wParam, lParam); switch (id) { case IDOK: /* read out Dismiss FLag */ bDismissFlag = (int) SendDlgItemMessage(hDlg, ID_DISMISS, BM_GETCHECK, 0, 0L); /* read out Wrap Flag */ /* bWrapFlag = (int) SendDlgItemMessage(hDlg, ID_WRAP, BM_GETCHECK, 0, 0L); */ break; default: return (FALSE); } break; /* end of WM_COMMAND case */ case WM_INITDIALOG: /* message: initialize */ /* Set up Dismiss Flag check box */ (void) SendDlgItemMessage(hDlg, ID_DISMISS, BM_SETCHECK, (WPARAM) bDismissFlag, 0L); /* Set up Wrap Flag check box */ /* (void) SendDlgItemMessage(hDlg, ID_WRAP, BM_SETCHECK, (WPARAM) bWrapFlag, 0L); */ return (TRUE); /* Indicates the focus is *not* set to a control */ /* break; */ default: return (FALSE); } return (FALSE); /* let Dialog Box Proc process message */ /* return (TRUE); */ /* processed message - don't process again */ } /* lParam unreferenced */ void ShowCommDlgError(char *); /* in winprint.c */ /* new CommDlg Search 94/Jan/7 */ /* no longer used 94/Feb/8 */ /* BUT: reinstated after bug fixes 95/Mar/1 */ void CommSearch (HINSTANCE hInst, HWND hWnd) { /* HWND hDlg; */ /* 1994/Feb/9 */ if (uFindReplaceMsg != 0) return; /* don't if already put up */ /* Moved to before FindText(...) 1996/Aug/14 */ uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING); /* Note: fr needs to be static because of modeless dialog box ! */ memset (&fr, 0, sizeof(FINDREPLACE)); fr.lStructSize = sizeof(FINDREPLACE); fr.hwndOwner = hWnd; fr.hInstance = hInst; /* needed only for FR_ENABLETEMPLATE */ /* fr.Flags = FR_HIDEUPDOWN; */ /* fr.Flags = FR_HIDEUPDOWN | FR_ENABLETEMPLATE; */ fr.Flags = FR_HIDEUPDOWN | FR_ENABLETEMPLATE | FR_ENABLEHOOK; /* 96/Aug/14 */ /* We misuse the `Match Whole Word' button for `Wrap' */ if (bWrapFlag) fr.Flags = fr.Flags | FR_WHOLEWORD; if (bCaseSensitive) fr.Flags = fr.Flags | FR_MATCHCASE; fr.lpstrFindWhat = searchtext; fr.wFindWhatLen = sizeof(searchtext); fr.lpfnHook = (LPFRHOOKPROC) SearchHook; /* 1996/Aug/15 */ fr.lpTemplateName = MAKEINTRESOURCE(FINDDLGORD); /* hDlg = FindText(&fr); */ /* any need to remember hDlg ? */ hFindBox = FindText(&fr); /* Shouldn't we register Window message *first* ? */ /* uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING); */ if (hFindBox == NULL) { ShowCommDlgError("FindText"); } else { bShowSearchFlag = 1; bShowSearchExposed = 1; } } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* assumes only one file open at a time */ /* versions of getc and ungetc using low-level C input/output */ /* static void unwingetc(int c, HFILE input) { if (ungotten >= 0) { winerror("Repeated unwingetc"); errcount(); } else filepos--; ungotten = c; } */ static int replenishbuf(HFILE input, int bufferlen) { /* presumably buflen = 0 at this point */ /* buflen = read(input, buffer, (unsigned int) bufferlen); */ buflen = _lread(input, buffer, (unsigned int) bufferlen); if (buflen < 0) { strcpy (debugstr, "Read error in wingetc "); if (errno == EBADF) strcat(debugstr, "invalid file handle"); (void) wincancel(debugstr); finish = -1; } bufptr = buffer; if (buflen <= 0) return EOF; /* end of file or read error */ /* bufptr = buffer; */ return buflen; } #ifdef IGNORED static int wingetc(HFILE input) { int c; if (ungotten >= 0) { c = ungotten; ungotten = -1; filepos++; return c; } else if (buflen-- > 0) { filepos++; return (unsigned char) *bufptr++; } else { if (replenishbuf(input, BUFFERLEN) < 0) return EOF; buflen--; filepos++; return (unsigned char) *bufptr++; } } #endif static int wingetc(HFILE input) { int c; if (ungotten >= 0) { /* can't happen? no ungetc ? */ c = ungotten; ungotten = -1; filepos++; return c; } if (buflen <= 0) { if (replenishbuf(input, BUFFERLEN) < 0) return EOF; } buflen--; filepos++; return (unsigned char) *bufptr++; } static long wintell(HFILE input) { /* where are we in the file */ return filepos; } /* possibly check for whether new position is somewhere in buffer ? */ static long winseek(HFILE input, long place) { long foo; if (filepos == place) return place; /* dangerous ? */ if (place < 0) { sprintf(debugstr, "Negative seek %ld", place); (void) wincancel(debugstr); return 0; } /* foo = lseek(input, place, 0); */ foo = _llseek(input, place, SEEK_SET); if (foo != place) { /* sprintf(str, "Seek error: to %ld - at %ld", place, foo); */ sprintf(debugstr, "Seek error: to %ld ", place); if (errno == EBADF) strcat(debugstr, "invalid file handle"); else if (errno == EINVAL) strcat(debugstr, "invalid origin or position"); (void) wincancel(debugstr); } filepos = place; ungotten = -1; buflen = 0; bufptr = buffer; /* redundant ? */ return foo; } static int wininit(HFILE input) { filepos = 0; /* beginning of file */ ungotten = -1; buflen = 0; /* nothing buffered yet */ bufptr = buffer; /* redundant ? */ return 0; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* stuff for reading signed and unsigned numbers of various lengths */ static unsigned int ureadone (HFILE input) { return (unsigned int) wingetc(input); } static unsigned int ureadtwo (HFILE input) { return (wingetc(input) << 8) | wingetc(input); } static unsigned long ureadthree (HFILE input) { int c, d, e; c = wingetc(input); d = wingetc(input); e = wingetc(input); return ((((unsigned long) c << 8) | d) << 8) | e; } /* static unsigned long ureadfour (HFILE input) { int c, d, e, f; c = wingetc(input); d = wingetc(input); e = wingetc(input); f = wingetc(input); return ((((((unsigned long) c << 8) | (unsigned long) d) << 8) | e) << 8) | f; } */ /* static int sreadone (HFILE input) { int c; c = wingetc(input); if (c > 127) return (c - 256); else return c; } */ /* static int sreadtwo (HFILE input) { return (wingetc(input) << 8) | wingetc(input); } */ /* static long sreadthree (HFILE input) { int c, d, e; c = wingetc(input); d = wingetc(input); e = wingetc(input); if (c > 127) c = c - 256; return ((((long) c << 8) | d) << 8) | e; } */ static long sreadfour (HFILE input) { int c, d, e, f; c = wingetc(input); d = wingetc(input); e = wingetc(input); f = wingetc(input); return ((((((long) c << 8) | (long) d) << 8) | e) << 8) | f; } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ void seado_push(void) { } void seado_pop(void) { } /* here we need to use ANSI characterset operations on user supplied string */ /* returns non-zero if accumulated complete match */ int matchchar(int c) { /* see whether matched the search text */ if (c == '-') return 0; /* try and ignore hyphens */ if (bCaseSensitive == 0) { /* make all lower case */ /* if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a'; */ /* NO */ /* AnsiLower is obsolete, use CharLower */ c = (int) LOWORD (CharLower ((LPSTR) MAKELONG (c, 0))); /* c = (int) LOWORD (AnsiLower ((LPSTR) MAKELONG (c, 0))); */ } if (findtext[textindex] == (char) c) { if (++textindex == textlength) return -1; } /* Try and allow for wild card character 1994/Oct/29 */ else if (findtext[textindex] == '?') { if (++textindex == textlength) return -1; } /* Try and allow for ffi, ffl, ff, fi, fl ligatures 1994/Oct/29 */ else if (bIgnoreLigatures && !IsCharAlphaNumeric((char) c) && findtext[textindex] == 'f') { if (++textindex == textlength) return -1; if (findtext[textindex] == 'f') { if (++textindex == textlength) return -1; if (findtext[textindex] == 'i' || findtext[textindex] == 'l') { if (++textindex == textlength) return -1; } } else if (findtext[textindex] == 'i' || findtext[textindex] == 'l') { if (++textindex == textlength) return -1; } else textindex = 0; /* no match - reset - start over */ } else textindex = 0; /* no match - reset - start over */ return 0; } static void normalchar (HFILE input, int c) { if (matchchar(c) != 0) { /* lastsearch = wintell(input) - 1; */ /* ??? */ lastsearch = wintell(input); /* ??? */ lastdvipage = pagenumber; /* debugging */ finish = -1; /* if found match, then go home ! */ } } void seado_set1(HFILE input) { int c; c = wingetc(input); /* in text search process character - in other searches, ignore it */ if (bMarkSearch == 0) normalchar (input, c); /* textindex = 0; ? */ } /* don't bother making this efficient, since it should never happen */ void seado_set2(HFILE input) { /* NOT REALLY NEEDED ! */ (void) wingetc(input); seado_set1(input); } void seado_set3(HFILE input) { /* NOT REALLY NEEDED ! */ (void) wingetc(input); (void) wingetc(input); seado_set1(input); } void seado_set4(HFILE input) { /* NOT REALLY NEEDED ! */ (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); seado_set1(input); } /* set character c and DO NOT increase h by width of character */ void seado_put1(HFILE input) { int c; c = wingetc(input); /* in text search process character - in other searches, ignore it */ if (bMarkSearch == 0) normalchar (input, c); /* seado_set1(input); */ /* (void) wingetc(input); */ /* textindex = 0; ? */ } void seado_put2(HFILE input) { /* NOT NEEDED */ (void) wingetc(input); seado_put1(input); } void seado_put3(HFILE input) { /* NOT REALLY NEEDED ! */ (void) wingetc(input); (void) wingetc(input); seado_put1(input); } void seado_put4(HFILE input) { /* NOT REALLY NEEDED ! */ (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); seado_put1(input); } void seado_set_rule(HFILE input) { int k; for (k = 0; k < 8; k++) (void) wingetc(input); /* sreadfour(input); */ /* sreadfour(input); */ textindex = 0; } void seado_put_rule(HFILE input) { int k; for (k = 0; k < 8; k++) (void) wingetc(input); /* sreadfour(input); */ /* sreadfour(input); */ textindex = 0; } void seado_bop(HFILE input) { /* beginning of page */ int k; pagestart = wintell(input) - 1; /* remember bop position */ /* current = wintell(input) - 1; */ /* pagenumber++; */ /* increment page number */ /* for(k=0; k < 10; k++) counter[k] = an_sreadfour(input); */ for(k=0; k < 40; k++) (void) wingetc(input); /* 10 counters */ for(k=0; k < 4; k++) (void) wingetc(input); /* previous */ } void seado_eop(HFILE input) { /* end of page */ if (wrapped != 0) { /* wrapped around already ? */ if (wintell(input) > startposition) { #ifdef DEBUGSEARCH if (bDebug > 1) { sprintf(debugstr, "wrapped %d present pos %ld start pos %ld\n", wrapped, wintell(input), startposition); OutputDebugString(debugstr); } #endif lastsearch = -1; /* indicate failure */ /* NEW */ finish = -1; /* went past point where we started */ return; } } pagenumber++; /* increment page number */ if (textures != 0) (void) sreadfour(input); /* skip over length code */ } void seado_right1(HFILE input) { /* rare */ (void) wingetc(input); } void seado_right2(HFILE input) { (void) wingetc(input); (void) wingetc(input); } void seado_right3(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_right4(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_w0(void) { } void seado_w1(HFILE input) { /* rare */ (void) wingetc(input); } void seado_w2(HFILE input) { (void) wingetc(input); (void) wingetc(input); } void seado_w3(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_w4(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_x0(void) { } void seado_x1(HFILE input) { /* rare */ (void) wingetc(input); } void seado_x2(HFILE input) { (void) wingetc(input); (void) wingetc(input); } void seado_x3(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_x4(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_down1(HFILE input) { /* rare */ (void) wingetc(input); } void seado_down2(HFILE input) { /* rare */ (void) wingetc(input); (void) wingetc(input); } void seado_down3(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_down4(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_y0(void) { } void seado_y1(HFILE input) { /* rare */ (void) wingetc(input); } void seado_y2(HFILE input) { (void) wingetc(input); (void) wingetc(input); } void seado_y3(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_y4(HFILE input) { /* not used */ (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_z0(void) { } void seado_z1(HFILE input) { /* rare */ (void) wingetc(input); } void seado_z2(HFILE input) { (void) wingetc(input); (void) wingetc(input); } void seado_z3(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } void seado_z4(HFILE input) { (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); (void) wingetc(input); } static void switchfont(int f) { /* switching to other font */ /* textindex = 0; */ } void seado_fnt1(HFILE input) { /* switch fonts */ switchfont((int) wingetc(input)); } void seado_fnt2(HFILE input) { /* switch fonts */ switchfont((int) ureadtwo(input)); } void seado_fnt3(HFILE input) { /* switch fonts */ switchfont((int) ureadthree(input)); } void seado_fnt4(HFILE input) { /* switch fonts */ switchfont((int) sreadfour(input)); } /* The following may take more work ... no kidding! */ void seado_xxxi (HFILE input, unsigned int n) { /* int c; */ unsigned int k; int m; char specialstring[MAXFILENAME]; char *s, *t; /* ignore specials when searching for string or when special too long */ /* if (bMarkSearch == 0 || n >= MAXFILENAME) */ if (bMarkSearch == 0 || n >= sizeof(specialstring)) { for (k = 0; k < n; k++) (void) wingetc(input); textindex = 0; } else { s = specialstring; /* grab the rest of special */ for (k = 0; k < n; k++) *s++ = (char) wingetc(input); *s = '\0'; /* 95/Aug/12 */ if (bMarkSearch == 1 && strncmp(specialstring, "mark:", 5) == 0) { s = specialstring + 5; /* now get the mark label */ /* just use getbuttonname ??? */ /* while (*s <= ' ') s++; */ /* search for non-space */ while (*s <= ' ' && s > 0) s++; /* search for non-space */ if (*s == '\"') { /* scan up to matching " */ s++; t = s; /* while (*t != '\"' && t < s + MAXMARKS) t++; */ while (*t != '\"' && *t > 0 && t < s + MAXMARKS) t++; } else { /* scan up to white space or end of string */ t = s; /* while (*t > ' ' && t < s + MAXMARKS) t++; */ /* 95/Dec/20 */ while (*t > ' ' && *t != ',' && t < s + MAXMARKS) t++; } /* *t = '\0'; */ if (t != s) { m = t - s; /* if (strncmp(s, buttonlabel, m) == 0) */ /* 95/Oct/3 fix */ if ((strlen(buttonlabel) == (unsigned int) m) && (strncmp(s, buttonlabel, m) == 0)) { lastsearch = wintell(input); /* ??? */ lastdvipage = pagenumber; /* debugging */ finish = -1; } } } else if (bMarkSearch == 2 && strncmp(specialstring, "src:", 4) == 0) { /* 98/Dec/15 */ s = specialstring+4; while (*s == ' ') s++; if (sscanf(s, "%d%n", &srclineno, &m) == 1) { s += m; while (*s == ' ') s++; if (strlen(s) < sizeof(srcfile)) strcpy(srcfile, s); if (szSource != NULL && (_stricmp(srcfile, szSource) == 0) && (srclineno >= nSourceLine)) { srctaghit++; lastsearch = wintell(input); /* ??? */ lastdvipage = pagenumber; /* debugging */ finish = -1; /* what else needs to be done here ? */ } } } } } void seado_xxx1 (HFILE input) { /* for /special */ unsigned n; n = ureadone(input); /* n = wingetc(input); */ seado_xxxi(input, n); } void seado_xxx2 (HFILE input) { /* for /special */ unsigned int n; n = ureadtwo(input); seado_xxxi(input, n); } void seado_xxxl (HFILE input, unsigned long n) { /* int c; */ unsigned long k; /* if it needs a long form of \special then it is too long ... */ for(k = 0; k < n; k++) (void) wingetc(input); textindex = 0; } void seado_xxx3 (HFILE input) { seado_xxxl(input, ureadthree(input)); } void seado_xxx4 (HFILE input) { seado_xxxl(input, (unsigned long) sreadfour(input)); } /* need to do this even if skipping pages */ /* nothing much should actually happen here !!! */ /* ignore this all - should be done properly on prescan !!! */ /* simplify later by flushing stuff ! */ void seafnt_def(HFILE input, unsigned int k) { /* unsigned int f; */ unsigned int na, nl, i; /* int newfont=1; */ /* char *fp; */ for (k = 0; k < 12; k++) (void) wingetc(input); /* don't analyze again */ /* fc[f] = sreadfour(input); */ /* fs[f] = sreadfour(input); */ /* fd[f] = sreadfour(input); */ na = ureadone(input); /* always zero */ /* na = wingetc(input); */ nl = ureadone(input); /* nl = wingetc(input); */ for (i = 0; i < na+nl; i++) (void) wingetc(input); } void seado_fnt_def1(HFILE input) { /* define font */ seafnt_def(input, ureadone(input)); /* seafnt_def(input, wingetc(input)); */ } void seado_fnt_def2(HFILE input) { /* define font */ seafnt_def(input, (unsigned int) ureadtwo(input)); } void seado_fnt_defsub(HFILE input, unsigned long k) { seafnt_def(input, (unsigned int) k); } void seado_fnt_def3(HFILE input) { /* define font */ seado_fnt_defsub(input, (unsigned long) ureadthree(input)); } void seado_fnt_def4(HFILE input) { /* define font */ seado_fnt_defsub(input, (unsigned long) sreadfour(input)); } /* need to do this even if skipping pages */ void seado_pre(HFILE input) { /* doesn't do output */ unsigned int k, j; /* i */ /* sprintf(str, "HIT PRE! buflen %d filepos %ld", buflen, filepos); */ /* winerror(str); */ /* debugging */ pagenumber = 1; /* 0 ??? */ textindex = 0; /* if (wrapped++ != 0) finish = -1; */ /* i = ureadone(input); */ (void) ureadone(input); for (j = 0; j < 12; j++) (void) wingetc(input); /* don't read again */ /* dvi_num = sreadfour(input); */ /* dvi_den = sreadfour(input); */ /* mag = sreadfour(input); */ k = ureadone(input); /* k = wingetc(input); */ /* s = comment; */ for (j = 0; j < k; j++) (void) wingetc(input); /* redundant: done in dvipslog */ if (textures != 0) (void) sreadfour(input); /* skip over length code */ } /* need to do this even if skipping pages */ void seado_post(HFILE input) { /* doesn't do output */ int k; textindex = 0; (void) sreadfour(input); /* pointer to previous */ pagestart = wintell(input) - 1; /* current = wintell(input) - 1; */ for (k = 0; k < 12; k++) (void) wingetc(input); /* don't read again */ /* dvi_num = sreadfour(input); */ /* dvi_den = sreadfour(input); */ /* mag = sreadfour(input); */ for (k = 0; k < 8; k++) (void) wingetc(input); /* don't read again */ /* l = sreadfour(input); */ /* u = sreadfour(input); */ for (k = 0; k < 4; k++) (void) wingetc(input); /* don't read again */ /* s = ureadtwo(input); */ /* t = ureadtwo(input); */ /* if (bWrapFlag != 0 && wrapped++ == 0) */ /* *always* wrap at end of file if its hyper text mark search 95/Dec/28 */ /* or \special{src...} search 98/Dec/12 ? */ if ((bWrapFlag != 0 || bMarkSearch != 0) && wrapped++ == 0) { /* current = dvistart; */ #ifdef DEBUGSEARCH if (bDebug > 1) OutputDebugString("Wrapping back to start\n"); #endif (void) winseek(input, dvistart); pagenumber = 1; /* 0 ??? */ } else { finish = -1; /* gone around one too many times */ lastsearch = -1; /* ??? */ /* indicate failure */ } } /* could terminate as soon as wrapped != 0 && wintell(input) > startpos */ void seado_post_post (HFILE input) { /* should never get here ! */ /* unsigned long q; */ /* unsigned int i; */ /* q = sreadfour(input); */ (void) sreadfour(input); /* i = ureadone(input); */ (void) ureadone(input); finish = -1; /* STOP it before we hit EOF !!! */ /* check ID_BYTE again ? */ /* followed by at least four 223's */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ long oldlastsearch; /* searchdvifile used by both string search and search for hypertext mark */ /* flag = 0 for text string search */ /* flag = 1 for hypertext mark search */ /* flag = 2 for \special{src...} search */ /* NOTE: removes white space and `-' from string supplied */ int searchdvifile (HFILE input, long position, char *s, BOOL flag) { int c, j, k; /* long oldlastsearch; */ /* int flag=0; */ int olddvipage; /* debugging */ /* not accessed */ long bytecount = 0; bMarkSearch = flag; if (bDebug > 1) { sprintf(debugstr, "searchdvifile %ld %s bMarkSearch %d", position, s, flag); OutputDebugString(debugstr); } /* if (input == -1) */ /* sanity check 95/Aug/14 */ if (input == HFILE_ERROR) { /* sanity check 95/Aug/14 */ winerror("Invalid File Handle"); return -1; } (void) wininit(input); /* buffer may have been screwed with */ /* oldlastsearch = lastsearch; */ olddvipage = dvipage; /* remember for debugging ? */ #ifdef DEBUGSEARCH if (bDebug) { /* DEBUGGING STUFF - FLUSH LATER */ if (bFileValid == 0) winerror("bFileValid == 0"); if (hPages == NULL) winerror("hPages == NULL"); if (dvipage == -INFINITY) winerror("wantedpage == -INFINITY"); if (dvipage <= 0 || dvipage > dvi_t) { sprintf(str, "wantedpage is %d [0--%d]", dvipage, dvi_t); winerror(str); } } #endif if (pagecurrent(dvipage) == 0) { /* get file position for this page */ #ifdef DEBUGSEARCH if (bDebug) { /* DEBUGGING STUFF - FLUSH LATER */ sprintf(debugstr, "pagecurrent for %d yielded zero\n", dvipage); OutputDebugString(debugstr); } #endif current = dvistart; dvipage = 1; } /* sprintf(str, "SEARCHDVIFILE: dvipage %d lastsearch %ld current %ld", dvipage, lastsearch, current); winerror(str); */ if (current > lastsearch) { if (bDebug > 1) { sprintf(str, "current (%ld) > lastsearch (%ld)?", current, lastsearch); winerror(str); } /* dvipage--; */ /* lastsearch = -1; */ /* more aggressive 1993/March/29 ??? */ /* lastdvipage = dvipage; */ /* debugging */ if (pagecurrent(dvipage) == 0) { /* more aggressive ? */ current = dvistart; dvipage = 1; } lastsearch = current; /* more aggressive 1993/March/29 ??? */ } /* strncpy(findtext, s, MAXSEARCHTEXT); */ /* remember text to search for */ if (bMarkSearch == 0) { /* text search case */ strncpy(findtext, s, sizeof(findtext)); /* remember text search for */ /* squeeze out spaces and hyphens */ k = j = 0; while ((c = findtext[k++]) != '\0') { if (c > ' ' && c != '-') { if (bCaseSensitive == 0) { /* make lower case */ /* if (c >= 'A' && c <= 'Z') c = c - 'A' + 'a'; */ /* NO */ /* AnsiLower is obsolete, use CharLower */ c = (int) LOWORD (CharLower ((LPSTR) MAKELONG (c, 0))); /* c = (int) LOWORD (AnsiLower ((LPSTR) MAKELONG (c, 0))); */ } findtext[j++] = (char) c; } } findtext[j] = '\0'; #ifdef DEBUGSEARCH if (bDebug > 1) OutputDebugString(findtext); #endif textlength = (int) strlen(findtext); /* how many characters */ if (textlength > MAXSEARCHTEXT) /* debugging 93/March/29 */ winerror("Search text too long"); textindex = 0; /* how many have been matched */ } /* end of bMarkSearch == 0 */ /* sprintf(str, "string %s length %d", findtext, textlength); */ startposition = position; wrapped = 0; /* not wrapped yet! */ finish = 0; /* not finished yet ! */ pagenumber = dvipage; /* incremented by eop */ #ifdef DEBUGSEARCH if (bDebug > 1) { sprintf(debugstr, "seek to %ld\n", position); OutputDebugString(debugstr); } #endif (void) winseek(input, position); for(;;) { if ((bytecount++ & (HOWOFTEN-1)) == 0) { /* see if interrupted */ if(bEnableTermination != 0 && checkuser() != 0) { finish = -1; /* redundant */ bUserAbort = 1; /* set for termination */ /* lastsearch = wintell(input) - 1; */ } } c = wingetc(input); if (c == EOF) { winerror("Unexpected EOF on input"); finish = -1; /* redundant */ break; /* giveup(13); */ } if (c < 128) { if (bMarkSearch == 0) normalchar(input, c); /* text searach case */ } /* set character in current font and advance h by width of character */ else if ((c - 171) >= 0 && (c -171) < 64) /* fs = (c - 171); */ /* switch to font (c - 171) */ switchfont(c - 171); else switch(c) { case set1: seado_set1(input); break; case set2: seado_set2(input); break; /* silly */ case set3: seado_set3(input); break; /* silly */ case set4: seado_set4(input); break; /* silly */ case set_rule: seado_set_rule(input); break; case put1: seado_put1(input); break ; case put2: seado_put2(input); break; /* silly */ case put3: seado_put3(input); break; /* silly */ case put4: seado_put4(input); break; /* silly */ case put_rule: seado_put_rule(input); break; case nop: break; /* easy, do nothing ! */ case bop: seado_bop(input); break; case eop: seado_eop(input); break; case push: seado_push(); break; case pop: seado_pop(); break; case right1: seado_right1(input); break; case right2: seado_right2(input); break; case right3: seado_right3(input); break; case right4: seado_right4(input); break; case w0: seado_w0(); break; case w1: seado_w1(input); break; case w2: seado_w2(input); break; case w3: seado_w3(input); break; case w4: seado_w4(input); break; /* not used ? */ case x0: seado_x0(); break; case x1: seado_x1(input); break; case x2: seado_x2(input); break; case x3: seado_x3(input); break; case x4: seado_x4(input); break; /* not used ? */ case down1: seado_down1(input); break; case down2: seado_down2(input); break; case down3: seado_down3(input); break; case down4: seado_down4(input); break; /* case y0: seado_y0(); break; */ /* conflict math.h */ case y5: seado_y0(); break; /* case y1: seado_y1(input); break; */ /* conflict math.h */ case y6: seado_y1(input); break; case y2: seado_y2(input); break; case y3: seado_y3(input); break; case y4: seado_y4(input); break; /* not used ? */ case z0: seado_z0(); break; case z1: seado_z1(input); break; case z2: seado_z2(input); break; case z3: seado_z3(input); break; case z4: seado_z4(input); break; /* not used ? */ case fnt1: seado_fnt1(input); break; case fnt2: seado_fnt2(input); break; /* silly */ case fnt3: seado_fnt3(input); break; /* silly */ case fnt4: seado_fnt4(input); break; /* silly */ case xxx1: seado_xxx1(input); break; case xxx2: seado_xxx2(input); break; /* not used ? */ case xxx3: seado_xxx3(input); break; /* not used ? */ case xxx4: seado_xxx4(input); break; case fnt_def1: seado_fnt_def1(input); break; case fnt_def2: seado_fnt_def2(input); break; /* silly */ case fnt_def3: seado_fnt_def3(input); break; /* silly */ case fnt_def4: seado_fnt_def4(input); break; /* silly */ case post: seado_post(input); break; case pre: seado_pre(input); break; case post_post: seado_post_post(input); break; default: { /* we already complained about this in dvipslog ... */ finish = -1; /* ??? */ /* this should normally not happen: */ sprintf(str, "Unknown DVI command (%d)", c); winerror(str); errcount(); break; } /* break; */ } #ifdef IGNORED if (pagenumber < olddvipage) { if (bDebug > 1) { sprintf (debugstr, "pagenumber (%d) < olddvipage (%d)\n", pagenumber, olddvipage); OutputDebugString (debugstr); } break; /* ??? */ } #endif if (finish != 0) { if (bDebug > 1) { sprintf(debugstr, "finish %d", finish); OutputDebugString(debugstr); } break; /* trip out */ } } /* bMarkSearch = 0; */ /* 98/Dec/15 ? */ if (bUserAbort != 0) return 0; /* interrupted */ /* if (lastsearch != oldlastsearch && lastsearch > 0) */ if (lastsearch < 0) { /* did not find anything */ /* lastsearch = oldlastsearch; */ /* restore old value */ return 0; } else { if (bDebug > 1) { sprintf(debugstr, "page %d", pagenumber); OutputDebugString(debugstr); } return pagenumber; /* did find something */ } } /* Returns non-zero if need to redraw screen after cursor movement */ int AdjustCursor (HWND hWnd, HDC hDC) { RECT ClientRect; /* client area */ POINT CurPoint; POINT steparr[2]; /* int xll, yll, xur, yur; */ int xlld, ylld, xurd, yurd; long xmd, ymd; /* int xmd, ymd; */ long xdd, ydd; /* int xdn, ydn; */ int redrawflag = 0; if (bSpreadFlag == 0) { xdd = mapx(dvi_spot_h); ydd = mapy(dvi_spot_v); } else { /* this is only non-trivial when bSpreadFlag != 0 */ xoffsetold = xoffset; if (bCountZero == 0) { /* arbitrarily use right page */ xoffset = rightpageoffset(xoffsetold); } else { /* this is only a pain when bCountZero != 0 */ usepagetable(dvipage, 0); /* redundant ? */ if (rightcountzero != -INFINITY) { xoffset = rightpageoffset(xoffsetold); } else { /* this is only hard if its on the left page */ /* sprintf(str, "ADJUSTCURSOR: dvipage %d, rightcountzero %ld", dvipage, rightcountzero); winerror(str); */ dvipage++; usepagetable(dvipage, 0); /* sprintf(str, "ADJUSTCURSOR: dvipage %d, leftcountzero %ld", dvipage, leftcountzero); winerror(str); */ if (leftcountzero == -INFINITY) winerror("Impossible!"); xoffset = leftpageoffset(xoffsetold); } } xdd = mapx(dvi_spot_h); ydd = mapy(dvi_spot_v); xoffset = xoffsetold; } GetClientRect(hWnd, (LPRECT) &ClientRect); /* xll = ClientRect.left; yll = ClientRect.bottom; */ /* xur = ClientRect.right; yur = ClientRect.top; */ steparr[0].x = ClientRect.left; steparr[0].y = ClientRect.bottom; steparr[1].x = ClientRect.right; steparr[1].y = ClientRect.top; (void) DPtoLP(hDC, steparr, 2); xlld = steparr[0].x; ylld = steparr[0].y; xurd = steparr[1].x; yurd = steparr[1].y; /* xmd = (int) xdd; ymd = (int) ydd; */ xmd = xdd; ymd = ydd; if (xdd < xlld || xdd > xurd) { xmd = (xlld + xurd) / 2; /* if (partwayflag == 0) xoffset += ((long) xmd - xdd); */ if (partwayflag == 0) xoffset += (xmd - xdd); else { /* xoffset += ((long) xmd - xdd)/2; */ xoffset += (xmd - xdd)/2; /* xmd = (xmd + (int) xdd)/2; */ xmd = (xmd + xdd)/2; } redrawflag++; /* not neccessarily - scroll ? */ } if (ydd < ylld || ydd > yurd) { ymd = (ylld + yurd) / 2; /* if (partwayflag == 0) yoffset += ((long) ymd - ydd); */ if (partwayflag == 0) yoffset += (ymd - ydd); else { /* yoffset += ((long) ymd - ydd)/2; */ yoffset += (ymd - ydd)/2; /* ymd = (ymd + (int) ydd)/2; */ ymd = (ymd + ydd)/2; } redrawflag++; /* not neccessarily - scroll ? */ } /* xdn = mapx(dvi_spot_h); ydn = mapy(dvi_spot_v); sprintf(str, "xdn %ld ydn %ld xmd %d ymd %d", xdn, ydn, xmd, ymd); winerror(str); */ /* steparr[0].x = xmd; steparr[0].y = ymd; */ steparr[0].x = (int) xmd; steparr[0].y = (int) ymd; (void) LPtoDP(hDC, steparr, 1); /* can this LPtoDP fail? Do we care? */ CurPoint.x = steparr[0].x; CurPoint.y = steparr[0].y; ClientToScreen(hWnd, &CurPoint); if (bDebug > 1) { sprintf(debugstr, "New Cursor Position %d %d redraw", CurPoint.x, CurPoint.y, redrawflag); OutputDebugString(debugstr); } SetCursorPos(CurPoint.x, CurPoint.y); return redrawflag; } void savehyperstate(void) { int k; if (hyperindex == MAXHYPERPUSH - 1) { /* move down if depth exceeded */ #ifdef HYPERFILE if (hyperfile[0] != NULL) { free (hyperfile[0]); hyperfile[0] = NULL; } #endif for (k = 1; k < MAXHYPERPUSH; k++) { /* overflowed stack */ hyperpos[k-1] = hyperpos[k]; hyperpage[k-1] = hyperpage[k]; #ifdef HYPERFILE hyperfile[k-1] = hyperfile[k]; /* hMarks ? */ #endif } #ifdef HYPERFILE hyperfile[hyperindex] = NULL; #endif hyperindex--; } #ifdef DEBUGHYPERTEXT if (bDebug > 1) { /* DEBUGGING 1995/Mar/10 */ #ifdef HYPERFILE sprintf(debugstr, "Saving: hyper index %d pos %ld page %d in %s\n", /* hyperindex, oldbuttonpos, oldbuttondvipage, FileName); */ hyperindex, oldbuttonpos, oldbuttondvipage, szHyperFile); #else sprintf(debugstr, "Saving: hyperpos[%d] %ld hyperpage[%d] %d\n", hyperindex, oldbuttonpos, hyperindex, oldbuttondvipage); #endif OutputDebugString(debugstr); } #endif if (hyperindex < MAXHYPERPUSH - 1) { /* hyperpos[hyperindex] = lastsearch; */ /* hyperpos[hyperindex] = buttonpos; */ /* ??? */ hyperpos[hyperindex] = oldbuttonpos; /* 95/Aug/12 */ /* if (bDebug && lastdvipage == 0) winerror("Pushing zero page"); */ /* DEBUGGING ONLY */ if (lastdvipage == 0) lastdvipage = dvipage; /* ??? */ /* hyperpage[hyperindex] = lastdvipage; */ /* ??? */ /* hyperpage[hyperindex] = buttondvipage; */ /* experiment 95/Mar/10 */ hyperpage[hyperindex] = oldbuttondvipage; /* 95/Aug/12 */ #ifdef HYPERFILE if (hyperfile[hyperindex] != NULL) { free(hyperfile[hyperindex]); hyperfile[hyperindex] = NULL; } hyperfile[hyperindex] = zstrdup(szHyperFile); /* not OpenName */ *szHyperFile = '\0'; #endif hyperindex++; } bHyperLast = 1; /* last action was hyper text jump 95/Aug/12 */ } void restorehyperstate(void) { int hyperindexsvd; char *s; if (hyperindex == 0) return; /* nothing to to */ hyperindex--; /* lastsearch = hyperpos[hyperindex]; */ current = hyperpos[hyperindex]; /* lastdvipage = hyperpage[hyperindex]; */ dvipage = hyperpage[hyperindex]; /* if (bDebug && dvipage == 0) { winerror("Restoring zero page"); */ /* DEBUGGING ONLY */ #ifdef DEBUGHYPERTEXT if (bDebug > 1) { /* DEBUGGING 1995/Mar/10 */ #ifdef HYPERFILE sprintf(debugstr, "Restoring: hyper index %d pos %ld page %d in %s\n", hyperindex, current, dvipage, hyperfile[hyperindex]); #else sprintf(debugstr, "Restoring: hyperpos[%d] %ld hyperpage[%d] %d\n", hyperindex, current, hyperindex, dvipage); #endif OutputDebugString(debugstr); } #endif #ifdef HYPERFILE /* if (hyperfile[hyperindex] == NULL) DAMN ERROR ! */ if (hyperfile[hyperindex] != NULL) { /* let's first check whether it is the same file we are already viewing ... */ if (strchr(OpenName, '\\') == NULL && strchr(OpenName, '/') == NULL && strchr(OpenName, ':') == NULL) { /* strcpy(FileName, DefPath); */ strcpy(szHyperFile, DefPath); s = szHyperFile + strlen(szHyperFile) - 1; if (*s != '\\' && *s != '/') strcat(szHyperFile, "\\"); strcat(szHyperFile, OpenName); } else strcpy(szHyperFile, OpenName); /* if (strcmp(OpenName, hyperfile[hyperindex]) != 0) */ if (_stricmp(szHyperFile, hyperfile[hyperindex]) != 0) { strcpy(OpenName, hyperfile[hyperindex]); hyperindexsvd = hyperindex; SwitchDVIFile(hwnd, dvipage, 0); /* and now activate it !!! */ /* Need to somehow keep file open - avoid hFile = -1 ! */ ReOpenFile(hwnd); /* in dviwindo.c */ hyperindex = hyperindexsvd; } free (hyperfile[hyperindex]); /* free it, it has been used */ hyperfile[hyperindex] = NULL; current = hyperpos[hyperindex]; dvipage = hyperpage[hyperindex]; } #endif } void hyperundopush(void) { /* 95/Dec/29 */ if (hyperindex == 0) return; /* nothing to do */ if (bDebug > 1) OutputDebugString("Undoing hyper save\n"); hyperindex--; free (hyperfile[hyperindex]); hyperfile[hyperindex] = NULL; /* current = hyperpos[hyperindex]; */ /* dvipage = hyperpage[hyperindex]; */ } void free_hyperfile (void) { int k; /* if (hyperindex == 0) return; */ /* for (k = 0; k < hyperindex; k++) */ for (k = 0; k < MAXHYPERPUSH; k++) { if (hyperfile[k] != NULL) { free(hyperfile[k]); hyperfile[k] = NULL; } } hyperindex = 0; } /* pagenumber is dvipage of page with text searched for on it */ /* lastsearch is byte in file where match was found */ /* searchandmark used by string search, search for hypertext mark */ /* and search for \special{src:...} */ /* flag / bMarkSearch is -1 for hyper button pop */ /* flag / bMarkSearch is 0 for ordinary text string search /* /* flag / bMarkSearch is 1 for hyper button push target search */ /* flag / bMarkSearch is 2 for src \special 98/Dec/12 */ /* sets dvipage number of page with text searched for */ /* or, one page later if bSpreadFlag != 0 and bCountZero != 0, */ /* and page has even counter[0] */ /* returns 0 if no need to InvalidateRect (same page or failed) */ /* returns -1 otherwise */ /* Not safe in following to put up message boxes since repaint possible */ int searchandmark (HWND hWnd, BOOL flag) { HDC hDC; HWND hFocus; int olddvipage, redrawflag=0; /* if (bBusyFlag != 0) return 0; */ /* 1993/March/29 */ bMarkSearch = flag; /* remember globally */ /* if (bMarkSearch > 0) savehyperstate(); */ if (bMarkSearch == 1) savehyperstate(); /* PUSH --- for hyper button search */ if (bMarkSearch == 0 && *searchtext == '\0') return 0; /* empty text string - nothing to do */ bUserAbort = 0; /* 1993/March/29 ??? */ if (ReOpenFile(hWnd) < 0) return 0; /* file failed to reopen */ olddvipage = dvipage; /* save up current page 94/Dec/11 ! */ if (bMarkSearch == -1) { /* hyper text pop ? */ if (hyperindex == 0) { bMarkSearch = 0; return 0; /* nothing to do */ } restorehyperstate(); /* POP hypertext */ /* if (bDebug > 1) { sprintf(debugstr, "POP to PAGE %d\n", dvipage); OutputDebugString(debugstr); } */ lastsearch = current; /* ??? */ lastdvipage = dvipage; /* ??? */ /* (void) winseek(input, current); */ goto knownhit; } /* end of bMarkSearch == -1 (hyper pop) */ /* redrawflag = 0; */ /* olddvipage = dvipage; */ /* moved higher up 94/Dec/11 */ /* start were we left off last time --- if there was a last time */ if (lastsearch < 0) { /* either no previous search, or an error ... */ #ifdef DEBUGSEARCH if (bDebug > 1) OutputDebugString("lastsearch < 0\n"); #endif lastsearch = current; lastdvipage = dvipage; /* debugging */ } else { /* there was a previous search */ #ifdef DEBUGSEARCH if (dvipage != lastdvipage) { if (bDebug > 1) { sprintf(debugstr, "dvipage %d lastdvipage %d\n", dvipage, lastdvipage); OutputDebugString(debugstr); } } #endif dvipage = lastdvipage; /* debugging */ /* usepagetable(dvipage, 0); */ } /* need to search file for text specified */ /* BAD THINGS CAN HAPPEN HERE IF DVI FILE SCAN PUTS UP ERROR BOXES */ bScanFlag = 1; /* hack to prevent repaint 95/Dec/28 */ bHourFlag = 1; hSaveCursor = SetCursor(hHourGlass); /* sprintf(str, "SEARCHDVIFILE: dvipage %d lastsearch %ld current %ld", dvipage, lastsearch, current); winerror(str); */ bEnableTermination = 0; /* disable early termination */ /* debug */ oldlastsearch = lastsearch; if (bMarkSearch == 0) /* text search */ dvipage = searchdvifile(hFile, lastsearch, searchtext, bMarkSearch); /* else */ else if (bMarkSearch == 1) /* hypertext button search */ dvipage = searchdvifile(hFile, lastsearch, buttonlabel, bMarkSearch); else if (bMarkSearch == 2) /* src special search 98/Dec/12 */ dvipage = searchdvifile(hFile, lastsearch, szSource, bMarkSearch); (void) SetCursor(hSaveCursor); bHourFlag = 0; bScanFlag = 0; /* undo hack to prevent repaint 95/Dec/28 */ /* deal with case where mark is on same page as button and no redraw */ /* in which case bHyperUsed is reset to zero, and may not get set again */ /* if (bMarkSearch != 0 && dvipage == olddvipage) */ if (bMarkSearch == 1 && dvipage == olddvipage) bHyperUsed = 1; /* 94/Oct/10 */ if (bMarkSearch == 2 && dvipage == olddvipage) bSourceUsed = 1; /* 98/Dec/10 */ /* check and reset bUserAbort ??? */ if (bUserAbort != 0) { if (bDebug > 1) OutputDebugString("Search Aborted\n"); bUserAbort = 0; lastsearch = oldlastsearch; /* restore old value ??? */ dvipage = olddvipage; /* is it safe to exit here? file still open? */ if (bKeepFileOpen == 0) { /* if (hFile < 0) wincancel("File already closed (no hit)"); */ if (hFile == HFILE_ERROR) { if (bDebug) { sprintf(debugstr, "%s (%s)\n", "File already closed", "no hit A"); if (bDebug > 1) OutputDebugString(buffer); else (void) wincancel(debugstr); } } else (void) _lclose (hFile); /* need to close input again */ /* hFile = -1; */ hFile = HFILE_ERROR; } /* end of if (bKeepFileOpen == 0) */ bMarkSearch = 0; return 0; } /* end of bUserAbort */ /* Now first deal with failure case */ if (dvipage == 0) { /* did not find anything */ lastsearch = oldlastsearch; /* restore old value */ dvipage = olddvipage; /* if (bMarkSearch == 0) sprintf(str, "`%s' not found", searchtext); else sprintf(str, "`%s' not found", buttonlabel); if ((hFocus = GetFocus()) == NULL) hFocus = hwnd; (void) MessageBox(hFocus, str, "Search String", MB_ICONEXCLAMATION | MB_OK); */ if (bKeepFileOpen == 0) { if (hFile == HFILE_ERROR) { if (bDebug) { sprintf(debugstr, "%s (%s)\n", "File already closed", "no hit B"); if (bDebug > 1) OutputDebugString(debugstr); else (void) wincancel(debugstr); } } else (void) _lclose (hFile); /* need to close input again */ /* hFile = -1; */ hFile = HFILE_ERROR; } /* end of bKeepFileOpen == 0 */ /* moved down here 95/Dec/20 to avoid MessageBox repaint */ /* if (bMarkSearch == 0) sprintf(debugstr, "`%s' not found", searchtext); */ /* else sprintf(debugstr, "`%s' not found", buttonlabel); */ if (bMarkSearch == 0) sprintf(debugstr, "%s `%s' not found", "String", searchtext); else if (bMarkSearch == 1) sprintf(debugstr, "%s `%s' not found", "Anchor", buttonlabel); else if (bMarkSearch == 2) sprintf(debugstr, "Source line %d in `%s' not found", nSourceLine, szSource); else sprintf(debugstr, "Error"); /* should not happen */ if ((hFocus = GetFocus()) == NULL) hFocus = hwnd; (void) MessageBox(hFocus, debugstr, "Search", MB_ICONEXCLAMATION | MB_OK); /* if we failed hypertext search don't keep saved info on stack */ if (bMarkSearch == 1) hyperundopush(); /* --- 98/Dec/12 */ bMarkSearch = 0; /* ??? */ return 0; /* failed */ } /* end of dvipage == 0 (i.e. failed search) */ /* drop through here if search succeeded */ knownhit: /* or come here from hypertext POP */ /* bMarkSearch = 0; */ /* ??? */ if (bDebug > 1) OutputDebugString("HIT"); /* now apparently have found a hit --- time to do something about it */ /* need to rewind ? */ if (lastsearch < 0) { #ifdef DEBUGSEARCH /* if (bDebug) winerror("lastsearch < 0"); */ if (bDebug > 1) OutputDebugString("lastsearch < 0\n"); /* 95/Dec/20 */ #endif lastsearch = current; lastdvipage = dvipage; } /* sprintf(str, "lastsearch %ld", lastsearch); winerror(str); */ /* if (dvipage != olddvipage) redrawflag++; */ usepagetable(dvipage, 0); /* sprintf(str, "current %ld", current); winerror(str); */ /* showflag = 0; */ bScanFlag = 1; /* hack to prevent repaint 95/Dec/21 */ /* do before GrabWidths and GetDC */ hDC = GetDC(hWnd); /* ??? */ /* sprintf(str, "GetDC %d", hDC); winerror(str); */ /* if (bCopyFlag == 0) */ /* this shouldn't ever be non-zero ... */ (void) SetMapMode(hDC, MM_TWIPS); /* set unit to twips */ bHourFlag = 1; hSaveCursor = SetCursor(hHourGlass); bEnableTermination = 0; dvi_spot_h = oneinch; /* if missed ! */ dvi_spot_v = oneinch; /* if missed ! */ bMarkSpotFlag = 1; if (pagecurrent(dvipage) == 0) { current = dvistart; dvipage = 1; } if (bDebug > 1) { sprintf(debugstr, "SCANDVIPAGE: dvipage %d lastsearch %ld current %ld bMarkSearch %d", dvipage, lastsearch, current, bMarkSearch); OutputDebugString(debugstr); } bEnableTermination = 0; /* disable early termination */ /* debug */ /* oldbCountZero = bCountZero; */ GrabWidths(); /* (void) scandvifile(hFile, hDC, 0); */ /* bCountZero = 0; */ /* need to fool it ! */ (void) scandvipage(hFile, hDC, 0); /* now scan only page of interest */ ReleaseWidths(); /* bCountZero = oldbCountZero; */ bMarkSpotFlag = 0; if (bKeepFileOpen == 0) { if (hFile == HFILE_ERROR) { if (bDebug) { sprintf(debugstr, "%s (%s)\n", "File already closed", "hit"); if (bDebug > 1) OutputDebugString(debugstr); else (void) wincancel(debugstr); } } else (void) _lclose (hFile); /* hFile = -1; */ hFile = HFILE_ERROR; } bHourFlag = 0; (void) SetCursor(hSaveCursor); /* (void) ReleaseDC(hWnd, hDC); return 0; */ /* debug */ /* sprintf(str, "h %ld v %ld", dvi_spot_h, dvi_spot_v); winerror(str); */ if (dvi_spot_h == (long) oneinch && dvi_spot_v == (long) oneinch) { if (bDebug) { sprintf(debugstr, "MISSED: dvipage %d lastsearch %ld current %ld\n", dvipage, lastsearch, current); /* sprintf(str, "MISSED: dvipage %d lastsearch %ld current %ld\n\ lastdvipage %d startposition %ld pagestart %ld pagenumber %d wrapped %d\n\ buttonpos %ld", dvipage, lastsearch, current, lastdvipage, startposition, pagestart, pagenumber, wrapped, buttonpos); */ if (bDebug > 1) OutputDebugString(debugstr); else (void) wincancel(debugstr); } } /* else */ /* now figure out whether need to move display data and where to put arrow */ if (AdjustCursor(hWnd, hDC) > 0) redrawflag++; if (dvipage != olddvipage) redrawflag++; /* if ((bDebug > 1) && (dvipage == olddvipage)) OutputDebugString("Same DVI Page\n"); */ /* end of fiddling with screen adjustments */ /* } */ /* sprintf(str, "ReleaseDC %d", hDC); winerror(str); */ (void) ReleaseDC(hWnd, hDC); /* ??? */ bScanFlag = 0; /* hack to prevent repaint 95/Dec/21 */ /* do after ReleaseWidths and ReleaseDC */ bMarkSearch = 0; /* ??? */ if (redrawflag == 0) return 0; /* no need to redraw */ else { checkcontrols(hWnd, +1); SetupWindowText(hWnd); return -1; /* indicate need to redraw */ } } /* see whether user has hit a marked rectangular area */ /* need some work here to figure this out - similar to search - or tagfont */ /* marknumber is -1 if nothing hit, 0 if hit labelled button, > 0 if number */ int checkmarkhit(HWND hWnd, int curx, int cury) { HDC hDC; POINT steparr[1]; /* if (bBusyFlag != 0) return -1; */ /* 1993/March/29 */ bUserAbort = 0; /* 1993/March/29 ??? */ /* need to reopen input file */ if (ReOpenFile(hWnd) < 0) { return -1; /* failed to reopen */ } bScanFlag = 1; /* hack to prevent repaint 95/Dec/21 */ /* do before GrabWidths and GetDC */ hDC = GetDC(hWnd); if (bCopyFlag == 0) /* this shouldn't ever be non-zero ... */ (void) SetMapMode(hDC, MM_TWIPS); /* set unit to twips */ bHourFlag = 1; /* 1995/Dec/21 */ hSaveCursor = SetCursor(hHourGlass); /* 1995/Dec/21 */ bEnableTermination = 0; /* Disable 1995/Dec/21 */ bMarkFlag = 1; marknumber = -1; /* nothing hit */ GrabWidths(); /* compute logical coordinates from window coordinates */ steparr[0].x = curx; steparr[0].y = cury; (void) DPtoLP(hDC, steparr, 1); tagx = steparr[0].x; tagy = steparr[0].y; /* sigh, may need to do both pages of two page spread */ (void) scandvifile(hFile, hDC, 0); ReleaseWidths(); bMarkFlag = 0; if (bKeepFileOpen == 0) { if (hFile == HFILE_ERROR) { sprintf(debugstr, "%s (%s)\n", "File already closed", "check mark hit"); if (bDebug) { if (bDebug > 1) OutputDebugString(debugstr); else (void) wincancel(debugstr); } } else (void) _lclose (hFile); /* 1992/Nov/6 */ /* hFile = -1; */ hFile = HFILE_ERROR; } bHourFlag = 0; /* 1995/Dec/21 */ (void) SetCursor(hSaveCursor); /* 1995/Dec/21 */ (void) ReleaseDC(hWnd, hDC); bScanFlag = 0; /* allow repaint again */ /* do after ReleaseWidths and ReleaseDC */ return marknumber; /* OK */ } /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* BOOL bAddItem = 1; */ /* extra entry for adding an item */ /* BOOL bAddItem = 0; */ /* extra entry for adding an item */ BOOL bCallPreview = 1; /* extra entry for calling preview */ BOOL bNewEnvVar = 1; /* extra entry for setting up new var */ BOOL bMustExist = 0; /* non-zero if file and path must exist 93/Dec/7 */ BOOL bAllowBlank = 0; /* non-zero if CANCEL allowed in FileOpen 94/Jun/29 */ BOOL bCreateFile = 1; /* create file if it does not exist */ /* BOOL bNoValidate = 1; */ /* Suppress validation TeX Menu GetOpenFileName */ char *texhelpfile="txhlp0.dvi"; char *texhelpdir="c:\\texhelp\\"; /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* HERE IS THE CODE FOR LINKING TO OTHER APPLICATIONS 1993/Dec/1 TeX menu */ /* this used to rely on checktexmenu to leave keys in str ... */ void filltexmenu (HWND hWnd) { /* HMENU hMenu; */ HMENU hSubMenu; char *s, *sm; int k; /* int m; */ char *keybuffer=NULL; /* 97/June/5 */ /* possible allocate memory for keybuffer ? */ if (!bApplications) return; if (hTeXMenu == NULL) return; nApplications = 0; #ifdef IGNORED hMenu = GetMenu(hWnd); m = GetMenuItemCount(hMenu); if (!bHelpAtEnd) hSubMenu = GetSubMenu(hMenu, m - 1); /* last sub menu */ else hSubMenu = GetSubMenu(hMenu, m - 2); /* last sub menu */ #endif hSubMenu = hTeXMenu; if (bCallPreview) { strcpy(str, "Preview\t"); strcat(str, szPreviewHotKey); AppendMenu(hSubMenu, MF_ENABLED | MF_STRING, IDM_APPLICATION + nApplications, str); nApplications++; } if (bCallPreview) { AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL); nApplications++; } /* start by reading in all of the keys in the [Applications] section */ for (;;) { keybuffer = (char *) LocalAlloc(LMEM_FIXED, (UINT) nkeybuffer); if (keybuffer == NULL) { /* unable to allocate memory */ winerror ("Unable to allocate memory"); return; } k = GetPrivateProfileString(achAp, NULL, "", /* keybuffer, sizeof(keybuffer), achFile); */ keybuffer, nkeybuffer, achFile); if (k < nkeybuffer-2) break; /* the keys fitted in */ LocalFree ((HLOCAL) keybuffer); nkeybuffer = nkeybuffer * 2; /* try again with larger buffer */ } s = keybuffer; for (;;) { if ((sm = strchr(s, '|')) != NULL) *sm = '\t'; /* 93/Dec/25*/ if (_strnicmp(s, "DummyEntry", 10) == 0) { /* 97/July/12 */ } else if (strncmp(s, "Separator", 9) == 0) { AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL); nApplications++; } else { AppendMenu(hSubMenu, MF_ENABLED | MF_STRING, IDM_APPLICATION + nApplications, s); nApplications++; } s = s + strlen(s) + 1; if (*s == '\0') break; } if (keybuffer != NULL) LocalFree ((HLOCAL) keybuffer); /* bTeXMenuOK = 1; */ /* set once it has been filled */ return; } /* hWnd unreferenced */ void cleartexmenu (HWND hWnd) { /* clear the TeX menu */ /* HMENU hMenu; */ HMENU hSubMenu; int i, n; /* int m; */ if (!bApplications) return; if (hTeXMenu == NULL) return; #ifdef IGNORED hMenu = GetMenu(hWnd); m = GetMenuItemCount(hMenu); if (!bHelpAtEnd) hSubMenu = GetSubMenu(hMenu, m - 1); /* last sub menu */ else hSubMenu = GetSubMenu(hMenu, m - 2); /* last sub menu */ #endif hSubMenu = hTeXMenu; n = GetMenuItemCount(hSubMenu); for (i = n-1; i >= 0; i--) DeleteMenu(hSubMenu, i, MF_BYPOSITION); } /* hWnd unreferenced */ int checktexmenu (HWND hWnd) { /* see whether menu agrees with ini file */ int k, nmenu; /* int m; */ int napp=0, flag=0; /* HMENU hMenu; */ HMENU hSubMenu; char menustring[MAXKEY]; char *keybuffer=NULL; /* 97/June/5 */ /* possible allocate memory for keybuffer ? */ char *s, *sm; if (!bApplications) return 0; if (hTeXMenu == NULL) return 0; /* start by reading in all of the keys in the [Applications] section */ for (;;) { keybuffer = (char *) LocalAlloc(LMEM_FIXED, (UINT) nkeybuffer); if (keybuffer == NULL) { winerror ("Unable to allocate memory"); return -1; } k = GetPrivateProfileString(achAp, NULL, "", /* keybuffer, sizeof(keybuffer), achFile); */ keybuffer, nkeybuffer, achFile); if (k < nkeybuffer-2) break; /* the keys fitted in */ LocalFree ((HLOCAL) keybuffer); nkeybuffer = nkeybuffer * 2; /* try again with larger buffer */ } #ifdef IGNORED hMenu = GetMenu(hWnd); m = GetMenuItemCount(hMenu); if (!bHelpAtEnd) hSubMenu = GetSubMenu(hMenu, m - 1); /* last sub menu */ else hSubMenu = GetSubMenu(hMenu, m - 2); /* last sub menu */ #endif hSubMenu = hTeXMenu; nmenu = GetMenuItemCount(hSubMenu); s = keybuffer; /* s = str; */ napp = 0; if (bCallPreview) napp++; /* step over first two */ if (bCallPreview) napp++; /* for separator */ for (;;) { GetMenuString(hSubMenu, napp, menustring, sizeof(menustring), MF_BYPOSITION); if ((sm = strchr(menustring, '\t')) != NULL) *sm = '|'; /* 93/Dec/25*/ if (strcmp(s, menustring) != 0) { /* see if key matches */ flag = 1; break; /* no => mismatch */ } s = s + strlen(s); napp++; if (*s == '\0' && napp == nmenu ) { /* correct number of items ? */ flag = 0; break; /* yes, finish together */ } if (*s == '\0' || napp == nmenu) { flag = 1; break; /* no, one shorter than other */ } } if (keybuffer != NULL) LocalFree ((HLOCAL) keybuffer); return flag; /* returns non-zero if mismatch */ } /* hWnd unreferenced */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* Simpleminded bubblesort for env var names */ /* Should be efficient enough, since we typically have only 25-30 env vars */ /* Do we want to make this case insensitive? */ void sortkeys (char *keys[], int nenv) { int i, j, flag; char *s; for (i = 0; i < nenv-1; i++) { flag = 0; for (j = 0; j < nenv-i-1; j++) { if (strcmp(keys[j], keys[j+1]) > 0) { s = keys[j]; keys[j] = keys[j+1]; keys[j+1] = s; flag++; } } if (flag == 0) break; } } // Environment variables that should not be listed in the menu // since these are handled elsewhere ... int IgnoreEnv (char *s) { if (_stricmp(s, "DummyEntry") == 0) return 1; if (_stricmp(s, "DEBUGPAUSE") == 0) return 1; if (_stricmp(s, "Encoding") == 0) return 1; return 0; } /* New 1998/Aug/28 - support for [Environment] variable fiddling */ void fillenvmenu (HWND hWnd) { HMENU hSubMenu; char *s; int k, nenv; char *keybuffer=NULL; /* 97/June/5 */ char **keys=NULL; if (!bEnvironment) return; if (hEnvMenu == NULL) return; nEnvironment = 0; hSubMenu = hEnvMenu; if (bNewEnvVar) { strcpy(str, "[...NEW...]"); AppendMenu(hSubMenu, MF_ENABLED | MF_STRING, IDM_ENVIRONMENT + nEnvironment, str); nEnvironment++; } if (bCallPreview) { AppendMenu(hSubMenu, MF_SEPARATOR, 0, NULL); nEnvironment++; } /* start by reading in all of the keys in the [Environment] section */ for (;;) { keybuffer = (char *) LocalAlloc(LMEM_FIXED, (UINT) nkeybuffer); if (keybuffer == NULL) { winerror ("Unable to allocate memory"); return; } k = GetPrivateProfileString(achEnv, NULL, "", keybuffer, nkeybuffer, achFile); if (k < nkeybuffer-2) break; /* the keys fitted in */ LocalFree ((HLOCAL) keybuffer); nkeybuffer = nkeybuffer * 2; /* try again with larger buffer */ } s = keybuffer; nenv = 0; while (*s != '\0') { /* don't count "ENCODING" "DEBUGPAUSE" "DummyEntry" */ if (IgnoreEnv(s) == 0) nenv++; s = s + strlen(s) + 1; } if (nenv > 0) { keys = (char **) LocalAlloc(LMEM_FIXED, nenv * sizeof(char *)); if (keys == NULL) { winerror ("Unable to allocate memory"); return; } s = keybuffer; k = 0; while (*s != '\0') { /* don't include "ENCODING" */ /* don't include "DummyEntry" */ /* don't count "ENCODING" "DEBUGPAUSE" "DummyEntry" */ if (IgnoreEnv(s) == 0) { keys[k++] = s; if (k >= nenv) break; /* sanity check */ } s = s + strlen(s) + 1; } if (k < nenv) { if (bDebug > 1) { sprintf(debugstr, "k %d nenv %d", k, nenv); winerror(debugstr); } nenv = k; } if (bSortEnv) sortkeys(keys, nenv); for (k = 0; k < nenv; k++) { s = keys[k]; /* if (_strnicmp(s, "DummyEntry", 10) == 0) continue; */ AppendMenu(hSubMenu, MF_ENABLED | MF_STRING, IDM_ENVIRONMENT + nEnvironment, s); nEnvironment++; } } if (keybuffer != NULL) LocalFree ((HLOCAL) keybuffer); return; } /* hWnd unreferenced */ #ifdef IGNORED s = keybuffer; while (*s != '\0') { AppendMenu(hSubMenu, MF_ENABLED | MF_STRING, IDM_ENVIRONMENT + nEnvironment, s); nEnvironment++; s = s + strlen(s) + 1; } #endif void clearenvmenu (HWND hWnd) { /* clear the env menu */ HMENU hSubMenu; int i, n; if (!bEnvironment) return; if (hEnvMenu == NULL) return; hSubMenu = hEnvMenu; n = GetMenuItemCount(hSubMenu); for (i = n-1; i >= 0; i--) DeleteMenu(hSubMenu, i, MF_BYPOSITION); } /* hWnd unreferenced */ int checkenvmenu (HWND hWnd) { /* see whether menu agrees with ini file */ int k, nmenu; int napp=0, flag=0; HMENU hSubMenu; char menustring[MAXKEY]; char *keybuffer=NULL; /* 97/June/5 */ char *s; if (!bEnvironment) return 0; if (hEnvMenu == NULL) return 0; /* start by reading in all of the keys in the [Environment] section */ for (;;) { keybuffer = (char *) LocalAlloc(LMEM_FIXED, (UINT) nkeybuffer); if (keybuffer == NULL) { winerror ("Unable to allocate memory"); return -1; } k = GetPrivateProfileString(achAp, NULL, "", keybuffer, nkeybuffer, achFile); if (k < nkeybuffer-2) break; /* the keys fitted in */ LocalFree ((HLOCAL) keybuffer); nkeybuffer = nkeybuffer * 2; /* try again with larger buffer */ } hSubMenu = hEnvMenu; nmenu = GetMenuItemCount(hSubMenu); s = keybuffer; /* s = str; */ napp = 0; if (bNewEnvVar) napp++; /* step over first two */ if (bNewEnvVar) napp++; /* for separator */ for (;;) { GetMenuString(hSubMenu, napp, menustring, sizeof(menustring), MF_BYPOSITION); if (strcmp(s, menustring) != 0) { /* see if key matches */ flag = 1; break; /* no => mismatch */ } s = s + strlen(s); napp++; if (*s == '\0' && napp == nmenu ) { /* correct number of items ? */ flag = 0; break; /* yes, finish together */ } if (*s == '\0' || napp == nmenu) { flag = 1; break; /* no, one shorter than other */ } } if (keybuffer != NULL) LocalFree ((HLOCAL) keybuffer); return flag; /* returns non-zero if mismatch */ } /* hWnd unreferenced */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* hot key matches menu ? */ int translatehotkey (HWND hWnd, int nVKey, int control) { int nmenu, n; /* int m; */ int napp=0; /* HMENU hMenu; */ HMENU hSubMenu; char menustring[MAXKEY]; char *sm; if (!bApplications) return 0; if (hTeXMenu == NULL) return 0; /* if (nVKey == VK_F1) { CallHelp(hWnd); return 0; } */ /* hard-wired to Help ? */ /* if (nVKey == VK_F1 && control != 0) */ /* return 1; */ /* C-F1 is hard wired to `Preview' */ /* first check out preview */ /* just treat the same as all the rest ? */ /* sm = szPreviewHotKey; if (control == 0 && *sm == 'F') n = atoi(sm+1); else if (control != 0 && strncmp(sm, "C-F", 3) == 0) n = atoi(sm+3); else n = 0; if (n == (nVKey - VK_F1 + 1)) return 1; */ #ifdef IGNORED hMenu = GetMenu(hWnd); m = GetMenuItemCount(hMenu); if (!bHelpAtEnd) hSubMenu = GetSubMenu(hMenu, m - 1); /* last sub menu */ else hSubMenu = GetSubMenu(hMenu, m - 2); /* last sub menu */ #endif hSubMenu = hTeXMenu; nmenu = GetMenuItemCount(hSubMenu); napp = 0; /* if (bCallPreview) napp++; */ /* step over second */ for (;;) { GetMenuString(hSubMenu, napp, menustring, sizeof(menustring), MF_BYPOSITION); if ((sm = strchr(menustring, '\t')) != NULL) { sm++; if (control == 0 && *sm == 'F') n = atoi(sm+1); /* grab number */ else if (control != 0 && strncmp(sm, "C-F", 3) == 0) n = atoi(sm+3); /* grab number */ else n = 0; if (n == (nVKey - VK_F1 + 1)) return napp; /* found it */ } napp++; if (napp == nmenu ) break; } return -1; /* returns negative if not found */ } /* hWnd unreferenced */ /* NOTE: Also sets up value for this key in string str */ int findmenukey (HWND hWnd, char *name) { /* find menu item if exist */ int nmenu; int napp=0; /* int m; */ /* int flag=0; */ /* HMENU hMenu; */ HMENU hSubMenu; char menustring[MAXKEY]; char *s, *sm; int n; if (!bApplications) return 0; if (hTeXMenu == NULL) return 0; if ((s = strchr(name, '|')) != NULL) n = s - name; else n = strlen(name); #ifdef IGNORED hMenu = GetMenu(hWnd); m = GetMenuItemCount(hMenu); if (!bHelpAtEnd) hSubMenu = GetSubMenu(hMenu, m - 1); /* last sub menu */ else hSubMenu = GetSubMenu(hMenu, m - 2); /* last sub menu */ #endif hSubMenu = hTeXMenu; nmenu = GetMenuItemCount(hSubMenu); s = str; napp = 0; if (bCallPreview) napp++; /* step over first two */ if (bCallPreview) napp++; /* for separator */ for (;;) { GetMenuString(hSubMenu, napp, menustring, sizeof(menustring), MF_BYPOSITION); if ((sm = strchr(menustring, '\t')) != NULL) *sm = '|'; if (strncmp(menustring, name, n) == 0 && (menustring[n] == '\0' || menustring[n] == '|')) { n = GetPrivateProfileString(achAp, menustring, "", str, sizeof(str), achFile); return n; } s = s + strlen(s); napp++; if (napp == nmenu) break; } return 0; /* returns zero if failed */ } /* hWnd unreferenced */ /* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ /* replace string at s of length ns with string at t length nt */ /* remember to move/copy the terminating null of s also ... */ /* returns 0 if it won't fit in buffer */ /* returns 1 if success */ /* void replacestring (char *s, int ns, char *t, int nt) */ int replacestring (char *s, int ns, char *t, int nt, char *buf, unsigned int nbuf) { /* check space available first */ if (nt > ns) { /* if replacement is larger than original */ if (strlen (buf) + (nt - ns) >= nbuf) { sprintf(str, "Pattern too large:\n%s", buf); winerror(str); return 0; } } memmove (s + nt, s + ns, strlen (s + ns) + 1); memcpy (s, t, nt); return 1; } /* Replace string, but if it contains spaces, delimit with quotes "..." */ /* unless it is already delimited by "..." 2000 May 27 */ int replacestringspace (char *s, int ns, char *t, int nt, char *buf, unsigned int nbuf) { /* 97/June/10 */ if (strchr(t, ' ') == NULL) return replacestring(s, ns, t, nt, buf, nbuf); if (s > buf && *(s-1) == '\"' && *(s+ns) == '\"') { return replacestring(s, ns, t, nt, buf, nbuf); } /* somewhat inefficient, but should hardly ever happen */ if (nt+2 > ns) { if (strlen (buf) + (nt+2 - ns) >= nbuf) { sprintf(str, "Pattern too large:\n%s", buf); winerror(str); return 0; } } replacestring(s, 0, "\"", 1, buf, nbuf); replacestring(s+1, ns, t, nt, buf, nbuf); replacestring(s+nt+1, 0, "\"", 1, buf, nbuf); return 1; } /* Used for szVector = grabenv("ENCODING"); and expandenv and TryWinExe */ /* and grabenv("YANDYPATH") in winprint.c for locating DVIPSONE and AFMtoTFM */ /* This assume str is available */ /* returns either str or DOS env var */ /* Will need to make copy using strdup for other than temporary use */ /* Returns NULL if not found ? */ char *grabenv (char *envvar) { /* look in dviwindo.ini 1994/May/23 */ if (bUseDVIWindo) { (void) GetPrivateProfileString(achEnv, envvar, "", str, sizeof(str), achFile); if (*str != '\0') return str; /* drop through if not found */ } return getenv(envvar); /* else try and get from DOS env */ } /* Deal with idiots who have white space in their environment variables! */ /* is this a safe thing to do now with file names that have spaces? */ /* conversely, should it be quoted if it does contain spaces? */ void stripspaces (char *str) { /* 96/June/26 */ char *s; int flag=0; s = str + strlen(str) - 1; // work backwards from right end while (s >= str) { if (*s <= ' ') { if (flag++ == 0) { /* show error first time in debug mode */ if (bDebug) (void) wincancel(str); } if (*(s+1) == '\0') strcpy(s, s+1); // trailing spaces else if (s > str) { // following on separator if (*(s-1) == ';' || *(s-1) == ',') strcpy(s, s+1); } } s--; } } /* Replace %% with value of environment variable */ int expandpercent (char *buf, unsigned int nbuf) { char environvar[BUFLEN]; /* needs to be this big? */ /* char *se, *te, *t, *u; */ char *se, *te; char *environvalue; /* int c, n, flag, first; */ int n; if ((se = strchr(buf, '%')) == NULL) return 1; /* nothing to do */ if ((te = strchr(se+1, '%')) == NULL) { if (bDebug) (void) wincancel(buf); /* show error 96/June/20 */ return 0; /* no match --- syntax error */ } se = buf; while ((se = strchr(se, '%')) != NULL) { if ((te = strchr(se+1, '%')) == NULL) { if (bDebug) (void) wincancel(buf); /* show error 96/June/20 */ return 0; /* no match --- syntax error */ } /* if (*(te+1) > ' ') { se = te + 1; continue; } */ /* no, leave for expandpercent later if not white space */ n = te - (se + 1); strncpy(environvar, se+1, n); *(environvar+n) = '\0'; /* DOS generally believes only in upper case env vars */ makeuppercase(environvar); /* in winpslog.c */ /* environvalue = getenv(environvar); */ environvalue = grabenv(environvar); if (environvalue == NULL) { /* environment variable not found */ if (bDebug) (void) wincancel(buf); /* show error 96/June/20 */ strcpy(se, te+1); /* just strip out the variable */ continue; /* could also call this an error? */ } /* now replace the %environvar% with the value */ /* try and check */ /* special case check on stuff like %TEXINPUTS%#*.tex 96/June/20 */ if (*(te+1) == '#') stripspaces(environvalue); /* 96/June/20 */ if (replacestring(se, (te+1 - se), environvalue, strlen(environvalue), buf, nbuf) == 0) return 0; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "replaced environment var: %s\n", buf); OutputDebugString(debugstr); } #endif } return 1; } /* Replace * with file name currently open (minus extension) */ /* if no file open, replace * with ? (meaning prompt user) */ /* but don't expand if -* since that may be command line option DVIPSONE */ int expandasterisk (char *buf, unsigned int nbuf) { char *s, *t; /* 97/Jan/14 */ char *namestart; /* char *nameend; */ int n; if (strchr(buf, '*') == NULL) return 1; /* nothing to do */ if (bFileValid == 0) { /* if no file open, prompt for file name */ s = buf; /* while ((s = strchr(s, '*')) != NULL) *s = '?'; */ while ((s = strchr(s, '*')) != NULL) { if (s == buf || *(s-1) != '-') /* avoid -* 97/Jan/14 */ *s = '?'; /* replace * with ? */ s++; /* fix 97/Mar/7 */ } #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "Replaced * with ?: %s\n", buf); OutputDebugString(debugstr); } #endif return 1; /* unable to replace * with file name */ } /* ignore path, since DVI file may be in quite different place from source */ namestart = removepath(OpenName); /* in winspeci.c */ /* if want fully qualified name, set namestart = OpenName here */ /* ignore extension if any, since we don't want DVI extension */ /* if ((s = strrchr(namestart, '.')) != NULL) nameend = s; else nameend = namestart + strlen(namestart); n = nameend - namestart; */ /* if ((s = strrchr(namestart, '.')) != NULL) n = s - namestart; */ /* made the following deal with things like ..\foo\bar 97/Jan/14 */ if ((s = strrchr(namestart, '.')) != NULL && ((t = strrchr(namestart, '\\')) == NULL || t < s) && ((t = strrchr(namestart, '/')) == NULL || t < s)) n = s - namestart; else n = strlen(namestart); s = buf; /* deal here with file name that has spaces in it ? */ while ((s = strchr(s, '*')) != NULL) { if (s == buf || *(s-1) != '-') { /* avoid -* 97/Jan/14 */ if (strchr(s, ' ') != NULL) { /* 97/Oct/23 */ if (replacestringspace(s, 1, namestart, n, buf, nbuf) == 0) return 0; /* won't fit in buffer give up */ } else { if (replacestring(s, 1, namestart, n, buf, nbuf) == 0) return 0; /* won't fit in buffer give up */ } } s++; /* fix 97/Mar/7 */ } /* hack to get right file name in even though OpenFile Dialog not shown ??? */ /* strcpy(SourceOpenName, ""); */ strncpy(SourceOpenName, namestart, n); SourceOpenName[n] = '\0'; strcat(SourceOpenName, SourceDefExt); /* ??? */ /* hack to get right file name in even though OpenFile Dialog not shown ??? */ return 1; /* succeeded */ } /* replace @ with %TEXINPUTS%#* 1994/July/3 */ /* this makes menu entries look less intimidating */ /* what about format specific environment variables ??? */ /* how do we know what format is being used anyway ??? */ int expandatsign (char *buf, unsigned int nbuf) { char *s; /* char *namestart; */ /* char *nameend; */ int n; if (strchr(buf, '@') == NULL) return 1; /* nothing to do */ if (bQuoteAtSign) { // 2000 May 27 s = buf; while ((s = strchr(s, '@')) != NULL) { // don't do if already quoted if (s > buf && *(s-1) != '\"') { n = strlen(s); memmove(s+1, s, n+1); *s = '\"'; while (*s > ' ') s++; n = strlen(s); memmove(s+1, s, n+1); *s = '\"'; } } } s = buf; while ((s = strchr(s, '@')) != NULL) { if (replacestring(s, 1, "%TEXINPUTS%#*", 13, buf, nbuf) == 0) return 0; } return 1; /* succeeded */ } char *deslash (char *s) { char *name = s; if (name) { while (*s) { if (*s == '\\') *s = '/'; s++; } /* endwhile */ } #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "Unixified name: %s\n", name); OutputDebugString(debugstr); } #endif return name; } /* this was separated out 1994/Aug/18 */ /* semicolon separated list of directories in `environvalue' */ /* name of file in `FileName' */ /* resulting full path name written back into `testname' */ /* returns non-zero if it fails to find the file */ /* do we screw something up by replacing the _access ??? */ int getthepath (char *environvalue, char *filename, char *testname) { char *s; #ifdef LONGNAMES HFILE hFile; /* shows global hFile ? */ #endif #ifndef SUBDIRSEARCH char *dirstar; #ifndef LONGNAMES OFSTRUCT OfStruct; #endif #endif if (bCurrentFlag) { /* try `current' (DVI) directory first ? */ if (bFileValid || bUseSourcePath) strcpy(testname, DefPath); /* use dir of DVI file */ else { /* Will the following `DOS' code work in WIN32 ? */ GetCurrentDirectory(sizeof(testname), testname); } #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "current directory: %s\n", testname); OutputDebugString(debugstr); } #endif s = (testname + strlen(testname) - 1); if (*s != '\\' && *s != '/') strcat(testname, "\\"); strcat(testname, filename); #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "testname: %s\n", testname); OutputDebugString(debugstr); } #endif /* do we loose the sub-directory search capbility here ? */ /* how does this compare with _access ??? */ /* use LongOpenFile instead ??? No, has its own search...*/ #ifdef LONGNAMES /* 95/Dec/1 */ /* hFile = _lopen(testname, READ); */ hFile = _lopen(testname, READ | OfExistCode); /* 96/May/18 */ if (hFile != HFILE_ERROR) { _lclose(hFile); hFile = HFILE_ERROR; return 0; /* success */ } #else #ifdef SUBDIRSEARCH /* check this can handle long file names ??? */ /* ACCESSCODE = 4 means check for read permision */ if (_access(testname, 4) == 0) return 0; /* success */ #else if (OpenFile(testname, &OfStruct, OF_EXIST) != HFILE_ERROR) return 0; /* success */ #endif /* not SUBDIRSEARCH */ #endif /* not LONGNAMES */ } #ifdef SUBDIRSEARCH if (searchalongpath (filename, environvalue, testname, 0) != 0) return -1; /* it failed */ else return 0; /* success */ #else dirstar = environvalue; /* step through and try paths in list */ for (;;) { /* try next directory in list */ dirstar = nextpathname(testname, dirstar); s = (testname + strlen(testname) - 1); if (*s != '\\' && *s != '/') strcat(testname, "\\"); strcat(testname, filename); #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "next testname: %s\n", testname); OutputDebugString(debugstr); } #endif #ifdef LONGNAMES /* hFile = _lopen(testname, READ); */ hFile = _lopen(testname, READ | OfExistCode); /* 96/May/18 */ if (hFile != HFILE_ERROR) { _lclose(hFile); hFile = HFILE_ERROR; return 0; /* success */ } #else if (OpenFile(testname, &OfStruct, OF_EXIST) != HFILE_ERROR) return 0; /* success */ #endif if (dirstar == NULL) /* end of the road ? - failed to find it */ break; /* failed */ } /* end of for(;;) env var search loop */ return -1; /* failed */ #endif } /* search for file matching specification along path given */ int expandhash (char *buf, unsigned int nbuf) { char filename[MAXFILENAME]; char testname[MAXFILENAME]; char *se, *te, *ue; char *environvalue; int c, n; char *s; /* 96/Oct/12 */ int flag, stripextension=0; /* 96/Oct/12 */ #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "entering expandhash: %s\n", buf); OutputDebugString(debugstr); } #endif if ((se = strchr(buf, '#')) == NULL) return 1; /* nothing to do */ se = buf; while ((se = strchr(se, '#')) != NULL) { if (*(se+1) == '?') { /* does `file name' start with ? */ /* strip out back to white space ? */ se++; /* step over it */ continue; /* and punt if filename unknown */ } te = se; // while (*te > ' ' && te > buf) while ((c = *te) > ' ' && c != '\"' && te > buf) // 2000 May 21 te--; /* scan back to white space (or ") */ if (te > buf) te++; environvalue = te; /* semicolon delimited path */ ue = se; /* change scan 97/Oct/23 will this create problems ? */ while (*ue != '.' && *ue != '\0') ue++; /* scan to file extension */ // while (*ue > ' ') while ((c = *ue) > ' ' && c != '\"') ue++; /* scan forward to white space (or ") */ n = ue - (se+1); strncpy(filename, se+1, n); filename[n] = '\0'; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "extracted filename: %s\n", filename); OutputDebugString(debugstr); } #endif *se = '\0'; /* delimit path list */ /* first = bCurrentFlag; */ /* try current directory first ? */ /* following split off 1994/Aug/18 */ /* if (getthepath(environvalue, filename, testname) != 0) */ flag = getthepath(environvalue, filename, testname); /* New: if no extension try with .tex extension, but strip off later */ if (flag != 0) { /* 1996/Oct/12 */ if (strchr(filename, '.') == NULL) { stripextension = 1; strcat(filename, ".tex"); /* try .tex extension */ flag = getthepath(environvalue, filename, testname); } } if (flag != 0) { *se = '#'; /* failed to find it - put hash back */ *(se+1) = '?'; /* replace file name with ? */ if ((ue = strchr(te, '.')) != NULL) strcpy(se+2, ue); else if ((ue = strchr(te, ' ')) != NULL) strcpy(se+2, ue); else *(se+2) = '\0'; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "failed: %s\n", buf); OutputDebugString(debugstr); } #endif return 1; /* will prompt for file name later */ } /* succeeded - now replace the # with complete filename */ *se = '#'; /* Now update SourceDefPath --- needed for next OpenFile Dialog */ /* ALSO needed if bUseSourcePath is non-zero 1993/Dec/10 */ strcpy(SourceDefPath, testname); *removepath(SourceDefPath) = '\0'; /* terminate after separator */ strcpy(SourceOpenName, removepath(testname)); #ifdef DEBUGPATTERN if (bDebug > 1) { OutputDebugString("Source Def Path: "); OutputDebugString(SourceDefPath); } #endif /* moved down here so SourceDefPath is slash free */ /* if (replacestring(te, (ue - te) + strlen(filename), */ if (bUnixify) deslash (testname); /* 1993/Dec/21 */ if (stripextension) { /* 1996/Oct/12 */ if ((s = strrchr(testname, '.')) != NULL) *s = '\0'; } /* quote the file name (to allow spaces in names) 97/Oct/23 */ if (strchr(testname, ' ') != NULL) { /* 97/Oct/23 */ if (replacestringspace(te, (ue - te), testname, strlen(testname), buf, nbuf) == 0) return 0; } else { if (replacestring(te, (ue - te), testname, strlen(testname), buf, nbuf) == 0) return 0; } se = te; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "replaced with filename: %s\n", buf); OutputDebugString(debugstr); } #endif } return 1; } // Common Dialog box stuff for File Open Dialog // called to fill in ? in expanding TeX Menu item #define FILEOPENORD 1536 /* in dlgs.h */ /* char *getuserfilename(HWND hWnd, char *filename) */ char *getuserfilename (HWND hWnd, char *filename, char *key) { /* do hairy stuff here later */ OPENFILENAME ofn; char szDirName[MAXFILENAME]; char szFile[MAXFILENAME]; char szFileTitle[MAXFILENAME]; /* on output file name minus path */ /* char szFilter[MAXFILENAME]; */ char szFilter[256]; /* 1994/Feb/10 */ /* char szExt[] = "tex"; */ /* default extension */ /* char *szExt = "tex"; */ /* default extension */ char szTitle[MAXKEY]="Select File"; UINT i, cbString; char chReplace; /* string separator for szFilter */ /* HFILE hf; */ int flag; char *s; if (bUsingCommDlg && bAllowCommDlg) { if (bDebug > 1) { sprintf(debugstr, "SourceDefPath '%s' SourceDefSpec '%s' SourceDefExt '%s'\n", SourceDefPath, SourceDefSpec, SourceDefExt); OutputDebugString(debugstr); } /* removeback(SourceDefPath); */ /* 1993/Dec/9 */ ChangeDirectory(SourceDefPath, 1); /* change directory and drive */ /* trailingback(SourceDefPath); */ /* 1993/Dec/9 */ if (key != NULL) { /* 1994/Feb/25 */ strcpy(szTitle, key); if ((s = strchr(szTitle, '|')) != NULL) *s='\0'; } /* if we validate file names ourselves we need to register message */ /* if (bNoValidate) uFileOKMsg = RegisterWindowMessage(FILEOKSTRING); */ /* May now be in wrong directory for application ! 1993/Dec/9 */ /* GetSystemDirectory(szDirName, sizeof (szDirName)); */ strcpy(szDirName, filename); /* copy directory from file name */ if ((s = strrchr(szDirName, '\\')) != NULL) ; else if ((s = strrchr(szDirName, '/')) != NULL) ; else if ((s = strrchr(szDirName, ':')) != NULL) s++; else s = szDirName + strlen(szDirName); *s = '\0'; /* overrridden later */ /* szFile[0] = '\0'; */ strcpy(szFile, removepath(filename)); /* Now set up file type selection string */ if ((cbString = LoadString(hInst, IDS_FILTERSTRING, szFilter, sizeof(szFilter))) == 0) { strcpy(szFilter, "TeX files(*.tex)|*.tex|"); } chReplace = szFilter[cbString - 1]; /* retrieve wild character */ for (i = 0; szFilter[i] != '\0'; i++) if (szFilter[i] == chReplace) szFilter[i] = '\0'; memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWnd; ofn.lpstrFilter = szFilter; /* ofn.nFilterIndex = 1; */ ofn.nFilterIndex = TeXFilterIndex; ofn.lpstrFile = szFile; /* have enough space for long name */ ofn.nMaxFile = sizeof(szFile); ofn.lpstrFileTitle = szFileTitle; ofn.nMaxFileTitle = sizeof(szFileTitle); /* ofn.lpstrTitle = "Select File"; */ ofn.lpstrTitle = szTitle; /* 1994/Feb/25 */ /* ofn.lpstrInitialDir = szDirName; */ /* ofn.lpstrInitialDir = SourceDefPath; */ /* 1993/Dec/9 */ /* ofn.lpstrDefExt = szExt; */ /* default extension */ /* ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; */ ofn.Flags = OFN_HIDEREADONLY; /* default is not to set this flags - but it doesn't help ? */ if (bMustExist) ofn.Flags |= OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; else if (bCreateFile) ofn.Flags |= OFN_CREATEPROMPT; /* 97/March/29 */ /* if (bNoValidate) */ /* 1996/Aug/18 */ /* ofn.Flags != OFN_NOVALIDATE; */ /* ofn.lpfnHook = OpenFileHook; */ /* ofn.Flags |= OFN_ENABLEHOOK; */ /* need also OFN_EXPLORER if using new style dialog box */ /* *and* a more complicated hook procedure ! */ /* } */ /* Use our own template with longer file list */ /* except in new shell in Windows 95 where we have long file names */ if (bHiresScreen && (bNewShell == 0)) /* if (bHiresScreen) */ { ofn.hInstance = hInst; ofn.Flags = ofn.Flags | OFN_ENABLETEMPLATE; ofn.lpTemplateName = MAKEINTRESOURCE(FILEOPENORD); } #ifdef LONGNAMES if (bLongNames) { /* has no effect with Explorer style dialog ... */ ofn.Flags = ofn.Flags | OFN_LONGNAMES; /* 95/Dec/5 */ /* if (bDebug > 1) OutputDebugString("OFN_LONGNAMES\n"); */ } #endif flag = GetOpenFileName(&ofn); /* WINVER == 0x300 problem ? */ if (flag == 0) { /* no file specified */ if (bDebug > 1) OutputDebugString("GetOpenFileName returned zero\n"); if (bAllowBlank) return ""; /* leave it blank - 1994/June/29 */ else return NULL; /* user cancelled - don't go on - 1993/Dec/7 */ } else { if (bDebug > 1) { TeXFilterIndex = ofn.nFilterIndex; /* remember 95/July/6 */ sprintf (debugstr, "lpstrFile %s nFileOffset %d nFileExtension %d", ofn.lpstrFile, ofn.nFileOffset, ofn.nFileExtension); OutputDebugString(debugstr); } /* New special case, a way to indicate don't want to specify file */ if (lstrcmp(ofn.lpstrFile + ofn.nFileOffset, "!") == 0) return ""; /* 94/July/11 */ if (lstrcmp(ofn.lpstrFile + ofn.nFileOffset, "nul") == 0) return ""; /* 95/July/6 */ /* lopen(ofn.lpstrFile, OF_READ); */ /* lstrcpy (SourceOpenName, ofn.lpstrFile); */ /* 1993/Dec/9 */ lstrcpy (SourceOpenName, ofn.lpstrFile + ofn.nFileOffset); /* following added 1993/Dec/9 */ if (ofn.nFileExtension > 0) { /* retrieve extension for future reference ".tex" */ SourceDefExt[0] = '.'; lstrcpy (SourceDefExt+1, ofn.lpstrFile + ofn.nFileExtension); /* retrieve default file specification for future reference "*.tex" */ SourceDefSpec[0] = '*'; SourceDefSpec[1] = '.'; lstrcpy (SourceDefSpec+2, ofn.lpstrFile + ofn.nFileExtension); } else { /* 98/Sep/14 */ SourceDefExt[0] = '\0'; SourceDefSpec[0] = '*'; SourceDefSpec[1] = '\0'; } /* retrieve path for future reference */ lstrcpy (SourceDefPath, ofn.lpstrFile); *(SourceDefPath + ofn.nFileOffset) = '\0'; if (bDebug > 1) { sprintf(debugstr, "lpstrFile '%s' nFileOffset %d nFileExtension %d", ofn.lpstrFile, ofn.nFileOffset, ofn.nFileExtension); OutputDebugString(debugstr); sprintf(debugstr, "OpenName '%s', DefExt '%s', DefSpec '%s', DefPath '%s'\n", SourceOpenName, SourceDefExt, SourceDefSpec, SourceDefPath); OutputDebugString(debugstr); } } /* return SourceOpenName; */ /* is it safe to construct the name in str ? */ strcpy(str, SourceDefPath); /* 1993/Dec/9 */ s = SourceDefPath + strlen(SourceDefPath) - 1; if (*s != '\\' && *s != '/') strcat (str, "\\"); strcat(str, SourceOpenName); if (!bMustExist && bCreateFile) { /* 97/Mar/29 */ HFILE hFile; hFile = _lopen(str, READ | OfExistCode); /* does file exist? */ if (hFile == HFILE_ERROR) { /* if not, create an empty one */ /* hFile = _lopen(str, WRITE); */ hFile = _lcreat(str, 0); if (hFile == HFILE_ERROR) { DWORD err; err = GetLastError(); /* err = errno; */ sprintf(debugstr, "Unable to create file %s (%d)\n", str, errno); (void) ExplainError(debugstr, err, 1); /* winerror(debugstr); */ } } _lclose(hFile); } if (bUnixify) deslash(str); /* 94/Dec/31 ??? */ return str; } /* end of CommDlg method for file selection */ else { /* do it the old Windows 3.0 way */ strcpy(SourceOpenName, filename); flag = DialogBoxParam(hInst, "FileSelect", hWnd, FileDlg, 1L); /* indicate `Call Application' mode */ /* if (flag == 0) return filename; */ if (bUnixify) deslash(SourceOpenName); /* 1994/Dec/31 ??? */ if (flag <= 0) return NULL; else return SourceOpenName; } } void stripextension (char *name) { char *s, *t; if ((s = strrchr(name, '\\')) != NULL) s++; else if ((s = strrchr(name, '/')) != NULL) s++; else if ((s = strrchr(name, ':')) != NULL) s++; else s = name; if ((t = strrchr(s, '.')) != NULL) *t = '\0'; } // copy string up to next white space // or "..." 2000 May 21 // hence now somewhat of a misnomer ... void copyspacedelimited (char *s, char *t) { int c; // char *so=s; // debugging only char *te = t + strlen(t) - 1; if (*t == '\"') { // form "..." or "... t++; // 2000 May 21 while ((c = *t++) != '\0' && c != '\"') // 2000 May 21 *s++ = (char) c; } else if (*te == '\"') { // form ..." while ((c = *t++) != '\0' && c != '\"') // 2000 May 21 *s++ = (char) c; } else { // form ... // while ((c = *t++) > ' ') /* ends on white space */ while ((c = *t++) > ' ' && c != '\"') // 2000 May 21 *s++ = (char) c; } *s= '\0'; /* end string copied */ // wincancel(so); // debugging only } /* prompt user to supply arguments */ /* form: "Title|Default" */ /* what about quotes used to delimit file name with spaces in it ??? */ int expandquotes (HWND hWnd, char *buf, unsigned int nbuf) { char *se, *te; /* char *sq, *tq; */ int n, m, flag; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "entering expandquotes: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif if ((se = strchr(buf, '\"')) == NULL) return 1; /* no ", nothing to do */ if ((te = strchr(se+1, '\"')) == NULL) { /* is there another " ? */ if (bDebug) (void) wincancel(buf); /* show error 96/June/20 */ return 0; /* mismatch --- syntax error */ } // if ((sb = strchr(se, '|')) == NULL || sb >= te) // return 0; // ignore quoted material without | 2000 May 21 se = buf; /* keep going until no more "..." or "...|..." strings */ while ((se = strchr(se, '\"')) != NULL) { if ((te = strchr(se+1, '\"')) == NULL) { if (bDebug) (void) wincancel(buf); /* show error 96/June/20 */ return 0; /* mismatch --- syntax error */ } // if ((sb = strchr(se, '|')) == NULL || sb >= te) { // se = te + 1; // step over it // continue; // ignore quoted material without | 2000 May 21 // } n = (te - (se+1)); /* may be zero if empty string */ strncpy(str, se+1, n); str[n] = '\0'; if (strchr(str, '|') != NULL) { /* only if "...|..." 96/Oct/12 */ #ifdef DEBUGPATTERN if (bDebug > 1) { OutputDebugString(str); // wincancel(debugstr); // debugging only } #endif flag = DialogBoxParam(hInst, "FileSelect", hWnd, FileDlg, 2L); /* indicate `Supply Parameter' mode */ /* if (flag == 0) strcpy (sq, tq+1);*/ /* just flush the string*/ if (flag <= 0) return 0; /* failed - user cancelled */ /* check whether result should be quoted ... 96/Jan/28 */ /* look for characters that DOS may interpret on the command line */ /* not sure this will work ... i.e., will the " be stripped again ? */ if (strpbrk(str, " |<>=&^") != NULL) { memmove(str+1, str, strlen(str)+1); *str = '\"'; strcat(str, "\""); } /* if (bDebug > 1) { OutputDebugString("User supplied: "); OutputDebugString(str); } */ /* debugging */ m = strlen(str); if (replacestring(se, n+2, str, strlen(str), buf, nbuf) == 0) return 0; /* error, did not fit in buffer */ se = se + m; /* avoid looking at "..." again 96/Jan/28 */ } else se = te + 1; /* step over "..." without change 96/Oct/12 */ /* if (bDebug > 1) { OutputDebugString("Rest of string: "); OutputDebugString(se); } */ /* debugging */ } #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "leaving expandquotes: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif return 1; /* succeeded */ } /* prompt user for file name */ /* either because ? or because shift key */ /* int expandquestion (HWND hWnd, char *buf, unsigned int nbuf, int shift) */ int expandquestion (HWND hWnd, char *buf, unsigned int nbuf, int shiftflag, char *key) { char filename[MAXFILENAME]; char *s, *t, *sq, *tq, *uq; char *newfile; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "entering expandquestion: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif if (strchr(buf, '?') == NULL) { /* no ? on the command line */ if (shiftflag) { /* but shift key pressed */ /* if shift key is pressed prompt for file name using what is constructed */ /* assumes the file to be prompted for is the last thing on the line ! */ s = buf + strlen(buf) - 1; // 2000 May 21 if (*s == '\"' && s > buf) { s = strrchr(s-1, '\"'); // allow for "..." } else s = strrchr(buf, ' '); // last white space // if ((s = strrchr(buf, ' ')) != NULL) /* last white space */ if (s != NULL) { copyspacedelimited(filename, s+1); /* newfile = getuserfilename(hWnd, filename); */ newfile = getuserfilename(hWnd, filename, key); if (newfile == NULL) return 0; /* user cancelled */ if (bStripPath) t = removepath(newfile); /* 96/Oct/4 */ else t = newfile; /* quote the file name (to allow spaces in names) 97/Oct/23 */ if (strchr(newfile, ' ') != NULL) { /* 97/Oct/23 */ if (replacestringspace(s+1, strlen(s+1), t, strlen(t), buf, nbuf) == 0) return 0; } else { if (replacestring(s+1, strlen(s+1), t, strlen(t), buf, nbuf) == 0) return 0; } if (bUnixify) deslash (s+1); /* 1994/Jan/27 */ } else { /* no ' ', only one item on the line - append file name */ strcpy(filename, SourceOpenName); /* newfile = getuserfilename(hWnd, filename); */ newfile = getuserfilename(hWnd, filename, key); if (newfile == NULL) return 0; /* used cancelled */ strcat (buf, " "); /* strcat (buf, newfile); */ /* need space checking ... */ s = buf + strlen(buf); /* if (replacestring(buf + strlen(buf), 0, newfile, strlen(newfile), */ if (bStripPath) t = removepath(newfile); /* 96/Oct/4 */ else t = newfile; /* if (replacestring(s, 0, newfile, strlen(newfile), */ if (replacestring(s, 0, t, strlen(t), buf, nbuf) == 0) return 0; if (bUnixify) deslash (s); /* 1994/Jan/27 */ } return 1; } else return 1; /* nothing to do no ? and no shift key */ /* can't drop through here ... */ } /* end of if (strchr(buf, '?') == NULL) */ /* get here if there is at least one `?' on the line */ /* advance to end of field and retreat to beginning wrt white space */ sq = buf; while ((sq = strchr(sq, '?')) != NULL) { uq = sq; // while (*uq > ' ') uq++; /* advance to end of field */ while (*uq > ' ' && *uq != '\"') uq++; /* advance to end of field - 2000 May 21 */ tq = sq; // while (*tq > ' ' && tq > buf) tq--; /* retreat to beg of field */ while (*tq > ' ' && tq > buf && *tq != '\"') tq--; /* retreat to beg of field - 2000 May 21 */ tq++; /* use previous application field name ? */ if (*SourceOpenName != '\0') { strcpy(filename, SourceOpenName); { sprintf(debugstr, "filename '%s' sq '%s' SourceDefExt '%s'", filename, sq, SourceDefExt); // wincancel(debugstr); // debugging only } if (*(sq+1) == '.') { /* but modify extension ? */ /* if ((s = strrchr(filename, '.')) != NULL) strcpy(s, sq+1); */ /* strncpy(SourceDefExt, sq+1, 4); */ /* new default extension ? */ strcpy(SourceDefExt, sq+1); /* new default extension ? */ s = SourceDefExt + strlen(SourceDefExt) - 1; if (*s == '\"') *s-- = '\0'; // 2000 May 21 // while (*(--s) <= ' ' && s > SourceDefExt) ; while ((*s <= ' ' || *s == '\"') && s > SourceDefExt) *s-- = '\0'; // 2000 May 21 *(s+1) = '\0'; /* 99/Jan/3 */ if ((s = strrchr(filename, '.')) != NULL) strcpy(s, SourceDefExt); // ??? } } else { if (bFileValid != 0) { /* if file open, use as starting point */ /* Will the following `DOS' code work in WIN32 ? */ GetCurrentDirectory(sizeof(filename), filename); if (*(filename + strlen(filename) -1) != '\\') strcat(filename, "\\"); strcat(filename, removepath(OpenName)); stripextension(filename); /* flush extension */ #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "constructed: %s\n", filename); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif } else { /* Will the following `DOS' code work in WIN32 ? */ GetCurrentDirectory(sizeof(filename), filename); if (*(filename + strlen(filename) - 1) != '\\') strcat(filename, "\\"); strcat(filename, "*"); /* ? */ } /* attach specified extension to guess */ copyspacedelimited(filename+strlen(filename), sq+1); } #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "offering to getuserfilename: %s\n", filename); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif /* newfile = getuserfilename(hWnd, filename); */ newfile = getuserfilename(hWnd, filename, key); if (newfile == NULL) return 0; /* user cancelled */ if (bStripPath) t = removepath(newfile); /* 96/Oct/4 */ else t = newfile; /* if (replacestring(tq, uq - tq, newfile, strlen(newfile), */ if (replacestring(tq, uq - tq, t, strlen(t), buf, nbuf) == 0) return 0; /* s not initialized ??? use tq ??? instead */ /* if (bUnixify) deslash (s); */ /* 1995/Jan/13 */ if (bUnixify) deslash (tq); /* 1998/Mar/26 ??? */ /* replacestring(sq, tq - sq -1, newfile, strlen(newfile)); */ /* if (*(sq-1) == '%') removeenviron(buf, sq); */ #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "present state: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif sq = tq; } #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "leaving expandquestion: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif return 1; /* succeeded */ } HWND hSwitchWindow; /* Modified 99/Mar/17 to allow leading ... ellipsis if flag is non-zero */ BOOL CALLBACK _export EnumSwitchProc(HWND hwnd, LPARAM lParam) { char buffer[128]; int flag = lParam; GetWindowText(hwnd, buffer, sizeof(buffer)); if (flag == 0) { /* compare start of title with given string */ if (strncmp (buffer, str, strlen(str)) == 0) { hSwitchWindow = hwnd; return FALSE; /* got it, stop enumerating */ } else return TRUE; /* not yet, continue enumerating */ } else { /* see whether title contains given string */ if (strstr (buffer, str) != NULL) { hSwitchWindow = hwnd; return FALSE; /* got it, stop enumerating */ } else return TRUE; /* not yet, continue enumerating */ } } /* lParam used for flag 0 => FooBar... format, while 1 => ...FooBar format */ /* WARNING: uses string str */ HWND GetSwitchWindow (char *szTitle, int flag) { strcpy (str, szTitle); hSwitchWindow = NULL; (void) EnumWindows((WNDENUMPROC) EnumSwitchProc, flag); return hSwitchWindow; } int switchtowindow (HWND hWnd, char *buf, int shift) { char *s, *t, *u, *v; HWND hWindow; if ((s = strchr(buf, '$')) == NULL) return 0; s++; if (strncmp(s, "Window", 6) == 0) { if ((t = strchr(s, '(')) == NULL) return 0; t++; if ((u = strchr(t, ')')) == NULL) return 0; *u = '\0'; /* terminate Window title */ if ((v = strstr(t, "...")) == NULL) { /* does not have ellipsis */ /* try for *exact* match with Window Title */ hWindow = FindWindow (NULL, t); } else { /* does have ellipsis */ if (v == t) { /* starts with ellipsis */ /* try to find given string in Window Title */ hWindow = GetSwitchWindow (v+3, 1); /* WARNING: uses string str */ } else { /* ends in ellipsis */ *v = '\0'; /* strip off trailing ellipses */ /* try to match start of Window Title against given string */ hWindow = GetSwitchWindow (t, 0); /* WARNING: uses string str */ *v = '.'; /* put it back (for debug output) */ } } if (hWindow != NULL) { if (SetForegroundWindow(hWindow) == 0) { (void) MessageBox(hWnd, "SetForegroundWindow failed", modname, MB_ICONINFORMATION | MB_OK); } /* Note: in WIN32 can't get SetFocus to Window in other thread */ /* if (SetFocus (hWindow) == NULL) { if (bDebug > 1) OutputDebugString("SetFocus failed\n"); shift = 1; } if (shift) { if (SetActiveWindow (hWindow) == NULL) { (void) MessageBox(hWnd, "SetActiveWindow failed", modname, MB_ICONINFORMATION | MB_OK); } } */ *u = ')'; /* put it back (for debug output) */ return 1; } else { sprintf(str, "Can't find Window `%s' to activate", t); (void) MessageBox(hWnd, str, modname, MB_ICONEXCLAMATION | MB_OK); *u = ')'; /* put it back (for debug output) */ return 0; } } return 0; /* ? */ } /* shift unreferenced */ /* Tries key and replaces with number if it matches */ /* dlr points at leading dollar sign - part of what gets replaced */ /* returns -1 if it did not match */ /* returns 1 if it matched and did fit */ /* returns 0 if it won't fit */ int trynamed (char *dlr, char *key, long num, char *buf, int nbuf) { char number[16]; int n = strlen(key); if (strncmp(dlr+1, key, n) != 0) return -1; sprintf(number, "%ld", num); return replacestring(dlr, n+1, number, strlen(number), buf, nbuf); } /* returns non-zero if it was `switchtowindow' --- so there is no WinExec */ int expanddollars (HWND hWnd, char *buf, int nbuf, int shift) { /* char number[16]; */ int flag, n, nc; char *s; s = buf; while ((s = strchr(s, '$')) != NULL) { /* s++; */ if (*(s+1) == '$') { /* $$ gives a real $ (escape mechanism) */ strcpy(s, s+1); /* remove one $ */ s++; /* step over it */ continue; } if (strncmp(s+1, "Window", 6) == 0) { switchtowindow(hWnd, buf, shift); return -1; /* suppress WinExec */ } if (strncmp(s+1, "Comment", 7) == 0) { /* comment passed by TeX */ *s = '\"'; /* put between " ? */ if (replacestring(s+1, 7, dvi_comment, strlen(dvi_comment)+1, buf, nbuf) == 0) return 0; s += strlen(dvi_comment)+1; *s = '\"'; /* put between " ? */ continue; } if (strncmp(s+1, "Font", 4) == 0 && *(s+1+4) != 's') { if (replacestring(s, 4+1, TestFont, strlen(TestFont), buf, nbuf) == 0) return 0; s += strlen(TestFont); continue; } if (strncmp(s+1, "Counter", 7) == 0) { if (sscanf(s+1+7,"[%d]%n", &nc, &n) == 1) { if (nc >= 0 && nc < TEXCOUNTERS) { sprintf(str, "%ld", counter[nc]); if (replacestring(s, 7+1+n, str, strlen(str), buf, nbuf) == 0) return 0; continue; } } } /* Possible place for $File or $Name 96/Oct/4 */ flag = trynamed(s, "Page", (long) dvipage, buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ /* following is redundant - use Counter[0] */ flag = trynamed(s, "Logical", counter[0], buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ flag = trynamed(s, "Last", (long) dvi_t, buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ /* do we really want all of the following ??? */ flag = trynamed(s, "Magnification", (long) dvi_mag, buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ flag = trynamed(s, "Width", (long) dvi_u, buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ flag = trynamed(s, "Height", (long) dvi_l, buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ flag = trynamed(s, "Fonts", (long) dvi_fonts, buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ flag = trynamed(s, "Stack", (long) dvi_s, buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ flag = trynamed(s, "Byte", current, buf, nbuf); /* bop ? */ if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ flag = trynamed(s, "Length", (long) dvi_bytes, buf, nbuf); if (flag == 0) return 0; /* no space left */ if (flag > 0) continue; /* matched and replaced */ /* else try for environment variable 97/June/5 */ /* t = grabenv(s); */ /* no, just use %Variable% instead */ if (bDebug) (void) wincancel(buf); /* show error 96/June/20 */ /* winerror("Don't understand call pattern"); */ /* winerror(buf); */ /* break;*/ /* worry about getting stuck in loop if the $ is not replaced */ if (*s == '\0') break; /* sanity escape */ if (*s == '$') s++; /* allow nonsense $ */ } return 0; /* normal return - no window switch */ } int isdvipsonecallflag; /* Set if WinExe is used to call DVIPSONE 00/Apr/3 */ int istexcallflag; /* Set if WinExe is used to call TeX 98/Jun/28 */ char *IsDVIPSONECall (char *buf) { char *s; if ((s = strstr(buf, "dvipsone.bat")) != NULL || (s = strstr(buf, "dvipsone.exe")) != NULL || (s = strstr(buf, "DVIPSONE.BAT")) != NULL || (s = strstr(buf, "DVIPSONE.EXE")) != NULL) { return s; /* past end is s+12 */ } return NULL; } char *IsTeXCall (char *buf) { char *s; if ((s = strstr(buf, "tex.bat")) != NULL || (s = strstr(buf, "tex.exe")) != NULL || (s = strstr(buf, "TEX.BAT")) != NULL || (s = strstr(buf, "TEX.EXE")) != NULL) { /* includes yandytex.exe */ if (strstr(buf, "bibtex") == NULL && strstr(buf, "BIBTEX") == NULL) { /* but excludes bibtex.exe */ return s; /* past end is s+7 */ } } return NULL; } /* interpret and fill pattern */ /* int parseapplication (HWND hWnd, char *buf, unsigned int nbuf, int shift) */ int parseapplication (HWND hWnd, char *buf, unsigned int nbuf, int shift, char *key) { /* int flag; */ char *s; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "Entering parseapplication: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif if (strchr(buf, '@') != NULL) { if (expandatsign (buf, nbuf) == 0) return 0; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "After expandat: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif } if (strchr(buf, '*') != NULL) { if (expandasterisk (buf, nbuf) == 0) return 0; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "After expandasterisk: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif } if (strchr(buf, '%') != NULL) { if (expandpercent (buf, nbuf) == 0) return 0; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "After expandpercent: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif } if (strchr(buf, '#') != NULL) { if (expandhash(buf, nbuf) == 0) return 0; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "After expandhash: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif } if (strchr(buf, '\"') != NULL) { if (expandquotes(hWnd, buf, nbuf) == 0) return 0; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "After expandquotes: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif } if (strchr(buf, '$') != NULL) { /* 1994/Feb/20 */ /* switchtowindow (hWnd, buf, shift); */ if (expanddollars(hWnd, buf, nbuf, shift) != 0) return 0; /* it was switchtowindow: avoid WinExec */ } if (strchr(buf, '?') != NULL || shift != 0) { /* if (expandquestion (hWnd, buf, nbuf, shift) == 0) return 0; */ if (expandquestion(hWnd, buf, nbuf, shift, key) == 0) return 0; #ifdef DEBUGPATTERN if (bDebug > 1) { sprintf(debugstr, "After expandquestion: %s\n", buf); OutputDebugString(debugstr); // wincancel(debugstr); // debugging only } #endif } if ((s = IsDVIPSONECall(buf)) == NULL) isdvipsonecallflag = 0; else { isdvipsonecallflag = 1; /* pass along requested command line flags for DVIPSONE */ // Direct to Distiller cannot happen when called from menu ? 99/Dec/30 // if (bUsingDistiller && szDVIDistiller != NULL) { // ??? // replacestring (s+12, 0, " ", 1, buf, nbuf); // replacestring (s+13, 0, szDVIDistiller, strlen(szDVIDistiller), buf, nbuf); // if (bDebug > 1) OutputDebugString(buf); // } else if (szDVIPSONE != NULL) { replacestring (s+12, 0, " ", 1, buf, nbuf); replacestring (s+13, 0, szDVIPSONE, strlen(szDVIPSONE), buf, nbuf); if (bDebug > 1) OutputDebugString(buf); } } if ((s = IsTeXCall(buf)) == NULL) istexcallflag = 0; else { istexcallflag = 1; if (strstr(buf, "initex") == NULL && /* 97/June/5 */ strstr(buf, "INITEX") == NULL) { /* don't screw iniTeX call */ /* pass along requested command line flags for YANDYTEX */ if (szYandYTeX != NULL) { replacestring (s+7, 0, " ", 1, buf, nbuf); replacestring (s+8, 0, szYandYTeX, strlen(szYandYTeX), buf, nbuf); if (bDebug > 1) OutputDebugString(buf); } } } /* pass along requested command line flags for LaTeX --- 2000/April/3 ??? */ if ((s = strstr(buf, "latex.bat")) != NULL || (s = strstr(buf, "LATEX.BAT")) != NULL) { if (szYandYTeX != NULL) { replacestring (s+9, 0, " +latex ", 8, buf, nbuf); replacestring (s+17, 0, szYandYTeX, strlen(szYandYTeX), buf, nbuf); // duplication ??? if (bDebug > 1) OutputDebugString(buf); } } return 1; } /* Write new entry in [Applications] section of INI file - make it n-th item */ /* non-trivial if we want to avoid reading/writing the INI file */ // WritePrivateOrder(szMenuKey, szNewValue, id, 0); // WritePrivateOrder("", "", id+1, 1); BOOL WritePrivateOrder (char *szEntry, char *szString, int n, int delete) { int k; char *achTemp = "Temporary"; char *keybuffer=NULL; /* 97/June/5 */ char szNewKey[MAXKEY]; char *s; int napp; int flag=0; /* Replace tab with bar in key if user misused notation */ if ((s = strchr(szEntry, '\t')) != NULL) *s = '|'; /* Make a copy of the whole [Applications] section under new name */ /* Clean out existing [Temporary] section if it exists (should not) */ WritePrivateProfileString (achTemp, NULL, NULL, achFile); napp = 0; if (bCallPreview) napp++; /* step over first two */ /* start by reading in all of the keys in the [Applications] section */ for (;;) { keybuffer = (char *) LocalAlloc(LMEM_FIXED, (UINT) nkeybuffer); if (keybuffer == NULL) { /* unable to allocate memory */ winerror ("Unable to allocate memory"); return 0; } k = GetPrivateProfileString(achAp, NULL, "", /* keybuffer, sizeof(keybuffer), achFile); */ keybuffer, nkeybuffer, achFile); if (k < nkeybuffer-2) break; /* the keys fitted in */ LocalFree ((HLOCAL) keybuffer); nkeybuffer = nkeybuffer * 2; /* try again with larger buffer */ } if (k == 0) { LocalFree ((HLOCAL) keybuffer); return 0; /* failed */ } /* now step through all the keys and read the corresponding values */ s = keybuffer; for (;;) { /* step through and transfer to Temporary */ if (_strnicmp(s, "DummyEntry", 10) == 0) { // 2000 Aug 15 } else { GetPrivateProfileString (achAp, s, "", str, sizeof(str), achFile); WritePrivateProfileString (achTemp, s, str, achFile); napp++; } s = s + strlen(s) + 1; if (*s == '\0') break; } /* Now copy back items in [Temporary] to the [Applications] section */ /* Clean out the [Applications] section to get ready */ WritePrivateProfileString (achAp, NULL, NULL, achFile); napp = 0; if (bCallPreview) napp++; /* step over first two */ /* start by reading in all of the keys in the [Temporary] section */ k = GetPrivateProfileString(achTemp, NULL, "", /* keybuffer, sizeof(keybuffer), achFile); */ keybuffer, nkeybuffer, achFile); /* we are assuming it fits this time ... */ /* if (k == 0) ; */ /* failed */ /* now step through all the keys and read the corresponding values */ s = keybuffer; for (;;) { if (napp == n && delete == 0) { /* insert new item here ? */ WritePrivateProfileString (achAp, szEntry, szString, achFile); napp++; #ifdef DEBUGGING if (bDebug > 1) { sprintf(debugstr, "%s=%s (%d %d)\n", szEntry, szString, n, napp); OutputDebugString(debugstr); } #endif flag++; /* note that we put it in */ } GetPrivateProfileString(achTemp, s, "", str, sizeof(str), achFile); if (strncmp(s, "Separator", 9) == 0) { /* assign new numbers */ sprintf(szNewKey, "Separator%d", napp); } else strcpy(szNewKey, s); /* don't copy it over if we have been asked to delete it */ if (napp == n && delete != 0) { // sprintf(debugstr, "Deleting %s=%s (%d)", szNewKey, str, n); // winerror(debugstr); // debugging only flag++; } else WritePrivateProfileString (achAp, szNewKey, str, achFile); napp++; s = s + strlen(s) + 1; if (*s == '\0') break; } if (flag == 0) { /* if (bDebug > 1) { sprintf(debugstr, "%s=%s (%d %d)\n", szEntry, szString, n, napp); OutputDebugString(debugstr); */ /* following fixed 1995/Nov/17 */ if (napp == n && delete == 0) { /* insert new item here ? */ WritePrivateProfileString (achAp, szEntry, szString, achFile); napp++; #ifdef DEBUGGING if (bDebug > 1) { sprintf(debugstr, "%s=%s (%d %d)\n", szEntry, szString, n, napp); OutputDebugString(debugstr); } #endif flag++; /* note that we put it in */ } } /* clean out [Temporary] section again */ /* omit for debugging */ WritePrivateProfileString (achTemp, NULL, NULL, achFile); // omit for debugging only /* Clear Window's cache of the INI file - if it is currently cached */ /* WritePrivateProfileString (NULL, NULL, NULL, lpszFileName); */ if (keybuffer != NULL) LocalFree ((HLOCAL) keybuffer); return 1; } #ifdef IGNORED /* Clear Window's cache of the INI file - if it is currently cached */ /* WritePrivateProfileString (NULL, NULL, NULL, lpszFileName); */ /* memset (&ofin, 0, sizeof(OFSTRUCT)); ofin.cBytes = sizeof(OFSTRUCT); inifile = OpenFile(lpszFileName, &ofin, OF_READ); if (inifile == NULL) { if (bDebug && bDebugKernel) OutputDebugString ("Can't open INI\n"); WritePrivateProfileString (lpszSection, lpszEntry, lpszString, lpszFileName); return 1; } */ #endif char *appcallpatt = "Application Call Pattern|"; int addmenuitem (HWND hWnd) { /* new version 94/Feb/24 */ int n, flag; char szNewValue[BUFLEN]; /* needs to be this big? */ *szMenuKey = '\0'; /* set up initial Key */ *str = '\0'; /* set up initial Value */ // flag = DialogBox(hInst, "EditItem", hWnd, (DLGPROC) EditItemDlg); flag = DialogBox(hInst, "EditItem", hWnd, EditItemDlg); /* Key returned in szMenuKey, Value in str */ if (flag == 0) return 0; /* user cancelled */ if (flag == IAI_DELETE) return 0; /* `Delete' makes no sense here */ else if (flag == IAI_SEPARATOR) { /* add a separator here */ sprintf(szMenuKey, "Separator%d", nApplications); sprintf(str, "Line"); } /* Treat IAI_REPLACE and IAI_ADD the same way */ if (*szMenuKey == '\0' || *str == '\0') { winerror ("Need Key and Value"); return 0; } if (strcmp(szMenuKey, "Preview") == 0 || strcmp(szMenuKey, "Add Item") == 0) { winerror ("Illegal Key"); return 0; } strcpy (szNewValue, str); /* save value out of harms way */ /* see if it already exists */ /* is it safe to use `buffer' here ? */ n = findmenukey(hWnd, szMenuKey); /* returns zero if not found */ if (n > 0) { winerror ("Key Already Exists"); return 0; } if (flag <= 0) return 0; /* user cancelled */ if (*szNewValue == '\0') return 0; /* insanity check */ /* always append to end of menu */ (void) WritePrivateProfileString(achAp, szMenuKey, szNewValue, achFile); return 1; /* success */ } int editmenuitem (HWND hWnd, char *szKey, char *item, int id) { int n, flag; char szOldKey[MAXKEY]; char szNewValue[BUFLEN]; /* needs to be this big? */ strcpy(szOldKey, szKey); /* remember old Key */ strcpy(szMenuKey, szKey); /* set up initial Key */ strcpy(str, item); /* set up initial Value */ // flag = DialogBox(hInst, "EditItem", hWnd, (DLGPROC) EditItemDlg); flag = DialogBox(hInst, "EditItem", hWnd, EditItemDlg); /* Dialog Procedure: Key returned in szMenuKey, Value in str */ if (flag == 0) return 0; /* user cancelled */ if (flag == IAI_NEXT) { /* delete NEXT */ /* step through and delete Separator that comes next */ WritePrivateOrder ("", "", id, 1); // 2000 Aug 15 // WritePrivateOrder("", "", id+1, 1); return 1; } if (flag == IAI_DELETE) { /* just delete item */ if (strcmp(szOldKey, szMenuKey) != 0) { winerror("Key Has Changed"); return 0; /* don't mess with it then */ } /* *str = '\0'; */ (void) WritePrivateProfileString(achAp, szOldKey, NULL, achFile); return 1; } else if (flag == IAI_SEPARATOR) { /* add a separator here */ sprintf(szMenuKey, "Separator%d", id); /* sprintf(str, "Line"); */ /* then treat same as `Add' */ strcpy(str, "Line"); /* then treat same as `Add' */ } /* IAI_REPLACE and IAI_ADD cases: */ else if (*szMenuKey == '\0' || *str == '\0') { winerror ("Need Key and Value"); return 0; } if (strcmp(szMenuKey, "Preview") == 0 || strcmp(szMenuKey, "Add Item") == 0) { winerror ("Illegal Key"); return 0; } if (*szMenuKey == '\0') return 0; /// sanity check if (flag <= 0) return 0; /* user cancelled */ strcpy(szNewValue, str); /* save value out of harms way */ if (flag == IAI_REPLACE) { /* check simple replacement case */ if (strcmp(szOldKey, szMenuKey) == 0) { (void) WritePrivateProfileString(achAp, szMenuKey, szNewValue, achFile); return 1; /* simple case --- user did not change the key */ } } /* see if it already exists */ /* is it safe to use `buffer' here ? */ n = findmenukey(hWnd, szMenuKey); /* returns zero if not found */ if (n > 0) { /* sets up value of key in str .... */ if (flag != IAI_REPLACE) { /* 1994/Mar/3 */ winerror ("Key Already Exists"); return 0; } } if (flag == IAI_REPLACE) { /* key changed - first get rid of old entry */ (void) WritePrivateProfileString(achAp, szOldKey, NULL, achFile); id--; // ??? /* then treat just the same as `Add' case */ } /* (void) WritePrivateProfileString(achAp, szMenuKey, szNewValue, achFile); */ /* WritePrivateOrder(szMenuKey, str, id); */ WritePrivateOrder(szMenuKey, szNewValue, id, 0); return 1; /* success */ } void trimoffname (char *filename) { /* clip filename off, leaving path */ char *s; if ((s = strrchr(filename, '\\')) != NULL) *s = '\0'; else if ((s = strrchr(filename, '/')) != NULL) *s = '\0'; else if ((s = strrchr(filename, ':')) != NULL) *(s+1) = '\0'; } /* Try and bring up appropriate DVI file on screen */ /* returns non-zero if it wants DVIWindo to open a file */ /* -1 for random DVI file, -2 for help file */ int callpreview (HWND hWnd) { /* click on `Preview' in `TeX menu' */ char namea[MAXDIRLEN], nameb[MAXDIRLEN]; int helpflag=0; /* get ready to show `txhlp0.dvi' */ char *s; int n; char buffer[BUFLEN]; /* temp */ /* why not use global one ? */ #ifndef LONGNAMES OFSTRUCT OfStruct; /* used only to check for texhelp DVI file */ #endif if (bTeXHelpFlag) { /* If TeXHelp was the last thing called */ /* make the directory up from texhelp= entry in dviwindo.ini */ /* n = GetPrivateProfileString(achAp, "TeXHelp", "", str, sizeof(str), achFile); */ n = findmenukey(hWnd, "TeXHelp"); /* find TeXHelp menu item */ if (n == 0) strcpy(str, texhelpdir); /* use default */ /* trim off the `texhelp.exe' part */ trimoffname(str); strcat(str, "\\"); strcat(str, texhelpfile); #ifdef DEBUGTEXHELP if (bDebug > 1) { OutputDebugString(str); // wincancel(str); // debugging only } #endif /* check whether c:\texhelp\txhlp0.dvi exists - if not then punt */ #ifdef LONGNAMES if (LongOpenFile(str, OF_EXIST) != HFILE_ERROR) { #else if (OpenFile(str, &OfStruct, OF_EXIST) != HFILE_ERROR) { #endif helpflag = 1; strcpy(buffer, str); /* avoid corruption ? */ if (bDebug > 1) OutputDebugString("FOUND\n"); /* maybe don't mess up SourceOpenName, SourceDefPath etc */ /* strcpy(SourceOpenName, removepath(str)); */ /* strcpy(SourceDefPath, str); */ /* trimoffname(SourceDefPath); */ /* strcpy(SourceDefExt, ".dvi"); */ } /* success ! */ } /* Maybe DON'T copy c:\texhelp\txhlp0.dvi over SourceOpenName */ if (bFileValid) { /* check whether currently showing a file */ /* check first whether happen to currently be showing the specified file ! */ /* don't do this if showing TeXHelp dvi file */ if (*SourceOpenName != '\0' && helpflag == 0) { strcpy(namea, removepath(OpenName)); if ((s = strrchr(namea, '.')) != NULL) *s = '\0'; strcpy(nameb, removepath(SourceOpenName)); if ((s = strrchr(nameb, '.')) != NULL) *s = '\0'; if (strcmp(namea, nameb) == 0) { if (bDebug > 1) { OutputDebugString(SourceOpenName); OutputDebugString(" already showing\n"); } return 0; /* if so, do nothing */ } } /* otherwise if showing wrong file, close the file and go on */ closeup(hWnd, 1); if (bDebug > 1) OutputDebugString("closeup\n"); /* (void) SendMessage(hWnd, WM_COMMAND, IDM_CLOSE, 0L); if (bDebug > 1) OutputDebugString("SendMessage IDM_CLOSE\n"); */ } /* check whether SourceOpenName is non-empty */ /* don't do this if showing TeXHelp dvi file */ if (*SourceOpenName == '\0' && helpflag == 0) /* if no name specified, just call Open Dialog */ /* use SendMessage ? */ return -1; /* If calling TeXHelp, try and hide the old file name if any */ if (helpflag && *OpenName != '\0') { strcpy(SourceOpenName, OpenName); strcpy(SourceDefPath, DefPath); /* strcpy(SourceDefExt, DefExt); */ /* strcpy(SourceDefSpec, DefSpec); */ bTeXHideFlag = 1; /* indicate it was hidden */ if (bDebug > 1) OutputDebugString("TeXHelp file name hidden\n"); } /* If we are using WorkingDirectory then copy IniDefPath */ /* If we are using SourceDirectory then copy SourceDefPath */ /* If TEXDVI environment variable is set then use that */ /* strcpy(DefPath, IniDefPath); */ /* ??? */ /* if (bUseSourcePath) strcpy(DefPath, IniDefPath); */ /* ??? */ /* else if (bUseWorkPath) _getcwd(DefPath, sizeof(DefPath)); */ /* ??? */ if (bUseWorkPath && IniDefPath != NULL) strcpy(DefPath, IniDefPath); // if (IniDefPath != NULL) strcpy(DefPath, IniDefPath); if (bUseSourcePath) strcpy(DefPath, SourceDefPath); /* 93/Dec/9 */ if (bUseTeXDVI && szTeXDVI != NULL) strcpy(DefPath, szTeXDVI); /* 94/Feb/18 */ /* if a name has been specified, then just make up OpenName */ strcpy(OpenName, DefPath); /* ??? */ s = OpenName + strlen(OpenName) - 1; if (*s != '\\' && *s != '/') strcat(OpenName, "\\"); strcat(OpenName, removepath(SourceOpenName)); /* first flush existing extension if any */ if ((s = strrchr(OpenName, '.')) != NULL) { *s = '\0'; } /* then force default extension 98/June/30 */ strcat(OpenName, DefExt); /* or ".dvi" */ if (helpflag) { if (bDebug > 1) OutputDebugString("Help Flag On "); strcpy(OpenName, removepath(buffer)); strcpy(DefPath, buffer); /* 93/Dec/19 */ trimoffname(DefPath); strcpy(DefExt, ".dvi"); } if (bDebug > 1) OutputDebugString(OpenName); if (! helpflag) { ParseFileName(); /* 1996/Jan/10 ??? */ strcpy(DefSpec, "*"); /* ??? */ strcat(DefSpec, DefExt); /* fix up DefSpec */ return -1; } return -2; // 2000/Jan/02 } #ifdef YANDYTEXDLL HINSTANCE hYandYTeX=NULL; int RunYandYTeXDLL (HWND hWnd, char *str) { int (* lpYandYTeX) (HWND, char *, int(*)(char *, char *, char *))=NULL; /* above must match ConsoleInput definition in texwin.h */ /* int ConsoleInput(char *, char *, char *); */ int ret, fault=0; if (bDebug > 1) OutputDebugString("RunYandYTeXDLL"); if (hYandYTeX == NULL) hYandYTeX = LoadLibrary("YandYTeX"); /* connect to YandYTeX.DLL */ if (hYandYTeX == NULL){ WriteError("Can't link to YandYTeX.DLL"); return -1; } lpYandYTeX = (int (*) (HWND, char *, int(*)(char *, char *, char *))) GetProcAddress(hYandYTeX, "yandytex"); if (lpYandYTeX == NULL) { winerror("Can't find YandYTeX entry point"); fault++; } else { if (hConsoleWnd == NULL) // create console window if needed CreateConsole(hInst, hWnd); // for YandYTeX.DLL if (hConsoleWnd == NULL) { ShowLastError(); // no console window created fault++; } else { (void) EnableWindow(hWnd, FALSE); /* disable main Window ??? */ /* call YandYTeX with command line string */ ret = (* lpYandYTeX) (hConsoleWnd, str, ConsoleInput); (void) EnableWindow(hWnd, TRUE); /* reenable main Window ??? */ } /* can free library now since dviwindo takes care of modeless dialog */ } FreeLibrary(hYandYTeX); hYandYTeX = NULL; return fault; } #endif // EXE_ERROR strings no longer exist... /* ideally want *.PIF around to control windowing and such... */ /* WinExec: `For a non-Windows application, the PIF, if any, */ /* determines the windows state' */ /* returns 0 if it fails, 1 if it succeeds, -1 if it wants IDM_OPEN */ /* -2 if it wants IDM_OPEN, but its just the Help file being opened */ // flag = callapplication(hWnd, id-IDM_APPLICATION, bShiftFlag, bControlFlag); int callapplication (HWND hWnd, int id, int shift, int editflag) { HMENU hMenu, hSubMenu; /* HWND hFocus; */ int m, n; int flag; /* int nCmdShow = SW_SHOW; */ int nCmdShow; /* UINT err; */ HINSTANCE err; /* 95/Mar/31 */ char key[MAXKEY]; char buffer[BUFLEN]; /* temporary buffer */ char *s, *sm; if (id < 0 || id >= nApplications) return 0; /* fail */ if (bCallPreview) { /* "Preview" */ if (id < 1) return callpreview(hWnd); /* returns -1 if it wants FileOpen */ } /* if (GetAsyncKeyState(VK_CONTROL) < 0) editflag = 1; else editflag = 0; */ hMenu = GetMenu(hWnd); m = GetMenuItemCount(hMenu); if (!bHelpAtEnd) hSubMenu = GetSubMenu(hMenu, m - 1); /* last sub menu */ else hSubMenu = GetSubMenu(hMenu, m - 2); /* last sub menu */ /* editnext: */ /* loop for edit next */ if (id < 0 || id >= nApplications) return 0; // sanity check /* get KEY for this application */ n = GetMenuString(hSubMenu, id, key, sizeof(key), MF_BYPOSITION); if (n == 0) { if (bDebug > 1) OutputDebugString("GetMenuString Failed\n"); return 0; /* fail */ } /* if (strncmp(key, "Separator", 9) == 0) return 0; */ /* nonsense ? */ if (*key == '\0') return 0; // sanity check /* a tab in menu is represented by a bar in dviwindo.ini */ if ((sm = strchr(key, '\t')) != NULL) *sm = '|'; /* 93/Dec/25 */ if (bDebug > 1) { OutputDebugString("TeX Menu Call: "); OutputDebugString(key); OutputDebugString("="); } /* Get calling pattern for this application */ n = GetPrivateProfileString(achAp, key, "", buffer, sizeof(buffer), achFile); #ifdef DEBUGPATTERN if (bDebug > 1) { OutputDebugString(buffer); // wincancel(buffer); // debugging only } #endif /* if (n == 0) return 0; */ /* fail */ if (editflag) { /* user wants to edit item */ editmenuitem(hWnd, key, buffer, id); /* 1994/Feb/25 */ return 1; /* finished edit */ } if (n == 0) return 0; /* fail */ if (parseapplication (hWnd, buffer, sizeof(buffer), shift, key) != 0) { /* if (bDebug > 1) OutputDebugString("Parsed Application\n"); */ /* for DOS applications, need PIF file to control such things */ /* here SW_SHOWMINIMIZED means as an icon ! */ /* if (bRunMinimized != 0) nCmdShow = SW_SHOWMINIMIZED; else nCmdShow = SW_SHOW; */ if (nCmdShowForce >= 0) nCmdShow = nCmdShowForce; /* else nCmdShow = SW_SHOWMAXIMIZED; */ /* 1994/Mar/7 */ else nCmdShow = SW_NORMAL; /* 1996/Dec/31 */ /* 0 Hide, 1 ShowNormal/Normal, 2 ShowMinimized, 3 ShowMaximized/Maximize */ /* 4 ShowNoactive, 5 Show, 6 Minimize, 7 ShowMinNoactive, 8 ShowNA, 9 Restore*/ /* set up current directory properly 1993/Dec/9 */ if (bUseWorkPath && IniDefPath != NULL) ChangeDirectory(IniDefPath, 1); // if (IniDefPath != NU