File: intlogs.c

package info (click to toggle)
emoslib 000380%2Bdfsg-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 47,712 kB
  • ctags: 11,551
  • sloc: fortran: 89,643; ansic: 24,200; makefile: 370; sh: 355
file content (95 lines) | stat: -rwxr-xr-x 1,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* Copyright 1981-2007 ECMWF
* 
* Licensed under the GNU Lesser General Public License which
* incorporates the terms and conditions of version 3 of the GNU
* General Public License.
* See LICENSE and gpl-3.0.txt for details.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef CRAY
#include <fortran.h>
#else
#define _fcd char *
#define _fcdtocp(a) a
#define _fcdlen(a) strlen(a)
#endif
 
char *fcd2char();	/* fortran to c string convertion (alloc memory) */

/* defines for FORTRAN subroutine */
#ifndef CRAY
#ifdef FORTRAN_NO_UNDERSCORE
#define INTLOGT intlogt
#else
#define INTLOGT intlogt_
#endif
#endif

/* Pointer to display function */
void (*g_pp_err_fn)(char * buffer) = 0;

void intlogs(void (*pp_error)(char *)) {

  g_pp_err_fn = pp_error;
  return;
}

#define MAXMESSAGE 79

void INTLOGT(char * message, long length) {
char * buffer;
int messageLen;

#ifndef CRAY
  messageLen = (length > MAXMESSAGE) ? MAXMESSAGE : length;
  if( g_pp_err_fn != 0 ) {

    buffer = (char*) malloc(messageLen+1);
    if( buffer == NULL) {
      perror("INTLOGT: malloc error");
      return;
    }

    strncpy(buffer,message,messageLen);
    buffer[messageLen] = '\0';
    {
     char * p;
      p  = buffer + messageLen - 1;
      while(*p == ' ') {
        *p = '\0';
        p--;
      }
    }
    g_pp_err_fn(buffer);
    free(buffer);

  }
#else
char messagebuff[256];
char * fmessage;
char * p;

  if( g_pp_err_fn != 0 ) {

    if( (fmessage = fcd2char(message)) ) {
      p  = fmessage + strlen(fmessage);

      while(*p == ' ') {
        *p = '\0';
        p--;
      }

      g_pp_err_fn(fmessage);
      free(fmessage);
    }
  }

#endif

  return;
}