/* static method, ( pos.d ih -- flag? ) */ static void grubfs_files_probe( grubfs_info_t *dummy ) { ihandle_t ih = POP_ih(); long long offs = DPOP(); int i; curfs->dev_fd = open_ih(ih); if (curfs->dev_fd == -1) { RET( -1 ); } curfs->offset = offs; for (i = 0; i < sizeof(fsys_table)/sizeof(fsys_table[0]); i++) { #ifdef CONFIG_DEBUG_FS printk("Probing for %s\n", fsys_table[i].name); #endif if (fsys_table[i].mount_func()) { RET( -1 ); } } #ifdef CONFIG_DEBUG_FS printk("Unknown filesystem type\n"); #endif close_io(curfs->dev_fd); RET ( 0 ); }
int main(int argc, char **argv) { struct holder holder = {}; if (argc < 2) errx(1, "bad arguments"); open_io(&holder, argv[1]); holder.samples_count = holder.ininfo.samplerate / 100; /* do we have enough data? no = clamp the graph */ if (holder.width > holder.samples_count / 2) holder.width = holder.samples_count / 2; prepare_fftw(&holder); decode(&holder); destroy_fftw(&holder); close_io(&holder); return 0; }
void file_close(void) { if(load_fd==-1) return; close_io(load_fd); load_fd=-1; }
static unsigned long process_image_notes(Elf_phdr *phdr, int phnum, unsigned short *sum_ptr, unsigned int offset) { int i; char *buf = NULL; int retval = 0; unsigned long addr, end; Elf_Nhdr *nhdr; const char *name; void *desc; for (i = 0; i < phnum; i++) { if (phdr[i].p_type != PT_NOTE) continue; buf = malloc(phdr[i].p_filesz); seek_io(fd, offset + phdr[i].p_offset); if ((size_t)read_io(fd, buf, phdr[i].p_filesz) != phdr[i].p_filesz) { printf("Can't read note segment\n"); goto out; } addr = (unsigned long) buf; end = addr + phdr[i].p_filesz; while (addr < end) { nhdr = (Elf_Nhdr *) addr; addr += sizeof(Elf_Nhdr); name = (const char *) addr; addr += (nhdr->n_namesz+3) & ~3; desc = (void *) addr; addr += (nhdr->n_descsz+3) & ~3; if (nhdr->n_namesz==sizeof(ELF_NOTE_BOOT) && memcmp(name, ELF_NOTE_BOOT, sizeof(ELF_NOTE_BOOT))==0) { if (nhdr->n_type == EIN_PROGRAM_NAME) { image_name = ob_calloc(1, nhdr->n_descsz + 1); memcpy(image_name, desc, nhdr->n_descsz); } if (nhdr->n_type == EIN_PROGRAM_VERSION) { image_version = ob_calloc(1, nhdr->n_descsz + 1); memcpy(image_version, desc, nhdr->n_descsz); } if (nhdr->n_type == EIN_PROGRAM_CHECKSUM) { *sum_ptr = *(unsigned short *) desc; debug("Image checksum: %#04x\n", *sum_ptr); /* Where in the file */ retval = phdr[i].p_offset + (unsigned long) desc - (unsigned long) buf; } } } } out: close_io(fd); if (buf) free(buf); return retval; }
int bootcode_load(ihandle_t dev) { int retval = -1, count = 0, fd; unsigned long bootcode, loadbase, offset; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { goto out; } /* Default to loading at load-base */ fword("load-base"); loadbase = POP(); #ifdef CONFIG_PPC /* However Old World Macs need to load to a different address */ if (is_oldworld()) { loadbase = OLDWORLD_BOOTCODE_BASEADDR; } #endif bootcode = loadbase; offset = 0; while(1) { if (seek_io(fd, offset) == -1) break; count = read_io(fd, (void *)bootcode, 512); offset += count; bootcode += count; } /* If we didn't read anything then exit */ if (!count) { goto out; } /* Initialise saved-program-state */ PUSH(loadbase); feval("saved-program-state >sps.entry !"); PUSH(offset); feval("saved-program-state >sps.file-size !"); feval("bootcode saved-program-state >sps.file-type !"); feval("-1 state-valid !"); out: close_io(fd); return retval; }
/* ( -- success? ) */ static void hfsp_files_open( hfsp_info_t *mi ) { int fd; char *path = my_args_copy(); if ( ! path ) RET( 0 ); fd = open_ih( my_parent() ); if ( fd == -1 ) { free( path ); RET( 0 ); } mi->vol = malloc( sizeof(volume) ); if (volume_open(mi->vol, fd)) { free( path ); close_io( fd ); RET( 0 ); } mi->hfspfile = malloc( sizeof(hfsp_file_t) ); /* Leading \\ means system folder. The finder info block has * the following meaning. * * [0] Prefered boot directory ID * [3] MacOS 9 boot directory ID * [5] MacOS X boot directory ID */ if( !strncmp(path, "\\\\", 2) ) { int *p = (int*)&(mi->vol)->vol.finder_info[0]; int cnid = p[0]; /* printk(" p[0] = %x, p[3] = %x, p[5] = %x\n", p[0], p[3], p[5] ); */ if( p[0] == p[5] && p[3] ) cnid = p[3]; if( record_init_cnid(&(mi->hfspfile->rec), &(mi->vol)->catalog, cnid) ) RET ( 0 ); path += 2; } else { record_init_root( &(mi->hfspfile->rec), &(mi->vol)->catalog ); } if( !search_files(&(mi->hfspfile->rec), 0, match_path, path, mi->hfspfile ) ) RET ( -1 ); RET ( -1 ); }
/* ( -- cstr|0 ) */ static void hfsp_files_volume_name( hfsp_info_t *mi ) { int fd; char *volname = malloc(VOLNAME_SIZE); fd = open_ih(my_self()); if (fd >= 0) { get_hfs_vol_name(fd, volname, VOLNAME_SIZE); close_io(fd); } else { volname[0] = '\0'; } PUSH(pointer2cell(volname)); }
/* static method, ( pos.d ih -- flag? ) */ static void hfsp_files_probe( hfsp_info_t *dummy ) { ihandle_t ih = POP_ih(); long long offs = DPOP(); int fd, ret = 0; fd = open_ih(ih); if (fd >= 0) { if (volume_probe(fd, offs)) { ret = -1; } close_io(fd); } else { ret = -1; } RET (ret); }
static void briq_startup( void ) { const char *paths[] = { "hd:0,\\zImage.chrp", NULL }; const char *args[] = { "root=/dev/hda2 console=ttyS0,115200", NULL }; unsigned long entry; int i, fd; for( i=0; paths[i]; i++ ) { if( (fd=open_io(paths[i])) == -1 ) continue; (void) load_elf_rom( &entry, fd ); close_io( fd ); encode_bootpath( paths[i], args[i] ); update_nvram(); transfer_control_to_elf( entry ); /* won't come here */ } printk("*** Boot failure! No secondary bootloader specified ***\n"); }
int fcode_load(ihandle_t dev) { int retval = -1; uint8_t fcode_header[8]; unsigned long start, size; unsigned int offset; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { goto out; } for (offset = 0; offset < 16 * 512; offset += 512) { seek_io(fd, offset); if (read_io(fd, &fcode_header, sizeof(fcode_header)) != sizeof(fcode_header)) { debug("Can't read FCode header from ihandle " FMT_ucellx "\n", dev); retval = LOADER_NOT_SUPPORT; goto out; } if (is_fcode(fcode_header)) goto found; } debug("Not a bootable FCode image\n"); retval = LOADER_NOT_SUPPORT; goto out; found: size = (fcode_header[4] << 24) | (fcode_header[5] << 16) | (fcode_header[6] << 8) | fcode_header[7]; fword("load-base"); start = POP(); printf("\nLoading FCode image...\n"); seek_io(fd, offset); if ((size_t)read_io(fd, (void *)start, size) != size) { printf("Can't read file (size 0x%lx)\n", size); goto out; } debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start); // Initialise load-state PUSH(size); feval("load-state >ls.file-size !"); feval("fcode load-state >ls.file-type !"); out: close_io(fd); return retval; }
int aout_load(struct sys_info *info, ihandle_t dev) { int retval = -1; struct exec ehdr; unsigned long start, size; unsigned int offset; image_name = image_version = NULL; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { goto out; } for (offset = 0; offset < 16 * 512; offset += 512) { seek_io(fd, offset); if (read_io(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { debug("Can't read a.out header\n"); retval = LOADER_NOT_SUPPORT; goto out; } if (is_aout(&ehdr)) break; } if (!is_aout(&ehdr)) { debug("Not a bootable a.out image\n"); retval = LOADER_NOT_SUPPORT; goto out; } if (ehdr.a_text == 0x30800007) ehdr.a_text=64*1024; if (N_MAGIC(ehdr) == NMAGIC) { size = addr_fixup(N_DATADDR(ehdr)) + addr_fixup(ehdr.a_data); } else { size = addr_fixup(ehdr.a_text) + addr_fixup(ehdr.a_data); } if (size < 7680) size = 7680; fword("load-base"); start = POP(); // N_TXTADDR(ehdr); memcpy((void *)start, &ehdr, sizeof(ehdr)); if (!check_mem_ranges(info, start, size)) goto out; printf("Loading a.out %s...\n", image_name ? image_name : "image"); seek_io(fd, offset + N_TXTOFF(ehdr)); if (N_MAGIC(ehdr) == NMAGIC) { if ((size_t)read_io(fd, (void *)(start + N_TXTOFF(ehdr)), ehdr.a_text) != ehdr.a_text) { printf("Can't read program text segment (size 0x" FMT_aout_ehdr ")\n", ehdr.a_text); goto out; } if ((size_t)read_io(fd, (void *)(start + N_DATADDR(ehdr)), ehdr.a_data) != ehdr.a_data) { printf("Can't read program data segment (size 0x" FMT_aout_ehdr ")\n", ehdr.a_data); goto out; } } else { if ((size_t)read_io(fd, (void *)(start + N_TXTOFF(ehdr)), size) != size) { printf("Can't read program (size 0x" FMT_sizet ")\n", size); goto out; } } debug("Loaded %lu bytes\n", size); debug("entry point is %#lx\n", start); // Initialise saved-program-state PUSH(size); feval("load-state >ls.file-size !"); feval("aout load-state >ls.file-type !"); out: close_io(fd); return retval; }
int xcoff_load(ihandle_t dev) { COFF_filehdr_t fhdr; COFF_aouthdr_t ahdr; COFF_scnhdr_t shdr; uint32_t offset; size_t total_size = 0; int fd, i; int retval = -1; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { retval = LOADER_NOT_SUPPORT; goto out; } for (offset = 0; offset < 16 * 512; offset += 512) { seek_io(fd, offset); if (read_io(fd, &fhdr, sizeof fhdr) != sizeof fhdr) { DPRINTF("Can't read XCOFF header\n"); retval = LOADER_NOT_SUPPORT; goto out; } if (is_xcoff(&fhdr)) break; } /* Is it executable ? */ if (fhdr.f_magic != 0x01DF && (fhdr.f_flags & COFF_F_EXEC) == 0) { DPRINTF("Not an executable XCOFF file %02x\n", fhdr.f_flags); return LOADER_NOT_SUPPORT; } /* Optional header is a.out ? */ if (fhdr.f_opthdr != sizeof(COFF_aouthdr_t)) { DPRINTF("AOUT optional error size mismatch in XCOFF file\n"); return LOADER_NOT_SUPPORT; } seek_io(fd, sizeof(COFF_filehdr_t)); read_io(fd, &ahdr, sizeof(COFF_aouthdr_t)); /* check a.out magic number */ if (ahdr.magic != AOUT_MAGIC) { DPRINTF("Invalid AOUT optional header\n"); return LOADER_NOT_SUPPORT; } offset = sizeof(COFF_filehdr_t) + sizeof(COFF_aouthdr_t); DPRINTF("XCOFF file with %d sections\n", fhdr.f_nscns); for (i = 0; i < fhdr.f_nscns; i++) { DPRINTF("Read header at offset %0x\n", offset); seek_io(fd, offset); read_io(fd, &shdr, sizeof(COFF_scnhdr_t)); DPRINTF("Initializing '%s' section from %0x %0x to %0x (%0x)\n", shdr.s_name, offset, shdr.s_scnptr, shdr.s_vaddr, shdr.s_size); if (strcmp(shdr.s_name, ".text") == 0) { read_io(fd, (void *)shdr.s_vaddr, shdr.s_size); total_size += shdr.s_size; #ifdef CONFIG_PPC flush_icache_range((char*)(uintptr_t)shdr.s_vaddr, (char*)(uintptr_t)(shdr.s_vaddr + shdr.s_size)); #endif } else if (strcmp(shdr.s_name, ".data") == 0) { read_io(fd, (void *)shdr.s_vaddr, shdr.s_size); total_size += shdr.s_size; } else if (strcmp(shdr.s_name, ".bss") == 0) { memset((void *)(uintptr_t)shdr.s_vaddr, 0, shdr.s_size); total_size += shdr.s_size; } else { DPRINTF(" Skip '%s' section\n", shdr.s_name); } offset += sizeof(COFF_scnhdr_t); } DPRINTF("XCOFF entry point: %x\n", *(uint32_t*)ahdr.entry); // Initialise load-state PUSH(total_size); feval("load-state >ls.file-size !"); feval("xcoff load-state >ls.file-type !"); out: close_io(fd); return retval; }
int elf_load(struct sys_info *info, ihandle_t dev, const char *cmdline, void **boot_notes) { Elf_ehdr ehdr; Elf_phdr *phdr = NULL; unsigned long checksum_offset, file_size; unsigned short checksum = 0; int retval = -1; unsigned int offset; image_name = image_version = NULL; /* Mark the saved-program-state as invalid */ feval("0 state-valid !"); fd = open_ih(dev); if (fd == -1) { goto out; } offset = find_elf(&ehdr); if (!offset) { retval = LOADER_NOT_SUPPORT; goto out; } #if DEBUG printk("ELF header:\n"); printk(" ehdr.e_type = %d\n", (int)ehdr.e_type); printk(" ehdr.e_machine = %d\n", (int)ehdr.e_machine); printk(" ehdr.e_version = %d\n", (int)ehdr.e_version); printk(" ehdr.e_entry = 0x%08x\n", (int)ehdr.e_entry); printk(" ehdr.e_phoff = 0x%08x\n", (int)ehdr.e_phoff); printk(" ehdr.e_shoff = 0x%08x\n", (int)ehdr.e_shoff); printk(" ehdr.e_flags = %d\n", (int)ehdr.e_flags); printk(" ehdr.e_ehsize = 0x%08x\n", (int)ehdr.e_ehsize); printk(" ehdr.e_phentsize = 0x%08x\n", (int)ehdr.e_phentsize); printk(" ehdr.e_phnum = %d\n", (int)ehdr.e_phnum); #endif if (ehdr.e_phnum > MAX_HEADERS) { printk ("elfload: too many program headers (MAX_HEADERS)\n"); retval = 0; goto out; } phdr = elf_readhdrs(offset, &ehdr); if (!phdr) goto out; if (!check_mem_ranges(info, phdr, ehdr.e_phnum)) goto out; checksum_offset = process_image_notes(phdr, ehdr.e_phnum, &checksum, offset); printf("Loading %s", image_name ? image_name : "image"); if (image_version) printf(" version %s", image_version); printf("...\n"); if (!load_segments(phdr, ehdr.e_phnum, checksum_offset, offset, &file_size)) goto out; if (checksum_offset) { if (!verify_image(&ehdr, phdr, ehdr.e_phnum, checksum)) goto out; } /* If we are attempting an ELF boot image, we pass a non-NULL pointer into boot_notes and mark the image as elf-boot rather than standard ELF */ if (boot_notes) { *boot_notes = (void *)virt_to_phys(build_boot_notes(info, cmdline)); feval("elf-boot saved-program-state >sps.file-type !"); } else { feval("elf saved-program-state >sps.file-type !"); } //debug("current time: %lu\n", currticks()); debug("entry point is " FMT_elf "\n", addr_fixup(ehdr.e_entry)); // Initialise saved-program-state PUSH(addr_fixup(ehdr.e_entry)); feval("saved-program-state >sps.entry !"); PUSH(file_size); feval("saved-program-state >sps.file-size !"); feval("-1 state-valid !"); out: close_io(fd); if (phdr) free(phdr); if (image_name) free(image_name); if (image_version) free(image_version); return retval; }
static int load_initrd(struct linux_header *hdr, struct sys_info *info, uint32_t kern_end, struct linux_params *params, const char *initrd_file) { uint32_t max; uint32_t start, end, size; uint64_t forced; fd = open_io(initrd_file); if (fd == -1) { printf("Can't open initrd: %s\n", initrd_file); return -1; } #if 0 if (using_devsize) { printf("Attempt to load up to end of device as initrd; " "specify the image size\n"); return -1; } #endif size = file_size(); /* Find out the kernel's restriction on how high the initrd can be * placed */ if (hdr->protocol_version >= 0x203) max = hdr->initrd_addr_max; else max = 0x38000000; /* Hardcoded value for older kernels */ /* FILO itself is at the top of RAM. (relocated) * So, try putting initrd just below us. */ end = virt_to_phys(_start); if (end > max) end = max; /* If "mem=" option is given, we have to put the initrd within * the specified range. */ if (forced_memsize) { forced = forced_memsize; if (forced > max) forced = max; /* If the "mem=" is lower, it's easy */ if (forced <= end) end = forced; else { /* Otherwise, see if we can put it above us */ if (virt_to_phys(_end) + size <= forced) end = forced; /* Ok */ } } start = end - size; start &= ~0xfff; /* page align */ end = start + size; debug("start=%#x end=%#x\n", start, end); if (start < kern_end) { printf("Initrd is too big to fit in memory\n"); return -1; } printf("Loading initrd... "); if (read_io(fd, phys_to_virt(start), size) != size) { printf("Can't read initrd\n"); return -1; } printf("ok\n"); params->initrd_start = start; params->initrd_size = size; close_io(fd); return 0; }
int main(int argc, char **argv) { int c; char *scan; /* the + on the front tells GNU getopt not to rearrange argv */ const char *optlist = "+F:f:v:W;m:D"; int stopped_early = FALSE; int old_optind; extern int optind; extern int opterr; extern char *optarg; int i; int stdio_problem = FALSE; /* do these checks early */ if (getenv("TIDYMEM") != NULL) do_tidy_mem = TRUE; if (getenv("WHINY_USERS") != NULL) whiny_users = TRUE; #ifdef HAVE_MCHECK_H if (do_tidy_mem) mtrace(); #endif /* HAVE_MCHECK_H */ #if defined(LC_CTYPE) setlocale(LC_CTYPE, ""); #endif #if defined(LC_COLLATE) setlocale(LC_COLLATE, ""); #endif #if defined(LC_MESSAGES) setlocale(LC_MESSAGES, ""); #endif #if defined(LC_NUMERIC) /* * Force the issue here. According to POSIX 2001, decimal * point is used for parsing source code and for command-line * assignments and the locale value for processing input, * number to string conversion, and printing output. */ setlocale(LC_NUMERIC, "C"); #endif #if defined(LC_TIME) setlocale(LC_TIME, ""); #endif #ifdef MBS_SUPPORT /* * In glibc, MB_CUR_MAX is actually a function. This value is * tested *a lot* in many speed-critical places in gawk. Caching * this value once makes a speed difference. */ gawk_mb_cur_max = MB_CUR_MAX; /* Without MBS_SUPPORT, gawk_mb_cur_max is 1. */ #endif (void) bindtextdomain(PACKAGE, LOCALEDIR); (void) textdomain(PACKAGE); (void) signal(SIGFPE, catchsig); (void) signal(SIGSEGV, catchsig); #ifdef SIGBUS (void) signal(SIGBUS, catchsig); #endif myname = gawk_name(argv[0]); argv[0] = (char *) myname; os_arg_fixup(&argc, &argv); /* emulate redirection, expand wildcards */ /* remove sccs gunk */ if (strncmp(version_string, "@(#)", 4) == 0) version_string += 4; if (argc < 2) usage(1, stderr); /* Robustness: check that file descriptors 0, 1, 2 are open */ init_fds(); /* init array handling. */ array_init(); /* we do error messages ourselves on invalid options */ opterr = FALSE; /* option processing. ready, set, go! */ for (optopt = 0, old_optind = 1; (c = getopt_long(argc, argv, optlist, optab, NULL)) != EOF; optopt = 0, old_optind = optind) { if (do_posix) opterr = TRUE; switch (c) { case 'F': preassigns_add(PRE_ASSIGN_FS, optarg); break; case 'S': disallow_var_assigns = TRUE; /* fall through */ case 'f': /* * a la MKS awk, allow multiple -f options. * this makes function libraries real easy. * most of the magic is in the scanner. * * The following is to allow for whitespace at the end * of a #! /bin/gawk line in an executable file */ scan = optarg; if (argv[optind-1] != optarg) while (ISSPACE(*scan)) scan++; srcfiles_add(SOURCEFILE, (*scan == '\0' ? argv[optind++] : optarg)); break; case 'v': preassigns_add(PRE_ASSIGN, optarg); break; case 'm': /* * Research awk extension. * -mf nnn set # fields, gawk ignores * -mr nnn set record length, ditto */ if (do_lint) lintwarn(_("`-m[fr]' option irrelevant in gawk")); if (optarg[0] != 'r' && optarg[0] != 'f') warning(_("-m option usage: `-m[fr] nnn'")); /* * Set fixed length records for Tandem, * ignored on other platforms (see io.c:get_a_record). */ if (optarg[0] == 'r') { if (ISDIGIT(optarg[1])) MRL = atoi(optarg+1); else { MRL = atoi(argv[optind]); optind++; } } else if (optarg[1] == '\0') optind++; break; case 'W': /* gawk specific options - now in getopt_long */ fprintf(stderr, _("%s: option `-W %s' unrecognized, ignored\n"), argv[0], optarg); break; /* These can only come from long form options */ case 'C': copyleft(); break; case 'd': do_dump_vars = TRUE; if (optarg != NULL && optarg[0] != '\0') varfile = optarg; break; case 'l': #ifndef NO_LINT do_lint = LINT_ALL; if (optarg != NULL) { if (strcmp(optarg, "fatal") == 0) lintfunc = r_fatal; else if (strcmp(optarg, "invalid") == 0) do_lint = LINT_INVALID; } #endif break; case 'p': do_profiling = TRUE; if (optarg != NULL) set_prof_file(optarg); else set_prof_file(DEFAULT_PROFILE); break; case 's': if (optarg[0] == '\0') warning(_("empty argument to `--source' ignored")); else srcfiles_add(CMDLINE, optarg); break; case 'u': usage(0, stdout); /* per coding stds */ break; case 'V': version(); break; case 0: /* * getopt_long found an option that sets a variable * instead of returning a letter. Do nothing, just * cycle around for the next one. */ break; case 'D': #ifdef GAWKDEBUG yydebug = 2; break; #endif /* if not debugging, fall through */ case '?': default: /* * New behavior. If not posix, an unrecognized * option stops argument processing so that it can * go into ARGV for the awk program to see. This * makes use of ``#! /bin/gawk -f'' easier. * * However, it's never simple. If optopt is set, * an option that requires an argument didn't get the * argument. We care because if opterr is 0, then * getopt_long won't print the error message for us. */ if (! do_posix && (optopt == '\0' || strchr(optlist, optopt) == NULL)) { /* * can't just do optind--. In case of an * option with >= 2 letters, getopt_long * won't have incremented optind. */ optind = old_optind; stopped_early = TRUE; goto out; } else if (optopt != '\0') /* Use 1003.2 required message format */ fprintf(stderr, _("%s: option requires an argument -- %c\n"), myname, optopt); /* else let getopt print error message for us */ break; } if (c == 'S') /* --exec ends option processing */ break; } out: if (do_nostalgia) nostalgia(); /* check for POSIXLY_CORRECT environment variable */ if (! do_posix && getenv("POSIXLY_CORRECT") != NULL) { do_posix = TRUE; if (do_lint) lintwarn( _("environment variable `POSIXLY_CORRECT' set: turning on `--posix'")); } if (do_posix) { if (do_traditional) /* both on command line */ warning(_("`--posix' overrides `--traditional'")); else do_traditional = TRUE; /* * POSIX compliance also implies * no GNU extensions either. */ } if (do_traditional && do_non_decimal_data) { do_non_decimal_data = FALSE; warning(_("`--posix'/`--traditional' overrides `--non-decimal-data'")); } if (do_lint && os_is_setuid()) warning(_("running %s setuid root may be a security problem"), myname); /* * Force profiling if this is pgawk. * Don't bother if the command line already set profiling up. */ if (! do_profiling) init_profiling(& do_profiling, DEFAULT_PROFILE); /* load group set */ init_groupset(); /* initialize the null string */ Nnull_string = make_string("", 0); Nnull_string->numbr = 0.0; Nnull_string->type = Node_val; Nnull_string->flags = (PERM|STRCUR|STRING|NUMCUR|NUMBER); /* * Tell the regex routines how they should work. * Do this before initializing variables, since * they could want to do a regexp compile. */ resetup(); /* Set up the special variables */ init_vars(); /* Set up the field variables */ init_fields(); /* Now process the pre-assignments */ for (i = 0; i <= numassigns; i++) if (preassigns[i].stype == PRE_ASSIGN) (void) arg_assign(preassigns[i].val, TRUE); else /* PRE_ASSIGN_FS */ cmdline_fs(preassigns[i].val); free(preassigns); if ((BINMODE & 1) != 0) if (os_setbinmode(fileno(stdin), O_BINARY) == -1) fatal(_("can't set binary mode on stdin (%s)"), strerror(errno)); if ((BINMODE & 2) != 0) { if (os_setbinmode(fileno(stdout), O_BINARY) == -1) fatal(_("can't set binary mode on stdout (%s)"), strerror(errno)); if (os_setbinmode(fileno(stderr), O_BINARY) == -1) fatal(_("can't set binary mode on stderr (%s)"), strerror(errno)); } #ifdef GAWKDEBUG setbuf(stdout, (char *) NULL); /* make debugging easier */ #endif if (isatty(fileno(stdout))) output_is_tty = TRUE; /* No -f or --source options, use next arg */ if (numfiles == -1) { if (optind > argc - 1 || stopped_early) /* no args left or no program */ usage(1, stderr); srcfiles_add(CMDLINE, argv[optind]); optind++; } init_args(optind, argc, (char *) myname, argv); (void) tokexpand(); #if defined(LC_NUMERIC) /* * FRAGILE! CAREFUL! * Pre-initing the variables with arg_assign() can change the * locale. Force it to C before parsing the program. */ setlocale(LC_NUMERIC, "C"); #endif /* Read in the program */ if (yyparse() != 0 || errcount != 0) exit(1); free(srcfiles); if (do_intl) exit(0); if (do_lint && begin_block == NULL && expression_value == NULL && end_block == NULL) lintwarn(_("no program text at all!")); if (do_lint) shadow_funcs(); init_profiling_signals(); #if defined(LC_NUMERIC) /* See comment above. */ setlocale(LC_NUMERIC, ""); #endif #if defined(HAVE_LOCALE_H) loc = *localeconv(); /* Make a local copy of locale numeric info */ #endif /* Whew. Finally, run the program. */ if (begin_block != NULL) { in_begin_rule = TRUE; (void) interpret(begin_block); } in_begin_rule = FALSE; if (! exiting && (expression_value != NULL || end_block != NULL)) do_input(); if (end_block != NULL) { in_end_rule = TRUE; (void) interpret(end_block); } in_end_rule = FALSE; /* * This used to be: * * if (close_io() != 0 && ! exiting && exit_val == 0) * exit_val = 1; * * Other awks don't care about problems closing open files * and pipes, in that it doesn't affect their exit status. * So we no longer do either. */ (void) close_io(& stdio_problem); /* * However, we do want to exit non-zero if there was a problem * with stdout/stderr, so we reinstate a slightly different * version of the above: */ if (stdio_problem && ! exiting && exit_val == 0) exit_val = 1; if (do_profiling) { dump_prog(begin_block, expression_value, end_block); dump_funcs(); } if (do_dump_vars) dump_vars(varfile); if (do_tidy_mem) release_all_vars(); exit(exit_val); /* more portable */ return exit_val; /* to suppress warnings */ }