Exemplo n.º 1
0
mxml_node * node_identify( void * doc, const mxml_char_t * str, parsing_context *ctx )
{	
	mxml_node * doc_node = (mxml_node *)doc;
	mxml_node * ident_node = NULL;

	UNUSED_ARG( ctx );

	if ( !doc_node )
		return NULL;
	
	if ( is_declaration ( str ) )
		ident_node = create_declaration( doc_node );
	else if ( is_comment( str ) )
		ident_node = create_comment( doc_node );
	else if ( is_unknown( str ) )
		ident_node = create_unknown( doc_node );
	else if ( is_element( str ) )
		ident_node = create_element( XML_T(""), doc_node );
	else if ( is_text( str ) )
		ident_node = create_text( doc_node );
	else 
		ident_node = create_unknown( doc_node );

	return ident_node;
}
Exemplo n.º 2
0
CL_CSSLayoutText CL_CSSLayoutNode::to_text() const
{
	if (is_text())
		return CL_CSSLayoutText(impl);
	else
		return CL_CSSLayoutText();
}
static inline const char *reason_phrase_end (const char *start, const char *end){
	if(start){
		while((start<end) && (is_text(*start))){
			start++;
		}
		if((start+2 <= end) && (*start++ == RTSP_CR) && (*start++ == RTSP_LF)){
			return (start);
		} else {
			return (NULL);
		}
	}
	return (NULL);
}
Exemplo n.º 4
0
int main(int argc, char *argv[]){
int i, n, count;
struct stat s;
FILE *stream, *new;
char *buf;
size_t size=BUFSIZ;


i=lstat(argv[1], &s);
if(i!=0){
  fprintf(stderr, "Error : stat - %s\n", strerror(errno));
	return -1;
}

if(S_ISREG(s.st_mode)){
  stream=fopen(argv[1], "r");
  if(stream==NULL){
    fprintf(stderr, "Error : open - %s\n", strerror(errno));
    return -1;
  }
  if(is_text(stream)){
    rewind(stream);
    n=atoi(argv[2]);
    count=0;
    buf=(char *)malloc(BUFSIZ + 1);
    for(i=0;i<n;i++){
      count=getline(&buf,&size,stream);
      if(count == -1) {
        printf("Il file ha meno di n linee\n");
        exit(1);
      }
      count--;//non conto anche \n come carattere
    }
    free(buf);
    buf=NULL;
    printf("%d\n",count );
  }else{
    printf("Non è un file di testo\n" );
  }

  }else{

    printf("Non è un file regolare\n" );
  }

  return 0;
  }
Exemplo n.º 5
0
	DomText DomNode::to_text() const
	{
		if (is_text())
			return DomText(impl);
		return DomText();
	}
Exemplo n.º 6
0
size_t
print_output(unsigned char *str,
	     size_t slen)
{
    size_t len;
    

    len = 0;
    
    if (str == NULL)
    {
	printf("NULL");
	return len;
    }

    if (is_text(str, slen))
    {
	printf("TXT : ");
    
	while (len < slen && len < maxlen)
	{
	    if (isprint(* (unsigned char *) str))
		putchar(*str);
	    else
		switch (*str)
		{
		  case '\0':
		    printf("\\0");
		    break;
		    
		  case '\n':
		    if (line_f)
			return len;
		    printf("\\n");
		    break;
		    
		  case '\r':
		    if (line_f)
			return len;
		    printf("\\r");
		    break;
		    
		  case '\t':
		    printf("\\t");
		    break;
		    
		  default:
		    printf("\\x%02x", * (unsigned char *) str);
		}

	    ++len;
	    ++str;
	}
    }
    
    else
    {
	printf("HEX :");
	while (len < slen && len < maxlen)
	{
	    printf(" %02x", * (unsigned char *) str);
	    ++len;
	    ++str;
	}
    }

    return len;
}
/** 
 * @brief - Decoding string line as a status line
 * 
 * @param p_start_line
 * @param rtsp_msg_buffer
 * @param rtsp_msg_len
 * 
 * @return 
 */
