mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
added string utils
This commit is contained in:
@@ -10,6 +10,7 @@ changes since wmaker 0.62.1:
|
|||||||
- added WMReparentWidget()
|
- added WMReparentWidget()
|
||||||
- added WMCreateTabViewItem()
|
- added WMCreateTabViewItem()
|
||||||
- added W_CreateUnmanagedTopView()
|
- added W_CreateUnmanagedTopView()
|
||||||
|
- added wtokenize()
|
||||||
|
|
||||||
changes since wmaker 0.62.0:
|
changes since wmaker 0.62.0:
|
||||||
............................
|
............................
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ libWINGs_a_SOURCES = \
|
|||||||
hashtable.c \
|
hashtable.c \
|
||||||
host.c \
|
host.c \
|
||||||
memory.c \
|
memory.c \
|
||||||
|
string.c \
|
||||||
usleep.c
|
usleep.c
|
||||||
|
|
||||||
|
|
||||||
@@ -105,6 +106,7 @@ libWUtil_a_SOURCES = \
|
|||||||
findfile.c \
|
findfile.c \
|
||||||
hashtable.c \
|
hashtable.c \
|
||||||
memory.c \
|
memory.c \
|
||||||
|
string.c \
|
||||||
usleep.c
|
usleep.c
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -792,6 +792,8 @@ void WMUnmapWidget(WMWidget *w);
|
|||||||
|
|
||||||
void WMMapWidget(WMWidget *w);
|
void WMMapWidget(WMWidget *w);
|
||||||
|
|
||||||
|
void WMRaiseWidget(WMWidget *w);
|
||||||
|
|
||||||
void WMMoveWidget(WMWidget *w, int x, int y);
|
void WMMoveWidget(WMWidget *w, int x, int y);
|
||||||
|
|
||||||
void WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height);
|
void WMResizeWidget(WMWidget *w, unsigned int width, unsigned int height);
|
||||||
|
|||||||
@@ -265,6 +265,20 @@ char *wstrdup(char *str);
|
|||||||
|
|
||||||
char *wstrappend(char *dst, char *src);
|
char *wstrappend(char *dst, char *src);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void wtokensplit(char *command, char ***argv, int *argc);
|
||||||
|
|
||||||
|
char *wtokenjoin(char **list, int count);
|
||||||
|
|
||||||
|
void wtokenfree(char **tokens, int count);
|
||||||
|
|
||||||
|
char *wtrimspace(char *s);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char *wusergnusteppath();
|
char *wusergnusteppath();
|
||||||
|
|
||||||
char *wdefaultspathfordomain(char *domain);
|
char *wdefaultspathfordomain(char *domain);
|
||||||
|
|||||||
181
WINGs/string.c
Normal file
181
WINGs/string.c
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "WUtil.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define PRC_ALPHA 0
|
||||||
|
#define PRC_BLANK 1
|
||||||
|
#define PRC_ESCAPE 2
|
||||||
|
#define PRC_DQUOTE 3
|
||||||
|
#define PRC_EOS 4
|
||||||
|
#define PRC_SQUOTE 5
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
short nstate;
|
||||||
|
short output;
|
||||||
|
} DFA;
|
||||||
|
|
||||||
|
|
||||||
|
static DFA mtable[9][6] = {
|
||||||
|
{{3,1},{0,0},{4,0},{1,0},{8,0},{6,0}},
|
||||||
|
{{1,1},{1,1},{2,0},{3,0},{5,0},{1,1}},
|
||||||
|
{{1,1},{1,1},{1,1},{1,1},{5,0},{1,1}},
|
||||||
|
{{3,1},{5,0},{4,0},{1,0},{5,0},{6,0}},
|
||||||
|
{{3,1},{3,1},{3,1},{3,1},{5,0},{3,1}},
|
||||||
|
{{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
|
||||||
|
{{6,1},{6,1},{7,0},{6,1},{5,0},{3,0}},
|
||||||
|
{{6,1},{6,1},{6,1},{6,1},{5,0},{6,1}},
|
||||||
|
{{-1,-1},{0,0},{0,0},{0,0},{0,0},{0,0}}, /* final state */
|
||||||
|
};
|
||||||
|
|
||||||
|
static char*
|
||||||
|
next_token(char *word, char **next)
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
char *ret, *t;
|
||||||
|
int state, ctype;
|
||||||
|
|
||||||
|
t = ret = wmalloc(strlen(word)+1);
|
||||||
|
ptr = word;
|
||||||
|
|
||||||
|
state = 0;
|
||||||
|
*t = 0;
|
||||||
|
while (1) {
|
||||||
|
if (*ptr==0)
|
||||||
|
ctype = PRC_EOS;
|
||||||
|
else if (*ptr=='\\')
|
||||||
|
ctype = PRC_ESCAPE;
|
||||||
|
else if (*ptr=='"')
|
||||||
|
ctype = PRC_DQUOTE;
|
||||||
|
else if (*ptr=='\'')
|
||||||
|
ctype = PRC_SQUOTE;
|
||||||
|
else if (*ptr==' ' || *ptr=='\t')
|
||||||
|
ctype = PRC_BLANK;
|
||||||
|
else
|
||||||
|
ctype = PRC_ALPHA;
|
||||||
|
|
||||||
|
if (mtable[state][ctype].output) {
|
||||||
|
*t = *ptr; t++;
|
||||||
|
*t = 0;
|
||||||
|
}
|
||||||
|
state = mtable[state][ctype].nstate;
|
||||||
|
ptr++;
|
||||||
|
if (mtable[state][0].output<0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*ret==0)
|
||||||
|
t = NULL;
|
||||||
|
else
|
||||||
|
t = wstrdup(ret);
|
||||||
|
|
||||||
|
free(ret);
|
||||||
|
|
||||||
|
if (ctype==PRC_EOS)
|
||||||
|
*next = NULL;
|
||||||
|
else
|
||||||
|
*next = ptr;
|
||||||
|
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* separate a string in tokens, taking " and ' into account */
|
||||||
|
void
|
||||||
|
wtokensplit(char *command, char ***argv, int *argc)
|
||||||
|
{
|
||||||
|
char *token, *line;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
count = 0;
|
||||||
|
line = command;
|
||||||
|
do {
|
||||||
|
token = next_token(line, &line);
|
||||||
|
if (token) {
|
||||||
|
if (count == 0)
|
||||||
|
*argv = wmalloc(sizeof(char**));
|
||||||
|
else
|
||||||
|
*argv = wrealloc(*argv, (count+1)*sizeof(char**));
|
||||||
|
(*argv)[count++] = token;
|
||||||
|
}
|
||||||
|
} while (token!=NULL && line!=NULL);
|
||||||
|
|
||||||
|
*argc = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char*
|
||||||
|
wtokenjoin(char **list, int count)
|
||||||
|
{
|
||||||
|
int i, j;
|
||||||
|
char *flat_string, *wspace;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
for (i=0; i<count; i++) {
|
||||||
|
if (list[i]!=NULL && list[i][0]!=0) {
|
||||||
|
j += strlen(list[i]);
|
||||||
|
if (strpbrk(list[i], " \t"))
|
||||||
|
j += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flat_string = malloc(j+count+1);
|
||||||
|
if (!flat_string) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
*flat_string = 0;
|
||||||
|
for (i=0; i<count; i++) {
|
||||||
|
if (list[i]!=NULL && list[i][0]!=0) {
|
||||||
|
if (i>0)
|
||||||
|
strcat(flat_string, " ");
|
||||||
|
wspace = strpbrk(list[i], " \t");
|
||||||
|
if (wspace)
|
||||||
|
strcat(flat_string, "\"");
|
||||||
|
strcat(flat_string, list[i]);
|
||||||
|
if (wspace)
|
||||||
|
strcat(flat_string, "\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return flat_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
wtokenfree(char **tokens, int count)
|
||||||
|
{
|
||||||
|
while (--count) free(tokens[count]);
|
||||||
|
free(tokens);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
char*
|
||||||
|
wtrimspace(char *s)
|
||||||
|
{
|
||||||
|
char *t;
|
||||||
|
char *c;
|
||||||
|
|
||||||
|
while (isspace(*s) && *s) s++;
|
||||||
|
t = s+strlen(s);
|
||||||
|
while (t > s && isspace(*t)) t--;
|
||||||
|
|
||||||
|
c = wmalloc(t-s + 1);
|
||||||
|
memcpy(c, s, t-s);
|
||||||
|
c[t-s] = 0;
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This event handling stuff was based on Tk.
|
* This event handling stuff was inspired on Tk.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "WINGsP.h"
|
#include "WINGsP.h"
|
||||||
|
|||||||
@@ -52,6 +52,27 @@ WMRunAlertPanel(WMScreen *scrPtr, WMWindow *owner,
|
|||||||
panel = WMCreateAlertPanel(scrPtr, owner, title, msg, defaultButton,
|
panel = WMCreateAlertPanel(scrPtr, owner, title, msg, defaultButton,
|
||||||
alternateButton, otherButton);
|
alternateButton, otherButton);
|
||||||
|
|
||||||
|
{
|
||||||
|
int px, py;
|
||||||
|
WMView *view = WMWidgetView(panel->win);
|
||||||
|
|
||||||
|
if (owner) {
|
||||||
|
WMView *oview = WMWidgetView(owner);
|
||||||
|
WMPoint pt = WMGetViewScreenPosition(oview);
|
||||||
|
|
||||||
|
px = (W_VIEW_WIDTH(oview)-W_VIEW_WIDTH(view))/2;
|
||||||
|
py = (W_VIEW_HEIGHT(oview)-W_VIEW_HEIGHT(view))/2;
|
||||||
|
|
||||||
|
px += pt.x;
|
||||||
|
py += pt.y;
|
||||||
|
} else {
|
||||||
|
px = (W_VIEW_WIDTH(scrPtr->rootView)-W_VIEW_WIDTH(view))/2;
|
||||||
|
py = (W_VIEW_HEIGHT(scrPtr->rootView)-W_VIEW_HEIGHT(view))/2;
|
||||||
|
}
|
||||||
|
WMSetWindowInitialPosition(panel->win, px, py);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
scrPtr->modalView = W_VIEW(panel->win);
|
scrPtr->modalView = W_VIEW(panel->win);
|
||||||
WMMapWidget(panel->win);
|
WMMapWidget(panel->win);
|
||||||
|
|
||||||
@@ -166,43 +187,56 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner,
|
|||||||
dw = WMWidthOfString(scrPtr->normalFont, defaultButton,
|
dw = WMWidthOfString(scrPtr->normalFont, defaultButton,
|
||||||
strlen(defaultButton));
|
strlen(defaultButton));
|
||||||
|
|
||||||
w = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0);
|
dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0);
|
||||||
if (aw > w)
|
|
||||||
w = aw;
|
aw += 30;
|
||||||
if (ow > w)
|
ow += 30;
|
||||||
w = ow;
|
dw += 30;
|
||||||
|
|
||||||
|
w = WMAX(dw, WMAX(aw, ow));
|
||||||
|
if ((w+10)*3 < 400) {
|
||||||
|
aw = w;
|
||||||
|
ow = w;
|
||||||
|
dw = w;
|
||||||
|
} else {
|
||||||
|
int t;
|
||||||
|
|
||||||
|
t = 400 - 40 - aw - ow - dw;
|
||||||
|
aw += t/3;
|
||||||
|
ow += t/3;
|
||||||
|
dw += t/3;
|
||||||
|
}
|
||||||
|
|
||||||
w += 30;
|
|
||||||
x = 400;
|
x = 400;
|
||||||
|
|
||||||
if (defaultButton) {
|
if (defaultButton) {
|
||||||
x -= w + 10;
|
x -= dw + 10;
|
||||||
|
|
||||||
panel->defBtn = WMCreateCommandButton(panel->win);
|
panel->defBtn = WMCreateCommandButton(panel->win);
|
||||||
WMSetButtonAction(panel->defBtn, alertPanelOnClick, panel);
|
WMSetButtonAction(panel->defBtn, alertPanelOnClick, panel);
|
||||||
WMMoveWidget(panel->defBtn, x, 144);
|
WMMoveWidget(panel->defBtn, x, 144);
|
||||||
WMResizeWidget(panel->defBtn, w, 24);
|
WMResizeWidget(panel->defBtn, dw, 24);
|
||||||
WMSetButtonText(panel->defBtn, defaultButton);
|
WMSetButtonText(panel->defBtn, defaultButton);
|
||||||
WMSetButtonImage(panel->defBtn, scrPtr->buttonArrow);
|
WMSetButtonImage(panel->defBtn, scrPtr->buttonArrow);
|
||||||
WMSetButtonAltImage(panel->defBtn, scrPtr->pushedButtonArrow);
|
WMSetButtonAltImage(panel->defBtn, scrPtr->pushedButtonArrow);
|
||||||
WMSetButtonImagePosition(panel->defBtn, WIPRight);
|
WMSetButtonImagePosition(panel->defBtn, WIPRight);
|
||||||
}
|
}
|
||||||
if (alternateButton) {
|
if (alternateButton) {
|
||||||
x -= w + 10;
|
x -= aw + 10;
|
||||||
|
|
||||||
panel->altBtn = WMCreateCommandButton(panel->win);
|
panel->altBtn = WMCreateCommandButton(panel->win);
|
||||||
WMMoveWidget(panel->altBtn, x, 144);
|
WMMoveWidget(panel->altBtn, x, 144);
|
||||||
WMResizeWidget(panel->altBtn, w, 24);
|
WMResizeWidget(panel->altBtn, aw, 24);
|
||||||
WMSetButtonAction(panel->altBtn, alertPanelOnClick, panel);
|
WMSetButtonAction(panel->altBtn, alertPanelOnClick, panel);
|
||||||
WMSetButtonText(panel->altBtn, alternateButton);
|
WMSetButtonText(panel->altBtn, alternateButton);
|
||||||
}
|
}
|
||||||
if (otherButton) {
|
if (otherButton) {
|
||||||
x -= w + 10;
|
x -= ow + 10;
|
||||||
|
|
||||||
panel->othBtn = WMCreateCommandButton(panel->win);
|
panel->othBtn = WMCreateCommandButton(panel->win);
|
||||||
WMSetButtonAction(panel->othBtn, alertPanelOnClick, panel);
|
WMSetButtonAction(panel->othBtn, alertPanelOnClick, panel);
|
||||||
WMMoveWidget(panel->othBtn, x, 144);
|
WMMoveWidget(panel->othBtn, x, 144);
|
||||||
WMResizeWidget(panel->othBtn, w, 24);
|
WMResizeWidget(panel->othBtn, ow, 24);
|
||||||
WMSetButtonText(panel->othBtn, otherButton);
|
WMSetButtonText(panel->othBtn, otherButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,6 +301,27 @@ WMRunInputPanel(WMScreen *scrPtr, WMWindow *owner, char *title,
|
|||||||
panel = WMCreateInputPanel(scrPtr, owner, title, msg, defaultText,
|
panel = WMCreateInputPanel(scrPtr, owner, title, msg, defaultText,
|
||||||
okButton, cancelButton);
|
okButton, cancelButton);
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
int px, py;
|
||||||
|
WMView *view = WMWidgetView(panel->win);
|
||||||
|
|
||||||
|
if (owner) {
|
||||||
|
WMView *oview = WMWidgetView(owner);
|
||||||
|
WMPoint pt = WMGetViewScreenPosition(oview);
|
||||||
|
|
||||||
|
px = (W_VIEW_WIDTH(oview)-W_VIEW_WIDTH(view))/2;
|
||||||
|
py = (W_VIEW_HEIGHT(oview)-W_VIEW_HEIGHT(view))/2;
|
||||||
|
|
||||||
|
px += pt.x;
|
||||||
|
py += pt.y;
|
||||||
|
} else {
|
||||||
|
px = (W_VIEW_WIDTH(scrPtr->rootView)-W_VIEW_WIDTH(view))/2;
|
||||||
|
py = (W_VIEW_HEIGHT(scrPtr->rootView)-W_VIEW_HEIGHT(view))/2;
|
||||||
|
}
|
||||||
|
WMSetWindowInitialPosition(panel->win, px, py);
|
||||||
|
}
|
||||||
|
|
||||||
WMMapWidget(panel->win);
|
WMMapWidget(panel->win);
|
||||||
|
|
||||||
while (!panel->done || WMScreenPending(scrPtr)) {
|
while (!panel->done || WMScreenPending(scrPtr)) {
|
||||||
|
|||||||
@@ -18,6 +18,12 @@
|
|||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* README README README README README README README
|
||||||
|
* Nwanua: dont use // style comments please!
|
||||||
|
* It doesnt work in lots of compilers out there :/
|
||||||
|
* -Alfredo
|
||||||
|
* README README README README README README README
|
||||||
|
*/
|
||||||
|
|
||||||
#include "WINGsP.h"
|
#include "WINGsP.h"
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|||||||
@@ -692,6 +692,7 @@ WMSetViewNotifySizeChanges(WMView *view, Bool flag)
|
|||||||
view->flags.notifySizeChanged = flag;
|
view->flags.notifySizeChanged = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Window
|
Window
|
||||||
WMViewXID(WMView *view)
|
WMViewXID(WMView *view)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -478,6 +478,7 @@ WMSetWindowInitialPosition(WMWindow *win, int x, int y)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WMSetWindowMinSize(WMWindow *win, unsigned width, unsigned height)
|
WMSetWindowMinSize(WMWindow *win, unsigned width, unsigned height)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user