예제 #1
0
static char *get_comment(char *filename)
{
	char buf[81];
	FILE *fp = fopen(filename, "r");

	if (!fp)
	{
		perror(filename);
		exit(1);
	}
	while (fgets(buf, sizeof(buf), fp))
	{
		append_comment(buf);
	}
	fclose(fp);
	return st_cmt;
}
예제 #2
0
static char *get_comment_stdin(void)
{
	char buf[81];
	char *p;

	printf("Enter the comment. Use a dot on a line by itself to mark the "
		"end.\n");
	do
	{
		putchar(':');
		fflush(stdout);
		p = fgets(buf, sizeof(buf), stdin);
		if ((p == NULL) || !strcmp(p, ".") || !strcmp(p, ".\n"))
			break;
		append_comment(p);
	} while (1);
	
	return st_cmt;
}
예제 #3
0
파일: zip_file.cpp 프로젝트: omegaluo/xlnt
void zip_file::save(std::vector<unsigned char> &bytes)
{
    if(archive_->m_zip_mode == MZ_ZIP_MODE_WRITING)
    {
        mz_zip_writer_finalize_archive(archive_.get());
    }
    
    if(archive_->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED)
    {
        mz_zip_writer_end(archive_.get());
    }
    
    if(archive_->m_zip_mode == MZ_ZIP_MODE_INVALID)
    {
        start_read();
    }
    
    append_comment();
    bytes.assign(buffer_.begin(), buffer_.end());
}
예제 #4
0
파일: zip_file.cpp 프로젝트: omegaluo/xlnt
void zip_file::save(std::ostream &stream)
{
    if(archive_->m_zip_mode == MZ_ZIP_MODE_WRITING)
    {
        mz_zip_writer_finalize_archive(archive_.get());
    }
    
    if(archive_->m_zip_mode == MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED)
    {
        mz_zip_writer_end(archive_.get());
    }
    
    if(archive_->m_zip_mode == MZ_ZIP_MODE_INVALID)
    {
        start_read();
    }
    
    append_comment();
    stream.write(buffer_.data(), buffer_.size());
}
예제 #5
0
/*
 * Read and parse the next line from {fs,m}tab or mountinfo
 */
static int mnt_table_parse_next(struct libmnt_table *tb, FILE *f,
				struct libmnt_fs *fs,
				const char *filename, int *nlines)
{
	char buf[BUFSIZ];
	char *s;
	int rc;

	assert(tb);
	assert(f);
	assert(fs);

	/* read the next non-blank non-comment line */
next_line:
	do {
		if (fgets(buf, sizeof(buf), f) == NULL)
			return -EINVAL;
		++*nlines;
		s = strchr (buf, '\n');
		if (!s) {
			/* Missing final newline?  Otherwise an extremely */
			/* long line - assume file was corrupted */
			if (feof(f)) {
				DBG(TAB, mnt_debug_h(tb,
					"%s: no final newline",	filename));
				s = strchr (buf, '\0');
			} else {
				DBG(TAB, mnt_debug_h(tb,
					"%s:%d: missing newline at line",
					filename, *nlines));
				goto err;
			}
		}

		/* comments parser */
		if (tb->comms
		    && (tb->fmt == MNT_FMT_GUESS || tb->fmt == MNT_FMT_FSTAB)
		    && is_comment_line(buf)) {
			do {
				rc = append_comment(tb, fs, buf, feof(f));
				if (!rc)
					rc = next_comment_line(buf,
							sizeof(buf),
							f, &s, nlines);
			} while (rc == 0);

			if (rc == 1 && feof(f))
				rc = append_comment(tb, fs, NULL, 1);
			if (rc < 0)
				return rc;

		}

		*s = '\0';
		if (--s >= buf && *s == '\r')
			*s = '\0';
		s = (char *) skip_blank(buf);
	} while (*s == '\0' || *s == '#');

	if (tb->fmt == MNT_FMT_GUESS) {
		tb->fmt = guess_table_format(s);
		if (tb->fmt == MNT_FMT_SWAPS)
			goto next_line;			/* skip swap header */
	}

	switch (tb->fmt) {
	case MNT_FMT_FSTAB:
		rc = mnt_parse_table_line(fs, s);
		break;
	case MNT_FMT_MOUNTINFO:
		rc = mnt_parse_mountinfo_line(fs, s);
		break;
	case MNT_FMT_UTAB:
		rc = mnt_parse_utab_line(fs, s);
		break;
	case MNT_FMT_SWAPS:
		if (strncmp(s, "Filename\t", 9) == 0)
			goto next_line;			/* skip swap header */
		rc = mnt_parse_swaps_line(fs, s);
		break;
	default:
		rc = -1;	/* unknown format */
		break;
	}

	if (rc == 0)
		return 0;
err:
	DBG(TAB, mnt_debug_h(tb, "%s:%d: %s parse error", filename, *nlines,
				tb->fmt == MNT_FMT_MOUNTINFO ? "mountinfo" :
				tb->fmt == MNT_FMT_SWAPS ? "swaps" :
				tb->fmt == MNT_FMT_FSTAB ? "tab" : "utab"));

	/* by default all errors are recoverable, otherwise behavior depends on
	 * the errcb() function. See mnt_table_set_parser_errcb().
	 */
	return tb->errcb ? tb->errcb(tb, filename, *nlines) : 1;
}