void set_settings(unsigned char buffer[], struct settings kerm) { buffer[4] = tochar(kerm.maxl); buffer[5] = tochar(kerm.time); buffer[6] = tochar(kerm.npad); buffer[7] = ctl(kerm.padc); buffer[8] = tochar(kerm.eol); buffer[9] = kerm.qctl; buffer[10] = kerm.qbin; buffer[11] = kerm.chkt; buffer[12] = kerm.rept; }
static char *mk_string_list(char *ptr, size_t *len, size_t *begin, size_t *run, ssize_t cur, int inchar) { int rlen; if (cur != -1) { if (!*begin) { /* begin of the list */ *begin = cur + 1; return ptr; } if (*begin + *run == cur) { /* no gap, continue */ (*run)++; return ptr; } } else if (!*begin) { *ptr = '\0'; return ptr; /* end of empty list */ } /* add to the list */ if (!*run) rlen = inchar ? snprintf(ptr, *len, "%c,", tochar(*begin)) : snprintf(ptr, *len, "%zd,", *begin); else if (*run == 1) rlen = inchar ? snprintf(ptr, *len, "%c,%c,", tochar(*begin), tochar(*begin + 1)) : snprintf(ptr, *len, "%zd,%zd,", *begin, *begin + 1); else rlen = inchar ? snprintf(ptr, *len, "%c-%c,", tochar(*begin), tochar(*begin + *run)) : snprintf(ptr, *len, "%zd-%zd,", *begin, *begin + *run); if (rlen < 0 || (size_t) rlen + 1 > *len) return NULL; ptr += rlen; if (rlen > 0 && *len > (size_t) rlen) *len -= rlen; else *len = 0; if (cur == -1 && *begin) { /* end of the list */ *(ptr - 1) = '\0'; /* remove tailing ',' from the list */ return ptr; } *begin = cur + 1; *run = 0; return ptr; }
cStr *decode(cStr * str) { char *s = string_chars(str), *n = s, h, l; register Int len = string_length(str); for (; len > 0; len--, s++, n++) { switch (*s) { case '+': *n = ' '; break; case '%': h = *++s; l = *++s; len -= 2; *n = tochar(h, l); break; default: *n = *s; } } *n = '\0'; str->len = (n - str->s); return str; }
char * fromDec(int n, char form) { int base = DEC_BASE; if (form == 'x') base = HEX_BASE; else if (form == 'o') base = OCT_BASE; else if (form == 'b') base = BIN_BASE; char *result = (char *) calloc(1, sizeof(char)); char *digit = (char *) calloc(1, sizeof(char)); int remainder; char *neg = ""; if (n < 0) { n = (~n)+1; neg = "-"; } while (n) { remainder = n % base; if (base == HEX_BASE && remainder >= 10) { digit[0] = toHexChar(remainder); } else { digit[0] = tochar(remainder); } strcat(result, digit); n /= base; } printf("%s%c", neg, form); return strrev(result); }
static inline short next_char(int *m, int k) { int n = *m / k; *m = *m % k; return tochar(n); }
/***********************************************************************//** * @brief Exception message. ***************************************************************************/ const char* GLATExceptionHandler::what() const throw() { // Set error message std::string message = "*** ERROR in " + m_origin + ": " + m_message; // Return message as C character array return tochar(message); }
int main() { freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); int ans,mod,now,len; now=1; int i=1; while(now<99999){ ban1[i]=tochar(now,ban0[i]); i++; now<<=1; } while(gets(str1) && (str1[0]!='\n') ){ gets(str2); //printf("1 %s %s 2\n",str1,str2); a=tonumber(str1); b=tonumber(str2); ans=a*b; now=1; //printf("%d %d %d \n",a,b,ans); while(b){ mod=b&1; b>>=1; len=ban1[now]; strcpy(tmp,ban0[now]); tmp[len++]=' '; if(mod){ tmp[len++]='*'; } while(len<34)tmp[len++]=' '; tmp[len]='\0'; printf("%s",tmp); len=tochar(a,tmp); printf("%s \n",tmp); now++; a<<=1; } tochar(ans,tmp); printf("The solution is: %s\n",tmp); } //getchar();getchar(); return 0; }
void print(LLBin **list, char *form) { int b; char *ans = (char *) malloc(sizeof(char)); int ret; if (strcmp(form, "b")) { while (*list) { printf("%c", tochar((*list)->num)); (*list) = (*list)->next; } return; } else if (strcmp(form, "x")) b = HEX_BASE; else if (strcmp(form, "o")) b = OCT_BASE; else if (strcmp(form, "d")) b = DEC_BASE; while (list) { ret += pow((*list)->num,b); } printf("%c", tochar(ret)); }
void Auto_Reader(void) { while(1) { if(PcdRequest(0x52,Temp)==MI_OK) { if(Temp[0]==0x04&&Temp[1]==0x00) PutString("MFOne-S50"); else if(Temp[0]==0x02&&Temp[1]==0x00) PutString("MFOne-S70"); else if(Temp[0]==0x44&&Temp[1]==0x00) PutString("MF-UltraLight"); else if(Temp[0]==0x08&&Temp[1]==0x00) PutString("MF-Pro"); else if(Temp[0]==0x44&&Temp[1]==0x03) PutString("MF Desire"); else PutString("Unknown"); if(PcdAnticoll(UID)==MI_OK) { PutString0("Card Id is:"); tochar(UID[0]); tochar(UID[1]); tochar(UID[2]); tochar(UID[3]); while (!(IFG1 & UTXIFG0)); TXBUF0 = '\n'; //发送换行指令 RED_LED_ON ; Delay(200) ; RED_LED_OFF ; Delay(200) ; } } else GRE_LED_OFF ; } }
//检查文件是否存在 bool isexist(int b) { char* path = tochar(b); ifstream file(path, ios::in); bool is = true; if(!file) { is = false; } else { is = true; } file.close(); delete[] path; return is; }
//新建一个block int createBlock(int block) { char *temp = tochar(block); int buffer = -1; ofstream fw(temp, ofstream::out|ofstream::binary); if(!fw) { cout<<"Error in function createBlock! Please restart the Program! block:"<<block<<endl; exit(0); } for(int i=0;i<1024;i++) { fw.write( (char*)& buffer, 4); }//以int的最小值补充,代表未使用空间 fw.close(); delete temp; temp = NULL; return block; }
void Time::format2445(short* buf, bool hasTime) const { int n; n = t.tm_year+1900; buf[0] = next_char(&n, 1000); buf[1] = next_char(&n, 100); buf[2] = next_char(&n, 10); buf[3] = tochar(n); n = t.tm_mon+1; buf[4] = next_char(&n, 10); buf[5] = tochar(n); n = t.tm_mday; buf[6] = next_char(&n, 10); buf[7] = tochar(n); if (hasTime) { buf[8] = 'T'; n = t.tm_hour; buf[9] = next_char(&n, 10); buf[10] = tochar(n); n = t.tm_min; buf[11] = next_char(&n, 10); buf[12] = tochar(n); n = t.tm_sec; buf[13] = next_char(&n, 10); buf[14] = tochar(n); bool inUtc = strcmp("UTC", timezone) == 0; if (inUtc) { buf[15] = 'Z'; } } }
static void send_file_data(int fd_out, int fd_in, int file, unsigned char *ptr_seq) { unsigned char buffer[0x64], response[0x64]; unsigned char len, seq, times, coded[200]; unsigned int current_character, previous_character; int i, k, previous_position, response_length; seq = *ptr_seq; k = previous_position = 0; current_character = 0; previous_character = MY_EOF; times = 0; getchar_with_buffer(FILE_BUFFER_RESET); do { current_character = getchar_with_buffer(file); if(current_character == previous_character && times < 94) { times++; } else { if(times <= DONT_COMPRESS_THRESHOLD) { for(i = 0; i < times; i++) encode_single_char(me, coded, &k, previous_character); } else { coded[k++] = '~'; coded[k++] = tochar(times); encode_single_char(me, coded, &k, previous_character); } previous_character = current_character; times = 1; } if(k > me.maxl - 4) { len = previous_position + 4; for(i = 0; i < previous_position; i++) buffer[i+4] = coded[i]; set_hf_send_packet(fd_out, fd_in, buffer, len, &seq, 'D', response, &response_length); k -= previous_position; for(i = 0; i < k; i++) coded[i] = coded[i + previous_position]; } previous_position = k; } while(current_character != (unsigned int) MY_EOF); if(k) { len = k + 4; for(i = 0; i < k; i++) buffer[i+4] = coded[i]; set_hf_send_packet(fd_out, fd_in, buffer, len, &seq, 'D', response, &response_length); } *ptr_seq = seq; }
static int ask_number(struct fdisk_context *cxt, struct fdisk_ask *ask, char *buf, size_t bufsz) { char prompt[128] = { '\0' }; const char *q = fdisk_ask_get_query(ask); const char *range = fdisk_ask_number_get_range(ask); uint64_t dflt = fdisk_ask_number_get_default(ask), low = fdisk_ask_number_get_low(ask), high = fdisk_ask_number_get_high(ask); int inchar = fdisk_ask_number_inchars(ask); assert(q); DBG(ASK, ul_debug("asking for number " "['%s', <%ju,%ju>, default=%ju, range: %s]", q, low, high, dflt, range)); if (range && dflt >= low && dflt <= high) { if (inchar) snprintf(prompt, sizeof(prompt), _("%s (%s, default %c): "), q, range, tochar(dflt)); else snprintf(prompt, sizeof(prompt), _("%s (%s, default %ju): "), q, range, dflt); } else if (dflt >= low && dflt <= high) { if (inchar) snprintf(prompt, sizeof(prompt), _("%s (%c-%c, default %c): "), q, tochar(low), tochar(high), tochar(dflt)); else snprintf(prompt, sizeof(prompt), _("%s (%ju-%ju, default %ju): "), q, low, high, dflt); } else if (inchar) snprintf(prompt, sizeof(prompt), _("%s (%c-%c): "), q, tochar(low), tochar(high)); else snprintf(prompt, sizeof(prompt), _("%s (%ju-%ju): "), q, low, high); do { int rc = get_user_reply(cxt, prompt, buf, bufsz); uint64_t num; if (rc) return rc; if (!*buf && dflt >= low && dflt <= high) return fdisk_ask_number_set_result(ask, dflt); if (isdigit_string(buf)) { char *end; errno = 0; num = strtoumax(buf, &end, 10); if (errno || buf == end || (end && *end)) continue; } else if (inchar && isalpha(*buf)) { num = tolower(*buf) - 'a' + 1; } else rc = -EINVAL; if (rc == 0 && num >= low && num <= high) return fdisk_ask_number_set_result(ask, num); fdisk_warnx(cxt, _("Value out of range.")); } while (1); return -1; }
int deeper(int depth) { unsigned char r[16], *ptr2; int i, j, ok = 0, rs = 0, len, clen, nlen; if (depth > 31) return -1; memset(r, 0, sizeof(r)); // generate base packet cnt++; buf[1] = cnt; for (i = 0; i < depth; i++) { buf[sizeof(buf_start) + 2 + i * 2] = 1; buf[sizeof(buf_start) + 2 + i * 2 + 1] = range[depth - i - 1]; } memcpy(buf + sizeof(buf_start) + 2 + depth * 2, buf_end, sizeof(buf_end)); buf_len = sizeof(buf_start) + 2 + depth * 2 + sizeof(buf_end); // loop to finish generation and send redo: for (i = 0; i < 16; i++) { if (r[i] == 0) { buf[0] = i; buf[13] = tohex(i); if (send(sock, buf, buf_len, 0) < 0) { fprintf(stderr, "Error: can not send to network!\n"); exit(-1); } else usleep(5); } } //recveive and process replies wait = 1; alarm(waittime); while(ok == 0 && wait == 1) { if ((len = recv(sock, buf2, sizeof(buf2), 0)) > 70 && buf2[1] == cnt) { i = (buf2[0] & 15); if ((buf2[3] & 3) == 0) { if (depth == 31) { r[i] = 3; if (buf2[7] == 1) { found++; strcpy(name, "Found: "); ptr2 = buf2 + 12; i = 0; while (i < 32 && *ptr2 == 1) { if (i % 2 == 0) j = tochar(ptr2[1]); else dst6[15 - i/2] = (tochar(ptr2[1]) * 16) + j; ptr2 += 2; i++; } strcat(name, thc_ipv62notation(dst6)); strcat(name, " is "); ptr2 = buf2 + 102; while (*ptr2 != 0 && ptr2 + *ptr2 + 1 <= buf2 + len) { clen = *ptr2; nlen = *(ptr2 + clen + 1); *(ptr2 + clen + 1) = 0; strcat(name, ptr2 + 1); strcat(name, "."); *(ptr2 + *ptr2 + 1) = nlen; ptr2 += clen + 1; } if (debug) { strcat(name, " is "); ptr2 = buf2 + 12; while (*ptr2 != 0 && ptr2 + *ptr2 + 1 <= buf2 + len) { clen = *ptr2; nlen = *(ptr2 + clen + 1); *(ptr2 + clen + 1) = 0; strcat(name, ptr2 + 1); strcat(name, "."); *(ptr2 + *ptr2 + 1) = nlen; ptr2 += clen + 1; } } printf("%s\n", name); } } else r[i] = 2; } else r[i] = 1; rs++; } if (rs == 16) ok = 1; } alarm(0); if (ok == 1 || rs == 16) { // all packets received for (i = 0; i < 16; i++) if (r[i] == 2) { range[depth] = tohex(i); deeper(depth + 1); } } else { // packet loss / timeout if (rs < 16) waittime++; if (rs < 11) waittime++; if (rs < 6) waittime++; if (rs < 2) waittime++; if ((rs == 0 && (waittime >= WAITTIME_START + 6)) || waittime > 15) { fprintf(stderr, "Error: DNS Server %s is not answering or not reliable enough anymore!\n", dst); exit(-1); } fprintf(stderr, "Warning: packet loss, increasing response timeout to %d seconds\n", waittime); goto redo; } return rs; }
void set_packet_header(unsigned char buffer[], unsigned char len, unsigned char seq, unsigned char type) { buffer[0] = mark; buffer[1] = tochar(len); buffer[2] = tochar(seq); buffer[3] = type; }