From 91dc1d741013857ec40ce75de49e4d8c40c5f5ad Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Thu, 22 Jun 2017 19:09:55 -0700 Subject: [PATCH] Fix some files with CRLF (DOS) line endings to have LF (Unix). modified: doskbd.c modified: launch.asm modified: lpkit.c modified: lplexyy.c modified: lpytab.c modified: mouseif.c --- src/doskbd.c | 640 +++++----- src/launch.asm | 724 ++++++------ src/lpkit.c | 3026 ++++++++++++++++++++++++------------------------ src/lplexyy.c | 1318 ++++++++++----------- src/lpytab.c | 1298 ++++++++++----------- src/mouseif.c | 250 ++-- 6 files changed, 3628 insertions(+), 3628 deletions(-) mode change 100755 => 100644 src/launch.asm diff --git a/src/doskbd.c b/src/doskbd.c index 9df4f2f..740138e 100644 --- a/src/doskbd.c +++ b/src/doskbd.c @@ -1,320 +1,320 @@ -/* $Id: doskbd.c,v 1.2 1999/01/03 02:06:55 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved - */ -static char *id = "$Id: doskbd.c,v 1.2 1999/01/03 02:06:55 sybalsky Exp $ Copyright (C) Venue"; -/************************************************************************/ -/* */ -/* D O S K E Y B O A R D H A N D L E R */ -/* */ -/* */ -/************************************************************************/ - -/************************************************************************/ -/* */ -/* (C) Copyright 1989, 1990, 1990, 1991, 1992, 1993, 1994, 1995 Venue. */ -/* All Rights Reserved. */ -/* Manufactured in the United States of America. */ -/* */ -/* The contents of this file are proprietary information */ -/* belonging to Venue, and are provided to you under license. */ -/* They may not be further distributed or disclosed to third */ -/* parties without the specific permission of Venue. */ -/* */ -/************************************************************************/ - -#include "version.h" - -#include /* defines REGS & other structs */ -#include /* "#pragma interrupt" & '_chain_intr'*/ -#include -#include - -#include "lispemul.h" -#include "keyboard.h" -#include "keysym.h" -#include "devif.h" - -int nokbdflag = FALSE; -extern int eurokbd; -extern KbdInterface currentkbd; -extern MouseInterface currentmouse; -extern IOPAGE *IOPage68K; -extern IFPAGE *InterfacePage; -extern int KBDEventFlg; - -extern keybuffer *CTopKeyevent; - -extern LispPTR *LASTUSERACTION68k; -extern LispPTR *KEYBUFFERING68k; - -/************************************************/ -/* Keyboard-Interface Registers, Status Codes */ -/************************************************/ -#define KBD_COMMAND_PORT 0x64 /* I/O port commands go out on */ -#define KBD_ENABLE 0xAE -#define KBD_DISABLE 0xAD -#define KBD_RESET 0xF6 - -#define PORT_8042 0x60 /* Port scan codes come in on */ -#define KBD_SCAN_CODE_PORT 0x60 -#define KBD_resend 0xFE /* KBD asked for resend */ -#define KBD_ack 0xFA /* KBD ack's our command */ -#define KBD_echo_response 0xEE /* KBD responds to echo req */ -#define KBD_failure 0xFD /* Failure code */ -#define KBD_prefix 0xE0 /* Prefix for extended chars */ -#define KBD_pause_prefix 0xE1 /* Pause prefix?? */ -#define KBD_overflow 0x00 /* Overflow of some kind */ -#define KBD_overrun 0xFF /* KBD buffer overrun */ - -#define KBD_STATUS_PORT 0x64 /* Port KBD status comes in on */ -#define KBD_INP_FULL 0x02 /* input buffer full */ - -#define INTA00 0x20 /* The 8259 port, to reset irq */ -#define ENDOFINTERRUPT 0x20 - -#define PRTSC_KEY 0x37 /* Keyboard codes for extended chars */ -#define HOME_KEY 0x47 -#define UPARROW_KEY 0x48 -#define PGUP_KEY 0x49 -#define LEFTARROW_KEY 0x4b -#define RIGHTARROW_KEY 0x4d -#define END_KEY 0x4f -#define DOWNARROW_KEY 0x50 -#define PGDOWN_KEY 0x51 -#define INS_KEY 0x52 -#define DEL_KEY 0x53 - -/******************************************************/ -/* Tell the Interrupt-dispatch IC we're done, and */ -/* Tell the keyboard itself that we're ready again. */ -/* */ -/* (This process is critical to the proper function */ -/* of the handler, so let's do it once, correctly.) */ -/******************************************************/ -#define ENABLE_KBD \ - { \ - outp(INTA00, ENDOFINTERRUPT); \ - outp(KBD_COMMAND_PORT, KBD_ENABLE); /* Turn kbd on again. */ \ - } - -/************************************************************************/ -/* */ -/* K B D _ E V E N T */ -/* */ -/* Keyboard interrupt handler routine */ -/************************************************************************/ -extern DLword *DisplayRegion68k; - -#pragma interrupt(Kbd_event) - -void Kbd_event() { - _XSTACK *ebp; /* Real-mode handler stack frame */ - DLword w, r; - KBEVENT *kbevent; - unsigned char keycode, tmpkey; - - ebp = (_XSTACK *)_get_stk_frame(); /* Get stack frame address */ - ebp->opts |= _STK_NOINT; /* Bypass real-mode handler */ - - /*************************************************/ - /* First, get the scan code from the keyboard. */ - /* Handle exceptional conditions & errors, and */ - /* the extended-character prefix, 0xE0 */ - /* generated for, e.g., the INSERT key. */ - /*************************************************/ - - _disable(); /* prevent further interrupts from killing us */ - outp(KBD_COMMAND_PORT, KBD_DISABLE); /* Turn the kbd off. */ - do { tmpkey = inp(KBD_STATUS_PORT); } while (tmpkey & KBD_INP_FULL); - - /* Finite state machine that either returns or goes to label handle: */ - switch (tmpkey = inp(KBD_SCAN_CODE_PORT)) { - case KBD_overflow: /* Ignore these. */ - case KBD_pause_prefix: - case KBD_echo_response: - case KBD_ack: - case KBD_failure: - case KBD_resend: - case KBD_overrun: - ENABLE_KBD; - return; - break; - - case KBD_prefix: /* It's a prefix, so really use next char. */ - /* Remember that we saw the prefix: */ - currentkbd->lastbyte = tmpkey; - ENABLE_KBD; - return; - break; - - default: - tmpkey = inp(KBD_SCAN_CODE_PORT); - if (currentkbd->lastbyte == KBD_prefix) - switch (tmpkey) /* deal with prefixed characters */ - { - case 0x2A: /* by ignoring some (what are they??) */ - case 0xAA: - case 0xB6: - case 0x36: - ENABLE_KBD; - return; - break; - - default: /* and passing the rest thru as-is */ - currentkbd->lastbyte = tmpkey; /* Set the state. */ - goto handle; - break; - } - else { - currentkbd->lastbyte = tmpkey; /* Set the state. */ - goto handle; - } - } - - return; /* Don't have anything to handle yet, so just return */ - -/*****************************************************/ -/* Second, translate the scan code into a LISP key */ -/* transition, add it to the ring buffer, and set */ -/* the interrupt-request flags so lisp sees it. */ -/*****************************************************/ -handle: - /* The upflag is the eight bit in the char ie. upflag = currentkbd->lastbyte >> 7 */ - /* The event is the lower seven bits of the byte */ - - keycode = currentkbd->KeyMap[currentkbd->lastbyte & 0x7f]; - - if (keycode != 0xff) { - if (keycode < 64) { - PUTBASEBIT68K(&(IOPage68K->dlkbdad0), keycode, (currentkbd->lastbyte >> 7) & 1); - } else if (keycode >= 80) { - PUTBASEBIT68K(&(IOPage68K->dlkbdad0), keycode - 16, (currentkbd->lastbyte >> 7) & 1); - } else { - PUTBASEBIT68K(&(IOPage68K->dlutilin), (keycode & 0xf), (currentkbd->lastbyte >> 7) & 1); - PUTBASEBIT68K(&(InterfacePage->fakemousebits), (keycode & 0xf), - (currentkbd->lastbyte >> 7) & 1); - } - } - - /* In DOS we can't enter uraid inside an exception handler. */ - /* Uraid may touch a swapped out address and that dumps Medley */ - if (((IOPage68K->dlkbdad2 & 2113) == 0) || /* Ctrl-shift-NEXT */ - ((IOPage68K->dlkbdad2 & 2114) == 0)) { /* Ctrl-shift-DEL */ - currentkbd->URaid = TRUE; /* Tell the dispatch loop about it. */ - return; - } - - r = CTopKeyevent->ring.vectorindex.read; - w = CTopKeyevent->ring.vectorindex.write; - - if (r != w) { - kbevent = (KBEVENT *)((DLword *)CTopKeyevent + w); - /* Copy the Hardware bits. */ - kbevent->W0 = IOPage68K->dlkbdad0; - kbevent->W1 = IOPage68K->dlkbdad1; - kbevent->W2 = IOPage68K->dlkbdad2; - kbevent->W3 = IOPage68K->dlkbdad3; - kbevent->W4 = IOPage68K->dlkbdad4; - kbevent->W5 = IOPage68K->dlkbdad5; - kbevent->WU = IOPage68K->dlutilin; - - /* If queue was empty, update the read pointer */ - if (r == 0) CTopKeyevent->ring.vectorindex.read = w; - - /* Update the write pointer */ - if (w >= currentkbd->maxkeyevent) - CTopKeyevent->ring.vectorindex.write = MINKEYEVENT; - else - CTopKeyevent->ring.vectorindex.write += currentkbd->keyeventsize; - } - if (*KEYBUFFERING68k == NIL) *KEYBUFFERING68k = ATOM_T; - - KBDEventFlg++; - Irq_Stk_End = 0; - Irq_Stk_Check = 0; - - ENABLE_KBD; - return; -} - -extern u_char DOSLispKeyMap_101[]; - -/************************************************************************/ -/* */ -/* E X I T D O S K B D */ -/* */ -/* Turn off the DOS keyboard handler, and reinstall the */ -/* normal DOS handler. */ -/************************************************************************/ - -void ExitDosKbd(KbdInterface kbd) -{ - if (kbd->device.active == TRUE) { - kbd->device.active = FALSE; - - _dpmi_unlockregion((void *)¤tkbd, sizeof(currentkbd)); - _dpmi_unlockregion((void *)kbd, sizeof(*kbd)); - _dpmi_unlockregion((void *)&InterfacePage, sizeof(InterfacePage)); - _dpmi_unlockregion((void *)InterfacePage, sizeof(IFPAGE)); - _dpmi_unlockregion((void *)&IOPage68K, sizeof(IOPage68K)); - _dpmi_unlockregion((void *)IOPage68K, sizeof(IOPAGE)); - - _dpmi_unlockregion((void *)&CTopKeyevent, sizeof(CTopKeyevent)); - _dpmi_unlockregion((void *)CTopKeyevent, sizeof(*CTopKeyevent)); - - _dpmi_unlockregion((void *)&MachineState, sizeof(MachineState)); - _dpmi_unlockregion((void *)&KEYBUFFERING68k, sizeof(KEYBUFFERING68k)); - _dpmi_unlockregion((void *)&ExitDosKbd, 4096); - _dpmi_unlockregion((void *)&Kbd_event, 4096); - - _dos_setvect(0x09, kbd->prev_handler); /* unhook our handlr, install previous*/ - } -} - -/************************************************************************/ -/* */ -/* E N T E R D O S K B D */ -/* */ -/* Turn on the DOS keyboard device. */ -/* */ -/************************************************************************/ - -void EnterDosKbd(KbdInterface kbd) -{ - int i; - - if (kbd->device.active == FALSE) { - kbd->device.active = TRUE; - for (i = 0; i < 0x80; i++) kbd->KeyMap[i] = DOSLispKeyMap_101[i]; - - if (eurokbd) - kbd->keyeventsize = EUROKEYEVENTSIZE; - else - kbd->keyeventsize = NOEUROKEYEVENTSIZE; - kbd->eurokbd = eurokbd; - - /* Offset of the end of the ring buffer */ - kbd->maxkeyevent = (MINKEYEVENT + (NUMBEROFKEYEVENTS * kbd->keyeventsize)); - - _dpmi_lockregion((void *)¤tkbd, sizeof(currentkbd)); - _dpmi_lockregion((void *)kbd, sizeof(*kbd)); - _dpmi_lockregion((void *)&InterfacePage, sizeof(InterfacePage)); - _dpmi_lockregion((void *)InterfacePage, sizeof(IFPAGE)); - _dpmi_lockregion((void *)&IOPage68K, sizeof(IOPage68K)); - _dpmi_lockregion((void *)IOPage68K, sizeof(IOPAGE)); - _dpmi_lockregion((void *)&MachineState, sizeof(MachineState)); - - _dpmi_lockregion((void *)&CTopKeyevent, sizeof(CTopKeyevent)); - _dpmi_lockregion((void *)CTopKeyevent, sizeof(*CTopKeyevent)); - - _dpmi_lockregion((void *)&KEYBUFFERING68k, sizeof(KEYBUFFERING68k)); - _dpmi_lockregion((void *)&ExitDosKbd, 4096); - _dpmi_lockregion((void *)&Kbd_event, 4096); - - /* Don't hook in our handler if the user flagged he wants to run */ - /* without a kbd. */ - if (!nokbdflag) { - kbd->prev_handler = _dos_getvect(0x09); /* get addr of currnt 09 hndlr */ - _dos_setvect(0x09, kbd->device_event); /* hook our int handler to interrupt */ - } - } -} +/* $Id: doskbd.c,v 1.2 1999/01/03 02:06:55 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved + */ +static char *id = "$Id: doskbd.c,v 1.2 1999/01/03 02:06:55 sybalsky Exp $ Copyright (C) Venue"; +/************************************************************************/ +/* */ +/* D O S K E Y B O A R D H A N D L E R */ +/* */ +/* */ +/************************************************************************/ + +/************************************************************************/ +/* */ +/* (C) Copyright 1989, 1990, 1990, 1991, 1992, 1993, 1994, 1995 Venue. */ +/* All Rights Reserved. */ +/* Manufactured in the United States of America. */ +/* */ +/* The contents of this file are proprietary information */ +/* belonging to Venue, and are provided to you under license. */ +/* They may not be further distributed or disclosed to third */ +/* parties without the specific permission of Venue. */ +/* */ +/************************************************************************/ + +#include "version.h" + +#include /* defines REGS & other structs */ +#include /* "#pragma interrupt" & '_chain_intr'*/ +#include +#include + +#include "lispemul.h" +#include "keyboard.h" +#include "keysym.h" +#include "devif.h" + +int nokbdflag = FALSE; +extern int eurokbd; +extern KbdInterface currentkbd; +extern MouseInterface currentmouse; +extern IOPAGE *IOPage68K; +extern IFPAGE *InterfacePage; +extern int KBDEventFlg; + +extern keybuffer *CTopKeyevent; + +extern LispPTR *LASTUSERACTION68k; +extern LispPTR *KEYBUFFERING68k; + +/************************************************/ +/* Keyboard-Interface Registers, Status Codes */ +/************************************************/ +#define KBD_COMMAND_PORT 0x64 /* I/O port commands go out on */ +#define KBD_ENABLE 0xAE +#define KBD_DISABLE 0xAD +#define KBD_RESET 0xF6 + +#define PORT_8042 0x60 /* Port scan codes come in on */ +#define KBD_SCAN_CODE_PORT 0x60 +#define KBD_resend 0xFE /* KBD asked for resend */ +#define KBD_ack 0xFA /* KBD ack's our command */ +#define KBD_echo_response 0xEE /* KBD responds to echo req */ +#define KBD_failure 0xFD /* Failure code */ +#define KBD_prefix 0xE0 /* Prefix for extended chars */ +#define KBD_pause_prefix 0xE1 /* Pause prefix?? */ +#define KBD_overflow 0x00 /* Overflow of some kind */ +#define KBD_overrun 0xFF /* KBD buffer overrun */ + +#define KBD_STATUS_PORT 0x64 /* Port KBD status comes in on */ +#define KBD_INP_FULL 0x02 /* input buffer full */ + +#define INTA00 0x20 /* The 8259 port, to reset irq */ +#define ENDOFINTERRUPT 0x20 + +#define PRTSC_KEY 0x37 /* Keyboard codes for extended chars */ +#define HOME_KEY 0x47 +#define UPARROW_KEY 0x48 +#define PGUP_KEY 0x49 +#define LEFTARROW_KEY 0x4b +#define RIGHTARROW_KEY 0x4d +#define END_KEY 0x4f +#define DOWNARROW_KEY 0x50 +#define PGDOWN_KEY 0x51 +#define INS_KEY 0x52 +#define DEL_KEY 0x53 + +/******************************************************/ +/* Tell the Interrupt-dispatch IC we're done, and */ +/* Tell the keyboard itself that we're ready again. */ +/* */ +/* (This process is critical to the proper function */ +/* of the handler, so let's do it once, correctly.) */ +/******************************************************/ +#define ENABLE_KBD \ + { \ + outp(INTA00, ENDOFINTERRUPT); \ + outp(KBD_COMMAND_PORT, KBD_ENABLE); /* Turn kbd on again. */ \ + } + +/************************************************************************/ +/* */ +/* K B D _ E V E N T */ +/* */ +/* Keyboard interrupt handler routine */ +/************************************************************************/ +extern DLword *DisplayRegion68k; + +#pragma interrupt(Kbd_event) + +void Kbd_event() { + _XSTACK *ebp; /* Real-mode handler stack frame */ + DLword w, r; + KBEVENT *kbevent; + unsigned char keycode, tmpkey; + + ebp = (_XSTACK *)_get_stk_frame(); /* Get stack frame address */ + ebp->opts |= _STK_NOINT; /* Bypass real-mode handler */ + + /*************************************************/ + /* First, get the scan code from the keyboard. */ + /* Handle exceptional conditions & errors, and */ + /* the extended-character prefix, 0xE0 */ + /* generated for, e.g., the INSERT key. */ + /*************************************************/ + + _disable(); /* prevent further interrupts from killing us */ + outp(KBD_COMMAND_PORT, KBD_DISABLE); /* Turn the kbd off. */ + do { tmpkey = inp(KBD_STATUS_PORT); } while (tmpkey & KBD_INP_FULL); + + /* Finite state machine that either returns or goes to label handle: */ + switch (tmpkey = inp(KBD_SCAN_CODE_PORT)) { + case KBD_overflow: /* Ignore these. */ + case KBD_pause_prefix: + case KBD_echo_response: + case KBD_ack: + case KBD_failure: + case KBD_resend: + case KBD_overrun: + ENABLE_KBD; + return; + break; + + case KBD_prefix: /* It's a prefix, so really use next char. */ + /* Remember that we saw the prefix: */ + currentkbd->lastbyte = tmpkey; + ENABLE_KBD; + return; + break; + + default: + tmpkey = inp(KBD_SCAN_CODE_PORT); + if (currentkbd->lastbyte == KBD_prefix) + switch (tmpkey) /* deal with prefixed characters */ + { + case 0x2A: /* by ignoring some (what are they??) */ + case 0xAA: + case 0xB6: + case 0x36: + ENABLE_KBD; + return; + break; + + default: /* and passing the rest thru as-is */ + currentkbd->lastbyte = tmpkey; /* Set the state. */ + goto handle; + break; + } + else { + currentkbd->lastbyte = tmpkey; /* Set the state. */ + goto handle; + } + } + + return; /* Don't have anything to handle yet, so just return */ + +/*****************************************************/ +/* Second, translate the scan code into a LISP key */ +/* transition, add it to the ring buffer, and set */ +/* the interrupt-request flags so lisp sees it. */ +/*****************************************************/ +handle: + /* The upflag is the eight bit in the char ie. upflag = currentkbd->lastbyte >> 7 */ + /* The event is the lower seven bits of the byte */ + + keycode = currentkbd->KeyMap[currentkbd->lastbyte & 0x7f]; + + if (keycode != 0xff) { + if (keycode < 64) { + PUTBASEBIT68K(&(IOPage68K->dlkbdad0), keycode, (currentkbd->lastbyte >> 7) & 1); + } else if (keycode >= 80) { + PUTBASEBIT68K(&(IOPage68K->dlkbdad0), keycode - 16, (currentkbd->lastbyte >> 7) & 1); + } else { + PUTBASEBIT68K(&(IOPage68K->dlutilin), (keycode & 0xf), (currentkbd->lastbyte >> 7) & 1); + PUTBASEBIT68K(&(InterfacePage->fakemousebits), (keycode & 0xf), + (currentkbd->lastbyte >> 7) & 1); + } + } + + /* In DOS we can't enter uraid inside an exception handler. */ + /* Uraid may touch a swapped out address and that dumps Medley */ + if (((IOPage68K->dlkbdad2 & 2113) == 0) || /* Ctrl-shift-NEXT */ + ((IOPage68K->dlkbdad2 & 2114) == 0)) { /* Ctrl-shift-DEL */ + currentkbd->URaid = TRUE; /* Tell the dispatch loop about it. */ + return; + } + + r = CTopKeyevent->ring.vectorindex.read; + w = CTopKeyevent->ring.vectorindex.write; + + if (r != w) { + kbevent = (KBEVENT *)((DLword *)CTopKeyevent + w); + /* Copy the Hardware bits. */ + kbevent->W0 = IOPage68K->dlkbdad0; + kbevent->W1 = IOPage68K->dlkbdad1; + kbevent->W2 = IOPage68K->dlkbdad2; + kbevent->W3 = IOPage68K->dlkbdad3; + kbevent->W4 = IOPage68K->dlkbdad4; + kbevent->W5 = IOPage68K->dlkbdad5; + kbevent->WU = IOPage68K->dlutilin; + + /* If queue was empty, update the read pointer */ + if (r == 0) CTopKeyevent->ring.vectorindex.read = w; + + /* Update the write pointer */ + if (w >= currentkbd->maxkeyevent) + CTopKeyevent->ring.vectorindex.write = MINKEYEVENT; + else + CTopKeyevent->ring.vectorindex.write += currentkbd->keyeventsize; + } + if (*KEYBUFFERING68k == NIL) *KEYBUFFERING68k = ATOM_T; + + KBDEventFlg++; + Irq_Stk_End = 0; + Irq_Stk_Check = 0; + + ENABLE_KBD; + return; +} + +extern u_char DOSLispKeyMap_101[]; + +/************************************************************************/ +/* */ +/* E X I T D O S K B D */ +/* */ +/* Turn off the DOS keyboard handler, and reinstall the */ +/* normal DOS handler. */ +/************************************************************************/ + +void ExitDosKbd(KbdInterface kbd) +{ + if (kbd->device.active == TRUE) { + kbd->device.active = FALSE; + + _dpmi_unlockregion((void *)¤tkbd, sizeof(currentkbd)); + _dpmi_unlockregion((void *)kbd, sizeof(*kbd)); + _dpmi_unlockregion((void *)&InterfacePage, sizeof(InterfacePage)); + _dpmi_unlockregion((void *)InterfacePage, sizeof(IFPAGE)); + _dpmi_unlockregion((void *)&IOPage68K, sizeof(IOPage68K)); + _dpmi_unlockregion((void *)IOPage68K, sizeof(IOPAGE)); + + _dpmi_unlockregion((void *)&CTopKeyevent, sizeof(CTopKeyevent)); + _dpmi_unlockregion((void *)CTopKeyevent, sizeof(*CTopKeyevent)); + + _dpmi_unlockregion((void *)&MachineState, sizeof(MachineState)); + _dpmi_unlockregion((void *)&KEYBUFFERING68k, sizeof(KEYBUFFERING68k)); + _dpmi_unlockregion((void *)&ExitDosKbd, 4096); + _dpmi_unlockregion((void *)&Kbd_event, 4096); + + _dos_setvect(0x09, kbd->prev_handler); /* unhook our handlr, install previous*/ + } +} + +/************************************************************************/ +/* */ +/* E N T E R D O S K B D */ +/* */ +/* Turn on the DOS keyboard device. */ +/* */ +/************************************************************************/ + +void EnterDosKbd(KbdInterface kbd) +{ + int i; + + if (kbd->device.active == FALSE) { + kbd->device.active = TRUE; + for (i = 0; i < 0x80; i++) kbd->KeyMap[i] = DOSLispKeyMap_101[i]; + + if (eurokbd) + kbd->keyeventsize = EUROKEYEVENTSIZE; + else + kbd->keyeventsize = NOEUROKEYEVENTSIZE; + kbd->eurokbd = eurokbd; + + /* Offset of the end of the ring buffer */ + kbd->maxkeyevent = (MINKEYEVENT + (NUMBEROFKEYEVENTS * kbd->keyeventsize)); + + _dpmi_lockregion((void *)¤tkbd, sizeof(currentkbd)); + _dpmi_lockregion((void *)kbd, sizeof(*kbd)); + _dpmi_lockregion((void *)&InterfacePage, sizeof(InterfacePage)); + _dpmi_lockregion((void *)InterfacePage, sizeof(IFPAGE)); + _dpmi_lockregion((void *)&IOPage68K, sizeof(IOPage68K)); + _dpmi_lockregion((void *)IOPage68K, sizeof(IOPAGE)); + _dpmi_lockregion((void *)&MachineState, sizeof(MachineState)); + + _dpmi_lockregion((void *)&CTopKeyevent, sizeof(CTopKeyevent)); + _dpmi_lockregion((void *)CTopKeyevent, sizeof(*CTopKeyevent)); + + _dpmi_lockregion((void *)&KEYBUFFERING68k, sizeof(KEYBUFFERING68k)); + _dpmi_lockregion((void *)&ExitDosKbd, 4096); + _dpmi_lockregion((void *)&Kbd_event, 4096); + + /* Don't hook in our handler if the user flagged he wants to run */ + /* without a kbd. */ + if (!nokbdflag) { + kbd->prev_handler = _dos_getvect(0x09); /* get addr of currnt 09 hndlr */ + _dos_setvect(0x09, kbd->device_event); /* hook our int handler to interrupt */ + } + } +} diff --git a/src/launch.asm b/src/launch.asm old mode 100755 new mode 100644 index 53d0606..69bc3d4 --- a/src/launch.asm +++ b/src/launch.asm @@ -1,363 +1,363 @@ ;; # @(#) launch.asm Version 1.1 (12/29/94). Copyright Venue # -;************************************************************************ -;* * -;* l a u n c h . a s m * -;* * -;* This is the launcher for Medley on DOS. It: * -;* * -;* * Looks for and validates any -m memsize argument on the * -;* command line. Only values in the range 8 - 32 are allowed. * -;* * -;* * Loads the real Medley emulator, emul.exe, from the same * -;* directory that the launcher came from. * -;* * -;* * Sets the Intel DOS Extender's profile to the requested * -;* memory size + 3Mb (to allow for the emulator, internal * -;* data areas, etc.) * -;* * -;* * Set the termination address in the child process's PSP, * -;* so control returns to the launcher when Medley terminates. * -;* * -;* * Jumps to the emulator's start address. * -;* * -;* * Upon return, just terminates cleanly. * -;* * -;* [We could perhaps do some diagnosis here of error returns?] * -;* * -;* * -;* * -;************************************************************************ - -;************************************************************************/ -;* */ -;* (C) Copyright 1993, 1994 Venue. All Rights Reserved. */ -;* Manufactured in the United States of America. */ -;* */ -;* The contents of this file are proprietary information */ -;* belonging to Venue, and are provided to you under license. */ -;* They may not be further distributed or disclosed to third */ -;* parties without the specific permission of Venue. */ -;* */ -;************************************************************************/ - -.model small -.386p -.stack 100h -.data - align 8 - ;******************************************************** - ;* Parameter block for INT 214B, that loads medley.exe * - ;******************************************************** -envseg DW 0 ; environment (0 = copy mine) -cmdip DW ? ; command-line-tail pointer -cmdcs DW ? -fcb1 DD ? ; dummy first FCB to fill in -fcb2 DD ? ; " 2nd FCB, not here in DOS 4.01??? -stk DD ? ; SS:SP for emul.exe, filled in by loader -csip DD ? ; start addr for emul.exe, filled in by loader - - - -retad DD FAR PTR myret ; cs:ip return address, to put in - ; child PSP, so we get control back. - - - ;* Error messages, misc strings, and work areas* - align 8 -memval dd 0 -errstg DB 'ERROR: Couldn''t free excess storage.',13,10,'$' -noload db 'ERROR: Loading emulator failed: $' -loaded db 'LOAD SUCCESSFUL.',13,10,'$' -nominfo db 'ERROR: -m must be followed by a number 8 - 64.',13,10,'$' -badexe db 'ERROR: emul.exe is corrupted.',13,10,'$' -emulpath DB 'emul.exe',0 ; name of the real emulator. -mflag db '-m' ; to search for -m/-M in cmd line -mmflag db '-M' -profile db 'PRO' ; to find the DOS extender profile -cmdline db 128 dup (?) ; hold the cmd line tail for real emulator - - ;* Error-message table for failures loading emul.exe - align 2 -errtbl dw OFFSET ng0msg ; 0 = unknown failure - dw OFFSET ng1msg ; 1 = "invalid function" - dw OFFSET ng2msg ; 2 = file not found - dw OFFSET ng3msg ; 3 = path not found - dw OFFSET ng4msg ; 4 = too many open files - dw OFFSET ng5msg ; 5 = access denied - dw OFFSET ng0msg ; 6 = not possible error - dw OFFSET ng0msg ; 7 = not possible error - dw OFFSET ng8msg ; 8 = insufficient storage - dw OFFSET ng0msg ; 9 = not possible - dw OFFSET ngamsg ; A = bad environment - dw OFFSET ngbmsg ; B = bad format (corrupt .exe?)a - -ng0msg db 'Unknown problem',13,10,'$' -ng1msg db 'Invalid Function',13,10 - db 'Make sure you are running DOS 4.0 or later.',13,10,'$' -ng2msg db 'File not found.',13,10 - db 'CD to proper directory, or set PATH.',13,10,'$' -ng3msg db 'Path not found.',13,10 - db 'CD to proper directory, or set PATH.',13,10,'$' -ng4msg db 'Too many files open.',13,10 - db 'Shut down some TSRs that have file open?',13,10,'$' -ng5msg db 'Access denied.',13,10 - db 'Make sure of your access rights to emul.exe?',13,10,'$' -ng8msg db 'Not enough memory.',13,10 - db 'Shut down some TSR applications?',13,10,'$' -ngamsg db 'Environment corrupt.',13,10 - db 'Check using SET; You may need to re-boot.',13,10,'$' -ngbmsg db 'EXE file corrupted.',13,10,'$' - db 'You may need to restore from backup or re-install.',13,10,'$' -.code - - - -;************************************************************************ -;* * -;* M A C R O S * -;* * -;* prints Given a string ptr in DX, print it to the display. * -;* * -;* kill Exit cleanly, using INT 21/4C * -;* * -;************************************************************************ - -prints macro text - mov dx, OFFSET text - mov ah,9 - int 21h - endm - -kill macro - mov ah,4ch - int 21h - endm - - - -;************************************************************************ -;* * -;* M A I N E N T R Y * -;* * -;* * -;* * -;* * -;* * -;************************************************************************ - -PUBLIC main -main PROC NEAR - - mov ax,ds ; Save memory-block start for freeing - mov es,ax ; excess memory in a bit. - - mov ax,@data ; DS points to start of data segment - mov ds,ax - - mov cmdcs, ax ; Copy the command line for the emulator - mov cmdip, OFFSET cmdline - - mov di, OFFSET cmdline - mov cx,128 - mov bx,es - mov dx,ds - mov es,dx - mov ds,bx - mov si,80h - - rep - movsb - - mov es,bx ; Free the excess memory that DOS gives - mov ds,dx ; us (we need it for the emulator) - - mov ax,4a00h - mov bx,090h ; We only need 900h bytes for this program - int 21h - jnc freeok - - prints errstg ; Couldn't free spare space; punt. - kill - - ;************************************************ - ;* Search the command line for -m or -M * - ;************************************************ -freeok: - mov di,81h ; start of command line tail - mov si, OFFSET mflag - mov cx, 2 - - mov bx,81h - add bl,es:[80h] - -m1lp: call strcmp - je fndm - - add di, 1 - cmp di, bx - jl m1lp - - mov di,81h ; start of command line tail - mov si, OFFSET mmflag - -m2lp: call strcmp - je fndm - - add di, 1 - cmp di, bx - jl m2lp - - mov memval,02400000h ; memory value not set--use 35MB total. - jmp doload - -fndm: add di,2 ; Found "-m". Now look for a number - cmp di,bx ; (Make sure it's not end of line) - jnl nogoodm - -ok1: - mov edx, 0 ; Holds the memory-requirement value - mov ax,0 ; holds characters as we read - - ;************************************************ - ;* Skip over spaces/tabs before any number * - ;************************************************ -skiplp: - mov al, es:[di] - inc di - cmp al, 20h ; spaces - je skiplp - cmp al, 09h ; tabs - je skiplp - cmp di,bx ; make sure we're still in the string - jle cnvst ; Yup, we've got the first char, so enter - ; the conversion loop part-way down. - -nogoodm: - prints nominfo ; no arg to -m, or it's bad; Punt. - kill - - ;******************************************************** - ; Convert the numeric argument to -m; result in edx. * - ;******************************************************** -cnvlp: mov al,es:[di] - add di, 1 -cnvst: cmp al, 30h - jl endcnv - cmp al, 39h - jg endcnv - sub al, 30h - imul dx, 10 - add dx, ax - jmp cnvlp - -endcnv: - cmp edx,0 ; if still 0, no valid chars! - je nogoodm - cmp edx, 8 ; must be in the range [8, 32] - jl nogoodm - cmp edx,64 - jg nogoodm - - add edx, 3 ; add 3mb for data areas, etc, and - sal edx, 20 ; convert to megabytes - mov memval, edx ; save memory requested - - ;************************************************ - ;* Load the real emulator .EXE file, emul.exe * - ;************************************************ -doload: mov dx, OFFSET emulpath - mov ax, seg envseg - mov es, ax - mov bx, OFFSET envseg - mov ax,4b01h ; load-don't-start - int 21h - jnc loadok - - add ax,ax - mov si,ax - prints noload - mov bx,OFFSET errtbl - mov dx,ds:[bx+si] - mov ah,9 - int 21h - kill - -loadok: ; Load succeeded. - mov ah,51h ; get PSP address for child - int 21h - mov es, bx ; get segment for DI addressing - -; mov cx,128 ; copy the command line tail -; mov di,80h ; (which appears to be flaky in DOS 4) -; mov si, offset cmdline -; rep -; movsb - - mov eax,retad - mov dword ptr es:[+0ah], eax ; set up return address. - - cmp memval, 0 ; If no -m value given, just - je dorun ; go start the emulator. - - mov di,0 ; Search for the Intel Extender's PROFILE - mov si, OFFSET profile ; (see extender.h) - mov cx, 3 ; (length is 3 bytes) - -srchlp: call strcmp - je gotprof ; found the profile; fix it. - add di, 1 - cmp di, 2048 - jle srchlp - - prints badexe ; No extender profile, so the emulator - kill ; EXE must be corrupt. Punt. - -gotprof: - mov eax,memval ; Fill in the memory requirement. - mov es:[di+1bch], eax - -;******************************************************** -;* * -;* Set up the stack seg/pointer & start medley. * -;* * -;******************************************************** -dorun: lss sp,stk ; load stack SS & SP regs - mov ax, es ; copy PSP ptr to ax & ds, since some - mov bx, ds ; code expects it in both places. - mov fs,bx ; Also, copy DS to FS, so we still have - mov ds,ax ; a base for the indirect jump . . . - jmp fs:[csip] ; to start-of-medley. - -myret: kill ; we get back here, so quit gracefully. - -main endp - - - -;************************************************************************/ -;* */ -;* s t r c m p */ -;* */ -;* Compare [ds]di and es:[si] for (CX) characters. If the */ -;* strings are equal, the Zero flag is set when this returns. */ -;* */ -;* All registers are preserved. */ -;* */ -;************************************************************************/ - -strcmp proc near - cld - push di - push si - push cx - - repe - cmpsb - - pop cx - pop si - pop di - ret -strcmp endp - -END +;************************************************************************ +;* * +;* l a u n c h . a s m * +;* * +;* This is the launcher for Medley on DOS. It: * +;* * +;* * Looks for and validates any -m memsize argument on the * +;* command line. Only values in the range 8 - 32 are allowed. * +;* * +;* * Loads the real Medley emulator, emul.exe, from the same * +;* directory that the launcher came from. * +;* * +;* * Sets the Intel DOS Extender's profile to the requested * +;* memory size + 3Mb (to allow for the emulator, internal * +;* data areas, etc.) * +;* * +;* * Set the termination address in the child process's PSP, * +;* so control returns to the launcher when Medley terminates. * +;* * +;* * Jumps to the emulator's start address. * +;* * +;* * Upon return, just terminates cleanly. * +;* * +;* [We could perhaps do some diagnosis here of error returns?] * +;* * +;* * +;* * +;************************************************************************ + +;************************************************************************/ +;* */ +;* (C) Copyright 1993, 1994 Venue. All Rights Reserved. */ +;* Manufactured in the United States of America. */ +;* */ +;* The contents of this file are proprietary information */ +;* belonging to Venue, and are provided to you under license. */ +;* They may not be further distributed or disclosed to third */ +;* parties without the specific permission of Venue. */ +;* */ +;************************************************************************/ + +.model small +.386p +.stack 100h +.data + align 8 + ;******************************************************** + ;* Parameter block for INT 214B, that loads medley.exe * + ;******************************************************** +envseg DW 0 ; environment (0 = copy mine) +cmdip DW ? ; command-line-tail pointer +cmdcs DW ? +fcb1 DD ? ; dummy first FCB to fill in +fcb2 DD ? ; " 2nd FCB, not here in DOS 4.01??? +stk DD ? ; SS:SP for emul.exe, filled in by loader +csip DD ? ; start addr for emul.exe, filled in by loader + + + +retad DD FAR PTR myret ; cs:ip return address, to put in + ; child PSP, so we get control back. + + + ;* Error messages, misc strings, and work areas* + align 8 +memval dd 0 +errstg DB 'ERROR: Couldn''t free excess storage.',13,10,'$' +noload db 'ERROR: Loading emulator failed: $' +loaded db 'LOAD SUCCESSFUL.',13,10,'$' +nominfo db 'ERROR: -m must be followed by a number 8 - 64.',13,10,'$' +badexe db 'ERROR: emul.exe is corrupted.',13,10,'$' +emulpath DB 'emul.exe',0 ; name of the real emulator. +mflag db '-m' ; to search for -m/-M in cmd line +mmflag db '-M' +profile db 'PRO' ; to find the DOS extender profile +cmdline db 128 dup (?) ; hold the cmd line tail for real emulator + + ;* Error-message table for failures loading emul.exe + align 2 +errtbl dw OFFSET ng0msg ; 0 = unknown failure + dw OFFSET ng1msg ; 1 = "invalid function" + dw OFFSET ng2msg ; 2 = file not found + dw OFFSET ng3msg ; 3 = path not found + dw OFFSET ng4msg ; 4 = too many open files + dw OFFSET ng5msg ; 5 = access denied + dw OFFSET ng0msg ; 6 = not possible error + dw OFFSET ng0msg ; 7 = not possible error + dw OFFSET ng8msg ; 8 = insufficient storage + dw OFFSET ng0msg ; 9 = not possible + dw OFFSET ngamsg ; A = bad environment + dw OFFSET ngbmsg ; B = bad format (corrupt .exe?)a + +ng0msg db 'Unknown problem',13,10,'$' +ng1msg db 'Invalid Function',13,10 + db 'Make sure you are running DOS 4.0 or later.',13,10,'$' +ng2msg db 'File not found.',13,10 + db 'CD to proper directory, or set PATH.',13,10,'$' +ng3msg db 'Path not found.',13,10 + db 'CD to proper directory, or set PATH.',13,10,'$' +ng4msg db 'Too many files open.',13,10 + db 'Shut down some TSRs that have file open?',13,10,'$' +ng5msg db 'Access denied.',13,10 + db 'Make sure of your access rights to emul.exe?',13,10,'$' +ng8msg db 'Not enough memory.',13,10 + db 'Shut down some TSR applications?',13,10,'$' +ngamsg db 'Environment corrupt.',13,10 + db 'Check using SET; You may need to re-boot.',13,10,'$' +ngbmsg db 'EXE file corrupted.',13,10,'$' + db 'You may need to restore from backup or re-install.',13,10,'$' +.code + + + +;************************************************************************ +;* * +;* M A C R O S * +;* * +;* prints Given a string ptr in DX, print it to the display. * +;* * +;* kill Exit cleanly, using INT 21/4C * +;* * +;************************************************************************ + +prints macro text + mov dx, OFFSET text + mov ah,9 + int 21h + endm + +kill macro + mov ah,4ch + int 21h + endm + + + +;************************************************************************ +;* * +;* M A I N E N T R Y * +;* * +;* * +;* * +;* * +;* * +;************************************************************************ + +PUBLIC main +main PROC NEAR + + mov ax,ds ; Save memory-block start for freeing + mov es,ax ; excess memory in a bit. + + mov ax,@data ; DS points to start of data segment + mov ds,ax + + mov cmdcs, ax ; Copy the command line for the emulator + mov cmdip, OFFSET cmdline + + mov di, OFFSET cmdline + mov cx,128 + mov bx,es + mov dx,ds + mov es,dx + mov ds,bx + mov si,80h + + rep + movsb + + mov es,bx ; Free the excess memory that DOS gives + mov ds,dx ; us (we need it for the emulator) + + mov ax,4a00h + mov bx,090h ; We only need 900h bytes for this program + int 21h + jnc freeok + + prints errstg ; Couldn't free spare space; punt. + kill + + ;************************************************ + ;* Search the command line for -m or -M * + ;************************************************ +freeok: + mov di,81h ; start of command line tail + mov si, OFFSET mflag + mov cx, 2 + + mov bx,81h + add bl,es:[80h] + +m1lp: call strcmp + je fndm + + add di, 1 + cmp di, bx + jl m1lp + + mov di,81h ; start of command line tail + mov si, OFFSET mmflag + +m2lp: call strcmp + je fndm + + add di, 1 + cmp di, bx + jl m2lp + + mov memval,02400000h ; memory value not set--use 35MB total. + jmp doload + +fndm: add di,2 ; Found "-m". Now look for a number + cmp di,bx ; (Make sure it's not end of line) + jnl nogoodm + +ok1: + mov edx, 0 ; Holds the memory-requirement value + mov ax,0 ; holds characters as we read + + ;************************************************ + ;* Skip over spaces/tabs before any number * + ;************************************************ +skiplp: + mov al, es:[di] + inc di + cmp al, 20h ; spaces + je skiplp + cmp al, 09h ; tabs + je skiplp + cmp di,bx ; make sure we're still in the string + jle cnvst ; Yup, we've got the first char, so enter + ; the conversion loop part-way down. + +nogoodm: + prints nominfo ; no arg to -m, or it's bad; Punt. + kill + + ;******************************************************** + ; Convert the numeric argument to -m; result in edx. * + ;******************************************************** +cnvlp: mov al,es:[di] + add di, 1 +cnvst: cmp al, 30h + jl endcnv + cmp al, 39h + jg endcnv + sub al, 30h + imul dx, 10 + add dx, ax + jmp cnvlp + +endcnv: + cmp edx,0 ; if still 0, no valid chars! + je nogoodm + cmp edx, 8 ; must be in the range [8, 32] + jl nogoodm + cmp edx,64 + jg nogoodm + + add edx, 3 ; add 3mb for data areas, etc, and + sal edx, 20 ; convert to megabytes + mov memval, edx ; save memory requested + + ;************************************************ + ;* Load the real emulator .EXE file, emul.exe * + ;************************************************ +doload: mov dx, OFFSET emulpath + mov ax, seg envseg + mov es, ax + mov bx, OFFSET envseg + mov ax,4b01h ; load-don't-start + int 21h + jnc loadok + + add ax,ax + mov si,ax + prints noload + mov bx,OFFSET errtbl + mov dx,ds:[bx+si] + mov ah,9 + int 21h + kill + +loadok: ; Load succeeded. + mov ah,51h ; get PSP address for child + int 21h + mov es, bx ; get segment for DI addressing + +; mov cx,128 ; copy the command line tail +; mov di,80h ; (which appears to be flaky in DOS 4) +; mov si, offset cmdline +; rep +; movsb + + mov eax,retad + mov dword ptr es:[+0ah], eax ; set up return address. + + cmp memval, 0 ; If no -m value given, just + je dorun ; go start the emulator. + + mov di,0 ; Search for the Intel Extender's PROFILE + mov si, OFFSET profile ; (see extender.h) + mov cx, 3 ; (length is 3 bytes) + +srchlp: call strcmp + je gotprof ; found the profile; fix it. + add di, 1 + cmp di, 2048 + jle srchlp + + prints badexe ; No extender profile, so the emulator + kill ; EXE must be corrupt. Punt. + +gotprof: + mov eax,memval ; Fill in the memory requirement. + mov es:[di+1bch], eax + +;******************************************************** +;* * +;* Set up the stack seg/pointer & start medley. * +;* * +;******************************************************** +dorun: lss sp,stk ; load stack SS & SP regs + mov ax, es ; copy PSP ptr to ax & ds, since some + mov bx, ds ; code expects it in both places. + mov fs,bx ; Also, copy DS to FS, so we still have + mov ds,ax ; a base for the indirect jump . . . + jmp fs:[csip] ; to start-of-medley. + +myret: kill ; we get back here, so quit gracefully. + +main endp + + + +;************************************************************************/ +;* */ +;* s t r c m p */ +;* */ +;* Compare [ds]di and es:[si] for (CX) characters. If the */ +;* strings are equal, the Zero flag is set when this returns. */ +;* */ +;* All registers are preserved. */ +;* */ +;************************************************************************/ + +strcmp proc near + cld + push di + push si + push cx + + repe + cmpsb + + pop cx + pop si + pop di + ret +strcmp endp + +END diff --git a/src/lpkit.c b/src/lpkit.c index 181d524..b1d5102 100644 --- a/src/lpkit.c +++ b/src/lpkit.c @@ -1,1513 +1,1513 @@ -/* $Id: lpkit.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */ -static char *id = "$Id: lpkit.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $ Copyright (C) Venue"; - -/************************************************************************/ -/* */ -/* (C) Copyright 1989-99 Venue. All Rights Reserved. */ -/* Manufactured in the United States of America. */ -/* */ -/* The contents of this file are proprietary information */ -/* belonging to Venue, and are provided to you under license. */ -/* They may not be further distributed or disclosed to third */ -/* parties without the specific permission of Venue. */ -/* */ -/************************************************************************/ - -#include "version.h" - -#include "lpkit.h" -#include "lpglob.h" -#include -#include -#include - -/* Globals */ -lprec *Lp = NULL; /* pointer to active problem */ -int Rows; -int Columns; -int Sum; -int Non_zeros; -int Level; -matrec *Mat; -int *Col_no; -int *Col_end; -int *Row_end; -REAL *Orig_rh; -REAL *Rh; -REAL *Rhs; -short *Must_be_int; -REAL *Orig_upbo; -REAL *Orig_lowbo; -REAL *Upbo; -REAL *Lowbo; -int *Bas; -short *Basis; -short *Lower; -int Eta_alloc; -int Eta_size; -REAL *Eta_value; -int *Eta_row_nr; -int *Eta_col_end; -int Num_inv; -REAL *Solution; -REAL *Best_solution; -REAL Infinite; -REAL Epsilon; -REAL Epsb; -REAL Epsd; -REAL Epsel; - -REAL TREJ; -REAL TINV; - -short Maximise; -short Floor_first; -REAL Extrad; - -int Warn_count; /* used in CHECK version of rounding macro */ -#ifdef NEVER -void error(char *format, ...) { - va_list ap; - va_start(ap, format); - vfprintf(stderr, format, ap); - fputc('\n', stderr); - va_end(ap); - exit(FAIL); -} -#endif - -lprec *make_lp(int rows, int columns) { - lprec *newlp; - int i, sum; - sstate *st; /* to save state in MILP runs */ - - sum = rows + columns; - if (rows < 0 || columns < 0) error("rows < 0 or columns < 0"); - CALLOC(newlp, 1, lprec); - - strcpy(newlp->lp_name, "unnamed"); - newlp->active = FALSE; - newlp->verbose = FALSE; - newlp->print_duals = FALSE; - newlp->print_sol = FALSE; - newlp->debug = FALSE; - newlp->print_at_invert = FALSE; - newlp->trace = FALSE; - - newlp->rows = rows; - newlp->columns = columns; - newlp->sum = sum; - newlp->rows_alloc = rows; - newlp->columns_alloc = columns; - newlp->sum_alloc = sum; - newlp->names_used = FALSE; - - newlp->obj_bound = DEF_INFINITE; - newlp->infinite = DEF_INFINITE; - newlp->epsilon = DEF_EPSILON; - newlp->epsb = DEF_EPSB; - newlp->epsd = DEF_EPSD; - newlp->epsel = DEF_EPSEL; - newlp->non_zeros = 0; - newlp->mat_alloc = 1; - CALLOC(newlp->mat, newlp->mat_alloc, matrec); - CALLOC(newlp->col_no, newlp->mat_alloc, int); - CALLOC(newlp->col_end, columns + 1, int); - CALLOC(newlp->row_end, rows + 1, int); - newlp->row_end_valid = FALSE; - CALLOC(newlp->orig_rh, rows + 1, REAL); - CALLOC(newlp->rh, rows + 1, REAL); - CALLOC(newlp->rhs, rows + 1, REAL); - CALLOC(newlp->must_be_int, sum + 1, short); - for (i = 0; i <= sum; i++) newlp->must_be_int[i] = FALSE; - CALLOC(newlp->orig_upbo, sum + 1, REAL); - for (i = 0; i <= sum; i++) newlp->orig_upbo[i] = newlp->infinite; - CALLOC(newlp->upbo, sum + 1, REAL); - CALLOC(newlp->orig_lowbo, sum + 1, REAL); - CALLOC(newlp->lowbo, sum + 1, REAL); - - newlp->basis_valid = TRUE; - CALLOC(newlp->bas, rows + 1, int); - CALLOC(newlp->basis, sum + 1, short); - CALLOC(newlp->lower, sum + 1, short); - for (i = 0; i <= rows; i++) { - newlp->bas[i] = i; - newlp->basis[i] = TRUE; - } - for (i = rows + 1; i <= sum; i++) newlp->basis[i] = FALSE; - for (i = 0; i <= sum; i++) newlp->lower[i] = TRUE; - - newlp->eta_valid = TRUE; - newlp->eta_size = 0; - newlp->eta_alloc = 10000; - newlp->max_num_inv = DEFNUMINV; - - newlp->nr_lagrange = 0; - - CALLOC(newlp->eta_value, newlp->eta_alloc, REAL); - CALLOC(newlp->eta_row_nr, newlp->eta_alloc, int); - CALLOC(newlp->eta_col_end, newlp->rows_alloc + newlp->max_num_inv, int); - - newlp->bb_rule = FIRST_NI; - newlp->break_at_int = FALSE; - newlp->break_value = 0; - - newlp->iter = 0; - newlp->total_iter = 0; - CALLOC(newlp->solution, sum + 1, REAL); - CALLOC(newlp->best_solution, sum + 1, REAL); - CALLOC(newlp->duals, rows + 1, REAL); - - newlp->maximise = FALSE; - newlp->floor_first = TRUE; - - newlp->scaling_used = FALSE; - newlp->columns_scaled = FALSE; - - CALLOC(newlp->ch_sign, rows + 1, short); - - for (i = 0; i <= rows; i++) newlp->ch_sign[i] = FALSE; - - st = newlp->solve_states = NULL; - for (i = 0; i < Sum + 2; i++) { - if (st) /* There's an old state-saver to use; re-use it. */ - { - st->saved = 0; /* clear the in-use field */ - st->notint = 0; /* And the not-integer field */ - st = st->next; - } else { - st = (sstate *)malloc(sizeof(sstate)); - if (!st) ERROR(ERR_NOMEM); /* Tell the guy there's no memory */ - st->next = newlp->solve_states; - st->saved = 0; - st->notint = 0; /* And the not-integer field */ - newlp->solve_states = st; - st = (sstate *)NULL; - } - } - - newlp->valid = FALSE; - - return (newlp); -} - -void delete_lp(lprec *lp) { - int i; - - if (lp->active) Lp = NULL; - if (lp->names_used) { - free(lp->row_name); - free(lp->col_name); - } - free(lp->mat); - free(lp->col_no); - free(lp->col_end); - free(lp->row_end); - free(lp->orig_rh); - free(lp->rh); - free(lp->rhs); - free(lp->must_be_int); - free(lp->orig_upbo); - free(lp->orig_lowbo); - free(lp->upbo); - free(lp->lowbo); - free(lp->bas); - free(lp->basis); - free(lp->lower); - free(lp->eta_value); - free(lp->eta_row_nr); - free(lp->eta_col_end); - free(lp->solution); - free(lp->best_solution); - free(lp->duals); - free(lp->ch_sign); - if (lp->scaling_used) free(lp->scale); - if (lp->nr_lagrange > 0) { - free(lp->lag_rhs); - free(lp->lambda); - free(lp->lag_con_type); - for (i = 0; i < lp->nr_lagrange; i++) free(lp->lag_row[i]); - free(lp->lag_row); - } - - free(lp); - lp = NULL; -} - -lprec *copy_lp(lprec *lp) { - lprec *newlp; - int i, rowsplus, colsplus, sumplus; - - rowsplus = lp->rows_alloc + 1; - colsplus = lp->columns_alloc + 1; - sumplus = lp->sum_alloc + 1; - - MALLOCCPY(newlp, lp, 1, lprec); /* copy all non pointers */ - - newlp->active = FALSE; - - if (newlp->names_used) { - MALLOCCPY(newlp->col_name, lp->col_name, colsplus, nstring); - MALLOCCPY(newlp->row_name, lp->row_name, rowsplus, nstring); - } - - MALLOCCPY(newlp->mat, lp->mat, newlp->mat_alloc, matrec); - MALLOCCPY(newlp->col_end, lp->col_end, colsplus, int); - MALLOCCPY(newlp->col_no, lp->col_no, newlp->mat_alloc, int); - MALLOCCPY(newlp->row_end, lp->row_end, rowsplus, int); - MALLOCCPY(newlp->orig_rh, lp->orig_rh, rowsplus, REAL); - MALLOCCPY(newlp->rh, lp->rh, rowsplus, REAL); - MALLOCCPY(newlp->rhs, lp->rhs, rowsplus, REAL); - MALLOCCPY(newlp->must_be_int, lp->must_be_int, sumplus, short); - MALLOCCPY(newlp->orig_upbo, lp->orig_upbo, sumplus, REAL); - MALLOCCPY(newlp->orig_lowbo, lp->orig_lowbo, sumplus, REAL); - MALLOCCPY(newlp->upbo, lp->upbo, sumplus, REAL); - MALLOCCPY(newlp->lowbo, lp->lowbo, sumplus, REAL); - MALLOCCPY(newlp->bas, lp->bas, rowsplus, int); - MALLOCCPY(newlp->basis, lp->basis, sumplus, short); - MALLOCCPY(newlp->lower, lp->lower, sumplus, short); - MALLOCCPY(newlp->eta_value, lp->eta_value, lp->eta_alloc, REAL); - MALLOCCPY(newlp->eta_row_nr, lp->eta_row_nr, lp->eta_alloc, int); - MALLOCCPY(newlp->eta_col_end, lp->eta_col_end, lp->rows_alloc + lp->max_num_inv, int); - MALLOCCPY(newlp->solution, lp->solution, sumplus, REAL); - MALLOCCPY(newlp->best_solution, lp->best_solution, sumplus, REAL); - MALLOCCPY(newlp->duals, lp->duals, rowsplus, REAL); - MALLOCCPY(newlp->ch_sign, lp->ch_sign, rowsplus, short); - - if (newlp->scaling_used) MALLOCCPY(newlp->scale, lp->scale, sumplus, REAL); - - if (newlp->nr_lagrange > 0) { - MALLOCCPY(newlp->lag_rhs, lp->lag_rhs, newlp->nr_lagrange, REAL); - MALLOCCPY(newlp->lambda, lp->lambda, newlp->nr_lagrange, REAL); - MALLOCCPY(newlp->lag_con_type, lp->lag_con_type, newlp->nr_lagrange, short); - MALLOC(newlp->lag_row, newlp->nr_lagrange, REAL *); - for (i = 0; i < newlp->nr_lagrange; i++) - MALLOCCPY(newlp->lag_row[i], lp->lag_row[i], colsplus, REAL); - } - return (newlp); -} - -void inc_mat_space(lprec *lp, int maxextra) { - if (lp->non_zeros + maxextra >= lp->mat_alloc) { - lp->mat_alloc = lp->non_zeros + maxextra; - REALLOC(lp->mat, lp->mat_alloc, matrec); - REALLOC(lp->col_no, lp->mat_alloc, int); - if (lp->active) { - Mat = lp->mat; - Col_no = lp->col_no; - } - } -} - -void inc_row_space(lprec *lp) { - if (lp->rows > lp->rows_alloc) { - lp->rows_alloc = lp->rows + 10; - lp->sum_alloc = lp->rows_alloc + lp->columns_alloc; - REALLOC(lp->orig_rh, lp->rows_alloc + 1, REAL); - REALLOC(lp->rh, lp->rows_alloc + 1, REAL); - REALLOC(lp->rhs, lp->rows_alloc + 1, REAL); - REALLOC(lp->orig_upbo, lp->sum_alloc + 1, REAL); - REALLOC(lp->upbo, lp->sum_alloc + 1, REAL); - REALLOC(lp->orig_lowbo, lp->sum_alloc + 1, REAL); - REALLOC(lp->lowbo, lp->sum_alloc + 1, REAL); - REALLOC(lp->solution, lp->sum_alloc + 1, REAL); - REALLOC(lp->best_solution, lp->sum_alloc + 1, REAL); - REALLOC(lp->row_end, lp->rows_alloc + 1, int); - REALLOC(lp->basis, lp->sum_alloc + 1, short); - REALLOC(lp->lower, lp->sum_alloc + 1, short); - REALLOC(lp->must_be_int, lp->sum_alloc + 1, short); - REALLOC(lp->bas, lp->rows_alloc + 1, int); - REALLOC(lp->duals, lp->rows_alloc + 1, REAL); - REALLOC(lp->ch_sign, lp->rows_alloc + 1, short); - REALLOC(lp->eta_col_end, lp->rows_alloc + lp->max_num_inv, int); - if (lp->names_used) REALLOC(lp->row_name, lp->rows_alloc + 1, nstring); - if (lp->scaling_used) REALLOC(lp->scale, lp->sum_alloc + 1, REAL); - if (lp->active) set_globals(lp); - } -} - -void inc_col_space(lprec *lp) { - if (lp->columns >= lp->columns_alloc) { - lp->columns_alloc = lp->columns + 10; - lp->sum_alloc = lp->rows_alloc + lp->columns_alloc; - REALLOC(lp->must_be_int, lp->sum_alloc + 1, short); - REALLOC(lp->orig_upbo, lp->sum_alloc + 1, REAL); - REALLOC(lp->upbo, lp->sum_alloc + 1, REAL); - REALLOC(lp->orig_lowbo, lp->sum_alloc + 1, REAL); - REALLOC(lp->lowbo, lp->sum_alloc + 1, REAL); - REALLOC(lp->solution, lp->sum_alloc + 1, REAL); - REALLOC(lp->best_solution, lp->sum_alloc + 1, REAL); - REALLOC(lp->basis, lp->sum_alloc + 1, short); - REALLOC(lp->lower, lp->sum_alloc + 1, short); - if (lp->names_used) REALLOC(lp->col_name, lp->columns_alloc + 1, nstring); - if (lp->scaling_used) REALLOC(lp->scale, lp->sum_alloc + 1, REAL); - REALLOC(lp->col_end, lp->columns_alloc + 1, int); - if (lp->active) set_globals(lp); - } -} - -void set_mat(lprec *lp, int Row, int Column, REAL Value) { - int elmnr, lastelm, i; - - if (Row > lp->rows || Row < 0) error("Row out of range"); - if (Column > lp->columns || Column < 1) error("Column out of range"); - if (lp->scaling_used) Value *= lp->scale[Row] * lp->scale[lp->rows + Column]; - - if (TRUE /*abs(Value) > lp->epsilon*/) { - if (lp->basis[Column] == TRUE && Row > 0) lp->basis_valid = FALSE; - lp->eta_valid = FALSE; - elmnr = lp->col_end[Column - 1]; - while ((elmnr < lp->col_end[Column]) ? (lp->mat[elmnr].row_nr != Row) : FALSE) elmnr++; - - if ((elmnr != lp->col_end[Column]) ? (lp->mat[elmnr].row_nr == Row) : FALSE) - if (lp->scaling_used) { - if (lp->ch_sign[Row]) - lp->mat[elmnr].value = -Value * lp->scale[Row] * lp->scale[Column]; - else - lp->mat[elmnr].value = Value * lp->scale[Row] * lp->scale[Column]; - } else { - if (lp->ch_sign[Row]) - lp->mat[elmnr].value = -Value; - else - lp->mat[elmnr].value = Value; - } - else { - /* check if more space is needed for matrix */ - inc_mat_space(lp, 1); - - /* Shift the matrix */ - lastelm = lp->non_zeros; - for (i = lastelm; i > elmnr; i--) lp->mat[i] = lp->mat[i - 1]; - for (i = Column; i <= lp->columns; i++) lp->col_end[i]++; - - /* Set new element */ - lp->mat[elmnr].row_nr = Row; - - if (lp->scaling_used) { - if (lp->ch_sign[Row]) - lp->mat[elmnr].value = -Value * lp->scale[Row] * lp->scale[Column]; - else - lp->mat[elmnr].value = Value * lp->scale[Row] * lp->scale[Column]; - } else { - if (lp->ch_sign[Row]) - lp->mat[elmnr].value = -Value; - else - lp->mat[elmnr].value = Value; - } - - lp->row_end_valid = FALSE; - - lp->non_zeros++; - if (lp->active) Non_zeros = lp->non_zeros; - } - } -} - -void set_obj_fn(lprec *lp, REAL *row) { - int i; - for (i = 1; i <= lp->columns; i++) set_mat(lp, 0, i, row[i]); -} - -void str_set_obj_fn(lprec *lp, char *row) { - int i; - REAL *arow; - char *p, *newp; - CALLOC(arow, lp->columns + 1, REAL); - p = row; - for (i = 1; i <= lp->columns; i++) { - arow[i] = (REAL)strtod(p, &newp); - if (p == newp) - error("Bad string in str_set_obj_fn"); - else - p = newp; - } - set_obj_fn(lp, arow); - free(arow); -} - -void add_constraint(lprec *lp, REAL *row, short constr_type, REAL rh) { - matrec *newmat; - int i, j; - int elmnr; - int stcol; - int *addtoo; - int *num, *rownum, row_nr; - REAL theta; - - MALLOC(addtoo, lp->columns + 1, int) - - for (i = 1; i <= lp->columns; i++) - if (row[i] != 0) { - addtoo[i] = TRUE; - lp->non_zeros++; - } else - addtoo[i] = FALSE; - - MALLOC(newmat, lp->non_zeros, matrec); - inc_mat_space(lp, 0); - lp->rows++; - lp->sum++; - inc_row_space(lp); - - if (lp->scaling_used) { - /* shift scale */ - for (i = lp->sum; i > lp->rows; i--) lp->scale[i] = lp->scale[i - 1]; - lp->scale[lp->rows] = 1; - } - - if (lp->names_used) sprintf(lp->row_name[lp->rows], "r_%d", lp->rows); - - if (lp->scaling_used && lp->columns_scaled) - for (i = 1; i <= lp->columns; i++) row[i] *= lp->scale[lp->rows + i]; - - if (constr_type == GE) - lp->ch_sign[lp->rows] = TRUE; - else - lp->ch_sign[lp->rows] = FALSE; - - elmnr = 0; - stcol = 0; - for (i = 1; i <= lp->columns; i++) { - for (j = stcol; j < lp->col_end[i]; j++) { - newmat[elmnr].row_nr = lp->mat[j].row_nr; - newmat[elmnr].value = lp->mat[j].value; - elmnr++; - } - if (addtoo[i]) { - if (lp->ch_sign[lp->rows]) - newmat[elmnr].value = -row[i]; - else - newmat[elmnr].value = row[i]; - newmat[elmnr].row_nr = lp->rows; - elmnr++; - } - stcol = lp->col_end[i]; - lp->col_end[i] = elmnr; - } - - memcpy(lp->mat, newmat, lp->non_zeros * sizeof(matrec)); - - free(newmat); - free(addtoo); - - for (i = lp->sum; i > lp->rows; i--) { - lp->orig_upbo[i] = lp->orig_upbo[i - 1]; - lp->orig_lowbo[i] = lp->orig_lowbo[i - 1]; - lp->basis[i] = lp->basis[i - 1]; - lp->lower[i] = lp->lower[i - 1]; - lp->must_be_int[i] = lp->must_be_int[i - 1]; - } - - for (i = 1; i <= lp->rows; i++) - if (lp->bas[i] >= lp->rows) lp->bas[i]++; - - if (constr_type == LE || constr_type == GE) { - lp->orig_upbo[lp->rows] = lp->infinite; - } else if (constr_type == EQ) { - lp->orig_upbo[lp->rows] = 0; - } else { - fprintf(stderr, "Wrong constraint type\n"); - exit(FAIL); - } - - lp->orig_lowbo[lp->rows] = 0; - - if (constr_type == GE && rh != 0) - lp->orig_rh[lp->rows] = -rh; - else - lp->orig_rh[lp->rows] = rh; - - lp->row_end_valid = FALSE; - - lp->bas[lp->rows] = lp->rows; - lp->basis[lp->rows] = TRUE; - lp->lower[lp->rows] = TRUE; - - if (lp->active) set_globals(lp); - lp->eta_valid = FALSE; -} - -void str_add_constraint(lprec *lp, char *row_string, short constr_type, REAL rh) { - int i; - REAL *aRow; - char *p, *newp; - CALLOC(aRow, lp->columns + 1, REAL); - p = row_string; - - for (i = 1; i <= lp->columns; i++) { - aRow[i] = (REAL)strtod(p, &newp); - if (p == newp) - error("Bad string in str_add_constr"); - else - p = newp; - } - add_constraint(lp, aRow, constr_type, rh); - free(aRow); -} - -void del_constraint(lprec *lp, int del_row) { - int i, j; - unsigned elmnr; - int startcol; - int row_nr; - - if (del_row < 1 || del_row > lp->rows) { - fprintf(stderr, "There is no constraint nr. %d\n", del_row); - exit(FAIL); - } - - elmnr = 0; - startcol = 0; - - for (i = 1; i <= lp->columns; i++) { - for (j = startcol; j < lp->col_end[i]; j++) { - if (lp->mat[j].row_nr != del_row) { - lp->mat[elmnr] = lp->mat[j]; - if (lp->mat[elmnr].row_nr > del_row) lp->mat[elmnr].row_nr--; - elmnr++; - } else - lp->non_zeros--; - } - startcol = lp->col_end[i]; - lp->col_end[i] = elmnr; - } - for (i = del_row; i < lp->rows; i++) { - lp->orig_rh[i] = lp->orig_rh[i + 1]; - lp->ch_sign[i] = lp->ch_sign[i + 1]; - lp->bas[i] = lp->bas[i + 1]; - if (lp->names_used) strcpy(lp->row_name[i], lp->row_name[i + 1]); - } - for (i = 1; i < lp->rows; i++) - if (lp->bas[i] > del_row) lp->bas[i]--; - - for (i = del_row; i < lp->sum; i++) { - lp->lower[i] = lp->lower[i + 1]; - lp->basis[i] = lp->basis[i + 1]; - lp->orig_upbo[i] = lp->orig_upbo[i + 1]; - lp->orig_lowbo[i] = lp->orig_lowbo[i + 1]; - lp->must_be_int[i] = lp->must_be_int[i + 1]; - if (lp->scaling_used) lp->scale[i] = lp->scale[i + 1]; - } - - lp->rows--; - lp->sum--; - - lp->row_end_valid = FALSE; - - if (lp->active) set_globals(lp); - lp->eta_valid = FALSE; - lp->basis_valid = FALSE; -} - -void add_lag_con(lprec *lp, REAL *row, short con_type, REAL rhs) { - int i; - REAL sign; - if (con_type == LE || con_type == EQ) - sign = 1; - else if (con_type == GE) - sign = -1; - else - error("con_type not implemented\n"); - - lp->nr_lagrange++; - if (lp->nr_lagrange == 1) { - CALLOC(lp->lag_row, lp->nr_lagrange, REAL *); - CALLOC(lp->lag_rhs, lp->nr_lagrange, REAL); - CALLOC(lp->lambda, lp->nr_lagrange, REAL); - CALLOC(lp->lag_con_type, lp->nr_lagrange, short); - } else { - REALLOC(lp->lag_row, lp->nr_lagrange, REAL *); - REALLOC(lp->lag_rhs, lp->nr_lagrange, REAL); - REALLOC(lp->lambda, lp->nr_lagrange, REAL); - REALLOC(lp->lag_con_type, lp->nr_lagrange, short); - } - CALLOC(lp->lag_row[lp->nr_lagrange - 1], lp->columns + 1, REAL); - lp->lag_rhs[lp->nr_lagrange - 1] = rhs * sign; - for (i = 1; i <= lp->columns; i++) lp->lag_row[lp->nr_lagrange - 1][i] = row[i] * sign; - lp->lambda[lp->nr_lagrange - 1] = 0; - lp->lag_con_type[lp->nr_lagrange - 1] = (con_type == EQ); -} - -void str_add_lag_con(lprec *lp, char *row, short con_type, REAL rhs) { - int i; - REAL *a_row; - char *p, *new_p; - CALLOC(a_row, lp->columns + 1, REAL); - p = row; - - for (i = 1; i <= lp->columns; i++) { - a_row[i] = (REAL)strtod(p, &new_p); - if (p == new_p) - error("Bad string in str_add_lag_con"); - else - p = new_p; - } - add_lag_con(lp, a_row, con_type, rhs); - free(a_row); -} - -void add_column(lprec *lp, REAL *column) { - int i, j, elmnr, row_nr, *num, *rownum; - - lp->columns++; - lp->sum++; - inc_col_space(lp); - inc_mat_space(lp, lp->rows + 1); - - if (lp->scaling_used) { - for (i = 0; i <= lp->rows; i++) column[i] *= lp->scale[i]; - lp->scale[lp->sum] = 1; - } - - elmnr = lp->col_end[lp->columns - 1]; - for (i = 0; i <= lp->rows; i++) - if (column[i] != 0) { - lp->mat[elmnr].row_nr = i; - if (lp->ch_sign[i]) - lp->mat[elmnr].value = -column[i]; - else - lp->mat[elmnr].value = column[i]; - lp->non_zeros++; - elmnr++; - } - lp->col_end[lp->columns] = elmnr; - lp->orig_lowbo[lp->sum] = 0; - lp->orig_upbo[lp->sum] = lp->infinite; - lp->lower[lp->sum] = TRUE; - lp->basis[lp->sum] = FALSE; - lp->must_be_int[lp->sum] = FALSE; - if (lp->names_used) sprintf(lp->col_name[lp->columns], "var_%d", lp->columns); - - lp->row_end_valid = FALSE; - - if (lp->active) { - Sum = lp->sum; - Columns = lp->columns; - Non_zeros = lp->non_zeros; - } -} - -void str_add_column(lprec *lp, char *col_string) { - int i; - REAL *aCol; - char *p, *newp; - CALLOC(aCol, lp->rows + 1, REAL); - p = col_string; - - for (i = 0; i <= lp->rows; i++) { - aCol[i] = (REAL)strtod(p, &newp); - if (p == newp) - error("Bad string in str_add_column"); - else - p = newp; - } - add_column(lp, aCol); - free(aCol); -} - -void del_column(lprec *lp, int column) { - int i, j, from_elm, to_elm, elm_in_col; - if (column > lp->columns || column < 1) error("Column out of range in del_column"); - for (i = 1; i <= lp->rows; i++) { - if (lp->bas[i] == lp->rows + column) - lp->basis_valid = FALSE; - else if (lp->bas[i] > lp->rows + column) - lp->bas[i]--; - } - for (i = lp->rows + column; i < lp->sum; i++) { - if (lp->names_used) strcpy(lp->col_name[i - lp->rows], lp->col_name[i - lp->rows + 1]); - lp->must_be_int[i] = lp->must_be_int[i + 1]; - lp->orig_upbo[i] = lp->orig_upbo[i + 1]; - lp->orig_lowbo[i] = lp->orig_lowbo[i + 1]; - lp->upbo[i] = lp->upbo[i + 1]; - lp->lowbo[i] = lp->lowbo[i + 1]; - lp->basis[i] = lp->basis[i + 1]; - lp->lower[i] = lp->lower[i + 1]; - if (lp->scaling_used) lp->scale[i] = lp->scale[i + 1]; - } - for (i = 0; i < lp->nr_lagrange; i++) - for (j = column; j <= lp->columns; j++) lp->lag_row[i][j] = lp->lag_row[i][j + 1]; - to_elm = lp->col_end[column - 1]; - from_elm = lp->col_end[column]; - elm_in_col = from_elm - to_elm; - for (i = from_elm; i < lp->non_zeros; i++) { - lp->mat[to_elm] = lp->mat[i]; - to_elm++; - } - for (i = column; i < lp->columns; i++) lp->col_end[i] = lp->col_end[i + 1] - elm_in_col; - lp->non_zeros -= elm_in_col; - lp->row_end_valid = FALSE; - lp->eta_valid = FALSE; - - lp->sum--; - lp->columns--; - if (lp->active) set_globals(lp); -} - -void set_upbo(lprec *lp, int column, REAL value) { - if (column > lp->columns || column < 1) error("Column out of range"); - if (lp->scaling_used) value /= lp->scale[lp->rows + column]; - if (value < lp->orig_lowbo[lp->rows + column]) error("Upperbound must be >= lowerbound"); - lp->eta_valid = FALSE; - lp->orig_upbo[lp->rows + column] = value; -} - -void set_lowbo(lprec *lp, int column, REAL value) { - if (column > lp->columns || column < 1) error("Column out of range"); - if (lp->scaling_used) value /= lp->scale[lp->rows + column]; - if (value > lp->orig_upbo[lp->rows + column]) error("Upperbound must be >= lowerbound"); - lp->eta_valid = FALSE; - lp->orig_lowbo[lp->rows + column] = value; -} - -void set_int(lprec *lp, int column, short must_be_int) { - if (column > lp->columns || column < 1) error("Column out of range"); - lp->must_be_int[lp->rows + column] = must_be_int; - if (must_be_int == TRUE) - if (lp->columns_scaled) unscale_columns(lp); -} - -void set_rh(lprec *lp, int row, REAL value) { - if (row > lp->rows || row < 0) error("Row out of Range"); - if (row == 0) /* setting of RHS of OF not meaningful */ - { - fprintf(stderr, "Warning: attempt to set RHS of objective function, ignored\n"); - return; - } - if (lp->scaling_used) - if (lp->ch_sign[row]) - lp->orig_rh[row] = -value * lp->scale[row]; - else - lp->orig_rh[row] = value * lp->scale[row]; - else if (lp->ch_sign[row]) - lp->orig_rh[row] = -value; - else - lp->orig_rh[row] = value; - lp->eta_valid = FALSE; -} - -void set_rh_vec(lprec *lp, REAL *rh) { - int i; - if (lp->scaling_used) - for (i = 1; i <= lp->rows; i++) - if (lp->ch_sign[i]) - lp->orig_rh[i] = -rh[i] * lp->scale[i]; - else - lp->orig_rh[i] = rh[i] * lp->scale[i]; - else - for (i = 1; i <= lp->rows; i++) - if (lp->ch_sign[i]) - lp->orig_rh[i] = -rh[i]; - else - lp->orig_rh[i] = rh[i]; - lp->eta_valid = FALSE; -} - -void str_set_rh_vec(lprec *lp, char *rh_string) { - int i; - REAL *newrh; - char *p, *newp; - CALLOC(newrh, lp->rows + 1, REAL); - p = rh_string; - - for (i = 1; i <= lp->rows; i++) { - newrh[i] = (REAL)strtod(p, &newp); - if (p == newp) - error("Bad string in str_set_rh_vec"); - else - p = newp; - } - set_rh_vec(lp, newrh); - free(newrh); -} - -void set_maxim(lprec *lp) { - int i; - if (lp->maximise == FALSE) { - for (i = 0; i < lp->non_zeros; i++) - if (lp->mat[i].row_nr == 0) lp->mat[i].value *= -1; - lp->eta_valid = FALSE; - } - lp->maximise = TRUE; - lp->ch_sign[0] = TRUE; - if (lp->active) Maximise = TRUE; -} - -void set_minim(lprec *lp) { - int i; - if (lp->maximise == TRUE) { - for (i = 0; i < lp->non_zeros; i++) - if (lp->mat[i].row_nr == 0) lp->mat[i].value = -lp->mat[i].value; - lp->eta_valid = FALSE; - } - lp->maximise = FALSE; - lp->ch_sign[0] = FALSE; - if (lp->active) Maximise = FALSE; -} - -void set_constr_type(lprec *lp, int row, short con_type) { - int i; - if (row > lp->rows || row < 1) error("Row out of Range"); - if (con_type == EQ) { - lp->orig_upbo[row] = 0; - lp->basis_valid = FALSE; - if (lp->ch_sign[row]) { - for (i = 0; i < lp->non_zeros; i++) - if (lp->mat[i].row_nr == row) lp->mat[i].value *= -1; - lp->eta_valid = FALSE; - lp->ch_sign[row] = FALSE; - if (lp->orig_rh[row] != 0) lp->orig_rh[row] *= -1; - } - } else if (con_type == LE) { - lp->orig_upbo[row] = lp->infinite; - lp->basis_valid = FALSE; - if (lp->ch_sign[row]) { - for (i = 0; i < lp->non_zeros; i++) - if (lp->mat[i].row_nr == row) lp->mat[i].value *= -1; - lp->eta_valid = FALSE; - lp->ch_sign[row] = FALSE; - if (lp->orig_rh[row] != 0) lp->orig_rh[row] *= -1; - } - } else if (con_type == GE) { - lp->orig_upbo[row] = lp->infinite; - lp->basis_valid = FALSE; - if (!lp->ch_sign[row]) { - for (i = 0; i < lp->non_zeros; i++) - if (lp->mat[i].row_nr == row) lp->mat[i].value *= -1; - lp->eta_valid = FALSE; - lp->ch_sign[row] = TRUE; - if (lp->orig_rh[row] != 0) lp->orig_rh[row] *= -1; - } - } else - error("Constraint type not (yet) implemented"); -} - -REAL mat_elm(lprec *lp, int row, int column) { - REAL value; - int elmnr; - if (row < 0 || row > lp->rows) error("Row out of range in mat_elm"); - if (column < 1 || column > lp->columns) error("Column out of range in mat_elm"); - value = 0; - elmnr = lp->col_end[column - 1]; - while (lp->mat[elmnr].row_nr != row && elmnr < lp->col_end[column]) elmnr++; - if (elmnr != lp->col_end[column]) { - value = lp->mat[elmnr].value; - if (lp->ch_sign[row]) value = -value; - if (lp->scaling_used) value /= lp->scale[row] * lp->scale[lp->rows + column]; - } - return (value); -} - -void get_row(lprec *lp, int row_nr, REAL *row) { - int i, j; - REAL RowMult; - if (row_nr < 0 || row_nr > lp->rows) error("Row nr. out of range in get_row"); - for (i = 1; i <= lp->columns; i++) { - row[i] = 0; - for (j = lp->col_end[i - 1]; j < lp->col_end[i]; j++) - if (lp->mat[j].row_nr == row_nr) row[i] = lp->mat[j].value; - if (lp->scaling_used) row[i] /= lp->scale[lp->rows + i] * lp->scale[row_nr]; - } - if (lp->ch_sign[row_nr]) - for (i = 0; i <= lp->columns; i++) - if (row[i] != 0) row[i] = -row[i]; -} - -void get_column(lprec *lp, int col_nr, REAL *column) { - int i; - - if (col_nr < 1 || col_nr > lp->columns) error("Col. nr. out of range in get_column"); - for (i = 0; i <= lp->rows; i++) column[i] = 0; - for (i = lp->col_end[col_nr - 1]; i < lp->col_end[col_nr]; i++) - column[lp->mat[i].row_nr] = lp->mat[i].value; - for (i = 0; i <= lp->rows; i++) - if (column[i] != 0) { - if (lp->ch_sign[i]) column[i] *= -1; - if (lp->scaling_used) column[i] /= (lp->scale[i] * lp->scale[lp->rows + col_nr]); - } -} - -void get_reduced_costs(lprec *lp, REAL *rc) { - int varnr, i, j; - REAL f; - - if (!lp->basis_valid) error("Not a valid basis in get_reduced_costs"); - set_globals(lp); - if (!lp->eta_valid) invert(); - for (i = 1; i <= lp->sum; i++) rc[i] = 0; - rc[0] = 1; - btran(rc); - for (i = 1; i <= lp->columns; i++) { - varnr = lp->rows + i; - if (!Basis[varnr]) - if (Upbo[varnr] > 0) { - f = 0; - for (j = Col_end[i - 1]; j < Col_end[i]; j++) f += rc[Mat[j].row_nr] * Mat[j].value; - rc[varnr] = f; - } - } - for (i = 1; i <= Sum; i++) my_round(rc[i], Epsd); -} - -short is_feasible(lprec *lp, REAL *values) { - int i, elmnr; - REAL *this_rhs; - REAL dist; - - if (lp->scaling_used) { - for (i = lp->rows + 1; i <= lp->sum; i++) - if (values[i - lp->rows] < lp->orig_lowbo[i] * lp->scale[i] || - values[i - lp->rows] > lp->orig_upbo[i] * lp->scale[i]) - return (FALSE); - } else { - for (i = lp->rows + 1; i <= lp->sum; i++) - if (values[i - lp->rows] < lp->orig_lowbo[i] || values[i - lp->rows] > lp->orig_upbo[i]) - return (FALSE); - } - CALLOC(this_rhs, lp->rows + 1, REAL) - for (i = 1; i <= lp->columns; i++) - for (elmnr = lp->col_end[i - 1]; elmnr < lp->col_end[i]; elmnr++) - this_rhs[lp->mat[elmnr].row_nr] += lp->mat[elmnr].value * values[i]; - for (i = 1; i <= lp->rows; i++) { - dist = lp->orig_rh[i] - this_rhs[i]; - my_round(dist, 0.001) if ((lp->orig_upbo[i] == 0 && dist != 0) || dist < 0) { - free(this_rhs); - return (FALSE); - } - } - free(this_rhs); - return (TRUE); -} - -short column_in_lp(lprec *lp, REAL *testcolumn) { - int i, j; - short ident; - REAL value; - - if (lp->scaling_used) - for (i = 1; i <= lp->columns; i++) { - ident = TRUE; - j = lp->col_end[i - 1]; - while (ident && (j < lp->col_end[i])) { - value = lp->mat[j].value; - if (lp->ch_sign[lp->mat[j].row_nr]) value = -value; - value /= lp->scale[lp->rows + i]; - value /= lp->scale[lp->mat[j].row_nr]; - value -= testcolumn[lp->mat[j].row_nr]; - if (my_abs(value) > 0.001) /* should be some epsilon? MB */ - ident = FALSE; - j++; - } - if (ident) return (TRUE); - } - else - for (i = 1; i <= lp->columns; i++) { - ident = TRUE; - j = lp->col_end[i - 1]; - while (ident && j < lp->col_end[i]) { - value = lp->mat[j].value; - if (lp->ch_sign[lp->mat[j].row_nr]) value *= -1; - value -= testcolumn[lp->mat[j].row_nr]; - if (my_abs(value) > 0.001) ident = FALSE; - j++; - } - if (ident) return (TRUE); - } - return (FALSE); -} - -void print_lp(lprec *lp) { - int i, j; - REAL *fatmat; - CALLOC(fatmat, (lp->rows + 1) * lp->columns, REAL); - for (i = 1; i <= lp->columns; i++) - for (j = lp->col_end[i - 1]; j < lp->col_end[i]; j++) - fatmat[(i - 1) * (lp->rows + 1) + lp->mat[j].row_nr] = lp->mat[j].value; - - printf("problem name: %s\n", lp->lp_name); - printf(" "); - for (j = 1; j <= lp->columns; j++) - if (lp->names_used) - printf("%8s ", lp->col_name[j]); - else - printf("Var[%3d] ", j); - if (lp->maximise) { - printf("\nMaximise "); - for (j = 0; j < lp->columns; j++) printf("% 8.2f ", -fatmat[j * (lp->rows + 1)]); - } else { - printf("\nMinimize "); - for (j = 0; j < lp->columns; j++) printf("% 8.2f ", fatmat[j * (lp->rows + 1)]); - } - printf("\n"); - for (i = 1; i <= lp->rows; i++) { - if (lp->names_used) - printf("%9s ", lp->row_name[i]); - else - printf("Row[%3d] ", i); - for (j = 0; j < lp->columns; j++) - if (lp->ch_sign[i] && fatmat[j * (lp->rows + 1) + i] != 0) - printf("% 8.2f ", -fatmat[j * (lp->rows + 1) + i]); - else - printf("% 8.2f ", fatmat[j * (lp->rows + 1) + i]); - if (lp->orig_upbo[i] == lp->infinite) - if (lp->ch_sign[i]) - printf(">= "); - else - printf("<= "); - else - printf(" = "); - if (lp->ch_sign[i]) - printf("% 8.2f\n", -lp->orig_rh[i]); - else - printf("% 8.2f\n", lp->orig_rh[i]); - } - printf("Type "); - for (i = 1; i <= lp->columns; i++) - if (lp->must_be_int[lp->rows + i] == TRUE) - printf(" Int "); - else - printf(" Real "); - printf("\nupbo "); - for (i = 1; i <= lp->columns; i++) - if (lp->orig_upbo[lp->rows + i] == lp->infinite) - printf(" Inf "); - else - printf("% 8.2f ", lp->orig_upbo[lp->rows + i]); - printf("\nlowbo "); - for (i = 1; i <= lp->columns; i++) printf("% 8.2f ", lp->orig_lowbo[lp->rows + i]); - printf("\n"); - for (i = 0; i < lp->nr_lagrange; i++) { - printf("lag[%3d] ", i); - for (j = 1; j <= lp->columns; j++) printf("% 8.2f ", lp->lag_row[i][j]); - if (lp->orig_upbo[i] == lp->infinite) - if (lp->lag_con_type[i] == GE) - printf(">= "); - else if (lp->lag_con_type[i] == LE) - printf("<= "); - else if (lp->lag_con_type[i] == EQ) - printf(" = "); - printf("% 8.2f\n", lp->lag_rhs[i]); - } - - free(fatmat); -} - -void set_row_name(lprec *lp, int row, nstring new_name) { - int i; - - if (!lp->names_used) { - CALLOC(lp->row_name, lp->rows_alloc + 1, nstring); - CALLOC(lp->col_name, lp->columns_alloc + 1, nstring); - lp->names_used = TRUE; - for (i = 0; i <= lp->rows; i++) sprintf(lp->row_name[i], "r_%d", i); - for (i = 1; i <= lp->columns; i++) sprintf(lp->col_name[i], "var_%d", i); - } - strcpy(lp->row_name[row], new_name); -} - -void set_col_name(lprec *lp, int column, nstring new_name) { - int i; - - if (!lp->names_used) { - CALLOC(lp->row_name, lp->rows_alloc + 1, nstring); - CALLOC(lp->col_name, lp->columns_alloc + 1, nstring); - lp->names_used = TRUE; - for (i = 0; i <= lp->rows; i++) sprintf(lp->row_name[i], "r_%d", i); - for (i = 1; i <= lp->columns; i++) sprintf(lp->col_name[i], "var_%d", i); - } - strcpy(lp->col_name[column], new_name); -} - -static REAL minmax_to_scale(REAL min, REAL max) { - REAL scale; - - /* should do something sensible when min or max is 0, MB */ - if ((min == 0) || (max == 0)) return ((REAL)1); - - scale = 1 / pow(10, (log10(min) + log10(max)) / 2); - return (scale); -} - -void unscale_columns(lprec *lp) { - int i, j; - - /* unscale mat */ - for (j = 1; j <= lp->columns; j++) - for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) - lp->mat[i].value /= lp->scale[lp->rows + j]; - - /* unscale bounds as well */ - for (i = lp->rows + 1; i < lp->sum; i++) { - if (lp->orig_lowbo[i] != 0) lp->orig_lowbo[i] *= lp->scale[i]; - if (lp->orig_upbo[i] != lp->infinite) lp->orig_upbo[i] *= lp->scale[i]; - } - - for (i = lp->rows + 1; i <= lp->sum; i++) lp->scale[i] = 1; - lp->columns_scaled = FALSE; - lp->eta_valid = FALSE; -} - -void unscale(lprec *lp) { - int i, j; - - if (lp->scaling_used) { - /* unscale mat */ - for (j = 1; j <= lp->columns; j++) - for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) - lp->mat[i].value /= lp->scale[lp->rows + j]; - - /* unscale bounds */ - for (i = lp->rows + 1; i < lp->sum; i++) { - if (lp->orig_lowbo[i] != 0) lp->orig_lowbo[i] *= lp->scale[i]; - if (lp->orig_upbo[i] != lp->infinite) lp->orig_upbo[i] *= lp->scale[i]; - } - - /* unscale the matrix */ - for (j = 1; j <= lp->columns; j++) - for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) - lp->mat[i].value /= lp->scale[lp->mat[i].row_nr]; - - /* unscale the rhs! */ - for (i = 0; i <= lp->rows; i++) lp->orig_rh[i] /= lp->scale[i]; - - free(lp->scale); - lp->scaling_used = FALSE; - lp->eta_valid = FALSE; - } -} - -void auto_scale(lprec *lp) { - int i, j, row_nr, IntUsed; - REAL *row_max, *row_min, *scalechange, absval; - REAL col_max, col_min, col_scale; - - if (!lp->scaling_used) { - MALLOC(lp->scale, lp->sum_alloc + 1, REAL); - for (i = 0; i <= lp->sum; i++) lp->scale[i] = 1; - } - MALLOC(row_max, lp->rows + 1, REAL); - MALLOC(row_min, lp->rows + 1, REAL); - MALLOC(scalechange, lp->sum + 1, REAL); - - /* initialise min and max values */ - for (i = 0; i <= lp->rows; i++) { - row_max[i] = 0; - row_min[i] = lp->infinite; - } - - /* calculate min and max absolute values of rows */ - for (j = 1; j <= lp->columns; j++) { - for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) { - row_nr = lp->mat[i].row_nr; - absval = my_abs(lp->mat[i].value); - if (absval != 0) { - row_max[row_nr] = my_max(row_max[row_nr], absval); - row_min[row_nr] = my_min(row_min[row_nr], absval); - } - } - } - /* calculate scale factors for rows */ - for (i = 0; i <= lp->rows; i++) { - scalechange[i] = minmax_to_scale(row_min[i], row_max[i]); - lp->scale[i] *= scalechange[i]; - } - - /* now actually scale the matrix */ - for (j = 1; j <= lp->columns; j++) - for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) - lp->mat[i].value *= scalechange[lp->mat[i].row_nr]; - - /* and scale the rhs! */ - for (i = 0; i <= lp->rows; i++) lp->orig_rh[i] *= scalechange[i]; - - free(row_max); - printf("after free r_max. "); - free(row_min); - printf("after free rmin. "); - - IntUsed = FALSE; - i = lp->rows + 1; - while (!IntUsed && i <= lp->sum) { - IntUsed = lp->must_be_int[i]; - i++; - } - if (!IntUsed) { - REAL col_max, col_min, col_scale; - - /* calculate scales */ - for (j = 1; j <= lp->columns; j++) { - col_max = 0; - col_min = lp->infinite; - for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) { - if (lp->mat[i].value != 0) { - col_max = my_max(col_max, my_abs(lp->mat[i].value)); - col_min = my_min(col_min, my_abs(lp->mat[i].value)); - } - } - scalechange[lp->rows + j] = minmax_to_scale(col_min, col_max); - lp->scale[lp->rows + j] *= scalechange[lp->rows + j]; - } - - /* scale mat */ - for (j = 1; j <= lp->columns; j++) - for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) - lp->mat[i].value *= scalechange[lp->rows + j]; - - /* scale bounds as well */ - for (i = lp->rows + 1; i < lp->sum; i++) { - if (lp->orig_lowbo[i] != 0) lp->orig_lowbo[i] /= scalechange[i]; - if (lp->orig_upbo[i] != lp->infinite) lp->orig_upbo[i] /= scalechange[i]; - } - lp->columns_scaled = TRUE; - } - printf("b4 free scch. "); - free(scalechange); - printf("after free scch. "); - lp->scaling_used = TRUE; - lp->eta_valid = FALSE; -} - -void reset_basis(lprec *lp) { lp->basis_valid = FALSE; } - -void print_solution(lprec *lp) { - int i; - - fprintf(stdout, "Value of objective function: %16.10g\n", (double)lp->best_solution[0]); - - /* print normal variables */ - for (i = 1; i <= lp->columns; i++) - if (lp->names_used) - fprintf(stdout, "%-10s%16.5g\n", lp->col_name[i], (double)lp->best_solution[lp->rows + i]); - else - fprintf(stdout, "Var [%4d] %16.5g\n", i, (double)lp->best_solution[lp->rows + i]); - - /* print achieved constraint values */ - if (lp->verbose) { - fprintf(stdout, "\nActual values of the constraints:\n"); - for (i = 1; i <= lp->rows; i++) - if (lp->names_used) - fprintf(stdout, "%-10s%16.5g\n", lp->row_name[i], (double)lp->best_solution[i]); - else - fprintf(stdout, "%Row [%4d] %16.5g\n", i, (double)lp->best_solution[i]); - } - - if ((lp->verbose || lp->print_duals)) { - if (lp->max_level != 1) - fprintf(stdout, "These are the duals from the node that gave the optimal solution.\n"); - else - fprintf(stdout, "\nDual values:\n"); - for (i = 1; i <= lp->rows; i++) - if (lp->names_used) - fprintf(stdout, "%-10s%16.5g\n", lp->row_name[i], (double)lp->duals[i]); - else - fprintf(stdout, "Row [%4d] %16.5g\n", i, (double)lp->duals[i]); - } -} /* Printsolution */ - -void write_LP(lprec *lp, FILE *output) { - int i, j; - REAL *row; - nstring var_name; - - MALLOC(row, lp->columns + 1, REAL); - if (lp->maximise) - fprintf(output, "max:"); - else - fprintf(output, "min:"); - - get_row(lp, 0, row); - for (i = 1; i <= lp->columns; i++) - if (row[i] != 0) { - if (row[i] == -1) - fprintf(output, " -"); - else if (row[i] == 1) - fprintf(output, " +"); - else - fprintf(output, " %+g ", row[i]); - if (lp->names_used) - fprintf(output, "%s", lp->col_name[i]); - else - fprintf(output, "x%d", i); - } - fprintf(output, ";\n"); - - for (j = 1; j <= lp->rows; j++) { - if (lp->names_used) fprintf(output, "%s:", lp->row_name[j]); - get_row(lp, j, row); - for (i = 1; i <= lp->columns; i++) - if (row[i] != 0) { - if (row[i] == -1) - fprintf(output, " -"); - else if (row[i] == 1) - fprintf(output, " +"); - else - fprintf(output, " %+g ", row[i]); - if (lp->names_used) - fprintf(output, "%s", lp->col_name[i]); - else - fprintf(output, "x%d", i); - } - if (lp->orig_upbo[j] == 0) - fprintf(output, " ="); - else if (lp->ch_sign[j]) - fprintf(output, " >"); - else - fprintf(output, " <"); - if (lp->ch_sign[j]) - fprintf(output, " %g;\n", -lp->orig_rh[j]); - else - fprintf(output, " %g;\n", lp->orig_rh[j]); - } - for (i = lp->rows + 1; i <= lp->sum; i++) { - if (lp->orig_lowbo[i] != 0) { - if (lp->names_used) - fprintf(output, "%s > %g;\n", lp->col_name[i - lp->rows], lp->orig_lowbo[i]); - else - fprintf(output, "x%d > %g;\n", i - lp->rows, lp->orig_lowbo[i]); - } - if (lp->orig_upbo[i] != lp->infinite) { - if (lp->names_used) - fprintf(output, "%s < %g;\n", lp->col_name[i - lp->rows], lp->orig_upbo[i]); - else - fprintf(output, "x%d < %g;\n", i - lp->rows, lp->orig_upbo[i]); - } - } - - i = 1; - while (!lp->must_be_int[lp->rows + i] && i <= lp->columns) i++; - if (i <= lp->columns) { - if (lp->names_used) - fprintf(output, "\nint %s", lp->col_name[i]); - else - fprintf(output, "\nint x%d", i); - i++; - for (; i <= lp->columns; i++) - if (lp->must_be_int[lp->rows + i]) - if (lp->names_used) - fprintf(output, ",%s", lp->col_name[i]); - else - fprintf(output, ", x%d", i); - fprintf(output, ";\n"); - } - free(row); -} - -void write_MPS(lprec *lp, FILE *output) { - int i, j, marker; - REAL *column; - - MALLOC(column, lp->rows + 1, REAL); - marker = 0; - fprintf(output, "NAME %s\n", lp->lp_name); - fprintf(output, "ROWS\n"); - for (i = 0; i <= lp->rows; i++) { - if (i == 0) - fprintf(output, " N "); - else if (lp->orig_upbo[i] == lp->infinite) - if (lp->ch_sign[i]) - fprintf(output, " G "); - else - fprintf(output, " L "); - else - fprintf(output, " E "); - if (lp->names_used) - fprintf(output, "%s\n", lp->row_name[i]); - else - fprintf(output, "r_%d\n", i); - } - - fprintf(output, "COLUMNS\n"); - j = 0; - for (i = 1; i <= lp->columns; i++) { - if ((lp->must_be_int[i + lp->rows]) && (marker % 2) == 0) { - fprintf(output, " MARK%04d 'MARKER' 'INTORG'\n", marker); - marker++; - } - if ((!lp->must_be_int[i + lp->rows]) && (marker % 2) == 1) { - fprintf(output, " MARK%04d 'MARKER' 'INTEND'\n", marker); - marker++; - } - get_column(lp, i, column); - j = 0; - if (lp->maximise) { - if (column[j] != 0) { - if (lp->names_used) - fprintf(output, " %-8s %-8s %g\n", lp->col_name[i], lp->row_name[j], -column[j]); - else - fprintf(output, " var_%-4d r_%-6d %g\n", i, j, -column[j]); - } - } else { - if (column[j] != 0) { - if (lp->names_used) - fprintf(output, " %-8s %-8s %g\n", lp->col_name[i], lp->row_name[j], column[j]); - else - fprintf(output, " var_%-4d r_%-6d %g\n", i, j, column[j]); - } - } - for (j = 1; j <= lp->rows; j++) - if (column[j] != 0) { - if (lp->names_used) - fprintf(output, " %-8s %-8s %g\n", lp->col_name[i], lp->row_name[j], column[j]); - else - fprintf(output, " var_%-4d r_%-6d %g\n", i, j, column[j]); - } - } - if ((marker % 2) == 1) { - fprintf(output, " MARK%04d 'MARKER' 'INTEND'\n", marker); - marker++; - } - - fprintf(output, "RHS\n"); - for (i = 1; i <= lp->rows; i++) { - if (lp->ch_sign[i]) { - if (lp->names_used) - fprintf(output, " RHS %-8s %g\n", lp->row_name[i], (double)-lp->orig_rh[i]); - else - fprintf(output, " RHS r_%-6d %g\n", i, (double)-lp->orig_rh[i]); - } else { - if (lp->names_used) - fprintf(output, " RHS %-8s %g\n", lp->row_name[i], (double)lp->orig_rh[i]); - else - fprintf(output, " RHS r_%-6d %g\n", i, (double)lp->orig_rh[i]); - } - } - - fprintf(output, "BOUNDS\n"); - if (lp->names_used) - for (i = lp->rows + 1; i <= lp->sum; i++) { - if (lp->orig_upbo[i] < lp->infinite) - fprintf(output, " UP BND %-8s %g\n", lp->col_name[i - lp->rows], - (double)lp->orig_upbo[i]); - if (lp->orig_lowbo[i] != 0) - fprintf(output, " LO BND %-8s %g\n", lp->col_name[i - lp->rows], - (double)lp->orig_lowbo[i]); - } - else - for (i = lp->rows + 1; i <= lp->sum; i++) { - if (lp->orig_upbo[i] < lp->infinite) - fprintf(output, " UP BND var_%-4d %g\n", i - lp->rows, (double)lp->orig_upbo[i]); - if (lp->orig_lowbo[i] != 0) - fprintf(output, " LO BND var_%-4d %g\n", i - lp->rows, (double)lp->orig_lowbo[i]); - } - fprintf(output, "ENDATA\n"); - free(column); -} - -void print_duals(lprec *lp) { - int i; - for (i = 1; i <= lp->rows; i++) - if (lp->names_used) - fprintf(stdout, "%10s [%3d] % 10.4f\n", lp->row_name[i], i, lp->duals[i]); - else - fprintf(stdout, "Dual [%3d] % 10.4f\n", i, lp->duals[i]); -} - -void print_scales(lprec *lp) { - int i; - if (lp->scaling_used) { - for (i = 0; i <= lp->rows; i++) - fprintf(stdout, "Row[%3d] scaled at % 10.6f\n", i, lp->scale[i]); - for (i = 1; i <= lp->columns; i++) - fprintf(stdout, "Column[%3d] scaled at % 10.6f\n", i, lp->scale[lp->rows + i]); - } -} +/* $Id: lpkit.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved */ +static char *id = "$Id: lpkit.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $ Copyright (C) Venue"; + +/************************************************************************/ +/* */ +/* (C) Copyright 1989-99 Venue. All Rights Reserved. */ +/* Manufactured in the United States of America. */ +/* */ +/* The contents of this file are proprietary information */ +/* belonging to Venue, and are provided to you under license. */ +/* They may not be further distributed or disclosed to third */ +/* parties without the specific permission of Venue. */ +/* */ +/************************************************************************/ + +#include "version.h" + +#include "lpkit.h" +#include "lpglob.h" +#include +#include +#include + +/* Globals */ +lprec *Lp = NULL; /* pointer to active problem */ +int Rows; +int Columns; +int Sum; +int Non_zeros; +int Level; +matrec *Mat; +int *Col_no; +int *Col_end; +int *Row_end; +REAL *Orig_rh; +REAL *Rh; +REAL *Rhs; +short *Must_be_int; +REAL *Orig_upbo; +REAL *Orig_lowbo; +REAL *Upbo; +REAL *Lowbo; +int *Bas; +short *Basis; +short *Lower; +int Eta_alloc; +int Eta_size; +REAL *Eta_value; +int *Eta_row_nr; +int *Eta_col_end; +int Num_inv; +REAL *Solution; +REAL *Best_solution; +REAL Infinite; +REAL Epsilon; +REAL Epsb; +REAL Epsd; +REAL Epsel; + +REAL TREJ; +REAL TINV; + +short Maximise; +short Floor_first; +REAL Extrad; + +int Warn_count; /* used in CHECK version of rounding macro */ +#ifdef NEVER +void error(char *format, ...) { + va_list ap; + va_start(ap, format); + vfprintf(stderr, format, ap); + fputc('\n', stderr); + va_end(ap); + exit(FAIL); +} +#endif + +lprec *make_lp(int rows, int columns) { + lprec *newlp; + int i, sum; + sstate *st; /* to save state in MILP runs */ + + sum = rows + columns; + if (rows < 0 || columns < 0) error("rows < 0 or columns < 0"); + CALLOC(newlp, 1, lprec); + + strcpy(newlp->lp_name, "unnamed"); + newlp->active = FALSE; + newlp->verbose = FALSE; + newlp->print_duals = FALSE; + newlp->print_sol = FALSE; + newlp->debug = FALSE; + newlp->print_at_invert = FALSE; + newlp->trace = FALSE; + + newlp->rows = rows; + newlp->columns = columns; + newlp->sum = sum; + newlp->rows_alloc = rows; + newlp->columns_alloc = columns; + newlp->sum_alloc = sum; + newlp->names_used = FALSE; + + newlp->obj_bound = DEF_INFINITE; + newlp->infinite = DEF_INFINITE; + newlp->epsilon = DEF_EPSILON; + newlp->epsb = DEF_EPSB; + newlp->epsd = DEF_EPSD; + newlp->epsel = DEF_EPSEL; + newlp->non_zeros = 0; + newlp->mat_alloc = 1; + CALLOC(newlp->mat, newlp->mat_alloc, matrec); + CALLOC(newlp->col_no, newlp->mat_alloc, int); + CALLOC(newlp->col_end, columns + 1, int); + CALLOC(newlp->row_end, rows + 1, int); + newlp->row_end_valid = FALSE; + CALLOC(newlp->orig_rh, rows + 1, REAL); + CALLOC(newlp->rh, rows + 1, REAL); + CALLOC(newlp->rhs, rows + 1, REAL); + CALLOC(newlp->must_be_int, sum + 1, short); + for (i = 0; i <= sum; i++) newlp->must_be_int[i] = FALSE; + CALLOC(newlp->orig_upbo, sum + 1, REAL); + for (i = 0; i <= sum; i++) newlp->orig_upbo[i] = newlp->infinite; + CALLOC(newlp->upbo, sum + 1, REAL); + CALLOC(newlp->orig_lowbo, sum + 1, REAL); + CALLOC(newlp->lowbo, sum + 1, REAL); + + newlp->basis_valid = TRUE; + CALLOC(newlp->bas, rows + 1, int); + CALLOC(newlp->basis, sum + 1, short); + CALLOC(newlp->lower, sum + 1, short); + for (i = 0; i <= rows; i++) { + newlp->bas[i] = i; + newlp->basis[i] = TRUE; + } + for (i = rows + 1; i <= sum; i++) newlp->basis[i] = FALSE; + for (i = 0; i <= sum; i++) newlp->lower[i] = TRUE; + + newlp->eta_valid = TRUE; + newlp->eta_size = 0; + newlp->eta_alloc = 10000; + newlp->max_num_inv = DEFNUMINV; + + newlp->nr_lagrange = 0; + + CALLOC(newlp->eta_value, newlp->eta_alloc, REAL); + CALLOC(newlp->eta_row_nr, newlp->eta_alloc, int); + CALLOC(newlp->eta_col_end, newlp->rows_alloc + newlp->max_num_inv, int); + + newlp->bb_rule = FIRST_NI; + newlp->break_at_int = FALSE; + newlp->break_value = 0; + + newlp->iter = 0; + newlp->total_iter = 0; + CALLOC(newlp->solution, sum + 1, REAL); + CALLOC(newlp->best_solution, sum + 1, REAL); + CALLOC(newlp->duals, rows + 1, REAL); + + newlp->maximise = FALSE; + newlp->floor_first = TRUE; + + newlp->scaling_used = FALSE; + newlp->columns_scaled = FALSE; + + CALLOC(newlp->ch_sign, rows + 1, short); + + for (i = 0; i <= rows; i++) newlp->ch_sign[i] = FALSE; + + st = newlp->solve_states = NULL; + for (i = 0; i < Sum + 2; i++) { + if (st) /* There's an old state-saver to use; re-use it. */ + { + st->saved = 0; /* clear the in-use field */ + st->notint = 0; /* And the not-integer field */ + st = st->next; + } else { + st = (sstate *)malloc(sizeof(sstate)); + if (!st) ERROR(ERR_NOMEM); /* Tell the guy there's no memory */ + st->next = newlp->solve_states; + st->saved = 0; + st->notint = 0; /* And the not-integer field */ + newlp->solve_states = st; + st = (sstate *)NULL; + } + } + + newlp->valid = FALSE; + + return (newlp); +} + +void delete_lp(lprec *lp) { + int i; + + if (lp->active) Lp = NULL; + if (lp->names_used) { + free(lp->row_name); + free(lp->col_name); + } + free(lp->mat); + free(lp->col_no); + free(lp->col_end); + free(lp->row_end); + free(lp->orig_rh); + free(lp->rh); + free(lp->rhs); + free(lp->must_be_int); + free(lp->orig_upbo); + free(lp->orig_lowbo); + free(lp->upbo); + free(lp->lowbo); + free(lp->bas); + free(lp->basis); + free(lp->lower); + free(lp->eta_value); + free(lp->eta_row_nr); + free(lp->eta_col_end); + free(lp->solution); + free(lp->best_solution); + free(lp->duals); + free(lp->ch_sign); + if (lp->scaling_used) free(lp->scale); + if (lp->nr_lagrange > 0) { + free(lp->lag_rhs); + free(lp->lambda); + free(lp->lag_con_type); + for (i = 0; i < lp->nr_lagrange; i++) free(lp->lag_row[i]); + free(lp->lag_row); + } + + free(lp); + lp = NULL; +} + +lprec *copy_lp(lprec *lp) { + lprec *newlp; + int i, rowsplus, colsplus, sumplus; + + rowsplus = lp->rows_alloc + 1; + colsplus = lp->columns_alloc + 1; + sumplus = lp->sum_alloc + 1; + + MALLOCCPY(newlp, lp, 1, lprec); /* copy all non pointers */ + + newlp->active = FALSE; + + if (newlp->names_used) { + MALLOCCPY(newlp->col_name, lp->col_name, colsplus, nstring); + MALLOCCPY(newlp->row_name, lp->row_name, rowsplus, nstring); + } + + MALLOCCPY(newlp->mat, lp->mat, newlp->mat_alloc, matrec); + MALLOCCPY(newlp->col_end, lp->col_end, colsplus, int); + MALLOCCPY(newlp->col_no, lp->col_no, newlp->mat_alloc, int); + MALLOCCPY(newlp->row_end, lp->row_end, rowsplus, int); + MALLOCCPY(newlp->orig_rh, lp->orig_rh, rowsplus, REAL); + MALLOCCPY(newlp->rh, lp->rh, rowsplus, REAL); + MALLOCCPY(newlp->rhs, lp->rhs, rowsplus, REAL); + MALLOCCPY(newlp->must_be_int, lp->must_be_int, sumplus, short); + MALLOCCPY(newlp->orig_upbo, lp->orig_upbo, sumplus, REAL); + MALLOCCPY(newlp->orig_lowbo, lp->orig_lowbo, sumplus, REAL); + MALLOCCPY(newlp->upbo, lp->upbo, sumplus, REAL); + MALLOCCPY(newlp->lowbo, lp->lowbo, sumplus, REAL); + MALLOCCPY(newlp->bas, lp->bas, rowsplus, int); + MALLOCCPY(newlp->basis, lp->basis, sumplus, short); + MALLOCCPY(newlp->lower, lp->lower, sumplus, short); + MALLOCCPY(newlp->eta_value, lp->eta_value, lp->eta_alloc, REAL); + MALLOCCPY(newlp->eta_row_nr, lp->eta_row_nr, lp->eta_alloc, int); + MALLOCCPY(newlp->eta_col_end, lp->eta_col_end, lp->rows_alloc + lp->max_num_inv, int); + MALLOCCPY(newlp->solution, lp->solution, sumplus, REAL); + MALLOCCPY(newlp->best_solution, lp->best_solution, sumplus, REAL); + MALLOCCPY(newlp->duals, lp->duals, rowsplus, REAL); + MALLOCCPY(newlp->ch_sign, lp->ch_sign, rowsplus, short); + + if (newlp->scaling_used) MALLOCCPY(newlp->scale, lp->scale, sumplus, REAL); + + if (newlp->nr_lagrange > 0) { + MALLOCCPY(newlp->lag_rhs, lp->lag_rhs, newlp->nr_lagrange, REAL); + MALLOCCPY(newlp->lambda, lp->lambda, newlp->nr_lagrange, REAL); + MALLOCCPY(newlp->lag_con_type, lp->lag_con_type, newlp->nr_lagrange, short); + MALLOC(newlp->lag_row, newlp->nr_lagrange, REAL *); + for (i = 0; i < newlp->nr_lagrange; i++) + MALLOCCPY(newlp->lag_row[i], lp->lag_row[i], colsplus, REAL); + } + return (newlp); +} + +void inc_mat_space(lprec *lp, int maxextra) { + if (lp->non_zeros + maxextra >= lp->mat_alloc) { + lp->mat_alloc = lp->non_zeros + maxextra; + REALLOC(lp->mat, lp->mat_alloc, matrec); + REALLOC(lp->col_no, lp->mat_alloc, int); + if (lp->active) { + Mat = lp->mat; + Col_no = lp->col_no; + } + } +} + +void inc_row_space(lprec *lp) { + if (lp->rows > lp->rows_alloc) { + lp->rows_alloc = lp->rows + 10; + lp->sum_alloc = lp->rows_alloc + lp->columns_alloc; + REALLOC(lp->orig_rh, lp->rows_alloc + 1, REAL); + REALLOC(lp->rh, lp->rows_alloc + 1, REAL); + REALLOC(lp->rhs, lp->rows_alloc + 1, REAL); + REALLOC(lp->orig_upbo, lp->sum_alloc + 1, REAL); + REALLOC(lp->upbo, lp->sum_alloc + 1, REAL); + REALLOC(lp->orig_lowbo, lp->sum_alloc + 1, REAL); + REALLOC(lp->lowbo, lp->sum_alloc + 1, REAL); + REALLOC(lp->solution, lp->sum_alloc + 1, REAL); + REALLOC(lp->best_solution, lp->sum_alloc + 1, REAL); + REALLOC(lp->row_end, lp->rows_alloc + 1, int); + REALLOC(lp->basis, lp->sum_alloc + 1, short); + REALLOC(lp->lower, lp->sum_alloc + 1, short); + REALLOC(lp->must_be_int, lp->sum_alloc + 1, short); + REALLOC(lp->bas, lp->rows_alloc + 1, int); + REALLOC(lp->duals, lp->rows_alloc + 1, REAL); + REALLOC(lp->ch_sign, lp->rows_alloc + 1, short); + REALLOC(lp->eta_col_end, lp->rows_alloc + lp->max_num_inv, int); + if (lp->names_used) REALLOC(lp->row_name, lp->rows_alloc + 1, nstring); + if (lp->scaling_used) REALLOC(lp->scale, lp->sum_alloc + 1, REAL); + if (lp->active) set_globals(lp); + } +} + +void inc_col_space(lprec *lp) { + if (lp->columns >= lp->columns_alloc) { + lp->columns_alloc = lp->columns + 10; + lp->sum_alloc = lp->rows_alloc + lp->columns_alloc; + REALLOC(lp->must_be_int, lp->sum_alloc + 1, short); + REALLOC(lp->orig_upbo, lp->sum_alloc + 1, REAL); + REALLOC(lp->upbo, lp->sum_alloc + 1, REAL); + REALLOC(lp->orig_lowbo, lp->sum_alloc + 1, REAL); + REALLOC(lp->lowbo, lp->sum_alloc + 1, REAL); + REALLOC(lp->solution, lp->sum_alloc + 1, REAL); + REALLOC(lp->best_solution, lp->sum_alloc + 1, REAL); + REALLOC(lp->basis, lp->sum_alloc + 1, short); + REALLOC(lp->lower, lp->sum_alloc + 1, short); + if (lp->names_used) REALLOC(lp->col_name, lp->columns_alloc + 1, nstring); + if (lp->scaling_used) REALLOC(lp->scale, lp->sum_alloc + 1, REAL); + REALLOC(lp->col_end, lp->columns_alloc + 1, int); + if (lp->active) set_globals(lp); + } +} + +void set_mat(lprec *lp, int Row, int Column, REAL Value) { + int elmnr, lastelm, i; + + if (Row > lp->rows || Row < 0) error("Row out of range"); + if (Column > lp->columns || Column < 1) error("Column out of range"); + if (lp->scaling_used) Value *= lp->scale[Row] * lp->scale[lp->rows + Column]; + + if (TRUE /*abs(Value) > lp->epsilon*/) { + if (lp->basis[Column] == TRUE && Row > 0) lp->basis_valid = FALSE; + lp->eta_valid = FALSE; + elmnr = lp->col_end[Column - 1]; + while ((elmnr < lp->col_end[Column]) ? (lp->mat[elmnr].row_nr != Row) : FALSE) elmnr++; + + if ((elmnr != lp->col_end[Column]) ? (lp->mat[elmnr].row_nr == Row) : FALSE) + if (lp->scaling_used) { + if (lp->ch_sign[Row]) + lp->mat[elmnr].value = -Value * lp->scale[Row] * lp->scale[Column]; + else + lp->mat[elmnr].value = Value * lp->scale[Row] * lp->scale[Column]; + } else { + if (lp->ch_sign[Row]) + lp->mat[elmnr].value = -Value; + else + lp->mat[elmnr].value = Value; + } + else { + /* check if more space is needed for matrix */ + inc_mat_space(lp, 1); + + /* Shift the matrix */ + lastelm = lp->non_zeros; + for (i = lastelm; i > elmnr; i--) lp->mat[i] = lp->mat[i - 1]; + for (i = Column; i <= lp->columns; i++) lp->col_end[i]++; + + /* Set new element */ + lp->mat[elmnr].row_nr = Row; + + if (lp->scaling_used) { + if (lp->ch_sign[Row]) + lp->mat[elmnr].value = -Value * lp->scale[Row] * lp->scale[Column]; + else + lp->mat[elmnr].value = Value * lp->scale[Row] * lp->scale[Column]; + } else { + if (lp->ch_sign[Row]) + lp->mat[elmnr].value = -Value; + else + lp->mat[elmnr].value = Value; + } + + lp->row_end_valid = FALSE; + + lp->non_zeros++; + if (lp->active) Non_zeros = lp->non_zeros; + } + } +} + +void set_obj_fn(lprec *lp, REAL *row) { + int i; + for (i = 1; i <= lp->columns; i++) set_mat(lp, 0, i, row[i]); +} + +void str_set_obj_fn(lprec *lp, char *row) { + int i; + REAL *arow; + char *p, *newp; + CALLOC(arow, lp->columns + 1, REAL); + p = row; + for (i = 1; i <= lp->columns; i++) { + arow[i] = (REAL)strtod(p, &newp); + if (p == newp) + error("Bad string in str_set_obj_fn"); + else + p = newp; + } + set_obj_fn(lp, arow); + free(arow); +} + +void add_constraint(lprec *lp, REAL *row, short constr_type, REAL rh) { + matrec *newmat; + int i, j; + int elmnr; + int stcol; + int *addtoo; + int *num, *rownum, row_nr; + REAL theta; + + MALLOC(addtoo, lp->columns + 1, int) + + for (i = 1; i <= lp->columns; i++) + if (row[i] != 0) { + addtoo[i] = TRUE; + lp->non_zeros++; + } else + addtoo[i] = FALSE; + + MALLOC(newmat, lp->non_zeros, matrec); + inc_mat_space(lp, 0); + lp->rows++; + lp->sum++; + inc_row_space(lp); + + if (lp->scaling_used) { + /* shift scale */ + for (i = lp->sum; i > lp->rows; i--) lp->scale[i] = lp->scale[i - 1]; + lp->scale[lp->rows] = 1; + } + + if (lp->names_used) sprintf(lp->row_name[lp->rows], "r_%d", lp->rows); + + if (lp->scaling_used && lp->columns_scaled) + for (i = 1; i <= lp->columns; i++) row[i] *= lp->scale[lp->rows + i]; + + if (constr_type == GE) + lp->ch_sign[lp->rows] = TRUE; + else + lp->ch_sign[lp->rows] = FALSE; + + elmnr = 0; + stcol = 0; + for (i = 1; i <= lp->columns; i++) { + for (j = stcol; j < lp->col_end[i]; j++) { + newmat[elmnr].row_nr = lp->mat[j].row_nr; + newmat[elmnr].value = lp->mat[j].value; + elmnr++; + } + if (addtoo[i]) { + if (lp->ch_sign[lp->rows]) + newmat[elmnr].value = -row[i]; + else + newmat[elmnr].value = row[i]; + newmat[elmnr].row_nr = lp->rows; + elmnr++; + } + stcol = lp->col_end[i]; + lp->col_end[i] = elmnr; + } + + memcpy(lp->mat, newmat, lp->non_zeros * sizeof(matrec)); + + free(newmat); + free(addtoo); + + for (i = lp->sum; i > lp->rows; i--) { + lp->orig_upbo[i] = lp->orig_upbo[i - 1]; + lp->orig_lowbo[i] = lp->orig_lowbo[i - 1]; + lp->basis[i] = lp->basis[i - 1]; + lp->lower[i] = lp->lower[i - 1]; + lp->must_be_int[i] = lp->must_be_int[i - 1]; + } + + for (i = 1; i <= lp->rows; i++) + if (lp->bas[i] >= lp->rows) lp->bas[i]++; + + if (constr_type == LE || constr_type == GE) { + lp->orig_upbo[lp->rows] = lp->infinite; + } else if (constr_type == EQ) { + lp->orig_upbo[lp->rows] = 0; + } else { + fprintf(stderr, "Wrong constraint type\n"); + exit(FAIL); + } + + lp->orig_lowbo[lp->rows] = 0; + + if (constr_type == GE && rh != 0) + lp->orig_rh[lp->rows] = -rh; + else + lp->orig_rh[lp->rows] = rh; + + lp->row_end_valid = FALSE; + + lp->bas[lp->rows] = lp->rows; + lp->basis[lp->rows] = TRUE; + lp->lower[lp->rows] = TRUE; + + if (lp->active) set_globals(lp); + lp->eta_valid = FALSE; +} + +void str_add_constraint(lprec *lp, char *row_string, short constr_type, REAL rh) { + int i; + REAL *aRow; + char *p, *newp; + CALLOC(aRow, lp->columns + 1, REAL); + p = row_string; + + for (i = 1; i <= lp->columns; i++) { + aRow[i] = (REAL)strtod(p, &newp); + if (p == newp) + error("Bad string in str_add_constr"); + else + p = newp; + } + add_constraint(lp, aRow, constr_type, rh); + free(aRow); +} + +void del_constraint(lprec *lp, int del_row) { + int i, j; + unsigned elmnr; + int startcol; + int row_nr; + + if (del_row < 1 || del_row > lp->rows) { + fprintf(stderr, "There is no constraint nr. %d\n", del_row); + exit(FAIL); + } + + elmnr = 0; + startcol = 0; + + for (i = 1; i <= lp->columns; i++) { + for (j = startcol; j < lp->col_end[i]; j++) { + if (lp->mat[j].row_nr != del_row) { + lp->mat[elmnr] = lp->mat[j]; + if (lp->mat[elmnr].row_nr > del_row) lp->mat[elmnr].row_nr--; + elmnr++; + } else + lp->non_zeros--; + } + startcol = lp->col_end[i]; + lp->col_end[i] = elmnr; + } + for (i = del_row; i < lp->rows; i++) { + lp->orig_rh[i] = lp->orig_rh[i + 1]; + lp->ch_sign[i] = lp->ch_sign[i + 1]; + lp->bas[i] = lp->bas[i + 1]; + if (lp->names_used) strcpy(lp->row_name[i], lp->row_name[i + 1]); + } + for (i = 1; i < lp->rows; i++) + if (lp->bas[i] > del_row) lp->bas[i]--; + + for (i = del_row; i < lp->sum; i++) { + lp->lower[i] = lp->lower[i + 1]; + lp->basis[i] = lp->basis[i + 1]; + lp->orig_upbo[i] = lp->orig_upbo[i + 1]; + lp->orig_lowbo[i] = lp->orig_lowbo[i + 1]; + lp->must_be_int[i] = lp->must_be_int[i + 1]; + if (lp->scaling_used) lp->scale[i] = lp->scale[i + 1]; + } + + lp->rows--; + lp->sum--; + + lp->row_end_valid = FALSE; + + if (lp->active) set_globals(lp); + lp->eta_valid = FALSE; + lp->basis_valid = FALSE; +} + +void add_lag_con(lprec *lp, REAL *row, short con_type, REAL rhs) { + int i; + REAL sign; + if (con_type == LE || con_type == EQ) + sign = 1; + else if (con_type == GE) + sign = -1; + else + error("con_type not implemented\n"); + + lp->nr_lagrange++; + if (lp->nr_lagrange == 1) { + CALLOC(lp->lag_row, lp->nr_lagrange, REAL *); + CALLOC(lp->lag_rhs, lp->nr_lagrange, REAL); + CALLOC(lp->lambda, lp->nr_lagrange, REAL); + CALLOC(lp->lag_con_type, lp->nr_lagrange, short); + } else { + REALLOC(lp->lag_row, lp->nr_lagrange, REAL *); + REALLOC(lp->lag_rhs, lp->nr_lagrange, REAL); + REALLOC(lp->lambda, lp->nr_lagrange, REAL); + REALLOC(lp->lag_con_type, lp->nr_lagrange, short); + } + CALLOC(lp->lag_row[lp->nr_lagrange - 1], lp->columns + 1, REAL); + lp->lag_rhs[lp->nr_lagrange - 1] = rhs * sign; + for (i = 1; i <= lp->columns; i++) lp->lag_row[lp->nr_lagrange - 1][i] = row[i] * sign; + lp->lambda[lp->nr_lagrange - 1] = 0; + lp->lag_con_type[lp->nr_lagrange - 1] = (con_type == EQ); +} + +void str_add_lag_con(lprec *lp, char *row, short con_type, REAL rhs) { + int i; + REAL *a_row; + char *p, *new_p; + CALLOC(a_row, lp->columns + 1, REAL); + p = row; + + for (i = 1; i <= lp->columns; i++) { + a_row[i] = (REAL)strtod(p, &new_p); + if (p == new_p) + error("Bad string in str_add_lag_con"); + else + p = new_p; + } + add_lag_con(lp, a_row, con_type, rhs); + free(a_row); +} + +void add_column(lprec *lp, REAL *column) { + int i, j, elmnr, row_nr, *num, *rownum; + + lp->columns++; + lp->sum++; + inc_col_space(lp); + inc_mat_space(lp, lp->rows + 1); + + if (lp->scaling_used) { + for (i = 0; i <= lp->rows; i++) column[i] *= lp->scale[i]; + lp->scale[lp->sum] = 1; + } + + elmnr = lp->col_end[lp->columns - 1]; + for (i = 0; i <= lp->rows; i++) + if (column[i] != 0) { + lp->mat[elmnr].row_nr = i; + if (lp->ch_sign[i]) + lp->mat[elmnr].value = -column[i]; + else + lp->mat[elmnr].value = column[i]; + lp->non_zeros++; + elmnr++; + } + lp->col_end[lp->columns] = elmnr; + lp->orig_lowbo[lp->sum] = 0; + lp->orig_upbo[lp->sum] = lp->infinite; + lp->lower[lp->sum] = TRUE; + lp->basis[lp->sum] = FALSE; + lp->must_be_int[lp->sum] = FALSE; + if (lp->names_used) sprintf(lp->col_name[lp->columns], "var_%d", lp->columns); + + lp->row_end_valid = FALSE; + + if (lp->active) { + Sum = lp->sum; + Columns = lp->columns; + Non_zeros = lp->non_zeros; + } +} + +void str_add_column(lprec *lp, char *col_string) { + int i; + REAL *aCol; + char *p, *newp; + CALLOC(aCol, lp->rows + 1, REAL); + p = col_string; + + for (i = 0; i <= lp->rows; i++) { + aCol[i] = (REAL)strtod(p, &newp); + if (p == newp) + error("Bad string in str_add_column"); + else + p = newp; + } + add_column(lp, aCol); + free(aCol); +} + +void del_column(lprec *lp, int column) { + int i, j, from_elm, to_elm, elm_in_col; + if (column > lp->columns || column < 1) error("Column out of range in del_column"); + for (i = 1; i <= lp->rows; i++) { + if (lp->bas[i] == lp->rows + column) + lp->basis_valid = FALSE; + else if (lp->bas[i] > lp->rows + column) + lp->bas[i]--; + } + for (i = lp->rows + column; i < lp->sum; i++) { + if (lp->names_used) strcpy(lp->col_name[i - lp->rows], lp->col_name[i - lp->rows + 1]); + lp->must_be_int[i] = lp->must_be_int[i + 1]; + lp->orig_upbo[i] = lp->orig_upbo[i + 1]; + lp->orig_lowbo[i] = lp->orig_lowbo[i + 1]; + lp->upbo[i] = lp->upbo[i + 1]; + lp->lowbo[i] = lp->lowbo[i + 1]; + lp->basis[i] = lp->basis[i + 1]; + lp->lower[i] = lp->lower[i + 1]; + if (lp->scaling_used) lp->scale[i] = lp->scale[i + 1]; + } + for (i = 0; i < lp->nr_lagrange; i++) + for (j = column; j <= lp->columns; j++) lp->lag_row[i][j] = lp->lag_row[i][j + 1]; + to_elm = lp->col_end[column - 1]; + from_elm = lp->col_end[column]; + elm_in_col = from_elm - to_elm; + for (i = from_elm; i < lp->non_zeros; i++) { + lp->mat[to_elm] = lp->mat[i]; + to_elm++; + } + for (i = column; i < lp->columns; i++) lp->col_end[i] = lp->col_end[i + 1] - elm_in_col; + lp->non_zeros -= elm_in_col; + lp->row_end_valid = FALSE; + lp->eta_valid = FALSE; + + lp->sum--; + lp->columns--; + if (lp->active) set_globals(lp); +} + +void set_upbo(lprec *lp, int column, REAL value) { + if (column > lp->columns || column < 1) error("Column out of range"); + if (lp->scaling_used) value /= lp->scale[lp->rows + column]; + if (value < lp->orig_lowbo[lp->rows + column]) error("Upperbound must be >= lowerbound"); + lp->eta_valid = FALSE; + lp->orig_upbo[lp->rows + column] = value; +} + +void set_lowbo(lprec *lp, int column, REAL value) { + if (column > lp->columns || column < 1) error("Column out of range"); + if (lp->scaling_used) value /= lp->scale[lp->rows + column]; + if (value > lp->orig_upbo[lp->rows + column]) error("Upperbound must be >= lowerbound"); + lp->eta_valid = FALSE; + lp->orig_lowbo[lp->rows + column] = value; +} + +void set_int(lprec *lp, int column, short must_be_int) { + if (column > lp->columns || column < 1) error("Column out of range"); + lp->must_be_int[lp->rows + column] = must_be_int; + if (must_be_int == TRUE) + if (lp->columns_scaled) unscale_columns(lp); +} + +void set_rh(lprec *lp, int row, REAL value) { + if (row > lp->rows || row < 0) error("Row out of Range"); + if (row == 0) /* setting of RHS of OF not meaningful */ + { + fprintf(stderr, "Warning: attempt to set RHS of objective function, ignored\n"); + return; + } + if (lp->scaling_used) + if (lp->ch_sign[row]) + lp->orig_rh[row] = -value * lp->scale[row]; + else + lp->orig_rh[row] = value * lp->scale[row]; + else if (lp->ch_sign[row]) + lp->orig_rh[row] = -value; + else + lp->orig_rh[row] = value; + lp->eta_valid = FALSE; +} + +void set_rh_vec(lprec *lp, REAL *rh) { + int i; + if (lp->scaling_used) + for (i = 1; i <= lp->rows; i++) + if (lp->ch_sign[i]) + lp->orig_rh[i] = -rh[i] * lp->scale[i]; + else + lp->orig_rh[i] = rh[i] * lp->scale[i]; + else + for (i = 1; i <= lp->rows; i++) + if (lp->ch_sign[i]) + lp->orig_rh[i] = -rh[i]; + else + lp->orig_rh[i] = rh[i]; + lp->eta_valid = FALSE; +} + +void str_set_rh_vec(lprec *lp, char *rh_string) { + int i; + REAL *newrh; + char *p, *newp; + CALLOC(newrh, lp->rows + 1, REAL); + p = rh_string; + + for (i = 1; i <= lp->rows; i++) { + newrh[i] = (REAL)strtod(p, &newp); + if (p == newp) + error("Bad string in str_set_rh_vec"); + else + p = newp; + } + set_rh_vec(lp, newrh); + free(newrh); +} + +void set_maxim(lprec *lp) { + int i; + if (lp->maximise == FALSE) { + for (i = 0; i < lp->non_zeros; i++) + if (lp->mat[i].row_nr == 0) lp->mat[i].value *= -1; + lp->eta_valid = FALSE; + } + lp->maximise = TRUE; + lp->ch_sign[0] = TRUE; + if (lp->active) Maximise = TRUE; +} + +void set_minim(lprec *lp) { + int i; + if (lp->maximise == TRUE) { + for (i = 0; i < lp->non_zeros; i++) + if (lp->mat[i].row_nr == 0) lp->mat[i].value = -lp->mat[i].value; + lp->eta_valid = FALSE; + } + lp->maximise = FALSE; + lp->ch_sign[0] = FALSE; + if (lp->active) Maximise = FALSE; +} + +void set_constr_type(lprec *lp, int row, short con_type) { + int i; + if (row > lp->rows || row < 1) error("Row out of Range"); + if (con_type == EQ) { + lp->orig_upbo[row] = 0; + lp->basis_valid = FALSE; + if (lp->ch_sign[row]) { + for (i = 0; i < lp->non_zeros; i++) + if (lp->mat[i].row_nr == row) lp->mat[i].value *= -1; + lp->eta_valid = FALSE; + lp->ch_sign[row] = FALSE; + if (lp->orig_rh[row] != 0) lp->orig_rh[row] *= -1; + } + } else if (con_type == LE) { + lp->orig_upbo[row] = lp->infinite; + lp->basis_valid = FALSE; + if (lp->ch_sign[row]) { + for (i = 0; i < lp->non_zeros; i++) + if (lp->mat[i].row_nr == row) lp->mat[i].value *= -1; + lp->eta_valid = FALSE; + lp->ch_sign[row] = FALSE; + if (lp->orig_rh[row] != 0) lp->orig_rh[row] *= -1; + } + } else if (con_type == GE) { + lp->orig_upbo[row] = lp->infinite; + lp->basis_valid = FALSE; + if (!lp->ch_sign[row]) { + for (i = 0; i < lp->non_zeros; i++) + if (lp->mat[i].row_nr == row) lp->mat[i].value *= -1; + lp->eta_valid = FALSE; + lp->ch_sign[row] = TRUE; + if (lp->orig_rh[row] != 0) lp->orig_rh[row] *= -1; + } + } else + error("Constraint type not (yet) implemented"); +} + +REAL mat_elm(lprec *lp, int row, int column) { + REAL value; + int elmnr; + if (row < 0 || row > lp->rows) error("Row out of range in mat_elm"); + if (column < 1 || column > lp->columns) error("Column out of range in mat_elm"); + value = 0; + elmnr = lp->col_end[column - 1]; + while (lp->mat[elmnr].row_nr != row && elmnr < lp->col_end[column]) elmnr++; + if (elmnr != lp->col_end[column]) { + value = lp->mat[elmnr].value; + if (lp->ch_sign[row]) value = -value; + if (lp->scaling_used) value /= lp->scale[row] * lp->scale[lp->rows + column]; + } + return (value); +} + +void get_row(lprec *lp, int row_nr, REAL *row) { + int i, j; + REAL RowMult; + if (row_nr < 0 || row_nr > lp->rows) error("Row nr. out of range in get_row"); + for (i = 1; i <= lp->columns; i++) { + row[i] = 0; + for (j = lp->col_end[i - 1]; j < lp->col_end[i]; j++) + if (lp->mat[j].row_nr == row_nr) row[i] = lp->mat[j].value; + if (lp->scaling_used) row[i] /= lp->scale[lp->rows + i] * lp->scale[row_nr]; + } + if (lp->ch_sign[row_nr]) + for (i = 0; i <= lp->columns; i++) + if (row[i] != 0) row[i] = -row[i]; +} + +void get_column(lprec *lp, int col_nr, REAL *column) { + int i; + + if (col_nr < 1 || col_nr > lp->columns) error("Col. nr. out of range in get_column"); + for (i = 0; i <= lp->rows; i++) column[i] = 0; + for (i = lp->col_end[col_nr - 1]; i < lp->col_end[col_nr]; i++) + column[lp->mat[i].row_nr] = lp->mat[i].value; + for (i = 0; i <= lp->rows; i++) + if (column[i] != 0) { + if (lp->ch_sign[i]) column[i] *= -1; + if (lp->scaling_used) column[i] /= (lp->scale[i] * lp->scale[lp->rows + col_nr]); + } +} + +void get_reduced_costs(lprec *lp, REAL *rc) { + int varnr, i, j; + REAL f; + + if (!lp->basis_valid) error("Not a valid basis in get_reduced_costs"); + set_globals(lp); + if (!lp->eta_valid) invert(); + for (i = 1; i <= lp->sum; i++) rc[i] = 0; + rc[0] = 1; + btran(rc); + for (i = 1; i <= lp->columns; i++) { + varnr = lp->rows + i; + if (!Basis[varnr]) + if (Upbo[varnr] > 0) { + f = 0; + for (j = Col_end[i - 1]; j < Col_end[i]; j++) f += rc[Mat[j].row_nr] * Mat[j].value; + rc[varnr] = f; + } + } + for (i = 1; i <= Sum; i++) my_round(rc[i], Epsd); +} + +short is_feasible(lprec *lp, REAL *values) { + int i, elmnr; + REAL *this_rhs; + REAL dist; + + if (lp->scaling_used) { + for (i = lp->rows + 1; i <= lp->sum; i++) + if (values[i - lp->rows] < lp->orig_lowbo[i] * lp->scale[i] || + values[i - lp->rows] > lp->orig_upbo[i] * lp->scale[i]) + return (FALSE); + } else { + for (i = lp->rows + 1; i <= lp->sum; i++) + if (values[i - lp->rows] < lp->orig_lowbo[i] || values[i - lp->rows] > lp->orig_upbo[i]) + return (FALSE); + } + CALLOC(this_rhs, lp->rows + 1, REAL) + for (i = 1; i <= lp->columns; i++) + for (elmnr = lp->col_end[i - 1]; elmnr < lp->col_end[i]; elmnr++) + this_rhs[lp->mat[elmnr].row_nr] += lp->mat[elmnr].value * values[i]; + for (i = 1; i <= lp->rows; i++) { + dist = lp->orig_rh[i] - this_rhs[i]; + my_round(dist, 0.001) if ((lp->orig_upbo[i] == 0 && dist != 0) || dist < 0) { + free(this_rhs); + return (FALSE); + } + } + free(this_rhs); + return (TRUE); +} + +short column_in_lp(lprec *lp, REAL *testcolumn) { + int i, j; + short ident; + REAL value; + + if (lp->scaling_used) + for (i = 1; i <= lp->columns; i++) { + ident = TRUE; + j = lp->col_end[i - 1]; + while (ident && (j < lp->col_end[i])) { + value = lp->mat[j].value; + if (lp->ch_sign[lp->mat[j].row_nr]) value = -value; + value /= lp->scale[lp->rows + i]; + value /= lp->scale[lp->mat[j].row_nr]; + value -= testcolumn[lp->mat[j].row_nr]; + if (my_abs(value) > 0.001) /* should be some epsilon? MB */ + ident = FALSE; + j++; + } + if (ident) return (TRUE); + } + else + for (i = 1; i <= lp->columns; i++) { + ident = TRUE; + j = lp->col_end[i - 1]; + while (ident && j < lp->col_end[i]) { + value = lp->mat[j].value; + if (lp->ch_sign[lp->mat[j].row_nr]) value *= -1; + value -= testcolumn[lp->mat[j].row_nr]; + if (my_abs(value) > 0.001) ident = FALSE; + j++; + } + if (ident) return (TRUE); + } + return (FALSE); +} + +void print_lp(lprec *lp) { + int i, j; + REAL *fatmat; + CALLOC(fatmat, (lp->rows + 1) * lp->columns, REAL); + for (i = 1; i <= lp->columns; i++) + for (j = lp->col_end[i - 1]; j < lp->col_end[i]; j++) + fatmat[(i - 1) * (lp->rows + 1) + lp->mat[j].row_nr] = lp->mat[j].value; + + printf("problem name: %s\n", lp->lp_name); + printf(" "); + for (j = 1; j <= lp->columns; j++) + if (lp->names_used) + printf("%8s ", lp->col_name[j]); + else + printf("Var[%3d] ", j); + if (lp->maximise) { + printf("\nMaximise "); + for (j = 0; j < lp->columns; j++) printf("% 8.2f ", -fatmat[j * (lp->rows + 1)]); + } else { + printf("\nMinimize "); + for (j = 0; j < lp->columns; j++) printf("% 8.2f ", fatmat[j * (lp->rows + 1)]); + } + printf("\n"); + for (i = 1; i <= lp->rows; i++) { + if (lp->names_used) + printf("%9s ", lp->row_name[i]); + else + printf("Row[%3d] ", i); + for (j = 0; j < lp->columns; j++) + if (lp->ch_sign[i] && fatmat[j * (lp->rows + 1) + i] != 0) + printf("% 8.2f ", -fatmat[j * (lp->rows + 1) + i]); + else + printf("% 8.2f ", fatmat[j * (lp->rows + 1) + i]); + if (lp->orig_upbo[i] == lp->infinite) + if (lp->ch_sign[i]) + printf(">= "); + else + printf("<= "); + else + printf(" = "); + if (lp->ch_sign[i]) + printf("% 8.2f\n", -lp->orig_rh[i]); + else + printf("% 8.2f\n", lp->orig_rh[i]); + } + printf("Type "); + for (i = 1; i <= lp->columns; i++) + if (lp->must_be_int[lp->rows + i] == TRUE) + printf(" Int "); + else + printf(" Real "); + printf("\nupbo "); + for (i = 1; i <= lp->columns; i++) + if (lp->orig_upbo[lp->rows + i] == lp->infinite) + printf(" Inf "); + else + printf("% 8.2f ", lp->orig_upbo[lp->rows + i]); + printf("\nlowbo "); + for (i = 1; i <= lp->columns; i++) printf("% 8.2f ", lp->orig_lowbo[lp->rows + i]); + printf("\n"); + for (i = 0; i < lp->nr_lagrange; i++) { + printf("lag[%3d] ", i); + for (j = 1; j <= lp->columns; j++) printf("% 8.2f ", lp->lag_row[i][j]); + if (lp->orig_upbo[i] == lp->infinite) + if (lp->lag_con_type[i] == GE) + printf(">= "); + else if (lp->lag_con_type[i] == LE) + printf("<= "); + else if (lp->lag_con_type[i] == EQ) + printf(" = "); + printf("% 8.2f\n", lp->lag_rhs[i]); + } + + free(fatmat); +} + +void set_row_name(lprec *lp, int row, nstring new_name) { + int i; + + if (!lp->names_used) { + CALLOC(lp->row_name, lp->rows_alloc + 1, nstring); + CALLOC(lp->col_name, lp->columns_alloc + 1, nstring); + lp->names_used = TRUE; + for (i = 0; i <= lp->rows; i++) sprintf(lp->row_name[i], "r_%d", i); + for (i = 1; i <= lp->columns; i++) sprintf(lp->col_name[i], "var_%d", i); + } + strcpy(lp->row_name[row], new_name); +} + +void set_col_name(lprec *lp, int column, nstring new_name) { + int i; + + if (!lp->names_used) { + CALLOC(lp->row_name, lp->rows_alloc + 1, nstring); + CALLOC(lp->col_name, lp->columns_alloc + 1, nstring); + lp->names_used = TRUE; + for (i = 0; i <= lp->rows; i++) sprintf(lp->row_name[i], "r_%d", i); + for (i = 1; i <= lp->columns; i++) sprintf(lp->col_name[i], "var_%d", i); + } + strcpy(lp->col_name[column], new_name); +} + +static REAL minmax_to_scale(REAL min, REAL max) { + REAL scale; + + /* should do something sensible when min or max is 0, MB */ + if ((min == 0) || (max == 0)) return ((REAL)1); + + scale = 1 / pow(10, (log10(min) + log10(max)) / 2); + return (scale); +} + +void unscale_columns(lprec *lp) { + int i, j; + + /* unscale mat */ + for (j = 1; j <= lp->columns; j++) + for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) + lp->mat[i].value /= lp->scale[lp->rows + j]; + + /* unscale bounds as well */ + for (i = lp->rows + 1; i < lp->sum; i++) { + if (lp->orig_lowbo[i] != 0) lp->orig_lowbo[i] *= lp->scale[i]; + if (lp->orig_upbo[i] != lp->infinite) lp->orig_upbo[i] *= lp->scale[i]; + } + + for (i = lp->rows + 1; i <= lp->sum; i++) lp->scale[i] = 1; + lp->columns_scaled = FALSE; + lp->eta_valid = FALSE; +} + +void unscale(lprec *lp) { + int i, j; + + if (lp->scaling_used) { + /* unscale mat */ + for (j = 1; j <= lp->columns; j++) + for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) + lp->mat[i].value /= lp->scale[lp->rows + j]; + + /* unscale bounds */ + for (i = lp->rows + 1; i < lp->sum; i++) { + if (lp->orig_lowbo[i] != 0) lp->orig_lowbo[i] *= lp->scale[i]; + if (lp->orig_upbo[i] != lp->infinite) lp->orig_upbo[i] *= lp->scale[i]; + } + + /* unscale the matrix */ + for (j = 1; j <= lp->columns; j++) + for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) + lp->mat[i].value /= lp->scale[lp->mat[i].row_nr]; + + /* unscale the rhs! */ + for (i = 0; i <= lp->rows; i++) lp->orig_rh[i] /= lp->scale[i]; + + free(lp->scale); + lp->scaling_used = FALSE; + lp->eta_valid = FALSE; + } +} + +void auto_scale(lprec *lp) { + int i, j, row_nr, IntUsed; + REAL *row_max, *row_min, *scalechange, absval; + REAL col_max, col_min, col_scale; + + if (!lp->scaling_used) { + MALLOC(lp->scale, lp->sum_alloc + 1, REAL); + for (i = 0; i <= lp->sum; i++) lp->scale[i] = 1; + } + MALLOC(row_max, lp->rows + 1, REAL); + MALLOC(row_min, lp->rows + 1, REAL); + MALLOC(scalechange, lp->sum + 1, REAL); + + /* initialise min and max values */ + for (i = 0; i <= lp->rows; i++) { + row_max[i] = 0; + row_min[i] = lp->infinite; + } + + /* calculate min and max absolute values of rows */ + for (j = 1; j <= lp->columns; j++) { + for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) { + row_nr = lp->mat[i].row_nr; + absval = my_abs(lp->mat[i].value); + if (absval != 0) { + row_max[row_nr] = my_max(row_max[row_nr], absval); + row_min[row_nr] = my_min(row_min[row_nr], absval); + } + } + } + /* calculate scale factors for rows */ + for (i = 0; i <= lp->rows; i++) { + scalechange[i] = minmax_to_scale(row_min[i], row_max[i]); + lp->scale[i] *= scalechange[i]; + } + + /* now actually scale the matrix */ + for (j = 1; j <= lp->columns; j++) + for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) + lp->mat[i].value *= scalechange[lp->mat[i].row_nr]; + + /* and scale the rhs! */ + for (i = 0; i <= lp->rows; i++) lp->orig_rh[i] *= scalechange[i]; + + free(row_max); + printf("after free r_max. "); + free(row_min); + printf("after free rmin. "); + + IntUsed = FALSE; + i = lp->rows + 1; + while (!IntUsed && i <= lp->sum) { + IntUsed = lp->must_be_int[i]; + i++; + } + if (!IntUsed) { + REAL col_max, col_min, col_scale; + + /* calculate scales */ + for (j = 1; j <= lp->columns; j++) { + col_max = 0; + col_min = lp->infinite; + for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) { + if (lp->mat[i].value != 0) { + col_max = my_max(col_max, my_abs(lp->mat[i].value)); + col_min = my_min(col_min, my_abs(lp->mat[i].value)); + } + } + scalechange[lp->rows + j] = minmax_to_scale(col_min, col_max); + lp->scale[lp->rows + j] *= scalechange[lp->rows + j]; + } + + /* scale mat */ + for (j = 1; j <= lp->columns; j++) + for (i = lp->col_end[j - 1]; i < lp->col_end[j]; i++) + lp->mat[i].value *= scalechange[lp->rows + j]; + + /* scale bounds as well */ + for (i = lp->rows + 1; i < lp->sum; i++) { + if (lp->orig_lowbo[i] != 0) lp->orig_lowbo[i] /= scalechange[i]; + if (lp->orig_upbo[i] != lp->infinite) lp->orig_upbo[i] /= scalechange[i]; + } + lp->columns_scaled = TRUE; + } + printf("b4 free scch. "); + free(scalechange); + printf("after free scch. "); + lp->scaling_used = TRUE; + lp->eta_valid = FALSE; +} + +void reset_basis(lprec *lp) { lp->basis_valid = FALSE; } + +void print_solution(lprec *lp) { + int i; + + fprintf(stdout, "Value of objective function: %16.10g\n", (double)lp->best_solution[0]); + + /* print normal variables */ + for (i = 1; i <= lp->columns; i++) + if (lp->names_used) + fprintf(stdout, "%-10s%16.5g\n", lp->col_name[i], (double)lp->best_solution[lp->rows + i]); + else + fprintf(stdout, "Var [%4d] %16.5g\n", i, (double)lp->best_solution[lp->rows + i]); + + /* print achieved constraint values */ + if (lp->verbose) { + fprintf(stdout, "\nActual values of the constraints:\n"); + for (i = 1; i <= lp->rows; i++) + if (lp->names_used) + fprintf(stdout, "%-10s%16.5g\n", lp->row_name[i], (double)lp->best_solution[i]); + else + fprintf(stdout, "%Row [%4d] %16.5g\n", i, (double)lp->best_solution[i]); + } + + if ((lp->verbose || lp->print_duals)) { + if (lp->max_level != 1) + fprintf(stdout, "These are the duals from the node that gave the optimal solution.\n"); + else + fprintf(stdout, "\nDual values:\n"); + for (i = 1; i <= lp->rows; i++) + if (lp->names_used) + fprintf(stdout, "%-10s%16.5g\n", lp->row_name[i], (double)lp->duals[i]); + else + fprintf(stdout, "Row [%4d] %16.5g\n", i, (double)lp->duals[i]); + } +} /* Printsolution */ + +void write_LP(lprec *lp, FILE *output) { + int i, j; + REAL *row; + nstring var_name; + + MALLOC(row, lp->columns + 1, REAL); + if (lp->maximise) + fprintf(output, "max:"); + else + fprintf(output, "min:"); + + get_row(lp, 0, row); + for (i = 1; i <= lp->columns; i++) + if (row[i] != 0) { + if (row[i] == -1) + fprintf(output, " -"); + else if (row[i] == 1) + fprintf(output, " +"); + else + fprintf(output, " %+g ", row[i]); + if (lp->names_used) + fprintf(output, "%s", lp->col_name[i]); + else + fprintf(output, "x%d", i); + } + fprintf(output, ";\n"); + + for (j = 1; j <= lp->rows; j++) { + if (lp->names_used) fprintf(output, "%s:", lp->row_name[j]); + get_row(lp, j, row); + for (i = 1; i <= lp->columns; i++) + if (row[i] != 0) { + if (row[i] == -1) + fprintf(output, " -"); + else if (row[i] == 1) + fprintf(output, " +"); + else + fprintf(output, " %+g ", row[i]); + if (lp->names_used) + fprintf(output, "%s", lp->col_name[i]); + else + fprintf(output, "x%d", i); + } + if (lp->orig_upbo[j] == 0) + fprintf(output, " ="); + else if (lp->ch_sign[j]) + fprintf(output, " >"); + else + fprintf(output, " <"); + if (lp->ch_sign[j]) + fprintf(output, " %g;\n", -lp->orig_rh[j]); + else + fprintf(output, " %g;\n", lp->orig_rh[j]); + } + for (i = lp->rows + 1; i <= lp->sum; i++) { + if (lp->orig_lowbo[i] != 0) { + if (lp->names_used) + fprintf(output, "%s > %g;\n", lp->col_name[i - lp->rows], lp->orig_lowbo[i]); + else + fprintf(output, "x%d > %g;\n", i - lp->rows, lp->orig_lowbo[i]); + } + if (lp->orig_upbo[i] != lp->infinite) { + if (lp->names_used) + fprintf(output, "%s < %g;\n", lp->col_name[i - lp->rows], lp->orig_upbo[i]); + else + fprintf(output, "x%d < %g;\n", i - lp->rows, lp->orig_upbo[i]); + } + } + + i = 1; + while (!lp->must_be_int[lp->rows + i] && i <= lp->columns) i++; + if (i <= lp->columns) { + if (lp->names_used) + fprintf(output, "\nint %s", lp->col_name[i]); + else + fprintf(output, "\nint x%d", i); + i++; + for (; i <= lp->columns; i++) + if (lp->must_be_int[lp->rows + i]) + if (lp->names_used) + fprintf(output, ",%s", lp->col_name[i]); + else + fprintf(output, ", x%d", i); + fprintf(output, ";\n"); + } + free(row); +} + +void write_MPS(lprec *lp, FILE *output) { + int i, j, marker; + REAL *column; + + MALLOC(column, lp->rows + 1, REAL); + marker = 0; + fprintf(output, "NAME %s\n", lp->lp_name); + fprintf(output, "ROWS\n"); + for (i = 0; i <= lp->rows; i++) { + if (i == 0) + fprintf(output, " N "); + else if (lp->orig_upbo[i] == lp->infinite) + if (lp->ch_sign[i]) + fprintf(output, " G "); + else + fprintf(output, " L "); + else + fprintf(output, " E "); + if (lp->names_used) + fprintf(output, "%s\n", lp->row_name[i]); + else + fprintf(output, "r_%d\n", i); + } + + fprintf(output, "COLUMNS\n"); + j = 0; + for (i = 1; i <= lp->columns; i++) { + if ((lp->must_be_int[i + lp->rows]) && (marker % 2) == 0) { + fprintf(output, " MARK%04d 'MARKER' 'INTORG'\n", marker); + marker++; + } + if ((!lp->must_be_int[i + lp->rows]) && (marker % 2) == 1) { + fprintf(output, " MARK%04d 'MARKER' 'INTEND'\n", marker); + marker++; + } + get_column(lp, i, column); + j = 0; + if (lp->maximise) { + if (column[j] != 0) { + if (lp->names_used) + fprintf(output, " %-8s %-8s %g\n", lp->col_name[i], lp->row_name[j], -column[j]); + else + fprintf(output, " var_%-4d r_%-6d %g\n", i, j, -column[j]); + } + } else { + if (column[j] != 0) { + if (lp->names_used) + fprintf(output, " %-8s %-8s %g\n", lp->col_name[i], lp->row_name[j], column[j]); + else + fprintf(output, " var_%-4d r_%-6d %g\n", i, j, column[j]); + } + } + for (j = 1; j <= lp->rows; j++) + if (column[j] != 0) { + if (lp->names_used) + fprintf(output, " %-8s %-8s %g\n", lp->col_name[i], lp->row_name[j], column[j]); + else + fprintf(output, " var_%-4d r_%-6d %g\n", i, j, column[j]); + } + } + if ((marker % 2) == 1) { + fprintf(output, " MARK%04d 'MARKER' 'INTEND'\n", marker); + marker++; + } + + fprintf(output, "RHS\n"); + for (i = 1; i <= lp->rows; i++) { + if (lp->ch_sign[i]) { + if (lp->names_used) + fprintf(output, " RHS %-8s %g\n", lp->row_name[i], (double)-lp->orig_rh[i]); + else + fprintf(output, " RHS r_%-6d %g\n", i, (double)-lp->orig_rh[i]); + } else { + if (lp->names_used) + fprintf(output, " RHS %-8s %g\n", lp->row_name[i], (double)lp->orig_rh[i]); + else + fprintf(output, " RHS r_%-6d %g\n", i, (double)lp->orig_rh[i]); + } + } + + fprintf(output, "BOUNDS\n"); + if (lp->names_used) + for (i = lp->rows + 1; i <= lp->sum; i++) { + if (lp->orig_upbo[i] < lp->infinite) + fprintf(output, " UP BND %-8s %g\n", lp->col_name[i - lp->rows], + (double)lp->orig_upbo[i]); + if (lp->orig_lowbo[i] != 0) + fprintf(output, " LO BND %-8s %g\n", lp->col_name[i - lp->rows], + (double)lp->orig_lowbo[i]); + } + else + for (i = lp->rows + 1; i <= lp->sum; i++) { + if (lp->orig_upbo[i] < lp->infinite) + fprintf(output, " UP BND var_%-4d %g\n", i - lp->rows, (double)lp->orig_upbo[i]); + if (lp->orig_lowbo[i] != 0) + fprintf(output, " LO BND var_%-4d %g\n", i - lp->rows, (double)lp->orig_lowbo[i]); + } + fprintf(output, "ENDATA\n"); + free(column); +} + +void print_duals(lprec *lp) { + int i; + for (i = 1; i <= lp->rows; i++) + if (lp->names_used) + fprintf(stdout, "%10s [%3d] % 10.4f\n", lp->row_name[i], i, lp->duals[i]); + else + fprintf(stdout, "Dual [%3d] % 10.4f\n", i, lp->duals[i]); +} + +void print_scales(lprec *lp) { + int i; + if (lp->scaling_used) { + for (i = 0; i <= lp->rows; i++) + fprintf(stdout, "Row[%3d] scaled at % 10.6f\n", i, lp->scale[i]); + for (i = 1; i <= lp->columns; i++) + fprintf(stdout, "Column[%3d] scaled at % 10.6f\n", i, lp->scale[lp->rows + i]); + } +} diff --git a/src/lplexyy.c b/src/lplexyy.c index 5d0d094..9eed1b6 100644 --- a/src/lplexyy.c +++ b/src/lplexyy.c @@ -1,659 +1,659 @@ -/* $Id: lplexyy.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved - */ -static char *id = "$Id: lplexyy.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $ Copyright (C) Venue"; - -/************************************************************************/ -/* */ -/* (C) Copyright 1989-95 Venue. All Rights Reserved. */ -/* Manufactured in the United States of America. */ -/* */ -/* The contents of this file are proprietary information */ -/* belonging to Venue, and are provided to you under license. */ -/* They may not be further distributed or disclosed to third */ -/* parties without the specific permission of Venue. */ -/* */ -/************************************************************************/ - -#include "version.h" - -#ifndef BIGATOMS -#include "stdio.h" -#define U(x) x -#define NLSTATE yyprevious = YYNEWLINE -#define BEGIN yybgin = yysvec + 1 + -#define INITIAL 0 -#define YYLERR yysvec -#define YYSTATE (yyestate - yysvec - 1) -#define YYOPTIM 1 -#define YYLMAX 200 -#define output(c) putc(c, yyout) -#define input() \ - (((yytchar = yysptr > yysbuf ? U(*--yysptr) : getc(yyin)) == 10 ? (yylineno++, yytchar) \ - : yytchar) == EOF \ - ? 0 \ - : yytchar) -#define unput(c) \ - { \ - yytchar = (c); \ - if (yytchar == '\n') yylineno--; \ - *yysptr++ = yytchar; \ - } -#define yymore() (yymorfg = 1) -#define ECHO fprintf(yyout, "%s", yytext) -#define REJECT \ - { \ - nstr = yyreject(); \ - goto yyfussy; \ - } -int yyleng; -extern char yytext[]; -int yymorfg; -extern char *yysptr, yysbuf[]; -int yytchar; -FILE *yyin = {stdin}, *yyout = {stdout}; -extern int yylineno; -struct yysvf { - struct yywork *yystoff; - struct yysvf *yyother; - int *yystops; -}; -struct yysvf *yyestate; -extern struct yysvf yysvec[], *yybgin; -extern int yylook(); -#ifdef __cplusplus -extern "C" { -#endif -#define yywrap() (1) -extern int yylex(); -extern int yyreject(); -extern int yyracc(int); -extern int yyless(int); -#ifdef __cplusplus -} -#endif -#define COMMENT 2 -#define YYNEWLINE 10 -yylex() { - int nstr; - extern int yyprevious; - while ((nstr = yylook()) >= 0) - yyfussy: - switch (nstr) { - case 0: - if (yywrap()) return (0); - break; - case 1: { - BEGIN COMMENT; - } break; - case 2: { - BEGIN INITIAL; - } break; - case 3: { - } break; - case 4: { - } break; - case 5: { - } break; - case 6: { - return (COMMA); - } break; - case 7: { - return (MINIMISE); - } break; - case 8: { - return (MAXIMISE); - } break; - case 9: { - sscanf((char *)yytext, "%lf", &f); - return (CONS); - } break; - case 10: { - Sign = 0; - for (x = 0; x < yyleng; x++) - if (yytext[x] == '-' || yytext[x] == '+') Sign = (Sign == (yytext[x] == '+')); - return (SIGN); - /* Sign is TRUE if the sign-string - represents a '-'. Otherwise Sign - is FALSE */ - } break; - case 11: { - strcpy(Last_var, (char *)yytext); - return (VAR); - } break; - case 12: { - return (COLON); - } break; - case 13: { - return (AR_M_OP); - } break; - case 14: { - return (RE_OP); - } break; - case 15: { - return (END_C); - } break; - case 16: { - fprintf(stderr, "LEX ERROR : %s lineno %d \n", yytext, yylineno); - } break; - case -1: break; - default: fprintf(yyout, "bad switch yylook %d", nstr); - } - return (0); -} -/* end of yylex */ -int yyvstop[] = {0, - - 14, 0, - - 14, 0, - - 14, 0, - - 14, 0, - - 16, 0, - - 5, 10, 16, 0, - - 5, 10, 0, - - 13, 16, 0, - - 10, 16, 0, - - 6, 16, 0, - - 16, 0, - - 16, 0, - - 9, 16, 0, - - 12, 16, 0, - - 15, 16, 0, - - 14, 16, 0, - - 14, 16, 0, - - 11, 16, 0, - - 11, 16, 0, - - 3, 0, - - 4, 0, - - 3, 0, - - 10, 0, - - 9, 0, - - 1, 0, - - 9, 0, - - 14, 0, - - 11, 0, - - 11, 0, - - 11, 0, - - 2, 0, - - 9, 0, - - 11, 0, - - 11, 0, - - 11, 0, - - 8, 0, - - 7, 0, 0}; -#define YYTYPE char -struct yywork { - YYTYPE verify, advance; -} yycrank[] = { - 0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 7, - 9, 23, 9, 23, 23, 23, 23, 23, 0, 0, 6, 7, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 23, - 1, 5, 23, 23, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 1, 8, 1, 9, 1, 10, 4, 22, 1, 11, - 1, 12, 1, 13, 12, 25, 6, 23, 2, 8, 6, 23, 2, 10, 22, 34, 2, 11, 2, 12, 0, 0, 1, 14, - 1, 15, 1, 16, 1, 17, 0, 0, 3, 20, 16, 29, 1, 18, 1, 18, 2, 14, 2, 15, 1, 18, 2, 17, - 3, 20, 3, 21, 1, 18, 24, 28, 0, 0, 0, 0, 1, 19, 1, 18, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 3, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 22, 3, 20, 24, 28, - 0, 0, 0, 0, 0, 0, 3, 20, 11, 24, 11, 24, 11, 24, 11, 24, 11, 24, 11, 24, 11, 24, 11, 24, - 11, 24, 11, 24, 0, 0, 3, 20, 0, 0, 0, 0, 0, 0, 0, 0, 3, 20, 3, 20, 0, 0, 0, 0, - 3, 20, 0, 0, 0, 0, 0, 0, 3, 20, 0, 0, 0, 0, 0, 0, 3, 20, 3, 20, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 26, 3, 20, 13, 27, 13, 27, 13, 27, 13, 27, - 13, 27, 13, 27, 13, 27, 13, 27, 13, 27, 13, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 28, 35, 0, 0, 28, 35, 0, 0, 13, 28, 28, 36, 28, 36, 28, 36, 28, 36, 28, 36, 28, 36, - 28, 36, 28, 36, 28, 36, 28, 36, 35, 36, 35, 36, 35, 36, 35, 36, 35, 36, 35, 36, 35, 36, 35, 36, - 35, 36, 35, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 13, 28, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, - 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, - 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, - 18, 30, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, - 0, 0, 18, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, - 18, 0, 18, 31, 18, 0, 18, 0, 18, 0, 0, 0, 18, 30, 18, 30, 0, 0, 0, 0, 18, 30, 0, 0, - 0, 0, 0, 0, 18, 30, 0, 0, 0, 0, 0, 0, 18, 30, 18, 30, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 30, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, - 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 18, 0, 19, 0, 19, 0, 19, 0, - 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, - 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, - 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 19, 0, 0, 0, 19, 0, 19, 0, 19, 0, - 0, 0, 19, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 33, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 19, 0, 0, 0, 0, 0, 19, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, - 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, - 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, - 30, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, - 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 30, 0, 30, 0, 0, 0, 30, 0, 30, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, - 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 30, 0, 31, 0, - 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, - 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, - 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 37, 0, 0, 0, 0, - 0, 0, 0, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 0, 0, 0, 0, 31, 37, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0, 31, 0, 31, 0, 31, 0, - 31, 0, 31, 0, 0, 0, 31, 37, 31, 37, 0, 0, 0, 0, 31, 37, 0, 0, 0, 0, 0, 0, 31, 37, - 0, 0, 0, 0, 0, 0, 31, 37, 31, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 31, 37, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 31, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, - 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, - 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, - 32, 0, 32, 0, 32, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 32, 0, 32, 0, - 32, 0, 32, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 32, 0, 32, 0, 0, 0, 32, 0, 32, 0, 32, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 38, 0, 0, 0, 0, - 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, - 32, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, - 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, - 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 33, 0, - 0, 0, 33, 0, 33, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, - 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 33, 0, 37, 0, 37, 0, 37, 0, 37, 0, - 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, - 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, - 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 0, - 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 40, 37, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 0, - 0, 0, 0, 0, 37, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, - 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, - 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, - 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 38, 41, 38, 0, 0, 0, 38, 0, 38, 0, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0, - 0, 0, 0, 0, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0, 0, 0, 38, 0, 39, 0, 39, 0, - 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, - 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, - 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 42, 39, 0, 0, 0, 39, 0, 39, 0, - 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 39, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -struct yysvf yysvec[] = {0, - 0, - 0, - yycrank + -1, - 0, - yyvstop + 1, - yycrank + -10, - yysvec + 1, - yyvstop + 3, - yycrank + -63, - 0, - yyvstop + 5, - yycrank + -4, - yysvec + 3, - yyvstop + 7, - yycrank + 0, - 0, - yyvstop + 9, - yycrank + 8, - 0, - yyvstop + 11, - yycrank + 0, - yysvec + 6, - yyvstop + 15, - yycrank + 0, - 0, - yyvstop + 18, - yycrank + 3, - yysvec + 6, - yyvstop + 21, - yycrank + 0, - 0, - yyvstop + 24, - yycrank + 64, - 0, - yyvstop + 27, - yycrank + 8, - 0, - yyvstop + 29, - yycrank + 104, - 0, - yyvstop + 31, - yycrank + 0, - 0, - yyvstop + 34, - yycrank + 0, - 0, - yyvstop + 37, - yycrank + 4, - 0, - yyvstop + 40, - yycrank + 0, - 0, - yyvstop + 43, - yycrank + -205, - 0, - yyvstop + 46, - yycrank + -332, - yysvec + 18, - yyvstop + 49, - yycrank + 0, - 0, - yyvstop + 52, - yycrank + 0, - 0, - yyvstop + 54, - yycrank + 8, - 0, - yyvstop + 56, - yycrank + 5, - yysvec + 6, - yyvstop + 58, - yycrank + 6, - yysvec + 11, - yyvstop + 60, - yycrank + 0, - 0, - yyvstop + 62, - yycrank + 0, - yysvec + 11, - 0, - yycrank + 0, - yysvec + 13, - yyvstop + 64, - yycrank + 126, - 0, - 0, - yycrank + 0, - 0, - yyvstop + 66, - yycrank + -459, - yysvec + 18, - yyvstop + 68, - yycrank + -586, - 0, - 0, - yycrank + -713, - yysvec + 18, - yyvstop + 70, - yycrank + -840, - yysvec + 18, - yyvstop + 72, - yycrank + 0, - 0, - yyvstop + 74, - yycrank + 136, - 0, - 0, - yycrank + 0, - yysvec + 35, - yyvstop + 76, - yycrank + -967, - yysvec + 31, - 0, - yycrank + -1094, - yysvec + 18, - yyvstop + 78, - yycrank + -1221, - yysvec + 18, - yyvstop + 80, - yycrank + 0, - 0, - yyvstop + 82, - yycrank + 0, - 0, - yyvstop + 84, - yycrank + 0, - 0, - yyvstop + 86, - 0, - 0, - 0}; -struct yywork *yytop = yycrank + 1348; -struct yysvf *yybgin = yysvec + 1; -char yymatch[] = { - 00, 01, 01, 01, 01, 01, 01, 01, 01, 011, 012, 01, 01, 01, 01, 01, 01, 01, 01, - 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 011, 01, 01, '#', '#', '#', - '#', '#', 01, 01, 01, '+', 01, '+', '#', '#', '0', '0', '0', '0', '0', '0', '0', '0', '0', - '0', 01, 01, '<', 01, '<', 01, '#', 'A', 'B', 'B', 'B', 'E', 'B', 'B', 'B', 'I', 'B', 'B', - 'B', 'M', 'N', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'X', 'B', 'B', '#', 01, '#', '#', - '#', 01, 'A', 'B', 'B', 'B', 'E', 'B', 'B', 'B', 'I', 'B', 'B', 'B', 'M', 'N', 'B', 'B', 'B', - 'B', 'B', 'B', 'B', 'B', 'B', 'X', 'B', 'B', '#', 01, '#', '#', 01, 0}; -char yyextra[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -#ident "$Header: /disk/disk3/cvsroot/medley/src/lplexyy.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $" -int yylineno = 1; -#define YYU(x) x -#define NLSTATE yyprevious = YYNEWLINE -char yytext[YYLMAX]; -struct yysvf *yylstate[YYLMAX], **yylsp, **yyolsp; -char yysbuf[YYLMAX]; -char *yysptr = yysbuf; -int *yyfnd; -extern struct yysvf *yyestate; -int yyprevious = YYNEWLINE; -int yyback(int *p, int m) { - if (p == 0) return (0); - while (*p) { - if (*p++ == m) return (1); - } - return (0); -} -/* the following are only used in the lex library */ -int yyinput() { return (input()); } -void yyoutput(int c) { output(c); } -void yyunput(int c) { unput(c); } - -int yylook() { - register struct yysvf *yystate, **lsp; - register struct yywork *yyt; - struct yysvf *yyz; - int yych, yyfirst; - struct yywork *yyr; -#ifdef LEXDEBUG - int debug; -#endif - char *yylastch; -/* start off machines */ -#ifdef LEXDEBUG - debug = 0; -#endif - yyfirst = 1; - if (!yymorfg) - yylastch = yytext; - else { - yymorfg = 0; - yylastch = yytext + yyleng; - } - for (;;) { - lsp = yylstate; - yyestate = yystate = yybgin; - if (yyprevious == YYNEWLINE) yystate++; - for (;;) { -#ifdef LEXDEBUG - if (debug) fprintf(yyout, "state %d\n", yystate - yysvec - 1); -#endif - yyt = yystate->yystoff; - if (yyt == yycrank && !yyfirst) { /* may not be any transitions */ - yyz = yystate->yyother; - if (yyz == 0) break; - if (yyz->yystoff == yycrank) break; - } - *yylastch++ = yych = input(); - yyfirst = 0; - tryagain: -#ifdef LEXDEBUG - if (debug) { - fprintf(yyout, "char "); - allprint(yych); - putchar('\n'); - } -#endif - yyr = yyt; - if ((int)yyt > (int)yycrank) { - yyt = yyr + yych; - if (yyt <= yytop && yyt->verify + yysvec == yystate) { - if (yyt->advance + yysvec == YYLERR) /* error transitions */ - { - unput(*--yylastch); - break; - } - *lsp++ = yystate = yyt->advance + yysvec; - goto contin; - } - } -#ifdef YYOPTIM - else if ((int)yyt < (int)yycrank) { /* r < yycrank */ - yyt = yyr = yycrank + (yycrank - yyt); -#ifdef LEXDEBUG - if (debug) fprintf(yyout, "compressed state\n"); -#endif - yyt = yyt + yych; - if (yyt <= yytop && yyt->verify + yysvec == yystate) { - if (yyt->advance + yysvec == YYLERR) /* error transitions */ - { - unput(*--yylastch); - break; - } - *lsp++ = yystate = yyt->advance + yysvec; - goto contin; - } - yyt = yyr + YYU(yymatch[yych]); -#ifdef LEXDEBUG - if (debug) { - fprintf(yyout, "try fall back character "); - allprint(YYU(yymatch[yych])); - putchar('\n'); - } -#endif - if (yyt <= yytop && yyt->verify + yysvec == yystate) { - if (yyt->advance + yysvec == YYLERR) /* error transition */ - { - unput(*--yylastch); - break; - } - *lsp++ = yystate = yyt->advance + yysvec; - goto contin; - } - } - if ((yystate = yystate->yyother) && (yyt = yystate->yystoff) != yycrank) { -#ifdef LEXDEBUG - if (debug) fprintf(yyout, "fall back to state %d\n", yystate - yysvec - 1); -#endif - goto tryagain; - } -#endif - else { - unput(*--yylastch); - break; - } - contin: -#ifdef LEXDEBUG - if (debug) { - fprintf(yyout, "state %d char ", yystate - yysvec - 1); - allprint(yych); - putchar('\n'); - } -#endif - ; - } -#ifdef LEXDEBUG - if (debug) { - fprintf(yyout, "stopped at %d with ", *(lsp - 1) - yysvec - 1); - allprint(yych); - putchar('\n'); - } -#endif - while (lsp-- > yylstate) { - *yylastch-- = 0; - if (*lsp != 0 && (yyfnd = (*lsp)->yystops) && *yyfnd > 0) { - yyolsp = lsp; - if (yyextra[*yyfnd]) { /* must backup */ - while (yyback((*lsp)->yystops, -*yyfnd) != 1 && lsp > yylstate) { - lsp--; - unput(*yylastch--); - } - } - yyprevious = YYU(*yylastch); - yylsp = lsp; - yyleng = yylastch - yytext + 1; - yytext[yyleng] = 0; -#ifdef LEXDEBUG - if (debug) { - fprintf(yyout, "\nmatch "); - sprint(yytext); - fprintf(yyout, " action %d\n", *yyfnd); - } -#endif - return (*yyfnd++); - } - unput(*yylastch); - } - if (yytext[0] == 0 /* && feof(yyin) */) { - yysptr = yysbuf; - return (0); - } - yyprevious = yytext[0] = input(); - if (yyprevious > 0) output(yyprevious); - yylastch = yytext; -#ifdef LEXDEBUG - if (debug) putchar('\n'); -#endif - } -} -#endif +/* $Id: lplexyy.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved + */ +static char *id = "$Id: lplexyy.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $ Copyright (C) Venue"; + +/************************************************************************/ +/* */ +/* (C) Copyright 1989-95 Venue. All Rights Reserved. */ +/* Manufactured in the United States of America. */ +/* */ +/* The contents of this file are proprietary information */ +/* belonging to Venue, and are provided to you under license. */ +/* They may not be further distributed or disclosed to third */ +/* parties without the specific permission of Venue. */ +/* */ +/************************************************************************/ + +#include "version.h" + +#ifndef BIGATOMS +#include "stdio.h" +#define U(x) x +#define NLSTATE yyprevious = YYNEWLINE +#define BEGIN yybgin = yysvec + 1 + +#define INITIAL 0 +#define YYLERR yysvec +#define YYSTATE (yyestate - yysvec - 1) +#define YYOPTIM 1 +#define YYLMAX 200 +#define output(c) putc(c, yyout) +#define input() \ + (((yytchar = yysptr > yysbuf ? U(*--yysptr) : getc(yyin)) == 10 ? (yylineno++, yytchar) \ + : yytchar) == EOF \ + ? 0 \ + : yytchar) +#define unput(c) \ + { \ + yytchar = (c); \ + if (yytchar == '\n') yylineno--; \ + *yysptr++ = yytchar; \ + } +#define yymore() (yymorfg = 1) +#define ECHO fprintf(yyout, "%s", yytext) +#define REJECT \ + { \ + nstr = yyreject(); \ + goto yyfussy; \ + } +int yyleng; +extern char yytext[]; +int yymorfg; +extern char *yysptr, yysbuf[]; +int yytchar; +FILE *yyin = {stdin}, *yyout = {stdout}; +extern int yylineno; +struct yysvf { + struct yywork *yystoff; + struct yysvf *yyother; + int *yystops; +}; +struct yysvf *yyestate; +extern struct yysvf yysvec[], *yybgin; +extern int yylook(); +#ifdef __cplusplus +extern "C" { +#endif +#define yywrap() (1) +extern int yylex(); +extern int yyreject(); +extern int yyracc(int); +extern int yyless(int); +#ifdef __cplusplus +} +#endif +#define COMMENT 2 +#define YYNEWLINE 10 +yylex() { + int nstr; + extern int yyprevious; + while ((nstr = yylook()) >= 0) + yyfussy: + switch (nstr) { + case 0: + if (yywrap()) return (0); + break; + case 1: { + BEGIN COMMENT; + } break; + case 2: { + BEGIN INITIAL; + } break; + case 3: { + } break; + case 4: { + } break; + case 5: { + } break; + case 6: { + return (COMMA); + } break; + case 7: { + return (MINIMISE); + } break; + case 8: { + return (MAXIMISE); + } break; + case 9: { + sscanf((char *)yytext, "%lf", &f); + return (CONS); + } break; + case 10: { + Sign = 0; + for (x = 0; x < yyleng; x++) + if (yytext[x] == '-' || yytext[x] == '+') Sign = (Sign == (yytext[x] == '+')); + return (SIGN); + /* Sign is TRUE if the sign-string + represents a '-'. Otherwise Sign + is FALSE */ + } break; + case 11: { + strcpy(Last_var, (char *)yytext); + return (VAR); + } break; + case 12: { + return (COLON); + } break; + case 13: { + return (AR_M_OP); + } break; + case 14: { + return (RE_OP); + } break; + case 15: { + return (END_C); + } break; + case 16: { + fprintf(stderr, "LEX ERROR : %s lineno %d \n", yytext, yylineno); + } break; + case -1: break; + default: fprintf(yyout, "bad switch yylook %d", nstr); + } + return (0); +} +/* end of yylex */ +int yyvstop[] = {0, + + 14, 0, + + 14, 0, + + 14, 0, + + 14, 0, + + 16, 0, + + 5, 10, 16, 0, + + 5, 10, 0, + + 13, 16, 0, + + 10, 16, 0, + + 6, 16, 0, + + 16, 0, + + 16, 0, + + 9, 16, 0, + + 12, 16, 0, + + 15, 16, 0, + + 14, 16, 0, + + 14, 16, 0, + + 11, 16, 0, + + 11, 16, 0, + + 3, 0, + + 4, 0, + + 3, 0, + + 10, 0, + + 9, 0, + + 1, 0, + + 9, 0, + + 14, 0, + + 11, 0, + + 11, 0, + + 11, 0, + + 2, 0, + + 9, 0, + + 11, 0, + + 11, 0, + + 11, 0, + + 8, 0, + + 7, 0, 0}; +#define YYTYPE char +struct yywork { + YYTYPE verify, advance; +} yycrank[] = { + 0, 0, 0, 0, 1, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 1, 7, + 9, 23, 9, 23, 23, 23, 23, 23, 0, 0, 6, 7, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 23, + 1, 5, 23, 23, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 1, 8, 1, 9, 1, 10, 4, 22, 1, 11, + 1, 12, 1, 13, 12, 25, 6, 23, 2, 8, 6, 23, 2, 10, 22, 34, 2, 11, 2, 12, 0, 0, 1, 14, + 1, 15, 1, 16, 1, 17, 0, 0, 3, 20, 16, 29, 1, 18, 1, 18, 2, 14, 2, 15, 1, 18, 2, 17, + 3, 20, 3, 21, 1, 18, 24, 28, 0, 0, 0, 0, 1, 19, 1, 18, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 22, 3, 20, 24, 28, + 0, 0, 0, 0, 0, 0, 3, 20, 11, 24, 11, 24, 11, 24, 11, 24, 11, 24, 11, 24, 11, 24, 11, 24, + 11, 24, 11, 24, 0, 0, 3, 20, 0, 0, 0, 0, 0, 0, 0, 0, 3, 20, 3, 20, 0, 0, 0, 0, + 3, 20, 0, 0, 0, 0, 0, 0, 3, 20, 0, 0, 0, 0, 0, 0, 3, 20, 3, 20, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 26, 3, 20, 13, 27, 13, 27, 13, 27, 13, 27, + 13, 27, 13, 27, 13, 27, 13, 27, 13, 27, 13, 27, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 28, 35, 0, 0, 28, 35, 0, 0, 13, 28, 28, 36, 28, 36, 28, 36, 28, 36, 28, 36, 28, 36, + 28, 36, 28, 36, 28, 36, 28, 36, 35, 36, 35, 36, 35, 36, 35, 36, 35, 36, 35, 36, 35, 36, 35, 36, + 35, 36, 35, 36, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 13, 28, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, + 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, + 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, + 18, 30, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 18, 0, 0, 0, + 0, 0, 18, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, + 18, 0, 18, 31, 18, 0, 18, 0, 18, 0, 0, 0, 18, 30, 18, 30, 0, 0, 0, 0, 18, 30, 0, 0, + 0, 0, 0, 0, 18, 30, 0, 0, 0, 0, 0, 0, 18, 30, 18, 30, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 30, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, + 0, 0, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 18, 0, 19, 0, 19, 0, 19, 0, + 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, + 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, + 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 19, 0, 0, 0, 19, 0, 19, 0, 19, 0, + 0, 0, 19, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 33, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 19, 0, 0, 0, 0, 0, 19, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, + 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, + 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, + 30, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, + 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 30, 0, 30, 0, 0, 0, 30, 0, 30, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, + 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0, 0, 0, 30, 0, 31, 0, + 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, + 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, + 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 37, 0, 0, 0, 0, + 0, 0, 0, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 31, 0, 0, 0, 0, 0, 31, 37, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0, 31, 0, 31, 0, 31, 0, + 31, 0, 31, 0, 0, 0, 31, 37, 31, 37, 0, 0, 0, 0, 31, 37, 0, 0, 0, 0, 0, 0, 31, 37, + 0, 0, 0, 0, 0, 0, 31, 37, 31, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 31, 37, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 31, 0, 0, 0, 0, 0, 31, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, + 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, + 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, 32, 0, + 32, 0, 32, 0, 32, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 32, 0, 32, 0, + 32, 0, 32, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 32, 0, 32, 0, 0, 0, 32, 0, 32, 0, 32, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 38, 0, 0, 0, 0, + 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, + 32, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, + 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, + 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 33, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 33, 0, + 0, 0, 33, 0, 33, 0, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 0, 0, + 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 33, 0, 0, 0, 0, 0, 33, 0, 37, 0, 37, 0, 37, 0, 37, 0, + 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, + 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, + 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 0, + 37, 0, 37, 0, 37, 0, 37, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 0, 37, 0, 37, 0, 37, 0, 37, 40, 37, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, 37, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 0, + 0, 0, 0, 0, 37, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, + 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, + 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, + 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, 38, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 38, 41, 38, 0, 0, 0, 38, 0, 38, 0, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0, + 0, 0, 0, 0, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0, 0, 0, 38, 0, 39, 0, 39, 0, + 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, + 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, + 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 42, 39, 0, 0, 0, 39, 0, 39, 0, + 39, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 39, 0, 0, 0, 0, 0, 39, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +struct yysvf yysvec[] = {0, + 0, + 0, + yycrank + -1, + 0, + yyvstop + 1, + yycrank + -10, + yysvec + 1, + yyvstop + 3, + yycrank + -63, + 0, + yyvstop + 5, + yycrank + -4, + yysvec + 3, + yyvstop + 7, + yycrank + 0, + 0, + yyvstop + 9, + yycrank + 8, + 0, + yyvstop + 11, + yycrank + 0, + yysvec + 6, + yyvstop + 15, + yycrank + 0, + 0, + yyvstop + 18, + yycrank + 3, + yysvec + 6, + yyvstop + 21, + yycrank + 0, + 0, + yyvstop + 24, + yycrank + 64, + 0, + yyvstop + 27, + yycrank + 8, + 0, + yyvstop + 29, + yycrank + 104, + 0, + yyvstop + 31, + yycrank + 0, + 0, + yyvstop + 34, + yycrank + 0, + 0, + yyvstop + 37, + yycrank + 4, + 0, + yyvstop + 40, + yycrank + 0, + 0, + yyvstop + 43, + yycrank + -205, + 0, + yyvstop + 46, + yycrank + -332, + yysvec + 18, + yyvstop + 49, + yycrank + 0, + 0, + yyvstop + 52, + yycrank + 0, + 0, + yyvstop + 54, + yycrank + 8, + 0, + yyvstop + 56, + yycrank + 5, + yysvec + 6, + yyvstop + 58, + yycrank + 6, + yysvec + 11, + yyvstop + 60, + yycrank + 0, + 0, + yyvstop + 62, + yycrank + 0, + yysvec + 11, + 0, + yycrank + 0, + yysvec + 13, + yyvstop + 64, + yycrank + 126, + 0, + 0, + yycrank + 0, + 0, + yyvstop + 66, + yycrank + -459, + yysvec + 18, + yyvstop + 68, + yycrank + -586, + 0, + 0, + yycrank + -713, + yysvec + 18, + yyvstop + 70, + yycrank + -840, + yysvec + 18, + yyvstop + 72, + yycrank + 0, + 0, + yyvstop + 74, + yycrank + 136, + 0, + 0, + yycrank + 0, + yysvec + 35, + yyvstop + 76, + yycrank + -967, + yysvec + 31, + 0, + yycrank + -1094, + yysvec + 18, + yyvstop + 78, + yycrank + -1221, + yysvec + 18, + yyvstop + 80, + yycrank + 0, + 0, + yyvstop + 82, + yycrank + 0, + 0, + yyvstop + 84, + yycrank + 0, + 0, + yyvstop + 86, + 0, + 0, + 0}; +struct yywork *yytop = yycrank + 1348; +struct yysvf *yybgin = yysvec + 1; +char yymatch[] = { + 00, 01, 01, 01, 01, 01, 01, 01, 01, 011, 012, 01, 01, 01, 01, 01, 01, 01, 01, + 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 01, 011, 01, 01, '#', '#', '#', + '#', '#', 01, 01, 01, '+', 01, '+', '#', '#', '0', '0', '0', '0', '0', '0', '0', '0', '0', + '0', 01, 01, '<', 01, '<', 01, '#', 'A', 'B', 'B', 'B', 'E', 'B', 'B', 'B', 'I', 'B', 'B', + 'B', 'M', 'N', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'X', 'B', 'B', '#', 01, '#', '#', + '#', 01, 'A', 'B', 'B', 'B', 'E', 'B', 'B', 'B', 'I', 'B', 'B', 'B', 'M', 'N', 'B', 'B', 'B', + 'B', 'B', 'B', 'B', 'B', 'B', 'X', 'B', 'B', '#', 01, '#', '#', 01, 0}; +char yyextra[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +#ident "$Header: /disk/disk3/cvsroot/medley/src/lplexyy.c,v 1.2 1999/01/03 02:07:18 sybalsky Exp $" +int yylineno = 1; +#define YYU(x) x +#define NLSTATE yyprevious = YYNEWLINE +char yytext[YYLMAX]; +struct yysvf *yylstate[YYLMAX], **yylsp, **yyolsp; +char yysbuf[YYLMAX]; +char *yysptr = yysbuf; +int *yyfnd; +extern struct yysvf *yyestate; +int yyprevious = YYNEWLINE; +int yyback(int *p, int m) { + if (p == 0) return (0); + while (*p) { + if (*p++ == m) return (1); + } + return (0); +} +/* the following are only used in the lex library */ +int yyinput() { return (input()); } +void yyoutput(int c) { output(c); } +void yyunput(int c) { unput(c); } + +int yylook() { + register struct yysvf *yystate, **lsp; + register struct yywork *yyt; + struct yysvf *yyz; + int yych, yyfirst; + struct yywork *yyr; +#ifdef LEXDEBUG + int debug; +#endif + char *yylastch; +/* start off machines */ +#ifdef LEXDEBUG + debug = 0; +#endif + yyfirst = 1; + if (!yymorfg) + yylastch = yytext; + else { + yymorfg = 0; + yylastch = yytext + yyleng; + } + for (;;) { + lsp = yylstate; + yyestate = yystate = yybgin; + if (yyprevious == YYNEWLINE) yystate++; + for (;;) { +#ifdef LEXDEBUG + if (debug) fprintf(yyout, "state %d\n", yystate - yysvec - 1); +#endif + yyt = yystate->yystoff; + if (yyt == yycrank && !yyfirst) { /* may not be any transitions */ + yyz = yystate->yyother; + if (yyz == 0) break; + if (yyz->yystoff == yycrank) break; + } + *yylastch++ = yych = input(); + yyfirst = 0; + tryagain: +#ifdef LEXDEBUG + if (debug) { + fprintf(yyout, "char "); + allprint(yych); + putchar('\n'); + } +#endif + yyr = yyt; + if ((int)yyt > (int)yycrank) { + yyt = yyr + yych; + if (yyt <= yytop && yyt->verify + yysvec == yystate) { + if (yyt->advance + yysvec == YYLERR) /* error transitions */ + { + unput(*--yylastch); + break; + } + *lsp++ = yystate = yyt->advance + yysvec; + goto contin; + } + } +#ifdef YYOPTIM + else if ((int)yyt < (int)yycrank) { /* r < yycrank */ + yyt = yyr = yycrank + (yycrank - yyt); +#ifdef LEXDEBUG + if (debug) fprintf(yyout, "compressed state\n"); +#endif + yyt = yyt + yych; + if (yyt <= yytop && yyt->verify + yysvec == yystate) { + if (yyt->advance + yysvec == YYLERR) /* error transitions */ + { + unput(*--yylastch); + break; + } + *lsp++ = yystate = yyt->advance + yysvec; + goto contin; + } + yyt = yyr + YYU(yymatch[yych]); +#ifdef LEXDEBUG + if (debug) { + fprintf(yyout, "try fall back character "); + allprint(YYU(yymatch[yych])); + putchar('\n'); + } +#endif + if (yyt <= yytop && yyt->verify + yysvec == yystate) { + if (yyt->advance + yysvec == YYLERR) /* error transition */ + { + unput(*--yylastch); + break; + } + *lsp++ = yystate = yyt->advance + yysvec; + goto contin; + } + } + if ((yystate = yystate->yyother) && (yyt = yystate->yystoff) != yycrank) { +#ifdef LEXDEBUG + if (debug) fprintf(yyout, "fall back to state %d\n", yystate - yysvec - 1); +#endif + goto tryagain; + } +#endif + else { + unput(*--yylastch); + break; + } + contin: +#ifdef LEXDEBUG + if (debug) { + fprintf(yyout, "state %d char ", yystate - yysvec - 1); + allprint(yych); + putchar('\n'); + } +#endif + ; + } +#ifdef LEXDEBUG + if (debug) { + fprintf(yyout, "stopped at %d with ", *(lsp - 1) - yysvec - 1); + allprint(yych); + putchar('\n'); + } +#endif + while (lsp-- > yylstate) { + *yylastch-- = 0; + if (*lsp != 0 && (yyfnd = (*lsp)->yystops) && *yyfnd > 0) { + yyolsp = lsp; + if (yyextra[*yyfnd]) { /* must backup */ + while (yyback((*lsp)->yystops, -*yyfnd) != 1 && lsp > yylstate) { + lsp--; + unput(*yylastch--); + } + } + yyprevious = YYU(*yylastch); + yylsp = lsp; + yyleng = yylastch - yytext + 1; + yytext[yyleng] = 0; +#ifdef LEXDEBUG + if (debug) { + fprintf(yyout, "\nmatch "); + sprint(yytext); + fprintf(yyout, " action %d\n", *yyfnd); + } +#endif + return (*yyfnd++); + } + unput(*yylastch); + } + if (yytext[0] == 0 /* && feof(yyin) */) { + yysptr = yysbuf; + return (0); + } + yyprevious = yytext[0] = input(); + if (yyprevious > 0) output(yyprevious); + yylastch = yytext; +#ifdef LEXDEBUG + if (debug) putchar('\n'); +#endif + } +} +#endif diff --git a/src/lpytab.c b/src/lpytab.c index 4b710f5..c9b03d8 100644 --- a/src/lpytab.c +++ b/src/lpytab.c @@ -1,649 +1,649 @@ -/* $Id: lpytab.c,v 1.2 1999/01/03 02:07:21 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved - */ -static char *id = "$Id: lpytab.c,v 1.2 1999/01/03 02:07:21 sybalsky Exp $ Copyright (C) Venue"; - -/************************************************************************/ -/* */ -/* (C) Copyright 1989-95 Venue. All Rights Reserved. */ -/* Manufactured in the United States of America. */ -/* */ -/* The contents of this file are proprietary information */ -/* belonging to Venue, and are provided to you under license. */ -/* They may not be further distributed or disclosed to third */ -/* parties without the specific permission of Venue. */ -/* */ -/************************************************************************/ - -#include "version.h" - -#ifndef BIGATOMS - -#define VAR 257 -#define CONS 258 -#define SIGN 259 -#define AR_M_OP 260 -#define RE_OP 261 -#define END_C 262 -#define COMMA 263 -#define COLON 264 -#define MINIMISE 265 -#define MAXIMISE 266 - -#line 10 "lp.y" -#include "lpdefines.h" -#include "lpglobals.h" - -/* globals */ -char Last_var[NAMELEN]; -char Constraint_name[NAMELEN]; -int Lin_term_count; -double f; -int x; -int Sign; -int isign; /* internal_sign variable to make sure nothing goes wrong */ -/* with lookahead */ -int make_neg; /* is true after the relational operator is seen in order */ -/* to remember if lin_term stands before or after re_op */ -#define yyclearin yychar = -1 -#define yyerrok yyerrflag = 0 -extern int yychar; -extern int yyerrflag; -#ifndef YYMAXDEPTH -#define YYMAXDEPTH 150 -#endif -#ifndef YYSTYPE -#define YYSTYPE int -#endif -YYSTYPE yylval, yyval; -typedef int yytabelem; -#define YYERRCODE 256 - -#line 193 "lp.y" - -#include "lexyy.c" -yytabelem yyexca[] = { - -1, 1, 0, -1, -2, 0, -1, 31, 257, 15, -2, 31, -}; -#define YYNPROD 38 -#define YYLAST 87 -yytabelem yyact[] = { - - 10, 11, 9, 34, 36, 51, 56, 57, 5, 4, 50, 52, 23, 44, 36, 24, 35, 10, 20, 18, 26, 10, - 20, 27, 31, 20, 18, 10, 11, 9, 15, 20, 18, 10, 11, 42, 40, 17, 14, 16, 19, 32, 13, 8, - 6, 8, 8, 38, 25, 21, 22, 7, 47, 37, 43, 29, 33, 30, 46, 45, 28, 12, 3, 2, 1, 0, - 39, 0, 0, 0, 0, 0, 41, 0, 0, 48, 0, 0, 0, 49, 0, 0, 0, 0, 53, 55, 54}; -yytabelem yypact[] = { - - -1000, -1000, -257, -227, -230, -230, -1000, -247, -1000, -1000, -1000, -237, - -233, -1000, -1000, -261, -245, -1000, -1000, -1000, -237, -1000, -1000, -1000, - -1000, -224, -1000, -221, -1000, -1000, -222, -261, -1000, -244, -1000, -1000, - -1000, -236, -224, -1000, -1000, -1000, -1000, -252, -1000, -240, -240, -236, - -1000, -1000, -1000, -1000, -251, -1000, -255, -1000, -1000, -1000}; -yytabelem yypgo[] = { - - 0, 64, 63, 62, 61, 60, 42, 38, 59, 39, 58, 57, 41, 56, 54, 37, 53, 52, 40, 51, 48, 47, 44}; -yytabelem yyr1[] = { - - 0, 2, 1, 4, 4, 6, 8, 6, 10, 7, 5, 5, 11, 11, 12, 13, 14, 14, 14, - 9, 16, 9, 17, 9, 15, 15, 19, 20, 19, 21, 19, 18, 18, 18, 3, 3, 3, 22}; -yytabelem yyr2[] = { - - 0, 1, 8, 2, 4, 2, 1, 8, 1, 11, 0, 2, 2, 4, 7, 3, 3, 5, 7, - 2, 1, 6, 1, 8, 2, 3, 2, 1, 6, 1, 8, 3, 5, 7, 5, 5, 2, 5}; -yytabelem yychk[] = { - - -1000, -1, -2, -3, 266, 265, -22, -19, -18, 259, 257, 258, -4, -6, -7, - 257, -9, -15, 259, -18, 258, -22, -22, 259, 262, -20, 257, 260, -5, -6, - -11, 257, -12, -13, 264, 261, 259, -16, -21, -18, 257, -12, 257, -14, 257, - -8, -10, -17, -15, -18, 262, 257, 263, -7, -9, -15, 257, 262}; -yytabelem yydef[] = { - - 1, -2, 0, 0, 0, 0, 36, 0, 26, 27, 31, 0, 10, 3, 5, 31, 0, 19, 20, 24, - 25, 34, 35, 29, 37, 0, 32, 0, 2, 4, 11, -2, 12, 0, 6, 8, 22, 0, 0, 28, - 33, 13, 15, 0, 16, 0, 0, 0, 21, 30, 14, 17, 0, 7, 0, 23, 18, 9}; -typedef struct { - char *t_name; - int t_val; -} yytoktype; -#ifndef YYDEBUG -#define YYDEBUG 0 /* don't allow debugging */ -#endif - -#if YYDEBUG - -yytoktype yytoks[] = { - "VAR", 257, "CONS", 258, "SIGN", 259, "AR_M_OP", 260, "RE_OP", 261, "END_C", 262, - "COMMA", 263, "COLON", 264, "MINIMISE", 265, "MAXIMISE", 266, "-unknown-", -1 /* ends search */ -}; - -char *yyreds[] = { - "-no such reduction-", - "inputfile : /* empty */", - "inputfile : objective_function constraints int_declarations", - "constraints : constraint", - "constraints : constraints constraint", - "constraint : real_constraint", - "constraint : VAR COLON", - "constraint : VAR COLON real_constraint", - "real_constraint : x_lineair_sum RE_OP", - "real_constraint : x_lineair_sum RE_OP x_lineair_sum END_C", - "int_declarations : /* empty */", - "int_declarations : real_int_decls", - "real_int_decls : int_declaration", - "real_int_decls : real_int_decls int_declaration", - "int_declaration : int_declarator vars END_C", - "int_declarator : VAR", - "vars : VAR", - "vars : vars VAR", - "vars : vars COMMA VAR", - "x_lineair_sum : x_lineair_term", - "x_lineair_sum : SIGN", - "x_lineair_sum : SIGN x_lineair_term", - "x_lineair_sum : x_lineair_sum SIGN", - "x_lineair_sum : x_lineair_sum SIGN x_lineair_term", - "x_lineair_term : lineair_term", - "x_lineair_term : CONS", - "lineair_sum : lineair_term", - "lineair_sum : SIGN", - "lineair_sum : SIGN lineair_term", - "lineair_sum : lineair_sum SIGN", - "lineair_sum : lineair_sum SIGN lineair_term", - "lineair_term : VAR", - "lineair_term : CONS VAR", - "lineair_term : CONS AR_M_OP VAR", - "objective_function : MAXIMISE real_of", - "objective_function : MINIMISE real_of", - "objective_function : real_of", - "real_of : lineair_sum END_C", -}; -#endif /* YYDEBUG */ -/* - * Copyright 1987 Silicon Graphics, Inc. - All Rights Reserved - */ - -#ident "$Revision: 1.2 $" - -/* -** Skeleton parser driver for yacc output -*/ - -/* -** yacc user known macros and defines -*/ -#define YYERROR goto yyerrlab -#define YYACCEPT return (0) -#define YYABORT return (1) -#define YYBACKUP(newtoken, newvalue) \ - \ -{ \ - if (yychar >= 0 || (yyr2[yytmp] >> 1) != 1) { \ - yyerror("syntax error - cannot backup"); \ - goto yyerrlab; \ - } \ - yychar = newtoken; \ - yystate = *yyps; \ - yylval = newvalue; \ - goto yynewstate; \ - \ -} -#define YYRECOVERING() (!!yyerrflag) -#ifndef YYDEBUG -#define YYDEBUG 1 /* make debugging available */ -#endif - -/* -** user known globals -*/ -int yydebug; /* set to 1 to get debugging */ - -/* -** driver internal defines -*/ -#define YYFLAG (-1000) - -/* -** global variables used by the parser -*/ -YYSTYPE yyv[YYMAXDEPTH]; /* value stack */ -int yys[YYMAXDEPTH]; /* state stack */ - -YYSTYPE *yypv; /* top of value stack */ -int *yyps; /* top of state stack */ - -int yystate; /* current state */ -int yytmp; /* extra var (lasts between blocks) */ - -int yynerrs; /* number of errors */ -int yyerrflag; /* error recovery flag */ -int yychar; /* current input token number */ - -/* -** yyparse - return 0 if worked, 1 if syntax error not recovered from -*/ -int yyparse() { - register YYSTYPE *yypvt; /* top of value stack for $vars */ - - /* - ** Initialize externals - yyparse may be called more than once - */ - yypv = &yyv[-1]; - yyps = &yys[-1]; - yystate = 0; - yytmp = 0; - yynerrs = 0; - yyerrflag = 0; - yychar = -1; - - goto yystack; - { - register YYSTYPE *yy_pv; /* top of value stack */ - register int *yy_ps; /* top of state stack */ - register int yy_state; /* current state */ - register int yy_n; /* internal state number info */ - - /* - ** get globals into registers. - ** branch to here only if YYBACKUP was called. - */ - yynewstate: - yy_pv = yypv; - yy_ps = yyps; - yy_state = yystate; - goto yy_newstate; - - /* - ** get globals into registers. - ** either we just started, or we just finished a reduction - */ - yystack: - yy_pv = yypv; - yy_ps = yyps; - yy_state = yystate; - - /* - ** top of for (;;) loop while no reductions done - */ - yy_stack: -/* -** put a state and value onto the stacks -*/ -#if YYDEBUG - /* - ** if debugging, look up token value in list of value vs. - ** name pairs. 0 and negative (-1) are special values. - ** Note: linear search is used since time is not a real - ** consideration while debugging. - */ - if (yydebug) { - register int yy_i; - - printf("State %d, token ", yy_state); - if (yychar == 0) - printf("end-of-file\n"); - else if (yychar < 0) - printf("-none-\n"); - else { - for (yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++) { - if (yytoks[yy_i].t_val == yychar) break; - } - printf("%s\n", yytoks[yy_i].t_name); - } - } -#endif /* YYDEBUG */ - if (++yy_ps >= &yys[YYMAXDEPTH]) /* room on stack? */ - { - yyerror("yacc stack overflow"); - YYABORT; - } - *yy_ps = yy_state; - *++yy_pv = yyval; - - /* - ** we have a new state - find out what to do - */ - yy_newstate: - if ((yy_n = yypact[yy_state]) <= YYFLAG) goto yydefault; /* simple state */ -#if YYDEBUG - /* - ** if debugging, need to mark whether new token grabbed - */ - yytmp = yychar < 0; -#endif - if ((yychar < 0) && ((yychar = yylex()) < 0)) yychar = 0; /* reached EOF */ -#if YYDEBUG - if (yydebug && yytmp) { - register int yy_i; - - printf("Received token "); - if (yychar == 0) - printf("end-of-file\n"); - else if (yychar < 0) - printf("-none-\n"); - else { - for (yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++) { - if (yytoks[yy_i].t_val == yychar) break; - } - printf("%s\n", yytoks[yy_i].t_name); - } - } -#endif /* YYDEBUG */ - if (((yy_n += yychar) < 0) || (yy_n >= YYLAST)) goto yydefault; - if (yychk[yy_n = yyact[yy_n]] == yychar) /*valid shift*/ - { - yychar = -1; - yyval = yylval; - yy_state = yy_n; - if (yyerrflag > 0) yyerrflag--; - goto yy_stack; - } - - yydefault: - if ((yy_n = yydef[yy_state]) == -2) { -#if YYDEBUG - yytmp = yychar < 0; -#endif - if ((yychar < 0) && ((yychar = yylex()) < 0)) yychar = 0; /* reached EOF */ -#if YYDEBUG - if (yydebug && yytmp) { - register int yy_i; - - printf("Received token "); - if (yychar == 0) - printf("end-of-file\n"); - else if (yychar < 0) - printf("-none-\n"); - else { - for (yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++) { - if (yytoks[yy_i].t_val == yychar) { break; } - } - printf("%s\n", yytoks[yy_i].t_name); - } - } -#endif /* YYDEBUG */ - /* - ** look through exception table - */ - { - register int *yyxi = yyexca; - - while ((*yyxi != -1) || (yyxi[1] != yy_state)) { yyxi += 2; } - while ((*(yyxi += 2) >= 0) && (*yyxi != yychar)) - ; - if ((yy_n = yyxi[1]) < 0) YYACCEPT; - } - } - - /* - ** check for syntax error - */ - if (yy_n == 0) /* have an error */ - { - /* no worry about speed here! */ - switch (yyerrflag) { - case 0: /* new error */ - yyerror("syntax error"); - goto skip_init; - yyerrlab: - /* - ** get globals into registers. - ** we have a user generated syntax type error - */ - yy_pv = yypv; - yy_ps = yyps; - yy_state = yystate; - yynerrs++; - skip_init: - case 1: - case 2: /* incompletely recovered error */ - /* try again... */ - yyerrflag = 3; - /* - ** find state where "error" is a legal - ** shift action - */ - while (yy_ps >= yys) { - yy_n = yypact[*yy_ps] + YYERRCODE; - if (yy_n >= 0 && yy_n < YYLAST && yychk[yyact[yy_n]] == YYERRCODE) { - /* - ** simulate shift of "error" - */ - yy_state = yyact[yy_n]; - goto yy_stack; - } -/* -** current state has no shift on -** "error", pop stack -*/ -#if YYDEBUG -#define _POP_ "Error recovery pops state %d, uncovers state %d\n" - if (yydebug) printf(_POP_, *yy_ps, yy_ps[-1]); -#undef _POP_ -#endif - yy_ps--; - yy_pv--; - } - /* - ** there is no state on stack with "error" as - ** a valid shift. give up. - */ - YYABORT; - case 3: /* no shift yet; eat a token */ -#if YYDEBUG - /* - ** if debugging, look up token in list of - ** pairs. 0 and negative shouldn't occur, - ** but since timing doesn't matter when - ** debugging, it doesn't hurt to leave the - ** tests here. - */ - if (yydebug) { - register int yy_i; - - printf("Error recovery discards "); - if (yychar == 0) - printf("token end-of-file\n"); - else if (yychar < 0) - printf("token -none-\n"); - else { - for (yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++) { - if (yytoks[yy_i].t_val == yychar) { break; } - } - printf("token %s\n", yytoks[yy_i].t_name); - } - } -#endif /* YYDEBUG */ - if (yychar == 0) /* reached EOF. quit */ - YYABORT; - yychar = -1; - goto yy_newstate; - } - } /* end if ( yy_n == 0 ) */ -/* -** reduction by production yy_n -** put stack tops, etc. so things right after switch -*/ -#if YYDEBUG - /* - ** if debugging, print the string that is the user's - ** specification of the reduction which is just about - ** to be done. - */ - if (yydebug) printf("Reduce by (%d) \"%s\"\n", yy_n, yyreds[yy_n]); -#endif - yytmp = yy_n; /* value to switch over */ - yypvt = yy_pv; /* $vars top of value stack */ - /* - ** Look in goto table for next state - ** Sorry about using yy_state here as temporary - ** register variable, but why not, if it works... - ** If yyr2[ yy_n ] doesn't have the low order bit - ** set, then there is no action to be done for - ** this reduction. So, no saving & unsaving of - ** registers done. The only difference between the - ** code just after the if and the body of the if is - ** the goto yy_stack in the body. This way the test - ** can be made before the choice of what to do is needed. - */ - { - /* length of production doubled with extra bit */ - register int yy_len = yyr2[yy_n]; - - if (!(yy_len & 01)) { - yy_len >>= 1; - yyval = (yy_pv -= yy_len)[1]; /* $$ = $1 */ - yy_state = yypgo[yy_n = yyr1[yy_n]] + *(yy_ps -= yy_len) + 1; - if (yy_state >= YYLAST || yychk[yy_state = yyact[yy_state]] != -yy_n) { - yy_state = yyact[yypgo[yy_n]]; - } - goto yy_stack; - } - yy_len >>= 1; - yyval = (yy_pv -= yy_len)[1]; /* $$ = $1 */ - yy_state = yypgo[yy_n = yyr1[yy_n]] + *(yy_ps -= yy_len) + 1; - if (yy_state >= YYLAST || yychk[yy_state = yyact[yy_state]] != -yy_n) { - yy_state = yyact[yypgo[yy_n]]; - } - } - /* save until reenter driver code */ - yystate = yy_state; - yyps = yy_ps; - yypv = yy_pv; - } - /* - ** code supplied by user is placed in this switch - */ - switch (yytmp) { - case 1: -#line 32 "lp.y" - { - init_read(); - isign = 0; - make_neg = 0; - } break; - case 6: -#line 49 "lp.y" - { - add_constraint_name(Last_var, Rows); - } break; - case 8: -#line 58 "lp.y" - { - store_re_op(); - make_neg = 1; - } break; - case 9: -#line 64 "lp.y" - { - if (Lin_term_count == 0) { - fprintf(stderr, "WARNING line %d: constraint contains no variables\n", yylineno); - null_tmp_store(); - } - - if (Lin_term_count > 1) Rows++; - - if (Lin_term_count == 1) store_bounds(); - - Lin_term_count = 0; - isign = 0; - make_neg = 0; - Constraint_name[0] = '\0'; - } break; - case 14: -#line 93 "lp.y" - { - Having_ints = 1; - } break; - case 15: -#line 96 "lp.y" - { /* check_decl(yytext);*/ - } break; - case 16: -#line 99 "lp.y" - { - add_int_var((char *)yytext); - } break; - case 17: -#line 100 "lp.y" - { - add_int_var((char *)yytext); - } break; - case 18: -#line 101 "lp.y" - { - add_int_var((char *)yytext); - } break; - case 20: -#line 106 "lp.y" - { - isign = Sign; - } break; - case 22: -#line 112 "lp.y" - { - isign = Sign; - } break; - case 25: -#line 120 "lp.y" - { - if ((isign || !make_neg) && !(isign && !make_neg)) /* but not both! */ - f = -f; - rhs_store(f); - isign = 0; - } break; - case 27: -#line 131 "lp.y" - { - isign = Sign; - } break; - case 29: -#line 137 "lp.y" - { - isign = Sign; - } break; - case 31: -#line 144 "lp.y" - { - if ((isign || make_neg) && !(isign && make_neg)) /* but not both! */ - var_store(Last_var, Rows, (double)-1); - else - var_store(Last_var, Rows, (double)1); - isign = 0; - } break; - case 32: -#line 154 "lp.y" - { - if ((isign || make_neg) && !(isign && make_neg)) /* but not both! */ - f = -f; - var_store(Last_var, Rows, f); - isign = 0; - } break; - case 33: -#line 164 "lp.y" - { - if ((isign || make_neg) && !(isign && make_neg)) /* but not both! */ - f = -f; - var_store(Last_var, Rows, f); - isign = 0; - } break; - case 34: -#line 174 "lp.y" - { - Maximise = TRUE; - } break; - case 35: -#line 178 "lp.y" - { - Maximise = FALSE; - } break; - case 37: -#line 186 "lp.y" - { - Rows++; - Lin_term_count = 0; - isign = 0; - make_neg = 0; - } break; - } - goto yystack; /* reset registers in driver code */ -} -#endif +/* $Id: lpytab.c,v 1.2 1999/01/03 02:07:21 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved + */ +static char *id = "$Id: lpytab.c,v 1.2 1999/01/03 02:07:21 sybalsky Exp $ Copyright (C) Venue"; + +/************************************************************************/ +/* */ +/* (C) Copyright 1989-95 Venue. All Rights Reserved. */ +/* Manufactured in the United States of America. */ +/* */ +/* The contents of this file are proprietary information */ +/* belonging to Venue, and are provided to you under license. */ +/* They may not be further distributed or disclosed to third */ +/* parties without the specific permission of Venue. */ +/* */ +/************************************************************************/ + +#include "version.h" + +#ifndef BIGATOMS + +#define VAR 257 +#define CONS 258 +#define SIGN 259 +#define AR_M_OP 260 +#define RE_OP 261 +#define END_C 262 +#define COMMA 263 +#define COLON 264 +#define MINIMISE 265 +#define MAXIMISE 266 + +#line 10 "lp.y" +#include "lpdefines.h" +#include "lpglobals.h" + +/* globals */ +char Last_var[NAMELEN]; +char Constraint_name[NAMELEN]; +int Lin_term_count; +double f; +int x; +int Sign; +int isign; /* internal_sign variable to make sure nothing goes wrong */ +/* with lookahead */ +int make_neg; /* is true after the relational operator is seen in order */ +/* to remember if lin_term stands before or after re_op */ +#define yyclearin yychar = -1 +#define yyerrok yyerrflag = 0 +extern int yychar; +extern int yyerrflag; +#ifndef YYMAXDEPTH +#define YYMAXDEPTH 150 +#endif +#ifndef YYSTYPE +#define YYSTYPE int +#endif +YYSTYPE yylval, yyval; +typedef int yytabelem; +#define YYERRCODE 256 + +#line 193 "lp.y" + +#include "lexyy.c" +yytabelem yyexca[] = { + -1, 1, 0, -1, -2, 0, -1, 31, 257, 15, -2, 31, +}; +#define YYNPROD 38 +#define YYLAST 87 +yytabelem yyact[] = { + + 10, 11, 9, 34, 36, 51, 56, 57, 5, 4, 50, 52, 23, 44, 36, 24, 35, 10, 20, 18, 26, 10, + 20, 27, 31, 20, 18, 10, 11, 9, 15, 20, 18, 10, 11, 42, 40, 17, 14, 16, 19, 32, 13, 8, + 6, 8, 8, 38, 25, 21, 22, 7, 47, 37, 43, 29, 33, 30, 46, 45, 28, 12, 3, 2, 1, 0, + 39, 0, 0, 0, 0, 0, 41, 0, 0, 48, 0, 0, 0, 49, 0, 0, 0, 0, 53, 55, 54}; +yytabelem yypact[] = { + + -1000, -1000, -257, -227, -230, -230, -1000, -247, -1000, -1000, -1000, -237, + -233, -1000, -1000, -261, -245, -1000, -1000, -1000, -237, -1000, -1000, -1000, + -1000, -224, -1000, -221, -1000, -1000, -222, -261, -1000, -244, -1000, -1000, + -1000, -236, -224, -1000, -1000, -1000, -1000, -252, -1000, -240, -240, -236, + -1000, -1000, -1000, -1000, -251, -1000, -255, -1000, -1000, -1000}; +yytabelem yypgo[] = { + + 0, 64, 63, 62, 61, 60, 42, 38, 59, 39, 58, 57, 41, 56, 54, 37, 53, 52, 40, 51, 48, 47, 44}; +yytabelem yyr1[] = { + + 0, 2, 1, 4, 4, 6, 8, 6, 10, 7, 5, 5, 11, 11, 12, 13, 14, 14, 14, + 9, 16, 9, 17, 9, 15, 15, 19, 20, 19, 21, 19, 18, 18, 18, 3, 3, 3, 22}; +yytabelem yyr2[] = { + + 0, 1, 8, 2, 4, 2, 1, 8, 1, 11, 0, 2, 2, 4, 7, 3, 3, 5, 7, + 2, 1, 6, 1, 8, 2, 3, 2, 1, 6, 1, 8, 3, 5, 7, 5, 5, 2, 5}; +yytabelem yychk[] = { + + -1000, -1, -2, -3, 266, 265, -22, -19, -18, 259, 257, 258, -4, -6, -7, + 257, -9, -15, 259, -18, 258, -22, -22, 259, 262, -20, 257, 260, -5, -6, + -11, 257, -12, -13, 264, 261, 259, -16, -21, -18, 257, -12, 257, -14, 257, + -8, -10, -17, -15, -18, 262, 257, 263, -7, -9, -15, 257, 262}; +yytabelem yydef[] = { + + 1, -2, 0, 0, 0, 0, 36, 0, 26, 27, 31, 0, 10, 3, 5, 31, 0, 19, 20, 24, + 25, 34, 35, 29, 37, 0, 32, 0, 2, 4, 11, -2, 12, 0, 6, 8, 22, 0, 0, 28, + 33, 13, 15, 0, 16, 0, 0, 0, 21, 30, 14, 17, 0, 7, 0, 23, 18, 9}; +typedef struct { + char *t_name; + int t_val; +} yytoktype; +#ifndef YYDEBUG +#define YYDEBUG 0 /* don't allow debugging */ +#endif + +#if YYDEBUG + +yytoktype yytoks[] = { + "VAR", 257, "CONS", 258, "SIGN", 259, "AR_M_OP", 260, "RE_OP", 261, "END_C", 262, + "COMMA", 263, "COLON", 264, "MINIMISE", 265, "MAXIMISE", 266, "-unknown-", -1 /* ends search */ +}; + +char *yyreds[] = { + "-no such reduction-", + "inputfile : /* empty */", + "inputfile : objective_function constraints int_declarations", + "constraints : constraint", + "constraints : constraints constraint", + "constraint : real_constraint", + "constraint : VAR COLON", + "constraint : VAR COLON real_constraint", + "real_constraint : x_lineair_sum RE_OP", + "real_constraint : x_lineair_sum RE_OP x_lineair_sum END_C", + "int_declarations : /* empty */", + "int_declarations : real_int_decls", + "real_int_decls : int_declaration", + "real_int_decls : real_int_decls int_declaration", + "int_declaration : int_declarator vars END_C", + "int_declarator : VAR", + "vars : VAR", + "vars : vars VAR", + "vars : vars COMMA VAR", + "x_lineair_sum : x_lineair_term", + "x_lineair_sum : SIGN", + "x_lineair_sum : SIGN x_lineair_term", + "x_lineair_sum : x_lineair_sum SIGN", + "x_lineair_sum : x_lineair_sum SIGN x_lineair_term", + "x_lineair_term : lineair_term", + "x_lineair_term : CONS", + "lineair_sum : lineair_term", + "lineair_sum : SIGN", + "lineair_sum : SIGN lineair_term", + "lineair_sum : lineair_sum SIGN", + "lineair_sum : lineair_sum SIGN lineair_term", + "lineair_term : VAR", + "lineair_term : CONS VAR", + "lineair_term : CONS AR_M_OP VAR", + "objective_function : MAXIMISE real_of", + "objective_function : MINIMISE real_of", + "objective_function : real_of", + "real_of : lineair_sum END_C", +}; +#endif /* YYDEBUG */ +/* + * Copyright 1987 Silicon Graphics, Inc. - All Rights Reserved + */ + +#ident "$Revision: 1.2 $" + +/* +** Skeleton parser driver for yacc output +*/ + +/* +** yacc user known macros and defines +*/ +#define YYERROR goto yyerrlab +#define YYACCEPT return (0) +#define YYABORT return (1) +#define YYBACKUP(newtoken, newvalue) \ + \ +{ \ + if (yychar >= 0 || (yyr2[yytmp] >> 1) != 1) { \ + yyerror("syntax error - cannot backup"); \ + goto yyerrlab; \ + } \ + yychar = newtoken; \ + yystate = *yyps; \ + yylval = newvalue; \ + goto yynewstate; \ + \ +} +#define YYRECOVERING() (!!yyerrflag) +#ifndef YYDEBUG +#define YYDEBUG 1 /* make debugging available */ +#endif + +/* +** user known globals +*/ +int yydebug; /* set to 1 to get debugging */ + +/* +** driver internal defines +*/ +#define YYFLAG (-1000) + +/* +** global variables used by the parser +*/ +YYSTYPE yyv[YYMAXDEPTH]; /* value stack */ +int yys[YYMAXDEPTH]; /* state stack */ + +YYSTYPE *yypv; /* top of value stack */ +int *yyps; /* top of state stack */ + +int yystate; /* current state */ +int yytmp; /* extra var (lasts between blocks) */ + +int yynerrs; /* number of errors */ +int yyerrflag; /* error recovery flag */ +int yychar; /* current input token number */ + +/* +** yyparse - return 0 if worked, 1 if syntax error not recovered from +*/ +int yyparse() { + register YYSTYPE *yypvt; /* top of value stack for $vars */ + + /* + ** Initialize externals - yyparse may be called more than once + */ + yypv = &yyv[-1]; + yyps = &yys[-1]; + yystate = 0; + yytmp = 0; + yynerrs = 0; + yyerrflag = 0; + yychar = -1; + + goto yystack; + { + register YYSTYPE *yy_pv; /* top of value stack */ + register int *yy_ps; /* top of state stack */ + register int yy_state; /* current state */ + register int yy_n; /* internal state number info */ + + /* + ** get globals into registers. + ** branch to here only if YYBACKUP was called. + */ + yynewstate: + yy_pv = yypv; + yy_ps = yyps; + yy_state = yystate; + goto yy_newstate; + + /* + ** get globals into registers. + ** either we just started, or we just finished a reduction + */ + yystack: + yy_pv = yypv; + yy_ps = yyps; + yy_state = yystate; + + /* + ** top of for (;;) loop while no reductions done + */ + yy_stack: +/* +** put a state and value onto the stacks +*/ +#if YYDEBUG + /* + ** if debugging, look up token value in list of value vs. + ** name pairs. 0 and negative (-1) are special values. + ** Note: linear search is used since time is not a real + ** consideration while debugging. + */ + if (yydebug) { + register int yy_i; + + printf("State %d, token ", yy_state); + if (yychar == 0) + printf("end-of-file\n"); + else if (yychar < 0) + printf("-none-\n"); + else { + for (yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++) { + if (yytoks[yy_i].t_val == yychar) break; + } + printf("%s\n", yytoks[yy_i].t_name); + } + } +#endif /* YYDEBUG */ + if (++yy_ps >= &yys[YYMAXDEPTH]) /* room on stack? */ + { + yyerror("yacc stack overflow"); + YYABORT; + } + *yy_ps = yy_state; + *++yy_pv = yyval; + + /* + ** we have a new state - find out what to do + */ + yy_newstate: + if ((yy_n = yypact[yy_state]) <= YYFLAG) goto yydefault; /* simple state */ +#if YYDEBUG + /* + ** if debugging, need to mark whether new token grabbed + */ + yytmp = yychar < 0; +#endif + if ((yychar < 0) && ((yychar = yylex()) < 0)) yychar = 0; /* reached EOF */ +#if YYDEBUG + if (yydebug && yytmp) { + register int yy_i; + + printf("Received token "); + if (yychar == 0) + printf("end-of-file\n"); + else if (yychar < 0) + printf("-none-\n"); + else { + for (yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++) { + if (yytoks[yy_i].t_val == yychar) break; + } + printf("%s\n", yytoks[yy_i].t_name); + } + } +#endif /* YYDEBUG */ + if (((yy_n += yychar) < 0) || (yy_n >= YYLAST)) goto yydefault; + if (yychk[yy_n = yyact[yy_n]] == yychar) /*valid shift*/ + { + yychar = -1; + yyval = yylval; + yy_state = yy_n; + if (yyerrflag > 0) yyerrflag--; + goto yy_stack; + } + + yydefault: + if ((yy_n = yydef[yy_state]) == -2) { +#if YYDEBUG + yytmp = yychar < 0; +#endif + if ((yychar < 0) && ((yychar = yylex()) < 0)) yychar = 0; /* reached EOF */ +#if YYDEBUG + if (yydebug && yytmp) { + register int yy_i; + + printf("Received token "); + if (yychar == 0) + printf("end-of-file\n"); + else if (yychar < 0) + printf("-none-\n"); + else { + for (yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++) { + if (yytoks[yy_i].t_val == yychar) { break; } + } + printf("%s\n", yytoks[yy_i].t_name); + } + } +#endif /* YYDEBUG */ + /* + ** look through exception table + */ + { + register int *yyxi = yyexca; + + while ((*yyxi != -1) || (yyxi[1] != yy_state)) { yyxi += 2; } + while ((*(yyxi += 2) >= 0) && (*yyxi != yychar)) + ; + if ((yy_n = yyxi[1]) < 0) YYACCEPT; + } + } + + /* + ** check for syntax error + */ + if (yy_n == 0) /* have an error */ + { + /* no worry about speed here! */ + switch (yyerrflag) { + case 0: /* new error */ + yyerror("syntax error"); + goto skip_init; + yyerrlab: + /* + ** get globals into registers. + ** we have a user generated syntax type error + */ + yy_pv = yypv; + yy_ps = yyps; + yy_state = yystate; + yynerrs++; + skip_init: + case 1: + case 2: /* incompletely recovered error */ + /* try again... */ + yyerrflag = 3; + /* + ** find state where "error" is a legal + ** shift action + */ + while (yy_ps >= yys) { + yy_n = yypact[*yy_ps] + YYERRCODE; + if (yy_n >= 0 && yy_n < YYLAST && yychk[yyact[yy_n]] == YYERRCODE) { + /* + ** simulate shift of "error" + */ + yy_state = yyact[yy_n]; + goto yy_stack; + } +/* +** current state has no shift on +** "error", pop stack +*/ +#if YYDEBUG +#define _POP_ "Error recovery pops state %d, uncovers state %d\n" + if (yydebug) printf(_POP_, *yy_ps, yy_ps[-1]); +#undef _POP_ +#endif + yy_ps--; + yy_pv--; + } + /* + ** there is no state on stack with "error" as + ** a valid shift. give up. + */ + YYABORT; + case 3: /* no shift yet; eat a token */ +#if YYDEBUG + /* + ** if debugging, look up token in list of + ** pairs. 0 and negative shouldn't occur, + ** but since timing doesn't matter when + ** debugging, it doesn't hurt to leave the + ** tests here. + */ + if (yydebug) { + register int yy_i; + + printf("Error recovery discards "); + if (yychar == 0) + printf("token end-of-file\n"); + else if (yychar < 0) + printf("token -none-\n"); + else { + for (yy_i = 0; yytoks[yy_i].t_val >= 0; yy_i++) { + if (yytoks[yy_i].t_val == yychar) { break; } + } + printf("token %s\n", yytoks[yy_i].t_name); + } + } +#endif /* YYDEBUG */ + if (yychar == 0) /* reached EOF. quit */ + YYABORT; + yychar = -1; + goto yy_newstate; + } + } /* end if ( yy_n == 0 ) */ +/* +** reduction by production yy_n +** put stack tops, etc. so things right after switch +*/ +#if YYDEBUG + /* + ** if debugging, print the string that is the user's + ** specification of the reduction which is just about + ** to be done. + */ + if (yydebug) printf("Reduce by (%d) \"%s\"\n", yy_n, yyreds[yy_n]); +#endif + yytmp = yy_n; /* value to switch over */ + yypvt = yy_pv; /* $vars top of value stack */ + /* + ** Look in goto table for next state + ** Sorry about using yy_state here as temporary + ** register variable, but why not, if it works... + ** If yyr2[ yy_n ] doesn't have the low order bit + ** set, then there is no action to be done for + ** this reduction. So, no saving & unsaving of + ** registers done. The only difference between the + ** code just after the if and the body of the if is + ** the goto yy_stack in the body. This way the test + ** can be made before the choice of what to do is needed. + */ + { + /* length of production doubled with extra bit */ + register int yy_len = yyr2[yy_n]; + + if (!(yy_len & 01)) { + yy_len >>= 1; + yyval = (yy_pv -= yy_len)[1]; /* $$ = $1 */ + yy_state = yypgo[yy_n = yyr1[yy_n]] + *(yy_ps -= yy_len) + 1; + if (yy_state >= YYLAST || yychk[yy_state = yyact[yy_state]] != -yy_n) { + yy_state = yyact[yypgo[yy_n]]; + } + goto yy_stack; + } + yy_len >>= 1; + yyval = (yy_pv -= yy_len)[1]; /* $$ = $1 */ + yy_state = yypgo[yy_n = yyr1[yy_n]] + *(yy_ps -= yy_len) + 1; + if (yy_state >= YYLAST || yychk[yy_state = yyact[yy_state]] != -yy_n) { + yy_state = yyact[yypgo[yy_n]]; + } + } + /* save until reenter driver code */ + yystate = yy_state; + yyps = yy_ps; + yypv = yy_pv; + } + /* + ** code supplied by user is placed in this switch + */ + switch (yytmp) { + case 1: +#line 32 "lp.y" + { + init_read(); + isign = 0; + make_neg = 0; + } break; + case 6: +#line 49 "lp.y" + { + add_constraint_name(Last_var, Rows); + } break; + case 8: +#line 58 "lp.y" + { + store_re_op(); + make_neg = 1; + } break; + case 9: +#line 64 "lp.y" + { + if (Lin_term_count == 0) { + fprintf(stderr, "WARNING line %d: constraint contains no variables\n", yylineno); + null_tmp_store(); + } + + if (Lin_term_count > 1) Rows++; + + if (Lin_term_count == 1) store_bounds(); + + Lin_term_count = 0; + isign = 0; + make_neg = 0; + Constraint_name[0] = '\0'; + } break; + case 14: +#line 93 "lp.y" + { + Having_ints = 1; + } break; + case 15: +#line 96 "lp.y" + { /* check_decl(yytext);*/ + } break; + case 16: +#line 99 "lp.y" + { + add_int_var((char *)yytext); + } break; + case 17: +#line 100 "lp.y" + { + add_int_var((char *)yytext); + } break; + case 18: +#line 101 "lp.y" + { + add_int_var((char *)yytext); + } break; + case 20: +#line 106 "lp.y" + { + isign = Sign; + } break; + case 22: +#line 112 "lp.y" + { + isign = Sign; + } break; + case 25: +#line 120 "lp.y" + { + if ((isign || !make_neg) && !(isign && !make_neg)) /* but not both! */ + f = -f; + rhs_store(f); + isign = 0; + } break; + case 27: +#line 131 "lp.y" + { + isign = Sign; + } break; + case 29: +#line 137 "lp.y" + { + isign = Sign; + } break; + case 31: +#line 144 "lp.y" + { + if ((isign || make_neg) && !(isign && make_neg)) /* but not both! */ + var_store(Last_var, Rows, (double)-1); + else + var_store(Last_var, Rows, (double)1); + isign = 0; + } break; + case 32: +#line 154 "lp.y" + { + if ((isign || make_neg) && !(isign && make_neg)) /* but not both! */ + f = -f; + var_store(Last_var, Rows, f); + isign = 0; + } break; + case 33: +#line 164 "lp.y" + { + if ((isign || make_neg) && !(isign && make_neg)) /* but not both! */ + f = -f; + var_store(Last_var, Rows, f); + isign = 0; + } break; + case 34: +#line 174 "lp.y" + { + Maximise = TRUE; + } break; + case 35: +#line 178 "lp.y" + { + Maximise = FALSE; + } break; + case 37: +#line 186 "lp.y" + { + Rows++; + Lin_term_count = 0; + isign = 0; + make_neg = 0; + } break; + } + goto yystack; /* reset registers in driver code */ +} +#endif diff --git a/src/mouseif.c b/src/mouseif.c index a1b6a4f..26061a7 100644 --- a/src/mouseif.c +++ b/src/mouseif.c @@ -1,125 +1,125 @@ -/* $Id: mouseif.c,v 1.2 1999/01/03 02:07:26 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved - */ -static char *id = "$Id: mouseif.c,v 1.2 1999/01/03 02:07:26 sybalsky Exp $ Copyright (C) Venue"; - -/************************************************************************/ -/* */ -/* (C) Copyright 1989, 1990, 1990, 1991, 1992, 1993, 1994, 1995 Venue. */ -/* All Rights Reserved. */ -/* Manufactured in the United States of America. */ -/* */ -/* The contents of this file are proprietary information */ -/* belonging to Venue, and are provided to you under license. */ -/* They may not be further distributed or disclosed to third */ -/* parties without the specific permission of Venue. */ -/* */ -/************************************************************************/ - -/* * * * D O S M O U S E I N T E R F A C E * * * */ - -#include "version.h" - -#include "lispemul.h" -#include "dbprint.h" -#include "devif.h" - -MouseInterfaceRec _curmouse; -MouseInterface currentmouse = &_curmouse; - -#ifdef DOS -#include - -int nomouseflag = FALSE; -extern DLword *Lisp_world; -extern LispPTR *LASTUSERACTION68k; -extern int twobuttonflag; - -extern void EnterDosMouse(); -extern void ExitDosMouse(); -extern void DosMouseAfterRaid(); -extern void DosMouseBeforeRaid(); -extern unsigned long GenericReturnT(); -extern void ThreeButtonHandler(); -extern void TwoButtonHandler(); -#endif /* DOS */ - -/*****************************************************************/ -/* p r o b e m o u s e */ -/* */ -/* Probe for mouse and return the number of buttons available. */ -/*****************************************************************/ -int probemouse() { - union REGS regs; - char c; - /*************************************************************************** - * Reset mouse driver, exit if no mouse driver present - ***************************************************************************/ - /* int 33h, case 0000, ax = drive installed, bx = # of buttons. */ - if (nomouseflag) { - return (666); /* return something, why not 666? */ - } else { - regs.w.eax = 0; /* Func 0 = Reset mouse, ret. button info */ - int86(0x33, ®s, ®s); - - if (regs.x.ax == 0x0000) VESA_errorexit("No mouse driver found.", -1); - return (regs.x.bx); - } -} - -void make_mouse_instance(MouseInterface mouse) -{ -#ifdef DOS - - int NumberOfButtons; - if (nomouseflag) { - mouse->device.enter = &GenericReturnT; - mouse->device.exit = &GenericReturnT; - mouse->device.before_raid = &GenericReturnT; - mouse->device.after_raid = &GenericReturnT; - mouse->device.active = FALSE; - NumberOfButtons = 3; - } else { - mouse->device.enter = &EnterDosMouse; - mouse->device.exit = &ExitDosMouse; - mouse->device.before_raid = &DosMouseBeforeRaid; - mouse->device.after_raid = &DosMouseAfterRaid; - mouse->device.active = FALSE; - NumberOfButtons = probemouse(); - } - mouse->Button.StartTime = 2; - - mouse->Cursor.Last.width = 16; - mouse->Cursor.Last.height = 16; - - if (nomouseflag == FALSE) { - if (twobuttonflag) { /* We force two button handling. */ - mouse->Handler = &TwoButtonHandler; - mouse->Button.TwoButtonP = TRUE; - } else /* Determine how many buttons we have. */ - switch (NumberOfButtons) { - case 0x0000: /* Other than 2 buttons, assume three */ - mouse->Button.TwoButtonP = FALSE; - mouse->Handler = &ThreeButtonHandler; - break; - case 0x0002: /* Two buttons. */ - mouse->Button.TwoButtonP = TRUE; - mouse->Handler = &TwoButtonHandler; - break; - case 0x0003: /* Three buttons. */ - mouse->Button.TwoButtonP = FALSE; - mouse->Handler = &ThreeButtonHandler; - break; - case 0xffff: /* Two buttons. */ - mouse->Button.TwoButtonP = TRUE; - mouse->Handler = &TwoButtonHandler; - break; - default: /* Strange case, assume three. */ - mouse->Button.TwoButtonP = FALSE; - mouse->Handler = &ThreeButtonHandler; - break; - } - } -/* mouse->timestamp = ((*LASTUSERACTION68k& 0xffffff) + Lisp_world); */ -#elif XWINDOW -#endif /* DOS or XWINDOW */ -} +/* $Id: mouseif.c,v 1.2 1999/01/03 02:07:26 sybalsky Exp $ (C) Copyright Venue, All Rights Reserved + */ +static char *id = "$Id: mouseif.c,v 1.2 1999/01/03 02:07:26 sybalsky Exp $ Copyright (C) Venue"; + +/************************************************************************/ +/* */ +/* (C) Copyright 1989, 1990, 1990, 1991, 1992, 1993, 1994, 1995 Venue. */ +/* All Rights Reserved. */ +/* Manufactured in the United States of America. */ +/* */ +/* The contents of this file are proprietary information */ +/* belonging to Venue, and are provided to you under license. */ +/* They may not be further distributed or disclosed to third */ +/* parties without the specific permission of Venue. */ +/* */ +/************************************************************************/ + +/* * * * D O S M O U S E I N T E R F A C E * * * */ + +#include "version.h" + +#include "lispemul.h" +#include "dbprint.h" +#include "devif.h" + +MouseInterfaceRec _curmouse; +MouseInterface currentmouse = &_curmouse; + +#ifdef DOS +#include + +int nomouseflag = FALSE; +extern DLword *Lisp_world; +extern LispPTR *LASTUSERACTION68k; +extern int twobuttonflag; + +extern void EnterDosMouse(); +extern void ExitDosMouse(); +extern void DosMouseAfterRaid(); +extern void DosMouseBeforeRaid(); +extern unsigned long GenericReturnT(); +extern void ThreeButtonHandler(); +extern void TwoButtonHandler(); +#endif /* DOS */ + +/*****************************************************************/ +/* p r o b e m o u s e */ +/* */ +/* Probe for mouse and return the number of buttons available. */ +/*****************************************************************/ +int probemouse() { + union REGS regs; + char c; + /*************************************************************************** + * Reset mouse driver, exit if no mouse driver present + ***************************************************************************/ + /* int 33h, case 0000, ax = drive installed, bx = # of buttons. */ + if (nomouseflag) { + return (666); /* return something, why not 666? */ + } else { + regs.w.eax = 0; /* Func 0 = Reset mouse, ret. button info */ + int86(0x33, ®s, ®s); + + if (regs.x.ax == 0x0000) VESA_errorexit("No mouse driver found.", -1); + return (regs.x.bx); + } +} + +void make_mouse_instance(MouseInterface mouse) +{ +#ifdef DOS + + int NumberOfButtons; + if (nomouseflag) { + mouse->device.enter = &GenericReturnT; + mouse->device.exit = &GenericReturnT; + mouse->device.before_raid = &GenericReturnT; + mouse->device.after_raid = &GenericReturnT; + mouse->device.active = FALSE; + NumberOfButtons = 3; + } else { + mouse->device.enter = &EnterDosMouse; + mouse->device.exit = &ExitDosMouse; + mouse->device.before_raid = &DosMouseBeforeRaid; + mouse->device.after_raid = &DosMouseAfterRaid; + mouse->device.active = FALSE; + NumberOfButtons = probemouse(); + } + mouse->Button.StartTime = 2; + + mouse->Cursor.Last.width = 16; + mouse->Cursor.Last.height = 16; + + if (nomouseflag == FALSE) { + if (twobuttonflag) { /* We force two button handling. */ + mouse->Handler = &TwoButtonHandler; + mouse->Button.TwoButtonP = TRUE; + } else /* Determine how many buttons we have. */ + switch (NumberOfButtons) { + case 0x0000: /* Other than 2 buttons, assume three */ + mouse->Button.TwoButtonP = FALSE; + mouse->Handler = &ThreeButtonHandler; + break; + case 0x0002: /* Two buttons. */ + mouse->Button.TwoButtonP = TRUE; + mouse->Handler = &TwoButtonHandler; + break; + case 0x0003: /* Three buttons. */ + mouse->Button.TwoButtonP = FALSE; + mouse->Handler = &ThreeButtonHandler; + break; + case 0xffff: /* Two buttons. */ + mouse->Button.TwoButtonP = TRUE; + mouse->Handler = &TwoButtonHandler; + break; + default: /* Strange case, assume three. */ + mouse->Button.TwoButtonP = FALSE; + mouse->Handler = &ThreeButtonHandler; + break; + } + } +/* mouse->timestamp = ((*LASTUSERACTION68k& 0xffffff) + Lisp_world); */ +#elif XWINDOW +#endif /* DOS or XWINDOW */ +}