コード例 #1
0
ファイル: sym.c プロジェクト: inste/jane
struct Symbol * sym_alloc_shallow(int type, int is_constant, char * label, void * data) {
	struct Symbol * sym;
	
	sym = (struct Symbol *) jmalloc(sizeof(struct Symbol));
	sym->type = type;
	sym->is_constant = is_constant;
	sym->label = label;
	sym->data = data;
	return sym;
}
コード例 #2
0
ファイル: pmenu.c プロジェクト: spippolatore/abuse
pmenu_item::pmenu_item(char *Name, psub_menu *Sub, pmenu_item *Next, int xpos)
{
  xp=xpos;
  id=0; hotkey=-1;
  next=Next;
  on_off=NULL;
  CONDITION(Name,"Sub menu cannot have a NULL name");
  n=strcpy((char *)jmalloc(strlen(Name)+1,"pmenu_item::name"),Name); 
  sub=Sub;
}
コード例 #3
0
ファイル: cqueue.c プロジェクト: Joinhack/fragement
static cqueue_item *create_cqueue_item() {
	cqueue_item *cq_item;
	size_t len = sizeof(cqueue_item);
	cq_item = jmalloc(len);
	if(cq_item == NULL)
		return NULL;
	cq_item->next = NULL;
	cq_item->prev = NULL;
	cq_item->data = NULL;
	return cq_item;
}
コード例 #4
0
ファイル: pmenu.c プロジェクト: spippolatore/abuse
pmenu_item::pmenu_item(int ID, char *Name, char *on_off_flag, int Hotkey, pmenu_item *Next)
{ 
  xp=-1;
  id=ID; 
  hotkey=Hotkey;
  on_off=on_off_flag;
  if (Name)
    n=strcpy((char *)jmalloc(strlen(Name)+1,"pmenu_item::name"),Name); 
  else n=NULL;
  next=Next;
  sub=NULL;
}
コード例 #5
0
ファイル: AdvVariousType.cpp プロジェクト: ivan0124/MyHandler
AdvVariousType::AdvVariousType(const char *str) {
	int len = strlen(str);
	jn = Allocate_GC();
	jn->type = JSON_TYPE_STRING;
	jn->s = jmalloc(jn->s, &jn->alloc, len + 1);
	//doubleQuote(jn->s, str, &len);
	memcpy(jn->s,str,len);
	jn->s[len] = 0;
	jn->len = len;
	count = 1;
	//a = 0;
}
コード例 #6
0
ファイル: jnet.c プロジェクト: spippolatore/abuse
uchar *get_local_address()                             // same format as above (be sure to jfree this)
{
  char name[80];
  uchar *ip=(uchar *)jmalloc(4,"IP address");

  if (gethostname(name,80)!=0)
  { ip[0]=127; ip[1]=ip[2]=0; ip[3]=1; }
  else
  {
    struct hostent *me=gethostbyname(name);
    memcpy(ip,me->h_addr,4);
  }
}
コード例 #7
0
ファイル: cevent.c プロジェクト: Joinhack/chat
cevents *cevents_create() {
	cevents *evts;
	int len;
	len = sizeof(cevents);
	evts = (cevents *)jmalloc(len);

	memset((void *)evts, 0, len);
	evts->events = jmalloc(sizeof(cevent) * MAX_EVENTS);
	memset(evts->events, 0, sizeof(cevent) * MAX_EVENTS);
	evts->fired_fds = jmalloc(sizeof(int) * MAX_EVENTS);
	for(size_t i = 0; i < MAX_EVENTS; i++) {
		evts->events[i].fired_queue = clist_create();
	}
	evts->fired_fds = clist_create();
	LOCK_INIT(&evts->qlock);
	LOCK_INIT(&evts->lock);
	cevents_create_priv_impl(evts);
	evts->poll_sec = 0;
	evts->poll_ms = 0;
	evts->timers = ctimer_base_create();
	return evts;
}
コード例 #8
0
ファイル: jcdc_general.c プロジェクト: bgtwoigu/1110
static cdc_cmd_priv_t *cdc_init_request_priv(jcdc_dev_softc_t *sc,
    cdc_req_type type, uwh_cdc_app_h app_ctx, void *app_priv)
{
    cdc_cmd_priv_t *priv = (cdc_cmd_priv_t *)jmalloc(sizeof(cdc_cmd_priv_t), 
        M_ZERO);
    if (priv)
    {
        priv->sc = sc;
        priv->req_type = type;
        priv->app_ctx = app_ctx;
        priv->app_priv = app_priv;
    }

    return priv;
}
コード例 #9
0
ファイル: cio.c プロジェクト: Joinhack/thr_socket
cio *cio_create() {
	cio *io = jmalloc(sizeof(cio));
	memset(io, 0, sizeof(cio));
	io->rbuf = cstr_create(1024);
	io->wbuf = cstr_create(1024);
	io->wcount = 0;
	io->priv = NULL;
	io->flag = 0;
	io->argc = 0;
	io->tabidx = 0;
	io->bulk_len = 0;
	io->nbulk = 0;
	io->reqtype = REQ_TYPE_NORMAL;
	io->argv = NULL;
	return io;
}
コード例 #10
0
ファイル: text_gui.c プロジェクト: spippolatore/abuse
int nice_copy(char *title, char *source, char *dest)
{
  int x1=0,y1=0,x2=79,y2=25;
  bar(x1,y1+1,x2,y2,176,0x01);
  put_title(title);

  box(x1,(y1+y2)/2-1,x2,(y1+y2)/2+3,0x17);
  bar(x1+1,(y1+y2)/2,x2-1,(y1+y2)/2+2,' ',0x17);
  
  char msg[100];
  sprintf(msg,"Copying %s -> %s",source,dest);
  put_string(x1+1,(y1+y2)/2,msg,0x17);
  bar(x1+1,(y1+y2)/2+2,x2-1,(y1+y2)/2+2,176,0x17);

  char *buffer=(char *)jmalloc(0xf000,"read buf");
  if (!buffer) return 0;
  FILE *out=fopen(dest,"wb");
  if (!out) { jfree(buffer) ; return 0; }
  FILE *in=fopen(source,"rb");
  if (!in) { jfree(buffer); fclose(out); unlink(dest); return 0; }

  fseek(in,0,SEEK_END);
  long size=ftell(in);
  fseek(in,0,SEEK_SET);
  int osize=size;
  while (size)
  {
    long tr=fread(buffer,1,0xf000,in);
    bar(x1+1,(y1+y2)/2+2,x1+1+(x2-x1)*(osize-size-tr)/osize,(y1+y2)/2+2,178,0x17);

    if (fwrite(buffer,1,tr,out)!=tr)
    {
      fclose(out);
      fclose(in);
      unlink(dest);
      jfree(buffer);
      return 0;
    }
    size-=tr;
    
  }
  fclose(in);
  fclose(out);
  jfree(buffer);
  cls();
  return 1;
}
コード例 #11
0
ファイル: fd_storage_usb.c プロジェクト: bgtwoigu/1110
/**
 * Function name:  mass_storage_init
 * Description:    Initializes the mass storage function driver.
 * Parameters: 
 *     @ctx: (IN) Core context
 *
 * Return value: 0 on success, otherwise an error code 
 * Scope:        Global
 **/
