static PyObject *AO_repr( PyAscanfObject *self ) { char *repr= NULL; PyObject *ret= NULL; if( self ){ if( self->af ){ repr= concat( "<", ATN(self->af), " PyAscanfObject \"", self->af->name, "\"", NULL ); if( self->af->type== _ascanf_array ){ char *type= (self->af->iarray)? "integer(s)" : "double(s)"; char count[256]; snprintf( count, sizeof(count)/sizeof(char), "0x%lx[%d]", ((self->af->iarray)? (void*) self->af->iarray : (void*) self->af->array), self->af->N ); repr= concat2( repr, "\t: ", count, " ", type, NULL ); } if( self->af->usage ){ repr= concat2( repr, "\t:\t\"", self->af->usage, "\"", NULL ); } repr= concat2( repr, ">", NULL ); } else{ repr= XGstrdup("(NULL pointer)"); } } // ret= PyBytes_FromString(repr); ret= PyString_FromString( repr ); xfree(repr); return(ret); }
void number(void) { if (sgt_printf()->flags.prec < 0 && sgt_printf()->flags.spec != 'f') sgt_printf()->flags.prec = 1; else if (sgt_printf()->flags.spec != 'f') sgt_printf()->flags.pad = ' '; if (sgt_printf()->flags.prec == 0 && sgt_printf()->flags.number.word == 0) { if ((sgt_printf()->flags.base == 8 && sgt_printf()->flags.alt) || sgt_printf()->flags.spec == 'f' || sgt_printf()->flags.spec == 'b') number_type(); } else { number_type(); } if (sgt_printf()->flags.spec == 'f' && sgt_printf()->flags.alt && sgt_printf()->flags.prec == 0) sgt_printf()->work_buffer = concat2(sgt_printf()->work_buffer, ft_strlen(sgt_printf()->work_buffer), ".", 1); sgt_printf()->flags.prec = ft_max(0, sgt_printf()->flags.prec - ft_strlen(sgt_printf()->work_buffer)); if (sgt_printf()->flags.left == false) s_not_left(); else number_left(); }
static void findlibs(char *const *liblst) { int i, k; const char *lib, *path; char *lfn; size_t len; lfn = NULL; for (i = 0; (lib = liblst[i]) != NULL; i++) { for (k = 0; (path = libsrchpath[k]) != NULL; k++) { len = strlen(path) + strlen(lib); lfn = xrealloc(lfn, len + sizeof ("/llib-l.ln")); (void)sprintf(lfn, "%s/llib-l%s.ln", path, lib); if (rdok(lfn)) break; lfn = xrealloc(lfn, len + sizeof ("/lint/llib-l.ln")); (void)sprintf(lfn, "%s/lint/llib-l%s.ln", path, lib); if (rdok(lfn)) break; } if (path != NULL) { appstrg(&l2libs, concat2("-l", lfn)); } else { warnx("cannot find llib-l%s.ln", lib); } } free(lfn); }
static void appdef(char ***lstp, const char *def) { appstrg(lstp, concat2("-D__", def)); appstrg(lstp, concat3("-D__", def, "__")); }
void compute_output_file_names (void) { compute_file_name_parts (); /* If not yet done. */ if (!src_extension) src_extension = xstrdup (".c"); if (!header_extension) header_extension = xstrdup (".h"); parser_file_name = (spec_outfile ? xstrdup (spec_outfile) : concat2 (all_but_ext, src_extension)); if (defines_flag) { if (! spec_defines_file) spec_defines_file = concat2 (all_but_ext, header_extension); } if (graph_flag) { if (! spec_graph_file) spec_graph_file = concat2 (all_but_tab_ext, ".dot"); output_file_name_check (&spec_graph_file); } if (xml_flag) { if (! spec_xml_file) spec_xml_file = concat2 (all_but_tab_ext, ".xml"); output_file_name_check (&spec_xml_file); } if (report_flag) { if (!spec_verbose_file) spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT); output_file_name_check (&spec_verbose_file); } free (all_but_tab_ext); free (src_extension); free (header_extension); }
void compute_output_file_names (void) { char const *name[4]; int i; int j; int names = 0; compute_file_name_parts (); /* If not yet done. */ if (!src_extension) src_extension = ".c"; if (!header_extension) header_extension = ".h"; name[names++] = parser_file_name = spec_outfile ? spec_outfile : concat2 (all_but_ext, src_extension); if (defines_flag) { if (! spec_defines_file) spec_defines_file = concat2 (all_but_ext, header_extension); name[names++] = spec_defines_file; } if (graph_flag) { if (! spec_graph_file) spec_graph_file = concat2 (all_but_tab_ext, ".vcg"); name[names++] = spec_graph_file; } if (report_flag) { spec_verbose_file = concat2 (all_but_tab_ext, OUTPUT_EXT); name[names++] = spec_verbose_file; } for (j = 0; j < names; j++) for (i = 0; i < j; i++) if (strcmp (name[i], name[j]) == 0) warn (_("conflicting outputs to file %s"), quote (name[i])); }
/* Returns 0 if the printer has been deleted due to a fatal I/O error, 1 otherwise. */ static int sync_printer_with_devmode (struct device* d, DEVMODEW* devmode_in, DEVMODEW* devmode_out, Lisp_Object devname) { /* Change connection if the device changed */ if (!NILP (devname) && lisp_strcasecmp_i18n (devname, DEVICE_MSPRINTER_NAME (d)) != 0) { Lisp_Object new_connection = devname; DEVICE_CONNECTION (d) = Qnil; if (!NILP (Ffind_device (new_connection, Qmsprinter))) { /* We are in trouble - second msprinter for the same device. Nothing wrong on the Windows side, just forge a unique connection name. Use the memory address of d as a unique suffix. */ Ibyte new_connext[20]; qxesprintf (new_connext, ":%X", LISP_OBJECT_UID (wrap_device (d))); new_connection = concat2 (devname, build_istring (new_connext)); } DEVICE_CONNECTION (d) = new_connection; /* Reinitialize printer. The device can pop off in process */ if (!msprinter_reinit_device (d, devname)) { /* Kaboom! */ delete_device_internal (d, 1, 0, 1); return 0; } } { Extbyte *nameext; nameext = LISP_STRING_TO_TSTR (DEVICE_MSPRINTER_NAME (d)); /* Apply the new devmode to the printer */ qxeDocumentProperties (NULL, DEVICE_MSPRINTER_HPRINTER (d), nameext, devmode_out, devmode_in, DM_IN_BUFFER | DM_OUT_BUFFER); /* #### ResetDC fails sometimes, Bill only knows why. The solution below looks more like a workaround to me, although it might be fine. --kkm */ if (qxeResetDC (DEVICE_MSPRINTER_HDC (d), devmode_out) == NULL) { DeleteDC (DEVICE_MSPRINTER_HDC (d)); DEVICE_MSPRINTER_HDC (d) = qxeCreateDC (XETEXT ("WINSPOOL"), nameext, NULL, devmode_out); } } return 1; }
int ascanf_concat ( ASCB_ARGLIST ) { ASCB_FRAME ascanf_Function *s1; set_NaN(*result); ascanf_arg_error= 0; if( !args || ascanf_arguments< 1 ){ ascanf_arg_error= 1; } else{ int idx= 0; char *rstring= NULL; for( idx= 0; idx< ascanf_arguments; idx++ ){ if( (s1= parse_ascanf_address(args[idx], 0, "ascanf_concat", (int) ascanf_verbose, NULL )) && s1->usage && !(s1->type== _ascanf_procedure || s1->type== _ascanf_function) ){ rstring= concat2( rstring, s1->usage, NULL ); } else if( s1 ){ if( s1->type== _ascanf_array && s1->N ){ int i; rstring= concat2( rstring, "{", ad2str( ASCANF_ARRAY_ELEM(s1,0), d3str_format, NULL ), NULL ); for( i= 1; i< s1->N-1; i++ ){ rstring= concat2( rstring, ",", ad2str( ASCANF_ARRAY_ELEM(s1,i), d3str_format, NULL ), NULL ); } rstring= concat2( rstring, ",", ad2str( ASCANF_ARRAY_ELEM(s1,i), d3str_format, NULL ), "}", NULL ); } else{ rstring= concat2( rstring, ad2str(s1->value, d3str_format, NULL), NULL ); } } else{ rstring= concat2( rstring, ad2str(args[idx], d3str_format, NULL), NULL ); } } if( rstring ){ ascanf_Function *allocated; if( (allocated= Create_Internal_ascanfString( rstring, level )) ){ /* We must now make sure that the just created internal variable behaves as a user variable: */ allocated->user_internal= True; allocated->internal= True; *result= take_ascanf_address( allocated ); } else{ fprintf( StdErr, " (error: could not duplicate %s=\"%s\": %s)== ", s1->name, rstring, serror() ); ascanf_arg_error= True; *result= 0; } xfree(rstring); } } return(!ascanf_arg_error); }
/* Build termlist: a comma separated list of all the words in the list for * use in the SQL query later. */ static char * build_termlist(char **list, int n) { char *termlist = NULL; int total_len = BUFLEN * 20; /* total bytes allocated to termlist */ termlist = emalloc(total_len); int offset = 0; /* Next byte to write at in termlist */ int i; termlist[0] = '('; offset++; for (i = 0; i < n; i++) { int d = strlen(list[i]); if (total_len - offset < d + 3) { termlist = erealloc(termlist, offset + total_len); total_len *= 2; } memcpy(termlist + offset++, "\'", 1); memcpy(termlist + offset, list[i], d); offset += d; if (i == n - 1) { memcpy(termlist + offset, "\'", 1); offset++; } else { memcpy(termlist + offset, "\',", 2); offset += 2; } } if (total_len - offset > 3) memcpy(termlist + offset, ")", 2); else concat2(&termlist, ")", 1); return termlist; }
/* * concat-- * Utility function. Concatenates together: dst, a space character and src. * dst + " " + src */ void concat(char **dst, const char *src) { concat2(dst, src, strlen(src)); }
int main (int argc, char **argv) { const char *prev_arg; const char *shname; const char *runprog = NULL; int remaining_args = 0; int exit_with_session; int exit_with_x11 = FALSE; int binary_syntax = FALSE; int c_shell_syntax = FALSE; int bourne_shell_syntax = FALSE; int auto_shell_syntax = FALSE; int autolaunch = FALSE; int requires_arg = FALSE; int close_stderr = FALSE; int i; int ret; int bus_pid_to_launcher_pipe[2]; int bus_pid_to_babysitter_pipe[2]; int bus_address_to_launcher_pipe[2]; char *config_file; dbus_bool_t user_bus_supported = FALSE; DBusString user_bus; const char *error_str; exit_with_session = FALSE; config_file = NULL; /* Ensure that the first three fds are open, to ensure that when we * create other file descriptors (for example for epoll, inotify or * a socket), they never get assigned as fd 0, 1 or 2. If they were, * which could happen if our caller had (incorrectly) closed those * standard fds, then we'd start dbus-daemon with those fds closed, * which is unexpected and could cause it to misbehave. */ if (!_dbus_ensure_standard_fds (0, &error_str)) { fprintf (stderr, "dbus-launch: fatal error setting up standard fds: %s: %s\n", error_str, _dbus_strerror (errno)); return 1; } prev_arg = NULL; i = 1; while (i < argc) { const char *arg = argv[i]; if (strcmp (arg, "--help") == 0 || strcmp (arg, "-h") == 0 || strcmp (arg, "-?") == 0) usage (0); else if (strcmp (arg, "--auto-syntax") == 0) auto_shell_syntax = TRUE; else if (strcmp (arg, "-c") == 0 || strcmp (arg, "--csh-syntax") == 0) c_shell_syntax = TRUE; else if (strcmp (arg, "-s") == 0 || strcmp (arg, "--sh-syntax") == 0) bourne_shell_syntax = TRUE; else if (strcmp (arg, "--binary-syntax") == 0) binary_syntax = TRUE; else if (strcmp (arg, "--version") == 0) version (); else if (strcmp (arg, "--exit-with-session") == 0) exit_with_session = TRUE; else if (strcmp (arg, "--exit-with-x11") == 0) exit_with_x11 = TRUE; else if (strcmp (arg, "--close-stderr") == 0) close_stderr = TRUE; else if (strstr (arg, "--autolaunch=") == arg) { const char *s; if (autolaunch) { fprintf (stderr, "--autolaunch given twice\n"); exit (1); } autolaunch = TRUE; s = strchr (arg, '='); ++s; save_machine_uuid (s); } else if (prev_arg && strcmp (prev_arg, "--autolaunch") == 0) { if (autolaunch) { fprintf (stderr, "--autolaunch given twice\n"); exit (1); } autolaunch = TRUE; save_machine_uuid (arg); requires_arg = FALSE; } else if (strcmp (arg, "--autolaunch") == 0) requires_arg = TRUE; else if (strstr (arg, "--config-file=") == arg) { const char *file; if (config_file != NULL) { fprintf (stderr, "--config-file given twice\n"); exit (1); } file = strchr (arg, '='); ++file; config_file = xstrdup (file); } else if (prev_arg && strcmp (prev_arg, "--config-file") == 0) { if (config_file != NULL) { fprintf (stderr, "--config-file given twice\n"); exit (1); } config_file = xstrdup (arg); requires_arg = FALSE; } else if (strcmp (arg, "--config-file") == 0) requires_arg = TRUE; else if (arg[0] == '-') { if (strcmp (arg, "--") != 0) { fprintf (stderr, "Option `%s' is unknown.\n", arg); exit (1); } else { runprog = argv[i+1]; remaining_args = i+2; break; } } else { runprog = arg; remaining_args = i+1; break; } prev_arg = arg; ++i; } if (requires_arg) { fprintf (stderr, "Option `%s' requires an argument.\n", prev_arg); exit (1); } if (auto_shell_syntax) { if ((shname = getenv ("SHELL")) != NULL) { if (!strncmp (shname + strlen (shname) - 3, "csh", 3)) c_shell_syntax = TRUE; else bourne_shell_syntax = TRUE; } else bourne_shell_syntax = TRUE; } if (exit_with_session) verbose ("--exit-with-session enabled\n"); if (exit_with_x11) verbose ("--exit-with-x11 enabled\n"); if (autolaunch) { #ifndef DBUS_BUILD_X11 fprintf (stderr, "Autolaunch requested, but X11 support not compiled in.\n" "Cannot continue.\n"); exit (1); #else /* DBUS_BUILD_X11 */ fprintf (stderr, "X11 autolaunch support disabled at compile time.\n"); exit (1); #endif /* DBUS_BUILD_X11 */ } else if (exit_with_x11) { #ifndef DBUS_BUILD_X11 fprintf (stderr, "Session lifetime based on X11 requested, but X11 support not compiled in.\n"); exit (1); #else /* DBUS_BUILD_X11 */ if (!read_machine_uuid_if_needed()) { fprintf (stderr, "Session lifetime based on X11 requested, but machine UUID unavailable.\n"); exit (1); } if (!x11_init ()) { fprintf (stderr, "Session lifetime based on X11 requested, but X11 initialization failed.\n"); exit (1); } #endif /* DBUS_BUILD_X11 */ } #ifdef DBUS_BUILD_X11 else if (read_machine_uuid_if_needed()) { x11_init(); } #endif /* DBUS_BUILD_X11 */ if (pipe (bus_pid_to_launcher_pipe) < 0 || pipe (bus_address_to_launcher_pipe) < 0 || pipe (bus_pid_to_babysitter_pipe) < 0) { fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); exit (1); } ret = fork (); if (ret < 0) { fprintf (stderr, "Failed to fork: %s\n", strerror (errno)); exit (1); } if (ret == 0) { /* Child */ #define MAX_FD_LEN 64 char write_pid_fd_as_string[MAX_FD_LEN]; char write_address_fd_as_string[MAX_FD_LEN]; #ifdef DBUS_BUILD_X11 xdisplay = NULL; #endif if (close_stderr) do_close_stderr (); verbose ("=== Babysitter's intermediate parent created\n"); /* Fork once more to create babysitter */ ret = fork (); if (ret < 0) { fprintf (stderr, "Failed to fork: %s\n", strerror (errno)); exit (1); } if (ret > 0) { /* In babysitter */ verbose ("=== Babysitter's intermediate parent continues\n"); close (bus_pid_to_launcher_pipe[READ_END]); close (bus_pid_to_launcher_pipe[WRITE_END]); close (bus_address_to_launcher_pipe[READ_END]); close (bus_address_to_launcher_pipe[WRITE_END]); close (bus_pid_to_babysitter_pipe[WRITE_END]); /* babysit() will fork *again* * and will also reap the pre-forked bus * daemon */ babysit (exit_with_session || exit_with_x11, ret, bus_pid_to_babysitter_pipe[READ_END]); exit (0); } verbose ("=== Bus exec process created\n"); /* Now we are the bus process (well, almost; * dbus-daemon itself forks again) */ close (bus_pid_to_launcher_pipe[READ_END]); close (bus_address_to_launcher_pipe[READ_END]); close (bus_pid_to_babysitter_pipe[READ_END]); close (bus_pid_to_babysitter_pipe[WRITE_END]); /* If we have a user bus and want to use it, do so instead of * exec'ing a new dbus-daemon. */ if (autolaunch && user_bus_supported) { do_write (bus_pid_to_launcher_pipe[WRITE_END], "0\n", 2); close (bus_pid_to_launcher_pipe[WRITE_END]); do_write (bus_address_to_launcher_pipe[WRITE_END], _dbus_string_get_const_data (&user_bus), _dbus_string_get_length (&user_bus)); do_write (bus_address_to_launcher_pipe[WRITE_END], "\n", 1); close (bus_address_to_launcher_pipe[WRITE_END]); exit (0); } sprintf (write_pid_fd_as_string, "%d", bus_pid_to_launcher_pipe[WRITE_END]); sprintf (write_address_fd_as_string, "%d", bus_address_to_launcher_pipe[WRITE_END]); verbose ("Calling exec()\n"); #ifdef DBUS_ENABLE_EMBEDDED_TESTS { /* exec from testdir */ const char *test_daemon = getenv ("DBUS_TEST_DAEMON"); if (test_daemon != NULL) { if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL) { config_file = concat2 (getenv ("DBUS_TEST_DATA"), "/valid-config-files/session.conf"); if (config_file == NULL) { fprintf (stderr, "Out of memory\n"); exit (1); } } execl (test_daemon, test_daemon, "--fork", "--print-pid", write_pid_fd_as_string, "--print-address", write_address_fd_as_string, config_file ? "--config-file" : "--session", config_file, /* has to be last in this varargs list */ NULL); fprintf (stderr, "Failed to execute test message bus daemon %s: %s.\n", test_daemon, strerror (errno)); exit (1); } } #endif /* DBUS_ENABLE_EMBEDDED_TESTS */ execl (DBUS_DAEMONDIR"/dbus-daemon", DBUS_DAEMONDIR"/dbus-daemon", "--fork", "--print-pid", write_pid_fd_as_string, "--print-address", write_address_fd_as_string, config_file ? "--config-file" : "--session", config_file, /* has to be last in this varargs list */ NULL); fprintf (stderr, "Failed to execute message bus daemon %s: %s. Will try again without full path.\n", DBUS_DAEMONDIR"/dbus-daemon", strerror (errno)); /* * If it failed, try running without full PATH. Note this is needed * because the build process builds the run-with-tmp-session-bus.conf * file and the dbus-daemon will not be in the install location during * build time. */ execlp ("dbus-daemon", "dbus-daemon", "--fork", "--print-pid", write_pid_fd_as_string, "--print-address", write_address_fd_as_string, config_file ? "--config-file" : "--session", config_file, /* has to be last in this varargs list */ NULL); fprintf (stderr, "Failed to execute message bus daemon: %s\n", strerror (errno)); exit (1); } else { /* Parent */ #define MAX_PID_LEN 64 pid_t bus_pid; char bus_address[MAX_ADDR_LEN]; char buf[MAX_PID_LEN]; char *end; long wid = 0; long val; verbose ("=== Parent dbus-launch continues\n"); close (bus_pid_to_launcher_pipe[WRITE_END]); close (bus_address_to_launcher_pipe[WRITE_END]); close (bus_pid_to_babysitter_pipe[READ_END]); verbose ("Waiting for babysitter's intermediate parent\n"); /* Immediately reap parent of babysitter * (which was created just for us to reap) */ if (do_waitpid (ret) < 0) { fprintf (stderr, "Failed to waitpid() for babysitter intermediate process: %s\n", strerror (errno)); exit (1); } verbose ("Reading address from bus\n"); /* Read the pipe data, print, and exit */ switch (read_line (bus_address_to_launcher_pipe[READ_END], bus_address, MAX_ADDR_LEN)) { case READ_STATUS_OK: break; case READ_STATUS_EOF: fprintf (stderr, "EOF in dbus-launch reading address from bus daemon\n"); exit (1); break; case READ_STATUS_ERROR: fprintf (stderr, "Error in dbus-launch reading address from bus daemon: %s\n", strerror (errno)); exit (1); break; } close (bus_address_to_launcher_pipe[READ_END]); verbose ("Reading PID from daemon\n"); /* Now read data */ switch (read_line (bus_pid_to_launcher_pipe[READ_END], buf, MAX_PID_LEN)) { case READ_STATUS_OK: break; case READ_STATUS_EOF: fprintf (stderr, "EOF reading PID from bus daemon\n"); exit (1); break; case READ_STATUS_ERROR: fprintf (stderr, "Error reading PID from bus daemon: %s\n", strerror (errno)); exit (1); break; } end = NULL; val = strtol (buf, &end, 0); if (buf == end || end == NULL) { fprintf (stderr, "Failed to parse bus PID \"%s\": %s\n", buf, strerror (errno)); exit (1); } bus_pid = val; /* Have to initialize bus_pid_to_kill ASAP, so that the X error callback can kill it if an error happens. */ bus_pid_to_kill = bus_pid; close (bus_pid_to_launcher_pipe[READ_END]); #ifdef DBUS_ENABLE_X11_AUTOLAUNCH if (xdisplay != NULL) { int ret2; verbose("Saving x11 address\n"); ret2 = x11_save_address (bus_address, bus_pid, &wid); /* Only get an existing dbus session when autolaunching */ if (autolaunch) { if (ret2 == 0) { char *address = NULL; /* another window got added. Return its address */ if (x11_get_address (&address, &bus_pid, &wid) && address != NULL) { verbose ("dbus-daemon is already running. Returning existing parameters.\n"); /* Kill the old bus */ kill_bus(); pass_info (runprog, address, bus_pid, wid, c_shell_syntax, bourne_shell_syntax, binary_syntax, argc, argv, remaining_args); } } if (ret2 < 0) { fprintf (stderr, "Error saving bus information.\n"); bus_pid_to_kill = bus_pid; kill_bus_and_exit (1); } } } #endif /* Forward the pid to the babysitter */ write_pid (bus_pid_to_babysitter_pipe[WRITE_END], bus_pid); close (bus_pid_to_babysitter_pipe[WRITE_END]); pass_info (runprog, bus_address, bus_pid, wid, c_shell_syntax, bourne_shell_syntax, binary_syntax, argc, argv, remaining_args); } return 0; }
static void single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *skp_v) { Lisp_Object map, item_string, enabled; struct gcpro gcpro1, gcpro2; int res; struct skp *skp = skp_v; /* Parse the menu item and leave the result in item_properties. */ GCPRO2 (key, item); res = parse_menu_item (item, 0); UNGCPRO; if (!res) return; /* Not a menu item. */ map = XVECTOR (item_properties)->contents[ITEM_PROPERTY_MAP]; enabled = XVECTOR (item_properties)->contents[ITEM_PROPERTY_ENABLE]; item_string = XVECTOR (item_properties)->contents[ITEM_PROPERTY_NAME]; if (!NILP (map) && SREF (item_string, 0) == '@') { if (!NILP (enabled)) /* An enabled separate pane. Remember this to handle it later. */ skp->pending_maps = Fcons (Fcons (map, Fcons (item_string, key)), skp->pending_maps); return; } #if defined(HAVE_X_WINDOWS) || defined(MSDOS) #ifndef HAVE_BOXES /* Simulate radio buttons and toggle boxes by putting a prefix in front of them. */ { Lisp_Object prefix = Qnil; Lisp_Object type = XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE]; if (!NILP (type)) { Lisp_Object selected = XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED]; if (skp->notbuttons) /* The first button. Line up previous items in this menu. */ { int index = skp->notbuttons; /* Index for first item this menu. */ int submenu = 0; Lisp_Object tem; while (index < menu_items_used) { tem = XVECTOR (menu_items)->contents[index + MENU_ITEMS_ITEM_NAME]; if (NILP (tem)) { index++; submenu++; /* Skip sub menu. */ } else if (EQ (tem, Qlambda)) { index++; submenu--; /* End sub menu. */ } else if (EQ (tem, Qt)) index += 3; /* Skip new pane marker. */ else if (EQ (tem, Qquote)) index++; /* Skip a left, right divider. */ else { if (!submenu && SREF (tem, 0) != '\0' && SREF (tem, 0) != '-') XVECTOR (menu_items)->contents[index + MENU_ITEMS_ITEM_NAME] = concat2 (build_string (" "), tem); index += MENU_ITEMS_ITEM_LENGTH; } } skp->notbuttons = 0; } /* Calculate prefix, if any, for this item. */ if (EQ (type, QCtoggle)) prefix = build_string (NILP (selected) ? "[ ] " : "[X] "); else if (EQ (type, QCradio)) prefix = build_string (NILP (selected) ? "( ) " : "(*) "); } /* Not a button. If we have earlier buttons, then we need a prefix. */ else if (!skp->notbuttons && SREF (item_string, 0) != '\0' && SREF (item_string, 0) != '-') prefix = build_string (" "); if (!NILP (prefix)) item_string = concat2 (prefix, item_string); } #endif /* not HAVE_BOXES */ #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK) if (!NILP (map)) /* Indicate visually that this is a submenu. */ item_string = concat2 (item_string, build_string (" >")); #endif #endif /* HAVE_X_WINDOWS || MSDOS */ push_menu_item (item_string, enabled, key, XVECTOR (item_properties)->contents[ITEM_PROPERTY_DEF], XVECTOR (item_properties)->contents[ITEM_PROPERTY_KEYEQ], XVECTOR (item_properties)->contents[ITEM_PROPERTY_TYPE], XVECTOR (item_properties)->contents[ITEM_PROPERTY_SELECTED], XVECTOR (item_properties)->contents[ITEM_PROPERTY_HELP]); #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI) /* Display a submenu using the toolkit. */ if (! (NILP (map) || NILP (enabled))) { push_submenu_start (); single_keymap_panes (map, Qnil, key, skp->maxdepth - 1); push_submenu_end (); } #endif }
cellInfo_t sql_eval( sqlInfo_t *db, Expr expr, tableInfo_t * table, cellInfo_t * row, int index, int total, sqlData_t * params, cellInfo_t * aggregate ) { value_t stack[ 64 ]; int sp; int i; static char buffer[ 16384 ]; // FIX ME: this is the source of bugs static int size = 0; int top = size; for ( i=0,sp=0; expr[ i ] != OP_END; ) { op_t op = READ_OP; switch( op ) { case OP_PUSH_INTEGER: stack[ sp++ ].i = READ_INT; break; case OP_PUSH_STRING: stack[ sp++ ].s = READ_STRING; break; case OP_PUSH_COLUMN: stack[ sp++ ].p = table->columns + READ_OP; break; case OP_PUSH_COLUMN_VAL: stack[ sp++ ].i = row[ READ_OP ].integer; break; case OP_PUSH_STRING_PARAM: stack[ sp++ ].s = params[ READ_OP ].payload.string; break; case OP_PUSH_INTEGER_PARAM: stack[ sp++ ].i = params[ READ_OP ].payload.integer; break; case OP_ROWINDEX: stack[ sp++ ].i = (row - table->rows) / table->column_count; break; case OP_ROWNUMBER: stack[ sp++ ].i = index; break; case OP_ROWTOTAL: stack[ sp++ ].i = total; break; case OP_ROWCOUNT: stack[ sp++ ].i = table->row_count; break; case OP_SYS_TIME: stack[ sp++ ].i = Sys_Milliseconds(); break; case OP_SUBTRACT: LVALUE.i = LEFT_OPERAND.i - RIGHT_OPERAND.i; sp--; break; case OP_ADD: LVALUE.i = LEFT_OPERAND.i + RIGHT_OPERAND.i; sp--; break; case OP_DIVIDE: LVALUE.i = LEFT_OPERAND.i / RIGHT_OPERAND.i; sp--; break; case OP_MULTIPLY: LVALUE.i = LEFT_OPERAND.i * RIGHT_OPERAND.i; sp--; break; case OP_MODULUS: LVALUE.i = LEFT_OPERAND.i % RIGHT_OPERAND.i; sp--; break; case OP_LOGICAL_AND: LVALUE.i = LEFT_OPERAND.i && RIGHT_OPERAND.i; sp--; break; case OP_LOGICAL_OR: LVALUE.i = LEFT_OPERAND.i || RIGHT_OPERAND.i; sp--; break; case OP_BITWISE_AND: LVALUE.i = LEFT_OPERAND.i & RIGHT_OPERAND.i; sp--; break; case OP_BITWISE_OR: LVALUE.i = LEFT_OPERAND.i | RIGHT_OPERAND.i; sp--; break; case OP_GT: LVALUE.i = LEFT_OPERAND.i > RIGHT_OPERAND.i; sp--; break; case OP_LT: LVALUE.i = LEFT_OPERAND.i < RIGHT_OPERAND.i; sp--; break; case OP_GE: LVALUE.i = LEFT_OPERAND.i >= RIGHT_OPERAND.i; sp--; break; case OP_LE: LVALUE.i = LEFT_OPERAND.i <= RIGHT_OPERAND.i; sp--; break; case OP_EQ: LVALUE.i = LEFT_OPERAND.i == RIGHT_OPERAND.i; sp--; break; case OP_NE: LVALUE.i = LEFT_OPERAND.i != RIGHT_OPERAND.i; sp--; break; case OP_ATOI: if (stack[ sp-1 ].s) { stack[ sp-1 ].i = atoi( stack[ sp-1 ].s ); } else { stack[ sp-1 ].i = -1; } break; case OP_LIKE: LVALUE.i = Q_stricmp( LEFT_OPERAND.s, RIGHT_OPERAND.s ) == 0; sp--; break; case OP_MATCH: LVALUE.i = Com_Filter( RIGHT_OPERAND.s, LEFT_OPERAND.s, 0 ); sp--; break; case OP_NOTLIKE: LVALUE.i = Q_stricmp( LEFT_OPERAND.s, RIGHT_OPERAND.s ) != 0; sp--; break; case OP_INT_MIN: LVALUE.i = (LEFT_OPERAND.i<RIGHT_OPERAND.i)?LEFT_OPERAND.i:RIGHT_OPERAND.i; sp--; break; case OP_INT_MAX: LVALUE.i = (LEFT_OPERAND.i>RIGHT_OPERAND.i)?LEFT_OPERAND.i:RIGHT_OPERAND.i; sp--; break; case OP_ABS: stack[ sp-1 ].i = abs( stack[ sp-1 ].i ); break; case OP_UMINUS: stack[ sp-1 ].i = -stack[ sp-1 ].i; break; case OP_NOT: stack[ sp-1 ].i = !(stack[ sp-1 ].i); break; case OP_REMOVE: { int p = READ_OP; int n = min( params[ p ].payload.integer, stack[ sp-1 ].i ); params[ p ].payload.integer -= n; stack[ sp-1 ].i = n; } break; case OP_ASSIGN_INT_TO_COLUMN: { columnInfo_t * c = (columnInfo_t*)LEFT_OPERAND.p; ASSERT( c->num >= 0 && c->num < table->column_count ); if ( row[ c->num ].integer != RIGHT_OPERAND.i ) { table->modified |= (1<<c->num); } LVALUE.i = row[ c->num ].integer = RIGHT_OPERAND.i; sp--; } break; case OP_ASSIGN_STRING_TO_COLUMN: { // a string is being inserted into a table. this string is expected to remain // constant throughout the life of the table. strings stored in tables do not // change. string cells can not be modified with an 'UPDATE' command columnInfo_t * c = (columnInfo_t*)LEFT_OPERAND.p; cellInfo_t * cell = row + c->num; const char * o = cell->string; ASSERT( c->format == STRING ); //ASSERT( cell->string == 0 ); // help!! if ( abs(RIGHT_OPERAND.i) < 0x10000 ) { // can't figure out data type for cases like: INSERT INTO missions VALUES(7,'wealth',500); 3rd column in text // so trying to guess LVALUE.s = cell->string = sql_alloc_string( db, fn( RIGHT_OPERAND.i, FN_PLAIN ) ); sp--; } else { LVALUE.s = cell->string = sql_alloc_string( db, RIGHT_OPERAND.s ); sp--; } if ( Q_stricmp( o, cell->string ) ) { table->modified |= (1<<c->num); } } break; case OP_ASSIGN_CS_TO_ROW: { row_cs( db, table, row, stack[ sp-1 ].s ); } break; case OP_COUNT: (*aggregate).integer++; break; case OP_MAX: { int v = stack[ sp-1 ].i; (*aggregate).integer = (index==0)?v:max( (*aggregate).integer, v ); } break; case OP_MIN: { int v = stack[ sp-1 ].i; (*aggregate).integer = (index==0)?v:min( (*aggregate).integer, v ); } break; case OP_SUM: (*aggregate).integer += stack[ sp-1 ].i; break; case OP_FORMAT: { char * s = buffer + size; int flags = READ_INT; size += fn_buffer( s, stack[ sp-1 ].i, flags ); stack[ sp-1 ].s = s; } break; case OP_CONCAT: { LVALUE.s = concat( LEFT_OPERAND.s, RIGHT_OPERAND.s, buffer, sizeof(buffer), &size ); sp--; } break; case OP_COLLAPSE: { char * s = buffer + size; size += concat2( s, sizeof(buffer)-size, stack, sp ); stack[ 0 ].s = s; sp = 1; } break; case OP_CVAR: { stack[ sp-1 ].s = Cvar_VariableString( stack[ sp-1 ].s ); } break; case OP_ACCESS_TABLE: { tableInfo_t * table; columnInfo_t * c; table = find_table( db, LEFT_OPERAND.s ); // allow table access outside current db if ( !table ) { table = find_table( sql_getclientdb(), LEFT_OPERAND.s ); if ( !table ) { table = find_table( sql_getserverdb(), LEFT_OPERAND.s ); if ( !table ) { table = find_table( sql_getcommondb(), LEFT_OPERAND.s ); } } } #ifdef DEVELOPER if ( !table ) { Com_Error( ERR_FATAL, "table '%s' does not exist.\n\n%s", LEFT_OPERAND.s, CURRENT_STMT ); } #endif c = find_column( table, RIGHT_OPERAND.s ); #ifdef DEVELOPER if ( !c ) { Com_Error( ERR_FATAL, "column '%s' expected on table '%s'.\n\n%s\n", RIGHT_OPERAND.s, LEFT_OPERAND.s, CURRENT_STMT ); } #endif LVALUE.p = table; sp--; stack[ sp++ ].p = c; } break; case OP_LOOKUP_I: { tableInfo_t * t = stack[ sp-3 ].p; columnInfo_t * c = stack[ sp-2 ].p; cellInfo_t k; int index; k.integer = stack[ sp-1 ].i; if ( !c->index ) { sql_create_index( db, t, c ); } #ifdef DEVELOPER if ( !c->index ) { Com_Error( ERR_FATAL, "index needed for column '%s' on table '%s'.\n\n%s", c->name, t->name, CURRENT_STMT ); } if ( c->format != INTEGER ) { Com_Error( ERR_FATAL, "expecting column '%s' on table '%s' to be integer, not string.\n\n%s", c->name, t->name, CURRENT_STMT ); } #endif if ( t->last_changed != t->last_indexed ) sql_table_reindex( t ); index = search_index_i( c->index, t->row_count, t->rows, t->column_count, c->num, k ); LVALUE.i = (index>=0)?c->index[ index ]:index; sp--; } break; case OP_ACCESS_ROW_I: { tableInfo_t * t = stack[ sp-3 ].p; int r = stack[ sp-2 ].i; columnInfo_t * c = find_column( t, stack[ sp-1 ].s ); #ifdef DEVELOPER if ( !t ) { Com_Error( ERR_FATAL, "table '%s' does not exist.\n\n%s", stack[sp-3].s, CURRENT_STMT ); } if ( !c ) { Com_Error( ERR_FATAL, "could not find column '%s' on table '%s' in statement:\n\n%s", stack[ sp-1 ].s, stack[sp-3].s, CURRENT_STMT ); } #endif sp -= 3; if ( r < 0 ) { stack[ sp++ ].i = -1; } else { int cell = (t->column_count*r) + c->num; if ( c->format == STRING ) { stack[ sp++ ].i = atoi( t->rows[ cell ].string ); } else { stack[ sp++ ].i = t->rows[ cell ].integer; } } } break; case OP_LOOKUP_S: { tableInfo_t * t = stack[ sp-3 ].p; columnInfo_t * c = stack[ sp-2 ].p; cellInfo_t k; int index; k.string = stack[ sp-1 ].s; if ( !c->index ) { sql_create_index( db, t, c ); } #ifdef DEVELOPER if ( !c->index ) { Com_Error( ERR_FATAL, "index needed for column '%s' on table '%s'.\n\n%s", c->name, t->name, CURRENT_STMT ); } if ( c->format != STRING ) { Com_Error( ERR_FATAL, "expecting column '%s' on table '%s' to be string, not integer.\n\n%s", c->name, t->name, CURRENT_STMT ); } #endif if ( t->last_changed != t->last_indexed ) sql_table_reindex( t ); index = search_index_s( c->index, t->row_count, t->rows, t->column_count, c->num, k ); LVALUE.i = (index>=0)?c->index[ index ]:index; sp--; } break; case OP_ACCESS_ROW_S: { tableInfo_t * t = stack[ sp-3 ].p; int r = stack[ sp-2 ].i; columnInfo_t * c = find_column( t, stack[ sp-1 ].s ); #ifdef DEVELOPER if ( !t ) { Com_Error( ERR_FATAL, "table does not exist.\n\n%s", CURRENT_STMT ); } if ( !c ) { Com_Error( ERR_FATAL, "invalid column for table '%s' in statement:\n\n%s", t->name, CURRENT_STMT ); } #endif sp -= 3; stack[ sp++ ].s = (r>=0)?t->rows[ (t->column_count*r) + c->num ].string:"???"; } break; case OP_PUSH_GS: { int offset = READ_INT; stack[ sp++ ].i = db->gs[ offset ]; } break; case OP_PUSH_GS_OFFSET: { int offset = READ_INT; stack[ sp-1 ].i = db->gs[ offset + stack[ sp-1 ].i ]; } break; case OP_PUSH_PS_CLIENT: { int offset = READ_INT; stack[ sp++ ].i = db->ps[ offset ]; } break; case OP_PUSH_PS_CLIENT_OFFSET: { int offset = READ_INT; stack[ sp-1 ].i = db->ps[ offset + stack[ sp-1 ].i ]; } break; case OP_IFTHENELSE: { int c = stack[ sp-1 ].i; value_t a = stack[ sp-2 ]; value_t b = stack[ sp-3 ]; sp -= 3; stack[ sp++ ] = (c)?b:a; } break; case OP_SHADER: { ASSERT( db->shader ); stack[ sp-1 ].i = db->shader( stack[ sp-1 ].s ); } break; case OP_SOUND: { ASSERT( db->sound ); stack[ sp-1 ].i = db->sound( stack[ sp-1 ].s ); } break; case OP_MODEL: { ASSERT( db->model ); stack[ sp-1 ].i = db->model( stack[ sp-1 ].s ); } break; case OP_PORTRAIT: { ASSERT( db->portrait ); stack[ sp-1 ].i = db->portrait( stack[ sp-1 ].s ); } break; case OP_PUSH_INTEGER_GLOBAL: { const char * global_id = READ_STRING; ASSERT( db->global_int ); stack[ sp++ ].i = db->global_int( global_id ); } break; // recursive integer call case OP_EVAL: { const char * s = stack[ sp-1 ].s; int r; switch ( SWITCHSTRING(s) ) { case 0: case CS('0',0,0,0): r = 0; break; case CS('1',0,0,0): r = 1; break; default: { Expr e; parseInfo_t pi = { 0 }; char tmp[ SQL_STMT_ALLOC ]; sqlStack_t* save = db->stmt_buffer.c; db->stmt_buffer.c = (sqlStack_t*)tmp; db->stmt_buffer.c->top = sizeof(sqlStack_t); pi.db = db; e = parse_expression( &s, &pi ); ASSERT( pi.rt == INTEGER ); ASSERT( pi.more == 0 ); r = sql_eval( db, e, table, row, index, total, params, aggregate ).integer; db->stmt_buffer.c = save; } break; } stack[ sp-1 ].i = r; } break; // recursive string call case OP_PRINT: { const char * s = stack[ sp-1 ].s; Expr e; parseInfo_t pi = { 0 }; char tmp[ SQL_STMT_ALLOC ]; sqlStack_t* save = db->stmt_buffer.c; db->stmt_buffer.c = (sqlStack_t*)tmp; db->stmt_buffer.c->top = sizeof(sqlStack_t); pi.db = db; pi.flags = PARSE_STRINGLITERAL; e = parse_expression( &s, &pi ); ASSERT( pi.rt == STRING ); ASSERT( pi.more == 0 ); stack[ sp-1 ].s = sql_eval( db, e, table, row, index, total, params, aggregate ).string; db->stmt_buffer.c = save; } break; // execute a precompiled expression, returns string case OP_RUN: { int index = stack[ sp-1 ].i; if ( index < 0 || index >= db->stmts_byindex_count || !db->stmts_byindex[ index ] ) { stack[ sp-1 ].s = "???"; break; } stack[ sp-1 ].s = sql_eval( db, ((formatInfo_t*)db->stmts_byindex[ index ])->print, 0, 0, 0, 0, 0, 0 ).string; size += strlen(stack[ sp-1 ].s) + 1; } break; case OP_RND: { LVALUE.i = Rand_NextInt32InRange( &db->rand, LEFT_OPERAND.i, RIGHT_OPERAND.i ); sp--; } break; #if DEVELOPER default: { Com_Error(ERR_FATAL, "invalid sql op code: '%d'.\n", op ); } break; #endif } #ifdef DEVELOPER db->ops++; #endif } ASSERT( size <= sizeof(buffer) ); // stack overflow size = top; if ( sp == 0 ) { cellInfo_t c; c.integer = 0; return c; } ASSERT( sp == 1 ); return *(cellInfo_t*)stack; }
int main(int argc, char *argv[]) { int c; char flgbuf[3], *s; const char *tmp; size_t len; if ((tmp = getenv("TMPDIR")) == NULL || (len = strlen(tmp)) == 0) { tmpdir = _PATH_TMP; } else { s = xmalloc(len + 2); (void)sprintf(s, "%s%s", tmp, tmp[len - 1] == '/' ? "" : "/"); tmpdir = s; } cppout = xmalloc(strlen(tmpdir) + sizeof ("lint0.XXXXXX")); (void)sprintf(cppout, "%slint0.XXXXXX", tmpdir); cppoutfd = mkstemp(cppout); if (cppoutfd == -1) { warn("can't make temp"); terminate(-1); } p1out = xcalloc(1, sizeof (char *)); p2in = xcalloc(1, sizeof (char *)); cflags = xcalloc(1, sizeof (char *)); lcflags = xcalloc(1, sizeof (char *)); l1flags = xcalloc(1, sizeof (char *)); l2flags = xcalloc(1, sizeof (char *)); l2libs = xcalloc(1, sizeof (char *)); deflibs = xcalloc(1, sizeof (char *)); libs = xcalloc(1, sizeof (char *)); libsrchpath = xcalloc(1, sizeof (char *)); appcstrg(&cflags, "-E"); appcstrg(&cflags, "-x"); appcstrg(&cflags, "c"); #if 0 appcstrg(&cflags, "-D__attribute__(x)="); appcstrg(&cflags, "-D__extension__(x)=/*NOSTRICT*/0"); #else appcstrg(&cflags, "-U__GNUC__"); appcstrg(&cflags, "-undef"); #endif #if 0 appcstrg(&cflags, "-Wp,-$"); #endif appcstrg(&cflags, "-Wp,-C"); appcstrg(&cflags, "-Wcomment"); appcstrg(&cflags, "-D__LINT__"); appcstrg(&cflags, "-Dlint"); /* XXX don't def. with -s */ appdef(&cflags, "lint"); appcstrg(&deflibs, "c"); if (signal(SIGHUP, terminate) == SIG_IGN) (void)signal(SIGHUP, SIG_IGN); (void)signal(SIGINT, terminate); (void)signal(SIGQUIT, terminate); (void)signal(SIGTERM, terminate); while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:M:SU:VX:")) != -1) { switch (c) { case 'a': case 'b': case 'c': case 'e': case 'g': case 'r': case 'v': case 'w': case 'z': (void)sprintf(flgbuf, "-%c", c); appcstrg(&l1flags, flgbuf); break; case 'F': Fflag = 1; /* FALLTHROUGH */ case 'u': case 'h': (void)sprintf(flgbuf, "-%c", c); appcstrg(&l1flags, flgbuf); appcstrg(&l2flags, flgbuf); break; case 'X': (void)sprintf(flgbuf, "-%c", c); appcstrg(&l1flags, flgbuf); appcstrg(&l1flags, optarg); break; case 'i': if (Cflag) usage(); iflag = 1; break; case 'n': freelst(&deflibs); break; case 'p': appcstrg(&lcflags, "-Wtraditional"); appcstrg(&lcflags, "-Wno-system-headers"); appcstrg(&l1flags, "-p"); appcstrg(&l2flags, "-p"); if (*deflibs != NULL) { freelst(&deflibs); appcstrg(&deflibs, "c"); } break; case 's': if (tflag) usage(); freelst(&lcflags); appcstrg(&lcflags, "-trigraphs"); appcstrg(&lcflags, "-Wtrigraphs"); appcstrg(&lcflags, "-pedantic"); appcstrg(&lcflags, "-D__STRICT_ANSI__"); appcstrg(&l1flags, "-s"); appcstrg(&l2flags, "-s"); sflag = 1; break; case 'S': if (tflag) usage(); appcstrg(&l1flags, "-S"); Sflag = 1; break; #if !HAVE_CONFIG_H case 't': if (sflag) usage(); freelst(&lcflags); appcstrg(&lcflags, "-traditional"); appstrg(&lcflags, concat2("-D", MACHINE)); appstrg(&lcflags, concat2("-D", MACHINE_ARCH)); appcstrg(&l1flags, "-t"); appcstrg(&l2flags, "-t"); tflag = 1; break; #endif case 'x': appcstrg(&l2flags, "-x"); break; case 'C': if (Cflag || oflag || iflag) usage(); Cflag = 1; appstrg(&l2flags, concat2("-C", optarg)); p2out = xmalloc(sizeof ("llib-l.ln") + strlen(optarg)); (void)sprintf(p2out, "llib-l%s.ln", optarg); freelst(&deflibs); break; case 'd': if (dflag) usage(); dflag = 1; appcstrg(&cflags, "-nostdinc"); appcstrg(&cflags, "-idirafter"); appcstrg(&cflags, optarg); break; case 'D': case 'I': case 'M': case 'U': (void)sprintf(flgbuf, "-%c", c); appstrg(&cflags, concat2(flgbuf, optarg)); break; case 'l': appcstrg(&libs, optarg); break; case 'o': if (Cflag || oflag) usage(); oflag = 1; outputfn = xstrdup(optarg); break; case 'L': appcstrg(&libsrchpath, optarg); break; case 'H': appcstrg(&l2flags, "-H"); break; case 'B': Bflag = 1; libexec_path = xstrdup(optarg); break; case 'V': Vflag = 1; break; default: usage(); /* NOTREACHED */ } } argc -= optind; argv += optind; /* * To avoid modifying getopt(3)'s state engine midstream, we * explicitly accept just a few options after the first source file. * * In particular, only -l<lib> and -L<libdir> (and these with a space * after -l or -L) are allowed. */ while (argc > 0) { const char *arg = argv[0]; if (arg[0] == '-') { char ***list; /* option */ switch (arg[1]) { case 'l': list = &libs; break; case 'L': list = &libsrchpath; break; default: usage(); /* NOTREACHED */ } if (arg[2]) appcstrg(list, arg + 2); else if (argc > 1) { argc--; appcstrg(list, *++argv); } else usage(); } else { /* filename */ fname(arg); first = 0; } argc--; argv++; } if (first) usage(); if (iflag) terminate(0); if (!oflag) { if ((tmp = getenv("LIBDIR")) == NULL || strlen(tmp) == 0) tmp = PATH_LINTLIB; appcstrg(&libsrchpath, tmp); findlibs(libs); findlibs(deflibs); } (void)printf("Lint pass2:\n"); lint2(); if (oflag) cat(p2in, outputfn); if (Cflag) p2out = NULL; terminate(0); /* NOTREACHED */ }
static void compute_file_name_parts (void) { const char *base, *tab, *ext; /* Compute ALL_BUT_EXT and ALL_BUT_TAB_EXT from SPEC_OUTFILE or GRAMMAR_FILE. The precise -o name will be used for FTABLE. For other output files, remove the ".c" or ".tab.c" suffix. */ if (spec_outfile) { file_name_split (spec_outfile, &base, &tab, &ext); dir_prefix = xstrndup (spec_outfile, base - spec_outfile); /* ALL_BUT_EXT goes up the EXT, excluding it. */ all_but_ext = xstrndup (spec_outfile, (strlen (spec_outfile) - (ext ? strlen (ext) : 0))); /* ALL_BUT_TAB_EXT goes up to TAB, excluding it. */ all_but_tab_ext = xstrndup (spec_outfile, (strlen (spec_outfile) - (tab ? strlen (tab) : (ext ? strlen (ext) : 0)))); if (ext) compute_exts_from_src (ext); } else { file_name_split (grammar_file, &base, &tab, &ext); if (spec_file_prefix) { /* If --file-prefix=foo was specified, ALL_BUT_TAB_EXT = `foo'. */ dir_prefix = xstrndup (grammar_file, base - grammar_file); all_but_tab_ext = xstrdup (spec_file_prefix); } else if (yacc_flag) { /* If --yacc, then the output is `y.tab.c'. */ dir_prefix = ""; all_but_tab_ext = "y"; } else { /* Otherwise, ALL_BUT_TAB_EXT is computed from the input grammar: `foo/bar.yy' => `bar'. */ dir_prefix = ""; all_but_tab_ext = xstrndup (base, (strlen (base) - (ext ? strlen (ext) : 0))); } all_but_ext = concat2 (all_but_tab_ext, TAB_EXT); /* Compute the extensions from the grammar file name. */ if (ext && !yacc_flag) compute_exts_from_gf (ext); } }
static void single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *skp_v) { Lisp_Object map, item_string, enabled; struct gcpro gcpro1, gcpro2; bool res; struct skp *skp = skp_v; /* Parse the menu item and leave the result in item_properties. */ GCPRO2 (key, item); res = parse_menu_item (item, 0); UNGCPRO; if (!res) return; /* Not a menu item. */ map = AREF (item_properties, ITEM_PROPERTY_MAP); enabled = AREF (item_properties, ITEM_PROPERTY_ENABLE); item_string = AREF (item_properties, ITEM_PROPERTY_NAME); if (!NILP (map) && SREF (item_string, 0) == '@') { if (!NILP (enabled)) /* An enabled separate pane. Remember this to handle it later. */ skp->pending_maps = Fcons (Fcons (map, Fcons (item_string, key)), skp->pending_maps); return; } /* Simulate radio buttons and toggle boxes by putting a prefix in front of them. */ if (!have_boxes ()) { char const *prefix = 0; Lisp_Object type = AREF (item_properties, ITEM_PROPERTY_TYPE); if (!NILP (type)) { Lisp_Object selected = AREF (item_properties, ITEM_PROPERTY_SELECTED); if (skp->notbuttons) /* The first button. Line up previous items in this menu. */ { int idx = skp->notbuttons; /* Index for first item this menu. */ int submenu = 0; Lisp_Object tem; while (idx < menu_items_used) { tem = AREF (menu_items, idx + MENU_ITEMS_ITEM_NAME); if (NILP (tem)) { idx++; submenu++; /* Skip sub menu. */ } else if (EQ (tem, Qlambda)) { idx++; submenu--; /* End sub menu. */ } else if (EQ (tem, Qt)) idx += 3; /* Skip new pane marker. */ else if (EQ (tem, Qquote)) idx++; /* Skip a left, right divider. */ else { if (!submenu && SREF (tem, 0) != '\0' && SREF (tem, 0) != '-') ASET (menu_items, idx + MENU_ITEMS_ITEM_NAME, concat2 (SCOPED_STRING (" "), tem)); idx += MENU_ITEMS_ITEM_LENGTH; } } skp->notbuttons = 0; } /* Calculate prefix, if any, for this item. */ if (EQ (type, QCtoggle)) prefix = NILP (selected) ? "[ ] " : "[X] "; else if (EQ (type, QCradio)) prefix = NILP (selected) ? "( ) " : "(*) "; } /* Not a button. If we have earlier buttons, then we need a prefix. */ else if (!skp->notbuttons && SREF (item_string, 0) != '\0' && SREF (item_string, 0) != '-') prefix = " "; if (prefix) item_string = concat2 (SCOPED_STRING (prefix), item_string); } if ((FRAME_TERMCAP_P (XFRAME (Vmenu_updating_frame)) || FRAME_MSDOS_P (XFRAME (Vmenu_updating_frame))) && !NILP (map)) /* Indicate visually that this is a submenu. */ item_string = concat2 (item_string, SCOPED_STRING (" >")); push_menu_item (item_string, enabled, key, AREF (item_properties, ITEM_PROPERTY_DEF), AREF (item_properties, ITEM_PROPERTY_KEYEQ), AREF (item_properties, ITEM_PROPERTY_TYPE), AREF (item_properties, ITEM_PROPERTY_SELECTED), AREF (item_properties, ITEM_PROPERTY_HELP)); #if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI) /* Display a submenu using the toolkit. */ if (FRAME_WINDOW_P (XFRAME (Vmenu_updating_frame)) && ! (NILP (map) || NILP (enabled))) { push_submenu_start (); single_keymap_panes (map, Qnil, key, skp->maxdepth - 1); push_submenu_end (); } #endif }
static Token next_token (void) { Token token; restart: outbuffer_off(); outbuffer_on(); token.startindex = out.buffindex; { int c = next_char(); switch (c) { case EOF: /* EOF */ token.type = eof; goto done; case ' ': case '\v': case '\t': case '\n': /* whitespace, ignore */ goto restart; case '\\': if (peek_char()=='\n') { /* backslash newline, ignore */ next_char(); goto restart; } goto separator; case '/': if (peek_char() == '*') { /* Comment */ next_char(); while (1) { c = next_char(); if (c==EOF) { fprintf(stderr,"Unfinished comment\n"); break; } if ((c=='*') && (peek_char()=='/')) { next_char(); break; } } goto restart; } goto separator; case '*': if (peek_char() == '/') fprintf(stderr,"End of comment outside comment in line %lu\n",input_line); goto separator; case '#': /* preprocessor directive */ { char* line = next_line(); if (line) { char* old_line = line; line = concat2("#",line); xfree(old_line); } else line = concat1("#"); while (line[strlen(line)-1] == '\\') { char* continuation_line = next_line(); line[strlen(line)-1] = '\0'; if (continuation_line) { char* old_line = line; line = concat2(line,continuation_line); xfree(old_line); xfree(continuation_line); } } { const char* condition; long line_directive; if ((condition = is_if(line)) != NULL) { do_if(condition); } else if (is_else(line)) { do_else(); line_repeat_else(); } else if ((condition = is_elif(line)) != NULL) { do_elif(condition); line_repeat_else(); } else if (is_endif(line)) { do_endif(); line_repeat_endif(); } else if ((line_directive = decode_line_directive(line)) >= 0) input_line = line_directive; #ifdef SPLIT_OBJECT_INITIALIZATIONS else { /* Replace "var object foo = ..." with "var object foo; foo = ..." in macros as well. */ if (out.buffindex < MAXHEADERLEN) { uintB* p; out.buffer[out.buffindex] = '\0'; for (p = &out.buffer[token.startindex]; ; p++) { p = (uintB*) strstr((char*)p,"var "); if (p == NULL) break; if ((strncmp((char*)p,"var object ", strlen("var object "))==0 || strncmp((char*)p,"var chart ", strlen("var chart "))==0) && (p[-1] == ' ' || p[-1] == '{')) { if (strncmp((char*)p,"var object ", strlen("var object "))==0) p += strlen("var object "); else if (strncmp((char*)p,"var chart ", strlen("var chart "))==0) p += strlen("var chart "); { uintB* q = p; if ((*q >= 'A' && *q <= 'Z') || (*q >= 'a' && *q <= 'z') || *q == '_') { do q++; while ((*q >= 'A' && *q <= 'Z') || (*q >= 'a' && *q <= 'z') || (*q >= '0' && *q <= '9') || *q == '_'); while (*q == ' ') q++; if (*q == '=') { uintL insertlen = 2+(q-p); if (out.buffindex + insertlen < MAXHEADERLEN) { memmove(q+insertlen,q, &out.buffer[out.buffindex]-q+1); q[0] = ';'; q[1] = ' '; memcpy(q+2, p, q-p); out.buffindex += insertlen; } } } } } } } } #endif } xfree(line); } goto separator; case '.': c = peek_char(); if (!(((c>='0') && (c<='9')) || (c=='.'))) goto separator; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': /* Digit. Continue reading as long as alphanumeric or '.'. */ while (1) { c = peek_char(); if (((c>='0') && (c<='9')) || ((c>='A') && (c<='Z')) || ((c>='a') && (c<='z')) || (c=='.')) next_char(); else break; } token.type = number; goto done; case '\'': /* Character constant */ while (1) { c = next_char(); if (c==EOF) { fprintf(stderr,"Unterminated character constant\n"); break; } if (c=='\'') break; if (c=='\\') c = next_char(); } token.type = charconst; goto done; case '\"': /* String constant */ while (1) { c = next_char(); if (c==EOF) { fprintf(stderr,"Unterminated string constant\n"); break; } if (c=='\"') break; if (c=='\\') c = next_char(); } token.type = stringconst; goto done; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': case '_': /* Identifier. */ while (1) { c = peek_char(); if (((c>='0') && (c<='9')) || ((c>='A') && (c<='Z')) || ((c>='a') && (c<='z')) || (c=='_')) next_char(); else break; } token.type = ident; goto done; default: separator: token.type = sep; token.ch = c; goto done; } } done: token.endindex = out.buffindex; return token; }