コード例 #1
0
ファイル: ethread_tests.c プロジェクト: 0x00evil/otp
static void succeed(char *frmt,...)
{
    print_eol();
    fprintf(stderr, "ETHR-TEST-SUCCESS");
    PRINT_VA_LIST(frmt);
    print_eol();
    exit(0);
}
コード例 #2
0
ファイル: ethread_tests.c プロジェクト: 0x00evil/otp
static void skip(char *frmt,...)
{
    print_eol();
    fprintf(stderr, "ETHR-TEST-SKIP");
    PRINT_VA_LIST(frmt);
    print_eol();
    exit(0);
}
コード例 #3
0
ファイル: ethread_tests.c プロジェクト: 0x00evil/otp
static void fail(char *frmt,...)
{
    char *abrt_env;
    print_eol();
    fprintf(stderr, "ETHR-TEST-FAILURE");
    PRINT_VA_LIST(frmt);
    print_eol();
    abrt_env = getenv("ERL_ABORT_ON_FAILURE");
    if (abrt_env && strcmp("true", abrt_env) == 0)
	abort();
    else
	exit(1);
}
コード例 #4
0
ファイル: ui.c プロジェクト: leyyin/university
void ui_print_help_menu()
{
    puts("Help menu");
    puts("\t 1. Add holiday offer");
    puts("\t 2. Update holiday offer");
    puts("\t 3. Delete offer");
    puts("\t 4. List all offers");
    print_eol();
    puts("\t 5. Filter by type");
    puts("\t 6. Filter by price");
    puts("\t 7. Undo the last operation");
    print_eol();
    puts("\t 0. Quit");
}
コード例 #5
0
ファイル: ui.c プロジェクト: leyyin/university
int ui_start()
{
    // test_holiday();
    Storage* storage = storage_create();

    puts("Travel agency program");
    print_eol();
    ui_print_help_menu();
    while (1)
    {
        int command;

        printf(">> ");
        SAFE_SCANF(scanf("%d", &command))

        if (command == 1)
        {
            Holiday temp_holiday;

            puts("Add holiday");

            ui_read_holiday(storage, &temp_holiday);
            VALIDATE_HOLIDAY(temp_holiday, storage_insert_holiday(storage, &temp_holiday))
        }
        else if (command == 2)
コード例 #6
0
ファイル: PRINTER.C プロジェクト: daemqn/Atari_ST_Sources
static boolean print_line 
( 
	char *dline 	/* 0-terminated line to print */
)
{
	char *p;					/* address of position in dline string */
	int i;						/* position in printer line */
	boolean status = FALSE;		/* prtchar print status */

	p = dline;
	i = 0;
	while ( !status && (*p != 0) )
	{
		status = prtchar(*p); 		/* beware: prtchar is false when OK ! */
		p++;
		i++;
		if ( !status && ((*p == 0) || (i >= plinelen)) ) /* end of line or line too long */
		{
			i = 0;					/* reset linelength counter */
			status = print_eol();	/* print cr lf */
		}	/* if...    */ 
	} 		/* while... */

	return status;					/* this one is FALSE if ok, too! */
}
コード例 #7
0
ファイル: PRINTER.C プロジェクト: daemqn/Atari_ST_Sources
void dir_print
(
	WINDOW *wd, 	/* to window structure */
	int n, 			/* number of items */
	int *list		/* to item list */
)
{
	boolean 
		noerror = TRUE;	/* true while no error */

	char 
		dline[134];		/* sufficiently long string for directory line */

	long 
		nfiles = 0,		/* file count */
	 	nfolders = 0,	/* folder count */
		nbytes = 0;		/* bytes sum */

	int
		error,			/* error id; =0 if  no errors */ 
		i,				/* item counter */
		button,			/* pressed button id. */
		type;			/* item type (file, folder...) */ 
	

	/* Count files, folders and bytes in this directory only (don't recurse) */

	for ( i = 0; i < n; i++ )
	{
		type = itm_type(wd, list[i]);
		if ( type == ITM_FILE || type == ITM_PROGRAM )
		{
			if ( (error = itm_attrib( wd, list[i], 0 ,&pattr) ) == 0 )
			{
				nbytes += pattr.size;
				nfiles++;
			}
			else
				error = copy_error(error, itm_name(wd, list[i]), 0); /* 0= any op but move or delete */
		}
		else if ( type == ITM_FOLDER )
			nfolders++;

		if ( error != 0 )
		{
			noerror = FALSE;
			break;
		}
	}

	if ( noerror )
	{
		/* Open confirmation dialog */

		cv_fntoform ( copyinfo + CPFOLDER, dir_path(wd) );
		*cpfile = 0;
		button = open_cfdialog( CF_PRINT, nfolders, nfiles, nbytes, CMD_PRINTDIR ); 

		/* If confirmed, print indeed */

		if ( button == COPYOK ) 
		{
			strcpy ( dline, get_freestring(TDIROF) ); 		/* Get "Directory of " string */
			get_dir_line( wd, &dline[strlen(dline)], -1 );	/* Append window title */

			if ( (noerror = !print_line(dline) ) == TRUE )
				noerror = !print_eol();

			i = 0;
			while ( (i < n) && noerror )
			{
				get_dir_line( wd, dline, list[i] );
				if ( dline[1] == (char)7 )
					dline[1] = '\\';	/* Mark folders with "\" */
				noerror = !print_line(dline);
				if ( escape_abort( cfdial_open ) )
					noerror = FALSE;
				i++;
			}
	
			if ( noerror )
			{
 				get_dir_line ( wd, dline, -2 );						/* get directory info line */
				if ( (noerror = !print_eol()) == TRUE )				/* print blank line */
					if ( ( noerror = !print_line(dline) ) == TRUE )	/* print directory total */
						noerror = !print_eol();						/* print blank line */
			}	/* noerror */
		}		/* button  */
		else
			noerror = FALSE;

	} /* if noerror */

	if ( button != 0 )
		close_cfdialog(button);
}
コード例 #8
0
ファイル: PRINTER.C プロジェクト: daemqn/Atari_ST_Sources
static int print_file(WINDOW *w, int item)
{
	/* int handle, error = 0, i, key, result = 0, r; DjV 033 010203 */
	int handle, error = 0, i, result = 0; /* DjV 033 010203 */
	char *buffer;
	const char *name;
	long l;			/* index in buffer[] */
	int ll = 0;		/* DjV 031 150203 line length counter */
	boolean stop = FALSE;

	if ((name = itm_fullname(w, item)) == NULL)
		return XFATAL;

	buffer = x_alloc(PBUFSIZ);

	if (buffer != NULL)
	{
		graf_mouse(HOURGLASS, NULL);

		if ((handle = x_open(name, O_DENYW | O_RDONLY)) >= 0)
		{
			do
			{
				if ((l = x_read(handle, PBUFSIZ, buffer)) >= 0)
				{
					for (i = 0; i < (int) l; i++)
					{
						/* DjV 031 150203 ---vvv--- */
						/* 
						 * line wrap & new line handling;
						 */
						ll++;
						if ( (buffer[i] == (char)13) || (buffer[i] == (char)10) || (buffer[i] == (char)12) )
							ll = 0; /* reset linelength counter at CR, LF or FF */
						else if ( ll >= plinelen )
						{
							ll = 0;
							if (( stop = print_eol() ) == TRUE)
								break;
						}
						/* DjV 031 150203 ---^^^--- */

						if ((stop = prtchar(buffer[i])) == TRUE)
							break;
					}
					/* DjV 033 010203 ---vvv--- */
					/*
					if ((r = key_state(&key, TRUE)) > 0)
					{
						if (key == ESCAPE)
							stop = TRUE;
					}
					else if (r < 0)
						stop = TRUE;
					*/

					if ( escape_abort(TRUE) )
						stop = TRUE;

					/* DjV 033 010203 ---^^^--- */
				}
				else
					error = (int) l;
			}
			while ((l == PBUFSIZ) && (stop == FALSE));

			x_close(handle);
			print_eol(); /* DjV 031 150203 print cr lf at end of file */
		}
		else
			error = handle;

		if (stop == TRUE)
			result = XABORT;

		if (error != 0)
			result = xhndl_error(MEPRINT, error, itm_name(w, item));

		graf_mouse(ARROW, NULL);
		x_free(buffer);
	}
	else
	{
		xform_error(ENSMEM);
		result = XFATAL;
	}

	free(name);

	return result;
}
コード例 #9
0
ファイル: ethread_tests.c プロジェクト: 0x00evil/otp
static void print_line(char *frmt,...)
{
    PRINT_VA_LIST(frmt);
    print_eol();
}
コード例 #10
0
ファイル: erl_print_tests.c プロジェクト: AlainODea/otp
static void
print_cmp_test(int n, char *frmt, ...)
{
    int res = -1;
    static char clib_buf[BUF_SIZE];
    static unsigned char the_erts_buf[BUF_SIZE];
    char *erts_buf = (char *) &the_erts_buf[FENCE_SIZE]; 
    va_list args;

    if (outfile) {
	char *fp, *tp;
	va_start(args, frmt);
	if (n < 0)
	    res = vsprintf(erts_buf, frmt, args);
	else {
#ifdef HAVE_VSNPRINTF
	    res = vsnprintf(erts_buf, (size_t) n, frmt, args);
#else
	    fail("No vsnprintf()");
#endif
	}
	va_end(args);
	ASSERT(res >= 0);
	fp = erts_buf;
	tp = clib_buf;
	while (*fp) {
	    switch (*fp) {
	    case '\a':	*(tp++) = '\\';	*(tp++) = 'a';	break;
	    case '\b':	*(tp++) = '\\';	*(tp++) = 'b';	break;
	    case '\f':	*(tp++) = '\\';	*(tp++) = 'f';	break;
	    case '\n':	*(tp++) = '\\';	*(tp++) = 'n';	break;
	    case '\r':	*(tp++) = '\\';	*(tp++) = 'r';	break;
	    case '\t':	*(tp++) = '\\';	*(tp++) = 't';	break;
	    case '\v':	*(tp++) = '\\';	*(tp++) = 'v';	break;
	    case '\"':	*(tp++) = '\\';	*(tp++) = '\"';	break;
	    case '\\':	*(tp++) = '\\';	*(tp++) = '\\';	break;
	    default:	*(tp++) = *fp;			break;
	    }
	    fp++;
	}
	*tp = '\0';
	res = fprintf(outfile, "\t\"%s\",\n", clib_buf);
	ASSERT(res >= 0);
    }
    else {
	char *xres;
	va_start(args, frmt);
	if (n < 0)
	    res = erts_vsprintf(erts_buf, frmt, args);
	else {
	    int i;
	    int chk_sz = 2*FENCE_SIZE + n;
	    for (i = 0; i < chk_sz; i++)
		the_erts_buf[i] = 0xeb;
	    res = erts_vsnprintf(erts_buf, (size_t) n, frmt, args);
	    for (i = 0; i < chk_sz; i++)
		if ((((char *) &the_erts_buf[i]) < erts_buf
		     || erts_buf + n <= ((char *) &the_erts_buf[i]))
		    && the_erts_buf[i] != 0xeb) {
		    int j;
		    for (j = 0; j < chk_sz; j++)
			print(j ? ",%x(%d)" : "%x(%d)",
			      (unsigned) the_erts_buf[j], j - FENCE_SIZE);
		    print_eol();
		    fail("Garbage written out of bounds (%d,%d)",
			 i - FENCE_SIZE, n);
		}
	}
	va_end(args);
	ASSERT(res >= 0);

	if (expected_result) {
	    ASSERT(*expected_result);
	    xres = *expected_result;
	    expected_result++;
	}
	else {
	    va_start(args, frmt);
	    if (n < 0)
		res = vsprintf(clib_buf, frmt, args);
	    else {
#ifdef HAVE_VSNPRINTF
		res = vsnprintf(clib_buf, (size_t) n, frmt, args);
#else
		fail("No vsnprintf()");
#endif
	    }
	    va_end(args);
	    ASSERT(res >= 0);
	    xres = clib_buf;
	}

	if (strcmp(xres, erts_buf) != 0) {
	    print_line("expected result : \"%s\"", xres);
	    print_line("erts_buf        : \"%s\"", erts_buf);
	    fail("\"%s\" != \"%s\" (format=\"%s\")", xres, erts_buf, frmt);
	}

	print_line("Checked format \"%s\" with result: \"%s\"", frmt, erts_buf);
    }
}