Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
Macros
macros.h File Reference

Useful macros. More...

#include <ctype.h>

Go to the source code of this file.

Macros

#define PI   (4.0 * atan(1.0))
 
#define TRUE   1
 
#define FALSE   0
 
#define RANGECHECK(x, y, z)   ((x)<(y)) ? (y) : ((x)>(z)) ? (z) : (x)
 
#define DISTSQ(a, b)
 
#define DIST(a, b)
 
#define ABS(x)   (((x)<0) ? (-(x)) : (x))
 
#define MAX(a, b)   (((a)>(b)) ? (a) : (b))
 
#define MIN(a, b)   (((a)<(b)) ? (a) : (b))
 
#define INIT(x, y)
 
#define INITPREV(x, y)
 
#define NEXT(x)   (x)=(x)->next
 
#define PREV(x)   (x)=(x)->prev
 
#define ALLOCNEXT(x, y)
 
#define ALLOCNEXTPREV(x, y)
 
#define LAST(x)   while(((x)!=NULL) && ((x)->next != NULL)) NEXT(x)
 
#define FREELIST(y, z)
 
#define FREE(x)   if((x)!=NULL) free(x); (x) = NULL
 
#define DELETE(x, y, z)
 
#define DELETEDOUBLE(s, x, y)
 
#define FINDPREV(p, s, l)
 
#define NEWLINE   printf("\n")
 
#define TOGGLE(x)   (x) = (x) ? FALSE : TRUE
 
#define TERMINATE(x)
 
#define TERMAT(x, y)
 
#define UPPER(x)
 
#define LOWER(x)
 
#define KILLLEADSPACES(y, x)
 
#define KILLTRAILSPACES(x)
 
#define TESTINARRAY(x, l, y, r)
 
#define FINDINARRAY(x, l, y, r)
 
#define PADMINTERM(string, len)
 
#define PADCHARMINTERM(s, c, l)
 
#define DOTIFY(str)
 
#define DEDOTIFY(str)
 
#define SUBSCHAR(s, x, y)
 
#define STRNCPYNOSPACES(out, in, mx)
 
#define SET(x, y)   (x) |= (y)
 
#define UNSET(x, y)   (x) &= (~(y))
 
#define ISSET(x, y)   ((BOOL)((x)&(y)))
 
#define FCLOSE(x)
 
#define D(BUG)
 
#define PROMPT(in, x)   printf("%s",(x))
 

Detailed Description

Useful macros.

Version
V2.25
Date
04.11.15
Author
Dr. Andrew C. R. Martin
Institute of Structural & Molecular Biology, University College London, Gower Street, London. WC1E 6BT.
andre.nosp@m.w@bi.nosp@m.oinf..nosp@m.org..nosp@m.uk andre.nosp@m.w.ma.nosp@m.rtin@.nosp@m.ucl..nosp@m.ac.uk

This code is NOT IN THE PUBLIC DOMAIN, but it may be copied according to the conditions laid out in the accompanying file COPYING.DOC.

The code may be modified as required, but any modifications must be documented so that the person responsible can be identified.

The code may not be sold commercially or included as part of a commercial product except as described in the file COPYING.DOC.

Description:

If not Amiga defines abs(). Defines max(), min() and PI if not done. Defines list handling macros. Defines newline() and toggle() macros.

Usage:

Revision History:

Definition in file macros.h.

Macro Definition Documentation

#define ABS (   x)    (((x)<0) ? (-(x)) : (x))

Definition at line 232 of file macros.h.

#define ALLOCNEXT (   x,
 
)
Value:
do { (x)->next=(y *)malloc(sizeof(y));\
if((x)->next != NULL) { (x)->next->next=NULL; }\
NEXT(x); } while(0)
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99
#define NEXT(x)
Definition: macros.h:246

Definition at line 248 of file macros.h.

#define ALLOCNEXTPREV (   x,
 
)
Value:
do { (x)->next=(y *)malloc(sizeof(y));\
if((x)->next != NULL)\
{ (x)->next->prev = (x); \
(x)->next->next=NULL; }\
NEXT(x);} while(0)
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99
struct _memlist * prev
Definition: safemem.c:115
#define NEXT(x)
Definition: macros.h:246

Definition at line 251 of file macros.h.

#define D (   BUG)

Definition at line 565 of file macros.h.

#define DEDOTIFY (   str)
Value:
do { \
char *_dedotify_macro_chp; \
_dedotify_macro_chp = str; \
while(*_dedotify_macro_chp) { \
if(*_dedotify_macro_chp=='.') *_dedotify_macro_chp = ' '; \
_dedotify_macro_chp++; \
} } while(0)

Macro to replace '.' in a string with ' '

  • 21.04.99 Original By: ACRM

Definition at line 501 of file macros.h.

#define DELETE (   x,
  y,
 
)

Definition at line 281 of file macros.h.

