summaryrefslogtreecommitdiff
path: root/app/twm/src
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2006-11-28 13:13:07 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2006-11-28 13:13:07 +0000
commitae3e48afb29cd015e15e8657bb4329b85a9e6537 (patch)
tree0d5f3f141cdfb09744793a2ce48961ce813fe2ae /app/twm/src
parent02371b9fc05f10c1f5fc6ceb00ef6a51da2afa48 (diff)
OpenBSD fixes and customizations.
Diffstat (limited to 'app/twm/src')
-rw-r--r--app/twm/src/iconmgr.c4
-rw-r--r--app/twm/src/menus.c23
-rw-r--r--app/twm/src/parse.c4
-rw-r--r--app/twm/src/resize.c2
-rw-r--r--app/twm/src/session.c18
-rw-r--r--app/twm/src/system.twmrc56
-rw-r--r--app/twm/src/util.c14
7 files changed, 79 insertions, 42 deletions
diff --git a/app/twm/src/iconmgr.c b/app/twm/src/iconmgr.c
index b90b6654b..9eebf9fd4 100644
--- a/app/twm/src/iconmgr.c
+++ b/app/twm/src/iconmgr.c
@@ -97,8 +97,8 @@ void CreateIconManagers()
JunkX, JunkY, p->width, p->height, 1,
Scr->Black, background);
- sprintf(str, "%s Icon Manager", p->name);
- sprintf(str1, "%s Icons", p->name);
+ snprintf(str, sizeof(str), "%s Icon Manager", p->name);
+ snprintf(str1, sizeof(str1), "%s Icons", p->name);
if (p->icon_name)
icon_name = p->icon_name;
else
diff --git a/app/twm/src/menus.c b/app/twm/src/menus.c
index d91dd2412..5aa542015 100644
--- a/app/twm/src/menus.c
+++ b/app/twm/src/menus.c
@@ -1983,8 +1983,8 @@ ExecuteFunction(int func, char *action, Window w, TwmWindow *tmp_win,
break;
case F_CUT:
- strcpy(tmp, action);
- strcat(tmp, "\n");
+ strlcpy(tmp, action, sizeof(tmp));
+ strlcat(tmp, "\n", sizeof(tmp));
XStoreBytes(dpy, tmp, strlen(tmp));
break;
@@ -2155,8 +2155,8 @@ ExecuteFunction(int func, char *action, Window w, TwmWindow *tmp_win,
break;
case F_FILE:
- ptr = ExpandFilename(action);
- fd = open(ptr, O_RDONLY);
+ action = ExpandFilename(action);
+ fd = open(action, O_RDONLY);
if (fd >= 0)
{
count = read(fd, buff, MAX_FILE_SIZE - 1);
@@ -2168,9 +2168,8 @@ ExecuteFunction(int func, char *action, Window w, TwmWindow *tmp_win,
else
{
fprintf (stderr, "%s: unable to open file \"%s\"\n",
- ProgramName, ptr);
+ ProgramName, action);
}
- if (ptr != action) free(ptr);
break;
case F_REFRESH:
@@ -2358,7 +2357,11 @@ Execute(char *s)
oldDisplay[0] = '\0';
doisplay=getenv("DISPLAY");
if (doisplay)
- strcpy (oldDisplay, doisplay);
+ if (strlcpy (oldDisplay, doisplay, sizeof(oldDisplay)) >=
+ sizeof(oldDisplay)) {
+ /* some error report? */
+ return;
+ }
/*
* Build a display string using the current screen number, so that
@@ -2368,8 +2371,8 @@ Execute(char *s)
*/
colon = strrchr (ds, ':');
if (colon) { /* if host[:]:dpy */
- strcpy (buf, "DISPLAY=");
- strcat (buf, ds);
+ strlcpy (buf, "DISPLAY=", sizeof(buf));
+ strlcat (buf, ds, sizeof(buf));
colon = buf + 8 + (colon - ds); /* use version in buf */
dot1 = strchr (colon, '.'); /* first period after colon */
if (!dot1) dot1 = colon + strlen (colon); /* if not there, append */
@@ -2381,7 +2384,7 @@ Execute(char *s)
(void) system (s);
if (restorevar) { /* why bother? */
- (void) sprintf (buf, "DISPLAY=%s", oldDisplay);
+ (void) snprintf (buf, sizeof(buf), "DISPLAY=%s", oldDisplay);
putenv (buf);
}
}
diff --git a/app/twm/src/parse.c b/app/twm/src/parse.c
index 88b0b0887..c89da98e5 100644
--- a/app/twm/src/parse.c
+++ b/app/twm/src/parse.c
@@ -183,8 +183,8 @@ int ParseTwmrc (char *filename)
if (home) {
homelen = strlen (home);
cp = tmpfilename;
- (void) sprintf (tmpfilename, "%s/.twmrc.%d",
- home, Scr->screen);
+ (void) snprintf (tmpfilename, sizeof(tmpfilename),
+ "%s/.twmrc.%d", home, Scr->screen);
break;
}
}
diff --git a/app/twm/src/resize.c b/app/twm/src/resize.c
index 2f114e197..a6950d7f7 100644
--- a/app/twm/src/resize.c
+++ b/app/twm/src/resize.c
@@ -514,7 +514,7 @@ DisplaySize(TwmWindow *tmp_win, int width, int height)
dheight /= tmp_win->hints.height_inc;
}
- (void) sprintf (str, " %4d x %-4d ", dwidth, dheight);
+ (void) snprintf (str, sizeof(str), " %4d x %-4d ", dwidth, dheight);
XRaiseWindow(dpy, Scr->SizeWindow);
MyFont_ChangeGC(Scr->DefaultC.fore, Scr->DefaultC.back, &Scr->SizeFont);
MyFont_DrawImageString (dpy, Scr->SizeWindow, &Scr->SizeFont,
diff --git a/app/twm/src/session.c b/app/twm/src/session.c
index 7c4ce9978..87af4e132 100644
--- a/app/twm/src/session.c
+++ b/app/twm/src/session.c
@@ -741,12 +741,11 @@ int *pFd;
char tempFile[PATH_MAX];
char *tmp;
- sprintf (tempFile, "%s/%sXXXXXX", path, prefix);
+ snprintf (tempFile, sizeof(tempFile), "%s/%sXXXXXX", path, prefix);
tmp = (char *) mktemp (tempFile);
if (tmp)
{
- char *ptr = (char *) malloc (strlen (tmp) + 1);
- strcpy (ptr, tmp);
+ char *ptr = strdup(tmp);
return (ptr);
}
else
@@ -756,13 +755,8 @@ int *pFd;
char tempFile[PATH_MAX];
char *ptr;
- sprintf (tempFile, "%s/%sXXXXXX", path, prefix);
- ptr = (char *)malloc(strlen(tempFile) + 1);
- if (ptr != NULL)
- {
- strcpy(ptr, tempFile);
- *pFd = mkstemp(ptr);
- }
+ snprintf (tempFile, sizeof(tempFile), "%s/%sXXXXXX", path, prefix);
+ ptr = strdup(tempFile);
return ptr;
#endif
}
@@ -805,7 +799,7 @@ SmPointer clientData;
prop1val.value = Argv[0];
prop1val.length = strlen (Argv[0]);
- sprintf (userId, "%ld", (long)getuid());
+ snprintf (userId, sizeof(userId), "%ld", (long)getuid());
prop2.name = SmUserID;
prop2.type = SmARRAY8;
prop2.num_vals = 1;
@@ -924,7 +918,7 @@ SmPointer clientData;
prop1.num_vals = numVals;
- sprintf (discardCommand, "rm %s", filename);
+ snprintf (discardCommand, sizeof(discardCommand), "rm %s", filename);
prop2.name = SmDiscardCommand;
prop2.type = SmARRAY8;
prop2.num_vals = 1;
diff --git a/app/twm/src/system.twmrc b/app/twm/src/system.twmrc
index 740a1e925..c2fcefab3 100644
--- a/app/twm/src/system.twmrc
+++ b/app/twm/src/system.twmrc
@@ -73,6 +73,38 @@ Button2 = : iconmgr : f.iconify
menu "defops"
{
"Twm" f.title
+"XTerm" !"xterm &"
+"" f.nop
+"Utilities" f.menu "Utilities"
+"" f.nop
+"Window Ops" f.menu "Window Ops"
+"" f.nop
+"Kill" f.destroy
+"Delete" f.delete
+"" f.nop
+"Refresh" f.refresh
+"" f.nop
+"(Re)Start" f.menu "Restart"
+"Exit" f.menu "Quit"
+}
+
+menu "Utilities"
+{
+"Top" !"xterm -T Top -n Top -e top &"
+"Calculator" !"xcalc &"
+"Xman" !"xman &"
+"Xmag" !"xmag &"
+"Editres" !"editres &"
+"" f.nop
+#"XEmacs" !"xemacs &"
+#"Mail" !"xmh -font fixed &"
+#"" f.nop
+"XLock" !"xlock -mode random &"
+"Reset X defaults" !"xrdb -load $HOME/.Xdefaults"
+}
+
+menu "Window Ops"
+{
"Iconify" f.iconify
"Resize" f.resize
"Move" f.move
@@ -83,12 +115,24 @@ menu "defops"
"Unfocus" f.unfocus
"Show Iconmgr" f.showiconmgr
"Hide Iconmgr" f.hideiconmgr
+}
+
+menu "Restart"
+{
+"Restart" f.restart
"" f.nop
-"Xterm" f.exec "exec xterm &"
-"" f.nop
-"Kill" f.destroy
-"Delete" f.delete
+"twm" f.startwm "twm"
+"fvwm" f.startwm "fvwm"
+"wm2" f.startwm "wm2"
+"ctwm" f.startwm "ctwm"
+"mwm" f.startwm "mwm"
+"olwm" f.startwm "olwm"
"" f.nop
-"Restart" f.restart
-"Exit" f.quit
+"dummy" f.startwm "xterm"
+}
+menu "Quit"
+{
+"Don't quit" f.nop
+ "" f.nop
+"Really Quit" f.quit
}
diff --git a/app/twm/src/util.c b/app/twm/src/util.c
index 1e8784767..50675fd2f 100644
--- a/app/twm/src/util.c
+++ b/app/twm/src/util.c
@@ -265,14 +265,12 @@ ExpandFilename(char *name)
if (name[0] != '~') return name;
- newname = (char *) malloc (HomeLen + strlen(name) + 2);
+ asprintf(&newname, "%s/%s", Home, &name[1]);
if (!newname) {
fprintf (stderr,
"%s: unable to allocate %ld bytes to expand filename %s/%s\n",
ProgramName, HomeLen + (unsigned long)strlen(name) + 2,
Home, &name[1]);
- } else {
- (void) sprintf (newname, "%s/%s", Home, &name[1]);
}
return newname;
@@ -357,15 +355,13 @@ FindBitmap (char *name, unsigned *widthp, unsigned *heightp)
/*
* Attempt to find icon in old IconDirectory (now obsolete)
*/
- bigname = (char *) malloc (strlen(name) + strlen(Scr->IconDirectory) +
- 2);
+ asprintf(&bigname, "%s/%s", Scr->IconDirectory, name);
if (!bigname) {
fprintf (stderr,
"%s: unable to allocate memory for \"%s/%s\"\n",
ProgramName, Scr->IconDirectory, name);
return None;
}
- (void) sprintf (bigname, "%s/%s", Scr->IconDirectory, name);
if (XReadBitmapFile (dpy, Scr->Root, bigname, widthp, heightp, &pm,
&HotX, &HotY) != BitmapSuccess) {
pm = None;
@@ -600,9 +596,9 @@ GetFont(MyFont *font)
XFreeFontSet(dpy, font->fontset);
}
- basename2 = (char *)malloc(strlen(font->name) + 3);
- if (basename2) sprintf(basename2, "%s,*", font->name);
- else basename2 = font->name;
+ asprintf(&basename2, "%s,*", font->name);
+ if (!basename2)
+ basename2 = font->name;
if( (font->fontset = XCreateFontSet(dpy, basename2,
&missing_charset_list_return,
&missing_charset_count_return,