1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-01-01 11:32:34 +01:00

Change to the linux kernel coding style

for arq in `git ls-files *.c`; do
    echo $arq;
    indent -linux -l115 $arq;
    done

The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
Carlos R. Mafra
2009-08-20 00:59:40 +02:00
parent 59fc927dc9
commit 688a56e8ab
209 changed files with 87034 additions and 98138 deletions

View File

@@ -20,7 +20,6 @@
* USA.
*/
#define PROG_VERSION "convertfonts (Window Maker) 1.0"
#include <stdlib.h>
@@ -32,119 +31,111 @@
#include "../src/wconfig.h"
char *FontOptions[] = {
"IconTitleFont",
"ClipTitleFont",
"DisplayFont",
"LargeDisplayFont",
"MenuTextFont",
"MenuTitleFont",
"WindowTitleFont",
"SystemFont",
"BoldSystemFont",
NULL
"IconTitleFont",
"ClipTitleFont",
"DisplayFont",
"LargeDisplayFont",
"MenuTextFont",
"MenuTitleFont",
"WindowTitleFont",
"SystemFont",
"BoldSystemFont",
NULL
};
char *ProgName;
extern char* convertFont(char *font, Bool keepXLFD);
extern char *convertFont(char *font, Bool keepXLFD);
void
print_help()
void print_help()
{
printf("\nUsage: %s <style_file>\n\n", ProgName);
puts("Converts fonts in a style file into fontconfig format");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
puts(" to the font name. This property is not used by the fontconfig");
puts(" matching engine to find the font, but it is useful as a hint");
puts(" about what the original font was to allow hand tuning the");
puts(" result or restoring the xlfd. The default is to not add it");
puts(" as it results in long, unreadable and confusing names.");
puts("");
printf("\nUsage: %s <style_file>\n\n", ProgName);
puts("Converts fonts in a style file into fontconfig format");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
puts(" --keep-xlfd preserve the original xlfd by appending a ':xlfd=<xlfd>' hint");
puts(" to the font name. This property is not used by the fontconfig");
puts(" matching engine to find the font, but it is useful as a hint");
puts(" about what the original font was to allow hand tuning the");
puts(" result or restoring the xlfd. The default is to not add it");
puts(" as it results in long, unreadable and confusing names.");
puts("");
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
WMPropList *style, *key, *val;
char *file = NULL, *oldfont, *newfont;
struct stat statbuf;
Bool keepXLFD = False;
int i;
WMPropList *style, *key, *val;
char *file = NULL, *oldfont, *newfont;
struct stat statbuf;
Bool keepXLFD = False;
int i;
ProgName = argv[0];
ProgName = argv[0];
if (argc<2) {
print_help();
exit(0);
}
if (argc < 2) {
print_help();
exit(0);
}
for (i=1; i < argc; i++) {
if (strcmp("--version", argv[i])==0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp("--help", argv[i])==0) {
print_help();
exit(0);
} else if (strcmp("--keep-xlfd", argv[i])==0) {
keepXLFD = True;;
} else if (argv[i][0]=='-') {
printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
printf("Try '%s --help' for more information\n", ProgName);
exit(1);
} else {
file = argv[i];
}
}
for (i = 1; i < argc; i++) {
if (strcmp("--version", argv[i]) == 0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp("--help", argv[i]) == 0) {
print_help();
exit(0);
} else if (strcmp("--keep-xlfd", argv[i]) == 0) {
keepXLFD = True;;
} else if (argv[i][0] == '-') {
printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
printf("Try '%s --help' for more information\n", ProgName);
exit(1);
} else {
file = argv[i];
}
}
/* we need this in order for MB_CUR_MAX to work */
setlocale(LC_ALL, "");
/* we need this in order for MB_CUR_MAX to work */
setlocale(LC_ALL, "");
WMPLSetCaseSensitive(False);
WMPLSetCaseSensitive(False);
if (stat(file, &statbuf) < 0) {
perror(file);
exit(1);
}
if (stat(file, &statbuf) < 0) {
perror(file);
exit(1);
}
style = WMReadPropListFromFile(file);
if (!style) {
perror(file);
printf("%s: could not load style file.\n", ProgName);
exit(1);
}
style = WMReadPropListFromFile(file);
if (!style) {
perror(file);
printf("%s: could not load style file.\n", ProgName);
exit(1);
}
if (!WMIsPLDictionary(style)) {
printf("%s: '%s' is not a well formatted style file\n", ProgName, file);
exit(1);
}
if (!WMIsPLDictionary(style)) {
printf("%s: '%s' is not a well formatted style file\n", ProgName, file);
exit(1);
}
for (i=0; FontOptions[i]!=NULL; i++) {
key = WMCreatePLString(FontOptions[i]);
val = WMGetFromPLDictionary(style, key);
if (val) {
oldfont = WMGetFromPLString(val);
newfont = convertFont(oldfont, keepXLFD);
if (oldfont != newfont) {
val = WMCreatePLString(newfont);
WMPutInPLDictionary(style, key, val);
WMReleasePropList(val);
wfree(newfont);
}
}
WMReleasePropList(key);
}
for (i = 0; FontOptions[i] != NULL; i++) {
key = WMCreatePLString(FontOptions[i]);
val = WMGetFromPLDictionary(style, key);
if (val) {
oldfont = WMGetFromPLString(val);
newfont = convertFont(oldfont, keepXLFD);
if (oldfont != newfont) {
val = WMCreatePLString(newfont);
WMPutInPLDictionary(style, key, val);
WMReleasePropList(val);
wfree(newfont);
}
}
WMReleasePropList(key);
}
WMWritePropListToFile(style, file, True);
WMWritePropListToFile(style, file, True);
exit(0);
exit(0);
}

View File

@@ -20,11 +20,8 @@
* USA.
*/
#include "../src/config.h"
#ifdef USE_JPEG
#include <stdlib.h>
@@ -37,186 +34,172 @@
#include <setjmp.h>
struct my_error_mgr {
struct jpeg_error_mgr pub; /* "public" fields */
struct jpeg_error_mgr pub; /* "public" fields */
jmp_buf setjmp_buffer; /* for return to caller */
jmp_buf setjmp_buffer; /* for return to caller */
};
typedef struct my_error_mgr * my_error_ptr;
typedef struct my_error_mgr *my_error_ptr;
/*
* Here's the routine that will replace the standard error_exit method:
*/
static void
my_error_exit (j_common_ptr cinfo)
static void my_error_exit(j_common_ptr cinfo)
{
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
my_error_ptr myerr = (my_error_ptr) cinfo->err;
/* cinfo->err really points to a my_error_mgr struct, so coerce pointer */
my_error_ptr myerr = (my_error_ptr) cinfo->err;
/* Always display the message. */
/* We could postpone this until after returning, if we chose. */
(*cinfo->err->output_message) (cinfo);
/* Always display the message. */
/* We could postpone this until after returning, if we chose. */
(*cinfo->err->output_message) (cinfo);
/* Return control to the setjmp point */
longjmp(myerr->setjmp_buffer, 1);
/* Return control to the setjmp point */
longjmp(myerr->setjmp_buffer, 1);
}
static Bool
canLoad(RContext *rc)
static Bool canLoad(RContext * rc)
{
if (rc->depth != 16 || rc->vclass != TrueColor
|| rc->red_offset!=11 || rc->green_offset!=5 || rc->blue_offset!=0)
return False;
if (rc->depth != 16 || rc->vclass != TrueColor
|| rc->red_offset != 11 || rc->green_offset != 5 || rc->blue_offset != 0)
return False;
return True;
return True;
}
static void
readData(RContext *rc, struct jpeg_decompress_struct *cinfo,
JSAMPROW *buffer, RXImage *ximg)
static void readData(RContext * rc, struct jpeg_decompress_struct *cinfo, JSAMPROW * buffer, RXImage * ximg)
{
int i, j;
unsigned long pixel;
int y = 0;
int i, j;
unsigned long pixel;
int y = 0;
/* for 16bpp only */
while (cinfo->output_scanline < cinfo->output_height) {
/* for 16bpp only */
while (cinfo->output_scanline < cinfo->output_height) {
jpeg_read_scanlines(cinfo, buffer, (JDIMENSION)1);
jpeg_read_scanlines(cinfo, buffer, (JDIMENSION) 1);
if (cinfo->out_color_space==JCS_RGB) {
for (i=0,j=0; i<cinfo->image_width; i++) {
if (cinfo->out_color_space == JCS_RGB) {
for (i = 0, j = 0; i < cinfo->image_width; i++) {
printf("%i %i %i\n",
(((unsigned long)buffer[0][j])&0xf8)<<8,
(((unsigned long)buffer[0][j+1])&0xf4)<<3,
(((unsigned long)buffer[0][j+2]))>>3);
printf("%i %i %i\n",
(((unsigned long)buffer[0][j]) & 0xf8) << 8,
(((unsigned long)buffer[0][j + 1]) & 0xf4) << 3,
(((unsigned long)buffer[0][j + 2])) >> 3);
pixel = (((unsigned long)buffer[0][j++])&0xf8)<<8
|(((unsigned long)buffer[0][j++])&0xf4)<<3
|(((unsigned long)buffer[0][j++]))>>3;
pixel = (((unsigned long)buffer[0][j++]) & 0xf8) << 8
| (((unsigned long)buffer[0][j++]) & 0xf4) << 3
| (((unsigned long)buffer[0][j++])) >> 3;
XPutPixel(ximg->image, i, y, pixel);
}
} else {
for (i=0,j=0; i<cinfo->image_width; i++, j++) {
XPutPixel(ximg->image, i, y, pixel);
}
} else {
for (i = 0, j = 0; i < cinfo->image_width; i++, j++) {
pixel = (unsigned long)buffer[0][j]<<8
|(unsigned long)buffer[0][j]<<3
|(unsigned long)buffer[0][j]>>3;
pixel = (unsigned long)buffer[0][j] << 8
| (unsigned long)buffer[0][j] << 3 | (unsigned long)buffer[0][j] >> 3;
XPutPixel(ximg->image, i, y, pixel);
}
}
y++;
}
XPutPixel(ximg->image, i, y, pixel);
}
}
y++;
}
}
Pixmap
LoadJPEG(RContext *rc, char *file_name, int *width, int *height)
Pixmap LoadJPEG(RContext * rc, char *file_name, int *width, int *height)
{
struct jpeg_decompress_struct cinfo;
JSAMPROW buffer[1];
FILE *file;
struct my_error_mgr jerr;
RXImage *ximg = NULL;
unsigned char buf[8];
Pixmap p = None;
struct jpeg_decompress_struct cinfo;
JSAMPROW buffer[1];
FILE *file;
struct my_error_mgr jerr;
RXImage *ximg = NULL;
unsigned char buf[8];
Pixmap p = None;
if (!canLoad(rc))
return None;
if (!canLoad(rc))
return None;
file = fopen(file_name, "rb");
if (!file) {
return None;
}
if (fread(buf, 2, 1, file) != 1) {
fclose(file);
return None;
}
if (buf[0] != 0xff || buf[1] != 0xd8) {
fclose(file);
return None;
}
rewind(file);
file = fopen(file_name, "rb");
if (!file) {
return None;
}
if (fread(buf, 2, 1, file) != 1) {
fclose(file);
return None;
}
if (buf[0] != 0xff || buf[1] != 0xd8) {
fclose(file);
return None;
}
rewind(file);
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(&cinfo);
fclose(file);
cinfo.err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit;
/* Establish the setjmp return context for my_error_exit to use. */
if (setjmp(jerr.setjmp_buffer)) {
/* If we get here, the JPEG code has signaled an error.
* We need to clean up the JPEG object, close the input file, and return.
*/
jpeg_destroy_decompress(&cinfo);
fclose(file);
if (ximg) {
RDestroyXImage(rc, ximg);
}
if (ximg) {
RDestroyXImage(rc, ximg);
}
return None;
}
return None;
}
jpeg_create_decompress(&cinfo);
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo, file);
jpeg_stdio_src(&cinfo, file);
jpeg_read_header(&cinfo, TRUE);
jpeg_read_header(&cinfo, TRUE);
buffer[0] = (JSAMPROW)malloc(cinfo.image_width*cinfo.num_components);
if (!buffer[0]) {
RErrorCode = RERR_NOMEMORY;
goto bye;
}
buffer[0] = (JSAMPROW) malloc(cinfo.image_width * cinfo.num_components);
if (!buffer[0]) {
RErrorCode = RERR_NOMEMORY;
goto bye;
}
if(cinfo.jpeg_color_space==JCS_GRAYSCALE) {
cinfo.out_color_space=JCS_GRAYSCALE;
} else
cinfo.out_color_space = JCS_RGB;
cinfo.quantize_colors = FALSE;
cinfo.do_fancy_upsampling = FALSE;
cinfo.do_block_smoothing = FALSE;
jpeg_calc_output_dimensions(&cinfo);
if (cinfo.jpeg_color_space == JCS_GRAYSCALE) {
cinfo.out_color_space = JCS_GRAYSCALE;
} else
cinfo.out_color_space = JCS_RGB;
cinfo.quantize_colors = FALSE;
cinfo.do_fancy_upsampling = FALSE;
cinfo.do_block_smoothing = FALSE;
jpeg_calc_output_dimensions(&cinfo);
ximg = RCreateXImage(rc, rc->depth, cinfo.image_width, cinfo.image_height);
if (!ximg) {
goto bye;
}
jpeg_start_decompress(&cinfo);
ximg = RCreateXImage(rc, rc->depth, cinfo.image_width, cinfo.image_height);
if (!ximg) {
goto bye;
}
jpeg_start_decompress(&cinfo);
readData(rc, &cinfo, buffer, ximg);
readData(rc, &cinfo, buffer, ximg);
jpeg_finish_decompress(&cinfo);
jpeg_finish_decompress(&cinfo);
p = XCreatePixmap(rc->dpy, rc->drawable, cinfo.image_width,
cinfo.image_height, rc->depth);
p = XCreatePixmap(rc->dpy, rc->drawable, cinfo.image_width, cinfo.image_height, rc->depth);
RPutXImage(rc, p, rc->copy_gc, ximg, 0, 0, 0, 0, cinfo.image_width,
cinfo.image_height);
RPutXImage(rc, p, rc->copy_gc, ximg, 0, 0, 0, 0, cinfo.image_width, cinfo.image_height);
*width = cinfo.image_width;
*height = cinfo.image_height;
*width = cinfo.image_width;
*height = cinfo.image_height;
bye:
jpeg_destroy_decompress(&cinfo);
bye:
jpeg_destroy_decompress(&cinfo);
fclose(file);
fclose(file);
if (buffer[0])
free(buffer[0]);
if (buffer[0])
free(buffer[0]);
if (ximg)
RDestroyXImage(rc, ximg);
if (ximg)
RDestroyXImage(rc, ximg);
return p;
return p;
}
#endif /* USE_JPEG */
#endif /* USE_JPEG */