static inline rtsp_error_t rtsp_parse_status_line(rtsp_start_line_t *p_start_line,const char *rtsp_msg_buffer, int32_t rtsp_msg_len , const char **endptr){

	const char *parse_string = NULL, *end = NULL, *temp = NULL;
	rtsp_error_t e_ret_val = RTSP_E_FAILURE;

	if(!p_start_line || !rtsp_msg_buffer || rtsp_msg_len <= 0){
		return (RTSP_E_INVALID_ARG);
	}
	/* R[7.1]
	 * Status-Line = RTSP-Version SP Status-Code SP Reason-Phrase CRLF
	 * Allowing multiple SP since RFC Text R[7.1] suggests
	 */

	parse_string = rtsp_msg_buffer;
	end = rtsp_msg_buffer + rtsp_msg_len;
	/* RTSP-Version */
	e_ret_val = rtsp_get_version(&p_start_line->version, parse_string, rtsp_msg_len, &parse_string);

	switch (e_ret_val){
	case RTSP_E_SUCCESS:
		/* Found Version String  Start Hence it is status line */ 
		p_start_line->msg_type = RTSP_MSG_RESPONSE;

		/* SP */
		temp = skip_SP(parse_string, end);
		if((NULL == temp) || (temp==parse_string)){
			/* No spaces */
			e_ret_val = RTSP_E_FAILURE;
		}else if(temp == end){
			/* Only spaces till end */
			e_ret_val = RTSP_E_INCOMPLETE;
			break;
		}
		parse_string = temp;

		/* Status-Code */
		if((parse_string + RTSP_STATUS_CODE_LEN) <= end){
			if(0 == (p_start_line->response.status_code = RTSP_STATUS_CODE(parse_string))){
				e_ret_val = RTSP_E_FAILURE;
				break;
			}
		} else {
			e_ret_val = RTSP_E_INCOMPLETE;
			break;
		}
		parse_string += RTSP_STATUS_CODE_LEN;

		/* SP */
		temp = skip_SP(parse_string, end);
		if((NULL == temp) || (temp==parse_string)){
			/* No spaces */
			e_ret_val = RTSP_E_FAILURE;
		}else if(temp==end){
			/* Only spaces till end */
			e_ret_val = RTSP_E_INCOMPLETE;
			break;
		}
		parse_string = temp;

		/* Reason-Phrase */

		p_start_line->response.reason_phrase = parse_string;
		while((parse_string <= end) && is_text(*parse_string))
			parse_string++;
			;
		/* CRLF */
		if((parse_string+1) <= end){
			if(RTSP_CR == *parse_string++ && RTSP_LF ==*parse_string++){
				p_start_line->response.reason_len = (int32_t)((rtsp_msg_buffer - parse_string)+ rtsp_msg_len);
			} else {
				e_ret_val = RTSP_E_FAILURE;
				break;
			}
		} else {
			e_ret_val = RTSP_E_INCOMPLETE;
			break;
		}

		if(endptr)
			*endptr = parse_string;
		e_ret_val = RTSP_E_SUCCESS;
		break;
	case RTSP_E_UNSUPPORTED:
		/* Version Not supported */
	case RTSP_E_FAILURE:
	default:
		/* Must Be Request-Line */
		break;
	}
	return (e_ret_val);
}
Exemplo n.º 8
0
void *_festival_speak(void *nothing)
{

	int ret;
	int bytes;
	int wave_cached;
	FT_Wave *fwave;
	int debug_count = 0;
	int r;
	int terminate = 0;

	char *callback;

	log_msg(OTTS_LOG_INFO, "festival: speaking thread starting.......\n");

	cache_init();

	set_speaking_thread_parameters();

	while (1) {
sem_wait:
		sem_wait(festival_semaphore);
		log_msg(OTTS_LOG_DEBUG, "Semaphore on, speaking\n");

		opentts_audio_set_volume(module_audio_id, festival_volume);

		festival_stopped = 0;
		festival_speaking = 1;
		wave_cached = 0;
		fwave = NULL;

		terminate = 0;

		bytes = strlen(*festival_message);

		module_report_event_begin();

		log_msg(OTTS_LOG_INFO, "Going to synthesize: |%s|",
			*festival_message);
		if (bytes > 0) {
			if (!is_text(festival_message_type)) {	/* it is a raw text */
				log_msg(OTTS_LOG_INFO, "Cache mechanisms...");
				fwave =
				    cache_lookup(*festival_message,
						 festival_message_type, 1);
				if (fwave != NULL) {
					wave_cached = 1;
					if (fwave->num_samples != 0) {
						if (FestivalDebugSaveOutput) {
							char filename_debug
							    [256];
							sprintf(filename_debug,
								"/tmp/debug-festival-%d.snd",
								debug_count++);
							save_FT_Wave_snd(fwave,
									 filename_debug);
						}

						festival_send_to_audio(fwave);

						if (!festival_stopped) {
							CLEAN_UP(0,
								 module_report_event_end);
						} else {
							CLEAN_UP(0,
								 module_report_event_stop);
						}

					} else {
						CLEAN_UP(0,
							 module_report_event_end);
					}
				}
			}

			/*  Set multi-mode for appropriate kind of events */
			if (is_text(festival_message_type)) {	/* it is a raw text */
				ret = FestivalSetMultiMode(festival_info, "t");
				if (ret != 0)
					CLP(0, module_report_event_stop);
			} else {	/* it is some kind of event */
				ret =
				    FestivalSetMultiMode(festival_info, "nil");
				if (ret != 0)
					CLP(0, module_report_event_stop);
			}

			switch (festival_message_type) {
			case SPD_MSGTYPE_TEXT:
				r = festivalStringToWaveRequest(festival_info,
								*festival_message);
				break;
			case SPD_MSGTYPE_SOUND_ICON:
				r = festivalSoundIcon(festival_info,
						      *festival_message);
				break;
			case SPD_MSGTYPE_CHAR:
				r = festivalCharacter(festival_info,
						      *festival_message);
				break;
			case SPD_MSGTYPE_KEY:
				r = festivalKey(festival_info,
						*festival_message);
				break;
			case SPD_MSGTYPE_SPELL:
				r = festivalSpell(festival_info,
						  *festival_message);
				break;
			default:
				r = -1;
			}
			if (r < 0) {
				log_msg(OTTS_LOG_WARN,
					"Couldn't process the request to say the object.");
				CLP(0, module_report_event_stop);
			}
		}

		while (1) {

			wave_cached = 0;
			log_msg(OTTS_LOG_INFO, "Retrieving data\n");

			/* (speechd-next) */
			if (is_text(festival_message_type)) {

				if (festival_stopped) {
					log_msg(OTTS_LOG_INFO,
						"Module stopped 1");
					CLEAN_UP(0, module_report_event_stop);
				}

				log_msg(OTTS_LOG_INFO,
					"Getting data in multi mode");
				fwave =
				    festivalGetDataMulti(festival_info,
							 &callback,
							 &festival_stop_request,
							 FestivalReopenSocket);

				if (callback != NULL) {
					if ((festival_pause_requested)
					    &&
					    (!strncmp
					     (callback, INDEX_MARK_BODY,
					      INDEX_MARK_BODY_LEN))) {
						log_msg(OTTS_LOG_NOTICE,
							"Pause requested, pausing.");
						module_report_index_mark
						    (callback);
						g_free(callback);
						festival_pause_requested = 0;
						CLEAN_UP(0,
							 module_report_event_pause);
					} else {
						module_report_index_mark
						    (callback);
						g_free(callback);
						continue;
					}
				}
			} else {	/* is event */
				log_msg(OTTS_LOG_INFO,
					"Getting data in single mode");
				fwave =
				    festivalStringToWaveGetData(festival_info);
				terminate = 1;
				callback = NULL;
			}

			if (fwave == NULL) {
				log_msg(OTTS_LOG_INFO,
					"End of sound samples, terminating this message...");
				CLEAN_UP(0, module_report_event_end);
			}

			if (festival_message_type == SPD_MSGTYPE_CHAR
			    || festival_message_type == SPD_MSGTYPE_KEY
			    || festival_message_type ==
			    SPD_MSGTYPE_SOUND_ICON) {
				log_msg(OTTS_LOG_DEBUG,
					"Storing record for %s in cache\n",
					*festival_message);
				/* cache_insert takes care of not inserting the same
				   message again */
				cache_insert(g_strdup(*festival_message),
					     festival_message_type, fwave);
				wave_cached = 1;
			}

			if (festival_stopped) {
				log_msg(OTTS_LOG_NOTICE, "Module stopped 2");
				CLEAN_UP(0, module_report_event_stop);
			}

			if (fwave->num_samples != 0) {
				log_msg(OTTS_LOG_INFO,
					"Sending message to audio: %ld bytes\n",
					(fwave->num_samples) * sizeof(short));

				if (FestivalDebugSaveOutput) {
					char filename_debug[256];
					sprintf(filename_debug,
						"/tmp/debug-festival-%d.snd",
						debug_count++);
					save_FT_Wave_snd(fwave, filename_debug);
				}

				log_msg(OTTS_LOG_INFO, "Playing sound samples");
				festival_send_to_audio(fwave);

				if (!wave_cached)
					delete_FT_Wave(fwave);
				log_msg(OTTS_LOG_NOTICE,
					"End of playing sound samples");
			}

			if (terminate) {
				log_msg(OTTS_LOG_INFO,
					"Ok, end of samples, returning");
				CLP(0, module_report_event_end);
			}

			if (festival_stopped) {
				log_msg(OTTS_LOG_NOTICE, "Module stopped 3");
				CLP(0, module_report_event_stop);
			}
		}

	}

	festival_stopped = 0;
	festival_speaking = 0;

	log_msg(OTTS_LOG_INFO, "festival: speaking thread ended.......\n");

	pthread_exit(NULL);
}