home *** CD-ROM | disk | FTP | other *** search
- /* > $.CLIB.C.general
- *
- * HASWIN Graphics Library
- * =========================
- *
- * Copyright (C) H.A.Shaw 1990.
- * Howard A. Shaw.
- * The Unit for Space Sciences,
- * Room 165,
- * Physics Building,
- * University of Kent at Canterbury.
- * Canterbury.
- * Kent. CT2 7NJ
- * You may use and distribute this code freely, however please leave
- * it alone. If you find bugs (and there will be many) please contact
- * me and the master source can be modified. If you keep me informed
- * of who you give copies of this to then I can get release upgrades
- * to them.
- *
- * general routines to do things at global levels.
- */
- #include "includes.h"
-
- /*
- * scan string 'str' and put '\0' at first non printable.
- * returns length.
- */
- int asciilen(char *str) {
-
- register int i = 0;
-
- if (!str)
- return(0);
- while (*str >= ' ') {
- i++; str++;
- }
- *str = '\0';
- return(i);
- }
-
- /*
- * do the same as strncpy, but don't copy single quotes
- */
- void strnqcpy(char *str1, char *str2, int max) {
-
- while ((*str2) && (max > 0)) {
- if (*str2 == '\'')
- str2++;
- else
- *(str1++) = *(str2++);
- max--;
- }
- *str1 = '\0';
- }
-
- /*
- * do the same as strcpy, but don't copy single quotes
- */
- void strqcpy(char *str1, char *str2) {
-
- while (*str2) {
- if (*str2 == '\'')
- str2++;
- else
- *(str1++) = *(str2++);
- }
- *str1 = '\0';
- }
-
- /*
- * turn a string into a number. The string is of the following form:
- * <spaces...>0-9* - decimal
- * <spaces...>0[xX]0-9* - hexadecimal
- * <spaces...>O0-9* - octal
- */
- int atoint(char *str) {
-
- int state, value;
-
- value = state = 0;
- while (*str == ' ')
- str++;
- while (*str > ' ') {
- switch (state) {
- case 0: /* starting state */
- if ((*str >= '1') && (*str <= '9')) {
- state = 3;
- value = *str - '0';
- break;
- }
- if (*str == '0') {
- state = 1;
- break;
- }
- if (*str == 'O') {
- state = 2;
- break;
- }
- return(0);
- case 1: /* if first character is '0' */
- if ((*str >= '0') && (*str <= '9')) {
- state = 3;
- value = *str - '0';
- break;
- }
- if ((*str == 'x') || (*str == 'X')) {
- state = 4;
- break;
- }
- return(0);
- case 2: /* octal number state */
- if ((*str >= '0') && (*str <= '7')) {
- value = value*8 + (*str - '0');
- break;
- }
- return(value);
- case 3: /* decimal number state */
- if ((*str >= '0') && (*str <= '9')) {
- value = value*10 + (*str - '0');
- break;
- }
- return(value);
- case 4: /* hexadecimal number state */
- if ((*str >= '0') && (*str <= '9')) {
- value = value*16 + (*str - '0');
- break;
- }
- if ((*str >= 'a') && (*str <= 'f')) {
- value = value*16 + 10 + (*str - 'a');
- break;
- }
- if ((*str >= 'A') && (*str <= 'F')) {
- value = value*16 + 10 + (*str - 'A');
- break;
- }
- return(value);
- }
- str++;
- }
- return(value);
- }
-
- int haswin_getversion() {
- if (!(haswin_flags & HASWIN_FLAGS_STARTED))
- return(HASWIN_UNKNOWN);
- return(haswin_version);
- }
-
- int haswin_getflags() {
- return(haswin_flags);
- }
-
- int haswin_setflags(int new) {
-
- haswin_flags |= (new & HASWIN_INIT_USERFLAGS);
- return(haswin_flags);
- }
-
- int haswin_clearflags(int new) {
-
- haswin_flags &= ~(new & HASWIN_INIT_USERFLAGS);
- return(haswin_flags);
- }
-
- /*
- * initialise the window managment system.
- */
- int haswin_initialise(char *name, int flags, int mem) {
-
- _kernel_swi_regs regs;
-
- /* initialise internal list pointers */
- haswin_baricons = (icon *)0;
- haswin_topwindow = (window *)0;
- memset((char *)&haswin_menu, 0, sizeof(menu));
- /*
- * find out about the memory limits and regions.
- */
- if (mem > 0)
- regs.r[0] = mem;
- else
- regs.r[0] = -1;
- regs.r[1] = -1;
- if (!haswin_swi(HASWIN_Slot_size, ®s))
- return(HASWIN_FALSE);
- /* get the virtual address of the byte past the top of the program, the
- time of program start, and the command line string */
- haswin_swi(OS_GetEnv, ®s);
- haswin_commline = (char *)(regs.r[0]);
- haswin_programtop = haswin_getthisslotsize();
- haswin_starttime = (int *)(regs.r[2]);
- /* initialise the malloc()/free() system */
- if (!haswin_initmemorymanager())
- return(HASWIN_FALSE);
- /* start the WIMP and the HASWIN task manager */
- if (!haswin_taskinitialise(name))
- return(HASWIN_FALSE);
- haswin_flags |= HASWIN_FLAGS_STARTED | (flags&HASWIN_INIT_USERFLAGS);
- /* initialise the VDU variables */
- haswin_updateallvduvariables(0);
- /* initialise window saving into sprites */
- haswin_windowtosprite(0, 0, 0);
- /* get the error system going */
- if (!haswin_initerrorhandlers())
- return(HASWIN_FALSE);
- /* get the HASWIN sprites */
- haswin_addhaswinsprites(HASWIN_SPRITEFILE);
- /* initialise the pointer stack */
- if (!haswin_initpointerinfo())
- return(HASWIN_FALSE);
- return(haswin_version);
- }
-
- /*
- * this returns the last state of the hourglass, so it can be restored
- */
- int haswin_hourglass(int onoff) {
-
- static int hourglass = 0;
- int tmp;
- _kernel_swi_regs regs;
-
- if (onoff > 1)
- onoff = 1;
- else if (onoff < 0)
- onoff = 0;
- switch (onoff) {
- case 1: haswin_swi(HASWIN_Hourglass_on, ®s);
- break;
- case 0: haswin_swi(HASWIN_Hourglass_off, ®s);
- break;
- }
- tmp = hourglass;
- hourglass = onoff;
- return(tmp);
- }
-
- char *haswin_getcommandline(void) {
- return(haswin_commline);
- }
-
- int *haswin_getstarttime(void) {
- return(haswin_starttime);
- }
-
- /*
- * create a standard information window. We do the following to
- * find a window.
- * 1) if a window called "information" is available use it.
- * 2) if "information" can be found in the currently open
- * template file use it.
- * 3) if "information" can be found in HASWINs own template file
- * use it.
- * We then setup icons 0-3 to be name, purpose, author and version of
- * the program.
- */
- int haswin_setinfowindow(char *name, char *purpose, char *author, char *version) {
- window *win;
- icon *ic;
- int oldflags;
-
- if ((win=haswin_findwindowname("information")) == 0) {
- oldflags = haswin_flags & HASWIN_FLAGS_VERBOSE;
- haswin_flags &= ~HASWIN_FLAGS_VERBOSE;
- if ((win=haswin_loadwindow("information", 0)) == 0) {
- haswin_pushtemplate(HASWIN_TEMPLATEFILE);
- if ((win=haswin_loadwindow("information", 0)) == 0) {
- haswin_poptemplate();
- haswin_flags |= oldflags;
- return(HASWIN_FALSE);
- }
- haswin_poptemplate();
- }
- haswin_flags |= oldflags;
- }
- if (name) {
- if ((ic=haswin_findiconhandle(win, 0)) != 0)
- haswin_seticondata(ic, name);
- }
- if (purpose) {
- if ((ic=haswin_findiconhandle(win, 1)) != 0)
- haswin_seticondata(ic, purpose);
- }
- if (author) {
- if ((ic=haswin_findiconhandle(win, 2)) != 0)
- haswin_seticondata(ic, author);
- }
- if (version) {
- if ((ic=haswin_findiconhandle(win, 3)) != 0)
- haswin_seticondata(ic, version);
- }
- haswin_flags |= HASWIN_FLAGS_INFOWIN;
- return(HASWIN_TRUE);
- }
-
-