View File

@@ -8,188 +8,171 @@
#define DEFAULT_FONT "sans serif:pixelsize=12"
static int
countChar(char *str, char c)
static int countChar(char *str, char c)
{
int count = 0;
int count = 0;
if (!str)
return 0;
if (!str)
return 0;
for (; *str!=0; str++) {
if (*str == c) {
count++;
}
}
for (; *str != 0; str++) {
if (*str == c) {
count++;
}
}
return count;
return count;
}
typedef struct str {
char *str;
int len;
char *str;
int len;
} str;
#define XLFD_TOKENS 14
static str*
getXLFDTokens(char *xlfd)
static str *getXLFDTokens(char *xlfd)
{
static str tokens[XLFD_TOKENS];
int i, len, size;
char *ptr;
static str tokens[XLFD_TOKENS];
int i, len, size;
char *ptr;
if (!xlfd || *xlfd!='-' || countChar(xlfd, '-')<XLFD_TOKENS)
return NULL;
if (!xlfd || *xlfd != '-' || countChar(xlfd, '-') < XLFD_TOKENS)
return NULL;
memset(tokens, 0, sizeof(str)*XLFD_TOKENS);
memset(tokens, 0, sizeof(str) * XLFD_TOKENS);
len = strlen(xlfd);
len = strlen(xlfd);
for (ptr=xlfd, i=0; i<XLFD_TOKENS && len>0; i++) {
/* skip one '-' */
ptr++;
len--;
if (len <= 0)
break;
size = strcspn(ptr, "-,");
tokens[i].str = ptr;
tokens[i].len = size;
ptr += size;
len -= size;
}
for (ptr = xlfd, i = 0; i < XLFD_TOKENS && len > 0; i++) {
/* skip one '-' */
ptr++;
len--;
if (len <= 0)
break;
size = strcspn(ptr, "-,");
tokens[i].str = ptr;
tokens[i].len = size;
ptr += size;
len -= size;
}
return tokens;
return tokens;
}
static int
strToInt(str *token)
static int strToInt(str * token)
{
int res=0, pos, c;
int res = 0, pos, c;
if (token->len==0 || token->str[0]=='*') {
return -1;
} else {
for (res=0, pos=0; pos<token->len; pos++) {
c = token->str[pos] - '0';
if (c<0 || c>9)
break;
res = res*10 + c;
}
}
return res;
if (token->len == 0 || token->str[0] == '*') {
return -1;
} else {
for (res = 0, pos = 0; pos < token->len; pos++) {
c = token->str[pos] - '0';
if (c < 0 || c > 9)
break;
res = res * 10 + c;
}
}
return res;
}
static char*
mapWeightToName(str *weight)
static char *mapWeightToName(str * weight)
{
char *normalNames[] = {"medium", "normal", "regular"};
static char buf[32];
int i;
char *normalNames[] = { "medium", "normal", "regular" };
static char buf[32];
int i;
if (weight->len==0)
return "";
if (weight->len == 0)
return "";
for (i=0; i<sizeof(normalNames)/sizeof(char*); i++) {
if (strlen(normalNames[i])==weight->len &&
strncmp(normalNames[i], weight->str, weight->len))
{
return "";
}
}
for (i = 0; i < sizeof(normalNames) / sizeof(char *); i++) {
if (strlen(normalNames[i]) == weight->len && strncmp(normalNames[i], weight->str, weight->len)) {
return "";
}
}
snprintf(buf, sizeof(buf), ":%.*s", weight->len, weight->str);
snprintf(buf, sizeof(buf), ":%.*s", weight->len, weight->str);
return buf;
return buf;
}
static char*
mapSlantToName(str *slant)
static char *mapSlantToName(str * slant)
{
if (slant->len==0)
return "";
if (slant->len == 0)
return "";
switch(slant->str[0]) {
case 'i':
return ":italic";
case 'o':
return ":oblique";
case 'r':
default:
return "";
}
switch (slant->str[0]) {
case 'i':
return ":italic";
case 'o':
return ":oblique";
case 'r':
default:
return "";
}
}
char*
xlfdToFc(char *xlfd, char *useFamily, Bool keepXLFD)
char *xlfdToFc(char *xlfd, char *useFamily, Bool keepXLFD)
{
str *tokens, *family, *weight, *slant;
char *name, buf[64];
int size, pixelsize;
str *tokens, *family, *weight, *slant;
char *name, buf[64];
int size, pixelsize;
tokens = getXLFDTokens(xlfd);
if (!tokens)
return wstrdup(DEFAULT_FONT);
tokens = getXLFDTokens(xlfd);
if (!tokens)
return wstrdup(DEFAULT_FONT);
family = &(tokens[1]);
weight = &(tokens[2]);
slant = &(tokens[3]);
pixelsize = strToInt(&tokens[6]);
size = strToInt(&tokens[7]);
family = &(tokens[1]);
weight = &(tokens[2]);
slant = &(tokens[3]);
pixelsize = strToInt(&tokens[6]);
size = strToInt(&tokens[7]);
if (useFamily) {
name = wstrdup(useFamily);
} else {
if (family->len==0 || family->str[0]=='*')
return wstrdup(DEFAULT_FONT);
if (useFamily) {
name = wstrdup(useFamily);
} else {
if (family->len == 0 || family->str[0] == '*')
return wstrdup(DEFAULT_FONT);
snprintf(buf, sizeof(buf), "%.*s", family->len, family->str);
name = wstrdup(buf);
}
snprintf(buf, sizeof(buf), "%.*s", family->len, family->str);
name = wstrdup(buf);
}
if (size>0 && pixelsize<=0) {
snprintf(buf, sizeof(buf), "-%d", size/10);
name = wstrappend(name, buf);
}
if (size > 0 && pixelsize <= 0) {
snprintf(buf, sizeof(buf), "-%d", size / 10);
name = wstrappend(name, buf);
}
name = wstrappend(name, mapWeightToName(weight));
name = wstrappend(name, mapSlantToName(slant));
name = wstrappend(name, mapWeightToName(weight));
name = wstrappend(name, mapSlantToName(slant));
if (size<=0 && pixelsize<=0) {
name = wstrappend(name, ":pixelsize=12");
} else if (pixelsize>0) {
/* if pixelsize is present size will be ignored so we skip it */
snprintf(buf, sizeof(buf), ":pixelsize=%d", pixelsize);
name = wstrappend(name, buf);
}
if (size <= 0 && pixelsize <= 0) {
name = wstrappend(name, ":pixelsize=12");
} else if (pixelsize > 0) {
/* if pixelsize is present size will be ignored so we skip it */
snprintf(buf, sizeof(buf), ":pixelsize=%d", pixelsize);
name = wstrappend(name, buf);
}
if (keepXLFD) {
name = wstrappend(name, ":xlfd=");
name = wstrappend(name, xlfd);
}
if (keepXLFD) {
name = wstrappend(name, ":xlfd=");
name = wstrappend(name, xlfd);
}
return name;
return name;
}
/* return converted font (if conversion is needed) else the original font */
char*
convertFont(char *font, Bool keepXLFD)
char *convertFont(char *font, Bool keepXLFD)
{
if (font[0]=='-') {
if (MB_CUR_MAX < 2) {
return xlfdToFc(font, NULL, keepXLFD);
} else {
return xlfdToFc(font, "sans serif", keepXLFD);
}
} else {
return font;
}
if (font[0] == '-') {
if (MB_CUR_MAX < 2) {
return xlfdToFc(font, NULL, keepXLFD);
} else {
return xlfdToFc(font, "sans serif", keepXLFD);
}
} else {
return font;
}
}

View File

@@ -22,7 +22,6 @@
#define PROG_VERSION "geticonset (Window Maker) 0.1"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -31,110 +30,97 @@
#include "../src/wconfig.h"
char *ProgName;
char*
defaultsPathForDomain(char *domain)
char *defaultsPathForDomain(char *domain)
{
static char path[1024];
char *gspath;
static char path[1024];
char *gspath;
gspath = getenv("GNUSTEP_USER_ROOT");
if (gspath) {
strcpy(path, gspath);
strcat(path, "/");
} else {
char *home;
gspath = getenv("GNUSTEP_USER_ROOT");
if (gspath) {
strcpy(path, gspath);
strcat(path, "/");
} else {
char *home;
home = getenv("HOME");
if (!home) {
printf("%s:could not get HOME environment variable!\n", ProgName);
exit(0);
}
strcpy(path, home);
strcat(path, "/GNUstep/");
}
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, domain);
home = getenv("HOME");
if (!home) {
printf("%s:could not get HOME environment variable!\n", ProgName);
exit(0);
}
strcpy(path, home);
strcat(path, "/GNUstep/");
}
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, domain);
return path;
return path;
}
void
print_help()
void print_help()
{
printf("Usage: %s [OPTIONS] [FILE]\n", ProgName);
puts("Retrieves program icon configuration and output to FILE or to stdout");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
printf("Usage: %s [OPTIONS] [FILE]\n", ProgName);
puts("Retrieves program icon configuration and output to FILE or to stdout");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
WMPropList *all_windows, *iconset, *keylist;
char *path;
int i;
WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
WMPropList *all_windows, *iconset, *keylist;
char *path;
int i;
ProgName = argv[0];
ProgName = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
}
}
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h")==0
|| strcmp(argv[i], "--help")==0) {
print_help();
exit(0);
} else if (strcmp(argv[i], "--version")==0) {
puts(PROG_VERSION);
exit(0);
}
}
path = defaultsPathForDomain("WMWindowAttributes");
path = defaultsPathForDomain("WMWindowAttributes");
all_windows = WMReadPropListFromFile(path);
if (!all_windows) {
printf("%s:could not load WindowMaker configuration file \"%s\".\n", ProgName, path);
exit(1);
}
all_windows = WMReadPropListFromFile(path);
if (!all_windows) {
printf("%s:could not load WindowMaker configuration file \"%s\".\n",
ProgName, path);
exit(1);
}
iconset = WMCreatePLDictionary(NULL, NULL);
iconset = WMCreatePLDictionary(NULL, NULL);
keylist = WMGetPLDictionaryKeys(all_windows);
icon_key = WMCreatePLString("Icon");
keylist = WMGetPLDictionaryKeys(all_windows);
icon_key = WMCreatePLString("Icon");
for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
WMPropList *icondic;
for (i=0; i<WMGetPropListItemCount(keylist); i++) {
WMPropList *icondic;
window_name = WMGetFromPLArray(keylist, i);
if (!WMIsPLString(window_name))
continue;
window_name = WMGetFromPLArray(keylist, i);
if (!WMIsPLString(window_name))
continue;
window_attrs = WMGetFromPLDictionary(all_windows, window_name);
if (window_attrs && WMIsPLDictionary(window_attrs)) {
icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
if (icon_value) {
icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
WMPutInPLDictionary(iconset, window_name, icondic);
}
}
}
window_attrs = WMGetFromPLDictionary(all_windows, window_name);
if (window_attrs && WMIsPLDictionary(window_attrs)) {
icon_value = WMGetFromPLDictionary(window_attrs, icon_key);
if (icon_value) {
icondic = WMCreatePLDictionary(icon_key, icon_value, NULL);
WMPutInPLDictionary(iconset, window_name, icondic);
}
}
}
if (argc==2) {
WMWritePropListToFile(iconset, argv[1], False);
} else {
puts(WMGetPropListDescription(iconset, True));
}
exit(0);
if (argc == 2) {
WMWritePropListToFile(iconset, argv[1], False);
} else {
puts(WMGetPropListDescription(iconset, True));
}
exit(0);
}

