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

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

BROWSE.C contains all the routines for browsing images.
Written by Ron Baalke - 10/30/90.

***/

#define __MSC

/* * * * INCLUDE files * * * */

#include
#include
#include
#include
#include "imdef.h"
#include "imdisp.h"
#include "dispio.h"
#include "fileutil.h"
#include "keywutil.h"
#include "textutil.h"
#include "buffer.h"

/* * * * External functions * * * */

/* * * * Function declarations * * * */

int DoBrowse (void);
int Browse (void);
int Add_Browse (char *);
void Browse_Buffers(void);

/**************************************************************************/
/* These variables are purposely placed here to make them global to the */
/* browse routines, but not seen by any other routines. Since the browse */
/* routine is called recursively, and recursive routines make heavy use */
/* of the stack, there variables were made global so that the chances for */
/* of a stack overflow are reduced. Ron Baalke 10/30/90 */
/**************************************************************************/

#define PROTECT 60 /* # lines at the bottom of the screen to be */
/* protected from being overwritten by the images */

FILE *fp;
char mask[80], directory[80];
int i, file_number, sub;
int set_flag, all_flag, pause_flag;
int auto_amount, auto_stretch_flag;
int pause_value;

int dsl, dss, size, pics, across, down, labflag;
char *loc;

/*************************************************************************/
/* DoBrowse */
/* */
/* Modified extensively by Ron Baalke 10/30/90 */
/* */
/* This routine will execute the BROWSE command by building a */
/* BROWSE.CMD batch file on the user's disk (normally the C: drive), and */
/* then executing the batch file. The BROWSE command is normally used */
/* with wildcards, and if the ALL option is specified, then the all of */
/* the subdirectories are also traversed. The Browse() routine is */
/* called recursively in such a case. */
/* */
/* Four new options have been added to the BROWSE command: ALL, PAUSE */
/* SELECT and FILE. */
/* */
/* Note: some of the processing for the SELECT option is done in the */
/* DisplayImage() routine in DISPLAY.C */
/*************************************************************************/

