示例#1
0
dilation(unsigned char **image_pixel,int height,int width)
{
  int i,j;
  unsigned char **tmppixel;


  tmppixel=(unsigned char**)mymalloc2(height,width,sizeof(unsigned char));
  for(j=0;j<height;j++)
    for(i=0;i<width;i++)
      tmppixel[j][i]=image_pixel[j][i];
  for(j=1;j<height-1;j++)
    for(i=1;i<width-1;i++){
      if(tmppixel[j-1][i-1]==LOW  ||
         tmppixel[j-1][i  ]==LOW  ||
         tmppixel[j-1][i+1]==LOW  ||
	 tmppixel[j  ][i-1]==LOW  ||
         tmppixel[j  ][i+1]==LOW  ||
	 tmppixel[j+1][i-1]==LOW  ||
         tmppixel[j+1][i  ]==LOW  ||
         tmppixel[j+1][i+1]==LOW  )

	image_pixel[j][i]=LOW;
    }
  myfree2((void **)tmppixel,height);
}
/* copy a string */
char *mystrdup2(const char *str, const char *src_function, const char *src_file, unsigned int src_line)
{
  char *copy;

  copy = (char *)mymalloc2(strlen(str)+1, 0, src_function, src_file, src_line);
  strcpy(copy, str);
  return copy;
}
/* append a suffix to a string */
char *mystrsuffix(const char *str, const char *suffix)
#endif /* WITHOUT_MEMSAVE */
{
  char *copy;
  size_t max;

  max = strlen(str) + strlen(suffix) + 1;
#ifndef WITHOUT_MEMSAVE
  copy = (char *)mymalloc2(max, 0, src_function, src_file, src_line);
#else /* WITHOUT_MEMSAVE */
  copy = mymalloc(max);
#endif /* WITHOUT_MEMSAVE */
  snprintf(copy, max, "%s%s", str, suffix); /* NOTRANSLATE */
  return copy;
}
/* append a suffix to a string and adding a separation character */
char *mystrjoin(const char *str1, const char *str2, unsigned int delimiter)
#endif /* WITHOUT_MEMSAVE */
{
  char *copy;
  size_t len1;
  size_t max;

  len1 = strlen(str1);
  max = len1 + strlen(str2) + 1;
  if ((delimiter != 0 ) && ((unsigned char)str1[len1] != (unsigned char)delimiter))
    ++max;
#ifndef WITHOUT_MEMSAVE
  copy = (char *)mymalloc2(max, 0, src_function, src_file, src_line);
#else /* WITHOUT_MEMSAVE */
  copy = mymalloc(max);
#endif /* WITHOUT_MEMSAVE */
  if ((delimiter != 0 ) && ((unsigned char)str1[len1 - 1] != (unsigned char)delimiter)) {
    snprintf(copy, max, "%s%c%s", str1, delimiter, str2); /* NOTRANSLATE */
  } else {
    snprintf(copy, max, "%s%s", str1, str2); /* NOTRANSLATE */
  }
  return copy;
}
/* extract one argument from a line */
char *getpart(const char *line, unsigned int howmany)
#endif /* WITHOUT_MEMSAVE */
{
  const char *start;
  const char *src;
  char *dest;
  size_t plen;
  unsigned int inquotes;
  unsigned int part;

  if (line == NULL)
    return NULL;

  if (howmany == 0)
    return NULL;

  inquotes = 0;
  part = 0;

  start = line;
  for (src = start; ; ++src) {
    if ((*src == ' ') && (inquotes != 0))
      continue;
    if (*src == '"') {
      if ((start == src) && (inquotes == 0)) {
        ++inquotes;
        continue;
      }
      if (inquotes == 0)
        continue;
      --inquotes;
      ++start;
    } else {
      if (*src) {
        if (*src != ' ')
          continue;
        if (src == start) {
          /* skip leading spaces */
          ++start;
          continue;
        }
      }
    }
    plen = src - start;
    if (plen == 0)
      continue;

    if (++part < howmany) {
      if (*src == 0)
        return NULL;
      start = src + 1;
      continue;
    }

    /* found end */
    break;
  }
#ifndef WITHOUT_MEMSAVE
  dest = (char *)mymalloc2(plen + 1, 0, src_function, src_file, src_line);
#else /* WITHOUT_MEMSAVE */
  dest = mymalloc(plen + 1);
#endif /* WITHOUT_MEMSAVE */
  memcpy(dest, start, plen);
  dest[plen] = '\0';
  return dest;
}
/* split a line in a number of arguments */
unsigned int get_argv(char **result, const char *line, unsigned int howmany)
#endif /* WITHOUT_MEMSAVE */
{
  const char *start;
  const char *src;
  char *dest;
  size_t plen;
  unsigned int inquotes;
  unsigned int moreargs;
  unsigned int morequote;
  unsigned int part;

  if (howmany == 0)
    return 0;

  if (line == NULL) {
    clean_missing_parts(result, 0, howmany);
    return 0;
  }

  inquotes = 0;
  moreargs = 0;
  morequote = 0;
  part = 0;

  start = line;
  for (src = start; ; ++src) {
    if ((*src == ' ') && (inquotes != 0))
      continue;
    if (*src == '"') {
      if ((start == src) && (inquotes == 0)) {
        ++inquotes;
        continue;
      }
      if (inquotes == 0)
        continue;
      --inquotes;
      if (part + 1 == howmany) {
        ++morequote;
        continue;
      }
      ++start;
    } else {
      if (*src) {
        if (*src != ' ')
          continue;
        if (src == start) {
          /* skip leading spaces */
          ++start;
          continue;
        }
        if (part + 1 == howmany) {
          ++moreargs;
          continue;
        }
      }
    }
    plen = src - start;
    if (plen == 0)
      continue;

    if (*src == '"')
      ++src;

    /* found end */
#ifndef WITHOUT_MEMSAVE
    dest = (char *)mymalloc2(plen + 1, 0, src_function, src_file, src_line);
#else /* WITHOUT_MEMSAVE */
    dest = mymalloc(plen + 1);
#endif /* WITHOUT_MEMSAVE */
    memcpy(dest, start, plen);
    dest[plen] = '\0';
    if ((morequote > 0) && (moreargs == 0))
      clean_quotes(dest);
    result[part++] = dest;
    if (part >= howmany)
      return part;
    if (*src == 0) {
      clean_missing_parts(result, part, howmany);
      return part;
    }
    start = src + 1;
  }
}