/* \brief crc calculation */ static unsigned long calcCRC (HANDLE_CRC hCrcBuf, unsigned long bValue, int nBits) { int i; unsigned long bMask = (1UL << (nBits - 1)); FLC_sub_start("calcCRC"); ADD(1); SHIFT(1); /* counting previous operations */ LOOP(1); for (i = 0; i < nBits; i++, bMask >>= 1) { unsigned short flag = (hCrcBuf->crcState & hCrcBuf->crcMask) ? 1 : 0; unsigned short flag1 = (bMask & bValue) ? 1 : 0; INDIRECT(2); ADD(2); LOGIC(2); BRANCH(2); MOVE(2); /* counting previous operations */ LOGIC(1); flag ^= flag1; SHIFT(1); STORE(1); hCrcBuf->crcState <<= 1; BRANCH(1); if (flag) { INDIRECT(1); LOGIC(1); STORE(1); hCrcBuf->crcState ^= hCrcBuf->crcPoly; } } FLC_sub_end(); return (hCrcBuf->crcState); }
unsigned char ReadADC(unsigned char sens) { unsigned char data; switch(sens) { case FLOW: // Select temp pin. ADMUX |= SHIFT(MUX0); break; case TEMP: // Select flow pin. ADMUX &= ~SHIFT(MUX0); break; } // Start dummy conversion. ADCSRA |= SHIFT(ADSC); // Wait for conversion to finish. while(!(ADCSRA & SHIFT(ADIF))) {} // Start actual conversion. ADCSRA |= SHIFT(ADSC); // Wait for conversion to finish. while(!(ADCSRA & SHIFT(ADIF))) {} data = ADCH; return data; }
/* Description: Initialises the teensy, SPI module, transceiver and ADC module. */ void Init() { // Set inputs. DDRD |= SHIFT(DDD1) | SHIFT(NIRQ); PORTD |= SHIFT(PORTD1) | SHIFT(NIRQ); InitADC(); InitSPI(); InitAlpha(); }
int echo(int argc, char* argv[], GString* output) { if (SHIFT(argc, argv)) { // if there still is an argument g_string_append(output, argv[0]); while (SHIFT(argc, argv)) { g_string_append_c(output, ' '); g_string_append(output, argv[0]); } } g_string_append_c(output, '\n'); return 0; }
int vfc_i2c_xmit_addr(struct vfc_dev *dev, unsigned char addr, char mode) { int ret, raddr; #if 1 WRITE_S1(SEND_I2C_STOP | ACK); WRITE_S1(SELECT(S0) | ENABLE_SERIAL); vfc_i2c_delay(dev); #endif switch(mode) { case VFC_I2C_READ: raddr = SHIFT(((unsigned int)addr | 0x1)); WRITE_REG(raddr); VFC_I2C_DEBUG_PRINTK(("vfc%d: receiving from i2c addr 0x%x\n", dev->instance, addr | 0x1)); break; case VFC_I2C_WRITE: raddr = SHIFT((unsigned int)addr & ~0x1); WRITE_REG(raddr); VFC_I2C_DEBUG_PRINTK(("vfc%d: sending to i2c addr 0x%x\n", dev->instance, addr & ~0x1)); break; default: return -EINVAL; }; WRITE_S1(SEND_I2C_START); vfc_i2c_delay(dev); ret = vfc_i2c_wait_for_pin(dev,VFC_I2C_ACK_CHECK); /* We wait for the i2c send to finish here but Sun doesn't, hmm */ if (ret) { printk(KERN_ERR "vfc%d: VFC xmit addr timed out or no ack\n", dev->instance); return ret; } else if (mode == VFC_I2C_READ) { if ((ret = sbus_readl(&dev->regs->i2c_reg) & 0xff000000) != raddr) { printk(KERN_WARNING "vfc%d: returned slave address " "mismatch(%x,%x)\n", dev->instance, raddr, ret); } } return 0; }
static void initThrQuiet(int numPb, int *pbOffset, float *pbBarcVal, float *pbThresholdQuiet) { int i; float barcThrQuiet; COUNT_sub_start("initThrQuiet"); PTR_INIT(1); /* pbBarcVal[] pbThresholdQuiet[] pbOffset[] */ LOOP(1); for(i=0; i<numPb; i++) { /* because one pb equals a sfb in psych it's better to use the minimum of the bark-wise threshold in quiet */ int bv1, bv2; BRANCH(1); if (i>0) { ADD(1); SHIFT(1); bv1 = (int)(pbBarcVal[i] + pbBarcVal[i-1])>>1; } else {
void recv_command(struct ev_loop *loop, struct ev_io *io, int rev) { ADEBUG(!(rev & EV_ERROR)); void *sock = SHIFT(io, config_zmqsocket_t, _watch)->_sock; while(TRUE) { Z_SEQ_INIT(msg, sock); Z_RECV_START(msg, break); size_t len; while(TRUE) { len = zmq_msg_size(&msg); REPLY_COMMAND(sock, msg, TRUE); if(!len) break; Z_RECV_NEXT(msg); } Z_RECV(msg); len = zmq_msg_size(&msg); char *data = zmq_msg_data(&msg); LDEBUG("Got command `%.*s`", len, data); if COMMAND(list_commands) { // Keep alphabetically sorted REPLY_SHORT(sock, msg, "list_commands", TRUE); REPLY_SHORT(sock, msg, "pause_websockets", TRUE); REPLY_SHORT(sock, msg, "resume_websockets", TRUE); REPLY_SHORT(sock, msg, "sync_now", TRUE); REPLY_SHORT(sock, msg, "reopen_logs", FALSE); } else if COMMAND(pause_websockets) { LWARN("Pausing websockets because of command"); pause_websockets(TRUE); REPLY_SHORT(sock, msg, "paused", FALSE); } else if COMMAND(resume_websockets) {
void recv_command(struct ev_loop *loop, struct ev_io *io, int rev) { ADEBUG(!(rev & EV_ERROR)); void *sock = SHIFT(io, config_zmqsocket_t, _watch)->_sock; while(TRUE) { Z_SEQ_INIT(msg, sock); Z_RECV_START(msg, break); size_t len; while(TRUE) { len = zmq_msg_size(&msg); REPLY_COMMAND(sock, msg, TRUE); if(!len) break; Z_RECV(msg); } Z_RECV(msg); len = zmq_msg_size(&msg); char *data = zmq_msg_data(&msg); LDEBUG("Got command `%.*s`", len, data); if COMMAND(list_commands) { // Keep alphabetically sorted REPLY_SHORT(sock, msg, "get_statistics", TRUE); REPLY_SHORT(sock, msg, "list_commands", TRUE); REPLY_SHORT(sock, msg, "pause_websockets", TRUE); REPLY_SHORT(sock, msg, "resume_websockets", FALSE); } else if COMMAND(get_statistics) { char buf[4096]; len = format_statistics(buf); SNIMPL(zmq_msg_init_size(&msg, len)); memcpy(zmq_msg_data(&msg), buf, len); REPLY_COMMAND(sock, msg, FALSE); } else if COMMAND(pause_websockets) {
gboolean on_entry_key_press_event(GtkEntry *entry, GdkEvent *event) { guint k = GDK_KEY_VoidSymbol; gdk_event_get_keyval(event, &k); GdkModifierType s; gdk_event_get_state(event, &s); #define KEY(S) (k == S) #define CTRL(S) (KEY(S) && s & GDK_CONTROL_MASK) #define SHIFT(S) (KEY(S) && s & GDK_SHIFT_MASK) if (KEY(GDK_KEY_Escape) || CTRL(GDK_KEY_c)) gtk_main_quit(); else if (KEY(GDK_KEY_Tab) || CTRL(GDK_KEY_i)) gtk_entry_set_text(entry, row_text(selected_row())); else if (KEY(GDK_KEY_Down) || CTRL(GDK_KEY_f)) select_row(selected_row() + 1); else if (KEY(GDK_KEY_Up) || CTRL(GDK_KEY_b)) select_row(selected_row() - 1); else if (KEY(GDK_KEY_Return) || CTRL(GDK_KEY_j)) output(row_text(selected_row())); else if (SHIFT(GDK_KEY_Return) || CTRL(GDK_KEY_J)) output(entry_text()); return FALSE; }
int ncss_files(int argc, char *argv[]) { int result = 0; int lines = 0, nclines = 0; int nfiles = argc - 1; if (Verbose) puts(" CSL PCT NCSL PCT TOTAL FILENAME"); if (argc == 1) { ncss_file("stdin", stdin, &lines, &nclines); } else { while (argc > 1) { FILE *f; if ((f = fopen(argv[1], "r")) == NULL) { result = 2; perror(argv[1]); } else { ncss_file(argv[1], f, &lines, &nclines); fclose(f); } SHIFT(1); } } if (Totals) { if (lines != 0) { int pct_csl = (int)(0.4999999 + 100.0 * (lines - nclines) / lines); printf("%6d%4d%6d%4d%7d (total files: %d)\n", lines - nclines, pct_csl, nclines, 100 - pct_csl, lines, nfiles); } else { printf("%6d n/a%6d n/a%7d (total files: %d)\n", lines - nclines, nclines, lines, nfiles); } } return result; }
int decomment_files(int argc, char *argv[]) { int result = 0; if (argc == 1) { decomment_file("stdin", stdin); } else { while (argc > 1) { FILE *f; if ((f = fopen(argv[1], "r")) == NULL) { result = 2; perror(argv[1]); } else { decomment_file(argv[1], f); fclose(f); } SHIFT(1); } } return result; }
int silent_command(int argc, char* argv[]) { if (argc <= 1) { return HERBST_NEED_MORE_ARGS; } (void)SHIFT(argc, argv); return call_command_no_output(argc, argv); }
/* \brief Reads n bits from Bitbuffer \return bits */ unsigned long getbits (HANDLE_BIT_BUFFER hBitBuf, int n) { unsigned long ret_value = 0; assert(n <= 32); FLC_sub_start("getbits"); MOVE(1); /* counting previous operation */ LOOP(1); while (n>8) { ADD(1); n -= 8; FUNC(2); SHIFT(1); ADD(1); ret_value += getbits(hBitBuf,8) << n; } INDIRECT(1); ADD(1); BRANCH(1); if (hBitBuf->buffered_bits <= 8) { INDIRECT(2); SHIFT(1); LOGIC(1); STORE(1); hBitBuf->buffer_word = (hBitBuf->buffer_word << 8) | *hBitBuf->char_ptr++; ADD(1); STORE(1); hBitBuf->buffered_bits += 8; } ADD(1); STORE(1); hBitBuf->buffered_bits -= n; SHIFT(2); ADD(2); LOGIC(1); ret_value += (hBitBuf->buffer_word >> hBitBuf->buffered_bits) & ((1 << n) - 1); INDIRECT(1); ADD(1); STORE(1); hBitBuf->nrBitsRead += n; FLC_sub_end(); return (ret_value); }
int try_command(int argc, char* argv[], GString* output) { if (argc <= 1) { return HERBST_NEED_MORE_ARGS; } (void)SHIFT(argc, argv); call_command(argc, argv, output); return 0; }
void ResetISR(void) { uint32_t i; // real men don't need to initialize variables for (;; i ++) { LED_PORT->FIODIR = LED_MASK; // makes the code longer when placed before the loop LED_PORT->FIOPIN = SHIFT(i); } }
void InitADC() { DIDR0 |= SHIFT(PF0) | SHIFT(PF1); ADMUX |= SHIFT(REFS0) | SHIFT(ADLAR); //Set MUX values to 000000 or 000001. ADCSRA |= SHIFT(ADEN) | SHIFT(ADPS0); //ADSC for each conversion. }
int substitute_command(int argc, char* argv[], GString* output) { // usage: substitute identifier attribute command [args ...] // 0 1 2 3 if (argc < 4) { return HERBST_NEED_MORE_ARGS; } char* identifier = argv[1]; HSAttribute* attribute = hsattribute_parse_path_verbose(argv[2], output); if (!attribute) { return HERBST_INVALID_ARGUMENT; } GString* attribute_string = hsattribute_to_string(attribute); char* repl = attribute_string->str; (void) SHIFT(argc, argv); // remove command name (void) SHIFT(argc, argv); // remove identifier (void) SHIFT(argc, argv); // remove attribute int status = call_command_substitute(identifier, repl, argc, argv, output); g_string_free(attribute_string, true); return status; }
int main(void) { unsigned int w1 = 0177777u, w2 = 0444u; unsigned int shift(unsigned int value, int n); SHIFT(w1, 5) printf("%o\t", w1); w1 = 0177777u; printf("%o\n", w1 << 5); SHIFT(w1, -6) printf("%o\t", w1); w1 = 0177777u; printf("%o\n", w1 >> 6); SHIFT(w2, 0) printf("%o\t", w2); w2 = 0444u; printf("%o\n", w2 >> 0); SHIFT(w1, -3) SHIFT(w1, 3) printf("%o\n", w1); return 0; }
static int filter(struct af_instance *af, struct mp_audio *data) { if (!data) return 0; struct mp_audio *out = mp_audio_pool_get(af->out_pool, af->data, data->samples); if (!out) { talloc_free(data); return -1; } mp_audio_copy_attributes(out, data); size_t len = mp_audio_psize(data) / data->bps; if (data->bps == 4) { for (int s = 0; s < len; s++) { uint32_t val = *((uint32_t *)data->planes[0] + s); uint8_t *ptr = (uint8_t *)out->planes[0] + s * 3; ptr[0] = val >> SHIFT(0); ptr[1] = val >> SHIFT(1); ptr[2] = val >> SHIFT(2); } } else { for (int s = 0; s < len; s++) {
static __inline__ int in_cksum_internal(struct mbuf *m, int off, int len, u_int sum) { u_char *w; int mlen; int byte_swapped = 0; for (; m && len; m = m->m_next) { if (m->m_len == 0) continue; w = mtod(m, u_char *) + off; mlen = m->m_len - off; off = 0; if (len < mlen) mlen = len; len -= mlen; if ((long)w & 1) { REDUCE; ADDB; SHIFT(1); } while (mlen >= 2) { ADDS; SHIFT(2); } REDUCE; if (mlen == 1) ADDB; } if (byte_swapped) { REDUCE; ROL; } ADDCARRY; return (0xffff ^ sum); }
int settings_cycle_value(int argc, char** argv, GString* output) { if (argc < 3) { return HERBST_NEED_MORE_ARGS; } char* cmd_name = argv[0]; char* setting_name = argv[1]; // save this before shifting SettingsPair* pair = settings_find(argv[1]); if (!pair) { g_string_append_printf(output, "%s: Setting \"%s\" not found\n", argv[0], argv[1]); return HERBST_SETTING_NOT_FOUND; } (void)SHIFT(argc, argv); (void)SHIFT(argc, argv); char** pcurrent = (char**)table_find(argv, sizeof(*argv), argc, 0, memberequals_settingspair, pair); int i = pcurrent ? ((INDEX_OF(argv, pcurrent) + 1) % argc) : 0; int ret = settings_set(pair, argv[i]); if (ret == HERBST_INVALID_ARGUMENT) { g_string_append_printf(output, "%s: Invalid value for setting \"%s\"\n", cmd_name, setting_name); } return ret; }
int vfc_i2c_xmit_byte(struct vfc_dev *dev,unsigned char *byte) { int ret; u32 val = SHIFT((unsigned int)*byte); WRITE_REG(val); ret = vfc_i2c_wait_for_pin(dev, VFC_I2C_ACK_CHECK); switch(ret) { case -ETIMEDOUT: printk(KERN_ERR "vfc%d: VFC xmit byte timed out or no ack\n", dev->instance); break; case -EIO: ret = XMIT_LAST_BYTE; break; default: break; }; return ret; }
int IIR32Resample( float *inbuf, float *outbuf, int inSamples, int outSamples, int stride) { int i, k, s, ch, r; double accu; float scratch[IIR_INTERNAL_BUFSIZE]; int nProcessRuns = outSamples >> 1; COUNT_sub_start("IIR32Resample"); SHIFT(1); /* counting previous operation */ assert( stride <= IIR_CHANNELS); LOOP(1); for (ch=0; ch<stride; ch++) { int idxIn = ch; int idxOut = ch; MOVE(2); /* counting previous operations */ PTR_INIT(2); /* scratch[s] statesIIR[s*stride+ch] */ LOOP(1); for (s=0; s<IIR_32_ORDER; s++) { MOVE(1); scratch[s] = statesIIR[s*stride+ch]; } LOOP(1); for (r=0; r<nProcessRuns; r++) { PTR_INIT(1); /* scratch[s] */ MOVE(1); s=IIR_32_ORDER; PTR_INIT(2); /* inbuf[idxIn] outbuf[idxOut] */ LOOP(1); for (i=0; i<IIR_DOWNSAMPLE_FAC; i++) { MOVE(1); accu = inbuf[idxIn]; PTR_INIT(2); /* coeffDen[k] scratch[s-k] */ LOOP(1); for (k=1; k<IIR_32_ORDER; k++) { MAC(1); accu += coeffDen[k] * scratch[s-k]; } MOVE(1); scratch[s] = (float) accu; s++; assert( s<=IIR_INTERNAL_BUFSIZE); MOVE(1); accu = 0.0; PTR_INIT(2); /* coeffDen[k] scratch[s-k] */ LOOP(1); for (k=1; k<IIR_32_ORDER; k++) { MAC(1); accu += coeffDen[k] * scratch[s-k]; } MOVE(1); scratch[s] = (float) accu; s++; idxIn += stride; } PTR_INIT(1); /* scratch[s] */ MOVE(1); s = IIR_32_ORDER; LOOP(1); for (i=0; i<IIR_UPSAMPLE_FAC; i++) { MULT(1); accu = coeffNum[0] * scratch[s]; PTR_INIT(2); /* coeffNum[k] scratch[s-k] */ LOOP(1); for (k=1; k<IIR_32_ORDER; k++) { MAC(1); accu += coeffNum[k] * scratch[s-k]; } MOVE(1); outbuf[idxOut] = (float) accu; assert( s<=IIR_INTERNAL_BUFSIZE); s += IIR_DOWNSAMPLE_FAC; idxOut += stride; } FUNC(2); LOOP(1); PTR_INIT(2); MOVE(1); STORE(IIR_32_ORDER); memmove( &scratch[0], &scratch[IIR_UPSAMPLE_FAC*IIR_DOWNSAMPLE_FAC], IIR_32_ORDER*sizeof(float)); } PTR_INIT(2); /* statesIIR[s*stride+ch] scratch[s] */ LOOP(1); for (s=0; s<IIR_32_ORDER; s++) { MOVE(1); statesIIR[s*stride+ch] = scratch[s]; } assert(idxIn/stride <= inSamples); } /* ch */ MULT(1); /* counting post-operation */ COUNT_sub_end(); return outSamples * stride; }
void handler_src_dst_ip_input_process_nodes(GTree *tree, data_record_t *data, guint len) { // loop through all received entries data_record_t *curr_record; guint i, num_entries = len / sizeof(data_record_t); for (i = 0; i < num_entries; ++i) { curr_record = (data_record_t *) data + i; // allocate mem for a new node tree_node_t *node = g_new0(tree_node_t, 1); // assign the node's vars node->src_dst_ip.src_addr.s_addr = curr_record->address; node->src_dst_ip.dst_addr.s_addr = curr_record->dstaddr; node->src_dst_ip.src_network_bits = g_ntohl(curr_record->length); node->src_dst_ip.dst_network_bits = g_ntohl(curr_record->dstlen); node->src_dst_ip.src_origin_as = g_ntohl(curr_record->originas); node->src_dst_ip.dst_origin_as = g_ntohl(curr_record->dstoriginas); node->volume = g_ntohl(curr_record->count); // assign our RGB colors of the node as specified by the server node->src_dst_ip.src_coords.color[0] = curr_record->red; node->src_dst_ip.src_coords.color[1] = curr_record->green; node->src_dst_ip.src_coords.color[2] = curr_record->blue; node->src_dst_ip.dst_coords.color[0] = curr_record->red2; node->src_dst_ip.dst_coords.color[1] = curr_record->green2; node->src_dst_ip.dst_coords.color[2] = curr_record->blue2; // calculate the transparency of the node based on its network bits node->src_dst_ip.src_coords.color[3] = 255 - ((24 - node->src_dst_ip.src_network_bits) * 10); node->src_dst_ip.dst_coords.color[3] = 255 - ((24 - node->src_dst_ip.dst_network_bits) * 10); // calculate the quadtree coordinates node->src_dst_ip.src_coords.y_coord = 0.0; node->src_dst_ip.src_coords.z_coord = 0.0; node->src_dst_ip.dst_coords.y_coord = 0.0; node->src_dst_ip.dst_coords.z_coord = 0.0; // calculate width of the src/dst node guint src_num_of_quad_divisions = (node->src_dst_ip.src_network_bits + 1) / 2; guint dst_num_of_quad_divisions = (node->src_dst_ip.dst_network_bits + 1) / 2; GLfloat src_node_x_width = COORD_SIZE / (pow(2.0, src_num_of_quad_divisions)); GLfloat src_node_y_width = COORD_SIZE / (pow(2.0, src_num_of_quad_divisions)); GLfloat dst_node_x_width = COORD_SIZE / (pow(2.0, dst_num_of_quad_divisions)); GLfloat dst_node_y_width = COORD_SIZE / (pow(2.0, dst_num_of_quad_divisions)); // loop to find the coordinates where our quadtree begins for our src_address gboolean ignore_last = FALSE; guint i, loops = (node->src_dst_ip.src_network_bits + 1) / 2; GLfloat adjustment = COORD_SIZE; for (i = 0; i < loops; ++i) { adjustment /= 2.0; // if its our last loop and we have an odd num of network bits, ignore the last bit and double our y_width if ((i == (loops - 1)) && (node->src_dst_ip.src_network_bits % 2 == 1)) { ignore_last = TRUE; src_node_y_width *= 2.0; } // for a COORD_SIZE x COORD_SIZE grid switch (SHIFT(node->src_dst_ip.src_addr.s_addr, ((((i/4)+1)*8) - 2*((i%4)+1)), 0x3)) { // 00 case 0: // do nothing break; // 01 case 1: if (!ignore_last) { node->src_dst_ip.src_coords.z_coord += adjustment; } break; // 10 case 2: node->src_dst_ip.src_coords.y_coord += adjustment; break; // 11 case 3: node->src_dst_ip.src_coords.y_coord += adjustment; if (!ignore_last) { node->src_dst_ip.src_coords.z_coord += adjustment; } break; } } // loop to find the coordinates where our quadtree begins for our dst_address ignore_last = FALSE; loops = (node->src_dst_ip.dst_network_bits + 1) / 2; adjustment = COORD_SIZE; for (i = 0; i < loops; ++i) { adjustment /= 2.0; // if its our last loop and we have an odd num of network bits, ignore the last bit and double our y_width if ((i == (loops - 1)) && (node->src_dst_ip.dst_network_bits % 2 == 1)) { ignore_last = TRUE; dst_node_y_width *= 2.0; } // for a COORD_SIZE x COORD_SIZE grid switch (SHIFT(node->src_dst_ip.dst_addr.s_addr, ((((i/4)+1)*8) - 2*((i%4)+1)), 0x3)) { // 00 case 0: // do nothing break; // 01 case 1: if (!ignore_last) { node->src_dst_ip.dst_coords.z_coord += adjustment; } break; // 10 case 2: node->src_dst_ip.dst_coords.y_coord += adjustment; break; // 11 case 3: node->src_dst_ip.dst_coords.y_coord += adjustment; if (!ignore_last) { node->src_dst_ip.dst_coords.z_coord += adjustment; } break; } } GLfloat src_unit_size = CUBE_SIZE / (GLfloat) (viz->src_bound.max_x_coord - viz->src_bound.min_x_coord); GLfloat dst_unit_size = CUBE_SIZE / (GLfloat) (viz->dst_bound.max_x_coord - viz->dst_bound.min_x_coord); // adjust to the bounded box coords node->src_dst_ip.src_coords.y_coord -= viz->src_bound.min_x_coord; node->src_dst_ip.src_coords.z_coord -= viz->src_bound.min_y_coord; node->src_dst_ip.dst_coords.y_coord -= viz->dst_bound.min_x_coord; node->src_dst_ip.dst_coords.z_coord -= viz->dst_bound.min_y_coord; // translate src coords and dimensions onto the left side of the cube node->src_dst_ip.src_coords.y_coord = (GLfloat) (node->src_dst_ip.src_coords.y_coord * src_unit_size) - 1.0; node->src_dst_ip.src_coords.z_coord = (GLfloat) (node->src_dst_ip.src_coords.z_coord * src_unit_size) - 1.0; node->src_dst_ip.src_coords.x_width = (GLfloat) (src_node_x_width * src_unit_size); node->src_dst_ip.src_coords.y_width = (GLfloat) (src_node_y_width * src_unit_size); // translate dst coords and dimensions onto the right side of the cube node->src_dst_ip.dst_coords.y_coord = (GLfloat) (node->src_dst_ip.dst_coords.y_coord * dst_unit_size) - 1.0; node->src_dst_ip.dst_coords.z_coord = (GLfloat) (node->src_dst_ip.dst_coords.z_coord * dst_unit_size) - 1.0; node->src_dst_ip.dst_coords.x_width = (GLfloat) (dst_node_x_width * dst_unit_size); node->src_dst_ip.dst_coords.y_width = (GLfloat) (dst_node_y_width * dst_unit_size); // add the node to our GTree g_tree_insert(tree, node, NULL); } }
/* Pick one of the parameters to the function and tweak it up or down. */ static void tweak_parameters (ModeInfo *mi) { spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)]; /* If the -parameters command line option was specified, just use that all the time. */ if (static_parms && *static_parms && !!strcasecmp (static_parms, "(default)")) { unsigned long n; char dummy; if (8 == sscanf (static_parms, "%d %d %d %d %d %d %d %d %c", &cc->m[0], &cc->m[1], &cc->m[2], &cc->m[3], &cc->m[4], &cc->m[5], &cc->m[6], &cc->m[7], &dummy)) return; else if (strlen (static_parms) == 8 && 1 == sscanf (static_parms, "%lu %c", &n, &dummy)) { const char *s = static_parms; int i = 0; while (*s) cc->m[i++] = (*s++)-'0'; return; } fprintf (stderr, "%s: -parameters must be a string of 8 ints (not \"%s\")\n", progname, static_parms); exit (1); } static_parms = 0; # define SHIFT(N) do { \ int n = (N); \ cc->m[n] += cc->dm[n]; \ if (cc->m[n] <= 0) \ cc->m[n] = 0, cc->dm[n] = -cc->dm[n]; \ else if (cc->m[n] >= cc->m_max) \ cc->m[n] = cc->m_max, cc->dm[n] = -cc->dm[n]; \ } while(0) /* else if (cc->m[n] >= cc->m_max/2 && (! (random() % 3))) \ cc->m[n] = cc->m_max/2, cc->dm[n] = -cc->dm[n]; \ */ switch(random() % 8) { case 0: SHIFT(0); break; case 1: SHIFT(1); break; case 2: SHIFT(2); break; case 3: SHIFT(3); break; case 4: SHIFT(4); break; case 5: SHIFT(5); break; case 6: SHIFT(6); break; case 7: SHIFT(7); break; default: abort(); break; } # undef SHIFT #if 0 printf ("%s: state: %d %d %d %d %d %d %d %d\n", progname, cc->m[0], cc->m[1], cc->m[2], cc->m[3], cc->m[4], cc->m[5], cc->m[6], cc->m[7]); #endif }
LEX_ERROR(); } } static TSStateId ts_lex_states[STATE_COUNT] = { [0] = 1, [1] = 12, [2] = 12, }; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmissing-field-initializers" static const TSParseAction *ts_parse_actions[STATE_COUNT][SYMBOL_COUNT] = { [0] = { [sym_program] = ACTIONS(SHIFT(1)), [anon_sym_LF] = ACTIONS(SHIFT(2)), [anon_sym_CR] = ACTIONS(SHIFT(2)), [aux_sym_SLASH_BSLASHd_SLASH] = ACTIONS(SHIFT(2)), [anon_sym_DQUOTEhello_DQUOTE] = ACTIONS(SHIFT(2)), }, [1] = { [ts_builtin_sym_end] = ACTIONS(ACCEPT_INPUT()), }, [2] = { [ts_builtin_sym_end] = ACTIONS(REDUCE(sym_program, 1)), }, }; #pragma GCC diagnostic pop
namespace KStandardShortcut { struct KStandardShortcutInfo { //! The standard shortcut id. @see StandardShortcut StandardShortcut id; /** * Unique name for the given accel. The name is used to save the user * settings. It's not representable. Use description for that. * @warning NEVER EVER CHANGE IT OR TRANSLATE IT! */ const char* name; //! Context for the translation const char* translation_context; //! Localized label for user-visible display const char* description; //! The keys for this shortcut int cutDefault, cutDefault2; //! A shortcut that is created with @a cutDefault and @cutDefault2 KShortcut cut; //! If this struct is initialized. If not initialized @cut is not valid bool isInitialized; }; //! We need to remember the context to get the correct translation. #undef I18N_NOOP2 #define I18N_NOOP2(comment,x) comment, x #define CTRL(x) Qt::CTRL+Qt::Key_##x #define SHIFT(x) Qt::SHIFT+Qt::Key_##x #define CTRLSHIFT(x) Qt::CTRL+Qt::SHIFT+Qt::Key_##x #define ALT(x) Qt::ALT+Qt::Key_##x #define ALTSHIFT(x) Qt::ALT+Qt::SHIFT+Qt::Key_##x /** Array of predefined KStandardShortcutInfo objects, which cover all the "standard" accelerators. Each enum value from StandardShortcut should appear in this table. */ // STUFF WILL BREAK IF YOU DON'T READ THIS!!! // Read the comments of the big enum in kstandardshortcut.h before you change anything! static KStandardShortcutInfo g_infoStandardShortcut[] = { //Group File, {AccelNone, 0 , 0 , 0 , 0 , 0 , KShortcut(), false }, { Open , "Open" , I18N_NOOP2("@action", "Open") , CTRL(O), 0 , KShortcut(), false } , { New , "New" , I18N_NOOP2("@action", "New") , CTRL(N), 0 , KShortcut(), false } , { Close , "Close", I18N_NOOP2("@action", "Close"), CTRL(W), CTRL(Escape), KShortcut(), false } , { Save , "Save" , I18N_NOOP2("@action", "Save") , CTRL(S), 0 , KShortcut(), false } , { Print , "Print", I18N_NOOP2("@action", "Print"), CTRL(P), 0 , KShortcut(), false } , { Quit , "Quit" , I18N_NOOP2("@action", "Quit") , CTRL(Q), 0 , KShortcut(), false } , //Group Edit { Undo , "Undo" , I18N_NOOP2("@action", "Undo") , CTRL(Z) , 0 , KShortcut(), false }, { Redo , "Redo" , I18N_NOOP2("@action", "Redo") , CTRLSHIFT(Z) , 0 , KShortcut(), false }, { Cut , "Cut" , I18N_NOOP2("@action", "Cut") , CTRL(X) , SHIFT(Delete), KShortcut(), false }, { Copy , "Copy" , I18N_NOOP2("@action", "Copy") , CTRL(C) , CTRL(Insert) , KShortcut(), false }, { Paste , "Paste" , I18N_NOOP2("@action", "Paste") , CTRL(V) , SHIFT(Insert), KShortcut(), false }, { PasteSelection , "Paste Selection" , I18N_NOOP2("@action", "Paste Selection") , CTRLSHIFT(Insert), 0 , KShortcut(), false }, { SelectAll , "SelectAll" , I18N_NOOP2("@action", "Select All") , CTRL(A) , 0 , KShortcut(), false }, { Deselect , "Deselect" , I18N_NOOP2("@action", "Deselect") , CTRLSHIFT(A) , 0 , KShortcut(), false }, { DeleteWordBack , "DeleteWordBack" , I18N_NOOP2("@action", "Delete Word Backwards"), CTRL(Backspace) , 0 , KShortcut(), false }, { DeleteWordForward, "DeleteWordForward", I18N_NOOP2("@action", "Delete Word Forward") , CTRL(Delete) , 0 , KShortcut(), false }, { Find , "Find" , I18N_NOOP2("@action", "Find") , CTRL(F) , 0 , KShortcut(), false }, { FindNext , "FindNext" , I18N_NOOP2("@action", "Find Next") , Qt::Key_F3 , 0 , KShortcut(), false }, { FindPrev , "FindPrev" , I18N_NOOP2("@action", "Find Prev") , SHIFT(F3) , 0 , KShortcut(), false }, { Replace , "Replace" , I18N_NOOP2("@action", "Replace") , CTRL(R) , 0 , KShortcut(), false }, //Group Navigation { Home , "Home" , I18N_NOOP2("@action Go to main page" , "Home") , ALT(Home) , Qt::Key_HomePage , KShortcut(), false }, { Begin , "Begin" , I18N_NOOP2("@action Beginning of document", "Begin") , CTRL(Home) , 0 , KShortcut(), false }, { End , "End" , I18N_NOOP2("@action End of document" , "End") , CTRL(End) , 0 , KShortcut(), false }, { Prior , "Prior" , I18N_NOOP2("@action" , "Prior") , Qt::Key_PageUp , 0 , KShortcut(), false }, { Next , "Next" , I18N_NOOP2("@action Opposite to Prior" , "Next") , Qt::Key_PageDown, 0 , KShortcut(), false }, { Up , "Up" , I18N_NOOP2("@action" , "Up") , ALT(Up) , 0 , KShortcut(), false }, { Back , "Back" , I18N_NOOP2("@action" , "Back") , ALT(Left) , Qt::Key_Back , KShortcut(), false }, { Forward , "Forward" , I18N_NOOP2("@action" , "Forward") , ALT(Right) , Qt::Key_Forward , KShortcut(), false }, { Reload , "Reload" , I18N_NOOP2("@action" , "Reload") , Qt::Key_F5 , Qt::Key_Refresh , KShortcut(), false }, { BeginningOfLine, "BeginningOfLine" , I18N_NOOP2("@action" , "Beginning of Line") , Qt::Key_Home , 0 , KShortcut(), false }, { EndOfLine , "EndOfLine" , I18N_NOOP2("@action" , "End of Line") , Qt::Key_End , 0 , KShortcut(), false }, { GotoLine , "GotoLine" , I18N_NOOP2("@action" , "Go to Line") , CTRL(G) , 0 , KShortcut(), false }, { BackwardWord , "BackwardWord" , I18N_NOOP2("@action" , "Backward Word") , CTRL(Left) , 0 , KShortcut(), false }, { ForwardWord , "ForwardWord" , I18N_NOOP2("@action" , "Forward Word") , CTRL(Right) , 0 , KShortcut(), false }, { AddBookmark , "AddBookmark" , I18N_NOOP2("@action" , "Add Bookmark") , CTRL(B) , 0 , KShortcut(), false }, { ZoomIn , "ZoomIn" , I18N_NOOP2("@action" , "Zoom In") , CTRL(Plus) , CTRL(Equal) , KShortcut(), false }, { ZoomOut , "ZoomOut" , I18N_NOOP2("@action" , "Zoom Out") , CTRL(Minus) , 0 , KShortcut(), false }, { FullScreen , "FullScreen" , I18N_NOOP2("@action" , "Full Screen Mode") , CTRLSHIFT(F) , 0 , KShortcut(), false }, { ShowMenubar , "ShowMenubar" , I18N_NOOP2("@action" , "Show Menu Bar") , CTRL(M) , 0 , KShortcut(), false }, { TabNext , "Activate Next Tab" , I18N_NOOP2("@action" , "Activate Next Tab") , CTRL(Period) , CTRL(BracketRight), KShortcut(), false }, { TabPrev , "Activate Previous Tab", I18N_NOOP2("@action" , "Activate Previous Tab"), CTRL(Comma) , CTRL(BracketLeft) , KShortcut(), false }, //Group Help { Help , "Help" , I18N_NOOP2("@action" , "Help") , Qt::Key_F1 , 0 , KShortcut(), false }, { WhatsThis , "WhatsThis" , I18N_NOOP2("@action" , "What's This") , SHIFT(F1) , 0 , KShortcut(), false }, //Group TextCompletion { TextCompletion , "TextCompletion" , I18N_NOOP2("@action", "Text Completion") , CTRL(E) , 0, KShortcut(), false }, { PrevCompletion , "PrevCompletion" , I18N_NOOP2("@action", "Previous Completion Match"), CTRL(Up) , 0, KShortcut(), false }, { NextCompletion , "NextCompletion" , I18N_NOOP2("@action", "Next Completion Match") , CTRL(Down) , 0, KShortcut(), false }, { SubstringCompletion , "SubstringCompletion" , I18N_NOOP2("@action", "Substring Completion") , CTRL(T) , 0, KShortcut(), false }, { RotateUp , "RotateUp" , I18N_NOOP2("@action", "Previous Item in List") , Qt::Key_Up , 0, KShortcut(), false }, { RotateDown , "RotateDown" , I18N_NOOP2("@action", "Next Item in List") , Qt::Key_Down, 0, KShortcut(), false }, { OpenRecent , "OpenRecent" , I18N_NOOP2("@action", "Open Recent") , 0 , 0, KShortcut(), false }, { SaveAs , "SaveAs" , I18N_NOOP2("@action", "Save As") , 0 , 0, KShortcut(), false }, { Revert , "Revert" , I18N_NOOP2("@action", "Revert") , 0 , 0, KShortcut(), false }, { PrintPreview , "PrintPreview" , I18N_NOOP2("@action", "Print Preview") , 0 , 0, KShortcut(), false }, { Mail , "Mail" , I18N_NOOP2("@action", "Mail") , 0 , 0, KShortcut(), false }, { Clear , "Clear" , I18N_NOOP2("@action", "Clear") , 0 , 0, KShortcut(), false }, { ActualSize , "ActualSize" , I18N_NOOP2("@action", "Actual Size") , 0 , 0, KShortcut(), false }, { FitToPage , "FitToPage" , I18N_NOOP2("@action", "Fit To Page") , 0 , 0, KShortcut(), false }, { FitToWidth , "FitToWidth" , I18N_NOOP2("@action", "Fit To Width") , 0 , 0, KShortcut(), false }, { FitToHeight , "FitToHeight" , I18N_NOOP2("@action", "Fit To Height") , 0 , 0, KShortcut(), false }, { Zoom , "Zoom" , I18N_NOOP2("@action", "Zoom") , 0 , 0, KShortcut(), false }, { Goto , "Goto" , I18N_NOOP2("@action", "Goto") , 0 , 0, KShortcut(), false }, { GotoPage , "GotoPage" , I18N_NOOP2("@action", "Goto Page") , 0 , 0, KShortcut(), false }, { DocumentBack , "DocumentBack" , I18N_NOOP2("@action", "Document Back") , ALTSHIFT(Left), 0, KShortcut(), false }, { DocumentForward , "DocumentForward" , I18N_NOOP2("@action", "Document Forward") , ALTSHIFT(Right), 0, KShortcut(), false }, { EditBookmarks , "EditBookmarks" , I18N_NOOP2("@action", "Edit Bookmarks") , 0 , 0, KShortcut(), false }, { Spelling , "Spelling" , I18N_NOOP2("@action", "Spelling") , 0 , 0, KShortcut(), false }, { ShowToolbar , "ShowToolbar" , I18N_NOOP2("@action", "Show Toolbar") , 0 , 0, KShortcut(), false }, { ShowStatusbar , "ShowStatusbar" , I18N_NOOP2("@action", "Show Statusbar") , 0 , 0, KShortcut(), false }, { SaveOptions , "SaveOptions" , I18N_NOOP2("@action", "Save Options") , 0 , 0, KShortcut(), false }, { KeyBindings , "KeyBindings" , I18N_NOOP2("@action", "Key Bindings") , 0 , 0, KShortcut(), false }, { Preferences , "Preferences" , I18N_NOOP2("@action", "Preferences") , 0 , 0, KShortcut(), false }, { ConfigureToolbars , "ConfigureToolbars" , I18N_NOOP2("@action", "Configure Toolbars") , 0 , 0, KShortcut(), false }, { ConfigureNotifications , "ConfigureNotifications" , I18N_NOOP2("@action", "Configure Notifications") , 0 , 0, KShortcut(), false }, { TipofDay , "TipofDay" , I18N_NOOP2("@action", "Tip Of Day") , 0 , 0, KShortcut(), false }, { ReportBug , "ReportBug" , I18N_NOOP2("@action", "Report Bug") , 0 , 0, KShortcut(), false }, { SwitchApplicationLanguage, "SwitchApplicationLanguage", I18N_NOOP2("@action", "Switch Application Language"), 0 , 0, KShortcut(), false }, { AboutApp , "AboutApp" , I18N_NOOP2("@action", "About Application") , 0 , 0, KShortcut(), false }, { AboutKDE , "AboutKDE" , I18N_NOOP2("@action", "About KDE") , 0 , 0, KShortcut(), false }, //dummy entry to catch simple off-by-one errors. Insert new entries before this line. { AccelNone , 0 , 0 , 0 , 0, 0, KShortcut(), false } }; /** Search for the KStandardShortcutInfo object associated with the given @p id. Return a dummy entry with no name and an empty shortcut if @p id is invalid. */ static KStandardShortcutInfo *guardedStandardShortcutInfo(StandardShortcut id) { if (id >= static_cast<int>(sizeof(g_infoStandardShortcut) / sizeof(KStandardShortcutInfo)) || id < 0) { kWarning(125) << "KStandardShortcut: id not found!"; return &g_infoStandardShortcut[AccelNone]; } else return &g_infoStandardShortcut[id]; } /** Initialize the accelerator @p id by checking if it is overridden in the configuration file (and if it isn't, use the default). On X11, if QApplication was initialized with GUI disabled, the default will always be used. */ static void initialize(StandardShortcut id) { KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); // All three are needed. if (info->id!=AccelNone) { Q_ASSERT(info->description); Q_ASSERT(info->translation_context); Q_ASSERT(info->name); } KConfigGroup cg(KGlobal::config(), "Shortcuts"); #ifdef Q_WS_X11 // Code within this block breaks if we aren't running in GUI mode. if(QX11Info::display() && cg.hasKey(info->name)) #else if(cg.hasKey(info->name)) #endif { QString s = cg.readEntry(info->name); if (s != "none") info->cut = KShortcut(s); else info->cut = KShortcut(); } else { info->cut = hardcodedDefaultShortcut(id); } info->isInitialized = true; } void saveShortcut(StandardShortcut id, const KShortcut &newShortcut) { KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); // If the action has no standard shortcut associated there is nothing to // save if(info->id == AccelNone) return; KConfigGroup cg(KGlobal::config(), "Shortcuts"); info->cut = newShortcut; bool sameAsDefault = (newShortcut == hardcodedDefaultShortcut(id)); if (sameAsDefault) { // If the shortcut is the equal to the hardcoded one we remove it from // kdeglobal if necessary and return. if(cg.hasKey(info->name)) cg.deleteEntry(info->name, KConfig::Global|KConfig::Persistent); return; } // Write the changed shortcut to kdeglobals cg.writeEntry(info->name, info->cut.toString(), KConfig::Global|KConfig::Persistent); } QString name(StandardShortcut id) { return guardedStandardShortcutInfo(id)->name; } QString label(StandardShortcut id) { KStandardShortcutInfo *info = guardedStandardShortcutInfo( id ); return i18nc( info->translation_context, info->description); } // TODO: Add psWhatsThis entry to KStandardShortcutInfo QString whatsThis( StandardShortcut /*id*/ ) { // KStandardShortcutInfo* info = guardedStandardShortcutInfo( id ); // if( info && info->whatsThis ) // return i18n(info->whatsThis); // else return QString(); } const KShortcut &shortcut(StandardShortcut id) { KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); if(!info->isInitialized) initialize(id); return info->cut; } StandardShortcut find(const QKeySequence &seq) { if( !seq.isEmpty() ) { for(uint i = 0; i < sizeof(g_infoStandardShortcut) / sizeof(KStandardShortcutInfo); i++) { StandardShortcut id = g_infoStandardShortcut[i].id; if( id != AccelNone ) { if(!g_infoStandardShortcut[i].isInitialized) initialize(id); if(g_infoStandardShortcut[i].cut.contains(seq)) return id; } } } return AccelNone; } StandardShortcut find(const char *keyName) { for(uint i = 0; i < sizeof(g_infoStandardShortcut) / sizeof(KStandardShortcutInfo); i++) if (qstrcmp(g_infoStandardShortcut[i].name, keyName)) return g_infoStandardShortcut[i].id; return AccelNone; } KShortcut hardcodedDefaultShortcut(StandardShortcut id) { KShortcut cut; KStandardShortcutInfo *info = guardedStandardShortcutInfo(id); return KShortcut(info->cutDefault, info->cutDefault2); } const KShortcut& open() { return shortcut( Open ); } const KShortcut& openNew() { return shortcut( New ); } const KShortcut& close() { return shortcut( Close ); } const KShortcut& save() { return shortcut( Save ); } const KShortcut& print() { return shortcut( Print ); } const KShortcut& quit() { return shortcut( Quit ); } const KShortcut& cut() { return shortcut( Cut ); } const KShortcut& copy() { return shortcut( Copy ); } const KShortcut& paste() { return shortcut( Paste ); } const KShortcut& pasteSelection() { return shortcut( PasteSelection ); } const KShortcut& deleteWordBack() { return shortcut( DeleteWordBack ); } const KShortcut& deleteWordForward() { return shortcut( DeleteWordForward ); } const KShortcut& undo() { return shortcut( Undo ); } const KShortcut& redo() { return shortcut( Redo ); } const KShortcut& find() { return shortcut( Find ); } const KShortcut& findNext() { return shortcut( FindNext ); } const KShortcut& findPrev() { return shortcut( FindPrev ); } const KShortcut& replace() { return shortcut( Replace ); } const KShortcut& home() { return shortcut( Home ); } const KShortcut& begin() { return shortcut( Begin ); } const KShortcut& end() { return shortcut( End ); } const KShortcut& beginningOfLine() { return shortcut( BeginningOfLine ); } const KShortcut& endOfLine() { return shortcut( EndOfLine ); } const KShortcut& prior() { return shortcut( Prior ); } const KShortcut& next() { return shortcut( Next ); } const KShortcut& backwardWord() { return shortcut( BackwardWord ); } const KShortcut& forwardWord() { return shortcut( ForwardWord ); } const KShortcut& gotoLine() { return shortcut( GotoLine ); } const KShortcut& addBookmark() { return shortcut( AddBookmark ); } const KShortcut& tabNext() { return shortcut( TabNext ); } const KShortcut& tabPrev() { return shortcut( TabPrev ); } const KShortcut& fullScreen() { return shortcut( FullScreen ); } const KShortcut& zoomIn() { return shortcut( ZoomIn ); } const KShortcut& zoomOut() { return shortcut( ZoomOut ); } const KShortcut& help() { return shortcut( Help ); } const KShortcut& completion() { return shortcut( TextCompletion ); } const KShortcut& prevCompletion() { return shortcut( PrevCompletion ); } const KShortcut& nextCompletion() { return shortcut( NextCompletion ); } const KShortcut& rotateUp() { return shortcut( RotateUp ); } const KShortcut& rotateDown() { return shortcut( RotateDown ); } const KShortcut& substringCompletion() { return shortcut( SubstringCompletion ); } const KShortcut& whatsThis() { return shortcut( WhatsThis ); } const KShortcut& reload() { return shortcut( Reload ); } const KShortcut& selectAll() { return shortcut( SelectAll ); } const KShortcut& up() { return shortcut( Up ); } const KShortcut& back() { return shortcut( Back ); } const KShortcut& forward() { return shortcut( Forward ); } const KShortcut& showMenubar() { return shortcut( ShowMenubar ); } }
KEYMAP( KC_GRV , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_TRNS , KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_TRNS , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11, KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS, /* right hand */ KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_DELETE , KC_F6 , KC_LBRC , KC_RBRC, KC_MINS , KC_EQL , KC_BSLS , KC_F12, KC_TRNS , KC_TRNS, KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS , KC_TRNS , KC_TRNS ) , KEYMAP( /* left hand */ SHIFT(KC_GRV), SHIFT(KC_1) , SHIFT(KC_2), SHIFT(KC_3) , SHIFT(KC_4), SHIFT(KC_5) , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , KC_TRNS , /* right hand */ SHIFT(KC_6), SHIFT(KC_7) , SHIFT(KC_8) , SHIFT(KC_9) , SHIFT(KC_0) , KC_TRNS , KC_TRNS , SHIFT(KC_LBRC), SHIFT(KC_RBRC), SHIFT(KC_MINS) , SHIFT(KC_EQL) , SHIFT(KC_BSLS) , KC_FN0, KC_FN1, KC_FN2, KC_FN3, KC_FN4, KC_FN5, KC_FN6, KC_FN7, KC_TRNS , KC_TRNS , KC_TRNS, KC_TRNS ) , }; enum function_id { RGBLED_TOGGLE, RGBLED_STEP_MODE,
int sprintf_command(int argc, char* argv[], GString* output) { // usage: sprintf IDENTIFIER FORMAT [Params...] COMMAND [ARGS ...] if (argc < 4) { return HERBST_NEED_MORE_ARGS; } char* identifier = argv[1]; char* format = argv[2]; (void) SHIFT(argc, argv); (void) SHIFT(argc, argv); (void) SHIFT(argc, argv); GString* repl = g_string_new(""); int nextarg = 0; // next argument to consider for (int i = 0; format[i] != '\0'; i++) { if (format[i] == FORMAT_CHAR) { // FORMAT_CHAR is our format character // '%' is the printf format character switch (format[i+1]) { case FORMAT_CHAR: g_string_append(repl, "%%"); break; case 's': if (nextarg >= (argc - 1)) { g_string_append_printf(output, "Error: Too few parameters. A %dth parameter missing. " "(treating \"%s\" as the command to execute)\n", nextarg, argv[argc - 1]); g_string_free(repl, true); return HERBST_INVALID_ARGUMENT; } HSAttribute* attr; attr = hsattribute_parse_path_verbose(argv[nextarg], output); if (!attr) { g_string_free(repl, true); return HERBST_INVALID_ARGUMENT; } GString* gs = hsattribute_to_string(attr); g_string_append(repl, gs->str); g_string_free(gs, true); nextarg++; break; default: g_string_append_printf(output, "Error: unknown format specifier \'%c\' in format " "\"%s\" at position %d\n", format[i+1] ? format[i+1] : '?', format, i); g_string_free(repl, true); return HERBST_INVALID_ARGUMENT; break; } i++; } else { g_string_append_c(repl, format[i]); } } int cmdc = argc - nextarg; char** cmdv = argv + nextarg; int status; status = call_command_substitute(identifier, repl->str, cmdc, cmdv, output); g_string_free(repl, true); return status; }
uint16_t *Commodore::Vic20::Machine::sequence_for_character(Utility::Typer *typer, char character) { #define KEYS(...) {__VA_ARGS__, TerminateSequence} #define SHIFT(...) {KeyLShift, __VA_ARGS__, TerminateSequence} #define X {NotMapped} static Key key_sequences[][3] = { /* NUL */ X, /* SOH */ X, /* STX */ X, /* ETX */ X, /* EOT */ X, /* ENQ */ X, /* ACK */ X, /* BEL */ X, /* BS */ KEYS(KeyDelete), /* HT */ X, /* LF */ KEYS(KeyReturn), /* VT */ X, /* FF */ X, /* CR */ X, /* SO */ X, /* SI */ X, /* DLE */ X, /* DC1 */ X, /* DC2 */ X, /* DC3 */ X, /* DC4 */ X, /* NAK */ X, /* SYN */ X, /* ETB */ X, /* CAN */ X, /* EM */ X, /* SUB */ X, /* ESC */ X, /* FS */ X, /* GS */ X, /* RS */ X, /* US */ X, /* space */ KEYS(KeySpace), /* ! */ SHIFT(Key1), /* " */ SHIFT(Key2), /* # */ SHIFT(Key3), /* $ */ SHIFT(Key4), /* % */ SHIFT(Key5), /* & */ SHIFT(Key6), /* ' */ SHIFT(Key7), /* ( */ SHIFT(Key8), /* ) */ SHIFT(Key9), /* * */ KEYS(KeyAsterisk), /* + */ KEYS(KeyPlus), /* , */ KEYS(KeyComma), /* - */ KEYS(KeyDash), /* . */ KEYS(KeyFullStop), /* / */ KEYS(KeySlash), /* 0 */ KEYS(Key0), /* 1 */ KEYS(Key1), /* 2 */ KEYS(Key2), /* 3 */ KEYS(Key3), /* 4 */ KEYS(Key4), /* 5 */ KEYS(Key5), /* 6 */ KEYS(Key6), /* 7 */ KEYS(Key7), /* 8 */ KEYS(Key8), /* 9 */ KEYS(Key9), /* : */ KEYS(KeyColon), /* ; */ KEYS(KeySemicolon), /* < */ SHIFT(KeyComma), /* = */ KEYS(KeyEquals), /* > */ SHIFT(KeyFullStop), /* ? */ SHIFT(KeySlash), /* @ */ KEYS(KeyAt), /* A */ KEYS(KeyA), /* B */ KEYS(KeyB), /* C */ KEYS(KeyC), /* D */ KEYS(KeyD), /* E */ KEYS(KeyE), /* F */ KEYS(KeyF), /* G */ KEYS(KeyG), /* H */ KEYS(KeyH), /* I */ KEYS(KeyI), /* J */ KEYS(KeyJ), /* K */ KEYS(KeyK), /* L */ KEYS(KeyL), /* M */ KEYS(KeyM), /* N */ KEYS(KeyN), /* O */ KEYS(KeyO), /* P */ KEYS(KeyP), /* Q */ KEYS(KeyQ), /* R */ KEYS(KeyR), /* S */ KEYS(KeyS), /* T */ KEYS(KeyT), /* U */ KEYS(KeyU), /* V */ KEYS(KeyV), /* W */ KEYS(KeyW), /* X */ KEYS(KeyX), /* Y */ KEYS(KeyY), /* Z */ KEYS(KeyZ), /* [ */ SHIFT(KeyColon), /* \ */ X, /* ] */ SHIFT(KeySemicolon), /* ^ */ X, /* _ */ X, /* ` */ X, /* a */ KEYS(KeyA), /* b */ KEYS(KeyB), /* c */ KEYS(KeyC), /* d */ KEYS(KeyD), /* e */ KEYS(KeyE), /* f */ KEYS(KeyF), /* g */ KEYS(KeyG), /* h */ KEYS(KeyH), /* i */ KEYS(KeyI), /* j */ KEYS(KeyJ), /* k */ KEYS(KeyK), /* l */ KEYS(KeyL), /* m */ KEYS(KeyM), /* n */ KEYS(KeyN), /* o */ KEYS(KeyO), /* p */ KEYS(KeyP), /* q */ KEYS(KeyQ), /* r */ KEYS(KeyR), /* s */ KEYS(KeyS), /* t */ KEYS(KeyT), /* u */ KEYS(KeyU), /* v */ KEYS(KeyV), /* w */ KEYS(KeyW), /* x */ KEYS(KeyX), /* y */ KEYS(KeyY), /* z */ KEYS(KeyZ) }; #undef KEYS #undef SHIFT #undef X if(character > sizeof(key_sequences) / sizeof(*key_sequences)) return nullptr; if(key_sequences[character][0] == NotMapped) return nullptr; return (uint16_t *)key_sequences[character]; }