Use NAME_MAX when available. Don't try to fake a FILE on DragonFly. The implementation of textsw_scanf can be improved, it is very defensively and slow ATM, the snprintf usage should be portable. Fix a number of prototype mismatches, e.g. variable argument functions can conflict with K&R prototypes. Bump revision since the package "compiled" before, e.g. build errors where ignored.
440 lines
13 KiB
Text
440 lines
13 KiB
Text
$NetBSD: patch-cy,v 1.3 2006/01/05 18:25:57 joerg Exp $
|
|
|
|
--- lib/libxview/textsw/txt_file.c.orig 1993-06-29 07:17:48.000000000 +0200
|
|
+++ lib/libxview/textsw/txt_file.c 2004-09-30 22:24:41.000000000 +0200
|
|
@@ -18,6 +18,7 @@ static char sccsid[] = "@(#)txt_file
|
|
#include <xview_private/txt_impl.h>
|
|
#include <xview_private/ev_impl.h>
|
|
#include <xview_private/txt_18impl.h>
|
|
+#include <limits.h>
|
|
#ifdef SVR4
|
|
#include <dirent.h>
|
|
#include <string.h>
|
|
@@ -45,13 +46,27 @@ static char sccsid[] = "@(#)txt_file
|
|
|
|
extern CHAR *STRCAT();
|
|
extern CHAR *STRNCAT();
|
|
-#ifdef SVR4
|
|
+
|
|
+#if (defined(SVR4) || (__NetBSD_Version__ >= 103080000)) || defined(__DragonFly__)
|
|
+#define GETCWD
|
|
+#endif
|
|
+
|
|
+#ifdef GETCWD
|
|
extern char *getcwd();
|
|
#else
|
|
extern char *getwd();
|
|
-#endif /* SVR4 */
|
|
+#endif /* GETCWD */
|
|
+#if (defined(BSD) && (BSD >= 199306))
|
|
+#if defined(__DragonFly__) || (defined(__NetBSD__) && __NetBSD_Version__ > 103080000)
|
|
+#include <errno.h>
|
|
+#else
|
|
+extern int errno, sys_nerr;
|
|
+extern const char *const sys_errlist[];
|
|
+#endif
|
|
+#else
|
|
extern int errno, sys_nerr;
|
|
extern char *sys_errlist[];
|
|
+#endif
|
|
|
|
Pkg_private int textsw_change_directory();
|
|
Pkg_private void textsw_display(), textsw_display_view_margins();
|
|
@@ -314,7 +329,11 @@ textsw_load_selection(folio, locx, locy,
|
|
register int locx, locy;
|
|
int no_cd;
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ CHAR filename[NAME_MAX];
|
|
+#else
|
|
CHAR filename[MAXNAMLEN];
|
|
+#endif
|
|
register int result;
|
|
|
|
if (textsw_get_selection_as_filename(
|
|
@@ -354,21 +373,21 @@ textsw_full_pathname(name)
|
|
}
|
|
|
|
#ifdef OW_I18N
|
|
-#ifdef SVR4
|
|
+#ifdef GETCWD
|
|
if (getcwd(pathname_mb, MAXPATHLEN) == 0)
|
|
#else
|
|
if (getwd(pathname_mb) == 0)
|
|
-#endif /* SVR4 */
|
|
+#endif /* GETCWD */
|
|
return (0);
|
|
(void) mbstowcs(pathname, pathname_mb, MAXPATHLEN-1);
|
|
|
|
#else /* OW_I18N */
|
|
|
|
-#ifdef SVR4
|
|
+#ifdef GETCWD
|
|
if (getcwd(pathname, MAXPATHLEN) == 0)
|
|
#else
|
|
if (getwd(pathname) == 0)
|
|
-#endif /* SVR4 */
|
|
+#endif /* GETCWD */
|
|
return (0);
|
|
#endif /* OW_I18N */
|
|
|
|
@@ -459,8 +478,13 @@ textsw_load_file(abstract, filename, res
|
|
int reset_views;
|
|
int locx, locy;
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ char notice_msg_buf[NAME_MAX + 100];
|
|
+ CHAR scratch_name[NAME_MAX];
|
|
+#else
|
|
char notice_msg_buf[MAXNAMLEN + 100];
|
|
CHAR scratch_name[MAXNAMLEN];
|
|
+#endif
|
|
int result;
|
|
Es_status status;
|
|
Es_handle new_esh;
|
|
@@ -546,7 +570,11 @@ textsw_load_file_quietly(abstract, filen
|
|
int reset_views;
|
|
int locx, locy;
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ CHAR scratch_name[NAME_MAX];
|
|
+#else
|
|
CHAR scratch_name[MAXNAMLEN];
|
|
+#endif
|
|
Es_status status;
|
|
Es_handle new_esh;
|
|
Es_index start_at;
|
|
@@ -587,7 +615,11 @@ textsw_save_store_common(folio, output_n
|
|
CHAR *output_name;
|
|
int reload;
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ CHAR scratch_name[NAME_MAX];
|
|
+#else
|
|
CHAR scratch_name[MAXNAMLEN];
|
|
+#endif
|
|
Es_handle new_esh;
|
|
register Es_handle output;
|
|
Es_status result;
|
|
@@ -604,9 +636,16 @@ textsw_save_store_common(folio, output_n
|
|
es_destroy(output);
|
|
if (folio->checkpoint_name) {
|
|
#ifdef OW_I18N
|
|
+#ifdef NAME_MAX
|
|
+ char temp_mb[NAME_MAX];
|
|
+
|
|
+ (void) wcstombs(temp_mb, folio->checkpoint_name, NAME_MAX);
|
|
+#else
|
|
char temp_mb[MAXNAMLEN];
|
|
|
|
(void) wcstombs(temp_mb, folio->checkpoint_name, MAXNAMLEN);
|
|
+#endif
|
|
+
|
|
if (unlink(temp_mb) == -1) { /* } for match */
|
|
#else
|
|
if (unlink(folio->checkpoint_name) == -1) {
|
|
@@ -733,7 +772,11 @@ textsw_save_internal(folio, error_buf, l
|
|
int locx, locy; /* Currently unused */
|
|
{
|
|
Pkg_private Es_handle es_file_make_backup();
|
|
+#ifdef NAME_MAX
|
|
+ CHAR original_name[NAME_MAX], *name;
|
|
+#else
|
|
CHAR original_name[MAXNAMLEN], *name;
|
|
+#endif
|
|
register char *msg;
|
|
Es_handle backup, original = ES_NULL;
|
|
int status;
|
|
@@ -826,10 +869,16 @@ Was the file edited with another editor?
|
|
textsw_save_store_common(folio, original_name, RELOAD)) {
|
|
case ES_SUCCESS: {
|
|
#ifdef OW_I18N
|
|
+#ifdef NAME_MAX
|
|
+ char original_name_mb[NAME_MAX];
|
|
+
|
|
+ (void) wcstombs(original_name_mb, original_name, NAME_MAX);
|
|
+#else
|
|
char original_name_mb[MAXNAMLEN];
|
|
|
|
(void) wcstombs(original_name_mb, original_name, MAXNAMLEN);
|
|
#endif
|
|
+#endif
|
|
(void) es_destroy(original);
|
|
textsw_notify(folio->first_view,
|
|
#ifdef OW_I18N
|
|
@@ -868,7 +917,11 @@ textsw_save(abstract, locx, locy)
|
|
Textsw abstract;
|
|
int locx, locy;
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ char error_buf[NAME_MAX];
|
|
+#else
|
|
char error_buf[MAXNAMLEN + 100];
|
|
+#endif
|
|
Es_status status;
|
|
Textsw_view_handle view = VIEW_ABS_TO_REP(abstract);
|
|
|
|
@@ -969,7 +1022,11 @@ textsw_cd(textsw, locx, locy)
|
|
Textsw_folio textsw;
|
|
int locx, locy;
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ CHAR buf[NAME_MAX];
|
|
+#else
|
|
CHAR buf[MAXNAMLEN];
|
|
+#endif
|
|
|
|
if (0 == textsw_get_selection_as_filename(
|
|
textsw, buf, SIZEOF(buf), locx, locy)) {
|
|
@@ -988,15 +1045,27 @@ textsw_get_from_file(view, filename, pri
|
|
int fd;
|
|
Es_status status;
|
|
Textsw_status result = TEXTSW_STATUS_CANNOT_INSERT_FROM_FILE;
|
|
+#ifdef NAME_MAX
|
|
+ CHAR buf[NAME_MAX];
|
|
+#else
|
|
CHAR buf[MAXNAMLEN];
|
|
+#endif
|
|
|
|
if (!TXTSW_IS_READ_ONLY(folio) && ((int)STRLEN(filename) > 0)) {
|
|
STRCPY(buf, filename);
|
|
#ifdef OW_I18N
|
|
+#ifdef NAME_MAX
|
|
+ if (textsw_expand_filename(folio, buf, NAME_MAX, -1, -1) == 0) {/* } */
|
|
+ char buf_mb[NAME_MAX];
|
|
+
|
|
+ (void) wcstombs(buf_mb, buf, NAME_MAX);
|
|
+#else
|
|
if (textsw_expand_filename(folio, buf, MAXNAMLEN, -1, -1) == 0) {/* } */
|
|
char buf_mb[MAXNAMLEN];
|
|
|
|
(void) wcstombs(buf_mb, buf, MAXNAMLEN);
|
|
+#endif
|
|
+
|
|
if ((fd = open(buf_mb, 0)) >= 0) { /* } for match */
|
|
textsw_implicit_commit(folio);
|
|
#else
|
|
@@ -1034,9 +1103,15 @@ textsw_file_stuff(view, locx, locy)
|
|
{
|
|
Textsw_folio folio = FOLIO_FOR_VIEW(view);
|
|
int fd;
|
|
+#ifdef NAME_MAX
|
|
+ CHAR buf[NAME_MAX];
|
|
+ char msg[NAME_MAX + 100], *sys_msg;
|
|
+ char notice_msg1[NAME_MAX + 100];
|
|
+#else
|
|
CHAR buf[MAXNAMLEN];
|
|
char msg[MAXNAMLEN + 100], *sys_msg;
|
|
char notice_msg1[MAXNAMLEN + 100];
|
|
+#endif
|
|
char *notice_msg2;
|
|
Es_status status;
|
|
int cannot_open = 0;
|
|
@@ -1047,9 +1122,15 @@ textsw_file_stuff(view, locx, locy)
|
|
if (0 == textsw_get_selection_as_filename(
|
|
folio, buf, SIZEOF(buf), locx, locy)) {
|
|
#ifdef OW_I18N
|
|
+#ifdef NAME_MAX
|
|
+ char buf_mb[NAME_MAX];
|
|
+
|
|
+ (void) wcstombs(buf_mb, buf, NAME_MAX);
|
|
+#else
|
|
char buf_mb[MAXNAMLEN];
|
|
|
|
(void) wcstombs(buf_mb, buf, MAXNAMLEN);
|
|
+#endif
|
|
if ((fd = open(buf_mb, 0)) < 0) { /* } for match */
|
|
#else
|
|
if ((fd = open(buf, 0)) < 0) {
|
|
@@ -1141,8 +1222,13 @@ textsw_file_stuff_from_str(view, buf, lo
|
|
{
|
|
Textsw_folio folio = FOLIO_FOR_VIEW(view);
|
|
int fd;
|
|
+#ifdef NAME_MAX
|
|
+ char msg[NAME_MAX + 100], *sys_msg;
|
|
+ char notice_msg1[NAME_MAX + 100];
|
|
+#else
|
|
char msg[MAXNAMLEN + 100], *sys_msg;
|
|
char notice_msg1[MAXNAMLEN + 100];
|
|
+#endif
|
|
char *notice_msg2;
|
|
Es_status status;
|
|
int cannot_open = 0;
|
|
@@ -1150,9 +1236,15 @@ textsw_file_stuff_from_str(view, buf, lo
|
|
Xv_Notice text_notice;
|
|
Frame frame;
|
|
#ifdef OW_I18N
|
|
+#ifdef NAME_MAX
|
|
+ char buf_mb[NAME_MAX];
|
|
+
|
|
+ (void) wcstombs(buf_mb, buf, NAME_MAX);
|
|
+#else
|
|
char buf_mb[MAXNAMLEN];
|
|
|
|
(void) wcstombs(buf_mb, buf, MAXNAMLEN);
|
|
+#endif
|
|
if ((fd = open(buf_mb, 0)) < 0) { /* } for match */
|
|
#else
|
|
if ((fd = open(buf, 0)) < 0) {
|
|
@@ -1245,9 +1337,15 @@ textsw_store_init(textsw, filename)
|
|
{
|
|
struct stat stat_buf;
|
|
#ifdef OW_I18N
|
|
+#ifdef NAME_MAX
|
|
+ char filename_mb[NAME_MAX];
|
|
+
|
|
+ (void) wcstombs(filename_mb, filename, NAME_MAX);
|
|
+#else
|
|
char filename_mb[MAXNAMLEN];
|
|
|
|
(void) wcstombs(filename_mb, filename, MAXNAMLEN);
|
|
+#endif
|
|
if (stat(filename_mb, &stat_buf) == 0) { /* } for match */
|
|
#else
|
|
if (stat(filename, &stat_buf) == 0) {
|
|
@@ -1310,10 +1408,16 @@ textsw_process_store_error(textsw, filen
|
|
case ES_CANNOT_OVERWRITE:
|
|
#ifdef OW_I18N
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ char filename_mb[NAME_MAX];
|
|
+
|
|
+ (void) wcstombs(filename_mb, filename, NAME_MAX);
|
|
+#else
|
|
char filename_mb[MAXNAMLEN];
|
|
|
|
(void) wcstombs(filename_mb, filename, MAXNAMLEN);
|
|
#endif
|
|
+#endif
|
|
frame = FRAME_FROM_FOLIO_OR_VIEW(textsw);
|
|
text_notice = (Xv_Notice)xv_get(frame,
|
|
XV_KEY_DATA, text_notice_key,
|
|
@@ -1465,9 +1569,12 @@ textsw_store_file_internal(abstract, fil
|
|
if (status == ES_SUCCESS) {
|
|
if (textsw->state & TXTSW_STORE_CHANGES_FILE) {
|
|
#ifdef OW_I18N
|
|
- char filename_mbs[MAXNAMLEN];
|
|
+#ifdef NAME_MAX
|
|
+ char filename_mbs[NAME_MAX];
|
|
|
|
- (void) wcstombs(filename_mbs, filename, MAXNAMLEN);
|
|
+ (void) wcstombs(filename_mbs, filename, NAME_MAX);
|
|
+#else
|
|
+#endif
|
|
textsw_notify(textsw->first_view,
|
|
TEXTSW_ACTION_LOADED_FILE, filename_mbs,
|
|
TEXTSW_ACTION_LOADED_FILE_WCS, filename, 0);
|
|
@@ -1491,9 +1598,15 @@ textsw_store_file(abstract, filename, lo
|
|
int locx, locy;
|
|
{
|
|
#ifdef OW_I18N
|
|
+#ifdef NAME_MAX
|
|
+ CHAR filename_wcs[NAME_MAX];
|
|
+
|
|
+ (void) mbstowcs(filename_wcs, filename, NAME_MAX);
|
|
+#else
|
|
CHAR filename_wcs[MAXNAMLEN];
|
|
|
|
(void) mbstowcs(filename_wcs, filename, MAXNAMLEN);
|
|
+#endif
|
|
return (textsw_store_file_internal(abstract, filename_wcs, locx, locy));
|
|
#else
|
|
return (textsw_store_file_internal(abstract, filename, locx, locy));
|
|
@@ -1516,7 +1629,11 @@ textsw_store_to_selection(textsw, locx,
|
|
Textsw_folio textsw;
|
|
int locx, locy;
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ CHAR filename[NAME_MAX];
|
|
+#else
|
|
CHAR filename[MAXNAMLEN];
|
|
+#endif
|
|
|
|
if (textsw_get_selection_as_filename(
|
|
textsw, filename, SIZEOF(filename), locx, locy))
|
|
@@ -1545,11 +1662,19 @@ textsw_reset_2(abstract, locx, locy, pre
|
|
#endif /* SVR4 */
|
|
Pkg_private Es_handle es_mem_create();
|
|
Es_handle piece_esh, old_original_esh, new_original_esh;
|
|
+ char *temp_name;
|
|
+#ifdef NAME_MAX
|
|
+#ifdef OW_I18N
|
|
+ CHAR *name, save_name[NAME_MAX], scratch_name[NAME_MAX];
|
|
+#else
|
|
+ char *name, save_name[NAME_MAX], scratch_name[NAME_MAX];
|
|
+#endif
|
|
+#else
|
|
#ifdef OW_I18N
|
|
CHAR *name, save_name[MAXNAMLEN], scratch_name[MAXNAMLEN];
|
|
- char *temp_name;
|
|
#else
|
|
- char *name, save_name[MAXNAMLEN], scratch_name[MAXNAMLEN], *temp_name;
|
|
+ char *name, save_name[MAXNAMLEN], scratch_name[MAXNAMLEN];
|
|
+#endif
|
|
#endif
|
|
int status;
|
|
Textsw_folio folio = FOLIO_FOR_VIEW(VIEW_ABS_TO_REP(abstract));
|
|
@@ -1591,7 +1716,11 @@ textsw_reset_2(abstract, locx, locy, pre
|
|
(char *) window_get(abstract, TEXTSW_TEMP_FILENAME);
|
|
if (temp_name)
|
|
#ifdef OW_I18N
|
|
+#ifdef NAME_MAX
|
|
+ (void) mbstowcs(save_name, temp_name, NAME_MAX);
|
|
+#else
|
|
(void) mbstowcs(save_name, temp_name, MAXNAMLEN);
|
|
+#endif
|
|
#else
|
|
(void) STRCPY(save_name, temp_name);
|
|
#endif
|
|
@@ -2150,7 +2279,11 @@ textsw_post_error(folio_or_view, locx, l
|
|
int locx, locy; /* Unused */
|
|
char *msg1, *msg2;
|
|
{
|
|
+#ifdef NAME_MAX
|
|
+ char buf[NAME_MAX + 1000];
|
|
+#else
|
|
char buf[MAXNAMLEN + 1000];
|
|
+#endif
|
|
int size_to_use = sizeof(buf);
|
|
Frame frame;
|
|
Xv_Notice text_notice;
|
|
@@ -2226,8 +2359,13 @@ textsw_change_directory(textsw, filename
|
|
CHAR *full_pathname_wc;
|
|
char filename[MAXPATHLEN];
|
|
#endif
|
|
+#ifdef NAME_MAX
|
|
+ char msg[NAME_MAX + 100];
|
|
+ char notice_msg[NAME_MAX + 100];
|
|
+#else
|
|
char msg[MAXNAMLEN + 100];
|
|
char notice_msg[MAXNAMLEN + 100];
|
|
+#endif
|
|
struct stat stat_buf;
|
|
int result = 0;
|
|
int notice_result;
|
|
@@ -2402,8 +2540,13 @@ textsw_checkpoint_internal(folio)
|
|
CHAR *name;
|
|
if (textsw_file_name(folio, &name) != 0)
|
|
return (ES_CANNOT_GET_NAME);
|
|
+#ifdef NAME_MAX
|
|
+ if ((folio->checkpoint_name = (CHAR *) MALLOC(NAME_MAX)) == 0)
|
|
+ return (ES_CANNOT_GET_NAME);
|
|
+#else
|
|
if ((folio->checkpoint_name = (CHAR *) MALLOC(MAXNAMLEN)) == 0)
|
|
return (ES_CANNOT_GET_NAME);
|
|
+#endif
|
|
#ifdef OW_I18N
|
|
(void) SPRINTF(folio->checkpoint_name, "%ws%%%%", name);
|
|
#else
|
|
@@ -2773,7 +2916,11 @@ textsw_invalid_data_notice(view, filenam
|
|
int flag;
|
|
{
|
|
Xv_Notice text_notice;
|
|
+#ifdef NAME_MAX
|
|
+ char notice_msg[NAME_MAX + 300];
|
|
+#else
|
|
char notice_msg[MAXNAMLEN + 300];
|
|
+#endif
|
|
Frame frame = FRAME_FROM_FOLIO_OR_VIEW(view);
|
|
|
|
if (flag) {
|