/*Last Modified: 30-APR-1992 08:45:25.44, By: MARK */
/* ourutils.c
*
* Part of the Internet Gopher program, copyright (C) 1991
* University of Minnesota Microcomputer Workstation and Networks Center
*
*/
#include "gopher.h"
int readkey_row, readkey_col;
/*
** This procedure exits out of the curses environment and
** displays the file indicated by pathname to the screen
** using a pager command of some sort
*/
void
display_file(Filename)
char *Filename;
{
FILE *tmpfile, *fNew;
char command[MAXSTR];
char SaveName[MAXSTR];
short int ch;
int ret_status;
if (SecureMode) {
switch (ch) {
case SMG$K_TRM_LF:
case SMG$K_TRM_CR:
case SMG$K_TRM_SPACE:
break;
default:
ret_status = smg$ring_bell( &DisplayId );
fflush(stdout);
ch=0;
break;
}
}
else {
switch(ch) {
case SMG$K_TRM_LF:
case SMG$K_TRM_CR:
case SMG$K_TRM_SPACE :
if (strcmp(Filename,GOPHERHELP)!=0) {
if (remove(Filename) != 0 )
fprintf(stderr, "Couldn't remove %s!!!\n",Filename);
}
break;
case SMG$K_TRM_LOWERCASE_S:
case SMG$K_TRM_UPPERCASE_S:
strncpy(command, "\0", MAXSTR );
strncpy(SaveName, "\0", MAXSTR );
sprintf(command, "Enter save file name: ");
GetOneOption(command, SaveName);
if (strlen(SaveName) == 0)
break;
while ((fNew = fopen(SaveName, "w")) == NULL) {
bzero(SaveName, MAXSTR);
strncpy(command, "\0", MAXSTR );
sprintf(command, "Error opening %s: Enter new name or <Enter> to cancel: ", SaveName);
GetOneOption(command, SaveName);
if (SaveName[0] == 0)
break;
}
if (fNew == NULL)
break;
if ((tmpfile = fopen(Filename, "r")) == NULL)
fprintf(stderr, "%s cannot be opened.\n", Filename), exit(-1);
while (!feof(tmpfile)) fputc(fgetc(tmpfile), fNew);
case SMG$K_TRM_LOWERCASE_P:
case SMG$K_TRM_UPPERCASE_P:
bzero(SaveName, MAXSTR);
strncpy(SaveName,"sys$scratch:gopher.print",MAXSTR);
while ((fNew = fopen(SaveName, "w")) == NULL) {
bzero(SaveName, MAXSTR);
strncpy(command, "\0", MAXSTR );
sprintf(command, "Error opening %s: Enter new name or <Enter> to cancel: ", SaveName);
GetOneOption(command, SaveName);
if (SaveName[0] == 0)
break;
}
if (fNew == NULL)
break;
if ((tmpfile = fopen(Filename, "r")) == NULL)
fprintf(stderr, "%s cannot be opened.\n", Filename), exit(-1);
while (!feof(tmpfile)) fputc(fgetc(tmpfile), fNew);
/*
** Non System V getstr's all seem to be broken in some way. Anyways
** a normal getstr wouldn't do for us. This one displays a current value
** That the user can edit.
**
** Also, if a non-printable character is pressed we stop and return it.
** (tab, esc etc. )
*/
char
Mygetstr(inputline)
char *inputline;
{
int pointer = 0;
short int ch;
int ret_status, read_pos;
char *typedch, *outch;
/*
** This routine will allow the user to change a whole bunch of fields.
**
** The maximum number of options is hard set at 9 right now. It may be
** different in the future.
**
** The space for storing stuff is provided by the caller. This routine
** will present it to the user in this fashion:
**
** Option1 : responses1
** Option2 : responses2
** .....
**
** It would be wise to keep the length of the options and responses
** below 38 characters.
**
*/
Get_Options(Title, Err, numOptions, Options, Responses)
char *Title;
char Err[MAXSTR];
int numOptions;
char **Options;
char Responses[MAXRESP][MAXSTR];
{
int availlines;
char printstring[WHOLELINE];
char inputline[WHOLELINE];
int optionlen, ret_status, row, col;
int maxoptionlen;
int i,j; /** Acme Buggy whips and integers **/
BOOLEAN Done = FALSE;
char ch, fooch;
char *outstr;
else if (isdigit(ch)) {
i = ch - '1' ;
Draw_Status("Press Return when finished");
readkey_row = i + 6;
readkey_col = maxoptionlen + 8;
row = i + 6;
col = maxoptionlen + 8;
ret_status = smg$set_physical_cursor( &PasteId, &row, &col );
inputline[0] = '\0';
Mygetstr(Responses[i]);
}
else
ret_status = smg$ring_bell( &DisplayId );
}
}
/*
* This allows the user to add or change data in a form.
*
* It returns true if the user wants to keep the changes
* It returns false if the user wants to abort
*
*/
BOOLEAN
NewForm(ZeForm)
Form *ZeForm;
{
int availlines;
static char printstring[WHOLELINE];
int optionlen;
int maxoptionlen;
int i,j; /** Acme Buggy whips and integers **/
char ch;
while (1) {
DisplayForm(ZeForm);
sprintf(printstring, "Press <ESC> to accept fields and continue");
/* Centerline("Press <ESC> to accept fields and continue", LINES-3);
Centerline("or press <CTRL-A> to abort", LINES-2);
*/
/*** Now get some user input ***/
/*
* This Displays a form and a "menu". It displays the Form
* and then it waits for a keypress. It returns the value of the
* key that is pressed.
*/
void
DisplayForm(ZeForm)
Form *ZeForm;
{
int availlines;
static char printstring[WHOLELINE];
int optionlen;
int maxoptionlen;
int i,j; /** Acme Buggy whips and integers **/
BOOLEAN Done = FALSE;
char ch;
/*
* This routine allows the user to "find" a specific event.
* It doesn't allow them to look at documents, etc. It just lets
* them cruise around directories
*/
GopherStruct*
cruise_dirs(ZeGopher, Message)
GopherStruct *ZeGopher;
char *Message;
{
int Line;
char SavedTitle;
short int TypedChar = 0;
GopherStruct TmpGopher;
process_request(ZeGopher);
while (1) {
Line = GetMenu(iMenuLines, Gopher, Message, &TypedChar);
switch (TypedChar)
{
case SMG$K_TRM_CR:
case SMG$K_TRM_LF:
if (Gopher[Line-1].sFileType == '1')
process_request(&(Gopher[Line - 1]));
else
CursesErrorMsg("Cannot select these at this time");
break;
case SMG$K_TRM_SPACE:
/*** Use this directory/calendar ***/
return(&(Gopher[Line -1]));
break;
case SMG$K_TRM_LOWERCASE_U:
case SMG$K_TRM_UPPERCASE_U:
/*** Go up a directory level ***/
popgopher(&TmpGopher);
popgopher(&TmpGopher);
process_request(&TmpGopher);
break;
}
}
}
int
OpenGopherConn(ZeGopher)
GopherStruct *ZeGopher;
{
int sockfd;
static char inputline[MAXLINE];
int length;