jresult_t mass_storage_init(void *ctx)
{
    jresult_t rc;
    fd_storage_t *fd;

    fd = jmalloc(sizeof(fd_storage_t), M_ZERO);
    if (!fd)
        return JENOMEM;

    fd->core_ctx = ctx;
    fd->state = STATE_DISABLED;
    
    fd->fd_desc = copy_fd_desc();
    if (!fd->fd_desc)
    {
        jfree(fd);
        return JENOMEM;
    }

    /* Allocate requests */                    
    fd->ep0_request = core_request_alloc(1, NULL);
    if (!fd->ep0_request)
    {
        DBG_E(DSLAVE_MS_USB, ("mass_storage_init: Failed to allocate ep0 "
            "request\n"));
        return JENOMEM;
    }

    fd->cmd_request = core_request_alloc(SCSI_MAX_REQUEST_SIZE, NULL);
    if (!fd->cmd_request)
    {
        DBG_E(DSLAVE_MS_USB, ("mass_storage_init: Failed to allocate cmd "
            "request\n"));
        return JENOMEM;
    }

    /* The completion callback of ep0 is always the same */
    fd->ep0_request->complete = ep0_callback;
    fd->ep0_request->context = (void *)fd;

    rc = scsi_init(fd, &fd->total_luns, &fd->scsi_device);
    if (rc)
        return rc;

    return core_register_fd(fd->core_ctx, &fd_ops, (context_t)fd);
}
コード例 #12
0
ファイル: AdvVariousType.cpp プロジェクト: ivan0124/MyHandler
AdvVariousType::AdvVariousType(bool b) {
	jn = Allocate_GC();
	jn->type = JSON_TYPE_BOOL;
	jn->s = jmalloc(jn->s, &jn->alloc, 5);
	
	
	if(b) {
		strcpy(jn->s,"true");
		jn->len = 4;
	} else {
		strcpy(jn->s,"false");
		jn->len = 5;
	}
	
	count = 1;
	//a = 0;
}
コード例 #13
0
ファイル: audio_sample.c プロジェクト: bgtwoigu/1110
jresult_t uwd_audio_app_init(uwd_audio_drv_h fd_ctx, uwd_audio_app_h *app_ctx,
    uwd_audio_config_t **config)
{
    app_ctx_h app;

    DBG_I(DSLAVE_AUDIO_APP, ("AUDIO_APP: uwd_audio_app_init\n"));

    app = (app_ctx_h)jmalloc(sizeof(app_ctx_t), M_ZERO);
    if(!app)
    {
        DBG_E(DSLAVE_AUDIO_APP, ("AUDIO_APP: No memory\n"));
        return JENOMEM;
    }

    app->fd_ctx = fd_ctx;

    *config = &app_config;
    *app_ctx = app;

    return 0;
}
コード例 #14
0
ファイル: diskwritemda.cpp プロジェクト: magland/saladsort
void DiskWriteMda::allocate(int N1, int N2, int N3, int N4, int N5, int N6)
{
	if (d->m_allocated) {
		printf("Warning: cannot allocate once array has been allocated.\n");
		return;
	}
	jfclose(jfopen(d->m_path.toLatin1().data(),"wb")); //remove the file
	d->m_file=jfopen(d->m_path.toLatin1().data(),"wb+");
	if (!d->m_file) {
		printf("Warning: cannot allocate. Unable to open file: %s\n",d->m_path.toLatin1().data());
		return;
	}
	int dims[MDAIO_MAX_DIMS]; for (int i=0; i<MDAIO_MAX_DIMS; i++) dims[i]=1;
	dims[0]=N1;
	dims[1]=N2;
	dims[2]=N3;
	dims[3]=N4;
	dims[4]=N5;
	dims[5]=N6;
	int num_dims=2;
	for (int i=2; i<MDAIO_MAX_DIMS; i++) {
		if (dims[i]>1) num_dims=i+1;
	}
	d->m_total_size=1;
	for (int i=0; i<num_dims; i++) {
		d->m_total_size*=dims[i];
	}
	d->m_mda_header.data_type=d->m_data_type;
	for (int i=0; i<MDAIO_MAX_DIMS; i++) d->m_mda_header.dims[i]=dims[i];
	d->m_mda_header.num_dims=num_dims;
	mda_write_header(&d->m_mda_header,d->m_file);
	float *all_zeros=(float *)jmalloc(sizeof(float)*d->m_total_size);
	for (int j=0; j<d->m_total_size; j++) all_zeros[j]=0;
	mda_write_float32(all_zeros,&d->m_mda_header,d->m_total_size,d->m_file);
	jfree(all_zeros);
	d->m_allocated=true;
}
コード例 #15
0
ファイル: js.c プロジェクト: micha/json-table
char *js_unescape_string(char *in) {
  char *inp = in, *outp, *out;
  outp = out = jmalloc(strlen(in) + 1);

  while (*inp != '\0') {
    if (*inp != '\\') {
      *(outp++) = *(inp++);
    } else {
      switch(*(++inp)) {
        case 'b': *(outp++) = '\b'; inp++; break;
        case 'f': *(outp++) = '\f'; inp++; break;
        case 'n': *(outp++) = '\n'; inp++; break;
        case 'r': *(outp++) = '\r'; inp++; break;
        case 't': *(outp++) = '\t'; inp++; break;
        case 'u': inp++; js_encode_u_escaped(&inp, &outp); break;
        default:  *(outp++) = *(inp++);
      }
    }
  }

  *outp = '\0';

  return out;
}
コード例 #16
0
ファイル: innet.c プロジェクト: spippolatore/abuse
int net_init(int argc, char **argv)
{
  int i,x,db_level=0;
  base=&local_base;

  local_client_number=0;

  if (!main_net_cfg)
    main_net_cfg=new net_configuration;


  if (!registered) return 0;

  for (i=1;i<argc;i++) 
    if (!strcmp(argv[i],"-nonet"))
      return 0;
    else if (!strcmp(argv[i],"-port"))
    {
      if (i==argc-1 || !sscanf(argv[i+1],"%d",&x) || x<1 || x>0x7fff)
      {
        dprintf("bad value following -port, use 1..32000\n");
        return 0;
      } 
      else 
        main_net_cfg->port=x;
    } else if (!strcmp(argv[i],"-net") && i<argc-1)
    {
      i++;
      strcpy(main_net_cfg->server_name,argv[i]);
      main_net_cfg->state=net_configuration::CLIENT;
    }
    else if (!strcmp(argv[i],"-ndb"))
    {
      if (i==argc-1 || !sscanf(argv[i+1],"%d",&x) || x<1 || x>3)
      {
        dprintf("bad value following -ndb, use 1..3\n");
        return 0;
      } else { db_level=x; }
    } else if (!strcmp(argv[i],"-server"))
      main_net_cfg->state=net_configuration::SERVER; 
    else if (!strcmp(argv[i],"-min_players"))
    {
      i++; 
      int x=atoi(argv[i]);
      if (x>=1 && x<=8)
        main_net_cfg->min_players=x;
      else dprintf("bad value for min_players use 1..8\n");
    }

  
  net_protocol *n=net_protocol::first,*usable=NULL;     // find a usable protocol from installed list
  int total_usable=0;
  for (;n;n=n->next)                                    // show a list of usables, just to be cute
  {
    dprintf("Protocol %s : ",n->installed() ? "Installed" : "Not_installed");
    dprintf("%s\n",n->name());
    if (n->installed()) 
    {
      total_usable++;
      usable=n;
    }      
  }

  if (!usable) { dprintf("No network protocols installed\n");  return 0; }
  prot=usable;
  prot->set_debug_printing((net_protocol::debug_type)db_level);
  if (main_net_cfg->state==net_configuration::SERVER)
    set_login(main_net_cfg->name);

  comm_sock=game_sock=NULL;
  if (main_net_cfg->state==net_configuration::CLIENT)
  {
    dprintf("Attempting to locate server %s, please wait\n",main_net_cfg->server_name);
    char *sn=main_net_cfg->server_name;
    if (main_net_cfg->addr)
      net_server = main_net_cfg->addr->copy();
    else
      net_server=prot->get_node_address(sn,DEFAULT_COMM_PORT,0);
    if (!net_server) { dprintf(symbol_str("unable_locate"));  exit(0); }   
    dprintf("Server located!  Please wait while data loads....\n");
  }

  fman=new file_manager(argc,argv,prot);                                       // manages remote file access
  if (game_face)
    delete game_face;
  game_face=new game_handler;
  join_array=(join_struct *)jmalloc(sizeof(join_struct)*MAX_JOINERS,"join array");
  base->join_list=NULL;
  base->mem_lock=0;
  base->calc_crcs=0;
  base->get_lsf=0;
  base->wait_reload=0;
  base->need_reload=0;
  base->input_state=INPUT_COLLECTING;
  base->current_tick=0;
  base->packet.packet_reset();

  return 1;
}
コード例 #17
0
ファイル: dict_test.c プロジェクト: Joinhack/chat
void* cpy(const void *k1) {
	char *p = jmalloc(strlen((char*)k1));
	memset(p, 0, sizeof(p));
	strcpy(p, k1);
	return p;
}
コード例 #18
0
ファイル: unpackgl.c プロジェクト: spippolatore/abuse
void unpackgl(char *fn, int pict_only)
{
  unsigned short dir_length,sl,x,amread,bufsize;
  unsigned long offset,ret_ofs,length;
  char name[14],st[50],*buf;
  FILE *fp,*ot;
  CHECK(fn);
  fp=fopen(fn,"rb");
  if (!fp) return ;

  if (fread(&dir_length,2,1,fp)!=1) return ;
  dir_length=int_to_local(dir_length)/17-1;
  ret_ofs=ftell(fp);
  while (dir_length--)
  {
    fseek(fp,ret_ofs,SEEK_SET);
    if (fread(&offset,4,1,fp)!=1) return ;
    offset=long_to_local(offset);
    if (fread(name,13,1,fp)!=1)  return ;
    name[13]=0;
    sl=strlen(name);
    ret_ofs=ftell(fp);  // save the current spot in the file so we can come back to it later
    if (toupper(name[sl-3])=='P' || toupper(name[sl-3])=='C' || !pict_only)
    {
      fseek(fp,offset,SEEK_SET);
      fread(&length,1,4,fp);
      length=long_to_local(length);
      if (length>1000000)
        exit(1);
      ot=fopen(name,"rb");
      if (ot)
      { printf("File (%s) already exsist, overwrite (y/n)?\n",name);
	fgets(st,49,stdin);
	if (!(st[0]=='Y' || st[0]=='y'))
	  length=0;
	fclose(ot);
      }
      if (length)
	ot=fopen(name,"wb");
      if (!ot) return ;
      bufsize=0xf000;
      do {
	buf=(char *)jmalloc(bufsize,"unpack_gl::buffer");
	if (!buf) bufsize-=100;
      } while (!buf);

      while (length)
      {
	if (length>bufsize)
	  amread=bufsize;
	else amread=length;
	fread(buf,1,amread,fp);
	fwrite(buf,1,amread,ot);
	length-=amread;
      }
      jfree(buf);
      if (ot) fclose(ot);
    }
  }
  fclose(fp);
}
コード例 #19
0
ファイル: buffer.c プロジェクト: micha/json-table
void buf_alloc(Buffer **b) {
  *b = jmalloc(sizeof(Buffer));
  (*b)->buf = jmalloc(BUFSIZ * 2.5);
  (*b)->size = BUFSIZ * 2.5;
  buf_reset(*b, 0);
}
コード例 #20
0
ファイル: cevent.c プロジェクト: Joinhack/thr_socket
static cevent_fired *clone_cevent_fired(cevents *cevts, cevent_fired *fired) {
	cevent *cevent = cevts->events + fired->fd;
	cevent_fired *new_cevent_fired = jmalloc(sizeof(cevent_fired));
	*new_cevent_fired = *fired;
	return new_cevent_fired;
}
コード例 #21
0
ファイル: specache.hpp プロジェクト: spippolatore/abuse
 filename_node(char *filename, spec_directory *dir)
 {
   fn=(char *)memcpy(jmalloc(strlen(filename)+1,"spec_dir cache"),filename,strlen(filename)+1);
   sd=dir;
   next=left=right=0;      
 }
