home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GRIPS 2: Government Rast…rocessing Software & Data
/
GRIPS_2.cdr
/
dos
/
imdisp
/
source
/
browse.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-04
|
12KB
|
336 lines
/*************************************************************/
/* Copyright (C) 1989, California Institute of Technology */
/* U. S. Government Sponsorship under NASA Contract */
/* NAS7-918 is acknowledged. */
/*************************************************************/
/* * * * INCLUDE files * * * */
#include <conio.h>
#include <ctype.h>
#include <direct.h>
#include <dos.h>
#include <direct.h>
#include <io.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "imdef.h"
#include "imdisp.h"
#include "dispio.h"
#include "disputil.h"
#include "fileio.h"
#include "refresh.h"
/* * * * External functions * * * */
/* * * * Function declarations * * * */
int DoBrowse (void);
int Browse (void);
int Add_Browse (char *);
/**************************************************************************/
/* 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 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];
int i, flag;
int end;
int select_flag;
int file_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;
}
/* Retrieve all the options the user typed in */
GetKeywordInteger(CommandString, "SIZ", dispns, &size, &flag);
GetKeywordInteger(CommandString, "SUB", 1, &sub, &flag);
GetKeywordString (CommandString, "NOL", "",label, &labflag);
GetKeywordString (CommandString, "BRO", "*.*",filename,&flag);
GetKeywordString (CommandString, "ALL", "",label, &all_flag);
GetKeywordString (CommandString, "PAU", "",label, &pause_flag);
GetKeywordString (CommandString, "SEL", "",label, &select_flag);
GetKeywordString (CommandString, "FIL", "",label, &file_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;
/* 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)
strcpy(filename,"*.*");
/* This might take a while, so tell the user to wait */
ClearDisplay(0);
StatusLine(0,"Please Wait, Building Browse File......");
/* If SELECT option selected, then put SELECT into browse file */
if (select_flag != -1)
fprintf(fp,"SELECT\n");
/* 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 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;
}
}
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;
}
/* 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;
}
/* 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))
fprintf(fp,"pause\n");
/* 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\n",directory,file);
if (set_flag)
fprintf(fp,"set dnlo %d dnhi %d\n",DNlow,DNhigh);
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+25,dss,file);
}
file_number++;
}