File diff suppressed because it is too large Load Diff

View File

@@ -22,7 +22,6 @@
#define PROG_VERSION "seticons (Window Maker) 0.1"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -32,122 +31,111 @@
char *ProgName;
char*
defaultsPathForDomain(char *domain)
char *defaultsPathForDomain(char *domain)
{
static char path[1024];
char *gspath;
static char path[1024];
char *gspath;
gspath = getenv("GNUSTEP_USER_ROOT");
if (gspath) {
strcpy(path, gspath);
strcat(path, "/");
} else {
char *home;
gspath = getenv("GNUSTEP_USER_ROOT");
if (gspath) {
strcpy(path, gspath);
strcat(path, "/");
} else {
char *home;
home = getenv("HOME");
if (!home) {
printf("%s:could not get HOME environment variable!\n", ProgName);
exit(0);
}
home = getenv("HOME");
if (!home) {
printf("%s:could not get HOME environment variable!\n", ProgName);
exit(0);
}
strcpy(path, home);
strcat(path, "/GNUstep/");
}
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, domain);
strcpy(path, home);
strcat(path, "/GNUstep/");
}
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, domain);
return path;
return path;
}
void
print_help()
void print_help()
{
printf("Usage: %s [OPTIONS] FILE\n", ProgName);
puts("Reads icon configuration from FILE and updates Window Maker.");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
printf("Usage: %s [OPTIONS] FILE\n", ProgName);
puts("Reads icon configuration from FILE and updates Window Maker.");
puts("");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
WMPropList *all_windows, *iconset, *keylist;
int i;
char *path = NULL;
WMPropList *window_name, *icon_key, *window_attrs, *icon_value;
WMPropList *all_windows, *iconset, *keylist;
int i;
char *path = NULL;
ProgName = argv[0];
ProgName = argv[0];
if (argc < 2) {
printf("%s: missing argument\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
}
if (argc < 2) {
printf("%s: missing argument\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
}
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
print_help();
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
} else {
if (path) {
printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
printf("Try '%s --help' for more information\n", ProgName);
exit(1);
}
path = argv[i];
}
}
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-h")==0
|| strcmp(argv[i], "--help")==0) {
print_help();
exit(0);
} else if (strcmp(argv[i], "--version")==0) {
puts(PROG_VERSION);
exit(0);
} else {
if (path) {
printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
printf("Try '%s --help' for more information\n", ProgName);
exit(1);
}
path = argv[i];
}
}
path = defaultsPathForDomain("WMWindowAttributes");
path = defaultsPathForDomain("WMWindowAttributes");
all_windows = WMReadPropListFromFile(path);
if (!all_windows) {
printf("%s:could not load WindowMaker configuration file \"%s\".\n", ProgName, path);
exit(1);
}
all_windows = WMReadPropListFromFile(path);
if (!all_windows) {
printf("%s:could not load WindowMaker configuration file \"%s\".\n",
ProgName, path);
exit(1);
}
iconset = WMReadPropListFromFile(argv[1]);
if (!iconset) {
printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
exit(1);
}
iconset = WMReadPropListFromFile(argv[1]);
if (!iconset) {
printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
exit(1);
}
keylist = WMGetPLDictionaryKeys(iconset);
icon_key = WMCreatePLString("Icon");
for (i = 0; i < WMGetPropListItemCount(keylist); i++) {
window_name = WMGetFromPLArray(keylist, i);
if (!WMIsPLString(window_name))
continue;
keylist = WMGetPLDictionaryKeys(iconset);
icon_key = WMCreatePLString("Icon");
icon_value = WMGetFromPLDictionary(iconset, window_name);
if (!icon_value || !WMIsPLDictionary(icon_value))
continue;
for (i=0; i<WMGetPropListItemCount(keylist); i++) {
window_name = WMGetFromPLArray(keylist, i);
if (!WMIsPLString(window_name))
continue;
window_attrs = WMGetFromPLDictionary(all_windows, window_name);
if (window_attrs) {
if (WMIsPLDictionary(window_attrs)) {
WMMergePLDictionaries(window_attrs, icon_value, True);
}
} else {
WMPutInPLDictionary(all_windows, window_name, icon_value);
}
}
icon_value = WMGetFromPLDictionary(iconset, window_name);
if (!icon_value || !WMIsPLDictionary(icon_value))
continue;
WMWritePropListToFile(all_windows, path, True);
window_attrs = WMGetFromPLDictionary(all_windows, window_name);
if (window_attrs) {
if (WMIsPLDictionary(window_attrs)) {
WMMergePLDictionaries(window_attrs, icon_value, True);
}
} else {
WMPutInPLDictionary(all_windows, window_name, icon_value);
}
}
WMWritePropListToFile(all_windows, path, True);
exit(0);
exit(0);
}

File diff suppressed because it is too large Load Diff

View File

@@ -23,12 +23,10 @@
#define PROG_VERSION "wdread (Window Maker) 0.2"
/*
* WindowMaker defaults DB reader
*/
#include "../src/wconfig.h"
#include <stdlib.h>
@@ -40,94 +38,86 @@
#include <pwd.h>
char *ProgName;
char*
gethomedir()
char *gethomedir()
{
char *home = getenv("HOME");
struct passwd *user;
char *home = getenv("HOME");
struct passwd *user;
if (home)
return home;
if (home)
return home;
user = getpwuid(getuid());
if (!user) {
perror(ProgName);
return "/";
}
if (!user->pw_dir) {
return "/";
} else {
return user->pw_dir;
}
user = getpwuid(getuid());
if (!user) {
perror(ProgName);
return "/";
}
if (!user->pw_dir) {
return "/";
} else {
return user->pw_dir;
}
}
void
wAbort()
void wAbort()
{
exit(0);
exit(0);
}
void help()
{
printf("Syntax:\n%s [OPTIONS] <domain> <option>\n", ProgName);
puts("");
puts(" --help display this help message");
puts(" --version output version information and exit");
exit(1);
printf("Syntax:\n%s [OPTIONS] <domain> <option>\n", ProgName);
puts("");
puts(" --help display this help message");
puts(" --version output version information and exit");
exit(1);
}
int main(int argc, char **argv)
{
char path[256];
WMPropList *key, *value, *dict;
char *gsdir;
int i;
char path[256];
WMPropList *key, *value, *dict;
char *gsdir;
int i;
ProgName = argv[0];
ProgName = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp("--help", argv[i])==0) {
help();
exit(0);
} else if (strcmp("--version", argv[i])==0) {
puts(PROG_VERSION);
exit(0);
}
}
for (i = 1; i < argc; i++) {
if (strcmp("--help", argv[i]) == 0) {
help();
exit(0);
} else if (strcmp("--version", argv[i]) == 0) {
puts(PROG_VERSION);
exit(0);
}
}
if (argc<3) {
printf("%s: invalid argument format\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
exit(1);
}
if (argc < 3) {
printf("%s: invalid argument format\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
exit(1);
}
key = WMCreatePLString(argv[2]);
key = WMCreatePLString(argv[2]);
gsdir = getenv("GNUSTEP_USER_ROOT");
if (gsdir) {
strcpy(path, gsdir);
} else {
strcpy(path, gethomedir());
strcat(path, "/GNUstep");
}
strcat(path, "/");
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, argv[1]);
gsdir = getenv("GNUSTEP_USER_ROOT");
if (gsdir) {
strcpy(path, gsdir);
} else {
strcpy(path, gethomedir());
strcat(path, "/GNUstep");
}
strcat(path, "/");
strcat(path, DEFAULTS_DIR);
strcat(path, "/");
strcat(path, argv[1]);
if ((dict = WMReadPropListFromFile(path)) == NULL)
return 1; /* bad domain */
if ((value = WMGetFromPLDictionary(dict, key)) == NULL)
return 2; /* bad key */
if ((dict = WMReadPropListFromFile(path)) == NULL)
return 1; /* bad domain */
if ((value = WMGetFromPLDictionary(dict, key)) == NULL)
return 2; /* bad key */
printf("%s\n", WMGetPropListDescription(value, True));
return 0;
printf("%s\n", WMGetPropListDescription(value, True));
return 0;
}

View File

