file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/150142284.c
// test while-if int whileIf() { int a; a = 0; int b; b = 0; while (a < 100) { if (a == 5) { b = 25; } else if (a == 10) { b = 42; } else { b = a * 2; } a = a + 1; } return (b); } int main(){ return (whileIf()); }
the_stack_data/212642283.c
#include<stdio.h> void main(){ int num=12345,find=345,pow,len,flen,ctr,it,ct,dig,dig1; len=0; pow=1; while(num/pow){ len++; pow*=10; } pow=1; flen=0; while(find/pow){ flen++; pow*=10; } ctr=0; for(it=1,pow=1;it<len;it++) pow*=10; while(ctr!=len){ ctr++; for(ct=1;ct<=flen;ct++){ dig=(num/pow)%10; dig1=(find/pow)%10; printf("%d %d",dig,dig1); pow/=10; } } }
the_stack_data/38426.c
#include <stdio.h> #include <stdlib.h> #include <string.h> /* ################################################################ # Funçőes do Banco # ################################################################ */ // Variáveis Globais char nomeTabela[30]; char nomeColuna[30]; typedef struct { char nome[30]; int quantColunas; int tipos[30]; char colunas[20][30]; char linhas[20][20][30]; }BD_tabela; struct bancoDados { BD_tabela tabelas[20]; }; struct bancoDados ITPDB; void BD_salvar(){ FILE *arquivo = fopen("data/database.itp", "w"); if (arquivo == NULL){ fprintf(stderr, "Erro ao carregar a DB\n"); exit(1); } // escrever a estrutura no arquivo fwrite(&ITPDB, sizeof(struct bancoDados), 1, arquivo); if(fwrite == 0) printf("Erro ao salvar\n"); fclose (arquivo); } void BD_carregar(){ FILE *arquivo = fopen ("data/database.itp", "r"); if (arquivo == NULL) return; // carregar dados do arquivo e os insere na variável ITPDB fread(&ITPDB, sizeof(struct bancoDados), 1, arquivo); fclose (arquivo); } // verificar se o valor que o usuário colocar da chave primária já é existente int verificarChavePrimaria(int indexTabela, char *valor){ for(int i = 0; i < 20; i++){ if(strcmp(ITPDB.tabelas[indexTabela].linhas[i][0], valor) == 0) return 1; } return 0; } // verificar se o nome da coluna já é existente int verificarNomeColuna(int indexTabela, char *nomeColuna){ for(int i = 0; i < 20; i++){ if(strcmp(ITPDB.tabelas[indexTabela].colunas[i], nomeColuna) == 0) return 1; } return 0; } // verificar se o nome da tabela já é existente int verificarNomeTabela(char * nomeTabela){ for(int i = 0; i < 10; i++){ if(strcmp(ITPDB.tabelas[i].nome, nomeTabela) == 0) return i; } return -1; } // pegar proximo espaço vazio do banco | pegar próxima tabela/linha vazia (array) int pegarSlotVazio(){ // obter a index do próximo espaço livre for(int i = 0; i < 10; i++){ if(ITPDB.tabelas[i].quantColunas == 0) return i; } return 0; } int pegarProxLinhaVazia(int indexTabela){ for(int i = 0; i < 10; i++){ if(strlen(ITPDB.tabelas[indexTabela].linhas[i][0]) == 0) return i; } return 19; } char * tipos[] = {"INT", "CHAR", "FLOAT", "DOUBLE", "STRING"}; char * tipoVariavel(int tipo){ return tipos[tipo-1] ? tipos[tipo-1] : "Desconhecido"; } int detectarTipos(char * string, int tipoEsperado){ int tiposDetectados[5]; tiposDetectados[4] = 1; // string if(strlen(string) == 1) tiposDetectados[1] = 1; // char if(strtof(string, NULL) != 0 && strchr(string, '.')) tiposDetectados[2] = 1; // float if(strtod(string, NULL) != 0 && strchr(string, '.')) tiposDetectados[3] = 1; // double if(strtol(string, NULL, 10) != 0 && tiposDetectados[2] != 1 && tiposDetectados[3] != 1) tiposDetectados[0] = 1; // int // uma entrada pode ser string e int ao mesmo tempo ou char e int ou float e double, por isso é retornado uma array. return tiposDetectados[tipoEsperado-1]; } /* ################################################################ # Funçőes do Menu # ################################################################ */ void criarTabela(){ int quantColunas, tipo, indexTabela = pegarSlotVazio(); printf("Digite o nome da tabela: "); scanf("%s", nomeTabela); while(verificarNomeTabela(nomeTabela) != -1){ printf("Nome de tabela já existente!\n"); printf("Digite o nome da tabela: "); scanf("%s", nomeTabela); } strcpy(ITPDB.tabelas[indexTabela].nome, nomeTabela); printf("Digite a quantidade de colunas: "); scanf("%i", &ITPDB.tabelas[indexTabela].quantColunas); // não deixa colocar quantidade de colunas desejadas menores que 1 while(ITPDB.tabelas[indexTabela].quantColunas < 1){ printf("O número mínimo é 1! Insira novamente: "); scanf("%i", &ITPDB.tabelas[indexTabela].quantColunas); } printf("Digite o nome da chave primaria: "); scanf("%s", nomeColuna); strcpy(ITPDB.tabelas[indexTabela].colunas[0], nomeColuna); ITPDB.tabelas[indexTabela].tipos[0] = 1; fflush(stdin); //apagar o buffer do teclado for (int i = 1; i < ITPDB.tabelas[indexTabela].quantColunas; i++) { printf("Digite o nome da coluna %i: ", i); scanf("%s", nomeColuna); while(verificarNomeColuna(indexTabela, nomeColuna) == 1){ printf("Nome de coluna já existente!\n"); printf("Digite o nome da tabela: "); scanf("%s", nomeColuna); } strcpy(ITPDB.tabelas[indexTabela].colunas[i], nomeColuna); printf("Digite o número referente ao tipo da coluna:\n" "1-INT\n" "2-CHAR\n" "3-FLOAT\n" "4-DOUBLE\n" "5-STRING\n"); scanf("%d", &tipo); while(tipo < 1 || tipo > 5){ printf("Seleção inválida! Digite novamente: "); scanf("%d", &tipo); } ITPDB.tabelas[indexTabela].tipos[i] = tipo; } printf("\nTabela criada!"); BD_salvar(); // força o salvamento da DB } void apagarTabela(){ BD_salvar(); BD_tabela conjuntoVazio; int indexTabela = -1; while(indexTabela == -1){ printf("Digite o nome da tabela: "); scanf("%s", nomeTabela); while(verificarNomeTabela(nomeTabela) == -1){ printf("Nome de tabela inexistente!\n"); printf("Digite o nome da tabela: "); scanf("%s", nomeTabela); } indexTabela = verificarNomeTabela(nomeTabela); // ele sai do while quando é diferente de -1 } memset(&ITPDB.tabelas[indexTabela], 0, sizeof(conjuntoVazio)); // substituindo os dados da tabela por NULL printf("Tabela apagada!"); } void listarTabelas(){ printf("Listando tabelas...\n"); printf("=== Tabelas ===\n"); for(int i = 0; i < 10; i++){ if(strlen(ITPDB.tabelas[i].nome) != 0) printf("| %s |\n", ITPDB.tabelas[i].nome); // se existir o nome da tabela no DB ele imprime, senăo ele năo faz nada. } BD_salvar(); } void listarDadosTabela(){ BD_salvar(); int indexTabela = -1; //só pra entrar no WHILE printf("== Listando valores ==\n"); while(indexTabela == -1){ printf("Digite o nome da tabela: "); scanf("%s", nomeTabela); indexTabela = verificarNomeTabela(nomeTabela); } printf("Colunas: "); for(int i = 0; i < ITPDB.tabelas[indexTabela].quantColunas; i++){ if(ITPDB.tabelas[indexTabela].colunas[i]){ if(i == 0) printf("%s* (INT) | ", ITPDB.tabelas[indexTabela].colunas[i]); else printf("%s (%s) | ", ITPDB.tabelas[indexTabela].colunas[i], tipoVariavel(ITPDB.tabelas[indexTabela].tipos[i])); } } for(int i = 0; i < 20; i++){ // linhas if(strlen(ITPDB.tabelas[indexTabela].linhas[i][0]) != 0) printf("\nLinha %i: ", i); for(int j = 0; j < ITPDB.tabelas[indexTabela].quantColunas; j++){ // colunas if(strlen(ITPDB.tabelas[indexTabela].linhas[i][0]) != 0) printf("%s | ", ITPDB.tabelas[indexTabela].linhas[i][j]); } } } void inserirLinhasColuna(){ BD_salvar(); char * valorColuna = malloc(20); int indexTabela = -1, linhasQuant = 1; while(indexTabela == -1){ printf("\nDigite o nome da tabela: "); scanf("%s", nomeTabela); indexTabela = verificarNomeTabela(nomeTabela); // atribui o valor da index da tabela } int linhaLivre = pegarProxLinhaVazia(indexTabela); printf("Quantas linhas deseja inserir? "); scanf("%i", &linhasQuant); while(linhasQuant < 1){ printf("O número mínimo é 1! Insira novamente: "); scanf("%i", &linhasQuant); } for(int i = linhaLivre; i < linhaLivre+linhasQuant; i++){ printf("=== Linha %i ===\n", i); for(int j = 0; j < ITPDB.tabelas[indexTabela].quantColunas; j++){ printf("Digite os dados da coluna %s (%s)- ", ITPDB.tabelas[indexTabela].colunas[j], tipoVariavel(ITPDB.tabelas[indexTabela].tipos[j])); scanf("%s", valorColuna); while(detectarTipos(valorColuna, ITPDB.tabelas[indexTabela].tipos[j]) != 1){ printf("Você inseriu um valor com tipo inválido! Esperado: %s\nInsira novamente:", tipoVariavel(ITPDB.tabelas[indexTabela].tipos[j])); scanf("%s", valorColuna); } if(j == 0){ while(verificarChavePrimaria(indexTabela, valorColuna) == 1){ printf("Valor existente! Insira outro valor: "); scanf("%s", valorColuna); } } strcpy(ITPDB.tabelas[indexTabela].linhas[i][j], valorColuna); } } printf("\nLinha(s) inserida(s) com sucesso!"); } void apagarLinhaTabela(){ BD_salvar(); int indexTabela = -1; char *primary = malloc(20); while(indexTabela == -1){ printf("\nDigite o nome da tabela: "); scanf("%s", nomeTabela); while(verificarNomeTabela(nomeTabela) == -1){ printf("Nome de tabela inexistente!\n"); printf("Digite o nome da tabela: "); scanf("%s", nomeTabela); } indexTabela = verificarNomeTabela(nomeTabela); } printf("Digite o valor de %s para apagar: ", ITPDB.tabelas[indexTabela].colunas[0]); scanf("%s", primary); for(int i = 0; i < 20; i++){ if(strcmp(ITPDB.tabelas[indexTabela].linhas[i][0], primary) == 0){ memset(&ITPDB.tabelas[indexTabela].linhas[i], 0, sizeof(20 * 20 * 30)); break; } } } void opcoesMenu(){ printf("\n ___________________________________\n"); printf( "\n| 1- Criar Tabela |" "\n| 2- Listar Tabelas |" "\n| 3- Adicionar valor a tabela |" "\n| 4- Listar Dados da tabela |" "\n| 5- Apagar valor da tabela |" "\n| 6- Apagar tabela |" "\n| 0- Sair |"); printf("\n ___________________________________\n\n"); } void menuBanco() { int op = 1; while (op != 0) { fflush(stdin); opcoesMenu(); printf("\nEscolha: "); scanf("%d", &op); fflush(stdin); switch (op) { case 1: criarTabela(); break; case 2: listarTabelas(); break; case 3: inserirLinhasColuna(); break; case 4: listarDadosTabela(); break; case 5: apagarLinhaTabela(); break; case 6: apagarTabela(); break; case 0: printf("Até a próxima!\n"); BD_salvar(); break; default: printf("Opçăo inválida! Selecione uma das opçőes:\n"); opcoesMenu(); break; } } }
the_stack_data/130197.c
// Option should not be passed to the frontend by default. // RUN: %clang -target x86_64-apple-macosx10.15-gnu -fsanitize=address %s \ // RUN: -### 2>&1 | \ // RUN: FileCheck %s // CHECK-NOT: -fsanitize-address-destructor // RUN: %clang -target x86_64-apple-macosx10.15-gnu -fsanitize=address \ // RUN: -fsanitize-address-destructor=none %s -### 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-NONE-ARG %s // CHECK-NONE-ARG: "-fsanitize-address-destructor=none" // RUN: %clang -target x86_64-apple-macosx10.15-gnu -fsanitize=address \ // RUN: -fsanitize-address-destructor=global %s -### 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-GLOBAL-ARG %s // CHECK-GLOBAL-ARG: "-fsanitize-address-destructor=global" // RUN: %clang -target x86_64-apple-macosx10.15-gnu -fsanitize=address \ // RUN: -fsanitize-address-destructor=bad_arg %s -### 2>&1 | \ // RUN: FileCheck -check-prefix=CHECK-INVALID-ARG %s // CHECK-INVALID-ARG: error: unsupported argument 'bad_arg' to option 'fsanitize-address-destructor='
the_stack_data/40763766.c
#include <stdio.h> #include <string.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "<%s> string\n", argv[0]); return -1; } fprintf(stderr, "length of string [%s] is %d\n", argv[1], strlen(argv[1])); return 0; }
the_stack_data/116559.c
// Printing Tokens // Problem Link: https://www.hackerrank.com/challenges/printing-tokens-/problem #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { char *s; s = malloc(1024 * sizeof(char)); scanf("%[^\n]", s); s = realloc(s, strlen(s) + 1); // Solution int i; for (i=0; s[i]!='\0'; i++) { if (s[i]!=' ') printf("%c", s[i]); else { printf("\n"); } } return 0; }
the_stack_data/77922.c
/* * This is bin2c program, which allows you to convert binary file to * C language array, for use as embedded resource, for instance you can * embed graphics or audio file directly into your program. * This is public domain software, use it on your own risk. * Contact Serge Fukanchik at [email protected] if you have any questions. * * Some modifications were made by Gwilym Kuiper ([email protected]) * I have decided not to change the licence. */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #ifdef USE_BZ2 #include <bzlib.h> #endif #define ARRAY_TYPE "static const unsigned char" int main ( int argc, char* argv[] ) { char *buf; char* ident; unsigned int i, file_size, need_comma; FILE *f_input, *f_output; #ifdef USE_BZ2 char *bz2_buf; unsigned int uncompressed_size, bz2_size; #endif if (argc < 4) { fprintf(stderr, "Usage: %s binary_file output_file array_name\n", argv[0]); return -1; } f_input = fopen(argv[1], "rb"); if (f_input == NULL) { fprintf(stderr, "%s: can't open %s for reading\n", argv[0], argv[1]); return -1; } // Get the file length fseek(f_input, 0, SEEK_END); file_size = ftell(f_input); fseek(f_input, 0, SEEK_SET); file_size++; buf = (char *)malloc(file_size); assert(buf); fread(buf, file_size, 1, f_input); fclose(f_input); #ifdef USE_BZ2 // allocate for bz2. bz2_size = ((file_size) * 1.01) + 600; // as per the documentation bz2_buf = (char *)malloc(bz2_size); assert(bz2_buf); // compress the data int status = BZ2_bzBuffToBuffCompress(bz2_buf, &bz2_size, buf, file_size, 9, 1, 0); if(status != BZ_OK) { fprintf(stderr, "Failed to compress data: error %i\n", status); return -1; } // and be very lazy free(buf); uncompressed_size = file_size; file_size = bz2_size; buf = bz2_buf; #endif f_output = fopen(argv[2], "w"); if (f_output == NULL) { fprintf(stderr, "%s: can't open %s for writing\n", argv[0], argv[1]); return -1; } ident = argv[3]; need_comma = 0; fprintf(f_output, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"); //fprintf (f_output, "const char %s[%i] = {", ident, file_size); fprintf (f_output, ARRAY_TYPE " %s[] = {", ident); for (i = 0; i < file_size; ++i) { if (need_comma) fprintf(f_output, ", "); else need_comma = 1; if (( i % 11 ) == 0) fprintf(f_output, "\n\t"); fprintf(f_output, "0x%.2x", buf[i] & 0xff); } fprintf(f_output, "\n};\n\n"); fprintf(f_output, "const int %s_length = %i;\n", ident, file_size); fprintf(f_output, "\n#ifdef __cplusplus\n}\n#endif\n"); #ifdef USE_BZ2 fprintf(f_output, "const int %s_length_uncompressed = %i;\n", ident, uncompressed_size); #endif fclose(f_output); return 0; }
the_stack_data/170453981.c
#include <stdio.h> #include <stdlib.h> int main(int argc,char*argv[]) { system("PAUSE"); return 0; }
the_stack_data/459000.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <float.h> #define thisprog "xe-ldas5-sliceEPSP" #define TITLE_STRING thisprog" v 1: 6.September.2018 [JRH]" #define MAXLINELEN 1000 #define MAXLABELS 1000 /* <TAGS> SLICE file signal_processing filter </TAGS> */ /* TO DO - change estimation of artefact - time irrelevant, take RMS in unfiltered data between zero and max1? v 1: 2.October.2018 [JRH] - bugfix: fEPSP minimum is now actually the minimum, as stated, not the first negative inflection - allow user to specify whether fibre-volley is based on the first or the last inflection between max1 and max2 - include estimate of fEPSP quality (testing at present - RMS/mean might be best) v 1: 6.September.2018 [JRH] - bugfix - corrected use of wrong range (nn vs nnodes2) for checking fibre-volley nodes v 1: 2.September.2018 [JRH] - rethink of fibre-volley detection strategy 1. do not require artefact detection to proceed with FV detection and fEPSP - note that stim artefact is quite variable on the electrode in stratum radiatum - detection occassionally fails - also note that up to this point A2 (artefact positivity) has been defined as the last positivity before max1 - consequently, F2 must by definition fall after max1 2. detect last positivity, OR LAST NEGATIVITY before max2 - because sometimes there is only a negativity, and the peak of the fibre-volley comes late - using the mid-point of max2-max1 as the slope reference can result in the mid-point being near the actual peak - revising the algorithm this way ensures that the fibre volley will always include an actual negativity and positivity, one of which must fall between max1 and max2 3. Impose 1.5*(max2-max1) limit on allowable fibre-volley duration v 1: 30.August.2018 [JRH] - do not omit slope calculation based on issues with artefact amplitude relative to the POP spike - do not exit on slope-detection error/warning - switch to using half-time of fEPSP for calculating slope, rather than the less reliable half-amplitude (which used to fail for shallow slopes) - update instructions in xf_readwinltp1_f - update xf_geom_slope2_f to allow slopes to be ignored or to break the loop if they are negative or positive - update instructions v 1: 8.May.2018 [JRH] - estimate "fibre-volley" size and time for slope calculation, even if there is no fibre-volley preset v 1: 14.December.2017 [JRH] - three separate filter regimens for artefact, fibre-volley and fEPSP - slope is calculated using data filtered for fEPSP (data3) - this obliterates the fibre volley and other artefacts - however, the scope of the slope-search is defined according to the detection of artefact & fibre-volley using the other filter settings - requirements for stim-artefact reduced to a positivity before setmax1 (typically 1.5ms) v 1: 13.December.2017 [JRH] - make data0 the original unfiltered data - create separate arrays for strict (data1) and gently (data2) filtered arrays - bugfix: EPSP slope parameters now derived from more strictly-filtered data - enable filtered trace output (-fout) v 1: 2.November.2017 [JRH] - enable filtered trace output (-fout) v 1: 2.November.2017 [JRH] */ /* external functions start */ long xf_readwinltp1_f(char *setinfile, char *setchan, float **data0, double *result_d, char *message); char *xf_lineread1(char *line, long *maxlinelen, FILE *fpin); long *xf_lineparse1(char *line,long *nwords); long xf_interp3_f(float *data, long ndata); int xf_stats2_f(float *data1, long nn, int setlarge, float *result_f); double xf_mae1_f(float *data1, float *data2, long nn, char *message); double xf_rms1_f(float *input, long nn, char *message); double xf_samplefreq1_d(double *time1, long n1, char *message); int xf_compare1_d(const void *a, const void *b); int xf_filter_bworth1_f(float *X, size_t nn, float sample_freq, float low_freq, float high_freq, float res, char *message); long xf_detectinflect1_f(float *data,long n1,long **itime1,int **isign1,char *message); long xf_geom_slope2_f(float *data,long n1,long winsize,double interval,int test,double *min,double *max,char *message); /* external functions end */ int main (int argc, char *argv[]) { /* general variables */ char message[MAXLINELEN]; long int ii,jj,kk,ll,mm,nn; int v,w,x,y,z; float result_f[16]; double aa,bb,cc,dd,ee,result_d[64]; FILE *fpin,*fpout; /* program-specific variables */ char outfile1[64],outfile2[64]; int *isign1=NULL,*isign2=NULL,*isign3=NULL; long zero1,nnodes1,nnodes2,nnodes3,*isamp1=NULL,*isamp2=NULL,*isamp3=NULL; long sampA1,sampA2,sampF1,sampF2,sampE1,sampE2,slopewin,fvmaxdur,ifirst,ilast; float *data0=NULL,*data1=NULL,*data2=NULL,*data3=NULL,*dataslope; double *itime1=NULL,*itime2=NULL,*itime3=NULL; double timeA1,timeA2,timeF1,timeF2,timeE1,timeE2; double valueA1,valueA2,valueF1,valueF2,valueE1,valueE2,errE1; double sampint,samprate,baseline,mae,mean,sd,rms,slopemin,slopemax; /* arguments */ char *infile,*setchan; int setfiltout=2,setverb=0,setpos=2; double setfilthigh1=1500.0,setfilthigh2=1800.0,setfilthigh3=250.0,setmax1=1.25,setmax2=2.5,setmax3=15.0; /* define output file names */ snprintf(outfile1,64,"temp_%s_trace.txt",thisprog); snprintf(outfile2,64,"temp_%s_nodes.txt",thisprog); /******************************************************************************** PRINT INSTRUCTIONS IF THERE IS NO FILENAME SPECIFIED ********************************************************************************/ if(argc<3) { fprintf(stderr,"\n"); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"%s\n",TITLE_STRING); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"Slice-ephys analysis: fibre-volley (FV) and fEPSP\n"); fprintf(stderr,"- detect stim artefact (ART), FV & fEPSP with separate filters\n"); fprintf(stderr,"- FV: \n"); fprintf(stderr," - find neg or pos inflection between max1 and max2\n"); fprintf(stderr," - find next pos or previous neg inflection, respectively\n"); fprintf(stderr," - check that duration <= 1.5*(max2-max1)\n"); fprintf(stderr," - otherwise use (max1+max2)/2 as FV start and stop time\n"); fprintf(stderr,"- fEPSP slope: top half of line connecting FV and fEPSP minimum\n"); fprintf(stderr," - looks for most negative slope in 0.5ms sliding windows\n"); fprintf(stderr," - seeks from FV +ivity to fEPSP trough\n"); fprintf(stderr," - if no FV, use middle of max1-to-max2 (see below)\n"); fprintf(stderr,"\n"); fprintf(stderr,"USAGE: %s [input] [channel] [options]\n",thisprog); fprintf(stderr," [input]: WinLTP output filename or \"stdin\"\n"); fprintf(stderr," [channel]: channel to analyze- typically AD0 or AD1\n"); fprintf(stderr,"\n"); fprintf(stderr,"VALID OPTIONS: defaults in []\n"); fprintf(stderr," high-cut filter options (Hz)\n"); fprintf(stderr," -high1 artefact filter [%g]\n",setfilthigh1); fprintf(stderr," -high2 fibre-volley & slope-detection filter [%g]\n",setfilthigh2); fprintf(stderr," -high3 fEPSP filter [%g]\n",setfilthigh3); fprintf(stderr," maximum-times (ms) for phenomena\n"); fprintf(stderr," -max1 ART +ivity, also minimum for FV -ivity [%g]\n",setmax1); fprintf(stderr," -max2 FV -ivity [%g]\n",setmax2); fprintf(stderr," -max3 fEPSP trough [%g]\n",setmax3); fprintf(stderr," other options\n"); fprintf(stderr," -pos: FV detected as first(1) or last(2) inflection [%d]\n",setpos); fprintf(stderr," -fout output trace is filtered? (0=NO 1=high1, 2=high2, 3-high3) [%d]\n",setfiltout); fprintf(stderr," -verb sets verbosity (0=simple, 1=verbose) [%d]\n",setverb); fprintf(stderr,"\n"); fprintf(stderr,"EXAMPLES:\n"); fprintf(stderr," %s 63290358.P0 AD1 -verb 1\n",thisprog); fprintf(stderr," cat 63290358.P0 | %s stdin AD1\n",thisprog); fprintf(stderr,"\n"); fprintf(stderr,"SCREEN OUTPUT:\n"); fprintf(stderr," artmv fvms fvmv epspms epspmv epspslope\n"); fprintf(stderr,"\n"); fprintf(stderr,"FILE OUTPUT:\n"); fprintf(stderr," %s\n",outfile1); fprintf(stderr," - trace in format <time> <voltage>\n"); fprintf(stderr," %s\n",outfile2); fprintf(stderr," - fEPSP & fibre-volley nodes (used for plotting)\n"); fprintf(stderr,"----------------------------------------------------------------------\n"); fprintf(stderr,"\n"); exit(0); } /******************************************************************************** READ THE FILENAME AND OPTIONAL ARGUMENTS - including comma-separated list item ********************************************************************************/ infile= argv[1]; setchan= argv[2]; for(ii=3;ii<argc;ii++) { if( *(argv[ii]+0) == '-') { if((ii+1)>=argc) {fprintf(stderr,"\n--- Error [%s]: missing value for argument \"%s\"\n\n",thisprog,argv[ii]); exit(1);} else if(strcmp(argv[ii],"-high1")==0) setfilthigh1= atof(argv[++ii]); else if(strcmp(argv[ii],"-high2")==0) setfilthigh2= atof(argv[++ii]); else if(strcmp(argv[ii],"-high3")==0) setfilthigh3= atof(argv[++ii]); else if(strcmp(argv[ii],"-max1")==0) setmax1= atof(argv[++ii]); else if(strcmp(argv[ii],"-max2")==0) setmax2= atof(argv[++ii]); else if(strcmp(argv[ii],"-max3")==0) setmax3= atof(argv[++ii]); else if(strcmp(argv[ii],"-pos")==0) setpos= atoi(argv[++ii]); else if(strcmp(argv[ii],"-verb")==0) setverb= atoi(argv[++ii]); else if(strcmp(argv[ii],"-fout")==0) setfiltout= atoi(argv[++ii]); else {fprintf(stderr,"\n*** %s [ERROR: invalid command line argument \"%s\"]\n\n",thisprog,argv[ii]); exit(1);} }} if(setpos!=1 && setpos!=2) { fprintf(stderr,"\n--- Error [%s]: invalid -pos [%d] must be 1 or 2\n\n",thisprog,setpos);exit(1);} if(setverb!=0 && setverb!=1) { fprintf(stderr,"\n--- Error [%s]: invalid -verb [%d] must be 0 or 1\n\n",thisprog,setverb);exit(1);} if(setmax1>=setmax2) { fprintf(stderr,"\n--- Error [%s]: -max1 [%g] must be < max2 [%g]\n\n",thisprog,setmax1,setmax2);exit(1);} if(setmax2>=setmax3) { fprintf(stderr,"\n--- Error [%s]: -max2 [%g] must be < max3 [%g]\n\n",thisprog,setmax2,setmax3);exit(1);} if(setfiltout<0 || setfiltout>3) { fprintf(stderr,"\n--- Error [%s]: invalid -fout [%d] must be 0,1 or 2\n\n",thisprog,setfiltout);exit(1);} /********************************************************************************/ /* READ THE WINLTP FILE - STORE IN data0 */ /********************************************************************************/ nn= xf_readwinltp1_f(infile,setchan,&data0,result_d,message); if(nn<0) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } sampint= result_d[0]; samprate= result_d[1]; baseline= result_d[2]; zero1= (long)(samprate * (baseline/1000.0)); fvmaxdur= (long)(1.5*samprate*(setmax2-setmax1)/1000.0); if(setverb==1) { fprintf(stderr," infile= %s\n",infile); fprintf(stderr," total_samples= %ld\n",nn); fprintf(stderr," sample_interval= %g ms\n",sampint); fprintf(stderr," sample_rate= %g Hz\n",samprate); fprintf(stderr," baseline_period= %g ms\n",baseline); fprintf(stderr," setmax1= %g ms\n",setmax1); fprintf(stderr," setmax2= %g ms\n",setmax2); fprintf(stderr," setmax3= %g ms\n",setmax3); fprintf(stderr," highcut_filter1= %g Hz\n",setfilthigh1); fprintf(stderr," highcut_filter2= %g Hz\n",setfilthigh2); fprintf(stderr," highcut_filter3= %g Hz\n",setfilthigh3); fprintf(stderr," stimart_maxtime= %g ms\n",setmax1); fprintf(stderr," fibrevolley_maxtime= %g ms\n",setmax2); if(setpos==1) fprintf(stderr," fibrevolley_inflection= first\n"); if(setpos==2) fprintf(stderr," fibrevolley_inflection= last\n"); fprintf(stderr," fEPSP_maxtime= %g ms\n",setmax3); } /* INTERPOLATE */ jj= xf_interp3_f(data0,nn); if(jj<0) { fprintf(stderr,"\b\n\t--- Error [%s]: no valid data in %s\n\n",thisprog,infile); exit(1); } /********************************************************************************/ /* NORMALIZE TO THE MEAN OF THE BASELINE */ /********************************************************************************/ aa= 0.0; for(ii=0;ii<zero1;ii++) aa+= data0[ii]; mean= aa/(double)zero1; for(ii=0;ii<nn;ii++) data0[ii]-= mean; /********************************************************************************/ /* MAKE COPIES OF THE DATA */ /********************************************************************************/ data1= malloc(nn*sizeof(*data1)); data2= malloc(nn*sizeof(*data2)); data3= malloc(nn*sizeof(*data3)); if(data1==NULL) { fprintf(stderr,"\b\n\t--- Error [%s]: insufficient memory\n\n",thisprog); exit(1); } if(data2==NULL) { fprintf(stderr,"\b\n\t--- Error [%s]: insufficient memory\n\n",thisprog); exit(1); } if(data3==NULL) { fprintf(stderr,"\b\n\t--- Error [%s]: insufficient memory\n\n",thisprog); exit(1); } for(ii=0;ii<nn;ii++) data1[ii]= data2[ii]= data3[ii]= data0[ii]; /********************************************************************************/ /* APPLY FILTERING TO THE COPIES */ /********************************************************************************/ z= xf_filter_bworth1_f(data1,nn,samprate,0,setfilthigh1,1.412,message); if(z<0) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } z= xf_filter_bworth1_f(data2,nn,samprate,0,setfilthigh2,1.412,message); if(z<0) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } z= xf_filter_bworth1_f(data3,nn,samprate,0,setfilthigh3,1.412,message); if(z<0) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } /******************************************************************************** DETECT INFLECTIONS (NODES) - only detect for times > zero (after stimulation) ********************************************************************************/ nnodes1= xf_detectinflect1_f((data1+zero1),(nn-zero1),&isamp1,&isign1,message); if(nnodes1<0) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } if(nnodes1<5) { fprintf(stderr,"--- Warning [%s]: fewer than 5 nodes in %s\n",thisprog,infile); } /* build an inflection-times array: milliseconds, relative to zero */ itime1= malloc(nnodes1*sizeof(*itime1)); if(itime1==NULL) { fprintf(stderr,"\b\n\t--- Error [%s]: insufficient memory\n\n",thisprog); exit(1); } for(ii=0;ii<nnodes1;ii++) itime1[ii]= (double)isamp1[ii]*sampint; /* correct the timestamps so they refer to the entire dataset, since detection started at "zero" */ for(ii=0;ii<nnodes1;ii++) isamp1[ii]+=zero1; //TEST: for(ii=0;ii<nnodes1;ii++) fprintf(stderr,"node:%ld\tsamp:%ld\ttime:%.3f\n",ii,isamp1[ii],itime1[ii]); nnodes2= xf_detectinflect1_f((data2+zero1),(nn-zero1),&isamp2,&isign2,message); if(nnodes2<0) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } /* build an inflection-times array: milliseconds, relative to zero */ itime2= malloc(nnodes2*sizeof(*itime2)); if(itime2==NULL) { fprintf(stderr,"\b\n\t--- Error [%s]: insufficient memory\n\n",thisprog); exit(1); } for(ii=0;ii<nnodes2;ii++) itime2[ii]= (double)isamp2[ii]*sampint; /* correct the timestamps so they refer to the entire dataset, since detection started at "zero" */ for(ii=0;ii<nnodes2;ii++) isamp2[ii]+= zero1; //TEST:for(ii=0;ii<nnodes1;ii++) fprintf(stderr,"node:%ld\tsamp:%ld\ttime:%.3f\n",ii,isamp2[ii],itime2[ii]); nnodes3= xf_detectinflect1_f((data3+zero1),(nn-zero1),&isamp3,&isign3,message); if(nnodes3<0) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } /* build an inflection-times array: milliseconds, relative to zero */ itime3= malloc(nnodes3*sizeof(*itime3)); if(itime3==NULL) { fprintf(stderr,"\b\n\t--- Error [%s]: insufficient memory\n\n",thisprog); exit(1); } for(ii=0;ii<nnodes3;ii++) itime3[ii]= (double)isamp3[ii]*sampint; /* correct the timestamps so they refer to the entire dataset, since detection started at "zero" */ for(ii=0;ii<nnodes3;ii++) isamp3[ii]+= zero1; //TEST: for(ii=0;ii<nnodes3;ii++) fprintf(stderr,"node:%ld\tsamp:%ld\ttime:%.3f\n",ii,isamp3[ii],itime3[ii]); /******************************************************************************** DETECT STIMULATION-ARTEFACT (A1,A2, <setmax1) - based on data1 - look for last positivity before setmax1, then look back for preceding negativity - if the positivity is the first node, take the negativity as time zero ********************************************************************************/ /* INITIALIZE VARIABLES TO "INVALID" */ sampA1=sampA2=sampF1=sampF2=-1; timeA1=NAN; timeA2=NAN; valueA1=NAN; valueA2=NAN; /* DEFINE THE ARTEFACT START (A1, negative) AND STOP (A2, positive) */ jj=0; for(ii=0;ii<nnodes1;ii++) { if(itime1[ii]<setmax1 && isign1[ii]>0) { /* set sample-numbers and times for (A)rtefact */ if(ii>0) { timeA1= itime1[ii-1]; sampA1= isamp1[ii-1]; } /* if the positivity is the first inflection, take the negativity as time zero */ else { timeA1= 0.0; sampA1= 0; } valueA1= data1[sampA1]; timeA2= itime1[ii]; sampA2= isamp1[ii]; valueA2= data1[sampA2]; jj++; }} if(jj==0) { fprintf(stderr,"--- Warning [%s]: no artefact positivity before %gms in %s\n",thisprog,setmax1,infile); } //TEST: fprintf(stderr,"timeA1:%g sampA1:%ld valueA1:%g\n",timeA1,sampA1,valueA1); //TEST: fprintf(stderr,"timeA2:%g sampA2:%ld valueA2:%g\n",timeA2,sampA2,valueA2); /******************************************************************************** DETECT FIBRE-VOLLEY (F1,F2) BETWEEN MAX1 AND MAX2 - based on data2 - allow detection of multiple events as a precaution against really noisy data - detect last positivity in acceptable region, take preceding negativity as actual FV - define time and value for slope-reference (sampF2 valueF2) - if there is no fibre volley... - slope-reference value = mean of data2 values between setmax1 and setmax2 - slope-reference time = mid-point between setmax1 and setmax2 ********************************************************************************/ /* INITIALIZE VARIABLES TO "INVALID" */ timeF1= timeF2= NAN; valueF1= valueF2= NAN; /* SCAN NODES FOR LAST POSITIVITY - FV POSITIVITY IS THE NEXT SAMPLE */ // jj= inflection count, kk= sample-number //TEST:for(ii=1;ii<nnodes2;ii++) fprintf(stderr,"%g\n",itime2[ii]); jj= kk= 0; for(ii=1;ii<nnodes2;ii++) { if(isign2[ii]>0 && itime2[ii]>setmax1 && itime2[ii]<setmax2) { if(jj==0) ifirst= ii; kk= ii; jj++; }} /* if at least one positive inflection was detected... */ if(jj>0) { if(setpos==1) kk= ifirst; /* move pointer to first or last inflection depending on options */ if(jj>1) { if(setpos==1) fprintf(stderr,"--- Warning [%s]: %ld potential FVs in %s - taking the first %.2f-%.2f ms)\n",thisprog,jj,infile,itime2[kk-1],itime2[kk]); if(setpos==2) fprintf(stderr,"--- Warning [%s]: %ld potential FVs in %s - taking the last %.2f-%.2f ms)\n",thisprog,jj,infile,itime2[kk-1],itime2[kk]); } timeF1= itime2[kk-1]; sampF1= isamp2[kk-1]; valueF1= data2[sampF1]; timeF2= itime2[kk]; sampF2= isamp2[kk]; valueF2= data2[sampF2]; } /* ALTERNATIVELY, DETECT LAST NEGATIVE INFLECTION - FV POSITIVITY IS THE NEXT SAMPLE */ else { mm= nnodes2-1; jj= kk= 0; for(ii=0;ii<mm;ii++) { if(isign2[ii]<0 && itime2[ii]>setmax1 && itime2[ii]<setmax2) { if(jj==0) ifirst= ii; kk= ii; jj++; }} if(jj>0) { if(setpos==1) kk= ifirst; /* move pointer to first or last inflection depending on options */ if(jj>1) { if(setpos==1) fprintf(stderr,"--- Warning [%s]: %ld potential FVs in %s - taking the first %.2f-%.2f ms)\n",thisprog,jj,infile,itime2[kk-1],itime2[kk]); if(setpos==2) fprintf(stderr,"--- Warning [%s]: %ld potential FVs in %s - taking the last %.2f-%.2f ms)\n",thisprog,jj,infile,itime2[kk-1],itime2[kk]); } timeF1= itime2[kk]; sampF1= isamp2[kk]; valueF1= data2[sampF1]; timeF2= itime2[kk+1]; sampF2= isamp2[kk+1]; valueF2= data2[sampF2]; } } //TEST: fprintf(stderr,"actual %ld, max %ld\n",(sampF2-sampF1),(fvmaxdur)); /* IF NEITHER A NEGATIVE NOR POSITIVE INFLECTION WAS DETECTED, IMPROVISE! */ if(jj==0 || (sampF2-sampF1) > fvmaxdur) { fprintf(stderr,"--- Warning [%s]: no fibre-volley found between %gms and %gms in %s\n",thisprog,setmax1,setmax2,infile); aa= (setmax1+setmax2)/ 2000.0; // midpoint between max1 and max2, converted to seconds sampF1= sampF2= zero1 + (long)(aa * samprate); // convert midpoint to samples, add zero offset valueF1= NAN; // invalidate fibre-volley amplitude valueF2= data2[sampF2]; // store value for slope timeF1= timeF2= NAN; } //TEST: fprintf(stderr,"timeF1:%g sampF1:%ld valueF1:%g\n",timeF1,sampF1,valueF1); //TEST: fprintf(stderr,"timeF2:%g sampF2:%ld valueF2:%g\n",timeF2,sampF2,valueF2); /******************************************************************************** DETECT FIELD-EPSP MINIMUM (E1), BETWEEN STETMAX2 AND SETMAX3 - based on data3 (except for quality, which is based on data2) ********************************************************************************/ /* INITIALIZE VARIABLES TO "INVALID" */ sampE1=sampE2= -1; timeE1=valueE1=errE1= NAN; /* CALCULATE THE QUALITY, AS MEAN-ABSOLUTE-ERROR (data2-data3) BETWEEN setmax2 AND setmax3 */ ii= (long)(samprate * ((baseline+setmax2)/1000.0)); jj= (long)(samprate * ((baseline+setmax3)/1000.0)); kk= jj-ii; mae= xf_mae1_f((data2+ii),(data3+ii),kk,message); if(!isfinite(mae)) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } /* SCAN FOR fEPSP MINIMUM (E1) BETWEEN SETMAX2 AND SETMAX3 - OUTSIDE RANGE OF FIBRE-VOLLEY */ jj= kk= 0; // jj= counter, kk= node-number of minimum aa= DBL_MAX; // value of minimum for(ii=0;ii<nnodes3;ii++) { if(isign3[ii]==-1 && itime3[ii]>=setmax2 && itime3[ii]<=setmax3) { bb= data3[isamp3[ii]]; if(bb<aa) { aa= bb; kk= ii; jj++; } break; } } if(jj>0) { timeE1= itime3[kk]; sampE1= isamp3[kk]; valueE1= data3[sampE1]; errE1= mae; } else { fprintf(stderr,"--- Warning [%s]: no fEPSP minimum found between %gms and %gms in %s\n",thisprog,setmax2,setmax3,infile); } //TEST: fprintf(stderr,"timeE1:%g sampE1:%ld valueE1:%g\n",timeE1,sampE1,valueE1); /******************************************************************************** CALCULATE THE fEPSP SLOPE - use the highly filtered data (data3) - but feature times from more gently filtered data ********************************************************************************/ /* - note that scanning starts from sampF2 */ timeE2=valueE2= NAN; slopemin= slopemax= NAN; if(sampE1>0) { if(valueE1>valueA2) fprintf(stderr,"--- Warning [%s]: fEPSP minimum is higher than artefact positivity in %s\n",thisprog,infile); /* set pointer to appropriately filtered data */ dataslope= data2; /* define 0.5 ms sliding window to use for slope calculation */ slopewin= (long)(0.5/sampint); /* determine the temporal mid-point between the FV positivity and the EPSP minimum */ sampE2= (sampF2+sampE1)/2; timeE2= (sampE2-zero1)*sampint; valueE2= dataslope[sampE2]; /* set the size of the slope-scan region */ mm= (sampE1-sampF2)+1; /* analyze the slope */ /* note: do not exit on error - for this function it just means the data is too short or contains invalid values */ jj= xf_geom_slope2_f((dataslope+sampF2),mm,slopewin,sampint,0,&slopemin,&slopemax,message); if(jj<0) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); } } /* TEST fprintf(stderr,"sampA1=%ld = %gms\n",sampA1,timeA1); fprintf(stderr,"sampA2=%ld = %gms\n",sampA2,timeA2); fprintf(stderr,"sampF1=%ld = %gms\n",sampF1,timeF1); fprintf(stderr,"sampF2=%ld = %gms\n",sampF2,timeF2); fprintf(stderr,"sampE1=%ld = %gms\n",sampE1,timeE1); */ /********************************************************************************/ /* OUTPUT THE DATA */ /********************************************************************************/ /* WRITE THE TRACE */ if((fpout=fopen(outfile1,"w"))==NULL) { fprintf(stderr,"\b\n\t--- Error [%s]: could not open file %s for writing\n\n",thisprog,outfile1); exit(1); } jj= -zero1; fprintf(fpout,"ms mV\n"); if(setfiltout==0) for(ii=0;ii<nn;ii++) { aa= jj*sampint; fprintf(fpout,"%.3f\t%g\n",aa,data0[ii]); jj++; } if(setfiltout==1) for(ii=0;ii<nn;ii++) { aa= jj*sampint; fprintf(fpout,"%.3f\t%g\n",aa,data1[ii]); jj++; } if(setfiltout==2) for(ii=0;ii<nn;ii++) { aa= jj*sampint; fprintf(fpout,"%.3f\t%g\n",aa,data2[ii]); jj++; } if(setfiltout==3) for(ii=0;ii<nn;ii++) { aa= jj*sampint; fprintf(fpout,"%.3f\t%g\n",aa,data3[ii]); jj++; } fclose(fpout); /* WRITE THE NODES */ if((fpout=fopen(outfile2,"w"))==NULL) { fprintf(stderr,"\b\n\t--- Error [%s]: could not open file %s for writing\n\n",thisprog,outfile2); exit(1); } fprintf(fpout,"node colour ms mV\n"); fprintf(fpout,"A1 1 %g %g\n",timeA1,valueA1); fprintf(fpout,"A2 1 %g %g\n",timeA2,valueA2); fprintf(fpout,"F1 2 %g %g\n",timeF1,valueF1); fprintf(fpout,"F2 2 %g %g\n",timeF2,valueF2); fprintf(fpout,"E1 3 %g %g\n",timeE1,valueE1); fprintf(fpout,"E2 3 %g %g\n",timeE2,valueE2); if(! isfinite(timeF2)) { fprintf(fpout,"Fest 10 %gzero1= %g\n",((double)(sampF2-zero1)*sampint),valueF2); } fclose(fpout); /* WRITE THE SUMMARY */ printf("artmv fvms fvmv epspms epspmv epspslope epsperr\n"); printf("%.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",valueA1,timeF1,valueF1,timeE1,valueE1,slopemin,errE1); /********************************************************************************/ /* FREE MEMORY AND EXIT */ /********************************************************************************/ if(data0!=NULL) free(data0); if(data1!=NULL) free(data1); if(data2!=NULL) free(data2); if(data3!=NULL) free(data3); if(isamp1!=NULL) free(isamp1); if(isamp2!=NULL) free(isamp2); if(isamp3!=NULL) free(isamp3); if(isign1!=NULL) free(isign1); if(isign2!=NULL) free(isign2); if(isign3!=NULL) free(isign3); if(itime1!=NULL) free(itime1); if(itime2!=NULL) free(itime2); if(itime3!=NULL) free(itime3); exit(0); }
the_stack_data/43887555.c
/* C Library for Skeleton 3D Electrostatic PIC Code */ /* Wrappers for calling the Fortran routines from a C main program */ #include <complex.h> double ranorm_(); double randum_(); void distr3_(float *part, float *vtx, float *vty, float *vtz, float *vdx, float *vdy, float *vdz, int *npx, int *npy, int *npz, int *idimp, int *nop, int *nx, int *ny, int *nz, int *ipbc); void gpush3l_(float *part, float *fxyz, float *qbm, float *dt, float *ek, int *idimp, int *nop, int *nx, int *ny, int *nz, int *nxv, int *nyv, int *nzv, int *ipbc); void gpost3l_(float *part, float *q, float *qm, int *nop, int *idimp, int *nxv, int *nyv, int *nzv); void dsortp3yzl_(float *parta, float *partb, int *npic, int *idimp, int *nop, int *ny1, int *nyz1); void cguard3l_(float *fxyz, int *nx, int *ny, int *nz, int *nxe, int *nye, int *nze); void aguard3l_(float *q, int *nx, int *ny, int *nz, int *nxe, int *nye, int *nze); void pois33_(float complex *q, float complex *fxyz, int *isign, float complex *ffc, float *ax, float *ay, float *az, float *affp, float *we, int *nx, int *ny, int *nz, int *nxvh, int *nyv, int *nzv, int *nxhd, int *nyhd, int *nzhd); void wfft3rinit_(int *mixup, float complex *sct, int *indx, int *indy, int *indz, int *nxhyzd, int *nxyzhd); void fft3rxy_(float complex *f, int *isign, int *mixup, float complex *sct, int *indx, int *indy, int *indz, int *nzi, int *nzp, int *nxhd, int *nyd, int *nzd, int *nxhyzd, int *nxyzhd); void fft3rxz_(float complex *f, int *isign, int *mixup, float complex *sct, int *indx, int *indy, int *indz, int *nyi, int *nyp, int *nxhd, int *nyd, int *nzd, int *nxhyzd, int *nxyzhd); void fft3r3xy_(float complex *f, int *isign, int *mixup, float complex *sct, int *indx, int *indy, int *indz, int *nzi, int *nzp, int *nxhd, int *nyd, int *nzd, int *nxhyzd, int *nxyzhd); void fft3r3z_(float complex *f, int *isign, int *mixup, float complex *sct, int *indx, int *indy, int *indz, int *nyi, int *nyp, int *nxhd, int *nyd, int *nzd, int *nxhyzd, int *nxyzhd); void wfft3rx_(float complex *f, int *isign, int *mixup, float complex *sct, int *indx, int *indy, int *indz, int *nxhd, int *nyd, int *nzd, int *nxhyzd, int *nxyzhd); void wfft3r3_(float complex *f, int *isign, int *mixup, float complex *sct, int *indx, int *indy, int *indz, int *nxhd, int *nyd, int *nzd, int *nxhyzd, int *nxyzhd); /* Interfaces to C */ double ranorm() { return ranorm_(); } double randum() { return randum_(); } /*--------------------------------------------------------------------*/ void cdistr3(float part[], float vtx, float vty, float vtz, float vdx, float vdy, float vdz, int npx, int npy, int npz, int idimp, int nop, int nx, int ny, int nz, int ipbc) { distr3_(part,&vtx,&vty,&vtz,&vdx,&vdy,&vdz,&npx,&npy,&npz,&idimp, &nop,&nx,&ny,&nz,&ipbc); return; } /*--------------------------------------------------------------------*/ void cgpush3l(float part[], float fxyz[], float qbm, float dt, float *ek, int idimp, int nop, int nx, int ny, int nz, int nxv, int nyv, int nzv, int ipbc) { gpush3l_(part,fxyz,&qbm,&dt,ek,&idimp,&nop,&nx,&ny,&nz,&nxv,&nyv, &nzv,&ipbc); return; } /*--------------------------------------------------------------------*/ void cgpost3l(float part[], float q[], float qm, int nop, int idimp, int nxv, int nyv, int nzv) { gpost3l_(part,q,&qm,&nop,&idimp,&nxv,&nyv,&nzv); return; } /*--------------------------------------------------------------------*/ void cdsortp3yzl(float parta[], float partb[], int npic[], int idimp, int nop, int ny1, int nyz1) { dsortp3yzl_(parta,partb,npic,&idimp,&nop,&ny1,&nyz1); return; } /*--------------------------------------------------------------------*/ void ccguard3l(float fxyz[], int nx, int ny, int nz, int nxe, int nye, int nze) { cguard3l_(fxyz,&nx,&ny,&nz,&nxe,&nye,&nze); return; } /*--------------------------------------------------------------------*/ void caguard3l(float q[], int nx, int ny, int nz, int nxe, int nye, int nze) { aguard3l_(q,&nx,&ny, &nz,&nxe,&nye,&nze); return; } /*--------------------------------------------------------------------*/ void cpois33(float complex q[], float complex fxyz[], int isign, float complex ffc[], float ax, float ay, float az, float affp, float *we, int nx, int ny, int nz, int nxvh, int nyv, int nzv, int nxhd, int nyhd, int nzhd) { pois33_(q,fxyz,&isign,ffc,&ax,&ay,&az,&affp,we,&nx,&ny,&nz,&nxvh, &nyv,&nzv,&nxhd,&nyhd,&nzhd); return; } /*--------------------------------------------------------------------*/ void cwfft3rinit(int mixup[], float complex sct[], int indx, int indy, int indz, int nxhyzd, int nxyzhd) { wfft3rinit_(mixup,sct,&indx,&indy,&indz,&nxhyzd,&nxyzhd); return; } /*--------------------------------------------------------------------*/ void cfft3rxy(float complex f[], int isign, int mixup[], float complex sct[], int indx, int indy, int indz, int nzi, int nzp, int nxhd, int nyd, int nzd, int nxhyzd, int nxyzhd) { fft3rxy_(f,&isign,mixup,sct,&indx,&indy,&indz,&nzi,&nzp,&nxhd,&nyd, &nzd,&nxhyzd,&nxyzhd); return; } /*--------------------------------------------------------------------*/ void cfft3rxz(float complex f[], int isign, int mixup[], float complex sct[], int indx, int indy, int indz, int nyi, int nyp, int nxhd, int nyd, int nzd, int nxhyzd, int nxyzhd) { fft3rxz_(f,&isign,mixup,sct,&indx,&indy,&indz,&nyi,&nyp,&nxhd,&nyd, &nzd,&nxhyzd,&nxyzhd); return; } /*--------------------------------------------------------------------*/ void cfft3r3xy(float complex f[], int isign, int mixup[], float complex sct[], int indx, int indy, int indz, int nzi, int nzp, int nxhd, int nyd, int nzd, int nxhyzd, int nxyzhd) { fft3r3xy_(f,&isign,mixup,sct,&indx,&indy,&indz,&nzi,&nzp,&nxhd,&nyd, &nzd,&nxhyzd,&nxyzhd); return; } /*--------------------------------------------------------------------*/ void cfft3r3z(float complex f[], int isign, int mixup[], float complex sct[], int indx, int indy, int indz, int nyi, int nyp, int nxhd, int nyd, int nzd, int nxhyzd, int nxyzhd) { fft3r3z_(f,&isign,mixup,sct,&indx,&indy,&indz,&nyi,&nyp,&nxhd,&nyd, &nzd,&nxhyzd,&nxyzhd); return; } /*--------------------------------------------------------------------*/ void cwfft3rx(float complex f[], int isign, int mixup[], float complex sct[], int indx, int indy, int indz, int nxhd, int nyd, int nzd, int nxhyzd, int nxyzhd) { wfft3rx_(f,&isign,mixup,sct,&indx,&indy,&indz,&nxhd,&nyd,&nzd, &nxhyzd,&nxyzhd); return; } /*--------------------------------------------------------------------*/ void cwfft3r3(float complex f[], int isign, int mixup[], float complex sct[], int indx, int indy, int indz, int nxhd, int nyd, int nzd, int nxhyzd, int nxyzhd) { wfft3r3_(f,&isign,mixup,sct,&indx,&indy,&indz,&nxhd,&nyd,&nzd, &nxhyzd,&nxyzhd); return; }
the_stack_data/114941.c
#include <stdio.h> extern int gData; //declaration int display() { return gData ; }
the_stack_data/156392276.c
#include <stdio.h> int main(void) { long long list[41]={0,3,8}; int n; for(int i=3;i<41;i++) list[i]=2*list[i-1]+2*list[i-2]; while(~scanf("%d",&n)) printf("%lld\n",list[n]); return 0; }
the_stack_data/68888578.c
int func3a(void) { return 1; }
the_stack_data/393913.c
/* Exercise 1 - Calculations Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */ #include <stdio.h> int main() { int marks1, marks2; float avg; printf("Enter your marks 1 : "); scanf("%d", &marks1); printf("Enter your marks 2 : "); scanf("%d", &marks2); avg = (marks1 + marks2) / 2.0; printf("Average is %.2f", avg); return 0; }
the_stack_data/67325165.c
#include <stdio.h> #include <string.h> #include <stdlib.h> int main (void) { int n = 0; char *p; while (1) { if ((p = malloc(1<<24)) == NULL) { printf("malloc failure after %d MB\n", n); return 0; } memset (p, 0, (1<<24)); n += 16; printf ("got %d MB\n", n); } }
the_stack_data/145681.c
/* ************************************************************/ /* -- translated by f2c (version of 22 July 1992 22:54:52). */ /* umd Must include math.h before f2c.h - f2c does a #define abs. (Thanks go to Martin Wauchope for providing this correction) We manually included AT&T's f2c.h in this source file, i.e. it does not have to be present separately in order to compile. */ #include <math.h> /* CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC !!!! NOTICE !!!! 1. The routines contained in this file are due to Prof. K.Schittkowski of the University of Bayreuth, Germany (modification of routines due to Prof. MJD Powell at the University of Cambridge). They can be freely distributed. 2. A few minor modifications were performed at the University of Maryland. They are marked in the code by "umd". A.L. Tits, J.L. Zhou, and Craig Lawrence University of Maryland *********************************************************************** SOLUTION OF QUADRATIC PROGRAMMING PROBLEMS QL0001 SOLVES THE QUADRATIC PROGRAMMING PROBLEM MINIMIZE .5*X'*C*X + D'*X SUBJECT TO A(J)*X + B(J) = 0 , J=1,...,ME A(J)*X + B(J) >= 0 , J=ME+1,...,M XL <= X <= XU HERE C MUST BE AN N BY N SYMMETRIC AND POSITIVE MATRIX, D AN N-DIMENSIONAL VECTOR, A AN M BY N MATRIX AND B AN M-DIMENSIONAL VECTOR. THE ABOVE SITUATION IS INDICATED BY IWAR(1)=1. ALTERNATIVELY, I.E. IF IWAR(1)=0, THE OBJECTIVE FUNCTION MATRIX CAN ALSO BE PROVIDED IN FACTORIZED FORM. IN THIS CASE, C IS AN UPPER TRIANGULAR MATRIX. THE SUBROUTINE REORGANIZES SOME DATA SO THAT THE PROBLEM CAN BE SOLVED BY A MODIFICATION OF AN ALGORITHM PROPOSED BY POWELL (1983). USAGE: QL0001(M,ME,MMAX,N,NMAX,MNN,C,D,A,B,XL,XU,X,U,IOUT,IFAIL,IPRINT, WAR,LWAR,IWAR,LIWAR) DEFINITION OF THE PARAMETERS: M : TOTAL NUMBER OF CONSTRAINTS. ME : NUMBER OF EQUALITY CONSTRAINTS. MMAX : ROW DIMENSION OF A. MMAX MUST BE AT LEAST ONE AND GREATER THAN M. N : NUMBER OF VARIABLES. NMAX : ROW DIMENSION OF C. NMAX MUST BE GREATER OR EQUAL TO N. MNN : MUST BE EQUAL TO M + N + N. C(NMAX,NMAX): OBJECTIVE FUNCTION MATRIX WHICH SHOULD BE SYMMETRIC AND POSITIVE DEFINITE. IF IWAR(1) = 0, C IS SUPPOSED TO BE THE CHOLESKEY-FACTOR OF ANOTHER MATRIX, I.E. C IS UPPER TRIANGULAR. D(NMAX) : CONTAINS THE CONSTANT VECTOR OF THE OBJECTIVE FUNCTION. A(MMAX,NMAX): CONTAINS THE DATA MATRIX OF THE LINEAR CONSTRAINTS. B(MMAX) : CONTAINS THE CONSTANT DATA OF THE LINEAR CONSTRAINTS. XL(N),XU(N): CONTAIN THE LOWER AND UPPER BOUNDS FOR THE VARIABLES. X(N) : ON RETURN, X CONTAINS THE OPTIMAL SOLUTION VECTOR. U(MNN) : ON RETURN, U CONTAINS THE LAGRANGE MULTIPLIERS. THE FIRST M POSITIONS ARE RESERVED FOR THE MULTIPLIERS OF THE M LINEAR CONSTRAINTS AND THE SUBSEQUENT ONES FOR THE MULTIPLIERS OF THE LOWER AND UPPER BOUNDS. ON SUCCESSFUL TERMINATION, ALL VALUES OF U WITH RESPECT TO INEQUALITIES AND BOUNDS SHOULD BE GREATER OR EQUAL TO ZERO. IOUT : INTEGER INDICATING THE DESIRED OUTPUT UNIT NUMBER, I.E. ALL WRITE-STATEMENTS START WITH 'WRITE(IOUT,... '. IFAIL : SHOWS THE TERMINATION REASON. IFAIL = 0 : SUCCESSFUL RETURN. IFAIL = 1 : TOO MANY ITERATIONS (MORE THAN 40*(N+M)). IFAIL = 2 : ACCURACY INSUFFICIENT TO SATISFY CONVERGENCE CRITERION. IFAIL = 5 : LENGTH OF A WORKING ARRAY IS TOO SHORT. IFAIL > 10 : THE CONSTRAINTS ARE INCONSISTENT. IPRINT : OUTPUT CONTROL. IPRINT = 0 : NO OUTPUT OF QL0001. IPRINT > 0 : BRIEF OUTPUT IN ERROR CASES. WAR(LWAR) : REAL WORKING ARRAY. THE LENGTH LWAR SHOULD BE GRATER THAN 3*NMAX*NMAX/2 + 10*NMAX + 2*MMAX. IWAR(LIWAR): INTEGER WORKING ARRAY. THE LENGTH LIWAR SHOULD BE AT LEAST N. IF IWAR(1)=0 INITIALLY, THEN THE CHOLESKY DECOMPOSITION WHICH IS REQUIRED BY THE DUAL ALGORITHM TO GET THE FIRST UNCONSTRAINED MINIMUM OF THE OBJECTIVE FUNCTION, IS PERFORMED INTERNALLY. OTHERWISE, I.E. IF IWAR(1)=1, THEN IT IS ASSUMED THAT THE USER PROVIDES THE INITIAL FAC- TORIZATION BY HIMSELF AND STORES IT IN THE UPPER TRIAN- GULAR PART OF THE ARRAY C. A NAMED COMMON-BLOCK /CMACHE/EPS MUST BE PROVIDED BY THE USER, WHERE EPS DEFINES A GUESS FOR THE UNDERLYING MACHINE PRECISION. AUTHOR: K. SCHITTKOWSKI, MATHEMATISCHES INSTITUT, UNIVERSITAET BAYREUTH, 8580 BAYREUTH, GERMANY, F.R. VERSION: 1.4 (MARCH, 1987) */ /* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE typedef int integer; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; typedef long int logical; typedef short int shortlogical; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ #ifdef f2c_i2 /* for -i2 */ typedef short flag; typedef short ftnlen; typedef short ftnint; #else typedef long flag; typedef long ftnlen; typedef long ftnint; #endif /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ shortint h; integer i; real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; typedef long Long; struct Vardesc { /* for Namelist */ char *name; char *addr; Long *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (doublereal)abs(x) #define min(a,b) ((a) <= (b) ? (a) : (b)) #define max(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (doublereal)min(a,b) #define dmax(a,b) (doublereal)max(a,b) /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef int /* Unknown procedure type */ (*U_fp)(...); typedef shortint (*J_fp)(...); typedef integer (*I_fp)(...); typedef real (*R_fp)(...); typedef doublereal (*D_fp)(...), (*E_fp)(...); typedef /* Complex */ VOID (*C_fp)(...); typedef /* Double Complex */ VOID (*Z_fp)(...); typedef logical (*L_fp)(...); typedef shortlogical (*K_fp)(...); typedef /* Character */ VOID (*H_fp)(...); typedef /* Subroutine */ int (*S_fp)(...); #else typedef int /* Unknown procedure type */ (*U_fp)(); typedef shortint (*J_fp)(); typedef integer (*I_fp)(); typedef real (*R_fp)(); typedef doublereal (*D_fp)(), (*E_fp)(); typedef /* Complex */ VOID (*C_fp)(); typedef /* Double Complex */ VOID (*Z_fp)(); typedef logical (*L_fp)(); typedef shortlogical (*K_fp)(); typedef /* Character */ VOID (*H_fp)(); typedef /* Subroutine */ int (*S_fp)(); #endif /* E_fp is for real functions when -R is not specified */ typedef VOID C_f; /* complex function */ typedef VOID H_f; /* character function */ typedef VOID Z_f; /* double complex function */ typedef doublereal E_f; /* real function with -R not specified */ /* undef any lower-case symbols that your C compiler predefines, e.g.: */ #ifndef Skip_f2c_Undefs #undef cray #undef gcos #undef mc68010 #undef mc68020 #undef mips #undef pdp11 #undef sgi #undef sparc #undef sun #undef sun2 #undef sun3 #undef sun4 #undef u370 #undef u3b #undef u3b2 #undef u3b5 #undef unix #undef vax #endif #endif /* Common Block Declarations */ struct { doublereal eps; } cmache_; #define cmache_1 cmache_ /* Table of constant values */ static integer c__1 = 1; /* umd */ /* ql0002_ is declared here to provide ANSI C compliance. (Thanks got to Martin Wauchope for providing this correction) */ #ifdef __STDC__ int ql0002_(integer *n,integer *m,integer *meq,integer *mmax, integer *mn,integer *mnn,integer *nmax, logical *lql, doublereal *a,doublereal *b,doublereal *grad, doublereal *g,doublereal *xl,doublereal *xu,doublereal *x, integer *nact,integer *iact,integer *maxit, doublereal *vsmall, integer *info, doublereal *diag, doublereal *w, integer *lw); #else int ql0002_(); #endif /* umd */ /* When the fortran code was f2c converted, the use of fortran COMMON blocks was no longer available. Thus an additional variable, eps1, was added to the parameter list to account for this. */ /* umd */ /* Two alternative definitions are provided in order to give ANSI compliance. */ #ifdef __STDC__ int ql0001_(int *m,int *me,int *mmax,int *n,int *nmax,int *mnn, double *c,double *d,double *a,double *b,double *xl, double *xu,double *x,double *u,int *iout,int *ifail, int *iprint,double *war,int *lwar,int *iwar,int *liwar, double *eps1) #else /* Subroutine */ int ql0001_(m, me, mmax, n, nmax, mnn, c, d, a, b, xl, xu, x, u, iout, ifail, iprint, war, lwar, iwar, liwar, eps1) integer *m, *me, *mmax, *n, *nmax, *mnn; doublereal *c, *d, *a, *b, *xl, *xu, *x, *u; integer *iout, *ifail, *iprint; doublereal *war; integer *lwar, *iwar, *liwar; doublereal *eps1; #endif { /* Format strings */ static char fmt_1000[] = "(/8x,\002***QL: MATRIX G WAS ENLARGED\002,i3\ ,\002-TIMES BY UNITMATRIX\002)"; static char fmt_1100[] = "(/8x,\002***QL: CONSTRAINT \002,i5,\002 NOT CO\ NSISTENT TO \002,/,(10x,10i5))"; static char fmt_1200[] = "(/8x,\002***QL: LWAR TOO SMALL\002)"; static char fmt_1210[] = "(/8x,\002***QL: LIWAR TOO SMALL\002)"; static char fmt_1220[] = "(/8x,\002***QL: MNN TOO SMALL\002)"; static char fmt_1300[] = "(/8x,\002***QL: TOO MANY ITERATIONS (MORE THA\ N\002,i6,\002)\002)"; static char fmt_1400[] = "(/8x,\002***QL: ACCURACY INSUFFICIENT TO ATTAI\ N CONVERGENCE\002)"; /* System generated locals */ integer c_dim1, c_offset, a_dim1, a_offset, i__1, i__2; /* Builtin functions */ /* integer s_wsfe(), do_fio(), e_wsfe(); */ /* Local variables */ static doublereal diag; /* extern int ql0002_(); */ static integer nact, info; static doublereal zero; static integer i, j, idiag, maxit; static doublereal qpeps; static integer in, mn, lw; static doublereal ten; static logical lql; static integer inw1, inw2; /* Fortran I/O blocks */ static cilist io___16 = { 0, 0, 0, fmt_1000, 0 }; static cilist io___18 = { 0, 0, 0, fmt_1100, 0 }; static cilist io___19 = { 0, 0, 0, fmt_1200, 0 }; static cilist io___20 = { 0, 0, 0, fmt_1210, 0 }; static cilist io___21 = { 0, 0, 0, fmt_1220, 0 }; static cilist io___22 = { 0, 0, 0, fmt_1300, 0 }; static cilist io___23 = { 0, 0, 0, fmt_1400, 0 }; /* INTRINSIC FUNCTIONS: DSQRT */ /* Parameter adjustments */ --iwar; --war; --u; --x; --xu; --xl; --b; a_dim1 = *mmax; a_offset = a_dim1 + 1; a -= a_offset; --d; c_dim1 = *nmax; c_offset = c_dim1 + 1; c -= c_offset; /* Function Body */ cmache_1.eps = *eps1; /* CONSTANT DATA */ /* ################################################################# */ if (fabs(c[*nmax + *nmax * c_dim1]) == 0.e0) { c[*nmax + *nmax * c_dim1] = cmache_1.eps; } /* umd */ /* This prevents a subsequent more major modification of the Hessian */ /* matrix in the important case when a minmax problem (yielding a */ /* singular Hessian matrix) is being solved. */ /* ----UMCP, April 1991, Jian L. Zhou */ /* ################################################################# */ lql = FALSE_; if (iwar[1] == 1) { lql = TRUE_; } zero = 0.; ten = 10.; maxit = (*m + *n) * 40; qpeps = cmache_1.eps; inw1 = 1; inw2 = inw1 + *mmax; /* PREPARE PROBLEM DATA FOR EXECUTION */ if (*m <= 0) { goto L20; } in = inw1; i__1 = *m; for (j = 1; j <= i__1; ++j) { war[in] = -b[j]; /* L10: */ ++in; } L20: lw = *nmax * 3 * *nmax / 2 + *nmax * 10 + *m; if (inw2 + lw > *lwar) { goto L80; } if (*liwar < *n) { goto L81; } if (*mnn < *m + *n + *n) { goto L82; } mn = *m + *n; /* CALL OF QL0002 */ ql0002_(n, m, me, mmax, &mn, mnn, nmax, &lql, &a[a_offset], &war[inw1], & d[1], &c[c_offset], &xl[1], &xu[1], &x[1], &nact, &iwar[1], & maxit, &qpeps, &info, &diag, &war[inw2], &lw); /* TEST OF MATRIX CORRECTIONS */ *ifail = 0; if (info == 1) { goto L40; } if (info == 2) { goto L90; } idiag = 0; if (diag > zero && diag < 1e3) { idiag = (integer) diag; } /* if (*iprint > 0 && idiag > 0) { io___16.ciunit = *iout; s_wsfe(&io___16); do_fio(&c__1, (char *)&idiag, (ftnlen)sizeof(integer)); e_wsfe(); } */ if (info < 0) { goto L70; } /* REORDER MULTIPLIER */ i__1 = *mnn; for (j = 1; j <= i__1; ++j) { /* L50: */ u[j] = zero; } in = inw2 - 1; if (nact == 0) { goto L30; } i__1 = nact; for (i = 1; i <= i__1; ++i) { j = iwar[i]; u[j] = war[in + i]; /* L60: */ } L30: return 0; /* ERROR MESSAGES */ L70: *ifail = -info + 10; /* if (*iprint > 0 && nact > 0) { io___18.ciunit = *iout; s_wsfe(&io___18); i__1 = -info; do_fio(&c__1, (char *)&i__1, (ftnlen)sizeof(integer)); i__2 = nact; for (i = 1; i <= i__2; ++i) { do_fio(&c__1, (char *)&iwar[i], (ftnlen)sizeof(integer)); } e_wsfe(); } */ return 0; L80: *ifail = 5; /* if (*iprint > 0) { io___19.ciunit = *iout; s_wsfe(&io___19); e_wsfe(); } */ return 0; L81: *ifail = 5; /* if (*iprint > 0) { io___20.ciunit = *iout; s_wsfe(&io___20); e_wsfe(); } */ return 0; L82: *ifail = 5; /* if (*iprint > 0) { io___21.ciunit = *iout; s_wsfe(&io___21); e_wsfe(); } */ return 0; L40: *ifail = 1; /* if (*iprint > 0) { io___22.ciunit = *iout; s_wsfe(&io___22); do_fio(&c__1, (char *)&maxit, (ftnlen)sizeof(integer)); e_wsfe(); } */ return 0; L90: *ifail = 2; /* if (*iprint > 0) { io___23.ciunit = *iout; s_wsfe(&io___23); e_wsfe(); } */ return 0; /* FORMAT-INSTRUCTIONS */ } /* ql0001_ */ /* umd Two alternative definitions are provided in order to give ANSI compliance. (Thanks got to Martin Wauchope for providing this correction) */ #ifdef __STDC__ int ql0002_(integer *n,integer *m,integer *meq,integer *mmax, integer *mn,integer *mnn,integer *nmax, logical *lql, doublereal *a,doublereal *b,doublereal *grad, doublereal *g,doublereal *xl,doublereal *xu,doublereal *x, integer *nact,integer *iact,integer *maxit, doublereal *vsmall, integer *info, doublereal *diag, doublereal *w, integer *lw) #else /* Subroutine */ int ql0002_(n, m, meq, mmax, mn, mnn, nmax, lql, a, b, grad, g, xl, xu, x, nact, iact, maxit, vsmall, info, diag, w, lw) integer *n, *m, *meq, *mmax, *mn, *mnn, *nmax; logical *lql; doublereal *a, *b, *grad, *g, *xl, *xu, *x; integer *nact, *iact, *maxit; doublereal *vsmall; integer *info; doublereal *diag, *w; integer *lw; #endif { /* System generated locals */ integer a_dim1, a_offset, g_dim1, g_offset, i__1, i__2, i__3, i__4; doublereal d__1, d__2, d__3, d__4; /* Builtin functions */ /* umd */ /* double sqrt(); */ /* Local variables */ static doublereal onha, xmag, suma, sumb, sumc, temp, step, zero; static integer iwwn; static doublereal sumx, sumy; static integer i, j, k; static doublereal fdiff; static integer iflag, jflag, kflag, lflag; static doublereal diagr; static integer ifinc, kfinc, jfinc, mflag, nflag; static doublereal vfact, tempa; static integer iterc, itref; static doublereal cvmax, ratio, xmagr; static integer kdrop; static logical lower; static integer knext, k1; static doublereal ga, gb; static integer ia, id; static doublereal fdiffa; static integer ii, il, kk, jl, ip, ir, nm, is, iu, iw, ju, ix, iz, nu, iy; static doublereal parinc, parnew; static integer ira, irb, iwa; static doublereal one; static integer iwd, iza; static doublereal res; static integer ipp, iwr, iws; static doublereal sum; static integer iww, iwx, iwy; static doublereal two; static integer iwz; /* WHETHER THE CONSTRAINT IS ACTIVE. */ /* AUTHOR: K. SCHITTKOWSKI, */ /* MATHEMATISCHES INSTITUT, */ /* UNIVERSITAET BAYREUTH, */ /* 8580 BAYREUTH, */ /* GERMANY, F.R. */ /* AUTHOR OF ORIGINAL VERSION: */ /* M.J.D. POWELL, DAMTP, */ /* UNIVERSITY OF CAMBRIDGE, SILVER STREET */ /* CAMBRIDGE, */ /* ENGLAND */ /* REFERENCE: M.J.D. POWELL: ZQPCVX, A FORTRAN SUBROUTINE FOR CONVEX */ /* PROGRAMMING, REPORT DAMTP/1983/NA17, UNIVERSITY OF */ /* CAMBRIDGE, ENGLAND, 1983. */ /* VERSION : 2.0 (MARCH, 1987) */ /************************************************************************ ***/ /* INTRINSIC FUNCTIONS: DMAX1,DSQRT,DABS,DMIN1 */ /* INITIAL ADDRESSES */ /* Parameter adjustments */ --w; --iact; --x; --xu; --xl; g_dim1 = *nmax; g_offset = g_dim1 + 1; g -= g_offset; --grad; --b; a_dim1 = *mmax; a_offset = a_dim1 + 1; a -= a_offset; /* Function Body */ iwz = *nmax; iwr = iwz + *nmax * *nmax; iww = iwr + *nmax * (*nmax + 3) / 2; iwd = iww + *nmax; iwx = iwd + *nmax; iwa = iwx + *nmax; /* SET SOME CONSTANTS. */ zero = 0.; one = 1.; two = 2.; onha = 1.5; vfact = 1.; /* SET SOME PARAMETERS. */ /* NUMBER LESS THAN VSMALL ARE ASSUMED TO BE NEGLIGIBLE. */ /* THE MULTIPLE OF I THAT IS ADDED TO G IS AT MOST DIAGR TIMES */ /* THE LEAST MULTIPLE OF I THAT GIVES POSITIVE DEFINITENESS. */ /* X IS RE-INITIALISED IF ITS MAGNITUDE IS REDUCED BY THE */ /* FACTOR XMAGR. */ /* A CHECK IS MADE FOR AN INCREASE IN F EVERY IFINC ITERATIONS, */ /* AFTER KFINC ITERATIONS ARE COMPLETED. */ diagr = two; xmagr = .01; ifinc = 3; kfinc = max(10,*n); /* FIND THE RECIPROCALS OF THE LENGTHS OF THE CONSTRAINT NORMALS. */ /* RETURN IF A CONSTRAINT IS INFEASIBLE DUE TO A ZERO NORMAL. */ *nact = 0; if (*m <= 0) { goto L45; } i__1 = *m; for (k = 1; k <= i__1; ++k) { sum = zero; i__2 = *n; for (i = 1; i <= i__2; ++i) { /* L10: */ /* Computing 2nd power */ d__1 = a[k + i * a_dim1]; sum += d__1 * d__1; } if (sum > zero) { goto L20; } if (b[k] == zero) { goto L30; } *info = -k; if (k <= *meq) { goto L730; } if (b[k] <= 0.) { goto L30; } else { goto L730; } L20: sum = one / sqrt(sum); L30: ia = iwa + k; /* L40: */ w[ia] = sum; } L45: i__1 = *n; for (k = 1; k <= i__1; ++k) { ia = iwa + *m + k; /* L50: */ w[ia] = one; } /* IF NECESSARY INCREASE THE DIAGONAL ELEMENTS OF G. */ if (! (*lql)) { goto L165; } *diag = zero; i__1 = *n; for (i = 1; i <= i__1; ++i) { id = iwd + i; w[id] = g[i + i * g_dim1]; /* Computing MAX */ d__1 = *diag, d__2 = *vsmall - w[id]; *diag = max(d__1,d__2); if (i == *n) { goto L60; } ii = i + 1; i__2 = *n; for (j = ii; j <= i__2; ++j) { /* Computing MIN */ d__1 = w[id], d__2 = g[j + j * g_dim1]; ga = -min(d__1,d__2); gb = (d__1 = w[id] - g[j + j * g_dim1], abs(d__1)) + (d__2 = g[i + j * g_dim1], abs(d__2)); if (gb > zero) { /* Computing 2nd power */ d__1 = g[i + j * g_dim1]; ga += d__1 * d__1 / gb; } /* L55: */ *diag = max(*diag,ga); } L60: ; } if (*diag <= zero) { goto L90; } L70: *diag = diagr * *diag; i__1 = *n; for (i = 1; i <= i__1; ++i) { id = iwd + i; /* L80: */ g[i + i * g_dim1] = *diag + w[id]; } /* FORM THE CHOLESKY FACTORISATION OF G. THE TRANSPOSE */ /* OF THE FACTOR WILL BE PLACED IN THE R-PARTITION OF W. */ L90: ir = iwr; i__1 = *n; for (j = 1; j <= i__1; ++j) { ira = iwr; irb = ir + 1; i__2 = j; for (i = 1; i <= i__2; ++i) { temp = g[i + j * g_dim1]; if (i == 1) { goto L110; } i__3 = ir; for (k = irb; k <= i__3; ++k) { ++ira; /* L100: */ temp -= w[k] * w[ira]; } L110: ++ir; ++ira; if (i < j) { w[ir] = temp / w[ira]; } /* L120: */ } if (temp < *vsmall) { goto L140; } /* L130: */ w[ir] = sqrt(temp); } goto L170; /* INCREASE FURTHER THE DIAGONAL ELEMENT OF G. */ L140: w[j] = one; sumx = one; k = j; L150: sum = zero; ira = ir - 1; i__1 = j; for (i = k; i <= i__1; ++i) { sum -= w[ira] * w[i]; /* L160: */ ira += i; } ir -= k; --k; w[k] = sum / w[ir]; /* Computing 2nd power */ d__1 = w[k]; sumx += d__1 * d__1; if (k >= 2) { goto L150; } *diag = *diag + *vsmall - temp / sumx; goto L70; /* STORE THE CHOLESKY FACTORISATION IN THE R-PARTITION */ /* OF W. */ L165: ir = iwr; i__1 = *n; for (i = 1; i <= i__1; ++i) { i__2 = i; for (j = 1; j <= i__2; ++j) { ++ir; /* L166: */ w[ir] = g[j + i * g_dim1]; } } /* SET Z THE INVERSE OF THE MATRIX IN R. */ L170: nm = *n - 1; i__2 = *n; for (i = 1; i <= i__2; ++i) { iz = iwz + i; if (i == 1) { goto L190; } i__1 = i; for (j = 2; j <= i__1; ++j) { w[iz] = zero; /* L180: */ iz += *n; } L190: ir = iwr + (i + i * i) / 2; w[iz] = one / w[ir]; if (i == *n) { goto L220; } iza = iz; i__1 = nm; for (j = i; j <= i__1; ++j) { ir += i; sum = zero; i__3 = iz; i__4 = *n; for (k = iza; i__4 < 0 ? k >= i__3 : k <= i__3; k += i__4) { sum += w[k] * w[ir]; /* L200: */ ++ir; } iz += *n; /* L210: */ w[iz] = -sum / w[ir]; } L220: ; } /* SET THE INITIAL VALUES OF SOME VARIABLES. */ /* ITERC COUNTS THE NUMBER OF ITERATIONS. */ /* ITREF IS SET TO ONE WHEN ITERATIVE REFINEMENT IS REQUIRED. */ /* JFINC INDICATES WHEN TO TEST FOR AN INCREASE IN F. */ iterc = 1; itref = 0; jfinc = -kfinc; /* SET X TO ZERO AND SET THE CORRESPONDING RESIDUALS OF THE */ /* KUHN-TUCKER CONDITIONS. */ L230: iflag = 1; iws = iww - *n; i__2 = *n; for (i = 1; i <= i__2; ++i) { x[i] = zero; /* aha! Dxd 5-1-99 */ iw = iww + i; w[iw] = grad[i]; if (i > *nact) { goto L240; } w[i] = zero; is = iws + i; k = iact[i]; if (k <= *m) { goto L235; } if (k > *mn) { goto L234; } k1 = k - *m; w[is] = xl[k1]; goto L240; L234: k1 = k - *mn; w[is] = -xu[k1]; goto L240; L235: w[is] = b[k]; L240: ; } xmag = zero; vfact = 1.; if (*nact <= 0) { goto L340; } else { goto L280; } /* SET THE RESIDUALS OF THE KUHN-TUCKER CONDITIONS FOR GENERAL X. */ L250: iflag = 2; iws = iww - *n; i__2 = *n; for (i = 1; i <= i__2; ++i) { iw = iww + i; w[iw] = grad[i]; if (*lql) { goto L259; } id = iwd + i; w[id] = zero; i__1 = *n; for (j = i; j <= i__1; ++j) { /* L251: */ w[id] += g[i + j * g_dim1] * x[j]; } i__1 = i; for (j = 1; j <= i__1; ++j) { id = iwd + j; /* L252: */ w[iw] += g[j + i * g_dim1] * w[id]; } goto L260; L259: i__1 = *n; for (j = 1; j <= i__1; ++j) { /* L261: */ w[iw] += g[i + j * g_dim1] * x[j]; } L260: ; } if (*nact == 0) { goto L340; } i__2 = *nact; for (k = 1; k <= i__2; ++k) { kk = iact[k]; is = iws + k; if (kk > *m) { goto L265; } w[is] = b[kk]; i__1 = *n; for (i = 1; i <= i__1; ++i) { iw = iww + i; w[iw] -= w[k] * a[kk + i * a_dim1]; /* L264: */ w[is] -= x[i] * a[kk + i * a_dim1]; } goto L270; L265: if (kk > *mn) { goto L266; } k1 = kk - *m; iw = iww + k1; w[iw] -= w[k]; w[is] = xl[k1] - x[k1]; goto L270; L266: k1 = kk - *mn; iw = iww + k1; w[iw] += w[k]; w[is] = -xu[k1] + x[k1]; L270: ; } /* PRE-MULTIPLY THE VECTOR IN THE S-PARTITION OF W BY THE */ /* INVERS OF R TRANSPOSE. */ L280: ir = iwr; ip = iww + 1; ipp = iww + *n; il = iws + 1; iu = iws + *nact; i__2 = iu; for (i = il; i <= i__2; ++i) { sum = zero; if (i == il) { goto L300; } ju = i - 1; i__1 = ju; for (j = il; j <= i__1; ++j) { ++ir; /* L290: */ sum += w[ir] * w[j]; } L300: ++ir; /* L310: */ w[i] = (w[i] - sum) / w[ir]; } /* SHIFT X TO SATISFY THE ACTIVE CONSTRAINTS AND MAKE THE */ /* CORRESPONDING CHANGE TO THE GRADIENT RESIDUALS. */ i__2 = *n; for (i = 1; i <= i__2; ++i) { iz = iwz + i; sum = zero; i__1 = iu; for (j = il; j <= i__1; ++j) { sum += w[j] * w[iz]; /* L320: */ iz += *n; } x[i] += sum; if (*lql) { goto L329; } id = iwd + i; w[id] = zero; i__1 = *n; for (j = i; j <= i__1; ++j) { /* L321: */ w[id] += g[i + j * g_dim1] * sum; } iw = iww + i; i__1 = i; for (j = 1; j <= i__1; ++j) { id = iwd + j; /* L322: */ w[iw] += g[j + i * g_dim1] * w[id]; } goto L330; L329: i__1 = *n; for (j = 1; j <= i__1; ++j) { iw = iww + j; /* L331: */ w[iw] += sum * g[i + j * g_dim1]; } L330: ; } /* FORM THE SCALAR PRODUCT OF THE CURRENT GRADIENT RESIDUALS */ /* WITH EACH COLUMN OF Z. */ L340: kflag = 1; goto L930; L350: if (*nact == *n) { goto L380; } /* SHIFT X SO THAT IT SATISFIES THE REMAINING KUHN-TUCKER */ /* CONDITIONS. */ il = iws + *nact + 1; iza = iwz + *nact * *n; i__2 = *n; for (i = 1; i <= i__2; ++i) { sum = zero; iz = iza + i; i__1 = iww; for (j = il; j <= i__1; ++j) { sum += w[iz] * w[j]; /* L360: */ iz += *n; } /* L370: */ x[i] -= sum; } *info = 0; if (*nact == 0) { goto L410; } /* UPDATE THE LAGRANGE MULTIPLIERS. */ L380: lflag = 3; goto L740; L390: i__2 = *nact; for (k = 1; k <= i__2; ++k) { iw = iww + k; /* L400: */ w[k] += w[iw]; } /* REVISE THE VALUES OF XMAG. */ /* BRANCH IF ITERATIVE REFINEMENT IS REQUIRED. */ L410: jflag = 1; goto L910; L420: if (iflag == itref) { goto L250; } /* DELETE A CONSTRAINT IF A LAGRANGE MULTIPLIER OF AN */ /* INEQUALITY CONSTRAINT IS NEGATIVE. */ kdrop = 0; goto L440; L430: ++kdrop; if (w[kdrop] >= zero) { goto L440; } if (iact[kdrop] <= *meq) { goto L440; } nu = *nact; mflag = 1; goto L800; L440: if (kdrop < *nact) { goto L430; } /* SEEK THE GREATEAST NORMALISED CONSTRAINT VIOLATION, DISREGARDING */ /* ANY THAT MAY BE DUE TO COMPUTER ROUNDING ERRORS. */ L450: cvmax = zero; if (*m <= 0) { goto L481; } i__2 = *m; for (k = 1; k <= i__2; ++k) { ia = iwa + k; if (w[ia] <= zero) { goto L480; } sum = -b[k]; i__1 = *n; for (i = 1; i <= i__1; ++i) { /* L460: */ sum += x[i] * a[k + i * a_dim1]; } sumx = -sum * w[ia]; if (k <= *meq) { sumx = abs(sumx); } if (sumx <= cvmax) { goto L480; } temp = (d__1 = b[k], abs(d__1)); i__1 = *n; for (i = 1; i <= i__1; ++i) { /* L470: */ temp += (d__1 = x[i] * a[k + i * a_dim1], abs(d__1)); } tempa = temp + abs(sum); if (tempa <= temp) { goto L480; } temp += onha * abs(sum); if (temp <= tempa) { goto L480; } cvmax = sumx; res = sum; knext = k; L480: ; } L481: i__2 = *n; for (k = 1; k <= i__2; ++k) { lower = TRUE_; ia = iwa + *m + k; if (w[ia] <= zero) { goto L485; } sum = xl[k] - x[k]; if (sum < 0.) { goto L482; } else if (sum == 0) { goto L485; } else { goto L483; } L482: sum = x[k] - xu[k]; lower = FALSE_; L483: if (sum <= cvmax) { goto L485; } cvmax = sum; res = -sum; knext = k + *m; if (lower) { goto L485; } knext = k + *mn; L485: ; } /* TEST FOR CONVERGENCE */ *info = 0; if (cvmax <= *vsmall) { goto L700; } /* RETURN IF, DUE TO ROUNDING ERRORS, THE ACTUAL CHANGE IN */ /* X MAY NOT INCREASE THE OBJECTIVE FUNCTION */ ++jfinc; if (jfinc == 0) { goto L510; } if (jfinc != ifinc) { goto L530; } fdiff = zero; fdiffa = zero; i__2 = *n; for (i = 1; i <= i__2; ++i) { sum = two * grad[i]; sumx = abs(sum); if (*lql) { goto L489; } id = iwd + i; w[id] = zero; i__1 = *n; for (j = i; j <= i__1; ++j) { ix = iwx + j; /* L486: */ w[id] += g[i + j * g_dim1] * (w[ix] + x[j]); } i__1 = i; for (j = 1; j <= i__1; ++j) { id = iwd + j; temp = g[j + i * g_dim1] * w[id]; sum += temp; /* L487: */ sumx += abs(temp); } goto L495; L489: i__1 = *n; for (j = 1; j <= i__1; ++j) { ix = iwx + j; temp = g[i + j * g_dim1] * (w[ix] + x[j]); sum += temp; /* L490: */ sumx += abs(temp); } L495: ix = iwx + i; fdiff += sum * (x[i] - w[ix]); /* L500: */ fdiffa += sumx * (d__1 = x[i] - w[ix], abs(d__1)); } *info = 2; sum = fdiffa + fdiff; if (sum <= fdiffa) { goto L700; } temp = fdiffa + onha * fdiff; if (temp <= sum) { goto L700; } jfinc = 0; *info = 0; L510: i__2 = *n; for (i = 1; i <= i__2; ++i) { ix = iwx + i; /* L520: */ w[ix] = x[i]; } /* FORM THE SCALAR PRODUCT OF THE NEW CONSTRAINT NORMAL WITH EACH */ /* COLUMN OF Z. PARNEW WILL BECOME THE LAGRANGE MULTIPLIER OF */ /* THE NEW CONSTRAINT. */ L530: ++iterc; if (iterc <= *maxit) { goto L531; } *info = 1; goto L710; L531: iws = iwr + (*nact + *nact * *nact) / 2; if (knext > *m) { goto L541; } i__2 = *n; for (i = 1; i <= i__2; ++i) { iw = iww + i; /* L540: */ w[iw] = a[knext + i * a_dim1]; } goto L549; L541: i__2 = *n; for (i = 1; i <= i__2; ++i) { iw = iww + i; /* L542: */ w[iw] = zero; } k1 = knext - *m; if (k1 > *n) { goto L545; } iw = iww + k1; w[iw] = one; iz = iwz + k1; i__2 = *n; for (i = 1; i <= i__2; ++i) { is = iws + i; w[is] = w[iz]; /* L543: */ iz += *n; } goto L550; L545: k1 = knext - *mn; iw = iww + k1; w[iw] = -one; iz = iwz + k1; i__2 = *n; for (i = 1; i <= i__2; ++i) { is = iws + i; w[is] = -w[iz]; /* L546: */ iz += *n; } goto L550; L549: kflag = 2; goto L930; L550: parnew = zero; /* APPLY GIVENS ROTATIONS TO MAKE THE LAST (N-NACT-2) SCALAR */ /* PRODUCTS EQUAL TO ZERO. */ if (*nact == *n) { goto L570; } nu = *n; nflag = 1; goto L860; /* BRANCH IF THERE IS NO NEED TO DELETE A CONSTRAINT. */ L560: is = iws + *nact; if (*nact == 0) { goto L640; } suma = zero; sumb = zero; sumc = zero; iz = iwz + *nact * *n; i__2 = *n; for (i = 1; i <= i__2; ++i) { ++iz; iw = iww + i; suma += w[iw] * w[iz]; sumb += (d__1 = w[iw] * w[iz], abs(d__1)); /* L563: */ /* Computing 2nd power */ d__1 = w[iz]; sumc += d__1 * d__1; } temp = sumb + abs(suma) * .1; tempa = sumb + abs(suma) * .2; if (temp <= sumb) { goto L570; } if (tempa <= temp) { goto L570; } if (sumb > *vsmall) { goto L5; } goto L570; L5: sumc = sqrt(sumc); ia = iwa + knext; if (knext <= *m) { sumc /= w[ia]; } temp = sumc + abs(suma) * .1; tempa = sumc + abs(suma) * .2; if (temp <= sumc) { goto L567; } if (tempa <= temp) { goto L567; } goto L640; /* CALCULATE THE MULTIPLIERS FOR THE NEW CONSTRAINT NORMAL */ /* EXPRESSED IN TERMS OF THE ACTIVE CONSTRAINT NORMALS. */ /* THEN WORK OUT WHICH CONTRAINT TO DROP. */ L567: lflag = 4; goto L740; L570: lflag = 1; goto L740; /* COMPLETE THE TEST FOR LINEARLY DEPENDENT CONSTRAINTS. */ L571: if (knext > *m) { goto L574; } i__2 = *n; for (i = 1; i <= i__2; ++i) { suma = a[knext + i * a_dim1]; sumb = abs(suma); if (*nact == 0) { goto L581; } i__1 = *nact; for (k = 1; k <= i__1; ++k) { kk = iact[k]; if (kk <= *m) { goto L568; } kk -= *m; temp = zero; if (kk == i) { temp = w[iww + kk]; } kk -= *n; if (kk == i) { temp = -w[iww + kk]; } goto L569; L568: iw = iww + k; temp = w[iw] * a[kk + i * a_dim1]; L569: suma -= temp; /* L572: */ sumb += abs(temp); } L581: if (suma <= *vsmall) { goto L573; } temp = sumb + abs(suma) * .1; tempa = sumb + abs(suma) * .2; if (temp <= sumb) { goto L573; } if (tempa <= temp) { goto L573; } goto L630; L573: ; } lflag = 1; goto L775; L574: k1 = knext - *m; if (k1 > *n) { k1 -= *n; } i__2 = *n; for (i = 1; i <= i__2; ++i) { suma = zero; if (i != k1) { goto L575; } suma = one; if (knext > *mn) { suma = -one; } L575: sumb = abs(suma); if (*nact == 0) { goto L582; } i__1 = *nact; for (k = 1; k <= i__1; ++k) { kk = iact[k]; if (kk <= *m) { goto L579; } kk -= *m; temp = zero; if (kk == i) { temp = w[iww + kk]; } kk -= *n; if (kk == i) { temp = -w[iww + kk]; } goto L576; L579: iw = iww + k; temp = w[iw] * a[kk + i * a_dim1]; L576: suma -= temp; /* L577: */ sumb += abs(temp); } L582: temp = sumb + abs(suma) * .1; tempa = sumb + abs(suma) * .2; if (temp <= sumb) { goto L578; } if (tempa <= temp) { goto L578; } goto L630; L578: ; } lflag = 1; goto L775; /* BRANCH IF THE CONTRAINTS ARE INCONSISTENT. */ L580: *info = -knext; if (kdrop == 0) { goto L700; } parinc = ratio; parnew = parinc; /* REVISE THE LAGRANGE MULTIPLIERS OF THE ACTIVE CONSTRAINTS. */ L590: if (*nact == 0) { goto L601; } i__2 = *nact; for (k = 1; k <= i__2; ++k) { iw = iww + k; w[k] -= parinc * w[iw]; if (iact[k] > *meq) { /* Computing MAX */ d__1 = zero, d__2 = w[k]; w[k] = max(d__1,d__2); } /* L600: */ } L601: if (kdrop == 0) { goto L680; } /* DELETE THE CONSTRAINT TO BE DROPPED. */ /* SHIFT THE VECTOR OF SCALAR PRODUCTS. */ /* THEN, IF APPROPRIATE, MAKE ONE MORE SCALAR PRODUCT ZERO. */ nu = *nact + 1; mflag = 2; goto L800; L610: iws = iws - *nact - 1; nu = min(*n,nu); i__2 = nu; for (i = 1; i <= i__2; ++i) { is = iws + i; j = is + *nact; /* L620: */ w[is] = w[j + 1]; } nflag = 2; goto L860; /* CALCULATE THE STEP TO THE VIOLATED CONSTRAINT. */ L630: is = iws + *nact; L640: sumy = w[is + 1]; step = -res / sumy; parinc = step / sumy; if (*nact == 0) { goto L660; } /* CALCULATE THE CHANGES TO THE LAGRANGE MULTIPLIERS, AND REDUCE */ /* THE STEP ALONG THE NEW SEARCH DIRECTION IF NECESSARY. */ lflag = 2; goto L740; L650: if (kdrop == 0) { goto L660; } temp = one - ratio / parinc; if (temp <= zero) { kdrop = 0; } if (kdrop == 0) { goto L660; } step = ratio * sumy; parinc = ratio; res = temp * res; /* UPDATE X AND THE LAGRANGE MULTIPIERS. */ /* DROP A CONSTRAINT IF THE FULL STEP IS NOT TAKEN. */ L660: iwy = iwz + *nact * *n; i__2 = *n; for (i = 1; i <= i__2; ++i) { iy = iwy + i; /* L670: */ x[i] += step * w[iy]; } parnew += parinc; if (*nact >= 1) { goto L590; } /* ADD THE NEW CONSTRAINT TO THE ACTIVE SET. */ L680: ++(*nact); w[*nact] = parnew; iact[*nact] = knext; ia = iwa + knext; if (knext > *mn) { ia -= *n; } w[ia] = -w[ia]; /* ESTIMATE THE MAGNITUDE OF X. THEN BEGIN A NEW ITERATION, */ /* RE-INITILISING X IF THIS MAGNITUDE IS SMALL. */ jflag = 2; goto L910; L690: if (sum < xmagr * xmag) { goto L230; } if (itref <= 0) { goto L450; } else { goto L250; } /* INITIATE ITERATIVE REFINEMENT IF IT HAS NOT YET BEEN USED, */ /* OR RETURN AFTER RESTORING THE DIAGONAL ELEMENTS OF G. */ L700: if (iterc == 0) { goto L710; } ++itref; jfinc = -1; if (itref == 1) { goto L250; } L710: if (! (*lql)) { return 0; } i__2 = *n; for (i = 1; i <= i__2; ++i) { id = iwd + i; /* L720: */ g[i + i * g_dim1] = w[id]; } L730: return 0; /* THE REMAINIG INSTRUCTIONS ARE USED AS SUBROUTINES. */ /* ******************************************************************** */ /* CALCULATE THE LAGRANGE MULTIPLIERS BY PRE-MULTIPLYING THE */ /* VECTOR IN THE S-PARTITION OF W BY THE INVERSE OF R. */ L740: ir = iwr + (*nact + *nact * *nact) / 2; i = *nact; sum = zero; goto L770; L750: ira = ir - 1; sum = zero; if (*nact == 0) { goto L761; } i__2 = *nact; for (j = i; j <= i__2; ++j) { iw = iww + j; sum += w[ira] * w[iw]; /* L760: */ ira += j; } L761: ir -= i; --i; L770: iw = iww + i; is = iws + i; w[iw] = (w[is] - sum) / w[ir]; if (i > 1) { goto L750; } if (lflag == 3) { goto L390; } if (lflag == 4) { goto L571; } /* CALCULATE THE NEXT CONSTRAINT TO DROP. */ L775: ip = iww + 1; ipp = iww + *nact; kdrop = 0; if (*nact == 0) { goto L791; } i__2 = *nact; for (k = 1; k <= i__2; ++k) { if (iact[k] <= *meq) { goto L790; } iw = iww + k; if (res * w[iw] >= zero) { goto L790; } temp = w[k] / w[iw]; if (kdrop == 0) { goto L780; } if (abs(temp) >= abs(ratio)) { goto L790; } L780: kdrop = k; ratio = temp; L790: ; } L791: switch ((int)lflag) { case 1: goto L580; case 2: goto L650; } /* ******************************************************************** */ /* DROP THE CONSTRAINT IN POSITION KDROP IN THE ACTIVE SET. */ L800: ia = iwa + iact[kdrop]; if (iact[kdrop] > *mn) { ia -= *n; } w[ia] = -w[ia]; if (kdrop == *nact) { goto L850; } /* SET SOME INDICES AND CALCULATE THE ELEMENTS OF THE NEXT */ /* GIVENS ROTATION. */ iz = iwz + kdrop * *n; ir = iwr + (kdrop + kdrop * kdrop) / 2; L810: ira = ir; ir = ir + kdrop + 1; /* Computing MAX */ d__3 = (d__1 = w[ir - 1], abs(d__1)), d__4 = (d__2 = w[ir], abs(d__2)); temp = max(d__3,d__4); /* Computing 2nd power */ d__1 = w[ir - 1] / temp; /* Computing 2nd power */ d__2 = w[ir] / temp; sum = temp * sqrt(d__1 * d__1 + d__2 * d__2); ga = w[ir - 1] / sum; gb = w[ir] / sum; /* EXCHANGE THE COLUMNS OF R. */ i__2 = kdrop; for (i = 1; i <= i__2; ++i) { ++ira; j = ira - kdrop; temp = w[ira]; w[ira] = w[j]; /* L820: */ w[j] = temp; } w[ir] = zero; /* APPLY THE ROTATION TO THE ROWS OF R. */ w[j] = sum; ++kdrop; i__2 = nu; for (i = kdrop; i <= i__2; ++i) { temp = ga * w[ira] + gb * w[ira + 1]; w[ira + 1] = ga * w[ira + 1] - gb * w[ira]; w[ira] = temp; /* L830: */ ira += i; } /* APPLY THE ROTATION TO THE COLUMNS OF Z. */ i__2 = *n; for (i = 1; i <= i__2; ++i) { ++iz; j = iz - *n; temp = ga * w[j] + gb * w[iz]; w[iz] = ga * w[iz] - gb * w[j]; /* L840: */ w[j] = temp; } /* REVISE IACT AND THE LAGRANGE MULTIPLIERS. */ iact[kdrop - 1] = iact[kdrop]; w[kdrop - 1] = w[kdrop]; if (kdrop < *nact) { goto L810; } L850: --(*nact); switch ((int)mflag) { case 1: goto L250; case 2: goto L610; } /* ******************************************************************** */ /* APPLY GIVENS ROTATION TO REDUCE SOME OF THE SCALAR */ /* PRODUCTS IN THE S-PARTITION OF W TO ZERO. */ L860: iz = iwz + nu * *n; L870: iz -= *n; L880: is = iws + nu; --nu; if (nu == *nact) { goto L900; } if (w[is] == zero) { goto L870; } /* Computing MAX */ d__3 = (d__1 = w[is - 1], abs(d__1)), d__4 = (d__2 = w[is], abs(d__2)); temp = max(d__3,d__4); /* Computing 2nd power */ d__1 = w[is - 1] / temp; /* Computing 2nd power */ d__2 = w[is] / temp; sum = temp * sqrt(d__1 * d__1 + d__2 * d__2); ga = w[is - 1] / sum; gb = w[is] / sum; w[is - 1] = sum; i__2 = *n; for (i = 1; i <= i__2; ++i) { k = iz + *n; temp = ga * w[iz] + gb * w[k]; w[k] = ga * w[k] - gb * w[iz]; w[iz] = temp; /* L890: */ --iz; } goto L880; L900: switch ((int)nflag) { case 1: goto L560; case 2: goto L630; } /* ******************************************************************** */ /* CALCULATE THE MAGNITUDE OF X AN REVISE XMAG. */ L910: sum = zero; i__2 = *n; for (i = 1; i <= i__2; ++i) { sum += (d__1 = x[i], abs(d__1)) * vfact * ((d__2 = grad[i], abs(d__2)) + (d__3 = g[i + i * g_dim1] * x[i], abs(d__3))); if (*lql) { goto L920; } if (sum < 1e-30) { goto L920; } vfact *= 1e-10; sum *= 1e-10; xmag *= 1e-10; L920: ; } /* L925: */ xmag = max(xmag,sum); switch ((int)jflag) { case 1: goto L420; case 2: goto L690; } /* ******************************************************************** */ /* PRE-MULTIPLY THE VECTOR IN THE W-PARTITION OF W BY Z TRANSPOSE. */ L930: jl = iww + 1; iz = iwz; i__2 = *n; for (i = 1; i <= i__2; ++i) { is = iws + i; w[is] = zero; iwwn = iww + *n; i__1 = iwwn; for (j = jl; j <= i__1; ++j) { ++iz; /* L940: */ w[is] += w[iz] * w[j]; } } switch ((int)kflag) { case 1: goto L350; case 2: goto L550; } return 0; } /* ql0002_ */ #ifdef uNdEfInEd comments from the converter: (stderr from f2c) ql0001: ql0002: #endif
the_stack_data/876293.c
#include <stdio.h> #define MAX 10 int queue[MAX]; int front = -1, rear = -1; void insert(void); int delete_element(void); int peek(void); void display(void); int main() { int option, val; do { printf("\n 1. Insert an element"); printf("\n 2. Delete an element"); printf("\n 3. Peek"); printf("\n 4. Display the queue"); printf("\n 5. EXIT"); printf("\n Enter your option : "); scanf("%d", &option); switch(option) { case 1: insert(); break; case 2: val=delete_element(); if(val!=-1) { printf("\n The number deleted is : %d", val); } break; case 3: val=peek(); if(val!=-1) { printf("\n The first value in queue is : %d", val); } break; case 4: display(); break; } }while(option != 5); return 0; } void insert() { int num; printf("\n Enter the number to be inserted in the queue : "); scanf("%d", &num); if(rear==MAX-1) { printf("\n OVERFLOW"); } else if(front==-1 && rear==-1) { front=rear=0; } else { rear++; } queue[rear]=num; } int delete_element() { int val; if(front==-1 || front>rear) { printf("\n UNDERFLOW"); return -1; } else { val=queue[front]; front++; if(front>rear) { front=rear=-1; } return val; } } int peek() { if(front==-1 || front>rear) { printf("\n QUEUE IS EMPTY"); return -1; } else { return queue[front]; } } void display() { int i; printf("\n"); if(front==-1 || front>rear) { printf("\n QUEUE IS EMPTY"); } else { for(i = front;i <= rear;i++) { printf("\t %d", queue[i]); } } }
the_stack_data/1255031.c
#include <stdio.h> #include <stdlib.h> int main(int argc, char const *argv[]) { FILE *f; int Vertices,Semi; char Nome[20]; printf("Entre com o nome do arquivo de saida ser criado: "); scanf("%s",Nome); f = fopen(Nome,"w"); printf("Entre com a quantidade de vertices(impares para eulerianos,pares para nao-eulerianos):"); scanf("%d",&Vertices); printf("\nEscolha:\n\t1 - Euleriano\n\t2 - Semi-Euleriano\n"); do{ printf("Entre:"); scanf("%d",&Semi); if(Semi!=1 && Semi!=2){ printf("Erro! Opcao invalida!\n"); } }while(Semi!=1 && Semi!=2); fprintf(f,"%d\n",Vertices); if(Semi==1){ int i; for(i=1;i<Vertices;i++){ fprintf(f,"%d %d\n",i,i+1); } fprintf(f,"%d %d\n",i,1); } else{ int i; for(i=1;i<Vertices;i++){ fprintf(f,"%d %d\n",i,i+1); } } printf("Arquivo gerado com sucesso!\n"); fclose(f); return 0; }
the_stack_data/25972.c
#include <stdio.h> int month_to_i(char *month) { // Gets a valid 3-digit month code and returns an integer. if (month[0] == 'J') { if (month[1] == 'A') return 1; if (month[1] == 'U') { if (month[2] == 'N') return 6; if (month[2] == 'L') return 7; } } if (month[0] == 'F') return 2; if (month[0] == 'M') { if (month[2] == 'R') return 3; if (month[2] == 'Y') return 5; } if (month[0] == 'A') { if (month[1] == 'P') return 4; if (month[1] == 'U') return 8; } if (month[0] == 'S') return 9; if (month[0] == 'O') return 10; if (month[0] == 'N') return 11; if (month[0] == 'D') return 12; } int main(int argc, char *argv[]) { char *months[] = {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}; int counter = 0; for (int i = 0; i < 1200000000; ++i) { ++counter; if (month_to_i(months[i % 12]) != (1 + i % 12)) { printf("%s - %d Failed.\n", months[i % 12], i); } } printf("%d\n", counter); return 0; }
the_stack_data/144509.c
/* <:copyright-BRCM:2016-2020:Apache:standard Copyright (c) 2016-2020 Broadcom. All Rights Reserved The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. :> */ #ifdef ENABLE_LOG #include "bcm_dev_log_task.h" #include "bcm_dev_log_task_internal.h" #include "bcm_dev_log.h" #if defined(LINUX_KERNEL_SPACE) && !defined(__KERNEL__) #include "bcmos_mgmt_type.h" #include "bcmolt_dev_log_linux.h" #include "bcmolt_dev_log_linux_ud.h" #endif #ifdef DEV_LOG_SYSLOG #include <syslog.h> #endif #define USE_ANSI_ESCAPE_CODES #ifdef USE_ANSI_ESCAPE_CODES #define DEV_LOG_STYLE_NORMAL "\033[0m\033#5" #define DEV_LOG_STYLE_BOLD "\033[1m" #define DEV_LOG_STYLE_UNDERLINE "\033[4m" #define DEV_LOG_STYLE_BLINK "\033[5m" #define DEV_LOG_STYLE_REVERSE_VIDEO "\033[7m" #else #define DEV_LOG_STYLE_NORMAL " " #define DEV_LOG_STYLE_BOLD "*** " #define DEV_LOG_STYLE_UNDERLINE "___ " #define DEV_LOG_STYLE_BLINK "o_o " #define DEV_LOG_STYLE_REVERSE_VIDEO "!!! " #endif #define DEV_LOG_MSG_START_CHAR 0x1e /* record separator character */ #define MEM_FILE_HDR_SIZE sizeof(dev_log_mem_file_header) #define LOG_MIN(a,b) (((int)(a) <= (int)(b)) ? (a) : (b)) dev_log_id def_log_id; static int default_write_callback_unprotected(bcm_dev_log_file *file, const void *buf, uint32_t length); static bcm_dev_log_style dev_log_level2style[DEV_LOG_LEVEL_NUM_OF] = { [DEV_LOG_LEVEL_FATAL] = BCM_DEV_LOG_STYLE_NORMAL, [DEV_LOG_LEVEL_ERROR] = BCM_DEV_LOG_STYLE_NORMAL, [DEV_LOG_LEVEL_WARNING] = BCM_DEV_LOG_STYLE_NORMAL, [DEV_LOG_LEVEL_INFO] = BCM_DEV_LOG_STYLE_NORMAL, [DEV_LOG_LEVEL_DEBUG] = BCM_DEV_LOG_STYLE_NORMAL, }; static const char *dev_log_style_array[] = { [BCM_DEV_LOG_STYLE_NORMAL] = DEV_LOG_STYLE_NORMAL, [BCM_DEV_LOG_STYLE_BOLD] = DEV_LOG_STYLE_BOLD, [BCM_DEV_LOG_STYLE_UNDERLINE] = DEV_LOG_STYLE_UNDERLINE, [BCM_DEV_LOG_STYLE_BLINK] = DEV_LOG_STYLE_BLINK, [BCM_DEV_LOG_STYLE_REVERSE_VIDEO] = DEV_LOG_STYLE_REVERSE_VIDEO, }; bcm_dev_log dev_log = {{0}}; const char *log_level_str = "?FEWID"; static void bcm_dev_log_shutdown_msg_release(bcmos_msg *m) { (void)m; /* do nothing, the message is statically allocated */ } static bcmos_msg shutdown_msg = { .release = bcm_dev_log_shutdown_msg_release }; static void bcm_dev_log_file_save_msg(bcm_dev_log_file *files, const char *message) { uint32_t i; uint32_t len = strlen(message) + 1; /* including 0 terminator */ for (i = 0; (i < DEV_LOG_MAX_FILES) && (files[i].file_parm.flags & BCM_DEV_LOG_FILE_FLAG_VALID); i++) { files[i].file_parm.write_cb(&files[i], message, len); } } static void dev_log_save_task_format_message(dev_log_queue_msg *receive_msg, char *log_string, uint32_t log_string_size, ...) { uint32_t length; char time_str[17]; dev_log_id_parm *log_id = receive_msg->log_id; bcm_dev_log_level msg_level = receive_msg->msg_level; /* Build message header */ *log_string = '\0'; if (!(receive_msg->flags & BCM_LOG_FLAG_NO_HEADER)) { length = sizeof(time_str); dev_log.dev_log_parm.time_to_str_cb(receive_msg->time_stamp, time_str, length); snprintf( log_string, log_string_size, "[%s: %c %-20s] ", time_str, log_level_str[msg_level], log_id->name); } /* Modify the __FILE__ format so it would print the filename only without the path. * If using BCM_LOG_FLAG_CALLER_FMT, it is done in caller context, because filename might be long, taking a lot of * the space of the message itself. */ if ((receive_msg->flags & BCM_LOG_FLAG_FILENAME_IN_FMT) && !(receive_msg->flags & BCM_LOG_FLAG_CALLER_FMT)) { /* coverity[misra_violation] - cross-assignment under union is OK - they're both in the same union member */ receive_msg->u.fmt_args.fmt = dev_log_basename(receive_msg->u.fmt_args.fmt); } if (receive_msg->flags & BCM_LOG_FLAG_CALLER_FMT) { /* Copy user string to buffer */ strncat(log_string, receive_msg->u.str, log_string_size - strlen(log_string) - 1); } else { uint32_t offset = ((long)receive_msg->u.fmt_args.args % 8 == 0) ? 0 : 1; /* start on an 8-byte boundary */ #ifndef COMPILATION_32_BIT /* NOTE: why do we use so terrible input: * It is impossible to send va_list structure from bcm_dev_log.c. So we send array of arguments only. * The va_list maintains pointers to temporary memory on the stack. * After the function with variable args has returned, this automatic storage is gone and the contents are no longer usable. * Because of this, we cannot simply keep a copy of the va_list itself - the memory it references will contain unpredictable content. * In addition internal struct va_list is different in 64-bit and 32-bit, in ARM, in posix etc., so we cannot assume what exactly its fields contain */ snprintf(log_string + strlen(log_string), log_string_size - strlen(log_string), receive_msg->u.fmt_args.fmt, receive_msg->u.fmt_args.args[offset], receive_msg->u.fmt_args.args[offset+1], receive_msg->u.fmt_args.args[offset+2], receive_msg->u.fmt_args.args[offset+3], receive_msg->u.fmt_args.args[offset+4], receive_msg->u.fmt_args.args[offset+5], receive_msg->u.fmt_args.args[offset+6], receive_msg->u.fmt_args.args[offset+7], receive_msg->u.fmt_args.args[offset+8], receive_msg->u.fmt_args.args[offset+9], receive_msg->u.fmt_args.args[offset+10], receive_msg->u.fmt_args.args[offset+11], receive_msg->u.fmt_args.args[offset+12], receive_msg->u.fmt_args.args[offset+13], receive_msg->u.fmt_args.args[offset+14], receive_msg->u.fmt_args.args[offset+15], receive_msg->u.fmt_args.args[offset+16], receive_msg->u.fmt_args.args[offset+17], receive_msg->u.fmt_args.args[offset+18], receive_msg->u.fmt_args.args[offset+19], receive_msg->u.fmt_args.args[offset+20], receive_msg->u.fmt_args.args[offset+21], receive_msg->u.fmt_args.args[offset+22], receive_msg->u.fmt_args.args[offset+23], receive_msg->u.fmt_args.args[offset+24], receive_msg->u.fmt_args.args[offset+25], receive_msg->u.fmt_args.args[offset+26], receive_msg->u.fmt_args.args[offset+27], receive_msg->u.fmt_args.args[offset+28], receive_msg->u.fmt_args.args[offset+29], receive_msg->u.fmt_args.args[offset+30], receive_msg->u.fmt_args.args[offset+31], receive_msg->u.fmt_args.args[offset+32], receive_msg->u.fmt_args.args[offset+33], receive_msg->u.fmt_args.args[offset+34], receive_msg->u.fmt_args.args[offset+35], receive_msg->u.fmt_args.args[offset+36]); #else va_list ap; *(void **)&ap = &receive_msg->u.fmt_args.args[offset]; /* Copy user string to buffer */ vsnprintf(log_string + strlen(log_string), log_string_size - strlen(log_string), receive_msg->u.fmt_args.fmt, ap); #endif } /* Force last char to be end of string */ log_string[MAX_DEV_LOG_STRING_SIZE - 1] = '\0'; } static void dev_log_save_task_handle_message(bcmos_msg *msg) { static char log_string[MAX_DEV_LOG_STRING_SIZE]; dev_log_queue_msg *receive_msg = msg->data; dev_log_id_parm *log_id = receive_msg->log_id; bcm_dev_log_level msg_level = receive_msg->msg_level; dev_log_save_task_format_message(receive_msg, log_string, sizeof(log_string)); /* At this point, if the message is going to be sent to the print task, save the formatted string then forward it. * Otherwise, we can release the message before writing it to RAM. */ if ((log_id->log_type & DEV_LOG_ID_TYPE_PRINT) && (msg_level <= log_id->log_level_print)) { if (!bcm_dev_log_level_is_error(msg_level) && (receive_msg->flags & BCM_LOG_FLAG_DONT_SKIP_PRINT) != 0 && bcm_dev_log_pool_occupancy_percent_get() >= DEV_LOG_SKIP_PRINT_THRESHOLD_PERCENT) { log_id->print_skipped_count++; bcmos_msg_free(msg); } else { strcpy(receive_msg->u.str, log_string); /* so the print task doesn't need to re-format it */ bcmos_msg_send(&dev_log.print_queue, msg, BCMOS_MSG_SEND_AUTO_FREE); } } else { bcmos_msg_free(msg); } /* Save to file */ if ((log_id->log_type & DEV_LOG_ID_TYPE_SAVE) && (msg_level <= log_id->log_level_save)) { bcm_dev_log_file_save_msg(dev_log.files, log_string); } } static void dev_log_print_task_handle_message(bcmos_msg *msg) { static char log_string[MAX_DEV_LOG_STRING_SIZE]; dev_log_queue_msg *receive_msg = msg->data; dev_log_id_parm *log_id = receive_msg->log_id; bcm_dev_log_level msg_level = receive_msg->msg_level; /* make a local copy of the pre-formatted string (it was formatted in the save task) */ strcpy(log_string, receive_msg->u.str); /* free the message ASAP since printing might take some time */ bcmos_msg_free(msg); if (log_id->style == BCM_DEV_LOG_STYLE_NORMAL && dev_log_level2style[msg_level] == BCM_DEV_LOG_STYLE_NORMAL) { dev_log.dev_log_parm.print_cb(dev_log.dev_log_parm.print_cb_arg, "%s", log_string); } else { /* If style was set per log id, then use it. */ if (log_id->style != BCM_DEV_LOG_STYLE_NORMAL) { dev_log.dev_log_parm.print_cb( dev_log.dev_log_parm.print_cb_arg, "%s%s%s", dev_log_style_array[log_id->style], log_string, dev_log_style_array[BCM_DEV_LOG_STYLE_NORMAL]); } else { /* Otherwise - style was set per log level. */ dev_log.dev_log_parm.print_cb( dev_log.dev_log_parm.print_cb_arg, "%s%s%s", dev_log_style_array[dev_log_level2style[msg_level]], log_string, dev_log_style_array[BCM_DEV_LOG_STYLE_NORMAL]); } } } static int dev_log_print_task(long data) { bcmos_msg *m; bcmos_errno error; const char error_str[MAX_DEV_LOG_STRING_SIZE] = "Error: Can't receive from queue - dev_log print task exit\n"; while (1) { error = bcmos_msg_recv(&dev_log.print_queue, BCMOS_WAIT_FOREVER, &m); if (error != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("%s", error_str); dev_log.dev_log_parm.print_cb(dev_log.dev_log_parm.print_cb_arg, "%s", error_str); bcm_dev_log_file_save_msg(dev_log.files, error_str); return (int)error; } if (m == &shutdown_msg) { break; /* shut down gracefully */ } else { dev_log_print_task_handle_message(m); } } bcmos_sem_post(&dev_log.print_task_is_terminated); return 0; } static int dev_log_save_task(long data) { bcmos_msg *m; bcmos_errno error; const char error_str[MAX_DEV_LOG_STRING_SIZE] = "Error: Can't receive from queue - dev_log save task exit\n"; while (1) { error = bcmos_msg_recv(&dev_log.save_queue, BCMOS_WAIT_FOREVER, &m); if (error != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("%s", error_str); dev_log.dev_log_parm.print_cb(dev_log.dev_log_parm.print_cb_arg, "%s", error_str); bcm_dev_log_file_save_msg(dev_log.files, error_str); return (int)error; } if (m == &shutdown_msg) { break; /* shut down gracefully */ } else { dev_log_save_task_handle_message(m); } } bcmos_sem_post(&dev_log.save_task_is_terminated); return 0; } void dev_log_oops_complete_cb(void) { bcmos_msg *m; uint32_t i; /* We start traversing print queue. Those are already formatted messages that were forwarded from the save task. * Then we proceed to traversing save queue. Those are messages that haven't reached the print task yet. * We read from queue with timeout=0, meaning non-blocking call (we cannot wait in oops time - all OS services are down). */ while (bcmos_msg_recv(&dev_log.print_queue, 0, &m) == BCM_ERR_OK) dev_log_print_task_handle_message(m); for (i = 0; (i < DEV_LOG_MAX_FILES) && (dev_log.files[i].file_parm.flags & BCM_DEV_LOG_FILE_FLAG_VALID); i++) { if (dev_log.files[i].file_parm.type == BCM_DEV_LOG_FILE_MEMORY) dev_log.files[i].file_parm.write_cb = default_write_callback_unprotected; /* Avoid bcmos_mutex_lock()/bcmos_mutex_unlock() in regular (protected) version. */ } while (bcmos_msg_recv(&dev_log.save_queue, 0, &m) == BCM_ERR_OK) { static char log_string[MAX_DEV_LOG_STRING_SIZE]; dev_log_queue_msg *receive_msg; dev_log_id_parm *log_id; bcm_dev_log_level msg_level; receive_msg = m->data; log_id = receive_msg->log_id; msg_level = receive_msg->msg_level; dev_log_save_task_format_message(receive_msg, log_string, sizeof(log_string)); if ((log_id->log_type & DEV_LOG_ID_TYPE_PRINT) && (msg_level <= log_id->log_level_print)) { strcpy(receive_msg->u.str, log_string); dev_log_print_task_handle_message(m); } else { bcmos_msg_free(m); } /* Save to file */ if ((log_id->log_type & DEV_LOG_ID_TYPE_SAVE) && (msg_level <= log_id->log_level_save)) { bcm_dev_log_file_save_msg(dev_log.files, log_string); } } } static int default_time_to_str(uint32_t time_stamp, char *time_str, int time_str_size) { return snprintf(time_str, time_str_size, "%u", time_stamp); } static uint32_t default_get_time(void) { return 0; } static void default_print(void *arg, const char *format, ...) { va_list args; va_start(args, format); bcmos_vprintf(format, args); va_end(args); } static bcmos_errno default_open_callback_cond_reset(const bcm_dev_log_file_parm *file_parm, bcm_dev_log_file *file, bcmos_bool is_rewind) { bcmos_errno err; if (!file->file_parm.start_addr || file->file_parm.size <= MEM_FILE_HDR_SIZE) return BCM_ERR_PARM; /* Create file mutex */ err = bcmos_mutex_create(&file->u.mem_file.mutex, 0, NULL); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't create mutex (error: %d)\n", (int)err); return err; } /* Check file magic string */ memcpy(&file->u.mem_file.file_header, (uint8_t *)file->file_parm.start_addr, MEM_FILE_HDR_SIZE); if (memcmp(FILE_MAGIC_STR, file->u.mem_file.file_header.file_magic, FILE_MAGIC_STR_SIZE)) { DEV_LOG_INFO_PRINTF("No file magic string - file is empty/corrupt\n"); if (!is_rewind || !file->file_parm.rewind_cb) { bcmos_mutex_destroy(&file->u.mem_file.mutex); return BCM_ERR_NOENT; } return file->file_parm.rewind_cb(file); } DEV_LOG_INFO_PRINTF("Attached to existing file\n"); return BCM_ERR_OK; } static bcmos_errno default_open_callback(const bcm_dev_log_file_parm *file_parm, bcm_dev_log_file *file) { return default_open_callback_cond_reset(file_parm, file, BCMOS_TRUE); } static bcmos_errno default_close_callback(bcm_dev_log_file *file) { bcmos_mutex_destroy(&file->u.mem_file.mutex); return BCM_ERR_OK; } /* Look for start of msg character */ static int get_msg_start_offset(bcm_dev_log_file *file, uint32_t offset, uint32_t max_len) { uint8_t *buf, *msg; buf = (uint8_t *)file->file_parm.start_addr + offset + MEM_FILE_HDR_SIZE; msg = memchr(buf, DEV_LOG_MSG_START_CHAR, max_len); if (!msg) return -1; return (msg - buf + 1); } /* Look for 0-terminator */ static int get_msg_end_offset(bcm_dev_log_file *file, uint32_t offset, uint32_t max_len) { uint8_t *buf, *end; buf = (uint8_t *)file->file_parm.start_addr + offset + MEM_FILE_HDR_SIZE; end = memchr(buf, 0, max_len); if (!end) return -1; return (end - buf + 1); } static int default_read_callback(bcm_dev_log_file *log_file, uint32_t *p_offset, void *buf, uint32_t length) { uint32_t offset = *p_offset; uint32_t output_length = 0; uint32_t scan_length = 0; int start, end; bcmos_bool read_wrap = BCMOS_FALSE; /* If file wrapped around, offset is indeterminate, scan for start from current offset to end of file buffer, * if start not found, then try again from beginning of buffer up to write ptr */ if (log_file->u.mem_file.file_header.file_wrap_cnt) { scan_length = log_file->u.mem_file.file_header.data_size - offset; if (scan_length <= 0) { /* Insane offset passed in from user, reset it */ DEV_LOG_ERROR_PRINTF("%s: reset bad read offset:%d (> size of log buffer)\n", __FUNCTION__, offset); *p_offset = 0; return 0; } /* Find beginning of the next message */ start = get_msg_start_offset(log_file, offset, scan_length); if (start < 0) { /* Didn't find any up to the end of buffer. Scan again from the start, up to write offset */ offset = 0; if (!log_file->u.mem_file.file_header.write_offset) return 0; start = get_msg_start_offset(log_file, 0, log_file->u.mem_file.file_header.write_offset - 1); if (start <= 0) { return 0; } } } else { /* file not wrapped, scan from current offset up to write ptr */ scan_length = log_file->u.mem_file.file_header.write_offset - offset; /* Scan for start of message. Without wrap-around it should be between read offset, and the write ptr */ start = get_msg_start_offset(log_file, offset, scan_length); if (start <= 0) return 0; } offset += start; /* We have the beginning. Now find the end of message and copy to the user buffer if there is enough room */ if (offset + length > log_file->u.mem_file.file_header.data_size) { /* Possible read wrap may occur, scan up to end of file buffer first */ scan_length = log_file->u.mem_file.file_header.data_size - offset; end = get_msg_end_offset(log_file, offset, scan_length); if (end >= 0) { /* Found end before end of buffer, no read wrap, just copy and return */ memcpy(buf, (uint8_t *)log_file->file_parm.start_addr + MEM_FILE_HDR_SIZE + offset, end); *p_offset += start + end; return end; } /* Didn't find end of message in the end of file buffer. Copy first part from offset up to end of buffer, then wrap around */ memcpy(buf, (uint8_t *)log_file->file_parm.start_addr + MEM_FILE_HDR_SIZE + offset, scan_length); output_length = scan_length; buf = (uint8_t *)buf + scan_length; length -= scan_length; /* reduce remaining buffer space by size copied */ offset = 0; /* Reset to beginning of buffer for final "end" scan */ read_wrap = BCMOS_TRUE; scan_length = log_file->u.mem_file.file_header.write_offset - 1; /* Limit wrapped end scan from beginning of buffer up to write ptr */ } else { /* No read wrap, just scan for end from current offset to the end of the file , since the end might be past the buffer length */ scan_length = log_file->u.mem_file.file_header.data_size - offset; } end = get_msg_end_offset(log_file, offset, scan_length); if (end <= 0) { /* something is wrong. msg is not terminated */ DEV_LOG_ERROR_PRINTF("%s: no message end found!\n", __FUNCTION__); return 0; } /* If there is no room for the whole message - return overflow */ if (end > length) return (int)BCM_ERR_OVERFLOW; /* Copy whole message, or second part for wrapped read */ memcpy(buf, (uint8_t *)log_file->file_parm.start_addr + MEM_FILE_HDR_SIZE + offset, end); output_length += end; if (read_wrap) { /* Reset wrapped read ptr, and write wrap count */ log_file->u.mem_file.file_header.file_wrap_cnt = 0; *p_offset = end; } else *p_offset += start + output_length; /* Increment read ptr */ return output_length; } static int get_num_of_overwritten_messages(uint8_t *buf, uint32_t length) { uint8_t *p; int n = 0; do { p = memchr(buf, DEV_LOG_MSG_START_CHAR, length); if (p == NULL) break; ++n; length -= (p + 1 - buf); buf = p + 1; } while(length); return n; } static int default_write_callback_unprotected(bcm_dev_log_file *file, const void *buf, uint32_t length) { uint32_t offset, next_offset; uint8_t *p; int n_overwritten = 0; if ((file->file_parm.flags & BCM_DEV_LOG_FILE_FLAG_STOP_WHEN_FULL) && file->is_full) return 0; if (!length) return 0; offset = file->u.mem_file.file_header.write_offset; next_offset = offset + length + 1; /* 1 extra character for record delimiter */ /* Handle overflow */ if (next_offset >= file->u.mem_file.file_header.data_size) { uint32_t tail_length; /* Split buffer in 2 */ tail_length = next_offset - file->u.mem_file.file_header.data_size; /* 2nd segment length */ if ((file->file_parm.flags & BCM_DEV_LOG_FILE_FLAG_STOP_WHEN_FULL) && tail_length) { file->is_full = BCMOS_TRUE; return 0; } length -= tail_length; /* "if (next_offset >= file->u.mem_file.file_header.data_size)" condition * guarantees that there is room for at least 1 character in the end of file */ p = (uint8_t *)file->file_parm.start_addr + offset + MEM_FILE_HDR_SIZE; if (file->u.mem_file.file_header.file_wrap_cnt) n_overwritten += get_num_of_overwritten_messages(p, length + 1); *p = DEV_LOG_MSG_START_CHAR; if (length) { memcpy(p + 1, buf, length); buf = (const uint8_t *)buf + length; } if (tail_length) { p = (uint8_t *)file->file_parm.start_addr + MEM_FILE_HDR_SIZE; if (file->u.mem_file.file_header.file_wrap_cnt) n_overwritten += get_num_of_overwritten_messages(p, tail_length); memcpy(p, buf, tail_length); ++file->u.mem_file.file_header.file_wrap_cnt; } next_offset = tail_length; } else { p = (uint8_t *)file->file_parm.start_addr + MEM_FILE_HDR_SIZE + offset; if (file->u.mem_file.file_header.file_wrap_cnt) n_overwritten += get_num_of_overwritten_messages(p, length + 1); *(p++) = DEV_LOG_MSG_START_CHAR; memcpy(p, buf, length); } file->u.mem_file.file_header.write_offset = next_offset; file->u.mem_file.file_header.num_msgs += (1 - n_overwritten); /* update the header */ memcpy((uint8_t *)file->file_parm.start_addr, &file->u.mem_file.file_header, MEM_FILE_HDR_SIZE); /* send almost full indication if necessary */ if (file->almost_full.send_ind_cb && !file->almost_full.ind_sent && file->u.mem_file.file_header.write_offset > file->almost_full.threshold) { file->almost_full.ind_sent = (file->almost_full.send_ind_cb(file->almost_full.priv) == BCM_ERR_OK); } return length; } static int default_write_callback(bcm_dev_log_file *file, const void *buf, uint32_t length) { bcmos_mutex_lock(&file->u.mem_file.mutex); length = default_write_callback_unprotected(file, buf, length); bcmos_mutex_unlock(&file->u.mem_file.mutex); return length; } static bcmos_errno default_rewind_callback(bcm_dev_log_file *file) { bcmos_mutex_lock(&file->u.mem_file.mutex); DEV_LOG_INFO_PRINTF("Clear file\n"); file->u.mem_file.file_header.file_wrap_cnt = 0; file->u.mem_file.file_header.write_offset = 0; file->u.mem_file.file_header.data_size = file->file_parm.size - MEM_FILE_HDR_SIZE; file->u.mem_file.file_header.num_msgs = 0; strcpy(file->u.mem_file.file_header.file_magic, FILE_MAGIC_STR); memcpy((uint8_t *)file->file_parm.start_addr, &file->u.mem_file.file_header, MEM_FILE_HDR_SIZE); file->almost_full.ind_sent = BCMOS_FALSE; bcmos_mutex_unlock(&file->u.mem_file.mutex); return BCM_ERR_OK; } static void set_default_file_callbacks(bcm_dev_log_file *file) { file->file_parm.open_cb = default_open_callback; file->file_parm.close_cb = default_close_callback; file->file_parm.read_cb = default_read_callback; file->file_parm.write_cb = default_write_callback; file->file_parm.rewind_cb = default_rewind_callback; } static inline bcmos_bool bcm_dev_log_is_memory_file(bcm_dev_log_file *file) { return (file->file_parm.open_cb == default_open_callback); } bcmos_errno bcm_dev_log_file_clear(bcm_dev_log_file *file) { if (!file || !(file->file_parm.flags & BCM_DEV_LOG_FILE_FLAG_VALID)) return BCM_ERR_PARM; if (!file->file_parm.rewind_cb) return BCM_ERR_NOT_SUPPORTED; return file->file_parm.rewind_cb(file); } /* File index to file handle */ bcm_dev_log_file *bcm_dev_log_file_get(uint32_t file_index) { bcm_dev_log_file *file = &dev_log.files[file_index]; if ((file_index >= DEV_LOG_MAX_FILES) || !(file->file_parm.flags & BCM_DEV_LOG_FILE_FLAG_VALID)) return NULL; return file; } /* Read from file */ int bcm_dev_log_file_read(bcm_dev_log_file *file, uint32_t *offset, char *buf, uint32_t buf_len) { int len; if (!file || !buf || !(file->file_parm.flags & BCM_DEV_LOG_FILE_FLAG_VALID)) return (int)BCM_ERR_PARM; len = file->file_parm.read_cb(file, offset, buf, buf_len); /* If nothing more to read and CLEAR_AFTER_READ mode, read again under lock and clear if no new records */ if (!len && bcm_dev_log_is_memory_file(file) && (file->file_parm.flags & BCM_DEV_LOG_FILE_FLAG_CLEAR_AFTER_READ)) { bcmos_mutex_lock(&file->u.mem_file.mutex); len = file->file_parm.read_cb(file, offset, buf, buf_len); if (!len) { file->file_parm.rewind_cb(file); *offset = 0; /* Also reset user read ptr when log file is cleared down! */ } bcmos_mutex_unlock(&file->u.mem_file.mutex); } return len; } /* Attach file to memory buffer */ bcmos_errno bcm_dev_log_file_attach(void *buf, uint32_t buf_len, bcm_dev_log_file *file) { bcmos_errno rc; dev_log_mem_file_header *hdr = (dev_log_mem_file_header *)buf; if (!buf || !file || buf_len <= MEM_FILE_HDR_SIZE) return BCM_ERR_PARM; if (memcmp(FILE_MAGIC_STR, hdr->file_magic, FILE_MAGIC_STR_SIZE)) return BCM_ERR_NOENT; #if DEV_LOG_ENDIAN != BCM_CPU_ENDIAN hdr->file_wrap_cnt = bcmos_endian_swap_u32(hdr->file_wrap_cnt); hdr->write_offset = bcmos_endian_swap_u32(hdr->write_offset); hdr->data_size = bcmos_endian_swap_u32(hdr->data_size); hdr->num_msgs = bcmos_endian_swap_u32(hdr->num_msgs); #endif memset(file, 0, sizeof(*file)); file->file_parm.start_addr = buf; file->file_parm.size = buf_len; file->file_parm.flags = BCM_DEV_LOG_FILE_FLAG_VALID; set_default_file_callbacks(file); rc = default_open_callback_cond_reset(&file->file_parm, file, BCMOS_FALSE); if (rc) return rc; if (!file->u.mem_file.file_header.num_msgs) return BCM_ERR_NOENT; return BCM_ERR_OK; } /* Detach file handle from memory buffer */ bcmos_errno bcm_dev_log_file_detach(bcm_dev_log_file *file) { if (!file || !(file->file_parm.flags & BCM_DEV_LOG_FILE_FLAG_VALID)) return BCM_ERR_PARM; file->file_parm.flags = BCM_DEV_LOG_FILE_FLAG_VALID; bcmos_mutex_destroy(&file->u.mem_file.mutex); return BCM_ERR_OK; } #ifdef BCM_OS_POSIX /* Regular file callbacks */ /****************************************************************************************/ /* OPEN CALLBACK: open memory/file */ /* file_parm - file parameters */ /* file - file */ /****************************************************************************************/ static bcmos_errno _dev_log_reg_file_open(const bcm_dev_log_file_parm *file_parm, bcm_dev_log_file *file) { bcmos_errno err = BCM_ERR_OK; file->file_parm = *file_parm; file->u.reg_file_handle = fopen((char *)file_parm->udef_parms, "w+"); if (!file->u.reg_file_handle) { bcmos_printf("DEV_LOG: can't open file %s for writing\n", (char *)file_parm->udef_parms); err = BCM_ERR_IO; } return err; } /****************************************************************************************/ /* CLOSE CALLBACK: close memory/file */ /* file - file handle */ /****************************************************************************************/ static bcmos_errno _dev_log_reg_file_close(bcm_dev_log_file *file) { if (file->u.reg_file_handle) { fclose(file->u.reg_file_handle); /* coverity[misra_violation] - we're not "using" the closed file handle, we're invalidating it */ file->u.reg_file_handle = NULL; } return BCM_ERR_OK; } /****************************************************************************************/ /* REWIND CALLBACK: clears memory/file */ /* file - file handle */ /****************************************************************************************/ static bcmos_errno _dev_log_reg_file_rewind(bcm_dev_log_file *file) { bcmos_errno err = BCM_ERR_OK; FILE *f; if (file->u.reg_file_handle) { f = freopen((const char *)file->file_parm.udef_parms, "w+", file->u.reg_file_handle); if (NULL != f) { file->u.reg_file_handle = f; } else { err = BCM_ERR_IO; bcmos_printf("DEV_LOG: can't open file %s for writing\n", (char *)file->file_parm.udef_parms); } } return err; } /****************************************************************************************/ /* READ_CALLBACK: read form memory/file */ /* offset - the offset in bytes to read from, output */ /* buf - Where to put the result */ /* length - Buffer length */ /* This function should return the number of bytes actually read from file or 0 if EOF */ /****************************************************************************************/ static int _dev_log_reg_file_read(bcm_dev_log_file *file, uint32_t *offset, void *buf, uint32_t length) { int n = 0; if (file->u.reg_file_handle) { if (!fseek(file->u.reg_file_handle, SEEK_SET, *offset)) n = fread(buf, 1, length, file->u.reg_file_handle); *offset = ftell(file->u.reg_file_handle); } return (n < 0) ? 0 : n; } /****************************************************************************************/ /* WRITE_CALLBACK: write form memory/file */ /* buf - The buffer that should be written */ /* length - The number of bytes to write */ /* This function should return the number of bytes actually written to file or 0 if EOF */ /****************************************************************************************/ static int _dev_log_reg_file_write(bcm_dev_log_file *file, const void *buf, uint32_t length) { const char *cbuf = (const char *)buf; int n = 0; if (file->u.reg_file_handle) { /* Remove 0 terminator */ if (length && !cbuf[length-1]) --length; n = fwrite(buf, 1, length, file->u.reg_file_handle); fflush(file->u.reg_file_handle); } return n; } static void set_regular_file_callbacks(bcm_dev_log_file *file) { file->file_parm.open_cb = _dev_log_reg_file_open; file->file_parm.close_cb = _dev_log_reg_file_close; file->file_parm.read_cb = _dev_log_reg_file_read; file->file_parm.write_cb = _dev_log_reg_file_write; file->file_parm.rewind_cb = _dev_log_reg_file_rewind; } #endif /* #ifdef BCM_OS_POSIX */ #ifdef DEV_LOG_SYSLOG /* linux syslog integration */ /****************************************************************************************/ /* OPEN CALLBACK: open syslog interface */ /* file_parm->udef_parm contains optional log ident */ /****************************************************************************************/ static bcmos_errno _dev_log_syslog_file_open(const bcm_dev_log_file_parm *file_parm, bcm_dev_log_file *file) { file->file_parm = *file_parm; openlog((const char *)file_parm->udef_parms, 0, LOG_USER); return BCM_ERR_OK; } /****************************************************************************************/ /* CLOSE CALLBACK: close syslog interface */ /****************************************************************************************/ static bcmos_errno _dev_log_syslog_file_close(bcm_dev_log_file *file) { closelog(); return BCM_ERR_OK; } /****************************************************************************************/ /* REWIND CALLBACK: not supported by syslog. Return OK to prevent request failure */ /****************************************************************************************/ static bcmos_errno _dev_log_syslog_file_rewind(bcm_dev_log_file *file) { return BCM_ERR_OK; } /****************************************************************************************/ /* READ_CALLBACK: reading from syslog is not supported */ /****************************************************************************************/ static int _dev_log_syslog_file_read(bcm_dev_log_file *file, uint32_t *offset, void *buf, uint32_t length) { return 0; } /****************************************************************************************/ /* WRITE_CALLBACK: write to syslog */ /* buf - The buffer that should be written */ /* length - The number of bytes to write */ /* This function should return the number of bytes actually written to file or 0 if EOF */ /****************************************************************************************/ static int _dev_log_syslog_file_write(bcm_dev_log_file *file, const void *buf, uint32_t length) { const char *cbuf = (const char *)buf; static int log_priority = LOG_DEBUG; /* Identify log lovel */ if (cbuf && cbuf[0] == '[') { const char *clevel = strchr(cbuf, ' '); if (clevel) { switch (*(clevel + 1)) { case 'F': log_priority = LOG_CRIT; break; case 'E': log_priority = LOG_ERR; break; case 'W': log_priority = LOG_WARNING; break; case 'I': log_priority = LOG_INFO; break; case 'D': log_priority = LOG_DEBUG; break; default: break; } } } syslog(log_priority, "%s", cbuf); return length; } static void set_syslog_file_callbacks(bcm_dev_log_file *file) { file->file_parm.open_cb = _dev_log_syslog_file_open; file->file_parm.close_cb = _dev_log_syslog_file_close; file->file_parm.read_cb = _dev_log_syslog_file_read; file->file_parm.write_cb = _dev_log_syslog_file_write; file->file_parm.rewind_cb = _dev_log_syslog_file_rewind; } #endif /* #ifdef DEV_LOG_SYSLOG */ static bcmos_errno bcm_dev_log_create( const bcm_dev_log_parm *dev_log_parm, const bcmos_task_parm *save_task_parm, const bcmos_task_parm *print_task_parm, const bcmos_msg_queue_parm *save_queue_parm, const bcmos_msg_queue_parm *print_queue_parm, const bcmos_msg_pool_parm *pool_parm) { bcmos_errno err; int i; if (!dev_log_parm) return BCM_ERR_PARM; if (dev_log.state != BCM_DEV_LOG_STATE_UNINITIALIZED) return BCM_ERR_ALREADY; /* Set user callbacks */ dev_log.dev_log_parm = *dev_log_parm; if (!dev_log.dev_log_parm.print_cb) dev_log.dev_log_parm.print_cb = default_print; if (!dev_log.dev_log_parm.get_time_cb) dev_log.dev_log_parm.get_time_cb = default_get_time; if (!dev_log.dev_log_parm.time_to_str_cb) dev_log.dev_log_parm.time_to_str_cb = default_time_to_str; for (i = 0; (i < DEV_LOG_MAX_FILES) && (dev_log_parm->log_file[i].flags & BCM_DEV_LOG_FILE_FLAG_VALID); i++) { /* Copy log files */ dev_log.files[i].file_parm = dev_log_parm->log_file[i]; if (!dev_log.files[i].file_parm.open_cb) { if (dev_log.files[i].file_parm.type == BCM_DEV_LOG_FILE_MEMORY) set_default_file_callbacks(&dev_log.files[i]); #ifdef BCM_OS_POSIX else if (dev_log.files[i].file_parm.type == BCM_DEV_LOG_FILE_REGULAR) { set_regular_file_callbacks(&dev_log.files[i]); } #endif #ifdef DEV_LOG_SYSLOG else if (dev_log.files[i].file_parm.type == BCM_DEV_LOG_FILE_SYSLOG) set_syslog_file_callbacks(&dev_log.files[i]); #endif else { DEV_LOG_ERROR_PRINTF("file%d: open_cb must be set for user-defined file\n\n", i); continue; } } err = dev_log.files[i].file_parm.open_cb(&dev_log.files[i].file_parm, &dev_log.files[i]); if (err) { DEV_LOG_ERROR_PRINTF("file%d: open failed: %s (%d)\n\n", i, bcmos_strerror(err), err ); continue; } DEV_LOG_INFO_PRINTF("file: start_addr: 0x%p, size: %u, max msg size %u\n", dev_log.files[i].file_parm.start_addr, dev_log.files[i].file_parm.size, MAX_DEV_LOG_STRING_SIZE); } /* Create pool */ err = bcmos_msg_pool_create(&dev_log.pool, pool_parm); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't create pool (error: %d)\n", (int)err); return err; } /* Create message queues */ err = bcmos_msg_queue_create(&dev_log.save_queue, save_queue_parm); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("(%s) Error: Can't create save queue (error: %d)\n", __FUNCTION__, (int)err); return err; } err = bcmos_msg_queue_create(&dev_log.print_queue, print_queue_parm); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("(%s) Error: Can't create print queue (error: %d)\n", __FUNCTION__, (int)err); return err; } /* Create tasks */ err = bcmos_task_create(&dev_log.save_task, save_task_parm); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't spawn save task (error: %d)\n", (int)err); return err; } err = bcmos_task_create(&dev_log.print_task, print_task_parm); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't spawn print task (error: %d)\n", (int)err); return err; } bcmos_sem_create(&dev_log.save_task_is_terminated, 0, 0, "save_task_sem"); bcmos_sem_create(&dev_log.print_task_is_terminated, 0, 0, "print_task_sem"); dev_log.state = BCM_DEV_LOG_STATE_ENABLED; return BCM_ERR_OK; } void bcm_dev_log_destroy(void) { bcmos_errno err; uint32_t i; bcmos_msg_send_flags msg_flags; if (dev_log.state == BCM_DEV_LOG_STATE_UNINITIALIZED) { return; } /* Send a shutdown message to each task. When received by the main loops, it will tear down the tasks gracefully. * If the flag is set to tear down immediately, we'll send an URGENT teardown message, so it'll be handled before * all oustanding log messages (the oustanding log messages will be freed during bcmos_msg_queue_destroy). */ msg_flags = BCMOS_MSG_SEND_NOLIMIT; if ((dev_log.flags & BCM_DEV_LOG_FLAG_DESTROY_IMMEDIATELY) != 0) msg_flags |= BCMOS_MSG_SEND_URGENT; /* The save task depends on the print task, so we terminate the save task first. */ bcmos_msg_send(&dev_log.save_queue, &shutdown_msg, msg_flags); bcmos_sem_wait(&dev_log.save_task_is_terminated, BCMOS_WAIT_FOREVER); bcmos_msg_send(&dev_log.print_queue, &shutdown_msg, msg_flags); bcmos_sem_wait(&dev_log.print_task_is_terminated, BCMOS_WAIT_FOREVER); bcmos_sem_destroy(&dev_log.save_task_is_terminated); bcmos_sem_destroy(&dev_log.print_task_is_terminated); err = bcmos_task_destroy(&dev_log.save_task); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't destroy dev_log save task (error: %d)\n", (int)err); } err = bcmos_task_destroy(&dev_log.print_task); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't destroy dev_log print task (error: %d)\n", (int)err); } err = bcmos_msg_queue_destroy(&dev_log.save_queue); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't destroy save queue (error: %d)\n", (int)err); } err = bcmos_msg_queue_destroy(&dev_log.print_queue); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't destroy print queue (error: %d)\n", (int)err); } err = bcmos_msg_pool_destroy(&dev_log.pool); if (err != BCM_ERR_OK) { DEV_LOG_ERROR_PRINTF("Error: Can't destroy pool (error: %d)\n", (int)err); } for (i = 0; (i < DEV_LOG_MAX_FILES) && (dev_log.dev_log_parm.log_file[i].flags & BCM_DEV_LOG_FILE_FLAG_VALID); i++) { dev_log.files[i].file_parm.close_cb(&dev_log.files[i]); } dev_log.state = BCM_DEV_LOG_STATE_UNINITIALIZED; } typedef struct { bcmos_msg msg; dev_log_queue_msg log_queue_msg; bcmos_bool lock; bcmos_fastlock fastlock; } bcm_dev_log_drop_msg; typedef struct { bcm_dev_log_drop_msg msg; uint32_t drops; uint32_t reported_drops; bcmos_timer timer; uint32_t last_report_timestamp; } bcm_dev_log_drop; static bcm_dev_log_drop dev_log_drop; static void bcm_dev_log_log_message_release_drop(bcmos_msg *m) { unsigned long flags; flags = bcmos_fastlock_lock(&dev_log_drop.msg.fastlock); dev_log_drop.msg.lock = BCMOS_FALSE; bcmos_fastlock_unlock(&dev_log_drop.msg.fastlock, flags); /* Schedule a timer to report extra drops, because we may not meet DEV_LOG_DROP_REPORT_DROP_THRESHOLD soon. */ bcmos_timer_start(&dev_log_drop.timer, DEV_LOG_DROP_REPORT_RATE_US); } static void _bcm_dev_log_drop_report(void) { bcmos_msg *msg; dev_log_queue_msg *log_queue_msg; static char drop_str[MAX_DEV_LOG_STRING_SIZE]; msg = &dev_log_drop.msg.msg; msg->release = bcm_dev_log_log_message_release_drop; log_queue_msg = &dev_log_drop.msg.log_queue_msg; log_queue_msg->flags = BCM_LOG_FLAG_DONT_SKIP_PRINT; log_queue_msg->time_stamp = dev_log.dev_log_parm.get_time_cb(); log_queue_msg->msg_level = DEV_LOG_LEVEL_ERROR; sprintf(drop_str, "Log message pool exhausted, dropped message count=%u\n", dev_log_drop.drops - dev_log_drop.reported_drops); log_queue_msg->u.fmt_args.fmt = (const char *)drop_str; log_queue_msg->log_id = (dev_log_id_parm *)def_log_id; log_queue_msg->time_stamp = dev_log.dev_log_parm.get_time_cb(); dev_log_drop.reported_drops = dev_log_drop.drops; dev_log_drop.last_report_timestamp = bcmos_timestamp(); msg->data = log_queue_msg; msg->size = sizeof(*log_queue_msg); bcmos_msg_send(&dev_log.save_queue, msg, BCMOS_MSG_SEND_AUTO_FREE); } void bcm_dev_log_drop_report(void) { unsigned long flags; dev_log_drop.drops++; flags = bcmos_fastlock_lock(&dev_log_drop.msg.fastlock); /* The 1st drop report will be done immediately, because although DEV_LOG_DROP_REPORT_DROP_THRESHOLD isn't reached, the time difference is greater than * DEV_LOG_DROP_REPORT_RATE_US. */ if (dev_log_drop.msg.lock || ((dev_log_drop.drops - dev_log_drop.reported_drops < DEV_LOG_DROP_REPORT_DROP_THRESHOLD) && (bcmos_timestamp() - dev_log_drop.last_report_timestamp < DEV_LOG_DROP_REPORT_RATE_US))) { bcmos_fastlock_unlock(&dev_log_drop.msg.fastlock, flags); return; } dev_log_drop.msg.lock = BCMOS_TRUE; bcmos_fastlock_unlock(&dev_log_drop.msg.fastlock, flags); /* Do the actual report. */ _bcm_dev_log_drop_report(); } static bcmos_timer_rc bcm_dev_log_drop_timer_cb(bcmos_timer *timer, long data) { unsigned long flags; flags = bcmos_fastlock_lock(&dev_log_drop.msg.fastlock); if (dev_log_drop.msg.lock) { bcmos_fastlock_unlock(&dev_log_drop.msg.fastlock, flags); /* Logger task hasn't released the lock yet. * bcm_dev_log_log_message_release_drop() will (re)start drop reporting timer eventually. */ } else { if (dev_log_drop.drops == dev_log_drop.reported_drops) { /* No new drops to report. */ bcmos_fastlock_unlock(&dev_log_drop.msg.fastlock, flags); return BCMOS_TIMER_OK; } dev_log_drop.msg.lock = BCMOS_TRUE; bcmos_fastlock_unlock(&dev_log_drop.msg.fastlock, flags); /* Do the actual report. */ _bcm_dev_log_drop_report(); } return BCMOS_TIMER_OK; } bcmos_errno bcm_dev_log_init_default_logger_ext( bcm_dev_log_parm *dev_log_parm, uint32_t num_files, uint32_t stack_size, bcmos_task_priority priority, uint32_t pool_size) { bcmos_errno err; bcmos_task_parm save_task_parm = {0}; bcmos_task_parm print_task_parm = {0}; bcmos_msg_queue_parm print_queue_parm = {0}; bcmos_msg_queue_parm save_queue_parm = {0}; bcmos_msg_pool_parm pool_parm = {0}; bcmos_timer_parm timer_params = { .name = "dev_log_drop_timer", .owner = BCMOS_MODULE_ID_NONE, /* Will be called in ISR context */ .handler = bcm_dev_log_drop_timer_cb, }; if (!dev_log_parm) { DEV_LOG_ERROR_PRINTF("Error: dev_log_parm must be set\n"); return BCM_ERR_PARM; } save_task_parm.priority = priority; save_task_parm.stack_size = stack_size; save_task_parm.name = "dev_log_save"; save_task_parm.handler = dev_log_save_task; save_task_parm.data = 0; print_task_parm.priority = priority; print_task_parm.stack_size = stack_size; print_task_parm.name = "dev_log_print"; print_task_parm.handler = dev_log_print_task; print_task_parm.data = 0; /* It is important to avoid terminating logger task during an exception, as logger task is low priority and might have backlog of unhandled messages. * Even if as a result of the exception the logger task will be in a deadlock waiting for a resource (semaphore/mutex/timer), it is in lower priority than CLI and thus should not block * CLI. */ save_task_parm.flags = BCMOS_TASK_FLAG_NO_SUSPEND_ON_OOPS; print_task_parm.flags = BCMOS_TASK_FLAG_NO_SUSPEND_ON_OOPS; save_queue_parm.name = "dev_log_save"; save_queue_parm.size = 0; /* unlimited */ print_queue_parm.name = "dev_log_print"; print_queue_parm.size = 0; /* unlimited */ pool_parm.name = "dev_log"; pool_parm.size = pool_size; pool_parm.data_size = sizeof(dev_log_queue_msg); def_log_id = bcm_dev_log_id_register("default", DEV_LOG_LEVEL_INFO, DEV_LOG_ID_TYPE_BOTH); err = bcmos_timer_create(&dev_log_drop.timer, &timer_params); BCMOS_TRACE_CHECK_RETURN(err, err, "bcmos_timer_create"); bcmos_fastlock_init(&dev_log_drop.msg.fastlock, 0); if (!dev_log_parm->get_time_cb) dev_log_parm->get_time_cb = bcmos_timestamp; err = bcm_dev_log_create( dev_log_parm, &save_task_parm, &print_task_parm, &save_queue_parm, &print_queue_parm, &pool_parm); BCMOS_TRACE_CHECK_RETURN(err, err, "bcm_dev_log_create"); return BCM_ERR_OK; } bcmos_errno bcm_dev_log_init_default_logger(void **start_addresses, uint32_t *sizes, bcm_dev_log_file_flags *flags, uint32_t num_files, uint32_t stack_size, bcmos_task_priority priority, uint32_t pool_size) { bcm_dev_log_parm dev_log_parm = {0}; uint32_t i; for (i = 0; i < num_files; i++) { dev_log_parm.log_file[i].start_addr = start_addresses[i]; dev_log_parm.log_file[i].size = sizes[i]; /* size[i] might be 0 in simulation build for sram buffer. */ dev_log_parm.log_file[i].flags = (bcm_dev_log_file_flags) ((sizes[i] ? BCM_DEV_LOG_FILE_FLAG_VALID : BCM_DEV_LOG_FILE_FLAG_NONE) | (flags ? flags[i] : BCM_DEV_LOG_FILE_FLAG_WRAP_AROUND)); } return bcm_dev_log_init_default_logger_ext(&dev_log_parm, num_files, stack_size, priority, pool_size); } /* Log entry timestamp formatting callback */ static int bcm_log_time_to_ms_str_cb(uint32_t time_stamp, char *time_str, int time_str_size) { return snprintf(time_str, time_str_size, "%u", time_stamp / 1000); /* convert from usec to msec. */ } /* Simplified init function intended mainly for host use */ bcmos_errno bcm_log_init(const dev_log_init_parms *init_parms) { bcmos_errno rc; bcm_dev_log_parm log_parms = {}; uint32_t queue_size; log_parms.time_to_str_cb = bcm_log_time_to_ms_str_cb; if (init_parms->type == BCM_DEV_LOG_FILE_MEMORY) { log_parms.log_file[0].size = init_parms->mem_size ? init_parms->mem_size : BCM_DEV_LOG_DEFAULT_MEM_SIZE; log_parms.log_file[0].start_addr = bcmos_calloc(log_parms.log_file[0].size); log_parms.log_file[0].flags = (bcm_dev_log_file_flags)(BCM_DEV_LOG_FILE_FLAG_WRAP_AROUND | BCM_DEV_LOG_FILE_FLAG_CLEAR_AFTER_READ); if (log_parms.log_file[0].start_addr == NULL) return BCM_ERR_NOMEM; } #ifdef BCM_OS_POSIX else if (init_parms->type == BCM_DEV_LOG_FILE_REGULAR) { if (init_parms->filename == NULL) { bcmos_printf("%s: filename is required for log type BCMOLT_LOG_TYPE_FILE\n", __FUNCTION__); return BCM_ERR_PARM; } log_parms.log_file[0].udef_parms = (char *)(long)init_parms->filename; } #endif else #ifdef DEV_LOG_SYSLOG if (init_parms->type != BCM_DEV_LOG_FILE_SYSLOG) #endif { bcmos_printf("%s: log type %d is invalid\n", __FUNCTION__, init_parms->type); return BCM_ERR_PARM; } log_parms.log_file[0].type = init_parms->type; log_parms.log_file[0].flags |= BCM_DEV_LOG_FILE_FLAG_VALID; queue_size = init_parms->queue_size ? init_parms->queue_size : BCM_DEV_LOG_DEFAULT_QUEUE_SIZE; /* Only init a single log file */ rc = bcm_dev_log_init_default_logger_ext(&log_parms, 1, 0x4000, TASK_PRIORITY_DEV_LOG, queue_size); BCMOS_TRACE_CHECK_RETURN(rc, rc, "bcm_dev_log_init_default_logger_ext()\n"); bcm_dev_log_level_set_style(DEV_LOG_LEVEL_WARNING, BCM_DEV_LOG_STYLE_BOLD); if (init_parms->post_init_cb != NULL) { rc = init_parms->post_init_cb(); BCMOS_TRACE_CHECK_RETURN(rc, rc, "%s: post_init_cb()\n", __FUNCTION__); } BCM_LOG(INFO, def_log_id, "Logging started\n"); return BCM_ERR_OK; } log_name_table logs_names[DEV_LOG_MAX_IDS]; uint8_t log_name_table_index = 0; static void dev_log_add_log_name_to_table(const char *name) { char _name[MAX_DEV_LOG_ID_NAME + 1] = {}; char *p = _name; char *p_end; int i = 0; long val = -1; strncpy(_name, name, MAX_DEV_LOG_ID_NAME); while (*p) { /* While there are more characters to process... */ if (isdigit(*p)) { /* Upon finding a digit, ... */ val = strtol(p, &p_end, 10); /* Read a number, ... */ if ((_name + strlen(_name)) != p_end) { DEV_LOG_ERROR_PRINTF("Error: dev_log_add_log_name_to_table %s)\n", name); } *p = '\0'; break; } else { /* Otherwise, move on to the next character. */ p++; } } for (i = 0; i < log_name_table_index; i++) { if (strcmp(_name, logs_names[i].name) == 0) { if (val < logs_names[i].first_instance) { logs_names[i].first_instance = val; } if (val > logs_names[i].last_instance) { logs_names[i].last_instance = val; } break; } } if ((i == log_name_table_index) && (i < DEV_LOG_MAX_IDS)) { strncpy(logs_names[i].name, name, MAX_DEV_LOG_ID_NAME); if (val == -1) { val = LOG_NAME_NO_INSTANCE; } logs_names[i].last_instance = val; logs_names[i].first_instance = val; log_name_table_index++; } } void dev_log_get_log_name_table(char *buffer, uint32_t buf_len) { uint32_t i = 0; uint32_t buf_len_free = buf_len; buffer[0] = '\0'; for (i = 0; i < log_name_table_index; i++) { if (logs_names[i].first_instance == LOG_NAME_NO_INSTANCE) { snprintf(&buffer[strlen(buffer)], buf_len_free, "%s\n", logs_names[i].name); } else { snprintf(&buffer[strlen(buffer)], buf_len_free, "%s %d - %d\n", logs_names[i].name, logs_names[i].first_instance, logs_names[i].last_instance); } buffer[buf_len - 1] = '\0'; buf_len_free = buf_len - strlen(buffer); if (buf_len_free <= 1) { DEV_LOG_ERROR_PRINTF("Error: dev_log_get_log_name_table too long\n"); break; } } } static dev_log_id _bcm_dev_log_id_get_by_name(const char *name) { uint32_t i; for (i = 0; i < BCM_SIZEOFARRAY(dev_log.ids); i++) { if (!dev_log.ids[i].is_active) continue; if (!strcmp(dev_log.ids[i].name, name)) { return (dev_log_id)&dev_log.ids[i]; } } return DEV_LOG_INVALID_ID; } static dev_log_id_parm *bcm_dev_log_get_free_id(void) { uint32_t i; for (i = 0; i < BCM_SIZEOFARRAY(dev_log.ids); i++) { if (!dev_log.ids[i].is_active) return &dev_log.ids[i]; } return NULL; } dev_log_id bcm_dev_log_id_register(const char *name, bcm_dev_log_level default_log_level, bcm_dev_log_id_type default_log_type) { dev_log_id_parm *new_id; /* Check that we have room for one more ID */ new_id = bcm_dev_log_get_free_id(); if (!new_id) { DEV_LOG_ERROR_PRINTF("Error: Failed to register log ID for '%s' - out of free log IDs\n", name); return DEV_LOG_INVALID_ID; } /* Check that the log name isn't already registered */ if (!(dev_log.flags & BCM_DEV_LOG_FLAG_ALLOW_DUPLICATES) && _bcm_dev_log_id_get_by_name(name) != DEV_LOG_INVALID_ID) { DEV_LOG_ERROR_PRINTF("Error: duplicate log name \"%s\"\n", name); return DEV_LOG_INVALID_ID; } /* Add prefix for kernel log_ids in order to avoid clash with similarly-names logs in the user space */ #ifdef __KERNEL__ strcpy(new_id->name, "k_"); #endif /* Set log_id parameters */ strncat(new_id->name, name, sizeof(new_id->name) - strlen(new_id->name)); new_id->name[MAX_DEV_LOG_ID_NAME - 1] = '\0'; new_id->default_log_type = default_log_type; new_id->default_log_level = default_log_level; dev_log_add_log_name_to_table(new_id->name); bcm_dev_log_id_set_levels_and_type_to_default((dev_log_id)new_id); new_id->style = BCM_DEV_LOG_STYLE_NORMAL; new_id->is_active = BCMOS_TRUE; return (dev_log_id)new_id; } void bcm_dev_log_id_unregister(dev_log_id id) { dev_log_id_parm *parm = (dev_log_id_parm *)id; parm->is_active = BCMOS_FALSE; *parm->name = '\0'; } bcmos_errno bcm_dev_log_id_set_type(dev_log_id id, bcm_dev_log_id_type log_type) { dev_log_id_parm *parm = (dev_log_id_parm *)id; if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } /* In linux kernel we only support save */ #ifdef __KERNEL__ if (log_type & DEV_LOG_ID_TYPE_BOTH) log_type = DEV_LOG_ID_TYPE_SAVE; #endif DEV_LOG_INFO_PRINTF("ID: 0x%lx, New log type: %d\n", id, (int)log_type); parm->log_type = log_type; /* In linux user space we need to notify kernel integration code */ #if defined(LINUX_KERNEL_SPACE) && !defined(__KERNEL__) if (using_inband_get()) { bcm_dev_log_linux_id_set_type_ud(id, log_type); } else { bcm_dev_log_linux_id_set_type(id, log_type); } #endif return BCM_ERR_OK; } bcmos_errno bcm_dev_log_id_set_level(dev_log_id id, bcm_dev_log_level log_level_print, bcm_dev_log_level log_level_save) { dev_log_id_parm *parm = (dev_log_id_parm *)id; if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } if ((log_level_print >= DEV_LOG_LEVEL_NUM_OF) || (log_level_save >= DEV_LOG_LEVEL_NUM_OF)) { DEV_LOG_ERROR_PRINTF("Error: wrong parameters\n"); return BCM_ERR_PARM; } DEV_LOG_INFO_PRINTF("ID: 0x%p, New: log_level_print=%u, log_level_save=%u\n", (void *)parm, log_level_print, log_level_save); parm->log_level_print = log_level_print; parm->log_level_save = log_level_save; /* In linux user space we need to notify kernel integration code */ #if defined(LINUX_KERNEL_SPACE) && !defined(__KERNEL__) if (using_inband_get()) { bcm_dev_log_linux_id_set_level_ud(id, log_level_print, log_level_save); } else { bcm_dev_log_linux_id_set_level(id, log_level_print, log_level_save); } #endif return BCM_ERR_OK; } bcmos_errno bcm_dev_log_id_set_levels_and_type_to_default(dev_log_id id) { dev_log_id_parm *parm = (dev_log_id_parm *)id; if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } parm->log_level_print = parm->default_log_level; parm->log_level_save = parm->default_log_level; parm->log_type = parm->default_log_type; #ifdef TRIGGER_LOGGER_FEATURE memset(&parm->throttle,0, sizeof(dev_log_id_throttle)); memset(&parm->trigger, 0, sizeof(dev_log_id_trigger)); parm->throttle_log_level = DEV_LOG_LEVEL_NO_LOG; parm->trigger_log_level = DEV_LOG_LEVEL_NO_LOG; #endif /* In linux kernel space we don't support PRINT, only SAVE */ #ifdef __KERNEL__ if (parm->log_type & DEV_LOG_ID_TYPE_BOTH) parm->log_type = DEV_LOG_ID_TYPE_SAVE; #endif return BCM_ERR_OK; } void bcm_dev_log_level_set_style(bcm_dev_log_level level, bcm_dev_log_style style) { dev_log_level2style[level] = style; } bcmos_errno bcm_dev_log_id_set_style(dev_log_id id, bcm_dev_log_style style) { dev_log_id_parm *parm = (dev_log_id_parm *)id; if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } parm->style = style; return BCM_ERR_OK; } bcmos_errno bcm_dev_log_id_clear_counters(dev_log_id id) { dev_log_id_parm *parm = (dev_log_id_parm *)id; if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } memset(parm->counters, 0, sizeof(parm->counters)); parm->lost_msg_cnt = 0; parm->print_skipped_count = 0; return BCM_ERR_OK; } bcmos_errno bcm_dev_log_id_get(dev_log_id id, dev_log_id_parm *parm) { if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } *parm = *(dev_log_id_parm *)id; return BCM_ERR_OK; } bcmos_errno bcm_dev_log_id_set(dev_log_id id, dev_log_id_parm *parm) { if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } *(dev_log_id_parm *)id = *parm; return BCM_ERR_OK; } dev_log_id bcm_dev_log_id_get_by_index(uint32_t index) { if (index >= BCM_SIZEOFARRAY(dev_log.ids) || !dev_log.ids[index].is_active) return DEV_LOG_INVALID_ID; return (dev_log_id)&dev_log.ids[index]; } uint32_t bcm_dev_log_get_index_by_id(dev_log_id id) { uint32_t idx = (dev_log_id_parm *)id - &dev_log.ids[0]; if (idx >= BCM_SIZEOFARRAY(dev_log.ids)) idx = DEV_LOG_INVALID_INDEX; /* Return idx even is "is_active" is false. This is because the callers rely on this. */ return idx; } dev_log_id bcm_dev_log_id_get_next(dev_log_id id) { if (id == DEV_LOG_INVALID_ID) id = (dev_log_id)&dev_log.ids; else id = (dev_log_id)((dev_log_id_parm *)id + 1); for (; bcm_dev_log_get_index_by_id(id) != DEV_LOG_INVALID_INDEX && !((dev_log_id_parm *)id)->is_active; id = (dev_log_id)((dev_log_id_parm *)id + 1)); return bcm_dev_log_get_index_by_id(id) == DEV_LOG_INVALID_INDEX ? DEV_LOG_INVALID_ID : id; } dev_log_id bcm_dev_log_id_get_by_name(const char *name) { dev_log_id id; if (name == NULL) { return DEV_LOG_INVALID_ID; } id = _bcm_dev_log_id_get_by_name(name); if (id == DEV_LOG_INVALID_ID) { DEV_LOG_ERROR_PRINTF("Error: can't find name\n"); } return id; } bcmos_bool bcm_dev_log_get_control(void) { return dev_log.state == BCM_DEV_LOG_STATE_ENABLED; } uint32_t bcm_dev_log_get_num_of_messages(const bcm_dev_log_file *file) { return file->u.mem_file.file_header.num_msgs; } void bcm_dev_log_set_control(bcmos_bool control) { if (control && dev_log.state == BCM_DEV_LOG_STATE_DISABLED) dev_log.state = BCM_DEV_LOG_STATE_ENABLED; else if (!control && dev_log.state == BCM_DEV_LOG_STATE_ENABLED) dev_log.state = BCM_DEV_LOG_STATE_DISABLED; } bcm_dev_log_file_flags bcm_dev_log_get_file_flags(uint32_t file_id) { return dev_log.files[file_id].file_parm.flags; } void bcm_dev_log_set_file_flags(uint32_t file_id, bcm_dev_log_file_flags flags) { dev_log.files[file_id].file_parm.flags = flags; } bcm_dev_log_flags bcm_dev_log_get_flags(void) { return dev_log.flags; } void bcm_dev_log_set_flags(bcm_dev_log_flags flags) { dev_log.flags = flags; } void bcm_dev_log_set_print_cb(bcm_dev_log_print_cb cb) { dev_log.dev_log_parm.print_cb = cb; } void bcm_dev_log_set_get_time_cb(bcm_dev_log_get_time_cb cb) { dev_log.dev_log_parm.get_time_cb = cb; } void bcm_dev_log_set_time_to_str_cb(bcm_dev_log_time_to_str_cb cb) { dev_log.dev_log_parm.time_to_str_cb = cb; } #ifdef TRIGGER_LOGGER_FEATURE /********************************************************************************************/ /* */ /* Name: bcm_dev_log_set_throttle */ /* */ /* Abstract: Set throttle level for the specific log is and its level */ /* */ /* Arguments: */ /* - id - The ID in the Dev log (what we got form bcm_dev_log_id_register) */ /* - log_level - log level */ /* - throttle - throttle number, 0 - no throttle */ /* */ /* Return Value: */ /* bcmos_errno - Success code (BCM_ERR_OK) or Error code (see bcmos_errno.h) */ /* */ /********************************************************************************************/ bcmos_errno bcm_dev_log_set_throttle(dev_log_id id, bcm_dev_log_level log_level, uint32_t throttle) { dev_log_id_parm *parm = (dev_log_id_parm *)id; if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } parm->throttle_log_level = log_level; parm->throttle.threshold = throttle; parm->throttle.counter = 0; return BCM_ERR_OK; } /********************************************************************************************/ /* */ /* Name: bcm_dev_log_set_trigger */ /* */ /* Abstract: Set trigger counters for the specific log is and its level */ /* */ /* Arguments: */ /* - id - The ID in the Dev log (what we got form bcm_dev_log_id_register) */ /* - log_level - log level */ /* - start - start printing after this number, 0 - no trigger */ /* - stop - stop printing after this number, 0 - do not stop */ /* - repeat - start printing after this number, 0 - no repeat, -1 always */ /* */ /* Return Value: */ /* bcmos_errno - Success code (BCM_ERR_OK) or Error code (see bcmos_errno.h) */ /* */ /********************************************************************************************/ bcmos_errno bcm_dev_log_set_trigger(dev_log_id id, bcm_dev_log_level log_level, uint32_t start, uint32_t stop, int32_t repeat) { dev_log_id_parm *parm = (dev_log_id_parm *)id; if (!id || (id == DEV_LOG_INVALID_ID)) { DEV_LOG_ERROR_PRINTF("Error: id not valid (0x%x)\n", (unsigned int)id); return BCM_ERR_PARM; } parm->trigger_log_level = log_level; parm->trigger.start_threshold = start; parm->trigger.stop_threshold = stop; parm->trigger.repeat_threshold = repeat; parm->trigger.counter = 0; parm->trigger.repeat = 0; return BCM_ERR_OK; } #endif /* TRIGGER_LOGGER_FEATURE */ /* Get file info: max data size, used bytes */ bcmos_errno bcm_dev_log_get_file_info(bcm_dev_log_file *file, uint32_t *file_size, uint32_t *used_bytes) { if (!file || !file_size || !used_bytes) return BCM_ERR_PARM; /* Only supported for memory files */ if (!bcm_dev_log_is_memory_file(file)) return BCM_ERR_NOT_SUPPORTED; *file_size = file->u.mem_file.file_header.data_size; *used_bytes = (file->u.mem_file.file_header.file_wrap_cnt || file->is_full) ? file->u.mem_file.file_header.data_size : file->u.mem_file.file_header.write_offset; return BCM_ERR_OK; } /* Register indication to be sent when file utilization crosses threshold */ bcmos_errno bcm_dev_log_almost_full_ind_register(bcm_dev_log_file *file, uint32_t used_bytes_threshold, F_dev_log_file_almost_full send_ind_cb, long ind_cb_priv) { if (!file || (used_bytes_threshold && !send_ind_cb)) return BCM_ERR_PARM; /* Only supported for memory files */ if (!bcm_dev_log_is_memory_file(file)) return BCM_ERR_NOT_SUPPORTED; bcmos_mutex_lock(&file->u.mem_file.mutex); file->almost_full.threshold = used_bytes_threshold; file->almost_full.send_ind_cb = send_ind_cb; file->almost_full.priv = ind_cb_priv; file->almost_full.ind_sent = BCMOS_FALSE; bcmos_mutex_unlock(&file->u.mem_file.mutex); return BCM_ERR_OK; } #endif /* ENABLE_LOG */
the_stack_data/26700697.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define N 50 int main( ) { int a1[N]; int a2[N]; int a3[N]; int a4[N]; int a5[N]; int i; for ( i = 0 ; i < N ; i++ ) { a2[i] = a1[i]; } for ( i = 0 ; i < N ; i++ ) { a3[i] = a2[i]; } for ( i = 0 ; i < N ; i++ ) { a4[i] = a3[i]; } for ( i = 0 ; i < N ; i++ ) { a5[i] = a4[i]; } int x; for ( x = 0 ; x < N ; x++ ) { __VERIFIER_assert( a1[x] == a5[x] ); } return 0; }
the_stack_data/31387553.c
/* * Does a fuse mount first and then loads whatever fuse module * is loaded by the following command, as long as that command starts a * fuse filesystem and accepts the mountpoint as the last parameter. * Replaces the mountpoint with /dev/fd/NN where NN is a file descriptor * returned from opening /dev/fuse. Requires libfuse >= 3.3.0. * To compile and make setuid as root: * # cc -o fuse-premount fuse-premunt.c * # chmod 4755 fuse-premount * Written by Dave Dykstra 29 March 2019 */ #include <sys/types.h> #include <sys/stat.h> #include <sys/mount.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <string.h> #include <errno.h> int main(int argc, char **argv) { char *mnt; char tmp[128]; struct stat stbuf; int fd; int res; int i; printf("UID %d %d\n", geteuid(), getuid()); if (geteuid() != 0 || getuid() == 0) { fprintf(stderr, "Not running as setuid root\n", argv[0]); return 1; } mnt = argv[argc-1]; if (access(mnt, W_OK) != 0) { fprintf(stderr ,"%s: no write access mountpoint %s: %s\n", argv[0], mnt, strerror(errno)); return 1; } /* based on https://github.com/libfuse/libfuse/blob/fuse-3.3.0/lib/mount.c */ res = stat(mnt, &stbuf); if (res == -1) { fprintf(stderr ,"%s: failed to access mountpoint %s: %s\n", argv[0], mnt, strerror(errno)); return 1; } fd = open("/dev/fuse", O_RDWR); if (fd == -1) { fprintf(stderr, "%s: failed to open /dev/fuse: %s\n", argv[0], strerror(errno)); return 1; } snprintf(tmp, sizeof(tmp), "fd=%i,rootmode=%o,user_id=%u,group_id=%u", fd, stbuf.st_mode & S_IFMT, getuid(), getgid()); res = mount("/dev/fuse", mnt, "fuse", 0, tmp); if (res == -1) { fprintf(stderr ,"%s: failed to mount -o %s /dev/fuse %s: %s\n", argv[0], tmp, mnt, strerror(errno)); return 1; } if (setgid(getgid()) != 0) { fprintf(stderr ,"%s: failed to drop gid privilege: %s\n", argv[0], strerror(errno)); return 1; } if (setuid(getuid()) != 0) { fprintf(stderr ,"%s: failed to drop gid privilege: %s\n", argv[0], strerror(errno)); return 1; } if (setuid(0) == 0 || seteuid(0) == 0) { fprintf(stderr ,"%s: did not successfully drop root privilege\n", argv[0]); return 1; } snprintf(tmp, sizeof(tmp), "/dev/fd/%d", fd); argv[argc-1] = tmp; printf("+ "); for (i=1; i < argc; i++) printf("%s ", argv[i]); printf("\n"); fflush(stdout); execvp(argv[1],&argv[1]); perror("failed to execvp"); return(1); }
the_stack_data/184517624.c
/* vim: set cin et sw=4 ts=4: */ /* * fprm - print file permissions similar to `ls' * Copyright (C) 2012-2015 Jakob Kramer <[email protected]> * * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * In jurisdictions that recognize copyright laws, the author or authors * of this software dedicate any and all copyright interest in the * software to the public domain. We make this dedication for the benefit * of the public at large and to the detriment of our heirs and * successors. We intend this dedication to be an overt act of * relinquishment in perpetuity of all present and future rights to this * software under copyright law. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * For more information, please refer to <http://unlicense.org/> */ #include <stdio.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <sys/stat.h> void errexit(const char *str) { if (errno) fprintf(stderr, "%s: %s\n", str, strerror(errno)); else fprintf(stderr, "%s\n", str); exit(EXIT_FAILURE); } int main(int argc, char* argv[]) { int group, offset, file; struct stat s; char output[11] = "----------"; if (argc < 2) errexit("Usage: fprm FILE..."); for (file = 1; file < argc; file++) { if (stat(argv[file], &s) == -1) errexit("fprm: stat() failed"); if (S_ISDIR(s.st_mode)) output[0] = 'd'; for (group = 0100, offset = 0; group >= 1; group /= 010, offset += 3) { if (s.st_mode & (group * 4)) output[1 + offset] = 'r'; if (s.st_mode & (group * 2)) output[2 + offset] = 'w'; if (s.st_mode & group) output[3 + offset] = 'x'; } /* print file name, if there is more than one file specified */ if (argc > 2) printf("%s: ", argv[file]); puts(output); } return EXIT_SUCCESS; }
the_stack_data/25136733.c
/*BEGIN_LEGAL Intel Open Source License Copyright (c) 2002-2013 Intel Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. END_LEGAL */ /* This verifies that the interceptsegv_for_oaddr_cache.test ran as expected by analyzing the oaddr cache info activity in the pin.log file produced by the test */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <signal.h> #include <assert.h> #include <setjmp.h> #include <sys/types.h> #define MAX_STR 4096 char line[MAX_STR]; int numInvalidations = 0; int numFinds = 0; int numFindsAfterInvalidation = 0; void VerifyAndExit() { if (numInvalidations > 0 && numFinds > 0 && numFindsAfterInvalidation > 0) { exit (0); } else { if (numInvalidations <= 0) { printf ("** error expected to have some invalidations\n"); } if (numFinds <= 0) { printf ("** error expected to have some finds\n"); } if (numFindsAfterInvalidation <= 0) { printf ("** error expected to have some finds after invalidation\n"); } exit (-1); } } char *AdvanceToBlank (char *ptr) { while (*ptr != ' ') { ptr++; } return (ptr); } char *AdvanceToNonBlank (char *ptr) { while (*ptr == ' ') { ptr++; } return (ptr); } int readln (FILE *fp, char *target) { int i = 0; memset (target, 0, MAX_STR); while (1) { target[i] = fgetc (fp); if (EOF == target[i]) { target[i] = '\n'; return (EOF); } if ('\n' == target[i]) { target[i] = ' '; target[i+1] = 0; break; } /* if (0xa == target[i]) { break; } if (0xd == target[i]) { break; } */ i++; } return (EOF+1); } #define MAX_CRBS 8 char curOaddr[32]; struct crb { char name[32]; char ccEntryName[32]; char oaddrName[32]; }; struct crb crbs[MAX_CRBS]; int numCrbs = 0; /* ptr points to -> <- endPtr points to ccd: New cachedOaddrInfo 0xfeb660 for oaddr 0x604f6c ccEntry is 0x66c054 ccEntry iaddr 0x804853f ccEntry oaddr 0x604f58 */ void RecordNewCachedOaddrInfo(char *ptr, char *endPtr) { int i; *endPtr = 0; crbs[numCrbs].name[0] = 0; crbs[numCrbs].ccEntryName[0] = 0; crbs[numCrbs].oaddrName[0] = 0; strcpy (crbs[numCrbs].name, ptr); *endPtr = ' '; ptr = strstr (ptr, "is"); if (ptr==NULL) { printf ("** error could not find ccEntry is\n"); exit (-1); } ptr = AdvanceToBlank(ptr); ptr = AdvanceToNonBlank(ptr); endPtr = AdvanceToBlank(ptr); *endPtr = 0; strcpy (crbs[numCrbs].ccEntryName, ptr); *endPtr = ' '; strcpy (crbs[numCrbs].oaddrName, curOaddr); printf ("** new cachedRegBindings# %d name %s ccEntryName %s oaddrName %s\n", numCrbs, crbs[numCrbs].name, crbs[numCrbs].ccEntryName, crbs[numCrbs].oaddrName); /* verify we do not have this recorded - if it is then it should have been found */ for (i=0; i<numCrbs; i++) { if (!strcmp(crbs[numCrbs].oaddrName, crbs[i].oaddrName)) { printf ("** error found entry for same oaddrName at cachedOaddrInfo# %d\n", i); exit (-1); } } numCrbs++; } void HandleLookup(char *line) { char *endPtr; printf ("%s\n", line); char *ptr = strstr (line, "0x"); if (ptr == NULL) { exit (-1); } endPtr = AdvanceToBlank (ptr); *endPtr = '\0'; strcpy(curOaddr, ptr); } /* ccd: New cachedRegBindings 0xfeb660 for oaddr 0x604f6c ccEntry is 0x66c054 ccEntry iaddr 0x804853f ccEntry oaddr 0x604f58 */ void HandleNew(char * line) { char *ptr = strstr (line,"cachedRegBindings"); char *endPtr; printf ("%s\n", line); printf ("** New cachedRegBindings:\n"); if (ptr==NULL) { printf ("** error could not find cachedRegBindings\n"); exit(-1); } ptr = AdvanceToBlank (ptr); ptr = AdvanceToNonBlank (ptr); endPtr = AdvanceToBlank (ptr); RecordNewCachedOaddrInfo (ptr, endPtr); } /* ccd: Found cachedRegBindings 0xfeb660 */ void HandleFound(char *line) { char *ptr = strstr (line, "cachedRegBindings"); char *endPtr; int found = 0; int i, theCrbs, x; printf ("%s\n", line); if (ptr==NULL) { printf ("** error could not find cachedRegBindings\n"); exit(-1); } ptr = AdvanceToBlank (ptr); ptr = AdvanceToNonBlank (ptr); endPtr = AdvanceToBlank (ptr); *endPtr = 0; for (i=0; i<numCrbs; i++) { if (!strcmp(crbs[i].name, ptr)) { found = 1; theCrbs = i; break; } } if (!found) { printf ("** error could not find a valid cachedRegBindings with name %s\n", ptr); exit (-1); } if (strcmp(crbs[theCrbs].oaddrName, curOaddr)) { printf ("** error cachedRegBindings# %d has different oaddr %s %s\n", theCrbs, crbs[theCrbs].oaddrName, curOaddr); exit (-1); } numFinds++; if (numInvalidations>0) { numFindsAfterInvalidation++; } } /* ccd: Invalidate ccEntry 0x2cd054 ccd: Remove cachedRegBindings 0x124700 ccEntry is 0x2cd054 ccEntry iaddr 0x804853f */ void HandleInvalidate (char *line, FILE *fp) { char *ptr; char * endPtr; int i, x; int numFound; printf ("\n%s\n", line); x = readln (fp, line); if (x == EOF) { printf ("** error unexpected EOF100\n"); exit (-1); } printf ("%s\n", line); ptr = strstr (line, "RemoveEntriesInRange oaddr"); if (ptr==NULL) { return; } while (1) { x = readln (fp, line); if (x == EOF) { printf ("** error unexpected EOF10\n"); exit (-1); } printf ("%s\n", line); ptr = strstr (line, "None found"); if (ptr != NULL) { return; } ptr = strstr (line, "Remove cachedRegBindings"); if (ptr == NULL) { return; } ptr = strstr (line, "0x"); if (ptr == NULL) { printf ("** error could not find the address of the cachedRegBinding\n"); exit (-1); } endPtr = AdvanceToBlank(ptr); *endPtr = '\0'; numFound = 0; for (i=0; i<numCrbs; i++) { if (!strcmp(crbs[i].name, ptr)) { crbs[i].name[0] = 0; numFound++; } } if (numFound != 1) { printf ("** error did not expect to find %d etries to invalidate\n", numFound); exit (-1); } numInvalidations++; } } int main (int argc, char*argv[]) { int x; FILE *fp = fopen (argv[1], "r"); if (fp==NULL) { printf ("** error could not open pin logfile: %s\n", argv[1]); exit(-1); } x = readln (fp, line); if (x == EOF) { printf ("** error unexpected EOF100\n"); exit (-1); } while(1) { if (strstr (line, "Lookup")) { HandleLookup (line); } else if (strstr (line, "New")) { HandleNew (line); } else if (strstr (line, "Invalidate ccEntry")) { HandleInvalidate (line, fp); } else if (strstr (line, "Found")) { HandleFound (line); } x = readln (fp, line); if (x == EOF) { VerifyAndExit(); } } }
the_stack_data/68925.c
/* Author: Pate Williams (c) 1997 SAFER K-64 (Secure and Fast Encryption Routine). See "Handbook of Applied Cryptography" by Alfred J. Menezes et al 7.7.1 Section pages 266 - 269. */ #include <stdio.h> #include <stdlib.h> /* define the constant number of rounds */ #define ROUNDS 6 #define DEBUG typedef unsigned char uchar; void generate_S_boxes(short *S, short *S_inv) { short g = 45, i, j, t; S[0] = 1, S_inv[1] = 0; for (i = 1; i <= 255; i++) { t = (short) ((g * S[i - 1]) % 257); S[i] = t; S_inv[t] = (uchar) i; } S[128] = 0, S_inv[0] = 128; #ifdef DEBUG for (i = 0; i < 16; i++) { for (j = 0; j < 16; j++) printf("%3d ", S[i * 16 + j]); printf("\n"); } #endif } void SAFER_K_64_key_schedule(short *key, short *S, short *S_inv, uchar **K) { uchar B[2 * ROUNDS + 3][9], R[9], i, i2, j, t; generate_S_boxes(S, S_inv); for (i = 2; i <= 2 * ROUNDS + 1; i++) for (j = 1; j <= 8; j++) B[i][j] = (uchar) S[S[9 * i + j]]; for (i = 0; i < 4; i++) { i2= (uchar) (2 * i); R[i2 + 1] = (uchar) (key[i] >> 8); R[i2 + 2] = (uchar) (key[i] & 255); } #ifdef DEBUG for (i = 1; i <= 8; i++) printf("%3d ", B[2][i]); printf("\n"); for (i = 1; i <= 8; i++) printf("%3d ", B[13][i]); printf("\n"); for (i = 1; i <= 8; i++) printf("%3d ", R[i]); printf("\n"); #endif for (i = 1; i <= 8; i++) K[1][i] = R[i]; for (i = 2; i <= 2 * ROUNDS + 1; i++) { for (j = 1; j <= 8; j ++) { t = R[j]; R[j] = (uchar) ((t << 3) | (t >> 5)); } for (j = 1; j <= 8; j++) K[i][j] = (uchar) ((R[j] + B[i][j]) % 256); } } void f(uchar x, uchar y, uchar *X, uchar *Y) { int a = (2 * x + y) % 256; int b = (x + y) % 256; *X = (uchar) a, *Y = (uchar) b; } void SAFER_K_64_encryption(uchar *X, uchar *Y, short *S, short *S_inv, uchar **K) { uchar i, j; for (i = 1; i <= ROUNDS; i++) { j = (uchar) (2 * i - 1); X[1] ^= K[j][1]; X[4] ^= K[j][4]; X[5] ^= K[j][5]; X[8] ^= K[j][8]; X[2] = (uchar) ((X[2] + K[j][2]) % 256); X[3] = (uchar) ((X[3] + K[j][3]) % 256); X[6] = (uchar) ((X[6] + K[j][6]) % 256); X[7] = (uchar) ((X[7] + K[j][7]) % 256); X[1] = S[X[1]]; X[4] = S[X[4]]; X[5] = S[X[5]]; X[8] = S[X[8]]; X[2] = S_inv[X[2]]; X[3] = S_inv[X[3]]; X[6] = S_inv[X[6]]; X[7] = S_inv[X[7]]; j = (uchar) (2 * i); X[1] = (uchar) ((X[1] + K[j][1]) % 256); X[4] = (uchar) ((X[4] + K[j][4]) % 256); X[5] = (uchar) ((X[5] + K[j][5]) % 256); X[8] = (uchar) ((X[8] + K[j][8]) % 256); X[2] ^= K[j][2]; X[3] ^= K[j][3]; X[6] ^= K[j][6]; X[7] ^= K[j][7]; f(X[1], X[2], &X[1], &X[2]); f(X[3], X[4], &X[3], &X[4]); f(X[5], X[6], &X[5], &X[6]); f(X[7], X[8], &X[7], &X[8]); f(X[1], X[3], &Y[1], &Y[2]); f(X[5], X[7], &Y[3], &Y[4]); f(X[2], X[4], &Y[5], &Y[6]); f(X[6], X[8], &Y[7], &Y[8]); for (j = 1; j <= 8; j++) X[j] = Y[j]; f(X[1], X[3], &Y[1], &Y[2]); f(X[5], X[7], &Y[3], &Y[4]); f(X[2], X[4], &Y[5], &Y[6]); f(X[6], X[8], &Y[7], &Y[8]); for (j = 1; j <= 8; j++) X[j] = Y[j]; } i = 2 * ROUNDS + 1; Y[1] = X[1] ^ K[i][1]; Y[4] = X[4] ^ K[i][4]; Y[5] = X[5] ^ K[i][5]; Y[8] = X[8] ^ K[i][8]; Y[2] = (uchar) ((X[2] + K[i][2]) % 256); Y[3] = (uchar) ((X[3] + K[i][3]) % 256); Y[6] = (uchar) ((X[6] + K[i][6]) % 256); Y[7] = (uchar) ((X[7] + K[i][7]) % 256); } void f_inv(uchar L, uchar R, uchar *l, uchar *r) { int a = (L - R) % 256; int b = (2 * R - L) % 256; *l = (uchar) a, *r = (uchar) b; } void SAFER_K_64_decryption(uchar *X, uchar *Y, short *S, short *S_inv, uchar **K) { uchar i, j; i = 2 * ROUNDS + 1; Y[1] = X[1] ^ K[i][1]; Y[4] = X[4] ^ K[i][4]; Y[5] = X[5] ^ K[i][5]; Y[8] = X[8] ^ K[i][8]; Y[2] = (uchar) ((X[2] - K[i][2]) % 256); Y[3] = (uchar) ((X[3] - K[i][3]) % 256); Y[6] = (uchar) ((X[6] - K[i][6]) % 256); Y[7] = (uchar) ((X[7] - K[i][7]) % 256); for (i = 1; i <= 8; i++) X[i] = Y[i]; for (i = ROUNDS; i >= 1; i--) { f_inv(X[1], X[2], &X[1], &X[2]); f_inv(X[3], X[4], &X[3], &X[4]); f_inv(X[5], X[6], &X[5], &X[6]); f_inv(X[7], X[8], &X[7], &X[8]); f_inv(X[1], X[5], &Y[1], &Y[2]); f_inv(X[2], X[6], &Y[3], &Y[4]); f_inv(X[3], X[7], &Y[5], &Y[6]); f_inv(X[4], X[8], &Y[7], &Y[8]); for (j = 1; j <= 8; j++) X[j] = Y[j]; f_inv(X[1], X[5], &Y[1], &Y[2]); f_inv(X[2], X[6], &Y[3], &Y[4]); f_inv(X[3], X[7], &Y[5], &Y[6]); f_inv(X[4], X[8], &Y[7], &Y[8]); for (j = 1; j <= 8; j++) X[j] = Y[j]; j = (uchar) (2 * i); X[1] = (uchar) ((X[1] - K[j][1]) % 256); X[4] = (uchar) ((X[4] - K[j][4]) % 256); X[5] = (uchar) ((X[5] - K[j][5]) % 256); X[8] = (uchar) ((X[8] - K[j][8]) % 256); X[2] ^= K[j][2]; X[3] ^= K[j][3]; X[6] ^= K[j][6]; X[7] ^= K[j][7]; X[1] = S_inv[X[1]]; X[4] = S_inv[X[4]]; X[5] = S_inv[X[5]]; X[8] = S_inv[X[8]]; X[2] = S[X[2]]; X[3] = S[X[3]]; X[6] = S[X[6]]; X[7] = S[X[7]]; j = (uchar) (2 * i - 1); X[1] ^= K[j][1]; X[4] ^= K[j][4]; X[5] ^= K[j][5]; X[8] ^= K[j][8]; X[2] = (uchar) ((X[2] - K[j][2]) % 256); X[3] = (uchar) ((X[3] - K[j][3]) % 256); X[6] = (uchar) ((X[6] - K[j][6]) % 256); X[7] = (uchar) ((X[7] - K[j][7]) % 256); } for (i = 1; i <= 8; i++) Y[i] = X[i]; } int main(void) { short key[4], S[512], S_inv[512]; uchar X[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8}, Y[9]; uchar i, **K; K = calloc(2 * ROUNDS + 3, sizeof(char *)); for (i = 0; i < 2 * ROUNDS + 3; i++) K[i] = calloc(9, sizeof(char)); key[0] = 256 * 8 + 7; key[1] = 256 * 6 + 5; key[2] = 256 * 4 + 3; key[3] = 256 * 2 + 1; SAFER_K_64_key_schedule(key, S, S_inv, K); SAFER_K_64_encryption(X, Y, S, S_inv, K); printf("encryption results\n"); for (i = 1; i <= 8; i++) printf("%3d ", Y[i]); printf("\n"); SAFER_K_64_decryption(Y, X, S, S_inv, K); printf("decryption results\n"); for (i = 1; i <= 8; i++) printf("%3d ", X[i]); printf("\n"); for (i = 0; i < 2 * ROUNDS + 3; i++) free(K[i]); free(K); return 0; }
the_stack_data/178266604.c
/* Source code to implement a Queue over 2 Stacks contained as components by Akshat Pandey inside the Queue Stack -1 is the Primary Stack that contains the data elements of the Queue Stack -2 is the auxillary Stack used as a buffer (intermediate) storage while performing the dequeue operation on the Queue */ #include<stdio.h> #define MAX 5 // size of arrray ( capacity of Stack) #define TRUE 1 #define FALSE 0 /************ Implementation of Stack over array ******************/ struct Stack { int data[MAX]; // will store the elements of the Stack int top; // store the index of top element ( recent most) }typedef Stack; // Standart interface functions for the Stack ADT int isEmpty(Stack); //return TRUE if Stack is empty int isFull(Stack);// returnn FALSE if Stack is full int push(Stack*, int); // push ( return TRUE on success) an element onto the top of Stack int pop(Stack*); // pop the top element from Stack and return int peek(Stack); // return the top element of Stack without removing it //function definitions int isEmpty(Stack s) { if(s.top == -1) return TRUE; return FALSE; }//end of isEmpty int isFull(Stack s) { if(s.top == MAX-1) return TRUE; return FALSE; }//end of isFull int push(Stack* sp, int element) { if( isFull(*sp)) // if the Stack is Full { printf("\nStack Overflow, can't push %d ", element); return FALSE; // indicates a failure of current call to push } sp->top = sp->top + 1; // increment top to next vacant location sp->data[sp->top] = element; // add the element to new top location return TRUE;// successfully pushed the element }//end of push int pop(Stack *sp) { if( isEmpty(*sp)) // if the Stack is empty { printf("\nStack Underflow"); return -1; // indicates a failure for the current call to Pop } else { int top_element; top_element = sp->data[sp->top]; // hold the top element sp->top = sp->top - 1;//decrement top return top_element; // return the stored top element for this pop } }//end of pop int peek(Stack s) { if( isEmpty(s))// is Stack is empty can't peek return -1; // indicates failure for current call to peek return s.data[s.top]; // return the top element but with no changes in state of Stack } /*************************** Stack Implementation Ends *****************/ /********** Implementation of Queue using 2 Stack components ****************/ struct Queue { Stack s1; // primary stack used for storage Stack s2; // auxillary stack used as buffer while dequeue operation }typedef Queue; enqueue(Queue *q, int element) { if( !isFull(q->s1)) // if the primary stack is NOT full push(&q->s1,element); else printf("\nQueue Overflow .. can't add %d to Queue", element); }//end of enqueue dequeue(Queue *q) { if(isEmpty(q->s1)) { printf("\nUnderflow .."); return -1; // return value for dequque on empty stack } while(!isEmpty(q->s1)) { int x = pop(&q->s1);// pop from stack s1 (primary stack component of queue) push(&q->s2,x); // push to auxillary stack component } // now pop from auxillary stack for returning as a result of dequeue int front_element = pop(&q->s2); // transfer back the remaining contents from auxillary stack to primary stack while( !isEmpty(q->s2)) { int y = pop(&q->s2); // pop from auxillary stack push(&q->s1,y); } return front_element; }//end of dequque //driver code void main() { Queue q; // initialization of the stack components of the queue q.s1.top = -1; q.s2.top = -1; printf("\n Dequeue return value %d ", dequeue(&q));// Underflow ... -1 enqueue(&q, 100); // [ 100 ] enqueue(&q, 200); // [ 100 200] enqueue(&q, 300); // [ 100 200 300] enqueue(&q, 400); // [ 100 200 300 400] printf("\n Dequeue return value %d ", dequeue(&q)); // [ 200 300 400] printf("\n Dequeue return value %d ", dequeue(&q)); // [ 300 400 ] enqueue(&q, 500); // [ 300 400 500] enqueue(&q, 600); // [ 300 400 500 600] enqueue(&q, 700); // [ 300 400 500 600 700] enqueue(&q, 800); // Overflow printf("\n Dequeue return value %d ", dequeue(&q)); // [ 400 500 600 700 ] }//end of main
the_stack_data/86074529.c
#include <stdio.h> #define INFINITY 9999 #define MAX 10 void Dijkstra(int Graph[MAX][MAX], int n, int start){ int cost[MAX][MAX], distance[MAX], pred[MAX]; int visited[MAX], count, mindistance, nextnode, i, j; // Creating cost matrix for (i = 0; i < n; i++){ for (j = 0; j < n; j++){ if (Graph[i][j] == 0){ cost[i][j] = INFINITY; } else{ cost[i][j] = Graph[i][j]; } } } for (i = 0; i < n; i++) { distance[i] = cost[start][i]; pred[i] = start; visited[i] = 0; } distance[start] = 0; visited[start] = 1; count = 1; while (count < n - 1) { mindistance = INFINITY; for (i = 0; i < n; i++){ if (distance[i] < mindistance && !visited[i]) { mindistance = distance[i]; nextnode = i; } } visited[nextnode] = 1; for (i = 0; i < n; i++){ if (!visited[i]){ if (mindistance + cost[nextnode][i] < distance[i]) { distance[i] = mindistance + cost[nextnode][i]; pred[i] = nextnode; } } } count++; } // Printing the distance for (i = 0; i < n; i++) if (i != start) { printf("\nDistance from source to %d: %d", i, distance[i]); } } int main() { int Graph[MAX][MAX], i, j, n, u; printf("\nEnter the number of nodes: "); scanf("%d", &n); // for(i=0; i<n; i++){ // for(j=0; j<n; j++){ // printf("Enter the value of Graph[%d][%d] : ", i, j); // scanf("%d", &Graph[i][j]); // } // } FILE *fp = fopen("matrixdijkstra.txt", "r"); for (i = 0; i < n; i++){ for (j = 0; j < n; j++){ fscanf(fp, "%d", &Graph[i][j]); } } printf("Enter source vertex: "); scanf("%d", &u); Dijkstra(Graph, n, u); return 0; }
the_stack_data/27421.c
#include <stdio.h> /* copy input to output 2nd version */ int main() { int c; while ((c = getchar()) != EOF) putchar(c); return 0; }
the_stack_data/1030876.c
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #define NUM_BITS 12 // WARNING: bit is reversed (ltr) int filterOx (int bins[], int bins_len, int new_bins[], int bit) { int bit_set_times = 0; for (int i = 0; i < bins_len; ++i) { if ((bins[i] >> (NUM_BITS - bit - 1)) & 1) { bit_set_times++; } } int most_common = bit_set_times * 2 >= bins_len; int new_bins_len = 0; for (int i = 0; i < bins_len; ++i) { if (((bins[i] >> (NUM_BITS - bit - 1)) & 1) == (most_common & 1)) { new_bins[new_bins_len++] = bins[i]; } } return new_bins_len; } int filterCO (int bins[], int bins_len, int new_bins[], int bit) { int bit_set_times = 0; for (int i = 0; i < bins_len; ++i) { if ((bins[i] >> (NUM_BITS - bit - 1)) & 1) { bit_set_times++; } } int least_common = bit_set_times * 2 < bins_len; int new_bins_len = 0; for (int i = 0; i < bins_len; ++i) { if (((bins[i] >> (NUM_BITS - bit - 1)) & 1) == (least_common & 1)) { new_bins[new_bins_len++] = bins[i]; } } return new_bins_len; } int main () { FILE *stream = fopen("inputs/input3", "r"); int bins[1000]; int bins_len = 0; char line[NUM_BITS + 1]; while (fscanf(stream, "%s", line) != EOF) { bins[bins_len++] = strtol(line, NULL, 2); } int ox_bins[1000]; int ox_bins_len; for (; ox_bins_len < bins_len; ++ox_bins_len) { ox_bins[ox_bins_len] = bins[ox_bins_len]; } for (int i = 0; ox_bins_len > 1; ++i) { ox_bins_len = filterOx(ox_bins, ox_bins_len, ox_bins, i); } int co_bins[1000]; int co_bins_len; for (; co_bins_len < bins_len; ++co_bins_len) { co_bins[co_bins_len] = bins[co_bins_len]; } for (int i = 0; co_bins_len > 1; ++i) { co_bins_len = filterCO(co_bins, co_bins_len, co_bins, i); } printf("%d\n", co_bins[0] * ox_bins[0]); fclose(stream); return 0; }
the_stack_data/287579.c
#include <stdlib.h> #include <stdio.h> #include <string.h> #define LIN 10 #define COL 5 int main(){ int cont, j , k; char *ptr[LIN]; char *temp; static char foguet[LIN][COL] = { {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,0,0,0}, {0,0,'\x1E',0,0}, {0,'^','\xDB','\x1E',0}, }; static char terra [] = { '\xCD' , '\xCD', '\xCD', '\xCD', '\xCD', '\0'}; for (cont=0; cont<LIN; cont++) *(ptr+cont)=*(foguet+cont); for (cont = 0 ; cont < LIN-1 ; cont++){ for (j = 0 ; j < LIN ; j++){ for (k = 0 ; k < COL ; k++) printf("%c", *(*(ptr+j)+k)); printf("\n"); } printf("%s\n",terra); system("read b"); temp=*ptr; for(j=0;j<LIN-1;j++) *(ptr+j) =*(ptr+j+1); *(ptr+LIN-1)=temp; } }
the_stack_data/116412.c
/* * fgetgrent.c - This file is part of the libc-8086/grp package for ELKS, * Copyright (C) 1995, 1996 Nat Friedman <[email protected]>. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #include <stdio.h> #include <errno.h> #include "grp.h" struct group *tlg_fgetgrent(FILE * file) { if (file == NULL) { errno = EINTR; return NULL; } return __tlg_getgrent(fileno(file)); }
the_stack_data/131354.c
/* * qt-faststart.c, v0.2 * by Mike Melanson ([email protected]) * This file is placed in the public domain. Use the program however you * see fit. * * This utility rearranges a Quicktime file such that the moov atom * is in front of the data, thus facilitating network streaming. * * To compile this program, start from the base directory from which you * are building FFmpeg and type: * make tools/qt-faststart * The qt-faststart program will be built in the tools/ directory. If you * do not build the program in this manner, correct results are not * guaranteed, particularly on 64-bit platforms. * Invoke the program with: * qt-faststart <infile.mov> <outfile.mov> * * Notes: Quicktime files can come in many configurations of top-level * atoms. This utility stipulates that the very last atom in the file needs * to be a moov atom. When given such a file, this utility will rearrange * the top-level atoms by shifting the moov atom from the back of the file * to the front, and patch the chunk offsets along the way. This utility * presently only operates on uncompressed moov atoms. */ #include <stdio.h> #include <stdlib.h> #include <inttypes.h> #include <string.h> #ifdef __MINGW32__ #define fseeko(x, y, z) fseeko64(x, y, z) #define ftello(x) ftello64(x) #elif defined(_WIN32) #define fseeko(x, y, z) _fseeki64(x, y, z) #define ftello(x) _ftelli64(x) #endif #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) #define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) #define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ (((uint8_t*)(x))[1] << 16) | \ (((uint8_t*)(x))[2] << 8) | \ ((uint8_t*)(x))[3]) #define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \ ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \ ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \ ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \ ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \ ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \ ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \ ((uint64_t)( (uint8_t*)(x))[7])) #define BE_FOURCC(ch0, ch1, ch2, ch3) \ ( (uint32_t)(unsigned char)(ch3) | \ ((uint32_t)(unsigned char)(ch2) << 8) | \ ((uint32_t)(unsigned char)(ch1) << 16) | \ ((uint32_t)(unsigned char)(ch0) << 24) ) #define QT_ATOM BE_FOURCC /* top level atoms */ #define FREE_ATOM QT_ATOM('f', 'r', 'e', 'e') #define JUNK_ATOM QT_ATOM('j', 'u', 'n', 'k') #define MDAT_ATOM QT_ATOM('m', 'd', 'a', 't') #define MOOV_ATOM QT_ATOM('m', 'o', 'o', 'v') #define PNOT_ATOM QT_ATOM('p', 'n', 'o', 't') #define SKIP_ATOM QT_ATOM('s', 'k', 'i', 'p') #define WIDE_ATOM QT_ATOM('w', 'i', 'd', 'e') #define PICT_ATOM QT_ATOM('P', 'I', 'C', 'T') #define FTYP_ATOM QT_ATOM('f', 't', 'y', 'p') #define UUID_ATOM QT_ATOM('u', 'u', 'i', 'd') #define CMOV_ATOM QT_ATOM('c', 'm', 'o', 'v') #define STCO_ATOM QT_ATOM('s', 't', 'c', 'o') #define CO64_ATOM QT_ATOM('c', 'o', '6', '4') #define ATOM_PREAMBLE_SIZE 8 #define COPY_BUFFER_SIZE 33554432 int main(int argc, char *argv[]) { FILE *infile = NULL; FILE *outfile = NULL; unsigned char atom_bytes[ATOM_PREAMBLE_SIZE]; uint32_t atom_type = 0; uint64_t atom_size = 0; uint64_t atom_offset = 0; uint64_t last_offset; unsigned char *moov_atom = NULL; unsigned char *ftyp_atom = NULL; uint64_t moov_atom_size; uint64_t ftyp_atom_size = 0; uint64_t i, j; uint32_t offset_count; uint64_t current_offset; int64_t start_offset = 0; unsigned char *copy_buffer = NULL; int bytes_to_copy; if (argc != 3) { printf("Usage: qt-faststart <infile.mov> <outfile.mov>\n"); return 0; } if (!strcmp(argv[1], argv[2])) { fprintf(stderr, "input and output files need to be different\n"); return 1; } infile = fopen(argv[1], "rb"); if (!infile) { perror(argv[1]); goto error_out; } /* traverse through the atoms in the file to make sure that 'moov' is * at the end */ while (!feof(infile)) { if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { break; } atom_size = (uint32_t) BE_32(&atom_bytes[0]); atom_type = BE_32(&atom_bytes[4]); /* keep ftyp atom */ if (atom_type == FTYP_ATOM) { ftyp_atom_size = atom_size; free(ftyp_atom); ftyp_atom = malloc(ftyp_atom_size); if (!ftyp_atom) { printf("could not allocate %"PRIu64" bytes for ftyp atom\n", atom_size); goto error_out; } if ( fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR) || fread(ftyp_atom, atom_size, 1, infile) != 1 || (start_offset = ftello(infile))<0) { perror(argv[1]); goto error_out; } } else { int ret; /* 64-bit special case */ if (atom_size == 1) { if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { break; } atom_size = BE_64(&atom_bytes[0]); ret = fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR); } else { ret = fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR); } if(ret) { perror(argv[1]); goto error_out; } } printf("%c%c%c%c %10"PRIu64" %"PRIu64"\n", (atom_type >> 24) & 255, (atom_type >> 16) & 255, (atom_type >> 8) & 255, (atom_type >> 0) & 255, atom_offset, atom_size); if ((atom_type != FREE_ATOM) && (atom_type != JUNK_ATOM) && (atom_type != MDAT_ATOM) && (atom_type != MOOV_ATOM) && (atom_type != PNOT_ATOM) && (atom_type != SKIP_ATOM) && (atom_type != WIDE_ATOM) && (atom_type != PICT_ATOM) && (atom_type != UUID_ATOM) && (atom_type != FTYP_ATOM)) { printf("encountered non-QT top-level atom (is this a QuickTime file?)\n"); break; } atom_offset += atom_size; /* The atom header is 8 (or 16 bytes), if the atom size (which * includes these 8 or 16 bytes) is less than that, we won't be * able to continue scanning sensibly after this atom, so break. */ if (atom_size < 8) break; } if (atom_type != MOOV_ATOM) { printf("last atom in file was not a moov atom\n"); free(ftyp_atom); fclose(infile); return 0; } /* moov atom was, in fact, the last atom in the chunk; load the whole * moov atom */ if (fseeko(infile, -atom_size, SEEK_END)) { perror(argv[1]); goto error_out; } last_offset = ftello(infile); moov_atom_size = atom_size; moov_atom = malloc(moov_atom_size); if (!moov_atom) { printf("could not allocate %"PRIu64" bytes for moov atom\n", atom_size); goto error_out; } if (fread(moov_atom, atom_size, 1, infile) != 1) { perror(argv[1]); goto error_out; } /* this utility does not support compressed atoms yet, so disqualify * files with compressed QT atoms */ if (BE_32(&moov_atom[12]) == CMOV_ATOM) { printf("this utility does not support compressed moov atoms yet\n"); goto error_out; } /* close; will be re-opened later */ fclose(infile); infile = NULL; /* crawl through the moov chunk in search of stco or co64 atoms */ for (i = 4; i < moov_atom_size - 4; i++) { atom_type = BE_32(&moov_atom[i]); if (atom_type == STCO_ATOM) { printf(" patching stco atom...\n"); atom_size = (uint32_t)BE_32(&moov_atom[i - 4]); if (i + atom_size - 4 > moov_atom_size) { printf(" bad atom size\n"); goto error_out; } offset_count = BE_32(&moov_atom[i + 8]); if (i + 12LL + offset_count * 4LL > moov_atom_size) { printf(" bad atom size\n"); goto error_out; } for (j = 0; j < offset_count; j++) { current_offset = (uint32_t)BE_32(&moov_atom[i + 12 + j * 4]); current_offset += moov_atom_size; moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF; moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF; moov_atom[i + 12 + j * 4 + 2] = (current_offset >> 8) & 0xFF; moov_atom[i + 12 + j * 4 + 3] = (current_offset >> 0) & 0xFF; } i += atom_size - 4; } else if (atom_type == CO64_ATOM) { printf(" patching co64 atom...\n"); atom_size = (uint32_t)BE_32(&moov_atom[i - 4]); if (i + atom_size - 4 > moov_atom_size) { printf(" bad atom size\n"); goto error_out; } offset_count = BE_32(&moov_atom[i + 8]); if (i + 12LL + offset_count * 8LL > moov_atom_size) { printf(" bad atom size\n"); goto error_out; } for (j = 0; j < offset_count; j++) { current_offset = BE_64(&moov_atom[i + 12 + j * 8]); current_offset += moov_atom_size; moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF; moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF; moov_atom[i + 12 + j * 8 + 2] = (current_offset >> 40) & 0xFF; moov_atom[i + 12 + j * 8 + 3] = (current_offset >> 32) & 0xFF; moov_atom[i + 12 + j * 8 + 4] = (current_offset >> 24) & 0xFF; moov_atom[i + 12 + j * 8 + 5] = (current_offset >> 16) & 0xFF; moov_atom[i + 12 + j * 8 + 6] = (current_offset >> 8) & 0xFF; moov_atom[i + 12 + j * 8 + 7] = (current_offset >> 0) & 0xFF; } i += atom_size - 4; } } /* re-open the input file and open the output file */ infile = fopen(argv[1], "rb"); if (!infile) { perror(argv[1]); goto error_out; } if (start_offset > 0) { /* seek after ftyp atom */ if (fseeko(infile, start_offset, SEEK_SET)) { perror(argv[1]); goto error_out; } last_offset -= start_offset; } outfile = fopen(argv[2], "wb"); if (!outfile) { perror(argv[2]); goto error_out; } /* dump the same ftyp atom */ if (ftyp_atom_size > 0) { printf(" writing ftyp atom...\n"); if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) { perror(argv[2]); goto error_out; } } /* dump the new moov atom */ printf(" writing moov atom...\n"); if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) { perror(argv[2]); goto error_out; } /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */ bytes_to_copy = FFMIN(COPY_BUFFER_SIZE, last_offset); copy_buffer = malloc(bytes_to_copy); if (!copy_buffer) { printf("could not allocate %d bytes for copy_buffer\n", bytes_to_copy); goto error_out; } printf(" copying rest of file...\n"); while (last_offset) { bytes_to_copy = FFMIN(bytes_to_copy, last_offset); if (fread(copy_buffer, bytes_to_copy, 1, infile) != 1) { perror(argv[1]); goto error_out; } if (fwrite(copy_buffer, bytes_to_copy, 1, outfile) != 1) { perror(argv[2]); goto error_out; } last_offset -= bytes_to_copy; } fclose(infile); fclose(outfile); free(moov_atom); free(ftyp_atom); free(copy_buffer); return 0; error_out: if (infile) fclose(infile); if (outfile) fclose(outfile); free(moov_atom); free(ftyp_atom); free(copy_buffer); return 1; }
the_stack_data/220456886.c
#include <stdio.h> #include <stdlib.h> #include <time.h> struct nodo { int dados; struct nodo *prox; }; int insereUltimo(struct nodo **p, int v) { struct nodo *novo = (struct nodo *)malloc(sizeof(struct nodo)); if (novo != NULL) { novo->dados = v; if (*p == NULL) { novo->prox = novo; } else { novo->prox = (*p)->prox; (*p)->prox = novo; } *p = novo; return 1; } return 0; } int inserePrimeiro(struct nodo **p, int v) { struct nodo *novo = (struct nodo *)malloc(sizeof(struct nodo)); if (novo != NULL) { novo->dados = v; if (*p == NULL) { novo->prox = novo; *p = novo; } else { novo->prox = (*p)->prox; (*p)->prox = novo; } return 1; } return 0; } int insereAntesValor(struct nodo **p, int psq, int val) { struct nodo *aux = NULL; struct nodo *ant = NULL; struct nodo *novo = NULL; if (*p != NULL) { ant = *p; aux = (*p)->prox; do { if (aux->dados == psq) { novo = (struct nodo *)malloc(sizeof(struct nodo)); if (novo != NULL) { novo->dados = val; ant->prox = novo; novo->prox = aux; return 1; } else { return -1; } } ant = aux; aux = aux->prox; } while (aux != (*p)->prox); } return 0; } int excluiNodo(struct nodo **p, int psq) { struct nodo *aux = NULL; struct nodo *ant = NULL; if (*p != NULL) { ant = *p; aux = (*p)->prox; do { if (aux->dados == psq) { if (aux == ant) { *p = NULL; free(aux); } else { ant->prox = aux->prox; free(aux); } return 1; } ant = aux; aux = aux->prox; } while (aux != (*p)->prox); } return 0; } int imprime(struct nodo **p) { struct nodo *aux = NULL; if (*p != NULL) { aux = (*p)->prox; do { printf("%i ", aux->dados); aux = aux->prox; } while (aux != (*p)->prox); printf("\n"); } return 0; } int count(struct nodo **p) { int i = 0; struct nodo *aux = *p; if (*p != NULL) { aux = (*p)->prox; for (i = 1; aux != (*p); i++) aux = aux->prox; } return i; } int main() { int i = 0; struct nodo *p = NULL; srand(time(NULL)); for (i = 0; i < 25; i++) { int rnd = rand() % 100; insereUltimo(&p, i); } imprime(&p); int valPsq; printf("Digite um valor a ser pesquisado na LSE circular: "); scanf("%i", &valPsq); int valIns; printf("Digite o valor a ser inserido antes do valor anterior, se encontrado: "); scanf("%i", &valIns); int statusInsereAntesValor = insereAntesValor(&p, valPsq, valIns); if (statusInsereAntesValor == 0) { printf("Valor de pesquisa não encontrado.\n"); } else if (statusInsereAntesValor == -1) { printf("Não foi possível alocar a estrutura.\n"); } imprime(&p); int valDel; printf("Digite um valor a ser deletado da LSE circular: "); scanf("%i", &valDel); int statusExcluiNodo = excluiNodo(&p, valDel); if (statusExcluiNodo == 0) { printf("O valor selecionado não foi encontrado.\n"); } imprime(&p); printf("A LSE circular possui %i nodos.\n", count(&p)); return 0; }
the_stack_data/77869.c
#include<stdio.h> long long jie(int n) { long long mul=1,i; for(i=n;i>0;i--) { mul*=i; } return mul; } int main() { int m,n; long long num; scanf("%d%d",&m,&n); num=(jie(m))/(jie(n)*jie(m-n)); printf("%lld",num); return 0; }
the_stack_data/62637854.c
#include<stdio.h> int max(int x,int y,int z); float sum(float x, float y); int main() { int a, b, c; float d, e; printf("Enter three integers:"); scanf("%d,%d,%d",&a,&b,&c); printf("\nthe maximum of them is %d\n",max(a,b,c)); printf("Enter two floating point numbers:"); scanf("%f,%f",&d,&e); printf("\nthe sum of them is %f\n",sum(d,e)); } int max(int x, int y, int z) { int t; if (x>y) t=x; else t=y; if (t<z) t=z; return t; } float sum(float x, float y) { return x+y; }
the_stack_data/278173.c
/* { dg-do compile } */ /* { dg-options "-O -std=c89 -g -dA" } */ /* DW_LANG_C89 = 0x0001 */ /* { dg-final { scan-assembler "0x1.*DW_AT_language" { xfail { powerpc-ibm-aix* } } } } */ int version;
the_stack_data/212643040.c
#include <stdio.h> int main() { int A,B; scanf("%d %d", &A,&B); printf("PROD = %d\n",A*B); return 0; }
the_stack_data/824388.c
void upper2(char *str){ while (*str != '\0'){ if (*str >= 97 && *str <= 122){ *str -= 32; } str++; } }
the_stack_data/59511484.c
/* ** 2013-06-10 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: ** ** May you do good and not evil. ** May you find forgiveness for yourself and forgive others. ** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains a simple command-line utility for converting from ** integers and LogEst values and back again and for doing simple ** arithmetic operations (multiple and add) on LogEst values. ** ** Usage: ** ** ./LogEst ARGS ** ** See the showHelp() routine for a description of valid arguments. ** Examples: ** ** To convert 123 from LogEst to integer: ** ** ./LogEst ^123 ** ** To convert 123456 from integer to LogEst: ** ** ./LogEst 123456 ** */ #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <assert.h> #include <string.h> #include "sqlite3.h" typedef short int LogEst; /* 10 times log2() */ LogEst logEstMultiply(LogEst a, LogEst b){ return a+b; } LogEst logEstAdd(LogEst a, LogEst b){ static const unsigned char x[] = { 10, 10, /* 0,1 */ 9, 9, /* 2,3 */ 8, 8, /* 4,5 */ 7, 7, 7, /* 6,7,8 */ 6, 6, 6, /* 9,10,11 */ 5, 5, 5, /* 12-14 */ 4, 4, 4, 4, /* 15-18 */ 3, 3, 3, 3, 3, 3, /* 19-24 */ 2, 2, 2, 2, 2, 2, 2, /* 25-31 */ }; if( a<b ){ LogEst t = a; a = b; b = t; } if( a>b+49 ) return a; if( a>b+31 ) return a+1; return a+x[a-b]; } LogEst logEstFromInteger(sqlite3_uint64 x){ static LogEst a[] = { 0, 2, 3, 5, 6, 7, 8, 9 }; LogEst y = 40; if( x<8 ){ if( x<2 ) return 0; while( x<8 ){ y -= 10; x <<= 1; } }else{ while( x>255 ){ y += 40; x >>= 4; } while( x>15 ){ y += 10; x >>= 1; } } return a[x&7] + y - 10; } static sqlite3_uint64 logEstToInt(LogEst x){ sqlite3_uint64 n; if( x<10 ) return 1; n = x%10; x /= 10; if( n>=5 ) n -= 2; else if( n>=1 ) n -= 1; if( x>=3 ) return (n+8)<<(x-3); return (n+8)>>(3-x); } static LogEst logEstFromDouble(double x){ sqlite3_uint64 a; LogEst e; assert( sizeof(x)==8 && sizeof(a)==8 ); if( x<=0.0 ) return -32768; if( x<0.01 ) return -logEstFromDouble(1.0/x); if( x<1.0 ) return logEstFromDouble(100.0*x) - 66; if( x<1024.0 ) return logEstFromInteger((sqlite3_uint64)(1024.0*x)) - 100; if( x<=2000000000.0 ) return logEstFromInteger((sqlite3_uint64)x); memcpy(&a, &x, 8); e = (a>>52) - 1022; return e*10; } int isInteger(const char *z){ while( z[0]>='0' && z[0]<='9' ) z++; return z[0]==0; } int isFloat(const char *z){ char c; while( ((c=z[0])>='0' && c<='9') || c=='.' || c=='E' || c=='e' || c=='+' || c=='-' ) z++; return z[0]==0; } static void showHelp(const char *zArgv0){ printf("Usage: %s ARGS...\n", zArgv0); printf("Arguments:\n" " NUM Convert NUM from integer to LogEst and push onto the stack\n" " ^NUM Interpret NUM as a LogEst and push onto stack\n" " x Multiple the top two elements of the stack\n" " + Add the top two elements of the stack\n" " dup Dupliate the top element on the stack\n" " inv Take the reciprocal of the top of stack. N = 1/N.\n" " log Find the LogEst of the number on top of stack\n" " nlogn Compute NlogN where N is the top of stack\n" ); exit(1); } int main(int argc, char **argv){ int i; int n = 0; LogEst a[100]; for(i=1; i<argc; i++){ const char *z = argv[i]; if( strcmp(z,"+")==0 ){ if( n>=2 ){ a[n-2] = logEstAdd(a[n-2],a[n-1]); n--; } }else if( strcmp(z,"x")==0 ){ if( n>=2 ){ a[n-2] = logEstMultiply(a[n-2],a[n-1]); n--; } }else if( strcmp(z,"dup")==0 ){ if( n>0 ){ a[n] = a[n-1]; n++; } }else if( strcmp(z,"log")==0 ){ if( n>0 ) a[n-1] = logEstFromInteger(a[n-1]) - 33; }else if( strcmp(z,"nlogn")==0 ){ if( n>0 ) a[n-1] += logEstFromInteger(a[n-1]) - 33; }else if( strcmp(z,"inv")==0 ){ if( n>0 ) a[n-1] = -a[n-1]; }else if( z[0]=='^' ){ a[n++] = (LogEst)atoi(z+1); }else if( isInteger(z) ){ a[n++] = logEstFromInteger(atoi(z)); }else if( isFloat(z) && z[0]!='-' ){ a[n++] = logEstFromDouble(atof(z)); }else{ showHelp(argv[0]); } } for(i=n-1; i>=0; i--){ if( a[i]<-40 ){ printf("%5d (%f)\n", a[i], 1.0/(double)logEstToInt(-a[i])); }else if( a[i]<10 ){ printf("%5d (%f)\n", a[i], logEstToInt(a[i]+100)/1024.0); }else{ sqlite3_uint64 x = logEstToInt(a[i]+100)*100/1024; printf("%5d (%lld.%02lld)\n", a[i], x/100, x%100); } } return 0; }
the_stack_data/150143047.c
/* 1) Ler a altura de 5 pessoas, armazenar em um vetor. Validar para que seja informado um valor positivo para a altura. Identificar e mostrar a maior altura e o índice do vetor que essa altura corresponde. Calcular a média das alturas acima de 1,50 e mostrar essa média. Validar para que não seja realizada uma divisão por zero no cálculo da média. */ #include <stdio.h> int main(void) { int i; int aux; float vetoraltura[5]; float media; int qtde = 0; float maior; float soma = 0; for (i = 0; i < 5; i++) { do { printf("Informe a altura da pessoa %d (em cm): ", i + 1); scanf("%f", &vetoraltura[i]); } while (vetoraltura[i] <= 0); } maior = vetoraltura[0]; for (i = 0; i < 5; i++) { if (vetoraltura[i] > maior) { maior = vetoraltura[i]; aux = i; } if (vetoraltura[i] > 1.50) { soma = soma + vetoraltura[i]; qtde++; } } printf("A maior altura foi de %.2f e pertence ao INDICE %d do vetor.\n", maior, aux); if (qtde == 0) { printf("Impossivel fazer a media !!!\n"); } else { media = soma / qtde; printf("A media foi de %.2f.\n", media); } return 0; }
the_stack_data/7949190.c
#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> #include <pthread.h> int semid,a=0; int add_num=1; union semun { int val; // value for SETVAL struct semid_ds *buf; // buffer for IPC_STAT, IPC_SET unsigned short *array; // array for GETALL, SETALL struct seminfo *__buf; // buffer for IPC_INFO (Linux-specific) }; void P(int semid, int index) { struct sembuf sem; sem.sem_num = index;/*要操作的信号灯的编号*/ sem.sem_op = -1; /*要执行的操作*/ sem.sem_flg = 0; /*操作标志,一般设置为0*/ semop(semid,&sem,1); return; } void V(int semid,int index) { struct sembuf sem; sem.sem_num = index; sem.sem_op = 1; sem.sem_flg = 0; semop(semid,&sem,1); return; } void *thread1(void *arg) { for(int i=0;i<100;i++) { P(semid,0); a+=add_num; add_num++; V(semid,1); } } void *thread2(void *arg) { for(int i=0;i<100;i++) { P(semid,1); printf("a=%d\n",a); V(semid,0); } } int main() { pthread_t pid1,pid2; int ret; union semun arg1; union semun arg2; //创建信号灯 semid=semget(IPC_PRIVATE,2,IPC_CREAT|0666); arg1.val=1; arg2.val=0; //信号灯赋值 semctl(semid,0,SETVAL,arg1);//empty buffer semctl(semid,1,SETVAL,arg2);//full buffer //创建两个线程 while((ret=pthread_create(&pid1,NULL,thread1,NULL))!=0); while((ret=pthread_create(&pid2,NULL,thread2,NULL))!=0); //等待线程结束 pthread_join(pid1,NULL); pthread_join(pid2,NULL); //删除信号灯集 semctl(semid, 0, IPC_RMID); }
the_stack_data/618091.c
// RUN: %clang_cc1 -verify -fopenmp -ferror-limit 100 %s // RUN: %clang_cc1 -verify -fopenmp-simd -ferror-limit 100 %s int temp; // expected-note {{'temp' declared here}} struct vec { // expected-note {{definition of 'struct vec' is not complete until the closing '}'}} int len; #pragma omp declare mapper(id: struct vec v) map(v.len) // expected-error {{incomplete definition of type 'struct vec'}} double *data; }; #pragma omp declare mapper // expected-error {{expected '(' after 'declare mapper'}} #pragma omp declare mapper { // expected-error {{expected '(' after 'declare mapper'}} #pragma omp declare mapper( // expected-error {{expected a type}} expected-error {{expected declarator on 'omp declare mapper' directive}} #pragma omp declare mapper(# // expected-error {{expected a type}} expected-error {{expected declarator on 'omp declare mapper' directive}} #pragma omp declare mapper(struct v // expected-error {{expected declarator on 'omp declare mapper' directive}} #pragma omp declare mapper(struct vec // expected-error {{expected declarator on 'omp declare mapper' directive}} #pragma omp declare mapper(S v // expected-error {{unknown type name 'S'}} #pragma omp declare mapper(struct vec v // expected-error {{expected ')'}} expected-note {{to match this '('}} #pragma omp declare mapper(aa:struct vec v) // expected-error {{expected at least one clause on '#pragma omp declare mapper' directive}} #pragma omp declare mapper(bb:struct vec v) private(v) // expected-error {{expected at least one clause on '#pragma omp declare mapper' directive}} // expected-error {{unexpected OpenMP clause 'private' in directive '#pragma omp declare mapper'}} #pragma omp declare mapper(cc:struct vec v) map(v) ( // expected-warning {{extra tokens at the end of '#pragma omp declare mapper' are ignored}} #pragma omp declare mapper(++: struct vec v) map(v.len) // expected-error {{illegal OpenMP user-defined mapper identifier}} #pragma omp declare mapper(id1: struct vec v) map(v.len, temp) // expected-error {{only variable v is allowed in map clauses of this 'omp declare mapper' directive}} #pragma omp declare mapper(default : struct vec kk) map(kk.data[0:2]) // expected-note {{previous definition is here}} #pragma omp declare mapper(struct vec v) map(v.len) // expected-error {{redefinition of user-defined mapper for type 'struct vec' with name 'default'}} #pragma omp declare mapper(int v) map(v) // expected-error {{mapper type must be of struct, union or class type}} int fun(int arg) { #pragma omp declare mapper(id: struct vec v) map(v.len) { #pragma omp declare mapper(id: struct vec v) map(v.len) // expected-note {{previous definition is here}} #pragma omp declare mapper(id: struct vec v) map(v.len) // expected-error {{redefinition of user-defined mapper for type 'struct vec' with name 'id'}} { #pragma omp declare mapper(id: struct vec v) map(v.len) struct vec vv, v1; #pragma omp target map(mapper) // expected-error {{use of undeclared identifier 'mapper'}} {} #pragma omp target map(mapper:vv) // expected-error {{expected '(' after 'mapper'}} {} #pragma omp target map(mapper( :vv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-warning {{implicit declaration of function 'mapper' is invalid in C99}} expected-note {{to match this '('}} {} #pragma omp target map(mapper(aa :vv) // expected-error {{use of undeclared identifier 'aa'}} expected-error {{expected ')'}} expected-warning {{implicit declaration of function 'mapper' is invalid in C99}} expected-note {{to match this '('}} {} #pragma omp target map(mapper(ab) :vv) // expected-error {{missing map type}} expected-error {{cannot find a valid user-defined mapper for type 'struct vec' with name 'ab'}} {} #pragma omp target map(mapper(aa) :vv) // expected-error {{missing map type}} {} #pragma omp target map(mapper(aa) to:vv) map(close mapper(aa) from:v1) {} #pragma omp target update to(mapper) // expected-error {{expected '(' after 'mapper'}} expected-error {{expected expression}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} #pragma omp target update to(mapper() // expected-error {{illegal OpenMP user-defined mapper identifier}} expected-error {{expected expression}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} #pragma omp target update to(mapper:vv) // expected-error {{expected '(' after 'mapper'}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} #pragma omp target update to(mapper(:vv) // expected-error {{illegal OpenMP user-defined mapper identifier}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} #pragma omp target update to(mapper(aa :vv) // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} #pragma omp target update to(mapper(ab):vv) // expected-error {{cannot find a valid user-defined mapper for type 'struct vec' with name 'ab'}} expected-error {{expected at least one 'to' clause or 'from' clause specified to '#pragma omp target update'}} #pragma omp target update to(mapper(aa):vv) } } return arg; }
the_stack_data/23574167.c
#include <stdio.h> #include <math.h> int check_racine(int a,int b,int c,int *nb_racine,float *x1,float*x2) { int det; if(a==0) {nb_racine=0;return 0;} else {det=b*b-4*a*c; if (det<0) {*nb_racine=0;return 0;} else if (det==0) {*nb_racine=1,*x1=-b/(2*a); return 1;} else{*nb_racine=2; *x1=(-b+sqrt(det))/(2*a); *x2=(-b-sqrt(det))/(2*a); return 1;} } } int main(int argc, char const *argv[]) { int a,b,c,nb_racine; float x1,x2; printf("ax^2 + bx + c\n"); printf("a?");scanf("%d",&a); printf("b?");scanf("%d",&b); printf("c?");scanf("%d",&c); check_racine(a,b,c,&nb_racine,&x1,&x2); if(nb_racine>1) printf("deux racine x1=%.2f,x=%.2f\n",x1,x2 ); else if (nb_racine) printf("une seule racine x=%.2f",x1); else printf("pas de racine :(\n"); }
the_stack_data/97012636.c
#include<stdio.h> void circ(int x,float *area,float *circum); int main(){ int a; float area,circum; printf("Enter radius:\n"); scanf("%d",&a); circ(a,&area,&circum); printf("area=%.3f circum=%.3f",area,circum); return 0; } void circ(int x,float *area,float *circum){ *area=3.14*x*x; *circum=2*3.14*x; }
the_stack_data/777938.c
#include <stdio.h> int print_hash_value = 1; static void platform_main_begin(void) { } static unsigned crc32_tab[256]; static unsigned crc32_context = 0xFFFFFFFFUL; static void crc32_gentab (void) { unsigned crc; unsigned poly = 0xEDB88320UL; int i, j; for (i = 0; i < 256; i++) { crc = i; for (j = 8; j > 0; j--) { if (crc & 1) { crc = (crc >> 1) ^ poly; } else { crc >>= 1; } } crc32_tab[i] = crc; } } static void crc32_byte (unsigned char b) { crc32_context = ((crc32_context >> 8) & 0x00FFFFFF) ^ crc32_tab[(crc32_context ^ b) & 0xFF]; } extern int strcmp ( char *, char *); static void crc32_8bytes (unsigned val) { crc32_byte ((val>>0) & 0xff); crc32_byte ((val>>8) & 0xff); crc32_byte ((val>>16) & 0xff); crc32_byte ((val>>24) & 0xff); } static void transparent_crc (unsigned val, char* vname, int flag) { crc32_8bytes(val); if (flag) { printf("...checksum after hashing %s : %X\n", vname, crc32_context ^ 0xFFFFFFFFU); } } static void platform_main_end (int x, int flag) { if (!flag) printf ("checksum = %x\n", x); } static long __undefined; void csmith_compute_hash(void); void step_hash(int stmt_id); static unsigned short g_2 = 0x48BBL; static signed char func_1(void); static signed char func_1(void) { step_hash(1); return g_2; } void csmith_compute_hash(void) { transparent_crc(g_2, "g_2", print_hash_value); } void step_hash(int stmt_id) { int i = 0; csmith_compute_hash(); printf("before stmt(%d): checksum = %X\n", stmt_id, crc32_context ^ 0xFFFFFFFFUL); crc32_context = 0xFFFFFFFFUL; for (i = 0; i < 256; i++) { crc32_tab[i] = 0; } crc32_gentab(); } int main (void) { int print_hash_value = 0; platform_main_begin(); crc32_gentab(); func_1(); csmith_compute_hash(); platform_main_end(crc32_context ^ 0xFFFFFFFFUL, print_hash_value); return 0; }
the_stack_data/243892985.c
/* * Copyright 2014, NICTA * * This software may be distributed and modified according to the terms of * the BSD 2-Clause license. Note that NO WARRANTY is provided. * See "LICENSE_BSD2.txt" for details. * * @TAG(NICTA_BSD) */ typedef int foo; foo f(foo x) { return x + 1; }
the_stack_data/140764779.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_swap_item.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: akharrou <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/21 13:25:28 by akharrou #+# #+# */ /* Updated: 2019/02/25 11:21:45 by akharrou ### ########.fr */ /* */ /* ************************************************************************** */ void ft_swap_item(void **a, void **b) { void *tmp; tmp = *a; *a = *b; *b = tmp; }
the_stack_data/62638842.c
#include <unistd.h> #include <stdarg.h> int execl(const char *path, const char *argv0, ...) { int argc; va_list ap; va_start(ap, argv0); for (argc=1; va_arg(ap, const char *); argc++); va_end(ap); { int i; char *argv[argc+1]; va_start(ap, argv0); argv[0] = (char *)argv0; for (i=1; i<argc; i++) argv[i] = va_arg(ap, char *); argv[i] = NULL; return execv(path, argv); } }
the_stack_data/119404.c
/* C Library for Skeleton 2-1/2D Electromagnetic OpenMP PIC Code field */ /* diagnostics */ /* Wrappers for calling the Fortran routines from a C main program */ #include <complex.h> void mpotp2_(float complex *q, float complex *pot, float complex *ffc, float *we, int *nx, int *ny, int *nxvh, int *nyv, int *nxhd, int *nyhd); void mdivf2_(float complex *f, float complex *df, int *nx, int *ny, int *nxvh, int *nyv); void mgradf2_(float complex *df, float complex *f, int *nx, int *ny, int *nxvh, int *nyv); void mcurlf2_(float complex *f, float complex *g, int *nx, int *ny, int *nxvh, int *nyv); void mavpot23_(float complex *bxy, float complex *axy, int *nx, int *ny, int *nxvh, int *nyv); void mavrpot23_(float complex *axy, float complex *bxy, float complex *ffc, float *ci, int *nx, int *ny, int *nxvh, int *nyv, int *nxhd, int *nyhd); void msmooth2_(float complex *q, float complex *qs, float complex *ffc, int *nx, int *ny, int *nxvh, int *nyv, int *nxhd, int *nyhd); void msmooth23_(float complex *cu, float complex *cus, float complex *ffc, int *nx, int *ny, int *nxvh, int *nyv, int *nxhd, int *nyhd); void rdmodes2_(float complex *pot, float complex *pott, int *nx, int *ny, int *modesx, int *modesy, int *nxvh, int *nyv, int *modesxd, int *modesyd); void wrmodes2_(float complex *pot, float complex *pott, int *nx, int *ny, int *modesx, int *modesy, int *nxvh, int *nyv, int *modesxd, int *modesyd); void rdvmodes2_(float complex *vpot, float complex *vpott, int *nx, int *ny, int *modesx, int *modesy, int *ndim, int *nxvh, int *nyv, int *modesxd, int *modesyd); void wrvmodes2_(float complex *vpot, float complex *vpott, int *nx, int *ny, int *modesx, int *modesy, int *ndim, int *nxvh, int *nyv, int *modesxd, int *modesyd); /* Interfaces to C */ /*--------------------------------------------------------------------*/ void cmpotp2(float complex q[], float complex pot[], float complex ffc[], float *we, int nx, int ny, int nxvh, int nyv, int nxhd, int nyhd) { mpotp2_(q,pot,ffc,we,&nx,&ny,&nxvh,&nyv,&nxhd,&nyhd); return; } /*--------------------------------------------------------------------*/ void cmdivf2(float complex f[], float complex df[], int nx, int ny, int nxvh, int nyv) { mdivf2_(f,df,&nx,&ny,&nxvh,&nyv); return; } /*--------------------------------------------------------------------*/ void cmgradf2(float complex df[], float complex f[], int nx, int ny, int nxvh, int nyv) { mgradf2_(df,f,&nx,&ny,&nxvh,&nyv); return; } /*--------------------------------------------------------------------*/ void cmcurlf2(float complex f[], float complex g[], int nx, int ny, int nxvh, int nyv) { mcurlf2_(f,g,&nx,&ny,&nxvh,&nyv); return; } /*--------------------------------------------------------------------*/ void cmavpot23(float complex bxy[], float complex axy[], int nx, int ny, int nxvh, int nyv) { mavpot23_(bxy,axy,&nx,&ny,&nxvh,&nyv); return; } /*--------------------------------------------------------------------*/ void cmavrpot23(float complex axy[], float complex bxy[], float complex ffc[], float ci, int nx, int ny, int nxvh, int nyv, int nxhd, int nyhd) { mavrpot23_(axy,bxy,ffc,&ci,&nx,&ny,&nxvh,&nyv,&nxhd,&nyhd); return; } /*--------------------------------------------------------------------*/ void cmsmooth2(float complex q[], float complex qs[], float complex ffc[], int nx, int ny, int nxvh, int nyv, int nxhd, int nyhd) { msmooth2_(q,qs,ffc,&nx,&ny,&nxvh,&nyv,&nxhd,&nyhd); return; } /*--------------------------------------------------------------------*/ void cmsmooth23(float complex cu[], float complex cus[], float complex ffc[], int nx, int ny, int nxvh, int nyv, int nxhd, int nyhd) { msmooth23_(cu,cus,ffc,&nx,&ny,&nxvh,&nyv,&nxhd,&nyhd); return; } /*--------------------------------------------------------------------*/ void crdmodes2(float complex pot[], float complex pott[], int nx, int ny, int modesx, int modesy, int nxvh, int nyv, int modesxd, int modesyd) { rdmodes2_(pot,pott,&nx,&ny,&modesx,&modesy,&nxvh,&nyv,&modesxd, &modesyd); return; } /*--------------------------------------------------------------------*/ void cwrmodes2(float complex pot[], float complex pott[], int nx, int ny, int modesx, int modesy, int nxvh, int nyv, int modesxd, int modesyd) { wrmodes2_(pot,pott,&nx,&ny,&modesx,&modesy,&nxvh,&nyv,&modesxd, &modesyd); return; } /*--------------------------------------------------------------------*/ void crdvmodes2(float complex vpot[], float complex vpott[], int nx, int ny, int modesx, int modesy, int ndim, int nxvh, int nyv, int modesxd, int modesyd) { rdvmodes2_(vpot,vpott,&nx,&ny,&modesx,&modesy,&ndim,&nxvh,&nyv, &modesxd,&modesyd); return; } /*--------------------------------------------------------------------*/ void cwrvmodes2(float complex vpot[], float complex vpott[], int nx, int ny, int modesx, int modesy, int ndim, int nxvh, int nyv, int modesxd, int modesyd) { wrvmodes2_(vpot,vpott,&nx,&ny,&modesx,&modesy,&ndim,&nxvh,&nyv, &modesxd,&modesyd); return; }
the_stack_data/277165.c
#include<stdio.h> #include<malloc.h> #include<string.h> #include<stdbool.h> #define MAX_LENGTH 20050 typedef struct NUM { bool is_minus; char *num; } Bignumber; void add(Bignumber n1, Bignumber n2, Bignumber nr); void subtract(Bignumber n1, Bignumber n2, Bignumber nr); bool front_is_bigger(char *c1, char *c2){ int result1 = strlen(c1); int result2 = strlen(c2); if(result1 == result2){ c1 += result1 - 1; c2 += result1 - 1; while(*c1 == *c2 && result2 > 0){ result2--; c1--; c2--; } return *c1 > *c2; } else { return result1 > result2; } return false; } int add_two_char(char a, char b){ return (int)(a + b - 96); } void add(Bignumber n1, Bignumber n2, Bignumber nr){ if(n1.is_minus == n2.is_minus){ if(n2.num != nr.num) memset(nr.num, 0, MAX_LENGTH * sizeof(char)); int prev = 0; char *c1 = n1.num, *c2 = n2.num, *res = nr.num; while(*c1 || *c2 || prev){ char a = (*c1 ? *c1 : '0'), b = (*c2 ? *c2 : '0'); int result = add_two_char(a, b) + prev; *res = (char)(result % 10 + 48); prev = result / 10; c1++; c2++; res++; } if(n1.is_minus) *res = '-'; } else { if(front_is_bigger(n1.num, n2.num)){ n2.is_minus = !n2.is_minus; subtract(n1, n2, nr); } else { n1.is_minus = !n1.is_minus; subtract(n2, n1, nr); } } } int sub_two_char(char a, char b){ return (int)(a - b); } void subtract(Bignumber n1, Bignumber n2, Bignumber nr){ if(n1.is_minus == n2.is_minus){ memset(nr.num, 0, MAX_LENGTH * sizeof(char)); char *c1 = n1.num, *c2 = n2.num, *res = nr.num; if(!strcmp(c1, c2)){ *res = '0'; return; } int prev = 0; while(*c1 || *c2 || prev){ char a = (*c1 ? *c1 : '0'), b = (*c2 ? *c2 : '0'); int result = sub_two_char(a, b) + prev; *res = (char)((result + 10) % 10 + 48); prev = result < 0 ? -1 : 0; c1++; c2++; res++; } while(*(res - 1) == '0'){ res--; *res = '\0'; } if(n1.is_minus) *res = '-'; } else { n2.is_minus = !n2.is_minus; add(n1, n2, nr); } } bool reverse(Bignumber n1){ char* start = n1.num; bool result = *start == '-'; while(*(n1.num)) n1.num++; n1.num--; while(start < n1.num){ char ch = *start; *start = *(n1.num); *(n1.num) = ch; start++; n1.num--; } return result; } int main(){ Bignumber n1, n2, nr; n1.num = (char *)malloc(MAX_LENGTH * sizeof(char)); n2.num = (char *)malloc(MAX_LENGTH * sizeof(char)); nr.num = (char *)malloc(MAX_LENGTH * sizeof(char)); memset(n1.num, 0, MAX_LENGTH * sizeof(char)); memset(n2.num, 0, MAX_LENGTH * sizeof(char)); scanf("%s", n1.num); scanf("%s", n2.num); n1.is_minus = reverse(n1); n2.is_minus = reverse(n2); if(*(n1.num + strlen(n1.num) - 1) == '-') *(n1.num + strlen(n1.num) - 1) = '\0'; if(*(n2.num + strlen(n2.num) - 1) == '-') *(n2.num + strlen(n2.num) - 1) = '\0'; add(n1, n2, nr); reverse(nr); printf("%s", nr.num); free(n1.num); free(n2.num); free(nr.num); return 0; }
the_stack_data/28437.c
/************************************************************************* > File Name: mmapfile.c > Author: mudongliang > Mail: [email protected] > Created Time: Mon 23 Nov 2015 04:53:42 PM CST ************************************************************************/ #include<stdio.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<unistd.h> #include<sys/mman.h> int main(int argc,const char *argv[]) { struct stat sb; off_t len; char *p; int fd; if (argc != 2){ fprintf(stderr, "usage : %s <file>\n", argv[0]); return 1; } fd = open(argv[1], O_RDONLY); if (fd == -1){ perror("open error"); return 1; } if (fstat(fd, &sb) == -1){ perror("fstat error"); return -1; } if (!S_ISREG(sb.st_mode)){ fprintf(stderr, "%s is not a file\n", argv[1]); return 1; } p = mmap(0, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); if (p == MAP_FAILED){ perror("mmap error"); return 1; } if (close(fd) == -1){ perror("close error"); return -1; } for(len = 0; len < sb.st_size; len++) putchar(p[len]); if(munmap(p, sb.st_size) == -1){ perror("munmap error"); return 1; } return 0; }
the_stack_data/120186.c
#include <stdlib.h> #include <stdio.h> int main(int argc, char **argv) { void *ptr = NULL; ptr = realloc(ptr, 0); printf("realloc(NULL, 0) -- pointer = %p\n", ptr); ptr = malloc(0); printf("malloc(0) -- pointer = %p\n", ptr); return 0; }
the_stack_data/76699438.c
struct a { int b; int *c }; d(); struct a *e(); f(g) { int h, i; for (; h < f; h++) for (; f();) if (h) f(); for (; h < d;) ; for (; d();) if (h) d(); for (; h < e()->b; h++) if (e()->c[h]) i = h; if (h < e) for (; h;) if (i) e(); }
the_stack_data/82950349.c
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <sys/types.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/time.h> #define SEC(tv) (tv.tv_sec + tv.tv_usec/1e6) int main(int argc, char **argv) { struct timeval p_start, p_end, p_time; int *pid; unsigned long int x=1; int num, nproc, io_ops, cpu_ops; long int i=0; if (argc != 4) { printf("Uso comando: %s <num_procs> <IO_ops> <CPU_ops>" "\n <num_procs>: numero total de processos." "\n <IO_ops>: numero de operacoes de IO por processo" "\n <CPU_ops>: numero de operacoes de CPU por processo\n", argv[0]); return 0; } nproc = atoi(argv[1]); io_ops = atoi(argv[2]); cpu_ops = atoi(argv[3]); pid = (int *)calloc(nproc, sizeof(int)); if (!pid){ perror("calloc()"); return -1; } for(num=0; num<nproc; num++) { pid[num]=fork(); if(pid[num]==0) { // Se num for par, filho eh IO bound, // senao, eh CPU bund if((num % 2) == 0) { gettimeofday(&p_start, NULL); for(i=0; i<io_ops; i++){ fprintf(stderr, "Proc:%d i=%ld\n", num, i); fflush(stderr); } gettimeofday(&p_end, NULL); timersub(&p_end, &p_start, &p_time); printf("IO\t %d\t %g\n",num, SEC(p_time)); } else { gettimeofday(&p_start, NULL); for(i=0; i<cpu_ops; i++) { x = (x << 4) - (x << 4); } gettimeofday(&p_end, NULL); timersub(&p_end, &p_start, &p_time); printf("CPU\t %d\t %g\n",num, SEC(p_time)); } exit(0); // todo filho termina aqui ... } } // pai apenas aguarda o termino dos filhos for(i=0; i<nproc; i++) { int pid_p=wait(NULL); } return 0; }
the_stack_data/32949475.c
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* This file is part of the program and library */ /* SCIP --- Solving Constraint Integer Programs */ /* */ /* Copyright (C) 2002-2019 Konrad-Zuse-Zentrum */ /* fuer Informationstechnik Berlin */ /* */ /* SCIP is distributed under the terms of the ZIB Academic License. */ /* */ /* You should have received a copy of the ZIB Academic License */ /* along with SCIP; see the file COPYING. If not visit scip.zib.de. */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /**@file xternal_scheduler.c * @brief main document page * @author Stefan Heinz * @author Jens Schulz */ /*--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/ /**@page SCHEDULER_MAIN Scheduler * @author Stefan Heinz * @author Jens Schulz * * This example contains several readers and \ref heur_listscheduling.h "one primal heuristic" for scheduling * problems. Via this example three different type of scheduling problem can be parsed and solved with \SCIP. These are: * * - resource-constrained project scheduling problems (RCPSP) (see reader_sm.h) * - resource-constrained project scheduling problem with minimal and maximal time lags (RCPSP/max) (see reader_sch.h) * - pack instances (see reader_rcp.h) * * Installation * ------------ * * See the @ref INSTALL_APPLICATIONS_EXAMPLES "Install file" */
the_stack_data/14199438.c
/*Pragoram to evaluate sum of series 1+(1+2)+(1+2+3)+...n terms*/ #include<stdio.h> int main() { int n,i,j;long sum=0; //Initialization printf("Enter value of n: "); //Declaration scanf("%d",&n); //Input for(i=1;i<=n;i++) //Loop to calculate sum { for(j=1;j<=i;j++) //Loop inside 1st loop to calculate sum { sum+=j; } } printf("%ld",sum); return 0; }
the_stack_data/67933.c
#ifndef ROPE_H #define ROPE_H typedef struct rope rope; void rope_init( rope *s, int reserve, float grow ); void rope_append( rope *s, const char *buf, int len ); void rope_dump( rope *s ); int rope_len( rope *s ); #endif #ifdef ROPE_C #pragma once #include <stdint.h> #include <string.h> #include <stdio.h> #include <stdlib.h> struct rope { struct rope *root; struct rope *next; int len, cap; float grow; unsigned char *data; // unsigned char data[rope_BLOCKSIZE - sizeof(rope*)*2 - sizeof(int)*2 )]; }; void rope_init( rope *s, int reserve, float grow ) { memset(s, 0, sizeof(rope)); s->grow = grow; s->data = realloc( s->data, (s->len = 0, s->cap = reserve) ); } void rope_append( rope *s, const char *buf, int len ) { while( s->next ) s = s->next; if( len > 0 && s->cap > 0 ) { int max = len > s->cap ? s->cap : len; memcpy(s->data + s->len, buf, max); s->len += max; s->cap -= max; buf += max; len -= max; } if( len > 0 ) { s->next = malloc( sizeof(rope) ); // linear (no decimals) or incremental (decimals) rope_init( s->next, (s->grow - (int)s->grow) > 0 ? (len+1) * s->grow : s->grow, s->grow ); rope_append( s->next, buf, len ); } } void rope_dump( rope *s ) { puts("--"); for( ; s ; s = s->next ) { printf("%03d/%03d bytes: \"%.*s\"\n", s->len, s->cap + s->len, s->len, s->data); } } int rope_len( rope *s ) { int len = 0; for( ; s ; s = s->next ) { len += s->len; } return len; } #ifdef ROPE_DEMO int main() { rope s; rope_init(&s, 5, 5); // 1.75); // 1.75f); rope_dump(&s); rope_append(&s, "hello world.", 12); rope_dump(&s); rope_append(&s, "there's a lady who's sure all that glitter's gold.", 50); rope_dump(&s); printf("%d bytes\n", rope_len(&s)); } #define main main__ #endif // ROPE_DEMO #endif // ROPE_C
the_stack_data/184518632.c
#include <stdio.h> #include <stdlib.h> #define MAX_SIZE 100 typedef char VertexType; //顶点类型 typedef int EdgeType; //边上的权值类型 //保存邻接表上的信息 typedef struct EdgeNode { int adjvex; //邻接点域,存储该顶点对应的下标 //EdgeType weight; //边上的权值 struct EdgeNode* next; //下一个邻接点 }EdgeNode; //把整个图上的所有结点打包为一个数组 typedef struct VertexNode { VertexType data; //顶点信息 EdgeNode *firstedge; //边表头指针 }AdjList; typedef struct { AdjList list[MAX_SIZE]; //边表头数组 int NumVertexes, NumEdges;//图的顶点数,边数 }GraphAdjList; //创建图的邻接表 void CreateALGraph(GraphAdjList *g) { int i, j, k; EdgeNode *e; EdgeNode *t=NULL; //辅助指针 printf("输入顶点数和边数:\n"); scanf("%d%d", &g->NumVertexes, &g->NumEdges); //现将所有结点保存在一个数组中 printf("输入结点的data域的值:\n"); for (i = 0; i < g->NumVertexes; i++) { scanf("%s", &g->list[i].data); g->list[i].firstedge = NULL; //将边表置为空 } //创建邻接表 for (k = 0; k < g->NumEdges; k++) { printf("输入边(vi,vj)上的顶点序号:\n"); scanf("%d%d", &i, &j); //注意,以下是单链表的头插法 e = (EdgeNode*)malloc(sizeof(EdgeNode)); e->adjvex = j; //邻接序号为j e->next = g->list[i].firstedge; g->list[i].firstedge = e; e = (EdgeNode*)malloc(sizeof(EdgeNode)); //因为是无向图,一条边对应都是两个顶点,所以在一次循环中针对i和j分别进行插入; e->adjvex = i; e->next = g->list[j].firstedge; g->list[j].firstedge = e; } } void ShowALGraph(GraphAdjList *g) { int i; printf("\n遍历邻接表:\n"); for (i = 0; i < g->NumVertexes; i++) { printf("V%d:->", i); EdgeNode *h = g->list[i].firstedge; while (h) { printf("%d->", h->adjvex); h = h->next; } printf("NULL\n"); } } int main() { GraphAdjList *g; g = (GraphAdjList*)malloc(sizeof(GraphAdjList)); CreateALGraph(g); ShowALGraph(g); system("pause"); return 0; } // 输入: // 4 5 // V0 V1 V2 V3 // 0 1 // 0 2 // 0 3 // 1 2 // 2 3 // 输出: // 遍历邻接表: // V0:->3->2->1->NULL // V1:->2->0->NULL // V2:->3->1->0->NULL // V3:->2->0->NULL
the_stack_data/48576413.c
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ int size3, i, size1, size2; int size; char *pfull, *p; char f[70], l[70], id[70]; printf("Enter first name : "); gets(f); printf("Enter last name : "); gets(l); size1 = strlen(f); size2 = strlen(l); size3 = size1 + size2; pfull = (char*)malloc(size3 * sizeof(char)); strcpy(pfull, f); strcat(pfull, " "); strcat(pfull, l); printf("Enter your ID: "); gets(id); p = (char*)malloc((strlen(id) + 1) * sizeof(char)); strcpy(p, id); size = strlen(id) + size3; p = realloc(p, size); strcat(p, " "); strcat(p, pfull); puts(p); return 0; }
the_stack_data/106548.c
#include <stdio.h> #include <stdlib.h> int main() { int i; float chislo,max=0; for(i=0;i<3;i++){ scanf("%f",&chislo); if(chislo>max||i==0){ max=chislo; } } printf("%.1f\n",max); return 0; }
the_stack_data/31388545.c
/* Exercise 1 - Calculations Write a C program to input marks of two subjects. Calculate and print the average of the two marks. */ #include <stdio.h> int main() { float mark1,mark2; printf("Enter the 1st subject marks "); scanf("%f",&mark1); printf("Enter the 2nd subject marks "); scanf("%f",&mark2); printf("average marks %.2f",(mark1+mark2)/2); return 0; }
the_stack_data/90766710.c
/** * Compiler implementation of the * $(LINK2 http://www.dlang.org, D programming language). * * Copyright: Copyright (c) 2016-2017 by Digital Mars, All Rights Reserved * Authors: $(LINK2 http://www.digitalmars.com, Walter Bright) * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/ddmd/backend/gslice.c, backend/gslice.c) */ #if (SCPP || MARS) && !HTOD #include <stdio.h> #include <string.h> #include <stdlib.h> #include <time.h> #include "cc.h" #include "el.h" #include "go.h" #include "oper.h" #include "global.h" #include "type.h" #include "code.h" static char __file__[] = __FILE__; /* for tassert.h */ #include "tassert.h" /* This 'slices' a two register wide aggregate into two separate register-sized variables, * enabling much better enregistering. * SROA (Scalar Replacement Of Aggregates) is the common term for this. */ struct SymInfo { bool canSlice; bool accessSlice; // if Symbol was accessed as a slice bool usePair; // will use OPpair tym_t ty0; // type of first slice tym_t ty1; // type of second slice SYMIDX si0; }; static void sliceStructs_Gather(SymInfo *sia, elem *e) { while (1) { switch (e->Eoper) { case OPvar: { SYMIDX si = e->EV.sp.Vsym->Ssymnum; if (si >= 0 && sia[si].canSlice) { assert(si < globsym.top); unsigned sz = tysize(e->Ety); if (sz == 2 * REGSIZE && !tyfv(e->Ety)) { // Rewrite as OPpair later sia[si].usePair = true; /* OPpair cannot handle XMM registers, cdpair() and fixresult() */ if (tyfloating(sia[si].ty0) || tyfloating(sia[si].ty1)) sia[si].canSlice = false; } else if (sz == REGSIZE && (e->Eoffset == 0 || e->Eoffset == REGSIZE)) { if (!sia[si].accessSlice) { sia[si].ty0 = TYnptr; sia[si].ty1 = TYnptr; } sia[si].accessSlice = true; if (e->Eoffset == 0) sia[si].ty0 = tybasic(e->Ety); else sia[si].ty1 = tybasic(e->Ety); // Cannot slice float fields if the symbol is also accessed using OPpair (see above) if (sia[si].usePair && (tyfloating(sia[si].ty0) || tyfloating(sia[si].ty1))) sia[si].canSlice = false; } else { sia[si].canSlice = false; } } return; } default: if (OTassign(e->Eoper)) { if (OTbinary(e->Eoper)) sliceStructs_Gather(sia, e->E2); // Assignment to a whole var will disallow SROA if (e->E1->Eoper == OPvar) { elem *e1 = e->E1; SYMIDX si = e1->EV.sp.Vsym->Ssymnum; if (si >= 0 && sia[si].canSlice) { assert(si < globsym.top); if (tysize(e1->Ety) != REGSIZE || (e1->Eoffset != 0 && e1->Eoffset != REGSIZE)) { sia[si].canSlice = false; } } return; } e = e->E1; break; } if (OTunary(e->Eoper)) { e = e->E1; break; } if (OTbinary(e->Eoper)) { sliceStructs_Gather(sia, e->E2); e = e->E1; break; } return; } } } static void sliceStructs_Replace(SymInfo *sia, elem *e) { while (1) { switch (e->Eoper) { case OPvar: { Symbol *s = e->EV.sp.Vsym; SYMIDX si = s->Ssymnum; //printf("e: %d %d\n", si, sia[si].canSlice); //elem_print(e); if (si >= 0 && sia[si].canSlice) { if (tysize(e->Ety) == 2 * REGSIZE) { // Rewrite e as (si0 OPpair si0+1) elem *e1 = el_calloc(); el_copy(e1, e); e1->Ety = sia[si].ty0; elem *e2 = el_calloc(); el_copy(e2, e); Symbol *s1 = globsym.tab[sia[si].si0 + 1]; // +1 for second slice e2->Ety = sia[si].ty1; e2->EV.sp.Vsym = s1; e2->Eoffset = 0; e->Eoper = OPpair; e->E1 = e1; e->E2 = e2; } else if (e->Eoffset == 0) // the first slice of the symbol is the same as the original { } else { Symbol *s1 = globsym.tab[sia[si].si0 + 1]; // +1 for second slice e->EV.sp.Vsym = s1; e->Eoffset = 0; //printf("replaced with:\n"); //elem_print(e); } } return; } default: if (OTunary(e->Eoper)) { e = e->E1; break; } if (OTbinary(e->Eoper)) { sliceStructs_Replace(sia, e->E2); e = e->E1; break; } return; } } } void sliceStructs() { if (debugc) printf("sliceStructs()\n"); size_t sia_length = globsym.top; /* 3 is because it is used for two arrays, sia[] and sia2[]. * sia2[] can grow to twice the size of sia[], as symbols can get split into two. */ SymInfo *sia = (SymInfo *)malloc(3 * sia_length * sizeof(SymInfo)); assert(sia); SymInfo *sia2 = sia + sia_length; bool anySlice = false; for (int si = 0; si < globsym.top; si++) { Symbol *s = globsym.tab[si]; //printf("slice1: %s\n", s->Sident); if ((s->Sflags & (GTregcand | SFLunambig)) != (GTregcand | SFLunambig)) { sia[si].canSlice = false; continue; } targ_size_t sz = type_size(s->Stype); if (sz != 2 * REGSIZE || tyfv(s->Stype->Tty) || tybasic(s->Stype->Tty) == TYhptr) // because there is no TYseg { sia[si].canSlice = false; continue; } switch (s->Sclass) { case SCfastpar: case SCregister: case SCauto: case SCshadowreg: case SCparameter: anySlice = true; sia[si].canSlice = true; sia[si].accessSlice = false; sia[si].usePair = false; break; case SCstack: case SCpseudo: case SCstatic: case SCbprel: sia[si].canSlice = false; break; default: symbol_print(s); assert(0); } } if (!anySlice) goto Ldone; for (block *b = startblock; b; b = b->Bnext) { if (b->BC == BCasm) goto Ldone; if (b->Belem) sliceStructs_Gather(sia, b->Belem); } { // scope needed because of goto skipping declarations bool any = false; int n = 0; // the number of symbols added for (int si = 0; si < sia_length; si++) { sia2[si + n].canSlice = false; if (sia[si].canSlice) { if (!sia[si].accessSlice) { // If never did access it as a slice, don't slice sia[si].canSlice = false; continue; } /* Split slice-able symbol sold into two symbols, * (sold,snew) in adjacent slots in the symbol table. */ Symbol *sold = globsym.tab[si + n]; size_t idlen = 2 + strlen(sold->Sident) + 2; char *id = (char *)malloc(idlen + 1); assert(id); sprintf(id, "__%s_%d", sold->Sident, REGSIZE); if (debugc) printf("creating slice symbol %s\n", id); Symbol *snew = symbol_calloc(id, idlen); free(id); snew->Sclass = sold->Sclass; snew->Sfl = sold->Sfl; snew->Sflags = sold->Sflags; if (snew->Sclass == SCfastpar || snew->Sclass == SCshadowreg) { snew->Spreg = sold->Spreg2; snew->Spreg2 = NOREG; sold->Spreg2 = NOREG; } type_free(sold->Stype); sold->Stype = type_fake(sia[si].ty0); sold->Stype->Tcount++; snew->Stype = type_fake(sia[si].ty1); snew->Stype->Tcount++; SYMIDX sinew = symbol_add(snew); for (int i = sinew; i > si + n + 1; --i) { globsym.tab[i] = globsym.tab[i - 1]; globsym.tab[i]->Ssymnum += 1; } globsym.tab[si + n + 1] = snew; snew->Ssymnum = si + n + 1; sia2[si + n].canSlice = true; sia2[si + n].si0 = si + n; sia2[si + n].ty0 = sia[si].ty0; sia2[si + n].ty1 = sia[si].ty1; ++n; any = true; } } if (!any) goto Ldone; } for (int si = 0; si < globsym.top; si++) { Symbol *s = globsym.tab[si]; assert(s->Ssymnum == si); } for (block *b = startblock; b; b = b->Bnext) { if (b->Belem) sliceStructs_Replace(sia2, b->Belem); } Ldone: free(sia); } #endif
the_stack_data/727570.c
static int x; static int *y; int test116() { return x + 174; }
the_stack_data/168892833.c
#include <stdio.h> #include <locale.h> char VerificaPos(int Num) { char Ret; if (Num >= 0) { Ret = 'p'; } else { Ret = 'n'; } return Ret; } int Num; char Retorno; main() { setlocale(LC_ALL, "Portuguese"); //Leitura de variáveis printf("Digite um número: "); scanf("%d", &Num); //Verifica se Num é positivo ou negativo Retorno = VerificaPos(Num); //Exibe mensagem if (Retorno == 'p') { printf("Positivo!!"); } else { printf("Negativo!!"); } return 0; }
the_stack_data/57949086.c
/* * Copyright (c) 1994 Christopher G. Demetriou * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Christopher G. Demetriou. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef lint static char rcsid[] = "$FreeBSD: soc2013/dpl/head/lib/libcompat/4.1/ftime.c 211104 2010-08-08 08:19:23Z ed $"; #endif /* not lint */ #include <sys/types.h> #include <sys/time.h> #include <sys/timeb.h> int ftime(struct timeb *tbp) { struct timezone tz; struct timeval t; if (gettimeofday(&t, &tz) < 0) return (-1); tbp->millitm = t.tv_usec / 1000; tbp->time = t.tv_sec; tbp->timezone = tz.tz_minuteswest; tbp->dstflag = tz.tz_dsttime; return (0); }
the_stack_data/231392983.c
/* usbreset -- send a USB port reset to a USB device * * Compile using: gcc -o usbreset usbreset.c * * * */ #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <sys/ioctl.h> #include <linux/usbdevice_fs.h> int main(int argc, char **argv) { const char *filename; int fd; int rc; if (argc != 2) { fprintf(stderr, "Usage: usbreset device-filename\n"); return 1; } filename = argv[1]; fd = open(filename, O_WRONLY); if (fd < 0) { perror("Error opening output file"); return 1; } printf("Resetting USB device %s\n", filename); rc = ioctl(fd, USBDEVFS_RESET, 0); if (rc < 0) { perror("Error in ioctl"); return 1; } printf("Reset successful\n"); close(fd); return 0; }
the_stack_data/70449581.c
#include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <stdint.h> #include <string.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sem.h> #include <sys/wait.h> #define BUFSIZE 4096 #define BUFNUM 16 #define SRV_ADDR "127.0.0.1" #define SRV_PORT 7777 /* TODO: Useful structure */ union semun { int val; struct semid_ds *buf; unsigned short *array; }; struct sembuf p = { 0, -1}; //semwait struct sembuf v = { 0, +1}; //semsignal struct Buffer{ int eof; uint8_t ctx[BUFSIZE]; size_t len; }; /* Declare functions */ int sem_wait(int sem_id){ if (semop(sem_id, &p, 1) == -1) return -1; return 0; } int sem_signal(int sem_id){ if (semop(sem_id, &v, 1) == -1) return -1; return 0; } /* Writer */ void writer(int); /* Downloader */ int connect_to_server(); void downloader(int); /* IPC */ void IPC_init(); void IPC_release(); /* TODO: Declare some global variable here */ int sem_id; int full_id; int empty_id; int shm_id; struct Buffer *buf; int main(int argc, char** argv){ /* DO NOT Modify this function */ int i, pid, status, target_id, ret = 0; if (argc < 2){ perror("Please specify target id"); exit(1); } target_id = atoi(argv[1]); printf("IPC_init...\n"); IPC_init(); printf("Starting downloader and writer...\n"); for(i=0; i<2; i++){ pid = fork(); if(pid == -1){ perror("fork failed\n"); exit(1); } else if(pid == 0){ if(!i) downloader(target_id); else writer(target_id); } } /* * Make surce your downloader and writer exit normaly * */ for(i=0;i<2;i++){ wait(&status); if(status != 0) ret = 1; } IPC_release(); return ret; } void downloader(int target_id){ int ret, sockfd; unsigned local_it = 0; sockfd = connect_to_server(); if (write(sockfd, &target_id, sizeof(int)) == -1){ perror("socket write error\n"); exit(1); } while ( 1 ) { /* TODO: sync downloader and writer */ if(sem_wait(full_id) == -1){ perror("wait error\n"); exit(1); } if(sem_wait(sem_id) == -1){ perror("wait error\n"); exit(1); } //enter critical section ret = read(sockfd, buf[local_it].ctx, BUFSIZE); if (ret == -1){ perror("socket may be broken"); exit(1); } else if (ret == 0){ buf[local_it].eof = 1; //exit critical section (eof) /* TODO: signal writer */ if(sem_signal(sem_id) == -1){ perror("signal error\n"); exit(1); } if(sem_signal(empty_id) == -1){ perror("signal error\n"); exit(1); } exit(0); } buf[local_it].len = ret; //exit critical section /* TODO: sync downloader and writer */ if(sem_signal(sem_id) == -1){ perror("signal error\n"); exit(1); } if(sem_signal(empty_id) == -1){ perror("signal error\n"); exit(1); } local_it = (local_it+1) % BUFNUM; } } void writer(int target_id){ int local_it = 0, fd, ret; char path[256]; sprintf(path, "./output/%d", target_id); fd = open(path, O_CREAT|O_RDWR|O_TRUNC, 0755); if(fd == -1){ perror("Can not create output file"); exit(1); } while(1){ /* TODO: sync downloader and writer */ if(sem_wait(empty_id) == -1){ perror("wait error\n"); exit(1); } if(sem_wait(sem_id) == -1){ perror("wait error\n"); exit(1); } //enter critical section /* Receive EOF from downloader */ if (buf[local_it].eof){ printf("Receive EOF, exiting writer process\n"); exit(0); } ret = write(fd, buf[local_it].ctx, buf[local_it].len); if(ret != buf[local_it].len){ perror("Output file fd write failed"); exit(1); } //exit critical section /* TODO: sync downloader and writer */ if(sem_signal(sem_id) == -1){ perror("signal error\n"); exit(1); } if(sem_signal(full_id) == -1){ perror("signal error\n"); exit(1); } local_it = (local_it+1) % BUFNUM; } } void IPC_init(){ union semun sem_union; shm_id = shmget(IPC_PRIVATE, sizeof(struct Buffer)*BUFNUM, IPC_CREAT|0600); buf = (struct Buffer*)shmat(shm_id, NULL, 0); if(buf == (void*)-1){ perror("shmat error"); exit(1); } memset(buf, 0, sizeof(struct Buffer)*BUFNUM); printf("shm_id: %d\n", shm_id); /* TODO: Create semaphore */ if((sem_id = semget(IPC_PRIVATE, 1, IPC_CREAT | 0666)) < 0){ perror("semget error\n"); exit(1); } printf("mutex_id: %d\n", sem_id); if((empty_id = semget(IPC_PRIVATE, 1, IPC_CREAT | 0666)) < 0){ perror("semget error\n"); exit(1); } printf("empty_id: %d\n", empty_id); if((full_id = semget(IPC_PRIVATE, 1, IPC_CREAT | 0666)) < 0){ perror("semget error\n"); exit(1); } printf("full_id: %d\n", full_id); sem_union.val = 1; if(semctl(sem_id, 0, SETVAL, sem_union) == -1){ perror("semctl error\n"); exit(1); } sem_union.val = BUFNUM; if(semctl(full_id, 0, SETVAL, sem_union) == -1){ perror("semctl error\n"); exit(1); } sem_union.val = 0; if(semctl(empty_id, 0, SETVAL, sem_union) == -1){ perror("semctl error\n"); exit(1); } } void IPC_release(){ if(shmdt(buf) == -1){ perror("detach SHM Error"); } shmctl(shm_id, IPC_RMID, 0); /* TODO(Optinal): Release semaphore */ union semun sem_union; printf("release semaphores\n"); if (semctl(sem_id, 0, IPC_RMID, sem_union) == -1){ perror("release error\n"); exit(1); } if (semctl(empty_id, 0, IPC_RMID, sem_union) == -1){ perror("release error\n"); exit(1); } if (semctl(full_id, 0, IPC_RMID, sem_union) == -1){ perror("release error\n"); exit(1); } } int connect_to_server(){ /* DO NOT Modify this function */ struct sockaddr_in srv; int sockfd; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1){ perror("Failed to create socket\n"); exit(1); } memset(&srv, 0, sizeof(srv)); srv.sin_family = AF_INET; srv.sin_addr.s_addr = inet_addr(SRV_ADDR); srv.sin_port = htons(SRV_PORT); if (connect(sockfd, (struct sockaddr*)&srv, sizeof(srv)) == -1){ perror("Failed to connet to Server"); exit(1); } return sockfd; }
the_stack_data/85126.c
/* File: printf.c Copyright (C) 2004 Kustaa Nyholm This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "printf.h" typedef void (*putcf)(void*, char); static putcf stdout_putf; static void* stdout_putp; #ifdef PRINTF_LONG_SUPPORT static void uli2a(unsigned long int num, unsigned int base, int uc, char* bf) { int n = 0; unsigned int d = 1; while (num / d >= base) d *= base; while (d != 0) { int dgt = num / d; num %= d; d /= base; if (n || dgt > 0 || d == 0) { *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10); ++n; } } *bf = 0; } static void li2a(long num, char* bf) { if (num < 0) { num = -num; *bf++ = '-'; } uli2a(num, 10, 0, bf); } #endif static void ui2a(unsigned int num, unsigned int base, int uc, char* bf) { int n = 0; unsigned int d = 1; while (num / d >= base) d *= base; while (d != 0) { int dgt = num / d; num %= d; d /= base; if (n || dgt > 0 || d == 0) { *bf++ = dgt + (dgt < 10 ? '0' : (uc ? 'A' : 'a') - 10); ++n; } } *bf = 0; } static void i2a(int num, char* bf) { if (num < 0) { num = -num; *bf++ = '-'; } ui2a(num, 10, 0, bf); } static int a2d(char ch) { if (ch >= '0' && ch <= '9') return ch - '0'; else if (ch >= 'a' && ch <= 'f') return ch - 'a' + 10; else if (ch >= 'A' && ch <= 'F') return ch - 'A' + 10; else return -1; } static char a2i(char ch, char** src, int base, int* nump) { char* p = *src; int num = 0; int digit; while ((digit = a2d(ch)) >= 0) { if (digit > base) break; num = num * base + digit; ch = *p++; } *src = p; *nump = num; return ch; } static void putchw(void* putp, putcf putf, int n, char z, char* bf) { char fc = z ? '0' : ' '; char ch; char* p = bf; while (*p++ && n > 0) n--; while (n-- > 0) putf(putp, fc); while ((ch = *bf++)) putf(putp, ch); } void tfp_format(void* putp, putcf putf, char* fmt, va_list va) { char bf[12]; char ch; while ((ch = *(fmt++))) { if (ch != '%') putf(putp, ch); else { char lz = 0; #ifdef PRINTF_LONG_SUPPORT char lng = 0; #endif int w = 0; ch = *(fmt++); if (ch == '0') { ch = *(fmt++); lz = 1; } if (ch >= '0' && ch <= '9') { ch = a2i(ch, &fmt, 10, &w); } #ifdef PRINTF_LONG_SUPPORT if (ch == 'l') { ch = *(fmt++); lng = 1; } #endif switch (ch) { case 0: goto abort; case 'u': { #ifdef PRINTF_LONG_SUPPORT if (lng) uli2a(va_arg(va, unsigned long int), 10, 0, bf); else #endif ui2a(va_arg(va, unsigned int), 10, 0, bf); putchw(putp, putf, w, lz, bf); break; } case 'd': { #ifdef PRINTF_LONG_SUPPORT if (lng) li2a(va_arg(va, unsigned long int), bf); else #endif i2a(va_arg(va, int), bf); putchw(putp, putf, w, lz, bf); break; } case 'x': case 'X': #ifdef PRINTF_LONG_SUPPORT if (lng) uli2a(va_arg(va, unsigned long int), 16, (ch == 'X'), bf); else #endif ui2a(va_arg(va, unsigned int), 16, (ch == 'X'), bf); putchw(putp, putf, w, lz, bf); break; case 'c': putf(putp, (char)(va_arg(va, int))); break; case 's': putchw(putp, putf, w, 0, va_arg(va, char*)); break; case '%': putf(putp, ch); default: break; } } } abort:; } void init_printf(void* putp, void (*putf)(void*, char)) { stdout_putf = putf; stdout_putp = putp; } void tfp_printf(char* fmt, ...) { va_list va; va_start(va, fmt); tfp_format(stdout_putp, stdout_putf, fmt, va); va_end(va); } static void putcp(void* p, char c) { *(*((char**)p))++ = c; } void tfp_sprintf(char* s, char* fmt, ...) { va_list va; va_start(va, fmt); tfp_format(&s, putcp, fmt, va); putcp(&s, 0); va_end(va); }
the_stack_data/423700.c
/*********************************************************************************************************//** * @file syscalls.c * @version $Rev:: 93 $ * @date $Date:: 2015-11-24 #$ * @brief Implementation of system call related functions. ************************************************************************************************************* * @attention * * Firmware Disclaimer Information * * 1. The customer hereby acknowledges and agrees that the program technical documentation, including the * code, which is supplied by Holtek Semiconductor Inc., (hereinafter referred to as "HOLTEK") is the * proprietary and confidential intellectual property of HOLTEK, and is protected by copyright law and * other intellectual property laws. * * 2. The customer hereby acknowledges and agrees that the program technical documentation, including the * code, is confidential information belonging to HOLTEK, and must not be disclosed to any third parties * other than HOLTEK and the customer. * * 3. The program technical documentation, including the code, is provided "as is" and for customer reference * only. After delivery by HOLTEK, the customer shall use the program technical documentation, including * the code, at their own risk. HOLTEK disclaims any expressed, implied or statutory warranties, including * the warranties of merchantability, satisfactory quality and fitness for a particular purpose. * * <h2><center>Copyright (C) Holtek Semiconductor Inc. All rights reserved</center></h2> ************************************************************************************************************/ /* Includes ------------------------------------------------------------------------------------------------*/ #include <stdio.h> #include <stdarg.h> #include <sys/types.h> #include <sys/stat.h> /** @addtogroup HT32_Peripheral_Driver HT32 Peripheral Driver * @{ */ /** @defgroup SYSCALLS System call functions * @brief System call functions for GNU toolchain * @{ */ /* Global variables ----------------------------------------------------------------------------------------*/ /** @defgroup SYSCALLS_Global_Variable System call global variables * @{ */ #undef errno extern int errno; extern int _end; /** * @} */ /* Global functions ----------------------------------------------------------------------------------------*/ /** @defgroup SYSCALLS_Exported_Functions System call exported functions * @{ */ caddr_t _sbrk(int incr) { static unsigned char *heap; unsigned char *prev_heap; heap = (unsigned char *)&_end; prev_heap = heap; heap += incr; return (caddr_t) prev_heap; } int link(char *old, char *new) { return -1; } int _close(int fd) { return -1; } int _fstat(int fd, struct stat *st) { st->st_mode = S_IFCHR; return 0; } int _isatty(int fd) { return 1; } int _lseek(int fd, int ptr, int dir) { return 0; } int _read(int fd, char *ptr, int len) { return 0; } int _write(int fd, char *ptr, int len) { return len; } void abort(void) { /* Abort called */ while (1); } /** * @} */ /** * @} */ /** * @} */
the_stack_data/725823.c
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <sys/time.h> /* Console I/O. Exports: vmEmit, vmKey, vmQkey, vmKeyFormat If Linux: RawMode, CookedMode vmKeyFormat = 0 for Windows, 1 for Linux. The escape sequences are different. */ #ifdef __linux__ #include <string.h> #include <unistd.h> #include <sys/select.h> #include <termios.h> #elif _WIN32 #include <windows.h> #include <conio.h> #endif // __linux__ #ifdef __linux__ // Linux uses cooked mode to input a command line (see Tiff.c's QUIT loop). // Any keyboard input uses raw mode. // Apparently, Windows getch does this switchover for us. // Thanks to ncurses for providing a way to switch modes. static struct termios orig_termios; static int isRawMode=0; void CookedMode() { if (isRawMode) { tcsetattr(0, TCSANOW, &orig_termios); isRawMode = 0; } } void RawMode() { struct termios new_termios; if (!isRawMode) { isRawMode = 1; /* take two copies - one for now, one for later */ tcgetattr(0, &orig_termios); memcpy(&new_termios, &orig_termios, sizeof(new_termios)); /* register cleanup handler, and set the new terminal mode */ atexit(CookedMode); // in case BYE executes while in raw mode cfmakeraw(&new_termios); tcsetattr(0, TCSANOW, &new_termios); } } uint32_t vmKeyFormat(uint32_t dummy) { return 1; } uint32_t vmQkey(uint32_t dummy) { RawMode(); struct timeval tv = { 0L, 0L }; fd_set fds; FD_ZERO(&fds); FD_SET(0, &fds); return select(1, &fds, NULL, NULL, &tv); } uint32_t vmKey(uint32_t dummy) { RawMode(); int r; unsigned char c; if ((r = read(0, &c, sizeof(c))) < 0) { return r; } else { return c; } } #elif _WIN32 uint32_t vmQkey(uint32_t dummy) { Sleep(1); // don't hog the CPU return (_kbhit() != 0); // 0 or 1 } uint32_t vmKey(uint32_t dummy) { return _getch(); } uint32_t vmKeyFormat(uint32_t dummy) { return 0; } #else #error Unknown OS for console I/O #endif uint32_t vmEmit(uint32_t c) { putchar(c); #ifdef __linux__ fflush(stdout); usleep(1000); #endif return 0; }
the_stack_data/48574940.c
/* * Copyright (c) 1985 Regents of the University of California. * * Use and reproduction of this software are granted in accordance with * the terms and conditions specified in the Berkeley Software License * Agreement (in particular, this entails acknowledgement of the programs' * source, and inclusion of this notice) with the additional understanding * that all recipients should regard themselves as participants in an * ongoing research project and hence should feel obligated to report * their experiences (good or bad) with these elementary function codes, * using "sendbug 4bsd-bugs@BERKELEY", to the authors. */ #ifndef lint static char sccsid[] = "@(#)log__L.c 1.2 (Berkeley) 08/21/85"; #endif not lint /* log__L(Z) * LOG(1+X) - 2S X * RETURN --------------- WHERE Z = S*S, S = ------- , 0 <= Z <= .0294... * S 2 + X * * DOUBLE PRECISION (VAX D FORMAT 56 bits or IEEE DOUBLE 53 BITS) * KERNEL FUNCTION FOR LOG; TO BE USED IN LOG1P, LOG, AND POW FUNCTIONS * CODED IN C BY K.C. NG, 1/19/85; * REVISED BY K.C. Ng, 2/3/85, 4/16/85. * * Method : * 1. Polynomial approximation: let s = x/(2+x). * Based on log(1+x) = log(1+s) - log(1-s) * = 2s + 2/3 s**3 + 2/5 s**5 + ....., * * (log(1+x) - 2s)/s is computed by * * z*(L1 + z*(L2 + z*(... (L7 + z*L8)...))) * * where z=s*s. (See the listing below for Lk's values.) The * coefficients are obtained by a special Remez algorithm. * * Accuracy: * Assuming no rounding error, the maximum magnitude of the approximation * error (absolute) is 2**(-58.49) for IEEE double, and 2**(-63.63) * for VAX D format. * * Constants: * The hexadecimal values are the intended ones for the following constants. * The decimal values may be used, provided that the compiler will convert * from decimal to binary accurately enough to produce the hexadecimal values * shown. */ #ifdef VAX /* VAX D format (56 bits) */ /* static double */ /* L1 = 6.6666666666666703212E-1 , Hex 2^ 0 * .AAAAAAAAAAAAC5 */ /* L2 = 3.9999999999970461961E-1 , Hex 2^ -1 * .CCCCCCCCCC2684 */ /* L3 = 2.8571428579395698188E-1 , Hex 2^ -1 * .92492492F85782 */ /* L4 = 2.2222221233634724402E-1 , Hex 2^ -2 * .E38E3839B7AF2C */ /* L5 = 1.8181879517064680057E-1 , Hex 2^ -2 * .BA2EB4CC39655E */ /* L6 = 1.5382888777946145467E-1 , Hex 2^ -2 * .9D8551E8C5781D */ /* L7 = 1.3338356561139403517E-1 , Hex 2^ -2 * .8895B3907FCD92 */ /* L8 = 1.2500000000000000000E-1 , Hex 2^ -2 * .80000000000000 */ static long L1x[] = { 0xaaaa402a, 0xaac5aaaa}; static long L2x[] = { 0xcccc3fcc, 0x2684cccc}; static long L3x[] = { 0x49243f92, 0x578292f8}; static long L4x[] = { 0x8e383f63, 0xaf2c39b7}; static long L5x[] = { 0x2eb43f3a, 0x655ecc39}; static long L6x[] = { 0x85513f1d, 0x781de8c5}; static long L7x[] = { 0x95b33f08, 0xcd92907f}; static long L8x[] = { 0x00003f00, 0x00000000}; #define L1 (*(double*)L1x) #define L2 (*(double*)L2x) #define L3 (*(double*)L3x) #define L4 (*(double*)L4x) #define L5 (*(double*)L5x) #define L6 (*(double*)L6x) #define L7 (*(double*)L7x) #define L8 (*(double*)L8x) #else /* IEEE double */ static double L1 = 6.6666666666667340202E-1 , /*Hex 2^ -1 * 1.5555555555592 */ L2 = 3.9999999999416702146E-1 , /*Hex 2^ -2 * 1.999999997FF24 */ L3 = 2.8571428742008753154E-1 , /*Hex 2^ -2 * 1.24924941E07B4 */ L4 = 2.2222198607186277597E-1 , /*Hex 2^ -3 * 1.C71C52150BEA6 */ L5 = 1.8183562745289935658E-1 , /*Hex 2^ -3 * 1.74663CC94342F */ L6 = 1.5314087275331442206E-1 , /*Hex 2^ -3 * 1.39A1EC014045B */ L7 = 1.4795612545334174692E-1 ; /*Hex 2^ -3 * 1.2F039F0085122 */ #endif double log__L(z) double z; { #ifdef VAX return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*(L7+z*L8)))))))); #else /* IEEE double */ return(z*(L1+z*(L2+z*(L3+z*(L4+z*(L5+z*(L6+z*L7))))))); #endif }
the_stack_data/9511592.c
#include <stdio.h> #include <string.h> #define StrLen 256 static char root[StrLen]; /* * extract: * * This function extracts the root filename from a whole filename, * cutting off any path information and anything after the last period * ('.') character. * * The output is returned in a static area, so it should be copied * before calling this function again. If anything goes wrong, the * return value will be NULL. * */ char *extract(char *whole) { char *cp; if (whole == NULL) /* pointer to nothing */ return NULL; if (*whole == '\0') { /* pointer to zero-length string */ root[0] = *whole; return root; } /* cut off leading slashes */ cp = strrchr(whole, '/'); if (cp == NULL) /* no slashes */ (void) strcpy(root, whole); else { /* at least one slash */ (void) strcpy(root, cp + 1); } /* cut off the last period */ cp = strrchr(root, '.'); if (cp != NULL) /* there actually is a period to cut off */ *cp = '\0'; /* nothing went wrong, so report success */ #ifdef DEBUG (void) puts(root); #endif return root; }
the_stack_data/1112188.c
#include <stdio.h> int main() { int begin, end; int max = 0, num; int k, flag = 0;; do { printf("begin = "); k = scanf("%d", &begin); while (getchar() != '\n'); } while (k == 0); do { printf("end = "); k = scanf("%d", &end); while (getchar() != '\n'); } while (k == 0 || begin >= end); while (1) { printf("y/n"); k = getchar(); if (k == 'n') { break; } do { printf("num = "); k = scanf("%d", &num); while (getchar() != '\n'); } while (k == 0); if (flag == 0 && num > begin && num < end && num < 0) { max = num; flag = 1; } if (flag == 1 && num > begin && num < end && num < 0 && num > max) { max = num; } } if (flag == 0) { printf("No numbers"); } else { printf("max = %d", max); } return 0; }
the_stack_data/65460.c
extern float __VERIFIER_nondet_float(void); extern int __VERIFIER_nondet_int(void); typedef enum {false, true} bool; bool __VERIFIER_nondet_bool(void) { return __VERIFIER_nondet_int() != 0; } int main() { bool _J1817, _x__J1817; bool _J1811, _x__J1811; bool _J1805, _x__J1805; bool _EL_U_1781, _x__EL_U_1781; bool _EL_X_1776, _x__EL_X_1776; float x_0, _x_x_0; bool _EL_U_1783, _x__EL_U_1783; bool _EL_U_1785, _x__EL_U_1785; float x_7, _x_x_7; float x_10, _x_x_10; float x_3, _x_x_3; float x_2, _x_x_2; float x_16, _x_x_16; float x_4, _x_x_4; float x_22, _x_x_22; float x_5, _x_x_5; float x_6, _x_x_6; float x_8, _x_x_8; float x_11, _x_x_11; float x_13, _x_x_13; float x_19, _x_x_19; float x_20, _x_x_20; float x_9, _x_x_9; float x_21, _x_x_21; float x_12, _x_x_12; float x_23, _x_x_23; float x_14, _x_x_14; float x_15, _x_x_15; float x_17, _x_x_17; float x_18, _x_x_18; float x_1, _x_x_1; int __steps_to_fair = __VERIFIER_nondet_int(); _J1817 = __VERIFIER_nondet_bool(); _J1811 = __VERIFIER_nondet_bool(); _J1805 = __VERIFIER_nondet_bool(); _EL_U_1781 = __VERIFIER_nondet_bool(); _EL_X_1776 = __VERIFIER_nondet_bool(); x_0 = __VERIFIER_nondet_float(); _EL_U_1783 = __VERIFIER_nondet_bool(); _EL_U_1785 = __VERIFIER_nondet_bool(); x_7 = __VERIFIER_nondet_float(); x_10 = __VERIFIER_nondet_float(); x_3 = __VERIFIER_nondet_float(); x_2 = __VERIFIER_nondet_float(); x_16 = __VERIFIER_nondet_float(); x_4 = __VERIFIER_nondet_float(); x_22 = __VERIFIER_nondet_float(); x_5 = __VERIFIER_nondet_float(); x_6 = __VERIFIER_nondet_float(); x_8 = __VERIFIER_nondet_float(); x_11 = __VERIFIER_nondet_float(); x_13 = __VERIFIER_nondet_float(); x_19 = __VERIFIER_nondet_float(); x_20 = __VERIFIER_nondet_float(); x_9 = __VERIFIER_nondet_float(); x_21 = __VERIFIER_nondet_float(); x_12 = __VERIFIER_nondet_float(); x_23 = __VERIFIER_nondet_float(); x_14 = __VERIFIER_nondet_float(); x_15 = __VERIFIER_nondet_float(); x_17 = __VERIFIER_nondet_float(); x_18 = __VERIFIER_nondet_float(); x_1 = __VERIFIER_nondet_float(); bool __ok = (1 && (((( !(_EL_U_1785 || ( !(_EL_U_1783 || ( !(_EL_X_1776 || _EL_U_1781)))))) && ( !_J1805)) && ( !_J1811)) && ( !_J1817))); while (__steps_to_fair >= 0 && __ok) { if (((_J1805 && _J1811) && _J1817)) { __steps_to_fair = __VERIFIER_nondet_int(); } else { __steps_to_fair--; } _x__J1817 = __VERIFIER_nondet_bool(); _x__J1811 = __VERIFIER_nondet_bool(); _x__J1805 = __VERIFIER_nondet_bool(); _x__EL_U_1781 = __VERIFIER_nondet_bool(); _x__EL_X_1776 = __VERIFIER_nondet_bool(); _x_x_0 = __VERIFIER_nondet_float(); _x__EL_U_1783 = __VERIFIER_nondet_bool(); _x__EL_U_1785 = __VERIFIER_nondet_bool(); _x_x_7 = __VERIFIER_nondet_float(); _x_x_10 = __VERIFIER_nondet_float(); _x_x_3 = __VERIFIER_nondet_float(); _x_x_2 = __VERIFIER_nondet_float(); _x_x_16 = __VERIFIER_nondet_float(); _x_x_4 = __VERIFIER_nondet_float(); _x_x_22 = __VERIFIER_nondet_float(); _x_x_5 = __VERIFIER_nondet_float(); _x_x_6 = __VERIFIER_nondet_float(); _x_x_8 = __VERIFIER_nondet_float(); _x_x_11 = __VERIFIER_nondet_float(); _x_x_13 = __VERIFIER_nondet_float(); _x_x_19 = __VERIFIER_nondet_float(); _x_x_20 = __VERIFIER_nondet_float(); _x_x_9 = __VERIFIER_nondet_float(); _x_x_21 = __VERIFIER_nondet_float(); _x_x_12 = __VERIFIER_nondet_float(); _x_x_23 = __VERIFIER_nondet_float(); _x_x_14 = __VERIFIER_nondet_float(); _x_x_15 = __VERIFIER_nondet_float(); _x_x_17 = __VERIFIER_nondet_float(); _x_x_18 = __VERIFIER_nondet_float(); _x_x_1 = __VERIFIER_nondet_float(); __ok = ((((((((((((((((((((((((((((x_23 + (-1.0 * _x_x_0)) <= -16.0) && (((x_22 + (-1.0 * _x_x_0)) <= -14.0) && (((x_21 + (-1.0 * _x_x_0)) <= -6.0) && (((x_20 + (-1.0 * _x_x_0)) <= -7.0) && (((x_17 + (-1.0 * _x_x_0)) <= -17.0) && (((x_13 + (-1.0 * _x_x_0)) <= -19.0) && (((x_10 + (-1.0 * _x_x_0)) <= -11.0) && (((x_8 + (-1.0 * _x_x_0)) <= -13.0) && (((x_7 + (-1.0 * _x_x_0)) <= -19.0) && (((x_4 + (-1.0 * _x_x_0)) <= -3.0) && (((x_0 + (-1.0 * _x_x_0)) <= -15.0) && ((x_1 + (-1.0 * _x_x_0)) <= -10.0)))))))))))) && (((x_23 + (-1.0 * _x_x_0)) == -16.0) || (((x_22 + (-1.0 * _x_x_0)) == -14.0) || (((x_21 + (-1.0 * _x_x_0)) == -6.0) || (((x_20 + (-1.0 * _x_x_0)) == -7.0) || (((x_17 + (-1.0 * _x_x_0)) == -17.0) || (((x_13 + (-1.0 * _x_x_0)) == -19.0) || (((x_10 + (-1.0 * _x_x_0)) == -11.0) || (((x_8 + (-1.0 * _x_x_0)) == -13.0) || (((x_7 + (-1.0 * _x_x_0)) == -19.0) || (((x_4 + (-1.0 * _x_x_0)) == -3.0) || (((x_0 + (-1.0 * _x_x_0)) == -15.0) || ((x_1 + (-1.0 * _x_x_0)) == -10.0))))))))))))) && ((((x_21 + (-1.0 * _x_x_1)) <= -17.0) && (((x_17 + (-1.0 * _x_x_1)) <= -9.0) && (((x_15 + (-1.0 * _x_x_1)) <= -14.0) && (((x_14 + (-1.0 * _x_x_1)) <= -15.0) && (((x_12 + (-1.0 * _x_x_1)) <= -17.0) && (((x_11 + (-1.0 * _x_x_1)) <= -3.0) && (((x_10 + (-1.0 * _x_x_1)) <= -5.0) && (((x_9 + (-1.0 * _x_x_1)) <= -3.0) && (((x_7 + (-1.0 * _x_x_1)) <= -12.0) && (((x_5 + (-1.0 * _x_x_1)) <= -12.0) && (((x_0 + (-1.0 * _x_x_1)) <= -3.0) && ((x_2 + (-1.0 * _x_x_1)) <= -18.0)))))))))))) && (((x_21 + (-1.0 * _x_x_1)) == -17.0) || (((x_17 + (-1.0 * _x_x_1)) == -9.0) || (((x_15 + (-1.0 * _x_x_1)) == -14.0) || (((x_14 + (-1.0 * _x_x_1)) == -15.0) || (((x_12 + (-1.0 * _x_x_1)) == -17.0) || (((x_11 + (-1.0 * _x_x_1)) == -3.0) || (((x_10 + (-1.0 * _x_x_1)) == -5.0) || (((x_9 + (-1.0 * _x_x_1)) == -3.0) || (((x_7 + (-1.0 * _x_x_1)) == -12.0) || (((x_5 + (-1.0 * _x_x_1)) == -12.0) || (((x_0 + (-1.0 * _x_x_1)) == -3.0) || ((x_2 + (-1.0 * _x_x_1)) == -18.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_2)) <= -10.0) && (((x_21 + (-1.0 * _x_x_2)) <= -7.0) && (((x_19 + (-1.0 * _x_x_2)) <= -12.0) && (((x_18 + (-1.0 * _x_x_2)) <= -11.0) && (((x_16 + (-1.0 * _x_x_2)) <= -15.0) && (((x_15 + (-1.0 * _x_x_2)) <= -13.0) && (((x_13 + (-1.0 * _x_x_2)) <= -17.0) && (((x_12 + (-1.0 * _x_x_2)) <= -10.0) && (((x_7 + (-1.0 * _x_x_2)) <= -20.0) && (((x_6 + (-1.0 * _x_x_2)) <= -8.0) && (((x_1 + (-1.0 * _x_x_2)) <= -5.0) && ((x_3 + (-1.0 * _x_x_2)) <= -3.0)))))))))))) && (((x_23 + (-1.0 * _x_x_2)) == -10.0) || (((x_21 + (-1.0 * _x_x_2)) == -7.0) || (((x_19 + (-1.0 * _x_x_2)) == -12.0) || (((x_18 + (-1.0 * _x_x_2)) == -11.0) || (((x_16 + (-1.0 * _x_x_2)) == -15.0) || (((x_15 + (-1.0 * _x_x_2)) == -13.0) || (((x_13 + (-1.0 * _x_x_2)) == -17.0) || (((x_12 + (-1.0 * _x_x_2)) == -10.0) || (((x_7 + (-1.0 * _x_x_2)) == -20.0) || (((x_6 + (-1.0 * _x_x_2)) == -8.0) || (((x_1 + (-1.0 * _x_x_2)) == -5.0) || ((x_3 + (-1.0 * _x_x_2)) == -3.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_3)) <= -13.0) && (((x_22 + (-1.0 * _x_x_3)) <= -6.0) && (((x_20 + (-1.0 * _x_x_3)) <= -1.0) && (((x_17 + (-1.0 * _x_x_3)) <= -2.0) && (((x_16 + (-1.0 * _x_x_3)) <= -10.0) && (((x_15 + (-1.0 * _x_x_3)) <= -13.0) && (((x_12 + (-1.0 * _x_x_3)) <= -4.0) && (((x_11 + (-1.0 * _x_x_3)) <= -8.0) && (((x_9 + (-1.0 * _x_x_3)) <= -9.0) && (((x_6 + (-1.0 * _x_x_3)) <= -3.0) && (((x_2 + (-1.0 * _x_x_3)) <= -10.0) && ((x_3 + (-1.0 * _x_x_3)) <= -11.0)))))))))))) && (((x_23 + (-1.0 * _x_x_3)) == -13.0) || (((x_22 + (-1.0 * _x_x_3)) == -6.0) || (((x_20 + (-1.0 * _x_x_3)) == -1.0) || (((x_17 + (-1.0 * _x_x_3)) == -2.0) || (((x_16 + (-1.0 * _x_x_3)) == -10.0) || (((x_15 + (-1.0 * _x_x_3)) == -13.0) || (((x_12 + (-1.0 * _x_x_3)) == -4.0) || (((x_11 + (-1.0 * _x_x_3)) == -8.0) || (((x_9 + (-1.0 * _x_x_3)) == -9.0) || (((x_6 + (-1.0 * _x_x_3)) == -3.0) || (((x_2 + (-1.0 * _x_x_3)) == -10.0) || ((x_3 + (-1.0 * _x_x_3)) == -11.0)))))))))))))) && ((((x_17 + (-1.0 * _x_x_4)) <= -14.0) && (((x_15 + (-1.0 * _x_x_4)) <= -19.0) && (((x_12 + (-1.0 * _x_x_4)) <= -10.0) && (((x_11 + (-1.0 * _x_x_4)) <= -2.0) && (((x_10 + (-1.0 * _x_x_4)) <= -4.0) && (((x_9 + (-1.0 * _x_x_4)) <= -14.0) && (((x_7 + (-1.0 * _x_x_4)) <= -3.0) && (((x_5 + (-1.0 * _x_x_4)) <= -13.0) && (((x_3 + (-1.0 * _x_x_4)) <= -7.0) && (((x_2 + (-1.0 * _x_x_4)) <= -1.0) && (((x_0 + (-1.0 * _x_x_4)) <= -10.0) && ((x_1 + (-1.0 * _x_x_4)) <= -20.0)))))))))))) && (((x_17 + (-1.0 * _x_x_4)) == -14.0) || (((x_15 + (-1.0 * _x_x_4)) == -19.0) || (((x_12 + (-1.0 * _x_x_4)) == -10.0) || (((x_11 + (-1.0 * _x_x_4)) == -2.0) || (((x_10 + (-1.0 * _x_x_4)) == -4.0) || (((x_9 + (-1.0 * _x_x_4)) == -14.0) || (((x_7 + (-1.0 * _x_x_4)) == -3.0) || (((x_5 + (-1.0 * _x_x_4)) == -13.0) || (((x_3 + (-1.0 * _x_x_4)) == -7.0) || (((x_2 + (-1.0 * _x_x_4)) == -1.0) || (((x_0 + (-1.0 * _x_x_4)) == -10.0) || ((x_1 + (-1.0 * _x_x_4)) == -20.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_5)) <= -6.0) && (((x_20 + (-1.0 * _x_x_5)) <= -16.0) && (((x_16 + (-1.0 * _x_x_5)) <= -7.0) && (((x_13 + (-1.0 * _x_x_5)) <= -2.0) && (((x_11 + (-1.0 * _x_x_5)) <= -20.0) && (((x_10 + (-1.0 * _x_x_5)) <= -18.0) && (((x_8 + (-1.0 * _x_x_5)) <= -20.0) && (((x_7 + (-1.0 * _x_x_5)) <= -18.0) && (((x_5 + (-1.0 * _x_x_5)) <= -2.0) && (((x_4 + (-1.0 * _x_x_5)) <= -15.0) && (((x_0 + (-1.0 * _x_x_5)) <= -9.0) && ((x_3 + (-1.0 * _x_x_5)) <= -11.0)))))))))))) && (((x_21 + (-1.0 * _x_x_5)) == -6.0) || (((x_20 + (-1.0 * _x_x_5)) == -16.0) || (((x_16 + (-1.0 * _x_x_5)) == -7.0) || (((x_13 + (-1.0 * _x_x_5)) == -2.0) || (((x_11 + (-1.0 * _x_x_5)) == -20.0) || (((x_10 + (-1.0 * _x_x_5)) == -18.0) || (((x_8 + (-1.0 * _x_x_5)) == -20.0) || (((x_7 + (-1.0 * _x_x_5)) == -18.0) || (((x_5 + (-1.0 * _x_x_5)) == -2.0) || (((x_4 + (-1.0 * _x_x_5)) == -15.0) || (((x_0 + (-1.0 * _x_x_5)) == -9.0) || ((x_3 + (-1.0 * _x_x_5)) == -11.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_6)) <= -5.0) && (((x_22 + (-1.0 * _x_x_6)) <= -10.0) && (((x_20 + (-1.0 * _x_x_6)) <= -7.0) && (((x_19 + (-1.0 * _x_x_6)) <= -4.0) && (((x_18 + (-1.0 * _x_x_6)) <= -6.0) && (((x_11 + (-1.0 * _x_x_6)) <= -14.0) && (((x_10 + (-1.0 * _x_x_6)) <= -9.0) && (((x_9 + (-1.0 * _x_x_6)) <= -15.0) && (((x_8 + (-1.0 * _x_x_6)) <= -11.0) && (((x_6 + (-1.0 * _x_x_6)) <= -19.0) && (((x_0 + (-1.0 * _x_x_6)) <= -18.0) && ((x_5 + (-1.0 * _x_x_6)) <= -12.0)))))))))))) && (((x_23 + (-1.0 * _x_x_6)) == -5.0) || (((x_22 + (-1.0 * _x_x_6)) == -10.0) || (((x_20 + (-1.0 * _x_x_6)) == -7.0) || (((x_19 + (-1.0 * _x_x_6)) == -4.0) || (((x_18 + (-1.0 * _x_x_6)) == -6.0) || (((x_11 + (-1.0 * _x_x_6)) == -14.0) || (((x_10 + (-1.0 * _x_x_6)) == -9.0) || (((x_9 + (-1.0 * _x_x_6)) == -15.0) || (((x_8 + (-1.0 * _x_x_6)) == -11.0) || (((x_6 + (-1.0 * _x_x_6)) == -19.0) || (((x_0 + (-1.0 * _x_x_6)) == -18.0) || ((x_5 + (-1.0 * _x_x_6)) == -12.0)))))))))))))) && ((((x_22 + (-1.0 * _x_x_7)) <= -5.0) && (((x_18 + (-1.0 * _x_x_7)) <= -17.0) && (((x_14 + (-1.0 * _x_x_7)) <= -4.0) && (((x_13 + (-1.0 * _x_x_7)) <= -4.0) && (((x_12 + (-1.0 * _x_x_7)) <= -1.0) && (((x_11 + (-1.0 * _x_x_7)) <= -8.0) && (((x_7 + (-1.0 * _x_x_7)) <= -10.0) && (((x_6 + (-1.0 * _x_x_7)) <= -1.0) && (((x_5 + (-1.0 * _x_x_7)) <= -6.0) && (((x_4 + (-1.0 * _x_x_7)) <= -1.0) && (((x_2 + (-1.0 * _x_x_7)) <= -2.0) && ((x_3 + (-1.0 * _x_x_7)) <= -10.0)))))))))))) && (((x_22 + (-1.0 * _x_x_7)) == -5.0) || (((x_18 + (-1.0 * _x_x_7)) == -17.0) || (((x_14 + (-1.0 * _x_x_7)) == -4.0) || (((x_13 + (-1.0 * _x_x_7)) == -4.0) || (((x_12 + (-1.0 * _x_x_7)) == -1.0) || (((x_11 + (-1.0 * _x_x_7)) == -8.0) || (((x_7 + (-1.0 * _x_x_7)) == -10.0) || (((x_6 + (-1.0 * _x_x_7)) == -1.0) || (((x_5 + (-1.0 * _x_x_7)) == -6.0) || (((x_4 + (-1.0 * _x_x_7)) == -1.0) || (((x_2 + (-1.0 * _x_x_7)) == -2.0) || ((x_3 + (-1.0 * _x_x_7)) == -10.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_8)) <= -6.0) && (((x_21 + (-1.0 * _x_x_8)) <= -20.0) && (((x_17 + (-1.0 * _x_x_8)) <= -7.0) && (((x_15 + (-1.0 * _x_x_8)) <= -14.0) && (((x_14 + (-1.0 * _x_x_8)) <= -1.0) && (((x_13 + (-1.0 * _x_x_8)) <= -16.0) && (((x_12 + (-1.0 * _x_x_8)) <= -6.0) && (((x_10 + (-1.0 * _x_x_8)) <= -20.0) && (((x_8 + (-1.0 * _x_x_8)) <= -1.0) && (((x_5 + (-1.0 * _x_x_8)) <= -6.0) && (((x_1 + (-1.0 * _x_x_8)) <= -6.0) && ((x_2 + (-1.0 * _x_x_8)) <= -9.0)))))))))))) && (((x_23 + (-1.0 * _x_x_8)) == -6.0) || (((x_21 + (-1.0 * _x_x_8)) == -20.0) || (((x_17 + (-1.0 * _x_x_8)) == -7.0) || (((x_15 + (-1.0 * _x_x_8)) == -14.0) || (((x_14 + (-1.0 * _x_x_8)) == -1.0) || (((x_13 + (-1.0 * _x_x_8)) == -16.0) || (((x_12 + (-1.0 * _x_x_8)) == -6.0) || (((x_10 + (-1.0 * _x_x_8)) == -20.0) || (((x_8 + (-1.0 * _x_x_8)) == -1.0) || (((x_5 + (-1.0 * _x_x_8)) == -6.0) || (((x_1 + (-1.0 * _x_x_8)) == -6.0) || ((x_2 + (-1.0 * _x_x_8)) == -9.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_9)) <= -1.0) && (((x_19 + (-1.0 * _x_x_9)) <= -13.0) && (((x_18 + (-1.0 * _x_x_9)) <= -1.0) && (((x_16 + (-1.0 * _x_x_9)) <= -6.0) && (((x_15 + (-1.0 * _x_x_9)) <= -13.0) && (((x_11 + (-1.0 * _x_x_9)) <= -19.0) && (((x_8 + (-1.0 * _x_x_9)) <= -19.0) && (((x_7 + (-1.0 * _x_x_9)) <= -18.0) && (((x_6 + (-1.0 * _x_x_9)) <= -17.0) && (((x_4 + (-1.0 * _x_x_9)) <= -20.0) && (((x_1 + (-1.0 * _x_x_9)) <= -20.0) && ((x_2 + (-1.0 * _x_x_9)) <= -17.0)))))))))))) && (((x_23 + (-1.0 * _x_x_9)) == -1.0) || (((x_19 + (-1.0 * _x_x_9)) == -13.0) || (((x_18 + (-1.0 * _x_x_9)) == -1.0) || (((x_16 + (-1.0 * _x_x_9)) == -6.0) || (((x_15 + (-1.0 * _x_x_9)) == -13.0) || (((x_11 + (-1.0 * _x_x_9)) == -19.0) || (((x_8 + (-1.0 * _x_x_9)) == -19.0) || (((x_7 + (-1.0 * _x_x_9)) == -18.0) || (((x_6 + (-1.0 * _x_x_9)) == -17.0) || (((x_4 + (-1.0 * _x_x_9)) == -20.0) || (((x_1 + (-1.0 * _x_x_9)) == -20.0) || ((x_2 + (-1.0 * _x_x_9)) == -17.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_10)) <= -7.0) && (((x_22 + (-1.0 * _x_x_10)) <= -17.0) && (((x_19 + (-1.0 * _x_x_10)) <= -6.0) && (((x_18 + (-1.0 * _x_x_10)) <= -18.0) && (((x_17 + (-1.0 * _x_x_10)) <= -13.0) && (((x_16 + (-1.0 * _x_x_10)) <= -9.0) && (((x_15 + (-1.0 * _x_x_10)) <= -13.0) && (((x_12 + (-1.0 * _x_x_10)) <= -20.0) && (((x_8 + (-1.0 * _x_x_10)) <= -3.0) && (((x_5 + (-1.0 * _x_x_10)) <= -16.0) && (((x_2 + (-1.0 * _x_x_10)) <= -10.0) && ((x_4 + (-1.0 * _x_x_10)) <= -13.0)))))))))))) && (((x_23 + (-1.0 * _x_x_10)) == -7.0) || (((x_22 + (-1.0 * _x_x_10)) == -17.0) || (((x_19 + (-1.0 * _x_x_10)) == -6.0) || (((x_18 + (-1.0 * _x_x_10)) == -18.0) || (((x_17 + (-1.0 * _x_x_10)) == -13.0) || (((x_16 + (-1.0 * _x_x_10)) == -9.0) || (((x_15 + (-1.0 * _x_x_10)) == -13.0) || (((x_12 + (-1.0 * _x_x_10)) == -20.0) || (((x_8 + (-1.0 * _x_x_10)) == -3.0) || (((x_5 + (-1.0 * _x_x_10)) == -16.0) || (((x_2 + (-1.0 * _x_x_10)) == -10.0) || ((x_4 + (-1.0 * _x_x_10)) == -13.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_11)) <= -6.0) && (((x_16 + (-1.0 * _x_x_11)) <= -3.0) && (((x_15 + (-1.0 * _x_x_11)) <= -6.0) && (((x_13 + (-1.0 * _x_x_11)) <= -3.0) && (((x_11 + (-1.0 * _x_x_11)) <= -11.0) && (((x_10 + (-1.0 * _x_x_11)) <= -15.0) && (((x_9 + (-1.0 * _x_x_11)) <= -1.0) && (((x_7 + (-1.0 * _x_x_11)) <= -8.0) && (((x_6 + (-1.0 * _x_x_11)) <= -14.0) && (((x_4 + (-1.0 * _x_x_11)) <= -13.0) && (((x_0 + (-1.0 * _x_x_11)) <= -14.0) && ((x_3 + (-1.0 * _x_x_11)) <= -10.0)))))))))))) && (((x_21 + (-1.0 * _x_x_11)) == -6.0) || (((x_16 + (-1.0 * _x_x_11)) == -3.0) || (((x_15 + (-1.0 * _x_x_11)) == -6.0) || (((x_13 + (-1.0 * _x_x_11)) == -3.0) || (((x_11 + (-1.0 * _x_x_11)) == -11.0) || (((x_10 + (-1.0 * _x_x_11)) == -15.0) || (((x_9 + (-1.0 * _x_x_11)) == -1.0) || (((x_7 + (-1.0 * _x_x_11)) == -8.0) || (((x_6 + (-1.0 * _x_x_11)) == -14.0) || (((x_4 + (-1.0 * _x_x_11)) == -13.0) || (((x_0 + (-1.0 * _x_x_11)) == -14.0) || ((x_3 + (-1.0 * _x_x_11)) == -10.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_12)) <= -8.0) && (((x_22 + (-1.0 * _x_x_12)) <= -10.0) && (((x_21 + (-1.0 * _x_x_12)) <= -2.0) && (((x_20 + (-1.0 * _x_x_12)) <= -16.0) && (((x_18 + (-1.0 * _x_x_12)) <= -1.0) && (((x_15 + (-1.0 * _x_x_12)) <= -13.0) && (((x_12 + (-1.0 * _x_x_12)) <= -11.0) && (((x_10 + (-1.0 * _x_x_12)) <= -3.0) && (((x_9 + (-1.0 * _x_x_12)) <= -17.0) && (((x_6 + (-1.0 * _x_x_12)) <= -5.0) && (((x_0 + (-1.0 * _x_x_12)) <= -13.0) && ((x_3 + (-1.0 * _x_x_12)) <= -15.0)))))))))))) && (((x_23 + (-1.0 * _x_x_12)) == -8.0) || (((x_22 + (-1.0 * _x_x_12)) == -10.0) || (((x_21 + (-1.0 * _x_x_12)) == -2.0) || (((x_20 + (-1.0 * _x_x_12)) == -16.0) || (((x_18 + (-1.0 * _x_x_12)) == -1.0) || (((x_15 + (-1.0 * _x_x_12)) == -13.0) || (((x_12 + (-1.0 * _x_x_12)) == -11.0) || (((x_10 + (-1.0 * _x_x_12)) == -3.0) || (((x_9 + (-1.0 * _x_x_12)) == -17.0) || (((x_6 + (-1.0 * _x_x_12)) == -5.0) || (((x_0 + (-1.0 * _x_x_12)) == -13.0) || ((x_3 + (-1.0 * _x_x_12)) == -15.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_13)) <= -11.0) && (((x_20 + (-1.0 * _x_x_13)) <= -4.0) && (((x_17 + (-1.0 * _x_x_13)) <= -8.0) && (((x_15 + (-1.0 * _x_x_13)) <= -8.0) && (((x_14 + (-1.0 * _x_x_13)) <= -18.0) && (((x_11 + (-1.0 * _x_x_13)) <= -13.0) && (((x_8 + (-1.0 * _x_x_13)) <= -11.0) && (((x_7 + (-1.0 * _x_x_13)) <= -13.0) && (((x_6 + (-1.0 * _x_x_13)) <= -1.0) && (((x_5 + (-1.0 * _x_x_13)) <= -12.0) && (((x_1 + (-1.0 * _x_x_13)) <= -16.0) && ((x_4 + (-1.0 * _x_x_13)) <= -5.0)))))))))))) && (((x_23 + (-1.0 * _x_x_13)) == -11.0) || (((x_20 + (-1.0 * _x_x_13)) == -4.0) || (((x_17 + (-1.0 * _x_x_13)) == -8.0) || (((x_15 + (-1.0 * _x_x_13)) == -8.0) || (((x_14 + (-1.0 * _x_x_13)) == -18.0) || (((x_11 + (-1.0 * _x_x_13)) == -13.0) || (((x_8 + (-1.0 * _x_x_13)) == -11.0) || (((x_7 + (-1.0 * _x_x_13)) == -13.0) || (((x_6 + (-1.0 * _x_x_13)) == -1.0) || (((x_5 + (-1.0 * _x_x_13)) == -12.0) || (((x_1 + (-1.0 * _x_x_13)) == -16.0) || ((x_4 + (-1.0 * _x_x_13)) == -5.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_14)) <= -15.0) && (((x_21 + (-1.0 * _x_x_14)) <= -6.0) && (((x_17 + (-1.0 * _x_x_14)) <= -4.0) && (((x_13 + (-1.0 * _x_x_14)) <= -1.0) && (((x_11 + (-1.0 * _x_x_14)) <= -3.0) && (((x_10 + (-1.0 * _x_x_14)) <= -8.0) && (((x_8 + (-1.0 * _x_x_14)) <= -14.0) && (((x_6 + (-1.0 * _x_x_14)) <= -15.0) && (((x_4 + (-1.0 * _x_x_14)) <= -13.0) && (((x_3 + (-1.0 * _x_x_14)) <= -19.0) && (((x_0 + (-1.0 * _x_x_14)) <= -9.0) && ((x_1 + (-1.0 * _x_x_14)) <= -14.0)))))))))))) && (((x_23 + (-1.0 * _x_x_14)) == -15.0) || (((x_21 + (-1.0 * _x_x_14)) == -6.0) || (((x_17 + (-1.0 * _x_x_14)) == -4.0) || (((x_13 + (-1.0 * _x_x_14)) == -1.0) || (((x_11 + (-1.0 * _x_x_14)) == -3.0) || (((x_10 + (-1.0 * _x_x_14)) == -8.0) || (((x_8 + (-1.0 * _x_x_14)) == -14.0) || (((x_6 + (-1.0 * _x_x_14)) == -15.0) || (((x_4 + (-1.0 * _x_x_14)) == -13.0) || (((x_3 + (-1.0 * _x_x_14)) == -19.0) || (((x_0 + (-1.0 * _x_x_14)) == -9.0) || ((x_1 + (-1.0 * _x_x_14)) == -14.0)))))))))))))) && ((((x_22 + (-1.0 * _x_x_15)) <= -3.0) && (((x_21 + (-1.0 * _x_x_15)) <= -20.0) && (((x_20 + (-1.0 * _x_x_15)) <= -4.0) && (((x_19 + (-1.0 * _x_x_15)) <= -6.0) && (((x_18 + (-1.0 * _x_x_15)) <= -14.0) && (((x_17 + (-1.0 * _x_x_15)) <= -2.0) && (((x_14 + (-1.0 * _x_x_15)) <= -16.0) && (((x_13 + (-1.0 * _x_x_15)) <= -6.0) && (((x_12 + (-1.0 * _x_x_15)) <= -4.0) && (((x_10 + (-1.0 * _x_x_15)) <= -16.0) && (((x_1 + (-1.0 * _x_x_15)) <= -3.0) && ((x_5 + (-1.0 * _x_x_15)) <= -1.0)))))))))))) && (((x_22 + (-1.0 * _x_x_15)) == -3.0) || (((x_21 + (-1.0 * _x_x_15)) == -20.0) || (((x_20 + (-1.0 * _x_x_15)) == -4.0) || (((x_19 + (-1.0 * _x_x_15)) == -6.0) || (((x_18 + (-1.0 * _x_x_15)) == -14.0) || (((x_17 + (-1.0 * _x_x_15)) == -2.0) || (((x_14 + (-1.0 * _x_x_15)) == -16.0) || (((x_13 + (-1.0 * _x_x_15)) == -6.0) || (((x_12 + (-1.0 * _x_x_15)) == -4.0) || (((x_10 + (-1.0 * _x_x_15)) == -16.0) || (((x_1 + (-1.0 * _x_x_15)) == -3.0) || ((x_5 + (-1.0 * _x_x_15)) == -1.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_16)) <= -13.0) && (((x_22 + (-1.0 * _x_x_16)) <= -13.0) && (((x_21 + (-1.0 * _x_x_16)) <= -11.0) && (((x_20 + (-1.0 * _x_x_16)) <= -6.0) && (((x_16 + (-1.0 * _x_x_16)) <= -6.0) && (((x_10 + (-1.0 * _x_x_16)) <= -8.0) && (((x_9 + (-1.0 * _x_x_16)) <= -10.0) && (((x_8 + (-1.0 * _x_x_16)) <= -15.0) && (((x_4 + (-1.0 * _x_x_16)) <= -1.0) && (((x_3 + (-1.0 * _x_x_16)) <= -14.0) && (((x_1 + (-1.0 * _x_x_16)) <= -10.0) && ((x_2 + (-1.0 * _x_x_16)) <= -12.0)))))))))))) && (((x_23 + (-1.0 * _x_x_16)) == -13.0) || (((x_22 + (-1.0 * _x_x_16)) == -13.0) || (((x_21 + (-1.0 * _x_x_16)) == -11.0) || (((x_20 + (-1.0 * _x_x_16)) == -6.0) || (((x_16 + (-1.0 * _x_x_16)) == -6.0) || (((x_10 + (-1.0 * _x_x_16)) == -8.0) || (((x_9 + (-1.0 * _x_x_16)) == -10.0) || (((x_8 + (-1.0 * _x_x_16)) == -15.0) || (((x_4 + (-1.0 * _x_x_16)) == -1.0) || (((x_3 + (-1.0 * _x_x_16)) == -14.0) || (((x_1 + (-1.0 * _x_x_16)) == -10.0) || ((x_2 + (-1.0 * _x_x_16)) == -12.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_17)) <= -8.0) && (((x_20 + (-1.0 * _x_x_17)) <= -8.0) && (((x_14 + (-1.0 * _x_x_17)) <= -8.0) && (((x_11 + (-1.0 * _x_x_17)) <= -8.0) && (((x_9 + (-1.0 * _x_x_17)) <= -1.0) && (((x_8 + (-1.0 * _x_x_17)) <= -3.0) && (((x_7 + (-1.0 * _x_x_17)) <= -4.0) && (((x_6 + (-1.0 * _x_x_17)) <= -5.0) && (((x_5 + (-1.0 * _x_x_17)) <= -4.0) && (((x_4 + (-1.0 * _x_x_17)) <= -13.0) && (((x_1 + (-1.0 * _x_x_17)) <= -11.0) && ((x_2 + (-1.0 * _x_x_17)) <= -6.0)))))))))))) && (((x_21 + (-1.0 * _x_x_17)) == -8.0) || (((x_20 + (-1.0 * _x_x_17)) == -8.0) || (((x_14 + (-1.0 * _x_x_17)) == -8.0) || (((x_11 + (-1.0 * _x_x_17)) == -8.0) || (((x_9 + (-1.0 * _x_x_17)) == -1.0) || (((x_8 + (-1.0 * _x_x_17)) == -3.0) || (((x_7 + (-1.0 * _x_x_17)) == -4.0) || (((x_6 + (-1.0 * _x_x_17)) == -5.0) || (((x_5 + (-1.0 * _x_x_17)) == -4.0) || (((x_4 + (-1.0 * _x_x_17)) == -13.0) || (((x_1 + (-1.0 * _x_x_17)) == -11.0) || ((x_2 + (-1.0 * _x_x_17)) == -6.0)))))))))))))) && ((((x_19 + (-1.0 * _x_x_18)) <= -18.0) && (((x_18 + (-1.0 * _x_x_18)) <= -14.0) && (((x_16 + (-1.0 * _x_x_18)) <= -1.0) && (((x_15 + (-1.0 * _x_x_18)) <= -13.0) && (((x_13 + (-1.0 * _x_x_18)) <= -17.0) && (((x_12 + (-1.0 * _x_x_18)) <= -20.0) && (((x_11 + (-1.0 * _x_x_18)) <= -6.0) && (((x_6 + (-1.0 * _x_x_18)) <= -16.0) && (((x_5 + (-1.0 * _x_x_18)) <= -8.0) && (((x_4 + (-1.0 * _x_x_18)) <= -2.0) && (((x_1 + (-1.0 * _x_x_18)) <= -6.0) && ((x_2 + (-1.0 * _x_x_18)) <= -5.0)))))))))))) && (((x_19 + (-1.0 * _x_x_18)) == -18.0) || (((x_18 + (-1.0 * _x_x_18)) == -14.0) || (((x_16 + (-1.0 * _x_x_18)) == -1.0) || (((x_15 + (-1.0 * _x_x_18)) == -13.0) || (((x_13 + (-1.0 * _x_x_18)) == -17.0) || (((x_12 + (-1.0 * _x_x_18)) == -20.0) || (((x_11 + (-1.0 * _x_x_18)) == -6.0) || (((x_6 + (-1.0 * _x_x_18)) == -16.0) || (((x_5 + (-1.0 * _x_x_18)) == -8.0) || (((x_4 + (-1.0 * _x_x_18)) == -2.0) || (((x_1 + (-1.0 * _x_x_18)) == -6.0) || ((x_2 + (-1.0 * _x_x_18)) == -5.0)))))))))))))) && ((((x_21 + (-1.0 * _x_x_19)) <= -8.0) && (((x_20 + (-1.0 * _x_x_19)) <= -11.0) && (((x_18 + (-1.0 * _x_x_19)) <= -4.0) && (((x_17 + (-1.0 * _x_x_19)) <= -10.0) && (((x_9 + (-1.0 * _x_x_19)) <= -14.0) && (((x_8 + (-1.0 * _x_x_19)) <= -9.0) && (((x_7 + (-1.0 * _x_x_19)) <= -4.0) && (((x_6 + (-1.0 * _x_x_19)) <= -7.0) && (((x_5 + (-1.0 * _x_x_19)) <= -20.0) && (((x_4 + (-1.0 * _x_x_19)) <= -3.0) && (((x_0 + (-1.0 * _x_x_19)) <= -19.0) && ((x_1 + (-1.0 * _x_x_19)) <= -9.0)))))))))))) && (((x_21 + (-1.0 * _x_x_19)) == -8.0) || (((x_20 + (-1.0 * _x_x_19)) == -11.0) || (((x_18 + (-1.0 * _x_x_19)) == -4.0) || (((x_17 + (-1.0 * _x_x_19)) == -10.0) || (((x_9 + (-1.0 * _x_x_19)) == -14.0) || (((x_8 + (-1.0 * _x_x_19)) == -9.0) || (((x_7 + (-1.0 * _x_x_19)) == -4.0) || (((x_6 + (-1.0 * _x_x_19)) == -7.0) || (((x_5 + (-1.0 * _x_x_19)) == -20.0) || (((x_4 + (-1.0 * _x_x_19)) == -3.0) || (((x_0 + (-1.0 * _x_x_19)) == -19.0) || ((x_1 + (-1.0 * _x_x_19)) == -9.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_20)) <= -5.0) && (((x_22 + (-1.0 * _x_x_20)) <= -10.0) && (((x_21 + (-1.0 * _x_x_20)) <= -15.0) && (((x_18 + (-1.0 * _x_x_20)) <= -6.0) && (((x_15 + (-1.0 * _x_x_20)) <= -14.0) && (((x_14 + (-1.0 * _x_x_20)) <= -17.0) && (((x_8 + (-1.0 * _x_x_20)) <= -20.0) && (((x_5 + (-1.0 * _x_x_20)) <= -15.0) && (((x_4 + (-1.0 * _x_x_20)) <= -9.0) && (((x_2 + (-1.0 * _x_x_20)) <= -7.0) && (((x_0 + (-1.0 * _x_x_20)) <= -19.0) && ((x_1 + (-1.0 * _x_x_20)) <= -11.0)))))))))))) && (((x_23 + (-1.0 * _x_x_20)) == -5.0) || (((x_22 + (-1.0 * _x_x_20)) == -10.0) || (((x_21 + (-1.0 * _x_x_20)) == -15.0) || (((x_18 + (-1.0 * _x_x_20)) == -6.0) || (((x_15 + (-1.0 * _x_x_20)) == -14.0) || (((x_14 + (-1.0 * _x_x_20)) == -17.0) || (((x_8 + (-1.0 * _x_x_20)) == -20.0) || (((x_5 + (-1.0 * _x_x_20)) == -15.0) || (((x_4 + (-1.0 * _x_x_20)) == -9.0) || (((x_2 + (-1.0 * _x_x_20)) == -7.0) || (((x_0 + (-1.0 * _x_x_20)) == -19.0) || ((x_1 + (-1.0 * _x_x_20)) == -11.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_21)) <= -16.0) && (((x_19 + (-1.0 * _x_x_21)) <= -16.0) && (((x_18 + (-1.0 * _x_x_21)) <= -15.0) && (((x_17 + (-1.0 * _x_x_21)) <= -17.0) && (((x_15 + (-1.0 * _x_x_21)) <= -1.0) && (((x_14 + (-1.0 * _x_x_21)) <= -2.0) && (((x_12 + (-1.0 * _x_x_21)) <= -1.0) && (((x_11 + (-1.0 * _x_x_21)) <= -1.0) && (((x_9 + (-1.0 * _x_x_21)) <= -15.0) && (((x_5 + (-1.0 * _x_x_21)) <= -4.0) && (((x_1 + (-1.0 * _x_x_21)) <= -11.0) && ((x_4 + (-1.0 * _x_x_21)) <= -9.0)))))))))))) && (((x_23 + (-1.0 * _x_x_21)) == -16.0) || (((x_19 + (-1.0 * _x_x_21)) == -16.0) || (((x_18 + (-1.0 * _x_x_21)) == -15.0) || (((x_17 + (-1.0 * _x_x_21)) == -17.0) || (((x_15 + (-1.0 * _x_x_21)) == -1.0) || (((x_14 + (-1.0 * _x_x_21)) == -2.0) || (((x_12 + (-1.0 * _x_x_21)) == -1.0) || (((x_11 + (-1.0 * _x_x_21)) == -1.0) || (((x_9 + (-1.0 * _x_x_21)) == -15.0) || (((x_5 + (-1.0 * _x_x_21)) == -4.0) || (((x_1 + (-1.0 * _x_x_21)) == -11.0) || ((x_4 + (-1.0 * _x_x_21)) == -9.0)))))))))))))) && ((((x_19 + (-1.0 * _x_x_22)) <= -20.0) && (((x_16 + (-1.0 * _x_x_22)) <= -18.0) && (((x_13 + (-1.0 * _x_x_22)) <= -19.0) && (((x_10 + (-1.0 * _x_x_22)) <= -5.0) && (((x_8 + (-1.0 * _x_x_22)) <= -18.0) && (((x_7 + (-1.0 * _x_x_22)) <= -7.0) && (((x_6 + (-1.0 * _x_x_22)) <= -17.0) && (((x_5 + (-1.0 * _x_x_22)) <= -11.0) && (((x_4 + (-1.0 * _x_x_22)) <= -9.0) && (((x_3 + (-1.0 * _x_x_22)) <= -2.0) && (((x_1 + (-1.0 * _x_x_22)) <= -3.0) && ((x_2 + (-1.0 * _x_x_22)) <= -18.0)))))))))))) && (((x_19 + (-1.0 * _x_x_22)) == -20.0) || (((x_16 + (-1.0 * _x_x_22)) == -18.0) || (((x_13 + (-1.0 * _x_x_22)) == -19.0) || (((x_10 + (-1.0 * _x_x_22)) == -5.0) || (((x_8 + (-1.0 * _x_x_22)) == -18.0) || (((x_7 + (-1.0 * _x_x_22)) == -7.0) || (((x_6 + (-1.0 * _x_x_22)) == -17.0) || (((x_5 + (-1.0 * _x_x_22)) == -11.0) || (((x_4 + (-1.0 * _x_x_22)) == -9.0) || (((x_3 + (-1.0 * _x_x_22)) == -2.0) || (((x_1 + (-1.0 * _x_x_22)) == -3.0) || ((x_2 + (-1.0 * _x_x_22)) == -18.0)))))))))))))) && ((((x_23 + (-1.0 * _x_x_23)) <= -17.0) && (((x_21 + (-1.0 * _x_x_23)) <= -1.0) && (((x_20 + (-1.0 * _x_x_23)) <= -10.0) && (((x_19 + (-1.0 * _x_x_23)) <= -18.0) && (((x_13 + (-1.0 * _x_x_23)) <= -8.0) && (((x_11 + (-1.0 * _x_x_23)) <= -15.0) && (((x_8 + (-1.0 * _x_x_23)) <= -14.0) && (((x_6 + (-1.0 * _x_x_23)) <= -18.0) && (((x_5 + (-1.0 * _x_x_23)) <= -4.0) && (((x_4 + (-1.0 * _x_x_23)) <= -16.0) && (((x_2 + (-1.0 * _x_x_23)) <= -5.0) && ((x_3 + (-1.0 * _x_x_23)) <= -18.0)))))))))))) && (((x_23 + (-1.0 * _x_x_23)) == -17.0) || (((x_21 + (-1.0 * _x_x_23)) == -1.0) || (((x_20 + (-1.0 * _x_x_23)) == -10.0) || (((x_19 + (-1.0 * _x_x_23)) == -18.0) || (((x_13 + (-1.0 * _x_x_23)) == -8.0) || (((x_11 + (-1.0 * _x_x_23)) == -15.0) || (((x_8 + (-1.0 * _x_x_23)) == -14.0) || (((x_6 + (-1.0 * _x_x_23)) == -18.0) || (((x_5 + (-1.0 * _x_x_23)) == -4.0) || (((x_4 + (-1.0 * _x_x_23)) == -16.0) || (((x_2 + (-1.0 * _x_x_23)) == -5.0) || ((x_3 + (-1.0 * _x_x_23)) == -18.0)))))))))))))) && (((((_EL_U_1785 == (_x__EL_U_1785 || ( !(_x__EL_U_1783 || ( !(_x__EL_U_1781 || _x__EL_X_1776)))))) && ((_EL_U_1783 == (_x__EL_U_1783 || ( !(_x__EL_U_1781 || _x__EL_X_1776)))) && ((_EL_X_1776 == ((_x_x_4 + (-1.0 * _x_x_21)) <= -18.0)) && (_EL_U_1781 == (_x__EL_U_1781 || _x__EL_X_1776))))) && (_x__J1805 == (( !((_J1805 && _J1811) && _J1817)) && (((_J1805 && _J1811) && _J1817) || ((_EL_X_1776 || ( !(_EL_X_1776 || _EL_U_1781))) || _J1805))))) && (_x__J1811 == (( !((_J1805 && _J1811) && _J1817)) && (((_J1805 && _J1811) && _J1817) || ((( !(_EL_X_1776 || _EL_U_1781)) || ( !(_EL_U_1783 || ( !(_EL_X_1776 || _EL_U_1781))))) || _J1811))))) && (_x__J1817 == (( !((_J1805 && _J1811) && _J1817)) && (((_J1805 && _J1811) && _J1817) || ((( !(_EL_U_1783 || ( !(_EL_X_1776 || _EL_U_1781)))) || ( !(_EL_U_1785 || ( !(_EL_U_1783 || ( !(_EL_X_1776 || _EL_U_1781))))))) || _J1817)))))); _J1817 = _x__J1817; _J1811 = _x__J1811; _J1805 = _x__J1805; _EL_U_1781 = _x__EL_U_1781; _EL_X_1776 = _x__EL_X_1776; x_0 = _x_x_0; _EL_U_1783 = _x__EL_U_1783; _EL_U_1785 = _x__EL_U_1785; x_7 = _x_x_7; x_10 = _x_x_10; x_3 = _x_x_3; x_2 = _x_x_2; x_16 = _x_x_16; x_4 = _x_x_4; x_22 = _x_x_22; x_5 = _x_x_5; x_6 = _x_x_6; x_8 = _x_x_8; x_11 = _x_x_11; x_13 = _x_x_13; x_19 = _x_x_19; x_20 = _x_x_20; x_9 = _x_x_9; x_21 = _x_x_21; x_12 = _x_x_12; x_23 = _x_x_23; x_14 = _x_x_14; x_15 = _x_x_15; x_17 = _x_x_17; x_18 = _x_x_18; x_1 = _x_x_1; } }
the_stack_data/42326.c
// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-pc-linux-gnu %s // CC qualifier can be applied only to functions int __attribute__((stdcall)) var1; // expected-warning{{'stdcall' only applies to function types; type here is 'int'}} int __attribute__((fastcall)) var2; // expected-warning{{'fastcall' only applies to function types; type here is 'int'}} // Different CC qualifiers are not compatible void __attribute__((stdcall, fastcall)) foo3(void); // expected-warning{{'stdcall' calling convention is not supported for this target}} expected-warning {{'fastcall' calling convention is not supported for this target}} void __attribute__((stdcall)) foo4(); // expected-warning{{'stdcall' calling convention is not supported for this target}} void __attribute__((fastcall)) foo4(void); // expected-warning {{'fastcall' calling convention is not supported for this target}} // rdar://8876096 void rdar8876096foo1(int i, int j) __attribute__((fastcall, cdecl)); // expected-warning{{'fastcall' calling convention is not supported for this target}} void rdar8876096foo2(int i, int j) __attribute__((fastcall, stdcall)); // expected-warning{{'stdcall' calling convention is not supported for this target}} expected-warning {{'fastcall' calling convention is not supported for this target}} void rdar8876096foo3(int i, int j) __attribute__((fastcall, regparm(2))); // expected-warning {{'fastcall' calling convention is not supported for this target}} void rdar8876096foo4(int i, int j) __attribute__((stdcall, cdecl)); // expected-warning{{'stdcall' calling convention is not supported for this target}} void rdar8876096foo5(int i, int j) __attribute__((stdcall, fastcall)); // expected-warning{{'stdcall' calling convention is not supported for this target}} expected-warning {{'fastcall' calling convention is not supported for this target}} void rdar8876096foo6(int i, int j) __attribute__((cdecl, fastcall)); // expected-warning {{'fastcall' calling convention is not supported for this target}} void rdar8876096foo7(int i, int j) __attribute__((cdecl, stdcall)); // expected-warning{{'stdcall' calling convention is not supported for this target}} void rdar8876096foo8(int i, int j) __attribute__((regparm(2), fastcall)); // expected-warning {{'fastcall' calling convention is not supported for this target}}
the_stack_data/159514883.c
#include <stdio.h> #include <stdbool.h> int equal(int h1, int h2, int h3); struct{ int a[100001]; }stack[3]; int main() { int n1, n2, n3, i; int h1=0, h2=0, h3=0; //printf("ENTER SIZE OF THE CYLINDER: \n"); scanf("%d %d %d", &n1, &n2, &n3); //printf("ENTER 1 CYLINDER: \n"); for(i=0; i<n1; i++){ scanf("%d", &stack[0].a[i]); h1 += stack[0].a[i]; } //printf("ENTER 2 CYLINDER: \n"); for(i=0; i<n2; i++){ scanf("%d", &stack[1].a[i]); h2 += stack[1].a[i]; } //printf("ENTER 3 CYLINDER: \n"); for(i=0; i<n3; i++){ scanf("%d", &stack[2].a[i]); h3 += stack[2].a[i]; } printf("%d", equal(h1, h2, h3)); return 0; } int equal(int h1, int h2, int h3) { int i=0, j=0, k=0; while(true){ if((h1 == h2)&&(h1 == h3)) break; if(h1>=h2 && h1 >= h3){ h1 -= stack[0].a[i]; i++;} else if(h2>=h1&&h2>=h3){h2 -= stack[1].a[j]; j++;} else if(h3>=h1&&h3>=h2){h3-= stack[2].a[k]; k++;} } return h1; }
the_stack_data/72012239.c
//refer to http://www.binarytides.com/socket-programming-c-linux-tutorial/ #include <stdio.h> #include <string.h> //strlen #include <sys/socket.h> #include <arpa/inet.h> //inet_addr #include <unistd.h> //write int main(int argc, char *argv[]) { int socket_desc, new_socket, c; struct sockaddr_in server, client; char message[100]; //Create socket socket_desc = socket(AF_INET, SOCK_STREAM, 0); if (socket_desc == -1) { printf("Could not create socket"); } //Prepare the sockaddr_in structure server.sin_family = AF_INET; server.sin_addr.s_addr = INADDR_ANY; server.sin_port = htons(8888); //server function: bind, listen , accept //Bind /* int bind(int sockfd, struct sockaddr *my_addr, int addrlen); return: 0 if ok, -1 on error associate the server's socket address with the socket descriptor question: why we don't need the bind operation for the client? what is the socket address for the client? */ if (bind(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) { puts("bind failed"); return 1; } puts("bind done"); //Listen /* server are passive entities that wait for connection requests from the client a server call the listen to label that descriptor will be used by a server instead of the client listen function convert sockfd from active socket to a listening socket that can recieve the requests from the clients the backlog parameters is sth realte to the detail of TCP/IP , we set it to a default value here int listen (int sockfd, int backlog) return 0 if ok -1 on error */ listen(socket_desc, 1024); //Accept and incoming connection puts("Waiting for incoming connections..."); c = sizeof(struct sockaddr_in); /* int accept(int listenfd, struct sockaddr* addr, int *addrlen) return: nonnegative connected descriptor if ok, -1 on error The accept function waits for a connection request from a client to arrive on the listening descriptor listenfd then fill in the clients's socket address in addr, and return a connected descriptor that can be used to communicate with client using I/O funciton IO multiplexing block -> select -> poll -> epoll ? */ int i = 0; while (1) { new_socket = accept(socket_desc, (struct sockaddr *)&client, (socklen_t *)&c); if (new_socket < 0) { perror("accept failed"); return 1; } puts("Connection accepted"); //Reply to the client i++; sprintf(message, "Hello Client , I have received your connection %d times\n", i); printf("src (%s) \n"); printf("processing numer (%d) request\n", i); sleep(5); // without using http protocol , only one action for any request write(new_socket, message, strlen(message)); //shutdown(new_socket); sleep(1); close(new_socket); if (i == 5) { break; } } return 0; }
the_stack_data/154453.c
/* File: * pth_tokenize.c * * Purpose: * Try to use threads to tokenize text input. Illustrate problems * with function that isn't threadsafe. * * Warning: * This program definitely has problems. * * Input: * Lines of text * Output: * For each line of input: * the line read by the program, and the tokens identified by * strtok * * Compile: * gcc -g -Wall -o pth_tokenize pth_tokenize.c -lpthread * Usage: * pth_tokenize <thread_count> < <input> * * Algorithm: * For each line of input, next thread reads the line and * "tokenizes" it. * * IPP: Section 4.11 (pp. 195 and ff.) */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <semaphore.h> const int MAX = 1000; int thread_count; sem_t* sems; void Usage(char* prog_name); void *Tokenize(void* rank); /* Thread function */ /*--------------------------------------------------------------------*/ int main(int argc, char* argv[]) { long thread; pthread_t* thread_handles; if (argc != 2) Usage(argv[0]); thread_count = atoi(argv[1]); thread_handles = (pthread_t*) malloc (thread_count*sizeof(pthread_t)); sems = (sem_t*) malloc(thread_count*sizeof(sem_t)); // sems[0] should be unlocked, the others should be locked sem_init(&sems[0], 0, 1); for (thread = 1; thread < thread_count; thread++) sem_init(&sems[thread], 0, 0); printf("Enter text\n"); for (thread = 0; thread < thread_count; thread++) pthread_create(&thread_handles[thread], (pthread_attr_t*) NULL, Tokenize, (void*) thread); for (thread = 0; thread < thread_count; thread++) { pthread_join(thread_handles[thread], NULL); } for (thread=0; thread < thread_count; thread++) sem_destroy(&sems[thread]); free(sems); free(thread_handles); return 0; } /* main */ /*-------------------------------------------------------------------- * Function: Usage * Purpose: Print command line for function and terminate * In arg: prog_name */ void Usage(char* prog_name) { fprintf(stderr, "usage: %s <number of threads>\n", prog_name); exit(0); } /* Usage */ /*------------------------------------------------------------------- * Function: Tokenize * Purpose: Tokenize lines of input * In arg: rank * Global vars: thread_count (in), sems (in/out) * Return val: Ignored */ void *Tokenize(void* rank) { long my_rank = (long) rank; int count; int next = (my_rank + 1) % thread_count; char *fg_rv; char my_line[MAX]; char *my_string; /* Force sequential reading of the input */ sem_wait(&sems[my_rank]); fg_rv = fgets(my_line, MAX, stdin); sem_post(&sems[next]); while (fg_rv != NULL) { printf("Thread %ld > my line = %s", my_rank, my_line); count = 0; my_string = strtok(my_line, " \t\n"); while ( my_string != NULL ) { count++; printf("Thread %ld > string %d = %s\n", my_rank, count, my_string); my_string = strtok(NULL, " \t\n"); } if (my_line != NULL) printf("Thread %ld > After tokenizing, my_line = %s\n", my_rank, my_line); sem_wait(&sems[my_rank]); fg_rv = fgets(my_line, MAX, stdin); sem_post(&sems[next]); } return NULL; } /* Tokenize */
the_stack_data/35828.c
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <sys/ipc.h> #include <sys/shm.h> #include <time.h> #define LOG_CAP (192 * 1024 * 1024) // 256 M log #define LOG_CAP_ ((192 * 1024 * 1024) - 1) // 256 M log #define CPE(val, msg, err_code) \ if(val) { fprintf(stderr, msg); fprintf(stderr, " Error %d \n", err_code); \ exit(err_code);} double cpu_run(long long *log) { int i; long long sum = 0; /**< Touch one cacheline at a time */ int step = (int) (64 / sizeof(long long)); struct timespec start, end; clock_gettime(CLOCK_REALTIME, &start); for(i = 0; i < LOG_CAP; i += step) { sum += log[i]; } clock_gettime(CLOCK_REALTIME, &end); printf("cpu_run: sum = %lld\n", sum); double time = (double) (end.tv_nsec - start.tv_nsec) / 1000000000 + (end.tv_sec - start.tv_sec); return time; } int main(int argc, char *argv[]) { int i; long long *log; srand(time(NULL)); unsigned long log_bytes = LOG_CAP * sizeof(long long); printf("Creating log of size %lu bytes\n", log_bytes); log = (long long *) malloc(log_bytes); assert(log != NULL); for(i = 0; i < LOG_CAP; i ++) { log[i] = i; } double cpu_time; while(1) { cpu_time = cpu_run(log); printf("CPU: time = %f, %.2f GB/s\n", cpu_time, (log_bytes) / (cpu_time * 1000000000)); } free(log); return 0; }
the_stack_data/949772.c
#include <stdbool.h> bool isPowerOfTwoNaive(int n){ if (n < 1) return false; while(n != 1) { if (n % 2 != 0) return false; n /= 2; } return true; } bool isPowerOfTwoBit(int n) { if (n < 1) return false; if ((n & (n - 1)) == 0) return true; else return false; }
the_stack_data/43888543.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <time.h> #define MAX 100 void converteTXT(char fname[30]){ int i; for(i=0;i<strlen(fname);i++) if(fname[i]==' ') fname[i]='_'; strcat(fname,".txt"); } void criaArquivo(char nome[40]){ FILE *f=fopen(nome,"w"); fclose(f); } int main() { FILE *f1, *f2; f1=fopen("matriz.txt","r"); if(f1==NULL){ criaArquivo("matrix.txt"); fclose(f1); f1=fopen("matriz.txt","r"); } f2=fopen("matriz_saida.txt","w"); if(f2==NULL){ criaArquivo("matriz_saida.txt"); fclose(f2); f2=fopen("matriz_saida.txt","w"); } int i, j, pos=0, m, n, anula, a, b, v[MAX][MAX]; char c; do{//le o numero de linhas, colunas e quantas posicoes serao anuladas c=fgetc(f1); if(c!=EOF && isdigit(c)){ if(pos==0) m=c-'0'; else if(pos==1) n=c-'0'; else if(pos==2) anula=c-'0'; pos++; } }while(pos<3); for(i=0;i<m;i++)//inicializacao do vetor for(j=0;j<n;j++) v[i][j]=1; pos=0; do{//anula as posicoes no vetor c=fgetc(f1); if(c!=EOF && isdigit(c)){ if(pos==0) a=c-'0'; else if(pos==1) b=c-'0'; pos++; if(pos==2){ pos=0; v[a][b]=0; } } }while(c!=EOF); for(i=0;i<m;i++){ for(j=0;j<n;j++){ fprintf(f2, "%d", v[i][j]); if(j<n-1) fprintf(f2, " "); } if(i<m-1) fprintf(f2, "\n"); } fclose(f1); fclose(f2); return 0; system("PAUSE"); }
the_stack_data/22013711.c
float A[1024][1024]; float B[1024][1024]; float C[1024][1024]; float AA[1024][1024]; float BB[1024][1024]; float CC[1024][1024]; float alpha = 1.1; float beta = 1.1; int main(void) { #pragma scop for (int i = 0; i < 1024; i++) for (int j = 0; j < 1024; j+=2) // note stride. { C[i][j] *= beta; for (int k = 0; k < 1024; ++k) C[i][j] += alpha * A[i][k] * B[k][j]; } #pragma endscop /* #pragma scop for (int i = 0; i < 1024; i++) for (int j = 0; j < 1024; j++) { for (int k = 0; k < 1024; ++k) C[i][j] += alpha * A[i][k] * B[k][j]; } #pragma endscop */ /* #pragma scop for (int i = 0; i < 1024; i++) for (int j = 0; j < 1024; j++) C[i][j] *= beta; for (int i = 0; i < 1024; ++i) for (int k = 0; k < 1024; k++) for (int j = 0; j < 1024; j++) C[i][j] += alpha * A[i][k] * B[k][j]; for (int i = 0; i < 1024; i++) for (int j = 0; j < 1024; j++) CC[i][j] *= beta; for (int i = 0; i < 1024; ++i) for (int k = 0; k < 1024; k++) for (int j = 0; j < 1024; j++) CC[i][j] += alpha * AA[i][k] * BB[k][j]; #pragma endscop */ return 0; }
the_stack_data/7950966.c
/* PR middle-end/80100 */ /* { dg-do compile } */ /* { dg-options "-O2" } */ long int foo (long int x) { return 2L | ((x - 1L) >> (__SIZEOF_LONG__ * __CHAR_BIT__ - 1)); }
the_stack_data/48451.c
#include <stdio.h> #include <locale.h> int main() { setlocale(LC_ALL, "Portuguese"); int ddd; printf("Informe o DDD: "); scanf("%i", &ddd); fflush(stdin); switch (ddd) { case 61: printf("DDD %i, Brasilia", ddd); break; case 71: printf("DDD %i, Salvador", ddd); break; case 11: printf("DDD %i, Sao Paulo", ddd); break; case 21: printf("DDD %i, Rio de Janeiro", ddd); break; case 32: printf("DDD %i, Juiz de Fora", ddd); break; case 19: printf("DDD %i, Campinas", ddd); break; case 27: printf("DDD %i, Vitoria", ddd); break; case 31: printf("DDD %i, Belo Horizonte", ddd); break; default: printf("DDD %i, Invalido", ddd); } return 0; }
the_stack_data/234518875.c
#include <stdio.h> #include <stdlib.h> #include <ctype.h> int main(int argc, char* argv[]) { char *end, *start = "100.00 alicates 200.00 martelos"; end = start; while(*start){ printf("%.0f, ", strtod(start, &end)); printf("Restante: %s\n", end); start = end; while(!isdigit(*start) && *start) start++; } putchar('\n'); exit(EXIT_SUCCESS); }
the_stack_data/22012499.c
/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2011 Nexenta Systems, Inc. All rights reserved. */ /* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ extern void __vatanf(int, float *, int, float *, int); #pragma weak vatanf_ = __vatanf_ /* just invoke the serial function */ void __vatanf_(int *n, float *x, int *stridex, float *y, int *stridey) { __vatanf(*n, x, *stridex, y, *stridey); }
the_stack_data/141268.c
/* PR tree-optimization/59643 */ /* { dg-do compile } */ /* { dg-options "-O3 -fdump-tree-pcom-details" } */ void foo (double *a, double *b, double *c, double d, double e, int n) { int i; for (i = 1; i < n - 1; i++) a[i] = d * (b[i] + c[i] + a[i - 1] + a[i + 1]) + e * a[i]; } /* { dg-final { scan-tree-dump-times "Before commoning:" 1 "pcom" } } */ /* { dg-final { scan-tree-dump-times "Unrolling 2 times" 1 "pcom" } } */
the_stack_data/1029080.c
/* f2c.h -- Standard Fortran to C header file */ /** barf [ba:rf] 2. "He suggested using FORTRAN, and everybody barfed." - From The Shogakukan DICTIONARY OF NEW ENGLISH (Second edition) */ #ifndef F2C_INCLUDE #define F2C_INCLUDE #include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conj(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimag(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static doublereal c_b3 = 1.; static integer c__1 = 1; static doublereal c_b19 = -1.; /* > \brief \b DLAORHR_COL_GETRFNP2 */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download DLAORHR_GETRF2NP + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlaorhr _col_getrfnp2.f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlaorhr _col_getrfnp2.f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlaorhr _col_getrfnp2.f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE DLAORHR_COL_GETRFNP2( M, N, A, LDA, D, INFO ) */ /* INTEGER INFO, LDA, M, N */ /* DOUBLE PRECISION A( LDA, * ), D( * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > DLAORHR_COL_GETRFNP2 computes the modified LU factorization without */ /* > pivoting of a real general M-by-N matrix A. The factorization has */ /* > the form: */ /* > */ /* > A - S = L * U, */ /* > */ /* > where: */ /* > S is a m-by-n diagonal sign matrix with the diagonal D, so that */ /* > D(i) = S(i,i), 1 <= i <= f2cmin(M,N). The diagonal D is constructed */ /* > as D(i)=-SIGN(A(i,i)), where A(i,i) is the value after performing */ /* > i-1 steps of Gaussian elimination. This means that the diagonal */ /* > element at each step of "modified" Gaussian elimination is at */ /* > least one in absolute value (so that division-by-zero not */ /* > possible during the division by the diagonal element); */ /* > */ /* > L is a M-by-N lower triangular matrix with unit diagonal elements */ /* > (lower trapezoidal if M > N); */ /* > */ /* > and U is a M-by-N upper triangular matrix */ /* > (upper trapezoidal if M < N). */ /* > */ /* > This routine is an auxiliary routine used in the Householder */ /* > reconstruction routine DORHR_COL. In DORHR_COL, this routine is */ /* > applied to an M-by-N matrix A with orthonormal columns, where each */ /* > element is bounded by one in absolute value. With the choice of */ /* > the matrix S above, one can show that the diagonal element at each */ /* > step of Gaussian elimination is the largest (in absolute value) in */ /* > the column on or below the diagonal, so that no pivoting is required */ /* > for numerical stability [1]. */ /* > */ /* > For more details on the Householder reconstruction algorithm, */ /* > including the modified LU factorization, see [1]. */ /* > */ /* > This is the recursive version of the LU factorization algorithm. */ /* > Denote A - S by B. The algorithm divides the matrix B into four */ /* > submatrices: */ /* > */ /* > [ B11 | B12 ] where B11 is n1 by n1, */ /* > B = [ -----|----- ] B21 is (m-n1) by n1, */ /* > [ B21 | B22 ] B12 is n1 by n2, */ /* > B22 is (m-n1) by n2, */ /* > with n1 = f2cmin(m,n)/2, n2 = n-n1. */ /* > */ /* > */ /* > The subroutine calls itself to factor B11, solves for B21, */ /* > solves for B12, updates B22, then calls itself to factor B22. */ /* > */ /* > For more details on the recursive LU algorithm, see [2]. */ /* > */ /* > DLAORHR_COL_GETRFNP2 is called to factorize a block by the blocked */ /* > routine DLAORHR_COL_GETRFNP, which uses blocked code calling */ /* . Level 3 BLAS to update the submatrix. However, DLAORHR_COL_GETRFNP2 */ /* > is self-sufficient and can be used without DLAORHR_COL_GETRFNP. */ /* > */ /* > [1] "Reconstructing Householder vectors from tall-skinny QR", */ /* > G. Ballard, J. Demmel, L. Grigori, M. Jacquelin, H.D. Nguyen, */ /* > E. Solomonik, J. Parallel Distrib. Comput., */ /* > vol. 85, pp. 3-31, 2015. */ /* > */ /* > [2] "Recursion leads to automatic variable blocking for dense linear */ /* > algebra algorithms", F. Gustavson, IBM J. of Res. and Dev., */ /* > vol. 41, no. 6, pp. 737-755, 1997. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] M */ /* > \verbatim */ /* > M is INTEGER */ /* > The number of rows of the matrix A. M >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The number of columns of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in,out] A */ /* > \verbatim */ /* > A is DOUBLE PRECISION array, dimension (LDA,N) */ /* > On entry, the M-by-N matrix to be factored. */ /* > On exit, the factors L and U from the factorization */ /* > A-S=L*U; the unit diagonal elements of L are not stored. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax(1,M). */ /* > \endverbatim */ /* > */ /* > \param[out] D */ /* > \verbatim */ /* > D is DOUBLE PRECISION array, dimension f2cmin(M,N) */ /* > The diagonal elements of the diagonal M-by-N sign matrix S, */ /* > D(i) = S(i,i), where 1 <= i <= f2cmin(M,N). The elements can */ /* > be only plus or minus one. */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -i, the i-th argument had an illegal value */ /* > \endverbatim */ /* > */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date November 2019 */ /* > \ingroup doubleGEcomputational */ /* > \par Contributors: */ /* ================== */ /* > */ /* > \verbatim */ /* > */ /* > November 2019, Igor Kozachenko, */ /* > Computer Science Division, */ /* > University of California, Berkeley */ /* > */ /* > \endverbatim */ /* ===================================================================== */ /* Subroutine */ int dlaorhr_col_getrfnp2_(integer *m, integer *n, doublereal *a, integer *lda, doublereal *d__, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1; doublereal d__1; /* Local variables */ integer i__; extern /* Subroutine */ int dscal_(integer *, doublereal *, doublereal *, integer *), dgemm_(char *, char *, integer *, integer *, integer * , doublereal *, doublereal *, integer *, doublereal *, integer *, doublereal *, doublereal *, integer *); integer iinfo; doublereal sfmin; extern /* Subroutine */ int dtrsm_(char *, char *, char *, char *, integer *, integer *, doublereal *, doublereal *, integer *, doublereal *, integer *); integer n1, n2; extern doublereal dlamch_(char *); extern /* Subroutine */ int xerbla_(char *, integer *, ftnlen); /* -- LAPACK computational routine (version 3.9.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* November 2019 */ /* ===================================================================== */ /* Test the input parameters */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --d__; /* Function Body */ *info = 0; if (*m < 0) { *info = -1; } else if (*n < 0) { *info = -2; } else if (*lda < f2cmax(1,*m)) { *info = -4; } if (*info != 0) { i__1 = -(*info); xerbla_("DLAORHR_COL_GETRFNP2", &i__1, (ftnlen)20); return 0; } /* Quick return if possible */ if (f2cmin(*m,*n) == 0) { return 0; } if (*m == 1) { /* One row case, (also recursion termination case), */ /* use unblocked code */ /* Transfer the sign */ d__[1] = -d_sign(&c_b3, &a[a_dim1 + 1]); /* Construct the row of U */ a[a_dim1 + 1] -= d__[1]; } else if (*n == 1) { /* One column case, (also recursion termination case), */ /* use unblocked code */ /* Transfer the sign */ d__[1] = -d_sign(&c_b3, &a[a_dim1 + 1]); /* Construct the row of U */ a[a_dim1 + 1] -= d__[1]; /* Scale the elements 2:M of the column */ /* Determine machine safe minimum */ sfmin = dlamch_("S"); /* Construct the subdiagonal elements of L */ if ((d__1 = a[a_dim1 + 1], abs(d__1)) >= sfmin) { i__1 = *m - 1; d__1 = 1. / a[a_dim1 + 1]; dscal_(&i__1, &d__1, &a[a_dim1 + 2], &c__1); } else { i__1 = *m; for (i__ = 2; i__ <= i__1; ++i__) { a[i__ + a_dim1] /= a[a_dim1 + 1]; } } } else { /* Divide the matrix B into four submatrices */ n1 = f2cmin(*m,*n) / 2; n2 = *n - n1; /* Factor B11, recursive call */ dlaorhr_col_getrfnp2_(&n1, &n1, &a[a_offset], lda, &d__[1], &iinfo); /* Solve for B21 */ i__1 = *m - n1; dtrsm_("R", "U", "N", "N", &i__1, &n1, &c_b3, &a[a_offset], lda, &a[ n1 + 1 + a_dim1], lda); /* Solve for B12 */ dtrsm_("L", "L", "N", "U", &n1, &n2, &c_b3, &a[a_offset], lda, &a[(n1 + 1) * a_dim1 + 1], lda); /* Update B22, i.e. compute the Schur complement */ /* B22 := B22 - B21*B12 */ i__1 = *m - n1; dgemm_("N", "N", &i__1, &n2, &n1, &c_b19, &a[n1 + 1 + a_dim1], lda, & a[(n1 + 1) * a_dim1 + 1], lda, &c_b3, &a[n1 + 1 + (n1 + 1) * a_dim1], lda); /* Factor B22, recursive call */ i__1 = *m - n1; dlaorhr_col_getrfnp2_(&i__1, &n2, &a[n1 + 1 + (n1 + 1) * a_dim1], lda, &d__[n1 + 1], &iinfo); } return 0; /* End of DLAORHR_COL_GETRFNP2 */ } /* dlaorhr_col_getrfnp2__ */
the_stack_data/18888252.c
#include <stdio.h> #define SIZE 5 double max_minus_min(double * arr, int length); int main(void) { double arr[SIZE]={2,43,1,34,6}; printf("minus = %.1f\n",max_minus_min(arr,SIZE)); return 0; } double max_minus_min(double * arr, int length) { int index; int min=0; int max=0; for(index=0;index<length;index++) { if(arr[index]>max) max=arr[index]; if(arr[index]<min) min=arr[index]; } return max-min; }
the_stack_data/964743.c
/* * Copyright (C) 2019 Deciso B.V. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/wait.h> static const char *auth_cmd = "/usr/local/libexec/opnsense-auth"; /** * simple wrapper for our authentication script to allow root execution on opnsense-auth via the setuid bit * called from pam_opnsense.so as a stepping stone. * forwards all data received on stdin via popen */ int main() { int ch; int script_response = 255; FILE *fp; FILE *fp_stdin; fp = popen(auth_cmd, "w"); if (!fp) { exit(3); } else { fp_stdin = fdopen(STDIN_FILENO, "r"); if (!fp_stdin) { exit(3); } if (fp_stdin == stdin && feof(stdin)) { clearerr(stdin); } while ((ch = getc(fp_stdin)) != EOF) { putc(ch, fp); } fclose(fp_stdin); script_response = pclose(fp); } return WEXITSTATUS(script_response); }
the_stack_data/136966.c
#include <assert.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <math.h> long long factor(const long long i) { long long max = (long long)ceil(sqrt((double)i)); long long j = 2; while(j <= max) { if(i % j == 0) return j; else j++; } return i; } int main(const int argc, const char **argv) { long long f, i = strtoll(argv[1], NULL, 10); bool first = true; if (i == 0) { printf("0\n"); exit(0); } if (i < 0) { printf("-1"); first = false; i = -i; } do { f = factor(i); if (first) { printf("%lld", f); first = false; } else { printf(" %lld", f); } i = i / f; } while(i != 1); printf("\n"); return 0; }
the_stack_data/91495.c
#include <stddef.h> int mx_strcmp(const char *s1, const char *s2); int mx_linear_search(char **arr, const char *s) { for (int i = 0; arr[i] != NULL; ++i) { if (mx_strcmp(arr[i], s) == 0) { return i; } } return -1; }
the_stack_data/217103.c
//gcc -m32 -o test_iconv test_iconv.c -L/usr/local/lib -liconv #include <iconv.h> #include <stdio.h> #include <stdlib.h> int iconv_code(const char *fromcode, const char *tocode, char *in, char *out) { char *sin, *sout; size_t lenin, lenout; int ret; iconv_t c_pt; if ((c_pt = iconv_open(tocode, fromcode)) == (iconv_t) (-1)){ out = in; return -1; } lenin = strlen(in) + 1; char* oldPasserName = malloc(sizeof(char) * lenin); strncpy(oldPasserName, in, strlen(in)); oldPasserName[lenin-1] = '\0'; lenout = lenin * 10; char* newPasserName = malloc(sizeof(char) * lenout); sin = oldPasserName; sout = newPasserName; ret = iconv(c_pt, &sin, &lenin, &sout, &lenout); if (ret == -1) { out = in; iconv_close(c_pt); free(oldPasserName); free(newPasserName); return -1; } iconv_close(c_pt); strcpy(out, newPasserName); free(oldPasserName); free(newPasserName); return 0; } int main() { char to[10] ={0}; int ret = iconv_code("UTF-8", "GBK", "防火墙", to); printf("ret = %d\n", ret); printf("to = %s\n", to); return 0; }
the_stack_data/20449321.c
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #include <assert.h> #include <errno.h> #include <stdint.h> #include <stdio.h> #include <string.h> #include <sys/types.h> #include <time.h> #include <unistd.h> int cwdtest1() { return 0; } int main(int argc, const char* argv[], const char* envp[]) { char cwdbuf[200]; assert(argc == 2); // Validate our cwd is the same as the passed in argv[2] assert(getcwd(cwdbuf, sizeof(cwdbuf)) != NULL); assert(strcmp(cwdbuf, argv[1]) == 0); // Now set our cwd to see if it affects the parent assert(chdir("/tmp") == 0); // validate it set properly assert(getcwd(cwdbuf, sizeof(cwdbuf)) != NULL); assert(strcmp(cwdbuf, "/tmp") == 0); return 0; }
the_stack_data/18819.c
/// /// Device code split specific test. /// // REQUIRES: clang-driver // REQUIRES: x86-registered-target /// ########################################################################### /// Check the phases graph when using a single target, different from the host. /// We should have an offload action joining the host compile and device /// preprocessor and another one joining the device linking outputs to the host /// action. The same graph should be generated when no -fsycl-targets is used /// The same phase graph will be used with -fsycl-use-bitcode // RUN: %clang -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -fsycl-targets=spir64-unknown-unknown-sycldevice %s 2>&1 \ // RUN: | FileCheck -check-prefixes=CHK-PHASES,CHK-PHASES-DEFAULT-MODE %s // RUN: %clang_cl -ccc-print-phases -fsycl -fsycl-device-code-split=per_source -fsycl-targets=spir64-unknown-unknown-sycldevice %s 2>&1 \ // RUN: | FileCheck -check-prefixes=CHK-PHASES,CHK-PHASES-CL-MODE %s // RUN: %clang -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split=per_source -fno-sycl-use-bitcode %s 2>&1 \ // RUN: | FileCheck -check-prefixes=CHK-PHASES,CHK-PHASES-DEFAULT-MODE %s // RUN: %clang_cl -ccc-print-phases -fsycl -fsycl-device-code-split=per_source -fno-sycl-use-bitcode %s 2>&1 \ // RUN: | FileCheck -check-prefixes=CHK-PHASES,CHK-PHASES-CL-MODE %s // RUN: %clang -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split=per_source -fsycl-use-bitcode %s 2>&1 \ // RUN: | FileCheck -check-prefixes=CHK-PHASES,CHK-PHASES-DEFAULT-MODE %s // RUN: %clang_cl -ccc-print-phases -fsycl -fsycl-device-code-split=per_source -fsycl-use-bitcode %s 2>&1 \ // RUN: | FileCheck -check-prefixes=CHK-PHASES,CHK-PHASES-CL-MODE %s // CHK-PHASES: 0: input, "[[INPUT:.+\.c]]", c, (host-sycl) // CHK-PHASES: 1: preprocessor, {0}, cpp-output, (host-sycl) // CHK-PHASES: 2: input, "[[INPUT]]", c, (device-sycl) // CHK-PHASES: 3: preprocessor, {2}, cpp-output, (device-sycl) // CHK-PHASES: 4: compiler, {3}, sycl-header, (device-sycl) // CHK-PHASES-DEFAULT-MODE: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64-unknown-unknown-sycldevice)" {4}, cpp-output // CHK-PHASES-CL-MODE: 5: offload, "host-sycl (x86_64-pc-windows-msvc)" {1}, "device-sycl (spir64-unknown-unknown-sycldevice)" {4}, cpp-output // CHK-PHASES: 6: compiler, {5}, ir, (host-sycl) // CHK-PHASES: 7: backend, {6}, assembler, (host-sycl) // CHK-PHASES: 8: assembler, {7}, object, (host-sycl) // CHK-PHASES: 9: linker, {8}, image, (host-sycl) // CHK-PHASES: 10: compiler, {3}, ir, (device-sycl) // CHK-PHASES: 11: linker, {10}, ir, (device-sycl) // CHK-PHASES: 12: sycl-post-link, {11}, tempfiletable, (device-sycl) // CHK-PHASES: 13: file-table-tform, {12}, tempfilelist, (device-sycl) // CHK-PHASES: 14: llvm-spirv, {13}, tempfilelist, (device-sycl) // CHK-PHASES: 15: file-table-tform, {12, 14}, tempfiletable, (device-sycl) // CHK-PHASES: 16: clang-offload-wrapper, {15}, object, (device-sycl) // CHK-PHASES-DEFAULT-MODE: 17: offload, "host-sycl (x86_64-unknown-linux-gnu)" {9}, "device-sycl (spir64-unknown-unknown-sycldevice)" {16}, image // CHK-PHASES-CL-MODE: 17: offload, "host-sycl (x86_64-pc-windows-msvc)" {9}, "device-sycl (spir64-unknown-unknown-sycldevice)" {16}, image /// ########################################################################### /// Check the phases also add a library to make sure it is treated as input by /// the device. // RUN: %clang -ccc-print-phases -target x86_64-unknown-linux-gnu -lsomelib -fsycl -fsycl-device-code-split -fsycl-targets=spir64-unknown-unknown-sycldevice %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-PHASES-LIB %s // CHK-PHASES-LIB: 0: input, "somelib", object, (host-sycl) // CHK-PHASES-LIB: 1: input, "[[INPUT:.+\.c]]", c, (host-sycl) // CHK-PHASES-LIB: 2: preprocessor, {1}, cpp-output, (host-sycl) // CHK-PHASES-LIB: 3: input, "[[INPUT]]", c, (device-sycl) // CHK-PHASES-LIB: 4: preprocessor, {3}, cpp-output, (device-sycl) // CHK-PHASES-LIB: 5: compiler, {4}, sycl-header, (device-sycl) // CHK-PHASES-LIB: 6: offload, "host-sycl (x86_64-unknown-linux-gnu)" {2}, "device-sycl (spir64-unknown-unknown-sycldevice)" {5}, cpp-output // CHK-PHASES-LIB: 7: compiler, {6}, ir, (host-sycl) // CHK-PHASES-LIB: 8: backend, {7}, assembler, (host-sycl) // CHK-PHASES-LIB: 9: assembler, {8}, object, (host-sycl) // CHK-PHASES-LIB: 10: linker, {0, 9}, image, (host-sycl) // CHK-PHASES-LIB: 11: compiler, {4}, ir, (device-sycl) // CHK-PHASES-LIB: 12: linker, {11}, ir, (device-sycl) // CHK-PHASES-LIB: 13: sycl-post-link, {12}, tempfiletable, (device-sycl) // CHK-PHASES-LIB: 14: file-table-tform, {13}, tempfilelist, (device-sycl) // CHK-PHASES-LIB: 15: llvm-spirv, {14}, tempfilelist, (device-sycl) // CHK-PHASES-LIB: 16: file-table-tform, {13, 15}, tempfiletable, (device-sycl) // CHK-PHASES-LIB: 17: clang-offload-wrapper, {16}, object, (device-sycl) // CHK-PHASES-LIB: 18: offload, "host-sycl (x86_64-unknown-linux-gnu)" {10}, "device-sycl (spir64-unknown-unknown-sycldevice)" {17}, image /// ########################################################################### /// Check the phases when using and multiple source files // RUN: echo " " > %t.c // RUN: %clang -ccc-print-phases -lsomelib -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -fsycl-targets=spir64-unknown-unknown-sycldevice %s %t.c 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-PHASES-FILES %s // CHK-PHASES-FILES: 0: input, "somelib", object, (host-sycl) // CHK-PHASES-FILES: 1: input, "[[INPUT1:.+\.c]]", c, (host-sycl) // CHK-PHASES-FILES: 2: preprocessor, {1}, cpp-output, (host-sycl) // CHK-PHASES-FILES: 3: input, "[[INPUT1]]", c, (device-sycl) // CHK-PHASES-FILES: 4: preprocessor, {3}, cpp-output, (device-sycl) // CHK-PHASES-FILES: 5: compiler, {4}, sycl-header, (device-sycl) // CHK-PHASES-FILES: 6: offload, "host-sycl (x86_64-unknown-linux-gnu)" {2}, "device-sycl (spir64-unknown-unknown-sycldevice)" {5}, cpp-output // CHK-PHASES-FILES: 7: compiler, {6}, ir, (host-sycl) // CHK-PHASES-FILES: 8: backend, {7}, assembler, (host-sycl) // CHK-PHASES-FILES: 9: assembler, {8}, object, (host-sycl) // CHK-PHASES-FILES: 10: input, "[[INPUT2:.+\.c]]", c, (host-sycl) // CHK-PHASES-FILES: 11: preprocessor, {10}, cpp-output, (host-sycl) // CHK-PHASES-FILES: 12: input, "[[INPUT2]]", c, (device-sycl) // CHK-PHASES-FILES: 13: preprocessor, {12}, cpp-output, (device-sycl) // CHK-PHASES-FILES: 14: compiler, {13}, sycl-header, (device-sycl) // CHK-PHASES-FILES: 15: offload, "host-sycl (x86_64-unknown-linux-gnu)" {11}, "device-sycl (spir64-unknown-unknown-sycldevice)" {14}, cpp-output // CHK-PHASES-FILES: 16: compiler, {15}, ir, (host-sycl) // CHK-PHASES-FILES: 17: backend, {16}, assembler, (host-sycl) // CHK-PHASES-FILES: 18: assembler, {17}, object, (host-sycl) // CHK-PHASES-FILES: 19: linker, {0, 9, 18}, image, (host-sycl) // CHK-PHASES-FILES: 20: compiler, {4}, ir, (device-sycl) // CHK-PHASES-FILES: 21: compiler, {13}, ir, (device-sycl) // CHK-PHASES-FILES: 22: linker, {20, 21}, ir, (device-sycl) // CHK-PHASES-FILES: 23: sycl-post-link, {22}, tempfiletable, (device-sycl) // CHK-PHASES-FILES: 24: file-table-tform, {23}, tempfilelist, (device-sycl) // CHK-PHASES-FILES: 25: llvm-spirv, {24}, tempfilelist, (device-sycl) // CHK-PHASES-FILES: 26: file-table-tform, {23, 25}, tempfiletable, (device-sycl) // CHK-PHASES-FILES: 27: clang-offload-wrapper, {26}, object, (device-sycl) // CHK-PHASES-FILES: 28: offload, "host-sycl (x86_64-unknown-linux-gnu)" {19}, "device-sycl (spir64-unknown-unknown-sycldevice)" {27}, image /// ########################################################################### /// Check separate compilation with offloading - unbundling actions // RUN: touch %t.o // RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -o %t.out -lsomelib -fsycl-targets=spir64-unknown-unknown-sycldevice %t.o 2>&1 \ // RUN: | FileCheck -DINPUT=%t.o -check-prefix=CHK-UBACTIONS %s // RUN: mkdir -p %t_dir // RUN: touch %t_dir/dummy // RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -o %t.out -lsomelib -fsycl-targets=spir64-unknown-unknown-sycldevice %t_dir/dummy 2>&1 \ // RUN: | FileCheck -DINPUT=%t_dir/dummy -check-prefix=CHK-UBACTIONS %s // CHK-UBACTIONS: 0: input, "somelib", object, (host-sycl) // CHK-UBACTIONS: 1: input, "[[INPUT]]", object, (host-sycl) // CHK-UBACTIONS: 2: clang-offload-unbundler, {1}, object, (host-sycl) // CHK-UBACTIONS: 3: linker, {0, 2}, image, (host-sycl) // CHK-UBACTIONS: 4: linker, {2}, ir, (device-sycl) // CHK-UBACTIONS: 5: sycl-post-link, {4}, tempfiletable, (device-sycl) // CHK-UBACTIONS: 6: file-table-tform, {5}, tempfilelist, (device-sycl) // CHK-UBACTIONS: 7: llvm-spirv, {6}, tempfilelist, (device-sycl) // CHK-UBACTIONS: 8: file-table-tform, {5, 7}, tempfiletable, (device-sycl) // CHK-UBACTIONS: 9: clang-offload-wrapper, {8}, object, (device-sycl) // CHK-UBACTIONS: 10: offload, "host-sycl (x86_64-unknown-linux-gnu)" {3}, "device-sycl (spir64-unknown-unknown-sycldevice)" {9}, image /// ########################################################################### /// Check separate compilation with offloading - unbundling with source // RUN: touch %t.o // RUN: %clang -### -ccc-print-phases -target x86_64-unknown-linux-gnu -lsomelib -fsycl -fsycl-device-code-split %t.o -fsycl-targets=spir64-unknown-unknown-sycldevice %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-UBUACTIONS %s // CHK-UBUACTIONS: 0: input, "somelib", object, (host-sycl) // CHK-UBUACTIONS: 1: input, "[[INPUT1:.+\.o]]", object, (host-sycl) // CHK-UBUACTIONS: 2: clang-offload-unbundler, {1}, object, (host-sycl) // CHK-UBUACTIONS: 3: input, "[[INPUT2:.+\.c]]", c, (host-sycl) // CHK-UBUACTIONS: 4: preprocessor, {3}, cpp-output, (host-sycl) // CHK-UBUACTIONS: 5: input, "[[INPUT2]]", c, (device-sycl) // CHK-UBUACTIONS: 6: preprocessor, {5}, cpp-output, (device-sycl) // CHK-UBUACTIONS: 7: compiler, {6}, sycl-header, (device-sycl) // CHK-UBUACTIONS: 8: offload, "host-sycl (x86_64-unknown-linux-gnu)" {4}, "device-sycl (spir64-unknown-unknown-sycldevice)" {7}, cpp-output // CHK-UBUACTIONS: 9: compiler, {8}, ir, (host-sycl) // CHK-UBUACTIONS: 10: backend, {9}, assembler, (host-sycl) // CHK-UBUACTIONS: 11: assembler, {10}, object, (host-sycl) // CHK-UBUACTIONS: 12: linker, {0, 2, 11}, image, (host-sycl) // CHK-UBUACTIONS: 13: compiler, {6}, ir, (device-sycl) // CHK-UBUACTIONS: 14: linker, {2, 13}, ir, (device-sycl) // CHK-UBUACTIONS: 15: sycl-post-link, {14}, tempfiletable, (device-sycl) // CHK-UBUACTIONS: 16: file-table-tform, {15}, tempfilelist, (device-sycl) // CHK-UBUACTIONS: 17: llvm-spirv, {16}, tempfilelist, (device-sycl) // CHK-UBUACTIONS: 18: file-table-tform, {15, 17}, tempfiletable, (device-sycl) // CHK-UBUACTIONS: 19: clang-offload-wrapper, {18}, object, (device-sycl) // CHK-UBUACTIONS: 20: offload, "host-sycl (x86_64-unknown-linux-gnu)" {12}, "device-sycl (spir64-unknown-unknown-sycldevice)" {19}, image /// ########################################################################### /// Ahead of Time compilation for fpga, gen, cpu // RUN: %clang -target x86_64-unknown-linux-gnu -ccc-print-phases -fsycl -fsycl-device-code-split -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %s 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-PHASES-AOT,CHK-PHASES-FPGA // RUN: %clang -target x86_64-unknown-linux-gnu -ccc-print-phases -fsycl -fsycl-device-code-split -fsycl-targets=spir64_gen-unknown-unknown-sycldevice %s 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-PHASES-AOT,CHK-PHASES-GEN // RUN: %clang -target x86_64-unknown-linux-gnu -ccc-print-phases -fsycl -fsycl-device-code-split -fsycl-targets=spir64_x86_64-unknown-unknown-sycldevice %s 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-PHASES-AOT,CHK-PHASES-CPU // CHK-PHASES-AOT: 0: input, "[[INPUT:.+\.c]]", c, (host-sycl) // CHK-PHASES-AOT: 1: preprocessor, {0}, cpp-output, (host-sycl) // CHK-PHASES-AOT: 2: input, "[[INPUT]]", c, (device-sycl) // CHK-PHASES-AOT: 3: preprocessor, {2}, cpp-output, (device-sycl) // CHK-PHASES-AOT: 4: compiler, {3}, sycl-header, (device-sycl) // CHK-PHASES-FPGA: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {4}, cpp-output // CHK-PHASES-GEN: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64_gen-unknown-unknown-sycldevice)" {4}, cpp-output // CHK-PHASES-CPU: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64_x86_64-unknown-unknown-sycldevice)" {4}, cpp-output // CHK-PHASES-AOT: 6: compiler, {5}, ir, (host-sycl) // CHK-PHASES-AOT: 7: backend, {6}, assembler, (host-sycl) // CHK-PHASES-AOT: 8: assembler, {7}, object, (host-sycl) // CHK-PHASES-AOT: 9: linker, {8}, image, (host-sycl) // CHK-PHASES-AOT: 10: compiler, {3}, ir, (device-sycl) // CHK-PHASES-AOT: 11: linker, {10}, ir, (device-sycl) // CHK-PHASES-AOT: 12: sycl-post-link, {11}, tempfiletable, (device-sycl) // CHK-PHASES-AOT: 13: file-table-tform, {12}, tempfilelist, (device-sycl) // CHK-PHASES-AOT: 14: llvm-spirv, {13}, tempfilelist, (device-sycl) // CHK-PHASES-GEN: 15: backend-compiler, {14}, tempfilelist, (device-sycl) // CHK-PHASES-FPGA: 15: backend-compiler, {14}, tempfilelist, (device-sycl) // CHK-PHASES-CPU: 15: backend-compiler, {14}, tempfilelist, (device-sycl) // CHK-PHASES-AOT: 16: file-table-tform, {12, 15}, tempfiletable, (device-sycl) // CHK-PHASES-AOT: 17: clang-offload-wrapper, {16}, object, (device-sycl) // CHK-PHASES-FPGA: 18: offload, "host-sycl (x86_64-unknown-linux-gnu)" {9}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {17}, image // CHK-PHASES-GEN: 18: offload, "host-sycl (x86_64-unknown-linux-gnu)" {9}, "device-sycl (spir64_gen-unknown-unknown-sycldevice)" {17}, image // CHK-PHASES-CPU: 18: offload, "host-sycl (x86_64-unknown-linux-gnu)" {9}, "device-sycl (spir64_x86_64-unknown-unknown-sycldevice)" {17}, image /// ########################################################################### /// Ahead of Time compilation for fpga, gen, cpu - tool invocation // RUN: %clang -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -fsycl-targets=spir64_fpga-unknown-unknown-sycldevice %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-TOOLS-AOT,CHK-TOOLS-FPGA // RUN: %clang -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -fintelfpga %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-TOOLS-AOT,CHK-TOOLS-FPGA // RUN: %clang -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -fsycl-targets=spir64_gen-unknown-unknown-sycldevice %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-TOOLS-AOT,CHK-TOOLS-GEN // RUN: %clang -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -fsycl-targets=spir64_x86_64-unknown-unknown-sycldevice %s -### 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-TOOLS-AOT,CHK-TOOLS-CPU // CHK-TOOLS-AOT: clang{{.*}} "-fsycl-is-device" {{.*}} "-o" "[[OUTPUT1:.+\.bc]]" // CHK-TOOLS-AOT: llvm-link{{.*}} "[[OUTPUT1]]" "-o" "[[OUTPUT2:.+\.bc]]" // CHK-TOOLS-AOT: sycl-post-link{{.*}} "-spec-const=default" "-o" "[[OUTPUT3:.+\.table]]" "[[OUTPUT2]]" // CHK-TOOLS-AOT: file-table-tform{{.*}} "-o" "[[OUTPUT4:.+\.txt]]" "[[OUTPUT3]]" // CHK-TOOLS-AOT: llvm-foreach{{.*}} "--in-file-list=[[OUTPUT4]]" "--in-replace=[[OUTPUT4]]" "--out-ext=spv" "--out-file-list=[[OUTPUT5:.+\.txt]]" "--out-replace=[[OUTPUT5]]" "--" "{{.*}}llvm-spirv{{.*}}" "-o" "[[OUTPUT5]]" {{.*}} "[[OUTPUT4]]" // CHK-TOOLS-FPGA: llvm-foreach{{.*}} "--out-file-list=[[OUTPUT6:.+\.txt]]{{.*}} "--" "{{.*}}aoc{{.*}} "-o" "[[OUTPUT6]]" "[[OUTPUT5]]" // CHK-TOOLS-GEN: llvm-foreach{{.*}} "--out-file-list=[[OUTPUT6:.+\.txt]]{{.*}} "--" "{{.*}}ocloc{{.*}} "-output" "[[OUTPUT6]]" "-file" "[[OUTPUT5]]" // CHK-TOOLS-CPU: llvm-foreach{{.*}} "--out-file-list=[[OUTPUT6:.+\.txt]]{{.*}} "--" "{{.*}}opencl-aot{{.*}} "-o=[[OUTPUT6]]" "--device=cpu" "[[OUTPUT5]]" // CHK-TOOLS-AOT: file-table-tform{{.*}} "-o" "[[OUTPUT7:.+\.table]]" "[[OUTPUT3]]" "[[OUTPUT6]]" // CHK-TOOLS-FPGA: clang-offload-wrapper{{.*}} "-o=[[OUTPUT8:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" "-target=spir64_fpga" "-kind=sycl" "-batch" "[[OUTPUT7]]" // CHK-TOOLS-GEN: clang-offload-wrapper{{.*}} "-o=[[OUTPUT8:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" "-target=spir64_gen" "-kind=sycl" "-batch" "[[OUTPUT7]]" // CHK-TOOLS-CPU: clang-offload-wrapper{{.*}} "-o=[[OUTPUT8:.+\.bc]]" "-host=x86_64-unknown-linux-gnu" "-target=spir64_x86_64" "-kind=sycl" "-batch" "[[OUTPUT7]]" // CHK-TOOLS-AOT: llc{{.*}} "-filetype=obj" "-o" "[[OUTPUT9:.+\.o]]" "[[OUTPUT8]]" // CHK-TOOLS-FPGA: clang{{.*}} "-triple" "spir64_fpga-unknown-unknown-sycldevice" {{.*}} "-fsycl-int-header=[[INPUT1:.+\.h]]" "-D__ENABLE_USM_ADDR_SPACE__" "-faddrsig" // CHK-TOOLS-GEN: clang{{.*}} "-triple" "spir64_gen-unknown-unknown-sycldevice" {{.*}} "-fsycl-int-header=[[INPUT1:.+\.h]]" "-faddrsig" // CHK-TOOLS-CPU: clang{{.*}} "-triple" "spir64_x86_64-unknown-unknown-sycldevice" {{.*}} "-fsycl-int-header=[[INPUT1:.+\.h]]" "-faddrsig" // CHK-TOOLS-AOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-include" "[[INPUT1]]" {{.*}} "-o" "[[OUTPUT10:.+\.o]]" // CHK-TOOLS-AOT: ld{{.*}} "[[OUTPUT10]]" "[[OUTPUT9]]" {{.*}} "-lsycl" /// ########################################################################### /// offload with multiple targets, including AOT // RUN: %clang -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-code-split -fsycl-targets=spir64-unknown-unknown-sycldevice,spir64_fpga-unknown-unknown-sycldevice,spir64_gen-unknown-unknown-sycldevice -### -ccc-print-phases %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-PHASE-MULTI-TARG %s // CHK-PHASE-MULTI-TARG: 0: input, "[[INPUT:.+\.c]]", c, (host-sycl) // CHK-PHASE-MULTI-TARG: 1: preprocessor, {0}, cpp-output, (host-sycl) // CHK-PHASE-MULTI-TARG: 2: input, "[[INPUT]]", c, (device-sycl) // CHK-PHASE-MULTI-TARG: 3: preprocessor, {2}, cpp-output, (device-sycl) // CHK-PHASE-MULTI-TARG: 4: compiler, {3}, sycl-header, (device-sycl) // CHK-PHASE-MULTI-TARG: 5: offload, "host-sycl (x86_64-unknown-linux-gnu)" {1}, "device-sycl (spir64-unknown-unknown-sycldevice)" {4}, cpp-output // CHK-PHASE-MULTI-TARG: 6: compiler, {5}, ir, (host-sycl) // CHK-PHASE-MULTI-TARG: 7: backend, {6}, assembler, (host-sycl) // CHK-PHASE-MULTI-TARG: 8: assembler, {7}, object, (host-sycl) // CHK-PHASE-MULTI-TARG: 9: linker, {8}, image, (host-sycl) // CHK-PHASE-MULTI-TARG: 10: input, "[[INPUT]]", c, (device-sycl) // CHK-PHASE-MULTI-TARG: 11: preprocessor, {10}, cpp-output, (device-sycl) // CHK-PHASE-MULTI-TARG: 12: compiler, {11}, ir, (device-sycl) // CHK-PHASE-MULTI-TARG: 13: linker, {12}, ir, (device-sycl) // CHK-PHASE-MULTI-TARG: 14: sycl-post-link, {13}, tempfiletable, (device-sycl) // CHK-PHASE-MULTI-TARG: 15: file-table-tform, {14}, tempfilelist, (device-sycl) // CHK-PHASE-MULTI-TARG: 16: llvm-spirv, {15}, tempfilelist, (device-sycl) // CHK-PHASE-MULTI-TARG: 17: file-table-tform, {14, 16}, tempfiletable, (device-sycl) // CHK-PHASE-MULTI-TARG: 18: clang-offload-wrapper, {17}, object, (device-sycl) // CHK-PHASE-MULTI-TARG: 19: input, "[[INPUT]]", c, (device-sycl) // CHK-PHASE-MULTI-TARG: 20: preprocessor, {19}, cpp-output, (device-sycl) // CHK-PHASE-MULTI-TARG: 21: compiler, {20}, ir, (device-sycl) // CHK-PHASE-MULTI-TARG: 22: linker, {21}, ir, (device-sycl) // CHK-PHASE-MULTI-TARG: 23: sycl-post-link, {22}, tempfiletable, (device-sycl) // CHK-PHASE-MULTI-TARG: 24: file-table-tform, {23}, tempfilelist, (device-sycl) // CHK-PHASE-MULTI-TARG: 25: llvm-spirv, {24}, tempfilelist, (device-sycl) // CHK-PHASE-MULTI-TARG: 26: backend-compiler, {25}, tempfilelist, (device-sycl) // CHK-PHASE-MULTI-TARG: 27: file-table-tform, {23, 26}, tempfiletable, (device-sycl) // CHK-PHASE-MULTI-TARG: 28: clang-offload-wrapper, {27}, object, (device-sycl) // CHK-PHASE-MULTI-TARG: 29: compiler, {3}, ir, (device-sycl) // CHK-PHASE-MULTI-TARG: 30: linker, {29}, ir, (device-sycl) // CHK-PHASE-MULTI-TARG: 31: sycl-post-link, {30}, tempfiletable, (device-sycl) // CHK-PHASE-MULTI-TARG: 32: file-table-tform, {31}, tempfilelist, (device-sycl) // CHK-PHASE-MULTI-TARG: 33: llvm-spirv, {32}, tempfilelist, (device-sycl) // CHK-PHASE-MULTI-TARG: 34: backend-compiler, {33}, tempfilelist, (device-sycl) // CHK-PHASE-MULTI-TARG: 35: file-table-tform, {31, 34}, tempfiletable, (device-sycl) // CHK-PHASE-MULTI-TARG: 36: clang-offload-wrapper, {35}, object, (device-sycl) // CHK-PHASE-MULTI-TARG: 37: offload, "host-sycl (x86_64-unknown-linux-gnu)" {9}, "device-sycl (spir64-unknown-unknown-sycldevice)" {18}, "device-sycl (spir64_fpga-unknown-unknown-sycldevice)" {28}, "device-sycl (spir64_gen-unknown-unknown-sycldevice)" {36}, image // Check -fsycl-one-kernel-per-module option passing. // RUN: %clang -### -fsycl -fsycl-device-code-split=per_kernel %s 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-ONE-KERNEL // RUN: %clang_cl -### -fsycl -fsycl-device-code-split=per_kernel %s 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-ONE-KERNEL // CHK-ONE-KERNEL: sycl-post-link{{.*}} "-split=kernel"{{.*}} "-o"{{.*}} // Check no device code split mode. // RUN: %clang -### -fsycl -fsycl-device-code-split -fsycl-device-code-split=off %s 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-NO-SPLIT // RUN: %clang_cl -### -fsycl -fsycl-device-code-split -fsycl-device-code-split=off %s 2>&1 \ // RUN: | FileCheck %s -check-prefixes=CHK-NO-SPLIT // CHK-NO-SPLIT-NOT: sycl-post-link{{.*}} -split{{.*}} // TODO: SYCL specific fail - analyze and enable // XFAIL: windows-msvc
the_stack_data/56695.c
/* text version of maze 'mazefiles/binary/minos03.maz' generated by mazetool (c) Peter Harrison 2018 o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o | | | | o o---o---o---o---o o o o---o---o---o---o o o o o | | | | | | | | | | o o o o o o o o o o---o---o---o o---o---o o | | | | | | | | | | | | o o o o o o---o o o o o o o---o o o o | | | | | | | | | | | | | o o o o o o o---o---o---o o o o---o o o o | | | | | | | | | o o o o---o o---o---o o o---o---o o---o---o---o o | | | | | | | | | o o---o---o---o---o o o o---o---o---o---o---o---o o o | | | | | o---o---o o o---o o o---o---o o---o o o---o---o o | | | | | | | | o---o---o o---o---o---o o o o---o o---o---o---o---o o | | | | | o o o o o---o o o---o---o o---o o---o o---o o | | | | | | | | | | | | | o o o---o o o o---o---o---o---o o---o---o---o---o o | | | | | | | o o o o---o o---o---o---o---o---o---o o o o---o o | | | | | | | o o---o o o---o o o---o---o---o---o o o o o---o | | | | | | | o---o---o---o o o---o o---o---o---o o---o o o o o | | | | | | | | | | o o o o o---o---o---o o---o o---o o o o---o---o | | | | | | | o o o---o---o---o---o---o---o---o o---o o o---o---o---o | | | | o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o---o */ int minos03_maz[] ={ 0x0E, 0x0A, 0x09, 0x0C, 0x0A, 0x0A, 0x0A, 0x09, 0x0D, 0x0C, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x09, 0x0C, 0x08, 0x03, 0x05, 0x0C, 0x0A, 0x0A, 0x01, 0x05, 0x05, 0x0E, 0x08, 0x0A, 0x0A, 0x09, 0x05, 0x05, 0x04, 0x0B, 0x04, 0x02, 0x09, 0x0E, 0x02, 0x02, 0x01, 0x0C, 0x02, 0x08, 0x0A, 0x03, 0x05, 0x05, 0x04, 0x0A, 0x02, 0x09, 0x06, 0x08, 0x09, 0x0C, 0x01, 0x05, 0x0C, 0x02, 0x0A, 0x09, 0x05, 0x05, 0x05, 0x0C, 0x09, 0x04, 0x08, 0x03, 0x05, 0x05, 0x05, 0x06, 0x02, 0x0A, 0x08, 0x03, 0x05, 0x05, 0x05, 0x05, 0x06, 0x01, 0x06, 0x0A, 0x03, 0x06, 0x02, 0x09, 0x0C, 0x0B, 0x06, 0x0A, 0x01, 0x05, 0x05, 0x06, 0x08, 0x01, 0x0D, 0x0C, 0x0A, 0x0A, 0x0A, 0x03, 0x05, 0x0C, 0x0A, 0x0A, 0x03, 0x05, 0x06, 0x09, 0x05, 0x05, 0x05, 0x05, 0x0C, 0x09, 0x0C, 0x0A, 0x03, 0x06, 0x0A, 0x08, 0x09, 0x05, 0x0D, 0x05, 0x05, 0x05, 0x05, 0x07, 0x04, 0x01, 0x05, 0x0C, 0x09, 0x0E, 0x08, 0x01, 0x05, 0x04, 0x02, 0x03, 0x05, 0x05, 0x05, 0x0E, 0x01, 0x06, 0x01, 0x05, 0x04, 0x0A, 0x03, 0x05, 0x05, 0x05, 0x0D, 0x0C, 0x01, 0x05, 0x04, 0x0B, 0x04, 0x0B, 0x05, 0x07, 0x06, 0x0A, 0x09, 0x05, 0x05, 0x06, 0x02, 0x01, 0x06, 0x02, 0x01, 0x0E, 0x01, 0x0E, 0x01, 0x0C, 0x08, 0x08, 0x01, 0x07, 0x05, 0x0C, 0x0A, 0x02, 0x0A, 0x0A, 0x01, 0x0F, 0x05, 0x0C, 0x01, 0x05, 0x07, 0x05, 0x06, 0x08, 0x03, 0x05, 0x0C, 0x0A, 0x0A, 0x0A, 0x01, 0x0E, 0x01, 0x05, 0x07, 0x05, 0x0C, 0x02, 0x09, 0x06, 0x09, 0x05, 0x05, 0x0E, 0x08, 0x09, 0x07, 0x0D, 0x05, 0x05, 0x0C, 0x03, 0x06, 0x0A, 0x03, 0x0E, 0x01, 0x07, 0x07, 0x0E, 0x03, 0x06, 0x0A, 0x02, 0x02, 0x02, 0x02, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x03, }; /* end of mazefile */
the_stack_data/134435.c
#include <stdlib.h> #include <stddef.h> #include <stdbool.h> /*----------- ESTRUCTURA NODO -----------*/ // estructura de nodo solamente con un puntero a un nodo siguiente, // y un puntero void* a un dato. typedef struct nodo { struct nodo* sig; void* dato; } nodo_t; /*----------- PRIMITIVA NODO -----------*/ nodo_t* nodo_crear(void){ nodo_t* nodo = malloc(sizeof(nodo_t)); if (nodo == NULL) return NULL; nodo->sig = NULL; return nodo; } /*----------- ESTRUCTURA COLA -----------*/ typedef struct cola { nodo_t* prim; nodo_t* ulti; } cola_t; /*----------- PRIMITIVAS COLA -----------*/ cola_t* cola_crear(void){ cola_t* cola = malloc(sizeof(cola_t)); if (!cola) return NULL; cola->prim = NULL; cola->ulti = NULL; return cola; } bool cola_esta_vacia(const cola_t *cola) { return cola->prim == NULL; } bool cola_encolar(cola_t *cola, void* valor) { nodo_t* n_nodo = nodo_crear(); if (!n_nodo) return false; n_nodo->dato = valor; if (cola_esta_vacia(cola)) { cola->prim = n_nodo; } else { cola->ulti->sig = n_nodo; } cola->ulti = n_nodo; return true; } void* cola_ver_primero(const cola_t *cola) { if (cola_esta_vacia(cola)) return NULL; return cola->prim->dato; } void* cola_desencolar(cola_t *cola) { if (cola_esta_vacia(cola)) return NULL; nodo_t* nuevo_prim = cola->prim->sig; void* valor = cola->prim->dato; free(cola->prim); cola->prim = nuevo_prim; if (!cola->prim) cola->ulti = NULL; return valor; } void cola_destruir(cola_t *cola, void destruir_dato(void*)) { while (!cola_esta_vacia(cola)) { void* dato = cola_desencolar(cola); if (destruir_dato) destruir_dato(dato); } free(cola); }
the_stack_data/113373.c
#include <stdio.h> #include <math.h> #include <stdlib.h> void compute_stats(double* x, int N, double* av, double* std) { double sum=0, sumsq=0; for(int i=0; i<N; ++i) { sum += x[i]; sumsq += x[i]*x[i]; } *av = sum/N; *std = sqrt( sumsq/N - (*av)*(*av) ); } double gaussrnd() { double u1 = drand48(); double u2 = drand48(); return sqrt(-2*log(u1))*cos(2*M_PI*u2); } int main(int argc, char** argv) { int N; FILE* f = fopen("data.txt", "r"); fscanf(f, "%d", &N); double* x = malloc(N*sizeof(double)); for(int i=0; i<N; ++i) fscanf(f, "%lf", &x[i]); fclose(f); double av, std; compute_stats(x, N, &av, &std); printf("av: %e std: %e\n", av, std); free(x); return 0; }
the_stack_data/1042419.c
#include <stdio.h> const int diffSquares(const int start,const int stop) { int sumOfSquares = 0,squareOfSum = 0; for (int i = start; i <= stop; i++) { sumOfSquares += i * i; squareOfSum += i; } return squareOfSum * squareOfSum - sumOfSquares; } int main(void) { printf("Difference is %d.\n",diffSquares(1,100)); return 0; }
the_stack_data/26699298.c
#include <stdio.h> main() { int i,p,n,number[10]; printf("Type ten numbers by terminal(Key board): "); for(i=0;i<10;i++) scanf("%d",&number[i]); p=0; n=0; for(i=0;i<10;i++) if(number[i]>=0) p=p+1; else n=n+1; printf("Total positive number=%d\n",p); printf("Total negative number=%d\n",n); }