コード例 #1
0
ファイル: line.c プロジェクト: playya/Enlightenment
void
line_create(void)
{
    char               *s;
    float               x1 = 0, y1 = 0, x2 = 0, y2 = 0;
    int                 res;

    serv_set_hint(DUP(_("enter first point: ")));

    serv_set_state(ST_LINE1);

    do
      {
          s = serv_get_string();
          res = get_values(s, shell->context.fx, shell->context.fy, &x1, &y1);
          if (res == 1)
              serv_set_hint(DUP(_("error, please reenter: ")));
      }
    while (res == 1);

    serv_set_state(ST_LINE2);

    if (res == 0)
      {
          serv_set_state(ST_NORMAL);
          return;
      }

    do
      {
          pre_line_x1y1(x1, y1);
          shell->context.fx = x1;
          shell->context.fy = y1;

          serv_set_hint(DUP(_("enter next point: ")));
          do
            {
                s = serv_get_string();
                res = get_values(s, x1, y1, &x2, &y2);
                if (res == 1)
                    serv_set_hint(DUP(_("error, please reenter: ")));
            }
          while (res == 1);
          if (res == 0)
            {
                serv_set_state(ST_NORMAL);
                return;
            }

          lock_data();
          _line_create(x1, y1, x2, y2);
          shell->context.fx = x2;
          shell->context.fy = y2;
          unlock_data();
          x1 = x2;
          y1 = y2;
      }
    while (1);
}
コード例 #2
0
ファイル: Menu.c プロジェクト: awmaker/awmaker
static void
menuItemCloned(WEditMenuDelegate * delegate, WEditMenu * menu, WEditMenuItem * origItem, WEditMenuItem * newItem)
{
	ItemData *data = WGetEditMenuItemData(origItem);
	ItemData *newData;

	/* Parameter not used, but tell the compiler that it is ok */
	(void) delegate;
	(void) menu;

	if (!data)
		return;

#define DUP(s) (s) ? wstrdup(s) : NULL

	newData = wmalloc(sizeof(ItemData));

	newData->type = data->type;

	switch (data->type) {
	case ExecInfo:
		newData->param.exec.command = DUP(data->param.exec.command);
		newData->param.exec.shortcut = DUP(data->param.exec.shortcut);
		break;

	case CommandInfo:
		newData->param.command.command = data->param.command.command;
		newData->param.command.parameter = DUP(data->param.command.parameter);
		newData->param.command.shortcut = DUP(data->param.command.shortcut);
		break;

	case PipeInfo:
		newData->param.pipe.command = DUP(data->param.pipe.command);
		newData->param.pipe.cached = data->param.pipe.cached;
		break;

	case PLPipeInfo:
		newData->param.pipe.command = DUP(data->param.pipe.command);
		newData->param.pipe.cached = data->param.pipe.cached;
		break;

	case ExternalInfo:
		newData->param.external.path = DUP(data->param.external.path);
		break;

	case DirectoryInfo:
		newData->param.directory.directory = DUP(data->param.directory.directory);
		newData->param.directory.command = DUP(data->param.directory.command);
		newData->param.directory.stripExt = data->param.directory.stripExt;
		break;

	default:
		break;
	}

#undef DUP

	WSetEditMenuItemData(newItem, newData, (WMCallback *) freeItemData);
}
コード例 #3
0
ファイル: line.c プロジェクト: playya/Enlightenment
void
_line_create(double x1, double y1, double x2, double y2)
{
    Line               *line;
    Drawing            *d;
    Layer              *layer;

    d = drawing;
    if (!d)
        return;
    layer = d->current_layer;
    if (!layer)
        return;

    line = _line_create_copy(NULL);

    line->color = shell->context.color;
    line->line_style = DUP(shell->context.line_style);
    line->thickness = shell->context.thickness;
    line->line_scale = shell->context.line_scale;
    line->x1 = x1;
    line->x2 = x2;
    line->y1 = y1;
    line->y2 = y2;

    layer->objects = eina_list_append(layer->objects, line);

    append_undo_new_object(line, CMD_SYNC, OBJ_LINE, line);
    msg_create_and_send(CMD_SYNC, OBJ_LINE, line);

    line->owner = (Object *) drawing->current_layer;
    line_ssync(line);
}
コード例 #4
0
ファイル: esl_event.c プロジェクト: newfront/FreeSWITCH
ESL_DECLARE(esl_status_t) esl_event_dup(esl_event_t **event, esl_event_t *todup)
{
	esl_event_header_t *hp;

	if (esl_event_create_subclass(event, ESL_EVENT_CLONE, todup->subclass_name) != ESL_SUCCESS) {
		return ESL_FAIL;
	}

	(*event)->event_id = todup->event_id;

	(*event)->event_user_data = todup->event_user_data;
	(*event)->bind_user_data = todup->bind_user_data;

	for (hp = todup->headers; hp; hp = hp->next) {
		esl_event_add_header_string(*event, ESL_STACK_BOTTOM, hp->name, hp->value);
	}

	if (todup->body) {
		(*event)->body = DUP(todup->body);
	}

	(*event)->key = todup->key;

	return ESL_SUCCESS;
}
コード例 #5
0
ファイル: esl_event.c プロジェクト: AaronZhangL/CC
ESL_DECLARE(esl_status_t) esl_event_dup(esl_event_t **event, esl_event_t *todup)
{
	esl_event_header_t *hp;

	if (esl_event_create_subclass(event, ESL_EVENT_CLONE, todup->subclass_name) != ESL_SUCCESS) {
		return ESL_GENERR;
	}

	(*event)->event_id = todup->event_id;
	(*event)->event_user_data = todup->event_user_data;
	(*event)->bind_user_data = todup->bind_user_data;
	(*event)->flags = todup->flags;
	for (hp = todup->headers; hp; hp = hp->next) {
		if (todup->subclass_name && !strcmp(hp->name, "Event-Subclass")) {
			continue;
		}
		
		if (hp->idx) {
			int i;
			for (i = 0; i < hp->idx; i++) {
				esl_event_add_header_string(*event, ESL_STACK_PUSH, hp->name, hp->array[i]);
			}
		} else {
			esl_event_add_header_string(*event, ESL_STACK_BOTTOM, hp->name, hp->value);
		}
	}

	if (todup->body) {
		(*event)->body = DUP(todup->body);
	}

	(*event)->key = todup->key;

	return ESL_SUCCESS;
}
コード例 #6
0
ファイル: esl_event.c プロジェクト: newfront/FreeSWITCH
ESL_DECLARE(esl_status_t) esl_event_create_subclass(esl_event_t **event, esl_event_types_t event_id, const char *subclass_name)
{
	*event = NULL;

	if ((event_id != ESL_EVENT_CLONE && event_id != ESL_EVENT_CUSTOM) && subclass_name) {
		return ESL_FAIL;
	}

	*event = ALLOC(sizeof(esl_event_t));
	esl_assert(*event);


	memset(*event, 0, sizeof(esl_event_t));

	if (event_id != ESL_EVENT_CLONE) {
		(*event)->event_id = event_id;
		esl_event_add_header_string(*event, ESL_STACK_BOTTOM, "Event-Name", esl_event_name((*event)->event_id));
	}

	if (subclass_name) {
		(*event)->subclass_name = DUP(subclass_name);
		esl_event_add_header_string(*event, ESL_STACK_BOTTOM, "Event-Subclass", subclass_name);
	}	
	
	return ESL_SUCCESS;
}
コード例 #7
0
ファイル: hatchstyle.c プロジェクト: playya/Enlightenment
HS                 *
_hs_load(const char *style)
{
    HS                 *hs;
    int                 i, num, res;
    char                buf[4096];
    float               x;

    sprintf(buf, "/hatchstyle/%s/num", style);
    E_DB_INT_GET(shell->hatch_styles_file, buf, i, res);
    ENGY_ASSERTS(res, "loading hatch style");
    if (!res)
        return NULL;

    hs = (HS *) malloc(sizeof(HS));
    ENGY_ASSERT(hs);
    memset(hs, 0, sizeof(HS));
    hs->num = i;
    hs->name = DUP(style);

    for (i = 0; i < hs->num; i++)
      {
          HS_Item            *it;

          it = hs_load_item(style, i);
          if (it)
              hs->items = eina_list_append(hs->items, it);
      }
    return hs;
}
コード例 #8
0
ファイル: line.c プロジェクト: playya/Enlightenment
Line               *
_line_create_copy(Line * src)
{
    Line               *li;

    li = (Line *) malloc(sizeof(Line));
    ENGY_ASSERT(li);
    memset(li, 0, sizeof(Line));

    li->type = OBJ_LINE;
    li->id = rand() + my_int++;
    li->flags = FLAG_VISIBLE;

    li->old.color.red = -1;
    li->old.color.green = -1;
    li->old.color.blue = -1;
    li->old.color.alpha = -1;

    if (!src)
        return li;
    li->flags = li->flags;
    li->color = src->color;
    li->line_style = DUP(src->line_style);
    li->thickness = src->thickness;
    li->line_scale = src->line_scale;
    li->x1 = src->x1;
    li->y1 = src->y1;
    li->x2 = src->x2;
    li->y2 = src->y2;

    return li;
}
コード例 #9
0
ファイル: esl_event.c プロジェクト: newfront/FreeSWITCH
ESL_DECLARE(esl_status_t) esl_event_add_header_string(esl_event_t *event, esl_stack_t stack, const char *header_name, const char *data)
{
	if (data) {
		return esl_event_base_add_header(event, stack, header_name, DUP(data));
	}
	return ESL_FAIL;
}
コード例 #10
0
ファイル: run.c プロジェクト: coursera-msb/radare2
static int handle_redirection(const char *cmd, bool in, bool out, bool err) {
	if (!cmd || cmd[0] == '\0') return 0;

	if (cmd[0] == '"') {
#if __UNIX__
		if (in) {
			int pipes[2];
			if (pipe (pipes) != -1) {
				write (pipes[1], cmd+1, strlen (cmd)-2);
				write (pipes[1], "\n", 1);
				close (0);
				dup2 (pipes[0], 0);
			} else {
				eprintf ("[ERROR] rarun2: Cannot create pipe\n");
			}
		}
#else
#warning quoted string redirection handle not yet done
#endif
		return 0;
	} else if (cmd[0] == '!') {
		// redirection to a process
		return handle_redirection_proc (cmd + 1, in, out, err);
	} else {
		// redirection to a file
		int f, flag = 0, mode = 0;
		flag |= in ? O_RDONLY : 0;
		flag |= out ? O_WRONLY | O_CREAT : 0;
		flag |= err ? O_WRONLY | O_CREAT : 0;
#ifdef __WINDOWS__
		mode = _S_IREAD | _S_IWRITE;
#else
		mode = S_IRUSR | S_IWUSR;
#endif
		f = open (cmd, flag, mode);
		if (f < 0) {
			eprintf ("[ERROR] rarun2: Cannot open: %s\n", cmd);
			return 1;
		}
#define DUP(x) { close(x); dup2(f,x); }
		if (in) DUP(0);
		if (out) DUP(1);
		if (err) DUP(2);
		close (f);
		return 0;
	}
}
コード例 #11
0
ファイル: watrack.cpp プロジェクト: Seldom/miranda-ng
void WATrack::GetData()
{
	SONGINFO *si = NULL;
	int playing = CallService(MS_WAT_GETMUSICINFO, WAT_INF_UNICODE, (LPARAM)&si);

	FreeData();

	// See if something is playing
	if (playing == WAT_RES_NOTFOUND || si == NULL || si->status != 1 || (IsEmpty(si->artist) && IsEmpty(si->title)))
		return;

	// Copy new data
	listening_info.ptszAlbum = DUP(si->album);
	listening_info.ptszArtist = DUP(si->artist);
	listening_info.ptszTitle = DUP(si->title);
	listening_info.ptszYear = DUP(si->year);

	if (si->track > 0) {
		listening_info.ptszTrack = (TCHAR*)mir_alloc(10 * sizeof(TCHAR));
		_itot(si->track, listening_info.ptszTrack, 10);
	}

	listening_info.ptszGenre = DUP(si->genre);

	if (si->total > 0) {
		listening_info.ptszLength = (TCHAR*)mir_alloc(10 * sizeof(TCHAR));

		int s = si->total % 60;
		int m = (si->total / 60) % 60;
		int h = (si->total / 60) / 60;

		if (h > 0)
			mir_sntprintf(listening_info.ptszLength, 9, _T("%d:%02d:%02d"), h, m, s);
		else
			mir_sntprintf(listening_info.ptszLength, 9, _T("%d:%02d"), m, s);
	}

	if (si->width > 0)
		listening_info.ptszType = mir_tstrdup(_T("Video"));
	else
		listening_info.ptszType = mir_tstrdup(_T("Music"));

	listening_info.ptszPlayer = DUPD(si->player, name);

	listening_info.cbSize = sizeof(listening_info);
	listening_info.dwFlags = LTI_TCHAR;
}
コード例 #12
0
ファイル: esl_event.c プロジェクト: aaron-thompson/FreeSWITCH
ESL_DECLARE(esl_status_t) esl_event_set_body(esl_event_t *event, const char *body)
{
	esl_safe_free(event->body);

	if (body) {
		event->body = DUP(body);
	}
	
	return ESL_SUCCESS;
}
コード例 #13
0
ファイル: dup3d.c プロジェクト: nathanweeks/ast
int
dup3d(int fd)
{
    register int	r;

    initialize();
    r = DUP(fd);
#if FS
    if (r >= 0 && r < elementsof(state.file))
        fs3d_dup(fd, r);
#endif
    return r;
}
コード例 #14
0
ファイル: Mpeg2Pmt.c プロジェクト: diffalot/DReaM
static RetCode
mpeg2PmtActivate(Mpeg2Pmt mpeg2Pmt, MmpContextObject *cop,
		 Mpeg2PmtTsProgramMapSection * pmsp)
{
    Mpeg2PmtStream     *streamp;
    Mpeg2PmtTsProgramMapSection *curPmsp;
    Mpeg2PmtCurrentNextIndicator cni;
    unsigned            pn;

    cni = Mpeg2PmtCurrentNextIndicator(pmsp->psiExtension.currentNextIndicator);
    pn = MPEG2_PMT_PROGRAM_NUMBER(&pmsp->psiExtension);

    curPmsp = (Mpeg2PmtTsProgramMapSection*)hashTableGet(mpeg2Pmt->pmtTable[cni], pn);

    if (curPmsp == NULL
	    || curPmsp->psiExtension.versionNumber
	    != pmsp->psiExtension.versionNumber) {
	mpeg2PmtDeactivate(mpeg2Pmt, pn, cni);
	(void) hashTablePut(mpeg2Pmt->pmtTable[cni], pn,
			DUP(Mpeg2PmtTsProgramMapSection, pmsp));
	if (mpeg2Pmt->shouldPmtStop) {
	    return RETCODE_CONS(retCodeId, MPEG2_PMT_ERROR_STOP);
	}
	for (streamp = pmsp->streamList;
		streamp != NULL; streamp = streamp->next) {
	    unsigned            streamType = streamp->streamHeader.streamType;
	    unsigned            ePid = MPEG2_PMT_STREAM_HEADER_ELEMENTARY_PID(
						    &streamp->streamHeader);
	    Pipe                pidPipe;

	    if (MMP_CONTEXT_PIDTOPIPE(cop, ePid) == NULL) {
		MmpParserObject    *pop = mpeg2Pmt->streamTypeToPop[streamType];
		RetCode             retCode;

		streamp->cop = cop;
		pidPipe = MMP_PARSER_NEWPIPE(pop, cop);
		retCode = MMP_CONTEXT_ADDPIPE(cop, ePid, pidPipe);
		ABORT_IF_FALSE(retCode == RETCODE_SUCCESS);
	    } else if (streamp->cop != cop) {
		return RETCODE_CONS(retCodeId, MPEG2_PMT_ERROR_PID_USE);
	    }
	}
    } else {
	mpeg2PmtDescListFree(pmsp->descList);
	mpeg2PmtStreamListFree(pmsp->streamList);
    }
    return RETCODE_SUCCESS;
}
コード例 #15
0
ファイル: shell.c プロジェクト: playya/Enlightenment
void check_rc_files(void){
    char                buf[4096];
    char               *home;
    FILE *test;
    int res;
    
    home = getenv("HOME");
    if(!home || (strlen(home)==0)){
	fprintf(stderr,"check out $HOME\n");
	exit(-1);
    }
    
    if(strlen(home)>1000) {
	fprintf(stderr,"$HOME is too long\n");
	exit(-1);
    }
    
    
    sprintf(buf, "%s/engycad/.engycad.db", home);
    test = fopen(buf,"r");
    if(!test){
	snprintf(buf,4000,"%s/engycad", home);
	res = mkdir(buf,0755);
	if(res==-1){
	    fprintf(stderr,"Cannot create $HOME/engycad dir!\n");
	}
	
	snprintf(buf, 4000, 
			"cp %s/resources/tools/.engycad.db %s/engycad/",
			PACKAGE_DATA_DIR, home);
	printf("%s\n", buf);
	system(buf);

	sprintf(buf, "%s/engycad/.engycad.db",home);
	test = fopen(buf,"r");
	if(!test){
	   fprintf(stderr,
		"Cannot create rcfile!\n");
	   exit(-1);
	}
    } else {
	fclose(test);
    }

    shell->rcfile = DUP(buf);
}               
コード例 #16
0
ファイル: shell.c プロジェクト: playya/Enlightenment
static void
bg_mouse_down(void *data, Evas *_e, Evas_Object *_o, void *event_info)
{
    Drawing            *d;
    double              x, y, _x, _y;
    Evas_Coord          ex, ey, ew, eh;
    int                 shift_state, ctrl_state;
    int 		_b;
    Evas_Event_Mouse_Down * em = (Evas_Event_Mouse_Down*) event_info;

    if (!shell)
        return;
    if (!shell->evas)
        return;

    _b = em->button;
    shift_state = evas_key_modifier_is_set(em->modifiers, "Shift"); 
    ctrl_state = evas_key_modifier_is_set(em->modifiers, "Control");

    evas_output_viewport_get(shell->evas, &ex, &ey, &ew, &eh);
    d = drawing;
    if (!d)
        return;
    _x = em->canvas.x;
    _y = em->canvas.y;

    if (!ctrl_state && (_b == 1))
      {
          x = _x / d->scale - d->x;
          y = -(_y - eh - ey) / d->scale - d->y;
          gra_pre_draw_mouse_click(x, y);
      }

    if (!shift_state && !ctrl_state && (_b == 3))
      {
          menu_box_show(DUP("context.menu"), (double)_x + 1, (double)_y + 1, 1);
      }

    if (_b == 2)
        shell_drag_start(_x, _y);
    if (ctrl_state && (_b == 1))
        shell_zoom(_x, _y);
    if (ctrl_state && (_b == 3))
        shell_unzoom(_x, _y);     
}
コード例 #17
0
ファイル: hatchstyle.c プロジェクト: playya/Enlightenment
char               *
hs_get_line_style(int num)
{
    Eina_List          *l;
    HS_Item            *it;

    if (!hs_current)
        return NULL;

    for (l = hs_current->items; l; l = l->next)
      {
          it = (HS_Item *) l->data;
          if (!it)
              continue;
          if ((it->num == num) && (it->line_style))
              return DUP(it->line_style);
      }
    return NULL;
}
コード例 #18
0
bool Babylon::open()
{
  FILE *f;
  unsigned char buf[6];
  int i;

  f = g_fopen( m_filename.c_str(), "rb" );
  if( f == NULL )
    return false;

  i = fread( buf, 1, 6, f );

  /* First four bytes: BGL signature 0x12340001 or 0x12340002 (big-endian) */
  if( i < 6 || memcmp( buf, "\x12\x34\x00", 3 ) || buf[3] == 0 || buf[3] > 2 )
    return false;

  /* Calculate position of gz header */

  i = buf[4] << 8 | buf[5];

  if( i < 6 )
    return false;

  if( fseek( f, i, SEEK_SET ) ) /* can't seek - emulate */
      for(int j=0;j < i - 6;j++) fgetc( f );

  if( ferror( f ) || feof( f ) )
    return false;

  /* we need to flush the file because otherwise some nfs mounts don't seem
   * to properly update the file position for the following reopen */

  fflush( f );

  file = gzdopen( DUP( fileno( f ) ), "r" );
  if( file == NULL )
    return false;

  fclose( f );

  return true;
}
コード例 #19
0
ファイル: shell.c プロジェクト: playya/Enlightenment
	static void
