예제 #1
0
static int
mkfstab(void)
{
    char *cmd = "/usr/lib/partconf/mkfstab";

    append_message("partconf: Create fstab\n");
    return system(cmd);
}
예제 #2
0
void	new_list(t_app *app, int *listing, char *found)
{
  char		*found1;

  *found = 0;
  *app->screen->users_text = 0;
  if ((found1 = strchr(found + 1, 31)))
    {
      *found1 = 0;
      append_message(&(app->screen->users_text), found + 1);
      strcpy(found, found1 + 1);
    }
  else
    {
      *listing = 1;
      append_message(&(app->screen->users_text), found + 1);
    }
}
예제 #3
0
static ::testing::AssertionResult UriIsExpected(const char *expected_var,
                                                const char *actual_var,
                                                const uri_expected &expected,
                                                const htp_uri_t *actual) {
    std::stringstream msg;
    bool equal=true;

    if (! bstr_equal_c(actual->scheme, expected.scheme)) {
        equal = false;
        append_message(msg, "scheme", expected.scheme, actual->scheme);
    }

    if (! bstr_equal_c(actual->username, expected.username)) {
        equal = false;
        append_message(msg, "username", expected.username, actual->username);
    }

    if (! bstr_equal_c(actual->password, expected.password)) {
        equal = false;
        append_message(msg, "password", expected.password, actual->password);
    }

    if (! bstr_equal_c(actual->hostname, expected.hostname)) {
        equal = false;
        append_message(msg, "hostname", expected.hostname, actual->hostname);
    }

    if (! bstr_equal_c(actual->port, expected.port)) {
        equal = false;
        append_message(msg, "port", expected.port, actual->port);
    }

    if (! bstr_equal_c(actual->path, expected.path)) {
        equal = false;
        append_message(msg, "path", expected.path, actual->path);
    }

    if (! bstr_equal_c(actual->query, expected.query)) {
        equal = false;
        append_message(msg, "query", expected.query, actual->query);
    }

    if (! bstr_equal_c(actual->fragment, expected.fragment)) {
        equal = false;
        append_message(msg, "fragment", expected.fragment, actual->fragment);
    }

    if (equal) {
        return ::testing::AssertionSuccess();
    } else {
        return ::testing::AssertionFailure() << msg.str();
    }
}
예제 #4
0
void hwu_assert_put_message(const char* exp, const char* file, const int line, const char* format, ...) 
{
    char    out[1024]         = {0};
    char    line_string[32]   = {0};
    char    user_message[256] = {0};
    va_list user_args;

    strcat(out, ASSERT_LINE_BEGIN);
    strcat(out, ASSERT_MESSAGE);
    append_message(out, "exp     :", exp);
    append_message(out, "file    :", file);

    append_message(out, "line    :", itoa(line, line_string, 8));

    va_start(user_args, format);
    vsprintf(user_message, format, user_args);
    va_end(user_args);
    append_message(out, "user    :", user_message);
    strcat(out, ASSERT_LINE_END);

    hwu_debug_print(out);
}
예제 #5
0
int		check_before_append(t_app *app, char *buffer)
{
  static int	listing;
  char		*found;

  if (!listing && (found = strchr(buffer, 31)))
    {
      new_list(app, &listing, found);
      return (1);
    }
  if (listing && (found = strchr(buffer, 31)))
    {
      *found = 0;
      append_message(&(app->screen->users_text), buffer);
      strcpy(buffer, found + 1);
      listing = 0;
      return (1);
    }
  if (listing)
    append_message(&(app->screen->users_text), buffer);
  return (0);
}
예제 #6
0
/*
 * add each top level reply in the thread, and then add each
 * reply to the top level replies
 */