int DoBrowse(void)
{
FILE *fp1;
char filename[80];
char label[80];
char dummy[40];
int i, flag;
int end;
int select_flag;
int file_flag;
int buffer_flag;
int done;
int protect; /* # lines at the bottom of the screen to be */
/* protected from being overwritten by the images*/

file_number = 0;
set_flag = 0;
labflag = 1;
protect = TextHeight * 4;

/* Open the browse file */

fp = fopen (BrowseName,"w");
if (fp == NULL)
{
StatusLine(0,"File can not be opened. Use SET BROWSE filename");
return(1);
}

/* Retrieve all the options the user typed in */

GetKeywordInteger(CommandString, "SIZ", dispns, &size, &flag);
GetKeywordInteger(CommandString, "SUB", 1, &sub, &flag);
GetKeywordString (CommandString, "NOL", "",dummy, &labflag);
GetKeywordString (CommandString, "BRO", "*.*",filename,&flag);
GetKeywordString (CommandString, "ALL", "",dummy, &all_flag);
GetKeywordString (CommandString, "SEL", "",dummy, &select_flag);
GetKeywordString (CommandString, "BUFFERS","", dummy, &buffer_flag);
GetKeywordString (CommandString, "FIL", "",label, &file_flag);
GetKeywordInteger(CommandString, "PAU", 0, &pause_value, &pause_flag);
GetKeywordInteger(CommandString, "LO", DNlow , &DNlow, &flag);
if (flag < 0)
GetKeywordInteger(CommandString, "DNL", DNlow , &DNlow, &flag);
if (flag > 0)
set_flag = 1;
GetKeywordInteger(CommandString, "HI", DNhigh , &DNhigh, &flag);
if (flag < 0)
GetKeywordInteger(CommandString, "DNH", DNhigh , &DNhigh, &flag);
if (flag > 0)
set_flag = 1;
GetKeywordInteger (CommandString, "AUT", 5,&auto_amount, &auto_stretch_flag);

/* make sure parameters don't get interpreted as a filemask. */

if (strncmp(filename,"SIZ",3) == 0 || strncmp(filename,"SUB", 3) == 0 ||
strncmp(filename,"LO", 2) == 0 || strncmp(filename,"DNLO",4) == 0 ||

strncmp(filename,"HI", 2) == 0 || strncmp(filename,"DNHI",4) == 0 ||
strncmp(filename,"NOL",3) == 0 || strncmp(filename,"ALL", 3) == 0 ||
strncmp(filename,"PAU",3) == 0 || strncmp(filename,"SEL", 3) == 0 ||
strncmp(filename,"FIL",3) == 0 || strncmp(filename,"AUT", 3) == 0)
strcpy(filename,"*.*");

/* This might take a while, so tell the user to wait */
ClearDisplay(0);
StatusLine(0,"Please Wait, Building Browse File......");

/* Calculate the variables used for the placement of the images
on the screen */

across = dispns/size;
if (across == 0)
across = 1;
down = (dispnl-protect)/size;
if (down == 0)
down = 1;
pics = across * down;

if (buffer_flag != -1)
{
Browse_Buffers();
fclose(fp); /* Close batch file and then execute it */
strcpy(CommandString,"BATCH ");
strcat(CommandString,BrowseName);
ClearDisplay(0);
DoBatch();
return(0);
}

/* If SELECT option selected, then put SELECT into browse file */

if (select_flag != -1)
fprintf(fp,"SELECT\n");


/* If FILE option is selected, then attempt to open the file
specified by the user */

if (file_flag == 1)
{
fp1 = fopen(label,"r");
if (fp1 == NULL)
{
StatusLine(0,"File can not be opened.");
fclose(fp);
return(1);
}
}

done = FALSE;
while (!done)
{
/* If FILE option, read in the filename */

if (file_flag == 1)
fscanf(fp1,"%s",filename);

/* Attempt to move to the directory where the file resides */

flag = ChangeDir(filename);
if (flag != 0)
{
StatusLine(0,"Bad Pathname, Try Again");
fclose(fp);
if (file_flag == 1) fclose(fp1);
return(1);
}

/* Extract out the filename portion to use as the mask */

strcpy(mask,filename);
end = strlen(filename) - 1;
for (i=end; i > 0; i--)
{
if ((strnicmp(&filename[i],"\\",1) == 0) ||
(strnicmp(&filename[i],":",1) == 0))
{
strncpy(&mask[0],&filename[i+1],end-i);
mask[end-i] = '\0';
break;
}
}

/* Find all the files matching the mask. Browse() is a recursive routine*/

Browse();

if ((file_flag != 1) ||
((file_flag == 1) && (feof(fp1)))) done = TRUE;

} /* end while loop */

/* If no files are found, then tell the user and exit */

if (file_number == 0)
{
StatusLine(0,"No files found for browse file specification.");
fclose(fp);
if (file_flag == 1) fclose(fp1);
return(1);
}

/* Close batch file and then execute it */

fclose(fp);
if (file_flag == 1) fclose(fp1);
strcpy(CommandString,"BATCH ");
strcat(CommandString,BrowseName);
ClearDisplay(0);
DoBatch();
}

/***************************************************************************/
/* Browse */
/* */
/* Written by Ron Baalke 10/30/90 */
/* */
/* This routine is a recursive routine that will find all of the files */
/* matching the mask and then write them out to the browse batch file. */
/* The recursive part is used to traverse through all of the */
/* subdirectories if the ALL option is selected. The _dos_findfirst & */
/* _dos_findnext routines are used to find the files matching the mask, */
/* and are also used to find the subdirectories. */
/***************************************************************************/
int Browse()
{
struct find_t fileinfo;

/* Find the first file matching the mask in the current directory */

if (!_dos_findfirst(mask, 0, &fileinfo))
{
getcwd(directory,80);
StatusLine(1,directory);
fprintf(fp,"text line %d samp 1 \'%-s\'\n",
dispnl-(TextHeight+12),directory);
Add_Browse(fileinfo.name); /* Add to browse batch file */

while (!_dos_findnext(&fileinfo)) /* Find the remaining files */
{
Add_Browse(fileinfo.name); /* Add them, too */
}
}

/* If the ALL option is selected, then parse through all of the */
/* subdirectories to find more files matching the mask */

if (all_flag != -1) /* If ALL option selected */
{
if (!_dos_findfirst("*.*", 0x10, &fileinfo))
{
if (fileinfo.attrib & _A_SUBDIR) /* Check if file is subdirectory */
{
if (fileinfo.name[0] != '.') /* Skip current & parent directory*/
{
chdir(fileinfo.name); /* Cd into directory */
Browse(); /* Look for files in this subdirectory*/
chdir(".."); /* Move back up to previous directory */
}
}

/* Do same thing for the other subdirectories */

while (!_dos_findnext(&fileinfo))
{
if (fileinfo.attrib & _A_SUBDIR)
{
if (fileinfo.name[0] != '.')
{
chdir(fileinfo.name);
Browse();
chdir("..");
}
}
}
}
}
}

