From 688a56e8ab67b56550e2874d9d7423f0d435bfd9 Mon Sep 17 00:00:00 2001 From: "Carlos R. Mafra" Date: Thu, 20 Aug 2009 00:59:40 +0200 Subject: [PATCH] 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 :-) --- WINGs/Examples/colorpick.c | 39 +- WINGs/Examples/connect.c | 242 +- WINGs/Examples/fontl.c | 118 +- WINGs/Examples/puzzle.c | 340 +- WINGs/Examples/server.c | 1023 +++-- WINGs/Extras/test.c | 173 +- WINGs/Extras/wtabledelegates.c | 786 ++-- WINGs/Extras/wtableview.c | 1815 ++++----- WINGs/Tests/mywidget.c | 232 +- WINGs/Tests/testmywidget.c | 56 +- WINGs/Tests/wmfile.c | 152 +- WINGs/Tests/wmquery.c | 129 +- WINGs/Tests/wtest.c | 1500 ++++---- WINGs/array.c | 434 +-- WINGs/bagtree.c | 1118 +++--- WINGs/configuration.c | 161 +- WINGs/connection.c | 1303 +++---- WINGs/data.c | 371 +- WINGs/dragcommon.c | 357 +- WINGs/dragdestination.c | 1337 +++---- WINGs/dragsource.c | 1626 ++++---- WINGs/error.c | 182 +- WINGs/findfile.c | 512 ++- WINGs/handlers.c | 755 ++-- WINGs/hashtable.c | 632 ++- WINGs/host.c | 317 +- WINGs/international.c | 5 +- WINGs/memory.c | 232 +- WINGs/misc.c | 14 +- WINGs/notification.c | 686 ++-- WINGs/proplist.c | 2553 ++++++------ WINGs/puzzle.c | 361 +- WINGs/selection.c | 611 ++- WINGs/snprintf.c | 1345 +++---- WINGs/string.c | 315 +- WINGs/tree.c | 321 +- WINGs/userdefaults.c | 810 ++-- WINGs/usleep.c | 38 +- WINGs/wapplication.c | 273 +- WINGs/wappresource.c | 204 +- WINGs/wballoon.c | 666 ++-- WINGs/wbox.c | 361 +- WINGs/wbrowser.c | 1706 ++++---- WINGs/wbutton.c | 1102 +++--- WINGs/wcolor.c | 452 +-- WINGs/wcolorpanel.c | 5645 +++++++++++++-------------- WINGs/wcolorwell.c | 558 ++- WINGs/wevent.c | 634 ++- WINGs/wfilepanel.c | 1374 ++++--- WINGs/wfont.c | 609 ++- WINGs/wfont_noxft.c | 1060 +++-- WINGs/wfont_wchar.c | 910 ++--- WINGs/wfontpanel.c | 1161 +++--- WINGs/wframe.c | 381 +- WINGs/widgets.c | 1643 ++++---- WINGs/winputmethod.c | 312 +- WINGs/wlabel.c | 306 +- WINGs/wlist.c | 1673 ++++---- WINGs/wmenuitem.c | 284 +- WINGs/wmisc.c | 624 ++- WINGs/wpanel.c | 935 ++--- WINGs/wpixmap.c | 315 +- WINGs/wpopupbutton.c | 1050 +++-- WINGs/wprogressindicator.c | 321 +- WINGs/wruler.c | 767 ++-- WINGs/wscroller.c | 1254 +++--- WINGs/wscrollview.c | 867 ++--- WINGs/wslider.c | 733 ++-- WINGs/wsplitview.c | 1103 +++--- WINGs/wtabview.c | 1324 +++---- WINGs/wtext.c | 6306 +++++++++++++++--------------- WINGs/wtextfield.c | 2323 ++++++----- WINGs/wutil.c | 29 +- WINGs/wview.c | 968 +++-- WINGs/wwindow.c | 1149 +++--- WPrefs.app/Appearance.c | 3316 ++++++++-------- WPrefs.app/Configurations.c | 756 ++-- WPrefs.app/Expert.c | 127 +- WPrefs.app/Focus.c | 507 ++- WPrefs.app/Font.c | 3161 ++++++++------- WPrefs.app/FontSimple.c | 1138 +++--- WPrefs.app/Icons.c | 484 ++- WPrefs.app/KeyboardSettings.c | 236 +- WPrefs.app/KeyboardShortcuts.c | 978 +++-- WPrefs.app/Menu.c | 2605 ++++++------- WPrefs.app/MenuPreferences.c | 307 +- WPrefs.app/MouseSettings.c | 1249 +++--- WPrefs.app/Paths.c | 463 ++- WPrefs.app/Preferences.c | 494 ++- WPrefs.app/TexturePanel.c | 2268 +++++------ WPrefs.app/Themes.c | 278 +- WPrefs.app/WPrefs.c | 1407 ++++--- WPrefs.app/WindowHandling.c | 618 ++- WPrefs.app/Workspace.c | 516 ++- WPrefs.app/double.c | 226 +- WPrefs.app/editmenu.c | 1916 +++++---- WPrefs.app/imagebrowser.c | 157 +- WPrefs.app/main.c | 235 +- WPrefs.app/xmodifier.c | 288 +- plugins/libwmfun/bilinear.c | 40 +- plugins/libwmfun/fade.c | 59 +- plugins/libwmfun/generic.c | 53 +- plugins/libwmfun/getopt.c | 811 ++-- plugins/libwmfun/getopt1.c | 177 +- plugins/libwmfun/wave.c | 51 +- src/actions.c | 2882 +++++++------- src/appicon.c | 1090 +++--- src/application.c | 679 ++-- src/appmenu.c | 421 +- src/balloon.c | 830 ++-- src/client.c | 1131 +++--- src/colormap.c | 159 +- src/cycling.c | 362 +- src/defaults.c | 5263 ++++++++++++------------- src/dialog.c | 2776 +++++++------ src/dock.c | 6642 +++++++++++++++----------------- src/dockedapp.c | 679 ++-- src/event.c | 2569 ++++++------ src/framewin.c | 2232 +++++------ src/geomview.c | 191 +- src/icon.c | 1332 +++---- src/main.c | 924 +++-- src/menu.c | 4050 +++++++++---------- src/menureader.c | 510 ++- src/misc.c | 1919 +++++---- src/monitor.c | 169 +- src/motif.c | 273 +- src/moveres.c | 3794 +++++++++--------- src/pixmap.c | 283 +- src/placement.c | 915 +++-- src/properties.c | 435 +-- src/resources.c | 37 +- src/rootmenu.c | 2592 ++++++------- src/screen.c | 1627 ++++---- src/session.c | 1756 ++++----- src/shutdown.c | 225 +- src/stacking.c | 741 ++-- src/startup.c | 1195 +++--- src/superfluous.c | 1086 +++--- src/switchmenu.c | 605 ++- src/switchpanel.c | 1058 +++-- src/text.c | 699 ++-- src/texture.c | 1066 +++-- src/usermenu.c | 458 ++- src/wcore.c | 174 +- src/wdefaults.c | 725 ++-- src/window.c | 4821 +++++++++++------------ src/winmenu.c | 914 +++-- src/winspector.c | 2520 ++++++------ src/wmspec.c | 2420 ++++++------ src/workspace.c | 2131 +++++----- src/wsmap.c | 105 +- src/wsound.c | 40 +- src/xdnd.c | 475 ++- src/xinerama.c | 400 +- src/xmodifier.c | 329 +- src/xutil.c | 307 +- test/notest.c | 164 +- test/wtest.c | 204 +- util/convertfonts.c | 181 +- util/directjpeg.c | 249 +- util/fontconv.c | 255 +- util/geticonset.c | 156 +- util/getstyle.c | 958 +++-- util/seticons.c | 180 +- util/setstyle.c | 888 ++--- util/wdread.c | 128 +- util/wdwrite.c | 143 +- util/wmagnify.c | 740 ++-- util/wmsetbg.c | 2276 ++++++----- util/wmsetup.c | 520 ++- util/wxcopy.c | 388 +- util/wxpaste.c | 349 +- wmlib/app.c | 74 +- wmlib/command.c | 77 +- wmlib/event.c | 94 +- wmlib/menu.c | 392 +- wrlib/CmapAlloc.c | 312 +- wrlib/CrCmap.c | 709 ++-- wrlib/DelCmap.c | 37 +- wrlib/LookupCmap.c | 361 +- wrlib/StdCmap.c | 276 +- wrlib/alloca.c | 505 ++- wrlib/color.c | 160 +- wrlib/context.c | 1130 +++--- wrlib/convert.c | 1699 ++++---- wrlib/convolve.c | 441 +-- wrlib/draw.c | 905 +++-- wrlib/gif.c | 324 +- wrlib/gradient.c | 915 +++-- wrlib/jpeg.c | 224 +- wrlib/load.c | 400 +- wrlib/misc.c | 307 +- wrlib/nxpm.c | 959 ++--- wrlib/png.c | 308 +- wrlib/ppm.c | 225 +- wrlib/raster.c | 998 ++--- wrlib/rotate.c | 530 ++- wrlib/save.c | 19 +- wrlib/scale.c | 845 ++-- wrlib/tests/testdraw.c | 965 +++-- wrlib/tests/testgrad.c | 308 +- wrlib/tests/testrot.c | 84 +- wrlib/tests/view.c | 116 +- wrlib/tiff.c | 177 +- wrlib/x86_specific.c | 1150 +++--- wrlib/xpixmap.c | 249 +- wrlib/xpm.c | 446 ++- wrlib/xutil.c | 352 +- 209 files changed, 87034 insertions(+), 98138 deletions(-) diff --git a/WINGs/Examples/colorpick.c b/WINGs/Examples/colorpick.c index ae1695e4..24daa2ce 100644 --- a/WINGs/Examples/colorpick.c +++ b/WINGs/Examples/colorpick.c @@ -3,40 +3,37 @@ #include #include - - void showSelectedColor(void *self, void *cdata) { - WMColorPanel *panel= (WMColorPanel*)self; + WMColorPanel *panel = (WMColorPanel *) self; - printf("Selected Color: %s\n", WMGetColorRGBDescription(WMGetColorPanelColor(panel))); + printf("Selected Color: %s\n", WMGetColorRGBDescription(WMGetColorPanelColor(panel))); } - int main(int argc, char **argv) { - Display *dpy; - WMScreen *scr; + Display *dpy; + WMScreen *scr; - WMInitializeApplication("wmcolorpick", &argc, argv); + WMInitializeApplication("wmcolorpick", &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)); - { - WMColorPanel *panel= WMGetColorPanel(scr); + { + WMColorPanel *panel = WMGetColorPanel(scr); - WMSetColorPanelAction(panel, showSelectedColor, NULL); + WMSetColorPanelAction(panel, showSelectedColor, NULL); - WMShowColorPanel(panel); - } + WMShowColorPanel(panel); + } - WMScreenMainLoop(scr); + WMScreenMainLoop(scr); - return 0; + return 0; } diff --git a/WINGs/Examples/connect.c b/WINGs/Examples/connect.c index 14a2174f..9b4b93a4 100644 --- a/WINGs/Examples/connect.c +++ b/WINGs/Examples/connect.c @@ -5,7 +5,6 @@ * */ - #include #include #include @@ -13,186 +12,161 @@ #include - - static int initialized = 0; +static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr); +static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr); -static void didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr); - -static void connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr); - -static void didInitialize(ConnectionDelegate *self, WMConnection *cPtr); - - +static void didInitialize(ConnectionDelegate * self, WMConnection * cPtr); static ConnectionDelegate socketDelegate = { - NULL, /* data */ - NULL, /* canResumeSending */ - NULL, /* didCatchException */ - connectionDidDie, /* didDie */ - didInitialize, /* didInitialize */ - didReceiveInput, /* didReceiveInput */ - NULL /* didTimeout */ + NULL, /* data */ + NULL, /* canResumeSending */ + NULL, /* didCatchException */ + connectionDidDie, /* didDie */ + didInitialize, /* didInitialize */ + didReceiveInput, /* didReceiveInput */ + NULL /* didTimeout */ }; - - -void -wAbort(Bool foo) +void wAbort(Bool foo) { - exit(1); + exit(1); } - -static char* -getMessage(WMConnection *cPtr) +static char *getMessage(WMConnection * cPtr) { - char *buffer; - WMData *aData; - int length; + char *buffer; + WMData *aData; + int length; - aData = WMGetConnectionAvailableData(cPtr); - if (!aData) - return NULL; - if ((length=WMGetDataLength(aData))==0) { - WMReleaseData(aData); - return NULL; - } + aData = WMGetConnectionAvailableData(cPtr); + if (!aData) + return NULL; + if ((length = WMGetDataLength(aData)) == 0) { + WMReleaseData(aData); + return NULL; + } - buffer = (char*)wmalloc(length+1); - WMGetDataBytes(aData, buffer); - buffer[length]= '\0'; - WMReleaseData(aData); + buffer = (char *)wmalloc(length + 1); + WMGetDataBytes(aData, buffer); + buffer[length] = '\0'; + WMReleaseData(aData); - return buffer; + return buffer; } - -static void -inputHandler(int fd, int mask, void *clientData) +static void inputHandler(int fd, int mask, void *clientData) { - WMConnection *cPtr = (WMConnection*)clientData; - WMData *aData; - char buf[4096]; - int n; + WMConnection *cPtr = (WMConnection *) clientData; + WMData *aData; + char buf[4096]; + int n; - if (!initialized) - return; + if (!initialized) + return; - n = read(fd, buf, 4096); - if (n>0) { - aData = WMCreateDataWithBytes(buf, n); - WMSendConnectionData(cPtr, aData); - WMReleaseData(aData); - } + n = read(fd, buf, 4096); + if (n > 0) { + aData = WMCreateDataWithBytes(buf, n); + WMSendConnectionData(cPtr, aData); + WMReleaseData(aData); + } } - -static void -didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr) +static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr) { - char *buffer; + char *buffer; - buffer = getMessage(cPtr); - if (!buffer) { - fprintf(stderr, "Connection closed by peer.\n"); - exit(0); - } + buffer = getMessage(cPtr); + if (!buffer) { + fprintf(stderr, "Connection closed by peer.\n"); + exit(0); + } - printf("%s", buffer); + printf("%s", buffer); - wfree(buffer); + wfree(buffer); } - -static void -connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr) +static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr) { - WMCloseConnection(cPtr); + WMCloseConnection(cPtr); - fprintf(stderr, "Connection closed by peer.\n"); - exit(0); + fprintf(stderr, "Connection closed by peer.\n"); + exit(0); } - -static void -didInitialize(ConnectionDelegate *self, WMConnection *cPtr) +static void didInitialize(ConnectionDelegate * self, WMConnection * cPtr) { - int state = WMGetConnectionState(cPtr); - WMHost *host; + int state = WMGetConnectionState(cPtr); + WMHost *host; - if (state == WCConnected) { - host = WMGetHostWithAddress(WMGetConnectionAddress(cPtr)); - fprintf(stderr, "connected to '%s:%s'\n", - host?WMGetHostName(host):WMGetConnectionAddress(cPtr), - WMGetConnectionService(cPtr)); - initialized = 1; - if (host) - WMReleaseHost(host); - return; - } else { - wsyserrorwithcode(WCErrorCode, "Unable to connect"); - exit(1); - } + if (state == WCConnected) { + host = WMGetHostWithAddress(WMGetConnectionAddress(cPtr)); + fprintf(stderr, "connected to '%s:%s'\n", + host ? WMGetHostName(host) : WMGetConnectionAddress(cPtr), WMGetConnectionService(cPtr)); + initialized = 1; + if (host) + WMReleaseHost(host); + return; + } else { + wsyserrorwithcode(WCErrorCode, "Unable to connect"); + exit(1); + } } - -int -main(int argc, char **argv) +int main(int argc, char **argv) { - char *ProgName, *host, *port; - int i; - WMConnection *sPtr; + char *ProgName, *host, *port; + int i; + WMConnection *sPtr; - wsetabort(wAbort); + wsetabort(wAbort); - WMInitializeApplication("connect", &argc, argv); + WMInitializeApplication("connect", &argc, argv); - ProgName = strrchr(argv[0],'/'); - if (!ProgName) - ProgName = argv[0]; - else - ProgName++; + ProgName = strrchr(argv[0], '/'); + if (!ProgName) + ProgName = argv[0]; + else + ProgName++; - host = NULL; - port = "34567"; + host = NULL; + port = "34567"; - if (argc>1) { - for (i=1; i 1) { + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { + printf("usage: %s [host [port]]\n\n", ProgName); + exit(0); + } else { + if (!host) + host = argv[i]; + else + port = argv[i]; + } + } + } - printf("Trying to make connection to '%s:%s'\n", - host?host:"localhost", port); + printf("Trying to make connection to '%s:%s'\n", host ? host : "localhost", port); - sPtr = WMCreateConnectionToAddressAndNotify(host, port, NULL); - if (!sPtr) { - wfatal("could not create connection. exiting"); - exit(1); - } + sPtr = WMCreateConnectionToAddressAndNotify(host, port, NULL); + if (!sPtr) { + wfatal("could not create connection. exiting"); + exit(1); + } - WMSetConnectionDelegate(sPtr, &socketDelegate); + WMSetConnectionDelegate(sPtr, &socketDelegate); - /* watch what user types and send it over the connection */ - WMAddInputHandler(0, WIReadMask, inputHandler, sPtr); + /* watch what user types and send it over the connection */ + WMAddInputHandler(0, WIReadMask, inputHandler, sPtr); - while (1) { - WHandleEvents(); - } + while (1) { + WHandleEvents(); + } - return 0; + return 0; } - - diff --git a/WINGs/Examples/fontl.c b/WINGs/Examples/fontl.c index ad9957aa..4e1f642e 100644 --- a/WINGs/Examples/fontl.c +++ b/WINGs/Examples/fontl.c @@ -19,88 +19,80 @@ * USA. */ - - - #include #include #include #include #include -void -wAbort() +void wAbort() { - exit(0); + exit(0); } -void show(WMWidget *self, void *data) +void show(WMWidget * self, void *data) { - char buf[60]; - void *d; - WMLabel *l = (WMLabel*)data; - d = WMGetHangedData(self); - sprintf(buf, "%i - 0x%x - 0%o", (int)(uintptr_t)d, (int)(uintptr_t)d, - (int)(uintptr_t)d); - WMSetLabelText(l, buf); + char buf[60]; + void *d; + WMLabel *l = (WMLabel *) data; + d = WMGetHangedData(self); + sprintf(buf, "%i - 0x%x - 0%o", (int)(uintptr_t) d, (int)(uintptr_t) d, (int)(uintptr_t) d); + WMSetLabelText(l, buf); } -void quit(WMWidget *self, void *data) +void quit(WMWidget * self, void *data) { - exit(0); + exit(0); } - -int -main(int argc, char **argv) +int main(int argc, char **argv) { - Display *dpy; - WMWindow *win; - WMScreen *scr; - WMButton *lab, *l0=NULL; - WMLabel *pos; - int x, y, c; - char buf[20]; + Display *dpy; + WMWindow *win; + WMScreen *scr; + WMButton *lab, *l0 = NULL; + WMLabel *pos; + int x, y, c; + char buf[20]; - WMInitializeApplication("FontView", &argc, argv); + WMInitializeApplication("FontView", &argc, argv); - dpy = XOpenDisplay(""); - if (!dpy) { - wfatal("cant open display"); - exit(0); - } + dpy = XOpenDisplay(""); + if (!dpy) { + wfatal("cant open display"); + exit(0); + } - scr = WMCreateSimpleApplicationScreen(dpy); + scr = WMCreateSimpleApplicationScreen(dpy); - win = WMCreateWindow(scr, "main"); - WMResizeWidget(win, 20*33, 20+20*9); - WMSetWindowTitle(win, "Font Chars"); - WMSetWindowCloseAction(win, quit, NULL); - pos = WMCreateLabel(win); - WMResizeWidget(pos, 20*33, 20); - WMMoveWidget(pos, 10, 5); + win = WMCreateWindow(scr, "main"); + WMResizeWidget(win, 20 * 33, 20 + 20 * 9); + WMSetWindowTitle(win, "Font Chars"); + WMSetWindowCloseAction(win, quit, NULL); + pos = WMCreateLabel(win); + WMResizeWidget(pos, 20 * 33, 20); + WMMoveWidget(pos, 10, 5); - c = 0; - for (y=0; y<8; y++) { - for (x=0; x<32; x++, c++) { - lab = WMCreateCustomButton(win, WBBStateLightMask); - WMResizeWidget(lab, 20, 20); - WMMoveWidget(lab, 10+x*20, 30+y*20); - sprintf(buf, "%c", c); - WMSetButtonText(lab, buf); - WMSetButtonAction(lab, show, pos); - WMHangData(lab, (void*)(uintptr_t)c); - if (c>0) { - WMGroupButtons(l0, lab); - } else { - l0 = lab; - } - } - } - WMRealizeWidget(win); - WMMapSubwidgets(win); - WMMapWidget(win); - WMScreenMainLoop(scr); - return 0; + c = 0; + for (y = 0; y < 8; y++) { + for (x = 0; x < 32; x++, c++) { + lab = WMCreateCustomButton(win, WBBStateLightMask); + WMResizeWidget(lab, 20, 20); + WMMoveWidget(lab, 10 + x * 20, 30 + y * 20); + sprintf(buf, "%c", c); + WMSetButtonText(lab, buf); + WMSetButtonAction(lab, show, pos); + WMHangData(lab, (void *)(uintptr_t) c); + if (c > 0) { + WMGroupButtons(l0, lab); + } else { + l0 = lab; + } + } + } + WMRealizeWidget(win); + WMMapSubwidgets(win); + WMMapWidget(win); + WMScreenMainLoop(scr); + return 0; } - diff --git a/WINGs/Examples/puzzle.c b/WINGs/Examples/puzzle.c index 21e69104..7e8b7997 100644 --- a/WINGs/Examples/puzzle.c +++ b/WINGs/Examples/puzzle.c @@ -1,15 +1,11 @@ - - #include #include #include #include - #define MAX_SIZE 10*10 - WMWindow *win; WMButton *Button[MAX_SIZE]; char Map[MAX_SIZE]; @@ -20,226 +16,218 @@ int MoveCount; int WinSize = 120; - -Bool -CheckWin(void) +Bool CheckWin(void) { - int i; + int i; - for (i = 0; i < Size*Size-1; i++) { - if (Map[i] != i) - return False; - } + for (i = 0; i < Size * Size - 1; i++) { + if (Map[i] != i) + return False; + } - return True; + return True; } - -void -MoveButton(int button, int x, int y) +void MoveButton(int button, int x, int y) { - WMMoveWidget(Button[button], x*(WinSize/Size), y*(WinSize/Size)); + WMMoveWidget(Button[button], x * (WinSize / Size), y * (WinSize / Size)); } - -Bool -SlideButton(int button) +Bool SlideButton(int button) { - int x=0, y=0, done = 0; + int x = 0, y = 0, done = 0; - /* locate the button */ - for (y = 0; y < Size; y++) { - for (x = 0; x < Size; x++) { - if (MAP(x,y) == button) { - done = 1; - break; - } - } - if (done) - break; - } + /* locate the button */ + for (y = 0; y < Size; y++) { + for (x = 0; x < Size; x++) { + if (MAP(x, y) == button) { + done = 1; + break; + } + } + if (done) + break; + } - if (x > 0 && MAP(x-1, y) < 0) { - MAP(x,y) = -1; - MoveButton(button, x-1, y); - MAP(x-1,y) = button; - } else if (x < Size-1 && MAP(x+1, y) < 0) { - MAP(x,y) = -1; - MoveButton(button, x+1, y); - MAP(x+1,y) = button; - } else if (y > 0 && MAP(x, y-1) < 0) { - MAP(x,y) = -1; - MoveButton(button, x, y-1); - MAP(x,y-1) = button; - } else if (y < Size-1 && MAP(x, y+1) < 0) { - MAP(x,y) = -1; - MoveButton(button, x, y+1); - MAP(x,y+1) = button; - } else { - return False; - } - return True; + if (x > 0 && MAP(x - 1, y) < 0) { + MAP(x, y) = -1; + MoveButton(button, x - 1, y); + MAP(x - 1, y) = button; + } else if (x < Size - 1 && MAP(x + 1, y) < 0) { + MAP(x, y) = -1; + MoveButton(button, x + 1, y); + MAP(x + 1, y) = button; + } else if (y > 0 && MAP(x, y - 1) < 0) { + MAP(x, y) = -1; + MoveButton(button, x, y - 1); + MAP(x, y - 1) = button; + } else if (y < Size - 1 && MAP(x, y + 1) < 0) { + MAP(x, y) = -1; + MoveButton(button, x, y + 1); + MAP(x, y + 1) = button; + } else { + return False; + } + return True; } - #define SWAP(a,b) {int tmp; tmp=a; a=b; b=tmp;} void ResetGame(void) { - int i, x, y, ox, oy; + int i, x, y, ox, oy; + MoveCount = 0; - MoveCount = 0; + for (i = 0; i < Size * Size - 1; i++) { + Map[i] = i; + } + Map[i] = -1; + ox = x = Size - 1; + oy = y = Size - 1; + for (i = 0; i < 1000; i++) { + int ok; + ok = 1; + switch (rand() % 4) { + case 0: + if (x > 0) + x--; + else + ok = 0; + break; + case 2: + if (x < Size - 1) + x++; + else + ok = 0; + break; + case 1: + if (y > 0) + y--; + else + ok = 0; + break; + case 3: + if (y < Size - 1) + y++; + else + ok = 0; + break; + } + if (ok) { + MoveButton(MAP(x, y), ox, oy); - for (i = 0; i < Size*Size-1; i++) { - Map[i] = i; - } - Map[i] = -1; - ox = x = Size-1; - oy = y = Size-1; - for (i = 0; i < 1000; i++) { - int ok; - ok = 1; - switch (rand()%4) { - case 0: - if (x > 0) x--; else ok = 0; - break; - case 2: - if (x < Size-1) x++; else ok = 0; - break; - case 1: - if (y > 0) y--; else ok = 0; - break; - case 3: - if (y < Size-1) y++; else ok = 0; - break; - } - if (ok) { - MoveButton(MAP(x,y), ox, oy); + SWAP(MAP(ox, oy), MAP(x, y)); - SWAP(MAP(ox, oy), MAP(x, y)); - - while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) { - XEvent ev; - WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev); - WMHandleEvent(&ev); - } - ox = x; - oy = y; - } - } + while (XPending(WMScreenDisplay(WMWidgetScreen(win)))) { + XEvent ev; + WMNextEvent(WMScreenDisplay(WMWidgetScreen(win)), &ev); + WMHandleEvent(&ev); + } + ox = x; + oy = y; + } + } } - -void buttonClick(WMWidget *w, void *ptr) +void buttonClick(WMWidget * w, void *ptr) { - char buffer[300]; + char buffer[300]; - if (SlideButton((int)(uintptr_t)ptr)) { - MoveCount++; + if (SlideButton((int)(uintptr_t) ptr)) { + MoveCount++; - if (CheckWin()) { - sprintf(buffer, "You finished the game in %i moves.", MoveCount); + if (CheckWin()) { + sprintf(buffer, "You finished the game in %i moves.", MoveCount); - if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer, - "Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) { - exit(0); - } + if (WMRunAlertPanel(WMWidgetScreen(w), win, "You Won!", buffer, + "Wee!", "Gah! Lemme retry!", NULL) == WAPRDefault) { + exit(0); + } - ResetGame(); - } - } + ResetGame(); + } + } } - -static void resizeObserver(void *self, WMNotification *notif) +static void resizeObserver(void *self, WMNotification * notif) { - WMSize size = WMGetViewSize(WMWidgetView(win)); - int x, y; + WMSize size = WMGetViewSize(WMWidgetView(win)); + int x, y; - WinSize = size.width; - for (y = 0; y < Size; y++) { - for (x = 0; x < Size; x++) { - if (MAP(x,y) >= 0) { - WMResizeWidget(Button[(int)MAP(x,y)], - WinSize/Size, WinSize/Size); - WMMoveWidget(Button[(int)MAP(x,y)], - x*(WinSize/Size), y*(WinSize/Size)); - } - } - } + WinSize = size.width; + for (y = 0; y < Size; y++) { + for (x = 0; x < Size; x++) { + if (MAP(x, y) >= 0) { + WMResizeWidget(Button[(int)MAP(x, y)], WinSize / Size, WinSize / Size); + WMMoveWidget(Button[(int)MAP(x, y)], x * (WinSize / Size), y * (WinSize / Size)); + } + } + } } - int main(int argc, char **argv) { - Display *dpy; - WMScreen *scr; - int x, y, i; + Display *dpy; + WMScreen *scr; + int x, y, i; - WMInitializeApplication("Puzzle", &argc, argv); + WMInitializeApplication("Puzzle", &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)); + win = WMCreateWindow(scr, "puzzle"); + WMResizeWidget(win, WinSize, WinSize); + WMSetWindowTitle(win, "zuPzel"); + WMSetWindowMinSize(win, 80, 80); + WMSetWindowAspectRatio(win, 2, 2, 2, 2); + WMSetWindowResizeIncrements(win, Size, Size); + WMSetViewNotifySizeChanges(WMWidgetView(win), True); + WMAddNotificationObserver(resizeObserver, NULL, WMViewSizeDidChangeNotification, WMWidgetView(win)); - win = WMCreateWindow(scr, "puzzle"); - WMResizeWidget(win, WinSize, WinSize); - WMSetWindowTitle(win, "zuPzel"); - WMSetWindowMinSize(win, 80, 80); - WMSetWindowAspectRatio(win, 2, 2, 2, 2); - WMSetWindowResizeIncrements(win, Size, Size); - WMSetViewNotifySizeChanges(WMWidgetView(win), True); - WMAddNotificationObserver(resizeObserver, NULL, - WMViewSizeDidChangeNotification, - WMWidgetView(win)); + for (i = y = 0; y < Size && i < Size * Size - 1; y++) { + for (x = 0; x < Size && i < Size * Size - 1; x++) { + char buf[32]; + WMColor *color; + RColor col; + RHSVColor hsv; + hsv.hue = i * 360 / (Size * Size - 1); + hsv.saturation = 120; + hsv.value = 200; + RHSVtoRGB(&hsv, &col); - for (i = y = 0; y < Size && i < Size*Size-1; y++) { - for (x = 0; x < Size && i < Size*Size-1; x++) { - char buf[32]; - WMColor *color; - RColor col; - RHSVColor hsv; + color = WMCreateRGBColor(scr, col.red << 8, col.green << 8, col.blue << 8, False); - hsv.hue = i*360/(Size*Size-1); - hsv.saturation = 120; - hsv.value = 200; + MAP(x, y) = i; + Button[i] = WMCreateButton(win, WBTMomentaryLight); + WMSetWidgetBackgroundColor(Button[i], color); + WMReleaseColor(color); + WMSetButtonAction(Button[i], buttonClick, (void *)(uintptr_t) i); + WMResizeWidget(Button[i], WinSize / Size, WinSize / Size); + WMMoveWidget(Button[i], x * (WinSize / Size), y * (WinSize / Size)); + sprintf(buf, "%i", i + 1); + WMSetButtonText(Button[i], buf); + WMSetButtonTextAlignment(Button[i], WACenter); + i++; + } + } - RHSVtoRGB(&hsv, &col); + WMMapSubwidgets(win); + WMMapWidget(win); + WMRealizeWidget(win); - color = WMCreateRGBColor(scr, col.red<<8, col.green<<8, - col.blue<<8, False); + ResetGame(); - MAP(x,y) = i; - Button[i] = WMCreateButton(win, WBTMomentaryLight); - WMSetWidgetBackgroundColor(Button[i], color); - WMReleaseColor(color); - WMSetButtonAction(Button[i], buttonClick, (void*)(uintptr_t)i); - WMResizeWidget(Button[i], WinSize/Size, WinSize/Size); - WMMoveWidget(Button[i], x*(WinSize/Size), y*(WinSize/Size)); - sprintf(buf, "%i", i+1); - WMSetButtonText(Button[i], buf); - WMSetButtonTextAlignment(Button[i], WACenter); - i++; - } - } + WMScreenMainLoop(scr); - WMMapSubwidgets(win); - WMMapWidget(win); - WMRealizeWidget(win); - - ResetGame(); - - WMScreenMainLoop(scr); - - return 0; + return 0; } - diff --git a/WINGs/Examples/server.c b/WINGs/Examples/server.c index d0d0e454..e747a1f5 100644 --- a/WINGs/Examples/server.c +++ b/WINGs/Examples/server.c @@ -5,7 +5,6 @@ * */ - #include #include #include @@ -13,22 +12,16 @@ #include - #define _(P) P #define MAXCMD_SIZE 512 - char *SEConnectionShouldBeRemovedNotification = "SEConnectionShouldBeRemovedNotification"; +static void didReceiveInput(ConnectionDelegate * self, WMConnection * cPtr); +static void connectionDidDie(ConnectionDelegate * self, WMConnection * cPtr); - -static void didReceiveInput(ConnectionDelegate *self, WMConnection *cPtr); - -static void connectionDidDie(ConnectionDelegate *self, WMConnection *cPtr); - -static void connectionDidTimeout(ConnectionDelegate *self, WMConnection *cPtr); - +static void connectionDidTimeout(ConnectionDelegate * self, WMConnection * cPtr); extern char *SEConnectionShouldBeRemovedNotification; @@ -39,702 +32,630 @@ static WMArray *allowedHostList = NULL; static WMArray *clientConnections = NULL; static WMConnection *serverPtr = NULL; - - static ConnectionDelegate socketDelegate = { - NULL, /* client data */ - NULL, /* canResumeSending */ - NULL, /* didCatchException */ - connectionDidDie, /* didDie */ - NULL, /* didInitialize */ - didReceiveInput, /* didReceiveInput */ - connectionDidTimeout /* didTimeout */ + NULL, /* client data */ + NULL, /* canResumeSending */ + NULL, /* didCatchException */ + connectionDidDie, /* didDie */ + NULL, /* didInitialize */ + didReceiveInput, /* didReceiveInput */ + connectionDidTimeout /* didTimeout */ }; - - -void -wAbort(Bool foo) +void wAbort(Bool foo) { - exit(1); + exit(1); } - -static void -printHelp(char *progname) +static void printHelp(char *progname) { - printf(_("usage: %s [options]\n\n"), progname); - puts(_(" --help print this message")); - puts(_(" --listen [address:]port only listen on the specified address/port")); - puts(_(" --allow host1[,host2...] only allow connections from listed hosts\n")); - puts(_(" By default server listens on all interfaces and port 34567, unless" - " something\nelse is specified with the --listen option. If address is" - " omitted or the keyword\n'Any' is used, it will listen on all interfaces else" - " only on the specified one.\n\nFor example --listen localhost: will" - " listen on the default port 34567, but only\non connections comming" - " in through the loopback interface.\n\n Also by default the server" - " listens to incoming connections from any host,\nunless a list of" - " hosts is given with the --allow option, in which case it will\nreject" - " connections not comming from those hosts.\nThe list of hosts is comma" - " separated and should NOT contain ANY spaces.")); + printf(_("usage: %s [options]\n\n"), progname); + puts(_(" --help print this message")); + puts(_(" --listen [address:]port only listen on the specified address/port")); + puts(_(" --allow host1[,host2...] only allow connections from listed hosts\n")); + puts(_(" By default server listens on all interfaces and port 34567, unless" + " something\nelse is specified with the --listen option. If address is" + " omitted or the keyword\n'Any' is used, it will listen on all interfaces else" + " only on the specified one.\n\nFor example --listen localhost: will" + " listen on the default port 34567, but only\non connections comming" + " in through the loopback interface.\n\n Also by default the server" + " listens to incoming connections from any host,\nunless a list of" + " hosts is given with the --allow option, in which case it will\nreject" + " connections not comming from those hosts.\nThe list of hosts is comma" + " separated and should NOT contain ANY spaces.")); } - -static void -enqueueConnectionForRemoval(WMConnection *cPtr) +static void enqueueConnectionForRemoval(WMConnection * cPtr) { - WMNotification *notif; + WMNotification *notif; - /*don't release notif here. it will be released by queue after processing */ - notif = WMCreateNotification(SEConnectionShouldBeRemovedNotification, - cPtr, NULL); - WMEnqueueNotification(WMGetDefaultNotificationQueue(), notif, WMPostASAP); + /*don't release notif here. it will be released by queue after processing */ + notif = WMCreateNotification(SEConnectionShouldBeRemovedNotification, cPtr, NULL); + WMEnqueueNotification(WMGetDefaultNotificationQueue(), notif, WMPostASAP); } - -static int -sendMessage(WMConnection *cPtr, char *message) +static int sendMessage(WMConnection * cPtr, char *message) { - WMData *aData; - int res; + WMData *aData; + int res; - if (WMGetConnectionState(cPtr)!=WCConnected) - return -1; + if (WMGetConnectionState(cPtr) != WCConnected) + return -1; - aData = WMCreateDataWithBytes(message, strlen(message)); - res = WMSendConnectionData(cPtr, aData); - WMReleaseData(aData); + aData = WMCreateDataWithBytes(message, strlen(message)); + res = WMSendConnectionData(cPtr, aData); + WMReleaseData(aData); - return res; + return res; } - -static Bool -enqueueMessage(WMConnection *cPtr, char *message) +static Bool enqueueMessage(WMConnection * cPtr, char *message) { - WMData *aData; - Bool res; + WMData *aData; + Bool res; - if (WMGetConnectionState(cPtr)!=WCConnected) - return False; + if (WMGetConnectionState(cPtr) != WCConnected) + return False; - aData = WMCreateDataWithBytes(message, strlen(message)); - res = WMEnqueueConnectionData(cPtr, aData); - WMReleaseData(aData); + aData = WMCreateDataWithBytes(message, strlen(message)); + res = WMEnqueueConnectionData(cPtr, aData); + WMReleaseData(aData); - return res; + return res; } - -static char* -findDelimiter(char *data, const char *endPtr) +static char *findDelimiter(char *data, const char *endPtr) { - wassertrv(data < endPtr, NULL); + wassertrv(data < endPtr, NULL); - while (data MAXCMD_SIZE) { - /* Hmmm... The message is too long. Possibly that someone is - * flooding us, or there is a dumb client which do not know - * who is talking to. */ - sendMessage(cPtr, "Command too long\n\r"); - WMFreeArray(messages); - WMReleaseData(aData); - WMCloseConnection(cPtr); - enqueueConnectionForRemoval(cPtr); - return NULL; - } - buffer = wmalloc(range.count+1); - WMGetDataBytesWithRange(aData, buffer, range); - buffer[range.count] = '\0'; - WMAddToArray(messages, buffer); - crtPos = ptr; - while (crtPos MAXCMD_SIZE) { + /* Hmmm... The message is too long. Possibly that someone is + * flooding us, or there is a dumb client which do not know + * who is talking to. */ + sendMessage(cPtr, "Command too long\n\r"); + WMFreeArray(messages); + WMReleaseData(aData); + WMCloseConnection(cPtr); + enqueueConnectionForRemoval(cPtr); + return NULL; + } + buffer = wmalloc(range.count + 1); + WMGetDataBytesWithRange(aData, buffer, range); + buffer[range.count] = '\0'; + WMAddToArray(messages, buffer); + crtPos = ptr; + while (crtPos < endPtr && (*crtPos == '\n' || *crtPos == '\r' || + *crtPos == '\t' || *crtPos == '\0' || + *crtPos == ';' || *crtPos == ' ')) { + crtPos++; + } + } - if (crtPos MAXCMD_SIZE) { - /* Flooooooding!!!! */ - sendMessage(cPtr, "Message too long\n\r"); - WMFreeArray(messages); - WMReleaseData(aData); - WMCloseConnection(cPtr); - enqueueConnectionForRemoval(cPtr); - return NULL; - } - holdData = WMGetSubdataWithRange(aData, range); - WMSetConnectionClientData(cPtr, holdData); - } - WMReleaseData(aData); + if (crtPos < endPtr) { + range.position = (crtPos - bytes); + range.count = (endPtr - crtPos); + if (range.count > MAXCMD_SIZE) { + /* Flooooooding!!!! */ + sendMessage(cPtr, "Message too long\n\r"); + WMFreeArray(messages); + WMReleaseData(aData); + WMCloseConnection(cPtr); + enqueueConnectionForRemoval(cPtr); + return NULL; + } + holdData = WMGetSubdataWithRange(aData, range); + WMSetConnectionClientData(cPtr, holdData); + } + WMReleaseData(aData); - if (WMGetArrayItemCount(messages)==0) { - WMFreeArray(messages); - messages = NULL; - } - return messages; + if (WMGetArrayItemCount(messages) == 0) { + WMFreeArray(messages); + messages = NULL; + } + return messages; } - - -static void -complainAboutBadArgs(WMConnection *cPtr, char *cmdName, char *badArgs) +static void complainAboutBadArgs(WMConnection * cPtr, char *cmdName, char *badArgs) { - char *buf = wmalloc(strlen(cmdName) + strlen(badArgs) + 100); + char *buf = wmalloc(strlen(cmdName) + strlen(badArgs) + 100); - sprintf(buf, _("Invalid parameters '%s' for command %s. Use HELP for" - " a list of commands.\n"), badArgs, cmdName); - sendMessage(cPtr, buf); - wfree(buf); + sprintf(buf, _("Invalid parameters '%s' for command %s. Use HELP for" + " a list of commands.\n"), badArgs, cmdName); + sendMessage(cPtr, buf); + wfree(buf); } - -static void -sendUpdateMessage(WMConnection *cPtr, char *id, int time) +static void sendUpdateMessage(WMConnection * cPtr, char *id, int time) { - char *buf = wmalloc(strlen(id) + 100); + char *buf = wmalloc(strlen(id) + 100); - sprintf(buf, "%s has %i minutes left\n", id, time); - sendMessage(cPtr, buf); - wfree(buf); + sprintf(buf, "%s has %i minutes left\n", id, time); + sendMessage(cPtr, buf); + wfree(buf); } - -static void -showId(WMConnection *cPtr) +static void showId(WMConnection * cPtr) { - sendMessage(cPtr, "Server example based on WMConnection\n"); + sendMessage(cPtr, "Server example based on WMConnection\n"); } - -static void -showHelp(WMConnection *cPtr) +static void showHelp(WMConnection * cPtr) { - char *buf = wmalloc(strlen(WMGetApplicationName()) + 16); + char *buf = wmalloc(strlen(WMGetApplicationName()) + 16); - sprintf(buf, _("%s commands:\n\n"), WMGetApplicationName()); + sprintf(buf, _("%s commands:\n\n"), WMGetApplicationName()); - enqueueMessage(cPtr, _("\n")); - enqueueMessage(cPtr, buf); - enqueueMessage(cPtr, _("GET \t- return time left (in minutes) " - "for user with id \n")); - enqueueMessage(cPtr, _("SET