static void append_thread(CONTEXT *ctx, notmuch_thread_t *thread)
{
	notmuch_messages_t *msgs;

	for (msgs = notmuch_thread_get_toplevel_messages(thread);
	     notmuch_messages_valid(msgs);
	     notmuch_messages_move_to_next(msgs)) {

		notmuch_message_t *m = notmuch_messages_get(msgs);
		append_message(ctx, m);
		append_replies(ctx, m);
		notmuch_message_destroy(m);
	}
}
예제 #7
0
/*
 * add all the replies to a given messages into the display.
 * Careful, this calls itself recursively to make sure we get
 * everything.
 */
static void append_replies(CONTEXT *ctx, notmuch_message_t *top)
{
	notmuch_messages_t *msgs;

	for (msgs = notmuch_message_get_replies(top);
	     notmuch_messages_valid(msgs);
	     notmuch_messages_move_to_next(msgs)) {

		notmuch_message_t *m = notmuch_messages_get(msgs);
		append_message(ctx, m);
		/* recurse through all the replies to this message too */
		append_replies(ctx, m);
		notmuch_message_destroy(m);
	}
}
예제 #8
0
static void read_mesgs_query(CONTEXT *ctx, notmuch_query_t *q, int dedup)
{
    struct nm_ctxdata *data = get_ctxdata(ctx);
    int limit;
    notmuch_messages_t *msgs;

    if (!data)
        return;

    limit = get_limit(data);

    for (msgs = notmuch_query_search_messages(q);
            notmuch_messages_valid(msgs) &&
            (limit == 0 || ctx->msgcount < limit);
            notmuch_messages_move_to_next(msgs)) {

        notmuch_message_t *m = notmuch_messages_get(msgs);
        append_message(ctx, q, m, dedup);
        notmuch_message_destroy(m);
    }
}
예제 #9
0
파일: aisdecoder.c 프로젝트: nohal/rtl-ais
void nmea_sentence_received(const char *sentence,
                          unsigned int length,
                          unsigned char sentences,
                          unsigned char sentencenum) {
    append_message(sentence);

    if (sentences == 1) {
        if (send_nmea( sentence, length) == -1) abort();
        if (debug_nmea) fprintf(stderr, "%s", sentence);
    } else {
        if (buffer_count + length < MAX_BUFFER_LENGTH) {
            memcpy(&buffer[buffer_count], sentence, length);
            buffer_count += length;
        } else {
            buffer_count=0;
        }

        if (sentences == sentencenum && buffer_count > 0) {
            if (send_nmea( buffer, buffer_count) == -1) abort();
            if (debug_nmea) fprintf(stderr, "%s", buffer);
            buffer_count=0;
        };
    }
}
예제 #10
0
static void
finish(void)
{
    int i, ret;
    char *cmd, *mntpt, *errq = NULL, *fs;

    // Sort the partitions according to the order they have to be mounted
    qsort(parts, part_count, sizeof(struct partition *), mountpoint_sort_func);
    for (i = 0; i < part_count; i++) {
        fs = parts[i]->op.filesystem;
        if (fs == NULL)
            fs = parts[i]->fstype;
        else {
            // Create the file system/swap
            if (strcmp(fs, "swap") == 0) {
                append_message("partconf: Creating swap on %s\n", parts[i]->path);
                asprintf(&cmd, "mkswap %s >/dev/null 2>>/var/log/messages", parts[i]->path);
                ret = system(cmd);
                free(cmd);
                if (ret != 0) {
                    errq = "partconf/failed-mkswap";
                    break;
                }
            } else {
		char *mkfs_opts="";
		/* mkfs.reiserfs is interactive unless passed a -q */
		if (strcmp(fs, "reiserfs") == 0) {
			mkfs_opts="-q";
		}
		/* mkfs.xfs will not overwrite existing filesystems unless
		 * one passes -f. at this point, user has claimed "yes, do
		 * as I say!" so let's force it here. */
		else if (strcmp(fs, "xfs") == 0) {
		  	mkfs_opts="-f";
		}
                append_message("partconf: Creating %s file system on %s\n", fs, parts[i]->path);
                asprintf(&cmd, "mkfs.%s %s %s >/dev/null 2>>/var/log/messages", fs, mkfs_opts, parts[i]->path);
                ret = system(cmd);
                free(cmd);
                if (ret != 0) {
                    errq = "partconf/failed-mkfs";
                    debconf_subst(debconf,errq, "FS", parts[i]->op.filesystem);
                    break;
                }
            }
        }
        if (fs != NULL) {
            if (strcmp(fs, "swap") == 0 && !check_proc_swaps(parts[i]->path)) {
                // Activate swap
                append_message("partconf: Activating swap on %s\n", parts[i]->path);
                asprintf(&cmd, "swapon %s >/dev/null 2>>/var/log/messages", parts[i]->path);
                ret = system(cmd);
                free(cmd);
                /* 
                 * Since we check if the swap is already activated, it may
                 * make sense to make this fatal. For now, it is, anyway.
                 */
                if (ret != 0) {
                    errq = "partconf/failed-swapon";
                    break;
                }
            } else if (parts[i]->op.mountpoint != NULL) {
                // And mount
                append_message("partconf: Mounting %s on %s\n",
                        parts[i]->path, parts[i]->op.mountpoint);
                asprintf(&mntpt, "/target%s", parts[i]->op.mountpoint);
                makedirs(mntpt);
                fs = parts[i]->op.filesystem ? parts[i]->op.filesystem : parts[i]->fstype;
                ret = mount(parts[i]->path, mntpt, fs, 0xC0ED0000, NULL);
                // Ignore failure due to unknown filesystem
                if (ret < 0 && errno != ENODEV) {
                    append_message("mount: %s\n", strerror(errno));
                    errq = "partconf/failed-mount";
                    debconf_subst(debconf, errq, "MOUNT", mntpt);
                    free(mntpt);
                    break;
                }
                free(mntpt);
            }
        }
    }
    if (errq != NULL) {
        debconf_subst(debconf, errq, "PARTITION", parts[i]->path);
        debconf_input(debconf,"critical", errq);
        debconf_go(debconf);
        exit(30);
    }
    mkfstab();

    exit(0);
}
예제 #11
0
파일: io.c 프로젝트: genetique/samstat
FILE* io_handler(FILE* file, int file_num,struct parameters* param)
{
	char command[1000];
	char  tmp[1000];
	//int i = 0;
	int gzcat = -1;
	if(access("/usr/bin/gzcat", X_OK) == 0){
		gzcat = 1;
	}else if(access("/bin/gzcat", X_OK) == 0){
		gzcat = 1;
	}else if(access("/usr/bin/zcat", X_OK) == 0){
		gzcat = 0;
	}else if(access("/bin/zcat", X_OK) == 0){
		gzcat = 0;
	}

	param->gzipped = 0;
	param->bzipped = 0;
	param->sam = 0;
	param->fasta = 0;
	
	if(!file_exists(param->infile[file_num])){
		sprintf(param->buffer,"ERROR: Cannot find input file: %s\n",param->infile[file_num] );
		param->messages = append_message(param->messages, param->buffer);
		free_param(param);
		exit(EXIT_FAILURE);
	}
	
	if(!strcmp(".sam", param->infile[file_num] + (strlen(param->infile[file_num] ) - 4))){
		param->sam = 1;
	}else if (!strcmp(".bam", param->infile[file_num] + (strlen(param->infile[file_num] ) - 4))){
		param->sam = 2;
	}else if (!strcmp(".fa", param->infile[file_num] + (strlen(param->infile[file_num] ) - 3))){
		param->sam = 0;
		param->fasta = 1;
	}else if (!strcmp(".fq", param->infile[file_num] + (strlen(param->infile[file_num] ) - 3))){
		param->sam = 0;
	}else if (!strcmp(".fastq", param->infile[file_num] + (strlen(param->infile[file_num] ) - 6))){
		param->sam = 0;
	}else if (!strcmp(".fastaq", param->infile[file_num] + (strlen(param->infile[file_num] ) - 7))){
		param->sam = 0;
	}else if (!strcmp(".fasta", param->infile[file_num] + (strlen(param->infile[file_num] ) - 6))){
		param->sam = 0;
		param->fasta = 1;
	}else if(!strcmp(".sam.gz", param->infile[file_num] + (strlen(param->infile[file_num] ) - 7))){
		param->sam = 1;
		param->gzipped  = 1;
	}else if (!strcmp(".bam.gz", param->infile[file_num] + (strlen(param->infile[file_num] ) - 7))){
		param->sam = 2;
		param->gzipped  = 1;
	}else if (!strcmp(".fa.gz", param->infile[file_num] + (strlen(param->infile[file_num] ) - 6))){
		param->sam = 0;
		param->fasta = 1;
		param->gzipped  = 1;
	}else if (!strcmp(".fq.gz", param->infile[file_num] + (strlen(param->infile[file_num] ) - 6))){
		param->sam = 0;
		param->gzipped  = 1;
	}else if (!strcmp(".fastq.gz", param->infile[file_num] + (strlen(param->infile[file_num] ) - 9))){
		param->sam = 0;
		param->gzipped  = 1;
	}else if (!strcmp(".fastaq.gz", param->infile[file_num] + (strlen(param->infile[file_num] ) - 10))){
		param->sam = 0;
		param->gzipped  = 1;
	}else if (!strcmp(".fasta.gz", param->infile[file_num] + (strlen(param->infile[file_num] ) - 9))){
		param->sam = 0;
		param->gzipped  = 1;
	}else if (!strcmp(".fastq.bz2", param->infile[file_num] + (strlen(param->infile[file_num] ) - 10))){
		param->sam = 0;
		param->bzipped  = 1;
	}else if (!strcmp(".fq.bz2", param->infile[file_num] + (strlen(param->infile[file_num] ) - 7))){
		param->sam = 0;
		param->bzipped  = 1;
	}else{
		sprintf(param->buffer,"ERROR: Cannot recognize format for file: %s\n", param->infile[file_num]);
		param->messages = append_message(param->messages, param->buffer);
		free_param(param);
		exit(EXIT_FAILURE);
		param->sam = -1;
	}
	
	
	if(param->gzipped && gzcat == -1){
		sprintf(param->buffer,"ERROR: Cannot find gzcat / zcat on your system. Try gzcat <infile> | samstat -f sam/bam/fa/fq\n");
		param->messages = append_message(param->messages, param->buffer);
		free_param(param);
		exit(EXIT_FAILURE);
	}
	
	if(file_num == -1){
		if(param->sam == 2){
			command[0] = 0;
			if(!param->filter){
				strcat ( command, "samtools view -F 768 "); 
			}else{
				strcat ( command, "samtools view -F "); 
				sprintf (tmp, "%s ",param->filter);
				strcat ( command, tmp);
			}
			sprintf (tmp, "%s ","-");
			strcat ( command, tmp);
			if (!(file = popen(command, "r"))) {
				sprintf(param->buffer,"ERROR: Cannot open bam file '%s' with command:%s\n",param->infile[file_num],command);
				param->messages = append_message(param->messages, param->buffer);
				free_param(param);
				exit(EXIT_FAILURE);
			}
		}else if(param->sam == 1){
			command[0] = 0;
			if(!param->filter){
				strcat ( command, "samtools view -SF 768 "); 
			}else{
				strcat ( command, "samtools view -SF "); 
				sprintf (tmp, "%s ",param->filter);
				strcat ( command, tmp);
			}
			sprintf (tmp, "%s ", "-");
			strcat ( command, tmp);
			if (!(file = popen(command, "r"))) {
				sprintf(param->buffer,"ERROR: Cannot open bam file '%s' with command:%s\n",param->infile[file_num],command);
				param->messages = append_message(param->messages, param->buffer);
				free_param(param);
				exit(EXIT_FAILURE);
			}
		}else{
			file = stdin;
		}
	}else{
		if(param->sam == 2){
			command[0] = 0;
			
			if(param->bzipped){
				strcat ( command, "bzcat ");
				if(!param->filter){
					sprintf (tmp, "%s | samtools view -F 768 - ", param->infile[file_num]);
					strcat ( command, tmp);
				}else{
					sprintf (tmp, "%s | samtools view -F  ", param->infile[file_num]);
					strcat ( command, tmp);
					sprintf (tmp, "%s - ",param->filter);
					strcat ( command, tmp);
				}
				
			}else if(param->gzipped){
				if(gzcat == 1){
					strcat ( command, "gzcat "); 
				}else{
					strcat ( command, "zcat "); 
				}
				if(!param->filter){
					sprintf (tmp, "%s | samtools view -F 768 - ", param->infile[file_num]);
					strcat ( command, tmp);
				}else{
					sprintf (tmp, "%s | samtools view -F  ", param->infile[file_num]);
					strcat ( command, tmp);
					sprintf (tmp, "%s - ",param->filter);
					strcat ( command, tmp);
				}
			}else{
				if(!param->filter){
					strcat ( command, "samtools view -F 768 "); 
				}else{
					strcat ( command, "samtools view -F "); 
					sprintf (tmp, "%s ",param->filter);
					strcat ( command, tmp);
				}
				sprintf (tmp, "%s ", param->infile[file_num]);
				strcat ( command, tmp);
			}
			if (!(file = popen(command, "r"))) {
				sprintf(param->buffer,"Cannot open bam file '%s' with command:%s\n",param->infile[file_num],command);
				param->messages = append_message(param->messages, param->buffer);
				free_param(param);
				exit(EXIT_FAILURE);
			}
		}else if(param->sam == 1){
			command[0] = 0;
			if(param->gzipped){
				if(gzcat == 1){
					strcat ( command, "gzcat "); 
				}else{
					strcat ( command, "zcat "); 
				}
				if(!param->filter){
					sprintf (tmp, "%s | samtools view -SF 768 - ", param->infile[file_num]);
					strcat ( command, tmp);
				}else{
					sprintf (tmp, "%s | samtools view -SF  ", param->infile[file_num]);
					strcat ( command, tmp);
					sprintf (tmp, "%s - ",param->filter);
					strcat ( command, tmp);
				}
			}else{
				if(!param->filter){
					strcat ( command, "samtools view -SF 768 "); 
				}else{
					strcat ( command, "samtools view -SF "); 
					sprintf (tmp, "%s ",param->filter);
					strcat ( command, tmp);
				}
				sprintf (tmp, "%s ", param->infile[file_num]);
				strcat ( command, tmp);
			}
			if (!(file = popen(command, "r"))) {
				sprintf(param->buffer,"Cannot open bam file '%s' with command:%s\n",param->infile[file_num],command);
				param->messages = append_message(param->messages, param->buffer);
				free_param(param);
				exit(EXIT_FAILURE);
			}
		}else{
			command[0] = 0;
			if(param->bzipped){
				strcat ( command, "bzcat ");
				
			}else if(param->gzipped){
				if(gzcat == 1){
					strcat ( command, "gzcat ");
				}else{
					strcat ( command, "zcat ");
				}
			}else{
				strcat ( command, "cat ");
			}
			sprintf (tmp, "%s ", param->infile[file_num]);
			strcat ( command, tmp);
			//fprintf(stderr,"%s\n",command);
			if (!(file = popen(command, "r"))) {
				sprintf(param->buffer,"Cannot open bam file '%s' with command:%s\n",param->infile[file_num],command);
				param->messages = append_message(param->messages, param->buffer);
				free_param(param);
				exit(EXIT_FAILURE);
			}
		}
	}
	return file;
}
예제 #12
0
파일: io.c 프로젝트: genetique/samstat
int read_fasta_fastq(struct read_info** ri,struct parameters* param,FILE *file) 
{
	int park_pos = -1;
	char line[MAX_LINE];
	int i;//,j;
	int seq_p = 0;
	int set = 0;
	int len = 0;
	int size = 0;
	
	ri = clear_read_info(ri, param->num_query);
	while(fgets(line, MAX_LINE, file)){
		if((line[0] == '@' && !set)|| (line[0] == '>' && !set)){
			//set sequence length of previous read
			
			//check if there is still space....
			//if(param->num_query == size){
			//	fseek (file , -  strlen(line) , SEEK_CUR);
			//	return size;
			//}
			park_pos++;
			len = 0;
			seq_p = 1;
			for(i = 1;i < MAX_LINE;i++){
				len++;
				if(iscntrl((int)line[i])){
					break;
				}
				
			}
			
			//ri[park_pos]->hits[0] = 0;
			//ri[park_pos]->strand[0] = 0;
			MMALLOC(ri[park_pos]->name,sizeof(unsigned char)* (len+1));
			for(i = 1;i < MAX_LINE;i++){
				
				if(iscntrl((int)line[i])){
					ri[park_pos]->name[i-1] = 0;
					break;
				}
				if(isspace((int)line[i])){
					ri[park_pos]->name[i-1] = ';';
				}
				
				ri[park_pos]->name[i-1] = line[i];
			}
			//fprintf(stderr,"LEN:%d	%s\n",len,ri[park_pos]->name);
			
			set = 1;
			size++;
			//get ready to read quality if present  
		}else if(line[0] == '+' && !set){
			seq_p = 0;
			set = 1;
			//reading sequence or quality  
		}else{	
			if(set){
				if(seq_p){
					len = 0;
					for(i = 0;i < MAX_LINE;i++){
						len++;
						if(iscntrl((int)line[i])){
							break;
						}
					}
					//fprintf(stderr,"SEQ LEN:%d	%s\n",len,line);
					MMALLOC(ri[park_pos]->seq,sizeof(unsigned char)* (len+1));
					
					MMALLOC(ri[park_pos]->labels, sizeof(unsigned char)* (len+1));
					
					for(i = 0;i < MAX_LINE;i++){
						if(iscntrl((int)line[i])){
							ri[park_pos]->seq[i] = 0;
							ri[park_pos]->labels[i] = 0;
							break;
						}
						ri[park_pos]->seq[i] = nuc_code[(int)line[i]];
						ri[park_pos]->labels[i] = 0;
					}
					ri[park_pos]->len = len-1;
				}else{
					len = 0;
					for(i = 0;i < MAX_LINE;i++){
						len++;
						if(iscntrl((int)line[i])){
							break;
						}
						
					}
					
					if(len-1 != ri[park_pos]->len ){
						sprintf(param->buffer,"ERROR: Length of sequence and base qualities differ!.\n");
						param->messages = append_message(param->messages, param->buffer);
						free_param(param);
						exit(EXIT_FAILURE);
					}
					
					//fprintf(stderr,"QUAL LEN:%d\n",len);
					MMALLOC(ri[park_pos]->qual,sizeof(unsigned char)* (len+1));
					for(i = 0;i < MAX_LINE;i++){
						if(iscntrl((int)line[i])){
							ri[park_pos]->qual[i] = 0;
							break;
						}
						ri[park_pos]->qual[i] = line[i];
					}
				}
			}
			set = 0;
		}
		if(param->num_query == size ){//here I know I am in the last entry AND filled the quality...
			if(!param->fasta && ri[park_pos]->qual){
				return size;
			}
			if(param->fasta && ri[park_pos]->seq){
			   
				return size;
			}
		}
	}
	return size;
}