#define DELETEDOUBLE (   s,
  x,
 
)
Value:
do { y *_deleteandnext_macro_temp; \
if(((s)!=NULL) && ((x)!=NULL)) \
{ if((x)==(s)) (s) = (x)->next; \
_deleteandnext_macro_temp = (x)->next; \
if((x)->prev != NULL) (x)->prev->next = (x)->next; \
if((x)->next != NULL) (x)->next->prev = (x)->prev; \
free(x); \
(x) = _deleteandnext_macro_temp; \
} } while(0)
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99
struct _memlist * prev
Definition: safemem.c:115

Definition at line 326 of file macros.h.

#define DIST (   a,
 
)
Value:
sqrt(((a)->x - (b)->x) * ((a)->x - (b)->x) + \
((a)->y - (b)->y) * ((a)->y - (b)->y) + \
((a)->z - (b)->z) * ((a)->z - (b)->z))

Definition at line 228 of file macros.h.

#define DISTSQ (   a,
 
)
Value:
(((a)->x - (b)->x) * ((a)->x - (b)->x) + \
((a)->y - (b)->y) * ((a)->y - (b)->y) + \
((a)->z - (b)->z) * ((a)->z - (b)->z))

Definition at line 225 of file macros.h.

#define DOTIFY (   str)
Value:
do { \
char *_dotify_macro_chp; \
_dotify_macro_chp = str; \
while(*_dotify_macro_chp) { \
if(*_dotify_macro_chp==' ') *_dotify_macro_chp = '.'; \
_dotify_macro_chp++; \
} } while(0)

Macro to replace ' ' in a string with '.'

  • 21.04.99 Original By: ACRM

Definition at line 483 of file macros.h.

#define FALSE   0

Definition at line 220 of file macros.h.

#define FCLOSE (   x)
Value:
do { \
if(((x) != NULL) && ((x) != stdin) && \
((x) != stdout) && ((x) != stderr)) { \
fclose((x)); \
(x) = NULL; \
} \
} while (0)
#define NULL
Definition: array2.c:99

Definition at line 553 of file macros.h.

#define FINDINARRAY (   x,
  l,
  y,
 
)
Value:
do { \
int _inarray_macro_i; \
(r) = (-1); \
if((x)==NULL) break; \
for(_inarray_macro_i=0; _inarray_macro_i<(l); _inarray_macro_i++) \
{ if((x)[_inarray_macro_i] == (y)) \
{ (r) = _inarray_macro_i; \
break; \
} } } while(FALSE)
#define NULL
Definition: array2.c:99
#define FALSE
Definition: macros.h:220

Definition at line 433 of file macros.h.

#define FINDPREV (   p,
  s,
 
)
Value:
do { p = (s); \
if((s)==(l)) \
{ p = NULL; } else \
{ \
while((p != NULL) && (p->next != (l))) \
{ p = p->next; \
} } } while(0)
#define NULL
Definition: array2.c:99

Definition at line 348 of file macros.h.

#define FREE (   x)    if((x)!=NULL) free(x); (x) = NULL

Definition at line 267 of file macros.h.

#define FREELIST (   y,
 
)
Value:
while((y)!=NULL) \
{ z *_freelist_macro_q; \
_freelist_macro_q = (y)->next; \
free((char *)(y)); \
(y) = _freelist_macro_q; \
}
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99

Definition at line 261 of file macros.h.

#define INIT (   x,
 
)
Value:
do { x=(y *)malloc(sizeof(y)); \
if(x != NULL) x->next = NULL; } while(0)
struct _memlist * next
Definition: safemem.c:115
#define NULL
Definition: array2.c:99

Definition at line 241 of file macros.h.

#define INITPREV (   x,
 
)
Value:
do { x=(y *)malloc(sizeof(y));\
if(x != NULL) {x->next=NULL; x->prev=NULL;} } \
while(0)
#define NULL
Definition: array2.c:99

Definition at line 243 of file macros.h.

#define ISSET (   x,
 
)    ((BOOL)((x)&(y)))

Definition at line 546 of file macros.h.

#define KILLLEADSPACES (   y,
 
)
Value:
do \
{ for((y)=(x); *(y) == ' ' || *(y) == '\t'; (y)++) ; } \
while(0)

Definition at line 397 of file macros.h.

#define KILLTRAILSPACES (   x)
Value:
do { int _kts_macro_i; \
_kts_macro_i = strlen(x) - 1; \
while(((x)[_kts_macro_i] == ' ' || \
(x)[_kts_macro_i] == '\t') && \
_kts_macro_i>=0) \
(_kts_macro_i)--; \
(x)[++(_kts_macro_i)] = '\0'; \
} while(0)

Definition at line 403 of file macros.h.

#define LAST (   x)    while(((x)!=NULL) && ((x)->next != NULL)) NEXT(x)

Definition at line 256 of file macros.h.

#define LOWER (   x)
Value:
do { int _lower_macro_i; \
for(_lower_macro_i=0; \
_lower_macro_i<(int)strlen(x) && \
(x)[_lower_macro_i]; \
_lower_macro_i++) \
if(isupper((x)[_lower_macro_i])) \
(x)[_lower_macro_i] = \
(char)tolower((x)[_lower_macro_i]); \
} while(0)

