示例#1
0
main()
{
    int   nitems;
    char  cline[MAXLINE];
    char  qchar, *malloc();
    Queue *qcreate();

    queue = qcreate( CHAR, 5 );
    printf("ready\n");
    while ( gets(cline) != NULL )  {
        if ( !strcmp( cline, "remove" ))  {
            if ( qremove( &qchar, queue ) == FAILURE )  {
                printf("queue empty\n");
                continue;
            }
            else  {
                printf("%c\n", qchar);
            }
        }
        else if ( !strcmp( cline, "read" ))  {
            if ( qread( &qchar, queue ) == FAILURE )  {
                printf("queue exhausted\n");
                continue;
            }
            else  {
                printf("%c\n", qchar);
            }
        }
        else if ( !strcmp( cline, "reset" ))  {
            qreset( queue );
        }
        else if ( !strcmp( cline, "clear" ))  {
            qclear( queue );
        }
        else if ( !strncmp( cline, "delete ", 7 ))  {
            if ( sscanf( cline, "delete %d", &nitems ) != 1 )  {
                printf("What?\n");
                continue;
            }
            if ( qdelete( nitems, queue ) == FAILURE )
                printf("too many items\n");
        }
        else  {
            qchar = cline[0];
            if ( qadd( &qchar, queue ) == FAILURE )
                printf("queue full\n");
        }
    }

    while ( qremove( &qchar, queue ) == SUCCESS )
        printf("%c\n");
    printf("queue empty\n");
}
int create_open_file(const char* file_name) {
	int file_id = qopen(file_name, O_BINARY | O_TRUNC | O_CREAT);
	if (file_id == BADADDR)
		file_id = qcreate(file_name, 511);

	return file_id;
}
示例#3
0
static void print_to_error_file(const char *error_msg) {
	int file_id = qopen(ERROR_FILE, O_WRONLY | O_APPEND);
	if (file_id == -1)
		file_id = qcreate(ERROR_FILE, 511);

	if (file_id == -1) {
		msg("FATAL: print_to_error_file failed!\n");
		return;
	}

	qwrite(file_id, error_msg, strlen(error_msg));
	qclose(file_id);
}
示例#4
0
static void print_to_output_file(const char *output_msg) {
	int file_id = qopen(OUTPUT_FILE, O_WRONLY | O_APPEND);
	if (file_id == -1)
		file_id = qcreate(OUTPUT_FILE, 511);

	if (file_id == -1) {
		msg("FATAL: print_to_output_file failed!\n");
		return;
	}

	qwrite(file_id, output_msg, strlen(output_msg));
	qclose(file_id);
}