示例#1
0
ClientOpt *login(char *user_name) {
	
	FILE *network_config;
	char *server_ip, *server_port, *client_port;
	if((network_config = fopen("network.config", "r")) == NULL) {
		printf("can not open network.config file");
		return NULL;
	}
	else {
		server_ip = fgetstr(network_config);
		server_port = fgetstr(network_config);
		client_port = fgetstr(network_config);
	}

	printf("server_ip:%s, server_port:%s, client_port:%s", server_ip, server_port, client_port);

	ClientOpt *copt = (ClientOpt *)calloc(1, sizeof(ClientOpt));
	copt->buffer_len = 1024;
	copt->remote_port = atoi(server_port);
	strcpy(copt->server_name, server_ip);
	copt->SocketProc = receivePackage;
	copt->user_name = user_name;
	copt->local_port = client_port;


	HANDLE * h = StartClient(copt);

	Login(copt);

	return copt;
}
示例#2
0
static int
help_getnext(int fd, char **topic, char **subtopic, char **desc) 
{
    char	line[81], *cp, *ep;
    
    for (;;) {
	if (fgetstr(line, 80, fd) < 0)
	    return(0);
	
	if ((strlen(line) < 3) || (line[0] != '#') || (line[1] != ' '))
	    continue;

	*topic = *subtopic = *desc = NULL;
	cp = line + 2;
	while((cp != NULL) && (*cp != 0)) {
	    ep = strchr(cp, ' ');
	    if ((*cp == 'T') && (*topic == NULL)) {
		if (ep != NULL)
		    *ep++ = 0;
		*topic = strdup(cp + 1);
	    } else if ((*cp == 'S') && (*subtopic == NULL)) {
		if (ep != NULL)
		    *ep++ = 0;
		*subtopic = strdup(cp + 1);
	    } else if (*cp == 'D') {
		*desc = strdup(cp + 1);
		ep = NULL;
	    }
	    cp = ep;
	}
	if (*topic == NULL) {
	    if (*subtopic != NULL)
		free(*subtopic);
	    if (*desc != NULL)
		free(*desc);
	    continue;
	}
	return(1);
    }
}
示例#3
0
文件: ui.c 项目: ChrisX34/stuff
/******************************************************************************
 * UI_getConfig
 ******************************************************************************/
