Exemplo n.º 1
0
void print_line(char line[], char source_name_to_print[], char date_to_print[])
{
    char save_ch;
    char *save_chp = NULL;
    static int line_count = MAX_LINES_PER_PAGE;
    
    if (++line_count > MAX_LINES_PER_PAGE) //checks for new page
    {
        print_page_header(source_name_to_print, date_to_print);
        line_count = 1;
    }
    if (strlen(line) > MAX_PRINT_LINE_LENGTH) //truncates line if needed
    {
        line[81] = '\0';
    }
    printf("%s", line);
    if (save_chp)
    {
        /* Missing Code Here */
    }
    /* Missing Code Here */
    if (save_chp)
    {
        /* Missing Code Here */
    }
}
Exemplo n.º 2
0
void print_line(char line[], char source_name_to_print[], char date_to_print[])
{
    char save_ch;
    char *save_chp = NULL;
    static int line_count = MAX_LINES_PER_PAGE;
    
    if (++line_count > MAX_LINES_PER_PAGE)
    {
        print_page_header(source_name_to_print, date_to_print);
        line_count = 1;
    }
    if (strlen(line) > MAX_PRINT_LINE_LENGTH) 
    {
        save_chp = &line[MAX_PRINT_LINE_LENGTH];
    }
    if (save_chp)
    {
        save_ch = *save_chp;
        *save_chp = '\0';
    }
    printf("%s", line);
    if (save_chp)
    {
        *save_chp = save_ch;
    }
}
Exemplo n.º 3
0
void print_line(char line[], char source_name_to_print[], char date_to_print[]) {
	char save_ch;
	char *save_chp = NULL;
	static int line_count = MAX_LINES_PER_PAGE;
	/*reset line count on new page  */
	if (++line_count > MAX_LINES_PER_PAGE) {
		print_page_header(source_name_to_print, date_to_print);
		line_count = 1;
	}/*make new line when line gets to max length  */
	if (strlen(line) > MAX_PRINT_LINE_LENGTH) {
		save_chp = &line[MAX_PRINT_LINE_LENGTH];
	}
	if (save_chp) {
		save_ch = *save_chp;
		*save_chp = '\0';
	}
	printf("%s", line);
	/* adds a space after every line that starts with a number  */
	if(line[3] == '1' || line[3] == '9' || line[3] == '2' || line[3] == '3' || line[3] == '4' 
		|| line[3] == '5' || line[3] == '6' || line[3] == '7' || line[3] == '8' ){
		printf("\n");
	}
	fflush(stdout);
	if (save_chp) {
		*save_chp = save_ch;
	}
}
Exemplo n.º 4
0
void cx_list_buffer::put_line(void) {
    // Start a new page if the current one is full.
    if (list_flag && (line_count == max_lines_per_page)) print_page_header();

    // Truncate the line if it's too long.
    text[max_printline_length] = '\0';

    // print the text line, and then blank out the text.
    std::cout << text << std::endl;
    memset(text, '\0', sizeof (text));

    ++line_count;
}
Exemplo n.º 5
0
void print_line(char line[], char source_name_to_print[], char date_to_print[])
{
    char save_ch;
    char *save_chp = NULL;
    static int line_count = MAX_LINES_PER_PAGE;
    if (++line_count > MAX_LINES_PER_PAGE)
    {
        print_page_header(source_name_to_print,date_to_print);
	line_count = 1;
    }
	else
	{
		fputs(line, stdout);
	}
}
Exemplo n.º 6
0
/** Initialize      Initialize the list buffer.  Set the date
 *                  for the page header, and print the first
 *                  header.
 *
 * @param p_file_name : ptr to source file name (for page header)
 */
