This is Unofficial EPICS BASE Doxygen Site
misc.c File Reference
#include <ctype.h>
#include "flexdef.h"
#include <assert.h>
#include <sys/types.h>
+ Include dependency graph for misc.c:

Go to the source code of this file.

Macros

#define isascii(c)   ((c) <= 0177)
 

Functions

void dataflush (void)
 
int otoi (Char[])
 
void action_out (void)
 
void * allocate_array (int size, int element_size)
 
int all_lower (Char *str)
 
int all_upper (Char *str)
 
void bubble (int v[], int n)
 
Char clower (int c)
 
char * copy_string (char *str)
 
Charcopy_unsigned_string (Char *str)
 
void cshell (Char *v, int n, int special_case_0)
 
void dataend (void)
 
void flexerror (char *msg)
 
void flexfatal (char *msg)
 
char * flex_gettime (void)
 
void lerrif (char *msg, int arg)
 
void lerrsf (char *msg, char *arg)
 
int htoi (unsigned char *str)
 
int is_hex_digit (int ch)
 
void line_directive_out (FILE *output_file_name)
 
void mk2data (int value)
 
void mkdata (int value)
 
int myctoi (Char *array)
 
Char myesc (Char *array)
 
int otoi (Char *str)
 
char * readable_form (int c)
 
void * reallocate_array (void *array, int size, int element_size)
 
void skelout (void)
 
void transition_struct_out (int element_v, int element_n)
 

Macro Definition Documentation

#define isascii (   c)    ((c) <= 0177)

Definition at line 43 of file misc.c.

Function Documentation

void action_out ( void  )

Definition at line 62 of file misc.c.

63 {
64  char buf[MAXLINE];
65 
66  while ( fgets( buf, MAXLINE, temp_action_file ) != NULL )
67  if ( buf[0] == '%' && buf[1] == '%' )
68  break;
69  else
70  fputs( buf, stdout );
71  }
#define NULL
Definition: catime.c:38
#define stdout
Definition: epicsStdio.h:30
#define MAXLINE
Definition: flexdef.h:72
FILE * temp_action_file
Definition: flex.c:103
int all_lower ( Char str)

Definition at line 104 of file misc.c.

105 {
106  while ( *str )
107  {
108  if ( ! isascii( (int) *str ) || ! islower( (int) *str ) )
109  return ( 0 );
110  ++str;
111  }
112 
113  return ( 1 );
114  }
#define str(v)
#define isascii(c)
Definition: misc.c:43
int all_upper ( Char str)

Definition at line 125 of file misc.c.

126 {
127  while ( *str )
128  {
129  if ( ! isascii( (int) *str ) || ! isupper( (int) *str ) )
130  return ( 0 );
131  ++str;
132  }
133 
134  return ( 1 );
135  }
#define str(v)
#define isascii(c)
Definition: misc.c:43
void* allocate_array ( int  size,
int  element_size 
)

Definition at line 76 of file misc.c.

77 {
78  void *mem;
79 
80  /* on 16-bit int machines (e.g., 80286) we might be trying to
81  * allocate more than a signed int can hold, and that won't
82  * work. Cheap test:
83  */
84  if ( element_size * size <= 0 )
85  flexfatal( "request for < 1 byte in allocate_array()" );
86 
87  mem = (void *) malloc( (unsigned) (element_size * size) );
88 
89  if ( mem == NULL )
90  flexfatal( "memory allocation failed in allocate_array()" );
91 
92  return ( mem );
93  }
#define NULL
Definition: catime.c:38
void flexfatal(char *msg)
Definition: misc.c:352
void bubble ( int  v[],
int  n 
)

Definition at line 152 of file misc.c.

153 {
154  int i, j, k;
155 
156  for ( i = n; i > 1; --i )
157  for ( j = 1; j < i; ++j )
158  if ( v[j] > v[j + 1] ) /* compare */
159  {
160  k = v[j]; /* exchange */
161  v[j] = v[j + 1];
162  v[j + 1] = k;
163  }
164  }
int i
Definition: scan.c:967
Char clower ( int  c)

Definition at line 175 of file misc.c.

176 {
177  return ( (isascii( c ) && isupper( c )) ? tolower( c ) : c );
178  }
#define isascii(c)
Definition: misc.c:43
char* copy_string ( char *  str)

Definition at line 188 of file misc.c.