@@ -22,12 +22,10 @@
#define PROG_VERSION "wdwrite (Window Maker) 0.2"
/*
* WindowMaker defaults DB writer
*/
#include "../src/wconfig.h"
#include <stdlib.h>
@@ -39,102 +37,95 @@
#include <pwd.h>
char *ProgName;
char*
gethomedir()
char *gethomedir()
{
char *home = getenv("HOME");
struct passwd *user;
char *home = getenv("HOME");
struct passwd *user;
if (home)
return home;
if (home)
return home;
user = getpwuid(getuid());
if (!user) {
perror(ProgName);
return "/";
}
if (!user->pw_dir) {
return "/";
} else {
return user->pw_dir;
}
user = getpwuid(getuid());
if (!user) {
perror(ProgName);
return "/";
}
if (!user->pw_dir) {
return "/";
} else {
return user->pw_dir;
}
}
void wAbort()
{
exit(0);
exit(0);
}
void help()
{
printf("Syntax:\n%s [OPTIONS] <domain> <option> <value>\n", ProgName);
puts("");
puts(" --help display this help message");
puts(" --version output version information and exit");
exit(1);
printf("Syntax:\n%s [OPTIONS] <domain> <option> <value>\n", ProgName);
puts("");
puts(" --help display this help message");
puts(" --version output version information and exit");
exit(1);
}
int main(int argc, char **argv)
{
char *path;
WMPropList *dom, *key, *value, *dict;
char *gsdir;
int i;
char *path;
WMPropList *dom, *key, *value, *dict;
char *gsdir;
int i;
ProgName = argv[0];
ProgName = argv[0];
for (i = 1; i < argc; i++) {
if (strcmp("--help", argv[i])==0) {
help();
exit(0);
} else if (strcmp("--version", argv[i])==0) {
puts(PROG_VERSION);
exit(0);
}
}
for (i = 1; i < argc; i++) {
if (strcmp("--help", argv[i]) == 0) {
help();
exit(0);
} else if (strcmp("--version", argv[i]) == 0) {
puts(PROG_VERSION);
exit(0);
}
}
if (argc<4) {
printf("%s: invalid argument format\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
exit(1);
}
if (argc < 4) {
printf("%s: invalid argument format\n", ProgName);
printf("Try '%s --help' for more information\n", ProgName);
exit(1);
}
dom = WMCreatePLString(argv[1]);
key = WMCreatePLString(argv[2]);
value = WMCreatePropListFromDescription(argv[3]);
if (!value) {
printf("%s:syntax error in value \"%s\"", ProgName, argv[3]);
exit(1);
}
gsdir = getenv("GNUSTEP_USER_ROOT");
if (gsdir) {
path = wstrdup(gsdir);
} else {
path = wstrdup(gethomedir());
path = wstrappend(path, "/GNUstep");
}
path = wstrappend(path, "/");
path = wstrappend(path, DEFAULTS_DIR);
path = wstrappend(path, "/");
path = wstrappend(path, argv[1]);
dom = WMCreatePLString(argv[1]);
key = WMCreatePLString(argv[2]);
value = WMCreatePropListFromDescription(argv[3]);
if (!value) {
printf("%s:syntax error in value \"%s\"", ProgName, argv[3]);
exit(1);
}
gsdir = getenv("GNUSTEP_USER_ROOT");
if (gsdir) {
path = wstrdup(gsdir);
} else {
path = wstrdup(gethomedir());
path = wstrappend(path, "/GNUstep");
}
path = wstrappend(path, "/");
path = wstrappend(path, DEFAULTS_DIR);
path = wstrappend(path, "/");
path = wstrappend(path, argv[1]);
dict = WMReadPropListFromFile(path);
if (!dict) {
dict = WMCreatePLDictionary(key, value, NULL);
} else {
WMPutInPLDictionary(dict, key, value);
}
dict = WMReadPropListFromFile(path);
if (!dict) {
dict = WMCreatePLDictionary(key, value, NULL);
} else {
WMPutInPLDictionary(dict, key, value);
}
WMWritePropListToFile(dict, path, True);
wfree(path);
WMWritePropListToFile(dict, path, True);
wfree(path);
return 0;
return 0;
}

View File

@@ -22,43 +22,39 @@
int refreshrate = 200;
typedef struct {
Drawable d;
XRectangle *rects;
int rectP;
unsigned long lastpixel;
unsigned long *buffer;
int width, height;
int rwidth, rheight; /* size of window in real pixels */
int magfactor;
int refreshrate;
Drawable d;
XRectangle *rects;
int rectP;
unsigned long lastpixel;
unsigned long *buffer;
int width, height;
int rwidth, rheight; /* size of window in real pixels */
int magfactor;
int refreshrate;
WMWindow *win;
WMLabel *label;
WMPixmap *pixmap;
WMWindow *win;
WMLabel *label;
WMPixmap *pixmap;
WMWindow *dlg;
WMWindow *dlg;
WMSlider *speed;
WMSlider *magnify;
WMButton *okB;
WMButton *cancelB;
WMButton *newB;
WMSlider *speed;
WMSlider *magnify;
WMButton *okB;
WMButton *cancelB;
WMButton *newB;
int x, y;
Bool frozen;
Bool firstDraw;
Bool markPointerHotspot;
int x, y;
Bool frozen;
Bool firstDraw;
Bool markPointerHotspot;
WMHandlerID tid;
WMHandlerID tid;
} BufferData;
static BufferData *newWindow(int magfactor);
int windowCount = 0;
int rectBufferSize = 32;
@@ -72,479 +68,439 @@ WMColor *cursorColor2;
#define inline
#endif
static BufferData*
makeBufferData(WMWindow *win, WMLabel *label, int width, int height,
int magfactor)
static BufferData *makeBufferData(WMWindow * win, WMLabel * label, int width, int height, int magfactor)
{
BufferData *data;
BufferData *data;
data = wmalloc(sizeof(BufferData));
data = wmalloc(sizeof(BufferData));
data->rwidth = width;
data->rheight = height;
data->rwidth = width;
data->rheight = height;
data->refreshrate = refreshrate;
data->refreshrate = refreshrate;
data->firstDraw = True;
data->firstDraw = True;
data->magfactor = magfactor;
data->magfactor = magfactor;
data->rects = wmalloc(sizeof(XRectangle)*rectBufferSize);
data->rectP = 0;
data->rects = wmalloc(sizeof(XRectangle) * rectBufferSize);
data->rectP = 0;
data->win = win;
data->label = label;
data->win = win;
data->label = label;
data->pixmap = WMCreatePixmap(scr, width, height,
WMScreenDepth(scr), False);
WMSetLabelImage(data->label, data->pixmap);
data->pixmap = WMCreatePixmap(scr, width, height, WMScreenDepth(scr), False);
WMSetLabelImage(data->label, data->pixmap);
data->d = WMGetPixmapXID(data->pixmap);
data->d = WMGetPixmapXID(data->pixmap);
data->frozen = False;
data->frozen = False;
width /= magfactor;
height /= magfactor;
data->buffer = wmalloc(sizeof(unsigned long)*width*height);
memset(data->buffer, 0, width*height*sizeof(unsigned long));
data->width = width;
data->height = height;
width /= magfactor;
height /= magfactor;
data->buffer = wmalloc(sizeof(unsigned long) * width * height);
memset(data->buffer, 0, width * height * sizeof(unsigned long));
data->width = width;
data->height = height;
return data;
return data;
}
static void
resizeBufferData(BufferData *data, int width, int height, int magfactor)
static void resizeBufferData(BufferData * data, int width, int height, int magfactor)
{
int w = width/magfactor;
int h = height/magfactor;
int w = width / magfactor;
int h = height / magfactor;
data->rwidth = width;
data->rheight = height;
data->firstDraw = True;
data->magfactor = magfactor;
data->buffer = wrealloc(data->buffer, sizeof(unsigned long)*w*h);
data->width = w;
data->height = h;
memset(data->buffer, 0, w*h*sizeof(unsigned long));
data->rwidth = width;
data->rheight = height;
data->firstDraw = True;
data->magfactor = magfactor;
data->buffer = wrealloc(data->buffer, sizeof(unsigned long) * w * h);
data->width = w;
data->height = h;
memset(data->buffer, 0, w * h * sizeof(unsigned long));
WMResizeWidget(data->label, width, height);
WMResizeWidget(data->label, width, height);
WMReleasePixmap(data->pixmap);
data->pixmap = WMCreatePixmap(scr, width, height, WMScreenDepth(scr),
False);
WMSetLabelImage(data->label, data->pixmap);
WMReleasePixmap(data->pixmap);
data->pixmap = WMCreatePixmap(scr, width, height, WMScreenDepth(scr), False);
WMSetLabelImage(data->label, data->pixmap);
data->d = WMGetPixmapXID(data->pixmap);
data->d = WMGetPixmapXID(data->pixmap);
}
static int
drawpoint(BufferData *data, unsigned long pixel, int x, int y)
static int drawpoint(BufferData * data, unsigned long pixel, int x, int y)
{
static GC gc = NULL;
Bool flush = (x < 0);
static GC gc = NULL;
Bool flush = (x < 0);
if (!flush) {
if (data->buffer[x+data->width*y] == pixel && !data->firstDraw)
return 0;
if (!flush) {
if (data->buffer[x + data->width * y] == pixel && !data->firstDraw)
return 0;
data->buffer[x+data->width*y] = pixel;
}
if (gc == NULL) {
gc = XCreateGC(dpy, DefaultRootWindow(dpy), 0, NULL);
}
data->buffer[x + data->width * y] = pixel;
}
if (gc == NULL) {
gc = XCreateGC(dpy, DefaultRootWindow(dpy), 0, NULL);
}
if (!flush && data->lastpixel == pixel && data->rectP < rectBufferSize) {
data->rects[data->rectP].x = x*data->magfactor;
data->rects[data->rectP].y = y*data->magfactor;
data->rects[data->rectP].width = data->magfactor;
data->rects[data->rectP].height = data->magfactor;
data->rectP++;
if (!flush && data->lastpixel == pixel && data->rectP < rectBufferSize) {
data->rects[data->rectP].x = x * data->magfactor;
data->rects[data->rectP].y = y * data->magfactor;
data->rects[data->rectP].width = data->magfactor;
data->rects[data->rectP].height = data->magfactor;
data->rectP++;
return 0;
}
XSetForeground(dpy, gc, data->lastpixel);
XFillRectangles(dpy, data->d, gc, data->rects, data->rectP);
data->rectP = 0;
data->rects[data->rectP].x = x*data->magfactor;
data->rects[data->rectP].y = y*data->magfactor;
data->rects[data->rectP].width = data->magfactor;
data->rects[data->rectP].height = data->magfactor;
data->rectP++;
return 0;
}
XSetForeground(dpy, gc, data->lastpixel);
XFillRectangles(dpy, data->d, gc, data->rects, data->rectP);
data->rectP = 0;
data->rects[data->rectP].x = x * data->magfactor;
data->rects[data->rectP].y = y * data->magfactor;
data->rects[data->rectP].width = data->magfactor;
data->rects[data->rectP].height = data->magfactor;
data->rectP++;
data->lastpixel = pixel;
data->lastpixel = pixel;
return 1;
return 1;
}
static inline unsigned long
getpix(XImage *image, int x, int y, int xoffs, int yoffs)
static inline unsigned long getpix(XImage * image, int x, int y, int xoffs, int yoffs)
{
if (x < xoffs || y < yoffs
|| x >= xoffs + image->width || y >= yoffs + image->height) {
return black;
}
return XGetPixel(image, x-xoffs, y-yoffs);
if (x < xoffs || y < yoffs || x >= xoffs + image->width || y >= yoffs + image->height) {
return black;
}
return XGetPixel(image, x - xoffs, y - yoffs);
}
static void
updateImage(BufferData *data, int rx, int ry)
static void updateImage(BufferData * data, int rx, int ry)
{
int gx, gy, gw, gh;
int x, y;
int xoffs, yoffs;
int changedPixels = 0;
XImage *image;
int gx, gy, gw, gh;
int x, y;
int xoffs, yoffs;
int changedPixels = 0;
XImage *image;
gw = data->width;
gh = data->height;
gw = data->width;
gh = data->height;
gx = rx - gw/2;
gy = ry - gh/2;
gx = rx - gw / 2;
gy = ry - gh / 2;
xoffs = yoffs = 0;
if (gx < 0) {
xoffs = abs(gx);
gw += gx;
gx = 0;
}
if (gx + gw >= WidthOfScreen(DefaultScreenOfDisplay(vdpy))) {
gw = WidthOfScreen(DefaultScreenOfDisplay(vdpy)) - gx;
}
if (gy < 0) {
yoffs = abs(gy);
gh += gy;
gy = 0;
}
if (gy + gh >= HeightOfScreen(DefaultScreenOfDisplay(vdpy))) {
gh = HeightOfScreen(DefaultScreenOfDisplay(vdpy)) - gy;
}
xoffs = yoffs = 0;
if (gx < 0) {
xoffs = abs(gx);
gw += gx;
gx = 0;
}
if (gx + gw >= WidthOfScreen(DefaultScreenOfDisplay(vdpy))) {
gw = WidthOfScreen(DefaultScreenOfDisplay(vdpy)) - gx;
}
if (gy < 0) {
yoffs = abs(gy);
gh += gy;
gy = 0;
}
if (gy + gh >= HeightOfScreen(DefaultScreenOfDisplay(vdpy))) {
gh = HeightOfScreen(DefaultScreenOfDisplay(vdpy)) - gy;
}
image = XGetImage(vdpy, DefaultRootWindow(vdpy), gx, gy, gw, gh,
AllPlanes, ZPixmap);
image = XGetImage(vdpy, DefaultRootWindow(vdpy), gx, gy, gw, gh, AllPlanes, ZPixmap);
for (y = 0; y < data->height; y++) {
for (x = 0; x < data->width; x++) {
unsigned long pixel;
for (y = 0; y < data->height; y++) {
for (x = 0; x < data->width; x++) {
unsigned long pixel;
pixel = getpix(image, x, y, xoffs, yoffs);
pixel = getpix(image, x, y, xoffs, yoffs);
if (drawpoint(data, pixel, x, y))
changedPixels++;
}
}
/* flush the point cache */
drawpoint(data, 0, -1, -1);
if (drawpoint(data, pixel, x, y))
changedPixels++;
}
}
/* flush the point cache */
drawpoint(data, 0, -1, -1);
XDestroyImage(image);
XDestroyImage(image);
if (data->markPointerHotspot && !data->frozen) {
XRectangle rects[4];
if (data->markPointerHotspot && !data->frozen) {
XRectangle rects[4];
rects[0].x = (data->width / 2 - 3) * data->magfactor;
rects[0].y = (data->height / 2) * data->magfactor;
rects[0].width = 2 * data->magfactor;
rects[0].height = data->magfactor;
rects[0].x = (data->width/2 - 3)*data->magfactor;
rects[0].y = (data->height/2)*data->magfactor;
rects[0].width = 2*data->magfactor;
rects[0].height = data->magfactor;
rects[1].x = (data->width / 2 + 2) * data->magfactor;
rects[1].y = (data->height / 2) * data->magfactor;
rects[1].width = 2 * data->magfactor;
rects[1].height = data->magfactor;
rects[1].x = (data->width/2 + 2)*data->magfactor;
rects[1].y = (data->height/2)*data->magfactor;
rects[1].width = 2*data->magfactor;
rects[1].height = data->magfactor;
XFillRectangles(dpy, data->d, WMColorGC(cursorColor1), rects, 2);
XFillRectangles(dpy, data->d, WMColorGC(cursorColor1), rects, 2);
rects[2].y = (data->height / 2 - 3) * data->magfactor;
rects[2].x = (data->width / 2) * data->magfactor;
rects[2].height = 2 * data->magfactor;
rects[2].width = data->magfactor;
rects[2].y = (data->height/2 - 3)*data->magfactor;
rects[2].x = (data->width/2)*data->magfactor;
rects[2].height = 2*data->magfactor;
rects[2].width = data->magfactor;
rects[3].y = (data->height / 2 + 2) * data->magfactor;
rects[3].x = (data->width / 2) * data->magfactor;
rects[3].height = 2 * data->magfactor;
rects[3].width = data->magfactor;
rects[3].y = (data->height/2 + 2)*data->magfactor;
rects[3].x = (data->width/2)*data->magfactor;
rects[3].height = 2*data->magfactor;
rects[3].width = data->magfactor;
XFillRectangles(dpy, data->d, WMColorGC(cursorColor2), rects + 2, 2);
}
XFillRectangles(dpy, data->d, WMColorGC(cursorColor2), rects + 2, 2);
}
if (changedPixels > 0) {
WMRedisplayWidget(data->label);
}
if (changedPixels > 0) {
WMRedisplayWidget(data->label);
}
data->firstDraw = False;
data->firstDraw = False;
}
static void
update(void *d)
static void update(void *d)
{
BufferData *data = (BufferData*)d;
Window win;
int rx, ry;
int bla;
unsigned ubla;
BufferData *data = (BufferData *) d;
Window win;
int rx, ry;
int bla;
unsigned ubla;
if (data->frozen) {
rx = data->x;
ry = data->y;
} else {
XQueryPointer(dpy, DefaultRootWindow(dpy), &win, &win, &rx, &ry, &bla, &bla, &ubla);
}
updateImage(data, rx, ry);
if (data->frozen) {
rx = data->x;
ry = data->y;
} else {
XQueryPointer(dpy, DefaultRootWindow(dpy), &win, &win, &rx, &ry,
&bla, &bla, &ubla);
}
updateImage(data, rx, ry);
data->tid = WMAddTimerHandler(data->refreshrate, update, data);
data->tid = WMAddTimerHandler(data->refreshrate, update, data);
}
void resizedWindow(void *d, WMNotification *notif)
void resizedWindow(void *d, WMNotification * notif)
{
BufferData *data = (BufferData*)d;
WMView *view = (WMView*)WMGetNotificationObject(notif);
WMSize size;
BufferData *data = (BufferData *) d;
WMView *view = (WMView *) WMGetNotificationObject(notif);
WMSize size;
size = WMGetViewSize(view);
size = WMGetViewSize(view);
resizeBufferData(data, size.width, size.height, data->magfactor);
resizeBufferData(data, size.width, size.height, data->magfactor);
}
void closeWindow(WMWidget *w, void *d)
void closeWindow(WMWidget * w, void *d)
{
BufferData *data = (BufferData*)d;
BufferData *data = (BufferData *) d;
windowCount--;
if (windowCount == 0) {
exit(0);
} else {
WMDeleteTimerHandler(data->tid);
WMDestroyWidget(w);
wfree(data->buffer);
wfree(data->rects);
WMReleasePixmap(data->pixmap);
wfree(data);
}
windowCount--;
if (windowCount == 0) {
exit(0);
} else {
WMDeleteTimerHandler(data->tid);
WMDestroyWidget(w);
wfree(data->buffer);
wfree(data->rects);
WMReleasePixmap(data->pixmap);
wfree(data);
}
}
#if 0
static void
clickHandler(XEvent *event, void *d)
static void clickHandler(XEvent * event, void *d)
{
BufferData *data = (BufferData*)d;
BufferData *data = (BufferData *) d;
data->win = WMCreateWindow(scr, "setup");
WMSetWindowTitle(data->win, "Magnify Options");
data->speed = WMCreateSlider(data->win);
data->magnify = WMCreateSlider(data->win);
data->win = WMCreateWindow(scr, "setup");
WMSetWindowTitle(data->win, "Magnify Options");
data->speed = WMCreateSlider(data->win);
data->magnify = WMCreateSlider(data->win);
}
#endif
static void
keyHandler(XEvent *event, void *d)
static void keyHandler(XEvent * event, void *d)
{
BufferData *data = (BufferData*)d;
char buf[32];
KeySym ks;
WMView *view = WMWidgetView(data->win);
WMSize size;
BufferData *data = (BufferData *) d;
char buf[32];
KeySym ks;
WMView *view = WMWidgetView(data->win);
WMSize size;
size = WMGetViewSize(view);
size = WMGetViewSize(view);
if (XLookupString(&event->xkey, buf, 31, &ks, NULL) > 0) {
switch (buf[0]) {
case 'n':
newWindow(data->magfactor);
break;
case 'm':
data->markPointerHotspot = !data->markPointerHotspot;
break;
case 'f':
case ' ':
data->frozen = !data->frozen;
if (data->frozen) {
data->x = event->xkey.x_root;
data->y = event->xkey.y_root;
sprintf(buf, "[Magnify %ix]", data->magfactor);
} else {
sprintf(buf, "Magnify %ix", data->magfactor);
}
WMSetWindowTitle(data->win, buf);
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
resizeBufferData(data, size.width, size.height, buf[0]-'0');
if (data->frozen) {
sprintf(buf, "[Magnify %ix]", data->magfactor);
} else {
sprintf(buf, "Magnify %ix", data->magfactor);
}
WMSetWindowTitle(data->win, buf);
break;
}
}
if (XLookupString(&event->xkey, buf, 31, &ks, NULL) > 0) {
switch (buf[0]) {
case 'n':
newWindow(data->magfactor);
break;
case 'm':
data->markPointerHotspot = !data->markPointerHotspot;
break;
case 'f':
case ' ':
data->frozen = !data->frozen;
if (data->frozen) {
data->x = event->xkey.x_root;
data->y = event->xkey.y_root;
sprintf(buf, "[Magnify %ix]", data->magfactor);
} else {
sprintf(buf, "Magnify %ix", data->magfactor);
}
WMSetWindowTitle(data->win, buf);
break;
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
resizeBufferData(data, size.width, size.height, buf[0] - '0');
if (data->frozen) {
sprintf(buf, "[Magnify %ix]", data->magfactor);
} else {
sprintf(buf, "Magnify %ix", data->magfactor);
}
WMSetWindowTitle(data->win, buf);
break;
}
}
}
static BufferData*
newWindow(int magfactor)
static BufferData *newWindow(int magfactor)
{
WMWindow *win;
WMLabel *label;
BufferData *data;
char buf[32];
WMWindow *win;
WMLabel *label;
BufferData *data;
char buf[32];
windowCount++;
windowCount++;
win = WMCreateWindow(scr, "magnify");
WMResizeWidget(win, 300, 200);
sprintf(buf, "Magnify %ix", magfactor);
WMSetWindowTitle(win, buf);
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
win = WMCreateWindow(scr, "magnify");
WMResizeWidget(win, 300, 200);
sprintf(buf, "Magnify %ix", magfactor);
WMSetWindowTitle(win, buf);
WMSetViewNotifySizeChanges(WMWidgetView(win), True);
label = WMCreateLabel(win);
WMResizeWidget(label, 300, 200);
WMMoveWidget(label, 0, 0);
WMSetLabelRelief(label, WRSunken);
WMSetLabelImagePosition(label, WIPImageOnly);
label = WMCreateLabel(win);
WMResizeWidget(label, 300, 200);
WMMoveWidget(label, 0, 0);
WMSetLabelRelief(label, WRSunken);
WMSetLabelImagePosition(label, WIPImageOnly);
data = makeBufferData(win, label, 300, 200, magfactor);
data = makeBufferData(win, label, 300, 200, magfactor);
WMCreateEventHandler(WMWidgetView(win), KeyReleaseMask,
keyHandler, data);
WMCreateEventHandler(WMWidgetView(win), KeyReleaseMask, keyHandler, data);
WMAddNotificationObserver(resizedWindow, data,
WMViewSizeDidChangeNotification,
WMWidgetView(win));
WMAddNotificationObserver(resizedWindow, data, WMViewSizeDidChangeNotification, WMWidgetView(win));
WMRealizeWidget(win);
WMRealizeWidget(win);
WMMapSubwidgets(win);
WMMapWidget(win);
WMMapSubwidgets(win);
WMMapWidget(win);
WMSetWindowCloseAction(win, closeWindow, data);
data->tid = WMAddTimerHandler(refreshrate, update, data);
WMSetWindowCloseAction(win, closeWindow, data);
data->tid = WMAddTimerHandler(refreshrate, update, data);
return data;
return data;
}
int main(int argc, char **argv)
{
BufferData *data;
int i;
char *display = "";
char *vdisplay = NULL;
int magfactor = 2;
BufferData *data;
int i;
char *display = "";
char *vdisplay = NULL;
int magfactor = 2;
#if 0
WMButton *radio, *tradio;
WMButton *radio, *tradio;
#endif
WMInitializeApplication("Magnify", &argc, argv);
WMInitializeApplication("Magnify", &argc, argv);
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-display") == 0) {
i++;
if (i >= argc)
goto help;
display = argv[i];
} else if (strcmp(argv[i], "-vdisplay") == 0) {
i++;
if (i >= argc)
goto help;
vdisplay = argv[i];
} else if (strcmp(argv[i], "-m") == 0) {
i++;
if (i >= argc)
goto help;
magfactor = atoi(argv[i]);
if (magfactor < 1 || magfactor > 32) {
printf("%s:invalid magnification factor ``%s''\n", argv[0], argv[i]);
exit(1);
}
} else if (strcmp(argv[i], "-r") == 0) {
i++;
if (i >= argc)
goto help;
refreshrate = atoi(argv[i]);
if (refreshrate < 1) {
printf("%s:invalid refresh rate ``%s''\n", argv[0], argv[i]);
exit(1);
}
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
help:
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-display")==0) {
i++;
if (i >= argc)
goto help;
display = argv[i];
} else if (strcmp(argv[i], "-vdisplay")==0) {
i++;
if (i >= argc)
goto help;
vdisplay = argv[i];
} else if (strcmp(argv[i], "-m")==0) {
i++;
if (i >= argc)
goto help;
magfactor = atoi(argv[i]);
if (magfactor < 1 || magfactor > 32) {
printf("%s:invalid magnification factor ``%s''\n", argv[0],
argv[i]);
exit(1);
}
} else if (strcmp(argv[i], "-r")==0) {
i++;
if (i >= argc)
goto help;
refreshrate = atoi(argv[i]);
if (refreshrate < 1) {
printf("%s:invalid refresh rate ``%s''\n", argv[0], argv[i]);
exit(1);
}
} else if (strcmp(argv[i], "-h")==0
|| strcmp(argv[i], "--help")==0) {
help:
printf("Syntax: %s [options]\n", argv[0]);
puts("Options:");
puts(" -display <display> display that should be used");
puts(" -m <number> change magnification factor (default 2)");
puts(" -r <number> change refresh delay, in milliseconds (default 200)");
puts("Keys:");
puts(" 1,2,3,4,5,6,7,8,9 change the magnification factor");
puts(" <space>, f freeze the 'camera', making it magnify only the current\n"
" position");
puts(" n create a new window");
puts(" m show/hide the pointer hotspot mark");
exit(0);
}
}
printf("Syntax: %s [options]\n",
argv[0]);
puts("Options:");
puts(" -display <display> display that should be used");
puts(" -m <number> change magnification factor (default 2)");
puts(" -r <number> change refresh delay, in milliseconds (default 200)");
puts("Keys:");
puts(" 1,2,3,4,5,6,7,8,9 change the magnification factor");
puts(" <space>, f freeze the 'camera', making it magnify only the current\n"
" position");
puts(" n create a new window");
puts(" m show/hide the pointer hotspot mark");
exit(0);
}
}
dpy = XOpenDisplay(display);
if (!dpy) {
puts("couldnt open display");
exit(1);
}
dpy = XOpenDisplay(display);
if (!dpy) {
puts("couldnt open display");
exit(1);
}
if (vdisplay) {
vdpy = XOpenDisplay(vdisplay);
if (!vdpy) {
puts("couldnt open display to be viewed");
exit(1);
}
} else {
vdpy = dpy;
}
if (vdisplay) {
vdpy = XOpenDisplay(vdisplay);
if (!vdpy) {
puts("couldnt open display to be viewed");
exit(1);
}
} else {
vdpy = dpy;
}
/* calculate how many rectangles we can send in a trip to the server */
rectBufferSize = XMaxRequestSize(dpy) - 128;
rectBufferSize /= sizeof(XRectangle);
if (rectBufferSize < 1)
rectBufferSize = 1;
/* calculate how many rectangles we can send in a trip to the server */
rectBufferSize = XMaxRequestSize(dpy) - 128;
rectBufferSize /= sizeof(XRectangle);
if (rectBufferSize < 1)
rectBufferSize = 1;
black = BlackPixel(dpy, DefaultScreen(dpy));
black = BlackPixel(dpy, DefaultScreen(dpy));
scr = WMCreateScreen(dpy, 0);
scr = WMCreateScreen(dpy, 0);
cursorColor1 = WMCreateNamedColor(scr, "#ff0000", False);
cursorColor2 = WMCreateNamedColor(scr, "#00ff00", False);
cursorColor1 = WMCreateNamedColor(scr, "#ff0000", False);
cursorColor2 = WMCreateNamedColor(scr, "#00ff00", False);
data = newWindow(magfactor);
data = newWindow(magfactor);
WMScreenMainLoop(scr);
WMScreenMainLoop(scr);
return 0;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@@ -18,8 +18,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if 1
int
main()
int main()
{
}
#else
@@ -37,389 +36,340 @@ main()
#include "../src/config.h"
char *RequiredDirectories[] = {
"/Defaults",
"/Library",
"/Library/Icons",
"/Library/WindowMaker",
"/Library/WindowMaker/Backgrounds",
"/Library/WindowMaker/IconSets",
"/Library/WindowMaker/Pixmaps",
"/Library/WindowMaker/CachedPixmaps",
"/Library/WindowMaker/SoundSets",
"/Library/WindowMaker/Sounds",
"/Library/WindowMaker/Styles",
"/Library/WindowMaker/Themes",
"/Library/WindowMaker/WPrefs",
NULL
"/Defaults",
"/Library",
"/Library/Icons",
"/Library/WindowMaker",
"/Library/WindowMaker/Backgrounds",
"/Library/WindowMaker/IconSets",
"/Library/WindowMaker/Pixmaps",
"/Library/WindowMaker/CachedPixmaps",
"/Library/WindowMaker/SoundSets",
"/Library/WindowMaker/Sounds",
"/Library/WindowMaker/Styles",
"/Library/WindowMaker/Themes",
"/Library/WindowMaker/WPrefs",
NULL
};
char *RequiredFiles[] = {
"/Defaults/WindowMaker",
"/Defaults/WMWindowAttributes",
NULL
"/Defaults/WindowMaker",
"/Defaults/WMWindowAttributes",
NULL
};
WMScreen *scr;
#define wlog wwarning
#if 0
void
wlog(const char *msg, ...)
void wlog(const char *msg, ...)
{
va_list args;
char buf[MAXLINE];
va_list args;
char buf[MAXLINE];
va_start(args, msg);
va_start(args, msg);
vsprintf(buf, msg, args);
puts(buf);
vsprintf(buf, msg, args);
puts(buf);
va_end(args);
va_end(args);
}
#endif
void
alert(const char *msg, ...)
void alert(const char *msg, ...)
{
va_list args;
char buffer[2048];
va_list args;
char buffer[2048];
va_start(args, msg);
va_start(args, msg);
vsprintf(buf, msg, args);
vsprintf(buf, msg, args);
WMRunAlertPanel(scr, NULL, _("Error"),
buffer, _("OK"), NULL, NULL);
WMRunAlertPanel(scr, NULL, _("Error"), buffer, _("OK"), NULL, NULL);
va_end(args);
va_end(args);
}
Bool
ask(char *title, char *yes, char *no, const char *msg, ...)
Bool ask(char *title, char *yes, char *no, const char *msg, ...)
{
va_list args;
char buffer[2048];
va_list args;
char buffer[2048];
va_start(args, msg);
va_start(args, msg);
vsprintf(buf, msg, args);
vsprintf(buf, msg, args);
WMRunAlertPanel(scr, NULL, title,
buffer, yes, no, NULL);
WMRunAlertPanel(scr, NULL, title, buffer, yes, no, NULL);
va_end(args);
va_end(args);
}
char*
renameName(char *path)
char *renameName(char *path)
{
char *buf = wmalloc(strlen(path)+8);
int i;
char *buf = wmalloc(strlen(path) + 8);
int i;
sprintf(buf, "%s~", path);
sprintf(buf, "%s~", path);
if (access(buf, F_OK) < 0) {
return buf;
}
if (access(buf, F_OK) < 0) {
return buf;
}
for (i = 0; i < 10; i++) {
sprintf(buf, "%s~%i", path, i);
for (i = 0; i < 10; i++) {
sprintf(buf, "%s~%i", path, i);
if (access(buf, F_OK) < 0) {
return buf;
}
}
if (access(buf, F_OK) < 0) {
return buf;
}
}
sprintf(buf, "%s~", path);
sprintf(buf, "%s~", path);
return buf;
return buf;
}
void
showFileError(int error, Bool directory, char *path)
void showFileError(int error, Bool directory, char *path)
{
switch (error) {
case EACCESS:
if (directory) {
alert(_("The directory %s needs to be fully accessible, but is\n"
"not. Make sure all of it's parent directories have\n"
"read and execute permissions set."), path);
} else {
alert(_("The file %s needs to be fully accessible, but is not.\n"
"Make sure it has read and write permissions set and\n"
"all of it's parent directories have read and execute\n"
"permissions."), path);
}
break;
switch (error) {
case EACCESS:
if (directory) {
alert(_("The directory %s needs to be fully accessible, but is\n"
"not. Make sure all of it's parent directories have\n"
"read and execute permissions set."), path);
} else {
alert(_("The file %s needs to be fully accessible, but is not.\n"
"Make sure it has read and write permissions set and\n"
"all of it's parent directories have read and execute\n" "permissions."), path);
}
break;
case EROFS:
alert(_("The %s %s is in a read-only file system, but it needs to be\n"
"writable. Start wmaker with the --static command line option."),
directory ? _("directory") : _("file"), path);
break;
case EROFS:
alert(_("The %s %s is in a read-only file system, but it needs to be\n"
"writable. Start wmaker with the --static command line option."),
directory ? _("directory") : _("file"), path);
break;
default:
alert(_("An error occurred while accessing the %s %s. Please make sure\n"
"it exists and is accessible.\n%s"),
directory ? _("directory") : _("file"), path,
wstrerror(error));
break;
}
default:
alert(_("An error occurred while accessing the %s %s. Please make sure\n"
"it exists and is accessible.\n%s"),
directory ? _("directory") : _("file"), path, wstrerror(error));
break;
}
}
Bool
checkDir(char *path, Bool fatal)
Bool checkDir(char *path, Bool fatal)
{
if (access(path, F_OK) < 0) {
if (mkdir(path, 0775) < 0) {
alert(_("could not create directory %s\n%s"), path,
wstrerror(errno));
return False;
} else {
wlog(_("created directory %s"), path);
}
}
if (access(path, F_OK) < 0) {
if (mkdir(path, 0775) < 0) {
alert(_("could not create directory %s\n%s"), path, wstrerror(errno));
return False;
} else {
wlog(_("created directory %s"), path);
}
}
if (access(path, R_OK|W_OK|X_OK) == 0) {
return True;
}
wsyserror("bad access to directory %s", path);
if (access(path, R_OK | W_OK | X_OK) == 0) {
return True;
}
wsyserror("bad access to directory %s", path);
if (!fatal) {
struct stat buf;
if (!fatal) {
struct stat buf;
if (stat(path, &buf) < 0) {
alert(_("The directory %s could not be stat()ed. Please make sure\n"
"it exists and is accessible."), path);
return False;
}
if (stat(path, &buf) < 0) {
alert(_("The directory %s could not be stat()ed. Please make sure\n"
"it exists and is accessible."), path);
return False;
}
if (!S_ISDIR(buf)) {
char *newName = renameName(path);
if (!S_ISDIR(buf)) {
char *newName = renameName(path);
if (ask(_("Rename"), _("OK"), _("Cancel"),
_("A directory named %s needs to be created but a file with\n"
"the same name already exists. The file will be renamed to\n"
"%s and the directory will be created."),
path, newName)) {
if (ask(_("Rename"), _("OK"), _("Cancel"),
_("A directory named %s needs to be created but a file with\n"
"the same name already exists. The file will be renamed to\n"
"%s and the directory will be created."), path, newName)) {
if (rename(path, newName) < 0) {
alert(_("Could not rename %s to %s:%s"),
path, newName, wstrerror(errno));
}
}
wfree(newName);
if (rename(path, newName) < 0) {
alert(_("Could not rename %s to %s:%s"), path, newName, wstrerror(errno));
}
}
wfree(newName);
return False;
}
if (!(buf.st_mode & S_IRWXU)) {
if (chmod(path, (buf.st_mode & 00077)|7) < 0) {
return False;
}
}
return False;
}
if (!(buf.st_mode & S_IRWXU)) {
if (chmod(path, (buf.st_mode & 00077) | 7) < 0) {
return False;
}
}
return checkDir(path, True);
}
return checkDir(path, True);
}
showFileError(errno, True, path);
showFileError(errno, True, path);
return False;
return False;
}
Bool
checkFile(char *path)
Bool checkFile(char *path)
{
if (access(path, F_OK|R_OK|W_OK) == 0) {
return True;
}
if (access(path, F_OK | R_OK | W_OK) == 0) {
return True;
}
showFileError(errno, False, path);
showFileError(errno, False, path);
return False;
return False;
}
Bool
checkCurrentSetup(char *home)
Bool checkCurrentSetup(char *home)
{
char path[1024];
char *p;
char path[1024];
char *p;
if (!checkDir(home, False)) {
wlog("couldnt make directory %s", home);
return False;
}
if (!checkDir(home, False)) {
wlog("couldnt make directory %s", home);
return False;
}
for (p = RequiredDirectories; p != NULL; p++) {
sprintf(path, "%s%s", home, p);
if (!checkDir(p, False)) {
wlog("couldnt make directory %s", p);
return False;
}
}
for (p = RequiredDirectories; p != NULL; p++) {
sprintf(path, "%s%s", home, p);
if (!checkDir(p, False)) {
wlog("couldnt make directory %s", p);
return False;
}
}
for (p = RequiredFiles; p != NULL; p++) {
sprintf(path, "%s%s", home, p);
if (!checkFile(p, False)) {
return False;
}
}
for (p = RequiredFiles; p != NULL; p++) {
sprintf(path, "%s%s", home, p);
if (!checkFile(p, False)) {
return False;
}
}
return True;
return True;
}
Bool
copyAllFiles(char *gsdir)
Bool copyAllFiles(char *gsdir)
{
FILE *f;
char path[2048];
char file[256];
char target[2048];
FILE *f;
char path[2048];
char file[256];
char target[2048];
/* copy misc data files */
/* copy misc data files */
sprintf(path, "%s/USER_FILES", DATADIR);
sprintf(path, "%s/USER_FILES", DATADIR);
f = fopen(path, "rb");
while (!feof(f)) {
if (!fgets(file, 255, f)) {
break;
}
sprintf(path, "%s/%s", DATADIR, file);
sprintf(target, "%s/Library/WindowMaker/%s", gsdir, file);
if (!copyFile(path, target)) {
return False;
}
}
fclose(f);
f = fopen(path, "rb");
while (!feof(f)) {
if (!fgets(file, 255, f)) {
break;
}
sprintf(path, "%s/%s", DATADIR, file);
sprintf(target, "%s/Library/WindowMaker/%s", gsdir, file);
if (!copyFile(path, target)) {
return False;
}
}
fclose(f);
/* copy auto{start,finish} scripts */
/* copy auto{start,finish} scripts */
/* select and copy menu */
/* select and copy menu */
/* copy Defaults stuff */
sprintf(path, "%s/USER_FILES", ETCDIR);
/* copy Defaults stuff */
f = fopen(path, "rb");
while (!feof(f)) {
if (!fgets(path, 255, f)) {
break;
}
sprintf(path, "%s/%s", ETCDIR, file);
sprintf(target, "%s/Defaults/%s", gsdir, file);
if (!copyFile(path, target)) {
return False;
}
}
fclose(f);
sprintf(path, "%s/USER_FILES", ETCDIR);
f = fopen(path, "rb");
while (!feof(f)) {
if (!fgets(path, 255, f)) {
break;
}
sprintf(path, "%s/%s", ETCDIR, file);
sprintf(target, "%s/Defaults/%s", gsdir, file);
if (!copyFile(path, target)) {
return False;
}
}
fclose(f);
/* setup .xinitrc */
/* setup .xinitrc */
}
void
showFinishSplash(char *gsdir)
void showFinishSplash(char *gsdir)
{
#if 0
WMWindow *win;
WMWindow *win;
win = WMCreateWindow(scr, "finished");
win = WMCreateWindow(scr, "finished");
#endif
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
Display *dpy;
char *gsdir;
int i;
Display *dpy;
char *gsdir;
int i;
for (i=1; i<argc; i++) {
if (strcmp(argv[i], "-display")==0) {
i++;
if (i>=argc) {
wwarning(_("too few arguments for %s"), argv[i-1]);
exit(0);
}
DisplayName = argv[i];
} else if (strcmp(argv[i], "-version")==0
|| strcmp(argv[i], "--version")==0) {
puts(PROG_VERSION);
exit(0);
}
}
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-display") == 0) {
i++;
if (i >= argc) {
wwarning(_("too few arguments for %s"), argv[i - 1]);
exit(0);
}
DisplayName = argv[i];
} else if (strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
}
}
WMInitializeApplication("WMSetup", &argc, argv);
WMInitializeApplication("WMSetup", &argc, argv);
dpy = XOpenDisplay("");
if (!dpy) {
printf("could not open display\n");
exit(1);
}
dpy = XOpenDisplay("");
if (!dpy) {
printf("could not open display\n");
exit(1);
}
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
scr = WMCreateScreen(dpy, DefaultScreen(dpy));
gsdir = wusergnusteppath();
gsdir = wusergnusteppath();
/* check directory structure and copy files */
if (access(gsdir, F_OK) != 0) {
if (!ask(_("Window Maker"), _("OK"), _("Cancel"),
_("Window Maker will create a directory named %s, where\n"
"it will store it's configuration files and other data."),
gsdir)) {
alert(_("Window Maker will be started in 'static' mode, where\n"
"it will use default configuration and will not write\n"
"any information to disk."));
return 1;
}
}
/* check directory structure and copy files */
if (access(gsdir, F_OK) != 0) {
if (!ask(_("Window Maker"), _("OK"), _("Cancel"),
_("Window Maker will create a directory named %s, where\n"
"it will store it's configuration files and other data."), gsdir)) {
alert(_("Window Maker will be started in 'static' mode, where\n"
"it will use default configuration and will not write\n"
"any information to disk."));
return 1;
}
}
if (checkCurrentSetup(gsdir)) {
printf(_("%s: wmaker configuration files already installed\n"),
argv[0]);
return 0;
}
if (checkCurrentSetup(gsdir)) {
printf(_("%s: wmaker configuration files already installed\n"), argv[0]);
return 0;
}
if (!copyAllFiles(gsdir)) {
alert(_("An error occurred while doing user specific setup of\n"
"Window Maker. It will be started in 'static' mode, where\n"
"the default configuration will be used and it will not write\n"
"any information to disk."));
return 1;
}
if (!copyAllFiles(gsdir)) {
alert(_("An error occurred while doing user specific setup of\n"
"Window Maker. It will be started in 'static' mode, where\n"
"the default configuration will be used and it will not write\n"
"any information to disk."));
return 1;
}
showFinishSplash(gsdir);
showFinishSplash(gsdir);
return 0;
return 0;
}
#endif

