/* MS-DOS specific C utilities. -*- coding: raw-text -*-
-Copyright (C) 1993-1997, 1999-2011 Free Software Foundation, Inc.
+Copyright (C) 1993-1997, 1999-2012 Free Software Foundation, Inc.
This file is part of GNU Emacs.
#include <time.h>
#include <sys/param.h>
#include <sys/time.h>
+/* gettime and settime in dos.h clash with their namesakes from
+ gnulib, so we move out of our way the prototypes in dos.h. */
+#define gettime dos_h_gettime_
+#define settime dos_h_settime_
#include <dos.h>
+#undef gettime
+#undef settime
#include <errno.h>
#include <sys/stat.h> /* for _fixpath */
#include <unistd.h> /* for chdir, dup, dup2, etc. */
#include <signal.h>
#include "syssignal.h"
+#include "careadlinkat.h"
+#include "allocator.h"
+
#ifndef SYSTEM_MALLOC
#ifdef GNU_MALLOC
#endif /* not SYSTEM_MALLOC */
+/* Return the current timestamp in milliseconds since midnight. */
static unsigned long
event_timestamp (void)
{
- struct time t;
+ struct timespec t;
unsigned long s;
gettime (&t);
- s = t.ti_min;
- s *= 60;
- s += t.ti_sec;
+ s = t.tv_sec;
+ s %= 86400;
s *= 1000;
- s += t.ti_hund * 10;
+ s += t.tv_nsec * 1000000;
return s;
}
void
mouse_get_pos (FRAME_PTR *f, int insist, Lisp_Object *bar_window,
enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y,
- unsigned long *time)
+ Time *time)
{
int ix, iy;
Lisp_Object frame, tail;
FOR_EACH_FRAME (tail, frame)
XFRAME (frame)->mouse_moved = 0;
- *f = SELECTED_FRAME();
+ *f = SELECTED_FRAME ();
*bar_window = Qnil;
mouse_get_xy (&ix, &iy);
*time = event_timestamp ();
int x, y;
mouse_get_xy (&x, &y);
- SELECTED_FRAME()->mouse_moved |= (x != mouse_last_x || y != mouse_last_y);
+ SELECTED_FRAME ()->mouse_moved |= (x != mouse_last_x || y != mouse_last_y);
mouse_last_x = x;
mouse_last_y = y;
}
/* If the user specified a special video mode for these dimensions,
use that mode. */
- sprintf (video_name, "screen-dimensions-%dx%d", *rows, *cols);
- video_mode = Fsymbol_value (Fintern_soft (build_string (video_name), Qnil));
+ video_mode
+ = Fsymbol_value (Fintern_soft (make_formatted_string
+ (video_name, "screen-dimensions-%dx%d",
+ *rows, *cols), Qnil));
if (INTEGERP (video_mode)
&& (video_mode_value = XINT (video_mode)) > 0)
/* If the dimensions changed, the mouse highlight info is invalid. */
if (current_rows != *rows || current_cols != *cols)
{
- struct frame *f = SELECTED_FRAME();
+ struct frame *f = SELECTED_FRAME ();
Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
Lisp_Object window = hlinfo->mouse_face_window;
/* Avoid the costly BIOS call if F isn't the currently selected
frame. Allow for NULL as unconditionally meaning the selected
frame. */
- if (f && f != SELECTED_FRAME())
+ if (f && f != SELECTED_FRAME ())
return;
if (tty->termscript)
static void
IT_set_face (int face)
{
- struct frame *sf = SELECTED_FRAME();
+ struct frame *sf = SELECTED_FRAME ();
struct face *fp = FACE_FROM_ID (sf, face);
struct face *dfp = FACE_FROM_ID (sf, DEFAULT_FACE_ID);
unsigned long fg, bg, dflt_fg, dflt_bg;
/* According to RBIL (INTERRUP.A, V-1000), 160 is the maximum possible
width of a DOS display in any known text mode. We multiply by 2 to
- accomodate the screen attribute byte. */
+ accommodate the screen attribute byte. */
#define MAX_SCREEN_BUF 160*2
extern unsigned char *encode_terminal_code (struct glyph *, int,
if (str_len <= 0) return;
- sf = SELECTED_FRAME();
+ sf = SELECTED_FRAME ();
/* Since faces get cached and uncached behind our back, we can't
rely on their indices in the cache being consistent across
IT_copy_glyphs (int xfrom, int xto, size_t len, int ypos)
{
/* The offsets of source and destination relative to the
- conventional memorty selector. */
+ conventional memory selector. */
int from = 2 * (xfrom + screen_size_X * ypos) + ScreenPrimary;
int to = 2 * (xto + screen_size_X * ypos) + ScreenPrimary;
{
}
-/* Remember the screen colors of the curent frame, to serve as the
+/* Remember the screen colors of the current frame, to serve as the
default colors for newly-created frames. */
DEFUN ("msdos-remember-default-colors", Fmsdos_remember_default_colors,
Smsdos_remember_default_colors, 1, 1, 0,
/* Extract parm names and values into those vectors. */
i = 0;
- for (tail = alist; CONSP (tail); tail = Fcdr (tail))
+ for (tail = alist; CONSP (tail); tail = XCDR (tail))
{
- Lisp_Object elt;
-
- elt = Fcar (tail);
+ Lisp_Object elt = XCAR (tail);
parms[i] = Fcar (elt);
CHECK_SYMBOL (parms[i]);
values[i] = Fcdr (elt);
if (redraw)
{
face_change_count++; /* forces xdisp.c to recompute basic faces */
- if (f == SELECTED_FRAME())
+ if (f == SELECTED_FRAME ())
redraw_frame (f);
}
}
{
static int init_needed = 1;
char *term = getenv ("TERM"), *colors;
- struct frame *sf = SELECTED_FRAME();
+ struct frame *sf = SELECTED_FRAME ();
struct tty_display_info *tty;
#ifdef HAVE_X_WINDOWS
}
Vinitial_window_system = Qpc;
- Vwindow_system_version = make_number (23); /* RE Emacs version */
+ Vwindow_system_version = make_number (24); /* RE Emacs version */
tty->terminal->type = output_msdos_raw;
/* If Emacs was dumped on DOS/V machine, forget the stale VRAM
void
check_x (void)
{
- if (! FRAME_MSDOS_P (SELECTED_FRAME()))
+ if (! FRAME_MSDOS_P (SELECTED_FRAME ()))
error ("Not running under a window system");
}
{
struct input_event event;
union REGS regs;
- Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (SELECTED_FRAME());
+ Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (SELECTED_FRAME ());
EVENT_INIT (event);
#ifndef HAVE_X_WINDOWS
/* Maybe put the cursor where it should be. */
- IT_cmgoto (SELECTED_FRAME());
+ IT_cmgoto (SELECTED_FRAME ());
#endif
/* The following condition is equivalent to `kbhit ()', except that
sc = regs.h.ah;
total_doskeys += 2;
- XVECTOR (recent_doskeys)->contents[recent_doskeys_index++]
- = make_number (c);
+ ASET (recent_doskeys, recent_doskeys_index, make_number (c));
+ recent_doskeys_index++;
if (recent_doskeys_index == NUM_RECENT_DOSKEYS)
recent_doskeys_index = 0;
- XVECTOR (recent_doskeys)->contents[recent_doskeys_index++]
- = make_number (sc);
+ ASET (recent_doskeys, recent_doskeys_index, make_number (sc));
+ recent_doskeys_index++;
if (recent_doskeys_index == NUM_RECENT_DOSKEYS)
recent_doskeys_index = 0;
/* Generate SELECT_WINDOW_EVENTs when needed. */
if (!NILP (Vmouse_autoselect_window))
{
- mouse_window = window_from_coordinates (SELECTED_FRAME(),
+ mouse_window = window_from_coordinates (SELECTED_FRAME (),
mouse_last_x,
mouse_last_y,
0, 0);
previous_help_echo_string = help_echo_string;
help_echo_string = help_echo_object = help_echo_window = Qnil;
help_echo_pos = -1;
- note_mouse_highlight (SELECTED_FRAME(), mouse_last_x, mouse_last_y);
+ note_mouse_highlight (SELECTED_FRAME (), mouse_last_x, mouse_last_y);
/* If the contents of the global variable help_echo has
changed, generate a HELP_EVENT. */
if (!NILP (help_echo_string) || !NILP (previous_help_echo_string))
left), but I don't think it's worth the effort. */
/* These hold text of the current and the previous menu help messages. */
-static char *menu_help_message, *prev_menu_help_message;
+static const char *menu_help_message, *prev_menu_help_message;
/* Pane number and item number of the menu item which generated the
last menu help message. */
static int menu_help_paneno, menu_help_itemno;
{
XMenu *menu;
- menu = (XMenu *) xmalloc (sizeof (XMenu));
+ menu = xmalloc (sizeof (XMenu));
menu->allocated = menu->count = menu->panecount = menu->width = 0;
return menu;
}
if (menu->allocated == 0)
{
int count = menu->allocated = 10;
- menu->text = (char **) xmalloc (count * sizeof (char *));
- menu->submenu = (XMenu **) xmalloc (count * sizeof (XMenu *));
- menu->panenumber = (int *) xmalloc (count * sizeof (int));
- menu->help_text = (char **) xmalloc (count * sizeof (char *));
+ menu->text = xmalloc (count * sizeof (char *));
+ menu->submenu = xmalloc (count * sizeof (XMenu *));
+ menu->panenumber = xmalloc (count * sizeof (int));
+ menu->help_text = xmalloc (count * sizeof (char *));
}
else if (menu->allocated == menu->count)
{
menu->panenumber
= (int *) xrealloc (menu->panenumber, count * sizeof (int));
menu->help_text
- = (char **) xrealloc (menu->help_text, count * sizeof (char *));
+ = (const char **) xrealloc (menu->help_text, count * sizeof (char *));
}
}
int i, j, face, width, mx, my, enabled, mousehere, row, col;
struct glyph *text, *p;
const unsigned char *q;
- struct frame *sf = SELECTED_FRAME();
+ struct frame *sf = SELECTED_FRAME ();
menu_help_message = NULL;
width = menu->width;
/* We multiply width by 2 to account for possible control characters.
FIXME: cater to non-ASCII characters in menus. */
- text = (struct glyph *) xmalloc ((width * 2 + 2) * sizeof (struct glyph));
+ text = xmalloc ((width * 2 + 2) * sizeof (struct glyph));
ScreenGetCursor (&row, &col);
mouse_get_xy (&mx, &my);
IT_update_begin (sf);
int
XMenuAddSelection (Display *bar, XMenu *menu, int pane,
- int foo, char *txt, int enable, char *help_text)
+ int foo, char *txt, int enable, char const *help_text)
{
int len;
char *p;
int
XMenuActivate (Display *foo, XMenu *menu, int *pane, int *selidx,
int x0, int y0, unsigned ButtonMask, char **txt,
- void (*help_callback)(char *, int, int))
+ void (*help_callback)(char const *, int, int))
{
struct IT_menu_state *state;
int statecount, x, y, i, b, screensize, leave, result, onepane;
int title_faces[4]; /* face to display the menu title */
int faces[4], buffers_num_deleted = 0;
- struct frame *sf = SELECTED_FRAME();
+ struct frame *sf = SELECTED_FRAME ();
Lisp_Object saved_echo_area_message, selectface;
/* Just in case we got here without a mouse present... */
/* Some lusers set TMPDIR=e:, probably because some losing
programs cannot handle multiple slashes if they use e:/.
e: fails in `access' below, so we interpret e: as e:/. */
- tmp_len = strlen(tmp);
+ tmp_len = strlen (tmp);
if (tmp[tmp_len - 1] != '/' && tmp[tmp_len - 1] != '\\')
{
- strcpy(buf, tmp);
+ strcpy (buf, tmp);
buf[tmp_len++] = '/', buf[tmp_len] = 0;
tmp = buf;
}
}
#endif
+char *
+careadlinkat (int fd, char const *filename,
+ char *buffer, size_t buffer_size,
+ struct allocator const *alloc,
+ ssize_t (*preadlinkat) (int, char const *, char *, size_t))
+{
+ if (!buffer)
+ {
+ /* We don't support the fancy auto-allocation feature. */
+ if (!buffer_size)
+ errno = ENOSYS;
+ else
+ errno = EINVAL;
+ buffer = NULL;
+ }
+ else
+ {
+ ssize_t len = preadlinkat (fd, filename, buffer, buffer_size);
+
+ if (len < 0 || len == buffer_size)
+ buffer = NULL;
+ else
+ buffer[len + 1] = '\0';
+ }
+ return buffer;
+}
+
+ssize_t
+careadlinkatcwd (int fd, char const *filename, char *buffer,
+ size_t buffer_size)
+{
+ (void) fd;
+ return readlink (filename, buffer, buffer_size);
+}
+
\f
#if __DJGPP__ == 2 && __DJGPP_MINOR__ < 2
#ifndef HAVE_SELECT
#include "sysselect.h"
-#ifndef EMACS_TIME_ZERO_OR_NEG_P
-#define EMACS_TIME_ZERO_OR_NEG_P(time) \
- ((long)(time).tv_sec < 0 \
- || ((time).tv_sec == 0 \
- && (long)(time).tv_usec <= 0))
-#endif
-
/* This yields the rest of the current time slice to the task manager.
It should be called by any code which knows that it has nothing
useful to do except idle.
because wait_reading_process_output takes care of that. */
int
sys_select (int nfds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, SELECT_TYPE *efds,
- EMACS_TIME *timeout)
+ EMACS_TIME *timeout, void *ignored)
{
int check_input;
- struct time t;
+ struct timespec t;
check_input = 0;
if (rfds)
EMACS_TIME clnow, cllast, cldiff;
gettime (&t);
- EMACS_SET_SECS_USECS (cllast, t.ti_sec, t.ti_hund * 10000L);
+ cllast = make_emacs_time (t.tv_sec, t.tv_nsec);
while (!check_input || !detect_input_pending ())
{
gettime (&t);
- EMACS_SET_SECS_USECS (clnow, t.ti_sec, t.ti_hund * 10000L);
- EMACS_SUB_TIME (cldiff, clnow, cllast);
-
- /* When seconds wrap around, we assume that no more than
- 1 minute passed since last `gettime'. */
- if (EMACS_TIME_NEG_P (cldiff))
- EMACS_SET_SECS (cldiff, EMACS_SECS (cldiff) + 60);
- EMACS_SUB_TIME (*timeout, *timeout, cldiff);
+ clnow = make_emacs_time (t.tv_sec, t.tv_nsec);
+ cldiff = sub_emacs_time (clnow, cllast);
+ *timeout = sub_emacs_time (*timeout, cldiff);
/* Stop when timeout value crosses zero. */
- if (EMACS_TIME_ZERO_OR_NEG_P (*timeout))
+ if (EMACS_TIME_SIGN (*timeout) <= 0)
return 0;
cllast = clnow;
dos_yield_time_slice ();
#ifndef HAVE_X_WINDOWS
/* The following two are from xfns.c: */
- Qreverse = intern_c_string ("reverse");
- staticpro (&Qreverse);
+ DEFSYM (Qreverse, "reverse");
DEFVAR_LISP ("dos-unsupported-char-glyph", Vdos_unsupported_char_glyph,
- doc: /* *Glyph to display instead of chars not supported by current codepage.
+ doc: /* Glyph to display instead of chars not supported by current codepage.
This variable is used only by MS-DOS terminals. */);
Vdos_unsupported_char_glyph = make_number ('\177');