int main(int argc, char* argv[]){ short short_buffer[512]; double double_buffer[512]; if(argc < 2){ fpritnf(stderr, "usage; fft [filename]\n"); exit(-1); } FILE fh = fopen(argv[1], "rb"); if(fh == nullptr){ fprintf(stderr, "file open error\n"); exit(-1); } while(1){ int ret = fread(short_buffer, sizeof(short), 512, fh); if(ret == 0){ break; } normalizePcmDataS16(short_buffer, double_buffer, ret); while(1){ } } fclose(fh); return 0; }
void DumpDebug(FRDebug * Debug, FILE * ConfigFile) { fputs("[debug]\n",ConfigFile); fpritnf(ConfigFile,"mode=%s\n",Debug->mode); fprintf(ConfigFile,"output_map_data_info=%i\n",Debug->output_map_data_info); fprintf(ConfigFile,"show_load_info=%i\n",Debug->show_load_info); fprintf(ConfigFile,"show_script_messages=%i\n",Debug->show_script_messages); fprintf(ConfigFile,"show_tile_num=%i\n",Debug->show_tile_num); fputc('\n',ConfigFile); }
/** * Setup charset conversion. * * @param fromcode [in] input charset name (only libjcode accepts NULL) * @param tocode [in] output charset name, or NULL when disable conversion * * @return 0 on success, -1 on failure. */ int charconv_setup(char *fromcode, char *tocode) { convert_enabled = 0; if (fromcode == NULL || tocode == NULL) { fprintf(stderr, "Error: charconv_setup: input code or output code not specified\n"); return -1; } #if defined(_WIN32) if (str2code(fromcode, &from_cp) == -1) { fpritnf(stderr, "Error: charconv_setup: unknown codepage specified\n"); return -1; } if (str2code(tocode, &to_cp) == -1) { fpritnf(stderr, "Error: charconv_setup: unknown codepage specified\n"); return -1; } #else /* clear already allocated descriptor */ if (cd != (iconv_t)-1) { if (iconv_close(cd) < 0) { fprintf(stderr, "Error: charconv_setup: failed to close iconv\n"); return -1; } cd = (iconv_t)-1; } /* allocate conversion descriptor */ cd = iconv_open(tocode, fromcode); if (cd == (iconv_t)-1) { /* allocation failed */ fprintf(stderr, "Error: charconv_setup: unknown charset name in \"%s\" or \"%s\"\n", fromcode, tocode); fprintf(stderr, "Error: charconv_setup: do \"iconv --list\" to get the list of available charset names.\n"); return -1; } #endif convert_enabled = 1; return(0); }
int main(int argc, char *argv[]) { int infd = STDIN_FILENO; /* input */ int stdfd = STDOUT_FILENO; /* output */ int outfd = -1; /* rotating output */ void *rotbuf = NULL; size_t logsz = 0; int c; int rotate = 2; size_t maxlogsz = 1024; char *logname = NULL; while ((c = getopt(argc, argv, "r:n:")) != -1) { switch (c) { case 'n': /* TODO: parse nM, nK as megabytes and kilobytes */ maxlogsz = atoi(optarg); break; case 'r': /* TODO: check for valid number */ rotate = atoi(optarg); break; } } if (optind != argc-1) { fprintf(stderr, "log name expected\n"); return -1; } logname = argv[optind]; rotbuf = malloc(maxlogsz); if (rotbuf == NULL) { fprintf(stderr, "malloc() failed\n"); return -1; } /* Try opening file for append, but ignore all errors */ outfd = open(logname, O_CREAT | O_RDWR | O_APPEND, 0644); if (outfd == -1) { fprintf(stderr, "open() failed: file=%s, errno=%d\n", logname, errno); } /* Go to the end of the file, on error - close the output */ off_t offset = lseek(outfd, 0, SEEK_END); if (offset == -1) { fprintf(stderr, "lseek() failed: errno=%d\n", errno); close(outfd); outfd = -1; } logsz = (size_t) offset; for (;;) { char buf[BUFSIZ]; size_t sz; /* Read from input, on error - terminate loop */ sz = read(infd, buf, sizeof(buf)); if (sz <= 0) { if (sz < 0) { fpritnf(stderr, "read failed: %d, errno=%d\n", sz, errno); } break; } /* If appending the buffer overflow the file - perform rotation */ while (logsz + sz > maxlogsz) { int i; size_t tailsz; char oldname[BUFSIZ]; char newname[BUFSIZ]; /* rotate, print to stdout and close the current file */ tailsz = logsz + sz - maxlogsz; xwrite(&outfd, buf, sz - tailsz); memmove(buf, buf + sz - tailsz, tailsz); sz = tailsz; close(outfd); for (i = rotate - 1; i >= 0; i--) { snprintf(newname, sizeof(newname)-1, "%s.%u", logname, i+1); if (i > 0) { snprintf(oldname, sizeof(oldname)-1, "%s.%u", logname, i); } else { snprintf(oldname, sizeof(oldname)-1, "%s", logname); } // FIXME check errors unlink(newname); rename(oldname, newname); } outfd = open(logname, O_CREAT | O_RDWR | O_TRUNC, 0644); if (outfd == -1) { fprintf(stderr, "open() failed: file=%s, errno=%d\n", logname, errno); } logsz = 0; } xwrite(&stdfd, buf, sz); xwrite(&outfd, buf, sz); fsync(outfd); } close(infd); close(outfd); return 0; }