Int UI_getConfig(UI_Handle hUI, Char * option, Char ** cfgString)
{
    static Int i = 0;
    
    if (i < QTINTERFACE_MAXCONFIGITEMS) {
        *option = fgetc(hUI->fpConfig);
        /* Got config option. Process it */
        if (*option != '\27') {
            /* Option is not ETB. Get the config string */
            fgetstr(configStrings[i].string, (int)QTINTERFACE_MAXSTRINGSIZE, 
                hUI->fpConfig);
            *cfgString = configStrings[i].string;
        }
        else {
            /* ETB received. End of configuration */
        } 
        i++;
        return SUCCESS;
    }
    else {
        ERR("Maximum number of configuration items exceeded.\n");
        return FAILURE;
    }
}
示例#4
0
int
include(const char *filename)
{
    struct includeline	*script, *se, *sp;
    char		input[256];			/* big enough? */
#ifdef BOOT_FORTH
    int			res;
    char		*cp;
    int			prevsrcid, fd, line;
#else
    int			argc,res;
    char		**argv, *cp;
    int			fd, flags, line;
#endif

    if (((fd = open(filename, O_RDONLY)) == -1)) {
	sprintf(command_errbuf,"can't open '%s': %s", filename, strerror(errno));
	return(CMD_ERROR);
    }

    /*
     * Read the script into memory.
     */
    script = se = NULL;
    line = 0;
	
    while (fgetstr(input, sizeof(input), fd) >= 0) {
	line++;
#ifdef BOOT_FORTH
	cp = input;
#else
	flags = 0;
	/* Discard comments */
	if (strncmp(input+strspn(input, " "), "\\ ", 2) == 0)
	    continue;
	cp = input;
	/* Echo? */
	if (input[0] == '@') {
	    cp++;
	    flags |= SL_QUIET;
	}
	/* Error OK? */
	if (input[0] == '-') {
	    cp++;
	    flags |= SL_IGNOREERR;
	}
#endif
	/* Allocate script line structure and copy line, flags */
	if (*cp == '\0')
		continue;	/* ignore empty line, save memory */
	sp = malloc(sizeof(struct includeline) + strlen(cp) + 1);
	/* On malloc failure (it happens!), free as much as possible and exit */
	if (sp == NULL) {
		while (script != NULL) {
			se = script;
			script = script->next;
			free(se);
		}
		sprintf(command_errbuf, "file '%s' line %d: memory allocation "
		    "failure - aborting", filename, line);
		return (CMD_ERROR);
	}
	strcpy(sp->text, cp);
#ifndef BOOT_FORTH
	sp->flags = flags;
	sp->line = line;
#endif
	sp->next = NULL;
	    
	if (script == NULL) {
	    script = sp;
	} else {
	    se->next = sp;
	}
	se = sp;
    }
    close(fd);
    
    /*
     * Execute the script
     */
#ifndef BOOT_FORTH
    argv = NULL;
#else
    prevsrcid = bf_vm->sourceID.i;
    bf_vm->sourceID.i = fd;
#endif
    res = CMD_OK;
    for (sp = script; sp != NULL; sp = sp->next) {
	
#ifdef BOOT_FORTH
	res = bf_run(sp->text);
	if (res != VM_OUTOFTEXT) {
		sprintf(command_errbuf, "Error while including %s, in the line:\n%s", filename, sp->text);
		res = CMD_ERROR;
		break;
	} else
		res = CMD_OK;
#else
	/* print if not being quiet */
	if (!(sp->flags & SL_QUIET)) {
	    prompt();
	    printf("%s\n", sp->text);
	}

	/* Parse the command */
	if (!parse(&argc, &argv, sp->text)) {
	    if ((argc > 0) && (perform(argc, argv) != 0)) {
		/* normal command */
		printf("%s: %s\n", argv[0], command_errmsg);
		if (!(sp->flags & SL_IGNOREERR)) {
		    res=CMD_ERROR;
		    break;
		}
	    }
	    free(argv);
	    argv = NULL;
	} else {
	    printf("%s line %d: parse error\n", filename, sp->line);
	    res=CMD_ERROR;
	    break;
	}
#endif
    }
#ifndef BOOT_FORTH
    if (argv != NULL)
	free(argv);
#else
    bf_vm->sourceID.i = prevsrcid;
#endif
    while(script != NULL) {
	se = script;
	script = script->next;
	free(se);
    }
    return(res);
}
示例#5
0
int main(int argc, char **argv) 
{
  JSAMPARRAY buf = malloc(sizeof(JSAMPROW)*BUF_LINES);
  jpeg_saved_marker_ptr exif_marker, cmarker;
  MD5_CTX *MD5 = malloc(sizeof(MD5_CTX));
  volatile int i;
  int c,j,lines_read, err_count;
  char ch;
  char namebuf[1024];
  long fs;
  char *md5buf,digest[16],digest_text[33];
  
  global_total_errors=0;
  if (rcsid); /* to keep compiler from not complaining about rcsid */
 
  cinfo.err = jpeg_std_error(&jerr.pub);
  jpeg_create_decompress(&cinfo);
  jerr.pub.error_exit=my_error_exit;
  jerr.pub.output_message=my_output_message;

  if (!buf || !MD5) no_memory();
  if (argc<2) {
    if (quiet_mode < 2) fprintf(stderr,"jpeginfo: file arguments missing\n"
			     "Try 'jpeginfo "
			     "--help"
			     "' for more information.\n");
    exit(1);
  }
 
  /* parse command line parameters */
  while(1) {
    opt_index=0;
    if ( (c=getopt_long(argc,argv,"livVdcChqm:f:5",
			long_options,&opt_index))  == -1) 
      break;
    switch (c) {
    case 'm':
        if (!strcasecmp(optarg,"all")) del_mode=0;
        else if (!strcasecmp(optarg,"erronly")) del_mode=1;
	else if (!quiet_mode) 
	  fprintf(stderr,"Unknown parameter for -m, --mode.\n");
      break;
    case 'f':
        if (!strcmp(optarg,"-")) listfile=stdin;
	else if ((listfile=fopen(optarg,"r"))==NULL) {
	  fprintf(stderr,"Cannot open file '%s'.\n",optarg);
	  exit(2);
	}
	input_from_file=1;
	break;
    case 'v':
      verbose_mode=1;
      break;
    case 'V':
      fprintf(stderr,"jpeginfo v" VERSION "  " HOST_TYPE 
	      "\nCopyright (c) Timo Kokkonen, 1995-2002.\n"); 
      exit(0);
    case 'd':
      delete_mode=1;
      break;
    case 'c':
      check_mode=1;
      break;
    case 'h':
      p_usage();
      break;
    case 'q':
      quiet_mode++;
      break;
    case 'l':
      list_mode=1;
      break;
    case 'i':
      longinfo_mode=1;
      break;
    case '5':
      md5_mode=1;
      break;
    case 'C':
      com_mode=1;
      break;
    case '?':
      break;

    default:
      if (!quiet_mode) 
	fprintf(stderr,"jpeginfo: error parsing parameters.\n");
    }
  }

  if (delete_mode && verbose_mode && !quiet_mode) 
    fprintf(stderr,"jpeginfo: delete mode enabled (%s)\n",
	    !del_mode?"normal":"errors only"); 

  i=1;  
  do {
   if (input_from_file) {
     if (!fgetstr(namebuf,sizeof(namebuf),listfile)) break;
     current=namebuf;
   } 
   else current=argv[i];
 
   if (current[0]==0) continue;
   if (current[0]=='-' && !input_from_file) continue;
 
   if (setjmp(jerr.setjmp_buffer)) {
      jpeg_abort_decompress(&cinfo);
      fclose(infile);
      if (list_mode && quiet_mode < 2) printf(" %s",current);
      if (quiet_mode < 2) printf(" [ERROR]\n");
      if (delete_mode) delete_file(current,verbose_mode,quiet_mode);
      continue;
   }

   if ((infile=fopen(current,"r"))==NULL) {
     if (!quiet_mode) fprintf(stderr, "jpeginfo: can't open '%s'\n", current);
     continue;
   }
   if (is_dir(infile)) {
     fclose(infile);
     if (verbose_mode) printf("directory: %s  skipped\n",current); 
     continue;
   }

   fs=filesize(infile);

   if (md5_mode) {
     md5buf=malloc(fs);
     if (!md5buf) no_memory();
     fread(md5buf,1,fs,infile);
     rewind(infile);
     
     MD5Init(MD5);
     MD5Update(MD5,md5buf,fs);
     MD5Final(digest,MD5);
     md2str(digest,digest_text);

     free(md5buf);
   }

   if (!list_mode && quiet_mode < 2) printf("%s ",current);

   global_error_counter=0;
   err_count=jerr.pub.num_warnings;
   if (com_mode) jpeg_save_markers(&cinfo, JPEG_COM, 0xffff);
   jpeg_save_markers(&cinfo, EXIF_JPEG_MARKER, 0xffff);
   jpeg_stdio_src(&cinfo, infile);
   jpeg_read_header(&cinfo, TRUE); 

   /* check for Exif marker */
   exif_marker=NULL;
   cmarker=cinfo.marker_list;
   while (cmarker) {
     if (cmarker->marker == EXIF_JPEG_MARKER) {
       if (!memcmp(cmarker->data,EXIF_IDENT_STRING,6)) exif_marker=cmarker;
     }
     cmarker=cmarker->next;
   }   

   if (quiet_mode < 2) {
     printf("%4d x %-4d %2dbit ",(int)cinfo.image_width,
            (int)cinfo.image_height,(int)cinfo.num_components*8);

     if (exif_marker) printf("Exif  ");
     else if (cinfo.saw_JFIF_marker) printf("JFIF  ");
     else if (cinfo.saw_Adobe_marker) printf("Adobe ");
     else printf("n/a   "); 

     if (longinfo_mode) {
       printf("%s %s",(cinfo.progressive_mode?"Progressive":"Normal"),
	      (cinfo.arith_code?"Arithmetic":"Huffman") );

       if (cinfo.density_unit==1||cinfo.density_unit==2) 
	 printf(",%ddp%c",MIN(cinfo.X_density,cinfo.Y_density),
		(cinfo.density_unit==1?'i':'c') );
     
       if (cinfo.CCIR601_sampling) printf(",CCIR601");
       printf(" %7ld ",fs);

     } else printf("%c %7ld ",(cinfo.progressive_mode?'P':'N'),fs);

     if (md5_mode) printf("%s ",digest_text);
     if (list_mode) printf("%s ",current);

     if (com_mode) {
       cmarker=cinfo.marker_list;
       while (cmarker) {
	 if (cmarker->marker == JPEG_COM) {
	   printf("\"");
	   for (j=0;j<cmarker->data_length;j++) {
	     ch = cmarker->data[j];
	     if (ch < 32 || iscntrl(ch)) continue;
	     printf("%c",cmarker->data[j]);
	   }
	   printf("\" ");
	 }
	 cmarker=cmarker->next;
       }
     }
   }

   if (check_mode) {
     cinfo.out_color_space=JCS_GRAYSCALE; /* to speed up the process... */
     cinfo.scale_denom = 8;
     jpeg_start_decompress(&cinfo);
 
     for (j=0;j<BUF_LINES;j++) {
        buf[j]=malloc(sizeof(JSAMPLE)*cinfo.output_width*
                                      cinfo.out_color_components);
        if (!buf[j]) no_memory();
     }

     while (cinfo.output_scanline < cinfo.output_height) {
       lines_read = jpeg_read_scanlines(&cinfo, buf,BUF_LINES);
     }

     jpeg_finish_decompress(&cinfo);
     for(j=0;j<BUF_LINES;j++) free(buf[j]);

     if (!global_error_counter) {
       if (quiet_mode < 2) printf(" [OK]\n");
     }
     else {
       if (quiet_mode < 2) printf(" [WARNING]\n");
       if (delete_mode && !del_mode) 
	 delete_file(current,verbose_mode,quiet_mode);
     }
   }
   else { /* !check_mode */
     if (quiet_mode < 2) printf("\n"); 
     jpeg_abort_decompress(&cinfo);
   }

   fclose(infile);
  
  } while (++i<argc || input_from_file);

  jpeg_destroy_decompress(&cinfo);
  free(buf);
  free(MD5);

  return (global_total_errors>0?1:0); /* return 1 if any errors found file(s)
					 we checked */
}
示例#6
0
static int
command_help(int argc, char *argv[]) 
{
    char	buf[81];	/* XXX buffer size? */
    int		hfd, matched, doindex;
    char	*topic, *subtopic, *t, *s, *d;

    /* page the help text from our load path */
    /* sprintf(buf, "%s/boot/loader.help", getenv("loaddev")); */
    /* page the help text from our base path */
    snprintf(buf, sizeof(buf), "%sloader.help", getenv("base"));
    if ((hfd = open(buf, O_RDONLY)) < 0) {
	if ((hfd = rel_open("loader.help", NULL, O_RDONLY)) < 0) {
	    printf("Verbose help not available, use '?' to list commands\n");
	    return(CMD_OK);
	}
    }

    /* pick up request from arguments */
    topic = subtopic = NULL;
    switch(argc) {
    case 3:
	subtopic = strdup(argv[2]);
    case 2:
	topic = strdup(argv[1]);
	break;
    case 1:
	topic = strdup("help");
	break;
    default:
	command_errmsg = "usage is 'help <topic> [<subtopic>]";
	return(CMD_ERROR);
    }

    /* magic "index" keyword */
    doindex = !strcmp(topic, "index");
    matched = doindex;
    
    /* Scan the helpfile looking for help matching the request */
    pager_open();
    while(help_getnext(hfd, &t, &s, &d)) {

	if (doindex) {		/* dink around formatting */
	    help_emitsummary(t, s, d);

	} else if (strcmp(topic, t)) {
	    /* topic mismatch */
	    if(matched)		/* nothing more on this topic, stop scanning */
		break;

	} else {
	    /* topic matched */
	    matched = 1;
	    if (((subtopic == NULL) && (s == NULL)) ||
		((subtopic != NULL) && (s != NULL) && !strcmp(subtopic, s))) {
		/* exact match, print text */
		while((fgetstr(buf, 80, hfd) >= 0) && (buf[0] != '#')) {
		    if (pager_output(buf))
			break;
		    if (pager_output("\n"))
			break;
		}
	    } else if ((subtopic == NULL) && (s != NULL)) {
		/* topic match, list subtopics */
		help_emitsummary(t, s, d);
	    }
	}
	free(t);
	free(s);
	free(d);
    }
    pager_close();
    close(hfd);
    if (!matched) {
	sprintf(command_errbuf, "no help available for '%s'", topic);
	free(topic);
	if (subtopic)
	    free(subtopic);
	return(CMD_ERROR);
    }
    free(topic);
    if (subtopic)
	free(subtopic);
    return(CMD_OK);
}
/**
 * @brief Read and parse a skin.
 *
 * @param sname name of the skin
 *
 * @return 0 (ok), -1 (skin file not found or not readable) or -2 (parsing error)
 */