engy_resize(Ecore_Evas * ee)
{
	Evas_Coord w, h;
	
	if (!shell->evas)
		return;
	
	evas_output_viewport_get(shell->evas, NULL, NULL, &w, &h);

	shell->w = (int)w;
	shell->h = (int)h;
	evas_object_resize(shell->o_bg, shell->w, shell->h);

        cl_configure(w,h);
        log_configure();
        info_configure();
        panel_configure();
        gui_put_string(DUP("_zoom_in|_zoom_out"));
}
コード例 #20
0
ファイル: esl_event.c プロジェクト: AaronZhangL/CC
static esl_event_header_t *new_header(const char *header_name)
{
	esl_event_header_t *header;

#ifdef ESL_EVENT_RECYCLE
		void *pop;
		if (esl_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == ESL_SUCCESS) {
			header = (esl_event_header_t *) pop;
		} else {
#endif
			header = ALLOC(sizeof(*header));
			esl_assert(header);
#ifdef ESL_EVENT_RECYCLE
		}
#endif	

		memset(header, 0, sizeof(*header));
		header->name = DUP(header_name);

		return header;

}
コード例 #21
0
ファイル: nacl_log.c プロジェクト: dsagal/native_client
/*
 * Setting the log stream buffering to fully buffered, so that the
 * write of the tag string will be less likely to be separated
 * from the write of the actual log message.
 */
