本文整理汇总了C++中read_file函数的典型用法代码示例。如果您正苦于以下问题:C++ read_file函数的具体用法?C++ read_file怎么用?C++ read_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:hwp,项目名称:interactiveOR,代码行数:92,代码来源:spectrogram.c
示例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;
//.........这里部分代码省略.........
开发者ID:wchingwei,项目名称:BitTorrent,代码行数:101,代码来源:bt_lib.c
示例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);
}
开发者ID:carrotli,项目名称:ansql,代码行数:4,代码来源:ssl.cpp
示例4: read_file
string HighlightCutoffEffect::output_fragment_shader()
{
return read_file("highlight_cutoff_effect.frag");
}
开发者ID:ddennedy,项目名称:movit,代码行数:4,代码来源:glow_effect.cpp
示例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;
}
开发者ID:malleusinferni,项目名称:wry,代码行数:61,代码来源:wry.c
示例6: read_file
string SaturationEffect::output_fragment_shader()
{
return read_file("saturation_effect.frag");
}
开发者ID:ddennedy,项目名称:movit,代码行数:4,代码来源:saturation_effect.cpp
示例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;
}
开发者ID:Gaoyuan0710,项目名称:Datatructures,代码行数:98,代码来源:work2.c
示例8: read_input_file
static int read_input_file ( const char *filename,
struct input_file *input ) {
return read_file ( filename, &input->buf, &input->len );
}
开发者ID:42wim,项目名称:ipxe,代码行数:4,代码来源:zbin.c
示例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);
//.........这里部分代码省略.........
开发者ID:canvural,项目名称:OpenCL_Object_Detector,代码行数:101,代码来源:main.c
示例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 +
开发者ID:joyforu,项目名称:android-ltp-ndk,代码行数:67,代码来源:cpuctl_def_task02.c
示例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);
}
开发者ID:akpresto,项目名称:star-galaxy-classification,代码行数:91,代码来源:filter_calcs.c
示例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);
}
开发者ID:dirkmueller,项目名称:hwinfo,代码行数:86,代码来源:serial.c
示例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;
}
开发者ID:jhbsz,项目名称:DIR-850L_A1,代码行数:61,代码来源:sealpac.c
示例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;
}
开发者ID:nihed,项目名称:magnetism,代码行数:100,代码来源:viewer-win32.c
示例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
开发者ID:jyin0813,项目名称:OpenBSD-src,代码行数:67,代码来源:main.c
示例16: off_read_trace
Trace *
off_read_trace (Dbptr db, double tstart, double tend)
{
char fname[1024];
char dtype[8];
char segtype[8];
long foff, nsamp;
void *data;
Trace *trace;
double time, endtime, samprate;
double calib, calper;
int isamp, jsamp, size, nbytec;
int ret;
dbgetv (db, 0, "time", &time, "endtime", &endtime,
"samprate", &samprate,
"nsamp", &nsamp, "datatype", dtype,
"segtype", segtype, "foff", &foff,
"calib", &calib, "calper", &calper, NULL);
switch (dtype[0]) {
default:
break;
case 'c':
nbytec = nsamp;
nsamp = (endtime - time)*samprate + 1.5;
break;
}
isamp = (tstart - time)*samprate - 1.5;
jsamp = (tend - time)*samprate + 1.5;
if (isamp < 0) isamp = 0;
if (jsamp > nsamp-1) jsamp = nsamp-1;
nsamp = jsamp+1;
size = atoi(&dtype[strlen(dtype)-1]);
nsamp -= isamp;
time += isamp/samprate;
if (nsamp < 0) nsamp = 0;
data = NULL;
if (nsamp > 0) {
if (dbfilename (db, fname) < 1) {
fprintf (stderr, "read_trace: Unable to find input file '%s'\n",
fname);
nsamp = 0;
data = NULL;
} else {
switch (dtype[0]) {
default:
foff += isamp*size;
if (!read_file (fname, foff, dtype, &nsamp, &data)) {
fprintf (stderr, "read_trace: Unable to read input file '%s'\n",
fname);
return (NULL);
}
break;
case 'c':
data = malloc (nsamp*size);
if (data == NULL) {
fprintf (stderr, "read_trace: malloc() error.\n");
return (NULL);
}
dtype[0] = 's';
ret = wf_read_idacompress (fname, foff, nbytec, isamp, nsamp, size, data);
if (ret < 0) {
fprintf (stderr, "read_trace: wf_read_idacompress() error.\n");
free (data);
return (NULL);
}
if (ret < nsamp) nsamp = ret;
break;
}
}
}
trace = (Trace *) malloc (sizeof(Trace));
if (trace == NULL) {
fprintf (stderr, "read_trace: Malloc error on Trace structure.\n");
free (data);
return (NULL);
}
trace->tstart = time;
trace->dt = 1.0/samprate;
trace->nsamps = nsamp;
trace->calib = calib;
trace->calper = calper;
strcpy (trace->rawdata_format, dtype);
strcpy (trace->rawdata_type, segtype);
trace->data = NULL;
trace->data_free = NULL;
trace->data_malloc = 0;
trace->raw_data = data;
trace->rawdata_free = data;
if (data) trace->rawdata_malloc = nsamp*size;
else trace->rawdata_malloc = 0;
trace->prev = NULL;
trace->next = NULL;
if (data) trace = (Trace *) SCV_trace_fixgaps (trace, "segment");
return (trace);
}
开发者ID:battistuz,项目名称:antelope_contrib,代码行数:97,代码来源:trace_subs.c
示例17: main
int main(int argc, char *argv[])
{
char *file_name = " Usage: -f filename";
CALC_MODE mode = CM_OVERLAP; // 計算する方式
int is_chaged = 1; // 計算方法に変更があったか
ACTION act; // 操作を選択
int threshold = 2; // 計算に用いる出現頻度の最小値
int i;
init(); // 要素の確保
// コマンドライン引数の読み込み
for (i = 0; i < argc; i++)
{
if (strcmp(argv[i], "-f") == 0 && i + 1 < argc) // 次の文字列があれば
file_name = argv[i + 1]; // 開くファイルを読み込む
}
read_file(file_name); // ファイル読み込み
printf("\nFinished Reading File\n");
printf("Total number of documents read = %d\n", n_docs);
printf("Total number of words in the index = %d\n", n_words);
fflush(stdout);
printf("\nCurrent Indicator Type: %s\n", mode_string[mode]);
while (1)
{
if (is_chaged) // 変更があった場合
{
free_results(); // 前回の結果の消去
// 次回の計算用
results = (RESULTS **)malloc(sizeof(RESULTS *) * n_results_max);
if (results == NULL)
{
fprintf(stderr, "Memory Allocation Error\n");
exit(1);
}
calc_indicator(mode, threshold); // 強度の計算
printf("\nCalculation Finished\n");
fflush(stdout);
sort_results(); // 結果のソート
printf("\nSort Finished\n");
fflush(stdout);
}
printf("\nCurrent Indicator Type: %s, Threshold: %d\n",
mode_string[mode], threshold);
printf("Choose Action (-1:Quit)\n");
printf("0:Show Results 1:Change Indicator \n");
printf("2:Change Precision 3:Write to Csv \n> ");
act = read_input_as_int(); // 操作を選択
switch (act)
{
case A_QUIT: // 終了
free_all();
printf("Quit\n");
return 0;
case A_SHOW_RESULTS:
show_results_in_range(); // 結果の表示
is_chaged = 0;
break;
case A_CHANGE_INDICATOR: // 計算方法の変更
is_chaged = change_mode(&mode);
break;
case A_CHANGE_PRECISION:
is_chaged = change_threshold(&threshold); // 計算に用いるときの閾値(頻度)の変更
break;
case A_WRITE_CSV:
write_to_csv_in_range(); // CSV形式で書き出し
is_chaged = 0;
break;
default:
break;
}
}
return 0;
}
开发者ID:tiwanari,项目名称:pro_exce,代码行数:92,代码来源:03-123006.c
示例18: generic_cache_info
/**
* information about the cache: level, associativity...
*/
int generic_cache_info(int cpu, int id, char* output, size_t len)
{
char tmp[_HW_DETECT_MAX_OUTPUT], tmp2[_HW_DETECT_MAX_OUTPUT];
char tmppath[_HW_DETECT_MAX_OUTPUT];
struct stat statbuf;
if (cpu == -1) cpu = get_cpu();
if (cpu == -1) return -1;
snprintf(path,sizeof(path), "/sys/devices/system/cpu/cpu%i/cache/index%i/", cpu, id);
memset(output, 0, len);
if(stat(path, &statbuf)) //path doesn't exist
return -1;
strncpy(tmppath, path, _HW_DETECT_MAX_OUTPUT);
strncat(tmppath, "level", (_HW_DETECT_MAX_OUTPUT-strlen(tmppath))-1);
if(read_file(tmppath, tmp, _HW_DETECT_MAX_OUTPUT)) {
snprintf(tmp2,_HW_DETECT_MAX_OUTPUT-1, "Level %s", tmp);
strncat(output, tmp2, (len-strlen(output))-1);
}
strncpy(tmppath, path, _HW_DETECT_MAX_OUTPUT);
strncat(tmppath, "type", (_HW_DETECT_MAX_OUTPUT-strlen(tmppath))-1);
if(read_file(tmppath, tmp, _HW_DETECT_MAX_OUTPUT)) {
if(!strcmp(tmp, "Unified")) {
strncpy(tmp2, output,_HW_DETECT_MAX_OUTPUT-1);
snprintf(output, len, "%s ", tmp);
strncat(output, tmp2, (len-strlen(output))-1);
}
else {
strncat(output, " ", (len-strlen(output))-1);
strncat(output, tmp, (len-strlen(output))-1);
}
}
strncat(output, " Cache,", (len-strlen(output))-1);
strncpy(tmppath, path, _HW_DETECT_MAX_OUTPUT);
strncat(tmppath, "size", (_HW_DETECT_MAX_OUTPUT-strlen(tmppath))-1);
if(read_file(tmppath, tmp, _HW_DETECT_MAX_OUTPUT)) {
strncat(output, " ", (len-strlen(output))-1);
strncat(output, tmp, (len-strlen(output))-1);
}
strncpy(tmppath, path, _HW_DETECT_MAX_OUTPUT);
strncat(tmppath, "ways_of_associativity", (_HW_DETECT_MAX_OUTPUT-strlen(tmppath))-1);
if(read_file(tmppath, tmp, _HW_DETECT_MAX_OUTPUT)) {
strncat(output, ", ", (len-strlen(output))-1);
strncat(output, tmp, (len-strlen(output))-1);
strncat(output, "-way set associative", (len-strlen(output))-1);
}
strncpy(tmppath, path,_HW_DETECT_MAX_OUTPUT);
strncat(tmppath, "coherency_line_size", (_HW_DETECT_MAX_OUTPUT-strlen(tmppath))-1);
if(read_file(tmppath, tmp, _HW_DETECT_MAX_OUTPUT)) {
strncat(output, ", ", (len-strlen(output))-1);
strncat(output, tmp, (len-strlen(output))-1);
strncat(output, " Byte cachelines", (len-strlen(output))-1);
}
strncpy(tmppath, path,_HW_DETECT_MAX_OUTPUT);
strncat(tmppath, "shared_cpu_map",(_HW_DETECT_MAX_OUTPUT-strlen(tmppath))-1);
if(read_file(tmppath, tmp, _HW_DETECT_MAX_OUTPUT)) {
cpu_map_to_list(tmp, tmp2, _HW_DETECT_MAX_OUTPUT);
snprintf(tmppath,_HW_DETECT_MAX_OUTPUT, "cpu%i ", cpu);
if(!strcmp(tmp2, tmppath))
{
strncat(output, ", exclusive for ", (len-strlen(output))-1);
strncat(output, tmppath, (len-strlen(output))-1);
}
else
{
strncat(output, ", shared among ", (len-strlen(output))-1);
strncat(output, tmp2, (len-strlen(output))-1);
}
}
return 0;
}
开发者ID:tud-zih-energy,项目名称:FIRESTARTER,代码行数:81,代码来源:generic.c
示例19: main
int main(int argc, char **argv){
cl_context context = get_platform(CL_DEVICE_TYPE_GPU);
cl_device_id device = 0;
cl_command_queue queue = get_first_device(context, &device);
char *prog_src = read_file(CL_PROGRAM("convolution.cl"), NULL);
cl_program program = build_program(prog_src, context, device, NULL);
free(prog_src);
cl_int err = CL_SUCCESS;
cl_kernel kernel = clCreateKernel(program, "convolve", &err);
check_cl_err(err, "failed to create kernel");
//Setup our input signal and mask
cl_uint in_signal[IN_DIM][IN_DIM] = {
{ 3, 1, 1, 4, 8, 2, 1, 3 },
{ 4, 2, 1, 1, 2, 1, 2, 3 },
{ 4, 4, 4, 4, 3, 2, 2, 2 },
{ 9, 8, 3, 8, 9, 0, 0, 0 },
{ 9, 3, 3, 9, 0, 0, 0, 0 },
{ 0, 9, 0, 8, 0, 0, 0, 0 },
{ 3, 0, 8, 8, 9, 4, 4, 4 },
{ 5, 9, 8, 1, 8, 1, 1, 1 }
};
cl_uint mask[MASK_DIM][MASK_DIM] = {
{ 1, 1, 1 },
{ 1, 0, 1 },
{ 1, 1, 1 }
};
//0 is input, 1 is mask, 2 is output
cl_mem mem_objs[3];
mem_objs[0] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(cl_uint) * IN_DIM * IN_DIM, in_signal, &err);
mem_objs[1] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
sizeof(cl_uint) * MASK_DIM * MASK_DIM, mask, &err);
mem_objs[2] = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
sizeof(cl_uint) * OUT_DIM * OUT_DIM, NULL, &err);
check_cl_err(err, "failed to create buffers");
for (int i = 0; i < 3; ++i){
err = clSetKernelArg(kernel, i, sizeof(cl
|
请发表评论