home *** CD-ROM | disk | FTP | other *** search
- #include "header.h"
- #if PC
- #include <bios.h>
- #endif
- #include "file.h"
-
- /************************************************************************/
- /** miscellaneous functions **/
- /************************************************************************/
- /* this file includes the functions:
- toupper1
- strupper
- alphanumq
- whitespq
- stripwhitesp
- numq
- numstrq
- makespstr
- hitreturn
- togglepr
- */
-
- /********************************/
- /* function: toupper1 */
- /********************************/
- /* replaces brain-damaged toupper of ctype.h:
- if (c >= 'a') and (c <= 'z') then converts to upper
- else returns c as it was. */
- toupper1 (c)
- char c;
- {
- /* decimal 'a' = 97, decimal 'z' = 122, decimal 'A' = 65 */
- if ((c >= 97) && (c <= 122))
- return(c-32);
- else
- return(c);
- } /* toupper1 */
-
- /********************************/
- /* function: strupper */
- /********************************/
- /* converts a string to all upper case, in place */
- strupper (str)
- char *str;
- {
- int i;
-
- for ( i=0; i<strlen(str); i++ )
- str[i] = toupper1(str[i]);
- return(0);
- } /* strupper */
-
- /********************************/
- /* function: alphanumq */
- /********************************/
- /* returns 1 if c is alphabetic/numeric/dash
- returns 0 otherwise
- this is used to check user input for legal cell names */
- alphanumq (c)
- char c;
- {
- if (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) ||
- ((c >= '0') && (c <= '9')) || (c=='-'))
- return(1);
- else
- return(0);
- } /* alphanumq */
-
- /********************************/
- /* function: whitespq */
- /********************************/
- /* returns 1 if c is whitespace (space/tab)
- returns 0 otherwise */
- whitespq (c)
- char c;
- {
- /* c is a char but its integer value works too */
- /* space=32 tab=9 LF=10 CR=13 */
- if ((c==32) || (c==9) || (c==13))
- return(1);
- else
- return(0);
- } /* whitespq */
-
- /********************************/
- /* function: stripwhitesp */
- /********************************/
- /* strips leading and trailing whitespace from a string, in place */
- stripwhitesp (str)
- char *str;
- { int i, j;
-
- #if (DEBUG > 4)
- #if PC
- clrscr1(1);
- gotoxy(8, 5);
- for ( i=0; i<strlen(str); i++ )
- cprintf("<%d>", str[i]);
- hitreturn(1);
- #else
- for ( i=0; i<strlen(str); i++ )
- printf("<%d>", str[i]);
- printf("\n);
- #endif
- #endif
- i = j = 0;
- /* skip leading white space */
- while (whitespq(str[j]))
- j++;
- while (! whitespq(str[j]))
- str[i++] = str[j++];
- str[i] = '\0';
- return(0);
- } /* stripwhitesp */
-
- /********************************/
- /* function: numq */
- /********************************/
- /* returns 1 if c is numeric/point/neg sign
- returns 0 otherwise
- this is used to check user input for legal numeric input */
- numq (c)
- char c;
- {
- if (((c>='0') && (c<='9')) || (c=='-') || (c=='.'))
- return(1);
- else
- return(0);
- } /* numq */
-
- /********************************/
- /* function: numstrq */
- /********************************/
- /* returns 1 if str is a legal floating point number
- (digits, decimal point, negative sign)
- returns 0 otherwise
- this is used to check user input for legal numeric input */
- numstrq (str)
- char *str;
- {
- int i, len, dotflag;
-
- if ((strcmp(str, "q")==0) || (strcmp(str, "Q")==0))
- printexit(13);
- len = strlen(str);
- if (len == 0)
- return(0); /* null input invalid */
- dotflag = 0;
- for ( i=0; i<len; i++ ) {
- if ((str[i]=='-') && (i==0))
- /* do nothing */;
- else
- if ((str[i]=='-') && i)
- return(0); /* neg sign must come 1st, if there is one */
- else {
- if ((str[i]=='.') && dotflag)
- return(0); /* too many decimal points */
- else {
- if ((str[i]=='.') && ! dotflag)
- dotflag = 1;
- else {
- if ((str[i] < '0') || (str[i] > '9'))
- return(0); /* not a decimal digit */
- }
- }
- }
- } /* for */
- return(1); /* get this far, must be an ok number */
- } /* numstrq */
-
- /********************************/
- /* function: makespstr */
- /********************************/
- /* makes a string of len spaces, in str */
- makespstr (str, len)
- char *str;
- int len;
- {
- int i;
-
- for ( i=0; i<len; i++ )
- str[i] = ' ';
- str[i] = '\0';
- return(0);
- } /* makespstr */
-
- /********************************/
- /* function: hitreturn */
- /********************************/
- /* "press any key to continue"... win will be the active window after */
- hitreturn (win)
- int win;
- {
- #if (! PC)
- char c;
- #else
- int key, keylo, keyhi;
- #endif
-
- #if PC
- clrscr1(2);
- cprintf("%sPress any key to continue (F8 still toggles printer):", tab);
- gotoxy(1, 2);
- highvideo();
- cprintf("%s%c%c%c ", tab2, HBAR, HBAR, RTRI);
- normvideo();
- #else
- printf("\n\n\t type <Enter> to continue...");
- #endif
-
- #if PC
- /* just get any one key */
- while (bioskey(1)==0); /* sit & spin */
- key = bioskey(0); /* read key */
- keylo = key & 0x000000FF;
- keyhi = (key & 0x0000FF00) >> 8; /* right shift 8 bits */
- switch (keylo) {
- case 0: /* F key? */
- switch (keyhi) {
- case 66: /* F8 */
- togglepr();
- break;
- default:
- break;
- } /* switch keyhi */
- default:
- break;
- } /* switch */
- if (win)
- makeactivewin(win);
- #else
- while ((c=getc(stdin)) != '\n')
- if (c=='q' || c=='Q')
- printexit(9);
- #endif
- return(0);
- } /* hitreturn */
-
- #if PC
-
- /********************************/
- /* function: togglepr */
- /********************************/
- /* toggles the printer on/off and prints the annunciator */
- togglepr ()
- {
- HARDCOPY = HARDCOPY ^ 1;
- if (! introprint) {
- introprint= 1;
- printintro(0, 0);
- }
- /* no need for this anymore, there isn't a print annunciator anymore
- printHARDCOPY(); */
- return(0);
- } /* togglepr */
-
- #endif
-
- /********************************/
- /* function: free1 */
- /********************************/
- /* checks for NULL ptrs to blocks before freeing */
- void free1 (blk)
- char *blk;
- {
- if (blk == NULL) {
- #if PC
- clrscr1(1);
- gotoxy(1, 5);
- cprintf("%sfree1: Can't free a NULL ptr", tab);
- #else
- printf("\tfree1: Can't free a NULL ptr\n");
- #endif
- printexit(666);
- } else
- free(blk);
- } /* free1 */