/****************************************************************************/
/* Add_Browse */
/* */
/* Written by Ron Baalke 10/30/90 */
/* */
/* This routine will write out the filename to the browse batch file that */
/* the Browse() routine found. It will also determine where the image */
/* will appear on the screen, dependent on the screen size and the options */
/* the user entered in with the BROWSE command. */
/****************************************************************************/
int Add_Browse( char *file )
{
/* Calculate where image will appear on the screen */

dsl = 1+((file_number%pics)/across)*size;
dss = 1+(file_number%across)*size;

/* Process PAUSE option */

if ((pause_flag != -1) && (dsl == 1) && (dss == 1) && (file_number > 0))
{
if (pause_value == 0)
fprintf(fp,"pause\n");
else
fprintf(fp,"pause %d\n",pause_value);
}

/* Add FILE and DISP commands to the browse file */
if (strlen(directory) == 3) /* root dir, get rid of \ */
directory[2] = '\0';
fprintf(fp,"file %s\\%s nom\n",directory,file);
if (set_flag)
fprintf(fp,"set dnlo %d dnhi %d\n",DNlow,DNhigh);
if (auto_stretch_flag >= 0)
fprintf(fp,"disp dsl %d dss %d sub %d auto %d\n",dsl,dss,sub,auto_amount);
else
fprintf(fp,"disp dsl %d dss %d sub %d\n",dsl,dss,sub);

/* Put image filename on image */

if (labflag == -1) /* put image file name on image */
{
loc = strstr(file,".");
if (loc != NULL)
*loc = '\0'; /* discard extension */
fprintf(fp,"text line %d samp %d \'%s\'\n",dsl+TextHeight*2+1,dss,file);
}
file_number++;
}
/****************************************************************************/
/* Browse_Buffers */
/* */
/* Written by Ron Baalke 06/17/91 */
/* */
/* This routine will browse through the buffers and display any images */
/* found. Most of the options used with the normal BROWSE command are */
/* still applicable. */
/****************************************************************************/

void Browse_Buffers(void)
{
int i;
char letter[2];

for (i=0; i {
if (Buffers[i].location != NOWHERE)
{
/* Calculate where image will appear on the screen */

dsl = 1+((file_number%pics)/across)*size;
dss = 1+(file_number%across)*size;

/* Process PAUSE option */

if ((pause_flag != -1) && (dsl == 1) && (dss == 1) && (file_number > 0))
{
if (pause_value == 0)
fprintf(fp,"pause\n");
else
fprintf(fp,"pause %d\n",pause_value);
fprintf(fp,"pause\n");
}

/* Add DISP commands to the browse file */

if (set_flag)
fprintf(fp,"set dnlo %d dnhi %d\n",DNlow,DNhigh);
strcpy(letter,"A");
letter[0] += i;
fprintf(fp,"disp %s dsl %d dss %d sub %d\n",letter,dsl,dss,sub);

/* Put buffer name on image */

if (labflag == -1) /* put image file name on image */
{
fprintf(fp,"text line %d samp %d \'%s\'\n",dsl+TextHeight*2+1,dss,letter);
}
file_number++;
}
}
}


  3 Responses to “Category : C Source Code
Archive   : IMDSRC78.ZIP
Filename : BROWSE.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/