static FILE *NaClLogDupFileIo(FILE *orig) {
  int  d;
  FILE *copy;

  /*
   * On windows (at least on a win7 machine which i tested on),
   * fileno(stderr) is -2.  I/O to the stderr stream appears to
   * succeed -- though who knows, maybe fclose(stderr) would actually
   * report an error? -- but DUP of -2 fails.  We don't try to detect
   * -2 (or other windows magic values) as a special case here, since
   * in the future other FILE* might be used here.  Instead, we just
   * check for DUP failure and trundle on as best as we could.
   */
  if (-1 == (d = DUP(fileno(orig)))) {
    copy = orig;
    /* this means that setvbuf later will affect the shared stream */
  } else if (NULL == (copy = FDOPEN(d, "a"))) {
    copy = orig;
    /* ditto */
  }
  (void) setvbuf(copy, (char *) NULL, _IOFBF, 1024);
  return copy;
}
コード例 #22
0
ファイル: esl_event.c プロジェクト: newfront/FreeSWITCH
static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t stack, const char *header_name, char *data)
{
	esl_event_header_t *header;
	esl_ssize_t hlen = -1;
	
	header = ALLOC(sizeof(*header));
	esl_assert(header);

	if ((event->flags & ESL_UNIQ_HEADERS)) {
		esl_event_del_header(event, header_name);
	}

	memset(header, 0, sizeof(*header));

	header->name = DUP(header_name);
	header->value = data;
	header->hash = esl_ci_hashfunc_default(header->name, &hlen);
	
	if (stack == ESL_STACK_TOP) {
		header->next = event->headers;
		event->headers = header;
		if (!event->last_header) {
			event->last_header = header;
		}
	} else {
		if (event->last_header) {
			event->last_header->next = header;
		} else {
			event->headers = header;
			header->next = NULL;
		}
		event->last_header = header;
	}

	return ESL_SUCCESS;
}
コード例 #23
0
ファイル: shell.c プロジェクト: playya/Enlightenment
void
shell_shutdown(void)
{
	E_DB_FLUSH;

	serv_put_string(DUP("__exit"));
	usleep(10000);
	gui_apply();
	alias_shutdown();
	cl_shutdown();
	menu_shutdown();
	panel_shutdown();
	drawing_free();

	if((long)shell->title_dcd != -1L)
		iconv_close(shell->title_dcd);

	if((long)shell->dcd != -1L)
		iconv_close(shell->dcd);


	ecore_evas_free(shell->ee);

	IF_FREE(shell->title);
	IF_FREE(shell->rcfile);
	IF_FREE(shell->menu_file);
	IF_FREE(shell->icons_file);
	IF_FREE(shell->dim_styles_file);
	IF_FREE(shell->text_styles_file);
	IF_FREE(shell->line_styles_file);
	IF_FREE(shell->point_styles_file);
	IF_FREE(shell->hatch_styles_file);
	IF_FREE(shell->home);
	IF_FREE(shell->aliases);

}
int main()
{
	{
		T x = HILO(5, 3);
		T y = __sync_add_and_fetch(&x, DUP(1));
		assert(y == HILO(6, 4));
		assert(x == HILO(6, 4));
		volatile T n = HILO(2, 1);
		if (emscripten_has_threading_support())
		{
			for(int i = 0; i < NUM_THREADS; ++i) pthread_create(&thread[i], NULL, thread_add_and_fetch, (void*)&n);
			for(int i = 0; i < NUM_THREADS; ++i) pthread_join(thread[i], NULL);
			printf("n: %llx\n", n);
			assert(n == HILO(NUM_THREADS*10000ULL+2ULL, NUM_THREADS*10000ULL+1ULL));
		}
	}
	{
		T x = HILO(15, 13);
		T y = __sync_sub_and_fetch(&x, HILO(10, 10));
		assert(y == HILO(5, 3));
		assert(x == HILO(5, 3));
		volatile T n = HILO(NUM_THREADS*10000ULL+5ULL, NUM_THREADS*10000ULL+3ULL);
		if (emscripten_has_threading_support())
		{
			for(int i = 0; i < NUM_THREADS; ++i) pthread_create(&thread[i], NULL, thread_sub_and_fetch, (void*)&n);
			for(int i = 0; i < NUM_THREADS; ++i) pthread_join(thread[i], NULL);
			printf("n: %llx\n", n);
			assert(n == HILO(5,3));
		}
	}
	{
		T x = HILO(32768 + 5, 5);
		T y = __sync_or_and_fetch(&x, HILO(65536 + 9, 9));
		assert(y == HILO(32768 + 65536 + 13, 13));
		assert(x == HILO(32768 + 65536 + 13, 13));
		for(int x = 0; x < 100; ++x) // Test a few times for robustness, since this test is so short-lived.
		{
			or_and_fetch_data = HILO(65536 + (1<<NUM_THREADS), 1<<NUM_THREADS);
			if (emscripten_has_threading_support())
			{
				for(int i = 0; i < NUM_THREADS; ++i)
				{
					threadArg[i] = DUP(1 << i);
					pthread_create(&thread[i], NULL, thread_or_and_fetch, (void*)&threadArg[i]);
				}
				for(int i = 0; i < NUM_THREADS; ++i) pthread_join(thread[i], NULL);
				assert(or_and_fetch_data == HILO(65536 + (1<<(NUM_THREADS+1))-1, (1<<(NUM_THREADS+1))-1));
			}
		}
	}
	{
		T x = HILO(32768 + 5, 5);
		T y = __sync_and_and_fetch(&x, HILO(32768 + 9, 9));
		assert(y == HILO(32768 + 1, 1));
		assert(x == HILO(32768 + 1, 1));
		if (emscripten_has_threading_support())
		{
			for(int x = 0; x < 100; ++x) // Test a few times for robustness, since this test is so short-lived.
			{
				and_and_fetch_data = HILO(65536 + (1<<(NUM_THREADS+1))-1, (1<<(NUM_THREADS+1))-1);
				for(int i = 0; i < NUM_THREADS; ++i)
				{
					threadArg[i] = DUP(~(1UL<<i));
					pthread_create(&thread[i], NULL, thread_and_and_fetch, (void*)&threadArg[i]);
				}
				for(int i = 0; i < NUM_THREADS; ++i) pthread_join(thread[i], NULL);
				assert(and_and_fetch_data == HILO(65536 + (1<<NUM_THREADS), 1<<NUM_THREADS));
			}
		}
	}
	{
		T x = HILO(32768 + 5, 5);
		T y = __sync_xor_and_fetch(&x, HILO(16384 + 9, 9));
		assert(y == HILO(32768 + 16384 + 12, 12));
		assert(x == HILO(32768 + 16384 + 12, 12));
		if (emscripten_has_threading_support())
		{
			for(int x = 0; x < 100; ++x) // Test a few times for robustness, since this test is so short-lived.
			{
				xor_and_fetch_data = HILO(32768 + (1<<NUM_THREADS), 1<<NUM_THREADS);
				for(int i = 0; i < NUM_THREADS; ++i)
				{
					threadArg[i] = DUP(~(1UL<<i));
					pthread_create(&thread[i], NULL, thread_xor_and_fetch, (void*)&threadArg[i]);
				}
				for(int i = 0; i < NUM_THREADS; ++i) pthread_join(thread[i], NULL);
				assert(xor_and_fetch_data == HILO(32768 + ((1<<(NUM_THREADS+1))-1), (1<<(NUM_THREADS+1))-1));
			}
		}
	}
// XXX NAND support does not exist in Atomics API.
#if 0
	{
		T x = 5;
		T y = __sync_nand_and_fetch(&x, 9);
		assert(y == 5);
		assert(x == -2);
		const int oddNThreads = NUM_THREADS-1;
		for(int x = 0; x < 100; ++x) // Test a few times for robustness, since this test is so short-lived.
		{
			nand_and_fetch_data = 0;
			for(int i = 0; i < oddNThreads; ++i) pthread_create(&thread[i], NULL, thread_nand_and_fetch, (void*)-1);
			for(int i = 0; i < oddNThreads; ++i) pthread_join(thread[i], NULL);
			assert(nand_and_fetch_data == -1);
		}
	}
#endif

#ifdef REPORT_RESULT
	REPORT_RESULT(0);
#endif
}
コード例 #25
0
ファイル: run.c プロジェクト: f0829/radare2
static int handle_redirection(const char *cmd, bool in, bool out, bool err) {
	if (!cmd || cmd[0] == '\0') {
		return 0;
	}

#if __APPLE__ && !__POWERPC__
	//XXX handle this in other layer since things changes a little bit
	//this seems like a really good place to refactor stuff
	return 0;
#endif
	if (cmd[0] == '"') {
#if __UNIX__
		if (in) {
			int pipes[2];
			if (pipe (pipes) != -1) {
				size_t cmdl = strlen (cmd)-2;
				if (write (pipes[1], cmd + 1, cmdl) != cmdl) {
					eprintf ("[ERROR] rarun2: Cannot write to the pipe\n");
					close (0);
					return 1;
				}
				if (write (pipes[1], "\n", 1) != 1) {
					eprintf ("[ERROR] rarun2: Cannot write to the pipe\n");
					close (0);
					return 1;
				}
				close (0);
				dup2 (pipes[0], 0);
			} else {
				eprintf ("[ERROR] rarun2: Cannot create pipe\n");
			}
		}
#else
#ifdef _MSC_VER
#pragma message ("string redirection handle not yet done")
#else
#warning quoted string redirection handle not yet done
#endif
#endif
		return 0;
	} else if (cmd[0] == '!') {
		// redirection to a process
		return handle_redirection_proc (cmd + 1, in, out, err);
	} else {
		// redirection to a file
		int f, flag = 0, mode = 0;
		flag |= in ? O_RDONLY : 0;
		flag |= out ? O_WRONLY | O_CREAT : 0;
		flag |= err ? O_WRONLY | O_CREAT : 0;
#ifdef __WINDOWS__
		mode = _S_IREAD | _S_IWRITE;
#else
		mode = S_IRUSR | S_IWUSR;
#endif
		f = open (cmd, flag, mode);
		if (f < 0) {
			eprintf ("[ERROR] rarun2: Cannot open: %s\n", cmd);
			return 1;
		}
#define DUP(x) { close(x); dup2(f,x); }
		if (in) {
			DUP(0);
		}
		if (out) {
			DUP(1);
		}
		if (err) {
			DUP(2);
		}
		close (f);
		return 0;
	}
}
コード例 #26
0
ファイル: conjgrad.c プロジェクト: 717524640/src
int main(int argc, char* argv[])
{
    int i, iter, niter, p[6][2], status, *mask;
    float *buf, *buf2, *wht;
    double rn, rnp, alpha, beta;
    pid_t pid[6]={1,1,1,1,1,1};
    off_t nm, nd, msiz, dsiz, pos;
    size_t nbuf, mbuf, dbuf;
    FILE *xfile, *Rfile, *gfile, *sfile, *Sfile;
    char *x, *R, *g, *s, *S, *prog;
    sf_file mod, dat, from, mwt, x0, known;  /* input */
    sf_file to, out; /* output */

    extern int fseeko(FILE *stream, off_t offset, int whence);
    extern off_t ftello (FILE *stream);

    sf_init(argc,argv);

    dat = sf_input("in");
    mod = sf_input("mod");

    if (SF_FLOAT != sf_gettype(mod) ||
	SF_FLOAT != sf_gettype(dat)) 
	sf_error("Need float type in mod and dat");

    for (i=0; i < argc-1; i++) {
	argv[i]=argv[i+1];
    }
    for (i=0; i < argc-1; i++) {	
	/* find the program to run */
	if (NULL == strchr(argv[i],'=')) {
	    /* first one without the '=' */
	    prog = argv[0];
	    argv[0] = argv[i];
	    argv[i] = prog;
	    break;
	}
    }

    argv[argc-1] = sf_charalloc(6);
    snprintf(argv[argc-1],6,"adj=X");

    if (!sf_getint("niter",&niter)) niter=1;
    /* number of iterations */

    Rfile = sf_tempfile(&R,"w+b"); 
    xfile = sf_tempfile(&x,"w+b"); 
    gfile = sf_tempfile(&g,"w+b");
    sfile = sf_tempfile(&s,"w+b");
    Sfile = sf_tempfile(&S,"w+b");

    fclose(Rfile);
    fclose(xfile);
    fclose(gfile);
    fclose(sfile);
    fclose(Sfile);

    nm = sf_filesize(mod);
    nd = sf_filesize(dat);

    /* I/O buffers */
    nbuf = BUFSIZ/sizeof(float);
    buf  = sf_floatalloc(nbuf);
    buf2 = sf_floatalloc(nbuf);

    if (NULL != sf_getstring("mwt")) {
	mwt = sf_input("mwt"); /* model weight */
	wht = sf_floatalloc(nbuf);
    } else {
	mwt = NULL;
	wht = NULL;
    }

    if (NULL != sf_getstring("known")) {
	known = sf_input("known"); /* known model mask */
	if (SF_INT != sf_gettype(known)) sf_error("Need int type in known");
	mask = sf_intalloc(nbuf);
    } else {
	known = NULL;
	mask = NULL;
    }

    if (NULL != sf_getstring("x0")) {
	x0 = sf_input("x0"); /* initial model */
    } else {
	x0 = NULL;
    }

    for (i=0; i < 6; i++) { /* make six pipes */
	if (pipe(p[i]) < 0) sf_error("pipe error:");
    }

    for (iter=0; iter < niter; iter++) {
	for (i=0; i < 6; i++) { /* fork six children */
	    if ((pid[i] = fork()) < 0) sf_error("fork error:");
	    if (0 == pid[i]) break;
	}
	
	if (0 == pid[0]) {	
	    /* feeds rr to p[0] */
	    close(p[0][0]);
	    close(STDOUT_FILENO);
	    DUP(p[0][1]);

	    to = sf_output("out");

	    if (0 == iter) {
		xfile = fopen(x,"wb");

		if (NULL == x0) {
		    for (i=0; i < nbuf; i++) { buf[i] = 0.0f; }
		}
		
		MLOOP( if (NULL != x0) sf_floatread(buf,mbuf,x0);
		       MWRITE(xfile); );
		
		fclose(xfile);

		Rfile = fopen(R,"wb");
		DLOOP( sf_floatread(buf,dbuf,dat); 
		       for (i=0; i < dbuf; i++) { buf[i] = -buf[i]; }
		       sf_floatwrite(buf,dbuf,to);
		       DWRITE (Rfile); );
コード例 #27
0
ファイル: esl_event.c プロジェクト: AaronZhangL/CC
static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t stack, const char *header_name, char *data)
{
	esl_event_header_t *header = NULL;
	esl_ssize_t hlen = -1;
	int exists = 0, fly = 0;
	char *index_ptr;
	int index = 0;
	char *real_header_name = NULL;

	if ((index_ptr = strchr(header_name, '['))) {
		index_ptr++;
		index = atoi(index_ptr);
		real_header_name = DUP(header_name);
		if ((index_ptr = strchr(real_header_name, '['))) {
			*index_ptr++ = '\0';
		}
		header_name = real_header_name;
	}
	
	if (index_ptr || (stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT)) {
		
		if (!(header = esl_event_get_header_ptr(event, header_name)) && index_ptr) {

			header = new_header(header_name);

			if (esl_test_flag(event, ESL_EF_UNIQ_HEADERS)) {
				esl_event_del_header(event, header_name);
			}

			fly++;
		}
		
		if ((header = esl_event_get_header_ptr(event, header_name))) {
			
			if (index_ptr) {
				if (index > -1 && index <= 4000) {
					if (index < header->idx) {
						FREE(header->array[index]);
						header->array[index] = DUP(data);
					} else {
						int i;
						char **m;
					
						m = realloc(header->array, sizeof(char *) * (index + 1));
						esl_assert(m);
						header->array = m;
						for (i = header->idx; i < index; i++) {
							m[i] = DUP("");
						}
						m[index] = DUP(data);
						header->idx = index + 1;
						if (!fly) {
							exists = 1;
						}

						goto redraw;
					}
				}
				goto end;
			} else {
				if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT)) {
					exists++;
					stack &= ~(ESL_STACK_TOP | ESL_STACK_BOTTOM);
				} else {
					header = NULL;
				}
			}
		}
	}


	if (!header) {

		if (esl_strlen_zero(data)) {
			esl_event_del_header(event, header_name);
			FREE(data);
			goto end;
		}

		if (esl_test_flag(event, ESL_EF_UNIQ_HEADERS)) {
			esl_event_del_header(event, header_name);
		}

		if (strstr(data, "ARRAY::")) {
			esl_event_add_array(event, header_name, data);
			FREE(data);
			goto end;
		}


		header = new_header(header_name);
	}
	
	if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT)) {
		char **m = NULL;
		esl_size_t len = 0;
		char *hv;
		int i = 0, j = 0;

		if (header->value && !header->idx) {
			m = malloc(sizeof(char *));
			esl_assert(m);
			m[0] = header->value;
			header->value = NULL;
			header->array = m;
			header->idx++;
			m = NULL;
		}

		i = header->idx + 1;
		m = realloc(header->array, sizeof(char *) * i); 
		esl_assert(m);

		if ((stack & ESL_STACK_PUSH)) {
			m[header->idx] = data;
		} else if ((stack & ESL_STACK_UNSHIFT)) {
			for (j = header->idx; j > 0; j--) {
				m[j] = m[j-1];
			}
			m[0] = data;
		}

		header->idx++;		
		header->array = m;

	redraw:
		len = 0;
		for(j = 0; j < header->idx; j++) {
			len += strlen(header->array[j]) + 2;
		}

		if (len) {
			len += 8;
			hv = realloc(header->value, len);
			esl_assert(hv);
			header->value = hv;

			esl_snprintf(header->value, len, "ARRAY::");
			for(j = 0; j < header->idx; j++) {
				esl_snprintf(header->value + strlen(header->value), len - strlen(header->value), "%s%s", j == 0 ? "" : "|:", header->array[j]);
			}
		}

	} else {
		header->value = data;
	}

	if (!exists) {
		header->hash = esl_ci_hashfunc_default(header->name, &hlen);

		if ((stack & ESL_STACK_TOP)) {
			header->next = event->headers;
			event->headers = header;
			if (!event->last_header) {
				event->last_header = header;
			}
		} else {
			if (event->last_header) {
				event->last_header->next = header;
			} else {
				event->headers = header;
				header->next = NULL;
			}
			event->last_header = header;
		}
	}

 end:

	esl_safe_free(real_header_name);

	return ESL_SUCCESS;
}
コード例 #28
0
ファイル: brw_metaops.c プロジェクト: astrofimov/vgallium
static void init_attribs( struct brw_context *brw )
{
   DUP(brw, gl_colorbuffer_attrib, Color);
   DUP(brw, gl_depthbuffer_attrib, Depth);
   DUP(brw, gl_fog_attrib, Fog);
   DUP(brw, gl_hint_attrib, Hint);
   DUP(brw, gl_light_attrib, Light);
   DUP(brw, gl_line_attrib, Line);
   DUP(brw, gl_point_attrib, Point);
   DUP(brw, gl_polygon_attrib, Polygon);
   DUP(brw, gl_scissor_attrib, Scissor);
   DUP(brw, gl_stencil_attrib, Stencil);
   DUP(brw, gl_texture_attrib, Texture);
   DUP(brw, gl_transform_attrib, Transform);
   DUP(brw, gl_viewport_attrib, Viewport);
   DUP(brw, gl_vertex_program_state, VertexProgram);
   DUP(brw, gl_fragment_program_state, FragmentProgram);
}
コード例 #29
0
ファイル: dottest.c プロジェクト: 1014511134/src
int main(int argc, char* argv[])
{
    int p[4][2], i, im, id, status;
    unsigned long mseed, dseed;
    off_t nm, nd, msiz, dsiz;
    size_t nbuf, mbuf, dbuf;
    float *buf;
    double dp;
    pid_t pid[6]={1,1,1,1,1,1};
    sf_file mod=NULL;
    sf_file dat=NULL;
    sf_file pip=NULL;

    sf_init(argc,argv);

    mod = sf_input("mod");
    dat = sf_input("dat");

    if (SF_FLOAT != sf_gettype(mod) ||
	SF_FLOAT != sf_gettype(dat))
	sf_error("Need float type in mod and dat");

    nm = sf_filesize(mod);
    nd = sf_filesize(dat);

    nbuf = BUFSIZ/sizeof(float);
    buf = sf_floatalloc(nbuf);

    mseed = (unsigned long) time(NULL);
    init_genrand(mseed);
    mseed = genrand_int32();
    dseed = genrand_int32();

    for (i=0; i < argc-1; i++) {
	argv[i]=argv[i+1];
    }
    argv[argc-1] = sf_charalloc(6);
    snprintf(argv[argc-1],6,"adj=X");

    for (i=0; i < 4; i++) { /* make four pipes */
	if (pipe(p[i]) < 0) sf_error("pipe error:");
    }

    for (i=0; i < 6; i++) { /* fork six children */
	if ((pid[i] = fork()) < 0) sf_error("fork error:");
	if (0 == pid[i]) break;
    }

    if (0 == pid[0]) {	
	/* makes random model and writes it to p[0] */

	close(p[0][0]);
	close(STDOUT_FILENO);
	DUP(p[0][1]);

	pip = sf_output("out");
	sf_fileflush(pip,mod);

	init_genrand(mseed);
	for (msiz=nm, mbuf=nbuf; msiz > 0; msiz -= mbuf) {
	    if (msiz < mbuf) mbuf=msiz;

	    sf_random(mbuf,buf);

	    sf_floatwrite(buf,mbuf,pip);
	}
    } 

    if (0 == pid[1]) {
	/* reads from p[0], runs the program, and writes to p[1] */

	close(p[0][1]);
	close(STDIN_FILENO);
	DUP(p[0][0]);

	close(p[1][0]);
	close(STDOUT_FILENO);
	DUP(p[1][1]);

	argv[argc-1][4]='0';
	execvp(argv[0],argv);

	_exit(1);
    }

    if (0 == pid[2]) {
	/* reads from p[1] and multiplies it with random data */
	
	close(p[1][1]);
	close(STDIN_FILENO);
	DUP(p[1][0]);

	pip = sf_input("in");

	init_genrand(dseed);
	dp = 0.;
	for (dsiz=nd, dbuf=nbuf; dsiz > 0; dsiz -= dbuf) {
	    if (dsiz < dbuf) dbuf=dsiz;

	    sf_floatread(buf,dbuf,pip);
	    for (id=0; id < dbuf; id++) {
		dp += buf[id]*genrand_real1 ();
	    }	
	}
	sf_warning(" L[m]*d=%g",dp);

	_exit(2);
    }

    if (0 == pid[3]) {	
	/* makes random data and writes it to p[2] */

	close(p[2][0]);
	close(STDOUT_FILENO);
	DUP(p[2][1]);

	pip = sf_output("out");
	sf_fileflush(pip,dat);

	init_genrand(dseed);
	for (dsiz=nd, dbuf=nbuf; dsiz > 0; dsiz -= dbuf) {
	    if (dsiz < dbuf) dbuf=dsiz;

	    sf_random(dbuf,buf);

	    sf_floatwrite(buf,dbuf,pip);
	}
    } 

    if (0 == pid[4]) {
	/* reads from p[2], runs the adjoint, and writes to p[3] */

	close(p[2][1]);
	close(STDIN_FILENO);
	DUP(p[2][0]);

	close(p[3][0]);
	close(STDOUT_FILENO);
	DUP(p[3][1]);

	argv[argc-1][4]='1';
	execvp(argv[0],argv);

	_exit(4);
    }

    if (0 == pid[5]) {
	/* reads from p[3] and multiplies it with random model */
	
	close(p[3][1]);
	close(STDIN_FILENO);
	DUP(p[3][0]);

	pip = sf_input("in");

	init_genrand(mseed);
	dp = 0.;
	for (msiz=nm, mbuf=nbuf; msiz > 0; msiz -= mbuf) {
	    if (msiz < mbuf) mbuf=msiz;

	    sf_floatread(buf,mbuf,pip);


	    for (im=0; im < mbuf; im++) {
		dp += buf[im]*genrand_real1 ();
	    }	
	}
	sf_warning("L'[d]*m=%g",dp);
	
	_exit(5);
    }

    for (i=0; i < 6; i++) {
	if (0 == pid[i]) break;
    }

    if (6==i) {
	/* parent waits */
	waitpid(pid[2],&status,0);
	waitpid(pid[5],&status,0);
    
	exit(0);
    }
}
コード例 #30
0
ファイル: esl_event.c プロジェクト: icblenke/FreeSWITCH-qmod
static esl_status_t esl_event_base_add_header(esl_event_t *event, esl_stack_t stack, const char *header_name, char *data)
{
	esl_event_header_t *header = NULL;
	esl_ssize_t hlen = -1;
	int exists = 0;
	
	if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT) || esl_test_flag(event, ESL_EF_CONTAINS_ARRAYS)) {

		if ((header = esl_event_get_header_ptr(event, header_name))) {
			
			if (!(stack & ESL_STACK_PUSH) && !(stack & ESL_STACK_UNSHIFT) && header->idx) {
				stack |= ESL_STACK_PUSH;
			}

			if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT)) {
				exists++;
				stack &= ~(ESL_STACK_TOP | ESL_STACK_BOTTOM);
			} else {
				header = NULL;
			}
		}
	}

	if (!header) {

#ifdef ESL_EVENT_RECYCLE
		void *pop;
		if (esl_queue_trypop(EVENT_HEADER_RECYCLE_QUEUE, &pop) == ESL_SUCCESS) {
			header = (esl_event_header_t *) pop;
		} else {
#endif
			header = ALLOC(sizeof(*header));
			esl_assert(header);
#ifdef ESL_EVENT_RECYCLE
		}
#endif
	

		if (esl_test_flag(event, ESL_EF_UNIQ_HEADERS)) {
			esl_event_del_header(event, header_name);
		}

		memset(header, 0, sizeof(*header));

		header->name = DUP(header_name);
	}
	
	if ((stack & ESL_STACK_PUSH) || (stack & ESL_STACK_UNSHIFT)) {
		char **m = NULL;
		esl_size_t len = 0;
		char *hv;
		int i = 0, j = 0;

		esl_set_flag(event, ESL_EF_CONTAINS_ARRAYS);

		if (header->value && !header->idx) {
			m = malloc(sizeof(char *));
			esl_assert(m);
			m[0] = header->value;
			header->value = NULL;
			header->array = m;
			header->idx++;
			m = NULL;
		}

		i = header->idx + 1;
		m = realloc(header->array, sizeof(char *) * i); 
		esl_assert(m);

		if ((stack & ESL_STACK_PUSH)) {
			m[header->idx] = data;
		} else if ((stack & ESL_STACK_UNSHIFT)) {
			for (j = header->idx; j > 0; j--) {
				m[j] = m[j-1];
			}
			m[0] = data;
		}

		header->idx++;		
		header->array = m;

		for(j = 0; j < header->idx; j++) {
			len += strlen(header->array[j]) + 2;
		}

		if (len) {
			len += 8;
			hv = realloc(header->value, len);
			esl_assert(hv);
			header->value = hv;
			esl_snprintf(header->value, len, "ARRAY::");
			for(j = 0; j < header->idx; j++) {
				esl_snprintf(header->value + strlen(header->value), len - strlen(header->value), "%s%s", j == 0 ? "" : "::", header->array[j]);
			}
		}

	} else {
		header->value = data;
	}

	if (!exists) {
		header->hash = esl_ci_hashfunc_default(header->name, &hlen);

		if ((stack & ESL_STACK_TOP)) {
			header->next = event->headers;
			event->headers = header;
			if (!event->last_header) {
				event->last_header = header;
			}
		} else {
			if (event->last_header) {
				event->last_header->next = header;
			} else {
				event->headers = header;
				header->next = NULL;
			}
			event->last_header = header;
		}
	}

	return ESL_SUCCESS;
}