int skinRead(char *sname)
{
    char *skinfname;
    FILE *skinfile;
    unsigned char line[256];
    unsigned char item[32];
    unsigned char param[256];
    unsigned int i;

    skinfname = setname(skinDirInHome, sname);

    if ((skinfile = fopen(skinfname, "rt")) == NULL) {
        skinfname = setname(skinMPlayerDir, sname);

        if ((skinfile = fopen(skinfname, "rt")) == NULL) {
            mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotFound, skinfname);
            return -1;
        }
    }

    mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[skin] configuration file: %s\n", skinfname);

    appFreeStruct();

    skin = NULL;
    currWinName[0] = 0;
    linenumber     = 0;

    while (fgetstr(line, sizeof(line), skinfile)) {
        linenumber++;

        strswap(line, '\t', ' ');
        trim(line);
        decomment(line);

        if (!*line)
            continue;

        cutItem(line, item, '=', 0);
        cutItem(line, param, '=', 1);
        strlower(item);

        for (i = 0; i < FF_ARRAY_ELEMS(skinItem); i++) {
            if (!strcmp(item, skinItem[i].name)) {
                if (skinItem[i].func(param) != 0)
                    return -2;
                else
                    break;
            }
        }

        if (i == FF_ARRAY_ELEMS(skinItem)) {
            skin_error(MSGTR_SKIN_UNKNOWN_ITEM, item);
            return -2;
        }
    }

    if (linenumber == 0) {
        mp_msg(MSGT_GPLAYER, MSGL_ERR, MSGTR_SKIN_SkinFileNotReadable, skinfname);
        return -1;
    }

    return 0;
}
示例#8
0
static int
splitfs_open(const char *fname, struct open_file *f)
{
    char *buf, *confname, *cp;
    int	conffd;
    struct split_file *sf;
    struct stat sb;

    /* Have to be in "just read it" mode */
    if (f->f_flags != F_READ)
	return(EPERM);

    /* If the name already ends in `.split', ignore it */
    if ((cp = strrchr(fname, '.')) && (!strcmp(cp, ".split")))
	return(ENOENT);

    /* Construct new name */
    confname = malloc(strlen(fname) + 7);
    sprintf(confname, "%s.split", fname);

    /* Try to open the configuration file */
    conffd = open(confname, O_RDONLY);
    free(confname);
    if (conffd == -1)
	return(ENOENT);

    if (fstat(conffd, &sb) < 0) {
	printf("splitfs_open: stat failed\n");
	close(conffd);
	return(ENOENT);
    }
    if (!S_ISREG(sb.st_mode)) {
	printf("splitfs_open: not a file\n");
	close(conffd);
	return(EISDIR);			/* best guess */
    }

    /* Allocate a split_file structure, populate it from the config file */
    sf = malloc(sizeof(struct split_file));
    bzero(sf, sizeof(struct split_file));
    buf = malloc(CONF_BUF);
    while (fgetstr(buf, CONF_BUF, conffd) > 0) {
	cp = buf;
	while ((*cp != '\0') && (isspace(*cp) == 0))
	    cp++;
	if (*cp != '\0') {
	    *cp = '\0';
	    cp++;
	}
	while ((*cp != '\0') && (isspace(*cp) != 0))
	    cp++;
	if (*cp == '\0')
	    cp = buf;
	sf->filesc++;
	sf->filesv = realloc(sf->filesv, sizeof(*(sf->filesv)) * sf->filesc);
	sf->descsv = realloc(sf->descsv, sizeof(*(sf->descsv)) * sf->filesc);
	sf->filesv[sf->filesc - 1] = strdup(buf);
	sf->descsv[sf->filesc - 1] = strdup(cp);
    }
    free(buf);
    close(conffd);

    if (sf->filesc == 0) {
	split_file_destroy(sf);
	return(ENOENT);
    }
    errno = split_openfile(sf);
    if (errno != 0) {
	split_file_destroy(sf);
	return(ENOENT);
    }

    /* Looks OK, we'll take it */
    f->f_fsdata = sf;
    return (0);
}
示例#9
0
文件: tae_subcmd.c 项目: E-LLP/VICAR
int add_subcmd_vars_to_parblk(struct PARBLK *parblk,FILE *fp)
{
	int done,found_sub,vallen,count,len;
	char *line, key[8],*value,*start;
	char sub_cmd[16];
	
	/* Get the chosen subcommand */
	zvp("_SUBCMD",sub_cmd,&count);
	len = strlen(sub_cmd);
	
	/* make sure the first PDF line is "PROCESS"-something */
	
	done = (fgetstr(&line, fp) <0);
	if (*line != 'P' && *line != 'p')
		tae_abort(MISINTRO,"");
		
	/* add PARMS which are global to all SUBCMD'S */

	do 
	{
		done = (fgetstr(&line, fp) <0); 
		done = done || (strncasecmp(line,"END-PROC",8)==0) ||
					(strncasecmp(line,"SUBCMD",6) == 0);

		if  ((! done) && (strncasecmp(line,"PARM",4)==0))
			add_one_pdf_variable_to_parblk(parblk,line);
	} while (! done);

	/* Now look for the correct subcommand */
	
	for ((done =FALSE,found_sub = FALSE); !found_sub && !done;)
	{
		if (strncasecmp(line,"SUBCMD",6)==0)
		{
			key[0]='\0';
			start = find_parm(line+6,key,&value,&vallen);
			switch(key[0])
			{
				case '\0': /* Then this is a subcmd NAME */
					found_sub = (strncasecmp(sub_cmd,value,len)==0);
					break;
				case '-':  /* SUBCMD-DEFAULT */
				{
					key[0] = '\0';
					start = find_parm(start,key,&value,&vallen);
					found_sub = (strncasecmp(sub_cmd,value,len)==0);
					break;
				}
			}

		} /* End-If SUBCMD line found */
		
		done = (fgetstr(&line,fp) < 0);
		done = done || (strncasecmp(line,"END-PROC",8)==0);
		
	}/* End of Search for subcommand */

	if (found_sub)	/* found the subcommand ! */
	{
		/* add PARMS which are local to the subcommand */
		for (done=FALSE; !done;) 
		{
			if  (strncasecmp(line,"PARM",4)==0)
				add_one_pdf_variable_to_parblk(parblk,line);
				
			done = (fgetstr(&line, fp) <0); 
			done = done || (strncasecmp(line,"END-",4)==0);
	
		}
	}
	
	return SUCCESS;
}
示例#10
0
文件: tae_subcmd.c 项目: E-LLP/VICAR
int add_subcmd_to_parblk(struct PARBLK *parblk, FILE *fp)
{
	long cur_pos;
	int done,vallen,nvalids;
	char *line, key[8],*value,*start;
	char parm[200],deflt[16],valid[16];
	
	strcpy(parm,"PARM _SUBCMD TYPE=KEYWORD VALID=(");
	
	/* save current position and go to start of file */
	cur_pos = fseek( fp, 0L, SEEK_CUR);
	fseek(fp,0L, SEEK_SET);
	
	done = (fgetstr(&line,fp) < 0);
	if (done)
		tae_abort(MISINTRO,"");

	done = (fgetstr(&line,fp) < 0);
	deflt[0] = '\0';
	nvalids = 0;
	
	/* Now Scan the file for SUBCMD statements */
	
	while (!done)
	{
		if (strncasecmp(line,"SUBCMD",6)==0)
		{
			key[0]='\0';
			start = find_parm(line+6,key,&value,&vallen);
			switch(key[0])
			{
				case '-':	/* probably default subcommand */
				
					if (strncasecmp(value,"DEFAULT",vallen)==0)
					{
						key[0]='\0';
						start = find_parm(start,key,&value,&vallen);
						strncpy(deflt,value,vallen);
						deflt[vallen] = '\0';
					}
					/* fall through to: */
					
				case '\0':	/* a VALID value for subcommand */
					nvalids++;
					strncpy(valid,value,vallen);
					valid[vallen] = '\0';
					strcat(parm,valid);	/* add valid to list */
					strcat(parm,",");	/* remember to delete last , */
					break;
			}
			
		} /* End-If SUBCMD line found */
		
		done = (fgetstr(&line,fp) < 0);
		done = done || (strncasecmp(line,"END-PROC",8)==0);
		
	}/* End of Loop through file */

	if (nvalids > 0)	/* found some subcommands ! */
	{
		/* Replace that last pesky comma with a ')' */
		parm[strlen(parm)-1] = ')';
		
		/* if a default was found, tack it on to the end */
		if (strlen(deflt) > 0)
		{
			strcat(parm," DEFAULT=");
			strcat(parm,deflt);
		}
		
		/* Now Convert the parm string into a _SUBCMD variable */
		
		add_one_pdf_variable_to_parblk(parblk,parm);
	}

	/* restore position of file */
	fseek(fp,cur_pos, SEEK_SET);
	
	return SUCCESS;
}
int traceTrajectory() {
    /***** DECLARATIONS *****/
    FILE *currentFile = NULL;
    char *video_path = (char*) malloc(sizeof (char) * MAX_PATH);
    char *pattern_path = (char*) malloc(sizeof (char) * MAX_PATH);
    char *center_path = (char*) malloc(sizeof (char) * MAX_PATH);
    CvCapture* capture = 0;
    bwimage_t *image_target, *image_pattern, *image_center;
    Pixel peak;
    error_e retval = EEA_OK;

    /***** MAIN PROCEDURE *****/
    do {
        /*** Find the paths to the images that need to be processed ***/
        currentFile = fopen("paths_center.txt", "r"); // file containing
                                                      // the paths to the images
        if (currentFile != NULL) {
            fgetstr(video_path, MAX_PATH, currentFile);
            fgetstr(pattern_path, MAX_PATH, currentFile);
            fgetstr(center_path, MAX_PATH, currentFile);
        } else {
            printf("paths_center.txt cannot be opened");
            exit(EXIT_FAILURE);
        }
        fclose(currentFile);

        /*** Load the input images ***/
        image_target = EEACreateImage();
        image_pattern = EEACreateImage();
        retval = EEALoadImage(pattern_path, image_pattern);
        if (retval != EEA_OK) break;
        // free paths
        free(video_path);
        free(pattern_path);

        /*** Initialize the video frame capture ***/
        capture = cvCreateFileCapture("samples/parabolic_drop_256.avi");
        if (!capture) {
            return -1;
        }
        IplImage *frame = cvQueryFrame(capture); //Init the video reading
        double fps = cvGetCaptureProperty(
                capture,
                CV_CAP_PROP_FPS
                );
        CvSize size = cvSize(
                (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
                (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT)
                );
        // Convert to grayscale frame
        IplImage *frameGray = cvCreateImage(size, IPL_DEPTH_8U, 1);

        /*** Process the images ***/
        bwimage_t *image_temp = createBlackBwimage(image_pattern->height,
                                                   image_pattern->width);
        Pixel center;
        copyImage(image_temp, image_pattern);
        trim(&image_temp, 0.08);
        findCenter(&center, image_temp);
        EEAFreeImage(image_temp);
        cvCvtColor(frame, frameGray, CV_RGB2GRAY);
        iplImageToBwimage(&image_target, frameGray);
        locateShape(image_target, image_pattern, 0.08, &peak);
        createCenterImage(&image_center, image_target->height,
                                image_target->width, peak, center);
        while (1) {
            frame = cvQueryFrame(capture);
            if (!frame) break;
            // Convert to grayscale frame
            cvCvtColor(frame, frameGray, CV_RGB2GRAY);
            iplImageToBwimage(&image_target, frameGray);
            locateShape(image_target, image_pattern, 0.08, &peak);
            addPosition(image_center, peak, center);
        }
        cvReleaseImage(&frame);
        cvReleaseImage(&frameGray);
        cvReleaseCapture(&capture);

        /*** Write the output images at the specified path ***/
        if (EEA_OK != (retval = EEADumpImage(center_path, image_center))) break;
        free(center_path);
    } while (0);

    /***** FREE HEAP MEMORY *****/
    EEAFreeImage(image_target);
    EEAFreeImage(image_pattern);
    EEAFreeImage(image_center);

    /***** ERROR HANDLING *****/
    switch (retval) {
        case EEA_OK:
            break;
        case EEA_ENOFILE:
            fprintf(stderr, "Cannot open file\n");
            break;
        case EEA_EBADBPS:
            fprintf(stderr, "Number of bits per sample must be equal to 8\n");
            break;
        case EEA_EBADPHOTOMETRIC:
            fprintf(stderr, "Not a colormap image\n");
            break;
        case EEA_ENOCOLORMAP:
            fprintf(stderr, "Image does not have a colormap\n");
            break;
        case EEA_ENOTGRAY:
            fprintf(stderr, "At least one entry in the colormap is not gray\n");
        case EEA_ENOMEM:
            fprintf(stderr, "Cannot allocate memory\n");
            break;
        default:
            ; /* Can't happen  */
    }

    return(EXIT_SUCCESS);
}
示例#12
0
文件: mml.c 项目: ArtemioUrbina/huc
int main(int argc,char *argv[])
{
	char infilename[13];
	char a,channel=0,pan_r,pan_l,ext=OFF;
	char f_channel=OFF;/* トラックデータ先アドレス登録テーブルがあるか */
	char pc_mode=0;/* パーカッションモード */
	static char ch[7]={0,OFF,OFF,OFF,OFF,OFF,OFF};
	static int ch_length[7]={4,4,4,4,4,4,4};
	static int amari[7]={0,0,0,0,0,0,0};
	int i,j,k,line=0,length=0,put_length,tone;
	double futen;
	FILE *infile,*outfile;
	
	
	if( argc != 2 ){
		puts(short_help);
		puts("\tUsagi:MML [mml-file]\n");
		exit(1);
	}
	
	for(i=0; argv[1][i]!=0 ;i++){
		if(argv[1][i]=='.'){
			ext=ON;
			break;
		}
	}
	
	strcpy(infilename,argv[1]);
	if(ext==OFF){
		strcat(infilename,".MML");
	}
	if( (infile=fopen(infilename,"r")) == NULL ){
		printf("File not found:[%s]\n",infilename);
		exit(1);
	}
	printf("INFILE:%s\n",infilename);
	
	strcpy(buf,remove_ext(infilename));
	strcat(buf,".asm");
	if( (outfile=fopen(buf,"w")) == NULL ){
		printf("\nCan't open OUTPUT_FILE.\n");
		exit(1);
	}
	
	/* 出力開始 */
	fputs("\torg\t\t$8000\n", outfile);
	
	/* トラックデータインデックステーブル */
	fputs("\
track_index:\n\
\tdw\t\ttrack0\n\
;\n", outfile);
	/* ループ開始 */
	while((i=fgetc(infile)) != EOF){
		line++;
		switch((char)i){
			case '.':
			/* 指令である */
				fgetstr(buf,infile,"=");
				if( /*strnicmp*/strncasecmp(buf, "START", 5) == 0 ){
					channel=buf[5]-'0';
					if( channel<1 || channel>6 ){
						printf("Channel Error in %s:%d\n",infilename,line);
						exit(1);
					}
					if( ch[channel] == ON ){
						printf("Channel [%d] already exist in %s:%d",channel,infilename,line);
						exit(1);
					}
					
					ch[channel]=ON;
					f_channel=ON;
					ch_length[channel]=4;
					pc_mode=0;
					fputs("START_CH", outfile);
					fputc(buf[5], outfile);
					fputs(":\n" ,outfile);
					goto MML_EXT;
				}
				break;
			case ' ':
			case '\t':
			/* 前の続き */
				goto MML_EXT;
			case ';':
			/* コメントである */
				fgetstr(buf, infile, "\n\r");
			case '\n':
			case '\r':
				break;
			default:
			/* それ以外は文字列 */
				ungetc((char)i, infile);
				channel=0;
				ch_length[channel]=4;
				pc_mode=0;
				fgetstr(buf2, infile, "=");
				strcpy(buf,"LABEL_");
				strcat(buf,buf2);
				strcat(buf,":\n");
				fputs( buf, outfile);
MML_EXT:
				j=0;
				fgetstr(buf,infile,";\n\r");
				/* MML展開ループ */
				while(buf[j] != 0){
					
					/* 通常の音符 */
					if( (k=instr("C D EF G A B", buf[j])) != 0 && pc_mode==0 ){
						j++;
						if(buf[j]=='#' || buf[j]=='+'){
							k++; /* 半音上げる */
							j++;
						}else if(buf[j]=='-'){
							k--; /* 半音下げる */
							j++;
						}
						/* 音長 */
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						switch(length){
							case 0:
								length=ch_length[channel];
								break;
							case 1:
							case 2:
							case 3:
							case 4:
							case 6:
							case 8:
							case 12:
							case 16:
							case 24:
							case 32:
							case 48:
							case 64:
							case 96:
								break;
							default:
								printf("Length error in:%d(%d)\n",line,length);
								exit(1);
						}
						/* kが1〜12以外のときの前処理 */
						if(k==0){
							fputs("\tdb\t\t$d9    \t;オクターブダウン\n", outfile);
						}else if(k==13){
							fputs("\tdb\t\t$d8    \t;オクターブアップ\n", outfile);
						}
						tone=k;
						if(k==0)tone=12;
						if(k==13)tone=1;
						tone*=16;
						/* ダイレクトレングスモード */
						put_length=(int)( (192+amari[channel])/length);
						amari[channel]=(int)( (192+amari[channel])%length);
						/* 符点処理 */
						futen=1.0;
						length=1;
						while(buf[j]=='.'){
							futen += pow(0.5, length++);
							j++;
						}
						put_length*=futen;
						fprintf(outfile, "\tdb\t\t$%02x,$%02x\t;オンプ\n", tone, put_length);
					
						/* kが1〜12以外のときの後処理 */
						if(k==0){
							fputs("\tdb\t\t$d8    \t;オクターブアップ\n", outfile);
						}else if(k==13){
							fputs("\tdb\t\t$d9    \t;オクターブダウン\n", outfile);
						}	/* 音長終わり */
					
					/* 休符 */
					}else if( buf[j]=='R' && pc_mode==0 ){
						j++;
						/* 休符長 */
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						switch(length){
							case 0:
								length=4;
								break;
							case 1:
							case 2:
							case 3:
							case 4:
							case 6:
							case 8:
							case 12:
							case 16:
							case 24:
							case 32:
							case 48:
							case 64:
							case 96:
								break;
							default:
								printf("Length error in:%d(%d)\n",line,length);
								exit(1);
						}
						put_length=(192/length);
						/* 符点処理 */
						futen=1.0;
						length=1;
						while(buf[j]=='.'){
							futen += pow(0.5, length++);
							j++;
						}
						put_length*=futen;
						fprintf(outfile, "\tdb\t\t$00,$%02x\t;キュウフ\n",put_length);
					
					/* オクターブ */
					}else if(buf[j] == 'O'){
						j++;
						/* オクターブ高 */
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if(length<1 || 7<length){
							printf("Parameter error of 'O' in:%d (%d)\n",line,length);
							exit(1);
						}
						fprintf(outfile, "\tdb\t\t$%02x    \t;オクターブ\n",0xD0+length);
					
					/* オクターブup */
					}else if(buf[j] == '>'){
						j++;
						fputs("\tdb\t\t$d8    \t;オクターブアップ\n", outfile);
					
					/* オクターブdown */
					}else if(buf[j] == '<'){
						j++;
						fputs("\tdb\t\t$d9    \t;オクターブダウン\n", outfile);
					
					/* タイ */
					}else if(buf[j] == '&'){
						j++;
						fputs("\tdb\t\t$da   \t;タイ\n", outfile);
					
					/* テンポ */
					}else if(buf[j] == 'T'){
						j++;
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<35 || 255<length ){
							printf("Parameter error of 'T' in:%d (%d)\n",line,length);
							exit(1);
						}
						fprintf(outfile, "\tdb\t\t$db,$%02x\t;テンポ\n",length);
					
					/* ヴォリューム0〜31 */
					}else if(buf[j] == 'V'){
						j++;
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<0 || 31<length ){
							printf("Parameter error of 'V' in:%d (%d)\n",line,length);
							exit(1);
						}
						fprintf(outfile, "\tdb\t\t$dc,$%02x\t;ボリューム\n",(char)length);
					
					/* パンポット0x00〜0xFF */
					}else if(buf[j] == 'P'){
						j++;
						pan_r=0;
						pan_l=0;
						while( isdigit((int)buf[j]) ){
							pan_r = pan_r*10+buf[j]-'0';
							j++;
						}
						if(buf[j]!=','){
							printf("Parameter error of 'P' in:%d (%d)\n",line,length);
							exit(1);
						}
						j++;
						while( isdigit((int)buf[j]) ){
							pan_l = pan_l*10+buf[j]-'0';
							j++;
						}
						if( (pan_r<0 || 15<pan_r)||(pan_l<0 || 15<pan_l) ){
							printf("Parameter error of 'P' in:%d (%d)\n",line,length);
							exit(1);
						}
						fprintf(outfile, "\tdb\t\t$dd,$%1x%1x\t;パンポット\n",pan_r,pan_l);
					
					/* 音長比1〜8 */
					}else if(buf[j] == 'Q'){
						j++;
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<1 || 8<length ){
							printf("Parameter error of 'Q' in:%d (%d)\n",line,length);
							exit(1);
						}
						fprintf(outfile, "\tdb\t\t$de,$%02x\t;オンチョウヒ\n",(char)length);
					/* 相対ヴォリューム */
					
					/* ダルセーニョ */
					
					/* セーニョ */
					
					/* リピートビギン */
					}else if(buf[j] == '['){
						j++;
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<0 || 255<length ){
							printf("Parameter error of '[' in:%d (%d)\n",line,length);
							exit(1);
						}
						fprintf(outfile, "\tdb\t\t$e3,$%02x\t;リピートビギン\n",(char)length);
					
					/* リピートエンド */
					}else if(buf[j] == ']'){
						j++;
						fputs("\tdb\t\t$e4    \t;リピートエンド\n", outfile);
					
					/* ウェーブ(音色) */
					}else if( (buf[j] == '@') && isdigit(buf[j+1]) ){
						j++;
						length=0;
						if( !isdigit((int)buf[j]) ){
							printf("Parameter error of '@' in:%d (null)\n",line);
							exit(1);
						}
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<0 || 44<length ){
							printf("Parameter error of '@' in:%d (%d)\n",line,length);
							exit(1);
						}
						fprintf(outfile, "\tdb\t\t$e5,$%02x\t;オンショク\n",(char)length);
					
					/* エンベロープ */
					}else if( (buf[j] == '@') && (buf[j+1] == 'E') ){
						j++; j++;
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<0 || 127<length ){
							printf("Parameter error of '@E' in:%d (%d)\n",line,length);
							exit(1);
						}
						fprintf(outfile, "\tdb\t\t$e6,$%02x\t;エンベロープ\n",(char)length);
					
					/* 周波数変調 */
					/* FMディレイ */
					/* FM補正 */
					/* ピッチエンベロープ(PE) */
					/* PEディレイ */
					/* デチューン */
					}else if( (buf[j] == '@') && (buf[j+1] == 'D') ){
						j++; j++;
						length=0;
						put_length=1;
						if(buf[j]=='-'){
							/* マイナスの値 */
							put_length=-1;
							j++;
						}
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<0 || 128<length ){
							printf("Parameter error of '@D' in:%d (%d)\n",line,length);
							exit(1);
						}
						put_length*=length;
						fprintf(outfile, "\tdb\t\t$ec,$%02x\t;デチューン\n",(char)put_length);
					
					/* スイープ */
					/* スイープタイム */
					/* ジャンプ */
					}else if(buf[j] == '/'){
						j++;
						k=6;
						strcpy(buf2, "LABEL_");
						while( buf[j] != '/' ){
							buf2[k]=buf[j];
							j++;
							k++;
						}
						j++;
						buf2[k]='\0';
						if( k==6 ){
							printf("Label name error in:%d\n",line);
							exit(1);
						}
						
						fprintf(outfile, "\tdb\t\t$ef    \t;ジャンプ\n");
						fprintf(outfile, "\tdw\t\t%s\t;ジャンプ\n",buf2);
					
					
					/* コール */
					}else if(buf[j] == '('){
						j++;
						k=6;
						strcpy(buf2, "LABEL_");
						while( buf[j] != ')' ){
							buf2[k]=buf[j];
							j++;
							k++;
						}
						j++;
						buf2[k]='\0';
						if( k==6 ){
							printf("Label name error in:%d\n",line);
							exit(1);
						}
						
						fprintf(outfile, "\tdb\t\t$f0    \t;コール\n");
						fprintf(outfile, "\tdw\t\t%s\t;コール\n",buf2);
					
					/* リターン */
					}else if(buf[j] == '\''){
						j++;
						fputs("\tdb\t\t$f1    \t;リターン\n", outfile);
					/* 移調 */
					/* 相対移調 */
					/* 全体移調 */
					/* ヴォリュームチェンジ */
					/* パンライトチェンジ */
					/* パンレフトチェンジ */
					/* モード */
					}else if( (buf[j] == '@') && (buf[j+1] == 'M') ){
						j++; j++;
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<0 || 2<length ){
							printf("Parameter error of '@M' in:%d (%d)\n",line,length);
							exit(1);
						}
						pc_mode=length;
						fprintf(outfile, "\tdb\t\t$f8,$%02x\t;モード\n",(char)length);
					
					/* フェードアウト */
					
					/* データエンド */
					}else if(buf[j] == '*'){
						j++;
						fputs("\tdb\t\t$ff    \t;データエンド\n", outfile);
					
					/* ここからは独自のコマンド */
					/* Lコマンド */
					}else if(buf[j] == 'L'){
						j++;
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						switch(length){
							case 1:
							case 2:
							case 3:
							case 4:
							case 6:
							case 8:
							case 12:
							case 16:
							case 24:
							case 32:
							case 48:
							case 64:
							case 96:
								break;
							default:
								printf("Parameter error of 'L' in:%d (%d)\n",line,length);
								exit(1);
						}
						ch_length[channel]=length;
						
					/* 拡張ヴォリューム @V0〜128 */
					}else if( (buf[j] == '@') && (buf[j+1] == 'V') ){
						j++; j++;
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						if( length<0 || 127<length ){
							printf("Parameter error of '@V' in:%d (%d)\n",line,length);
							exit(1);
						}
						put_length=length*31/127;
						fprintf(outfile, "\tdb\t\t$dc,$%02x\t;ボリューム(@V)\n",(char)put_length);
					
					/* パーカッションモードの音符 */
					}else if( (k=instr("RBSMCH      ", buf[j])) != 0 && pc_mode==1 ){
						j++;
						while( !isdigit(buf[j]) ){
							j++;
						}
						if(buf[j]=='!' ){
							/* ヴォリューム強調 */
							j++;
						}
						/* 音長 */
						length=0;
						while( isdigit((int)buf[j]) ){
							length = length*10+buf[j]-'0';
							j++;
						}
						switch(length){
							case 0:
								length=ch_length[channel];
								break;
							case 1:
							case 2:
							case 3:
							case 4:
							case 6:
							case 8:
							case 12:
							case 16:
							case 24:
							case 32:
							case 48:
							case 64:
							case 96:
								break;
							default:
								printf("Length error in:%d(%d)\n",line,length);
								exit(1);
						}
						tone=k;
						if(k==0)tone=12;
						if(k==13)tone=1;
						tone*=16;
						/* ダイレクトレングスモード */
						put_length=(int)( (192+amari[channel])/length);
						amari[channel]=(int)( (192+amari[channel])%length);
						/* 符点処理 */
						futen=1.0;
						length=1;
						while(buf[j]=='.'){
							futen += pow(0.5, length++);
							j++;
						}
						put_length*=futen;
						fprintf(outfile, "\tdb\t\t$%02x,$%02x\t;オンプ(パーカッション)\n", tone, put_length);
						/* 音長終わり */
					
					/* エラー */
					}else{
						printf("Not Support [%c]in:%d\n",buf[j],line);
						exit(1);
					}
					
				}/* MML展開ループ終わり */
				break;
		}/* switch(char)i)の終わり */
	}/* 読み込みがEOF */
	fclose(infile);
	/* トラックデータ先アドレス登録テーブル */
	if(f_channel==OFF){
		puts("No channel data.\n");
		exit(1);
	}
	fputs("track0:\n", outfile);
	for(a=0, i=1; i<=6; i++){
		a<<=1;
		a+=ch[i];
	}
	fprintf(outfile, "\tdb\t\t$%02x\t;00%1d%1d_%1d%1d%1d%1db\n",a,ch[1],ch[2],ch[3],ch[4],ch[5],ch[6]);
	for(i=1; i<=6; i++)
		if(ch[i]==ON)
			fprintf(outfile, "\tdw\t\tSTART_CH%1d\n",i);
	
