changeset: 71:d6fbbebd1f04
tag: tip
user: Anselm R. Garbe <arg_AT_suckless.org>
date: Thu Mar 22 14:49:13 2007 +0100
summary: some other fixes/rearrangements
diff -r 9b0522eedb36 -r d6fbbebd1f04 event.c
--- a/event.c Wed Mar 21 14:43:00 2007 +0100
+++ b/event.c Thu Mar 22 14:49:13 2007 +0100
@@ -39,32 +39,6 @@ static unsigned char *selection_text = N
#define SELECT_LINE 3
static void
-selectionpaste(Time tm) {
- int nbytes;
- char *text;
-
- XConvertSelection(dpy, XA_PRIMARY, XA_CUT_BUFFER0, None, win, tm);
- text = XFetchBytes(dpy, &nbytes);
- writecmd(text, nbytes);
-}
-
-static void
-selectionreset(void) {
- int i, j;
-
- selection_mode = SELECT_NONE;
- for(i = 0; i < screen_rows; i++) {
- for(j = 0; j < screen_cols; j++)
- text_screen[i].line[j].sel = 0;
- text_screen[i].needs_update = 1;
- }
- if(selection_text) {
- free(selection_text);
- selection_text = NULL;
- }
-}
-
-static void
selectline(int row, int col, Time tm) {
int i;
@@ -81,6 +55,40 @@ selectline(int row, int col, Time tm) {
text_screen[row-1].needs_update=1;
XStoreBuffer(dpy, (char *)selection_text, screen_cols, XA_CUT_BUFFER0);
XSetSelectionOwner(dpy, XA_PRIMARY, win, tm);
+}
+
+static void
+selectionpaste(Time tm) {
+ int nbytes;
+ char *text;
+
+ XConvertSelection(dpy, XA_PRIMARY, XA_CUT_BUFFER0, None, win, tm);
+ text = XFetchBytes(dpy, &nbytes);
+ writecmd(text, nbytes);
+}
+
+static void
+selectionreset(void) {
+ int i, j;
+
+ selection_mode = SELECT_NONE;
+ for(i = 0; i < screen_rows; i++) {
+ for(j = 0; j < screen_cols; j++)
+ text_screen[i].line[j].sel = 0;
+ text_screen[i].needs_update = 1;
+ }
+ if(selection_text) {
+ free(selection_text);
+ selection_text = NULL;
+ }
+}
+
+static void
+selectionstart(int row, int col, Time tm) {
+ fprintf(stderr, "Selection started, row=%d, col=%d\n", row, col);
+ selectionstart_col = col, selectionstart_row = row;
+ selection_end_col = col, selection_end_row = row;
+ selection_mode = SELECT_LETTER;
}
static void
@@ -106,14 +114,6 @@ selectword(int row, int col, Time tm) {
text_screen[row-1].needs_update = 1;
XStoreBuffer(dpy, (char *)selection_text, len, XA_CUT_BUFFER0);
XSetSelectionOwner(dpy, XA_PRIMARY, win, tm);
-}
-
-static void
-selectionstart(int row, int col, Time tm) {
- fprintf(stderr, "Selection started, row=%d, col=%d\n", row, col);
- selectionstart_col = col, selectionstart_row = row;
- selection_end_col = col, selection_end_row = row;
- selection_mode = SELECT_LETTER;
}
/* event handlers */
@@ -169,7 +169,7 @@ configurenotify(XEvent *xev) {
new_cols = xev->xconfigure.width / dc.font.width;
new_rows = xev->xconfigure.height / dc.font.height;
if(new_cols != screen_cols || new_rows != screen_rows) {
- remallocbuf(new_rows, new_cols);
+ reallocbuf(new_rows, new_cols);
screen_cols = new_cols;
screen_rows = new_rows;
scroll_region_start = 1;
diff -r 9b0522eedb36 -r d6fbbebd1f04 process.c
--- a/process.c Wed Mar 21 14:43:00 2007 +0100
+++ b/process.c Thu Mar 22 14:49:13 2007 +0100
@@ -33,40 +33,6 @@ static int slave;
static int slave;
char *ptydev, *ttydev;
-static void
-updatebuffer(int fd) {
- int len;
-
- waitforinput();
- len = read(fd, &output_buf[0], sizeof(output_buf));
- if(len < 0) {
- fprintf(stderr, "Error reading from command: %m\n");
- exit(1);
- }
- if(len == 0) {
- fprintf(stderr, "No more data! exiting.\n");
- exit(1);
- }
- endptr = len;
- startptr = 0;
-}
-
-static struct passwd *
-getuser(void) {
- uid_t uid;
- struct passwd *pw;
-
- if((uid = getuid()) == -1) {
- fprintf(stderr, "Couldn't find current uid: %m\n");
- exit(2);
- }
- if((pw = getpwuid(uid)) == NULL) {
- fprintf(stderr, "Couldn't find password entry for user %d: %m\n", uid);
- exit(2);
- }
- return pw;
-}
-
static struct winsize *
getwinsize() {
static struct winsize w;
@@ -121,6 +87,22 @@ gettty(void) {
return 0;
}
+static struct passwd *
+getuser(void) {
+ uid_t uid;
+ struct passwd *pw;
+
+ if((uid = getuid()) == -1) {
+ fprintf(stderr, "Couldn't find current uid: %m\n");
+ exit(2);
+ }
+ if((pw = getpwuid(uid)) == NULL) {
+ fprintf(stderr, "Couldn't find password entry for user %d: %m\n", uid);
+ exit(2);
+ }
+ return pw;
+}
+
static void
sigchld(int a) {
int status = 0;
@@ -139,6 +121,24 @@ sigchld(int a) {
else /* Something strange happened */
exit(1);
exit(0);
+}
+
+static void
+updatebuffer(int fd) {
+ int len;
+
+ waitforinput();
+ len = read(fd, &output_buf[0], sizeof(output_buf));
+ if(len < 0) {
+ fprintf(stderr, "Error reading from command: %m\n");
+ exit(1);
+ }
+ if(len == 0) {
+ fprintf(stderr, "No more data! exiting.\n");
+ exit(1);
+ }
+ endptr = len;
+ startptr = 0;
}
/* extern */
@@ -159,15 +159,6 @@ cmdgetc() {
#endif
startptr++;
return r;
-}
-
-int
-writecmd(const char *buf, int len) {
- if(write(cmd_fd, buf, len) < 0) {
- fprintf(stderr, "Error writing to process: %m\n");
- exit(2);
- }
- return 0;
}
int
@@ -263,3 +254,13 @@ waitforinput(void) {
}
}
}
+
+int
+writecmd(const char *buf, int len) {
+ if(write(cmd_fd, buf, len) < 0) {
+ fprintf(stderr, "Error writing to process: %m\n");
+ exit(2);
+ }
+ return 0;
+}
+
diff -r 9b0522eedb36 -r d6fbbebd1f04 st.h
--- a/st.h Wed Mar 21 14:43:00 2007 +0100
+++ b/st.h Thu Mar 22 14:49:13 2007 +0100
@@ -88,7 +88,7 @@ void hidecursor(void);
void hidecursor(void);
Row *mallocbuf(int rows, int cols);
void movecursor(void);
-void remallocbuf(int rows, int cols);
+void reallocbuf(int rows, int cols);
void scrollup(int rows);
void setfg(int c);
void setbg(int c);
diff -r 9b0522eedb36 -r d6fbbebd1f04 vt.c
--- a/vt.c Wed Mar 21 14:43:00 2007 +0100
+++ b/vt.c Thu Mar 22 14:49:13 2007 +0100
@@ -27,31 +27,6 @@ static void winscrolldown(int lines);
static void winscrolldown(int lines);
static void
-reallocbuf(Row **s, int rows, int cols) {
- int i;
-
- if(rows < screen_rows) {
- delrows(*s, 1, screen_rows - rows);
- moverows(*s, screen_rows - rows + 1, 1, rows);
- }
- *s = realloc(*s, rows * sizeof(Row));
- assert(*s);
- if(rows > screen_rows)
- addrows(*s, screen_rows + 1, rows - screen_rows);
- if(cols != screen_cols) {
- for(i = 0; i < rows; i++) {
- int j;
-
- (*s)[i].line = realloc((*s)[i].line, cols * sizeof(Glyph));
- assert((*s)[i].line);
- for(j = screen_cols; j < cols; j++)
- *(int*)(&((*s)[i]).line[j]) = 0;
- (*s)[i].needs_update = 1;
- }
- }
-}
-
-static void
addrows(Row *screen, int pos, int n) {
int i, j;
@@ -321,10 +296,29 @@ mallocbuf(int rows, int cols) {
}
void
-remallocbuf(int rows, int cols) {
- if(using_alternate_screen)
- reallocbuf(&saved_screen, rows, cols);
- reallocbuf(&text_screen, rows, cols);
+reallocbuf(int rows, int cols) {
+ int i;
+ Row **s = using_alternate_screen ? &saved_screen : &text_screen;
+
+ if(rows < screen_rows) {
+ delrows(*s, 1, screen_rows - rows);
+ moverows(*s, screen_rows - rows + 1, 1, rows);
+ }
+ *s = realloc(*s, rows * sizeof(Row));
+ assert(*s);
+ if(rows > screen_rows)
+ addrows(*s, screen_rows + 1, rows - screen_rows);
+ if(cols != screen_cols) {
+ for(i = 0; i < rows; i++) {
+ int j;
+
+ (*s)[i].line = realloc((*s)[i].line, cols * sizeof(Glyph));
+ assert((*s)[i].line);
+ for(j = screen_cols; j < cols; j++)
+ *(int*)(&((*s)[i]).line[j]) = 0;
+ (*s)[i].needs_update = 1;
+ }
+ }
}
void
Received on Thu Mar 22 2007 - 14:52:55 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:21 UTC