/* EXTPROTO */ int ThaiPixel2Col (rxvt_t* r, int page, int x, int y) { int row; /* row storing data */ int i; /* byte offset index */ int xpixel; /* dummy x pixel */ char *str; /* drawn_text pointer */ XFontStruct *wf; /* font */ /* locate buffer storing data */ row = Pixel2Row(y); MAX_IT(row, 0); MIN_IT(row, r->TermWin.nrow - 1); str = PVTS(r, page)->drawn_text[row]; /* access to font structure */ wf = r->TermWin.font; /* increase byte offset until we get to target x */ i = 0; xpixel = FONT_WIDTH(wf, str[0]); x -= r->TermWin.int_bwidth; while (xpixel <= x && i < r->TermWin.ncol){ i++; xpixel += FONT_WIDTH(wf, str[i]); /* wf->per_char[char_num].width; */ } MAX_IT(i, 0); MIN_IT(i, r->TermWin.ncol); return i; }
/** * Built-in default function for displaying help information. * * This is the default "help handler" function. It displays a list of * long and short options along with the description of each. It also * prints out a brief type identifier as produced by * get_option_type_string(). * * @see @link DOXGRP_MEM Memory Management Subsystem @endlink, SPIFOPT_HELPHANDLER_SET(), spifopt_helphandler_t * @ingroup DOXGRP_MEM */ void spifopt_usage(void) { spif_uint16_t i, col, l_long = 0, l_desc = 0; /* Find the longest long option and the longest description. */ for (i = 0; i < SPIFOPT_NUMOPTS_GET(); i++) { MAX_IT(l_long, strlen(SPIFOPT_OPT_LONG(i))); MAX_IT(l_desc, strlen(SPIFOPT_OPT_DESC(i))); } l_long += 2; /* Add 2 for the "--" */ l_desc += 7; /* Add 7 for the type and a space */ printf("%s %s\n", libast_program_name, libast_program_version); printf("Usage:\n\n"); printf("POSIX "); for (col = 0; col < (l_long - 3) / 2; col++) printf(" "); printf("GNU"); for (col = 0; col < (l_long - 3) / 2; col++) printf(" "); if (!(l_long % 2)) { printf(" "); } printf(" "); for (col = 0; col < (l_desc - 11) / 2; col++) printf(" "); printf("Description"); for (col = 0; col < (l_desc - 11) / 2; col++) printf(" "); if (!(l_desc % 2)) { printf(" "); } printf("\n"); printf("----- "); for (col = 0; col < l_long; col++) printf("-"); printf(" "); for (col = 0; col < l_desc; col++) printf("-"); printf("\n"); for (i = 0, l_long -= 2; i < SPIFOPT_NUMOPTS_GET(); i++) { if (SPIFOPT_OPT_SHORT(i)) { printf(" -%c ", SPIFOPT_OPT_SHORT(i)); } else { printf(" "); } printf("--%s", SPIFOPT_OPT_LONG(i)); for (col = strlen((char *) SPIFOPT_OPT_LONG(i)); col < l_long; col++) { printf(" "); } printf(" %-6s %s\n", get_option_type_string(SPIFOPT_OPT_TYPE(i)), SPIFOPT_OPT_DESC(i)); } exit(EXIT_FAILURE); }
/* EXTPROTO */ int rxvt_scale_pixmap(rxvt_t *r, int page, const char *geom) { int flags, changed = 0; int x = 0, y = 0; unsigned int w = 0, h = 0; unsigned int n; char *p, *str; bgPixmap_t *bgpixmap = &(PVTS(r, page)->bg); #define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") if (geom == NULL) return 0; str = rxvt_malloc(MAXLEN_GEOM + 1); if (!STRCMP(geom, "?")) { sprintf(str, "[%dx%d+%d+%d]", /* can't presume snprintf() ! */ min(bgpixmap->w, 9999), min(bgpixmap->h, 9999), min(bgpixmap->x, 9999), min(bgpixmap->y, 9999)); rxvt_xterm_seq(r, page, XTerm_title, str, CHAR_ST); rxvt_free(str); return 0; } if ((p = STRCHR(geom, ';')) == NULL) p = STRCHR(geom, '\0'); n = (p - geom); if (n <= MAXLEN_GEOM) { STRNCPY(str, geom, n); str[n] = '\0'; flags = XParseGeometry(str, &x, &y, &w, &h); if (!flags) { flags |= WidthValue; w = 0; } /* default is tile */ if (flags & WidthValue) { if (!(flags & XValue)) x = 50; if (!(flags & HeightValue)) h = w; if (w && !h) { w = (bgpixmap->w * w) / 100; h = bgpixmap->h; } else if (h && !w) { w = bgpixmap->w; h = (bgpixmap->h * h) / 100; } if (w > 1000) w = 1000; if (h > 1000) h = 1000; if (bgpixmap->w != (short)w) { bgpixmap->w = (short)w; changed++; } if (bgpixmap->h != (short)h) { bgpixmap->h = (short)h; changed++; } } if (!(flags & YValue)) { if (flags & XNegative) flags |= YNegative; y = x; } if (!(flags & WidthValue) && geom[0] != '=') { x += bgpixmap->x; y += bgpixmap->y; } else { if (flags & XNegative) x += 100; if (flags & YNegative) y += 100; } MIN_IT(x, 100); MIN_IT(y, 100); MAX_IT(x, 0); MAX_IT(y, 0); if (bgpixmap->x != x) { bgpixmap->x = x; changed++; } if (bgpixmap->y != y) { bgpixmap->y = y; changed++; } } rxvt_free(str); return changed; }