Beispiel #1
0
file_t * create_file(char * where, char * filename) {
	file_t * file = malloc(sizeof(file_t));
	file->term = init_term();
	file->buff = init_buff();
	file->modbuff = init_buff();
	file->rend = init_renderer();
	file->path = where;
	file->filename = filename;
	file->size = 0;
	file->is_modal = 0;

	init_keys();
	init_func(file);
	return file;
}
Beispiel #2
0
/*
**  Name:	void el1_init(dpeth_t *dep)
**  Function:	Initalizes board hardware and driver data structures.
*/
static void el1_init(dpeth_t * dep)
{
  int ix;

  dep->de_irq &= NOT(DEI_DEFAULT);	/* Strip the default flag. */
  dep->de_offset_page = 0;
  dep->de_data_port = dep->de_base_port + EL1_DATAPORT;

  el1_reset(dep);		/* Reset and initialize board */

  /* Start receiver (default mode) */
  outw_el1(dep, EL1_RECVPTR, 0);
  outb_el1(dep, EL1_CSR, ECSR_RIDE | ECSR_RECV);

  /* Initializes buffer pool */
  init_buff(dep, NULL);
  el1_mode_init(dep);

  printf("%s: Etherlink (%s) at %X:%d - ",
         dep->de_name, "3c501", dep->de_base_port, dep->de_irq);
  for (ix = 0; ix < SA_ADDR_LEN; ix += 1)
	printf("%02X%c", (dep->de_address.ea_addr[ix] = StationAddress[ix]),
	       ix < SA_ADDR_LEN - 1 ? ':' : '\n');

  /* Device specific functions */
  dep->de_recvf = el1_recv;
  dep->de_sendf = el1_send;
  dep->de_flagsf = el1_mode_init;
  dep->de_resetf = el1_reset;
  dep->de_getstatsf = el1_getstats;
  dep->de_dumpstatsf = el1_dumpstats;
  dep->de_interruptf = el1_interrupt;

  return;			/* Done */
}
Beispiel #3
0
void
delete_line(void)
{
    int count;

    /*** deletes the entire line                                 *****/

    if (buff_pntr == 0)
        return;                 /** There is nothing to do **/

    /** first I have to back up to the beginning of the line     ****/
    for (count = curr_pntr; count > 0; count--)
        myputchar(_BKSPC);

    /** blank over the end of the line      ***/
    for (count = 0; count < buff_pntr; count++) {
        myputchar(_BLANK);
    }
    /** back up again ***/
    for (count = buff_pntr; count > 0; count--)
        myputchar(_BKSPC);

    /* Also clear the buffer */
    init_buff(buff, buff_pntr);
    init_flag(buff_flag, buff_pntr);
    buff_pntr = curr_pntr = 0;

    fflush(stdout);
    return;

}
Beispiel #4
0
void k_merge_sort(char *ofname, char **fnames) {
    init_buff(ofname, fnames);
    int i=0; 
    for(; i<K; ++i) {
        input(i, BUFF_SIZE);
        // first step
        losertree.nodes[i] = pop_head(i);
    }
    build_loser_tree();
    // sort
    datatype winner_data;
    index_type winner = losertree.losers[0];
    datatype nextdata;
    while(1) {
        winner = losertree.losers[0];
        winner_data = losertree.nodes[winner];
        if(strcmp(winner_data, MAX_DATA) == 0) break;
        // save it to out_buff
        append_output_buff(winner_data);
        // get next data
        nextdata = pop_head(winner);
        losertree.nodes[winner] = nextdata;
        adjust_loser_tree(winner);
    }
    flush_output_buff();
}
Beispiel #5
0
int main () {
    pthread_t threads[NUM_THREADS];
    int rc, t;

    float standart;
    float input_value = 5;
    init_buff(&global_buff, input_value);//заполняем буфер 
    for(t = 0; t < NUM_THREADS; t++) {
        printf("In main: creating thread %d\n", t);
        rc = pthread_create(&threads[t], NULL, work_loop, NULL);
        if (rc) {
            printf("ERROR; return code from pthread_create() is %d\n", rc);
            exit(-1);
        }
    }

    for(t = 0; t < NUM_THREADS; t++) {
        pthread_join(threads[t], NULL);
        printf("Thread #%d finished\n", t);
    }
    
    standart = input_value;
    calculate(&standart);
    //global_buff[5] = 0;//вносим ошибку
    if(check_buff(global_buff, standart)) {
        printf("check: SUCCESS\n");
    }
    else {
        printf("check: FAIL\n");
    }
return 0;
}
Beispiel #6
0
QStringList Countries::countries()
{
    init_buff();
    QStringList res = p->data.keys();
    res.sort();
    return res;
}
static int OutBufferInit(aml_audio_dec_t *audec)
{
    g_bst=malloc(sizeof(buffer_stream_t));
    if(!g_bst)
    {
        adec_print("===g_bst malloc failed! \n");
        g_bst=NULL;
        return -1;
    }
    if(audec->adec_ops->nOutBufSize<=0) //set default if not set
        audec->adec_ops->nOutBufSize=DEFAULT_PCM_BUFFER_SIZE;
    int ret=init_buff(g_bst,audec->adec_ops->nOutBufSize);
    if(ret==-1)
    {
        adec_print("=====pcm buffer init failed !\n");
        return -1;
    }

    g_bst->data_width=audec->data_width=AV_SAMPLE_FMT_S16;
     if(audec->channels>0)
        g_bst->channels=audec->channels;
    else
        g_bst->channels=audec->channels=2;
    if(audec->samplerate>0)
        g_bst->samplerate=audec->samplerate;
    else
        g_bst->samplerate=audec->samplerate=48000;
    adec_print("=====pcm buffer init ok buf_size:%d\n",g_bst->buf_length);
    
    return 0;
}
Beispiel #8
0
void
clear_buff(void)
{
    int count;

    /*** called when spadbuf gives me a line incase there is something already
      on the line ****/
    if (buff_pntr > 0) {
        /*** backup to the beginning of the line ***/
        for (count = curr_pntr; count > 0; count--)
            myputchar(_BKSPC);
        /** blank over the line      ***/
        for (count = 0; count < buff_pntr; count++) {
            myputchar(_BLANK);
        }
        /** back up again ***/
        for (count = buff_pntr; count > 0; count--)
            myputchar(_BKSPC);
        init_buff(buff, buff_pntr);
        init_flag(buff_flag, buff_pntr);
        curr_pntr = buff_pntr = 0;
    }
}
Beispiel #9
0
AsemanCountriesModel::AsemanCountriesModel(QObject *parent)
    : QAbstractListModel(parent)
{
    p = new AsemanCountriesModelPrivate;
    init_buff();
}
Beispiel #10
0
QString Countries::countryFlag(const QString &country)
{
    init_buff();
    return FLAGS_PATH + p->data[country]["cca2"].toLower() + ".png";
}
Beispiel #11
0
QString Countries::phoneCode(const QString &country)
{
    init_buff();
    return p->data[country]["callingCode"];
}
static void *adec_armdec_loop(void *args)
{
    int ret;
	int rlen = 0;
	int inlen = 0;
	int dlen = 0;
	int declen = 0;
    aml_audio_dec_t *audec;
    audio_out_operations_t *aout_ops;
    adec_cmd_t *msg = NULL;
	AVPacket apkt;
	char *inbuf = NULL;
	char apkt_end[APACKET_END_SIZE];
	char outbuf[AVCODEC_MAX_AUDIO_FRAME_SIZE];
	int outlen = 0;
	AVCodecContext *ctxCodec = NULL;
	AVCodec *acodec = NULL;
	int in_ape_fp = -1;
	int out_ape_fp = -1;
	int audio_handle = -1;
	
	adec_print("adec_armdec_loop start!\n");

	audec = (aml_audio_dec_t *)args;
    aout_ops = &audec->aout_ops;
	av_init_packet(&apkt); 
	//memset(inbuf, 0, READ_ABUFFER_SIZE);
	memset(outbuf, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE);

	//buffer_stream_t init and set adsp_ops param
	audec->bs=malloc(sizeof(buffer_stream_t));
	int ret_value=init_buff(audec->bs);
	if(ret_value==1)
		adec_print("=====pcm buffer init ok buf_size:%d buf_data:0x%x  end:0x%x !\n",audec->bs->buf_length,audec->bs->data,audec->bs->data+1024*1024);
	audec->adsp_ops.dsp_on=1;
	aout_ops->init(audec);
	aout_ops->start(audec);

	ctxCodec = avcodec_alloc_context();
	if(!ctxCodec) {
		adec_print("APE AVCodecContext allocate error!\n");
		ctxCodec = NULL;
	}
	adec_print("ctxCodec!\n");

	
	adec_print("adec_armdec_loop   audec->pcodec = %d, audec->pcodec->ctxCodec = %d!\n", audec->pcodec, audec->pcodec->ctxCodec);
		
	ctxCodec = audec->pcodec->ctxCodec;
	ctxCodec->codec_type = CODEC_TYPE_AUDIO;
		
	adec_print("open codec_id = %d--\n",ctxCodec->codec_id);
	acodec = avcodec_find_decoder(ctxCodec->codec_id);
	if (!acodec) {
		adec_print("acodec not found\n");
	}
	adec_print("open codec_id = %d----------------------------------\n",ctxCodec->codec_id);
		
	if (avcodec_open(ctxCodec, acodec) < 0) {
		adec_print("Could not open acodec = %d\n", acodec);
	}

	out_ape_fp = open("./dump/123.dat", O_CREAT | O_RDWR);
	if (out_ape_fp < 0) {
        adec_print("Create input file failed! fd=%d------------------------------\n", out_ape_fp);
    }
    adec_print("out_ape_fp = %d!", out_ape_fp);
	in_ape_fp = open("./dump/in.dat", O_CREAT | O_RDWR);
	if (in_ape_fp < 0) {
        adec_print("Create input file failed! fd=%d------------------------------\n", out_ape_fp);
    }
    adec_print("in_ape_fp = %d!", in_ape_fp);

	ret = uio_init();
	if (ret < 0){
		adec_print("uio init error! \n");
		goto error;
	}
		
    while (1){

		if (inlen > 0) {
			if (inbuf) {
				free(inbuf);
				inbuf = NULL;
			}
			inbuf = malloc(READ_ABUFFER_SIZE + inlen);
			memcpy(inbuf, apkt_end, inlen);
			rlen = read_buffer(inbuf+inlen, READ_ABUFFER_SIZE);
			rlen += inlen;
		}
		else {
			if (inbuf) {
				free(inbuf);
				inbuf = NULL;
			}
			inbuf = malloc(READ_ABUFFER_SIZE);
			rlen = read_buffer(inbuf+inlen, READ_ABUFFER_SIZE);
		}
		if (out_ape_fp >= 0) {
			write(in_ape_fp, inbuf, rlen);
			adec_print("write ape data in rlen = %d bytes\n",rlen);
		}
		declen = 0;
		if (rlen > 0){
			inlen = rlen;
			while (declen<rlen) {	
				outlen = AVCODEC_MAX_AUDIO_FRAME_SIZE;
				dlen = decode_audio(ctxCodec, outbuf, &outlen, inbuf+declen, inlen);
				if (dlen <= 0){
					adec_print("dlen = %d error----\n",dlen);
					if (inlen > 0) {
						adec_print("packet end %d bytes----\n",inlen);
						memcpy(apkt_end, (uint8_t *)(inbuf+declen), inlen);
					}
					break;
				}
				declen += dlen;
				inlen -= dlen;
				write_pcm_buffer(outbuf, audec->bs,outlen);
				//write_buffer(outbuf, outlen);
				if (outlen > 0) {
					if (out_ape_fp >= 0) {
						write(out_ape_fp, outbuf, outlen);
					}
				}
			} 
		
#if 0			
			outsize = AVCODEC_MAX_AUDIO_FRAME_SIZE;
			apkt.data = inbuffer;
			apkt.size = rlen;
			while (apkt.size > 0){
				dlen = avcodec_decode_audio3(ctxCodec, (int16_t *)outbuffer, &outsize, &apkt);
				if (dlen <= 0){
					adec_print("dlen = %d error----\n",dlen);
				}
				if (outsize > 0) {
					if (out_ape_fp >= 0) {
						write(out_ape_fp, outbuffer, outsize);
						adec_print("write ape data%d bytes\n UUUUUUUU----\n",outsize);
					}
				}				
				declen += dlen;
				apkt.size -= dlen;					
				if (apkt.size > 0){
					apkt.data += dlen;
				}
				else if (apkt.size < 0){
					adec_print("wrong aptk.size = %d, declen = %d, dlen = %d!", apkt.size, declen, dlen);
				}					
			}
#endif			
		}
		else {			
			adec_print("rlen = %d", rlen);
			break;
		}
	}
    close(out_ape_fp);
    close(in_ape_fp);
	
    adec_print("Exit adec_armdec_loop Thread!");

error:	
    pthread_exit(NULL);
    return NULL;
}
Beispiel #13
0
void
handle_function_key(int key,int  chann)
{
    /** this procedure simply adds the string specified by the function key
      to the buffer                                               ****/
    int count, fd;
    int amount = strlen(function_key[key].str);
    int id;
    int save_echo;

    /*** This procedure takes the character at in_buff[num_proc] and adds
      it to the buffer. It first checks to see if we should be inserting
      or overwriting, and then does the appropriate thing      *******/

    switch ((function_key[key]).type) {
      case IMMEDIATE:
        if (INS_MODE) {
            forwardcopy(&buff[curr_pntr + amount],
                        &buff[curr_pntr],
                        buff_pntr - curr_pntr);
            forwardflag_cpy(&buff_flag[curr_pntr + amount],
                            &buff_flag[curr_pntr],
                            buff_pntr - curr_pntr);
            for (count = 0; count < amount; count++) {
                buff[curr_pntr + count] = (function_key[key].str)[count];
                buff_flag[curr_pntr + count] = '1';
            }
            ins_print(curr_pntr, amount + 1);
            buff_pntr = buff_pntr + amount;
        }
        else {
            for (count = 0; count < amount; count++) {
                buff[curr_pntr + count] = (function_key[key].str)[count];
                buff_flag[curr_pntr + count] = '1';
                myputchar((function_key[key].str)[count]);
            }
        }
        num_proc = num_proc + 6;
        curr_pntr = curr_pntr + amount;
        buff_pntr = buff_pntr + amount;
        send_function_to_child();
        break;
      case DELAYED:
        if (INS_MODE) {
            forwardcopy(&buff[curr_pntr + amount],
                        &buff[curr_pntr],
                        buff_pntr - curr_pntr);
            forwardflag_cpy(&buff_flag[curr_pntr + amount],
                            &buff_flag[curr_pntr],
                            buff_pntr - curr_pntr);
            for (count = 0; count < amount; count++) {
                buff[curr_pntr + count] = (function_key[key].str)[count];
                buff_flag[curr_pntr + count] = '1';
            }
            ins_print(curr_pntr, amount + 1);
            buff_pntr = buff_pntr + amount;
        }
        else {
            for (count = 0; count < amount; count++) {
                buff[curr_pntr + count] = (function_key[key].str)[count];
                buff_flag[curr_pntr + count] = '1';
                myputchar((function_key[key].str)[count]);
            }
        }
        num_proc = num_proc + 6;
        curr_pntr = curr_pntr + amount;
        buff_pntr = buff_pntr + amount;
        fflush(stdout);
        break;
      case SPECIAL:
        /* fprintf(stderr, "Here I am \n"); */
        if (access(editorfilename, F_OK) < 0) {
            fd = open(editorfilename, O_RDWR | O_CREAT, 0666);
            write(fd, buff, buff_pntr);
            back_up(buff_pntr);
            close(fd);
        }
        else {
            if (buff_pntr > 0) {
                fd = open(editorfilename, O_RDWR | O_TRUNC);
                write(fd, buff, buff_pntr);
                back_up(buff_pntr);
                close(fd);
            }
        }
#if defined(MACOSXplatform) || defined(BSDplatform)
        bsdSignal(SIGCHLD, null_fnct,RestartSystemCalls);
#else
        bsdSignal(SIGCLD, null_fnct,RestartSystemCalls);
#endif
        switch (id = fork()) {
          case -1:
            perror("Special key");
            break;
          case 0:
            execlp((function_key[12]).str,
                   (function_key[12]).str,
                   editorfilename, NULL);
            perror("Returned from exec");
            exit(0);

        }
        while (wait((int *) 0) < 0);
        /** now I should read that file and send all it stuff thru the
                  reader                                            *****/
        fd = open(editorfilename, O_RDWR);
        if (fd == -1) {
            perror("Opening temp file");
            exit(-1);
        }
        num_proc += 6;

        /** reinitialize the buffer  ***/
        init_flag(buff_flag, buff_pntr);
        init_buff(buff, buff_pntr);
        /**  reinitialize my buffer pointers **/
        buff_pntr = curr_pntr = 0;
        /** reset the ring pointer **/
        current = NULL;
        save_echo = ECHOIT;
        ECHOIT = 0;
        while ((num_read = read(fd, in_buff, MAXLINE))) {
            do_reading();
        }
        close(fd);
        break;
    }
    return;

}