file.c (most-5.0.0a) | : | file.c (most-5.1.0) | ||
---|---|---|---|---|
/* | /* | |||
This file is part of MOST. | This file is part of MOST. | |||
Copyright (c) 1991, 1999, 2002, 2005, 2006, 2007 John E. Davis | Copyright (c) 1991, 1999, 2002, 2005-2018, 2019 John E. Davis | |||
This program is free software; you can redistribute it and/or modify it | This program is free software; you can redistribute it and/or modify it | |||
under the terms of the GNU General Public License as published by the Free | under the terms of the GNU General Public License as published by the Free | |||
Software Foundation; either version 2 of the License, or (at your option) | Software Foundation; either version 2 of the License, or (at your option) | |||
any later version. | any later version. | |||
This program is distributed in the hope that it will be useful, but WITHOUT | This program is distributed in the hope that it will be useful, but WITHOUT | |||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |||
more details. | more details. | |||
skipping to change at line 72 | skipping to change at line 72 | |||
#if !defined(VMS) | #if !defined(VMS) | |||
static int create_gunzip_cmd (char *cmd, char *file, char *buf, unsigned int siz eof_buf) | static int create_gunzip_cmd (char *cmd, char *file, char *buf, unsigned int siz eof_buf) | |||
{ | { | |||
char *efile; | char *efile; | |||
if (NULL == (efile = most_escape_filename (file, '"'))) | if (NULL == (efile = most_escape_filename (file, '"'))) | |||
return -1; | return -1; | |||
_pSLsnprintf (buf, sizeof_buf, cmd, efile); | (void) _pSLsnprintf (buf, sizeof_buf, cmd, efile); | |||
SLfree (efile); | SLfree (efile); | |||
return 0; | return 0; | |||
} | } | |||
static int open_compressed_file(char *file, int mode, int *size) | static int open_compressed_file(char *file, int mode, int *size) | |||
{ | { | |||
int fd; | int fd; | |||
char buf[4], cmdbuf[2*MAX_PATHLEN]; | char buf[4], cmdbuf[2*MAX_PATHLEN]; | |||
struct stat st; | struct stat st; | |||
skipping to change at line 272 | skipping to change at line 272 | |||
recsz = st.st_fab_mrs; | recsz = st.st_fab_mrs; | |||
if (recsz <= 255) recsz = 255; | if (recsz <= 255) recsz = 255; | |||
/* VMS share options (shr=put) suggested by Henk D. Davids <hdavids@ms we.dnet.ms.philips.nl> */ | /* VMS share options (shr=put) suggested by Henk D. Davids <hdavids@ms we.dnet.ms.philips.nl> */ | |||
/* VMS share options (shr=upi,get,put) suggested by Mark Pizzolato <ma rk@infocomm.com> */ | /* VMS share options (shr=upi,get,put) suggested by Mark Pizzolato <ma rk@infocomm.com> */ | |||
fd = open(file,O_RDONLY,"ctx=rec","mbf=8","mbc=16","rop=RAH","shr=upi,get ,put"); | fd = open(file,O_RDONLY,"ctx=rec","mbf=8","mbc=16","rop=RAH","shr=upi,get ,put"); | |||
/* if (fd < 0) fd = open(file,O_RDONLY); */ | /* if (fd < 0) fd = open(file,O_RDONLY); */ | |||
#else | #else | |||
fd = open_compressed_file(file, O_RDONLY, &size); | fd = open_compressed_file(file, O_RDONLY, &size); | |||
# if MOST_HAS_MMAP | # if MOST_HAS_MMAP | |||
if (0 == try_mmap_buffer (fd)) | if (0 == try_mmap_buffer (fd)) | |||
return most_read_file_dsc (1); | return most_read_file_dsc (1, 1); | |||
# endif | # endif | |||
#endif | #endif | |||
} | } | |||
if (fd < 0) return(-1); | if (fd < 0) return(-1); | |||
if (!fd || (size <= 0)) size = 0x7FFF; | if (!fd || (size <= 0)) size = 0x7FFF; | |||
#ifdef VMS | #ifdef VMS | |||
Most_Buf->rec = recsz; | Most_Buf->rec = recsz; | |||
#endif | #endif | |||
Most_Buf->fd = fd; | Most_Buf->fd = fd; | |||
/* This will fail on really large files. */ | /* This will fail on really large files. */ | |||
Most_Eob = Most_Beg = Most_Buf->beg = (unsigned char *) MOSTMALLOC(size); | Most_Eob = Most_Beg = Most_Buf->beg = (unsigned char *) MOSTMALLOC(size); | |||
Most_Buf->size = size; | Most_Buf->size = size; | |||
return most_read_file_dsc (1); | return most_read_file_dsc (1, 1); | |||
} | } | |||
static void update_buffer_windows (Most_Buffer_Type *b) | static void update_buffer_windows (Most_Buffer_Type *b) | |||
{ | { | |||
Most_Window_Type *w; | Most_Window_Type *w; | |||
if (NULL == (w = Most_Win)) | if (NULL == (w = Most_Win)) | |||
return; | return; | |||
do | do | |||
{ | { | |||
skipping to change at line 345 | skipping to change at line 345 | |||
{ | { | |||
Most_V_Opt = 1; | Most_V_Opt = 1; | |||
Most_W_Opt = 1; | Most_W_Opt = 1; | |||
} | } | |||
} | } | |||
} | } | |||
static int First_Time_Hack = 0; /* true if reading file for first time */ | static int First_Time_Hack = 0; /* true if reading file for first time */ | |||
#if MOST_HAS_MMAP | #if MOST_HAS_MMAP | |||
static int read_mmap_file_dsc (int many) | static int read_mmap_file_dsc (int many, int count_lines) | |||
{ | { | |||
unsigned int size; | unsigned int size; | |||
size = Most_Buf->size; | size = Most_Buf->size; | |||
if (many == -1) | if (many == -1) | |||
{ | { | |||
if (-1 == resync_mmap ()) | if (-1 == resync_mmap ()) | |||
return -1; | return -1; | |||
} | } | |||
skipping to change at line 377 | skipping to change at line 377 | |||
} | } | |||
Most_Eob = Most_Buf->end = Most_Buf->beg + size; | Most_Eob = Most_Buf->end = Most_Buf->beg + size; | |||
Most_Buf->size = size; | Most_Buf->size = size; | |||
most_flush_message ("Mapping file..."); | most_flush_message ("Mapping file..."); | |||
if (First_Time_Hack) | if (First_Time_Hack) | |||
examine_file_contents (); | examine_file_contents (); | |||
Most_Num_Lines = most_count_lines (Most_Beg, Most_Eob); | if (count_lines) | |||
Most_Num_Lines = most_count_lines (Most_Beg, Most_Eob); | ||||
most_message(Most_Global_Msg, 0); | most_message(Most_Global_Msg, 0); | |||
return 1; | return 1; | |||
} | } | |||
#endif | #endif | |||
/* if read something, return non zero (1) */ | /* if read something, return non zero (1) */ | |||
int most_read_file_dsc (int many) | int most_read_file_dsc (int many, int count_lines) | |||
{ | { | |||
int fd = Most_Buf->fd, n = 0, i; | int fd = Most_Buf->fd, n = 0, i; | |||
int dsize, size, passes = 0; | int dsize, size, passes = 0; | |||
unsigned char *pos; | unsigned char *pos; | |||
#ifdef VMS | #ifdef VMS | |||
int recsz = Most_Buf->rec; | int recsz = Most_Buf->rec; | |||
#endif | #endif | |||
if (fd < 0) return 0; | if (fd < 0) return 0; | |||
#if MOST_HAS_MMAP | #if MOST_HAS_MMAP | |||
if (Most_Buf->is_mmaped) | if (Most_Buf->is_mmaped) | |||
{ | { | |||
int ret = read_mmap_file_dsc (many); | int ret = read_mmap_file_dsc (many, count_lines); | |||
if (-1 != ret) | if (-1 != ret) | |||
return ret; | return ret; | |||
if (Most_Buf->is_mmaped) | if (Most_Buf->is_mmaped) | |||
return -1; | return -1; | |||
/* No longer mapped..... */ | /* No longer mapped..... */ | |||
} | } | |||
#endif | #endif | |||
dsize = 0x3FFF; | dsize = 0x3FFF; | |||
skipping to change at line 442 | skipping to change at line 444 | |||
while (1) | while (1) | |||
{ | { | |||
#ifdef VMS | #ifdef VMS | |||
i = read (fd, (char *) pos, recsz); | i = read (fd, (char *) pos, recsz); | |||
#else | #else | |||
i = read (fd, (char *) pos, dsize - n); | i = read (fd, (char *) pos, dsize - n); | |||
#endif | #endif | |||
if (i == -1) | if (i == -1) | |||
{ | { | |||
#ifdef EINTR | #ifdef EINTR | |||
if (errno == EINTR) continue; | if ((errno == EINTR) && (SLKeyBoard_Quit == 0)) continue; | |||
#endif | #endif | |||
break; | break; | |||
} | } | |||
if (i == 0) | if (i == 0) | |||
{ | { | |||
/* EOF */ | /* EOF */ | |||
/* Under linux, for some reason bash when invoked by | /* Under linux, for some reason bash when invoked by | |||
* man will reset the terminal. Apparantly this is a | * man will reset the terminal. Apparantly this is a | |||
* result of most being orphaned. | * result of most being orphaned. | |||
skipping to change at line 481 | skipping to change at line 483 | |||
if ((i <= 0) | if ((i <= 0) | |||
|| SLKeyBoard_Quit) | || SLKeyBoard_Quit) | |||
{ | { | |||
break; | break; | |||
} | } | |||
} | } | |||
if (First_Time_Hack) | if (First_Time_Hack) | |||
examine_file_contents (); | examine_file_contents (); | |||
if (n || First_Time_Hack) | if (count_lines | |||
&& (n || First_Time_Hack)) | ||||
Most_Num_Lines = most_count_lines (Most_Beg, Most_Eob); | Most_Num_Lines = most_count_lines (Most_Beg, Most_Eob); | |||
update_buffer_windows (Most_Buf); | update_buffer_windows (Most_Buf); | |||
most_message("reading...done", 0); | most_message("reading...done", 0); | |||
most_put_message(); | most_put_message(); | |||
most_message(Most_Global_Msg, 0); | most_message(Most_Global_Msg, 0); | |||
return n; | return n; | |||
} | } | |||
skipping to change at line 512 | skipping to change at line 515 | |||
dn = n - Most_Num_Lines; | dn = n - Most_Num_Lines; | |||
if (dn < 0) return; | if (dn < 0) return; | |||
nbytes = 0; | nbytes = 0; | |||
if (Most_Num_Lines) | if (Most_Num_Lines) | |||
nbytes = dn * ((Most_Eob - Most_Beg) / Most_Num_Lines); | nbytes = dn * ((Most_Eob - Most_Beg) / Most_Num_Lines); | |||
if (nbytes < 0x3FFF) nbytes = 0x3FFF; | if (nbytes < 0x3FFF) nbytes = 0x3FFF; | |||
while ((Most_Buf->fd != -1) | while ((Most_Buf->fd != -1) | |||
&& (n >= Most_Num_Lines) | && (n >= Most_Num_Lines) | |||
&& (0 != most_read_file_dsc (nbytes / 0x3FFF)) | && (0 != most_read_file_dsc (nbytes / 0x3FFF, 1)) | |||
&& (SLKeyBoard_Quit == 0)) | && (SLKeyBoard_Quit == 0)) | |||
{ | { | |||
nbytes = 0; | nbytes = 0; | |||
if (Most_Num_Lines) | if (Most_Num_Lines) | |||
nbytes = dn * ((Most_Eob - Most_Beg) / Most_Num_Lines); | nbytes = dn * ((Most_Eob - Most_Beg) / Most_Num_Lines); | |||
if (nbytes < 0x3FFF) nbytes = 0x3FFF; | if (nbytes < 0x3FFF) nbytes = 0x3FFF; | |||
} | } | |||
} | } | |||
int most_find_file(char *file) | int most_find_file(char *file) | |||
skipping to change at line 737 | skipping to change at line 740 | |||
#endif | #endif | |||
/* really cheat here-- let system do it. The path must exist!! */ | /* really cheat here-- let system do it. The path must exist!! */ | |||
if (chdir(path)) | if (chdir(path)) | |||
{ | { | |||
most_message(path,1); | most_message(path,1); | |||
return(0); | return(0); | |||
} | } | |||
else | else | |||
{ | { | |||
most_get_cdir(path); | most_get_cdir(path); | |||
chdir(Most_C_Dir); | (void) chdir(Most_C_Dir); | |||
#ifndef VMS | #ifndef VMS | |||
n = strlen(path); | n = strlen(path); | |||
if (path[n-1] == '/') return(1); | if (path[n-1] == '/') return(1); | |||
path[n++] = '/'; path[n] = 0; | path[n++] = '/'; path[n] = 0; | |||
#endif | #endif | |||
} | } | |||
return(1); | return(1); | |||
} | } | |||
#if 0 | #if 0 | |||
skipping to change at line 772 | skipping to change at line 775 | |||
{ | { | |||
most_get_cdir(Most_C_Dir); /* expands ../ etc... */ | most_get_cdir(Most_C_Dir); /* expands ../ etc... */ | |||
n = strlen(Most_C_Dir); | n = strlen(Most_C_Dir); | |||
# ifndef VMS | # ifndef VMS | |||
if (Most_C_Dir[n-1] == '/') return; | if (Most_C_Dir[n-1] == '/') return; | |||
Most_C_Dir[n++] = '/'; Most_C_Dir[n] = 0; | Most_C_Dir[n++] = '/'; Most_C_Dir[n] = 0; | |||
# endif | # endif | |||
return; | return; | |||
} | } | |||
strcpy(Most_C_Dir,tmp_dir); | strcpy(Most_C_Dir,tmp_dir); | |||
chdir(Most_C_Dir); | (void) chdir(Most_C_Dir); | |||
most_message("Unable to change directory.",1); | most_message("Unable to change directory.",1); | |||
} | } | |||
#endif | #endif | |||
void most_user_get_file() | void most_user_get_file() | |||
{ | { | |||
char path[MAX_PATHLEN], file[MAX_PATHLEN], *name; | char path[MAX_PATHLEN], file[MAX_PATHLEN], *name; | |||
#ifdef VMS | #ifdef VMS | |||
unsigned int i, imax; | unsigned int i, imax; | |||
#endif | #endif | |||
End of changes. 13 change blocks. | ||||
13 lines changed or deleted | 16 lines changed or added |