View File

@@ -19,7 +19,6 @@
#define PROG_VERSION "wxcopy 0.3"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -28,218 +27,213 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#define LINESIZE (4*1024)
#define MAXDATA (64*1024)
void
help(char *progn)
void help(char *progn)
{
printf("Usage: %s [OPTIONS] [FILE]\n", progn);
puts("Copies data from FILE or stdin into X cut buffer.");
puts("");
puts(" -display <display> display to use");
puts(" --cutbuffer <number> cutbuffer number to put data");
puts(" --no-limit do not limit size of input data");
puts(" --clear-selection clears the current PRIMARY selection");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
printf("Usage: %s [OPTIONS] [FILE]\n", progn);
puts("Copies data from FILE or stdin into X cut buffer.");
puts("");
puts(" -display <display> display to use");
puts(" --cutbuffer <number> cutbuffer number to put data");
puts(" --no-limit do not limit size of input data");
puts(" --clear-selection clears the current PRIMARY selection");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
}
static int
errorHandler(Display *dpy, XErrorEvent *err)
static int errorHandler(Display * dpy, XErrorEvent * err)
{
/* ignore all errors */
return 0;
/* ignore all errors */
return 0;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
Display *dpy;
int i;
int buffer=-1;
char *filename=NULL;
FILE *file=stdin;
char *buf=NULL;
char *display_name="";
int l=0;
int buf_len = 0;
int limit_check = 1;
int clear_selection = 0;
Display *dpy;
int i;
int buffer = -1;
char *filename = NULL;
FILE *file = stdin;
char *buf = NULL;
char *display_name = "";
int l = 0;
int buf_len = 0;
int limit_check = 1;
int clear_selection = 0;
for (i=1; i<argc; i++) {
if (argv[i][0]=='-') {
if (strcmp(argv[i], "--help")==0) {
help(argv[0]);
exit(0);
} else if (strcmp(argv[i], "--version")==0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp(argv[i],"-cutbuffer")==0
|| strcmp(argv[i],"--cutbuffer")==0) {
if (i<argc-1) {
i++;
if (sscanf(argv[i],"%i", &buffer)!=1) {
fprintf(stderr, "%s: could not convert '%s' to int\n",
argv[0], argv[i]);
exit(1);
}
if (buffer<0 || buffer > 7) {
fprintf(stderr, "%s: invalid buffer number %i\n",
argv[0], buffer);
exit(1);
}
} else {
printf("%s: missing argument for '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
exit(1);
}
} else if (strcmp(argv[i], "-display")==0) {
if (i < argc-1) {
display_name = argv[++i];
} else {
printf("%s: missing argument for '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
exit(1);
}
} else if (strcmp(argv[i],"-clearselection")==0
|| strcmp(argv[i],"--clear-selection")==0) {
clear_selection = 1;
} else if (strcmp(argv[i],"-nolimit")==0
|| strcmp(argv[i],"--no-limit")==0) {
limit_check = 0;
} else {
printf("%s: invalid argument '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
exit(1);
}
} else {
filename = argv[i];
}
}
if (filename) {
file = fopen(filename, "rb");
if (!file) {
char line[1024];
sprintf(line, "%s: could not open \"%s\"", argv[0], filename);
perror(line);
exit(1);
}
}
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (strcmp(argv[i], "--help") == 0) {
help(argv[0]);
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp(argv[i], "-cutbuffer") == 0 || strcmp(argv[i], "--cutbuffer") == 0) {
if (i < argc - 1) {
i++;
if (sscanf(argv[i], "%i", &buffer) != 1) {
fprintf(stderr, "%s: could not convert '%s' to int\n",
argv[0], argv[i]);
exit(1);
}
if (buffer < 0 || buffer > 7) {
fprintf(stderr, "%s: invalid buffer number %i\n", argv[0], buffer);
exit(1);
}
} else {
printf("%s: missing argument for '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
exit(1);
}
} else if (strcmp(argv[i], "-display") == 0) {
if (i < argc - 1) {
display_name = argv[++i];
} else {
printf("%s: missing argument for '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
exit(1);
}
} else if (strcmp(argv[i], "-clearselection") == 0
|| strcmp(argv[i], "--clear-selection") == 0) {
clear_selection = 1;
} else if (strcmp(argv[i], "-nolimit") == 0 || strcmp(argv[i], "--no-limit") == 0) {
limit_check = 0;
} else {
printf("%s: invalid argument '%s'\n", argv[0], argv[i]);
printf("Try '%s --help' for more information\n", argv[0]);
exit(1);
}
} else {
filename = argv[i];
}
}
if (filename) {
file = fopen(filename, "rb");
if (!file) {
char line[1024];
sprintf(line, "%s: could not open \"%s\"", argv[0], filename);
perror(line);
exit(1);
}
}
dpy = XOpenDisplay(display_name);
XSetErrorHandler(errorHandler);
if (!dpy) {
fprintf(stderr, "%s: could not open display \"%s\"\n", argv[0],
XDisplayName(display_name));
exit(1);
}
dpy = XOpenDisplay(display_name);
XSetErrorHandler(errorHandler);
if (!dpy) {
fprintf(stderr, "%s: could not open display \"%s\"\n", argv[0], XDisplayName(display_name));
exit(1);
}
if (buffer<0) {
Atom *rootWinProps;
int exists[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int i, count;
if (buffer < 0) {
Atom *rootWinProps;
int exists[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
int i, count;
/* Create missing CUT_BUFFERs */
rootWinProps = XListProperties(dpy, DefaultRootWindow(dpy), &count);
for (i=0; i<count; i++) {
switch(rootWinProps[i]) {
case XA_CUT_BUFFER0:
exists[0] = 1; break;
case XA_CUT_BUFFER1:
exists[1] = 1; break;
case XA_CUT_BUFFER2:
exists[2] = 1; break;
case XA_CUT_BUFFER3:
exists[3] = 1; break;
case XA_CUT_BUFFER4:
exists[4] = 1; break;
case XA_CUT_BUFFER5:
exists[5] = 1; break;
case XA_CUT_BUFFER6:
exists[6] = 1; break;
case XA_CUT_BUFFER7:
exists[7] = 1; break;
default:
break;
}
}
if (rootWinProps) {
XFree(rootWinProps);
}
for (i=0; i<8; i++) {
if (!exists[i]) {
XStoreBuffer(dpy, "", 0, i);
}
}
/* Create missing CUT_BUFFERs */
rootWinProps = XListProperties(dpy, DefaultRootWindow(dpy), &count);
for (i = 0; i < count; i++) {
switch (rootWinProps[i]) {
case XA_CUT_BUFFER0:
exists[0] = 1;
break;
case XA_CUT_BUFFER1:
exists[1] = 1;
break;
case XA_CUT_BUFFER2:
exists[2] = 1;
break;
case XA_CUT_BUFFER3:
exists[3] = 1;
break;
case XA_CUT_BUFFER4:
exists[4] = 1;
break;
case XA_CUT_BUFFER5:
exists[5] = 1;
break;
case XA_CUT_BUFFER6:
exists[6] = 1;
break;
case XA_CUT_BUFFER7:
exists[7] = 1;
break;
default:
break;
}
}
if (rootWinProps) {
XFree(rootWinProps);
}
for (i = 0; i < 8; i++) {
if (!exists[i]) {
XStoreBuffer(dpy, "", 0, i);
}
}
XRotateBuffers(dpy, 1);
buffer=0;
}
XRotateBuffers(dpy, 1);
buffer = 0;
}
while (!feof(file)) {
char *nbuf;
char tmp[LINESIZE+2];
int nl=0;
while (!feof(file)) {
char *nbuf;
char tmp[LINESIZE + 2];
int nl = 0;
/*
* Use read() instead of fgets() to preserve NULLs, since
* especially since there's no reason to read one line at a time.
*/
if ((nl = fread(tmp, 1, LINESIZE, file)) <= 0) {
break;
}
if (buf_len == 0) {
nbuf = malloc(buf_len = l+nl+1);
} else if (buf_len < l+nl+1) {
/*
* To avoid terrible performance on big input buffers,
* grow by doubling, not by the minimum needed for the
* current line.
*/
buf_len = 2 * buf_len + nl + 1;
/* some realloc implementations don't do malloc if buf==NULL */
if (buf == NULL) {
nbuf = malloc(buf_len);
} else {
nbuf = realloc(buf, buf_len);
}
} else {
nbuf = buf;
}
if (!nbuf) {
fprintf(stderr, "%s: out of memory\n", argv[0]);
exit(1);
}
buf=nbuf;
/*
* Don't strcat, since it would make the algorithm n-squared.
* Don't use strcpy, since it stops on a NUL.
*/
memcpy(buf+l, tmp, nl);
l+=nl;
if (limit_check && l>=MAXDATA) {
fprintf
(
stderr,
"%s: too much data in input - more than %d bytes\n"
" use the -nolimit argument to remove the limit check.\n",
argv[0], MAXDATA
);
exit(1);
}
}
/*
* Use read() instead of fgets() to preserve NULLs, since
* especially since there's no reason to read one line at a time.
*/
if ((nl = fread(tmp, 1, LINESIZE, file)) <= 0) {
break;
}
if (buf_len == 0) {
nbuf = malloc(buf_len = l + nl + 1);
} else if (buf_len < l + nl + 1) {
/*
* To avoid terrible performance on big input buffers,
* grow by doubling, not by the minimum needed for the
* current line.
*/
buf_len = 2 * buf_len + nl + 1;
/* some realloc implementations don't do malloc if buf==NULL */
if (buf == NULL) {
nbuf = malloc(buf_len);
} else {
nbuf = realloc(buf, buf_len);
}
} else {
nbuf = buf;
}
if (!nbuf) {
fprintf(stderr, "%s: out of memory\n", argv[0]);
exit(1);
}
buf = nbuf;
/*
* Don't strcat, since it would make the algorithm n-squared.
* Don't use strcpy, since it stops on a NUL.
*/
memcpy(buf + l, tmp, nl);
l += nl;
if (limit_check && l >= MAXDATA) {
fprintf
(stderr,
"%s: too much data in input - more than %d bytes\n"
" use the -nolimit argument to remove the limit check.\n", argv[0], MAXDATA);
exit(1);
}
}
if (clear_selection) {
XSetSelectionOwner(dpy, XA_PRIMARY, None, CurrentTime);
}
if (buf) {
XStoreBuffer(dpy, buf, l, buffer);
}
XFlush(dpy);
XCloseDisplay(dpy);
exit(buf == NULL || errno != 0);
if (clear_selection) {
XSetSelectionOwner(dpy, XA_PRIMARY, None, CurrentTime);
}
if (buf) {
XStoreBuffer(dpy, buf, l, buffer);
}
XFlush(dpy);
XCloseDisplay(dpy);
exit(buf == NULL || errno != 0);
}

View File

@@ -34,217 +34,198 @@
# include <sys/select.h>
#endif
#define MAXDATA (4*1024*1024)
void
help(char *progn)
void help(char *progn)
{
printf("Usage: %s [OPTIONS] [FILE]\n", progn);
puts("Copies data from X selection or cutbuffer to FILE or stdout.");
puts("");
puts(" -display display display to use");
puts(" --cutbuffer number cutbuffer number to get data from");
puts(" --selection [selection] reads data from named selection instead of\n"
" cutbuffer");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
printf("Usage: %s [OPTIONS] [FILE]\n", progn);
puts("Copies data from X selection or cutbuffer to FILE or stdout.");
puts("");
puts(" -display display display to use");
puts(" --cutbuffer number cutbuffer number to get data from");
puts(" --selection [selection] reads data from named selection instead of\n"
" cutbuffer");
puts(" --help display this help and exit");
puts(" --version output version information and exit");
}
Time
getTimestamp(Display *dpy, Window win)
Time getTimestamp(Display * dpy, Window win)
{
XEvent ev;
XEvent ev;
/* So we do this trickery to get a time stamp:
*
* 1. Grab the server because we are paranoid and don't want to
* get in a race with another instance of wxpaste being ran at the
* same time.
*
* 2. Set a dummy property in our window.
*
* 3. Get the PropertyNotify event and get it's timestamp.
*
* 4. Ungrab the server.
*/
/* So we do this trickery to get a time stamp:
*
* 1. Grab the server because we are paranoid and don't want to
* get in a race with another instance of wxpaste being ran at the
* same time.
*
* 2. Set a dummy property in our window.
*
* 3. Get the PropertyNotify event and get it's timestamp.
*
* 4. Ungrab the server.
*/
XSelectInput(dpy, win, PropertyChangeMask);
XSelectInput(dpy, win, PropertyChangeMask);
/* Generate a PropertyNotify event */
XStoreName(dpy, win, "shit");
/* Generate a PropertyNotify event */
XStoreName(dpy, win, "shit");
/* wait for the event */
while (1) {
XNextEvent(dpy, &ev);
if (ev.type == PropertyNotify)
break;
}
/* wait for the event */
while (1) {
XNextEvent(dpy, &ev);
if (ev.type == PropertyNotify)
break;
}
return ev.xproperty.time;
return ev.xproperty.time;
}
char*
fetchSelection(Display *dpy, char *selection, char *progName)
char *fetchSelection(Display * dpy, char *selection, char *progName)
{
Atom selatom = XInternAtom(dpy, selection, False);
Atom clipatom = XInternAtom(dpy, "CLIPBOARD", False);
Time now;
XEvent ev;
Window win;
int ok = 0;
struct timeval timeout;
fd_set fdset;
Atom selatom = XInternAtom(dpy, selection, False);
Atom clipatom = XInternAtom(dpy, "CLIPBOARD", False);
Time now;
XEvent ev;
Window win;
int ok = 0;
struct timeval timeout;
fd_set fdset;
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1,
0, 0, 0);
/*
* The ICCCM says that we can't pass CurrentTime as the timestamp
* for XConvertSelection(), but we don't have anything to use as
* a timestamp...
*/
now = getTimestamp(dpy, win);
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 1, 1, 0, 0, 0);
/*
* The ICCCM says that we can't pass CurrentTime as the timestamp
* for XConvertSelection(), but we don't have anything to use as
* a timestamp...
*/
now = getTimestamp(dpy, win);
XConvertSelection(dpy, selatom, XA_STRING, clipatom, win, now);
XConvertSelection(dpy, selatom, XA_STRING, clipatom, win, now);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
/* wait for the convertion */
while (0) {
int res;
/* wait for the convertion */
while (0) {
int res;
if (XPending(dpy)==0) {
FD_ZERO(&fdset);
FD_SET(ConnectionNumber(dpy), &fdset);
res = select(ConnectionNumber(dpy)+1, &fdset, NULL, NULL,
&timeout);
if (res <= 0) {
ok = 0;
break;
}
}
if (res > 0 || XPending(dpy) > 0) {
XNextEvent(dpy, &ev);
if (ev.type == SelectionNotify && ev.xany.window == win) {
ok = 1;
break;
}
}
}
if (XPending(dpy) == 0) {
FD_ZERO(&fdset);
FD_SET(ConnectionNumber(dpy), &fdset);
res = select(ConnectionNumber(dpy) + 1, &fdset, NULL, NULL, &timeout);
if (res <= 0) {
ok = 0;
break;
}
}
if (res > 0 || XPending(dpy) > 0) {
XNextEvent(dpy, &ev);
if (ev.type == SelectionNotify && ev.xany.window == win) {
ok = 1;
break;
}
}
}
/* if success, return the data */
if (ok) {
Atom rtype;
int bits;
unsigned long len, bytes;
unsigned char *data;
/* if success, return the data */
if (ok) {
Atom rtype;
int bits;
unsigned long len, bytes;
unsigned char *data;
if (XGetWindowProperty(dpy, win, clipatom, 0, MAXDATA/4, False,
XA_STRING, &rtype, &bits, &len, &bytes, &data)!=0)
return NULL;
if (XGetWindowProperty(dpy, win, clipatom, 0, MAXDATA / 4, False,
XA_STRING, &rtype, &bits, &len, &bytes, &data) != 0)
return NULL;
if ((rtype!=XA_STRING) || (bits!=8)) {
return NULL;
} else {
return (char*)data;
}
}
return NULL;
if ((rtype != XA_STRING) || (bits != 8)) {
return NULL;
} else {
return (char *)data;
}
}
return NULL;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
Display *dpy;
int i, l;
int buffer=0;
char *buf;
int status;
char *display_name="";
char *selection_name=NULL;
Display *dpy;
int i, l;
int buffer = 0;
char *buf;
int status;
char *display_name = "";
char *selection_name = NULL;
for (i=1; i<argc; i++) {
if (argv[i][0]=='-') {
if (argv[i][1]=='h' || strcmp(argv[i], "--help")==0) {
help(argv[0]);
exit(0);
} else if (strcmp(argv[i], "--version")==0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp(argv[i],"-selection")==0
|| strcmp(argv[i],"--selection")==0) {
if (i<argc-1) {
selection_name = argv[++i];
} else {
selection_name = "PRIMARY";
}
} else if (strcmp(argv[i],"-display")==0) {
if (i<argc-1) {
display_name = argv[++i];
} else {
help(argv[0]);
exit(0);
}
} else if (strcmp(argv[i],"-cutbuffer")==0
|| strcmp(argv[i],"--cutbuffer")==0) {
if (i<argc-1) {
i++;
if (sscanf(argv[i],"%i", &buffer)!=1) {
fprintf(stderr, "%s: could not convert \"%s\" to int\n",
argv[0], argv[i]);
exit(1);
}
if (buffer<0 || buffer > 7) {
fprintf(stderr, "%s: invalid buffer number %i\n",
argv[0], buffer);
exit(1);
}
} else {
fprintf(stderr, "%s: invalid argument '%s'\n", argv[0],
argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n",
argv[0]);
exit(1);
}
}
} else {
fprintf(stderr, "%s: invalid argument '%s'\n", argv[0], argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n",
argv[0]);
exit(1);
}
}
dpy = XOpenDisplay(display_name);
if (!dpy) {
fprintf(stderr, "%s: could not open display \"%s\"\n", argv[0],
XDisplayName(display_name));
exit(1);
}
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
if (argv[i][1] == 'h' || strcmp(argv[i], "--help") == 0) {
help(argv[0]);
exit(0);
} else if (strcmp(argv[i], "--version") == 0) {
puts(PROG_VERSION);
exit(0);
} else if (strcmp(argv[i], "-selection") == 0 || strcmp(argv[i], "--selection") == 0) {
if (i < argc - 1) {
selection_name = argv[++i];
} else {
selection_name = "PRIMARY";
}
} else if (strcmp(argv[i], "-display") == 0) {
if (i < argc - 1) {
display_name = argv[++i];
} else {
help(argv[0]);
exit(0);
}
} else if (strcmp(argv[i], "-cutbuffer") == 0 || strcmp(argv[i], "--cutbuffer") == 0) {
if (i < argc - 1) {
i++;
if (sscanf(argv[i], "%i", &buffer) != 1) {
fprintf(stderr, "%s: could not convert \"%s\" to int\n",
argv[0], argv[i]);
exit(1);
}
if (buffer < 0 || buffer > 7) {
fprintf(stderr, "%s: invalid buffer number %i\n", argv[0], buffer);
exit(1);
}
} else {
fprintf(stderr, "%s: invalid argument '%s'\n", argv[0], argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
exit(1);
}
}
} else {
fprintf(stderr, "%s: invalid argument '%s'\n", argv[0], argv[i]);
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
exit(1);
}
}
dpy = XOpenDisplay(display_name);
if (!dpy) {
fprintf(stderr, "%s: could not open display \"%s\"\n", argv[0], XDisplayName(display_name));
exit(1);
}
if (selection_name) {
buf = fetchSelection(dpy, selection_name, argv[0]);
} else {
buf = NULL;
}
if (selection_name) {
buf = fetchSelection(dpy, selection_name, argv[0]);
} else {
buf = NULL;
}
if (buf == NULL) {
buf = XFetchBuffer(dpy, &l, buffer);
}
if (buf == NULL) {
buf = XFetchBuffer(dpy, &l, buffer);
}
if (buf == NULL) {
status = 1;
} else {
if (write(STDOUT_FILENO, buf, l) == -1)
status = errno;
else
status = 0;
}
XCloseDisplay(dpy);
exit(status);
if (buf == NULL) {
status = 1;
} else {
if (write(STDOUT_FILENO, buf, l) == -1)
status = errno;
else
status = 0;
}
XCloseDisplay(dpy);
exit(status);
}