]> granicus.if.org Git - xconq/blobdiff - kernel/ps.c
commits for 7.5.0 pre-release tarball
[xconq] / kernel / ps.c
index 5af9bca8476917e8adad18f2b5acbbdb4cdd0592..2c127cbccbf6a8399e3c96851e205b204510fe10 100644 (file)
@@ -272,7 +272,7 @@ ps_cook_imf()
     Image *img;
     
     if (buffer == NULL)
-      buffer = xmalloc(PSBUFSIZE + 4);
+      buffer = (char *)xmalloc(PSBUFSIZE + 4);
     if (unit_icon == NULL)
       unit_icon = (PsImage *)
        xmalloc (numutypes * sizeof(PsImage));
@@ -281,15 +281,15 @@ ps_cook_imf()
        xmalloc (numttypes * sizeof(PsImage));
     if (side_icon == NULL)
       side_icon = (PsImage *)
-       xmalloc (MAXSIDES  * sizeof(PsImage));
+       xmalloc ((MAXSIDES + 1)  * sizeof(PsImage));
     
     /* pick the images we need */
     for_all_unit_types(i) {
        unit_icon[i].imf = NULL;
        /* first choice */
        if (utypes[i].imagename) {
-           unit_icon[i].name = utypes[i].imagename;
-           unit_icon[i].imf = find_imf(utypes[i].imagename);
+           unit_icon[i].name = get_string(utypes[i].imagename);
+           unit_icon[i].imf = find_imf(get_string(utypes[i].imagename));
        }
        /* second choice */
        if (!unit_icon[i].imf && utypes[i].name) {
@@ -354,8 +354,7 @@ ps_cook_imf()
 }
 
 static void 
-ps_initialize_imf(psim)
-PsImage *psim;
+ps_initialize_imf(PsImage *psim)
 {
     /* checks & cleanup */
     if (!psim)
@@ -376,9 +375,7 @@ PsImage *psim;
 }
 
 static char *
-ps_hex_dump(data, w, h)
-Obj *data;
-int w, h;
+ps_hex_dump(Obj *data, int w, int h)
 {
     int i, numbytes;
     unsigned int u;
@@ -386,7 +383,7 @@ int w, h;
   
     numbytes = h * ((w + 7) / 8);
     interp_bytes(data, numbytes, buffer, 0);
-    c = hexdata = xmalloc(2*numbytes+2);
+    c = hexdata = (char *)xmalloc(2*numbytes+2);
     for (i = 0; i < numbytes; ++i) {
        u = buffer[i] & 0xff;
        sprintf(c, "%2.2x", u);
@@ -399,9 +396,7 @@ int w, h;
 /* Should use two symbolic constants instead of 8 ? */
 
 static char *
-img_untile(tiled, w, h, istile, dither, scale, gray)
-char *tiled;
-int w, h, istile, dither, scale, gray;
+img_untile(char *tiled, int w, int h, int istile, int dither, int scale, int gray)
 {
     int dx, dy, x, y, xo, yo, xi, yi, tw, th;
     unsigned int u;
@@ -483,13 +478,12 @@ int w, h, istile, dither, scale, gray;
    '\' to '\\', '(' to '\(', ')' to '\)'.  */
 
 static char *
-add_esc_string(str)
-char *str;
+add_esc_string(char *str)
 {
     char *ps, *pb;
 
     if (escbuf == NULL)
-      escbuf = xmalloc(BUFSIZE);
+      escbuf = (char *)xmalloc(BUFSIZE);
     for (ps = str, pb = escbuf; *ps && pb < escbuf + BUFSIZE - 2; ps++, pb++) {
        if (*ps == '(' || *ps == ')' || *ps == '\\')
          *pb++ = '\\';
@@ -503,8 +497,7 @@ char *str;
 /* all length are in PostScript units (1/72 in)  */
 
 void
-init_ps_print(ipp)
-PrintParameters *ipp;
+init_ps_print(PrintParameters *ipp)
 {
     double in, cm;
     
@@ -564,7 +557,7 @@ static void
 misc_init()
 {
     if (pp->terrain_dither) {
-       terr_gray = GRAY_SCALE*pp->terrain_gray + 0.5;
+       terr_gray = (int)(GRAY_SCALE*pp->terrain_gray + 0.5);
        terr_scale = (pp->terrain_double && terr_gray>0 &&
                      terr_gray<GRAY_SCALE) ? 2 : 1;
     } else {
@@ -601,17 +594,15 @@ misc_init()
     connection_width = pp->connection_width * hex_w/pp->cell_size;
     
     /* rows per page and cells per row */
-    height = (pp->page_height - pp->top_margin - pp->bottom_margin)
-      * 2 / (sqrt3 * pp->cell_size);
-    width  = (pp->page_width - pp->left_margin - pp->right_margin)
-      / pp->cell_size;
+    height = (int)((pp->page_height - pp->top_margin - pp->bottom_margin)
+      * 2 / (sqrt3 * pp->cell_size));
+    width  = (int)((pp->page_width - pp->left_margin - pp->right_margin) / pp->cell_size);
 }
 
 /* Write prolog and macro definitions to view file. */
 
 static void
-ps_initialize(fp)
-FILE *fp;
+ps_initialize(FILE *fp)
 {
     int i;
     Image *img;
@@ -795,10 +786,7 @@ FILE *fp;
 /* Initialize a page. */
 
 static void 
-page_init(fp, page, i, j, stime)
-FILE *fp;
-int page, i, j;
-char *stime;
+page_init(FILE *fp, int page, int i, int j, char *stime)
 {
     int x, xx, y, y0, nx, ny;
     char *gametitle;
@@ -873,8 +861,7 @@ char *stime;
 }
 
 static int
-nearest_valid_x(x, y)
-int x, y;
+nearest_valid_x(int x, int y)
 {
     int xlo, xhi;
 
@@ -888,9 +875,7 @@ int x, y;
 }
 
 static int
-sideno_of_seen_unit_at(x, y, side)
-int x, y;
-Side *side;
+sideno_of_seen_unit_at(int x, int y, Side *side)
 {
    Unit *unit;
    UnitView *uview;
@@ -902,14 +887,12 @@ Side *side;
      return side_number(unit->side);
    uview = unit_view_at(side, x, y);
    if (uview != NULL)
-     return view_side(uview)->id;
+     return uview->siden;
    return indepside->id;
 }
 
 static char *
-name_of_seen_unit_at(x, y, side)
-int x, y;
-Side *side;
+name_of_seen_unit_at(int x, int y, Side *side)
 {
     Unit *unit;
     
@@ -932,12 +915,10 @@ Side *side;
 }
 
 static char *
-summary_of_seen_units_at(x, y, side)
-int x, y;
-Side *side;
+summary_of_seen_units_at(int x, int y, Side *side)
 {
     Unit *mainunit, *other, *occ;
-    int i, nums[MAXUTYPES];
+    int i;
     
     if (!in_area(x, y) || !pp->cell_summary)
       return NULL;
@@ -946,20 +927,20 @@ Side *side;
       return NULL;
     
     for_all_unit_types(i) {
-       nums[i] = 0;
+       tmp_u_array[i] = 0;
     }
     for_all_stack(x, y, other) {
-       nums[other->type]++;
+       tmp_u_array[other->type]++;
        for_all_occupants(other, occ) {
-           nums[occ->type]++;
+           tmp_u_array[occ->type]++;
        }
     }
-    nums[mainunit->type]--;
+    tmp_u_array[mainunit->type]--;
     
     strcpy(buffer, "(+");
     for_all_unit_types(i) {
-       if (nums[i] != 0) {
-           tprintf(buffer, " %d %1s,", nums[i], utype_name_n(i, 1));
+       if (tmp_u_array[i] != 0) {
+           tprintf(buffer, " %d %1s,", tmp_u_array[i], utype_name_n(i, 1));
        }
     }
     i = strlen(buffer);
@@ -977,11 +958,11 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
     int f, nf, tw, th, font, named_unit_max=100, xmin, ymin, xmin1;
     int l, l1, x1, y1, x2, y2, d1, mvalue, nvalue, pad;
     FILE *fp;
-    char stime[42], *name, *summary, tmpbuf[BUFSIZE];
+    char stime[42], *name, *summary, tmppsbuf[BUFSIZE];
     char *name_layer, *name_position;
     time_t tnow;
     Legend *legs = NULL, *lp;
-    double length, magnif;
+    double dlength, magnif;
     
     if (ipp) {
        *pp = *ipp;
@@ -1037,8 +1018,6 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                nx = min(width, area.width - xmin);
                for (xx = xmin; xx < xmin + nx; xx++) {
                    x = xx - (y + 1) / 2 + x0;
-                   x = wrapx(x);
-
                    if ((terrain_seen_at(side, x, y) != NONTTYPE)
                        || (utype_seen_at(side, x, y) != NONUTYPE)) {
                        skip = FALSE;
@@ -1068,9 +1047,6 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                nx = min(width, area.width - xmin);
                nsp = 0;
                for (xx = xmin; xx < xmin + nx; xx++) {
-                   x = xx - (y + 1) / 2 + x0;
-                   x = wrapx(x);
-
                    if ((t = terrain_seen_at(side, x, y)) != NONTTYPE) {
                        if (nsp > 1) {
                            fprintf(fp, "%d msp ", nsp);
@@ -1100,7 +1076,6 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                for (xx = xmin; xx < xmin + nx; xx++) {
                    cx += hex_w;
                    x = xx - (y + 1) / 2 + x0;
-                   x = wrapx(x);
                    if (!in_area(x, y))
                      continue;
 
@@ -1137,7 +1112,6 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                for (xx = xmin; xx < xmin + nx; xx++) {
                    cx += hex_w;
                    x = xx - (y + 1) / 2 + x0;
-                   x = wrapx(x);
                    if (!in_area(x, y))
                      continue;
                    for_all_connection_types(t) {
@@ -1183,8 +1157,8 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                    cy = -hex_h / 2 - hex_c * (area.height - 1 - i * height - lp->oy) +
                      lp->dy * hex_c / 2;
 
-                   length = hex_w * (lp->dist + 1);
-                   magnif = (1000 * length) / ps_string_width(name, 2);
+                   dlength = hex_w * (lp->dist + 1);
+                   magnif = (1000 * dlength) / ps_string_width(name, 2);
 
                    /* tweak these parameters: */
                    magnif *= 0.9;
@@ -1199,12 +1173,12 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                    } else {
                        /* keep magnif near 20 */
                        font = 2;
-                       pad = ps_string_width(name, 2)
+                       pad = (int)(ps_string_width(name, 2)
                          * (magnif / 20.0 - 1.0)
-                           / (strlen(name) * ps_string_width(" ", 2)) + 0.5;
+                           / (strlen(name) * ps_string_width(" ", 2)) + 0.5);
                        name = pad_blanks(name, pad);
                        magnif =
-                         (1000 * length) / ps_string_width(name, 2) * 0.9;
+                         (1000 * dlength) / ps_string_width(name, 2) * 0.9;
                    }
 
                    /* comment containing debugging info */
@@ -1237,8 +1211,8 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                        x = xx - (y + 1) / 2 + x0;
 
                        /* we don't need the string here, so can overwrite */
-                       name = name_of_seen_unit_at(wrapx(x), y, side);
-                       summary = summary_of_seen_units_at(wrapx(x), y, side);
+                       name = name_of_seen_unit_at(x, y, side);
+                       summary = summary_of_seen_units_at(x, y, side);
 
                        if (!name && !summary)
                          continue;
@@ -1256,16 +1230,15 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                        for (l1 = 0; l1 < NUMDIRS; l1++) {
                            d = name_dir[l1];
                            point_in_dir(x, y, d, &x1, &y1);
-                           if ((unit_seen_at(side, wrapx(x1), y1)
+                           if ((unit_seen_at(side, x1, y1)
                                 && on_page(x1 - xmin1, y1 - ymin))
                                || (name_at(x1 - xmin1, y1 - ymin) & N_BK))
                              continue;
                            mvalue = 0;
                            for_all_directions(d1) {
                                point_in_dir(x1, y1, d1, &x2, &y2);
-                               if ((name_of_seen_unit_at(wrapx(x2), y2, side)
-                                    || summary_of_seen_units_at(wrapx(x2),
-                                                                y2, side))
+                               if ((name_of_seen_unit_at(x2, y2, side)
+                                    || summary_of_seen_units_at(x2, y2, side))
                                    && on_page(x2 - xmin1, y2 - ymin))
                                  mvalue++;
                            }
@@ -1281,8 +1254,7 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                            name_at(x1 - xmin1, y1 - ymin) |= N_BK;
                            /* comment containing debugging info */
                            fprintf(fp, "%% found pos for %s in (%d,%d) at (%d,%d), %s\n",
-                                   name_of_seen_unit_at(wrapx(x), y, side), x, y,
-                                   x1, y1, dirnames[d]);
+                                   name_of_seen_unit_at(x, y, side), x, y, x1, y1, dirnames[d]);
                        }
                    }
                }
@@ -1305,13 +1277,13 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                        cx += hex_w;
                        x = xx - (y + 1) / 2 + x0;
 
-                       name = name_of_seen_unit_at(wrapx(x), y, side);
+                       name = name_of_seen_unit_at(x, y, side);
                        /* free buffer */
                        if (name) {
-                           strcpy(tmpbuf,name);
-                           name = tmpbuf;
+                           strcpy(tmppsbuf,name);
+                           name = tmppsbuf;
                        }
-                       summary = summary_of_seen_units_at(wrapx(x), y, side);
+                       summary = summary_of_seen_units_at(x, y, side);
 
                        if (!name && !summary)
                          continue;
@@ -1357,13 +1329,11 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                for (xx = xmin; xx < xmin + nx; xx++) {
                    cx += hex_w;
                    x = xx - (y + 1) / 2 + x0;
-                   x = wrapx(x);
-                   
                    name = name_of_seen_unit_at(x, y, side);
                    /* free buffer */
                    if (name) {
-                       strcpy(tmpbuf,name);
-                       name = tmpbuf;
+                       strcpy(tmppsbuf,name);
+                       name = tmppsbuf;
                    }
                    summary = summary_of_seen_units_at(x, y, side);
                    if (!name)
@@ -1407,7 +1377,6 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
                for (xx = xmin; xx < xmin + nx; xx++) {
                    cx += hex_w;
                    x = xx - (y + 1) / 2 + x0;
-                   x = wrapx(x);
                    if (!in_area(x, y))
                      continue;
        
@@ -1442,9 +1411,7 @@ dump_ps_view(Side *side, PrintParameters *ipp, char *filename)
    "nominal size". */
 
 static int 
-ps_string_width(str, font)
-char *str;
-int font;
+ps_string_width(char *str, int font)
 {
     int ch, i = 0, esc = 0;
     
@@ -1468,10 +1435,7 @@ int font;
 }
 
 static int
-print_unit_legends(fp, name, summary, m, dir, cx, cy)
-FILE *fp;
-char *name, *summary, *m;
-int dir, cx, cy;
+print_unit_legends(FILE *fp, char *name, char *summary, char *m, int dir, int cx, int cy)
 {
     int left, wide_name, wide_summ, down;