Definition at line 388 of file macros.h.

#define MAX (   a,
 
)    (((a)>(b)) ? (a) : (b))

Definition at line 236 of file macros.h.

#define MIN (   a,
 
)    (((a)<(b)) ? (a) : (b))

Definition at line 237 of file macros.h.

#define NEWLINE   printf("\n")

Definition at line 359 of file macros.h.

#define NEXT (   x)    (x)=(x)->next

Definition at line 246 of file macros.h.

#define PADCHARMINTERM (   s,
  c,
 
)
Value:
do { int _padminterm_macro_i; \
if(strlen((s)) < (l)) \
{ for(_padminterm_macro_i=strlen((s)); \
_padminterm_macro_i<(l); \
_padminterm_macro_i++) \
(s)[_padminterm_macro_i] = (c); \
(s)[(l)] = '\0'; \
} } while(0)

Pads a string to a specified length using char and terminates at that point

  • 13.03.99 Original By: ACRM

Definition at line 463 of file macros.h.

#define PADMINTERM (   string,
  len 
)
Value:
do { \
if(strlen((string)) < (len)) blPadterm((string), (len)); \
} while(0)
void blPadterm(char *string, int length)
Definition: padterm.c:117

Definition at line 448 of file macros.h.

#define PI   (4.0 * atan(1.0))

Definition at line 212 of file macros.h.

#define PREV (   x)    (x)=(x)->prev

Definition at line 247 of file macros.h.

#define PROMPT (   in,
 
)    printf("%s",(x))

Definition at line 578 of file macros.h.

#define RANGECHECK (   x,
  y,
 
)    ((x)<(y)) ? (y) : ((x)>(z)) ? (z) : (x)

Definition at line 224 of file macros.h.

#define SET (   x,
 
)    (x) |= (y)

Definition at line 544 of file macros.h.

#define STRNCPYNOSPACES (   out,
  in,
  mx 
)
Value:
do { char *_chp; \
int _pos = 0; \
for(_chp=(in); *_chp != '\0'; _chp++) \
{ if(*_chp != ' ') \
{ buffer[_pos++] = *_chp; \
if(_pos >= (mx)) break; \
} } \
if(_pos < (mx)) buffer[_pos] = '\0'; \
} while(0)

Definition at line 529 of file macros.h.

#define SUBSCHAR (   s,
  x,
 
)
Value:
do { char *_subschar_macro_ch = (s); \
while(*_subschar_macro_ch != '\0') \
{ if(*_subschar_macro_ch == (x)) *_subschar_macro_ch = (y); \
_subschar_macro_ch++; \
} } while(0)

Substitute character x by character y in string s

  • 21.05.99 Original

Definition at line 520 of file macros.h.

#define TERMAT (   x,
 
)
Value:
do { int _termat_macro_j; \
for(_termat_macro_j=0; \
(x)[_termat_macro_j]; \
_termat_macro_j++) \
{ if((x)[_termat_macro_j] == (y)) \
{ (x)[_termat_macro_j] = '\0'; \
break; \
} } } while(0)

Definition at line 371 of file macros.h.

#define TERMINATE (   x)
Value:
do { int _terminate_macro_j; \
for(_terminate_macro_j=0; \
(x)[_terminate_macro_j]; \
_terminate_macro_j++) \
{ if((x)[_terminate_macro_j] == '\n') \
{ (x)[_terminate_macro_j] = '\0'; \
break; \
} } } while(0)

Definition at line 363 of file macros.h.

#define TESTINARRAY (   x,
  l,
  y,
 
)
Value:
do { \
int _inarray_macro_i; \
(r) = FALSE; \
if((x)==NULL) break; \
for(_inarray_macro_i=0; _inarray_macro_i<(l); _inarray_macro_i++) \
{ if((x)[_inarray_macro_i] == (y)) \
{ (r) = TRUE; \
break; \
} } } while(FALSE)
#define NULL
Definition: array2.c:99
#define FALSE
Definition: macros.h:220
#define TRUE
Definition: macros.h:216

Definition at line 418 of file macros.h.

#define TOGGLE (   x)    (x) = (x) ? FALSE : TRUE

Definition at line 361 of file macros.h.

#define TRUE   1

Definition at line 216 of file macros.h.

#define UNSET (   x,
 
)    (x) &= (~(y))

Definition at line 545 of file macros.h.

#define UPPER (   x)
Value:
do { int _upper_macro_i; \
for(_upper_macro_i=0; \
_upper_macro_i<(int)strlen(x) && \
(x)[_upper_macro_i]; \
_upper_macro_i++) \
if(islower((x)[_upper_macro_i])) \
(x)[_upper_macro_i] = \
(char)toupper((x)[_upper_macro_i]); \
} while(0)

Definition at line 379 of file macros.h.