189 {
190  char *c;
191  char *copy;
192 
193  /* find length */
194  for ( c = str; *c; ++c )
195  ;
196 
197  copy = malloc( (unsigned) ((c - str + 1) * sizeof( char )) );
198 
199  if ( copy == NULL )
200  flexfatal( "dynamic memory failure in copy_string()" );
201 
202  for ( c = copy; (*c++ = *str++); )
203  ;
204 
205  return ( copy );
206  }
#define NULL
Definition: catime.c:38
void flexfatal(char *msg)
Definition: misc.c:352
#define str(v)
void copy(PVValueArray< T > &pvFrom, size_t fromOffset, size_t fromStride, PVValueArray< T > &pvTo, size_t toOffset, size_t toStride, size_t count)
Copy a subarray from one scalar array to another.
Char* copy_unsigned_string ( Char str)

Definition at line 217 of file misc.c.

218 {
219  Char *c;
220  Char *copy;
221 
222  /* find length */
223  for ( c = str; *c; ++c )
224  ;
225 
226  copy = (Char *) malloc( (unsigned) ((c - str + 1) * sizeof( Char )) );
227 
228  if ( copy == NULL )
229  flexfatal( "dynamic memory failure in copy_unsigned_string()" );
230 
231  for ( c = copy; (*c++ = *str++); )
232  ;
233 
234  return ( copy );
235  }
#define NULL
Definition: catime.c:38
void flexfatal(char *msg)
Definition: misc.c:352
#define str(v)
void copy(PVValueArray< T > &pvFrom, size_t fromOffset, size_t fromStride, PVValueArray< T > &pvTo, size_t toOffset, size_t toStride, size_t count)
Copy a subarray from one scalar array to another.
#define Char
Definition: flexdef.h:59
void cshell ( Char v,
int  n,
int  special_case_0 
)

Definition at line 256 of file misc.c.

257 {
258  int gap, i, j, jg;
259  Char k;
260 
261  for ( gap = n / 2; gap > 0; gap = gap / 2 )
262  for ( i = gap; i < n; ++i )
263  for ( j = i - gap; j >= 0; j = j - gap )
264  {
265  jg = j + gap;
266 
267  if ( special_case_0 )
268  {
269  if ( v[jg] == 0 )
270  break;
271 
272  else if ( v[j] != 0 && v[j] <= v[jg] )
273  break;
274  }
275 
276  else if ( v[j] <= v[jg] )
277  break;
278 
279  k = v[j];
280  v[j] = v[jg];
281  v[jg] = k;
282  }
283  }
int i
Definition: scan.c:967
#define Char
Definition: flexdef.h:59
void dataend ( void  )

Definition at line 292 of file misc.c.

293 {
294  if ( datapos > 0 )
295  dataflush();
296 
297  /* add terminator for initialization */
298  puts( " } ;\n" );
299 
300  dataline = 0;
301  datapos = 0;
302  }
#define puts
Definition: epicsStdio.h:46
int datapos
Definition: flex.c:71
void dataflush(void)
Definition: misc.c:312
int dataline
Definition: flex.c:71
void dataflush ( void  )

Definition at line 312 of file misc.c.

313 {
314  putchar( '\n' );
315 
316  if ( ++dataline >= NUMDATALINES )
317  {
318  /* put out a blank line so that the table is grouped into
319  * large blocks that enable the user to find elements easily
320  */
321  putchar( '\n' );
322  dataline = 0;
323  }
324 
325  /* reset the number of characters written on the current line */
326  datapos = 0;
327  }
#define NUMDATALINES
Definition: flexdef.h:104
#define putchar
Definition: epicsStdio.h:51
int datapos
Definition: flex.c:71
int dataline
Definition: flex.c:71
char* flex_gettime ( void  )

Definition at line 381 of file misc.c.

382 {
383  time_t t, time(time_t *);
384  char *result, *ctime(const time_t *), *copy_string(char *str);
385 
386  t = time( NULL );
387 
388  result = copy_string( ctime( &t ) );
389 
390  /* get rid of trailing newline */
391  result[24] = '\0';
392 
393  return ( result );
394  }
pvac::PutEvent result
Definition: clientSync.cpp:117
#define NULL
Definition: catime.c:38
#define str(v)
char * copy_string(char *str)
Definition: misc.c:188
void flexerror ( char *  msg)

Definition at line 337 of file misc.c.

338 {
339  fprintf( stderr, "%s: %s\n", program_name, msg );
340 
341  flexend( 1 );
342  }
char * program_name
Definition: flex.c:108
void flexend(int status)
Definition: flex.c:196
#define stderr
Definition: epicsStdio.h:32
void flexfatal ( char *  msg)

