/* fitsmisc.c *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% * * Part of: The LDAC Tools * * Author: E.BERTIN, DeNIS/LDAC * * Contents: miscellaneous functions. * * Last modify: 23/01/97 * *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ #include #include #include #include #include "fitscat_defs.h" #include "fitscat.h" /****** wstrncmp *************************************************************** PROTO int wstrncmp(char *cs, char *ct, int n) PURPOSE simple wildcard strcmp. INPUT character string 1, character string 2, maximum number of characters to be compared. OUTPUT comparison integer (same meaning as strcmp). NOTES -. AUTHOR E. Bertin (IAP & Leiden observatory) VERSION 15/02/96 ***/ int wstrncmp(char *cs, char *ct, int n) { int diff,i; i = n; diff = 0; do { diff = ((*cs=='?'&&*ct)||(*ct=='?'&&*cs))?0:*cs-*ct; } while (!diff && --i && *(cs++) && *(ct++)); return diff; } /****** findkey **************************************************************** PROTO int findkey(char *str, char *key, int size) PURPOSE Find an item within a list of keywords. INPUT character string, an array of character strings containing the list of keywords, offset (in char) between each keyword. OUTPUT position in the list (0 = first) if keyword matched, RETURN_ERROR otherwise. NOTES the matching is case-sensitive. AUTHOR E. Bertin (IAP & Leiden observatory) VERSION 15/02/96 ***/ int findkey(char *str, char *key, int size) { int i; for (i=0; key[0]; i++, key += size) if (!strcmp(str, key)) return i; return RETURN_ERROR; } /********************************* findnkey ********************************** PROTO int findnkey(char *str, char *key, int size, int nkey) PURPOSE Find an item within a list of nkey keywords. INPUT character string, an array of character strings containing the list of keywords, offset (in char) between each keyword. number of keywords. OUTPUT position in the list (0 = first) if keyword matched, RETURN_ERROR otherwise. NOTES the matching is case-sensitive. AUTHOR E. Bertin (IAP & Leiden observatory) VERSION 15/02/96 ***/ int findnkey(char *str, char *key, int size, int nkey) { int i; for (i=0; i