void cx_list_buffer::initialize(const char *p_file_name) {
    memset(text, '\0', sizeof (text));
    page_number = 0;

    // Copy the input file name.
    p_source_file_name = new char[strlen(p_file_name) + 1];
    strcpy(p_source_file_name, p_file_name);

    // Set the date.
    time_t timer;
    time(&timer);
    strcpy(date, asctime(localtime(&timer)));
    date[strlen(date) - 1] = '\0'; // remove '\n' at end

    print_page_header();
}
Exemplo n.º 7
0
int main (int argc, char **argv)
{
    HPDF_Doc  pdf;
    HPDF_Page page;
    HPDF_Font def_font;
    HPDF_REAL height;
    HPDF_REAL width;
    HPDF_UINT i;
    int page_num = 1;
    int done = 0;
    char page_number[MAXSTRING];
    int line_num = 1;
    FILE *input_file = NULL;
    for (i = 1; i < argc; i++)
    {
        if (strcmp(argv[i], "-t") == 0)
        {
            strcpy(page_title, argv[++i]);
        }
        else if (strcmp(argv[i], "-o") == 0)
        {
            strcpy(fname, argv[++i]);
        }
        else if (strcmp(argv[i], "-k") == 0)
        {
            page_margin_odd = page_margin_kindle;
            page_margin_even = page_margin_kindle;
        }
        else if (strcmp(argv[i], "-n") == 0)
        {
            no_line_number = 1;
        }
        else if (strcmp(argv[i], "-h")==0)
        {
            usage();
        }
        else if (strcmp(argv[i], "-l") == 0)
        {
            use_landscape = 1;
            page_margin_odd = page_margin_odd_landscape;
            page_margin_even = page_margin_even_landscape;
            LINES_PER_PAGE=50;
        }
        else if (strcmp(argv[i], "-")==0)
        {
            input_file = stdin;
        }
        else
        {
            input_file = fopen(argv[i], "r");
        }
    }

    if (input_file == NULL)
    {
        printf("error: no input specified\n");
        usage();
    }

    pdf = HPDF_New (error_handler, NULL);
    if (!pdf) {
        printf ("error: cannot create PdfDoc object\n");
        return 1;
    }
    if (setjmp(env)) {
        HPDF_Free (pdf);
        return 1;
    }
    while (!done)
    {
        int n = 0;
        char buf[1000];
        char *p;

        while ((p = fgets(buf, 999, input_file)) && n < LINES_PER_PAGE)
        {
            if (buf[0] == '@')
            {
                if (strncmp(buf, "@title ", 7)==0)
                {
                    strcpy(page_title, buf+7);
                }
                else if (strncmp(buf, "@newpage", 8)==0)
                {
                    if (n != 0 && n != LINES_PER_PAGE-1)
                    {
                        line_num += LINES_PER_PAGE;
                        line_num -= line_num % LINES_PER_PAGE;
                        line_num ++;
                        break;
                    }
                }
                continue;
            }
            lines[n].line_num = line_num++;
            strcpy(lines[n].line, buf);
            n++;
        }

        /* If no more input in future, this is the last page,
         * flag as done.
         */
        if (p == NULL)
            done = 1;

        /* If no lines are read, we are done. */
        if (n == 0)
            break;

        /* Add a new page object. */
        page = HPDF_AddPage (pdf);
        HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_A4, use_landscape?HPDF_PAGE_LANDSCAPE:HPDF_PAGE_PORTRAIT); 
        HPDF_Page_SetRGBFill(page, 0, 0, 0);
        
        height = HPDF_Page_GetHeight (page);
        width = HPDF_Page_GetWidth (page);

        page_margin = EVENPAGE(page_num) ? page_margin_even : page_margin_odd;
        page_size.cx = (int)width;
        page_size.cy = (int)height;

        def_font = HPDF_GetFont (pdf, default_font_name, NULL);
        HPDF_Page_SetFontAndSize (page, def_font, 16);
        print_page_header(pdf, page, page_title);
        print_page_content(pdf, page, lines, n);
        sprintf(page_number, "%d", page_num);
        print_page_footer(pdf, page, page_number);
        page_num++;
    }
    if (page_num > 1)
    {
        HPDF_SaveToFile (pdf, fname);
        printf("Output written to %s\n", fname);
    }
    else
    {
        printf("No output\n");
    }
    
    if (input_file != stdin && input_file != NULL)
        fclose(input_file);

    /* clean up */
    HPDF_Free (pdf);
    return 0;
}
Exemplo n.º 8
0
int main (int argc, char **argv)
{
	enum ParserState state = 0;
	gunichar in;
	gboolean init = FALSE;
	/* used to parse attribute */
	gint attributes = 0;
	/* Input/output */
	FILE *input = stdin;
	FILE  *output = stdout;
	/* Error */
	GError *error = NULL;

	/* init the glib system  */
	g_type_init();
	/* needed to get the right charset from g_get_charset */
	setlocale(LC_ALL, "");
	/* Get charset */
	g_get_charset(&input_charset);

	/* parse options */
	parse_cmd_options(&argc, &argv);

	/* Handle input file */
	if(input_file && strcmp(input_file, "-")) {
		input = g_fopen(input_file, "r");
		EXCEPTION(input == NULL, "Failed to open: %s: %s\n", input_file, strerror(errno));
	}
	/* Handle output file */
	if(output_file) {
		output = g_fopen(output_file, "w");
		EXCEPTION(output == NULL, "Failed to open: %s: %s\n", output_file, strerror(errno));
	}
	/* Create channel for input */
	GIOChannel *chan = g_io_channel_unix_new(fileno(input));
	/* Set channel encoding */
	g_io_channel_set_encoding(chan, input_charset,&error);
	EXCEPTION(error != NULL, "Failed to set input encoding: %s\n", error->message);

	/* Read input */
	while(g_io_channel_read_unichar(chan, &in, &error) == G_IO_STATUS_NORMAL && error == NULL)
	{
		if(!init) {
			/* Output html header */
			print_page_header(output);
			/* Convert and print body */
			fprintf(output, "<pre style='font-family:monospace'>\n");
			init = TRUE;
		}
		/* If we hit the escape character, go into 'attribute parsing' mode */
		if(in == ESCAPE_CHAR) {
			state = PARSE_ATTRIBUTE;
			/* reset */
			attributes = 0;
		}
		/* if we are in attribute parsing mode, parse attribute */
		else if(state == PARSE_ATTRIBUTE) {
			if(in == '[') {
				/* Begin of attributes */
				state = PARSE_COLOR_ATTRIBUTE;
			}else {
				WARNING("Unknown Escape sequence found: %i\n", in);
				state = PARSE_NORMAL;
			}
		} else if(state == PARSE_COLOR_ATTRIBUTE) {
			if (in == ';') { /* End of element */
				process_attribute(output, attributes);
				attributes = 0;
			} else if(in == 'm') { /* end of attribute */
				process_attribute(output, attributes);
				state = PARSE_NORMAL;
			} else if(in >= '0' && in <= '9') {
				attributes *= 10;
				attributes += in-'0';
			}else if (in == 'h' || in == 'l' ) {
				WARNING("Unsupported attribute found: %i\n", in);
				state = PARSE_NORMAL;
			}
			continue;
		} else if (state == PARSE_NORMAL) {
			/* special chars (htmlspecialchars php doc) */
			if(in == '"') fputs("&quot;", output);
			else if(in == '\'') fputs("&#039;", output);
			else if(in == '&') fputs("&amp;", output);
			else if(in == '<') fputs("&lt;", output);
			else if(in == '>') fputs("&gt;", output);
			/* ascii values stay ascii*/
			else if(in >= 0 && in <= 177)
				fprintf(output, "%c", (char)in);
			/* Rest we encode in utf8 */
			else fprintf(output, "&#%i;", in);
		}
	}
	EXCEPTION(error != NULL, "Failed to read input character: %s\n", error->message);
	if(init) {
		/* Close open tags */
		process_attribute(output, 0);
		fprintf(output,"\n  </pre>\n");
		print_page_footer(output);
	}

	/* free input channel */
	g_io_channel_unref(chan);

	/* close i/o */
	if(input != stdin) fclose(input);
	if(output != stdout) fclose(output);

	return EXIT_SUCCESS;
}