home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fish 'n' More 2
/
fishmore-publicdomainlibraryvol.ii1991xetec.iso
/
disks
/
disk427.lzh
/
STV
/
source
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-09
|
7KB
|
237 lines
/*********************************
* MAIN 01/02/91
* Source file for STV
* © Copyright 1990 Timm Martin
* All Rights Reserved Worldwide
**********************************/
/*
WW WW WW AAAA RRRRR NN NN II NN NN GGGGG
WW WW WW AA AA RR RR NNN NN II NNN NN GG XX
WW WW WW AA AA RRRRR NNNNNN II NNNNNN GG GGG
WW WW WW AAAAAA RR RR NN NNN II NN NNN GG GG XX
WWWWWW AA AA RR RR NN NN II NN NN GGGGG
The program STV, this source file, and all related source
files are © Copyright 1990 by Timm Martin. All rights are
reserved worldwide. This program itself is freeware.
It may be distributed alone or in conjunction with any
program, commercial or otherwise, with no compensation to
the author. The source files may also be freely distributed
but cannot appear in any commercial product without permission
from the author.
*/
#include <ctype.h>
#include <exec/types.h>
#include <functions.h>
#include <graphics/text.h>
#include <intuition/intuition.h>
#include <stdlib.h>
#include <stdio.h>
#include <workbench/startup.h>
#include <workbench/workbench.h>
#include "func.h"
#include "main.h"
/********************
* GLOBAL VARIABLES
*********************/
/* whether this program was run from the CLI or Workbench */
BOOL from_cli;
/* if running under WB 2.x */
BOOL wb2;
struct GfxBase * GfxBase = NULL;
extern struct Library * IconBase = NULL;
struct IntuitionBase * IntuitionBase = NULL;
/*************
* ARGUMENTS
**************/
struct Argument arguments = /* GLOBAL */
{
/* short Files */ 0,
/* char * Names[] */ NULL,
/* struct WBArg * ArgList */ NULL,
/* short Left */ NO_ARGUMENT,
/* short Top */ NO_ARGUMENT,
/* short Width */ NO_ARGUMENT,
/* short Height */ NO_ARGUMENT,
/* short TextColor */ WHITE,
/* struct Screen * Screen */ NULL,
};
/***********
* M A I N
************/
/*
This procedure runs the program. If the user specified at least one file to
be read, the libraries and window will be opened and the first file will be
displayed. If the user didn't specify any file or if [s]he requested help, a
"USAGE" message will be displayed and the program will end.
*/
void main( int argc, char *argv[] )
{
if (parse_arguments( argc, argv ))
{
program_begin();
file_select();
}
else
printf( "USAGE: stv file [file...]\n" );
program_end( NULL );
}
/*******************
* PARSE ARGUMENTS
********************/
/*
This function parses the programs arguments whether run from the CLI or
Workbench. These arguments can include the name[s] of the file[s] to be
viewed, the left edge (-l), top edge (-t), width (-w), and height
(-h) of the window, the text color (-c), and a pointer to the custom screen
(-!) in which the window should be opened. File names are listed as is, and
special values are listed as ASCII decimal numbers preceeded by a hyphen and
a keyletter. YES is returned if there is a file to read. NO is returned if
there is no file or if the user requested help (a "USAGE" message) as
indicated by specifying no arguments or a question mark as the first argument.
*/
/* the first WB argument passed is this program and must be ignored */
#define WBSTART 1
BOOL parse_arguments( int argc, char *argv[] )
{
int a; /* which CLI argument working on */
struct DiskObject *obj;
char *type; /* tool type */
long value; /* long integer value of CLI argument */
extern struct WBStartup *WBenchMsg;
/* if run from the CLI (set flag, too) and user doesn't want help */
if (from_cli = argc > 0)
{
/* if not asking for help */
if (*argv[1] != '?')
{
/* check out each argument */
for (a = 1; a < argc; a++)
{
/* is a keyletter, not a file name */
if (*argv[a] == '-')
{
/* get integer value of this argument (starts at third char) */
value = atol( argv[a]+2 );
/* convert keyletter to lower case */
tolower( *(argv[a]+1) );
/* which keyletter is it? */
switch( *(argv[a]+1) )
{
case 'l': arguments.Left = value; break;
case 't': arguments.Top = value; break;
case 'w': arguments.Width = value; break;
case 'h': arguments.Height = value; break;
case 'c': arguments.TextColor = value; break;
case '!': arguments.Screen = (struct Screen *)value; break;
}
}
/* else this is a file; copy file names into beginning of argument
* array so that all filenames are located between 0..files-1
*/
else
argv[arguments.Files++] = argv[a];
} /* for each argument */
/* get pointer to argument names */
arguments.Names = argv;
} /* if not asking for help */
} /* if run from the CLI */
/* else run from the Workbench */
else if (IconBase = OpenLibrary( "icon.library", NULL ))
{
/* don't count the program itself */
if (WBenchMsg->sm_NumArgs > WBSTART)
{
arguments.Files = WBenchMsg->sm_NumArgs - WBSTART;
arguments.ArgList = (struct WBArg *)&WBenchMsg->sm_ArgList[WBSTART];
CurrentDir( (struct FileLock *)WBenchMsg->sm_ArgList[WBSTART].wa_Lock );
if (obj = GetDiskObject( WBenchMsg->sm_ArgList[WBSTART].wa_Name ))
{
if (type = FindToolType( obj->do_ToolTypes, "LEFT" ))
arguments.Left = atol( type );
if (type = FindToolType( obj->do_ToolTypes, "TOP" ))
arguments.Top = atol( type );
if (type = FindToolType( obj->do_ToolTypes, "WIDTH" ))
arguments.Width = atol( type );
if (type = FindToolType( obj->do_ToolTypes, "HEIGHT" ))
arguments.Height = atol( type );
if (type = FindToolType( obj->do_ToolTypes, "COLOR" ))
arguments.TextColor = atol( type );
FreeDiskObject( obj );
}
}
CloseLibrary( IconBase );
}
return (arguments.Files > 0);
}
/*****************
* PROGRAM BEGIN
******************/
/*
This procedure starts the program, opens the libraries, etc.
*/
void program_begin( void )
{
if (IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 36L ))
wb2 = YES;
else if (IntuitionBase = (struct IntuitionBase *)
OpenLibrary( "intuition.library", 34L ))
wb2 = NO;
else
program_end( "intuition" );
if (!(GfxBase = (struct GfxBase *)
OpenLibrary( "graphics.library", NULL )))
program_end( "graphics" );
pointer_open();
window_open();
}
/***************
* PROGRAM END
****************/
/*
This procedure ends the program, closes things up, and exits.
*/
void program_end( char *error )
{
if (from_cli && error)
printf( "STV failed: %s\n", error );
window_close();
pointer_close();
if (GfxBase) CloseLibrary( GfxBase );
if (IntuitionBase) CloseLibrary( IntuitionBase );
exit( 0 );
}