home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* Copyright 1988 by Chuck Musciano and Harris Corporation */
- /* */
- /* Permission to use, copy, modify, and distribute this software */
- /* and its documentation for any purpose and without fee is */
- /* hereby granted, provided that the above copyright notice */
- /* appear in all copies and that both that copyright notice and */
- /* this permission notice appear in supporting documentation, and */
- /* that the name of Chuck Musciano and Harris Corporation not be */
- /* used in advertising or publicity pertaining to distribution */
- /* of the software without specific, written prior permission. */
- /* Chuck Musciano and Harris Corporation make no representations */
- /* about the suitability of this software for any purpose. It is */
- /* provided "as is" without express or implied warranty. */
- /************************************************************************/
-
-
- /************************************************************************/
- /* Some miscellaneous support routines */
- /************************************************************************/
-
- #include <stdio.h>
- #include <pwd.h>
-
- #include <suntool/sunview.h>
- #include <suntool/panel.h>
-
- static short cross_bits[] = {0x4000, 0xe000, 0x4000};
- mpr_static(better_button_cross, 3, 3, 1, cross_bits);
-
- extern char *strcpy();
-
- text_width(text, font)
-
- char *text;
- struct pixfont *font;
-
- { int width;
-
- for (width = 0; *text; text++)
- width += font->pf_char[*text].pc_adv.x;
- return(width);
- }
-
- struct pixrect *better_button_image(panel, text, chars, pixels, font)
-
- Panel panel;
- char *text;
- int chars;
- int pixels;
- struct pixfont *font;
-
- { struct pixrect *pr;
- struct pr_prpos pos;
- int width, true_width, height;
-
- if (font == NULL)
- font = (struct pixfont *) window_get(panel, WIN_FONT);
- width = chars * font->pf_char['0'].pc_adv.x + pixels;
- true_width = text_width(text, font);
- if (width < true_width)
- width = true_width;
- pr = mem_create(width + 8, height = font->pf_defaultsize.y + 6, 1);
- pr_rop(pr, 3, 0, width + 2, 2, PIX_SRC | PIX_COLOR(1), NULL, 0, 0);
- pr_rop(pr, 3, height - 2, width + 2, 2, PIX_SRC | PIX_COLOR(1), NULL, 0, 0);
- pr_rop(pr, 0, 3, 2, height - 6, PIX_SRC | PIX_COLOR(1), NULL, 0, 0);
- pr_rop(pr, width + 6, 3, 2, height - 6, PIX_SRC | PIX_COLOR(1), NULL, 0, 0);
- pr_rop(pr, 1, 1, 3, 3, PIX_SRC | PIX_DST, &better_button_cross, 0, 0);
- pr_rop(pr, width + 4, 1, 3, 3, PIX_SRC | PIX_DST, &better_button_cross, 0, 0);
- pr_rop(pr, width + 4, height - 4, 3, 3, PIX_SRC | PIX_DST, &better_button_cross, 0, 0);
- pr_rop(pr, 1, height - 4, 3, 3, PIX_SRC | PIX_DST, &better_button_cross, 0, 0);
- pos.pr = pr;
- pos.pos.x = 4 + (width - true_width) / 2;
- pos.pos.y = 4 - font->pf_char['T'].pc_home.y;
- pf_ttext(pos, PIX_SRC | PIX_COLOR(1), font, text);
- return(pr);
- }
-
- char *user_name()
-
- { struct passwd *pp;
-
- pp = getpwuid(getuid());
- return(pp? pp->pw_name : NULL);
- }
-
- abend(s1, s2, s3, s4, s5, s6, s7, s8)
-
- char *s1, *s2, *s3, *s4, *s5, *s6, *s7, *s8;
-
- {
- fprintf(stderr, s1, s2, s3, s4, s5, s6, s7, s8);
- exit(1);
- }
-
- char *strindex(source, target)
-
- char *source;
- char *target;
-
- { register int len;
-
- len = strlen(target);
- for (; *source; source++)
- if (strncmp(source, target, len) == 0)
- return(source);
- return(0);
- }
-
- verify(source, valid)
-
- char *source;
- char *valid;
-
- { register char *s;
-
- for ( ; *source; source++) {
- for (s = valid; *s && *s != *source; s++)
- ;
- if (*s == '\0')
- return(0);
- }
- return(1);
- }
-
- char **saveargs(argc, argv)
-
- int argc;
- char **argv;
-
- { int i;
- char **copy;
-
- copy = (char **) malloc((argc + 1) * sizeof(char *));
- for (i = 0; i < argc; i++)
- strcpy(copy[i] = (char *) malloc(strlen(argv[i]) + 1), argv[i]);
- copy[i] = (char *) 0;
- return(copy);
- }
-
- static delarg(argc, argv)
-
- int *argc;
- char **argv;
-
- { char *p;
-
- while (*argv = *(argv+1))
- argv++;
- (*argc)--;
- }
-
- char getopt(argc, argv, opts, parm)
-
- int *argc;
- char **argv;
- char *opts;
- char **parm;
-
- { char c, *p, *index();
- int killed;
-
- *parm = NULL;
- while (*argv && ((**argv != '-') || (*(*argv+1) == '\0')))
- argv++;
- if (*argv == NULL)
- return(EOF);
- c = *(*argv+1);
- *++(*argv) = '-';
- if (killed = (*(*argv+1) == '\0'))
- delarg(argc, argv);
- if ((p = index(opts, c)) == NULL)
- c = '\0';
- else if (*(p+1) == ':') {
- *parm = killed ? *argv : *argv+1;
- delarg(argc, argv);
- }
- return(c);
- }
-