mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
- Added WMSetWindowUserPosition()
- Replaced FlattenStringList() and TokenizeString() with wtokenjoin() respective wtokensplit() from WINGs
This commit is contained in:
155
src/misc.c
155
src/misc.c
@@ -237,7 +237,8 @@ isBelow(WWindow *win1, WWindow *win2)
|
||||
* XFetchName Wrapper
|
||||
*
|
||||
*/
|
||||
Bool wFetchName(dpy, win, winname)
|
||||
Bool
|
||||
wFetchName(dpy, win, winname)
|
||||
Display *dpy;
|
||||
Window win;
|
||||
char **winname;
|
||||
@@ -281,7 +282,8 @@ char **winname;
|
||||
*
|
||||
*/
|
||||
|
||||
Bool wGetIconName(dpy, win, iconname)
|
||||
Bool
|
||||
wGetIconName(dpy, win, iconname)
|
||||
Display *dpy;
|
||||
Window win;
|
||||
char **iconname;
|
||||
@@ -502,153 +504,6 @@ FindImage(char *paths, char *file)
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
FlattenStringList(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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*----------------------------------------------------------------------
|
||||
* ParseCommand --
|
||||
* Divides a command line into a argv/argc pair.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
#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 */
|
||||
};
|
||||
|
||||
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
|
||||
TokenizeString(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;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
timeoutHandler(void *data)
|
||||
{
|
||||
@@ -875,7 +730,7 @@ get_dnd_selection(WScreen *scr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
flat_string = FlattenStringList(list, count);
|
||||
flat_string = wtokenjoin(list, count);
|
||||
if (!flat_string) {
|
||||
wwarning(_("out of memory while getting data from DND drop"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user