コード例 #22
0
ファイル: pictbridge_sample.c プロジェクト: bgtwoigu/1110
static void execute_dpof_job(void)
{
    char *dpof_file = NULL;
    char *dpof_jobs = NULL;
    sicd_object_t *obj = NULL;
    jint_t i;
    dps_job_config_t jconfig;
    dps_job_info_t jinfo;
    char *filename = NULL;
    DECLARE_FNAME("execute_dpof_job");

    DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname));

    dpof_file = (char*)jmalloc(MAX_DPOF_FILE_SIZE, M_ZERO);
    dpof_jobs = (char*)jmalloc(MAX_DPOF_FILE_SIZE, M_ZERO);
    if (!dpof_file || !dpof_jobs)
    {
        DBG_E(DSLAVE_DPS_API, ("%s: failed to allocate job info\n", fname));
        goto Error;
    }

    /* Generate JOB sections */
    *dpof_jobs = '\0';
    for (i=0; sample_image[i].image; i++)
    {
        if (!sicd_store_find_object(app_ctx.store_id, sample_image[i].id))
        {
            DBG_E(DSLAVE_DPS_API, ("%s: could not find picture object "
                "(%X) in store\n", filename, sample_image[i].id));
            goto Error;
        }

        filename = j_strdup(sample_image[i].name);
        if (!filename)
        {
            DBG_E(DSLAVE_DPS_API, ("%s: error allocating memory (strdup)."
                "skipping %s\n", fname, sample_image[i].name));
            continue;
        }

        to_upper(filename);
        
        /* TODO: In a real system, the file name given here should be
         * the image's path relative to the DPOF file */
        j_snprintf(dpof_jobs, MAX_DPOF_FILE_SIZE, DPOF_JOB_TEMPLATE,
            dpof_jobs, i+1, TEST_NUMBER_OF_COPIES, DCF_PREFIX,
            filename);

        jfree(filename);
    }

    dpof_jobs[MAX_DPOF_FILE_SIZE-1] = '\0';

    /* Generate header */
    j_snprintf(dpof_file, MAX_DPOF_FILE_SIZE, DPOF_HDR_TEMPLATE, dpof_jobs);
    dpof_file[MAX_DPOF_FILE_SIZE-1] = '\0';

    DBG_X(DSLAVE_DPS_API, ("%s: DPOF file: \n%s\n\n", fname, dpof_file));

    /*
     *   DPOF file generation ends here. Proper API sample code
     *   for DPOF printing begins here.
     */
    
    /* Add DPOF virtual file to store */
    obj = jmalloc(sizeof(sicd_object_t), M_ZERO);
    if (!obj)
    {
        DBG_E(DSLAVE_DPS_API, ("%s: failed to allocate sicd_object_t "
            "for sample image %u\n", fname, i+1));
        goto Error;
    }

    app_ctx.dpof_file_id = obj->id = sicd_get_new_obj_handle();
    obj->info.storage_id = app_ctx.store_id;
    obj->info.format = PTP_OBJ_FORMAT_DPOF;
    obj->info.compressed_size = j_strlen(dpof_file)+1;
    obj->info.filename = ptp_string_atow("/MISC/AUTPRINT.MRK");
    obj->data = (juint8_t*)dpof_file;

    if (sicd_store_add_object(app_ctx.store_id, obj))
    {
        DBG_E(DSLAVE_DPS_API, ("generate_dpof: failed on "
            "sicd_store_add_object (%u)\n"));
        goto Error;
    }

    /* Create JobInfo for DPOF file */
    j_memset(&jconfig, 0, sizeof(jconfig));
    jconfig.file_type = DPS_FILE_TYPE_DPOF;

    j_memset(&jinfo, 0, sizeof(jinfo));
    jinfo.file_id = obj->id;
    j_strlcpy(jinfo.file_name, "/MISC/AUTPRINT.MRK", DPS_FILENAME_SIZE + 1);

    /* If we are testing DPOF restart, add relevant parameters */
    if (TEST_DPOF_RESTART && app_ctx.can_restart)
    {
        j_memcpy(&jinfo.dpof_restart, &app_ctx.dpof_restart_info,
            sizeof(dpof_params_t));
    }

    /* Send Job */
    dps_start_job(app_ctx.dpsh, &jconfig, &jinfo, 1);
    goto Exit;

Error:
    if (obj)
        sicd_free_object(NULL, obj);
    else if (dpof_file)
        jfree(dpof_file);
Exit:
    if (dpof_jobs)
        jfree(dpof_jobs);
}
コード例 #23
0
ファイル: cevent.c プロジェクト: Joinhack/chat
static cevent_fired *clone_cevent_fired(cevent_fired *fired) {
	cevent_fired *new_cevent_fired = jmalloc(sizeof(cevent_fired));
	*new_cevent_fired = *fired;
	return new_cevent_fired;
}
コード例 #24
0
ファイル: stdlib_arythm_ops.c プロジェクト: inste/jane
void rcmp(int argc, struct Symbol ** params, struct Symbol * result) {
	struct Rational * r = (struct Rational *)(result->data = jmalloc(sizeof(struct Rational)));
	r->denom = 1;
	r->num = sym_rational_is_eq(params[0], params[1]);
}