Back to index

im-sdk  12.3.91
Defines | Functions
IIIMPClientDispatcher3.cpp File Reference
#include "FrameMgr.h"
#include "IIIMPClient.hh"
#include "IMProtoHandler.hh"
#include "IIIMPInputContext.hh"
#include "ICAttribute.hh"
#include "IIIMProtocol.hh"
#include "IMProtocolStructP.hh"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

Defines

#define TMPUNIT   1024
#define BUFSIZE   1024
#define PATHNAME_MAX   1024
#define Token   " \n\r\t,\"'"

Functions

char * read_object (char *, int *)
char * read_ccdef (char *, char *, int *)
static int get_path (char *, char *)
static FILE * openfile (char *, char *)

Define Documentation

#define BUFSIZE   1024

Definition at line 110 of file IIIMPClientDispatcher3.cpp.

#define PATHNAME_MAX   1024

Definition at line 115 of file IIIMPClientDispatcher3.cpp.

#define TMPUNIT   1024

Definition at line 109 of file IIIMPClientDispatcher3.cpp.

#define Token   " \n\r\t,\"'"

Definition at line 204 of file IIIMPClientDispatcher3.cpp.


Function Documentation

static int get_path ( char *  p,
char *  path 
) [static]

Definition at line 207 of file IIIMPClientDispatcher3.cpp.

{
  char tmp[BUFSIZE];
  char *k;

  strcpy(tmp, p);
  k = strtok(tmp, Token);
  if (k != NULL) {
    if (strncmp(k, "include", 7) == 0) {
      k = strtok(NULL, Token);
      if (k != NULL) {
       strcpy(path, k);
      }
      k = strtok(NULL, Token);
      if (k != NULL) {
       return 0;
      } else {
       return 1;
      }
    }
  }
  return 0;
}

Here is the caller graph for this function:

static FILE * openfile ( char *  basepath,
char *  incfile 
) [static]

Definition at line 235 of file IIIMPClientDispatcher3.cpp.

{
  char path[PATHNAME_MAX];
#ifdef WIN32
  if (incfile[0] == '\\') {
#else
    if (incfile[0] == '/') {
#endif
      sprintf(path, "%s", incfile);
    } else {
#ifdef WIN32
      sprintf(path, "%s\\%s", basepath, incfile);
#else
      sprintf(path, "%s/%s", basepath, incfile);
#endif
    }
    return fopen(path, "r");
}

Here is the caller graph for this function:

char * read_ccdef ( char *  path,
char *  basepath,
int *  length 
)

Definition at line 119 of file IIIMPClientDispatcher3.cpp.

{
  FILE *fp;
  int ret;
  struct stat s_buf;
  char *tmp;
  char line[PATHNAME_MAX];
  char incfile[PATHNAME_MAX];
  int m = 1;

  if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD)) {
    return 0;
  }

  tmp = (char *) malloc(sizeof(char) * TMPUNIT);
  strcpy(tmp, "");

  if ((fp = fopen(path, "rb")) == NULL) {
    return 0;
  }
  while (fgets((char *) line, 256, fp) != NULL) {
    if (strlen(line) <= 1) {
      continue;
    }
    if (strncmp(line, "#", 1) == 0) {
      continue;
    }
    if (strstr(line, "include")) {
      if (get_path(line, &incfile[0])) {
       FILE *fp2 = openfile(basepath, incfile);
       if (fp2 == NULL) {
#ifdef DEBUG
         printf("can't open incfile=%s\n", incfile);
#endif
         continue;
       } else {
         while (fgets((char *) line, 256, fp2) != NULL) {
           if (strlen(line) <= 1) {
             continue;
           }
           if (strncmp(line, "#", 1) == 0) {
             continue;
           }
           if (strlen(tmp) + strlen(line) >= TMPUNIT * m) {
             tmp = (char *) realloc((void *) tmp,
                                 sizeof(char) * TMPUNIT * (++m));
           }
           strcat(tmp, line);
#ifdef DEBUG
           printf("line=[%s]\n", line);
#endif
         }
         fclose(fp2);
       }
      } else {
       if (strlen(tmp) + strlen(line) >= TMPUNIT * m) {
         tmp = (char *) realloc((void *) tmp,
                             sizeof(char) * TMPUNIT * (++m));
       }
       strcat(tmp, line);
#ifdef DEBUG
       printf("line=[%s]\n", line);
#endif
      }
    } else {
      if (strlen(tmp) + strlen(line) >= TMPUNIT * m) {
       tmp = (char *) realloc((void *) tmp,
                            sizeof(char) * TMPUNIT * (++m));
      }
      strcat(tmp, line);
#ifdef DEBUG
      printf("line=[%s]\n", line);
#endif
    }
  }
  fclose(fp);

  *length = strlen(tmp);
  return tmp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char * read_object ( char *  path,
int *  length 
)

Definition at line 66 of file IIIMPClientDispatcher3.cpp.

{
  FILE *fd;
  int ret;
  struct stat s_buf;
  char *contents;
  *length = 0;

  if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD)) {
    perror("");
    return 0;
  }
  contents = new char[s_buf.st_size + 1];

  if ((fd = fopen(path, "rb")) == NULL) {
    perror("");
    return 0;
  }
  ret = fread(contents, s_buf.st_size, 1, fd);

  /*
   * if (ret != s_buf.st_size) { printf("size error %d != %d\n",
   * ret, s_buf.st_size); return 0; }
   */
  *length = s_buf.st_size;

#ifdef DEBUG
  for (int i = 0; i < *length; i++) {
    printf("%x\n", contents[i]);
  }
#endif

  fclose(fd);

  return contents;
}

Here is the caller graph for this function: