Debian Codegraph @

debian/external_deps/fetk/sg/tools/tilesg.c

raw
1 /*
2 * ***************************************************************************
3 * SG = < Socket Graphics >
4 * Copyright (C) 1994-- Michael Holst
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * rcsid="$Id: tilesg.c,v 1.4 2010/08/09 19:02:07 fetk Exp $"
21 * ***************************************************************************
22 */
23
24 /*
25 * ***************************************************************************
26 * File: tilesg.c
27 *
28 * Purpose: Auto-tiler for the Socket Graphics tool SG.
29 *
30 * Author: Michael Holst and Randy Bank
31 * ***************************************************************************
32 */
33
34 #if 0
35 # include <sg/vgl.h>
36 # define VEMBED(rctag) VPRIVATE const char* rctag; \
37 static void* use_rcsid=(0 ? &use_rcsid : (void*)&rcsid);
38 VEMBED(rcsid="$Id: tilesg.c,v 1.4 2010/08/09 19:02:07 fetk Exp $")
39 #else
40 # include <stdio.h>
41 # include <stdlib.h>
42 #endif
43
44 #include <X11/Xlib.h>
45
46 int main(int argc, char *argv[])
47 {
48 int i,j,k,ysize,xsize,header,winY,winX,bysize,bxsize,ret;
49 int border,menubar,xmin,ymin,nrow,ncol,nwin;
50 char cmdbuf[100],PR[80];
51
52 Display *myDisplay;
53 Screen *myScreen;
54
55 myDisplay= XOpenDisplay("");
56 myScreen = DefaultScreenOfDisplay(myDisplay);
57 winX = XWidthOfScreen(myScreen);
58 winY = XHeightOfScreen(myScreen);
59 ret = XCloseDisplay(myDisplay);
60
61 sprintf(PR,"%s","tilesg");
62
63 /* platform parameters (these are for MacOSX): */
64 menubar=20;
65 /* generic parameters: */
66 header=20;
67 border=2;
68
69 /* handles args; determine which Vio object to create (file/unix/inet) */
70 if (argc == 4) {
71 nrow = atoi(argv[1]);
72 ncol = atoi(argv[2]);
73 nwin = atoi(argv[3]);
74 } else {
75 fprintf(stderr,"\n");
76 fprintf(stderr, "Usage: %s rows cols nwin\n",PR);
77 fprintf(stderr,"\n");
78 fprintf(stderr," Parameter interpretation:\n\n");
79 fprintf(stderr," rows = number of rows\n");
80 fprintf(stderr," cols = number of columns\n");
81 fprintf(stderr," nwin = number of windows\n");
82 fprintf(stderr,"\n");
83 return 0;
84 }
85
86 /* ratio=5/7 */
87 ysize = (winY-menubar)/nrow - header - 2*border;
88 xsize = winX/ncol - 2*border;
89 if (5*xsize > 7*ysize) {
90 xsize = (ysize*7)/5;
91 } else {
92 ysize = (xsize*5)/7;
93 }
94 fprintf(stderr,"xsize=<%d> ysize=<%d>\n",xsize,ysize);
95 bysize = ysize + header + 2*border;
96 bxsize = xsize + 2*border;
97 for (i=0; i<ncol; i++) {
98 for (j=0; j<nrow; j++) {
99 k = j + i*nrow;
100 if (k < nwin) {
101 xmin = winX - (i+1)*bxsize;
102 ymin = winY - (j+1)*bysize;
103 fprintf(stderr,"k=<%d> xmin=<%d> ymin=<%d>\n",k,xmin,ymin);
104 sprintf(cmdbuf, "sg -Mci %d -wpos %d,%d@%d,%d &",
105 k,xsize,ysize,xmin,ymin);
106 system(cmdbuf);
107 }
108 }
109 }
110
111 return 0;
112 }
113