Definition at line 352 of file misc.c.

353 {
354  fprintf( stderr, "%s: fatal internal error, %s\n", program_name, msg );
355  flexend( 1 );
356  }
char * program_name
Definition: flex.c:108
void flexend(int status)
Definition: flex.c:196
#define stderr
Definition: epicsStdio.h:32
int htoi ( unsigned char *  str)

Definition at line 437 of file misc.c.

438 {
439  int result;
440 
441  (void) sscanf( (char *) str, "%x", &result );
442 
443  return ( result );
444  }
pvac::PutEvent result
Definition: clientSync.cpp:117
#define str(v)
int is_hex_digit ( int  ch)

Definition at line 456 of file misc.c.

457 {
458  if ( isdigit( ch ) )
459  return ( 1 );
460 
461  switch ( clower( ch ) )
462  {
463  case 'a':
464  case 'b':
465  case 'c':
466  case 'd':
467  case 'e':
468  case 'f':
469  return ( 1 );
470 
471  default:
472  return ( 0 );
473  }
474  }
Char clower(int c)
Definition: misc.c:175
void lerrif ( char *  msg,
int  arg 
)

Definition at line 405 of file misc.c.

406 {
407  char errmsg[MAXLINE];
408  (void) sprintf( errmsg, msg, arg );
409  flexerror( errmsg );
410  }
void flexerror(char *msg)
Definition: misc.c:337
#define MAXLINE
Definition: flexdef.h:72
void lerrsf ( char *  msg,
char *  arg 
)

Definition at line 420 of file misc.c.

421 {
422  char errmsg[MAXLINE];
423 
424  (void) sprintf( errmsg, msg, arg );
425  flexerror( errmsg );
426  }
void flexerror(char *msg)
Definition: misc.c:337
#define MAXLINE
Definition: flexdef.h:72
void line_directive_out ( FILE *  output_file_name)

Definition at line 479 of file misc.c.

480 {
481  if ( infilename && gen_line_dirs )
482  fprintf( output_file_name, "# line %d \"%s\"\n", linenum, infilename );
483  }
char * infilename
Definition: flex.c:73
int gen_line_dirs
Definition: flex.c:68
char * output_file_name
Definition: antelope.c:39
void mk2data ( int  value)

Definition at line 494 of file misc.c.

495 {
496  if ( datapos >= NUMDATAITEMS )
497  {
498  putchar( ',' );
499  dataflush();
500  }
501 
502  if ( datapos == 0 )
503  /* indent */
504  fputs( " ", stdout );
505 
506  else
507  putchar( ',' );
508 
509  ++datapos;
510 
511  printf( "%5d", value );
512  }
Definition: link.h:174
#define printf
Definition: epicsStdio.h:41
#define putchar
Definition: epicsStdio.h:51
int datapos
Definition: flex.c:71
#define NUMDATAITEMS
Definition: flexdef.h:99
#define stdout
Definition: epicsStdio.h:30
void dataflush(void)
Definition: misc.c:312
void mkdata ( int  value)

Definition at line 524 of file misc.c.

525 {
526  if ( datapos >= NUMDATAITEMS )
527  {
528  putchar( ',' );
529  dataflush();
530  }
531 
532  if ( datapos == 0 )
533  /* indent */
534  fputs( " ", stdout );
535 
536  else
537  putchar( ',' );
538 
539  ++datapos;
540 
541  printf( "%5d", value );
542  }
Definition: link.h:174
#define printf
Definition: epicsStdio.h:41
#define putchar
Definition: epicsStdio.h:51
int datapos
Definition: flex.c:71
#define NUMDATAITEMS
Definition: flexdef.h:99
#define stdout
Definition: epicsStdio.h:30
void dataflush(void)
Definition: misc.c:312
int myctoi ( Char array)

Definition at line 554 of file misc.c.

555 {
556  int val = 0;
557 
558  (void) sscanf( (char *) array, "%d", &val );
559 
560  return ( val );
561  }
Char myesc ( Char array)

Definition at line 572 of file misc.c.

