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 TERMINATECR(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.26
Date
14.12.16
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 235 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:249

Definition at line 251 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:249

Definition at line 254 of file macros.h.

#define D (   BUG)

Definition at line 576 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 512 of file macros.h.

#define DELETE (   x,
  y,
 
)

Definition at line 284 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 329 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 231 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 228 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 494 of file macros.h.

#define FALSE   0

Definition at line 223 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 564 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:223

Definition at line 444 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 351 of file macros.h.

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

Definition at line 270 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 264 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 244 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 246 of file macros.h.

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

Definition at line 557 of file macros.h.

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

Definition at line 408 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 414 of file macros.h.

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

Definition at line 259 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 399 of file macros.h.

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

Definition at line 239 of file macros.h.

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

Definition at line 240 of file macros.h.

#define NEWLINE   printf("\n")

Definition at line 362 of file macros.h.

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

Definition at line 249 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 474 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 459 of file macros.h.

#define PI   (4.0 * atan(1.0))

Definition at line 215 of file macros.h.

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

Definition at line 250 of file macros.h.

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

Definition at line 589 of file macros.h.

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

Definition at line 227 of file macros.h.

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

Definition at line 555 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 540 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 531 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 382 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 366 of file macros.h.

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

Definition at line 374 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:223
#define TRUE
Definition: macros.h:219

Definition at line 429 of file macros.h.

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

Definition at line 364 of file macros.h.

#define TRUE   1

Definition at line 219 of file macros.h.

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

Definition at line 556 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 390 of file macros.h.