Category : C Source Code
Archive   : IMDSRC78.ZIP
Filename : IMDUTIL.C

 
Output of file : IMDUTIL.C contained in archive : IMDSRC78.ZIP
/*** IMDISP module IMDUTIL.C

General Purpose Utility routines Routines

Contains routines such initialization, error messages and status
checking.

Moved to separate module from IMDISP.C by A. Warnock, 1/91

***/

#define __MSC

#include
#include
#include
#include
#include
#include
#include "mshell.h"
#include "imdef.h"
#include "imdisp.h"
#include "dispio.h"
#include "imageio.h"
#include "disputil.h"
#include "fileutil.h"
#include "textutil.h"
#include "refresh.h"
#include "timer.h"
#include "buffer.h"
#include "display.h"

int StartUp (int, char **);
void FatalError (char *);
int BadStatus (char *);
int ctrl_c (void);
void Sleep (float);
void Delay (int);
void insert (int, int *);

extern unsigned char *buffer1;
extern unsigned char *buffer2;
extern unsigned char *buffer3;
extern unsigned char *buffer4;
extern unsigned char *buffer5;
extern unsigned char *buffer6;

extern unsigned char *buffer7;
extern unsigned char *outbuffer;

int StartUp (int argc, char **argv)
/* StartUp sets up some things for the main program.
The display is turned on, variables initialized, and the
welcome message is printed or the file opened instead.
*/
{
int i;
char *dot_ptr, *batchname;
char f_extension[4];
char temp[40];


if ((buffer1 = malloc(MAXDISPNS)) == NULL)
{
FatalError( "Not enough memory for pixel buffer.\n");
}

if ((buffer2 = malloc(MAXDISPNS)) == NULL)
{
FatalError( "Not enough memory for pixel buffer.\n");
}

if ((buffer3 = malloc(MAXDISPNS)) == NULL)
{
FatalError( "Not enough memory for pixel buffer.\n");
}

if ((buffer4 = malloc(MAXDISPNS)) == NULL)
{
FatalError( "Not enough memory for pixel buffer.\n");
}

if ((buffer5 = malloc(MAXDISPNS)) == NULL)
{
FatalError( "Not enough memory for pixel buffer.\n");
}

if ((buffer6 = malloc(MAXDISPNS)) == NULL)
{
FatalError( "Not enough memory for pixel buffer.\n");
}

if ((buffer7 = malloc(MAXDISPNS)) == NULL)
{
FatalError( "Not enough memory for pixel buffer.\n");
}

if ((outbuffer = malloc(MAXDISPNS)) == NULL)
{
FatalError( "Not enough memory for pixel buffer.\n");
}

InitDisplay();
thefont = -1;
Font (0);
RefreshLines = 0;
Image_Line = 1;
Image_Sample = 1;
Image_Height = dispnl;
Image_Length = dispns;
Image_Zoom = 1;
Image_Subsample = 1;
CommandPtr = 0;
CommandFlag = FALSE;
for (i=0; i strcpy(CommandList[i],"");

/* Save the starting directory */
getcwd( DefaultDir, 66);
#ifdef __TURBOC__
DefaultDrive = getdisk() + 'A';
#else
_dos_getdrive( &DefaultDrive );
#endif


for (i=0; i Buffers[i].location = NOWHERE;

OpenFileFlag = 0;
nl = 0; ns = 0; sl = 1; ss = 1; sldd = 1; ssdd = 1;
subsample = 1; zoom = 1;
centerline = -1; centersamp = -1; lastsl = 1; lastss = 1;
DNlow = 0; DNhigh = 255;
if ((batchname = getenv("IMREFRESH")) != NULL)
{
strcpy(RefreshName, batchname);
strcat(RefreshName, "REFRESH.TMP");
}
if ((batchname = getenv("IMBROWSE")) != NULL)
{
strcpy(BrowseName, batchname);
strcat(BrowseName, "BROWSE.CMD");
strcpy(SelectName, batchname);
strcat(SelectName, "IMDISP.SEL");
}
if ((batchname = getenv("IMPALETTE")) != NULL)
{
strcpy(PalettePath, batchname);
}
if (argc > 1)
{
if((dot_ptr = strpbrk(argv[1],".")) == NULL)
{
StatusLine(0,"Illegal command line entry");
}
dot_ptr++; /* Move ptr to the extension of the command file */
strncpy(f_extension, dot_ptr, 3); /* Get copy of extension */
f_extension[3] = '\0';
if (!strcmp(strupr(f_extension),"MNU"))
{
strcpy (CommandString, "MENU ");
strcat (CommandString, argv[1]);
strupr (CommandString);
DoMenu();
}
else if (!strcmp(strupr(f_extension),"CMD") ||
!strcmp(strupr(f_extension),"BAT"))
{
strcpy (CommandString, "BATCH ");
strcat (CommandString, argv[1]);
strupr (CommandString);
DoBatch();
}
else
{
/* default will make the filename an image */
strcpy (CommandString, "FILE ");
strcat (CommandString, argv[1]);
strupr (CommandString);
GetFile();
}
}
else
{
Font (0);

DrawText ("Welcome to IMDISP",
30, 50, BigChars, 0, numDN-1);
DrawText ("The Image Display Program",
50, 40, TextHeight, 0, numDN-1);
DrawText ("Version 7.8g",
72, 80, TextHeight, 0, numDN-1);
DrawText ("Use HELP SET to see display options.",
120, 10, SmallChars, 0, numDN-1);

}
RefreshLines = AllocRefresh(1);
if (argc == 1) StatusLine(1,"Type HELP for help");
}

void FatalError (char * status)
/* Switches to text mode, prints the status message and
terminates execution.
*/
{
int i;
char stat[80];

/* Deallocate any buffers */
for (i=0; i {
if (Buffers[i].location != NOWHERE)
DeallocBuffer(i);
}

/* Close up any open files */

strcpy(stat,"");
if (OpenFileFlag)
{
CloseImage (0, stat);
BadStatus (stat); /* Ron took this out? */
}

if (logflag)
{
fflush( LogFile );
fclose( LogFile );
}

for (i=0; i fclose(BatchFile[i]);

/* Deallocate refresh buffer */

FreeRefresh();
DeallocRefresh();

/* Restore the starting directory and drive */
chdir( DefaultDir );
#ifdef __TURBOC__
NumDrives = setdisk( DefaultDrive );
#else
_dos_setdrive( DefaultDrive, &NumDrives );
#endif

/* Back to text mode */
DisplayOff();
if (Mem_Used() != 0)
{
printf( "*** Memory list not empty ***\n" );
Mem_Display( stdout );
}

printf("\n%s\n", status );
exit(2);
}

int BadStatus (char * status)
/* Prints out error message if there is one.
Returns true if error.
*/

{
if (strlen(status) > 0)
{
StatusLine(0,status);
return (1);
}
else
return (0);
}

int ctrl_c(void)
/* interrupt routine. */
{
FatalError("User Aborted");
}

void Delay(int millisec)
/* Calls timer routine to delay the specified
number of milliseconds (only good to about
4 billion nanoseconds (about 1 hour) before
overflow.

Written 2/91 by A. Warnock, ST Systems Corp.
*/
{
int i;
unsigned long start, elapsed, wait_ns;

wait_ns = 1000L * (unsigned long) millisec ;
i=0;
elapsed = 0L;
time_int();
start = elaptime();
do
{
elapsed = elapsed + (unsigned long) (838L * elaptime() / 1000L) ;
} while ( elapsed < wait_ns );
}

/**************************************************************************/
/* Sleep */
/* This routine will pause by the number of seconds specified by the */
/* caller. It is accurate to 1/10 second. */
/* */
/* Originally written by Ron Baalke, December 1986 in Turbo C 1.0 */
/* Converted to Microsoft C, Februray 3, 1991. */
/**************************************************************************/

void Sleep(float num_seconds)
{
#define TICKS_PER_SECOND 18.2
int count; /* Number of clock chip counts */
union REGS regs; /* BIOS call registers */
long old_time; /* Time when routine called. */
union {
long longword;
short word[2];
} overlay;

/* Convert to clock ticks */

count = (num_seconds * TICKS_PER_SECOND);
/**************************************************************************/
/* Get current time of day */
/**************************************************************************/
regs.h.ah = 0;
int86(26, ®s, ®s);
overlay.word[0] = regs.x.dx;
overlay.word[1] = regs.x.cx;
old_time = overlay.longword;
/**************************************************************************/
/* Loop until count clock ticks have occurred. */
/**************************************************************************/
while (old_time <= overlay.longword &&
old_time > overlay.longword - count) {
regs.h.ah = 0;
int86(26, ®s, ®s);
overlay.word[0] = regs.x.dx;
overlay.word[1] = regs.x.cx;
}

return;
}


/* inserti.c - insertion sort for an array of integers */

void insert( int na, int *a)
/* na number of integers to be sorted */
/* a[] array of integers to be sorted */
{
int i , j ; /* indices for loops */
int temp ; /* holds one element of array temporarily */

for( i=1 ; i < na ; i++ )
{ /* insert the i-th element into the array */
temp = a[i] ;
j = i - 1 ;
while( ( j >= 0 ) && ( temp < a[j] ) )
{
a[j+1] = a[j] ;
j-- ;
}
a[j+1] = temp ;
}
}



  3 Responses to “Category : C Source Code
Archive   : IMDSRC78.ZIP
Filename : IMDUTIL.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/