573 {
574  Char c, esc_char;
575  int sptr;
576 
577  switch ( array[1] )
578  {
579  case 'a': return ( '\a' );
580  case 'b': return ( '\b' );
581  case 'f': return ( '\f' );
582  case 'n': return ( '\n' );
583  case 'r': return ( '\r' );
584  case 't': return ( '\t' );
585  case 'v': return ( '\v' );
586 
587  case '0':
588  case '1':
589  case '2':
590  case '3':
591  case '4':
592  case '5':
593  case '6':
594  case '7':
595  case '8':
596  case '9':
597  { /* <octal> */
598  sptr = 1;
599 
600  while ( isascii( array[sptr] ) && isdigit( array[sptr] ) )
601  /* don't increment inside loop control because if
602  * isdigit() is a macro it might expand into multiple
603  * increments ...
604  */
605  ++sptr;
606 
607  c = array[sptr];
608  array[sptr] = '\0';
609 
610  esc_char = otoi( array + 1 );
611 
612  array[sptr] = c;
613 
614  return ( esc_char );
615  }
616 
617  case 'x':
618  { /* \x<hex> */
619  int sptr = 2;
620 
621  while ( isascii( array[sptr] ) && is_hex_digit( array[sptr] ) )
622  /* don't increment inside loop control because if
623  * isdigit() is a macro it might expand into multiple
624  * increments ...
625  */
626  ++sptr;
627 
628  c = array[sptr];
629  array[sptr] = '\0';
630 
631  esc_char = htoi( array + 2 );
632 
633  array[sptr] = c;
634 
635  return ( esc_char );
636  }
637 
638  default:
639  return ( array[1] );
640  }
641  }
int is_hex_digit(int ch)
Definition: misc.c:456
int htoi(unsigned char *str)
Definition: misc.c:437
#define Char
Definition: flexdef.h:59
int otoi(Char[])
#define isascii(c)
Definition: misc.c:43
int otoi ( Char  [])
int otoi ( Char str)

Definition at line 652 of file misc.c.

653 {
654  int result;
655 
656  (void) sscanf( (char *) str, "%o", &result );
657 
658  return ( result );
659  }
pvac::PutEvent result
Definition: clientSync.cpp:117
#define str(v)
char* readable_form ( int  c)

Definition at line 672 of file misc.c.

673 {
674  static char rform[10];
675 
676  if ( (c >= 0 && c < 32) || c >= 127 )
677  {
678  switch ( c )
679  {
680  case '\n': return ( "\\n" );
681  case '\t': return ( "\\t" );
682  case '\f': return ( "\\f" );
683  case '\r': return ( "\\r" );
684  case '\b': return ( "\\b" );
685 
686  default:
687  (void) sprintf( rform, "\\%.3o", c );
688  return ( rform );
689  }
690  }
691 
692  else if ( c == ' ' )
693  return ( "' '" );
694 
695  else
696  {
697  rform[0] = c;
698  rform[1] = '\0';
699 
700  return ( rform );
701  }
702  }
void* reallocate_array ( void *  array,
int  size,
int  element_size 
)

Definition at line 707 of file misc.c.

708 {
709  void *new_array;
710 
711  /* same worry as in allocate_array(): */
712  if ( size * element_size <= 0 )
713  flexfatal( "attempt to increase array size by less than 1 byte" );
714 
715  new_array =
716  (void *) realloc( (char *)array, (unsigned) (size * element_size ));
717 
718  if ( new_array == NULL )
719  flexfatal( "attempt to increase array size failed" );
720 
721  return ( new_array );
722  }
#define NULL
Definition: catime.c:38
void flexfatal(char *msg)
Definition: misc.c:352
void skelout ( void  )

Definition at line 734 of file misc.c.

735 {
736  char buf[MAXLINE];
737 
738  while ( fgets( buf, MAXLINE, skelfile ) != NULL )
739  if ( buf[0] == '%' && buf[1] == '%' )
740  break;
741  else
742  fputs( buf, stdout );
743  }
#define NULL
Definition: catime.c:38
#define stdout
Definition: epicsStdio.h:30
#define MAXLINE
Definition: flexdef.h:72
FILE * skelfile
Definition: flex.c:72
void transition_struct_out ( int  element_v,
int  element_n 
)

Definition at line 756 of file misc.c.

757 {
758  printf( "%7d, %5d,", element_v, element_n );
759 
761 
762  if ( datapos >= 75 )
763  {
764  putchar( '\n' );
765 
766  if ( ++dataline % 10 == 0 )
767  putchar( '\n' );
768 
769  datapos = 0;
770  }
771  }
#define printf
Definition: epicsStdio.h:41
#define putchar
Definition: epicsStdio.h:51
int datapos
Definition: flex.c:71
#define TRANS_STRUCT_PRINT_LENGTH
Definition: flexdef.h:107
int dataline
Definition: flex.c:71