void my_putc(char c) { fputc(c, stderr); }
void docIdSubOutput(struct docIdSub *el, FILE *f, char sep, char lastSep) /* Print out docIdSub. Separate fields with sep. Follow last field with lastSep. */ { fprintf(f, "%d", el->ix); fputc(sep,f); fprintf(f, "%d", el->status); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->assembly); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->submitDate); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->md5sum); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->valReport); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->valVersion); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->metaData); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->submitPath); if (sep == ',') fputc('"',f); fputc(sep,f); if (sep == ',') fputc('"',f); fprintf(f, "%s", el->submitter); if (sep == ',') fputc('"',f); fputc(lastSep,f); }
/* * This routine checks to see if a filesystem can be skipped; if so, * it will exit with E2FSCK_OK. Under some conditions it will print a * message explaining why a check is being forced. */ static void check_if_skip(e2fsck_t ctx) { ext2_filsys fs = ctx->fs; const char *reason = NULL; unsigned int reason_arg = 0; long next_check; int batt = is_on_batt(); int defer_check_on_battery; int broken_system_clock; time_t lastcheck; profile_get_boolean(ctx->profile, "options", "broken_system_clock", 0, 0, &broken_system_clock); if (ctx->flags & E2F_FLAG_TIME_INSANE) broken_system_clock = 1; profile_get_boolean(ctx->profile, "options", "defer_check_on_battery", 0, 1, &defer_check_on_battery); if (!defer_check_on_battery) batt = 0; if ((ctx->options & E2F_OPT_FORCE) || bad_blocks_file || cflag) return; lastcheck = fs->super->s_lastcheck; if (lastcheck > ctx->now) lastcheck -= ctx->time_fudge; if ((fs->super->s_state & EXT2_ERROR_FS) || !ext2fs_test_valid(fs)) reason = _(" contains a file system with errors"); else if ((fs->super->s_state & EXT2_VALID_FS) == 0) reason = _(" was not cleanly unmounted"); else if (check_backup_super_block(ctx)) reason = _(" primary superblock features different from backup"); else if ((fs->super->s_max_mnt_count > 0) && (fs->super->s_mnt_count >= (unsigned) fs->super->s_max_mnt_count)) { reason = _(" has been mounted %u times without being checked"); reason_arg = fs->super->s_mnt_count; if (batt && (fs->super->s_mnt_count < (unsigned) fs->super->s_max_mnt_count*2)) reason = 0; } else if (!broken_system_clock && fs->super->s_checkinterval && (ctx->now < lastcheck)) { reason = _(" has filesystem last checked time in the future"); if (batt) reason = 0; } else if (!broken_system_clock && fs->super->s_checkinterval && ((ctx->now - lastcheck) >= ((time_t) fs->super->s_checkinterval))) { reason = _(" has gone %u days without being checked"); reason_arg = (ctx->now - fs->super->s_lastcheck)/(3600*24); if (batt && ((ctx->now - fs->super->s_lastcheck) < fs->super->s_checkinterval*2)) reason = 0; } if (reason) { fputs(ctx->device_name, stdout); printf(reason, reason_arg); fputs(_(", check forced.\n"), stdout); return; } printf(_("%s: clean, %u/%u files, %u/%u blocks"), ctx->device_name, fs->super->s_inodes_count - fs->super->s_free_inodes_count, fs->super->s_inodes_count, fs->super->s_blocks_count - fs->super->s_free_blocks_count, fs->super->s_blocks_count); next_check = 100000; if (fs->super->s_max_mnt_count > 0) { next_check = fs->super->s_max_mnt_count - fs->super->s_mnt_count; if (next_check <= 0) next_check = 1; } if (!broken_system_clock && fs->super->s_checkinterval && ((ctx->now - fs->super->s_lastcheck) >= fs->super->s_checkinterval)) next_check = 1; if (next_check <= 5) { if (next_check == 1) { if (batt) fputs(_(" (check deferred; on battery)"), stdout); else fputs(_(" (check after next mount)"), stdout); } else printf(_(" (check in %ld mounts)"), next_check); } fputc('\n', stdout); ext2fs_close(fs); ctx->fs = NULL; e2fsck_free_context(ctx); exit(FSCK_OK); }
int main(int argc, char* argv[]) { // ensure proper usage if (argc != 4) { printf("Usage: ./resize n infile outfile\n"); return 1; } int n = atoi(argv[1]); if (n < 1 || n >= 100) { printf("unable to resize ; input number between [1,100) \n"); return 2; } // remember filenames char* infile = argv[2]; char* outfile = argv[3]; // open input file FILE* inptr = fopen(infile, "r"); if (inptr == NULL) { printf("Could not open %s.\n", infile); return 3; } // open output file FILE* outptr = fopen(outfile, "w"); if (outptr == NULL) { fclose(inptr); fprintf(stderr, "Could not create %s.\n", outfile); return 4; } // read infile's BITMAPFILEHEADER BITMAPFILEHEADER bf; fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr); // read infile's BITMAPINFOHEADER BITMAPINFOHEADER bi; fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr); // ensure infile is (likely) a 24-bit uncompressed BMP 4.0 if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 || bi.biBitCount != 24 || bi.biCompression != 0) { fclose(outptr); fclose(inptr); fprintf(stderr, "Unsupported file format.\n"); return 5; } // remember original height , width and padding int org_h = abs(bi.biHeight); int org_w = bi.biWidth; int padding_org = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; // new height,width and padding bi.biWidth *= n ; bi.biHeight *= n ; int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * ( abs(bi.biHeight) ); bf.bfSize = bi.biSizeImage + 54; // write outfile's BITMAPFILEHEADER fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr); // write outfile's BITMAPINFOHEADER fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr); // iterate over infile's scanlines for (int i = 0; i < org_h ; i++) { for(int k=1; k <= n ; k++) { // iterate over pixels in scanline for (int j = 0; j < org_w; j++) { // temporary storage RGBTRIPLE triple; // read RGB triple from infile fread(&triple, sizeof(RGBTRIPLE), 1, inptr); // write RGB triple to outfile for(int l=1;l <= n ;l++) fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr); } // skip over padding, if any fseek(inptr, padding_org, SEEK_CUR); // then add it back (to demonstrate how) for (int m = 0; m < padding; m++) fputc(0x00, outptr); // don't do this last time if (k < n) fseek(inptr, -(org_w * sizeof(RGBTRIPLE) + padding_org ),SEEK_CUR);// sending cursor in infile back to start } } // close infile fclose(inptr); // close outfile fclose(outptr); // that's all folks return 0; }
int buf_ctor(struct buf_s *buf, size_t bsiz, size_t rblk, size_t wblk, int rline, int wline, size_t hpage, size_t ioar, size_t ioaw) { int ret = -1; size_t adj, page, idx, rblki, wblki, bsiza, csiza; if (!buf) { fputs("buf: no buf ?\n", stderr); return -1; } if (bsiz < 2*rblk || bsiz < 2*wblk) { fputs("buf: 'buffer size' must be at least 2*max('read block, 'write block'),\n" " to avoid corner case starvations.\n", stderr); return -1; } memset(buf, 0, sizeof *buf); #ifndef h_mingw page = sysconf(_SC_PAGESIZE); if (page == hpage) { hpage = 0; } page = hpage ? hpage : page; adj = MAX(page, SHMLBA); #else hpage = 0; adj = page = 4096; #endif bsiza = ALIGN(bsiz, adj); if (!(idx = is_pow2(bsiza))) { fprintf(stderr, "buf: 'aligned buffer size' must be power of 2, but is: 0x%zX\n", bsiza); goto out; } buf->mask = (((size_t)1 << idx) - 1); rblki = ALIGN(rblk, ioar); wblki = ALIGN(wblk, ioaw); csiza = ALIGN(rblki + wblki, adj); buf->size = bsiza; preset_shm(buf); if (setup_shm(buf, bsiza, csiza, hpage) < 0) { fputs("buf: falling back to regular malloc()\n", stderr); ret = 1; detach_shm(buf); rm_shm(buf); preset_mal(buf); if (setup_mal(buf, bsiza, csiza, adj) < 0) { detach_mal(buf); ret = -1; goto out; } } else ret = 0; buf->rchunk = buf->chk; buf->wchunk = buf->chk + rblki; buf->flags |= hpage && buf->mapW ? M_HUGE : 0; buf->flags |= rline ? M_LINER : 0; buf->flags |= wline ? M_LINEW : 0; // buf->page = page; buf->ioar = ioar; buf->ioaw = ioaw; buf->rblk = rblk; buf->wblk = wblk; buf->crcw = crc_beg(); buf->crcr = buf->crcw; #if 0 if (rblk < wblk && rline && !wline) { fputs("buf: 'read block' must be greater or equal to 'write block',\n" " if the left side is in the line mode,\n" " and the right side is in the reblocking mode.\n", stderr); goto out; } #endif DEB("\nbuf map: C:%p, B:%p, B+S:%p, W:%p\n", buf->mapC, buf->mapB, buf->mapB + buf->size, buf->mapW); DEB("buf buf: C:%p, B:%p\n", buf->chk, buf->buf); out: if (ret < 0) buf_dtor(buf); fputc('\n', stderr); return ret; }
void PDF::WriteString(const char * name, const char * string) { WriteName(name); WriteString(string); fputc('\n', file); }
void PDF::WriteDate(const char * name, int year, int month, int day) { WriteName(name); WriteDate(year, month, day); fputc('\n', file); }
void svOutput::Printf( svLogLevel level, const char *format, va_list ap) { if (!debug && level == svLOG_DEBUG) return; pthread_mutex_lock(&mutex); #ifndef __WIN32__ if (log_file != NULL) { switch (level) { case svLOG_DEBUG: fprintf(log_file, "DEBUG: "); break; case svLOG_ERR: fprintf(log_file, "ERROR: "); break; default: break; } vfprintf(log_file, format, ap); fputc('\n', log_file); } #ifdef __ANDROID__ int priority; switch (level) { case svLOG_DEBUG: priority = ANDROID_LOG_DEBUG; break; case svLOG_INFO: priority = ANDROID_LOG_INFO; break; case svLOG_ERR: priority = ANDROID_LOG_ERROR; break; } __android_log_vprint(priority, "Suva", format, ap); #elif defined(HAVE_SYSLOG_H) if (log_facility == 0) { switch (level) { case svLOG_DEBUG: fprintf(stderr, "DEBUG: "); break; case svLOG_ERR: fprintf(stderr, "ERROR: "); break; default: break; } vfprintf(stderr, format, ap); fputc('\n', stderr); pthread_mutex_unlock(&mutex); return; } int priority = log_facility; switch (level) { case svLOG_DEBUG: priority |= LOG_DEBUG; break; case svLOG_INFO: priority |= LOG_INFO; break; case svLOG_ERR: priority |= LOG_ERR; break; } vsyslog(priority, format, ap); #endif // __ANDROID__ #else #define MSG_EVENT 0x00000064L if (el_source) { char message[512]; vsnprintf(message, sizeof(message), format, ap); char *log_str[1]; log_str[0] = message; DWORD el_type = EVENTLOG_INFORMATION_TYPE; switch (level) { case svLOG_DEBUG: el_type = EVENTLOG_WARNING_TYPE; case svLOG_ERR: el_type = EVENTLOG_ERROR_TYPE; } ReportEvent(el_source, el_type, 0, MSG_EVENT, NULL, 1, 0, (const char **)log_str, NULL); } else { switch (level) { case svLOG_DEBUG: fprintf(stdout, "DEBUG: "); break; case svLOG_ERR: fprintf(stdout, "ERROR: "); break; default: break; } vfprintf(stdout, format, ap); fputc('\n', stdout); } #endif pthread_mutex_unlock(&mutex); }
int main (int argc, char** argv) { char * curfilename; char toprint; FILE * fp; int i = 1; while(argv[i]!=NULL) { if (strcmp(argv[i], "--help") == 0) { printf("Usage: cat-lite [--help] [FILE]...\n"); printf("With no FILE, or when FILE is -, read standard input.\n\n"); printf("Examples:\n"); printf(" cat-lite README Print the file README to standard output.\n"); printf(" cat-lite f - g Print f's contents, then standard input,\n then g's contents.\n"); printf(" cat-lite Copy standard input to standard output.\n"); return EXIT_SUCCESS; } i++; } if(argv[1]==NULL) { fp = stdin; while(1) { toprint = fgetc(fp); if(feof(fp) == 1) { break; } fputc(toprint, stdout); // or printf("%c", toprint); } } i = 1; while(argv[i]!=NULL) { curfilename = argv[i]; if(strcmp(curfilename, "-") == 0) { fp = stdin; } else { fp = fopen(curfilename, "r"); } //might have to read file, count \n's, then set the size of the array to that. //char * filelines[256]; if(fp == NULL) { fprintf(stderr, "cat cannot open %s\n", curfilename); return EXIT_FAILURE; } while(1) { toprint = fgetc(fp); if(feof(fp) == 1) { break; } fputc(toprint, stdout); // or printf("%c", toprint); } if(strcmp(curfilename, "-") != 0) { fclose(fp); } i++; } //while( fscanf("%s\n", filelines) != EOF) //{ //} /*[zpaurus@ecelinux12 PA04]$ echo ... | ./cat-lite testcases/file3 - testcases/file4 I would not like them here or there. I would not like them anywhere. I do not like green eggs and ham. I do not like them, Sam-I-Am. ... Say! I like green eggs and ham! I do! I like them, Sam-I-Am! And I would eat them in a boat. And I would eat them with a goat... And I will eat them, in the rain. And in the dark. And on a train. And in a car. And in a tree. They are so good, so good, you see! So I will eat them in a box. And I will eat them with a fox. And I will eat them in a house. And I will eat them with a mouse. And I will eat them here and there. Say! I will eat them anywhere! I do so like green eggs and ham! Thank you! Thank you, Sam-I-Am.*/ return EXIT_SUCCESS; }
static inline void incr_bar(size_t this_index, size_t ntot, size_t ntoprint, char c) { if ( this_index % (ntot/ntoprint) != 0 ) return; fputc(c,stderr); }
/** * name: ExportModule * desc: write all settings from a database module to file * param: hContact - handle of contact the module is owned from * pszModule - name of the module to save * file - file to write the settings to * return nothing **/ static void ExportModule(MCONTACT hContact, LPCSTR pszModule, FILE* file) { DB::CEnumList Settings; if (!Settings.EnumSettings(hContact, pszModule)) { DBVARIANT dbv; LPSTR here; WORD j; int i; LPSTR pszSetting; //char tmp[32]; // print the module header.. fprintf(file, "\n[%s]\n", pszModule); for (i = 0; i < Settings.getCount(); i++) { pszSetting = Settings[i]; if (!DB::Setting::GetAsIs(hContact, pszModule, pszSetting, &dbv)) { switch (dbv.type) { case DBVT_BYTE: { fprintf(file, "%s=b%u\n", pszSetting, dbv.bVal); } break; case DBVT_WORD: { fprintf(file, "%s=w%u\n", pszSetting, dbv.wVal); } break; case DBVT_DWORD: { fprintf(file, "%s=d%u\n", pszSetting, dbv.dVal); } break; case DBVT_ASCIIZ: case DBVT_UTF8: { for (here = dbv.pszVal; here && *here; here++) { switch (*here) { // convert \r to STX case '\r': *here = 2; break; // convert \n to ETX case '\n': *here = 3; } } if (dbv.type == DBVT_UTF8) fprintf(file, "%s=u%s\n", pszSetting, dbv.pszVal); else fprintf(file, "%s=s%s\n", pszSetting, dbv.pszVal); } break; case DBVT_BLOB: { fprintf(file, "%s=n", pszSetting); for (j = 0; j < dbv.cpbVal; j++) { fprintf(file, "%02X ", (BYTE)dbv.pbVal[j]); } fputc('\n', file); } break; } db_free(&dbv); } } } }
void repeat_char(char c, int n) { for (int i=0; i<n; i++) { fputc(c,stderr); } }
/* * Creates the config file and tells i3 to reload. * */ static void finish() { printf("creating \"%s\"...\n", config_path); if (!(dpy = XOpenDisplay(NULL))) errx(1, "Could not connect to X11"); FILE *kc_config = fopen(SYSCONFDIR "/i3/config.keycodes", "r"); if (kc_config == NULL) err(1, "Could not open input file \"%s\"", SYSCONFDIR "/i3/config.keycodes"); FILE *ks_config = fopen(config_path, "w"); if (ks_config == NULL) err(1, "Could not open output config file \"%s\"", config_path); free(config_path); char *line = NULL; size_t len = 0; #ifndef USE_FGETLN ssize_t read; #endif bool head_of_file = true; /* write a header about auto-generation to the output file */ fputs("# This file has been auto-generated by i3-config-wizard(1).\n", ks_config); fputs("# It will not be overwritten, so edit it as you like.\n", ks_config); fputs("#\n", ks_config); fputs("# Should you change your keyboard layout some time, delete\n", ks_config); fputs("# this file and re-run i3-config-wizard(1).\n", ks_config); fputs("#\n", ks_config); #ifdef USE_FGETLN char *buf = NULL; while ((buf = fgetln(kc_config, &len)) != NULL) { /* fgetln does not return null-terminated strings */ FREE(line); sasprintf(&line, "%.*s", len, buf); #else size_t linecap = 0; while ((read = getline(&line, &linecap, kc_config)) != -1) { len = strlen(line); #endif /* skip the warning block at the beginning of the input file */ if (head_of_file && strncmp("# WARNING", line, strlen("# WARNING")) == 0) continue; head_of_file = false; /* Skip leading whitespace */ char *walk = line; while (isspace(*walk) && walk < (line + len)) { /* Pre-output the skipped whitespaces to keep proper indentation */ fputc(*walk, ks_config); walk++; } /* Set the modifier the user chose */ if (strncmp(walk, "set $mod ", strlen("set $mod ")) == 0) { if (modifier == MOD_Mod1) fputs("set $mod Mod1\n", ks_config); else fputs("set $mod Mod4\n", ks_config); continue; } /* Check for 'bindcode'. If it’s not a bindcode line, we * just copy it to the output file */ if (strncmp(walk, "bindcode", strlen("bindcode")) != 0) { fputs(walk, ks_config); continue; } char *result = rewrite_binding(walk); fputs(result, ks_config); free(result); } /* sync to do our best in order to have the file really stored on disk */ fflush(ks_config); fsync(fileno(ks_config)); #ifndef USE_FGETLN free(line); #endif fclose(kc_config); fclose(ks_config); /* tell i3 to reload the config file */ int sockfd = ipc_connect(socket_path); ipc_send_message(sockfd, strlen("reload"), 0, (uint8_t *)"reload"); close(sockfd); exit(0); } int main(int argc, char *argv[]) { config_path = resolve_tilde("~/.i3/config"); socket_path = getenv("I3SOCK"); char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; char *patternbold = "-misc-fixed-bold-r-normal--13-120-75-75-C-70-iso10646-1"; int o, option_index = 0; static struct option long_options[] = { {"socket", required_argument, 0, 's'}, {"version", no_argument, 0, 'v'}, {"limit", required_argument, 0, 'l'}, {"prompt", required_argument, 0, 'P'}, {"prefix", required_argument, 0, 'p'}, {"font", required_argument, 0, 'f'}, {"help", no_argument, 0, 'h'}, {0, 0, 0, 0}}; char *options_string = "s:vh"; while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { switch (o) { case 's': FREE(socket_path); socket_path = strdup(optarg); break; case 'v': printf("i3-config-wizard " I3_VERSION "\n"); return 0; case 'h': printf("i3-config-wizard " I3_VERSION "\n"); printf("i3-config-wizard [-s <socket>] [-v]\n"); return 0; } } /* Check if the destination config file does not exist but the path is * writable. If not, exit now, this program is not useful in that case. */ struct stat stbuf; if (stat(config_path, &stbuf) == 0) { printf("The config file \"%s\" already exists. Exiting.\n", config_path); return 0; } /* Create ~/.i3 if it does not yet exist */ char *config_dir = resolve_tilde("~/.i3"); if (stat(config_dir, &stbuf) != 0) if (mkdir(config_dir, 0755) == -1) err(1, "mkdir(%s) failed", config_dir); free(config_dir); int fd; if ((fd = open(config_path, O_CREAT | O_RDWR, 0644)) == -1) { printf("Cannot open file \"%s\" for writing: %s. Exiting.\n", config_path, strerror(errno)); return 0; } close(fd); unlink(config_path); int screen; if ((conn = xcb_connect(NULL, &screen)) == NULL || xcb_connection_has_error(conn)) errx(1, "Cannot open display\n"); if (socket_path == NULL) socket_path = root_atom_contents("I3_SOCKET_PATH", conn, screen); if (socket_path == NULL) socket_path = "/tmp/i3-ipc.sock"; keysyms = xcb_key_symbols_alloc(conn); xcb_get_modifier_mapping_cookie_t modmap_cookie; modmap_cookie = xcb_get_modifier_mapping(conn); symbols = xcb_key_symbols_alloc(conn); /* Place requests for the atoms we need as soon as possible */ #define xmacro(atom) \ xcb_intern_atom_cookie_t atom##_cookie = xcb_intern_atom(conn, 0, strlen(#atom), #atom); #include "atoms.xmacro" #undef xmacro root_screen = xcb_aux_get_screen(conn, screen); root = root_screen->root; if (!(modmap_reply = xcb_get_modifier_mapping_reply(conn, modmap_cookie, NULL))) errx(EXIT_FAILURE, "Could not get modifier mapping\n"); xcb_numlock_mask = get_mod_mask_for(XCB_NUM_LOCK, symbols, modmap_reply); font = load_font(pattern, true); bold_font = load_font(patternbold, true); /* Open an input window */ win = xcb_generate_id(conn); xcb_create_window( conn, XCB_COPY_FROM_PARENT, win, /* the window id */ root, /* parent == root */ 490, 297, 300, 205, /* dimensions */ 0, /* X11 border = 0, we draw our own */ XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */ XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, (uint32_t[]) { 0, /* back pixel: black */ XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS}); /* Map the window (make it visible) */ xcb_map_window(conn, win); /* Setup NetWM atoms */ #define xmacro(name) \ do { \ xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(conn, name##_cookie, NULL); \ if (!reply) \ errx(EXIT_FAILURE, "Could not get atom " #name "\n"); \ \ A_##name = reply->atom; \ free(reply); \ } while (0); #include "atoms.xmacro" #undef xmacro /* Set dock mode */ xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win, A__NET_WM_WINDOW_TYPE, A_ATOM, 32, 1, (unsigned char *)&A__NET_WM_WINDOW_TYPE_DIALOG); /* Set window title */ xcb_change_property(conn, XCB_PROP_MODE_REPLACE, win, A__NET_WM_NAME, A_UTF8_STRING, 8, strlen("i3: first configuration"), "i3: first configuration"); /* Create pixmap */ pixmap = xcb_generate_id(conn); pixmap_gc = xcb_generate_id(conn); xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, 500); xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0); /* Grab the keyboard to get all input */ xcb_flush(conn); /* Try (repeatedly, if necessary) to grab the keyboard. We might not * get the keyboard at the first attempt because of the keybinding * still being active when started via a wm’s keybinding. */ xcb_grab_keyboard_cookie_t cookie; xcb_grab_keyboard_reply_t *reply = NULL; int count = 0; while ((reply == NULL || reply->status != XCB_GRAB_STATUS_SUCCESS) && (count++ < 500)) { cookie = xcb_grab_keyboard(conn, false, win, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); reply = xcb_grab_keyboard_reply(conn, cookie, NULL); usleep(1000); } if (reply->status != XCB_GRAB_STATUS_SUCCESS) { fprintf(stderr, "Could not grab keyboard, status = %d\n", reply->status); exit(-1); } xcb_flush(conn); xcb_generic_event_t *event; while ((event = xcb_wait_for_event(conn)) != NULL) { if (event->response_type == 0) { fprintf(stderr, "X11 Error received! sequence %x\n", event->sequence); continue; } /* Strip off the highest bit (set if the event is generated) */ int type = (event->response_type & 0x7F); switch (type) { case XCB_KEY_PRESS: handle_key_press(NULL, conn, (xcb_key_press_event_t *)event); break; /* TODO: handle mappingnotify */ case XCB_BUTTON_PRESS: handle_button_press((xcb_button_press_event_t *)event); break; case XCB_EXPOSE: handle_expose(); break; } free(event); } return 0; }
int job_qs_upgrade( job *pj, /* I */ int fds, /* I */ char *path, /* I */ int version) /* I */ { char namebuf[MAXPATHLEN]; char log_buf[LOCAL_LOG_BUF_SIZE]; FILE *source; FILE *backup; int c; /* reset the file descriptor */ if (lseek(fds, 0, SEEK_SET) != 0) { sprintf(log_buf, "unable to reset fds\n"); log_err(-1, __func__, log_buf); return (-1); } snprintf(namebuf, sizeof(namebuf), "%s", path); namebuf[strlen(path) - strlen(JOB_FILE_SUFFIX)] = '\0'; /* cut off the .JB by replacing the '.' with a NULL */ if (strlen(namebuf) + strlen(JOB_FILE_BACKUP) > MAXPATHLEN - 1) { sprintf(log_buf, "ERROR: path too long for buffer, unable to backup!\n"); log_err(-1, __func__, log_buf); return (-1); } strcat(namebuf, JOB_FILE_BACKUP); source = fdopen(dup(fds), "r"); if ((backup = fopen(namebuf, "wb")) == NULL) { sprintf(log_buf, "Cannot open backup file.\n"); log_err(errno, __func__, log_buf); return -1; } while ((c = fgetc(source)) != EOF) { fputc(c, backup); } fclose(backup); fclose(source); sprintf(log_buf, "backed up to %s\n", namebuf); log_err(-1, __func__, log_buf); /* reset the file descriptor */ if (lseek(fds, 0, SEEK_SET) != 0) { sprintf(log_buf, "unable to reset fds\n"); log_err(-1, __func__, log_buf); return (-1); } if (version > PBS_QS_VERSION) { sprintf(log_buf, "job struct appears to be from an unknown " "version of TORQUE and can not be converted"); log_err(-1, "job_qs_upgrade", log_buf); return (-1); } else if (version - PBS_QS_VERSION_BASE == 1) { return upgrade_v1(pj, fds); } /* old style version numbers... */ else if (version == 0x00020300) { return upgrade_2_3_X(pj, fds); } else if (version == 0x00020200) { return upgrade_2_2_X(pj, fds); } /* predates versioning of ji_qs. assume 2.1.x format */ else { return upgrade_2_1_X(pj, fds); } }
void PDF::WriteDouble(const char * name, double value) { WriteName(name); WriteDouble(value); fputc('\n', file); }
static int ProcessDocs (query_data * qd, int num, int verbatim, char OutputType, FILE * Output) { int max_buf = 0; int DocCount = 0; char *doc_sepstr = NULL; char *para_sepstr = NULL; char *para_start = NULL; int heads_length = atoi (GetDefEnv ("heads_length", "50")); char QueryType = get_query_type (); int need_text = (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE || OutputType == OUTPUT_HEADERS || OutputType == OUTPUT_SILENT); if (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE) { if (QueryType == QUERY_APPROX || QueryType == QUERY_RANKED) { doc_sepstr = de_escape_string ( Xstrdup (GetDefEnv ("ranked_doc_sepstr", "---------------------------------- %n %w\\n"))); } else { doc_sepstr = de_escape_string ( Xstrdup (GetDefEnv ("doc_sepstr", "---------------------------------- %n\\n"))); } para_sepstr = de_escape_string ( Xstrdup (GetDefEnv ("para_sepstr", "\\n######## PARAGRAPH %n ########\\n"))); para_start = de_escape_string ( Xstrdup (GetDefEnv ("para_start", "***** Weight = %w *****\\n"))); } if (need_text) { max_buf = atoi (GetDefEnv ("buffer", "1048576")); } do { u_char *UDoc = NULL; unsigned long ULen; if (need_text) { /* load the compressed text */ if (LoadCompressedText (qd, max_buf)) { Message ("Unable to load compressed text."); FatalError (1, "This is probably due to lack of memory."); } /* uncompress the loaded text */ UDoc = GetDocText (qd, &ULen); if (UDoc == NULL) FatalError (1, "UDoc is unexpectedly NULL"); } if (!UDoc || PostProc ((char *) UDoc, verbatim)) { switch (OutputType) { case OUTPUT_COUNT: case OUTPUT_SILENT: break; case OUTPUT_DOCNUMS: /* This prints out the docnums string */ if (PagerRunning) fprintf (Output, "%8d %6.4f %7lu\n", GetDocNum (qd), GetDocWeight (qd), GetDocCompLength (qd)); break; case OUTPUT_HEADERS: /* This prints out the headers of the documents */ if (PagerRunning) fprintf (Output, "%d ", GetDocNum (qd)); HeaderOut (Output, UDoc, ULen, heads_length); if (PagerRunning) fputc ('\n', Output); break; #if TREC_MODE case OUTPUT_EXTRAS: /* This prints out the docnums string */ if (PagerRunning && trec_ids) { long DN, PN = GetDocNum (qd) - 1; if (trec_paras) DN = trec_paras[PN]; else DN = PN; fprintf (Output, "%-14.14s %8ld %10.5f\n", &trec_ids[DN * 14], PN + 1, GetDocWeight (qd)); } break; #endif case OUTPUT_TEXT: case OUTPUT_HILITE: { int j, para = -1, curr_para = 0; int init_para = -1; DocEntry *de, *doc_chain = NULL; int p_on = 0; register char ch = ' '; register char lch = '\n'; if (PagerRunning) { StringOut (Output, doc_sepstr, 1, GetDocNum (qd), QueryType == 'A' || QueryType == 'R', GetDocWeight (qd)); } if (qd->id->ifh.InvfLevel == 3) { init_para = FetchInitialParagraph (qd->td, GetDocNum (qd)); doc_chain = GetDocChain (qd); para = GetDocNum (qd) - init_para; StringOut (Output, para_sepstr, 1, curr_para + 1, 0, 0); if ((de = in_chain (0, init_para, doc_chain))) StringOut (Output, para_start, 0, 0, 1, de->Weight); if (doc_chain->DocNum - init_para == 0) p_on = 1; } for (j = 0; j < ULen; j++) { ch = UDoc[j]; switch (ch) { case '\02': break; case '\01': ch = '\n'; case '\03': p_on = 0; curr_para++; StringOut (Output, para_sepstr, 1, curr_para + 1, 0, 0); lch = *(strchr (para_sepstr, '\0') - 1); if ((de = in_chain (curr_para, init_para, doc_chain))) StringOut (Output, para_start, 0, 0, 1, de->Weight); if (doc_chain && doc_chain->DocNum - init_para == curr_para) p_on = 1; break; default: { if (PagerRunning) { fputc (ch, Output); if (p_on && isprint (ch)) { fputc ('\b', Output); fputc ('_', Output); } } lch = ch; } } } if (PagerRunning && lch != '\n') fputc ('\n', Output); p_on = 0; } } if (PagerRunning) fflush (Output); } DocCount++; } while (NextDoc (qd) && PagerRunning && (!Ctrl_C)); if (need_text) { FreeTextBuffer (qd); } if (OutputType == OUTPUT_TEXT || OutputType == OUTPUT_HILITE) { Xfree (doc_sepstr); Xfree (para_sepstr); Xfree (para_start); } return (DocCount); }
void PDF::WriteName(const char * name, const char * name2) { WriteName(name); WriteName(name2); fputc('\n', file); }
int main(int argc, char *argv[]) { int echo = 0; #ifdef notyet int print_statistics = 0; #endif int fipsflagger = 0; int perfstats = 0; int use_encryption = 0; int chained_transactions = 0; int headers = 0; char *columnwidth = NULL; const char *colseparator = " "; const char *lineseparator = "\n"; int timeout = 0; char *username = NULL; char *password = NULL; char *server = NULL; DBCHAR *char_set = NULL; char *hostname = NULL; char *interfaces_filename = NULL; char *input_filename = NULL; char *output_filename = NULL; int logintime = -1; char *language = NULL; int size = 0; char *sybenv; LOGINREC *login; int printedlines; int i; int dbrc; int c; int errflg = 0; char *prbuf; int prbuflen; int num_cols; int selcol; int col; int collen; DBINT colid; const char *opname; char adbuf[512]; DBINT convlen; int printedcompute = 0; char adash; const char *database_name = NULL; setlocale(LC_ALL, ""); #ifdef __VMS /* Convert VMS-style arguments to Unix-style */ parse_vms_args(&argc, &argv); #endif editor = getenv("EDITOR"); if (!editor) { editor = getenv("VISUAL"); } if (!editor) { editor = "vi"; } opterr = 0; optarg = NULL; while (!errflg && (c = getopt(argc, argv, "eFgpnvXYa:c:D:E:h:H:i:I:J:l:m:o:P:s:S:t:U:w:y:z:A:")) != -1) { switch (c) { case 'e': echo = 1; break; case 'F': fipsflagger = 1; break; case 'g': errflg++; break; case 'p': errflg++; perfstats = 1; break; case 'n': no_prompt = 1; break; case 'v': puts("fisql, a free isql replacement by Nicholas S. Castellano"); return EXIT_SUCCESS; break; case 'X': /* XXX: We get a different error message than isql gives; neither seems * to work */ use_encryption = 1; break; case 'Y': chained_transactions = 1; break; case 'c': cmdend = optarg; break; case 'E': editor = optarg; break; case 'h': headers = atoi(optarg); break; case 'H': hostname = optarg; break; case 'i': input_filename = optarg; break; case 'I': interfaces_filename = optarg; break; case 'J': errflg++; break; case 'l': logintime = atoi(optarg); break; case 'm': global_errorlevel = atoi(optarg); break; case 'o': output_filename = optarg; break; case 'P': password = optarg; break; case 's': colseparator = optarg; break; case 'S': server = optarg; break; case 't': timeout = atoi(optarg); break; case 'U': username = optarg; break; case 'w': columnwidth = optarg; break; case 'y': /* XXX: this doesn't seem to be what isql does with -y...it doesn't * seem to do anything actually */ sybenv = (char *) xmalloc((strlen(optarg) + 8) * sizeof(char)); strcpy(sybenv, "SYBASE="); strcat(sybenv, optarg); putenv(sybenv); break; case 'z': language = optarg; break; case 'A': size = atoi(optarg); break; case 'D': database_name = optarg; break; default: errflg++; break; } } if (errflg) { fprintf(stderr, "usage: fisql [-e] [-F] [-g] [-p] [-n] [-v] [-X] [-Y]\n"); fprintf(stderr, "\t[-c cmdend] [-D database_name] [-E editor]\n"); fprintf(stderr, "\t[-h headers] [-H hostname] [-i inputfile]\n"); fprintf(stderr, "\t[-I interfaces_file] [-J client character set]\n"); fprintf(stderr, "\t[-l login_timeout] [-m errorlevel]\n"); fprintf(stderr, "\t[-o outputfile]\n"); fprintf(stderr, "\t[-P password] [-s colseparator] [-S server]\n"); fprintf(stderr, "\t[-t timeout] [-U username] [-w columnwidth]\n"); fprintf(stderr, "\t[-y sybase_dir] [-z language]\n"); return EXIT_FAILURE; } if (!(isatty(fileno(stdin)))) { no_prompt = 1; rl_outstream = fopen("/dev/null", "rw"); } rl_readline_name = "fisql"; rl_bind_key('\t', rl_insert); if (password == NULL) { password = (char *) xmalloc(READPASSPHRASE_MAXLEN); readpassphrase("Password: "******"r", stdin) == NULL) { /* XXX: sybase isql generates this error while parsing the options, * but doesn't redirect the input until after the Password: prompt */ /* lack of newline for bug-compatibility with isql */ fprintf(stderr, "Unable to open input file '%s'.", optarg); return EXIT_FAILURE; } } if (output_filename) { if (freopen(output_filename, "w", stdout) == NULL) { /* XXX: sybase isql generates this error while parsing the options, * but doesn't redirect the output until after the Password: prompt */ /* lack of newline for bug-compatibility with isql */ fprintf(stderr, "Unable to open output file '%s'.", output_filename); return EXIT_FAILURE; } } if (isatty(fileno(stdin))) { rl_outstream = stdout; } dbinit(); #if 0 #ifdef DBVERSION_100 dbsetversion(DBVERSION_100); #endif #endif if ((login = dblogin()) == NULL) { reset_term(); return EXIT_FAILURE; } dbmsghandle(msg_handler); dberrhandle(err_handler); DBSETLAPP(login, "fisql"); if (username) { DBSETLUSER(login, username); } DBSETLPWD(login, password); memset(password, 0, strlen(password)); if (char_set) { DBSETLCHARSET(login, char_set); } if (use_encryption) { DBSETLENCRYPT(login, TRUE); } if (hostname) { DBSETLHOST(login, hostname); } if (language) { DBSETLNATLANG(login, language); } if (size) { DBSETLPACKET(login, (short) size); } if (interfaces_filename) { dbsetifile(interfaces_filename); } dbsettime(timeout); if (logintime >= 0) { dbsetlogintime(logintime); } if (database_name) { DBSETLDBNAME(login, database_name); } if ((dbproc = dbopen(login, server)) == NULL) { fprintf(stderr, "fisql: dbopen() failed.\n"); reset_term(); return EXIT_FAILURE; } dbsetopt(dbproc, DBPRLINESEP, lineseparator, strlen(lineseparator)); if (colseparator) { dbsetopt(dbproc, DBPRCOLSEP, colseparator, strlen(colseparator)); } if (columnwidth) { dbsetopt(dbproc, DBPRLINELEN, columnwidth, 0); } if (chained_transactions) { dbsetopt(dbproc, DBCHAINXACTS, NULL, 0); } if (fipsflagger) { dbsetopt(dbproc, DBFIPSFLAG, NULL, 0); } if (perfstats) { dbsetopt(dbproc, DBSTAT, "time", 0); } while (1) { if (sigsetjmp(restart, 1)) { reset_ibuf(); fputc('\n', stdout); rl_on_new_line(); rl_reset_line_state(); } dbcancel(dbproc); signal(SIGINT, inactive_interrupt_handler); read_sql_lines(); dbfreebuf(dbproc); for (i = 0; i < ibuflines; i++) { if (echo) { puts(ibuf[i]); } dbcmd(dbproc, ibuf[i]); dbcmd(dbproc, "\n"); free(ibuf[i]); } free(ibuf); ibuf = NULL; signal(SIGINT, active_interrupt_handler); dbsetinterrupt(dbproc, (void *) active_interrupt_pending, (void *) active_interrupt_servhandler); if (dbsqlexec(dbproc) == SUCCEED) { int status_printed = 0; maybe_handle_active_interrupt(); while ((dbrc = dbresults(dbproc)) != NO_MORE_RESULTS) { printedlines = 0; #define USE_DBPRROW 0 #if USE_DBPRROW dbprhead(dbproc); dbprrow(dbproc); #else if ((dbrc == SUCCEED) && (DBROWS(dbproc) == SUCCEED)) { prbuflen = dbspr1rowlen(dbproc); prbuf = (char *) xmalloc(prbuflen * sizeof(char)); dbsprhead(dbproc, prbuf, prbuflen); fputs(prbuf, stdout); fputc('\n', stdout); dbsprline(dbproc, prbuf, prbuflen, '-'); fputs(prbuf, stdout); fputc('\n', stdout); maybe_handle_active_interrupt(); while ((dbrc = dbnextrow(dbproc)) != NO_MORE_ROWS) { if (dbrc == FAIL) { break; } if (dbrc != REG_ROW) { num_cols = dbnumalts(dbproc, dbrc); for (selcol = col = 1; col <= num_cols; col++) { colid = dbaltcolid(dbproc, dbrc, col); while (selcol < colid) { collen = get_printable_column_size(dbproc, selcol); for (i = 0; i < collen; i++) { putchar(' '); } selcol++; printf("%s", colseparator); } opname = dbprtype(dbaltop(dbproc, dbrc, col)); printf("%s", opname); collen = get_printable_column_size(dbproc, colid); collen -= strlen(opname); while (collen-- > 0) { putchar(' '); } selcol++; printf("%s", colseparator); } printf("%s", lineseparator); for (selcol = col = 1; col <= num_cols; col++) { colid = dbaltcolid(dbproc, dbrc, col); while (selcol < colid) { collen = get_printable_column_size(dbproc, selcol); for (i = 0; i < collen; i++) { putchar(' '); } selcol++; printf("%s", colseparator); } collen = get_printable_column_size(dbproc, colid); adash = '-'; for (i = 0; i < collen; i++) { putchar(adash); } selcol++; printf("%s", colseparator); } printf("%s", lineseparator); for (selcol = col = 1; col <= num_cols; col++) { colid = dbaltcolid(dbproc, dbrc, col); while (selcol < colid) { collen = get_printable_column_size(dbproc, selcol); for (i = 0; i < collen; i++) { putchar(' '); } selcol++; printf("%s", colseparator); } convlen = dbconvert(dbproc, dbalttype(dbproc, dbrc, col), dbadata(dbproc, dbrc, col), dbadlen(dbproc, dbrc, col), SYBCHAR, (BYTE *) adbuf, sizeof(adbuf)); printf("%.*s", (int) convlen, adbuf); collen = get_printable_column_size(dbproc, colid); collen -= convlen; while (collen-- > 0) { putchar(' '); } selcol++; printf("%s", colseparator); } printf("%s", lineseparator); printedcompute = 1; continue; } if (printedcompute || (headers && (printedlines >= headers) && ((printedlines % headers) == 0))) { fputc('\n', stdout); dbsprhead(dbproc, prbuf, prbuflen); fputs(prbuf, stdout); fputc('\n', stdout); dbsprline(dbproc, prbuf, prbuflen, '-'); fputs(prbuf, stdout); fputc('\n', stdout); printedcompute = 0; } printedlines++; dbspr1row(dbproc, prbuf, prbuflen); fputs(prbuf, stdout); fputc('\n', stdout); maybe_handle_active_interrupt(); } fputc('\n', stdout); free(prbuf); maybe_handle_active_interrupt(); } #endif if (dbrc != FAIL) { if ((DBCOUNT(dbproc) >= 0) || dbhasretstat(dbproc)) { if (DBCOUNT(dbproc) >= 0) { fprintf(stdout, "(%d rows affected", (int) DBCOUNT(dbproc)); if (dbhasretstat(dbproc)) { status_printed = 1; dbrc = dbretstatus(dbproc); fprintf(stdout, ", return status = %d", dbrc); } fprintf(stdout, ")\n"); } else { if (dbhasretstat(dbproc)) { status_printed = 1; dbrc = dbretstatus(dbproc); fprintf(stdout, "(return status = %d)\n", dbrc); } } } } } if (!status_printed && dbhasretstat(dbproc)) { dbrc = dbretstatus(dbproc); fprintf(stdout, "(return status = %d)\n", dbrc); } } else { /* Something failed, so change the default * exit status to reflect that. */ default_exit = EXIT_FAILURE; } } reset_term(); dbexit(); return EXIT_FAILURE; }
void PDF::WriteReference(const char * name, int object) { WriteName(name); WriteReference(object); fputc('\n', file); }
int main(int argc, char *argv[]) { unsigned int length; unsigned char *buffer; int i, mode; /* iptc binary, or iptc text */ FILE *ifile = stdin, *ofile = stdout; char c, *usage = "usage: iptcutil -t | -b [-i file] [-o file] <input >output"; if( argc < 2 ) { puts(usage); return 1; } mode = 0; length = -1; buffer = (unsigned char *)NULL; for (i=1; i<argc; i++) { c = argv[i][0]; if (c == '-' || c == '/') { c = argv[i][1]; switch( c ) { case 't': mode = 1; #ifdef WIN32 /* Set "stdout" to binary mode: */ _setmode( _fileno( ofile ), _O_BINARY ); #endif break; case 'b': mode = 0; #ifdef WIN32 /* Set "stdin" to binary mode: */ _setmode( _fileno( ifile ), _O_BINARY ); #endif break; case 'i': if (mode == 0) ifile = fopen(argv[++i], "rb"); else ifile = fopen(argv[++i], "rt"); if (ifile == (FILE *)NULL) { printf("Unable to open: %s\n", argv[i]); return 1; } break; case 'o': if (mode == 0) ofile = fopen(argv[++i], "wt"); else ofile = fopen(argv[++i], "wb"); if (ofile == (FILE *)NULL) { printf("Unable to open: %s\n", argv[i]); return 1; } break; default: printf("Unknown option: %s\n", argv[i]); return 1; } } else { puts(usage); return 1; } } if (mode == 0) /* handle binary iptc info */ formatIPTC(ifile, ofile); if (mode == 1) /* handle text form of iptc info */ { char brkused, quoted, *line, *token, *newstr; int state, next; unsigned char recnum = 0, dataset = 0; int inputlen = BUFFER_SZ; line = (char *) malloc(inputlen); token = (char *)NULL; while((line = super_fgets(line,&inputlen,ifile))!=NULL) { state=0; next=0; token = (char *) malloc(inputlen); newstr = (char *) malloc(inputlen); while(tokenizer(0, token, inputlen, line, "", "=", "\"", 0, &brkused,&next,"ed)==0) { if (state == 0) { int state, next; char brkused, quoted; state=0; next=0; while(tokenizer(0, newstr, inputlen, token, "", "#", "", 0, &brkused, &next, "ed)==0) { if (state == 0) dataset = (unsigned char) atoi(newstr); else if (state == 1) recnum = (unsigned char) atoi(newstr); state++; } } else if (state == 1) { int next; unsigned long len; char brkused, quoted; next=0; len = strlen(token); while(tokenizer(0, newstr, inputlen, token, "", "&", "", 0, &brkused, &next, "ed)==0) { if (brkused && next > 0) { char *s = &token[next-1]; len -= convertHTMLcodes(s, strlen(s)); } } fputc(0x1c, ofile); fputc(dataset, ofile); fputc(recnum, ofile); if (len < 0x10000) { fputc((len >> 8) & 255, ofile); fputc(len & 255, ofile); } else { fputc(((len >> 24) & 255) | 0x80, ofile); fputc((len >> 16) & 255, ofile); fputc((len >> 8) & 255, ofile); fputc(len & 255, ofile); } next=0; while (len--) fputc(token[next++], ofile); }
void PDF::WriteReferenceArray(const char * name, const IntArray & array) { WriteName(name); WriteReferenceArray(array); fputc('\n', file); }
char scan(Scanner *s) { int cond = 1; fill(s, 0); for(;;) { s->tok = s->cur; #line 59 "<stdout>" { unsigned char yych; static void *yyctable[2] = { &&yyc_normal, &&yyc_comment, }; goto *yyctable[cond]; /* *********************************** */ yyc_comment: if ((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; } yych = *s->cur; if (yych != '*') goto yy4; ++s->cur; if ((yych = *s->cur) == '/') goto yy5; yy3: #line 83 "condition_05.cg.re" { goto yyc_comment; } #line 80 "<stdout>" yy4: yych = *++s->cur; goto yy3; yy5: ++s->cur; #line 79 "condition_05.cg.re" { continue; } #line 90 "<stdout>" /* *********************************** */ yyc_normal: if ((s->lim - s->cur) < 2) { if(fill(s, 2) >= 0) break; } yych = *s->cur; if (yych != '/') goto yy11; ++s->cur; if ((yych = *s->cur) == '*') goto yy12; yy10: #line 74 "condition_05.cg.re" { fputc(*s->tok, stdout); continue; } #line 104 "<stdout>" yy11: yych = *++s->cur; goto yy10; yy12: ++s->cur; #line 70 "condition_05.cg.re" { goto yyc_comment; } #line 114 "<stdout>" } #line 87 "condition_05.cg.re" } } int main(int argc, char **argv) { Scanner in; char c; if (argc != 2) { fprintf(stderr, "%s <file>\n", argv[0]); return 1;; } memset((char*) &in, 0, sizeof(in)); if (!strcmp(argv[1], "-")) { in.fp = stdin; } else if ((in.fp = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Cannot open file '%s'\n", argv[1]); return 1; } scan(&in); if (in.fp != stdin) { fclose(in.fp); } return 0; }
static int process_line(const char *fname, char *line, int lineno) { char buf[32]; char *op; /* '<' */ char *cl; /* '>' */ char *tcl_pos; /* tag class (T=") position */ char *tl_pos; /* tag length (TL=") position */ char *v_pos; /* value length (V=") position */ int constr; ber_tlv_tag_t tag_value; ber_tlv_tag_t tag_class; ber_tlv_tag_t tlv_tag; ber_tlv_len_t tlv_len; ber_tlv_len_t opt_tl_len; /* optional TL length */ ssize_t ret; /* Skip the whitespace */ for(; *line == ' ' || *line == '\t'; line++) ; /* Find a tag opening angle bracket */ op = line; switch(*op) { case '<': /* That's what we want! A tag opening */ break; case '\r': case '\n': case '#': /* This is a comment */ return 0; case '-': /* This is a comment (dash-dash) */ if(op[1] == '-') { return 0; } /* Fall through */ default: fprintf(stderr, "%s: Missing '<' after whitespace at line %d\n", fname, lineno); exit(EX_DATAERR); } /* Find a tag closing angle bracket */ for(; *line && *line != '>'; line++) { if(*line < ' ') { fprintf(stderr, "%s: Invalid charset (%d) at line %d\n", fname, *(const unsigned char *)line, lineno); exit(EX_DATAERR); } } cl = line; if(*cl != '>') { fprintf(stderr, "%s: Missing '>' at line %d\n", fname, lineno); exit(EX_DATAERR); } /* Ignore closing tags */ if(op[1] == '/') { if(strchr(cl, '<')) { /* We are not very robust */ fprintf(stderr, "%s: Multiple tags per line at line %d\n", fname, lineno); exit(EX_DATAERR); } /* End-of-content octets */ if(op[2] == 'I') { buf[0] = buf[1] = 0x00; fwrite(buf, 1, 2, stdout); } return 0; } switch(op[1]) { case '!': return 0; /* A comment */ case '?': return 0; /* An XML preamble */ case 'C': constr = 1; break; case 'P': constr = 0; break; case 'I': constr = 2; break; default: fprintf(stderr, "%s: Expected \"C\"/\"P\"/\"I\" as the XML tag name (%c) at " "line %d\n", fname, op[1], lineno); exit(EX_DATAERR); } *cl = '\0'; if(cl[-1] == 'F') { fprintf(stderr, "%s: Detected pretty-printing of primitive types at line %d. " "Re-run `unber` with -p option to disable pretty-printing.\n", fname, lineno); exit(EX_DATAERR); } tcl_pos = strstr(op, "T=\"["); tl_pos = strstr(op, "TL=\""); v_pos = strstr(op, "V=\""); if(!tcl_pos || (!v_pos && constr != 2)) { fprintf(stderr, "%s: Mandatory attribute %s is not found at line %d\n", fname, (!tcl_pos) ? "T" : "V", lineno); exit(EX_DATAERR); } errno = 0; opt_tl_len = tl_pos ? strtoul(tl_pos + 4, 0, 10) : 0; if(constr == 2) { tlv_len = 0; } else { tlv_len = strtoul(v_pos + 3, 0, 10); } if(errno || (opt_tl_len && opt_tl_len < 2) || tlv_len < 0) { fprintf(stderr, "%s: Invalid TL or V value at line %d\n", fname, lineno); exit(EX_DATAERR); } /* clang-format off */ tcl_pos += 4; switch(*tcl_pos) { case 'U': /* UNIVERSAL */ tag_class = ASN_TAG_CLASS_UNIVERSAL; break; case 'P': /* PRIVATE */ tag_class = ASN_TAG_CLASS_PRIVATE; break; case 'A': /* APPLICATION */ tag_class = ASN_TAG_CLASS_APPLICATION; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* context */ tag_class = ASN_TAG_CLASS_CONTEXT; break; default: fprintf(stderr, "%s: Invalid tag class (%c) at line %d\n", fname, tcl_pos[4], lineno); exit(EX_DATAERR); } for(;; tcl_pos++) { switch(*tcl_pos) { case '"': tcl_pos = ""; case '\0': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break; default: continue; } break; } /* clang-format on */ unsigned long tag_value_UL; errno = 0; if(!*tcl_pos || ((tag_value_UL = strtoul(tcl_pos, 0, 10)) > UINT_MAX) || errno) { fprintf(stderr, "%s: Invalid tag value (%c) at line %d\n", fname, *tcl_pos, lineno); exit(EX_DATAERR); } else { tag_value = tag_value_UL; } tlv_tag = ((tag_value << 2) | tag_class); ret = ber_tlv_tag_serialize(tlv_tag, buf, sizeof(buf)); assert(ret >= 1 && (size_t)ret < sizeof(buf)); if(constr == 2) { buf[ret] = 0x80; ret += 1; } else { ret += der_tlv_length_serialize(tlv_len, buf + ret, sizeof(buf) - ret); assert(ret >= 2 && (size_t)ret < sizeof(buf)); } if(opt_tl_len && ret != opt_tl_len) { fprintf(stderr, "%s: Cannot encode TL at line %d " "in the given number of bytes (%ld!=%ld)\n", fname, lineno, (long)ret, (long)opt_tl_len); exit(EX_DATAERR); } if(constr) *buf |= 0x20; /* Enable "constructed" bit */ fwrite(buf, 1, ret, stdout); if(!constr) { ber_tlv_len_t len; for(len = 0, cl++; *cl && *cl != '<'; cl++, len++) { unsigned char v; int h; if(*cl != '&') { fputc(*cl, stdout); continue; } cl++; if(*cl != '#') { fputc(*cl, stdout); continue; } cl++; if(*cl != 'x') { fprintf(stderr, "%s: Expected \"&#xNN;\" at line %d\n", fname, lineno); exit(EX_DATAERR); } for(v = 0, h = 0; h < 2; h++) { unsigned char clv = *++cl; v <<= 4; /* clang-format off */ switch(clv) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': v |= clv - '0'; break; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': v |= clv - 'A' + 10; break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': v |= clv - 'a' + 10; break; default: fprintf(stderr, "%s: Expected \"&#xNN;\" at line %d (%c)\n", fname, lineno, clv); exit(EX_DATAERR); } /* clang-format on */ } cl++; if(*cl != ';') { fprintf(stderr, "%s: Expected \"&#xNN;\" at line %d\n", fname, lineno); exit(EX_DATAERR); } fputc(v, stdout); } if(len != tlv_len) { if(no_validation) fprintf(stderr, "Warning: "); fprintf(stderr, "%s: Could not encode value of %ld chars " "at line %d in %ld bytes\n", fname, (long)len, lineno, (long)tlv_len); if(!no_validation) exit(EX_DATAERR); } } return 0; }
virtual int_type overflow(int_type c = traits_type::eof()) { return fputc(c, stdout) == EOF ? traits_type::eof() : c; }
// Main Function void _main(void) { ST_helpMsg("Saving external data, please wait..."); UnArchive("sumogfx"); FILE *fp = fopen("sumogfx", "wb"); if (!fp) Error(NULL); /* Write all Graphics Data into the 'sumodat' File */ //#define Write(x) printf("%lu\n", sizeof(x)); ngetchx(); #define Write(x) ({ Putshort(sizeof((x)), fp); if (fwrite((x), sizeof((x)), 1, fp) != 1) {Error(fp);} }) Write(stomp1); Write(stomp2); Write(stomp3); Write(salt1); Write(salt3); Write(kneel1); Write(kneel3); Write(kneel5); Write(tackle1); Write(tackle3); Write(walk1); Write(walk3); Write(charge1); Write(charge3); Write(tumble1); Write(tumble2); Write(tumble3); Write(tumble4); Write(spinn1); Write(spinn3); Write(tossbackleft); Write(pummel1); Write(pummelpush1); Write(pummellift1); Write(pummellift3); Write(pummellift5); Write(earthquake_throwleft); Write(shoveleft); Write(shovedright); Write(shovedleftedge1); Write(shovedleftedge2); Write(pummelthrowleft); Write(throwleft); Write(thrownright); Write(pummelthrowcounter1); Write(punchleft1); Write(punchleft2); Write(punchedleft1); Write(punchedleft2); Write(tauntleft1); Write(tauntleft2); Write(laughing1); Write(laughing2); Write(sumoeating1); Write(sumoeating2); Write(sweepingleft); Write(smushedleft); Write(bellyflopleft1); Write(bellyflopleft2); Write(backwardsslamleft1); Write(backwardsslamleft2); Write(slammed); Write(Ring_Matrix); Write(ring_sprites); // Put the extension "gfx" onto the Graphics File and close it fputc(0, fp); fputs("gfx", fp); fputc(0, fp); fputc(OTH_TAG, fp); fclose(fp); Archive("sumogfx"); // Archive the Configuration File ST_helpMsg("External Data File 'sumogfx' created"); }
void PDF::WriteBoolean(const char * name, bool boolean) { WriteName(name); WriteBoolean(boolean); fputc('\n', file); }
static void show_stats(e2fsck_t ctx) { ext2_filsys fs = ctx->fs; ext2_ino_t inodes, inodes_used; blk_t blocks, blocks_used; int dir_links; int num_files, num_links; int frag_percent_file, frag_percent_dir, frag_percent_total; int i, j; dir_links = 2 * ctx->fs_directory_count - 1; num_files = ctx->fs_total_count - dir_links; num_links = ctx->fs_links_count - dir_links; inodes = fs->super->s_inodes_count; inodes_used = (fs->super->s_inodes_count - fs->super->s_free_inodes_count); blocks = fs->super->s_blocks_count; blocks_used = (fs->super->s_blocks_count - fs->super->s_free_blocks_count); frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used; frag_percent_file = (frag_percent_file + 5) / 10; frag_percent_dir = (10000 * ctx->fs_fragmented_dir) / inodes_used; frag_percent_dir = (frag_percent_dir + 5) / 10; frag_percent_total = ((10000 * (ctx->fs_fragmented + ctx->fs_fragmented_dir)) / inodes_used); frag_percent_total = (frag_percent_total + 5) / 10; if (!verbose) { printf(_("%s: %u/%u files (%0d.%d%% non-contiguous), %u/%u blocks\n"), ctx->device_name, inodes_used, inodes, frag_percent_total / 10, frag_percent_total % 10, blocks_used, blocks); return; } printf (P_("\n%8u inode used (%2.2f%%)\n", "\n%8u inodes used (%2.2f%%)\n", inodes_used), inodes_used, 100.0 * inodes_used / inodes); printf (P_("%8u non-contiguous file (%0d.%d%%)\n", "%8u non-contiguous files (%0d.%d%%)\n", ctx->fs_fragmented), ctx->fs_fragmented, frag_percent_file / 10, frag_percent_file % 10); printf (P_("%8u non-contiguous directory (%0d.%d%%)\n", "%8u non-contiguous directories (%0d.%d%%)\n", ctx->fs_fragmented_dir), ctx->fs_fragmented_dir, frag_percent_dir / 10, frag_percent_dir % 10); printf (_(" # of inodes with ind/dind/tind blocks: %u/%u/%u\n"), ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count); for (j=MAX_EXTENT_DEPTH_COUNT-1; j >=0; j--) if (ctx->extent_depth_count[j]) break; if (++j) { printf (_(" Extent depth histogram: ")); for (i=0; i < j; i++) { if (i) fputc('/', stdout); printf("%u", ctx->extent_depth_count[i]); } fputc('\n', stdout); } printf (P_("%8u block used (%2.2f%%)\n", "%8u blocks used (%2.2f%%)\n", blocks_used), blocks_used, 100.0 * blocks_used / blocks); printf (P_("%8u bad block\n", "%8u bad blocks\n", ctx->fs_badblocks_count), ctx->fs_badblocks_count); printf (P_("%8u large file\n", "%8u large files\n", ctx->large_files), ctx->large_files); printf (P_("\n%8u regular file\n", "\n%8u regular files\n", ctx->fs_regular_count), ctx->fs_regular_count); printf (P_("%8u directory\n", "%8u directories\n", ctx->fs_directory_count), ctx->fs_directory_count); printf (P_("%8u character device file\n", "%8u character device files\n", ctx->fs_chardev_count), ctx->fs_chardev_count); printf (P_("%8u block device file\n", "%8u block device files\n", ctx->fs_blockdev_count), ctx->fs_blockdev_count); printf (P_("%8u fifo\n", "%8u fifos\n", ctx->fs_fifo_count), ctx->fs_fifo_count); printf (P_("%8u link\n", "%8u links\n", ctx->fs_links_count - dir_links), ctx->fs_links_count - dir_links); printf (P_("%8u symbolic link", "%8u symbolic links", ctx->fs_symlinks_count), ctx->fs_symlinks_count); printf (P_(" (%u fast symbolic link)\n", " (%u fast symbolic links)\n", ctx->fs_fast_symlinks_count), ctx->fs_fast_symlinks_count); printf (P_("%8u socket\n", "%8u sockets\n", ctx->fs_sockets_count), ctx->fs_sockets_count); printf ("--------\n"); printf (P_("%8u file\n", "%8u files\n", ctx->fs_total_count - dir_links), ctx->fs_total_count - dir_links); }
void PDF::WriteInteger(const char * name, int integer) { WriteName(name); WriteInteger(integer); fputc('\n', file); }
int e2fsck_simple_progress(e2fsck_t ctx, const char *label, float percent, unsigned int dpynum) { static const char spinner[] = "\\|/-"; int i; unsigned int tick; struct timeval tv; int dpywidth; int fixed_percent; if (ctx->flags & E2F_FLAG_PROG_SUPPRESS) return 0; /* * Calculate the new progress position. If the * percentage hasn't changed, then we skip out right * away. */ fixed_percent = (int) ((10 * percent) + 0.5); if (ctx->progress_last_percent == fixed_percent) return 0; ctx->progress_last_percent = fixed_percent; /* * If we've already updated the spinner once within * the last 1/8th of a second, no point doing it * again. */ gettimeofday(&tv, NULL); tick = (tv.tv_sec << 3) + (tv.tv_usec / (1000000 / 8)); if ((tick == ctx->progress_last_time) && (fixed_percent != 0) && (fixed_percent != 1000)) return 0; ctx->progress_last_time = tick; /* * Advance the spinner, and note that the progress bar * will be on the screen */ ctx->progress_pos = (ctx->progress_pos+1) & 3; ctx->flags |= E2F_FLAG_PROG_BAR; dpywidth = 66 - strlen(label); dpywidth = 8 * (dpywidth / 8); if (dpynum) dpywidth -= 8; i = ((percent * dpywidth) + 50) / 100; printf("%s%s: |%s%s", ctx->start_meta, label, bar + (sizeof(bar) - (i+1)), spaces + (sizeof(spaces) - (dpywidth - i + 1))); if (fixed_percent == 1000) fputc('|', stdout); else fputc(spinner[ctx->progress_pos & 3], stdout); printf(" %4.1f%% ", percent); if (dpynum) printf("%u\r", dpynum); else fputs(" \r", stdout); fputs(ctx->stop_meta, stdout); if (fixed_percent == 1000) e2fsck_clear_progbar(ctx); fflush(stdout); return 0; }
void list_symbols_aux(asmstate_t *as, FILE *of, struct symtabe *se) { struct symtabe *s; lw_expr_t te; struct listinfo li; li.as = as; if (!se) return; list_symbols_aux(as, of, se -> left); for (s = se; s; s = s -> nextver) { if (s -> flags & symbol_flag_nolist) continue; if ((as -> flags & FLAG_SYMBOLS_NOLOCALS) && (s -> context >= 0)) continue; lwasm_reduce_expr(as, s -> value); fputc('[', of); if (s -> flags & symbol_flag_set) fputc('S', of); else fputc(' ', of); if (as -> output_format == OUTPUT_OBJ) { if (lw_expr_istype(s -> value, lw_expr_type_int)) fputc('c', of); else fputc('s', of); } if (s -> context < 0) fputc('G', of); else fputc('L', of); fputc(']', of); fputc(' ', of); fprintf(of, "%-32s ", s -> symbol); te = lw_expr_copy(s -> value); li.complex = 0; li.sect = NULL; lw_expr_testterms(te, list_symbols_test, &li); if (li.sect) { as -> exportcheck = 1; as -> csect = li.sect; lwasm_reduce_expr(as, te); as -> exportcheck = 0; } if (lw_expr_istype(te, lw_expr_type_int)) { fprintf(of, "%04X", lw_expr_intval(te)); if (li.sect) { fprintf(of, " (%s)", li.sect -> name); } fprintf(of, "\n"); } else { fprintf(of, "<<incomplete>>\n"); // fprintf(of, "%s\n", lw_expr_print(s -> value)); } lw_expr_destroy(te); } list_symbols_aux(as, of, se -> right); }