// |plugin| must not be null. The caller takes ownership of the result, except // when it is null (at the end of the stream). No transfer of ownership of // |*plugin|. |*serializer| must be null on the first call and must be passed // unchanged to the successive calls; its ownership is not transferred. char const* principia__SerializePlugin(Plugin const* const plugin, PullSerializer** const serializer) { journal::Method<journal::SerializePlugin> m({plugin, serializer}, {serializer}); LOG(INFO) << __FUNCTION__; CHECK_NOTNULL(plugin); CHECK_NOTNULL(serializer); // Create and start a serializer if the caller didn't provide one. if (*serializer == nullptr) { *serializer = new PullSerializer(chunk_size, number_of_chunks); auto message = make_not_null_unique<serialization::Plugin>(); plugin->WriteToMessage(message.get()); (*serializer)->Start(std::move(message)); } // Pull a chunk. Bytes bytes; bytes = (*serializer)->Pull(); // If this is the end of the serialization, delete the serializer and return a // nullptr. if (bytes.size == 0) { TakeOwnership(serializer); return m.Return(nullptr); } // Convert to hexadecimal and return to the client. std::int64_t const hexadecimal_size = (bytes.size << 1) + 1; UniqueBytes hexadecimal(hexadecimal_size); HexadecimalEncode(bytes, hexadecimal.get()); hexadecimal.data.get()[hexadecimal_size - 1] = '\0'; return m.Return(reinterpret_cast<char const*>(hexadecimal.data.release())); }
void matchNumeric() const { givenACodeSampleToTokenize nonNumeric("abc", true); ASSERT_EQUALS(false, Token::Match(nonNumeric.tokens(), "%num%")); givenACodeSampleToTokenize binary("101010b", true); ASSERT_EQUALS(true, Token::Match(binary.tokens(), "%num%")); givenACodeSampleToTokenize octal("0123", true); ASSERT_EQUALS(true, Token::Match(octal.tokens(), "%num%")); givenACodeSampleToTokenize decimal("4567", true); ASSERT_EQUALS(true, Token::Match(decimal.tokens(), "%num%")); givenACodeSampleToTokenize hexadecimal("0xDEADBEEF", true); ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); givenACodeSampleToTokenize floatingPoint("0.0f", true); ASSERT_EQUALS(true, Token::Match(floatingPoint.tokens(), "%num%")); givenACodeSampleToTokenize doublePrecision("0.0d", true); ASSERT_EQUALS(true, Token::Match(doublePrecision.tokens(), "%num%")); givenACodeSampleToTokenize signedLong("0L", true); ASSERT_EQUALS(true, Token::Match(signedLong.tokens(), "%num%")); givenACodeSampleToTokenize negativeSignedLong("-0L", true); ASSERT_EQUALS(true, Token::Match(negativeSignedLong.tokens(), "- %num%")); givenACodeSampleToTokenize positiveSignedLong("+0L", true); ASSERT_EQUALS(true, Token::Match(positiveSignedLong.tokens(), "+ %num%")); givenACodeSampleToTokenize unsignedInt("0U", true); ASSERT_EQUALS(true, Token::Match(unsignedInt.tokens(), "%num%")); givenACodeSampleToTokenize unsignedLong("0UL", true); ASSERT_EQUALS(true, Token::Match(unsignedLong.tokens(), "%num%")); givenACodeSampleToTokenize unsignedLongLong("0ULL", true); ASSERT_EQUALS(true, Token::Match(unsignedLongLong.tokens(), "%num%")); givenACodeSampleToTokenize positive("+666", true); ASSERT_EQUALS(true, Token::Match(positive.tokens(), "+ %num%")); givenACodeSampleToTokenize negative("-42", true); ASSERT_EQUALS(true, Token::Match(negative.tokens(), "- %num%")); givenACodeSampleToTokenize negativeNull("-.0", true); ASSERT_EQUALS(true, Token::Match(negativeNull.tokens(), "- %num%")); givenACodeSampleToTokenize positiveNull("+.0", true); ASSERT_EQUALS(true, Token::Match(positiveNull.tokens(), "+ %num%")); }
type lexico(){ while(esp_blanco()); if(identificador()) return _id; else if(naturales()) return _nat; else if(octal()) return _oct; else if(eof()) return _eof; else if (hexadecimal()) return _hex; else if (parent_izq()) return _parent_izq; return _error; }
int main(){ FILE *p,*r; p=fopen("isa.txt","r"); r=fopen("binary.txt","w"); char c; int i=0,zz=0,k,mm=0,cx,bx,cn=0; char *s=(char *)malloc(sizeof(char)*max); while((c=fgetc(p))!=EOF){ if(i==0 && c>=48&&c<=57){ s[i]=c; i++; zz=1; } else if(c==':'){ i=0; } else if(c!=' ' && c!='\n' && c!=','){ s[i]=c; i++; } else if((c==' ' || c=='\n' || c==',')&&i!=0&&cn==0){ int j; s[i]='\0'; if(s[i-1]=='h'){ hexadecimal(r,s,i); } else if(zz==1){ binary(r,s); } else{ cx=findopcode(r,s); bx=symbolmatch(r,s); } i=0; zz=0; } if(c=='\n') cn=0; } fclose(p); fclose(r); return 0; }
int main() { int number,number2, counter, counter2, check; char hex[16]; scanf("%d", &number); do{ for(counter = 0, number2 = number; number2 != 0; counter++){ hex[counter] = hexadecimal(number2%16); number2 /= 16; } hex[counter] = '\0'; for(counter = 0, counter2 = strlen(hex) - 1, check = 1; counter < (strlen(hex) - 1); counter++, counter2--){ if(hex[counter] != hex[counter2]){ check = 0; number++; } } }while(!check); printf("%s \n", hex); return 0; }
int main (int argc, char **argv) { char *locale; tests_start_mpfr (); #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE) /* currently, we just check with 'C' locale */ locale = setlocale (LC_ALL, "C"); #endif bug20111102 (); native_types (); hexadecimal (); binary (); decimal (); mixed (); check_emax (); check_emin (); #if defined(HAVE_LOCALE_H) && defined(HAVE_SETLOCALE) #if MPFR_LCONV_DPTS locale_da_DK (); /* Avoid a warning by doing the setlocale outside of this #if */ #endif setlocale (LC_ALL, locale); #endif if (getenv ("MPFR_CHECK_LIBC_PRINTF")) { /* check against libc */ random_double (); bug20081214 (); bug20080610 (); } tests_end_mpfr (); return 0; }
void matchNumeric() { givenACodeSampleToTokenize nonNumeric("abc"); ASSERT_EQUALS(false, Token::Match(nonNumeric.tokens(), "%num%")); givenACodeSampleToTokenize binary("101010b"); ASSERT_EQUALS(true, Token::Match(binary.tokens(), "%num%")); givenACodeSampleToTokenize octal("0123"); ASSERT_EQUALS(true, Token::Match(octal.tokens(), "%num%")); givenACodeSampleToTokenize decimal("4567"); ASSERT_EQUALS(true, Token::Match(decimal.tokens(), "%num%")); givenACodeSampleToTokenize hexadecimal("0xDEADBEEF"); ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); givenACodeSampleToTokenize floatingPoint("0.0f"); ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); givenACodeSampleToTokenize doublePrecision("0.0d"); ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); givenACodeSampleToTokenize unsignedInt("0U"); ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); givenACodeSampleToTokenize unsignedLong("0UL"); ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); givenACodeSampleToTokenize unsignedLongLong("0ULL"); ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); givenACodeSampleToTokenize positive("+666"); ASSERT_EQUALS(true, Token::Match(positive.tokens(), "+ %num%")); givenACodeSampleToTokenize negative("-42"); ASSERT_EQUALS(true, Token::Match(negative.tokens(), "- %num%")); }
int main(int argc, char *argv[]){ FILE *arq_entrada; /* associado ao arquivo de entrada */ FILE *arq_saida; /* associado ao arquivo de saida */ char delim[] = " \n";/*delimitadores dos tokens*/ char str[1001];/*string referente a cada linha*/ char *token;/*string referente a cada token*/ int tam; /* auxiliar */ palavra mapa_mem; /* mapa de memoria */ rotulo mapa_rot; /* mapa de rotulos */ nome lista_nom; /* lista de nomes */ endereco end = {0,0}; /* ponteiro de endereco */ arq_entrada = fopen(argv[1],"r");/*abre o arquivo para leitura*/ arq_saida = fopen(argv[2],"w");/*abre o arquivo para escrita*/ /* Inicializa mapa dos rotulos */ InicializaMapaRotulos(&mapa_rot); InicializaMapaMemoria(&mapa_mem); InicializaNomes(&lista_nom); /* PRIMEIRA LEITURA DO ARQUIVO - MAPA DE ROTULOS */ while(!feof(arq_entrada)){ /* Carrega o primeiro token da linha de entrada */ token = strtok(fgets(str,1000,arq_entrada),delim); while(token != NULL){ /* Calcula tamanho do token */ tam = strlen(token); /* Teste se eh diretiva (primeiro caracter eh '.') */ if(token[0] == '.'){ diretivas(token, &end, &mapa_mem, &lista_nom); } /* Teste se eh roluto (ultimo caracter eh ':') */ else if(token[tam-1] == ':'){ InsereRotuloFim(&mapa_rot,token,end); } /* Teste se eh comentario (primeiro caracter eh '#') */ else if(token[0] == '#'){ /* Percorre ate o fim da linha */ token = strtok(NULL,"\n"); } /* TESTAR SE EH NECESSARIO INTERPRETAR INSTRUCOES NA PRIMEIRA LEITURA */ else{ instrucoes(token, end, &mapa_mem, &mapa_rot); } token = strtok(NULL, delim); } } /* Ordena mapa de memoria */ OrdenaMapa(&mapa_mem); /* Volta ao inicio do arquivo e reseta o contador de posicao */ fseek(arq_entrada, 0, SEEK_SET); end.endereco = 0; end.pos = 0; /* SEGUNDA LEITURA DO ARQUIVO - MAPA DE MEMORIA */ while(!feof(arq_entrada)){ /* Carrega o primeiro token da linha de entrada */ token = strtok(fgets(str,1000,arq_entrada),delim); while(token != NULL){ /* Calcula tamanho do token */ tam = strlen(token); /* Teste se eh diretiva (primeiro caracter eh '.') */ if(token[0] == '.'){ diretivas(token, &end, &mapa_mem, &lista_nom); } /* Teste se eh comentario (primeiro caracter eh '#' */ else if(token[0] == '#'){ /* Percorre ate o fim da linha */ token = strtok(NULL,"\n"); } /* Se nao eh nenhum desses, eh uma instrucao */ else{ instrucoes(token, end, &mapa_mem, &mapa_rot); } token = strtok(NULL, delim); } } /* Escrever arquivo de saida */ hexadecimal(&mapa_mem,arq_saida); LiberaRotulos(&mapa_rot); LiberaMapaPalavras(&mapa_mem); LiberaNomes(&lista_nom); fclose(arq_entrada);/*fecha o arquivo de entrada*/ fclose(arq_saida);/*fecha o arquivo de saida*/ return 0; }