#ifndef osx	/* damn BSD */
	fcloseall();
#endif
	return 0;
}
示例#13
0
int findShape() {
    FILE *currentFile = NULL;
    char *target_path = (char*) malloc(sizeof (char) * MAX_PATH);
    char *pattern_path = (char*) malloc(sizeof (char) * MAX_PATH);
    char *shapes_path = (char*) malloc(sizeof (char) * MAX_PATH);
    char *peaks_path = (char*) malloc(sizeof (char) * MAX_PATH);
    char *corfil_path = (char*) malloc(sizeof (char) * MAX_PATH);
    float tolerancethreshold = (float) 0.;
    bwimage_t *image_target, *image_pattern, *image_corfil, *image_peaks,
                *image_shapes;
    int npeak;
    Pixel *peaks;
    error_e retval = EEA_OK;
    image_target = EEACreateImage();
    image_pattern = EEACreateImage();
    
    /***** MAIN PROCEDURE *****/
    do {
        /*** Find the paths to the images that need to be processed ***/
        currentFile = fopen("paths.txt", "r"); // file containing the paths
                                              //  to the images
        if (currentFile != NULL) {
            fgetstr(target_path, MAX_PATH, currentFile);
            fgetstr(pattern_path, MAX_PATH, currentFile);
            fgetstr(shapes_path, MAX_PATH, currentFile);
            fgetstr(peaks_path, MAX_PATH, currentFile);
            fgetstr(corfil_path, MAX_PATH, currentFile);
        } else {
            printf("paths.txt cannot be opened");
            getchar();
            exit(EXIT_FAILURE);
        }
        fclose(currentFile);
        
    /*** Find the tolerance threshold to be used (0.7 is the default value) ***/
        currentFile = fopen("tolerancethreshold.txt", "r");
        if (currentFile != NULL) {
            if (fscanf(currentFile, "%f", &tolerancethreshold) == EOF
                    || tolerancethreshold == (float) 0.) {
                tolerancethreshold = (float) 0.7; // default value
            }
        } else {
            tolerancethreshold = (float) 0.7;
        }
        fclose(currentFile);
        
        /*** Load the input images ***/
        retval = EEALoadImage(target_path, image_target);
        if (retval != EEA_OK) break;
        retval = EEALoadImage(pattern_path, image_pattern);
        if (retval != EEA_OK) break;
        free(target_path);
        free(pattern_path);
        if (image_target->height >= image_target->width) {
            peaks = (Pixel *) malloc(image_target->height * sizeof (Pixel *));
        } else {
            peaks = (Pixel *) malloc(image_target->width * sizeof (Pixel *));
        }

        /*** Process the images ***/
        trimLocateShape(&image_corfil, image_target, &image_pattern, 0.08,
                                tolerancethreshold, &npeak, peaks);
        createPeakImage(&image_peaks, image_corfil->height,
                                image_corfil->width, peaks, npeak);
        fillWithShapes(&image_shapes, image_pattern, image_target->height,
                                image_target->width, peaks, npeak);
        
        /*** Write the output images at the specified path ***/
        if (EEA_OK != (retval = EEADumpImage(shapes_path, image_shapes))) break;
        if (EEA_OK != (retval = EEADumpImage(peaks_path, image_peaks))) break;
        if (EEA_OK != (retval = EEADumpImage(corfil_path, image_corfil))) break;

    } while (0);
    
    /***** FREE HEAP MEMORY *****/
    free(shapes_path);
    free(peaks_path);
    free(corfil_path);
    free(peaks);
    EEAFreeImage(image_target);
    EEAFreeImage(image_pattern);
    EEAFreeImage(image_corfil);
    EEAFreeImage(image_peaks);
    EEAFreeImage(image_shapes);
    
    /***** ERROR HANDLING *****/
    switch (retval) {
        case EEA_OK:
            break;
        case EEA_ENOFILE:
            fprintf(stderr, "Cannot open file\n");
            break;
        case EEA_EBADBPS:
            fprintf(stderr, "Number of bits per sample must be equal to 8\n");
            break;
        case EEA_EBADPHOTOMETRIC:
            fprintf(stderr, "Not a colormap image\n");
            break;
        case EEA_ENOCOLORMAP:
            fprintf(stderr, "Image does not have a colormap\n");
            break;
        case EEA_ENOTGRAY:
            fprintf(stderr, "At least one entry in the colormap is not gray\n");
        case EEA_ENOMEM:
            fprintf(stderr, "Cannot allocate memory\n");
            break;
        default:
            ; /* Can't happen */
    }

    return 0;
}