本文整理汇总了C++中read_file函数的典型用法代码示例。如果您正苦于以下问题:C++ read_file函数的具体用法?C++ read_file怎么用?C++ read_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_file函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv) {
int showhelp = 0;
unsigned int channels = 1;
int window_size = 1024;
int shift = 256;
int rate = 8000;
snd_pcm_format_t format = SND_PCM_FORMAT_UNKNOWN;
int opt;
while ((opt = getopt(argc, argv, "hw:s:r:f:")) != -1) {
switch (opt) {
case 'h':
showhelp = 1;
break;
case 'w':
window_size = atoi(optarg);
break;
case 's':
shift = atoi(optarg);
break;
case 'r':
rate = atoi(optarg);
break;
case 'f':
format = snd_pcm_format_value(optarg);
break;
default: /* '?' */
showhelp = 1;
break;
}
}
if (showhelp || argc - optind < 1) {
fprintf(stderr, "Usage: %s [-w window_size] [-s shift] "
"[-r sampling rate] [-f format] <inputFile>\n", argv[0]);
exit(EXIT_SUCCESS);
}
if (format == SND_PCM_FORMAT_UNKNOWN) {
fprintf(stderr, "Unknown format\n");
exit(EXIT_FAILURE);
}
FILE* input = fopen(argv[optind], "r");
if (input == NULL) {
fprintf(stderr, "Cannot Open File %s : %s\n", argv[optind], strerror(errno));
exit(EXIT_FAILURE);
}
// Load Audio File
double** data;
unsigned long int count = pcm_size(input, channels, format);
count = read_file(input, count, channels, format, &data);
fprintf(stderr, "%lu samples read\n", count);
fclose(input);
// Transform
int nos = number_of_spectrum(count, window_size, shift);
TimeFreq* tf = alloc_tf(window_size, nos);
stft(data[0], count, window_size, shift, tf);
printf("set style line 11 lc rgb '#808080' lt 1\n"
"set border 3 front ls 11\n"
"set tics nomirror out scale 0.75\n"
"unset key\n"
"unset colorbox\n"
"set palette defined (0 '#000090', 1 '#000fff', 2 '#0090ff', 3 '#0fffee', 4 '#90ff70', 5 '#ffee00', 6 '#ff7000', 7 '#ee0000', 8 '#7f0000')\n"
"set xlabel 'Time (s)'\n"
"set ylabel 'Frequency (Hz)'\n");
printf("set yrange [0:%g]\n", (double) rate / 2.0);
printf("set xrange [0:%g]\n", (double) count / rate);
printf("plot '-' matrix using (($2 + 0.5) * %g) : (($1 + 0.5) * %g) : (log($3))"
" with image\n", (double) shift / rate,
(double) rate / window_size);
int i, j;
for (i = 0; i < nos; i++) {
Spectra s = get_spectra(tf, i);
for (j = 0; j < window_size / 2 + 1; j++) {
printf("%g ", get_magnitude(s, j));
}
printf("\n");
}
printf("e\n");
// Free memory
free_data(data, channels);
free_tf(tf);
exit(EXIT_SUCCESS);
}
示例2: contact_tracker
int contact_tracker(bt_args_t *bt_args)
{
printf("Please wait ...\nConnecting with tracker.\n");
char *new_file;
long long leng;
new_file = read_file(bt_args->torrent_file, &leng);
if (!new_file)
return 1;
char *inf = strstr(strstr(new_file, "info"), "d");
// length on ubuntu 14.04 torrent should be 44478
long long len = be_len(inf);
memset(bt_args->info_hash, '\0', BT_INFO_HASH_SIZE);
memset(bt_args->bt_peer_id, '\0', BT_INFO_HASH_SIZE);
SHA1((unsigned char const *) inf, (size_t) len, (unsigned char *) bt_args->info_hash);
char *request_to_send = malloc(FILE_NAME_MAX);
request_to_send = malloc(FILE_NAME_MAX);
memset(request_to_send, '\0', FILE_NAME_MAX);
memcpy(bt_args->bt_peer_id, generate_peer_id(), 20);
//Port number this peer is listening on.
//Common behavior is for a downloader to try to listen on
//port 6881 and if that port is taken try 6882, then 6883, etc. and give up after 6889.
uint16_t port = INIT_PORT;
bt_args->bt_info->num_pieces = bt_args->bt_info->length / bt_args->bt_info->piece_length;
sprintf(request_to_send,
"%s?info_hash=%s&peer_id=%s&port=%hu&uploaded=0"
"&downloaded=0&left=%d&event=started&compact=1",
bt_args->bt_info->announce, url_encode(bt_args->info_hash),
url_encode(bt_args->bt_peer_id), port, bt_args->bt_info->length);
// correct request to send on ubuntu torrent
// http://torrent.ubuntu.com:6969/announce?
// info_hash=%B4%15%C9%13d%3E%5F%F4%9F%E3%7D0K%BB%5En%11%ADQ%01
// announce?info_hash=%b4%15%c9%13d%3e_%f4%9f%e3%7d0K%bb%5en%11%adQ%01
// &peer_id=TueFeb32137332015RRR&port=6681&event=started&uploaded=0
// &downloaded=0&left=1162936320&compact=1
if (bt_args->verbose)
printf("Request URL for tracker: %s\n", request_to_send);
char *result = _send_http_request(request_to_send);
if (result)
{
be_node *node = be_decoden(result, (long long int) be_len);
if (bt_args->verbose)
be_dump(node);
bt_peer *peer = malloc(sizeof(bt_peer));
// parse_info(peer, node);
_fill_peer_info(peer, node, 0, "");
int num_peers = 0;
char *peer_num = strstr(result, "peers");
if (peer_num == NULL)
{
printf("Something went wrong in parsing received data!\n");
free(result);
return 1;
}
int i = 0;
peer_num += 5;
char buff[20];
memset(buff, 0, 20);
for (; *peer_num != ':'; peer_num++, i++)
buff[i] = *peer_num;
char *endptr;
num_peers = (int) strtol(buff, &endptr, 10) / 6;
if (num_peers == 0)
{
free(result);
return 1;
}
int count = 0;
pthread_t *thread = malloc(num_peers * sizeof(pthread_t));
printf("Connecting with peers.\n");
for (i = 0; i < num_peers; i++)
{
uint32_t ip = *(uint32_t *) (peer->peer_hashes + count);
count = (int) (count + sizeof(uint32_t));
port = *(uint16_t *) (peer->peer_hashes + count);
count = (int) (count + sizeof(uint16_t));
peer_t *my_peer_t = malloc(sizeof(peer_t));
my_peer_t->interested = -1;
my_peer_t->choked = -1;
//.........这里部分代码省略.........
示例3: SSL_CTX_use_certificate_file
int SSL_CTX_use_certificate_file(SSL_CTX* ctx, const char* file, int format)
{
return read_file(ctx, file, format, Cert);
}
示例4: read_file
string HighlightCutoffEffect::output_fragment_shader()
{
return read_file("highlight_cutoff_effect.frag");
}
示例5: main
int main(int argc, char **argv) {
init_buf();
if (argc > 1)
strncpy(file_name, argv[1], BUFSIZ);
else
strcpy(file_name, "untitled.txt");
read_file(file_name);
initscr();
cbreak();
noecho();
if (has_colors()) {
int white;
start_color();
if (COLORS > 255)
white = 231;
else if (COLORS > 87)
white = 79;
else
white = 15;
init_pair(1, white, 0);
minibuf_attrs = COLOR_PAIR(1);
} else {
minibuf_attrs = A_BOLD;
}
while (TRUE) {
int ch;
// Redisplay
drop_until(getmaxy(stdscr) / 2);
print_queue();
mbuf_display();
refresh();
// Wait for input
switch ((ch = getch())) {
case EOF:
case '\x04': // ^D
quit();
case '\x08': // ^H
case '\x7f': // DEL
del_buf(buf.i - 1); break;
case '\x17': // ^W
del_buf(buf.wbeg); break;
case '\x15': // ^U
reset_buf("");
break;
case '\x1b': // ESC
mbuf_msg("Press CTRL+D to quit");
break;
case '\r':
case '\n':
append_buf('\n');
break;
default:
mbuf_msg(file_name);
if (ch > '\x1f')
append_buf(ch);
}
}
return 0;
}
示例6: read_file
string SaturationEffect::output_fragment_shader()
{
return read_file("saturation_effect.frag");
}
示例7: main
int main(int argc, char *argv[])
{
HTNODE ht[MAX];
HTNODE hs[MAX];
Char_code *head;
Char_code *p;
CODE *code;
CODE *q;
char data[MAX][MAX];
char data1[MAX][MAX];
int i;
int j;
int count = 0;
int pch = 0;
int qch = 0;
int ii, jj;
head = read_file(head, "a.png");
count = get_len(head);
Creat_Huffman(ht, head, count);
Get_Code(ht, data1, count);
write_import(ht, data1, count , "c.txt");
code = get_tree(code, "c.txt");
count = get_count(code);
Creat_Huffman_file(hs, code, count);
Get_Code_file(hs, data, count, code);
p = head->next;
q = code->next;
/*
while (p && q)
{
if (p->ch == 0)
{
pch++;
}
if (q->ch == 0)
{
qch++;
}
p = p->next;
q = q->next;
}
*/
while (p && q)
{
if (p->ch != q->ch )
{
printf("ch butong\n");
printf("p->ch %c %d q->ch %c \n", p->ch,p->ch, q->ch);
printf("p->count %d, q->count %d\n", p->count, q->count);
getchar();
// getchar();
}
if (p->count != q->count)
{
printf("count butong\n");
printf("%d %d", p->count, q->count);
// getchar();
}
p = p->next;
q = q->next;
}
if (p || q)
{
printf("ollllll\n");
getchar();
}
trans_to_code(code, "a.png", "data.txt");
Get_Language(hs, count, "data.txt", "b.png");
ii = get_count(code);
jj = get_len(head);
printf("ii = %d, jj = %d\n", ii, jj);
return EXIT_SUCCESS;
}
示例8: read_input_file
static int read_input_file ( const char *filename,
struct input_file *input ) {
return read_file ( filename, &input->buf, &input->len );
}
示例9: main
int main(int argc, char *argv[])
{
int err;
cl_platform_id platform;
cl_device_id device;
cl_command_queue command_queue;
cl_program program;
cl_kernel kernel;
cl_context context;
//##############################//
//########OpenCL Stuff##########//
//##############################//
// find platform and device to use
if (!connect_to_device(CL_DEVICE_TYPE_GPU, &platform, &device)) {
printf ("Unable to find suitable OpenCL device!\n");
return 1;
}
char buffer[512];
clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof (buffer), buffer, NULL);
printf ("Using device: %s\n", buffer);
context = clCreateContext(0, 1, &device, NULL, NULL, &err);
if (!context || err != CL_SUCCESS) {
printf("ERROR: Failed to create a compute context! %s\n", get_ocl_error(err));
return EXIT_FAILURE;
}
cl_command_queue_properties properties = CL_QUEUE_PROFILING_ENABLE;
command_queue = clCreateCommandQueue (context, device, properties, &err);
if (!command_queue || err != CL_SUCCESS) {
printf("ERROR: Failed to create a command commands! %s\n", get_ocl_error(err));
return EXIT_FAILURE;
}
const char *strings[] = {NULL, NULL};
strings[0] = read_file(KERNEL_FILE);
if (strings[0] == NULL) {
fprintf(stderr, "Unable to find \"%s\"", KERNEL_FILE);
return 1;
}
program = clCreateProgramWithSource(context, 1, (const char **) & strings[0], NULL, &err);
if (!program || err != CL_SUCCESS) {
printf("ERROR: Failed to create compute program! %s\n", get_ocl_error(err));
return EXIT_FAILURE;
}
err = clBuildProgram(program, 0, NULL, NULL, NULL, NULL);
if (err != CL_SUCCESS) {
size_t len;
char buffer[2048];
printf("ERROR: Failed to build program executable! %s\n", get_ocl_error(err));
clGetProgramBuildInfo(program, device, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &len);
printf("%s\n", buffer);
return EXIT_FAILURE;
}
kernel = clCreateKernel(program, KERNEL_FUNC, &err);
if (!kernel || err != CL_SUCCESS) {
printf("ERROR: Failed to create compute kernel! %s\n", get_ocl_error(err));
exit(1);
}
edizinami **all_histograms = malloc(0 * sizeof(edizinami*));
if(all_histograms == NULL) {
printf("Cannot allocate memory!");
return -1;
}
// Get all weak classifiers and dataset we'll use
read_all_histograms(&all_histograms);
for(int i = 0; i < current_size; i++) {
int total = 0;
//printf("Hallelujah! %s\n", all_histograms[i]->filename);
// Initial weights
all_histograms[i]->weight = 1 / current_size;
}
for(int i = 0; i < current_size; i++) {
free(all_histograms[i]->filename);
free(all_histograms[i]->data);
free(all_histograms[i]);
}
free(all_histograms);
clReleaseCommandQueue(command_queue);
//.........这里部分代码省略.........
示例10: main
//.........这里部分代码省略.........
strcat(mysharesfile, "/cpu.shares");
pid = getpid();
write_to_file(mytaskfile, "a", pid); /* Assign task to it's group*/
fd = open("./myfifo", 0);
if (fd == -1)
tst_brkm(TBROK, cleanup,
"Could not open fifo for synchronization");
read(fd, &ch, 1); /* Block task here to synchronize */
/*
* We now calculate the expected % cpu time of this task by getting
* it's group's shares, the total shares of all the groups and the
* number of tasks in this group.
*/
FLAG = 0;
total_shares = 0;
shares_pointer = &total_shares;
len = strlen(path);
if (!strncpy(fullpath, path, len))
tst_brkm(TBROK, cleanup,
"Could not copy directory path %s ", path);
if (scan_shares_files(shares_pointer) != 0)
tst_brkm(TBROK, cleanup,
"From function scan_shares_files in %s ", fullpath);
/* return val -1 in case of function error, else 2 is min share value */
if ((fmyshares = read_shares_file(mysharesfile)) < 2)
tst_brkm(TBROK, cleanup,
"in reading shares files %s ", mysharesfile);
if ((read_file(mytaskfile, GET_TASKS, &num_tasks)) < 0)
tst_brkm(TBROK, cleanup,
"in reading tasks files %s ", mytaskfile);
exp_cpu_time = (double)(fmyshares * 100) / (total_shares * num_tasks);
prev_time = time(NULL); /* Note down the time*/
while (1) {
/*
* Need to run some cpu intensive task, which also
* frequently checks the timer value
*/
double f = 274.345, mytime; /*just a float number for sqrt*/
alarm(TIME_INTERVAL);
timer_expired = 0;
/*
* Let the task run on cpu for TIME_INTERVAL. Time of this
* operation should not be high otherwise we can exceed the
* TIME_INTERVAL to measure cpu usage
*/
while (!timer_expired)
f = sqrt(f * f);
current_time = time(NULL);
/* Duration in case its not exact TIME_INTERVAL*/
delta_time = current_time - prev_time;
getrusage(0, &cpu_usage);
/* total_cpu_time = total user time + total sys time */
total_cpu_time = (cpu_usage.ru_utime.tv_sec +
cpu_usage.ru_utime.tv_usec * 1e-6 +
cpu_usage.ru_stime.tv_sec +
示例11: filter_calcs
void filter_calcs(void) {
//External variables
extern char filtersinput[FILEPATH_LENGTH];
extern char galssedinput[FILEPATH_LENGTH];
extern char starssedinput[FILEPATH_LENGTH];
//Internal variables
long *N,ii;
long sedlength = 0;
long regridfactor;
long filterlength[Nfilter];
double *pnorm;
double *filtlamb,*filtthru;
//Allocate temporary variables
N = (long *)malloc(sizeof(long));
pnorm = (double *)malloc(sizeof(double));
//How many filters?
get_num_files(filtersinput, N);
Nfilter = *N;
if (Nfilter<2) {
printf("Need more than 1 filter\n");
return;
}
printf("\n\nFound %ld Filters\n",Nfilter);
//Read in the number of star/galaxy SEDs
get_num_files(starssedinput, N);
Nstartemplate = *N;
get_num_files(galssedinput, N);
Ngaltemplate = *N;
//Find the finest SED amongst the bunch
for (ii=0;ii<Nstartemplate;ii++) {
get_filelength(ii,starssedinput,N);
if (*N * 2 > sedlength)
sedlength = *N * 2;
}
for (ii=0;ii<Ngaltemplate;ii++) {
get_filelength(ii,galssedinput,N);
if (*N * 2 > sedlength)
sedlength = *N * 2;
}
//Allocate final filter arrays, which are globals
filter_lgth_fine = (long *)malloc(Nfilter*sizeof(long));
filter_lamb_fine = malloc(Nfilter*sizeof(double*));
filter_thru_fine = malloc(Nfilter*sizeof(double*));
norm = (double *)malloc(Nfilter*sizeof(double));
//Loop over the filters in the file
for (ii=0;ii<Nfilter;ii++) {
//get length
get_filelength(ii,filtersinput, N);
filterlength[ii] = *N;
regridfactor = round((float)sedlength / (float)*N);
filter_lgth_fine[ii] = *N * regridfactor;
//alloc filter arrays
filtlamb = (double *)malloc(*N * sizeof(double));
filtthru = (double *)malloc(*N * sizeof(double));
filter_lamb_fine[ii] = (double *)malloc(regridfactor * *N * sizeof(double));
filter_thru_fine[ii] = (double *)malloc(regridfactor * *N * sizeof(double));
//read in the 2 column ascii filter file
read_file(ii,filtersinput,filtlamb,filtthru);
//regrid the filter to user spec, using gsl spline interpolation
regrid_filter(filtlamb,filtthru,filterlength[ii],filter_lgth_fine[ii], \
filter_lamb_fine[ii],filter_thru_fine[ii]);
//calculate the flux zeropoint
calc_normalization(filter_lamb_fine[ii],filter_thru_fine[ii], \
filter_lgth_fine[ii],pnorm);
norm[ii] = *pnorm;
printf("Filter %ld has (AB) zeropoint flux normalization: %g\n",ii,norm[ii]);
free(filtlamb);
free(filtthru);
}
free(pnorm);
free(N);
}
示例12: get_serial_info
void get_serial_info(hd_data_t *hd_data)
{
char buf[64];
unsigned u0, u1, u2;
#if !defined(__PPC__)
unsigned u3;
#endif
int i;
str_list_t *sl, *sl0, **sll;
serial_t *ser;
#if !defined(__PPC__)
/*
* Max. 44 serial lines at the moment; the serial proc interface is
* somewhat buggy at the moment (2.2.13), hence the explicit 44 lines
* limit. That may be dropped later.
*/
sl0 = read_file(PROC_DRIVER_SERIAL, 1, 44);
sll = &sl0;
while(*sll) sll = &(*sll)->next;
// append Agere modem devices
*sll = read_file("/proc/tty/driver/agrserial", 1, 17);
// ########## FIX !!!!!!!! ########
if(sl0) {
for(sl = sl0; sl; sl = sl->next) {
i = 0;
if(
sscanf(sl->str, "%u: uart:%31s port:%x irq:%u baud:%u", &u0, buf, &u1, &u2, &u3) == 5 ||
(i = 1, sscanf(sl->str, "%u: uart:%31s port:%x irq:%u tx:%u", &u0, buf, &u1, &u2, &u3) == 5)
) {
/*
* The 'baud' or 'tx' entries are only present for real interfaces.
*/
ser = add_serial_entry(&hd_data->serial, new_mem(sizeof *ser));
ser->line = u0;
if(u1 >= 0x100) ser->port = u1; // Agere modem does not use real port numbers
ser->irq = u2;
if(!i) ser->baud = u3;
ser->name = new_str(buf);
}
}
if((hd_data->debug & HD_DEB_SERIAL)) {
/* log just the first 16 entries */
ADD2LOG("----- "PROC_DRIVER_SERIAL" -----\n");
for(sl = sl0, i = 16; sl && i--; sl = sl->next) {
ADD2LOG(" %s", sl->str);
}
ADD2LOG("----- "PROC_DRIVER_SERIAL" end -----\n");
}
}
#endif /* !defined(__PPC__) */
#if defined(__PPC__)
sl0 = read_file(PROC_DRIVER_MACSERIAL, 1, 0);
if(sl0) {
for(sl = sl0; sl; sl = sl->next) {
if(
(i = sscanf(sl->str, "%u: port:%x irq:%u con:%63[^\n]", &u0, &u1, &u2, buf)) >= 3
) {
ser = add_serial_entry(&hd_data->serial, new_mem(sizeof *ser));
ser->line = u0;
ser->port = u1;
ser->irq = u2;
ser->name = new_str("SCC");
if(i == 4) ser->device = new_str(buf);
}
}
if((hd_data->debug & HD_DEB_SERIAL)) {
/* log just the first 16 entries */
ADD2LOG("----- "PROC_DRIVER_MACSERIAL" -----\n");
for(sl = sl0, i = 16; sl && i--; sl = sl->next) {
ADD2LOG(" %s", sl->str);
}
ADD2LOG("----- "PROC_DRIVER_MACSERIAL" end -----\n");
}
}
#endif /* defined(__PPC__) */
free_str_list(sl0);
}
示例13: read_directory
static int read_directory(const char * dname)
{
int ret = 0;
solist_t files;
solist_t dirs;
strobj_t sobj;
//d_dbg("%s: dname = '%s'\n",__func__,dname);
do
{
files = solist_new();
dirs = solist_new();
if (!files || !dirs)
{
ret = -1;
verbose("solist_new() return error!\n");
break;
}
ret = read_file_list(dname, files, dirs);
if (ret < 0)
{
verbose("error reading file list @ '%s' !\n", dname);
break;
}
/* handle files first */
ret = 0;
while ((sobj=solist_get_next(files)) != NULL)
{
ret = read_file(sobj_get_string(sobj));
if (ret < 0)
{
verbose("error handling file - '%s'\n",sobj_get_string(sobj));
break;
}
}
if (ret < 0) break;
/* handle diretories if recursive. */
if (o_recursive)
{
ret = 0;
while ((sobj=solist_get_next(dirs)) != NULL)
{
ret = read_directory(sobj_get_string(sobj));
if (ret < 0)
{
verbose("error handling directory - '%s'\n",sobj_get_string(sobj));
break;
}
}
if (ret < 0) break;
}
} while (0);
if (files) solist_del(files);
if (dirs) solist_del(dirs);
return ret;
}
示例14: main
int
main (int argc, char **argv)
{
char *text;
GtkWidget *window;
GtkWidget *scrollwin;
GtkWidget *vbox, *hbox;
GtkWidget *frame;
GtkWidget *checkbutton;
gtk_init (&argc, &argv);
if (argc != 2)
{
fprintf (stderr, "Usage: %s FILE\n", g_get_prgname ());
exit(1);
}
/* Create the list of paragraphs from the supplied file
*/
text = read_file (argv[1]);
if (!text)
exit(1);
context = pango_win32_get_context ();
paragraphs = split_paragraphs (text);
pango_context_set_language (context, pango_language_from_string ("en_US"));
pango_context_set_base_dir (context, PANGO_DIRECTION_LTR);
font_description = pango_font_description_new ();
pango_font_description_set_family(font_description, "sans");
pango_font_description_set_size(font_description, 16 * PANGO_SCALE);
#if 0 /* default init ok? */
font_description.style = PANGO_STYLE_NORMAL;
font_description.variant = PANGO_VARIANT_NORMAL;
font_description.weight = 500;
font_description.stretch = PANGO_STRETCH_NORMAL;
#endif
pango_context_set_font_description (context, font_description);
/* Create the user interface
*/
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_add (GTK_CONTAINER (window), vbox);
hbox = make_font_selector ();
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
scrollwin = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrollwin),
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_box_pack_start (GTK_BOX (vbox), scrollwin, TRUE, TRUE, 0);
layout = gtk_layout_new (NULL, NULL);
gtk_widget_set_events (layout, GDK_BUTTON_PRESS_MASK);
gtk_widget_set_app_paintable (layout, TRUE);
gtk_signal_connect (GTK_OBJECT (layout), "size_allocate",
GTK_SIGNAL_FUNC (size_allocate), paragraphs);
gtk_signal_connect (GTK_OBJECT (layout), "expose_event",
GTK_SIGNAL_FUNC (expose), paragraphs);
gtk_signal_connect (GTK_OBJECT (layout), "draw",
GTK_SIGNAL_FUNC (draw), paragraphs);
gtk_signal_connect (GTK_OBJECT (layout), "button_press_event",
GTK_SIGNAL_FUNC (button_press), paragraphs);
#if GTK_CHECK_VERSION (1,3,2)
gtk_widget_set_double_buffered (layout, FALSE);
#endif
gtk_container_add (GTK_CONTAINER (scrollwin), layout);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
message_label = gtk_label_new ("Current char:");
gtk_misc_set_padding (GTK_MISC (message_label), 1, 1);
gtk_misc_set_alignment (GTK_MISC (message_label), 0.0, 0.5);
gtk_container_add (GTK_CONTAINER (frame), message_label);
checkbutton = gtk_check_button_new_with_label ("Use RTL global direction");
gtk_signal_connect (GTK_OBJECT (checkbutton), "toggled",
GTK_SIGNAL_FUNC (checkbutton_toggled), NULL);
gtk_box_pack_start (GTK_BOX (vbox), checkbutton, FALSE, FALSE, 0);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}
示例15: main
//.........这里部分代码省略.........
}
if (seed != NULL)
srandom(atol(seed));
else
srandomdev();
if (f_usage)
fprintf(stderr,
"usage: %s [-lpqstu?] [-f game] [-g game] [-r seed]\n",
name);
if (f_showscore)
log_score(1);
if (f_list)
list_games();
if (f_printpath) {
size_t len;
char buf[256];
strlcpy(buf, _PATH_GAMES, sizeof buf);
len = strlen(buf);
if (len != 0 && buf[len - 1] == '/')
buf[len - 1] = '\0';
puts(buf);
}
if (f_usage || f_showscore || f_list || f_printpath)
exit(0);
if (file == NULL)
file = default_game();
else
file = okay_game(file);
if (file == NULL || read_file(file) < 0)
exit(1);
setup_screen(sp);
addplane();
signal(SIGINT, quit);
signal(SIGQUIT, quit);
#ifdef BSD
signal(SIGTSTP, SIG_IGN);
signal(SIGSTOP, SIG_IGN);
#endif
signal(SIGHUP, log_score_quit);
signal(SIGTERM, log_score_quit);
tcgetattr(fileno(stdin), &tty_start);
tty_new = tty_start;
tty_new.c_lflag &= ~(ICANON|ECHO);
tty_new.c_iflag |= ICRNL;
tty_new.c_cc[VMIN] = 1;
tty_new.c_cc[VTIME] = 0;
tcsetattr(fileno(stdin), TCSADRAIN, &tty_new);
memset(&sa, 0, sizeof sa);
sa.sa_handler = update;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGALRM);
sigaddset(&sa.sa_mask, SIGINT);
sa.sa_flags = 0;
sigaction(SIGALRM, &sa, (struct sigaction *)0);
#ifdef BSD