blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
357
content_id
stringlengths
40
40
detected_licenses
listlengths
0
58
license_type
stringclasses
2 values
repo_name
stringlengths
4
115
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringlengths
4
58
visit_date
timestamp[ns]date
2015-07-14 21:31:45
2023-09-06 10:45:08
revision_date
timestamp[ns]date
1970-01-01 00:00:00
2023-09-05 23:26:37
committer_date
timestamp[ns]date
1970-01-01 00:00:00
2023-09-05 23:26:37
github_id
int64
966
689M
star_events_count
int64
0
209k
fork_events_count
int64
0
110k
gha_license_id
stringclasses
24 values
gha_event_created_at
timestamp[ns]date
2012-06-07 00:51:45
2023-09-14 21:58:52
gha_created_at
timestamp[ns]date
2008-02-03 21:17:16
2023-08-24 19:49:39
gha_language
stringclasses
180 values
src_encoding
stringclasses
35 values
language
stringclasses
1 value
is_vendor
bool
1 class
is_generated
bool
2 classes
length_bytes
int64
6
10.4M
extension
stringclasses
121 values
filename
stringlengths
1
148
content
stringlengths
6
10.4M
864ed93d68e57603fcbc8d826d0f30dc32c2f0f7
d2609d1d56dddd3faef65a2bb0a41c8ec030212d
/problem1/primeNumber.c
55644bb7cd92fc015c5d46e3b59e1f28e0404877
[]
no_license
asicnick/hackerearth
a0ca97bf6eecf3a61137ceee97a58d11e35c3d48
cc5a1602e27405ed6dc574aedd1baf4896407e75
refs/heads/master
2020-03-18T00:23:18.108718
2018-05-27T09:13:09
2018-05-27T09:13:09
134,091,162
0
0
null
null
null
null
UTF-8
C
false
false
538
c
primeNumber.c
// primeNumber.cpp : Defines the entry point for the console application. // #include <stdio.h> #include <math.h> int main() { int range; int flag; scanf("%d", &range); for (int i = 2; i <= range; i++) { flag = 0; // Reference: https://stackoverflow.com/questions/5811151/why-do-we-check-up-to-the-square-root-of-a-prime-number-to-determine-if-it-is-pr for (int j = 2; j <= (sqrt((double)range)); j++) { if ((i%j == 0) && (i != j)) { flag = 1; // } } if (flag != 1) printf("%d ", i); } return 0; }
251d1095ad15ccd99e3be3bc14c15ff5e9e40eee
8ec083cfbc483a1f96d007e5e29cc613b8a86e97
/ios/Pods/Headers/Private/FlipperKit/FlipperKitLayoutHelpers/SKInvalidation.h
4b4f302b014c580a5ce05e239b71485dfec944d0
[]
no_license
hamid/react-native-ios-settings-bundle
c2fec5ee34cd5a386dce7f66f6273fcb4796c38a
a9be54b8782031ad47a93c6cb73a8f82127b1455
refs/heads/master
2023-02-11T02:01:27.129147
2022-06-16T09:55:27
2022-06-16T09:55:27
190,860,083
39
9
null
2023-02-09T04:31:54
2019-06-08T07:43:53
Java
UTF-8
C
false
false
121
h
SKInvalidation.h
../../../../FlipperKit/iOS/Plugins/FlipperKitPluginUtils/FlipperKitLayoutHelpers/FlipperKitLayoutHelpers/SKInvalidation.h
42b688c844ac7e9d9947e0a86511c45bc5fc3a01
e10614f4b6a2183709dd197fea6f9298be2678c1
/1819Fall/COMP2012H/PAs/PA2/Stock_skeleton_full_declarations/Stock.h
351f6a677050882b6ff1ad1e0a189d051ebfa330
[]
no_license
cokenhe/hkust-comp-material
63a267fff783e6ff53eeaeeeb8ad44599dd23c72
43af76fcdf9c47996a9ddd0e7b76b9d99ef8df3c
refs/heads/main
2023-05-06T18:40:29.057754
2021-05-20T10:45:55
2021-05-20T10:45:55
334,102,018
5
0
null
null
null
null
UTF-8
C
false
false
308
h
Stock.h
// do NOT submit this file // do NOT modify this file #ifndef SRC_STOCK_H_ #define SRC_STOCK_H_ // Stock has an ID and a value. struct Stock { const int stockId; // The stock's ID. It is -1 for the sentinel head StockNode. double value; // The stock's value. }; #endif /* SRC_STOCK_H_ */
d32ee80dc6a8c5371a476bb09d10ac0b39b1879c
6181d846ba72e1dfb9908c6d19a420c3ae2fcfcb
/IdentificadorDoCaminhoDireto.c
0e7873332e58f66a65d7f8fdb5e2356bcf89662d
[]
no_license
heitormasson/CanceladorAtivoDeRuido
4d8cd719d128cca152f357b3ea7af8860d9d9c5e
2623327ae0fe5f9aacf50c5d73d6b812e8f9efd0
refs/heads/main
2023-04-11T19:01:02.900790
2022-02-03T00:37:45
2022-02-03T00:37:45
454,974,670
0
0
null
null
null
null
UTF-8
C
false
false
10,626
c
IdentificadorDoCaminhoDireto.c
// FILE: Lab2_cpu01.c #include "F28x_Project.h" // Device Header File and Examples Include File #include "FIRFilter.h" #include "AdaptativeFIR.h" #define OUT_BUFFER_SIZE 256 // Function Prototypes void ConfigureADC(void); void ConfigureEPWM(void); void ConfigureDAC(void); void SetupADCEpwm(void); Uint16 calcMedia(Uint16 *vetor); Uint16 randNum(Uint16 seed); void ConfigureADC2(void); //void ConfigureADC2(void); interrupt void adca1_isr(void); //interrupt void adcb1_isr(void); // Variables #define RESULTS_BUFFER_SIZE 256 Uint16 AdcaResults[RESULTS_BUFFER_SIZE]; float input_data_buffer[LMS_FILTER_LENGTH]; float last_value; Uint16 inputsIndex; Uint16 DACoutNumber; float idealRef; float lmsErro; int AdcaResults2[RESULTS_BUFFER_SIZE]; float saida_filtro[OUT_BUFFER_SIZE]; Uint16 adaptWeights; Uint16 countSaida; Uint16 sin_index = 0; Uint16 dest_index = 0; Uint16 sin_divider = 2; Uint16 sin_deph = 16; Uint16 resultsIndex; Uint16 resultsIndex2; Uint16 ToggleCount = 0; Uint16 dacOffset; Uint16 dacOutput; Uint16 dacOutput2; Uint16 sineEnable = 0; Uint16 sineEnable2 = 0; FIRFilter lpfMic; //LMSFIR secPathFilt; extern int QuadratureTable[40]; void main(void) { // Initialize System Control InitSysCtrl(); FIRFilter_Init(&lpfMic); // LMSFIR_Init(&secPathFilt); EALLOW; ClkCfgRegs.PERCLKDIVSEL.bit.EPWMCLKDIV = 1; EDIS; // Initialize GPIO InitGpio(); // Configure default GPIO EALLOW; GpioCtrlRegs.GPADIR.bit.GPIO18 = 1; // Used as input to ADC GpioCtrlRegs.GPADIR.bit.GPIO31 = 1; // Drives LED LD2 on controlCARD EDIS; GpioDataRegs.GPADAT.bit.GPIO18 = 0; // Force GPIO18 output LOW GpioDataRegs.GPADAT.bit.GPIO31 = 1; // Turn off LED // Clear all interrupts and initialize PIE vector table DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000; InitPieVectTable(); // Map ISR functions EALLOW; PieVectTable.ADCA1_INT = &adca1_isr; // Function for ADCA interrupt 1 // PieVectTable.ADCB1_INT = &adcb1_isr; // Function for ADCA interrupt 1 EDIS; // Configure the ADC and power it up ConfigureADC(); // Configure the ePWM ConfigureEPWM(); // Configure DAC-B ConfigureDAC(); // Setup the ADC for ePWM triggered conversions on channel 0 SetupADCEpwm(); // Initialize results buffer for(resultsIndex = 0; resultsIndex < RESULTS_BUFFER_SIZE; resultsIndex++) { AdcaResults[resultsIndex] = 0; AdcaResults2[resultsIndex] = 0; } resultsIndex = 0; for(inputsIndex = 0; inputsIndex < LMS_FILTER_LENGTH; inputsIndex++) { input_data_buffer[inputsIndex] = 0.0f; } inputsIndex = 0; DACoutNumber = 0; idealRef = 0; adaptWeights = 0; for(countSaida=0; countSaida < 64; countSaida++) saida_filtro[countSaida]= 0.0f; countSaida=0; // Enable PIE interrupt PieCtrlRegs.PIEIER1.bit.INTx1 = 1; // Enable global interrupts and higher priority real-time debug events IER |= M_INT1; // Enable group 1 interrupts EINT; // Enable Global interrupt INTM ERTM; // Enable Global real-time interrupt DBGM // Sync ePWM EALLOW; CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; // Start ePWM EPwm2Regs.TBCTL.bit.CTRMODE = 0; // Un-freeze and enter up-count mode do { GpioDataRegs.GPADAT.bit.GPIO31 = 0; // Turn on LED DELAY_US(1000 * 500); // ON delay GpioDataRegs.GPADAT.bit.GPIO31 = 1; // Turn off LED DELAY_US(1000 * 500); // OFF delay } while(1); } Uint16 calcMedia(Uint16 *vetor){ unsigned long soma = 0; unsigned short i; for(i=0; i<RESULTS_BUFFER_SIZE; i++) soma = soma + vetor[i]; soma = soma/RESULTS_BUFFER_SIZE; return (Uint16) soma; } Uint16 randNum(Uint16 seed){ return (161*seed + 62)%2048; } // Write ADC configurations and power up the ADC for both ADC A and ADC B void ConfigureADC(void) { EALLOW; AdcaRegs.ADCCTL2.bit.PRESCALE = 6; // Set ADCCLK divider to /4 AdcaRegs.ADCCTL2.bit.RESOLUTION = 0; // 12-bit resolution AdcaRegs.ADCCTL2.bit.SIGNALMODE = 0; // Single-ended channel conversions (12-bit mode only) AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1; // Set pulse positions to late AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1; // Power up the ADC // AdcbRegs.ADCCTL2.bit.PRESCALE = 6; // Set ADCCLK divider to /4 // AdcbRegs.ADCCTL2.bit.RESOLUTION = 0; // 12-bit resolution // AdcbRegs.ADCCTL2.bit.SIGNALMODE = 0; // Single-ended channel conversions (12-bit mode only) // AdcbRegs.ADCCTL1.bit.INTPULSEPOS = 1; // Set pulse positions to late // AdcbRegs.ADCCTL1.bit.ADCPWDNZ = 1; // Power up the ADC DELAY_US(1000); // Delay for 1ms to allow ADC time to power up EDIS; } void ConfigureEPWM(void) { EALLOW; // Assumes ePWM clock is already enabled EPwm2Regs.TBCTL.bit.CTRMODE = 3; // Freeze counter EPwm2Regs.TBCTL.bit.HSPCLKDIV = 0; // TBCLK pre-scaler = /1 EPwm2Regs.TBPRD = 0x07D0; // Set period to 2000 counts (50kHz) EPwm2Regs.ETSEL.bit.SOCAEN = 0; // Disable SOC on A group EPwm2Regs.ETSEL.bit.SOCASEL = 2; // Select SOCA on period match EPwm2Regs.ETSEL.bit.SOCAEN = 1; // Enable SOCA // EPwm2Regs.ETPS.bit.SOCAPRD = 1; // Generate pulse on 1st event EPwm2Regs.ETPS.bit.SOCAPRD = ET_1ST; // Generate pulse on 1st event EDIS; } void ConfigureDAC(void) { EALLOW; DacbRegs.DACCTL.bit.DACREFSEL = 1; // Use ADC references DacbRegs.DACCTL.bit.LOADMODE = 0; // Load on next SYSCLK DacbRegs.DACVALS.all = 0x0800; // Set mid-range DacbRegs.DACOUTEN.bit.DACOUTEN = 1; // Enable DAC DacaRegs.DACCTL.bit.DACREFSEL = 1; // Use ADC references DacaRegs.DACCTL.bit.LOADMODE = 0; // Load on next SYSCLK DacaRegs.DACVALS.all = 0x0800; // Set mid-range DacaRegs.DACOUTEN.bit.DACOUTEN = 1; // Enable DAC EDIS; } void SetupADCEpwm(void) { EALLOW; AdcaRegs.ADCSOC0CTL.bit.CHSEL = 2; // SOC0 will convert pin A0 AdcaRegs.ADCSOC0CTL.bit.ACQPS = 14; // Sample window is 100 SYSCLK cycles AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 7; // Trigger on ePWM2 SOCA/C AdcaRegs.ADCSOC1CTL.bit.CHSEL = 3; // SOC0 will convert pin A0 AdcaRegs.ADCSOC1CTL.bit.ACQPS = 14; // Sample window is 100 SYSCLK cycles AdcaRegs.ADCSOC1CTL.bit.TRIGSEL = 7; // Trigger on ePWM2 SOCA/C AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0x01; // End of SOC0 will set INT1 flag AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Make sure INT1 flag is cleared // AdcbRegs.ADCSOC1CTL.bit.CHSEL = 2; // SOC0 will convert pin A0 // AdcbRegs.ADCSOC1CTL.bit.ACQPS = 14; // Sample window is 100 SYSCLK cycles // AdcbRegs.ADCSOC1CTL.bit.TRIGSEL = 7; // Trigger on ePWM2 SOCA/C // // AdcbRegs.ADCINTSEL1N2.bit.INT1SEL = 0; // End of SOC0 will set INT1 flag // AdcbRegs.ADCINTSEL1N2.bit.INT1E = 1; // Enable INT1 flag // AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Make sure INT1 flag is cleared EDIS; } interrupt void adca1_isr(void) { // Read the ADC result and store in circular buffer //Uint16 var = AdcaResultRegs.ADCRESULT0 - 1700; //var = var*20; AdcaResults2[resultsIndex] = AdcaResultRegs.ADCRESULT1; AdcaResults[resultsIndex++] = AdcaResultRegs.ADCRESULT0; int temporario = (int) AdcaResultRegs.ADCRESULT0 - (int) calcMedia(AdcaResults); float temp_ = (float) temporario; temp_ = temp_ / 2045.0f; FIRFilter_Update(&lpfMic, temp_); // temp_ = lpfMic.out*2045.0; // input_data_buffer[inputsIndex++] = lpfMic.out; // input_data_buffer[inputsIndex++] = temp_; //// // LMSFIR_Output(&secPathFilt, input_data_buffer, inputsIndex); // lmsErro = secPathFilt.out - idealRef; //// // saida_filtro[countSaida++] = secPathFilt.out; saida_filtro[countSaida++] = lpfMic.out; //// // if (adaptWeights != 0){ // LMSFIR_UpdateW(&secPathFilt, idealRef, input_data_buffer, inputsIndex); // } // lmsErro = secPathFilt.curr_error; if (countSaida>=OUT_BUFFER_SIZE){ countSaida=0; } // sinal aleatorio para identificacao do sistema // DACoutNumber = randNum(DACoutNumber); // exemplo de filtro digital passa baixa para display // FIRFilter_Update(&lpfMic, temp_); // temp_ = lpfMic.out*2045.0; // temporario = (int) temp_; // AdcaResults2[resultsIndex] = temporario; if(LMS_FILTER_LENGTH <= inputsIndex) { inputsIndex = 0; } if(RESULTS_BUFFER_SIZE <= resultsIndex) { resultsIndex = 0; } if (resultsIndex % sin_divider == 0){ sin_index ++; } if(RESULTS_BUFFER_SIZE <= sin_index){ sin_index = 0; } // Toggle GPIO18 so we can read it with the ADC if (ToggleCount++ >= 15) { GpioDataRegs.GPATOGGLE.bit.GPIO18 = 1; ToggleCount = 0; } // Write to DACB to create input to ADC-A0 if (sineEnable != 0) { dacOutput = dacOffset + ((QuadratureTable[sin_index % 0x20] ^ 0x8000) >> 5); } else { dacOutput = dacOffset; } if (sineEnable2 != 0) { dacOutput2 = dacOffset + ((QuadratureTable[(sin_index +sin_deph )% 0x20] ^ 0x8000) >> 5); } else { dacOutput2 = dacOffset; } if (sineEnable == 0){ DACoutNumber = 0; } // DacbRegs.DACVALS.all = DACoutNumber; DacbRegs.DACVALS.all = dacOutput; int normalizado = DACoutNumber-1023; idealRef = (float) normalizado/1024.0f; // DacbRegs.DACVALS.all = dacOutput; // DacaRegs.DACVALS.all = dacOutput2; // DacaRegs.DACVALS.all = (temporario>>5); // Return from interrupt AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Clear ADC INT1 flag PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge PIE group 1 to enable further interrupts } //interrupt void adcb1_isr(void) //{ // // Read the ADC result and store in circular buffer // //Uint16 var = AdcaResultRegs.ADCRESULT0 - 1700; // //var = var*20; // AdcaResults2[resultsIndex2++] = AdcbResultRegs.ADCRESULT0; //// AdcaResults2[resultsIndex] = AdcaResultRegs.ADCRESULT1; // if(RESULTS_BUFFER_SIZE <= resultsIndex2) // { // resultsIndex2 = 0; // } // // // // Return from interrupt // AdcbRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; // Clear ADC INT1 flag // PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; // Acknowledge PIE group 1 to enable further interrupts //} // end of file
f44327e1af34aad1846b3de637c365c8dea0aef3
8c4d080b1f58fd44d0c2a19110aaf8ad5764694e
/Sources/create_env.c
d6c37011c1211eeb4a10291863bd0390062ffbde
[ "MIT" ]
permissive
TheWeaklessOne/conf_reader
3b3529c20778415e8171c1791da626e47013fbb1
fadf6c85f033b6c535d728d1a2b87c3677b4cff8
refs/heads/master
2023-01-27T11:54:21.266001
2020-12-10T15:02:45
2020-12-10T15:02:45
257,278,777
2
0
null
null
null
null
UTF-8
C
false
false
2,610
c
create_env.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* create_env.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wstygg <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/07 12:52:19 by wstygg #+# #+# */ /* Updated: 2020/06/02 14:54:00 by wstygg ### ########.fr */ /* */ /* ************************************************************************** */ #include "conf.h" static void *splitr(char **split, void *ret) { ft_free_split(split); return (ret); } static char *read_content(char *content, int i) { char *ret; char **split; split = ft_strsplit(content); if (split[0][strlen(split[0]) - 1] != ':') { ft_error("Error at [%d] line: %s\n\':\' symbol have to be in the end " "of %s!\n", i + 1, content, split[0]); return (splitr(split, NULL)); } split[0][strlen(split[0]) - 1] = '\0'; if (!split[1]) { ft_error("Error at [%d] line: %s\nNo content after \"%s\"!\n", i + 1, content, split[0]); return (splitr(split, NULL)); } if (ft_split_size(split) > 2) { ft_error("Error at [%d] line: %s\nThere have to be only one content " "after \"%s\"!\n", i + 1, content, split[0]); return (splitr(split, NULL)); } ret = ft_strjoin(ft_strjoin(split[0], " = ", 0), split[1], 1); return (splitr(split, ret)); } static int count_content(char **conf, int i) { int ret; ret = 0; while (tab_count(conf[i++]) == 2) ret++; return (ret); } void create_env(t_task *task, char **conf, int *i) { char *content; char **split; char **env; register int k; split = ft_strsplit(conf[*i]); if (ft_split_size(split) != 1 && ft_error("Error at [%d] line: %s\nContent" " for env should have 2 tab depth!\n", *i + 1, conf[*i])) return (ft_free_split(split)); k = -1; (*i)++; env = ft_malloc(sizeof(char*) * (count_content(conf, *i) + 1)); while (!str_is_empty(conf[*i]) && tab_count(conf[*i]) == 2) { if ((content = read_content(conf[*i], *i))) env[++k] = content; (*i)++; } if (!env[0] && ft_error("Env content not provided!\n")) free(env); else task->env = env; (*i)--; ft_free_split(split); }
28f37daa2044564b2bffa90b69c8627af23df654
dbf36d4f9347e275543ac89ce81f7775247efc09
/bin/xbps-bin/check_pkg_requiredby.c
fdaefebf0d5b557920b7a832705bcca49a9ce2ba
[ "BSD-3-Clause", "ISC", "BSD-2-Clause", "LicenseRef-scancode-bsd-unchanged" ]
permissive
xdave/xbps
3194e2e135acb8b9f8de4e77acd51f0f77a25950
efe6d4ff949c0241d59fb04b446e48d0a50f874f
refs/heads/master
2020-12-25T13:24:30.575068
2012-10-02T09:02:52
2012-10-02T09:02:52
6,042,203
4
0
null
null
null
null
UTF-8
C
false
false
6,401
c
check_pkg_requiredby.c
/*- * Copyright (c) 2011-2012 Juan Romero Pardines. * 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 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. */ #include <stdio.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <sys/param.h> #include <xbps_api.h> #include "defs.h" struct check_reqby_data { prop_dictionary_t pkgd; prop_array_t pkgd_reqby; const char *pkgname; const char *pkgver; bool pkgd_reqby_alloc; }; static int check_reqby_pkg_cb(struct xbps_handle *xhp, prop_object_t obj, void *arg, bool *done) { struct check_reqby_data *crd = arg; prop_array_t curpkg_rdeps, provides; prop_dictionary_t curpkg_propsd; prop_string_t curpkgver; const char *curpkgn; (void)done; prop_dictionary_get_cstring_nocopy(obj, "pkgname", &curpkgn); /* skip same pkg */ if (strcmp(curpkgn, crd->pkgname) == 0) return 0; /* * Internalize current pkg props dictionary from its * installed metadata directory. */ curpkg_propsd = xbps_dictionary_from_metadata_plist(xhp, curpkgn, XBPS_PKGPROPS); if (curpkg_propsd == NULL) { xbps_error_printf("%s: missing %s metadata file!\n", curpkgn, XBPS_PKGPROPS); return -1; } curpkg_rdeps = prop_dictionary_get(curpkg_propsd, "run_depends"); if (curpkg_rdeps == NULL) { /* package has no rundeps, skip */ prop_object_release(curpkg_propsd); return 0; } /* * Check for pkgpattern match with real packages... */ if (!xbps_match_pkgdep_in_array(curpkg_rdeps, crd->pkgver)) { /* * ... otherwise check if package provides any virtual * package and is matched against any object in * run_depends. */ provides = prop_dictionary_get(obj, "provides"); if (provides == NULL) { /* doesn't provide any virtual pkg */ prop_object_release(curpkg_propsd); return 0; } if (!xbps_match_any_virtualpkg_in_rundeps(curpkg_rdeps, provides)) { /* doesn't match any virtual pkg */ prop_object_release(curpkg_propsd); return 0; } } crd->pkgd_reqby = prop_dictionary_get(crd->pkgd, "requiredby"); curpkgver = prop_dictionary_get(curpkg_propsd, "pkgver"); if (crd->pkgd_reqby != NULL) { /* * Now check that current pkgver has been registered into * its requiredby array. */ if (xbps_match_string_in_array(crd->pkgd_reqby, prop_string_cstring_nocopy(curpkgver))) { /* * Current package already requires our package, * this is good so skip it. */ prop_object_release(curpkg_propsd); return 0; } } else { /* * Missing requiredby array object, create it. */ crd->pkgd_reqby = prop_array_create(); if (crd->pkgd_reqby == NULL) { prop_object_release(curpkg_propsd); return -1; } crd->pkgd_reqby_alloc = true; } /* * Added pkgdep into pkg's requiredby array. */ if (!prop_array_add(crd->pkgd_reqby, curpkgver)) { prop_object_release(curpkg_propsd); return -1; } printf("%s: added missing requiredby entry for %s.\n\n", crd->pkgver, prop_string_cstring_nocopy(curpkgver)); prop_object_release(curpkg_propsd); return 1; } /* * Removes unused entries in pkg's requiredby array. */ static bool remove_stale_entries_in_reqby(struct xbps_handle *xhp, struct check_reqby_data *crd) { prop_array_t reqby; prop_dictionary_t pkgd; const char *str; size_t i; bool needs_update = false; reqby = prop_dictionary_get(crd->pkgd, "requiredby"); if (reqby == NULL || prop_array_count(reqby) == 0) return false; crd->pkgd_reqby = prop_dictionary_get(crd->pkgd, "requiredby"); for (i = 0; i < prop_array_count(reqby); i++) { prop_array_get_cstring_nocopy(reqby, i, &str); if ((pkgd = xbps_pkgdb_get_pkgd_by_pkgver(xhp, str)) != NULL) continue; printf("%s: found stale entry in requiredby `%s' (fixed)\n", crd->pkgver, str); if (xbps_remove_string_from_array(xhp, crd->pkgd_reqby, str)) needs_update = true; } if (needs_update) { prop_dictionary_set(crd->pkgd, "requiredby", crd->pkgd_reqby); printf("%s: requiredby fix done!\n\n", crd->pkgver); return true; } return false; } /* * Checks package integrity of an installed package. * The following task is accomplished in this file: * * o Check for missing reverse dependencies (aka requiredby) * entries in pkg's pkgdb dictionary. * * Returns 0 if test ran successfully, 1 otherwise and -1 on error. */ int check_pkg_requiredby(struct xbps_handle *xhp, const char *pkgname, void *arg, bool *pkgdb_update) { prop_dictionary_t pkgd = arg; struct check_reqby_data crd; int rv; crd.pkgd = pkgd; crd.pkgd_reqby = NULL; crd.pkgd_reqby_alloc = false; crd.pkgname = pkgname; prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &crd.pkgver); /* missing reqby entries in pkgs */ rv = xbps_pkgdb_foreach_cb(xhp, check_reqby_pkg_cb, &crd); if (rv < 0) { return rv; } else if (rv == 1) { *pkgdb_update = true; prop_dictionary_set(pkgd, "requiredby", crd.pkgd_reqby); if (crd.pkgd_reqby_alloc) prop_object_release(crd.pkgd_reqby); printf("%s: requiredby fix done!\n\n", crd.pkgver); } /* remove stale entries in pkg's reqby */ if (remove_stale_entries_in_reqby(xhp, &crd)) *pkgdb_update = true; return 0; }
a231edac4ee80970e94d60227d2d4aed760801a6
a139bd78c1ea8017649a205f24f26a92f38d49eb
/TBDraw/AppGeneral/AppDefine/NetworkAPI.h
fcf3e3ddcee9af7716222a891f66757c9b675761
[]
no_license
xcysuccess/TBDraw
7672a75545bc24d6ce50ae8b6014f82d48325ba5
fb28d3928cfccc7aaed9f0141dfdb2f4b5f240f8
refs/heads/master
2021-01-16T20:30:29.247091
2014-08-29T04:42:27
2014-08-29T04:42:27
null
0
0
null
null
null
null
UTF-8
C
false
false
227
h
NetworkAPI.h
// // NetworkAPI.h // TBAPP // // Created by 向晨宇 on 14-4-10. // Copyright (c) 2014年 Kingsoft. All rights reserved. // 定义项目里的网络接口 #ifndef TBAPP_NetworkAPI_h #define TBAPP_NetworkAPI_h #endif
5b14c572312d0530fd45664c0d573ca44057e660
6ebbd3c38c198d8561ac9ee9410c1bb09d549942
/ThirdPartyLibrariesAL/LWIP/LwipControlHandler/Core/Trunk/LwipControlHandler.h
078983f740927bfdebedea2c9a776e135aa55ba1
[]
no_license
liwei12400/SoftwareLibraries
5596921dc6f0044c803525a35cabf9d8019ad08d
2a9e8fb761beb528920fb0eec27f7e2f6a94f223
refs/heads/master
2023-02-19T05:32:15.455978
2021-01-20T19:32:09
2021-01-20T19:32:09
null
0
0
null
null
null
null
UTF-8
C
false
false
3,055
h
LwipControlHandler.h
/****************************************************************************** * @file LwipControlHandler.h * * @brief Stellaris LWIP handler declarations * * This file provides the declarations for the ethernet handler * * @copyright Copyright (c) 2012 Cyber Intergration * This document contains proprietary data and information of Endurance Products * LLC. It is the exclusive property of Endurance Products, LLC and will not be * disclosed in any form to any party without prior written permission of * Endurance Products, LLC. This document may not be reproduced or further used * without the prior written permission of Endurance Products, LLC. * * Version History * ====== * $Log: $ * * * \addtogroup LwipControlHandler * @{ *****************************************************************************/ // ensure only one instantiation #ifndef _LWIPCONTROLHANDLER_H #define _LWIPCONTROLHANDLER_H // system includes ------------------------------------------------------------ #if (SYSTEMDEFINE_OS_SELECTION == SYSTEMDEFINE_OS_TASKMANAGER ) #include "TaskManager/TaskManager.h" #endif // local includes ------------------------------------------------------------- #include "LwipControlHandler/LwipControlHandler_cfg.h" // library includes ----------------------------------------------------------- #include "lwip/api.h" #include "lwip/dhcp.h" #include "lwip/mem.h" #include "lwip/opt.h" #include "lwip/tcp.h" #include "lwip/udp.h" #if ( LWIPCONTROLHANDLER_ENABLE_DEBUGCMDS == 1 ) #include "AsciiCommandHandler/AsciiCommandHandler.h" #endif // LWIPCONTROLHANDLER_ENABLE_DEBUGCMDS // Macros and Defines --------------------------------------------------------- // enumerations --------------------------------------------------------------- /// enuemrate the errors typedef enum _LWIPERRORS { LWIP_ERROR_NONE = 0, ///< no error LWIP_ERROR_ILLMODE, ///< illegal mode } LWIPERRORS; // structures ----------------------------------------------------------------- // global parameter declarations ----------------------------------------------- #if ( LWIPCONTROLHANDLER_ENABLE_DEBUGCMDS == 1 ) /// initialize the command table extern const CODE ASCCMDENTRY atLwipHandlerCmdTable[ ]; #endif // LWIPCONTROLHANDLER_ENABLE_DEBUGCMDS // global function prototypes -------------------------------------------------- extern void LwipControlHandler_Initialize( void ); extern PLWIPCFGDEF LwipControlHandler_GetConfigDflt( void ); extern PLWIPCFGDEF LwipControlHandler_GetConfigActl( void ); extern void LwipControlHandler_Configure( void ); extern LWIPERRORS LwipControlHandler_SetConfig( PLWIPCFGDEF ptLwipCfgDef ); extern void LwipControlHandler_GetMacAddr( PU8 pnMacAddress ); extern void LwipControlHandler_SetMacAddr( PU8 pnMacAddress ); extern void LwipControlHandler_GetCurrentNetConfig( PLWIPCFGDEF ptLwipCfgDef ); extern void LwipControlHandler_ProcessTimer( void ); /**@} EOF LwipControlHandler.h */ #endif // _LWIPCONTROLHANDLER_H
d75fea0898d91c02d027811784c7dc4b37ab4856
3852cd1bd5e282dd23b8f7c64309cc2f598e3b75
/personal/c++/PirateTactics/Classes/MainScreen.h
47f23857f83fb10797a574e37e3bc162420ce505
[]
no_license
chandl34/public
4e6ca43afa410cd50f54f93d589a1784f51b55dc
e288ac323166f5170aaac7cd97d37dabffa70090
refs/heads/master
2021-08-18T05:42:00.234407
2021-07-29T02:43:03
2021-07-29T02:43:03
2,938,300
0
2
null
null
null
null
UTF-8
C
false
false
154
h
MainScreen.h
/* * MainScreen.h * Pirate Tactics * * Created by Jonathan Chandler on 2/19/10. * Copyright 2010 __MyCompanyName__. All rights reserved. * */
5911945090ef154ac2f4ab9417a224d95aa8688c
e3cdfae1dd874479c928dad193b33a4e3b8a623e
/src/classchg-menuselect.c
395a1152a326602bc34dd50972ce58a081622025
[]
no_license
FireEmblemUniverse/fireemblem8u
11493bf94844617b33254110ba006316defb3510
b9ad9bcafd9d4ecb7fc13cc77a464e2a82ac8338
refs/heads/master
2023-09-05T23:39:53.791339
2023-09-04T17:31:47
2023-09-04T17:31:47
121,802,075
118
31
null
2023-09-11T13:08:37
2018-02-16T21:21:50
Assembly
UTF-8
C
false
false
7,243
c
classchg-menuselect.c
#include "global.h" #include "classchg.h" #include "uimenu.h" #include "fontgrp.h" #include "bmunit.h" #include "proc.h" #include "hardware.h" #include "bmarch.h" #include "scene.h" #include "constants/classes.h" u32 ClassChgMenuSelOnInit(struct MenuProc *proc) { SyncMenuBgs(proc); return 0; } u32 ClassChgMenuSelOnEnd(struct MenuProc *proc) { SyncMenuBgs(proc); return 0; } u8 ClassChgMenuItem_OnSelect(struct MenuProc *pmenu, struct MenuItemProc *pmitem) { struct ProcClassChgMenuSel *parent; struct ProcPromoSel *gparent; struct ProcPromoMain *ggparent; parent = pmenu->proc_parent; gparent = parent->proc_parent; ggparent = gparent->proc_parent; if (gparent->stat == 0) { struct Unit *unit = GetUnitFromCharId(ggparent->pid); u8 classnumber = unit->pClassData->number; if (pmitem->itemNumber <= 1) { classnumber = gPromoJidLut[classnumber][pmitem->itemNumber]; ggparent->jid = classnumber; } else { if (pmitem->itemNumber == 2) { switch (classnumber) { case CLASS_JOURNEYMAN: ggparent->jid = CLASS_JOURNEYMAN_T1; break; case CLASS_PUPIL: ggparent->jid = CLASS_PUPIL_T1; break; case CLASS_RECRUIT: ggparent->jid = CLASS_RECRUIT_T1; break; default: ggparent->jid = classnumber; break; } } } switch ((u8) ggparent->jid) { case CLASS_RANGER: case CLASS_RANGER_F: if (unit->state & US_IN_BALLISTA) { TryRemoveUnitFromBallista(unit); } break; } InitTextFont(&gFontClassChgMenu, (void *)BG_VRAM + 0x1000, 0x80, 0x5); TileMap_FillRect(TILEMAP_LOCATED(gBG0TilemapBuffer, 9, 4), 0xA, 0x6, 0); BG_EnableSyncByMask(BG0_SYNC_BIT); StartMenuExt(&Menu_PromoSubConfirm, 2, 0, 0, 0, pmenu); } return 0; } u8 ClassChgMenuSelOnPressB(struct MenuProc *pmenu, struct MenuItemProc *pmitem) { struct ProcClassChgMenuSel *parent; struct ProcPromoSel *gparent; struct ProcPromoMain *ggparent; struct ProcPromoHandler *gggparent; parent = pmenu->proc_parent; gparent = parent->proc_parent; ggparent = gparent->proc_parent; gggparent = ggparent->proc_parent; if (gggparent->bmtype == PROMO_HANDLER_TYPE_TRANINEE) return 0; if (gggparent->bmtype == PROMO_HANDLER_TYPE_BM) { Proc_End(parent); Proc_Goto(gparent, PROC_CLASSCHG_SEL_2); return MENU_ACT_SKIPCURSOR | MENU_ACT_END | MENU_ACT_SND6B; } if (gggparent->bmtype == PROMO_HANDLER_TYPE_PREP) { Proc_End(parent); Proc_Goto(gparent, PROC_CLASSCHG_SEL_2); return MENU_ACT_SKIPCURSOR | MENU_ACT_END | MENU_ACT_SND6B;; } return 0; } void ClassChgMenuOnDrawCore(struct MenuProc *pmenu, struct MenuItemProc *pmitem, char *str) { u8 unused_stack[32]; u16 *mapbuf; if (pmitem->def->color) Text_SetColor(&pmitem->text, pmitem->def->color); if (pmitem->availability == MENU_DISABLED) Text_SetColor(&pmitem->text, TEXT_COLOR_SYSTEM_GRAY); ClearTextPart(&pmitem->text, 0, 20); Text_SetCursor(&pmitem->text, 8); Text_DrawString(&pmitem->text, str); mapbuf = BG_GetMapBuffer(pmenu->frontBg); PutText(&pmitem->text, &mapbuf[pmitem->yTile * 32 + pmitem->xTile]); } int ClassChgMenuItem_OnTextDraw(struct MenuProc *pmenu, struct MenuItemProc *pmitem) { u8 unused_stack[0x48]; struct ProcClassChgMenuSel *parent; struct ProcPromoSel *gparent; parent = pmenu->proc_parent; gparent = parent->proc_parent; ClassChgMenuOnDrawCore(pmenu, pmitem, GetStringFromIndex(GetClassData(gparent->jid[pmitem->itemNumber])->nameTextId)); } int ClassChgMenuItem_OnChange(struct MenuProc *pmenu, struct MenuItemProc *pmitem) { struct ProcClassChgMenuSel *parent; struct ProcPromoSel *gparent; parent = pmenu->proc_parent; gparent = parent->proc_parent; gparent->stat = 1; gparent->menu_index = pmitem->itemNumber; ChangeClassDescription(gparent->msg_desc[gparent->menu_index]); SetTalkPrintDelay(-1); } u8 ClassChgMenuItem_3rdUsability(const struct MenuItemDef * _def, int _number) { struct ProcClassChgMenuSel *proc = Proc_Find(ProcScr_ClassChgMenuSel); struct ProcPromoSel *parent = proc->proc_parent; struct ProcPromoMain *gparent = parent->proc_parent; if (Check3rdTraineeEnabled()) { switch (GetUnitFromCharId(gparent->pid)->pClassData->number) { case CLASS_JOURNEYMAN: case CLASS_PUPIL: case CLASS_RECRUIT: return MENU_ENABLED; default: return MENU_NOTSHOWN; } } return MENU_NOTSHOWN; } CONST_DATA struct MenuItemDef gMenuItem_PromoSel[] = { { " 第1兵種", 0, 0x6DC, /* Discard items. Important[NL]items cannot be discarded. */ TEXT_COLOR_SYSTEM_WHITE, 0, MenuAlwaysEnabled, ClassChgMenuItem_OnTextDraw, ClassChgMenuItem_OnSelect, 0, ClassChgMenuItem_OnChange, 0 }, { " 第2兵種", 0, 0x6DC, /* Discard items. Important[NL]items cannot be discarded. */ TEXT_COLOR_SYSTEM_WHITE, 1, MenuAlwaysEnabled, ClassChgMenuItem_OnTextDraw, ClassChgMenuItem_OnSelect, 0, ClassChgMenuItem_OnChange, 0 }, { " 第3兵種", 0, 0x6DC, /* Discard items. Important[NL]items cannot be discarded. */ TEXT_COLOR_SYSTEM_WHITE, 2, ClassChgMenuItem_3rdUsability, ClassChgMenuItem_OnTextDraw, ClassChgMenuItem_OnSelect, 0, ClassChgMenuItem_OnChange, 0 }, {0} }; CONST_DATA struct MenuDef gMenuDef_PromoSel = { .rect = { 16, 2, 8, 0 }, .menuItems = gMenuItem_PromoSel, .onInit = (void(*)(struct MenuProc*)) ClassChgMenuSelOnInit, .onEnd = (void(*)(struct MenuProc*)) ClassChgMenuSelOnEnd, .onBPress = ClassChgMenuSelOnPressB, }; CONST_DATA struct ProcCmd ProcScr_ClassChgMenuSel[] = { PROC_SLEEP(6), PROC_NAME("CCRamifyMenuSelect"), PROC_CALL(ClassChgMenuExec), PROC_REPEAT(nullsub_80CDDD4), PROC_YIELD, PROC_LABEL(0), PROC_GOTO(2), PROC_LABEL(1), PROC_CALL(nullsub_61), PROC_LABEL(2), PROC_END, }; CONST_DATA struct MenuRect ClassChgMenuRect = { .x = 1, .y = 1, .w = 12, .h = 0 }; void ClassChgMenuExec(struct ProcClassChgMenuSel *proc) { proc->unk4C = 0; ResetTextFont(); ResetText(); SetTextFontGlyphs(0); InitTextFont(&gFontClassChg, (void *)BG_VRAM + 0x1400, 160, 5); SetTextFont(&gFontClassChg); proc->pmenu = StartMenuCore( &gMenuDef_PromoSel, ClassChgMenuRect, 2, 0, 0, 0, (struct Proc *) proc); } void nullsub_80CDDD4(void) { return; } void nullsub_61(void) { return; } ProcPtr NewClassChgMenuSelect(ProcPtr parent) { return Proc_Start(ProcScr_ClassChgMenuSel, parent); }
9c1d15c7f42b9e998fe20d7bf8655356f08d8e3e
05ccdc8a0d4f3166669994e12ab5c4b5dd614465
/srv/ne2000/ne2000.h
a046066efb2dbf33434a44f232adc15e92ec0aa2
[ "BSD-3-Clause" ]
permissive
zhouxs1023/openblt
1d31b0d4e586efe5d4952298b2637b6ca7816752
78ce5be085831ba17020bb38c542bbcb33b8e54d
refs/heads/master
2021-07-10T08:15:23.248394
2019-11-18T10:54:07
2019-11-18T10:54:07
222,426,268
1
0
null
null
null
null
UTF-8
C
false
false
7,977
h
ne2000.h
/* $Id: //depot/blt/srv/ne2000/ne2000.h#2 $ ** ** Copyright 1998 Brian J. Swetland ** 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. 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 __NE2000_SHARED_CODE_BASE #define __NE2000_SHARED_CODE_BASE typedef unsigned int uint; typedef struct snic snic; typedef struct nic_stat nic_stat; typedef struct buffer_header buffer_header; typedef struct packet_data packet_data; typedef struct packet_buffer packet_buffer; typedef struct nic_error_stat nic_error_stat; /* internal implementation procedures */ int nic_probe(int addr); int nic_dump_prom(snic *nic, unsigned char *prom); void nic_overrun(snic *nic); void nic_tx(snic *nic); void nic_tx_err(snic *nic); void nic_rx(snic *nic); void nic_counters(snic *nic); void nic_get_header(snic *nic, uint page, buffer_header *header); int nic_send(snic *nic, uint buf); void nic_block_input(snic *nic, unsigned char *buf, uint len, uint offset); void nic_block_output(snic *nic, packet_buffer *pkt); #define PSTART 0x20 /* if NE2000 is byte length */ #define PSTOP 0x40 #define PSTARTW 0x40 /* if NE2000 is wordlength */ #define PSTOPW 0x80 #define MAX_LOAD 12 /* maximum services per IRQ request*/ #define MAX_RX 10 /* maximum packets recieve per call*/ #define MIN_LENGTH 60 /* minimum length for packet data */ #define MAX_LENGTH 1500 /* maximum length for packet data area */ #define TIMEOUT_DMAMATCH 40 /* for nic_block_input() */ #define TIMEOUT_TX 40 /* DP8390 NIC Registers*/ #define COMMAND 0x00 #define STATUS COMMAND+0 #define PHYSICAL COMMAND+1 /* page 1 */ #define MULTICAST COMMAND+8 /* page 1 */ #define PAGESTART COMMAND+1 /* page 0 */ #define PAGESTOP COMMAND+2 #define BOUNDARY COMMAND+3 #define TRANSMITSTATUS COMMAND+4 #define TRANSMITPAGE COMMAND+4 #define TRANSMITBYTECOUNT0 COMMAND+5 #define NCR COMMAND+5 #define TRANSMITBYTECOUNT1 COMMAND+6 #define INTERRUPTSTATUS COMMAND+7 #define CURRENT COMMAND+7 /* page 1 */ #define REMOTESTARTADDRESS0 COMMAND+8 #define CRDMA0 COMMAND+8 #define REMOTESTARTADDRESS1 COMMAND+9 #define CRDMA1 COMMAND+9 #define REMOTEBYTECOUNT0 COMMAND+10 /* how many bytes we will */ #define REMOTEBYTECOUNT1 COMMAND+11 /* read through remote DMA->IO */ #define RECEIVESTATUS COMMAND+12 #define RECEIVECONFIGURATION COMMAND+12 #define TRANSMITCONFIGURATION COMMAND+13 #define FAE_TALLY COMMAND+13 /* page 0 */ #define DATACONFIGURATION COMMAND+14 #define CRC_TALLY COMMAND+14 #define INTERRUPTMASK COMMAND+15 #define MISS_PKT_TALLY COMMAND+15 /* NE2000 specific implementation registers */ #define NE_RESET 0x1f /* Reset */ #define NE_DATA 0x10 /* Data port (use for PROM) */ #define PAR0 COMMAND+1 #define PAR1 COMMAND+2 #define PAR2 COMMAND+3 #define PAR3 COMMAND+4 #define PAR4 COMMAND+5 #define PAR5 COMMAND+6 /* NIC Commands */ #define NIC_STOP 0x01 /* STOP */ #define NIC_START 0x02 /* START */ #define NIC_PAGE0 0x00 #define NIC_PAGE1 0x40 #define NIC_PAGE2 0x80 #define NIC_TRANSMIT 0x04 /* Transmit a frame */ #define NIC_REM_READ 0x08 /* Remote Read */ #define NIC_REM_WRITE 0x10 /* Remote Write */ #define NIC_DMA_DISABLE 0x20 /* Disable DMA */ /* Data Configuration Register */ #define DCR_WTS 0x01 /* Word Transfer Select (0=byte, 1=word) */ #define DCR_BOS 0x02 /* Byte Order Select (0=big-endian) */ #define DCR_LAS 0x04 /* Long Address Select (0=dual 16-bit DMA) */ #define DCR_LS 0x08 /* Loopback Select (0=loopback) */ #define DCR_AR 0x10 /* Auto Initialize Remote */ #define DCR_FT 0x60 /* (FT0 & FT1) FIFO Threshhold (see datasheet) */ /*#define DCR_DEFAULT 0x58 Standard value for the DCR register */ #define DCR_DEFAULT 0x48 /* don't use Automatic send packet */ #define DCR_DEFAULT_WORD 0x49 /* defuault with wold length transfer */ /* Recieve Configure Register */ #define RCR_SEP 0x01 /* Save Errored Packets */ #define RCR_AR 0x02 /* Accept Runt Packets */ #define RCR_AB 0x04 /* Accept Broadcast */ #define RCR_AM 0x08 /* Accept Multicast */ #define RCR_PRO 0x10 /* Promiscuous Physical */ #define RCR_MON 0x20 /* Monitor Mode */ /*#define RCR_DEFAULT 0x00 Standard value for the RCR register */ #define RCR_DEFAULT 0x0c /* Accept Broadcast/Multicast Packets */ /* Recieve Status Register */ /* note, this is also stored in the status byte in the buffer header. */ /* That's the 4 byte entry in the local buffer, not the packet header. */ #define RSR_PRX 0x01 /* Pakcet Received Intact */ #define RSR_CRC 0x02 /* CRC Error */ #define RSR_FAE 0x04 /* Frame Alignment Error */ #define RSR_FO 0x08 /* FIFO Overrun */ #define RSR_MPA 0x10 /* Missed Packet */ #define RSR_PHY 0x20 /* Physical/Multicast Address (0=physical) */ #define RSR_DIS 0x40 /* Receiver Disabled */ #define RSR_DFR 0x80 /* Deferring */ /* Transmit Configure Register */ #define TCR_CRC 0x01 /* Inhibit CRC (0=CRC active) */ #define TCR_LB 0x06 /* (LB0 & LB1) Encoded Loopback Control */ #define TCR_ATD 0x08 /* Auto Transmit Disable (0=normal) */ #define TCR_OFST 0x10 /* Collision Offset Enable (1=low priority) */ #define TCR_DEFAULT 0x00 /* Standard value for the TCR register */ #define TCR_INTERNAL_LOOPBACK 0x02 /* Internal loopback configuration */ /* Transmit Status Register */ #define TSR_PTX 0x01 /* Packet Transmitted */ #define TSR_ND 0x02 /* Non-Deferral (Documented???) */ #define TSR_COL 0x04 /* Transmit Collided */ #define TSR_ABT 0x08 /* Transmit Aborted */ #define TSR_CRS 0x10 /* Carrier Sense Lost */ #define TSR_FU 0x20 /* FIFO Underrun */ #define TSR_CDH 0x40 /* CD Heartbeat */ #define TSR_OWC 0x80 /* Oout of Window Collision */ /* Interrupt Status Register */ #define ISR_PRX 0x01 /* Packet Received */ #define ISR_PTX 0x02 /* Packet Transmitted */ #define ISR_RXE 0x04 /* Receive Error */ #define ISR_TXE 0x08 /* Transmit Error */ #define ISR_OVW 0x10 /* Overwrite Warning */ #define ISR_CNT 0x20 /* Counter Overflow */ #define ISR_RDC 0x40 /* Remote DMA Complete */ #define ISR_RST 0x80 /* Reset Status */ #define ISR_DEFAULT 0x00 /* Standard value for the ISR register */ #define ISR_ALL 0x3f /* The services that we handle in the isr */ /* Interrupt Mask Register */ #define IMR_PRXE 0x01 /* Packet Received Interrupt Enable */ #define IMR_PTXE 0x02 /* Packet Transmitted Interrupt Enable */ #define IMR_RXEE 0x04 /* Receive Error Interrupt Enable */ #define IMR_TXEE 0x08 /* Transmit Error Interrupt Enable */ #define IMR_OVWE 0x10 /* Overwrite Warning Interrupt Enable */ #define IMR_CNTE 0x20 /* Counter Overflow Interrupt Enable */ #define IMR_RDCE 0x40 /* DMA Complete Interrupt Enable */ #define IMR_DEFAULT 0x3f /* CNTE | OVWE | TXEE | RXEE | PTXE | PRXE */ #endif
27344c1194090d24d87a4fe58f700f2dcb1c4021
d7bf1e354f57a86c23747d4c5e66e1cc453a5c9c
/strc51io.h
ccee7cfb15de8c26412170a7b4107a6a9bde65c7
[]
no_license
demiurge16/strc51io
37dd2b92b00aa3d3a6c7e626d0782a49c233ffe3
a70576feb00f004fdc8a63f8b361ec2935971ad7
refs/heads/master
2020-06-25T12:57:54.624272
2019-07-28T16:57:36
2019-07-28T16:57:36
199,313,830
4
0
null
null
null
null
UTF-8
C
false
false
2,224
h
strc51io.h
#ifndef STRC51IO_H #define STRC51IO_H /* * Device definitions */ #define NO_INPUT_DEVICE 0 #define RS232_INPUT 1 #define KB_INPUT 2 #define NO_OUTPUT_DEVICE 3 #define RS232_OUTPUT 4 #define LED_OUTPUT 5 #define LCD_OUTPUT 6 /* * LED max word size */ #define MAX_WORD_SIZE 4 /* * LED segments definition */ #define SEG_A 0x02 #define SEG_B 0x04 #define SEG_C 0x40 #define SEG_D 0x10 #define SEG_E 0x08 #define SEG_F 0x01 #define SEG_G 0x20 #define SEG_H 0x80 /* * LED clear */ #define cyfra_null 0 /* * Predefined numbers */ #define cyfra_0 SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F #define cyfra_1 SEG_B | SEG_C #define cyfra_2 SEG_A | SEG_B | SEG_D | SEG_E | SEG_G #define cyfra_3 SEG_A | SEG_B | SEG_C | SEG_D | SEG_G #define cyfra_4 SEG_B | SEG_C | SEG_F | SEG_G #define cyfra_5 SEG_A | SEG_C | SEG_D | SEG_F | SEG_G #define cyfra_6 SEG_A | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G #define cyfra_7 SEG_A | SEG_B | SEG_C #define cyfra_8 SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G #define cyfra_9 SEG_A | SEG_B | SEG_C | SEG_D | SEG_F | SEG_G #define cyfra_A SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G #define cyfra_B SEG_C | SEG_D | SEG_E | SEG_F | SEG_G #define cyfra_C SEG_A | SEG_D | SEG_E | SEG_F #define cyfra_D SEG_B | SEG_C | SEG_D | SEG_E | SEG_G #define cyfra_E SEG_A | SEG_D | SEG_E | SEG_F | SEG_G #define cyfra_F SEG_A | SEG_E | SEG_F | SEG_G /* * High level functions */ void printf(char* s, ...); void scanf(char* s, ...); void puts(const char* s); void gets(char* s); void putchar(char s); char getchar(); void devopen(char dev); /* * Primitives */ void buzzer_mksound(int frequency); char rs232_getchar(); void rs232_putchar(char c); void led_putchar(char c); void led_putcharpos(char c, int p); unsigned char kbhit(); unsigned char getkey(); void lcd_putchar(char c); void create_custom_character(unsigned char *pattern, const char location); void lcd_clear_screen(); void lcd_clear_chars(); void lcd_puts(const char* s); void goto_xy(char x, char y); void send_command_8bit_mode(unsigned char command); void send_command_4bit_mode(unsigned char command); void wait(int d); #endif
e9e98c06f4939dc11c0085faa3cee20bee3a6986
020df1046ef6ea1755b14478b9ef5c3c0ad0a1ca
/up4dar-os/src/asf/common/boards/user_board/init.c
1fa2bb787c9de9ffe6309e0e5b19b0651d67a9fc
[]
no_license
oe5stm/up4dar-os
d25a00753deb146902ae979d5566213a596fdaca
5e66b006f19513728198e41eaf056570ee73d669
refs/heads/master
2021-01-20T00:27:30.400483
2018-02-18T17:35:43
2018-02-18T17:35:43
89,131,135
3
0
null
2017-04-23T09:31:40
2017-04-23T09:31:39
null
UTF-8
C
false
false
12,280
c
init.c
/* Copyright (C) 2011,2012 Michael Dirska, DL1BFF (dl1bff@mdx.de) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <asf.h> #include <board.h> #include <conf_board.h> #include "gpio.h" #include "power_clocks_lib.h" #include "FreeRTOS.h" static const gpio_map_t lcd_gpio_map = { { AVR32_PIN_PA02, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // RES { AVR32_PIN_PB12, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // E { AVR32_PIN_PB13, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // CS1 { AVR32_PIN_PB14, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // CS2 { AVR32_PIN_PB21, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // D/I { AVR32_PIN_PB22, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // R/W { AVR32_PIN_PB24, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // D0 { AVR32_PIN_PB25, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // D1 { AVR32_PIN_PB26, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // D2 { AVR32_PIN_PB27, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // D3 { AVR32_PIN_PB28, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // D4 { AVR32_PIN_PB29, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // D5 { AVR32_PIN_PB30, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // D6 { AVR32_PIN_PB31, GPIO_DIR_OUTPUT | GPIO_INIT_LOW } // D7 }; static const gpio_map_t lcd_pwm_gpio_map = { { AVR32_PWM_6_PIN, AVR32_PWM_6_FUNCTION }, // LCD_Backlight { AVR32_PWM_0_PIN, AVR32_PWM_0_FUNCTION } // LCD_PWM_Kontrast }; static const gpio_map_t switch_gpio_map = { { AVR32_PIN_PA28, GPIO_DIR_INPUT | GPIO_PULL_UP }, // PTT { AVR32_PIN_PA18, GPIO_DIR_INPUT | GPIO_PULL_UP }, // SW1 { AVR32_PIN_PA19, GPIO_DIR_INPUT | GPIO_PULL_UP }, // SW2 { AVR32_PIN_PA20, GPIO_DIR_INPUT }, // SW3 has external pull up { AVR32_PIN_PA21, GPIO_DIR_INPUT }, // SW4 special analog input { AVR32_PIN_PA22, GPIO_DIR_INPUT | GPIO_PULL_UP }, // SW5 { AVR32_PIN_PA23, GPIO_DIR_INPUT | GPIO_PULL_UP } // SW6 }; static const gpio_map_t adc_gpio_map = { { AVR32_ADC_AD_0_PIN, AVR32_ADC_AD_0_FUNCTION } // SW4, PA21 }; static const gpio_map_t ambe_pin_gpio_map = { { AVR32_PIN_PB20, GPIO_DIR_OUTPUT | GPIO_INIT_LOW }, // RESETN { AVR32_PIN_PA07, GPIO_DIR_INPUT } // EPR }; static const gpio_map_t ambe_spi_gpio_map = { { AVR32_SPI0_NPCS_1_0_PIN, AVR32_SPI0_NPCS_1_0_FUNCTION }, // PA08 { AVR32_SPI0_NPCS_0_0_PIN, AVR32_SPI0_NPCS_0_0_FUNCTION }, // PA10 { AVR32_SPI0_MISO_0_0_PIN, AVR32_SPI0_MISO_0_0_FUNCTION }, // PA11 { AVR32_SPI0_MOSI_0_0_PIN, AVR32_SPI0_MOSI_0_0_FUNCTION }, // PA12 { AVR32_SPI0_SCK_0_0_PIN, AVR32_SPI0_SCK_0_0_FUNCTION } // PA13 }; static const gpio_map_t i2c_config_gpio_map = { { AVR32_TWI_SDA_0_0_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH | GPIO_OPEN_DRAIN }, // PA29 { AVR32_TWI_SCL_0_0_PIN, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH | GPIO_OPEN_DRAIN } // PA30 }; static const gpio_map_t i2c_gpio_map = { { AVR32_TWI_SDA_0_0_PIN, AVR32_TWI_SDA_0_0_FUNCTION }, // PA29 { AVR32_TWI_SCL_0_0_PIN, AVR32_TWI_SCL_0_0_FUNCTION } // PA30 }; static const gpio_map_t ssc_gpio_map = { { AVR32_SSC_TX_FRAME_SYNC_0_PIN, AVR32_SSC_TX_FRAME_SYNC_0_FUNCTION }, // PA14 { AVR32_SSC_TX_CLOCK_0_PIN, AVR32_SSC_TX_CLOCK_0_FUNCTION }, // PA15 { AVR32_SSC_TX_DATA_0_PIN, AVR32_SSC_TX_DATA_0_FUNCTION }, // PA16 { AVR32_SSC_RX_DATA_0_PIN, AVR32_SSC_RX_DATA_0_FUNCTION } // PA17 }; static const gpio_map_t eth_pin_gpio_map = { { AVR32_PIN_PA03, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH } // INT/POWERDOWN }; static const gpio_map_t eth_module_gpio_map = { { AVR32_MACB_MDC_0_PIN, AVR32_MACB_MDC_0_FUNCTION }, { AVR32_MACB_MDIO_0_PIN, AVR32_MACB_MDIO_0_FUNCTION }, { AVR32_MACB_RXD_0_PIN, AVR32_MACB_RXD_0_FUNCTION }, { AVR32_MACB_RXD_1_PIN, AVR32_MACB_RXD_1_FUNCTION }, { AVR32_MACB_TXD_0_PIN, AVR32_MACB_TXD_0_FUNCTION }, { AVR32_MACB_TXD_1_PIN, AVR32_MACB_TXD_1_FUNCTION }, { AVR32_MACB_TX_EN_0_PIN, AVR32_MACB_TX_EN_0_FUNCTION }, { AVR32_MACB_RX_ER_0_PIN, AVR32_MACB_RX_ER_0_FUNCTION }, { AVR32_MACB_RX_DV_0_PIN, AVR32_MACB_RX_DV_0_FUNCTION }, { AVR32_MACB_TX_CLK_0_PIN, AVR32_MACB_TX_CLK_0_FUNCTION } }; static const gpio_map_t usart_gpio_map = { { AVR32_USART0_RXD_0_0_PIN, AVR32_USART0_RXD_0_0_FUNCTION }, { AVR32_USART0_TXD_0_0_PIN, AVR32_USART0_TXD_0_0_FUNCTION }, { AVR32_USART1_RXD_0_0_PIN, AVR32_USART1_RXD_0_0_FUNCTION }, { AVR32_USART1_TXD_0_0_PIN, AVR32_USART1_TXD_0_0_FUNCTION } }; static const gpio_map_t usb_pin_gpio_map = { { AVR32_PIN_PB17, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH }, // VBOF pin { AVR32_PIN_PA09, GPIO_DIR_INPUT | GPIO_PULL_UP }, // OverCurrent pin { AVR32_PIN_PB16, GPIO_DIR_INPUT | GPIO_PULL_UP } // ID pin }; static const gpio_map_t usb_module_gpio_map = { // { AVR32_USBB_USB_VBOF_0_1_PIN, AVR32_USBB_USB_VBOF_0_1_FUNCTION }, // VBOF pin { AVR32_USBB_USB_ID_0_1_PIN, AVR32_USBB_USB_ID_0_1_FUNCTION } // ID pin }; static const gpio_map_t sdcard_gpio_map = { { AVR32_USART3_RXD_0_0_PIN, AVR32_USART3_RXD_0_0_FUNCTION }, { AVR32_USART3_TXD_0_0_PIN, AVR32_USART3_TXD_0_0_FUNCTION }, { AVR32_USART3_CLK_0_PIN, AVR32_USART3_CLK_0_FUNCTION } }; static const gpio_map_t sdcard_pin_gpio_map = { { AVR32_PIN_PA04, GPIO_DIR_OUTPUT | GPIO_INIT_HIGH } // CS pin }; void board_init(void) { /* pcl_freq_param_t freq = { configCPU_CLOCK_HZ, configPBA_CLOCK_HZ, FOSC0, OSC0_STARTUP }; pcl_configure_clocks ( &freq ); */ // first change to OSC0 (12MHz) pm_enable_osc0_crystal(& AVR32_PM, FOSC0); // Enable the Osc0 in crystal mode pm_enable_clk0(& AVR32_PM, OSC0_STARTUP); // Crystal startup time pm_switch_to_clock(& AVR32_PM, AVR32_PM_MCSEL_OSC0); // Then switch main clock to Osc0 pm_enable_osc1_ext_clock(& AVR32_PM); // ocs1 is external clock pm_enable_clk1(& AVR32_PM, OSC1_STARTUP); pm_pll_setup(&AVR32_PM , 0 // pll , 3 // mul , 0 // div -> f_vfo = 16.384 MHz * 8 = 131.072 MHz , 1 // osc , 16 // lockcount ); pm_pll_set_option(&AVR32_PM , 0 // pll , 1 // pll_freq (f_vfo range 80MHz - 180 MHz) , 1 // pll_div2 (f_pll1 = f_vfo / 2) , 0 // pll_wbwdisable ); pm_pll_enable(&AVR32_PM, 0); pm_wait_for_pll0_locked(&AVR32_PM); pm_cksel(&AVR32_PM , 1, 1 // PBA (CPU / 4) = 16.384 MHz , 0, 0 // PBB 65.536 MHz , 0, 0 // HSB = CPU 65.536 MHz ); flashc_set_wait_state(1); // one wait state if CPU clock > 33 MHz pm_switch_to_clock(&AVR32_PM, AVR32_PM_MCCTRL_MCSEL_PLL0); // switch to PLL0 // -------------------------------------- // USB clock // Use 12MHz from OSC0 and generate 96 MHz pm_pll_setup(&AVR32_PM, 1, // pll. 7, // mul. 1, // div. 0, // osc. 16); // lockcount. pm_pll_set_option(&AVR32_PM, 1, // pll. 1, // pll_freq: choose the range 80-180MHz. 1, // pll_div2. 0); // pll_wbwdisable. // start PLL1 and wait forl lock pm_pll_enable(&AVR32_PM, 1); // Wait for PLL1 locked. pm_wait_for_pll1_locked(&AVR32_PM); pm_gc_setup(&AVR32_PM, AVR32_PM_GCLK_USBB, // gc. 1, // osc_or_pll: use Osc (if 0) or PLL (if 1). 1, // pll_osc: select Osc0/PLL0 or Osc1/PLL1. 0, // diven. 0); // div. pm_gc_enable(&AVR32_PM, AVR32_PM_GCLK_USBB); // -------------------------------------- // LCD display gpio_enable_gpio( lcd_gpio_map, sizeof( lcd_gpio_map ) / sizeof( lcd_gpio_map[0] ) ); int i; for (i=0; i < (sizeof( lcd_gpio_map ) / sizeof( lcd_gpio_map[0] )); i++) { gpio_configure_pin( lcd_gpio_map[i].pin, lcd_gpio_map[i].function); } gpio_enable_module( lcd_pwm_gpio_map, sizeof( lcd_pwm_gpio_map ) / sizeof( lcd_pwm_gpio_map[0] ) ); // Backlight AVR32_PWM.channel[6].CMR.cpre = 3; AVR32_PWM.channel[6].cprd = 1000; AVR32_PWM.channel[6].cdty = 500; AVR32_PWM.ENA.chid6 = 1; // contrast AVR32_PWM.channel[0].CMR.cpre = 3; AVR32_PWM.channel[0].cprd = 1000; AVR32_PWM.channel[0].cdty = 520; AVR32_PWM.ENA.chid0 = 1; // switches gpio_enable_gpio( switch_gpio_map, sizeof( switch_gpio_map ) / sizeof( switch_gpio_map[0] ) ); for (i=0; i < (sizeof( switch_gpio_map ) / sizeof( switch_gpio_map[0] )); i++) { gpio_configure_pin( switch_gpio_map[i].pin, switch_gpio_map[i].function); } // ADC gpio_enable_module( adc_gpio_map, sizeof( adc_gpio_map ) / sizeof( adc_gpio_map[0] ) ); AVR32_ADC.mr = 0x0F031E20; // SHTIM = 15, STARTUP = 3, PRESCAL = 30, SLEEP Mode AVR32_ADC.cher = 1; // enable ADC0 AVR32_ADC.cr = 2; // start conversion // AMBE interface gpio_enable_gpio( ambe_pin_gpio_map, sizeof( ambe_pin_gpio_map ) / sizeof( ambe_pin_gpio_map[0] ) ); for (i=0; i < (sizeof( ambe_pin_gpio_map ) / sizeof( ambe_pin_gpio_map[0] )); i++) { gpio_configure_pin( ambe_pin_gpio_map[i].pin, ambe_pin_gpio_map[i].function); } gpio_enable_module( ambe_spi_gpio_map, sizeof( ambe_spi_gpio_map ) / sizeof( ambe_spi_gpio_map[0] ) ); // I2C gpio_enable_gpio( i2c_config_gpio_map, sizeof( i2c_config_gpio_map ) / sizeof( i2c_config_gpio_map[0] ) ); for (i=0; i < (sizeof( i2c_config_gpio_map ) / sizeof( i2c_config_gpio_map[0] )); i++) { gpio_configure_pin( i2c_config_gpio_map[i].pin, i2c_config_gpio_map[i].function); } gpio_enable_module( i2c_gpio_map, sizeof( i2c_gpio_map ) / sizeof( i2c_gpio_map[0] ) ); AVR32_TWI.cwgr = 0x00006060; // CKDIV = 0, CLDIV = CHDIV = 96 -> less than 100kHz // SSC gpio_enable_module( ssc_gpio_map, sizeof( ssc_gpio_map ) / sizeof( ssc_gpio_map[0] ) ); AVR32_SSC.cmr = 32; // 32 bit period, 8kHz sample rate -> 256kHz SSC clock AVR32_SSC.tcmr = 0x0F010504; // 32 bits per frame, STTDLY=1, // start = rising edge on TX_FRAME_SYNC, Continuous Transmit Clock AVR32_SSC.tfmr = 0x0020008F; // frame sync = Positive Pulse, frame sync length = 1, // 1 data word per frame, MSB first, 16 bits per data word AVR32_SSC.rcmr = 0x0F010121; // 32 bits per frame, STTDLY=1, // start = TX start , clock = TX Clock, // CKI -> sample bit on rising edge of clock AVR32_SSC.rfmr = 0x0000008F; // frame sync = Positive Pulse, frame sync length = 1, // 1 data word per frame, MSB first, 16 bits per data word // Ethernet gpio_enable_gpio( eth_pin_gpio_map, sizeof( eth_pin_gpio_map ) / sizeof( eth_pin_gpio_map[0] ) ); for (i=0; i < (sizeof( eth_pin_gpio_map ) / sizeof( eth_pin_gpio_map[0] )); i++) { gpio_configure_pin( eth_pin_gpio_map[i].pin, eth_pin_gpio_map[i].function); } gpio_enable_module( eth_module_gpio_map, sizeof( eth_module_gpio_map ) / sizeof( eth_module_gpio_map[0] ) ); // USART gpio_enable_module( usart_gpio_map, sizeof( usart_gpio_map ) / sizeof( usart_gpio_map[0] ) ); // USB gpio_enable_gpio( usb_pin_gpio_map, sizeof( usb_pin_gpio_map ) / sizeof( usb_pin_gpio_map[0] ) ); for (i=0; i < (sizeof( usb_pin_gpio_map ) / sizeof( usb_pin_gpio_map[0] )); i++) { gpio_configure_pin( usb_pin_gpio_map[i].pin, usb_pin_gpio_map[i].function); } gpio_enable_module( usb_module_gpio_map, sizeof( usb_module_gpio_map ) / sizeof( usb_module_gpio_map[0] ) ); // AVR32_USBB.usbcon = 0x03003000; // UIDE, VBUSPO, OTGPADE // AVR32_USBB.usbcon = 0x0300B000; // UIDE, USBE, VBUSPO, OTGPADE // AVR32_USBB.usbcon = 0x03006000; // default + VBUSPO // AVR32_USBB.udcon = 0; // SD card interface gpio_enable_module( sdcard_gpio_map, sizeof( sdcard_gpio_map ) / sizeof( sdcard_gpio_map[0] ) ); gpio_enable_gpio( sdcard_pin_gpio_map, sizeof( sdcard_pin_gpio_map ) / sizeof( sdcard_pin_gpio_map[0] ) ); for (i=0; i < (sizeof( sdcard_pin_gpio_map ) / sizeof( sdcard_pin_gpio_map[0] )); i++) { gpio_configure_pin( sdcard_pin_gpio_map[i].pin, sdcard_pin_gpio_map[i].function); } }
70e81bd32f1371d297426d758278064fc86f9fd7
38ea6e1ccdd3cd6338dd58c360a7c1f9d7ea607c
/nemu/src/monitor/debug/ui.c
7d5bd963806701506382f4a214f28bb1ce9f4caf
[]
no_license
szwathub/ics2015
699e36a454cad7d3ddc470df0b8bac5416a0f04e
77bc488241e15119836817ca30f2e5a582bf9b18
refs/heads/master
2023-03-10T17:18:14.260475
2016-01-06T17:11:28
2016-01-06T17:11:28
43,371,798
2
0
null
null
null
null
UTF-8
C
false
false
9,605
c
ui.c
#include "monitor/monitor.h" #include "monitor/expr.h" #include "monitor/watchpoint.h" #include "nemu.h" #include "color.h" #include <stdlib.h> #include <readline/readline.h> #include <readline/history.h> #include "cpu/helper.h" void cpu_exec(uint32_t); void print_bin_instr(swaddr_t eip, int len); /* We use the ``readline'' library to provide more flexibility to read from stdin. */ char* rl_gets() { static char *line_read = NULL; if (line_read) { free(line_read); line_read = NULL; } line_read = readline("(nemu) >"); if (line_read && *line_read) { add_history(line_read); } return line_read; } /* * @describe Continue the execution of the program * @param {string} args */ static int cmd_c(char *args) { cpu_exec(-1); return 0; } /* * @describe Exit NEMU * @param {string} args */ static int cmd_q(char *args) { return -1; } static int cmd_help(char *args); /* * @describe Single-step Debugging * @param {string} args */ static int cmd_si(char *args) { if(args == NULL) { cpu_exec(1); } else { cpu_exec(atoi(args)); } return 0; } /* * @describe Printing reg status or watchpoint * @param {string} args */ static int cmd_info(char *args) { int i = 0; if(args == NULL) { printf("The most commonly used info commands are:\n\n"); printf("r\t\tprint reg status\n"); printf("w\t\tprint information of watchpoint\n"); } else if(strcmp(args, "r") == 0) { printf(GREEN"+------+--------------------------------"NONE); printf(GREEN"+------+--------------------------------"NONE); printf(GREEN"+------+-------------------------------+\n"NONE); printf(GREEN"|"NONE \ LIGHT_RED" Reg "NONE \ GREEN"|"NONE \ LIGHT_RED" Value "NONE); printf(GREEN"|"NONE \ LIGHT_RED" Reg "NONE \ GREEN"|"NONE \ LIGHT_RED" Value "NONE); printf(GREEN"|"NONE \ LIGHT_RED" Reg "NONE \ GREEN"|"NONE \ LIGHT_RED" Value "NONE \ GREEN"|"NONE); printf("\n"); printf(GREEN"+------+--------------------------------"NONE); printf(GREEN"+------+--------------------------------"NONE); printf(GREEN"+------+-------------------------------+\n"NONE); printf(GREEN"| | "NONE \ LIGHT_BLUE"HEX"NONE \ GREEN" |"NONE LIGHT_BLUE" DEC "NONE); printf(GREEN"| | "NONE \ LIGHT_BLUE"HEX"NONE \ GREEN" |"NONE LIGHT_BLUE" DEC "NONE); printf(GREEN"| | "NONE \ LIGHT_BLUE"HEX"NONE \ GREEN" |"NONE LIGHT_BLUE" DEC "NONE GREEN"|"NONE); printf("\n"); printf(GREEN"+------+--------------------------------"NONE); printf(GREEN"+------+--------------------------------"NONE); printf(GREEN"+------+-------------------------------+\n"NONE); for(i = 0; i < 8; i++) { printf(GREEN"|"NONE \ LIGHT_CYAN" %-5s"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" 0x%-10x"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" %-13u"NONE, regsl[i], cpu.gpr[i]._32, cpu.gpr[i]._32); printf(GREEN"|"NONE \ LIGHT_CYAN" %-4s"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" 0x%-9x"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" %-11u"NONE, regsw[i], cpu.gpr[i]._16, cpu.gpr[i]._16); if(i < 4) { printf(GREEN"|"NONE \ LIGHT_CYAN" %-4s"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" 0x%-8x"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" %-9u"NONE GREEN"|\n"NONE, regsb[i], cpu.gpr[i]._8[0], cpu.gpr[i]._8[0]); } else { printf(GREEN"|"NONE \ LIGHT_CYAN" %-4s"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" 0x%-8x"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" %-9u"NONE GREEN"|\n"NONE, regsb[i], cpu.gpr[i - 4]._8[1], cpu.gpr[i - 4]._8[1]); } printf(GREEN"+------+--------------------------------"NONE); printf(GREEN"+------+--------------------------------"NONE); printf(GREEN"+------+-------------------------------+\n"NONE); } printf(GREEN"+------+--------------------------------+\n"NONE); printf(GREEN"|"NONE \ LIGHT_CYAN" eip "NONE \ GREEN"|"NONE \ LIGHT_PURPLE" 0x%-10x"NONE \ GREEN"|"NONE \ LIGHT_PURPLE" %-12u"NONE GREEN"|\n"NONE, cpu.eip, cpu.eip); printf(GREEN"+------+--------------------------------+\n"NONE); printf(GREEN"\n+----+----+----+----+----+----+\n"NONE); printf(GREEN"|"NONE \ CYAN" OF "NONE \ GREEN"|"NONE \ CYAN" SF "NONE \ GREEN"|"NONE \ CYAN" ZF "NONE \ GREEN"|"NONE \ CYAN" AF "NONE \ GREEN"|"NONE \ CYAN" PF "NONE \ GREEN"|"NONE \ CYAN" CF "NONE \ GREEN"|\n"NONE); printf(GREEN"+----+----+----+----+----+----+\n"NONE); printf(GREEN"|"NONE \ PURPLE" %-2x "NONE GREEN"|"NONE \ PURPLE" %-2x "NONE \ GREEN"|"NONE \ PURPLE" %-2x "NONE \ GREEN"|"NONE \ PURPLE" %-2x "NONE \ GREEN"|"NONE \ PURPLE" %-2x "NONE \ GREEN"|"NONE \ PURPLE" %-2x "NONE \ GREEN"|\n"NONE, cpu.OF, cpu.SF, cpu.ZF, cpu.AF, cpu.PF, cpu.CF); printf(GREEN"+----+----+----+----+----+----+\n"NONE); } else if(strcmp(args, "w") == 0) { show_all_wp(); } else if(strcmp(args, "--help") == 0) { printf("The most commonly used info commands are:\n\n"); printf("r\t\tprint reg status\n"); printf("w\t\tprint information of watchpoint\n"); } else { printf("info: '%s' is not a info command. See 'info --help'.\n", args); } return 0; } /** * @describe * @param {string} args */ static int cmd_p(char *args) { if(args == NULL) { printf("Simple: p expr\n"); return 0; } bool succ = false; uint32_t result = expr(args, &succ); if(succ) { printf(LIGHT_PURPLE"The Expression : %s\n"NONE, args); printf(LIGHT_PURPLE"The Result(DEC): %d\n"NONE, result); printf(LIGHT_PURPLE"The Result(HEX): %x\n"NONE, result); } return 0; } /** * @describe Scan memory * @param {string} args */ static int cmd_scan(char *args) { char *args_len; char *expression; int count; if(args == NULL) { printf("Simple: x N expr\n"); return 0; } args_len = args + strlen(args); char *arg = strtok(args, " "); count = atoi(arg); expression = arg + strlen(arg) + 1; if(expression > args_len) { printf("Simple: x N expr\n"); return 0; } bool flag; uint32_t address = expr(expression, &flag); while(count > 8) { print_bin_instr(address, 8); address += 8; count -= 8; } if(count > 0) { print_bin_instr(address, count); } printf("\n"); return 0; } /* Implement set watchpoint * @describe Set a watchpoint * @param {string} args */ static int cmd_w(char *args) { add_wp(args); return 0; } /* * @describe Delete a watch point * @param {string} args */ static int cmd_delete(char *args) { if(atoi(args) >= 32) { printf("Error!\n"); return 0; } del_wp(atoi(args)); return 0; } extern bool find_stack(int addr, char *str); /* TODO * */ static int cmd_bt(char *args) { int ebp = cpu.ebp; int eip = cpu.eip; int cnt = 0; char str[32]; if(!find_stack(eip, str)) { printf("No stack.\n"); return 0; } while(find_stack(eip, str)) { printf("#%d eip=0x%x in %s(%d, %d, %d, %d)\n", ++ cnt, eip, str, swaddr_read(ebp + 0x8, 4), swaddr_read(ebp + 0xc, 4), swaddr_read(ebp + 0x10, 4), swaddr_read(ebp + 0x14, 4)); eip = swaddr_read(ebp + 4, 4); ebp = swaddr_read(ebp, 4); } return 0; } static struct { char *name; char *description; int (*handler) (char *); } cmd_table [] = { { "help", "Display informations about all supported commands", cmd_help }, { "c", "Continue the execution of the program", cmd_c }, { "q", "Exit NEMU", cmd_q }, { "si", "Single-step debugging", cmd_si}, { "info", "Print reg status or watchpoint", cmd_info}, { "p", "表达式求值", cmd_p}, { "x", "Scan memory", cmd_scan}, { "w", "Set a watchpoint", cmd_w}, { "d", "Delete a watchpoint", cmd_delete}, { "bt", "Print backtrace", cmd_bt} /* Add more commands */ }; #define NR_CMD (sizeof(cmd_table) / sizeof(cmd_table[0])) static int cmd_help(char *args) { /* extract the first argument */ char *arg = strtok(NULL, " "); int i; if(arg == NULL) { /* no argument given */ for(i = 0; i < NR_CMD; i ++) { printf("%s\t\t%s\n", cmd_table[i].name, cmd_table[i].description); } } else { for(i = 0; i < NR_CMD; i ++) { if(strcmp(arg, cmd_table[i].name) == 0) { printf("%s\t\t%s\n", cmd_table[i].name, cmd_table[i].description); return 0; } } printf("Nemu: command not found: %s\n", arg); } return 0; } void ui_mainloop() { init_wp_list(); while(1) { char *str = rl_gets(); char *str_end = str + strlen(str); /* extract the first token as the command */ char *cmd = strtok(str, " "); if(cmd == NULL) { continue; } /* treat the remaining string as the arguments, * which may need further parsing */ char *args = cmd + strlen(cmd) + 1; if(args >= str_end) { args = NULL; } #ifdef HAS_DEVICE extern void sdl_clear_event_queue(void); sdl_clear_event_queue(); #endif int i; for(i = 0; i < NR_CMD; i ++) { if(strcmp(cmd, cmd_table[i].name) == 0) { if(cmd_table[i].handler(args) < 0) { return; } break; } } if(i == NR_CMD) { printf("Nemu: command not found: %s\n", cmd); } } }
605abc54d7a54725b35be30528dbe85af434f829
99bdb3251fecee538e0630f15f6574054dfc1468
/components/utilities/utest/utest.h
56a6e0d57eb3255d1e3c24fc13ac62ccac13412b
[ "Apache-2.0" ]
permissive
RT-Thread/rt-thread
03a7c52c2aeb1b06a544143b0e803d72f47d1ece
3602f891211904a27dcbd51e5ba72fefce7326b2
refs/heads/master
2023-09-01T04:10:20.295801
2023-08-31T16:20:55
2023-08-31T16:20:55
7,408,108
9,599
5,805
Apache-2.0
2023-09-14T13:37:26
2013-01-02T14:49:21
C
UTF-8
C
false
false
4,972
h
utest.h
/* * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2018-11-19 MurphyZhao the first version */ #ifndef __UTEST_H__ #define __UTEST_H__ #include <rtthread.h> #include <stdint.h> #include "utest_log.h" #include "utest_assert.h" #ifdef __cplusplus extern "C" { #endif /** * utest_error * * @brief Test result. * * @member UTEST_PASSED Test success. * @member UTEST_FAILED Test failed. * @member UTEST_PASSED Test skipped. * */ enum utest_error { UTEST_PASSED = 0, UTEST_FAILED = 1, UTEST_SKIPPED = 2 }; typedef enum utest_error utest_err_e; /** * utest * * @brief utest data structure. * * @member error Error number from enum `utest_error`. * @member passed_num Total number of tests passed. * @member failed_num Total number of tests failed. * */ struct utest { utest_err_e error; uint32_t passed_num; uint32_t failed_num; }; typedef struct utest *utest_t; /** * utest_tc_export * * @brief utest testcase data structure. * Will export the data to `UtestTcTab` section in flash. * * @member name Testcase name. * @member run_timeout Testcase maximum test time (Time unit: seconds). * @member init Necessary initialization before executing the test case function. * @member tc Total number of tests failed. * @member cleanup Total number of tests failed. * */ struct utest_tc_export { const char *name; uint32_t run_timeout; rt_err_t (*init)(void); void (*tc)(void); rt_err_t (*cleanup)(void); }; typedef struct utest_tc_export *utest_tc_export_t; /** * test_unit_func * * @brief Unit test handler function pointer. * */ typedef void (*test_unit_func)(void); /** * utest_unit_run * * @brief Unit test function executor. * No need for the user to call this function directly * * @param func Unit test function. * @param unit_func_name Unit test function name. * * @return void * */ void utest_unit_run(test_unit_func func, const char *unit_func_name); /** * utest_handle_get * * @brief Get the utest data structure handle. * No need for the user to call this function directly * * @param void * * @return utest_t type. (struct utest *) * */ utest_t utest_handle_get(void); /** * UTEST_NAME_MAX_LEN * * @brief Testcase name maximum length. * */ #define UTEST_NAME_MAX_LEN (128u) /** * UTEST_TC_EXPORT * * @brief Export testcase function to `UtestTcTab` section in flash. * Used in application layer. * * @param testcase The testcase function. * @param name The testcase name. * @param init The initialization function of the test case. * @param cleanup The cleanup function of the test case. * @param timeout Testcase maximum test time (Time unit: seconds). * * @return None * */ #ifdef _MSC_VER #pragma section("UtestTcTab$f",read) #define UTEST_TC_EXPORT(testcase, name, init, cleanup, timeout) \ __declspec(allocate("UtestTcTab$f")) \ static const struct utest_tc_export _utest_testcase = \ { \ name, \ timeout, \ init, \ testcase, \ cleanup \ } #pragma comment(linker, "/merge:UtestTcTab=tctext") #else #define UTEST_TC_EXPORT(testcase, name, init, cleanup, timeout) \ rt_used static const struct utest_tc_export _utest_testcase \ rt_section("UtestTcTab") = \ { \ name, \ timeout, \ init, \ testcase, \ cleanup \ } #endif /* _MSC_VER */ /** * UTEST_UNIT_RUN * * @brief Unit test function executor. * Used in `testcase` function in application. * * @param test_unit_func Unit test function * * @return None * */ #define UTEST_UNIT_RUN(test_unit_func) \ utest_unit_run(test_unit_func, #test_unit_func); \ if(utest_handle_get()->failed_num != 0) return; #ifdef __cplusplus } #endif #endif /* __UTEST_H__ */
e152c92828eaf96d234036727cd9aaf61bfbf64c
838a4f36504c5850a5f8dc6e788948710d2d4f37
/libft/ftoa.c
9d240604cfef944f03eba43b62944b6b25f6c942
[]
no_license
vlytvyne/Lem-in
1833d2048dd373d8740ff50c8100073883c4b9d5
3ee6011ed04aadc71171969c55c459fcbcab9789
refs/heads/master
2020-04-11T23:18:23.916275
2019-02-22T20:19:30
2019-02-22T20:19:30
162,162,727
0
0
null
null
null
null
UTF-8
C
false
false
1,824
c
ftoa.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ftoa.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: vlytvyne <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/11/16 11:51:10 by vlytvyne #+# #+# */ /* Updated: 2018/11/17 13:12:40 by vlytvyne ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" static long double float_abs(long double num) { if (num < 0) num *= -1; return (num); } static void cat_free(char *str, char *itoa_ret) { ft_strcat(str, itoa_ret); free(itoa_ret); } static void fill_zeros(char *str, char *itoa_ret, int precision) { int itoa_len; itoa_len = ft_strlen(itoa_ret); while (itoa_len++ < precision) ft_strcat(str, "0"); } char *ftoa(long double num, unsigned int precision) { long long int ip; long double fp; char *str; char *itoa_ret; str = ft_strnew(30); if (num < 0) { ft_strcat(str, "-"); num = float_abs(num); } ip = (long long int)num; fp = num - ip; itoa_ret = ft_itoa(ip); cat_free(str, itoa_ret); if (precision != 0) { ft_strcat(str, "."); fp = fp * power(10, precision); itoa_ret = fp - (int)fp >= 0.5 ? ft_itoa(fp + 1) : ft_itoa(fp); fill_zeros(str, itoa_ret, precision); cat_free(str, itoa_ret); } return (str); }
5e241f4f77186168e560baedd596a43dc4dbe8e1
a1232023595eed48bf3d56c0c1dcb8f05cdc261a
/1247. Minimum Swaps to Make Strings Equal/1247.c
9c5304af17342f56622ba6bc9b069f1bd318f71a
[]
no_license
NKcell/leetcode
2393ec3f8dc0e26b9ff098a592e4ffa9d7b774b8
88dec1c2106950e82819a0dd16425a9ee8fdaca4
refs/heads/master
2020-07-24T05:27:42.269903
2020-05-06T07:45:07
2020-05-06T07:45:07
207,814,442
0
0
null
null
null
null
UTF-8
C
false
false
596
c
1247.c
#include<string.h> int minimumSwap(char * s1, char * s2){ char *res = (char*)malloc(strlen(s1)); int count = 0; for (int i=0; i<strlen(s1); i++){ if (*(s1+i)!=*(s2+i)){ *(res+count) = *(s1+i); count++; } } if (count%2 != 0){ return -1; } int x = 0; int y = 0; for (int j=0; j<count; j++){ if (*(res+j) == 'x'){ x++; }else{ y++; } } free(res); if (x%2 == 0){ return x/2+y/2; } return x/2+y/2+2; }
c66f8d8cb7bc1ad8ccc5262f1315b6286f5d937f
a8b80485fc444a833f7a7a148ab29dee948b5f71
/test/raster_image_test.c
d876da5cb03ed7091fc54b244fe462e4d70df105
[]
no_license
liamwhite/image_proc
467ac02a72bd2b80fc3794ccf376a5c1504c0e98
37ef008da9a9549cc7c98f7344d7606a1ecbb088
refs/heads/master
2020-04-29T00:47:17.479162
2019-03-17T19:07:06
2019-03-17T19:07:06
175,707,770
0
0
null
null
null
null
UTF-8
C
false
false
3,618
c
raster_image_test.c
#include <assert.h> #include <stddef.h> #include <stdlib.h> #include "raster_image.h" // Small checkerboard pattern static const char inline_png[] = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52" "\x00\x00\x00\x10\x00\x00\x00\x10\x08\x04\x00\x00\x00\xB5\xFA\x37" "\xEA\x00\x00\x00\x19\x49\x44\x41\x54\x78\xDA\x63\xF8\xEF\x80\x0A" "\x19\xD0\xE1\x08\x51\x80\x2E\x80\xA1\x61\x64\x28\x00\x00\xA9\x5B" "\xBF\x81\xE6\x5B\xF9\x07\x00\x00\x00\x00\x49\x45\x4E\x44\xAE\x42" "\x60\x82"; void test_load_buf() { raster_image *ri = raster_image_from_buffer(inline_png, sizeof(inline_png)); assert(ri != NULL); dim_t dim = raster_image_dimensions(ri); size_t frames = raster_image_frame_count(ri); assert(dim.width == 16); assert(dim.height == 16); assert(frames == 1); raster_image_free(ri); } void test_load_file_jpg() { raster_image *ri = raster_image_from_file("test/test_jpeg.jpg"); assert(ri != NULL); dim_t dim = raster_image_dimensions(ri); size_t frames = raster_image_frame_count(ri); assert(dim.width == 1024); assert(dim.height == 768); assert(frames == 1); raster_image_free(ri); } void test_load_file_jpg_orient() { raster_image *ri = raster_image_from_file("test/test_jpeg_orient.jpg"); assert(ri != NULL); dim_t dim = raster_image_dimensions(ri); size_t frames = raster_image_frame_count(ri); assert(dim.width == 768); assert(dim.height == 1024); assert(frames == 1); raster_image_free(ri); } void test_load_file_png() { raster_image *ri = raster_image_from_file("test/test_png.png"); assert(ri != NULL); dim_t dim = raster_image_dimensions(ri); size_t frames = raster_image_frame_count(ri); assert(dim.width == 561); assert(dim.height == 535); assert(frames == 1); raster_image_free(ri); } void test_load_file_gif_static() { raster_image *ri = raster_image_from_file("test/test_gif_static.gif"); assert(ri != NULL); dim_t dim = raster_image_dimensions(ri); size_t frames = raster_image_frame_count(ri); assert(dim.width == 277); assert(dim.height == 344); assert(frames == 1); raster_image_free(ri); } void test_load_file_gif_animated() { raster_image *ri = raster_image_from_file("test/test_gif_animated.gif"); assert(ri != NULL); dim_t dim = raster_image_dimensions(ri); size_t frames = raster_image_frame_count(ri); assert(dim.width == 277); assert(dim.height == 344); assert(frames == 163); // Verify dimensions and aspect ratio raster_image *si = raster_image_scale(ri, 200, 200); dim = raster_image_dimensions(si); frames = raster_image_frame_count(si); assert(dim.width <= 200); assert(dim.height <= 200); assert(abs((double) dim.width / dim.height - 277./344) <= 1e-3); assert(frames == 163); raster_image_optimize(si); dim = raster_image_dimensions(si); frames = raster_image_frame_count(si); assert(dim.width <= 200); assert(dim.height <= 200); assert(abs((double) dim.width / dim.height - 277./344) <= 1e-3); assert(frames == 163); raster_image_to_file(si, "test/test_gif_animated_scaled.gif"); raster_image_free(si); raster_image_free(ri); } int main(int argc, char *argv[]) { // Test loading from buffer test_load_buf(); // Test loading various files test_load_file_jpg(); test_load_file_jpg_orient(); test_load_file_png(); test_load_file_gif_static(); test_load_file_gif_animated(); return 0; }
5e07008a99c5a11d25c0161d6e0aec52a536d5f7
8b66fd528468a2d7f8fd5fb8dab385086c8507ff
/final_sockets_project/contacts.c
40eff519ff0899bd3990f21b2203130b43681350
[]
no_license
alexgalloway20/summer2019
0a18a8769d07a366b736f525d2b076b1a5108952
4b7a1d5f3f62123da6b010031fbed8fa3812c853
refs/heads/master
2020-05-25T06:10:34.519999
2019-05-22T05:13:32
2019-05-22T05:13:32
187,663,642
0
0
null
null
null
null
UTF-8
C
false
false
3,718
c
contacts.c
#include <netdb.h> #include <errno.h> #include <sys/socket.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <string.h> #include <mysql/mysql.h> #define MAXADDRLEN 256 #define BUFLEN 128 extern int errno; void print_error(char *); int main(int argc, char *argv[]) { char firstName[24] = ""; char lastName[48] = ""; char email[36] = ""; long long phoneNumber; char resultCode[4]; struct addrinfo *host_ai; struct addrinfo hint; int sockfd, err; if (argc != 2) print_error("usage: client hostname"); for(;;) { int command, rec; printf("\n1. Insert New Contact\n"); printf("2. List contacts\n"); printf("3. Exit\n\n"); scanf("%d", &command); while ((getchar()) != '\n'); if(command == 1) { printf("\nAdding a new contact...\n\n"); send(sockfd, &command, 4, 0); bzero(firstName, sizeof(firstName)); printf("Enter first name: "); fgets(firstName, 24, stdin); send(sockfd, firstName, sizeof(firstName), 0); bzero(lastName, sizeof(lastName)); printf("Enter last name: "); fgets(lastName, 48, stdin); send(sockfd, lastName, sizeof(lastName), 0); bzero(email, sizeof(email)); printf("Enter email: "); fgets(email, 36, stdin); send(sockfd, email, sizeof(email), 0); printf("Enter phone number: "); scanf(" %lld", &phoneNumber); send(sockfd, &phoneNumber, sizeof(long long), 0); read(sockfd, resultCode, sizeof(resultCode)); printf("\n%s\n", resultCode); close(sockfd); break; } if(command == 2){ sockfd = server_connect(argv[1]); if(send(sockfd, &command, 4, 0) < 0){ printf("Error sending data: %s\n", strerror(errno)); } char *receiver = "0x02"; if(send(sockfd, receiver, 4, 0) < 0){ printf("Error sending data: %s\n", strerror(errno)); } int count; if(recv(sockfd, &count, 4, 0) < 0){ printf("Error receiving data: %s\n", strerror(errno)); } char *ret; int req = 116 * count; ret = malloc(req); memset(ret, 0, req); int count1 = 0; while(count1 < 4 * count){ if(recv(sockfd, ret, req, 0) < 0){ printf("Error receiving data: %s\n", strerror(errno)); } if(count1 % 4 == 0){ printf("\n"); } } printf("%s ", ret); count1++; } close(sockfd); break; if(command == 3) { printf("\nExiting...\n\n"); exit(1); } } } int server_connect(char *iphost){ struct addrinfo *host_ai; struct addrinfo hint; int sockfd, err; hint.ai_flags = 0; hint.ai_family = AF_INET; hint.ai_socktype = SOCK_STREAM; hint.ai_protocol = 0; hint.ai_addrlen = 0; hint.ai_canonname = NULL; hint.ai_addr = NULL; hint.ai_next = NULL; if ((err = getaddrinfo(iphost, "contacts", &hint, &host_ai)) != 0) { printf("getaddrinfo error: %s\n", gai_strerror(err)); return 0; } printf("creating socket\n"); if ((sockfd = socket(host_ai->ai_addr->sa_family, SOCK_STREAM, 0)) < 0) { print_error("Error creating socket"); } printf("socket created\n"); printf("attempting Connection\n"); if (connect(sockfd, host_ai->ai_addr, host_ai->ai_addrlen) != 0) { printf("can't connect to %s\n", iphost); print_error("Error connecting to server"); } printf("connection made...\n"); return(sockfd); } void print_error(char *str) { printf("%s: %s\n", str, strerror(errno)); exit(1); } // END OF FILE
e984792404c09494273d46fc848b24ad6f798053
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/Provenance/Cores/Genesis-Plus-GX/PVGenesis/Genesis/GenesisCore/genplusgx_source/gx/gui/extr_legal.c_legal.c
bfb29c5b7af7d58cc8b7ca80e41dcfde45278df0
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
4,325
c
extr_legal.c_legal.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ typedef struct TYPE_8__ TYPE_2__ ; typedef struct TYPE_7__ TYPE_1__ ; /* Type definitions */ typedef int /*<<< orphan*/ u8 ; struct TYPE_7__ {int width; int height; struct TYPE_7__* data; } ; typedef TYPE_1__ gx_texture ; struct TYPE_8__ {int /*<<< orphan*/ keys; } ; typedef int /*<<< orphan*/ GXColor ; /* Variables and functions */ int ASND_GetFirstUnusedVoice () ; int /*<<< orphan*/ ASND_Pause (int) ; int /*<<< orphan*/ ASND_SetVoice (int,int /*<<< orphan*/ ,int,int /*<<< orphan*/ ,int /*<<< orphan*/ *,int /*<<< orphan*/ ,int,int,int /*<<< orphan*/ *) ; scalar_t__ BLACK ; int /*<<< orphan*/ Bg_intro_c1_png ; int /*<<< orphan*/ Bg_intro_c2_png ; int /*<<< orphan*/ Bg_intro_c3_png ; int /*<<< orphan*/ Bg_intro_c4_png ; int /*<<< orphan*/ FONT_writeCenter (char*,int,int /*<<< orphan*/ ,int,int,int /*<<< orphan*/ ) ; int /*<<< orphan*/ GUI_FadeOut () ; int /*<<< orphan*/ Key_A_gcn_png ; int /*<<< orphan*/ Key_A_wii_png ; scalar_t__ SKY_BLUE ; int /*<<< orphan*/ VOICE_MONO_16BIT ; scalar_t__ WHITE ; scalar_t__ button_select_pcm ; int /*<<< orphan*/ button_select_pcm_size ; int /*<<< orphan*/ free (TYPE_1__*) ; int /*<<< orphan*/ gxClearScreen (int /*<<< orphan*/ ) ; int /*<<< orphan*/ gxDrawTexture (TYPE_1__*,int,int,int,int,int) ; int /*<<< orphan*/ gxSetScreen () ; int /*<<< orphan*/ gxTextureClose (TYPE_1__**) ; TYPE_1__* gxTextureOpenPNG (int /*<<< orphan*/ ,int /*<<< orphan*/ ) ; scalar_t__ intro_pcm ; int /*<<< orphan*/ intro_pcm_size ; TYPE_2__ m_input ; int /*<<< orphan*/ show_disclaimer (int) ; int /*<<< orphan*/ sleep (int) ; void legal () { int count = 2000; int vis = 0; #ifdef HW_RVL gx_texture *button = gxTextureOpenPNG(Key_A_wii_png,0); #else gx_texture *button = gxTextureOpenPNG(Key_A_gcn_png,0); #endif gx_texture *logo = gxTextureOpenPNG(Bg_intro_c4_png,0); gxClearScreen((GXColor)BLACK); show_disclaimer(56); gxDrawTexture(logo, (640-logo->width)/2, 480-24-logo->height, logo->width, logo->height,255); gxSetScreen(); sleep(1); while (!m_input.keys && count) { gxClearScreen((GXColor)BLACK); show_disclaimer(56); if (count%25 == 0) vis^=1; if (vis) { FONT_writeCenter("Press button to continue.",24,0,640,366,(GXColor)SKY_BLUE); gxDrawTexture(button, 220, 366-24+(24-button->height)/2, button->width, button->height,255); } gxDrawTexture(logo, (640-logo->width)/2, 480-24-logo->height, logo->width, logo->height,255); gxSetScreen(); count--; } gxTextureClose(&button); gxTextureClose(&logo); if (count > 0) { ASND_Pause(0); int voice = ASND_GetFirstUnusedVoice(); ASND_SetVoice(voice,VOICE_MONO_16BIT,44100,0,(u8 *)button_select_pcm,button_select_pcm_size,200,200,NULL); GUI_FadeOut(); ASND_Pause(1); return; } gxClearScreen((GXColor)BLACK); gx_texture *texture = gxTextureOpenPNG(Bg_intro_c1_png,0); if (texture) { gxDrawTexture(texture, (640-texture->width)/2, (480-texture->height)/2, texture->width, texture->height,255); if (texture->data) free(texture->data); free(texture); } gxSetScreen(); sleep (1); gxClearScreen((GXColor)WHITE); texture = gxTextureOpenPNG(Bg_intro_c2_png,0); if (texture) { gxDrawTexture(texture, (640-texture->width)/2, (480-texture->height)/2, texture->width, texture->height,255); if (texture->data) free(texture->data); free(texture); } gxSetScreen(); sleep (1); gxClearScreen((GXColor)BLACK); texture = gxTextureOpenPNG(Bg_intro_c3_png,0); if (texture) { gxDrawTexture(texture, (640-texture->width)/2, (480-texture->height)/2, texture->width, texture->height,255); if (texture->data) free(texture->data); free(texture); } gxSetScreen(); ASND_Pause(0); int voice = ASND_GetFirstUnusedVoice(); ASND_SetVoice(voice,VOICE_MONO_16BIT,44100,0,(u8 *)intro_pcm,intro_pcm_size,200,200,NULL); sleep (2); ASND_Pause(1); }
a6c643fc6623092ff547b33cd92a1a5f641be4de
6af50a4b5b928211880dd9f1c6ce92c2afea828b
/arch/xtensa/core/fatal.c
98fb3f4eef5b57ba8af3dbbf91027427db83b8ab
[ "Apache-2.0" ]
permissive
erwango/zephyr
1c7aa447f613de76439291ba9dde1e4dc7c5786e
162f4574c781ae17d3fecfd4ac10df111e90ae3c
refs/heads/arm
2023-08-11T10:29:20.031948
2017-05-10T09:50:21
2017-05-10T14:22:48
76,642,373
6
0
Apache-2.0
2020-02-04T19:16:46
2016-12-16T09:52:08
C
UTF-8
C
false
false
6,425
c
fatal.c
/* * Copyright (c) 2016 Cadence Design Systems, Inc. * SPDX-License-Identifier: Apache-2.0 */ #include <kernel.h> #include <arch/cpu.h> #include <kernel_structs.h> #include <inttypes.h> #include <kernel_arch_data.h> #include <misc/printk.h> #include <xtensa/specreg.h> const NANO_ESF _default_esf = { {0xdeaddead}, /* sp */ 0xdeaddead, /* pc */ }; /* Need to do this as a macro since regnum must be an immediate value */ #define get_sreg(regnum_p) ({ \ unsigned int retval; \ __asm__ volatile( \ "rsr %[retval], %[regnum]\n\t" \ : [retval] "=r" (retval) \ : [regnum] "i" (regnum_p)); \ retval; \ }) /** * * @brief Fatal error handler * * This routine is called when fatal error conditions are detected by software * and is responsible only for reporting the error. Once reported, it then * invokes the user provided routine _SysFatalErrorHandler() which is * responsible for implementing the error handling policy. * * The caller is expected to always provide a usable ESF. In the event that the * fatal error does not have a hardware generated ESF, the caller should either * create its own or use a pointer to the global default ESF <_default_esf>. * * @param reason the reason that the handler was called * @param pEsf pointer to the exception stack frame * * @return This function does not return. */ FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf) { switch (reason) { case _NANO_ERR_HW_EXCEPTION: case _NANO_ERR_RESERVED_IRQ: break; case _NANO_ERR_INVALID_TASK_EXIT: printk("***** Invalid Exit Software Error! *****\n"); break; #if defined(CONFIG_STACK_CANARIES) case _NANO_ERR_STACK_CHK_FAIL: printk("***** Stack Check Fail! *****\n"); break; #endif /* CONFIG_STACK_CANARIES */ case _NANO_ERR_ALLOCATION_FAIL: printk("**** Kernel Allocation Failure! ****\n"); break; case _NANO_ERR_KERNEL_OOPS: printk("***** Kernel OOPS! *****\n"); break; case _NANO_ERR_KERNEL_PANIC: printk("***** Kernel Panic! *****\n"); break; default: printk("**** Unknown Fatal Error %d! ****\n", reason); break; } printk("Current thread ID = %p\n" "Faulting instruction address = 0x%x\n", k_current_get(), pEsf->pc); /* * Now that the error has been reported, call the user implemented * policy * to respond to the error. The decisions as to what responses are * appropriate to the various errors are something the customer must * decide. */ _SysFatalErrorHandler(reason, pEsf); } #ifdef CONFIG_PRINTK static char *cause_str(unsigned int cause_code) { switch (cause_code) { case 0: return "illegal instruction"; case 1: return "syscall"; case 2: return "instr fetch error"; case 3: return "load/store error"; case 4: return "level-1 interrupt"; case 5: return "alloca"; case 6: return "divide by zero"; case 8: return "privileged"; case 9: return "load/store alignment"; case 12: return "instr PIF data error"; case 13: return "load/store PIF data error"; case 14: return "instr PIF addr error"; case 15: return "load/store PIF addr error"; case 16: return "instr TLB miss"; case 17: return "instr TLB multi hit"; case 18: return "instr fetch privilege"; case 20: return "inst fetch prohibited"; case 24: return "load/store TLB miss"; case 25: return "load/store TLB multi hit"; case 26: return "load/store privilege"; case 28: return "load prohibited"; case 29: return "store prohibited"; case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39: return "coprocessor disabled"; default: return "unknown/reserved"; } } #endif static inline unsigned int get_bits(int offset, int num_bits, unsigned int val) { int mask; mask = (1 << num_bits) - 1; val = val >> offset; return val & mask; } static void dump_exc_state(void) { #ifdef CONFIG_PRINTK unsigned int cause, ps; cause = get_sreg(EXCCAUSE); ps = get_sreg(PS); printk("Exception cause %d (%s):\n" " EPC1 : 0x%08x EXCSAVE1 : 0x%08x EXCVADDR : 0x%08x\n", cause, cause_str(cause), get_sreg(EPC_1), get_sreg(EXCSAVE_1), get_sreg(EXCVADDR)); printk("Program state (PS):\n" " INTLEVEL : %02d EXCM : %d UM : %d RING : %d WOE : %d\n", get_bits(0, 4, ps), get_bits(4, 1, ps), get_bits(5, 1, ps), get_bits(6, 2, ps), get_bits(18, 1, ps)); #ifndef __XTENSA_CALL0_ABI__ printk(" OWB : %02d CALLINC : %d\n", get_bits(8, 4, ps), get_bits(16, 2, ps)); #endif #endif /* CONFIG_PRINTK */ } FUNC_NORETURN void FatalErrorHandler(void) { printk("*** Unhandled exception ****\n"); dump_exc_state(); _NanoFatalErrorHandler(_NANO_ERR_HW_EXCEPTION, &_default_esf); } FUNC_NORETURN void ReservedInterruptHandler(unsigned int intNo) { printk("*** Reserved Interrupt ***\n"); dump_exc_state(); printk("INTENABLE = 0x%x\n" "INTERRUPT = 0x%x (%d)\n", get_sreg(INTENABLE), (1 << intNo), intNo); _NanoFatalErrorHandler(_NANO_ERR_RESERVED_IRQ, &_default_esf); } /* Implemented in Xtensa HAL */ extern FUNC_NORETURN void exit(int exit_code); /** * * @brief Fatal error handler * * This routine implements the corrective action to be taken when the system * detects a fatal error. * * This sample implementation attempts to abort the current thread and allow * the system to continue executing, which may permit the system to continue * functioning with degraded capabilities. * * System designers may wish to enhance or substitute this sample * implementation to take other actions, such as logging error (or debug) * information to a persistent repository and/or rebooting the system. * * @param reason the fatal error reason * @param pEsf pointer to exception stack frame * * @return N/A */ FUNC_NORETURN void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf) { ARG_UNUSED(pEsf); #if !defined(CONFIG_SIMPLE_FATAL_ERROR_HANDLER) if (reason == _NANO_ERR_KERNEL_PANIC) { goto hang_system; } if (k_is_in_isr() || _is_thread_essential()) { printk("Fatal fault in %s! Spinning...\n", k_is_in_isr() ? "ISR" : "essential thread"); goto hang_system; } printk("Fatal fault in thread %p! Aborting.\n", _current); k_thread_abort(_current); hang_system: #else ARG_UNUSED(reason); #endif #ifdef XT_SIMULATOR exit(255 - reason); #else for (;;) { k_cpu_idle(); } #endif CODE_UNREACHABLE; }
443a497c620f84a64188b81e13303067a6fdfff8
1ef9acf41d1e321b3a774741dc8e1d589d9478c8
/sampleCodesC/App/app_cfg.h
4abcb1cdeb778240baf120232ea8375d2df1c15a
[]
no_license
salvadorz/embeddedProgramming
1e54187a352349f31d43774e344f8f9bea3aaea0
1f000a0697223479ff5fa72f9a6a878a8cd0bf4b
refs/heads/master
2020-03-09T09:57:10.204432
2018-05-07T19:08:59
2018-05-07T19:08:59
128,725,019
0
0
null
null
null
null
UTF-8
C
false
false
277
h
app_cfg.h
/* * app_cfg.h * * Created on: 22/04/2018 * Author: John */ #ifndef APP_APP_CFG_H_ #define APP_APP_CFG_H_ #include "common.h" #ifndef TEST_MATH //#define TEST_MATH #endif #ifndef TEST_PTR #define TEST_PTR #endif #endif /* APP_APP_CFG_H_ */
af4e207929add922540bdabef61298c2147b3e4e
ea962997305cf24720c5f5c3a24416b76b3d5b60
/LPC1769/src/Timer.c
54edfa3d9fa5fba2fca23b9f9d88619bbc6d11b7
[]
no_license
PsychoSnake/SE2
175c5de1745cd73703b3580314d0e90f2b6fe9e3
64d6efc30266d6b105c26272f4a27e90b4db6562
refs/heads/master
2021-03-27T12:56:48.617780
2018-06-17T10:46:09
2018-06-17T10:46:09
123,959,243
0
0
null
null
null
null
UTF-8
C
false
false
480
c
Timer.c
#include <Timer.h> #include "LPC17xx.h" #define TIMER_ON 1 #define TIMER_OFF 2 void TIMER0_Init(unsigned int frequency){ LPC_TIM0->TCR = TIMER_OFF; LPC_SC->PCLKSEL0 |= 1 << 2; LPC_TIM0->PR = (((SystemCoreClock / frequency)) / 1000) - 1; LPC_TIM0->MCR = 0; LPC_TIM0->EMR = 0; LPC_TIM0->CTCR = 0; LPC_TIM0->TCR = TIMER_ON; } unsigned int TIMER0_GetValue(void){ return LPC_TIM0->TC; } unsigned int TIMER0_Elapse(unsigned int lastRead){ return LPC_TIM0->TC - lastRead; }
daa10dc9ac1215106b16589ab33a4034e83e427c
58dbd1dd5440a355f232e63ff479d5a69b1efe6b
/Firmware_March21_HCU/IMU_ACC_GYR.h
f418eae5fa4fd35f80df3df341282a74137d3459
[]
no_license
JSzypicyn/FirmwareMarch_HCU
0725492bb337d1b8a1a5d27b52906c6213cf31da
d264ebe6bc127f48ef1ac35cc1b77b490b359fcd
refs/heads/main
2023-06-16T07:05:20.935839
2021-07-13T14:34:12
2021-07-13T14:34:12
378,933,572
0
0
null
null
null
null
UTF-8
C
false
false
7,551
h
IMU_ACC_GYR.h
#ifndef IMU_ACC_GYR_file #define IMU_ACC_GYR_file #include <Adafruit_MPU6050.h> #include <Adafruit_Sensor.h> #include <FlashStorage_STM32.h> #include <Wire.h> #include <PinDefs.h> #include <Math.h> #include <FIR.h> static inline int8_t sgn(float val) { if (val < 0) return -1; if (val==0) return 1; return 1; } FIR<float, FIR_FILTER_LEN_LPF_ACC> firAcc; FIR<float, FIR_FILTER_LEN_MA_SPEED> firSpeed; FIR<float, FIR_FILTER_LEN_ACC> xacc_fir; FIR<float, FIR_FILTER_LEN_ACC> yacc_fir; FIR<float, FIR_FILTER_LEN_ACC> zacc_fir; FIR<float, FIR_FILTER_LEN_EXTRA> extra_fir; float currAngle = 0; int sampleIMUtime; Adafruit_MPU6050 mma; Adafruit_Sensor *mpu_temp, *mpu_accel, *mpu_gyro; sensors_event_t accel; sensors_event_t gyro; sensors_event_t temp; float newPitch = 0; float previous_mean_speed = 0; int8_t IMU_DS_ctr = 0; float acc_est = 0; const int WRITTEN_SIGNATURE = 0xBEEFDEED; typedef struct { float xacc; float zacc; float yacc; float xgyr; float ygyr; float zgyr; float refAngle1; float refAngle2; float refAngle3; float magG; } MMAOUT; float gyroAngleX = 0; float gyroAngleY = 0; float gyroAngleZ = 0; float gyroAngleZ2 = 0; MMAOUT zeroPoint; float filtAngle = 0; void getIMUData(void) { //mpu_temp->getEvent(&temp); mpu_accel->getEvent(&accel); mpu_gyro->getEvent(&gyro); } void readMeanIMU(void) { zeroPoint.xacc = 0; zeroPoint.yacc = 0; zeroPoint.zacc = 0; zeroPoint.xgyr = 0; zeroPoint.ygyr = 0; zeroPoint.zgyr = 0; digitalWrite(GLED, LOW); digitalWrite(RLED, HIGH); for (int ctr = 0; ctr <= 256; ctr++) { getIMUData(); if (ctr % 100 == 0) { digitalToggle(GLED); digitalToggle(RLED); } } for (int ctr = 0; ctr <= NUM_CAL_SAMPS; ctr++) { getIMUData(); zeroPoint.xacc += accel.acceleration.x; zeroPoint.yacc += accel.acceleration.y; zeroPoint.zacc += accel.acceleration.z; zeroPoint.xgyr += gyro.gyro.x; zeroPoint.ygyr += gyro.gyro.y; zeroPoint.zgyr += gyro.gyro.z; if (ctr % 100 == 0) { digitalToggle(GLED); digitalToggle(RLED); } } zeroPoint.xacc = zeroPoint.xacc / 1024.0; zeroPoint.yacc = zeroPoint.yacc / 1024.0; zeroPoint.zacc = zeroPoint.zacc / 1024.0; zeroPoint.xgyr = zeroPoint.xgyr / 1024.0; zeroPoint.ygyr = zeroPoint.ygyr / 1024.0; zeroPoint.zgyr = zeroPoint.zgyr / 1024.0; zeroPoint.refAngle1 = 180 * atan (zeroPoint.xacc / sqrt(zeroPoint.yacc * zeroPoint.yacc + zeroPoint.zacc * zeroPoint.zacc)) / M_PI; zeroPoint.refAngle2 = 180 * atan (zeroPoint.yacc / sqrt(zeroPoint.xacc * zeroPoint.xacc + zeroPoint.zacc * zeroPoint.zacc)) / M_PI; zeroPoint.refAngle3 = 180 * atan (zeroPoint.zacc / sqrt(zeroPoint.yacc * zeroPoint.yacc + zeroPoint.xacc * zeroPoint.xacc)) / M_PI; zeroPoint.magG = sqrt(zeroPoint.yacc * zeroPoint.yacc + zeroPoint.zacc * zeroPoint.zacc + zeroPoint.xacc * zeroPoint.xacc); digitalWrite(GLED, LOW); digitalWrite(RLED, LOW); } // Setup IMU and Comms void setupIMU(void) { // IMU is powered through a digital pin otherwise when a board undergoes soft reset, IMU remains powered and gets stuck. pinMode(IMU_PWR, OUTPUT); digitalWrite(IMU_PWR, LOW); delay(500); digitalWrite(IMU_PWR, HIGH); // Setup I2C Port Wire.setSDA(I2C_DataPin); Wire.setSCL(I2C_ClockPin); Wire.begin(); Wire.setClock(400000L); // Connect mma.begin(); // Keep trying to connect while (! mma.begin()) { Serial1.println("tuck"); digitalWrite(RLED, HIGH); } digitalWrite(RLED, LOW); // Change the detection range in PinDefs.h //zeroPoint = IMUcal(); mma.setAccelerometerRange(A_RANGE); mma.setGyroRange(G_RANGE); mma.setFilterBandwidth(BW_FILTER); mpu_temp = mma.getTemperatureSensor(); mpu_accel = mma.getAccelerometerSensor(); mpu_gyro = mma.getGyroSensor(); readMeanIMU(); firAcc.setFilterCoeffs(aLPF); firSpeed.setFilterCoeffs(aMA); xacc_fir.setFilterCoeffs(accMA); yacc_fir.setFilterCoeffs(accMA); zacc_fir.setFilterCoeffs(accMA); extra_fir.setFilterCoeffs(extraMA); } void IMUcal(void) { int signature; EEPROM.get(CAL_ADDRESS, signature); // If the EEPROM is empty then no WRITTEN_SIGNATURE if (signature == WRITTEN_SIGNATURE) { EEPROM.get(CAL_ADDRESS + sizeof(signature), zeroPoint); } else { EEPROM.put(CAL_ADDRESS, WRITTEN_SIGNATURE); readMeanIMU(); // ...and finally save everything into emulated-EEPROM EEPROM.put(CAL_ADDRESS + sizeof(signature), zeroPoint); } } /* MAIN INCLINE CALCULATION FUNCTION */ float XYZtoInc() { float refAngle; // float magV; float filt_angle; /* GET TIME STEP */ int time_temp = micros(); int td; if (time_temp > sampleIMUtime) { td = time_temp - sampleIMUtime; } else { td = (OVERFLOW_32BIT - sampleIMUtime) + time_temp; } /* GET IMU DATA */ getIMUData(); /* ESTIMATE ACCELERATION OF THE BIKE */ float current_mean_speed = firSpeed.processReading(wheelSpeed); acc_est = (current_mean_speed - previous_mean_speed) * 1 * 1e6 / float(td); //Serial1.println(acc_est); if (acc_est > 1) acc_est = 1; if (acc_est < -1) acc_est = -1; previous_mean_speed = current_mean_speed; //acc_est =0; /* Integrate Gyro Reading */ gyroAngleZ = newPitch - (gyro.gyro.z - zeroPoint.zgyr) * float(td) * 1e-6; /* DOWNSAMPLING COUNTER */ IMU_DS_ctr++; /* CALCULATE TOTAL G FORCE */ // magV = sqrt(accel.acceleration.y * accel.acceleration.y + accel.acceleration.x * accel.acceleration.x + accel.acceleration.z * accel.acceleration.z); /* ESTIMATE ANGLE FROM ACC-METER accounting for reference angle and physcial acceleration then filter */ refAngle = zeroPoint.refAngle2; float prev_currAngle = currAngle; if (abs(acc_est) > 0.6) { currAngle = 180 * atan ((accel.acceleration.y + acc_est * cos(refAngle * M_PI / 180.0) ) / sqrt((accel.acceleration.x - acc_est * sin(refAngle * M_PI / 180.0)) * (accel.acceleration.y - acc_est * sin(refAngle * M_PI / 180.0)) + accel.acceleration.z * accel.acceleration.z)) / M_PI; } else { currAngle = 180 * atan (accel.acceleration.y / sqrt((accel.acceleration.x) * (accel.acceleration.x) + accel.acceleration.z * accel.acceleration.z)) / M_PI; } if (isnan(currAngle)) { currAngle = prev_currAngle; } float x_temp = xacc_fir.processReading(accel.acceleration.x); float y_temp = yacc_fir.processReading(accel.acceleration.y); float z_temp = zacc_fir.processReading(accel.acceleration.z); float currAngle2 = 180 * atan (y_temp/ sqrt(x_temp * x_temp + z_temp * z_temp)) / M_PI; currAngle = extra_fir.processReading(currAngle2); //float filt_angle = LPF_ACC_GAIN * firAcc.processReading(-(currAngle - refAngle)); /* STORE TIMESTAMP */ sampleIMUtime = time_temp; /* FUSE SENSOR READINGS BY DOWNSAMPLING ACC-METER READOUT */ if (current_mean_speed > 0) { if (IMU_DS_ctr == MOD_CTR) { newPitch = 0.96 * gyroAngleZ + 0.04 * (-(currAngle - refAngle)); IMU_DS_ctr = 0; } else { newPitch = 0.99 * gyroAngleZ + 0.01 * filt_angle; } } else { if (IMU_DS_ctr == MOD_CTR) { newPitch = 0.9 * gyroAngleZ + 0.1 * (-(currAngle - refAngle)); IMU_DS_ctr = 0; } else { newPitch = 0.99 * gyroAngleZ + 0.01 * filt_angle; } } return -newPitch; } #endif
328afece4e893945f1fb59f8b5e02923efb920ee
c00ed5109418afb489079505e40d5cf7fff0af85
/app/src/main/jni/native-test.c
d375cf9ab05a658220829baaad6472b3cc6b8c6a
[]
no_license
jjp9624022/TestRosBridge
cd31cd37da7180f6005ae0cfa2346c0e858edf0e
f686535c6fa70437fa2dc00350768a7802f2aeb0
refs/heads/master
2023-05-28T07:06:34.205819
2018-11-11T13:11:23
2018-11-11T13:11:23
null
0
0
null
null
null
null
UTF-8
C
false
false
204
c
native-test.c
#include <jni.h> JNIEXPORT jstring JNICALL Java_com_example_dadac_testrosbridge_JNICallAll_stringFromJNI(JNIEnv *env, jobject instance) { char *a = "wen"; return (*env)->NewStringUTF(env, a); }
65aecaabfe450e54a9b57ed0607327e508cf068e
6ce3f1bd26f5a99537cb2b7aba6ca328f65d2340
/6_Keys/HARDWARE/4gpio_matrix_key.h
710fa9474b59d7dc630350f6d57e0d6ed453a9d8
[]
no_license
ebhorizon/Embedded_System_MCS51
8e885553ad4133b27df70cea83e1a776d3832237
5f498d6a8b6faa6b47c60d8b98fc8dbf2325b55c
refs/heads/master
2022-10-10T01:15:38.460879
2020-06-14T15:03:41
2020-06-14T15:03:41
271,720,235
1
0
null
null
null
null
GB18030
C
false
false
304
h
4gpio_matrix_key.h
#ifndef _4GPIO_MATRIX_KEY_H_ #define _4GPIO_MATRIX_KEY_H_ #include <reg52.h> // 定义常用类型 #ifndef u8 #define u8 unsigned char #endif #ifndef u16 #define u16 unsigned int #endif #define GPIOKEYS P2 // 只使用P2.0 ~ P2.3 // 加消抖的扫描 u8 GPIOKeyScanAgain(); #endif
2038d99c81602f39fe570113c238970f99252608
a33aac97878b2cb15677be26e308cbc46e2862d2
/program_data/PKU_raw/103/36.c
02800d935cadef93c52c60ff6f2700f2c19435be
[]
no_license
GabeOchieng/ggnn.tensorflow
f5d7d0bca52258336fc12c9de6ae38223f28f786
7c62c0e8427bea6c8bec2cebf157b6f1ea70a213
refs/heads/master
2022-05-30T11:17:42.278048
2020-05-02T11:33:31
2020-05-02T11:33:31
null
0
0
null
null
null
null
UTF-8
C
false
false
586
c
36.c
main() { char a[1001]; int n,i,x,count; scanf("%s",a); n=strlen(a); for(i=0;i<n;i++) { if(a[i]>'Z') a[i]=a[i]-'a'+'A'; } for(i=0,count=0,x=a[0];i<n;i++) { if(a[i]==x) { count++; } else { printf("(%c,%d)",x,count); count=1; x=a[i]; } if(i==n-1) printf("(%c,%d)",x,count); } getchar(); getchar(); return 0; }
b44b083bfa1e4cc599c113e372a356a54e012335
b32f7c4af16f34732c54ef84f2c0fa75d2010a79
/midtermsh/midtermsh.c
6b01eef2c58ea28ad9fb17c8c5322222ff24a651
[]
no_license
nikitakaberov/OS
0e7698eab69b45d357241a4c97d55d5a9735cc6d
71a148b49d1fed632271fc12c375e6454baecf92
refs/heads/master
2020-12-07T03:52:04.218228
2016-06-02T12:31:35
2016-06-02T12:31:35
53,164,094
0
0
null
null
null
null
UTF-8
C
false
false
1,926
c
midtermsh.c
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <string.h> #include <signal.h> void print$() { write(STDOUT_FILENO, "$ ", 2); } void sig_handler(int signo) { if (signo == SIGINT) { write(STDOUT_FILENO, "\n", 1); print$(); } } int main() { while(42) { print$(); signal(SIGINT, sig_handler); char *progs[4096]; int k = 0; char com[4096]; char arg[4096]; int first[2]; int second[2]; memset(com, 0, sizeof(char) * 4096); ssize_t len = read(STDIN_FILENO, com, 4096); com[len - 1] = 0; char* chs = strtok(com, "|"); while (chs != NULL) { progs[k++] = chs; chs = strtok(NULL, "|"); } int childs[4096]; int cld_cnt = 0; int i = 0; for (; i < k; i++) { char * args[4096]; int t = 0; memset(args, 0, sizeof(args)); char* chs = strtok(progs[i], " "); while (chs != NULL) { args[t++] = chs; chs = strtok(NULL, " "); } args[t++] = NULL; pipe(second); pid_t child = fork(); if (child < 0) { perror("Failed\n"); } else { childs[cld_cnt++] = child; } if (child == 0) { if (i > 0) { dup2(first[0], STDIN_FILENO); close(first[0]); close(first[1]); } if (i != k - 1) dup2(second[1], STDOUT_FILENO); close(second[0]); close(second[1]); execvp(args[0], args); } else { if (i > 0) { close(first[0]); close(first[1]); } if (i == k - 1) { close(second[0]); close(second[1]); } } first[0] = second[0]; first[1] = second[1]; } for (i = 0; i < cld_cnt; i++) waitpid(childs[i], 0, NULL); } }
c96072dea41e8c8b2c26bedf4eafa6cdf704ac39
9c5e94b59ce64f15ddbdc1ec6ecc8d005c305912
/libnemo-extension/nemo-extension-sims.c
aab3ffb32ba9e55c21b2ab6b731e4505891d24a0
[ "MIT" ]
permissive
Hsin2Code/technology
23250b4ba342a272c24fe06b0d58b79c340b67fa
0fa76359790b2ee371fb0bc611a1979fc4a77e69
refs/heads/master
2020-06-23T14:26:07.258387
2017-09-25T12:22:57
2017-09-25T12:22:57
74,646,169
0
0
null
null
null
null
UTF-8
C
false
false
6,380
c
nemo-extension-sims.c
#ifdef HAVE_CONFIG_H #include <config.h> /* for GETTEXT_PACKAGE */ #endif #include "nemo-extension-sims.h" #include "nemo-sims-callback.h" #include <libnemo-extension/nemo-extension-types.h> #include <libnemo-extension/nemo-file-info.h> #include <libnemo-extension/nemo-menu-provider.h> #include <glib.h> #include <gio/gio.h> #include <gtk/gtk.h> #include <syslog.h> #include <errno.h> #include <fcntl.h> #include <stdlib.h> /* for atoi */ #include <string.h> /* for strcmp */ #include <unistd.h> /* for chdir */ #include <sys/stat.h> #define ICONS_PATH "/usr/lib/vrv/icons/" static void nemo_sims_instance_init (NemoSims *cvs); static void nemo_sims_class_init (NemoSimsClass *class); static GType sims_type = 0; static GObjectClass *object_class = NULL; /* 支持的文件格式 */ static struct { char *mime_type; gboolean is_added; } archive_mime_types[] = { { "", TRUE }, { "", TRUE }, { "", TRUE }, { NULL, FALSE }, }; static gboolean unsupported_scheme (NemoFileInfo *file) { return TRUE; int i = 0; for (i = 0; archive_mime_types[i].mime_type != NULL; i++) { if (nemo_file_info_is_mime_type (file, archive_mime_types[i].mime_type)) { return TRUE; } } return FALSE; } #define MENU_APPEND_ITEM(type, label, tip, icon) \ { \ NemoMenuItem *item = nemo_menu_item_new (item_type_str[type], label, tip, icon); \ nemo_menu_append_item (menu, item); \ g_object_set_data_full (G_OBJECT (item), \ "files", \ nemo_file_info_list_copy (files), \ (GDestroyNotify) nemo_file_info_list_free); \ g_signal_connect (item, \ "activate", \ G_CALLBACK (item_type_func[type]), \ provider); \ } static GList * nemo_sims_get_file_items (NemoMenuProvider *provider, GtkWidget *window, GList *files) { if (g_list_length (files) != 1) /* 选定多个文件不显示 */ return NULL; /* if (nemo_file_info_is_mime_type ((NemoFileInfo *)files->data, "text")) */ /* return NULL; */ GList *items = NULL; /* 预定密 菜单 */ { NemoMenu *menu = nemo_menu_new(); NemoMenuItem *item = nemo_menu_item_new("Sims::Preset", "预定密", "预定级菜单", ICONS_PATH"Preset.bmp"); nemo_menu_item_set_submenu(item, menu); MENU_APPEND_ITEM(PRESET_LEVEL, "预定密", "文件预定密", ICONS_PATH"PresetLevel.bmp"); MENU_APPEND_ITEM(PRESET_INSPECT, "查看密级", "查看文件密级", ICONS_PATH"PresetInspect.bmp"); MENU_APPEND_ITEM(PRESET_REVISE, "修改密级", "修改文件密级", ICONS_PATH"PresetRevise.bmp"); items = g_list_append (items, item); } /* 密级标志管理系统子菜单项目 */ { NemoMenu *menu = nemo_menu_new(); NemoMenuItem *item = nemo_menu_item_new("Sims", "密级标志管理系统", "密级标志管理", ICONS_PATH"Sims.bmp"); nemo_menu_item_set_submenu(item, menu); /* -------------- 本地流程 --------------- */ MENU_APPEND_ITEM(LOCAL_OPEN, "安全打开", "安全打开文件", ICONS_PATH"LocalOpen.bmp"); /* -------------- 网络流程 --------------- */ MENU_APPEND_ITEM(NETWORK_APPLY, "申请定密", "申请文件定密", ICONS_PATH"NetworkApply.bmp"); MENU_APPEND_ITEM(NETWORK_CHANGE, "密级变更", "变更文件密级", ICONS_PATH"NetworkChange.bmp"); MENU_APPEND_ITEM(NETWORK_ISSUE, "签发", "签发文件", ICONS_PATH"NetworkIssue.bmp"); MENU_APPEND_ITEM(NETWORK_DECRPT, "申请解密", "申请文件解密", ICONS_PATH"NetworkDecrypt.bmp"); MENU_APPEND_ITEM(NETWORK_DECLASS, "申请脱密", "申请文件脱密", ICONS_PATH"NetworkDeclass.bmp"); /* -------------- 外发管理 --------------- */ MENU_APPEND_ITEM(ISSUE_DOC, "外发文档", "外发文档", ICONS_PATH"IssueDoc.bmp"); MENU_APPEND_ITEM(ISSUE_REVIEW, "外发授权", "外发授权", ICONS_PATH"IssueReview.bmp"); g_list_append(items, item); } return items; } static void nemo_sims_menu_provider_iface_init (NemoMenuProviderIface *iface) { // 右键点击桌面的, 目前不需要 // iface->get_background_items = nemo_sims_get_background_items; iface->get_file_items = nemo_sims_get_file_items; } static void nemo_sims_instance_init (NemoSims *cvs) { } static void nemo_sims_class_init (NemoSimsClass *class) { g_assert (object_class == NULL); object_class = g_type_class_peek_parent (class); } static void nemo_sims_class_finalize (NemoSimsClass *class) { g_assert (object_class != NULL); g_object_unref (object_class); object_class = NULL; } GType nemo_sims_get_type (void) { return sims_type; } void nemo_sims_register_type (GTypeModule *module) { static const GTypeInfo info = { sizeof (NemoSimsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) nemo_sims_class_init, (GClassFinalizeFunc) nemo_sims_class_finalize, NULL, sizeof (NemoSims), 0, (GInstanceInitFunc) nemo_sims_instance_init, }; static const GInterfaceInfo menu_provider_iface_info = { (GInterfaceInitFunc) nemo_sims_menu_provider_iface_init, NULL, NULL }; sims_type = g_type_module_register_type (module, G_TYPE_OBJECT, "Sims", &info, 0); g_type_module_add_interface (module, sims_type, NEMO_TYPE_MENU_PROVIDER, &menu_provider_iface_info); }
48575040e9096fdb90d561666152250bcaefbf57
1130043479f7ada57d7b732184e14a2508aa80bd
/CPP/ContactManager3/resource.h
adcc53872869d6a2a32cb4d4f2cc94b0a8222255
[]
no_license
Kwon1995-2/BC_CPP
1435a61aca7dc7a2e41aa2f5ffadd34651cdbd3c
08bf2e2f7e3c8b199617e2fb6243d6418830e262
refs/heads/main
2023-03-21T14:01:53.286699
2021-03-20T13:21:59
2021-03-20T13:21:59
349,702,948
0
0
null
null
null
null
UTF-8
C
false
false
1,406
h
resource.h
//{{NO_DEPENDENCIES}} // Microsoft Visual C++에서 생성한 포함 파일입니다. // ContactManager3.rc에서 사용되고 있습니다. // #define ID_DATAMODIFY 3 #define ID_DATADELETE 4 #define ID_DATALOAD 5 #define ID_DATASAVE 6 #define IDM_ABOUTBOX 0x0010 #define IDD_ABOUTBOX 100 #define IDS_ABOUTBOX 101 #define IDD_CONTACTMANAGER3_DIALOG 102 #define IDR_MAINFRAME 128 #define IDB_BITMAP1 130 #define IDB_BITMAP2 131 #define IDB_BITMAP3 132 #define IDC_LIST1 1000 #define IDC_EDIT1 1001 #define IDC_EDIT2 1002 #define IDC_EDIT3 1003 #define IDC_EDIT4 1004 #define IDC_EDIT5 1005 #define IDC_EDIT6 1006 #define IDC_LIST2 1007 #define ID_DATAINSERT 1008 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 133 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1010 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif
4625492ef00572291345ad72dbebfc663358e9b7
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/vlc/modules/control/extr_rc.c_ReadCommand.c
5301f1ba5a725e9d123b5e7a59fc9f210f32750f
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
2,515
c
extr_rc.c_ReadCommand.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ typedef struct TYPE_8__ TYPE_2__ ; typedef struct TYPE_7__ TYPE_1__ ; /* Type definitions */ struct TYPE_8__ {TYPE_1__* p_sys; } ; typedef TYPE_2__ intf_thread_t ; struct TYPE_7__ {int i_socket; int /*<<< orphan*/ b_quiet; } ; /* Variables and functions */ int /*<<< orphan*/ INTF_IDLE_SLEEP ; int MAX_LINE_LENGTH ; int ReadWin32 (TYPE_2__*,unsigned char*,int*) ; int /*<<< orphan*/ libvlc_Quit (int /*<<< orphan*/ ) ; int /*<<< orphan*/ net_Close (int) ; scalar_t__ net_Read (TYPE_2__*,int,char*,int) ; scalar_t__ read (int /*<<< orphan*/ ,char*,int) ; int /*<<< orphan*/ vlc_object_instance (TYPE_2__*) ; int /*<<< orphan*/ vlc_tick_sleep (int /*<<< orphan*/ ) ; __attribute__((used)) static bool ReadCommand(intf_thread_t *p_intf, char *p_buffer, int *pi_size) { #if defined(_WIN32) && !VLC_WINSTORE_APP if( p_intf->p_sys->i_socket == -1 && !p_intf->p_sys->b_quiet ) return ReadWin32( p_intf, (unsigned char*)p_buffer, pi_size ); else if( p_intf->p_sys->i_socket == -1 ) { vlc_tick_sleep( INTF_IDLE_SLEEP ); return false; } #endif while( *pi_size < MAX_LINE_LENGTH ) { if( p_intf->p_sys->i_socket == -1 ) { if( read( 0/*STDIN_FILENO*/, p_buffer + *pi_size, 1 ) <= 0 ) { /* Standard input closed: exit */ libvlc_Quit( vlc_object_instance(p_intf) ); p_buffer[*pi_size] = 0; return true; } } else { /* Connection closed */ if( net_Read( p_intf, p_intf->p_sys->i_socket, p_buffer + *pi_size, 1 ) <= 0 ) { net_Close( p_intf->p_sys->i_socket ); p_intf->p_sys->i_socket = -1; p_buffer[*pi_size] = 0; return true; } } if( p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' ) break; (*pi_size)++; } if( *pi_size == MAX_LINE_LENGTH || p_buffer[ *pi_size ] == '\r' || p_buffer[ *pi_size ] == '\n' ) { p_buffer[ *pi_size ] = 0; return true; } return false; }
d0e0080037625ca85c45d760737145271874aa4c
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/openssl/test/testutil/extr_format_output.c_test_fail_memory_common.c
2878971ddd1b0a1172895c2ade5174606ba0f5d4
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
3,681
c
extr_format_output.c_test_fail_memory_common.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ /* Variables and functions */ int MAX_STRING_WIDTH ; int /*<<< orphan*/ hex_convert_memory (unsigned char const*,size_t,char*,int) ; scalar_t__ memcmp (unsigned char const*,unsigned char const*,size_t) ; int /*<<< orphan*/ test_diff_header (char const*,char const*) ; int /*<<< orphan*/ test_fail_message_prefix (char const*,char const*,int,char const*,char const*,char const*,char const*) ; int /*<<< orphan*/ test_flush_stderr () ; int /*<<< orphan*/ test_memory_null_empty (unsigned char const*,char) ; int /*<<< orphan*/ test_printf_stderr (char*,...) ; __attribute__((used)) static void test_fail_memory_common(const char *prefix, const char *file, int line, const char *type, const char *left, const char *right, const char *op, const unsigned char *m1, size_t l1, const unsigned char *m2, size_t l2) { const size_t bytes = (MAX_STRING_WIDTH - 9) / 17 * 8; char b1[MAX_STRING_WIDTH + 1], b2[MAX_STRING_WIDTH + 1]; char *p, bdiff[MAX_STRING_WIDTH + 1]; size_t n1, n2, i; unsigned int cnt = 0, diff; test_fail_message_prefix(prefix, file, line, type, left, right, op); if (m1 == NULL) l1 = 0; if (m2 == NULL) l2 = 0; if (l1 == 0 && l2 == 0) { if ((m1 == NULL) == (m2 == NULL)) { test_memory_null_empty(m1, ' '); } else { test_diff_header(left, right); test_memory_null_empty(m1, '-'); test_memory_null_empty(m2, '+'); } goto fin; } if (l1 != l2 || (m1 != m2 && memcmp(m1, m2, l1) != 0)) test_diff_header(left, right); while (l1 > 0 || l2 > 0) { n1 = n2 = 0; if (l1 > 0) { n1 = l1 > bytes ? bytes : l1; hex_convert_memory(m1, n1, b1, 8); } if (l2 > 0) { n2 = l2 > bytes ? bytes : l2; hex_convert_memory(m2, n2, b2, 8); } diff = 0; i = 0; p = bdiff; if (n1 > 0 && n2 > 0) { const size_t j = n1 < n2 ? n1 : n2; for (; i < j; i++) { if (m1[i] == m2[i]) { *p++ = ' '; *p++ = ' '; } else { *p++ = '^'; *p++ = '^'; diff = 1; } if (i % 8 == 7 && i != j - 1) *p++ = ' '; } *p++ = '\0'; } if (n1 == n2 && !diff) { test_printf_stderr("%04x: %s\n", cnt, b1); } else { if (cnt == 0 && (m1 == NULL || l1 == 0)) test_memory_null_empty(m1, '-'); else if (n1 > 0) test_printf_stderr("%04x:-%s\n", cnt, b1); if (cnt == 0 && (m2 == NULL || l2 == 0)) test_memory_null_empty(m2, '+'); else if (n2 > 0) test_printf_stderr("%04x:+%s\n", cnt, b2); if (diff && i > 0) test_printf_stderr("%4s %s\n", "", bdiff); } m1 += n1; m2 += n2; l1 -= n1; l2 -= n2; cnt += bytes; } fin: test_flush_stderr(); }
0110dbe73b8b95031856af62ce6c96fd9680c7db
3d0b66f39b6b869f84ce0094b660707b7859702d
/Temp/il2cppOutput/il2cppOutput/mscorlib_System_Collections_Generic_Dictionary_2_Transform_1_18MethodDeclarations.h
92a55c28446bf093dbfa251440d2edc8669edcbb
[]
no_license
choirdesign/hack-slash
b12b2e86de09b2eec62685d40eec3856df619077
3754f5af407a783bfaf9d9eedbb61148cc50672c
refs/heads/master
2021-01-10T13:40:37.011080
2015-11-24T09:14:57
2015-11-24T09:14:57
45,164,312
0
0
null
null
null
null
UTF-8
C
false
false
3,052
h
mscorlib_System_Collections_Generic_Dictionary_2_Transform_1_18MethodDeclarations.h
#pragma once #include "il2cpp-config.h" #ifndef _MSC_VER # include <alloca.h> #else # include <malloc.h> #endif #include <stdint.h> #include <assert.h> #include <exception> // System.Collections.Generic.Dictionary`2/Transform`1<System.Object,UnityEngine.TextEditor/TextEditOp,System.Collections.DictionaryEntry> struct Transform_1_t2238; // System.Object struct Object_t; // System.IAsyncResult struct IAsyncResult_t225; // System.AsyncCallback struct AsyncCallback_t226; #include "codegen/il2cpp-codegen.h" #include "mscorlib_System_IntPtr.h" #include "mscorlib_System_Collections_DictionaryEntry.h" #include "UnityEngine_UnityEngine_TextEditor_TextEditOp.h" // System.Void System.Collections.Generic.Dictionary`2/Transform`1<System.Object,UnityEngine.TextEditor/TextEditOp,System.Collections.DictionaryEntry>::.ctor(System.Object,System.IntPtr) extern "C" void Transform_1__ctor_m16645_gshared (Transform_1_t2238 * __this, Object_t * ___object, IntPtr_t ___method, const MethodInfo* method); #define Transform_1__ctor_m16645(__this, ___object, ___method, method) (( void (*) (Transform_1_t2238 *, Object_t *, IntPtr_t, const MethodInfo*))Transform_1__ctor_m16645_gshared)(__this, ___object, ___method, method) // TRet System.Collections.Generic.Dictionary`2/Transform`1<System.Object,UnityEngine.TextEditor/TextEditOp,System.Collections.DictionaryEntry>::Invoke(TKey,TValue) extern "C" DictionaryEntry_t1053 Transform_1_Invoke_m16646_gshared (Transform_1_t2238 * __this, Object_t * ___key, int32_t ___value, const MethodInfo* method); #define Transform_1_Invoke_m16646(__this, ___key, ___value, method) (( DictionaryEntry_t1053 (*) (Transform_1_t2238 *, Object_t *, int32_t, const MethodInfo*))Transform_1_Invoke_m16646_gshared)(__this, ___key, ___value, method) // System.IAsyncResult System.Collections.Generic.Dictionary`2/Transform`1<System.Object,UnityEngine.TextEditor/TextEditOp,System.Collections.DictionaryEntry>::BeginInvoke(TKey,TValue,System.AsyncCallback,System.Object) extern "C" Object_t * Transform_1_BeginInvoke_m16647_gshared (Transform_1_t2238 * __this, Object_t * ___key, int32_t ___value, AsyncCallback_t226 * ___callback, Object_t * ___object, const MethodInfo* method); #define Transform_1_BeginInvoke_m16647(__this, ___key, ___value, ___callback, ___object, method) (( Object_t * (*) (Transform_1_t2238 *, Object_t *, int32_t, AsyncCallback_t226 *, Object_t *, const MethodInfo*))Transform_1_BeginInvoke_m16647_gshared)(__this, ___key, ___value, ___callback, ___object, method) // TRet System.Collections.Generic.Dictionary`2/Transform`1<System.Object,UnityEngine.TextEditor/TextEditOp,System.Collections.DictionaryEntry>::EndInvoke(System.IAsyncResult) extern "C" DictionaryEntry_t1053 Transform_1_EndInvoke_m16648_gshared (Transform_1_t2238 * __this, Object_t * ___result, const MethodInfo* method); #define Transform_1_EndInvoke_m16648(__this, ___result, method) (( DictionaryEntry_t1053 (*) (Transform_1_t2238 *, Object_t *, const MethodInfo*))Transform_1_EndInvoke_m16648_gshared)(__this, ___result, method)
2995de9226ef6c9325d8ee6f5b10516642b926c5
dc2f24165f0c5af3fa5f62537279104ef9e4ab13
/src/bcma/cint/core/cint_eval_asts.c
ff24e78a65f6dc050168332f8a904cfa53589d0c
[ "Apache-2.0" ]
permissive
opennetworkinglab/SDKLT
7376cf1708b17f6976ce9e0be9669ec3b579dd96
cf7dd8f2f04025ee40e13355cfed4ce9b9614593
refs/heads/master
2023-07-31T15:43:55.138638
2022-07-13T19:36:54
2022-07-13T19:36:54
186,948,886
10
4
null
2022-07-13T19:36:55
2019-05-16T04:06:06
C
UTF-8
C
false
false
45,873
c
cint_eval_asts.c
/* * $Id: cint_eval_asts.c,v 1.58 2012/12/18 17:44:20 noahm Exp $ * Copyright: (c) 2018 Broadcom. All Rights Reserved. "Broadcom" refers to * Broadcom Limited and/or its subsidiaries. * * Broadcom Switch Software License * * This license governs the use of the accompanying Broadcom software. Your * use of the software indicates your acceptance of the terms and conditions * of this license. If you do not agree to the terms and conditions of this * license, do not use the software. * 1. Definitions * "Licensor" means any person or entity that distributes its Work. * "Software" means the original work of authorship made available under * this license. * "Work" means the Software and any additions to or derivative works of * the Software that are made available under this license. * The terms "reproduce," "reproduction," "derivative works," and * "distribution" have the meaning as provided under U.S. copyright law. * Works, including the Software, are "made available" under this license * by including in or with the Work either (a) a copyright notice * referencing the applicability of this license to the Work, or (b) a copy * of this license. * 2. Grant of Copyright License * Subject to the terms and conditions of this license, each Licensor * grants to you a perpetual, worldwide, non-exclusive, and royalty-free * copyright license to reproduce, prepare derivative works of, publicly * display, publicly perform, sublicense and distribute its Work and any * resulting derivative works in any form. * 3. Grant of Patent License * Subject to the terms and conditions of this license, each Licensor * grants to you a perpetual, worldwide, non-exclusive, and royalty-free * patent license to make, have made, use, offer to sell, sell, import, and * otherwise transfer its Work, in whole or in part. This patent license * applies only to the patent claims licensable by Licensor that would be * infringed by Licensor's Work (or portion thereof) individually and * excluding any combinations with any other materials or technology. * If you institute patent litigation against any Licensor (including a * cross-claim or counterclaim in a lawsuit) to enforce any patents that * you allege are infringed by any Work, then your patent license from such * Licensor to the Work shall terminate as of the date such litigation is * filed. * 4. Redistribution * You may reproduce or distribute the Work only if (a) you do so under * this License, (b) you include a complete copy of this License with your * distribution, and (c) you retain without modification any copyright, * patent, trademark, or attribution notices that are present in the Work. * 5. Derivative Works * You may specify that additional or different terms apply to the use, * reproduction, and distribution of your derivative works of the Work * ("Your Terms") only if (a) Your Terms provide that the limitations of * Section 7 apply to your derivative works, and (b) you identify the * specific derivative works that are subject to Your Terms. * Notwithstanding Your Terms, this license (including the redistribution * requirements in Section 4) will continue to apply to the Work itself. * 6. Trademarks * This license does not grant any rights to use any Licensor's or its * affiliates' names, logos, or trademarks, except as necessary to * reproduce the notices described in this license. * 7. Limitations * Platform. The Work and any derivative works thereof may only be used, or * intended for use, with a Broadcom switch integrated circuit. * No Reverse Engineering. You will not use the Work to disassemble, * reverse engineer, decompile, or attempt to ascertain the underlying * technology of a Broadcom switch integrated circuit. * 8. Termination * If you violate any term of this license, then your rights under this * license (including the license grants of Sections 2 and 3) will * terminate immediately. * 9. Disclaimer of Warranty * THE WORK IS PROVIDED "AS IS" WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OR CONDITIONS OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE OR * NON-INFRINGEMENT. YOU BEAR THE RISK OF UNDERTAKING ANY ACTIVITIES UNDER * THIS LICENSE. SOME STATES' CONSUMER LAWS DO NOT ALLOW EXCLUSION OF AN * IMPLIED WARRANTY, SO THIS DISCLAIMER MAY NOT APPLY TO YOU. * 10. Limitation of Liability * EXCEPT AS PROHIBITED BY APPLICABLE LAW, IN NO EVENT AND UNDER NO LEGAL * THEORY, WHETHER IN TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE * SHALL ANY LICENSOR BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY DIRECT, * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF * OR RELATED TO THIS LICENSE, THE USE OR INABILITY TO USE THE WORK * (INCLUDING BUT NOT LIMITED TO LOSS OF GOODWILL, BUSINESS INTERRUPTION, * LOST PROFITS OR DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY OTHER * COMMERCIAL DAMAGES OR LOSSES), EVEN IF THE LICENSOR HAS BEEN ADVISED OF * THE POSSIBILITY OF SUCH DAMAGES. * * * * File: cint_eval_asts.c * Purpose: CINT AST evaluators */ #include "cint_eval_asts.h" #include "cint_porting.h" #include "cint_variables.h" #include "cint_internal.h" #include "cint_error.h" #include "cint_debug.h" #include "cint_eval_ast_cint.h" #include "cint_eval_ast_print.h" #include <stdarg.h> static int __breakable = 0; static int __returnable = 0; #define CINT_BREAK() CINT_ERRNO_IS(BREAK) #define CINT_CONTINUE() CINT_ERRNO_IS(CONTINUE) #define CINT_RETURN() CINT_ERRNO_IS(RETURN) #define CINT_EXIT() CINT_ERRNO_IS(EXIT) typedef cint_variable_t* (*cint_vararg_f)(cint_ast_t* ast); static cint_variable_t* __cint_eval_ast_Empty(cint_ast_t* ast) { return NULL; } static cint_variable_t* __cint_eval_ast_Integer(cint_ast_t* ast) { return cint_auto_integer(ast->utype.integer.i); } #if CINT_CONFIG_INCLUDE_LONGLONGS == 1 static cint_variable_t* __cint_eval_ast_LongLong(cint_ast_t* ast) { return cint_auto_longlong(ast->utype._longlong.i); } #endif static cint_variable_t* __cint_eval_ast_String(cint_ast_t* ast) { cint_variable_t* rv; rv = cint_auto_string(ast->utype.string.s); return rv; } #if CINT_CONFIG_INCLUDE_DOUBLES == 1 static cint_variable_t* __cint_eval_ast_Double(cint_ast_t* ast) { return cint_auto_double(ast->utype._double.d); } #endif static cint_variable_t* __cint_eval_ast_Type(cint_ast_t* ast) { return NULL; } static cint_variable_t* __cint_eval_ast_Initializer(cint_ast_t* ast) { return NULL; } static cint_variable_t* __cint_eval_ast_EnumDef(cint_ast_t* ast) { cint_enum_type_t* cet; cint_enum_map_t* map; cint_ast_t* e; int ecount; int evalue = 0; int map_size; /* * Allocate a new cint_enum_type_t structure */ cet = CINT_MALLOC(sizeof(*cet)); if(cet == NULL) { cint_ast_error(ast, CINT_E_MEMORY, "memory allocation failure"); return NULL; } CINT_MEMSET(cet, 0, sizeof(*cet)); cet->name = CINT_STRDUP(ast->utype.enumdef.identifier->utype.identifier.s); ecount = cint_ast_count(ast->utype.enumdef.enumerators); /* Allocate the map array based on the enum count */ map_size = sizeof(*map)*(ecount+1); map = CINT_MALLOC(map_size); if(map == NULL) { cint_ast_error(ast, CINT_E_MEMORY, "memory allocation failure"); cint_datatype_clear_enumeration(cet); return NULL; } CINT_MEMSET(map, 0, map_size); /* Initialize map array base on the enumerators */ cet->enum_map = map; for(e = ast->utype.enumdef.enumerators; e; e = e->next, map++) { map->name = CINT_STRDUP(e->utype.enumerator.identifier->utype.identifier.s); if(e->utype.enumerator.value) { cint_variable_t* rv; rv = cint_eval_ast(e->utype.enumerator.value); if (rv) { map->value = cint_integer_value(rv); evalue = map->value; } else { cint_ast_error(ast, CINT_E_BAD_AST, "illegal enum value"); cint_datatype_clear_enumeration(cet); return NULL; } } else { map->value = evalue; } evalue++; } map->name = NULL; cint_datatype_add_enumeration(cet); return NULL; } static cint_variable_t* __cint_eval_ast_Enumerator(cint_ast_t* ast) { return NULL; } static cint_variable_t* __cint_eval_ast_Identifier(cint_ast_t* ast) { cint_variable_t* rv = NULL; int c; cint_datatype_t dt; const char* id = ast->utype.identifier.s; /* Special Command Identifiers */ if(!CINT_STRCMP(id, "quit") || !CINT_STRCMP(id, "exit")) { cint_errno = CINT_E_EXIT; return NULL; } /* Variables */ if((rv = cint_variable_find(id, 0))) { return rv; } /* Enumerations */ if(cint_datatype_enum_find(id, &dt, &c) == CINT_E_NONE) { if(cint_variable_create(&rv, NULL, &dt.desc, CINT_VARIABLE_F_AUTO | CINT_VARIABLE_F_CONST, NULL) != CINT_E_NONE) { cint_internal_error(__FILE__, __LINE__, "could not create enum autovar of type '%s'", dt.desc.basetype); return NULL; } else { *((int*)rv->data) = c; } return rv; } /* Enumerations and constants */ if(cint_constant_find(id, &c) == CINT_E_NONE) { return cint_auto_integer(c); } /* Functions */ if(cint_datatype_find(id, &dt) == CINT_E_NONE) { if(dt.flags & (CINT_DATATYPE_F_FUNC | CINT_DATATYPE_F_FUNC_DYNAMIC)) { cint_parameter_desc_t pdt = { NULL, 0, 0 }; pdt.basetype = id; cint_variable_create(&rv, NULL, &pdt, CINT_VARIABLE_F_AUTO | CINT_VARIABLE_F_CONST, NULL); return rv; } } if(rv == NULL) { cint_ast_error(ast, CINT_E_BAD_VARIABLE, "identifier '%s' undeclared", ast->utype.identifier.s); } return rv; } static int _cint_eval_ast_declaration_parameter(cint_ast_t* ast, char *basetype, int basetype_len, unsigned* basetype_flags, int *pcount_p, int *array_dimension_count, int *array_dimensions) { int rc; cint_variable_t* rv; int pcount; int dim_index; int dimensions[CINT_CONFIG_ARRAY_DIMENSION_LIMIT]; if (ast->ntype != cintAstDeclaration) { return cint_ast_error(ast, CINT_E_BAD_AST, "expected declaration"); } pcount = ast->utype.declaration.pcount; rc = cint_eval_type_list(ast->utype.declaration.type, basetype, basetype_len, basetype_flags, 1); if (rc != CINT_E_NONE) { return rc; } if(ast->utype.declaration.num_dimension_initializers) { for(dim_index = 0; dim_index < ast->utype.declaration.num_dimension_initializers; dim_index++) { rv = cint_eval_ast( ast->utype.declaration.dimension_initializers[dim_index]); if(rv == NULL || (cint_is_integer(rv) == 0)) { return cint_ast_error(ast, CINT_E_BAD_AST, "illegal array definition"); } dimensions[dim_index] = cint_integer_value(rv); if(dim_index > 0 && dimensions[dim_index] <= 0) { return cint_ast_error(ast, CINT_E_BAD_AST, "illegal array definition"); } } if(dimensions[0] <= 0) { if(dimensions[0] == -1 && ast->utype.declaration.num_dimension_initializers == 1 && ast->utype.declaration.init && ast->utype.declaration.init->ntype == cintAstInitializer) { /* * Determine the proper size for this initialized array. * based on the length of the initializer chain */ dimensions[0] = cint_ast_count(ast->utype.declaration.init-> utype.initializer.initializers); } else { return cint_ast_error(ast, CINT_E_BAD_AST, "illegal array definition"); } } } if (rc == CINT_E_NONE) { *pcount_p = pcount; *array_dimension_count = ast->utype.declaration.num_dimension_initializers; for(dim_index = 0; dim_index < ast->utype.declaration.num_dimension_initializers; dim_index++) { array_dimensions[dim_index] = dimensions[dim_index]; } } return rc; } static cint_variable_t* __cint_eval_ast_Declaration(cint_ast_t* ast) { int rc; cint_variable_t* rv; cint_parameter_desc_t desc; unsigned basetype_flags; char basetype[64]; rc = _cint_eval_ast_declaration_parameter(ast, basetype, sizeof(basetype), &basetype_flags, &desc.pcount, &desc.num_dimensions, desc.dimensions); if (rc != CINT_E_NONE) { return NULL; } desc.name = ast->utype.declaration.identifier->utype.string.s; desc.basetype = basetype; if (CINT_STRLEN(desc.basetype) == 0) { cint_ast_error(ast, CINT_E_BAD_VARIABLE, "identifier '%s' has unknown type", desc.name); return NULL; } if((rv=cint_variable_find(desc.name, 1)) != NULL) { /* Variable already exists in current scope */ cint_ast_error(ast, CINT_E_BAD_VARIABLE, "identifier '%s' redeclared", desc.name); return NULL; } rc = cint_variable_create(&rv, desc.name, &desc, 0, NULL); if(rc < 0) { if(rc == CINT_E_BAD_TYPE) { cint_ast_error(ast, rc, "cannot declare variable of type '%s'", desc.basetype); } else { cint_ast_error(ast, rc, "variable create error: %s\n", cint_error_name(rc)); } return NULL; } else { if(ast->utype.declaration.init) { /* New variable has an initialization expression */ cint_ast_t *id; cint_ast_t *assign; /* * Identifier AST */ id = cint_ast_identifier(rv->name); /* * Assignment AST */ assign = cint_ast_operator(cintOpAssign, id, ast->utype.declaration.init); cint_eval_ast(assign); /* sdk-67627: free the two ast allocated in this scope */ cint_ast_free_single(assign); cint_ast_free_single(id); } if(basetype_flags & CINT_AST_TYPE_F_CONST || (desc.num_dimensions != 0 && desc.pcount == 0)) { rv->flags |= CINT_VARIABLE_F_CONST; } if(basetype_flags & CINT_AST_TYPE_F_VOLATILE) { rv->flags |= CINT_VARIABLE_F_VOLATILE; } } return rv; } static cint_variable_t* __cint_eval_ast_Operator(cint_ast_t* ast) { return cint_eval_operator(ast); } static int __cint_eval_ast_dimensions_equal(int length0, int length1, int *dimensions0, int *dimensions1) { int i; if(length0 != length1) { return 0; } for(i = 0; i < length0; i++) { if(dimensions0[i] != dimensions1[i]) { return 0; } } return 1; } static cint_variable_t* __cint_eval_ast_Function(cint_ast_t* ast) { cint_error_t rc; cint_datatype_t* dtp = NULL; cint_variable_t* rv = NULL; cint_fparams_t fparams; cint_parameter_desc_t* pd; cint_ast_t* p; int count; int fcount; cint_function_t* fp; /* * Find the function */ if((dtp = ast->utype.function.dtp) == NULL) { dtp = CINT_MALLOC(sizeof(*dtp)); if(dtp == NULL) { cint_ast_error(ast, CINT_E_MEMORY, "memory allocation failure"); return NULL; } CINT_MEMSET(dtp, 0, sizeof(*dtp)); if( ((rc = cint_datatype_find(ast->utype.function.name, dtp)) < 0) || ((dtp->flags & CINT_DATATYPE_FLAGS_FUNC) == 0) ) { cint_ast_error(ast, CINT_E_NOT_FOUND, "identifier '%s' is not a function", ast->utype.function.name); CINT_FREE(dtp); return NULL; } ast->utype.function.dtp = dtp; } fp = dtp->basetype.fp; if(dtp->flags & CINT_DATATYPE_F_FUNC_VARARG) { cint_vararg_f func = (cint_vararg_f)fp->addr; return func(ast); } /* * Return value? */ if(!cint_parameter_void(fp->params)) { /* Allocate variable to hold return type */ cint_variable_create(&rv, NULL, fp->params, 0, 0); if(rv) { fparams.rv = rv->data; } else { fparams.rv = NULL; } } /* * Check parameter count */ count = cint_ast_count(ast->utype.function.parameters); fcount = fp->params ? cint_parameter_count(fp->params) - 1 /* Return value doesn't count */ : 0; if(fcount == 1 && cint_parameter_void(fp->params+1)) { fcount = 0; } if(count != fcount) { cint_ast_error(ast, CINT_E_PARAM, "wrong number of parameters to function '%s' (expected %d but received %d)", fp->name, fcount, count); return NULL; } /* * Parameters */ for(count = 0, p = ast->utype.function.parameters, pd = fp->params+1; p; count ++, p = p->next, pd++) { /* Given parameter value */ cint_variable_t* v = cint_eval_ast(p); cint_datatype_t pdt; if(v == NULL) { cint_ast_error(ast, CINT_E_PARAM, "error evaluating argument %d to function '%s'", count+1, fp->name); return NULL; } CINT_MEMSET(&pdt, 0, sizeof(pdt)); /* Parameter type */ if(cint_datatype_find(pd->basetype, &pdt) != CINT_E_NONE) { return NULL; } if(cint_array_combine_dimensions(&pdt.desc, pd) != CINT_E_NONE) { return NULL; } pdt.desc.pcount += pd->pcount; if(cint_type_check(&v->dt, &pdt) == 0) { int rc1; cint_variable_t* nv; /* * Not the same type. Special pointer conversions, where * an extra level of indirection is added. */ /* * There may be other type conversions (string to * bcm_mac_t, string to bcm_ip_t) that should be * allowable. */ if((!CINT_STRCMP(v->dt.desc.basetype, pdt.desc.basetype) || cint_type_compatible(&v->dt, &pdt) ) && v->dt.desc.pcount == (pdt.desc.pcount-1) && v->dt.desc.num_dimensions == (pdt.desc.num_dimensions -1) && __cint_eval_ast_dimensions_equal( pdt.desc.num_dimensions - 1, v->dt.desc.num_dimensions == 0 ? v->cached_num_dimensions : v->dt.desc.num_dimensions, pdt.desc.dimensions + 1, v->dt.desc.dimensions)) { /* * The function expects a pointer to the given argument type. * Enable conversion. */ v = cint_variable_address(v); v->flags &= ~CINT_VARIABLE_F_CONST; } else { /* * Can we convert the argument through assignment? */ if((rc1 = cint_variable_create(&nv, NULL, pd, CINT_VARIABLE_F_AUTO, NULL)) != CINT_E_NONE) { cint_ast_error(ast, rc1, "error creating temporary variables"); return NULL; } if(cint_eval_operator_internal(ast, cintOpAssign, nv, v) == nv) { /* Conversion successful */ v = nv; } else { char* f1 = cint_datatype_format(&v->dt, 1); cint_ast_error(ast, CINT_E_PARAM, "arg %d to function '%s' was wrong type: expected %s, received %s", count+1, fp->name, cint_datatype_format(&pdt, 0), f1); CINT_FREE(f1); return NULL; } } } /* Parameter is good to go */ if(dtp->flags & CINT_DATATYPE_F_FUNC) { /* Static function call */ fparams.args[count] = v->data; } else { /* Stored for later -- see dynamic function call below */ fparams.args[count] = v; } } /* * Call function */ if(dtp->flags & CINT_DATATYPE_F_FUNC) { cint_ftrace(fp->name, 1); rc = fp->body.wrapper(&fparams); cint_ftrace(fp->name, 0); } else { /* * Clone all function parameters into a new scope using the expected parameter names */ int i; cint_variable_scope_push(fp->name); for(i = 0, pd = fp->params+1; i < count; i++, pd++) { cint_variable_t* pv = cint_variable_clone((cint_variable_t*)fparams.args[i]); cint_variable_rename(pv, pd->name); cint_variable_auto_save(pv); } /* * Evaluate function body */ cint_ftrace(fp->name, 1); __returnable++; rv = cint_eval_asts(fp->body.statements); if(rv) rv = cint_variable_clone(rv); if(cint_errno == CINT_E_RETURN) { cint_errno = CINT_E_NONE; } __returnable--; cint_ftrace(fp->name, 0); /* Do not destroy return value when scope is popped */ if(rv) rv->flags |= CINT_VARIABLE_F_NODESTROY; /* Pop function scope */ cint_variable_scope_pop(fp->name); /* Add return value back into the local scope list */ if(rv) { rv->flags &= ~CINT_VARIABLE_F_NODESTROY; rv->flags &= ~CINT_VARIABLE_F_AUTO; cint_variable_add(rv); } } return rv; } static cint_variable_t* __cint_eval_ast_Elist(cint_ast_t* ast) { cint_ast_t* p; cint_variable_t* rv = NULL; for(p = ast->utype.elist.list; p; p = p->next) { rv = cint_eval_ast(p); } return rv; } static cint_variable_t* __cint_eval_ast_While(cint_ast_t* ast) { cint_variable_t* rv; __breakable++; if(ast->utype._while.order) { rv = cint_eval_asts(ast->utype._while.statements); if(CINT_BREAK()) { cint_errno = CINT_E_NONE; return rv; } else if(CINT_CONTINUE()) { cint_errno = CINT_E_NONE; } else if(CINT_RETURN()) { cint_errno = CINT_E_RETURN; return rv; } } while(cint_logical_value(cint_eval_ast(ast->utype._while.condition))) { rv = cint_eval_asts(ast->utype._while.statements); if(CINT_BREAK()) { cint_errno = CINT_E_NONE; break; } else if(CINT_CONTINUE()) { cint_errno = CINT_E_NONE; continue; } else if(CINT_RETURN()) { cint_errno = CINT_E_RETURN; return rv; } else if (cint_errno != CINT_E_NONE) { break; } } __breakable--; return NULL; } static int _for_cond(cint_ast_t* ast) { int cond = 1; if (ast && ast->ntype != cintAstEmpty) { cond = cint_logical_value(cint_eval_ast(ast)); } return cond; } static cint_variable_t* __cint_eval_ast_For(cint_ast_t* ast) { cint_variable_t* rv = NULL; __breakable++; for(cint_eval_ast(ast->utype._for.pre); _for_cond(ast->utype._for.condition); cint_eval_ast(ast->utype._for.post)) { rv = cint_eval_asts(ast->utype._for.statements); if(CINT_BREAK()) { cint_errno = CINT_E_NONE; break; } if(CINT_CONTINUE()) { cint_errno = CINT_E_NONE; continue; } if(CINT_RETURN()) { break; } if(CINT_EXIT()) { break; } } __breakable--; return rv; } static cint_variable_t* __cint_eval_ast_If(cint_ast_t* ast) { cint_variable_t* rv = NULL; if(cint_logical_value(cint_eval_ast(ast->utype._if.condition))) { rv = cint_eval_asts(ast->utype._if.statements); } else if(ast->utype._if._else) { rv = cint_eval_asts(ast->utype._if._else); } return rv; } static cint_variable_t* __cint_eval_ast_Return(cint_ast_t* ast) { cint_variable_t* rv = NULL; if(!__returnable) { cint_ast_error(ast, CINT_E_BAD_AST, "return statement not within function"); return NULL; } if(ast->utype._return.expression) { rv = cint_eval_ast(ast->utype._return.expression); } cint_errno = CINT_E_RETURN; return rv; } static cint_variable_t* __cint_eval_ast_Continue(cint_ast_t* ast) { if(!__breakable) { cint_ast_error(ast, CINT_E_BAD_AST, "continue statement not within loop"); } else { cint_errno = CINT_E_CONTINUE; } return NULL; } static cint_variable_t* __cint_eval_ast_Break(cint_ast_t* ast) { if(!__breakable) { cint_ast_error(ast, CINT_E_BAD_AST, "break statement not within loop"); } else { cint_errno = CINT_E_BREAK; } return NULL; } static cint_variable_t* __cint_eval_ast_Switch(cint_ast_t* ast) { cint_ast_t* s; cint_ast_t* _default = NULL; cint_ast_t* eq = NULL; cint_variable_t* rv = NULL; /* * If this is a compound statement the brace operators might not get paired properly. * The first open brace will never get executed, since it is not part of a case label. * The final open brace may get executed as we fall through the labels (including the default). * * The trailing closing brace is disabled for this reason. */ s = cint_ast_last(ast->utype._switch.statements); if(cint_operator_type(s) == cintOpCloseBrace) { s->noexec = 1; } /* Find and validate default case */ for(s = ast->utype._switch.statements; s; s = s->next) { if( (s->ntype == cintAstCase) && s->utype._case.expression == NULL) { if(_default) { cint_ast_error(ast, CINT_E_BAD_AST, "more than one default label in switch statement"); return NULL; } else { _default = s; } } } eq = cint_ast_operator(cintOpEqual, ast->utype._switch.expression, NULL); for(s = ast->utype._switch.statements; s; s = s->next) { if( (s->ntype == cintAstCase) && (s->utype._case.expression) ) { cint_variable_t* v; /* Check the switch expression against the case expression */ eq->utype.operator.right = s->utype._case.expression; v = cint_eval_ast(eq); if(v == NULL) { rv = NULL; break; } if(cint_logical_value(v) == 1) { /* Begin executing all statements starting here */ __breakable++; rv = cint_eval_asts(s); __breakable--; if(CINT_BREAK()) { cint_errno = CINT_E_NONE; } if(CINT_RETURN()) { cint_errno = CINT_E_RETURN; } else { rv = NULL; } break; } } } /* Free up the AST as the switch evaluation is complete. */ cint_ast_free_single(eq); if (s) { return rv; } if(_default) { /* Execute default case */ __breakable++; rv = cint_eval_asts(_default); __breakable--; if(CINT_BREAK()) { cint_errno = CINT_E_NONE; } if(CINT_RETURN()) { cint_errno = CINT_E_RETURN; return rv; } } return NULL; } static cint_variable_t* __cint_eval_ast_Case(cint_ast_t* ast) { /* Evaluate all statements in case label */ return cint_eval_asts(ast->utype._case.statements); } static cint_variable_t* __cint_eval_ast_Print(cint_ast_t* ast) { /* cint_eval_ast_print.c */ return cint_eval_ast_Print(ast); } static cint_variable_t* __cint_eval_ast_Cint(cint_ast_t* ast) { /* cint_eval_ast_debug.c */ return cint_eval_ast_Cint(ast); } static cint_variable_t* __cint_eval_ast_StructureDef(cint_ast_t* ast) { cint_struct_type_t* cst = CINT_MALLOC(sizeof(*cst)); cint_ast_t* m; cint_parameter_desc_t* p0; cint_parameter_desc_t* p; cint_datatype_t dt; int mcount; int ssize = 0; char basetype[64]; int rv; int sm_size; int dim_index; if(cst == NULL) { cint_ast_error(ast, CINT_E_MEMORY, "memory allocation failure"); return NULL; } CINT_MEMSET((void *)cst, 0, sizeof(*cst)); CINT_MEMSET(&dt, 0, sizeof(dt)); if (ast->utype.structuredef.name) { cst->name = CINT_STRDUP(ast->utype.structuredef.name->utype.identifier.s); if (cst->name == NULL) { cint_ast_error(ast, CINT_E_MEMORY, "memory allocation failure"); cint_datatype_clear_structure(cst); return NULL; } } else { cint_ast_error(ast, CINT_E_BAD_AST, "structure name not found"); cint_datatype_clear_structure(cst); return NULL; } m = ast->utype.structuredef.members; mcount = cint_ast_count(m); sm_size = sizeof(*p)*(mcount+1); cst->struct_members = CINT_MALLOC(sm_size); if (cst->struct_members == NULL) { cint_datatype_clear_structure(cst); cint_ast_error(ast, CINT_E_MEMORY, "memory allocation failure"); return NULL; } CINT_MEMSET((void *)cst->struct_members, 0, sm_size); p = (cint_parameter_desc_t *) cst->struct_members; p0 = NULL; for(; m; m = m->next, p++) { if (m->ntype != cintAstDeclaration) { cint_ast_error(ast, CINT_E_BAD_AST, "invalid structure definition"); cint_datatype_clear_structure(cst); return NULL; } /* point of this exercise is to set p->{basetype,name,pcount} and to determine member size. */ p->name = CINT_STRDUP(m->utype.declaration.identifier->utype.string.s); rv = _cint_eval_ast_declaration_parameter(m, basetype, sizeof(basetype), NULL, &p->pcount, &p->num_dimensions, p->dimensions); if (rv != CINT_E_NONE) { cint_datatype_clear_structure(cst); return NULL; } if (CINT_STRLEN(basetype) > 0) { /* count and array are already set, so now save the basetype */ p->basetype = CINT_STRDUP(basetype); /* Save this structure member in case future structure members do not have a base type. Every structure member has a right to a base type. If it does not have a base type, this function will appoint one. */ p0 = p; } else { /* This structure member doesn't have a basetype, so use the basetype from the most recent structure member that *did* have one. At least one structure member needs to have a basetype. */ if (p0 == NULL) { /* It appears that no structure member had a basetype */ cint_ast_error(ast, CINT_E_BAD_AST, "no default member type definition found"); cint_datatype_clear_structure(cst); return NULL; } p->basetype = CINT_STRDUP(p0->basetype); p->pcount = p0->pcount; p->num_dimensions = p0->num_dimensions; for(dim_index = 0; dim_index < p0->num_dimensions; dim_index++) { p->dimensions[dim_index] = p0->dimensions[dim_index]; } } if(cint_datatype_find(p->basetype, &dt) != CINT_E_NONE) { cint_ast_error(ast, CINT_E_BAD_AST, "unknown type '%s' in structure definition", p->basetype); cint_datatype_clear_structure(cst); return NULL; } for(dim_index = 0; dim_index < p->num_dimensions; dim_index++) { dt.desc.dimensions[dim_index + dt.desc.num_dimensions] = p->dimensions[dim_index]; } dt.desc.num_dimensions += p->num_dimensions; dt.desc.pcount += p->pcount; ssize += cint_datatype_size(&dt); /* All members start on a word aligned address */ while(ssize % 4) ssize++; } cst->size = ssize; cst->maddr = cint_maddr_dynamic_struct_t; cint_datatype_add_structure(cst); return NULL; } /* function parameter and return types can be a composite type, like unsigned int, but only one of those AST nodes that comprise the composite is the 'Type' AST node. */ static cint_ast_t * __cint_ast_basetype(cint_ast_t* ast) { int rc = CINT_E_NONE; char basetype[64]; if(ast) { rc = cint_eval_type_list(ast, basetype, sizeof(basetype), NULL, 0); if (rc != CINT_E_NONE) { return NULL; } if(CINT_AST(ast,Type) && ast->utype.type.s){ CINT_FREE((char*) ast->utype.type.s); } ast->ntype = cintAstType; ast->utype.type.s = CINT_STRDUP(basetype); } return ast; } static cint_variable_t* __cint_eval_ast_FunctionDef(cint_ast_t* ast) { cint_function_t* f; cint_ast_t* decl = ast->utype.functiondef.declaration; cint_ast_t* params = ast->utype.functiondef.parameters; cint_ast_t* ret; cint_ast_t* name; cint_parameter_desc_t* p; int count; int desc_size; cint_datatype_t dt; if (decl == NULL) { cint_ast_error(ast, CINT_E_BAD_AST, "cannot determine declaration"); return NULL; } if (decl->ntype == cintAstType || decl->ntype == cintAstInteger #if CINT_CONFIG_INCLUDE_LONGLONGS == 1 || decl->ntype == cintAstLongLong #endif #if CINT_CONFIG_INCLUDE_FLOATS == 1 || decl->ntype == cintAstFloat #endif ) { /* This is a declaration, not a definition, so there's really nothing to do, yet. */ return NULL; } else if (decl->ntype != cintAstDeclaration) { cint_internal_error(__FILE__, __LINE__, "Node type %d unexpected", decl->ntype); return NULL; } /* Function name */ name = decl->utype.declaration.identifier; if (!CINT_AST(name, Identifier)) { cint_internal_error(__FILE__, __LINE__, "Node type %d unexpected", name->ntype); return NULL; } f = CINT_MALLOC(sizeof(*f)); if (f == NULL) { cint_ast_error(ast, CINT_E_MEMORY, "memory allocation failure"); return NULL; } CINT_MEMSET(f, 0, sizeof(*f)); f->name = CINT_STRDUP(name->utype.identifier.s); /* Return Type */ ret = __cint_ast_basetype(decl->utype.declaration.type); if (ret == NULL) { cint_internal_error(__FILE__, __LINE__, "unknown return type"); cint_datatype_clear_function(f); return NULL; } if (ret->utype.type.s == NULL) { cint_internal_error(__FILE__, __LINE__, "unknown return basetype"); cint_datatype_clear_function(f); return NULL; } /* Number of parameters */ count = cint_ast_count(params); /* Allocate parameter description array to hold parameters and return value */ desc_size = sizeof(*p)*(count+2); p = CINT_MALLOC(desc_size); if (p == NULL) { cint_ast_error(ast, CINT_E_MEMORY, "memory allocation failure"); cint_datatype_clear_function(f); return NULL; } CINT_MEMSET(p, 0, desc_size); f->params = p; p->basetype = CINT_STRDUP(ret->utype.type.s); p->name = CINT_STRDUP("r"); p->pcount = decl->utype.declaration.pcount; p->num_dimensions = 0; for(count = 1, params = ast->utype.functiondef.parameters; params; params = params->next, count++) { if (CINT_AST(params, Declaration)) { cint_ast_t *ty; cint_ast_t *ident = params->utype.declaration.identifier; ty = __cint_ast_basetype(params->utype.declaration.type); if (ty == NULL) { cint_ast_error(ast, CINT_E_BAD_AST, "param type not found"); cint_datatype_clear_function(f); return NULL; } if (ident && !CINT_AST(ident, Identifier)) { cint_ast_error(ast, CINT_E_BAD_AST, "unexpected param ident AST %d", ident->ntype); cint_datatype_clear_function(f); return NULL; } /* A NULL basetype is used as a sentinel for the parameter array, so it is not allowed to be NULL here */ if (ty->utype.type.s == NULL) { cint_ast_error(ast, CINT_E_BAD_AST, "base type not found"); cint_datatype_clear_function(f); return NULL; } p[count].basetype = CINT_STRDUP(ty->utype.type.s); p[count].name = ident ? CINT_STRDUP(ident->utype.identifier.s) : NULL; p[count].pcount = params->utype.declaration.pcount; p[count].num_dimensions = 0; /* for CINT, parameters are either IN or INOUT */ p[count].flags = CINT_PARAM_IN; if (p[count].pcount > 0) { cint_ast_t *modifier = params->utype.declaration.type; /* const pointer is in, else in/out */ if (!(CINT_AST(modifier, Integer) && modifier->utype.integer.i == CINT_AST_TYPE_F_CONST)) { p[count].flags |= CINT_PARAM_OUT; } } } else { /* If it is not a declaration, treat it as a dummy parameter. There still needs to be a basetype, though. */ p[count].basetype = CINT_STRDUP("void"); } } p[count].basetype = NULL; /* Statements */ f->body.statements = ast->utype.functiondef.statements; /* if function is already defined, remove previous definition */ CINT_MEMSET(&dt, 0, sizeof(dt)); if(CINT_E_NONE == cint_datatype_find(f->name, &dt)) { cint_datatype_delete_function(f->name); } /* * Register with interpreter */ cint_interpreter_add_function(f); return NULL; } int cint_interpreter_callback(cint_function_pointer_t* cb, int nargs, int nreturn, ...) { int i; cint_datatype_t dt; cint_parameter_desc_t* params; cint_variable_t* v; const char* fname; int returns; int fcount; int errno_save; va_list args; va_start(args,nreturn); if(cb == NULL) { cint_internal_error(__FILE__, __LINE__, "callback pointer is NULL"); va_end(args); return 0; } fname = (char*)cb->data; if(fname == NULL) { cint_internal_error(__FILE__, __LINE__, "callback name is NULL"); va_end(args); return 0; } CINT_MEMSET(&dt, 0, sizeof(dt)); if(cint_datatype_find(fname, &dt) != 0) { cint_internal_error(__FILE__, __LINE__, "callback type '%s' was not found", fname); va_end(args); return 0; } /* * Call dynamic function. * * Sanity check the signature to detect mismatched type errors. * This could be augmented to pass full type information back with the parameters. */ returns = !cint_parameter_void(dt.basetype.fp->params); fcount = cint_parameter_count(dt.basetype.fp->params) - 1; if(cint_parameter_void(dt.basetype.fp->params+1)) fcount--; if(fcount != nargs) { cint_internal_error(__FILE__, __LINE__, "callback type '%s' was not passed the correct number of arguments (expected %d, received %d)", fname, fcount, nargs); va_end(args); return 0; } if((returns) && (nreturn == 0)) { cint_internal_error(__FILE__, __LINE__, "callback type '%s' returns a value but calling function did not specify one", fname); va_end(args); return 0; } if((returns == 0) && (nreturn)) { cint_internal_error(__FILE__, __LINE__, "callback type '%s' does not return a value but calling function expects one", fname); va_end(args); return 0; } cint_variable_scope_push(fname); for(i = 0, params = dt.basetype.fp->params+1; params && params->basetype; params++, i++) { void* addr; if(cint_parameter_void(params)) { continue; } /* Get the address of this variable */ addr = va_arg(args, void*); /* Create a variable of the appropriate type with this address */ cint_variable_create(&v, params->name, params, CINT_VARIABLE_F_SDATA, addr); } /* Evaluate function body */ cint_ftrace(dt.basetype.fp->name, 1); __returnable++; errno_save = cint_errno; v = cint_eval_asts(dt.basetype.fp->body.statements); cint_errno = errno_save; __returnable--; cint_ftrace(dt.basetype.fp->name, 0); /* Return value? */ if(v && returns) { void* addr = va_arg(args, void*); if(addr) { cint_datatype_t rt; CINT_MEMSET(&rt, 0, sizeof(rt)); if (cint_datatype_find(dt.basetype.fp->params->basetype, &rt) != 0) { cint_internal_error(__FILE__, __LINE__, "callback return type '%s' was not found", dt.basetype.fp->params->basetype); va_end(args); return 0; } if (cint_type_check(&rt, &v->dt)) { CINT_MEMCPY(addr, v->data, v->size); } else { /* At least clear out the return value to avoid valgrind complaints. */ int size; size = cint_datatype_size(&rt); if (size > 0) { CINT_MEMSET(addr, 0, size); } cint_ast_error(dt.basetype.fp->body.statements, CINT_E_BAD_AST, "return type mismatch"); } } } cint_variable_scope_pop(fname); va_end(args); return 0; } struct { const char* name; cint_variable_t* (*handler)(cint_ast_t* ast); } __ast_handler_table[] = { #define CINT_AST_LIST_ENTRY(_entry) { #_entry, __cint_eval_ast_##_entry }, #include "cint_ast_entry.h" { NULL } }; cint_variable_t* cint_eval_ast(cint_ast_t* ast) { cint_variable_t* rv = NULL; cint_ast_type_t type; cint_atrace(ast); if(ast == NULL) { return NULL; } type = ast->ntype; if(type < 0 || type >= cintAstLast) { return NULL; } CINT_DTRACE(("AST: %s", __ast_handler_table[type].name)); if(ast->noexec) { CINT_DTRACE((" marked as noexec\n")); } else { rv = __ast_handler_table[type].handler(ast); } return rv; } cint_variable_t* cint_eval_asts(cint_ast_t* ast) { cint_variable_t* rv = NULL; cint_ast_t* p; cint_errno = CINT_E_NONE; for(p = ast; p && (cint_errno == CINT_E_NONE); p = p->next) { rv = cint_eval_ast(p); } cint_variable_auto_save(rv); cint_variable_auto_clear(); return rv; }
b43cd8e47377f6f4359ac3aa879a50cb6a7efb02
c2127331ae1e5d4994eb1d77f529a735bd21c8b5
/arch/x86/gdt.c
75e8ed31fa7deb37e60550ecb594c980e2c304c0
[]
no_license
jacklin9/neftis
e0816d65779a2f83058c9691160db39228d5e131
b847a4eef6bbe7d625f772eaef675acb4b92c0ca
refs/heads/master
2023-03-15T21:57:54.584167
2015-08-11T20:28:36
2015-08-11T20:28:36
null
0
0
null
null
null
null
UTF-8
C
false
false
4,934
c
gdt.c
/* * <one line to give the program's name and a brief idea of what it does.> * Copyright (C) <year> <name of author> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> */ #include <util.h> #include <asm/seg.h> #include <asm/upperhalf.h> #include <layout.h> struct gdt_entry gdt[GDT_MAX_SEGMENTS]; BOOT_SYMBOL (struct tss tss); INLINE void gdt_entry_setup (struct gdt_entry *dest, DWORD base, DWORD page_limit, BYTE access) { if (page_limit > 0xfffff) { error ("page_limit beyond 0xfffff? wtf\n"); return; } dest->limit_low = page_limit & 0xffff; dest->base_low = base & 0xffff; dest->base_mid = (base >> 16) & 0xff; dest->base_high = (base >> 24) & 0xff; dest->limit_high = (page_limit >> 16) & 0xf; dest->access = access; dest->flags = GDT_GRANULARITY_PAGES | GDT_SELECTOR_32_BIT; } INLINE void gdt_entry_setup_tss (struct gdt_entry *dest) { uint32_t tss_base = (uint32_t) &tss; uint32_t tss_limit = tss_base + sizeof (struct tss) - 1; /* Kernel stack is in kernel data segment */ tss.ss0 = GDT_SEGMENT_KERNEL_DATA; dest->limit_low = tss_limit & 0xffff; dest->base_low = tss_base & 0xffff; dest->base_mid = (tss_base >> 16) & 0xff; dest->base_high = (tss_base >> 24) & 0xff; dest->limit_high = (tss_limit >> 16) & 0xf; dest->access = GDT_ACCESS_PRESENT | GDT_ACCESS_EXECUTABLE | GDT_ACCESS_ACCESED | GDT_ACCESS_RING (3); dest->flags = GDT_SELECTOR_32_BIT; } INLINE void debug_access (int access) { if (access & GDT_ACCESS_ACCESED) printk ("ACCESED "); if (access & GDT_ACCESS_READWRITE) printk ("READWRITE "); if (access & GDT_ACCESS_CONFORMING) printk ("CONF/DOWN "); if (access & GDT_ACCESS_EXECUTABLE) printk ("EXECUTABLE "); if (access & GDT_ACCESS_SEGMENT) printk ("SEGMENT "); else printk ("TSS"); if (access & GDT_ACCESS_PRESENT) printk ("PRESENT RING(%d) ", (access >> 5) & 3); printk ("\n"); } INLINE void debug_gdt (struct gdt_ptr *ptr) { struct gdt_entry *this_entry; int elements, i; elements = __UNITS (ptr->limit, sizeof (struct gdt_entry)); printk ("%d elements in the original GDT, located at %p\n", elements, ptr->base); this_entry = ptr->base; for (i = 0; i < elements; i++) { printk ("%d. Base: %p, limit: %p, access: %p, flags %p\n", i, (this_entry[i].base_high << 24) | (this_entry[i].base_mid << 16) | (this_entry[i].base_low), this_entry[i].limit_low | ((0xf & this_entry[i].limit_high) << 16), this_entry[i].access, this_entry[i].flags); debug_access (this_entry[i].access); } } /* This is a Linux-fashioned way to implement it */ void x86_setup_tls (uint32_t base, uint32_t limit) { /* Please note that USER_TLS_BASE is in the middle of a page */ gdt_entry_setup (GDT_ENTRY (GDT_SEGMENT_USER_TLS), base, limit, GDT_ACCESS_READWRITE | GDT_ACCESS_SEGMENT | GDT_ACCESS_PRESENT | GDT_ACCESS_RING (3)); } void gdt_init (void) { struct gdt_ptr ptr, ptr2; BYTE *gdt_bytes; int i; ptr.limit = sizeof (struct gdt_entry) * GDT_MAX_SEGMENTS - 1; ptr.base = gdt; gdt_bytes = (BYTE *) gdt; for (i = 0; i <= ptr.limit; ++i) gdt_bytes[i] = 0; gdt_entry_setup (GDT_ENTRY (GDT_SEGMENT_KERNEL_CODE), 0, 0xfffff, GDT_ACCESS_EXECUTABLE | GDT_ACCESS_SEGMENT | GDT_ACCESS_PRESENT); gdt_entry_setup (GDT_ENTRY (GDT_SEGMENT_KERNEL_DATA), 0, 0xfffff, GDT_ACCESS_READWRITE | GDT_ACCESS_SEGMENT | GDT_ACCESS_PRESENT); gdt_entry_setup (GDT_ENTRY (GDT_SEGMENT_USER_CODE), 0, 0xfffff, GDT_ACCESS_EXECUTABLE | GDT_ACCESS_SEGMENT | GDT_ACCESS_PRESENT | GDT_ACCESS_RING (3)); gdt_entry_setup (GDT_ENTRY (GDT_SEGMENT_USER_DATA), 0, 0xfffff, GDT_ACCESS_READWRITE | GDT_ACCESS_SEGMENT | GDT_ACCESS_PRESENT | GDT_ACCESS_RING (3)); gdt_entry_setup_tss (GDT_ENTRY (GDT_SEGMENT_TSS)); x86_flush_gdt (&ptr); x86_flush_tss (); x86_get_current_gdt (&ptr2); } void x86_set_kernel_stack (uint32_t addr) { tss.esp0 = addr; } DEBUG_FUNC (gdt_entry_setup); DEBUG_FUNC (gdt_entry_setup_tss); DEBUG_FUNC (debug_access); DEBUG_FUNC (debug_gdt); DEBUG_FUNC (gdt_init); DEBUG_FUNC (x86_set_kernel_stack); DEBUG_FUNC (x86_enter_user);
0adeb57ee0d86fb43c88eff16ca3a677a354dd51
f6a4eaf615e515dfd22ba00607dc87e93114c2e2
/buffer.c
5ab43b9087262c97a1d94627df99070f1f04f931
[]
no_license
DevCodeOne/minvi
f732e150e514a0b98aef156a0a200ce91ea1eba3
4a2c2d8119bb95111ec40768e71b5bce85063bc9
refs/heads/master
2021-01-10T17:07:32.695184
2015-12-05T23:10:23
2015-12-05T23:10:23
47,476,088
0
0
null
null
null
null
UTF-8
C
false
false
7,010
c
buffer.c
#include <string.h> #include <stdlib.h> #include <wchar.h> #include <stdio.h> #include <ncurses.h> #include "buffer.h" const wchar_t *abc = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789_"; const wchar_t *special_chars = L"!\"$%&/()=?`'*+-\'"; buffer *create_buffer(int initial_size, int initial_line_size) { buffer *buf = malloc(sizeof(buffer)); buf->cursor_x = 0; buf->cursor_y = 0; buf->nol = initial_size; buf->initial_line_size = initial_line_size; buf->line = malloc(initial_size * sizeof(buffer_line)); if (buf->line == NULL) { free_buffer(buf); return NULL; } for (int i = 0; i < buf->nol; i++) { buf->line[i].cursor = 0; buf->line[i].size = initial_line_size; buf->line[i].line = malloc(initial_line_size * sizeof(wchar_t)); memset(buf->line[i].line, '\0', initial_line_size * sizeof(wchar_t)); if (buf->line[i].line == NULL) { free_buffer(buf); return NULL; } } return buf; } int resize_buffer(int new_size, int initial_line_size, buffer *buf) { buffer_line *new_line = realloc(buf->line, new_size * sizeof(buffer_line)); if (new_line == NULL) { return -1; } buf->line = new_line; for (int i = buf->nol; i < new_size; i++) { new_line[i].cursor = 0; new_line[i].size = initial_line_size; new_line[i].line = malloc(initial_line_size * sizeof(wchar_t)); if (buf->line[i].line == NULL) { buf->nol = i; return -1; } memset(buf->line[i].line, '\0', initial_line_size * sizeof(wchar_t)); } buf->nol = new_size; return 0; } int resize_buffer_line(int new_size, buffer_line *line) { wchar_t *new_line = realloc(line->line, new_size * sizeof(wchar_t)); if (new_line == NULL) { return -1; } line->size = new_size; line->line = new_line; return 0; } void free_buffer(buffer *buf) { if (buf != NULL) { if (buf->line != NULL) { for (int i = 0; i < buf->nol; i++) { if (buf->line[i].line != NULL) { free(buf->line[i].line); } } free(buf->line); } free(buf); } } int is_in_bounds(int row, int column, buffer *buf) { if (row > buf->nol || row < 0) return 0; if (column >= buf->line[row].cursor || column < 0) return 0; return 1; } void clip(int *row, int *column, buffer *buf) { if (*row < 0) *row = 0; if (*row > buf->nol) *row = buf->nol-1; if (*column > buf->line[*row].cursor) *column = buf->line[*row].cursor; if (*column < 0) *column = 0; } // origin indepenpent x and y so parameters for x and y int set_cursor(int row, int column, int origin, buffer *buf) { int target_x = buf->cursor_x, target_y = buf->cursor_y; switch(origin & 0xFFFF) { // y case CUR_Y : target_y += row; break; case FIRST_LINE : target_y = row; break; case LAST_LINE : target_y = buf->nol - 1 + row; // fix this last written line break; case NEXT_LINE : target_y++; break; case PREVIOUS_LINE : target_y--; break; default : break; } if (is_in_bounds(target_y, target_x, buf)) { buf->cursor_y = target_y; } else { // invalid cursor location -> clipped clip(&target_y, &target_x, buf); buf->cursor_y = target_y; } switch(origin & (0xFFFF << 16)) { // x case CUR_X : target_x += column; break; case LINE_START : target_x = column; break; case LINE_END : target_x = buf->line[buf->cursor_y].cursor + column; break; case NEXT_WORD : // implement break; case PREVIOUS_WORD : // implement break; default : break; } if (is_in_bounds(target_y, target_x, buf)) { buf->cursor_y = target_y; buf->cursor_x = target_x; return 0; } else { // invalid cursor location -> clipped clip(&target_y, &target_x, buf); buf->cursor_y = target_y; buf->cursor_x = target_x; return 1; } } void next_word(int *x, int *y, buffer *buf) { bool in_word = 0; wchar_t *c = &buf->line[buf->cursor_y].line[buf->cursor_x]; if (*c == L' ' || *c == L'\t') { // not in word wchar_t *next_word = wcspbrk(buf->line[buf->cursor_y].line, abc); wchar_t *next_special_word = wcspbrk(buf->line[buf->cursor_y].line, special_chars); if (next_word < next_special_word && next_word != NULL) { // jump to next word } else if (next_special_word != NULL) { } } else { // jump to first blank char then to the next char wchar_t *occurence = wcschr(abc, *c); if (occurence != NULL) { // in abc } else { } } } void previous_word(int *x, int *y, buffer *buf) { } int insert(wchar_t value, buffer *buf) { buffer_line *line = &buf->line[buf->cursor_y]; if (line->size - line->cursor < 2) { int ret = resize_buffer_line(line->size * 2, line); if (ret == -1) return ret; } wchar_t *start = line->line + buf->cursor_x; if (buf->cursor_x+1 < line->cursor) // no characters behind this one wmemmove(start+1, start, line->cursor - (buf->cursor_x)); line->line[buf->cursor_x++] = value; line->cursor++; return 0; } int replace(wchar_t value, buffer *buf) { buf->line[buf->cursor_y].line[buf->cursor_x] = value; return 0; } int delete(buffer *buf) { buffer_line *line = &buf->line[buf->cursor_y]; if (line->cursor == 0) return -1; // nothing to remove wchar_t *start = line->line + buf->cursor_x; if (line->cursor > buf->cursor_x) wmemmove(start, start+1, line->cursor - (buf->cursor_x)); line->cursor--; return 0; } int insert_line(buffer *buf) { // error here if (buf->line[buf->nol-1].cursor != 0 || buf->cursor_y >= buf->nol-2) { int ret = resize_buffer(buf->nol * 2, buf->initial_line_size, buf); if (ret == -1) return ret; } buffer_line tmp = buf->line[buf->nol-1]; buffer_line *start = &buf->line[buf->cursor_y]; memmove(start + 1, start, (buf->nol - (buf->cursor_y + 1)) * sizeof(buffer_line)); buf->line[buf->cursor_y] = tmp; return 0; } int delete_line(buffer *buf) { if (buf->cursor_y == 0) return -1; buffer_line tmp = buf->line[buf->cursor_y]; buffer_line *start = &buf->line[buf->cursor_y]; memmove(start, start+1, (buf->nol - (buf->cursor_y + 1)) * sizeof(buffer_line)); memcpy(&buf->line[buf->nol-1], &tmp, sizeof(buffer_line)); buf->line[buf->nol-1].cursor = 0; return 0; } int append_line(buffer_line *src, buffer *buf) { // reuse copy_line buffer_line *selected_line = get_selected_line(buf); return copy_line(selected_line, src, selected_line->cursor, 0, src->cursor); } int copy_line(buffer_line *dst, buffer_line *src, int dst_offset, int src_offset, int len) { if (src->size < src_offset + len) return -1; if (dst->size < dst_offset + len) { int ret = resize_buffer_line(dst->size + (len * 2), dst); if (ret == -1) return ret; } wmemcpy(&dst->line[dst_offset], &src->line[src_offset], len); dst->cursor += len; return 0; } int delete_range(buffer_line *line, int off, int len) { if (line->cursor < off + len) return -1; // nothing to remove wchar_t *start = &line->line[off]; wmemmove(start, start+len, len); line->cursor -= len; return 0; } buffer_line *get_selected_line(buffer *buf) { return &buf->line[buf->cursor_y]; }
fdc6766447adeda3e55cfa1dbee087f1924b0796
e0f55f78a0a012573370b9520288cd4ccd216239
/C/C/homework/shangxinqi/15.c
b34b021b661c76bca68bcfe6fdadf423ddfe8b15
[]
no_license
lxf2git/quectel_work
2ee2811ed82d4b147f39361af89929f6f8fc6b18
92acb485689d3b1111e33dc13862cc3fe4974b16
refs/heads/master
2021-06-23T22:29:46.032931
2020-10-26T16:14:12
2020-10-26T16:14:12
145,352,846
0
0
null
null
null
null
UTF-8
C
false
false
339
c
15.c
#include<stdio.h> void calculate(); int main() { calculate(); return 0; } void calculate() { int a,c,i,j; j = 0; c = 0; printf("请输入一个100~500之间的整数:\n"); scanf("%d",&a); for (i=2;i<=500;i++) { if(a%i==0&&a!=i) { j++; c=c+i; printf("%d\n",i); } } printf("约数的个数:%d\n约数的和为:%d\n",j,c); }
af09952181afa61e0eca84aec4c93ad1a4e04026
d3ceafba7eccf9bccff8006ef0bb7e95c25aa528
/Linguagem C/Lista 8 - Recursao/14.c
7eb2ac8e01d1aefe42a3d723b9f193d2859050da
[ "MIT" ]
permissive
ThiagoInocencio/ProgramacaoDescomplicada
6e888ed22ac5e5c9a8c99b2babae6a2b7b703aa7
cba5a4a28f4ba2df288950b77e175466f84c2df3
refs/heads/master
2021-01-11T20:02:57.871474
2018-03-07T01:00:26
2018-03-07T01:00:26
79,455,026
0
0
null
null
null
null
UTF-8
C
false
false
321
c
14.c
// 14º Exercício da lista de recursão #include <stdio.h> void imprimeSerie(int i, int j, int k) { if (i > j) return; printf("%d " , i); return imprimeSerie(i+k, j, k); } int main() { printf("Serie de 1 a 10 com inclemento de 4: "); imprimeSerie(1, 10, 4); return 0; }
5eee9da7133dde3e485ff0030eac6640b15be671
210ce23798a010b2061a27b4cc3217758d90032f
/例程/11.操作系统进行PID运算/pid.c
9b69f41f12a60658470ff81c79fa2a0fb3457598
[]
no_license
chuiming24/51Tiny_STC15W_DEMO
5fea8d81fcc8b43150b72a82669f535950ab4ed3
6696380ff02fa5e6360f9343597adb77d68d1167
refs/heads/master
2021-01-01T06:28:11.797887
2018-07-08T22:21:37
2018-07-08T22:21:37
97,429,384
2
1
null
null
null
null
WINDOWS-1252
C
false
false
740
c
pid.c
#include <config.h> #include <pid.h> float M2PID_SetPoint; float M2PID_SumError; float M2PID_LastError; uint PID_M2_PosLocCalc(float NextPoint) { register float iError,dError; float M2PID_Proportion=80,M2PID_Integral=0.01,M2PID_Derivative=5;//130,0.012,10 iError = M2PID_SetPoint - NextPoint; M2PID_SumError += iError; if(M2PID_SumError > 800.0) M2PID_SumError = 800.0; else if(M2PID_SumError < -800.0) M2PID_SumError = -800.0; dError = iError - M2PID_LastError; // ¦Ì¡À?¡ã?¡é¡¤? M2PID_LastError = iError; return(uint)( M2PID_Proportion * iError // ¡À¨¨¨¤y?? + M2PID_Integral * M2PID_SumError // ?y¡¤??? + M2PID_Derivative * dError); }
e373aa740497891b91feccb29600997aa466bcc9
a103ce3469518b373e508586376191620df1b75f
/include/common/namespace.h
f38227ba1ea0c1cc9045a6d28a40e3605d074117
[]
no_license
arichardson/freebsd-crossbuild
3bb210913dcb4662009b14429dabd2f101baebd5
2f8ac76f84633c43cf5a4bcbd7b151527d1107a6
refs/heads/master
2021-01-01T04:37:37.988181
2018-01-17T15:37:34
2018-01-17T15:37:34
97,212,182
1
0
null
null
null
null
UTF-8
C
false
false
700
h
namespace.h
// we are not building this as part of libc so an empty file works fine #pragma once #define _fstat(fd, buf) fstat(fd, buf) #define _fsync(fd) fsync(fd) #define _writev(a1, a2, a3) writev(a1, a2, a3) #define _pthread_rwlock_rdlock pthread_rwlock_rdlock #define _pthread_rwlock_wrlock pthread_rwlock_wrlock #define _pthread_rwlock_unlock pthread_rwlock_unlock #define _pthread_key_create pthread_key_create #define _pthread_getspecific pthread_getspecific #define _pthread_setspecific pthread_setspecific #define _pthread_main_np pthread_main_np #define _pthread_once pthread_once #define nsdispatch _nsdispatch #define __USE_GNU 1 #include <dlfcn.h> #define libc_dlopen(a1, a2) dlopen(a1, a2)
d70641a90c9a5db176a50f017c9c4b34e8fd04d9
2ac21aacac5402affabaf5e0e7ac2be444c69ad9
/evrApp/src/devLibPMC.h
22b930408702827a051fff32f55a311e329bd6e8
[ "LicenseRef-scancode-unknown-license-reference", "EPICS" ]
permissive
slac-epics/evrClient
dfa3d9d8ef2f420f05661e5f6f036fdbb16b601d
c67459fad27175bb94b502ddc4caaebeea965f05
refs/heads/master
2023-05-31T03:35:16.727030
2023-02-25T07:04:28
2023-02-25T07:04:28
80,707,286
0
0
null
null
null
null
UTF-8
C
false
false
4,009
h
devLibPMC.h
/* dayle 03apr2006 SLAC, aliases by Sheng */ #ifndef DEVLIBPMC_H #define DEVLIBPMC_H /*--------------------- * RTEMS-Specific Header Files */ #ifdef __rtems__ #include <rtems.h> /* for rtems_status_code */ #include <rtems/pci.h> /* for PCI_BASE_CLASS_MEMORY */ #include <bsp/irq.h> /* for BSP_PCI_IRQ_LOWEST_OFFSET */ #endif #ifdef vxWorks #define printInISR logMsg #elif defined(__rtems__) #define printInISR printk /* nowhere to be found */ #else #error "This driver is not implemented for this OS" #endif #ifndef OK #define OK 0 #endif #ifndef ERROR #define ERROR (-1) #endif /* Here we define some macro to cover difference between RTEMS and vxWorks */ #ifdef vxWorks /* TO DO: Add inlines to show signatures, in case something changes */ #define epicsPciFindDevice pciFindDevice #define epicsPciConfigInByte pciConfigInByte #define epicsPciConfigInWord pciConfigInWord #define epicsPciConfigInLong pciConfigInLong #define epicsPciConfigOutByte pciConfigOutByte #define epicsPciConfigOutWord pciConfigOutWord #define epicsPciConfigOutLong pciConfigOutLong typedef unsigned char EpicsPciByte; typedef unsigned short EpicsPciWord; typedef unsigned int EpicsPciDWord; #define epicsPciIntConnect(pciLine, isr, uarg) pciIntConnect(INUM_TO_IVEC(pciLine), isr, uarg) #define epicsPciIntDisconnect(pciLine, isr, uarg) pciIntDisconnect2(INUM_TO_IVEC(pciLine), isr, uarg) /* sysIntEnablePIC is good for some paticular platform */ #define epicsPciIntEnable(pciLine) intEnable(pciLine) #define epicsPciIntDisable(pciLine) intDisable(pciLine) /* PCI resources as seen by the CPU */ #define PCI2CPUADDR(pciaddr) pciBusToLocalAdrs(pciaddr) /* CPU memory as seen from the PCI bus */ #define MEM2PCIADDR(memaddr) pciLocalToBusAdrs(memaddr) #elif defined(__rtems__) int pmc_irq_install(rtems_irq_number, rtems_irq_hdl, rtems_irq_hdl_param); int pmc_isr_uninstall(rtems_irq_number pciLine, rtems_irq_hdl isr, rtems_irq_hdl_param uarg); /*pci_find_device(unsigned short vendorid, unsigned short deviceid, int instance, int *pbus, int *pdev, int *pfun) this is the prototype #define epicsPciFindDevice(unsigned short, unsigned short, int, int*, int*, int*) pci_find_device(unsigned short, unsigned short, int, int*, int*, int*) causes error../devLibPMC.h:57:37: error: macro parameters must be comma-separated*/ #define epicsPciFindDevice pci_find_device #define epicsPciConfigInByte pci_read_config_byte #define epicsPciConfigInWord pci_read_config_word #define epicsPciConfigInLong pci_read_config_dword #define epicsPciConfigOutByte pci_write_config_byte #define epicsPciConfigOutWord pci_write_config_word #define epicsPciConfigOutLong pci_write_config_dword #if (__RTEMS_MAJOR__ > 4 ) || (__RTEMS_MAJOR__ == 4 && __RTEMS_MINOR__ > 7 ) typedef uint8_t EpicsPciByte; typedef uint16_t EpicsPciWord; typedef uint32_t EpicsPciDWord; #else typedef unsigned char EpicsPciByte; typedef unsigned short EpicsPciWord; typedef unsigned int EpicsPciDWord; #endif #ifdef USING_BSP_EXT #define devConnectInterruptPCI(pciLine, isr, uarg) \ bspExtInstallSharedISR( (int)(BSP_PCI_IRQ_LOWEST_OFFSET + (pciLine)), isr, uarg, 0) #define epicsPciIntDisconnectPCI(pciLine, isr, uarg) \ bspExtRemoveSharedISR( (int)(BSP_PCI_IRQ_LOWEST_OFFSET + (pciLine)), isr, uarg) #else #define devConnectInterruptPCI(pciLine, isr, uarg) \ pmc_irq_install((rtems_irq_number)pciLine, (rtems_irq_hdl)isr, (rtems_irq_hdl_param)uarg) #define devDisconnectInterruptPCI(pciLine, isr, uarg) \ pmc_irq_uninstall(PmcIsrArg_t* d) #endif #define epicsPciIntEnable(pciLine) BSP_enable_irq_at_pic(pciLine) #define epicsPciIntDisable(pciLine) BSP_disable_irq_at_pic(pciLine) /* PCI resources as seen by the CPU */ #define PCI2CPUADDR(pciaddr) ((unsigned long)(pciaddr) + PCI_MEM_BASE) /* CPU memory as seen from the PCI bus */ #define MEM2PCIADDR(memaddr) ((unsigned long)(memaddr) + PCI_DRAM_OFFSET) #else #error "This driver is not implemented for this OS" #endif #endif
9880665f84295918ee143cb4d2769a0c214854d1
347864e98de6b3af98385173c596feb18288f8d5
/philo_one/ft_work_in_thread.c
f78feaedcaaf35b421bdb0f9c87e27c4f0bea636
[]
no_license
farhod-rahimov/philosophers
4f3a83e89ea4cf9748f779b4e88c5ecddec0b57b
1fd45720370ff906f142bf13569452c4e074ed49
refs/heads/master
2023-07-27T21:28:56.531108
2021-09-09T10:24:14
2021-09-09T10:24:14
353,594,161
0
0
null
2021-09-09T10:18:14
2021-04-01T06:12:47
C
UTF-8
C
false
false
1,969
c
ft_work_in_thread.c
#include "philo_one.h" void *ft_work_in_thread(void *n) { long long int current; g_data.start_starving[*(int *)n] = ft_get_time(); while (1) { if (g_data.should_eat[*(int *)n] == 1 && !g_data.is_sleeping[*(int *)n] && \ !g_data.is_thinking[*(int *)n]) { current = ft_get_time(); pthread_mutex_lock(&g_print_mutex); ft_print(current - g_data.start_time, *(int *)n, \ " has taken a fork\n"); ft_print(current - g_data.start_time, *(int *)n, \ " has taken a fork\n"); pthread_mutex_unlock(&g_print_mutex); ft_eat_phil(*(int *)n, current); } } return (NULL); } void ft_eat_phil(int n, long long int current) { g_data.start_starving[n] = current; pthread_mutex_lock(&g_print_mutex); ft_print(current - g_data.start_time, n, " is eating\n"); pthread_mutex_unlock(&g_print_mutex); ft_sleep(g_data.time_eat); pthread_mutex_unlock(&g_fork_mutex[n]); if (n + 1 == g_data.num_phils) pthread_mutex_unlock(&g_fork_mutex[0]); else pthread_mutex_unlock(&g_fork_mutex[n + 1]); if (--g_data.total_num_eat <= 0 && g_data.num_eat != -1) { pthread_mutex_lock(&g_print_mutex); exit(0); } g_data.should_eat[n] = 2; return (ft_sleep_phil(n, current + g_data.time_eat)); } void ft_sleep_phil(int n, long long int current) { g_data.is_sleeping[n] = 1; pthread_mutex_lock(&g_print_mutex); ft_print(current - g_data.start_time, n, " is sleeping\n"); pthread_mutex_unlock(&g_print_mutex); ft_sleep(g_data.time_sleep); g_data.is_sleeping[n] = 0; return (ft_think_phil(n, current + g_data.time_sleep)); } void ft_think_phil(int n, long long int current) { g_data.is_thinking[n] = 1; pthread_mutex_lock(&g_print_mutex); ft_print(current - g_data.start_time, n, " is thinking\n"); pthread_mutex_unlock(&g_print_mutex); g_data.is_thinking[n] = 0; } void ft_sleep(long long int milliseconds) { long long int start_time; start_time = ft_get_time(); while (ft_get_time() - start_time <= milliseconds) usleep(50); }
2e2ab93643ae0aabbeb122c7b30f27943353a28f
1eb263b2633dd6bd56ad39cef8cf8c8bb18357bc
/commonFunctions.c
77582daf5d80afae43007175088b044abdfb3b6b
[ "MIT" ]
permissive
daniyalmaroufi/danikala
ef14e5a63afef29f9e410763242fd65e82059962
7ddd0ce5f37f5b96f085da9ad198b7b5873582c2
refs/heads/master
2022-11-10T03:55:03.700516
2020-06-16T11:05:58
2020-06-16T11:05:58
null
0
0
null
null
null
null
UTF-8
C
false
false
1,044
c
commonFunctions.c
#ifndef HEADERS_IMPORTED #include "main.h" #include "commonFunctions.h" #endif //** this function checks malloc and exits program if error void checkMalloc(void* pointer) { if (pointer == NULL) { printf("Memory Allocation Error!"); exit(EXIT_FAILURE); } } //** this function checks for user given parameters int checkInput(void* pointer) { if (pointer == NULL) { printf("Wrong Input! Try again."); return 1; } return 0; } //** this function gets user input char* getCommandLine() { char* str; int ch; size_t size = 1; size_t len = 0; str = (char*)realloc(NULL, sizeof(char) * size); checkMalloc(str); while (EOF != (ch = getchar()) && ch != '\n') { str[len++] = ch; if (len == size) { str = (char*)realloc(str, sizeof(char) * (size += 16)); checkMalloc(str); } } str[len++] = '\0'; return (char*)realloc(str, sizeof(char) * len); }
bc9b321072437dda3e48945e41ae7e0fdeb4cb7c
94db9bd88338198cd05849084410858de8b7ca3f
/decibel/gl.c
e5dbfe2a4c83e24bde704ee24fa4deb6b383d11c
[]
no_license
mengdj/decibel
0107b6445a6aae94b96695289f8c9e590979316e
19756d1cd8b4044ba14dfe3c6e64b06f0b6a4926
refs/heads/master
2020-05-16T09:51:37.852009
2020-01-11T04:19:46
2020-01-11T04:19:46
182,963,373
1
1
null
null
null
null
UTF-8
C
false
false
14,295
c
gl.c
//http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html //https://www.jianshu.com/p/88cb8da9a494?utm_campaign=maleskine&utm_content=note&utm_medium=reader_share&utm_source=qzone #include "stdafx.h" #include "gl.h" #define REN_FRAME_COUNT 1024 #define REN_REL_VVAL 0.001953125f // 2/1024 #define MAX_CHAR 128 #define OPENGL_PI 3.1415926f #define FFT_FACTOR 0.1f #define BACKGROUND_WIDTH 500 #define BACKGROUND_HEIGHT 130 #ifndef MAX_LOADSTRING #define MAX_LOADSTRING 128 #endif // ! static HGLRC hRC = NULL; static HDC hDC = NULL; static HWND hOpenGlWnd = NULL; static HINSTANCE hInst = NULL; static GLfloat aHdata[REN_FRAME_COUNT]; static GLfloat aVdata[3276]; static HFONT hFont[2] = { 0 }; static HANDLE hFontsInstalled = NULL; static GLfloat iPointXPre = 0; static GLuint texturesIds[1]; static GLfloat vPrecent = 0.0f; static SIZE sMsgSize = { 0,0 }; static CHAR* bgNames[2] = { "res/background_a.png","res/background_b.png" }; static kiss_fft_cfg fft_cfg = NULL; static INT pre_channel = 0; ATOM RegisterGlCls(WNDPROC wndProc, HINSTANCE hInstance) { hInst = hInstance; WNDCLASS wc; wc.style = CS_OWNDC; wc.lpfnWndProc = wndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInst; wc.hIcon = NULL; wc.hCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_CURSOR_DEF)); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = TEXT("OpenGL"); return RegisterClass(&wc); } BOOL UnInitGlWindow() { BOOL ret = TRUE; glDeleteTextures(1, texturesIds); if (hRC) { if (hRC) { if (!wglMakeCurrent(NULL, NULL)) { ret = FALSE; } if (!wglDeleteContext(hRC)) { ret = FALSE; } hRC = NULL; } if (hFont[1]) { DeleteObject(SelectObject(hDC, hFont[1])); } if (hDC && !ReleaseDC(hOpenGlWnd, hDC)) { hDC = NULL; ret = FALSE; } if (hOpenGlWnd && !DestroyWindow(hOpenGlWnd)) { hOpenGlWnd = NULL; } if (!UnregisterClass("OpenGL", hInst)) { hInst = NULL; ret = FALSE; } } if (fft_cfg) { kiss_fft_free(fft_cfg); fft_cfg = NULL; } return ret; } VOID GlTextout(FLOAT x, FLOAT y, CONST WCHAR* wstring) { int len, i; HDC hDC = wglGetCurrentDC(); GLuint list = glGenLists(1); len = 0; for (i = 0; wstring[i] != '\0'; ++i) { if (IsDBCSLeadByte(wstring[i])) ++i; ++len; } glRasterPos2f(x, y); // 逐个输出字符 for (i = 0; i < len; ++i) { wglUseFontBitmapsW(hDC, wstring[i], 1, list); glCallList(list); } // 回收所有临时资源 glDeleteLists(list, 1); } VOID ReSizeGl(INT iX, INT iY, INT iWidth, INT iHeight) { vPrecent = 1.0f / (iWidth >> 1); sMsgSize.cx = sMsgSize.cy = 0; glViewport(iX, iY, iWidth, iHeight); } DWORD WINAPI RenderGl(LPVOID lpParameter) { static SYSTEMTIME sysTime = { 0 }; kiss_fft_cpx kfc_in[REN_FRAME_COUNT] = { 0 }, kfc_out[REN_FRAME_COUNT] = { 0 }; GLfloat gfPointVal[3][2] = { {-1.0f, 0.0f},{1.0f, 0.0f},{-1.0f,0.0f} }, gfCurrentColor[4] = { 0 }; INT iSize = 0, iRead = 0, iIndex = 0, iCount = 0; INT16 iVal = 0; LP_OPEN_GL_REN_ENV pEnv = (LP_OPEN_GL_REN_ENV)lpParameter; if (pEnv) { if (*pEnv->bRunning == TRUE) { //复位坐标到中心点 glMatrixMode(GL_MODELVIEW); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glGetFloatv(GL_CURRENT_COLOR, gfCurrentColor); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texturesIds[0]); glBegin(GL_QUADS); glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, -1.0, 1.0); //左下 glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 1.0, 1.0); //左上 glTexCoord2f(1.0, 0.0); glVertex3f(1.0, 1.0, 1.0); //右上 glTexCoord2f(1.0, 1.0); glVertex3f(1.0, -1.0, 1.0); //右下 glEnd(); glDisable(GL_TEXTURE_2D); glColor3ub(0x94, 0xE6, 0x5C); glLineWidth(1.0f); glBegin(GL_LINES); glVertex2fv(&gfPointVal[0]); glVertex2fv(&gfPointVal[1]); glEnd(); if (TryAcquireSRWLockShared(pEnv->pLock)) { //INFINITE iIndex = pEnv->pRingbuff->readIndex; iSize = PaUtil_GetRingBufferReadAvailable(pEnv->pRingbuff); iRead = MIN(iSize, REN_FRAME_COUNT); if (iSize > REN_FRAME_COUNT) { PaUtil_AdvanceRingBufferReadIndex(pEnv->pRingbuff, iSize - REN_FRAME_COUNT); iIndex = pEnv->pRingbuff->readIndex; iSize -= (iSize - REN_FRAME_COUNT); } if (iRead) { if (PaUtil_ReadRingBuffer(pEnv->pRingbuff, kfc_in, iRead) == iRead) { //kiss_fft(fft_cfg, kfc_in, kfc_out); iCount = 0; while (iCount < iRead) { iVal = kfc_in[iCount].r; if (iVal != 0) { glBegin(GL_LINES); if (iVal > 0) { gfPointVal[0][0] = -aHdata[iCount]; gfPointVal[0][1] = aVdata[(int)iVal / 10]; gfPointVal[1][0] = gfPointVal[0][0]; gfPointVal[1][1] = 0; } else { iVal = abs(iVal); gfPointVal[0][0] = -aHdata[iCount]; gfPointVal[0][1] = 0; gfPointVal[1][0] = gfPointVal[0][0]; gfPointVal[1][1] = -aVdata[(int)iVal / 10]; glColor3ub(0xFF, 0x74, 0x00);; } glColor3ub(0xFF, 0x74, 0x00); glVertex2fv(&gfPointVal[0]); glVertex2fv(&gfPointVal[1]); glEnd(); } iCount++; } } } if (iCount && PaUtil_GetRingBufferReadAvailable(pEnv->pRingbuff) < REN_FRAME_COUNT) { pEnv->pRingbuff->readIndex = iIndex - 1; PaUtil_AdvanceRingBufferReadIndex(pEnv->pRingbuff, 1); } if (pEnv->pWVariable != NULL) { WakeConditionVariable(pEnv->pWVariable); } ReleaseSRWLockShared(pEnv->pLock); } //录音状态 DWORD dTicket = GetTickCount(); if (*pEnv->bRecord) { if (pEnv->bRestart) { ZeroMemory(&sysTime, sizeof(SYSTEMTIME)); pEnv->bRestart = FALSE; pEnv->iTicket = 0; } else { if (pEnv->iMinizeTicket[1]) { //转化时间(从最小化和恢复来计算持续时间) INT iCalcSecond = (pEnv->iMinizeTicket[1] - pEnv->iMinizeTicket[0]) / 1000; if (iCalcSecond) { InterlockedAdd(&sysTime.wSecond, iCalcSecond); if (sysTime.wSecond >= 60) { InterlockedAdd(&sysTime.wMinute, sysTime.wSecond / 60); if (sysTime.wMinute >= 60) { InterlockedAdd(&sysTime.wHour, sysTime.wMinute / 60); InterlockedExchange(&sysTime.wMinute, sysTime.wMinute % 60); } InterlockedExchange(&sysTime.wSecond, sysTime.wSecond % 60); } } pEnv->iTicket = dTicket; pEnv->iMinizeTicket[0] = pEnv->iMinizeTicket[1] = 0; } } //1000ms if ((dTicket - pEnv->iTicket) > 1000) { pEnv->iTicket = dTicket; InterlockedAdd(&sysTime.wSecond, 1); if (sysTime.wSecond >= 60) { InterlockedExchange(&sysTime.wSecond, 0); InterlockedAdd(&sysTime.wMinute, 1); if (sysTime.wMinute >= 60) { InterlockedExchange(&sysTime.wMinute, 0); InterlockedAdd(&sysTime.wHour, 1); } } } glColor3ub(0xFF, 0x7C, 0x00); WCHAR cTimeStr[MAX_CHAR]; swprintf_s(cTimeStr, MAX_CHAR, TEXT("%.2d:%.2d:%.2d"), sysTime.wHour, sysTime.wMinute, sysTime.wSecond); //计算坐标 if (sMsgSize.cx == 0) { GetTextExtentPoint32(wglGetCurrentDC(), cTimeStr, lstrlen(cTimeStr), &sMsgSize); } GlTextout(1 - vPrecent * (sMsgSize.cx + 7), -0.90f, cTimeStr); } glColor4fv(gfCurrentColor); glFlush(); SwapBuffers(hDC); } return TRUE; } return FALSE; } BOOL InitGlWindow(HWND hWnd, INT bits, INT iWidth, INT iHeight, mz_zip_archive * pZip) { PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, //版本 PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, bits, // 选定色彩gL深度 0, 0, 0, 0, 0, 0, // 忽略的色彩位 0, // 无Alpha缓存 0, // 忽略Shift Bit 0, // 无累加缓存 0, 0, 0, 0, // 忽略聚集位 24, // 16位 Z-缓存 (深度缓存) 0, // 无蒙板缓存 0, // 无辅助缓存 PFD_MAIN_PLANE, // 主绘图层 0, // Reserved 0, 0, 0 // 忽略层遮罩 }; hOpenGlWnd = hWnd; GLuint iPixelFormat = 0; LPVOID resBuff = NULL; INT iSize = 0, iRealBytes = 0; hDC = GetDC(hWnd); if (!hDC) { UnInitGlWindow(); return -1; } if (!(iPixelFormat = ChoosePixelFormat(hDC, &pfd))) { UnInitGlWindow(); return -2; } if (!SetPixelFormat(hDC, iPixelFormat, &pfd)) { UnInitGlWindow(); return -3; } DescribePixelFormat(hDC, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd); if (!(hRC = wglCreateContext(hDC))) { UnInitGlWindow(); return -4; } if (!wglMakeCurrent(hDC, hRC)) { UnInitGlWindow(); return -5; } ReSizeGl(0, 0, iWidth, iHeight); glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glLoadIdentity(); //加载字体 hFont[0] = CreateFontA(32, 0, 0, 0, FW_THIN, 0, 0, 0, GB2312_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "方正细黑一简体"); if (hFont[0] != NULL) { hFont[1] = SelectObject(hDC, hFont[0]); } #ifndef _DEBUG free(resBuff); #endif resBuff = NULL; GLfloat iBaseVal = 32767 / 10; iBaseVal = 1 / iBaseVal; for (int i = 0; i <= 3276; i++) { aVdata[i] = i * iBaseVal; } //构建查询缓存) for (int j = 0; j < REN_FRAME_COUNT; j++) { aHdata[j] = 1 - REN_REL_VVAL * j; } iPointXPre = (GLfloat)(1.0f / iWidth); //纹理数据 srand((unsigned)time(NULL)); INT w = 0, h = 0, c = 0; glGenTextures(1, texturesIds); glEnable(GL_TEXTURE_2D); BYTE * resDecBuff = NULL; CHAR * pBackgroundName = NULL; WCHAR wName[MAX_LOADSTRING] = { 0 }; if (GetPrivateProfileStringLocal(TEXT("OPENGL"), TEXT("background"), TEXT("NULL"), wName, MAX_LOADSTRING)) { if (lstrcmp(wName, TEXT("NULL")) != 0) { HANDLE hFile = CreateFile( wName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 ); if (hFile != INVALID_HANDLE_VALUE) { //resBuff if (iSize = GetFileSize(hFile, NULL)) { resBuff = malloc(iSize); if (!ReadFile(hFile, resBuff, iSize, &iRealBytes, NULL)) { free(resBuff); resBuff = NULL; } } CloseHandle(hFile); } } } if ((resBuff != NULL) || (iSize = LoadResourceFromZip(pZip, bgNames[(rand() % 2)], &resBuff))) { resDecBuff = stbi_load_from_memory((BYTE*)resBuff, iSize, &w, &h, &c, 0); if (resDecBuff != NULL) { //0 glBindTexture(GL_TEXTURE_2D, texturesIds[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); pre_channel = c; if (c == 3) { //3通道 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, resDecBuff); } else { //4通道 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, resDecBuff); } stbi_image_free(resDecBuff); } #ifndef _DEBUG free(resBuff); #endif resBuff = NULL; } glDisable(GL_TEXTURE_2D); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); fft_cfg = kiss_fft_alloc(REN_FRAME_COUNT, 0, NULL, NULL); return TRUE; } BOOL GlUpdateBackgroundFromFile(CONST CHAR * cName) { INT w = 0, h = 0, c = 0; BOOL ret = FALSE; BYTE* resDecBuff = stbi_load(cName, &w, &h, &c, 0); if (resDecBuff) { if (texturesIds[1]) { if (pre_channel == c && w == BACKGROUND_WIDTH && h == BACKGROUND_HEIGHT) { glBindTexture(GL_TEXTURE_2D, texturesIds[0]); if (c == 3) { //3通道 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, resDecBuff); ret = TRUE; } else { //4通道 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, resDecBuff); } } else { //清理纹理内存 glDeleteTextures(1, texturesIds); glGenTextures(1, texturesIds); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texturesIds[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); pre_channel = c; //缩放图像 /** if (w > BACKGROUND_WIDTH || h > BACKGROUND_HEIGHT) { INT iNewWidth = MIN(BACKGROUND_WIDTH, w), iNewHeight = MIN(BACKGROUND_HEIGHT, h); LPBYTE resDecThumbBuff = malloc(iNewWidth * iNewHeight * c); if (resDecThumbBuff && stbir_resize_uint8(resDecBuff, w, h, 0, resDecThumbBuff, iNewWidth, iNewHeight, 0, c)) { CopyMemory(resDecBuff, resDecThumbBuff, iNewWidth * iNewHeight * c); w = iNewWidth; h = iNewHeight; } free(resDecThumbBuff); resDecThumbBuff = NULL; }*/ if (c == 3) { //3通道 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, resDecBuff); ret = TRUE; } else { //4通道 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, resDecBuff); } } if (ret) { WCHAR wName[MAX_LOADSTRING] = { 0 }; Char2WChar(cName, wName); if (!WritePrivateProfileStringLocal(TEXT("OPENGL"), TEXT("background"), wName)) { } } } stbi_image_free(resDecBuff); resDecBuff = NULL; } return ret; } VOID GlReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid * pixels) { //字节对齐 glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glReadPixels(0, 0, width, height, format, type, pixels); //图像翻转,由下到上转为由上到下 GLubyte* bufferConv = (GLubyte*)malloc(width * height * 4); if (bufferConv) { GLubyte* pFlipBuffer = pixels; for (int y = 0; y < height; y++) { for (int x = 0; x < width * 4; x++) { bufferConv[(height - 1 - y) * width * 4 + x] = pFlipBuffer[y * 4 * width + x]; } } CopyMemory(pixels, bufferConv, width * height * 4); free(bufferConv); } }
cd519221146b9f6dcb4a5fa17e17f7a8e8c7925b
9a45b9efb9faeaa665f9d4cb6f6d5387f7b37739
/OwlEngine/Headers/OwlTools.h
22c8097b5e749441e99771133d58741ff670eb94
[]
no_license
Remurr/RPGOwl
a2e6ee843a1cb272f026c784d6072547e277fb8a
0f2021a2868d0ac097dbb1606726b90e72d16a41
refs/heads/master
2020-04-10T07:07:34.651847
2018-12-13T21:35:25
2018-12-13T21:35:25
160,872,983
0
0
null
null
null
null
UTF-8
C
false
false
161
h
OwlTools.h
#pragma once #define owlassert(x) ((void)(!(x) && owl_assert_impl(#x, __FILE__, __LINE__))) bool owl_assert_impl(const char *expr, const char *file, int line);
307bf03620903428fc5d7ae0ba2d133de7b815c1
f5d536f66bebde70e9ae13177a6228f65e36b9e2
/cmds/std/_search.c
867d371dadebcdde132a22ae20213874d6fd4708
[]
no_license
MudRen/es
f60a5884c6a57bddc67893bcafa78896b0fe021c
4c2177e513c9f2e57fbcca3a9239e6a5096a6b7d
refs/heads/master
2021-08-26T07:38:41.278630
2021-08-17T09:40:05
2021-08-17T09:40:05
173,731,541
1
1
null
null
null
null
GB18030
C
false
false
1,854
c
_search.c
//#pragma save_binary // search.c // This is a default search command that doesn't find anything. The main // purpose of it is that if a player searches in a room that doesn't have // anything to search for, he gets the "You search but find nothing" instaed // of "What?". If a room defines a search command via add_action it will // override this command. (If it doesn't then dike this command out!) // Written by Mobydick, 11-13-92 // If you use this code, please leave this header in. // If you don't, the Code Police will hunt you down and kill you. // Added cusstomized messages by Annihilator@Eastern.Stories (12-19-93) int cmd_search(string arg) { object env; string msg, func; int herbs_skill; mapping reagent; if(!this_player()->query("vision")) return notify_fail( "你现在什麽也看不见,没有办法搜索。\n"); env = environment( this_player() ); if( !env ) return notify_fail( "这里一片虚无,无从搜索起....\n"); if( !arg || arg=="" ) arg = "here"; if( (msg= env->query("search_desc/"+arg)) ) { write( msg ); } else if( herbs_skill = this_player()->query_skill("herbs") && (reagent = (mapping)env->query("reagents")) ) { // Healers can get reagents in some place. write( "你找了又找,并没有发现任何东西。\n"); tell_room( environment(this_player()), this_player()->query("c_name") + "在这里四处搜索,不知道在找些什麽?\n", this_player() ); } else { write( "你找了又找,并没有发现任何东西。\n"); tell_room( environment(this_player()), this_player()->query("c_name") + "在这里四处搜索,不知道在找些什麽?\n" , this_player() ); } return 1; } int help() { write (@HELP 使用格式: search <目标> 这个指令将搜索四周或<目标>,是解谜手段之一. HELP ); return 1 ; }
c5aa0ce5ff7c767df76cbffb18ee8687d0c0277d
69e00e9be45e368174174a22255ea8b18dd8ee88
/3. ICG/tests/test4.c
d88e3302ad4c7c59ee2247fb49b5639722be88fc
[ "MIT" ]
permissive
apoorvegupta/Mini-C-Compiler
938705941a1bd2e0328635b733955ecf7433b165
70277f9884be4da1c031d98a80abb7f910167b47
refs/heads/master
2022-12-21T06:57:28.771346
2020-10-01T09:21:32
2020-10-01T09:21:32
266,260,564
0
1
MIT
2020-10-01T09:13:22
2020-05-23T04:11:04
C
UTF-8
C
false
false
128
c
test4.c
#include <stdio.h> int main() { int a=5; int b=6; int c=8; for(a=9;a!=6;a=a-1) { b=b+4; c=c-1; } b=b/9; return 0; }
d00eefff6890a574865c5f0fe271c50fd3bd7589
99629eb9d964b599b98ebb86ca1e0c0be37b8488
/source/Afloat/Afloat/AfloatScripting/AfloatScriptingWire.h
eb3611ef539a824653f239bffd8f8be0c5bbb3f2
[ "BSD-3-Clause" ]
permissive
w0lfschild/SIMBLPlugins
b11cb53522455c1135f37dc53ff9eb9527962cf8
55adeeb8a3438af08183246c432c532bab9b586e
refs/heads/master
2021-01-17T09:34:54.264034
2019-08-10T07:49:23
2019-08-10T07:49:23
42,365,689
68
4
null
null
null
null
UTF-8
C
false
false
2,764
h
AfloatScriptingWire.h
#define kAfloatScriptWireObject @"net.infinite-labs.Afloat.Scripting" // Toggles the "kept afloat" flag for the topmost window. // userInfo: // @"showsBadgeAnimation" -- if NO suppresses badge animation; otherwise or YES shows the badge animation. #define kAfloatScriptToggleKeptAfloatNotification @"net.infinite-labs.Afloat.Scripting.ToggleKeptAfloat" // Sets the "kept afloat" flag for a window. // userInfo: // @"showsBadgeAnimation" -- if NO suppresses badge animation; otherwise or YES shows the badge animation. // @"keptAfloat" -- YES to keep a window afloat, NO to return it to normal. // NOTE: keptAfloat = NO may return a pinned-to-desktop window to normal. #define kAfloatScriptSetKeptAfloatNotification @"net.infinite-labs.Afloat.Scripting.SetKeptAfloat" // Sets the alpha value for a window. // userInfo: // @"alphaValue" -- Real 0.0 to 1.0. It will be clamped to the built-in default range (which may be smaller). 0.0 means fully transparent, 1.0 fully opaque. #define kAfloatScriptSetAlphaValueNotification @"net.infinite-labs.Afloat.Scripting.SetAlphaValue" // Sets the "to be kept on the screen on all Spaces" flag for the topmost window. // userInfo: // @"keptOnAllSpaces" -- YES to keep on all Spaces, NO to return to normal. #define kAfloatScriptSetKeptOnAllSpacesNotification @"net.infinite-labs.Afloat.Scripting.SetKeptOnAllSpaces" // Sets the "pinned to desktop" flag for a window. // userInfo: // @"showsBadgeAnimation" -- YES to show a badge animation, NO otherwise. // @"pinnedToDesktop" -- YES to keep a window pinned, NO to return it to normal. // NOTE: pinnedToDesktop = NO may return an afloat window to normal. #define kAfloatScriptSetPinnedToDesktopNotification @"net.infinite-labs.Afloat.Scripting.SetKeptPinnedToDesktop" // Sets the "overlay" flag for a window. // userInfo: // @"showsBadgeAnimation" -- YES to show a badge animation, NO otherwise. // @"overlay" -- YES to make the window an overlay, NO to return it to normal. // NOTE: same behavior as the overlay checkbox in Adjust Effects. (Long to describe here.) #define kAfloatScriptSetOverlayNotification @"net.infinite-labs.Afloat.Scripting.SetOverlay" // Disables all overlays in the topmost app. #define kAfloatScriptDisableAllOverlaysNotification @"net.infinite-labs.Afloat.Scripting.DisableAllOverlays" // Makes one step more transparent. #define kAfloatScriptMoreTransparentNotification @"net.infinite-labs.Afloat.Scripting.MoreTransparent" // Makes one step less transparent. #define kAfloatScriptLessTransparentNotification @"net.infinite-labs.Afloat.Scripting.LessTransparent" // Shows the topmost window's file in the Finder, if any. #define kAfloatScriptShowWindowFileInFinderNotification @"net.infinite-labs.Afloat.Scripting.ShowWindowFileInFinder"
131cab16ebce0129ab6d892f4c705f30c03a5966
8043cea4c44b584000127aa376970998830e0453
/complex.h
79dd68f4f145510fa93c2cb044b218e975536193
[]
no_license
Pandoz/qwert
258d2d6700f61ac425bd38d4f1535eb1842a856c
e0240d96c03ca4d22b6e229f148db39a694d3ff2
refs/heads/master
2020-05-05T14:07:22.250530
2019-04-29T09:59:02
2019-04-29T09:59:02
180,108,165
1
0
null
null
null
null
UTF-8
C
false
false
296
h
complex.h
#ifndef Complex_h #define Complex_h struct Complex { double re; double im; }; bool check(double x, double y); void pluss(Complex N1, Complex N2); void substruct(Complex N1, Complex N2); void multiplication(Complex N1, Complex N2); void devide(Complex N1, Complex N2); #endif
ba4fac67941d29ce5f4c9cd4c8e9b1cd2ac99c14
db9ea9928ab6e74aeab5494e3c8e641b4d565547
/src/exec/data-or/or-template.h
d339beb1dfdd9f241f7c0486b7f9f390b548c437
[]
no_license
Zhang-Ying/ICS_lab
6327726467902b8ca5530ce666bd88c1ae9cdffc
bafbcdbf8d59d64c614559a04254cd2ef8cb3bde
refs/heads/master
2020-03-26T01:35:52.316197
2015-07-25T05:49:02
2015-07-25T05:49:02
39,623,139
0
0
null
null
null
null
UTF-8
C
false
false
4,066
h
or-template.h
#include "exec/helper.h" #include "exec/template-start.h" #include "cpu/modrm.h" make_helper(concat(or_rm2r_,SUFFIX)){ ModR_M m; m.val=instr_fetch(eip+1,1); DATA_TYPE s; long result; char t; if(m.mod==3){ REG(m.R_M)=REG(m.R_M)|REG(m.reg); s=REG(m.R_M); result=REG(m.R_M); t=s&0xff; t=(t>>1)^(t>>2)^(t>>3)^(t>>4)^(t>>5)^(t>>6)^(t>>7)^(t>>8); cpu.eflags.PF=t&0x01; if(result==s+0x100000000) cpu.eflags.CF=1; else cpu.eflags.CF=0; if(cpu.eflags.CF==1) cpu.eflags.SF=1; else if(s<0) cpu.eflags.SF=1; else cpu.eflags.SF=0; if(cpu.eflags.CF==0&&s==0) cpu.eflags.ZF=1; else cpu.eflags.ZF=0; if(cpu.eflags.CF==1) cpu.eflags.OF=0; else if(result!=s+0x100000000) cpu.eflags.OF=1; else cpu.eflags.OF=0; print_asm("or" str(SUFFIX) " %%%s,%%%s",REG_NAME(m.reg),REG_NAME(m.R_M)); return 1+1; } else{ swaddr_t addr; int len=read_ModR_M(eip+1,&addr); MEM_W(addr,MEM_R(addr)|REG(m.reg)); s=MEM_R(addr); result=MEM_R(addr); t=s&0xff; t=(t>>1)^(t>>2)^(t>>3)^(t>>4)^(t>>5)^(t>>6)^(t>>7)^(t>>8); cpu.eflags.PF=t&0x01; if(result==s+0x100000000) cpu.eflags.CF=1; else cpu.eflags.CF=0; if(cpu.eflags.CF==1) cpu.eflags.SF=1; else if(s<0) cpu.eflags.SF=1; else cpu.eflags.SF=0; if(cpu.eflags.CF==0&&s==0) cpu.eflags.ZF=1; else cpu.eflags.ZF=0; if(cpu.eflags.CF==1) cpu.eflags.OF=0; else if(result!=s+0x100000000) cpu.eflags.OF=1; else cpu.eflags.OF=0; print_asm("or" str(SUFFIX) "%s,%%%s",ModR_M_asm,REG_NAME(m.reg)); return 1+len; } } make_helper(concat(or_r2rm_,SUFFIX)){ ModR_M m; m.val=instr_fetch(eip+1,1); DATA_TYPE s; long result; char t; if(m.mod==3){ REG(m.reg)=REG(m.R_M)|REG(m.reg); s=REG(m.reg); result=REG(m.reg); t=s&0xff; t=(t>>1)^(t>>2)^(t>>3)^(t>>4)^(t>>5)^(t>>6)^(t>>7)^(t>>8); cpu.eflags.PF=t&0x01; if(result==s+0x100000000) cpu.eflags.CF=1; else cpu.eflags.CF=0; if(cpu.eflags.CF==1) cpu.eflags.SF=1; else if(s<0) cpu.eflags.SF=1; else cpu.eflags.SF=0; if(cpu.eflags.CF==0&&s==0) cpu.eflags.ZF=1; else cpu.eflags.ZF=0; if(cpu.eflags.CF==1) cpu.eflags.OF=0; else if(result!=s+0x100000000) cpu.eflags.OF=1; else cpu.eflags.OF=0; print_asm("or" str(SUFFIX) " %%%s,%%%s",REG_NAME(m.R_M),REG_NAME(m.reg)); return 1+1; } else{ swaddr_t addr; int len=read_ModR_M(eip+1,&addr); REG(m.reg)=MEM_R(addr)|REG(m.reg); s=REG(m.reg); result=REG(m.reg); t=s&0xff; t=(t>>1)^(t>>2)^(t>>3)^(t>>4)^(t>>5)^(t>>6)^(t>>7)^(t>>8); cpu.eflags.PF=t&0x01; if(result==s+0x100000000) cpu.eflags.CF=1; else cpu.eflags.CF=0; if(cpu.eflags.CF==1) cpu.eflags.SF=1; else if(s<0) cpu.eflags.SF=1; else cpu.eflags.SF=0; if(cpu.eflags.CF==0&&s==0) cpu.eflags.ZF=1; else cpu.eflags.ZF=0; if(cpu.eflags.CF==1) cpu.eflags.OF=0; else if(result!=s+0x100000000) cpu.eflags.OF=1; else cpu.eflags.OF=0; print_asm("or" str(SUFFIX) "%s,%%%s",REG_NAME(m.reg),ModR_M_asm); return 1+len; } } make_helper(concat(or_al_,SUFFIX)){ DATA_TYPE s; long result; char t; DATA_TYPE imm=instr_fetch(eip+1,DATA_BYTE); REG(0)=REG(0)|imm; s=REG(0); result=REG(0); t=s&0xff; t=(t>>1)^(t>>2)^(t>>3)^(t>>4)^(t>>5)^(t>>6)^(t>>7)^(t>>8); cpu.eflags.PF=t&0x01; if(result==s+0x100000000) cpu.eflags.CF=1; else cpu.eflags.CF=0; if(cpu.eflags.CF==1) cpu.eflags.SF=1; else if(s<0) cpu.eflags.SF=1; else cpu.eflags.SF=0; if(cpu.eflags.CF==0&&s==0) cpu.eflags.ZF=1; else cpu.eflags.ZF=0; if(cpu.eflags.CF==1) cpu.eflags.OF=0; else if(result!=s+0x100000000) cpu.eflags.OF=1; else cpu.eflags.OF=0; print_asm("or" str(SUFFIX) " 0x%x,%%%s",imm,REG_NAME(0)); return 1+DATA_BYTE; } #include "exec/template-end.h"
859485de1c3935309202f94bff403b90547ba598
142c86e4ec14ad0eebc6b21f3afbcc75d2f48be7
/srcs/ft_cast_map.c
668d8b78e6cdcc90bfbb28c1f1638a8dd08ca6ac
[]
no_license
lede-ser/bsq
ca9b23f22ca935960f1328df033a7927c86e7391
938a60cd0bb6694fd5143be8e9c6c572c53c825d
refs/heads/master
2016-09-12T16:29:32.275558
2016-04-25T11:28:37
2016-04-25T11:28:37
57,036,283
0
0
null
null
null
null
UTF-8
C
false
false
2,069
c
ft_cast_map.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_cast_map.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: lede-ser <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/09/22 15:45:39 by lede-ser #+# #+# */ /* Updated: 2015/09/24 21:45:27 by lede-ser ### ########.fr */ /* */ /* ************************************************************************** */ #include "bsq.h" void ft_save_biggest(int value, int h, int w, t_sqm *sqm) { sqm->h = h; sqm->w = w; sqm->size = value; } int ft_find_square(t_sqm *sqm, int w, int h, int **imap) { int ret; if (h >= 1 && w >= 1) { if (IMAPTL <= IMAPTR && IMAPTL <= IMAPBL) ret = (IMAPTL + 1); else if (IMAPTR <= IMAPTL && IMAPTR <= IMAPBL) ret = (IMAPTR + 1); else ret = (IMAPBL + 1); } else ret = 1; if (ret > sqm->size) ft_save_biggest(ret, h, w, sqm); return (ret); } int ft_get_biggest(t_sqm *sqm, t_mi minfo, int **imap, char **map) { int w; int h; h = 0; while (h < minfo.height) { w = 0; imap[h] = (int*)malloc(sizeof(int) * (minfo.width)); while (w < minfo.width) { if (map[h][w] != minfo.params[0] && map[h][w] != minfo.params[1]) { return (0); } imap[h][w] = (map[h][w] == minfo.params[1]) ? 0 : ft_find_square(sqm, w, h, imap); w++; } h++; } return (1); } t_sqm *ft_cast_map(t_mi minfo, char **map) { int **imap; t_sqm *sqm; imap = (int**)malloc(sizeof(int*) * (minfo.height)); sqm = (t_sqm *)malloc(sizeof(t_sqm)); if (ft_get_biggest(sqm, minfo, imap, map)) return (sqm); return (NULL); }
9112e53da2dfd727bfa50710b1b82f79f3560bc5
f25847541dd3dd87d42d78eba81a351b72a4d0af
/avbsf/src/avpbs.c
1f85bcda8df5b3ade1bd0e70a2c25540ae18850d
[ "MIT" ]
permissive
ireader/avcodec
a287e7905560d889e930e7a04865317fa00ef9cc
f3142ef12b5987d2f4c33ac3f073074798adf131
refs/heads/master
2023-09-05T16:56:48.006399
2023-08-26T10:35:48
2023-08-26T10:35:48
66,046,851
162
108
MIT
2023-02-03T10:32:36
2016-08-19T02:40:48
C
UTF-8
C
false
false
2,549
c
avpbs.c
#include "avpbs.h" #include <stdlib.h> #include <string.h> #include <assert.h> #include <errno.h> static struct avpbs_t* avpbs_common(void); struct avpbs_t* avpbs_h264(void); struct avpbs_t* avpbs_h265(void); struct avpbs_t* avpbs_h266(void); struct avpbs_t* avpbs_av1(void); struct avpbs_t* avpbs_vpx(void); struct avpbs_t* avpbs_aac(void); struct avpbs_t* avpbs_mp3(void); struct avpbs_t* avpbs_opus(void); struct avpbs_t* avpbs_g7xx(void); struct avpbs_t* avpbs_find(AVPACKET_CODEC_ID codec) { switch (codec) { // video case AVCODEC_VIDEO_H264: return avpbs_h264(); case AVCODEC_VIDEO_H265: return avpbs_h265(); case AVCODEC_VIDEO_H266: return avpbs_h266(); case AVCODEC_VIDEO_AV1: return avpbs_av1(); case AVCODEC_VIDEO_VP8: case AVCODEC_VIDEO_VP9: return avpbs_vpx(); // audio case AVCODEC_AUDIO_AAC: return avpbs_aac(); case AVCODEC_AUDIO_MP3: return avpbs_mp3(); case AVCODEC_AUDIO_OPUS: return avpbs_opus(); case AVCODEC_AUDIO_G711A: case AVCODEC_AUDIO_G711U: case AVCODEC_AUDIO_G726: case AVCODEC_AUDIO_G729: return avpbs_g7xx(); default: return avpbs_common(); } } struct avpbs_common_t { struct avstream_t* stream; avpbs_onpacket onpacket; void* param; }; static int avpbs_common_destroy(void** pp) { struct avpbs_common_t* bs; if (pp && *pp) { bs = (struct avpbs_common_t*)*pp; avstream_release(bs->stream); free(bs); *pp = NULL; } return 0; } static void* avpbs_common_create(int stream, AVPACKET_CODEC_ID codec, const uint8_t* extra, int bytes, avpbs_onpacket onpacket, void* param) { struct avpbs_common_t* bs; bs = calloc(1, sizeof(*bs)); if (!bs) return NULL; bs->stream = avstream_alloc(bytes); if (bs->stream) { bs->stream->stream = stream; bs->stream->codecid = codec; memcpy(bs->stream->extra, extra, bytes); } bs->onpacket = onpacket; bs->param = param; return bs; } static int avpbs_common_input(void* param, int64_t pts, int64_t dts, const uint8_t* data, int bytes, int flags) { int r; struct avpacket_t* pkt; struct avpbs_common_t* bs; bs = (struct avpbs_common_t*)param; pkt = avpacket_alloc(bytes); if (!pkt) return -(__ERROR__ + ENOMEM); memcpy(pkt->data, data, bytes); pkt->pts = pts; pkt->dts = dts; pkt->flags = flags; pkt->stream = bs->stream; avstream_addref(bs->stream); r = bs->onpacket(bs->param, pkt); avpacket_release(pkt); return r; } static struct avpbs_t* avpbs_common(void) { static struct avpbs_t bs = { avpbs_common_create, avpbs_common_destroy, avpbs_common_input, }; return &bs; }
c40fba440fb4e86095982ab048f4c0505382df84
44fe521ffd8f2b717aa25597720d5d18fb070ae6
/implementation/sources/hal/controller/controller.c
59336db5adcf405e42a6f4cc1a59eee85901d161
[]
no_license
gkolotelo/Embedded-Systems
064c579e70da0e93b5384a847bd743361f36c4b6
a081f9733595506a2b2843a5be3e5ec0f9c117e3
refs/heads/master
2021-01-20T17:19:50.275911
2016-06-29T15:43:20
2016-06-29T15:43:20
62,154,543
0
0
null
null
null
null
UTF-8
C
false
false
3,281
c
controller.c
/** * * File name: controller.c * File description: File containing the methods implementing * a PID controller. * * Authors: Bruno de Souza Ferreira * Guilherme Kairalla Kolotelo * Guilherme Bersi Pereira * * Creation date: 20Jun2016 * Revision date: 20Jun2016 * */ /* System includes */ #include <stdlib.h> /* Project includes */ #include "controller.h" /** * Method name: controller_initPID * Method description: Initializes the t_PID_Data with safe values * Input params: pidData = t_PID_Data struct * Output params: n/a */ void controller_initPID(t_PID_Data *pidData) { pidData->dKp = 0; pidData->dKi = 0; pidData->dKd = 0; pidData->dSensorPreviousValue = 0; pidData->dErrorSum = 0; pidData->dMaxSumError = 0; } /** * Method name: controller_setMaxSumError * Method description: Sets the maximum integrative error * Input params: pidData = t_PID_Data struct * dMaxError = Maximum error acceptable * Output params: n/a */ void controller_setMaxSumError(t_PID_Data *pidData, double dMaxSumError) { pidData->dMaxSumError = dMaxSumError; } /** * Method name: controller_setKp * Method description: Sets the Kp * Input params: pidData = t_PID_Data struct * dPGain = Proportional constant * Output params: n/a */ void controller_setKp(t_PID_Data *pidData, double dPGain) { pidData->dKp = dPGain; } /** * Method name: controller_setKi * Method description: Sets the Ki * Input params: pidData = t_PID_Data struct * dIGain = Integrative constant * Output params: n/a */ void controller_setKi(t_PID_Data *pidData, double dIGain) { pidData->dKi = dIGain; } /** * Method name: controller_setKd * Method description: Sets the Kd * Input params: pidData = t_PID_Data struct * dDGain = Derivative constant * Output params: n/a */ void controller_setKd(t_PID_Data *pidData, double dDGain) { pidData->dKd = dDGain; } /** * Method name: controller_PIDUpdate * Method description: Updates the running controller and retrieves the actuation value * Input params: pidData = t_PID_Data struct * dSensorValue = Value from sensor * dReferenceValue = Reference value * Output params: double = Actuation value */ double controller_PIDUpdate(t_PID_Data *pidData, double dSensorValue, double dReferenceValue) { if(dReferenceValue < 20) return 0; double dPterm, dIterm, dDterm; double dError, dDifference, dItemp; dError = dReferenceValue - dSensorValue; /* Proportional */ dPterm = pidData->dKp * dError; /* Integrative */ dItemp = pidData->dErrorSum + dError; if(abs(dItemp) < pidData->dMaxSumError) pidData->dErrorSum = dItemp; dIterm = pidData->dKi * pidData->dErrorSum; /* Derivative */ dDifference = pidData->dSensorPreviousValue - dSensorValue; pidData->dSensorPreviousValue = dSensorValue; dDterm = pidData->dKd * dDifference; return (dPterm + dIterm + dDterm); }
392abd0e96d02a7da8c0127304fb5fa34931da59
2ad3069984c4862f7a3a7d0890e54d388351811e
/Userland/SampleCodeModule/apps/chessConsole.c
d870df8fddb94a6fbf59ba3d1652fe3ea39f19d1
[]
no_license
guidommogni/TP2SO
b9569de3e3c8d31ba00886b24db901b120de6cc9
8b7f7964f0fd8d1e2056084d5ab1db8f306adfc8
refs/heads/main
2023-05-07T03:11:18.327797
2021-05-18T14:23:07
2021-05-18T14:23:07
369,917,222
0
0
null
2021-05-22T22:28:47
2021-05-22T22:28:47
null
UTF-8
C
false
false
2,582
c
chessConsole.c
/** * chessConsole.c: Driver consola */ #include <chessConsole.h> typedef struct { int x; int y; } t_currentPos; static t_currentPos currentPos; static char log[LAST_LINE][7]; static int playerOrder[LAST_LINE]; int currentSize = 0; /** * Imprime en una posicion y color determinado de la pantalla, * luego retorna a su posicion original. */ void printIn(char *string, int x, int y, int color) { int aux_x = currentPos.x; _setCursor(x, y,BLACK); printWithColor(string, color); _setCursor(aux_x, LAST_LINE,BLACK); } void initializeCursor() { _setCursor(0, LAST_LINE,BLACK); currentPos.x = 10; currentPos.y = LAST_LINE; } void initializeLog(){ currentSize = 0; } // Imprime una linea nueva de comando en el log void printLogLine(char *move, int player) { clearLine(LAST_LINE); addMoveToLog(move, player); printEntireLog(); } void printPlayer(int number, int line) { char *aux; switch (number) { case PLAYER1: aux = "Player 1: "; break; case PLAYER2: aux = "Player 2: "; break; default: break; } printIn(aux, 0, line, GREEN); } void clearLine(int y) { char toDraw[] = "X"; for (int i = 0; i < MAX_WIDTH / CHAR_WIDTH - CHAR_WIDTH; i++) { _drawFigure(toDraw, BLACK, CHAR_HEIGHT, getHorizontalPixelPosition(i), getVerticalPixelPosition(y)); } } int getVerticalPixelPosition(int value) { return CHAR_HEIGHT * value; } int getHorizontalPixelPosition(int value) { return CHAR_WIDTH * value; } // Se agrega un nuevo movimiento al log. void addMoveToLog(char *move, int player) { memcpy(log[currentSize], move, 6); playerOrder[currentSize++] = player; } // Se mueven todos los log una posicion para "arriba" eliminando al primer log ingresado. // Esto se hace para el estilo de scroll up. void updateTimerConsole(int time) { char aux[30]; uintToBase(time, aux, 10); printIn(aux, (MAX_WIDTH/CHAR_WIDTH) + 5, LAST_LINE, YELLOW); } void displayChar(char c) { putChar(c); if (c == '\b') { currentPos.x-=1; }else{ currentPos.x+=1; } } void printEntireLog(){ for(int i = 0; i<currentSize; i++){ char aux1[2]; uintToBase(playerOrder[currentSize - 1 - i], aux1, 10); printIn(aux1, 0, LAST_LINE - i -1 , GREEN); printIn(log[currentSize-1-i], 5, LAST_LINE - i -1, WHITE); // Imprime el movimiento. } resetCursor(); } void resetCursor(){ _setCursor(10, LAST_LINE,BLACK); currentPos.x = 10; currentPos.y = LAST_LINE; }
452734463d5d22a07eeb8fc83cbdc221d1cf0e7a
6dad975a21e75a9d75789c5cc809afb2de0942cc
/plugin_source/ccnxtlv_Name.c
785a4fd3fa387b58736ecb93f68c4e61b4dc8af6
[]
no_license
mmosko/ccnxWireshark
76535640a2d13f6fcf44c05208338c5a8d9a0a37
4b16a3a4578152d52410a0a53b407cc708280206
refs/heads/master
2020-05-04T02:48:30.327999
2016-04-05T19:49:51
2016-04-05T19:49:51
null
0
0
null
null
null
null
UTF-8
C
false
false
5,367
c
ccnxtlv_Name.c
/* ccnxtlv_UnknownTlv.h * Definitions for CCNx packet disassembly structures and routines * By Marc Mosko <marc.mosko@parc.com> * Copyright 2013,2014,2015,2016 Palo Alto Research Center * * Wireshark - Network traffic analyzer * By Gerald Combs <gerald@wireshark.org> * Copyright 1998 Gerald Combs * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ /** * This is not a dissector. It is common code to print an Name TLV. The user * must pass an initialized Header Field id to use for the formatting. * * This module is not auto-scanned for a protocol registration. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "moduleinfo.h" #include <glib.h> #include <ctype.h> #include <epan/packet.h> #include <epan/dissectors/packet-tcp.h> #include <epan/prefs.h> #include <epan/etypes.h> #include "packet-ccnxtlv.h" #include "ccnxtlv_Name.h" #include "ccnxtlv_v1_types.h" /** * The name component pointed to at (tvb_offset + inputOffset) should be printed as a * human-readable name component. It will be printed in ASCII with URI escapes. * * The name component will be appended to the char buffer "output" beginning at location * "outputOffset". * * Returns the new outputOffset */ static guint ccnxtlvName_PrintName(tvbuff_t *tvb, unsigned tvb_offset, guint inputOffset, guint end, char *output, guint outputOffset, guint outputLength) { while (inputOffset < end) { guint8 c = tvb_get_guint8(tvb, tvb_offset + inputOffset); if( isprint(c) ) { // g_printf("%s: char %02x print\n", __func__, c); outputOffset += g_snprintf(output + outputOffset, outputLength - outputOffset, "%c", c); } else { // g_printf("%s: char %02x escape\n", __func__, c); outputOffset += g_snprintf(output + outputOffset, outputLength - outputOffset, "%%%02x", c); } inputOffset++; } return outputOffset; } /** * The name component pointed to at (tvb_offset + inputOffset) should be printed as a * binary name component. It will be displayed as a HEX string. * * The name component will be appended to the char buffer "output" beginning at location * "outputOffset". * * Returns the new outputOffset */ static guint ccnxtlvName_PrintHex(tvbuff_t *tvb, unsigned tvb_offset, guint inputOffset, guint end, char *output, guint outputOffset, guint outputLength) { while (inputOffset < end) { guint8 c = tvb_get_guint8(tvb, tvb_offset + inputOffset); // g_printf("%s: char %02x escape\n", __func__, c); outputOffset += g_snprintf(output + outputOffset, outputLength - outputOffset, "%02x", c); inputOffset++; } return outputOffset; } /** * The buffer pointed to by tvb at offset tvb_offset is a CCNx Name TLV value. * It is a series of TLVs that each encapsulate a Name Segment. The entire * value length is inputLength. * * This function will allocate an output buffer with malloc() and print the * URI representation of the Name. */ static char * ccnxtlvName_TlvToLci(tvbuff_t *tvb, guint tvb_offset, guint inputLength) { // this should be more than enough without needing to realloc guint outputLength = inputLength * 10; guint outputOffset = 0; guint inputOffset = 0; char * output = g_malloc(outputLength); memset(output, 0, outputLength); outputOffset += g_snprintf(output + outputOffset, outputLength - outputOffset, "ccnx:"); while( inputOffset < inputLength ) { guint16 tlv_type = tvb_get_ntohs(tvb, tvb_offset + inputOffset); guint16 tlv_length = tvb_get_ntohs(tvb, tvb_offset + inputOffset + 2); inputOffset += 4; // g_printf("%s: tlv_type = %04x tlv_length = %u\n", __func__, tlv_type, tlv_length); g_assert(inputOffset + tlv_length <= inputLength); outputOffset += g_snprintf(output + outputOffset, outputLength - outputOffset, "/0x%x=", tlv_type); guint end = inputOffset + tlv_length; switch(tlv_type) { case V1_NAME_NAME: outputOffset = ccnxtlvName_PrintName(tvb, tvb_offset, inputOffset, end, output, outputOffset, outputLength); break; default: outputOffset = ccnxtlvName_PrintHex(tvb, tvb_offset, inputOffset, end, output, outputOffset, outputLength); break; } inputOffset += tlv_length; } return output; } guint ccnxtlvName_Dissect(tvbuff_t *tvb, guint headerfield, proto_tree *tree, guint offset, guint16 tlv_type, guint16 tlv_length) { if (tree) { char * nameString = ccnxtlvName_TlvToLci(tvb, offset, tlv_length); // proto_tree_add_string_format_value(tree, ccnxtlv_GetNameHeaderField(), tvb, offset, tlv_length, // "", "Type 0x%04x Length %u Value %s", // tlv_type, tlv_length, nameString); proto_tree_add_string_format_value(tree, headerfield, tvb, offset, tlv_length, "", "%s", nameString); g_free(nameString); } return tlv_length; }
fe9611c37b22b57d555022a7a7cb28e36a6da25e
2d576d7b69376b18d09e4fc574ec282ab7d5860c
/clib_sunred/data/rbbst_init_template.c
43bbde4b2e01a4d031cdf075a4a59cdf292d59ab
[]
no_license
cutxyz/BananaOS
beb04f46eaf3cdcd3a153aa5508e29d520fc3ee5
76441791ee789671775392d30cc7d9ea28d95718
refs/heads/master
2021-01-10T13:17:06.144346
2015-10-05T12:49:03
2015-10-05T12:49:03
43,681,851
0
0
null
null
null
null
UTF-8
C
false
false
2,960
c
rbbst_init_template.c
////////////////////////////////////// // rbbst_init_template.h // Created on: 2015-5-9 // Author: 李镇城 ( cut / cutxyz) // e-mail: cut-12345@hotmail.com / 501931049@qq.com ///////////////////////////////////// #include "rbbstnode_define_declare.h" #include "bst_init_template.c" #ifndef copy_rbbst_color_unsafe static SR_INLINE void __copy_tree_color( tree_node_ptr PARAM_INOUT dec_node_ptr, const tree_node_ptr PARAM_IN src_node_ptr) { set_tree_color(dec_node_ptr, get_tree_color(src_node_ptr)); } #define copy_rbbst_color_unsafe __copy_tree_color #endif //copy_rbbst_color_unsafe #ifndef rbbst_left_rotate_unsafe static SR_INLINE void __rbt_left_rotate ( tree_node_ptr* PARAM_INOUT root_node_ptrptr, tree_node_ptr PARAM_IN sentinel_node_ptr, tree_node_ptr PARAM_INOUT node_ptr) { tree_node_ptr temp_node_ptr; tree_node_ptr tmp_letf_node_ptr; tree_node_ptr tmp_parent_node_ptr; temp_node_ptr = get_tree_right(node_ptr); tmp_letf_node_ptr = get_tree_left(temp_node_ptr); set_tree_right(node_ptr, tmp_letf_node_ptr); if (tmp_letf_node_ptr != sentinel_node_ptr) { set_tree_parent(tmp_letf_node_ptr, node_ptr); } tmp_parent_node_ptr = get_tree_parent(node_ptr); set_tree_parent(temp_node_ptr, tmp_parent_node_ptr); if (node_ptr == *root_node_ptrptr) { *root_node_ptrptr = temp_node_ptr; } else { if (get_tree_left(tmp_parent_node_ptr) == node_ptr) { set_tree_left(tmp_parent_node_ptr, temp_node_ptr); } else { set_tree_right(tmp_parent_node_ptr, temp_node_ptr); } } set_tree_left (temp_node_ptr, node_ptr); set_tree_parent(node_ptr, temp_node_ptr); } #define rbbst_left_rotate_unsafe __rbt_left_rotate #endif //rbbst_left_rotate_unsafe #ifndef rbbst_right_rotate_unsafe static SR_INLINE void __rbt_right_rotate ( tree_node_ptr* PARAM_INOUT root_node_ptrptr, tree_node_ptr PARAM_IN sentinel_node_ptr, tree_node_ptr PARAM_INOUT node_ptr) { tree_node_ptr temp_node_ptr; tree_node_ptr temp_right_node_ptr; tree_node_ptr tmp_parent_node_ptr; temp_node_ptr = get_tree_left(node_ptr); temp_right_node_ptr = get_tree_right(temp_node_ptr); set_tree_right(node_ptr, temp_right_node_ptr); if (temp_right_node_ptr != sentinel_node_ptr) { set_tree_parent(temp_right_node_ptr, node_ptr); } tmp_parent_node_ptr = get_tree_parent(node_ptr); set_tree_parent(temp_node_ptr, tmp_parent_node_ptr); if (node_ptr == *root_node_ptrptr) { *root_node_ptrptr = temp_node_ptr; } else { if (get_tree_right(tmp_parent_node_ptr) == node_ptr) { set_tree_right(tmp_parent_node_ptr, temp_node_ptr); } else { set_tree_left(tmp_parent_node_ptr, temp_node_ptr); } } set_tree_right(temp_node_ptr, node_ptr); set_tree_parent(node_ptr, temp_node_ptr); } #define rbbst_right_rotate_unsafe __rbt_right_rotate #endif //rbbst_right_rotate_unsafe
91752c9fd18bf7e2970c8691f95e178b45d8f45d
602e0f4bae605f59d23688cab5ad10c21fc5a34f
/MyToolKit/OwspClient/owsp_def.h
fcf6a61a1cb7f785309cc9c04feaf70436b3a9c4
[]
no_license
yanbcxf/cpp
d7f26056d51f85254ae1dd2c4e8e459cfefb2fb6
e059b02e7f1509918bbc346c555d42e8d06f4b8f
refs/heads/master
2023-08-04T04:40:43.475657
2023-08-01T14:03:44
2023-08-01T14:03:44
172,408,660
8
5
null
null
null
null
GB18030
C
false
false
23,400
h
owsp_def.h
/* * Version 3.5 * Time: 20090226 */ #ifndef __LVSP_DEF_H_INCLUDED__ #define __LVSP_DEF_H_INCLUDED__ #define STR_LEN_32 32 #define STR_LEN_16 16 #define MAX_TLV_LEN 65535 //最大TLV长为(64K-1) //版本信息 #define VERSION_MAJOR 3 #define VERSION_MINOR 8 // // 如果已经定义 // #ifndef u_int32 typedef unsigned long u_int32; typedef unsigned short u_int16; typedef unsigned char u_int8; #endif #pragma pack(push) #pragma pack(4) #ifndef WAVE_FORMAT_PCM #define WAVE_FORMAT_PCM 0x0001 #endif #ifndef WAVE_FORMAT_MPEGLAYER3 #define WAVE_FORMAT_MPEGLAYER3 0x0055 // ISO/MPEG Layer 3 格式标记 #endif #ifndef WAVE_FORMAT_QUALCOMM_PUREVOICE #define WAVE_FORMAT_QUALCOMM_PUREVOICE 0x0150 #endif //AMR_NB CBR wave format #ifndef WAVE_FORMAT_AMR_CBR #define WAVE_FORMAT_AMR_CBR 0x7A21 #endif //AMR VBR Not support yet #ifndef WAVE_FORMAT_AMR_VBR #define WAVE_FORMAT_AMR_VBR 0x7A22 #endif //AMR_WB Wave format #ifndef WAVE_FORMAT_VOICEAGE_AMR_WB #define WAVE_FORMAT_VOICEAGE_AMR_WB 0xA104 #endif #define CODEC_H264 0x34363248 //H264 #define CODEC_H265 0x35363248 //H265 /* TLV 类型命令字 */ #define TLV_T_VERSION_INFO_ANSWER 39 #define TLV_T_VERSION_INFO_REQUEST 40 #define TLV_T_LOGIN_REQUEST 41 #define TLV_T_LOGIN_ANSWER 42 #define TLV_T_TOTAL_CHANNEL 43 //NOT USED #define TLV_T_SENDDATA_REQUEST 44 //通道请求 #define TLV_T_SENDDATA_ANSWER 45 //通道请求应答 #define TLV_T_TOTAL_CHANEL_ANSWER 46 //Not used #define TLV_T_SUSPENDSENDDATA_REQUEST 47 //停止发送数据 #define TLV_T_SUSPENDSENDDATA_ANSWER 48 #define TLV_T_DEVICE_KEEP_ALIVE 49 //心跳包 #define TLV_T_DEVICE_FORCE_EXIT 50 #define TLV_T_CONTROL_REQUEST 51 //云台等控制请求 #define TLV_T_CONTROL_ANSWER 52 //云台等响应 #define TLV_T_RECORD_REQUEST 53 //录像请求 #define TLV_T_RECORD_ANSWER 54 #define TLV_T_DEVICE_SETTING_REQUEST 55 //设备参数设置请求 #define TLV_T_DEVICE_SETTING_ANSWER 56 //设备参数设置应答 #define TLV_T_KEEP_ALIVE_ANSWER 57 //心跳包响应 #define TLV_T_DEVICE_RESET 58 //通知设备重启 #define TLV_T_DEVICE_RESET_ANSWER 59 //设备接收到重启命令后的响应,通常不用发出 #define TLV_T_ALERT_REQUEST 60 //报警请求,由设备发出 #define TLV_T_ALERT_ANSWER 61 //报警请求回应,由服务器发出,通常可以不用发出 #define TLV_T_ALERT_SEND_PHOTO 62 //报警后,设备采集当时的图片,发送到服务器 #define TLV_T_ALERT_SEND_PHOTO_ANSWER 63 //设备发送MSG_CMD_ALERT_SEND_PHOTO后,服务器的回应 #define TLV_T_CHANNLE_REQUEST 64 //切换到另一通道 #define TLV_T_CHANNLE_ANSWER 65 //切换另一通道应答 #define TLV_T_SUSPEND_CHANNLE_REQUEST 66 //挂起某一通道 #define TLV_T_SUSPEND_CHANNLE_ANSWER 67 //应答 #define TLV_T_VALIDATE_REQUEST 68 //程序验证请求 #define TLV_T_VALIDATE_ANSWER 69 //应答 #define TLV_T_DVS_INFO_REQUEST 70 //设备DVS通知连接方设备信息请求 #define TLV_T_DVS_INFO_ANSWER 71 // #define TLV_T_PHONE_INFO_REQUEST 72 //手机通知连接方手机信息请求 #define TLV_T_PHONE_INFO_ANSWER 73 // //vod & live #define TLV_T_AUDIO_INFO 0x61 //97 音频信息, 表示V为音频信息 #define TLV_T_AUDIO_DATA 0x62 //98 音频数据, 表示V为音频数据 #define TLV_T_VIDEO_FRAME_INFO 0x63 //99 视频帧信息, 表示V的数据描述帧信息 #define TLV_T_VIDEO_IFRAME_DATA 0x64 //100 视频关键帧数据,表示V的数据为关键帧 #define TLV_T_VIDEO_PFRAME_DATA 0x66 //102 视频P帧(参考帧)数据, 表示V的数据为参考帧 #define TLV_T_VIDEO_FRAME_INFO_EX 0x65 //101 扩展视频帧信息支持>=64KB的视频帧 #define TLV_T_STREAM_FORMAT_INFO 200 // 流格式信息 ,描述视频属性,音频属性 //vod #define TLV_T_STREAM_FILE_INDEX 213 #define TLV_T_STREAM_FILE_ATTRIBUTE 214 #define TLV_T_STREAM_FILE_END 0x0000FFFF // 对于 owsp_def.h ,以下补充定义 owsp 协议的命令类型 #define TLV_T_DISCONNECT 220 #define TLV_T_SAY_BYE 221 // 录像回放 2015-9-7 #define TLV_T_SEARCH_RECORD_REQ 0x014d // 录像查询请求 #define TLV_T_SEARCH_RECORD_RSP 0x014e // 搜索录像文件应答 #define TLV_T_RECORD_INFO 0x014f // 录像文件信息 #define TLV_T_PLAY_RECORD_REQ 0x0150 // 录像回放请求 #define TLV_T_PLAY_RECORD_RSP 0x0151 // 录像回放应答 /* response result */ #define _RESPONSECODE_SUCC 0x01 // 成功 #define _RESPONSECODE_USER_PWD_ERROR 0x02 // 用户名或密码错 #define _RESPONSECODE_PDA_VERSION_ERROR 0x04 // 版本不一致 #define _RESPONSECODE_MAX_USER_ERROR 0x05 #define _RESPONSECODE_DEVICE_OFFLINE 0x06 // 设备已经离线 #define _RESPONSECODE_DEVICE_HAS_EXIST 0x07 // 设备已经存在 #define _RESPONSECODE_DEVICE_OVERLOAD 0x08 // 设备性能超载(设备忙) #define _RESPONSECODE_INVALID_CHANNLE 0x09 // 设备不支持的通道 #define _RESPONSECODE_PROTOCOL_ERROR 0X0A //协议解析出错 #define _RESPONSECODE_NOT_START_ENCODE 0X0B //未启动编码 #define _RESPONSECODE_TASK_DISPOSE_ERROR 0X0C //任务处理过程出错 //云台控制码,取值范围为0~255 typedef enum _OWSP_ACTIONCode { OWSP_ACTION_MD_STOP = 0, // 停止运动 OWSP_ACTION_ZOOMReduce=5, OWSP_ACTION_ZOOMADD=6, OWSP_ACTION_FOCUSADD=7, //焦距 OWSP_ACTION_FOCUSReduce=8, OWSP_ACTION_MD_UP=9, // 向上 OWSP_ACTION_MD_DOWN=10, // 向下 OWSP_ACTION_MD_LEFT=11, // 向左 OWSP_ACTION_MD_RIGHT=12, // 向右 OWSP_ACTION_Circle_Add = 13, //光圈 OWSP_ACTION_Circle_Reduce = 14, // OWSP_ACTION_AUTO_CRUISE = 15, //自动巡航 OWSP_ACTION_GOTO_PRESET_POSITION = 16, //跳转预置位 OWSP_ACTION_SET_PRESET_POSITION = 17, //设置预置位点 OWSP_ACTION_CLEAR_PRESET_POSITION = 18, //清除预置位点 OWSP_ACTION_ACTION_RESET = 20, OWSP_ACTION_MD_LEFT_UP=21, // 向上 OWSP_ACTION_MD_LEFT_DOWN=22, // 向下 OWSP_ACTION_MD_RIGHT_UP=23, // 向左 OWSP_ACTION_MD_RIGHT_DOWN=24, // 向右 OWSP_ACTION_TV_SWITCH = 128, //切换视频源,消息参数为INT*,1--TV, 2--SV,3--CV1, 4--CV2 OWSP_ACTION_TV_TUNER = 129, //切换频道, 消息参数为INT*, 为频道号 OWSP_ACTION_TV_SET_QUALITY = 130, //画质设置, 亮度,色度,饱和度,对比度结构体 } OWSP_ACTIONCode; //报警种类,目前只支持探头报警,也就是ATC_INFRARED typedef enum _AlertTypeCode { ATC_VIDEO = 0,//视频帧预测 ATC_DEVICE_SERSTART = 1, /* 设备启动 */ ATC_MOTION = 2, /* 移动侦测报警 */ ATC_VIDEOLOST = 3, /* 视频丢失报警 */ ATC_DISKFULL = 4, /* 硬盘满报警 */ ATC_HIDEALARM=5, /* 视频遮挡报警 */ ATC_STOP = 6, /* 服务器停止 */ ATC_SDERROR = 7, /* SD卡异常*/ ATC_INFRARED = 20 //开关量探头(比如红外探头) }AlertTypeCode; //报警级别,主要针对帧预测,开光量探头报警时该值统一为0,目前只支持探头报警,当触发报警时,发送报警级别ALC_ALERT,当报警停止时,发送ALC_STOP typedef enum _AlertLevelCode { ALC_ALERT = 0,//报警,警报级别最高,通常用户开关量探头 ALC_LEVEL1 = 10,//1级警告,AlertLevelCode的值越大,警告级别越低 ALC_STOP = 255//报警停止,发送停止信息 }AlertLevelCode; //码流类型 2015-9-7 typedef enum _OWSP_StreamType { OWSP_STREAM_MAIN = 0, //请求主码流 OWSP_STREAM_SUB = 1, //请求次码流1 OWSP_STREAM_SUB1 = 2, //请求次码流2 OWSP_STREAM_VOD = 3, //请求录像文件 OWSP_MODE_SETTING = 4 //远程配置模式, } OWSP_StreamType; //数据类型 typedef enum _OWSP_StreamDataType { OWSP_VIDEO_DATA = 0, // video data only OWSP_AUDIO_DATA = 1, // audio data only OWSP_MIXED_DATA = 2 // video & audio data } OWSP_StreamDataType; // 播放控制命令 typedef enum _OWSP_PlayCommand { PlayCommandStart = 1, //播放 PlayCommandPause = 2, //暂停 PlayCommandResume = 3, //继续 PlayCommandStop = 4 //停止 } OWSP_PlayCommand; /* the common packet header, must be placed in front of any packets. */ typedef struct _OwspPacketHeader { u_int32 packet_length; //length of the following packet, donot include this header u_int32 packet_seq; //packet sequence 包序号,每发送一个包就自增 } OwspPacketHeader; ///////////////////////////////////////////////////////////////////////// //For TLV ////////////////////////////////////////////////////////////////////////// struct _TLV_Header { u_int16 tlv_type; u_int16 tlv_len; }; //__attribute ((packed)); typedef struct _TLV_Header TLV_HEADER; /* version info: remote -> streaming server. No response need */ // TLV_T: TLV_T_VERSION_INFO_ANSWER // TLV_L: sizeof(TLV_V_VersionInfoRequest) typedef struct _TLV_V_VersionInfoRequest { u_int16 versionMajor; // major version u_int16 versionMinor; // minor version }TLV_V_VersionInfoRequest; // TLV_T: TLV_T_VERSION_INFO_ANSWER // TLV_L: sizeof(TLV_V_VersionInfoResponse) typedef struct _TLV_V_VersionInfoResponse { u_int16 result; //result of login request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; }TLV_V_VersionInfoResponse; /* login request: remote -> streaming server */ typedef struct _TLV_V_LoginRequest { char userName[STR_LEN_32]; //用户名, 后面不足部分为数字0 (为ASCII字符串) char password[STR_LEN_16]; //密码, 后面不足部分为数字0 (为ASCII字符串) u_int32 deviceId; //设备ID. CS模式下由服务器统一分配, P2P模式下为固定值 u_int8 flag; //should be set to 1 to be compatible with the previous version. u_int8 channel; //channel //u_int8 reserve[2]; u_int8 streamMode; u_int8 dataType; } TLV_V_LoginRequest; /* login response, streaming server -> remote */ typedef struct _TLV_V_LoginResponse { u_int16 result; //result of login request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; } TLV_V_LoginResponse; /* send data request, streaming server -> remote. * Now this command is ignored, the remote will send data to server actively and immidietely after logining.*/ typedef struct _TLV_V_SendDataRequest { u_int32 deviceId; //device id generating by the remote device u_int8 videoChannel; u_int8 audioChannel; u_int16 reserve; } TLV_V_SendDataRequest; /* send data response, remote -> streaming server */ typedef struct _TLV_V_SendDataResponse { u_int16 result; //result of send data request u_int16 reserve; } TLV_V_SendDataResponse; /* suspend sending data request, streaming server -> remote */ typedef struct _TLV_V_SuspendSendDataRequest { u_int32 deviceId; //device id generating by the remote device u_int8 videoChannel; u_int8 audioChannel; u_int16 reserve; } TLV_V_SuspendSendDataRequest; /* suspend sending data response, remote -> streaming server */ typedef struct _TLV_V_SuspendSendDataResponse { u_int16 result; //result of send data request u_int16 reserve; } TLV_V_SuspendSendDataResponse; /* specify the format of video, this info is sent to server immidiately after StreamDataFormat*/ typedef struct _OWSP_VideoDataFormat { u_int32 codecId; //FOUR CC code,’H264’ u_int32 bitrate; //bps u_int16 width; //image widht u_int16 height; //image height u_int8 framerate; //fps u_int8 colorDepth; //should be 24 bits u_int16 reserve; } OWSP_VideoDataFormat; /* specify the format of audio, this info is sent to server immidiately after StreamDataFormat or VideoDataFormat*/ typedef struct _OWSP_AudioDataFormat { u_int32 samplesPerSecond; //samples per second u_int32 bitrate; //bps u_int16 waveFormat; //wave format, such as WAVE_FORMAT_PCM,WAVE_FORMAT_MPEGLAYER3 u_int16 channelNumber; //audio channel number u_int16 blockAlign; //block alignment defined by channelSize * (bitsSample/8) u_int16 bitsPerSample; //bits per sample u_int16 frameInterval; //interval between frames, in milliseconds u_int16 reserve; } OWSP_AudioDataFormat; /* this format should be sent to the server before any other stream data, Plus if any format of video/audio has changed, it should send this info to server at the first time. followed by VideoDataFormat/AudioDataFormat*/ typedef struct _TLV_V_StreamDataFormat { u_int8 videoChannel; //视频通道号 u_int8 audioChannel; //音频通道号 u_int8 dataType; //流数据类型, 取值见StreamDataType u_int8 reserve; //保留 OWSP_VideoDataFormat videoFormat; //视频格式 OWSP_AudioDataFormat audioFormat; //音频格式 } TLV_V_StreamDataFormat; /* 视频帧信息 TLV */ typedef struct _TLV_V_VideoFrameInfo { u_int8 channelId; //通道ID u_int8 reserve; //备用 u_int16 checksum; //校验和.目前为0未用 u_int32 frameIndex; //视频帧序号 u_int32 time; //时间戳. } TLV_V_VideoFrameInfo; //之后是视频数据TLV, V部分是视频编码后的Raw Data. /* 扩展视频帧信息 TLV, 当视频数据>64K时使用 */ typedef struct _TLV_V_VideoFrameInfoEx { u_int8 channelId; //通道ID u_int8 reserve; //备用 u_int16 checksum; //校验和.目前为0未用 u_int32 frameIndex; //视频帧序号 u_int32 time; //时间戳. u_int32 dataSize; //视频数据长度 } TLV_V_VideoFrameInfoEx; //之后是若干个视频数据TLV, V部分是视频编码后的Raw Data. /* 音频信息 TLV */ typedef struct _TLV_V_AudioInfo { u_int8 channelId; //channel id u_int8 reserve; //备用 u_int16 checksum; //checksum of audio data. u_int32 time; // specify the time when this audio data is created. } TLV_V_AudioInfo; //之后是音频数据TLV, V部分就是音频编码后的Raw Data. /* 扩展控制协议, 包括云台及TV控制 */ typedef struct _TLV_V_ControlRequest { u_int32 deviceId; // device id generating by the remote device u_int8 channel; // channel id u_int8 cmdCode; // 控制命令字,参见_PTZCode u_int16 size; // 控制参数数据长度,如果size==0 表示无控制参数 } TLV_V_ControlRequest; //u_int8 * data; //array of data followed. // size = sizeof(PTZArgData); //如果是上下左右,牵涉到速度的话,有水平速度arg1,垂直速度arg2; //如果是预置位的话,操作第几个预制位使用arg1标明 //如果是清除预置位,操作第几个预置位使用arg1标明,如果0xffffffff表示清除全部 //如果是自动巡航,arg1=1表示启动,0表示停止 typedef struct _ControlArgData { u_int32 arg1; u_int32 arg2; u_int32 arg3; u_int32 arg4; } ControlArgData; /* 云台请求响应 */ typedef struct _TLV_V_ControlResponse { u_int16 result; //result of login request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; } TLV_V_ControlResponse; /* 通道请求协议 Streaming server -> Device */ typedef struct _TLV_V_ChannelRequest { u_int32 deviceId; u_int8 sourceChannel; //源通道ID u_int8 destChannel; //切换的目的通道ID u_int8 reserve[2]; } TLV_V_ChannelRequest; /* 通道请求响应 Device -> Streaming server message: MSG_CMD_CHANNEL_RESPONSE */ typedef struct _TLV_V_ChannelResponse { u_int16 result; //result of request. _RESPONSECODE_SUCC - succeeded, others - failed u_int8 currentChannel; //如果不支持的通道,则返回当前通道号 u_int8 reserve; } TLV_V_ChannelResponse; /* 通道挂起协议 Streaming server -> Device message: MSG_CMD_CHANNEL_SUSPEND */ typedef struct _TLV_V_ChannelSuspendRequest { u_int8 channelId; //Chanel id u_int8 reserve[3]; } TLV_V_ChannelSuspendRequest; /* 通道挂起响应 Device -> Streaming server message: MSG_CMD_SUSPEND_RESPONSE */ typedef struct _TLV_V_ChannelSuspendResponse { u_int16 result; //result of request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; } TLV_V_ChannelSuspendResponse; /* 心跳包 Device -> Streaming server message: MSG_CMD_DEVICE_KEEP_ALIVE */ typedef struct _TLV_V_KeepAliveRequest { u_int8 channelID; //Channel id u_int8 reserve[3]; } TLV_V_KeepAliveRequest; /* 心跳包响应 Streaming server -> Device message: MSG_CMD_KEEP_ALIVE_ANSWER */ typedef struct _TLV_V_KeepAliveResponse { u_int16 result; //result of request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; } TLV_V_KeepAliveResponse; /* 扩展报警协议,设备发到服务器 */ typedef struct _TLV_V_AlertRequest { u_int32 deviceId; // device id generating by the remote device u_int8 channelId; // channel id u_int8 alertType; // 报警种类,参见 _AlertTypeCode u_int8 alertLevel; // 报警级别,参见 _AlertLevelCode u_int8 reserve; //保留 u_int8 localTime[14]; //报警时本地时间字符串,格式为yyyymmddhhmmss,如"20080919132059"代表2008年9月19日13点20分59秒,时间精度为秒 u_int16 size; // array of data size followed,default = 0 } TLV_V_AlertRequest; /* 报警请求响应,服务器发送到设备 */ typedef struct _TLV_V_AlertResponse { u_int16 result; //result of login request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; } TLV_V_AlertResponse; /* 日期定义 */ typedef struct _OWSP_DATE { u_int16 m_year; //年,2009 u_int8 m_month; //月,1-12 u_int8 m_day; //日,1-31 }OWSP_DATE; /* 时间定义 */ typedef struct _OWSP_TIME { u_int8 m_hour; //0-24 u_int8 m_minute; //0-59 u_int8 m_second; //0-59 u_int16 m_microsecond; //毫秒 0-1000 }OWSP_TIME; /* DVS报告设备信息 */ typedef struct _TLV_V_DVSInfoRequest { char companyIdentity[STR_LEN_16]; //公司识别码,最多16个字符,后面不足部分为数字0 (为ASCII字符串) char equipmentIdentity[STR_LEN_16]; //设备识别码,本字段中为DVS的物理地址,即MAC地址,后面不足部分为数字0 (为ASCII字符串) char equipmentName[STR_LEN_16]; //设备名称,最多16个字符,后面不足部分为数字0 (为ASCII字符串) char equipmentVersion[STR_LEN_16]; //设备的软件版本,最多16个字符, 后面不足部分为数字0 (为ASCII字符串) OWSP_DATE equipmentDate; //设备的出厂日期20090120 u_int8 channleNumber; //设备支持多少个通道 u_int8 reserve1; //保留 u_int8 reserve2; //保留 u_int8 reserve3; //保留 } TLV_V_DVSInfoRequest; /* DVS报告设备信息应答 */ typedef struct _TLV_V_DVSInfoResponse { u_int16 result; //result of login request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; } TLV_V_DVSInfoResponse; /* 手机报告设备信息 */ typedef struct _TLV_V_PhoneInfoRequest { u_int8 equipmentIdentity[STR_LEN_16]; //设备识别码,本字段中为DVS的物理地址,即MAC地址 u_int8 equipmentOS[STR_LEN_16]; //手机的操作系统 u_int8 reserve1; //保留 u_int8 reserve2; //保留 u_int8 reserve3; //保留 u_int8 reserve4; //保留 } TLV_V_PhoneInfoRequest; /* 手机报告设备信息应答 */ typedef struct _TLV_V_PhoneInfoResponse { u_int16 result; //result of login request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; } TLV_V_PhoneInfoResponse; ///////////////////////////////////////////////////////////////////////// //For TLV ////////////////////////////////////////////////////////////////////////// struct _TLV { u_int16 tlv_type; u_int16 tlv_len; u_int8 tlv_data[0]; }; // __attribute ((packed)) typedef struct _TLV TLV; #define FILEFLAG "DSV" ////////////////////////////////////////////////////////////////////////// //For vod streaming only Keyframe ////////////////////////////////////////////////////////////////////////// typedef struct _TLV_V_FileAttributeData { u_int32 totalframes; u_int32 totaltimes; }TLV_V_FileAttributeData; typedef struct _TLV_V_StreamIndexDataHeader { u_int32 count; // u_int32 reserve; //在文件 u_int32 datasize; // }TLV_V_StreamIndexDataHeader; typedef struct _TLV_V_StreamIndexData { u_int32 timestamp; u_int32 pos; //在文件 }TLV_V_StreamIndexData; typedef struct _TLV_V_StreamEndData { u_int32 timestamp; u_int16 result; //result of request. _RESPONSECODE_SUCC - succeeded, others - failed u_int16 reserve; } TLV_V_StreamEndData; typedef struct _TLV_V_StreamFileDataHeader { u_int32 timestamp; }TLV_V_StreamFileDataHeader; #pragma pack(pop) ////////////////////////////////////////////////////////////////////////// // 2015-9-7 录像文件回放 ////////////////////////////////////////////////////////////////////////// #pragma pack(push) #pragma pack(1) typedef struct _OWSP_DateTime { u_int16 m_year; //年,2009 u_int8 m_month; //月,1-12 u_int8 m_day; //日,1-31 u_int8 m_hour; //0-24 u_int8 m_minute; //0-59 u_int8 m_second; //0-59 } OWSP_DateTime; typedef struct _TLV_V_SearchRecordRequest { u_int32 deviceId; //设备编号(默认为0) u_int8 channel; //通道号 u_int8 recordTypeMask; //录像类型掩码 0x01 = 开关量告警录像, 0x02 = 移动侦测录像, 0x04 = 定时录像, 0x08 = 手动录像 u_int8 count; //返回最大记录个数 OWSP_DateTime startTime; //查询起始时间 OWSP_DateTime endTime; //查询终止时间 u_int8 reserve[3]; } TLV_V_SearchRecordRequest; typedef struct _TLV_V_SearchRecordResponse { u_int8 result; //结果 u_int8 count; //查询结果记录数 u_int8 reserve; } TLV_V_SearchRecordResponse; typedef struct _TLV_V_RecordInfo { u_int32 deviceId; OWSP_DateTime startTime; OWSP_DateTime endTime; u_int8 channel; u_int8 recordTypeMask; //录像类型掩码 0x01 = 开关量告警录像, 0x02 = 移动侦测录像, 0x04 = 定时录像, 0x08 = 手动录像; u_int8 reserve[2]; } TLV_V_RecordInfo; typedef struct _TLV_V_PlayRecordRequest { u_int32 deviceId; OWSP_DateTime startTime; //暂停、继续、停止命令无效 u_int8 channel; u_int8 command; //回放控制命令 u_int8 reserve; } TLV_V_PlayRecordRequest; typedef struct _TLV_V_PlayRecordResponse { u_int8 result; u_int8 reserve; } TLV_V_PlayRecordResponse; #pragma pack(pop) #endif
8460665b304d6f49c3ef935321b71dfca8a03ee7
6b229123ff20286119648c611fe8643b18c08bfe
/processor.c
5e2c3226476efa86faae13dd6ebb71b703e79748
[]
no_license
NikhilNar/IPC
7ad7da0a7a07969926115c7110642703267f3dff
36f74fd1b7b77e2c824b42c49bf8a2fa6660afe7
refs/heads/master
2020-08-14T09:31:51.014789
2019-12-03T04:27:56
2019-12-03T04:27:56
215,141,752
0
0
null
null
null
null
UTF-8
C
false
false
2,408
c
processor.c
#include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #define MEMSIZE 27 main() { int shmid; key_t key; char *shm, *s, *copy, *copy1; FILE *fPtr; // name of the shared memory segment key = 75678; // create secrets.out file fPtr = fopen("secrets.out", "w"); if (fPtr == NULL) { /* File not created hence exit */ printf("Unable to create file.\n"); exit(1); } /* * Find the segment. */ if ((shmid = shmget(key, MEMSIZE, 0777)) < 0) { perror("shmget"); exit(1); } // Attach the segment to the data space. if ((shm = shmat(shmid, NULL, 0)) == (char *)-1) { perror("shmat"); exit(1); } /* * Continue reading the secret code from the shared memory. * End the program if the word exit occurs in the message. * The file should be closed to persist the data on the file. * The problem is if I close the file inside the while loop then it will override the * previous data. Hence the mechanism of exit keyword is added to close the program and persist * the secret codes successfully in the file secrets.out */ while (1) { if (*shm != '*') { char charArray[1]; int noOfDigits = 0; char digitsToChar[10]; char message[100]; int j = 0; for (s = shm; *s != NULL; s++) { if (isdigit(*s)) noOfDigits++; message[j++] = *s; } message[j] = '\0'; printf("Message entered =%s\n", message); if (strstr(message, "exit")) { break; } // write secret code and no of digits in the secrets.out file. fputs(message, fPtr); charArray[0] = ' '; fputs(charArray, fPtr); sprintf(digitsToChar, "%d", noOfDigits); fputs(digitsToChar, fPtr); sprintf(digitsToChar, "%s", ""); charArray[0] = '\n'; fputs(charArray, fPtr); // Send the acknowledgement to the receiver that the message is read // by setting the shared memory to "*" *shm = '*'; } } fclose(fPtr); exit(0); }
3354802a2e64bf02de3bf5d857aa7618e437e4d5
1ab5dca795a138947801af5d382fce7db56ce8f2
/native/egl_render.h
5d37c783ec9dc176a663e640dd2e4f41cef66126
[]
no_license
deganii/ids
4fb1e912ea10a4bac63257850fb7f8cca8e5e02e
c3e6111abe44a72eb3665f0b756818cabc2e5974
refs/heads/master
2020-06-01T06:43:00.297435
2019-08-02T01:18:19
2019-08-02T01:18:19
190,683,406
0
0
null
null
null
null
UTF-8
C
false
false
383
h
egl_render.h
// // Created by idegani on 7/12/2019. // #ifndef IDS_EGL_RENDER_H #define IDS_EGL_RENDER_H #include "display.h" #include "app.h" #ifdef __cplusplus extern "C" { #endif int egl_component_init(display_state *disp_state); void egl_render_buffer(void *rgbBuffer, int len); void egl_component_deinit(display_state *disp_state); #ifdef __cplusplus } #endif #endif //IDS_EGL_RENDER_H
af62bd8e5afb0f3a1b201ff3d5c85ec4fd03eaad
e228071b1e5c385ce9bdf9110df7d657be7a6586
/src/asn/rrc/ASN_RRC_asn_constant.h
668ffda1c1e8dd508e901e743ddfd2fa02ec9a91
[ "LicenseRef-scancode-proprietary-license", "GPL-3.0-only" ]
permissive
anhtrung87vn/ue-ran-sim
cfd6138fcac498923ec602b27e3c73f53aacb371
cca07a8cd8da5a945e105a60377143eaa78be95d
refs/heads/master
2023-04-29T01:32:04.592375
2023-03-20T17:25:23
2023-03-20T17:25:23
278,814,429
0
0
MIT
2020-07-11T07:47:15
2020-07-11T07:47:14
null
UTF-8
C
false
false
15,994
h
ASN_RRC_asn_constant.h
/* * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) */ #ifndef _ASN_RRC_ASN_CONSTANT_H #define _ASN_RRC_ASN_CONSTANT_H #ifdef __cplusplus extern "C" { #endif #define min_val_ASN_RRC_AdditionalSpectrumEmission (0) #define max_val_ASN_RRC_AdditionalSpectrumEmission (7) #define min_val_ASN_RRC_ARFCN_ValueEUTRA (0) #define max_val_ASN_RRC_ARFCN_ValueEUTRA (262143) #define min_val_ASN_RRC_ARFCN_ValueNR (0) #define max_val_ASN_RRC_ARFCN_ValueNR (3279165) #define min_val_ASN_RRC_BWP_Id (0) #define max_val_ASN_RRC_BWP_Id (4) #define min_val_ASN_RRC_CellGroupId (0) #define max_val_ASN_RRC_CellGroupId (3) #define min_val_ASN_RRC_CellReselectionPriority (0) #define max_val_ASN_RRC_CellReselectionPriority (7) #define min_val_ASN_RRC_ControlResourceSetId (0) #define max_val_ASN_RRC_ControlResourceSetId (11) #define min_val_ASN_RRC_ControlResourceSetZero (0) #define max_val_ASN_RRC_ControlResourceSetZero (15) #define min_val_ASN_RRC_CSI_IM_ResourceId (0) #define max_val_ASN_RRC_CSI_IM_ResourceId (31) #define min_val_ASN_RRC_CSI_IM_ResourceSetId (0) #define max_val_ASN_RRC_CSI_IM_ResourceSetId (63) #define min_val_ASN_RRC_PortIndex8 (0) #define max_val_ASN_RRC_PortIndex8 (7) #define min_val_ASN_RRC_PortIndex4 (0) #define max_val_ASN_RRC_PortIndex4 (3) #define min_val_ASN_RRC_PortIndex2 (0) #define max_val_ASN_RRC_PortIndex2 (1) #define min_val_ASN_RRC_CSI_ReportConfigId (0) #define max_val_ASN_RRC_CSI_ReportConfigId (47) #define min_val_ASN_RRC_CSI_ResourceConfigId (0) #define max_val_ASN_RRC_CSI_ResourceConfigId (111) #define min_val_ASN_RRC_CSI_RS_Index (0) #define max_val_ASN_RRC_CSI_RS_Index (95) #define min_val_ASN_RRC_CSI_SSB_ResourceSetId (0) #define max_val_ASN_RRC_CSI_SSB_ResourceSetId (63) #define min_val_ASN_RRC_DRB_Identity (1) #define max_val_ASN_RRC_DRB_Identity (32) #define min_val_ASN_RRC_FreqBandIndicatorNR (1) #define max_val_ASN_RRC_FreqBandIndicatorNR (1024) #define min_val_ASN_RRC_Hysteresis (0) #define max_val_ASN_RRC_Hysteresis (30) #define min_val_ASN_RRC_LogicalChannelIdentity (1) #define max_val_ASN_RRC_LogicalChannelIdentity (32) #define min_val_ASN_RRC_MeasId (1) #define max_val_ASN_RRC_MeasId (64) #define min_val_ASN_RRC_EUTRA_CellIndex (1) #define max_val_ASN_RRC_EUTRA_CellIndex (32) #define min_val_ASN_RRC_MeasObjectId (1) #define max_val_ASN_RRC_MeasObjectId (64) #define min_val_ASN_RRC_NextHopChainingCount (0) #define max_val_ASN_RRC_NextHopChainingCount (7) #define min_val_ASN_RRC_NZP_CSI_RS_ResourceId (0) #define max_val_ASN_RRC_NZP_CSI_RS_ResourceId (191) #define min_val_ASN_RRC_NZP_CSI_RS_ResourceSetId (0) #define max_val_ASN_RRC_NZP_CSI_RS_ResourceSetId (63) #define min_val_ASN_RRC_P_Max (-30) #define max_val_ASN_RRC_P_Max (33) #define min_val_ASN_RRC_PCI_RangeIndex (1) #define max_val_ASN_RRC_PCI_RangeIndex (8) #define min_val_ASN_RRC_PhysCellId (0) #define max_val_ASN_RRC_PhysCellId (1007) #define min_val_ASN_RRC_PDCCH_BlindDetection (1) #define max_val_ASN_RRC_PDCCH_BlindDetection (15) #define min_val_ASN_RRC_MCC_MNC_Digit (0) #define max_val_ASN_RRC_MCC_MNC_Digit (9) #define min_val_ASN_RRC_PRB_Id (0) #define max_val_ASN_RRC_PRB_Id (274) #define min_val_ASN_RRC_PUCCH_ResourceSetId (0) #define max_val_ASN_RRC_PUCCH_ResourceSetId (3) #define min_val_ASN_RRC_PUCCH_ResourceId (0) #define max_val_ASN_RRC_PUCCH_ResourceId (127) #define min_val_ASN_RRC_PUCCH_PathlossReferenceRS_Id (0) #define max_val_ASN_RRC_PUCCH_PathlossReferenceRS_Id (3) #define min_val_ASN_RRC_P0_PUCCH_Id (1) #define max_val_ASN_RRC_P0_PUCCH_Id (8) #define min_val_ASN_RRC_PUCCH_SpatialRelationInfoId (1) #define max_val_ASN_RRC_PUCCH_SpatialRelationInfoId (8) #define min_val_ASN_RRC_P0_PUSCH_AlphaSetId (0) #define max_val_ASN_RRC_P0_PUSCH_AlphaSetId (29) #define min_val_ASN_RRC_PUSCH_PathlossReferenceRS_Id (0) #define max_val_ASN_RRC_PUSCH_PathlossReferenceRS_Id (3) #define min_val_ASN_RRC_SRI_PUSCH_PowerControlId (0) #define max_val_ASN_RRC_SRI_PUSCH_PowerControlId (15) #define min_val_ASN_RRC_Q_QualMin (-43) #define max_val_ASN_RRC_Q_QualMin (-12) #define min_val_ASN_RRC_Q_RxLevMin (-70) #define max_val_ASN_RRC_Q_RxLevMin (-22) #define min_val_ASN_RRC_RadioLinkMonitoringRS_Id (0) #define max_val_ASN_RRC_RadioLinkMonitoringRS_Id (9) #define min_val_ASN_RRC_RAN_AreaCode (0) #define max_val_ASN_RRC_RAN_AreaCode (255) #define min_val_ASN_RRC_RateMatchPatternId (0) #define max_val_ASN_RRC_RateMatchPatternId (3) #define min_val_ASN_RRC_RejectWaitTime (1) #define max_val_ASN_RRC_RejectWaitTime (16) #define min_val_ASN_RRC_ReportConfigId (1) #define max_val_ASN_RRC_ReportConfigId (64) #define min_val_ASN_RRC_RSRP_RangeEUTRA (0) #define max_val_ASN_RRC_RSRP_RangeEUTRA (97) #define min_val_ASN_RRC_RSRQ_RangeEUTRA (0) #define max_val_ASN_RRC_RSRQ_RangeEUTRA (34) #define min_val_ASN_RRC_SINR_RangeEUTRA (0) #define max_val_ASN_RRC_SINR_RangeEUTRA (127) #define min_val_ASN_RRC_ReselectionThreshold (0) #define max_val_ASN_RRC_ReselectionThreshold (31) #define min_val_ASN_RRC_ReselectionThresholdQ (0) #define max_val_ASN_RRC_ReselectionThresholdQ (31) #define min_val_ASN_RRC_RNTI_Value (0) #define max_val_ASN_RRC_RNTI_Value (65535) #define min_val_ASN_RRC_RSRP_Range (0) #define max_val_ASN_RRC_RSRP_Range (127) #define min_val_ASN_RRC_RSRQ_Range (0) #define max_val_ASN_RRC_RSRQ_Range (127) #define min_val_ASN_RRC_SCellIndex (1) #define max_val_ASN_RRC_SCellIndex (31) #define min_val_ASN_RRC_SchedulingRequestId (0) #define max_val_ASN_RRC_SchedulingRequestId (7) #define min_val_ASN_RRC_SchedulingRequestResourceId (1) #define max_val_ASN_RRC_SchedulingRequestResourceId (8) #define min_val_ASN_RRC_ScramblingId (0) #define max_val_ASN_RRC_ScramblingId (1023) #define min_val_ASN_RRC_QFI (0) #define max_val_ASN_RRC_QFI (63) #define min_val_ASN_RRC_PDU_SessionID (0) #define max_val_ASN_RRC_PDU_SessionID (255) #define min_val_ASN_RRC_SearchSpaceId (0) #define max_val_ASN_RRC_SearchSpaceId (39) #define min_val_ASN_RRC_SearchSpaceZero (0) #define max_val_ASN_RRC_SearchSpaceZero (15) #define min_val_ASN_RRC_ServCellIndex (0) #define max_val_ASN_RRC_ServCellIndex (31) #define min_val_ASN_RRC_SINR_Range (0) #define max_val_ASN_RRC_SINR_Range (127) #define min_val_ASN_RRC_SK_Counter (0) #define max_val_ASN_RRC_SK_Counter (65535) #define min_val_ASN_RRC_SlotFormatCombinationId (0) #define max_val_ASN_RRC_SlotFormatCombinationId (511) #define min_val_ASN_RRC_SRB_Identity (1) #define max_val_ASN_RRC_SRB_Identity (3) #define min_val_ASN_RRC_SRS_ResourceSetId (0) #define max_val_ASN_RRC_SRS_ResourceSetId (15) #define min_val_ASN_RRC_SRS_ResourceId (0) #define max_val_ASN_RRC_SRS_ResourceId (63) #define min_val_ASN_RRC_SSB_Index (0) #define max_val_ASN_RRC_SSB_Index (63) #define min_val_ASN_RRC_TAG_Id (0) #define max_val_ASN_RRC_TAG_Id (3) #define min_val_ASN_RRC_TCI_StateId (0) #define max_val_ASN_RRC_TCI_StateId (127) #define min_val_ASN_RRC_TDD_UL_DL_SlotIndex (0) #define max_val_ASN_RRC_TDD_UL_DL_SlotIndex (319) #define min_val_ASN_RRC_T_Reselection (0) #define max_val_ASN_RRC_T_Reselection (7) #define min_val_ASN_RRC_UAC_BarringInfoSetIndex (1) #define max_val_ASN_RRC_UAC_BarringInfoSetIndex (8) #define min_val_ASN_RRC_ZP_CSI_RS_ResourceId (0) #define max_val_ASN_RRC_ZP_CSI_RS_ResourceId (31) #define min_val_ASN_RRC_ZP_CSI_RS_ResourceSetId (0) #define max_val_ASN_RRC_ZP_CSI_RS_ResourceSetId (15) #define min_val_ASN_RRC_FeatureSetCombinationId (0) #define max_val_ASN_RRC_FeatureSetCombinationId (1024) #define min_val_ASN_RRC_FeatureSetDownlinkId (0) #define max_val_ASN_RRC_FeatureSetDownlinkId (1024) #define min_val_ASN_RRC_FeatureSetDownlinkPerCC_Id (1) #define max_val_ASN_RRC_FeatureSetDownlinkPerCC_Id (1024) #define min_val_ASN_RRC_FeatureSetEUTRA_DownlinkId (0) #define max_val_ASN_RRC_FeatureSetEUTRA_DownlinkId (256) #define min_val_ASN_RRC_FeatureSetEUTRA_UplinkId (0) #define max_val_ASN_RRC_FeatureSetEUTRA_UplinkId (256) #define min_val_ASN_RRC_FeatureSetUplinkId (0) #define max_val_ASN_RRC_FeatureSetUplinkId (1024) #define min_val_ASN_RRC_FeatureSetUplinkPerCC_Id (1) #define max_val_ASN_RRC_FeatureSetUplinkPerCC_Id (1024) #define min_val_ASN_RRC_FreqBandIndicatorEUTRA (1) #define max_val_ASN_RRC_FreqBandIndicatorEUTRA (256) #define min_val_ASN_RRC_NumberOfCarriers (1) #define max_val_ASN_RRC_NumberOfCarriers (16) #define min_val_ASN_RRC_EUTRA_PhysCellId (0) #define max_val_ASN_RRC_EUTRA_PhysCellId (503) #define min_val_ASN_RRC_RRC_TransactionIdentifier (0) #define max_val_ASN_RRC_RRC_TransactionIdentifier (3) #define ASN_RRC_maxBandComb (65536) #define ASN_RRC_maxCellBlack (16) #define ASN_RRC_maxCellInter (16) #define ASN_RRC_maxCellIntra (16) #define ASN_RRC_maxCellMeasEUTRA (32) #define ASN_RRC_maxEARFCN (262143) #define ASN_RRC_maxEUTRA_CellBlack (16) #define ASN_RRC_maxEUTRA_NS_Pmax (8) #define ASN_RRC_maxMultiBands (8) #define ASN_RRC_maxNARFCN (3279165) #define ASN_RRC_maxNR_NS_Pmax (8) #define ASN_RRC_maxNrofServingCells (32) #define ASN_RRC_maxNrofServingCells_1 (31) #define ASN_RRC_maxNrofAggregatedCellsPerCellGroup (16) #define ASN_RRC_maxNrofSCells (31) #define ASN_RRC_maxNrofCellMeas (32) #define ASN_RRC_maxNrofSS_BlocksToAverage (16) #define ASN_RRC_maxNrofCSI_RS_ResourcesToAverage (16) #define ASN_RRC_maxNrofDL_Allocations (16) #define ASN_RRC_maxNrofSR_ConfigPerCellGroup (8) #define ASN_RRC_maxLCG_ID (7) #define ASN_RRC_maxLC_ID (32) #define ASN_RRC_maxNrofTAGs (4) #define ASN_RRC_maxNrofTAGs_1 (3) #define ASN_RRC_maxNrofBWPs (4) #define ASN_RRC_maxNrofCombIDC (128) #define ASN_RRC_maxNrofSymbols_1 (13) #define ASN_RRC_maxNrofSlots (320) #define ASN_RRC_maxNrofSlots_1 (319) #define ASN_RRC_maxNrofPhysicalResourceBlocks (275) #define ASN_RRC_maxNrofPhysicalResourceBlocks_1 (274) #define ASN_RRC_maxNrofPhysicalResourceBlocksPlus1 (276) #define ASN_RRC_maxNrofControlResourceSets_1 (11) #define ASN_RRC_maxCoReSetDuration (3) #define ASN_RRC_maxNrofSearchSpaces_1 (39) #define ASN_RRC_maxSFI_DCI_PayloadSize (128) #define ASN_RRC_maxSFI_DCI_PayloadSize_1 (127) #define ASN_RRC_maxINT_DCI_PayloadSize (126) #define ASN_RRC_maxINT_DCI_PayloadSize_1 (125) #define ASN_RRC_maxNrofRateMatchPatterns (4) #define ASN_RRC_maxNrofRateMatchPatterns_1 (3) #define ASN_RRC_maxNrofRateMatchPatternsPerGroup (8) #define ASN_RRC_maxNrofCSI_ReportConfigurations (48) #define ASN_RRC_maxNrofCSI_ReportConfigurations_1 (47) #define ASN_RRC_maxNrofCSI_ResourceConfigurations (112) #define ASN_RRC_maxNrofCSI_ResourceConfigurations_1 (111) #define ASN_RRC_maxNrofAP_CSI_RS_ResourcesPerSet (16) #define ASN_RRC_maxNrOfCSI_AperiodicTriggers (128) #define ASN_RRC_maxNrofReportConfigPerAperiodicTrigger (16) #define ASN_RRC_maxNrofNZP_CSI_RS_Resources (192) #define ASN_RRC_maxNrofNZP_CSI_RS_Resources_1 (191) #define ASN_RRC_maxNrofNZP_CSI_RS_ResourcesPerSet (64) #define ASN_RRC_maxNrofNZP_CSI_RS_ResourceSets (64) #define ASN_RRC_maxNrofNZP_CSI_RS_ResourceSets_1 (63) #define ASN_RRC_maxNrofNZP_CSI_RS_ResourceSetsPerConfig (16) #define ASN_RRC_maxNrofNZP_CSI_RS_ResourcesPerConfig (128) #define ASN_RRC_maxNrofZP_CSI_RS_Resources (32) #define ASN_RRC_maxNrofZP_CSI_RS_Resources_1 (31) #define ASN_RRC_maxNrofZP_CSI_RS_ResourceSets_1 (15) #define ASN_RRC_maxNrofZP_CSI_RS_ResourcesPerSet (16) #define ASN_RRC_maxNrofZP_CSI_RS_ResourceSets (16) #define ASN_RRC_maxNrofCSI_IM_Resources (32) #define ASN_RRC_maxNrofCSI_IM_Resources_1 (31) #define ASN_RRC_maxNrofCSI_IM_ResourcesPerSet (8) #define ASN_RRC_maxNrofCSI_IM_ResourceSets (64) #define ASN_RRC_maxNrofCSI_IM_ResourceSets_1 (63) #define ASN_RRC_maxNrofCSI_IM_ResourceSetsPerConfig (16) #define ASN_RRC_maxNrofCSI_SSB_ResourcePerSet (64) #define ASN_RRC_maxNrofCSI_SSB_ResourceSets (64) #define ASN_RRC_maxNrofCSI_SSB_ResourceSets_1 (63) #define ASN_RRC_maxNrofCSI_SSB_ResourceSetsPerConfig (1) #define ASN_RRC_maxNrofFailureDetectionResources (10) #define ASN_RRC_maxNrofFailureDetectionResources_1 (9) #define ASN_RRC_maxNrofObjectId (64) #define ASN_RRC_maxNrofPageRec (32) #define ASN_RRC_maxNrofPCI_Ranges (8) #define ASN_RRC_maxPLMN (12) #define ASN_RRC_maxNrofCSI_RS_ResourcesRRM (96) #define ASN_RRC_maxNrofCSI_RS_ResourcesRRM_1 (95) #define ASN_RRC_maxNrofMeasId (64) #define ASN_RRC_maxNrofQuantityConfig (2) #define ASN_RRC_maxNrofCSI_RS_CellsRRM (96) #define ASN_RRC_maxNrofSRS_ResourceSets (16) #define ASN_RRC_maxNrofSRS_ResourceSets_1 (15) #define ASN_RRC_maxNrofSRS_Resources (64) #define ASN_RRC_maxNrofSRS_Resources_1 (63) #define ASN_RRC_maxNrofSRS_ResourcesPerSet (16) #define ASN_RRC_maxNrofSRS_TriggerStates_1 (3) #define ASN_RRC_maxNrofSRS_TriggerStates_2 (2) #define ASN_RRC_maxRAT_CapabilityContainers (8) #define ASN_RRC_maxSimultaneousBands (32) #define ASN_RRC_maxNrofSlotFormatCombinationsPerSet (512) #define ASN_RRC_maxNrofSlotFormatCombinationsPerSet_1 (511) #define ASN_RRC_maxNrofPUCCH_Resources (128) #define ASN_RRC_maxNrofPUCCH_Resources_1 (127) #define ASN_RRC_maxNrofPUCCH_ResourceSets (4) #define ASN_RRC_maxNrofPUCCH_ResourceSets_1 (3) #define ASN_RRC_maxNrofPUCCH_ResourcesPerSet (32) #define ASN_RRC_maxNrofPUCCH_P0_PerSet (8) #define ASN_RRC_maxNrofPUCCH_PathlossReferenceRSs (4) #define ASN_RRC_maxNrofPUCCH_PathlossReferenceRSs_1 (3) #define ASN_RRC_maxNrofP0_PUSCH_AlphaSets (30) #define ASN_RRC_maxNrofP0_PUSCH_AlphaSets_1 (29) #define ASN_RRC_maxNrofPUSCH_PathlossReferenceRSs (4) #define ASN_RRC_maxNrofPUSCH_PathlossReferenceRSs_1 (3) #define ASN_RRC_maxNrofNAICS_Entries (8) #define ASN_RRC_maxBands (1024) #define ASN_RRC_maxBandsMRDC (1280) #define ASN_RRC_maxBandsEUTRA (256) #define ASN_RRC_maxCellReport (8) #define ASN_RRC_maxDRB (29) #define ASN_RRC_maxFreq (8) #define ASN_RRC_maxFreqIDC_MRDC (32) #define ASN_RRC_maxNrofCandidateBeams (16) #define ASN_RRC_maxNrofPCIsPerSMTC (64) #define ASN_RRC_maxNrofQFIs (64) #define ASN_RRC_maxNrOfSemiPersistentPUSCH_Triggers (64) #define ASN_RRC_maxNrofSR_Resources (8) #define ASN_RRC_maxNrofSlotFormatsPerCombination (256) #define ASN_RRC_maxNrofSpatialRelationInfos (8) #define ASN_RRC_maxNrofIndexesToReport (32) #define ASN_RRC_maxNrofIndexesToReport2 (64) #define ASN_RRC_maxNrofSSBs_1 (63) #define ASN_RRC_maxNrofS_NSSAI (8) #define ASN_RRC_maxNrofTCI_StatesPDCCH (64) #define ASN_RRC_maxNrofTCI_States (128) #define ASN_RRC_maxNrofTCI_States_1 (127) #define ASN_RRC_maxNrofUL_Allocations (16) #define ASN_RRC_maxQFI (63) #define ASN_RRC_maxRA_CSIRS_Resources (96) #define ASN_RRC_maxRA_OccasionsPerCSIRS (64) #define ASN_RRC_maxRA_Occasions_1 (511) #define ASN_RRC_maxRA_SSB_Resources (64) #define ASN_RRC_maxSCSs (5) #define ASN_RRC_maxSecondaryCellGroups (3) #define ASN_RRC_maxNrofServingCellsEUTRA (32) #define ASN_RRC_maxMBSFN_Allocations (8) #define ASN_RRC_maxNrofMultiBands (8) #define ASN_RRC_maxCellSFTD (3) #define ASN_RRC_maxReportConfigId (64) #define ASN_RRC_maxNrofCodebooks (16) #define ASN_RRC_maxNrofCSI_RS_Resources (7) #define ASN_RRC_maxNrofSRI_PUSCH_Mappings (16) #define ASN_RRC_maxNrofSRI_PUSCH_Mappings_1 (15) #define ASN_RRC_maxSIB (32) #define ASN_RRC_maxSI_Message (32) #define ASN_RRC_maxPO_perPF (4) #define ASN_RRC_maxAccessCat_1 (63) #define ASN_RRC_maxBarringInfoSet (8) #define ASN_RRC_maxCellEUTRA (8) #define ASN_RRC_maxEUTRA_Carrier (8) #define ASN_RRC_maxPLMNIdentities (8) #define ASN_RRC_maxDownlinkFeatureSets (1024) #define ASN_RRC_maxUplinkFeatureSets (1024) #define ASN_RRC_maxEUTRA_DL_FeatureSets (256) #define ASN_RRC_maxEUTRA_UL_FeatureSets (256) #define ASN_RRC_maxFeatureSetsPerBand (128) #define ASN_RRC_maxPerCC_FeatureSets (1024) #define ASN_RRC_maxFeatureSetCombinations (1024) #define ASN_RRC_maxInterRAT_RSTD_Freq (3) #define min_val_ASN_RRC_BandCombinationIndex (1) #define max_val_ASN_RRC_BandCombinationIndex (65536) #define min_val_ASN_RRC_BandEntryIndex (0) #define max_val_ASN_RRC_BandEntryIndex (32) #define min_val_ASN_RRC_FeatureSetEntryIndex (1) #define max_val_ASN_RRC_FeatureSetEntryIndex (128) #define ASN_RRC_maxMeasFreqsMN (32) #define ASN_RRC_maxMeasFreqsSN (32) #define ASN_RRC_maxMeasIdentitiesMN (62) #define ASN_RRC_maxCellPrep (32) #ifdef __cplusplus } #endif #endif /* _ASN_RRC_ASN_CONSTANT_H */
0fb14e4b4d28996d4081709e2c5520ecff7c6bcb
206e8af08fec4c5333740b9d2744c6a425fb5a18
/srcs/frame.c
95cddb7b4ecf4aedac277fda1b59bd05cd5f160c
[]
no_license
NATHAN76543217/fract-ol
23e63fbe8cb5fcb465318de8ffd7e4f1cb2f7317
948c633fe957f39dc9dee1b956a5f1fac527e778
refs/heads/master
2021-02-07T01:41:56.363832
2020-03-02T19:18:13
2020-03-02T19:18:13
243,968,810
0
0
null
null
null
null
UTF-8
C
false
false
1,770
c
frame.c
#include "fractol.h" int draw(t_data *data, t_coord point, int color) { int val; // val = rgb_int(0, (color * 2 > 256) ? 256 : (color * 2), (color * 3 > 256) ? 256 : (color * 3), (color * 4 > 256) ? 256 : (color * 4)); val = rgb_int(0, 200, color * 10,color *5); *(int *)(data->image.add_image + (point.y * data->image.size_line) + point.x*sizeof(int)) = (color != 0) ? val : 0; return (0); } int computing(t_data *data, t_f_complex z0, t_coord point) { t_f_complex z; t_f_complex c; int i; float module; int nb_iter = 150; float tmp; i = 0; z = z0; c.re = 0.5; c.im = 0.9; while(i < nb_iter) { tmp = z.re; // z.re = z.re * z.re - z.im * z.im + c.re; // z.im = 2 * z.im * z.re + c.im; z = add_comp(mult_comp(z, z), c); module = (z.re * z.re + z.im * z.im); if (module >= 4) { draw(data, point, i); i = nb_iter; } i++; } if (i == nb_iter) draw(data, point, 0); return (0); } int frame(t_data *data) { t_coord point; t_f_complex coord; t_f_coord ratio; coord = (t_f_complex){.re = 0.0, .im = 0.0}; point = (t_coord){.y = 0, .x = 0}; ratio.x = 0.02 * ((float)200 / data->screen.x); ratio.y = 0.02 * ((float)200 / data->screen.y); while (point.x < data->screen.x) { coord.re = -1.5 + (ratio.x * point.x); while (point.y < data->screen.y) { coord.im = -1 + (ratio.y * point.y); computing(data, coord, point); point.y++; } point.y = 0; point.x++; } mlx_put_image_to_window(data->mlx.ptr, data->mlx.win, data->image.img, 0, 0); return (0); }
812ff4c30becb8a1245693c95949c27c2785e03f
0fde20a9fad07f041afb3bbc1c6ae00387d3250f
/TrabajoPracticoN1/main.c
81fa411e59edb240056d46f394cb242045a876c2
[]
no_license
EliasLeguizamon123/Entrega-de-Trabajos-Practicos
586398d5448557c960929871d96e4b26c8fab225
9d9df67491f3a9b6121124b3ef4f8860dc41c3d5
refs/heads/master
2021-01-20T05:10:44.249346
2017-04-29T02:34:24
2017-04-29T02:34:24
87,508,137
0
0
null
null
null
null
ISO-8859-1
C
false
false
1,265
c
main.c
/******************************************************************* * * Programa: ~ Calculadora | Trabajo Práctico N° 1. * * Alumno: Elias Leguizamón. * * Curso: 1F. * * Fecha de entrega: 06/04/2017. *******************************************************************/ #include <stdio.h> #include <stdlib.h> # include "milibreria.h" int main(void) { int numeroUno, numeroDos, opcion; int menuOperador; numeroUno= 0 ; numeroDos= 0 ; menu(numeroDos, numeroDos); do { switch(menuOperador) { case 1: numeroUno=operadorUno(); system("CLS"); menu(numeroUno, numeroDos); break; case 2: numeroDos=operadorDos(); system("CLS"); menu(numeroUno, numeroDos); break; } todas(opcion, numeroUno, numeroDos); printf("\n\n Opcion a elegir: "); scanf("%d",&menuOperador); system("CLS"); menu(numeroUno, numeroDos); }while(menuOperador!=9); return ; }
c65111966589a1041c1b08239011076f58a960ec
f720369e167889b8c65fb5c9f9ded80a8378a200
/src/test/video/include/video.h
d120b9e5f4b38a37097dcb241e3f2b0003c04ded
[ "BSD-3-Clause" ]
permissive
eugenecartwright/hthreads
1aa2af6838738ad49376511333a7b546ba47fa86
826c495dd855f8fcc1e12e1ac01845c2983ecf04
refs/heads/master
2020-04-06T07:00:23.582279
2016-11-27T02:47:34
2016-11-27T02:47:34
50,606,707
3
0
null
null
null
null
UTF-8
C
false
false
62
h
video.h
#ifndef _VIDEO_H_ #define _VIDEO_H_ #include <vga.h> #endif
a1717a5e558c5ebf76e310f85c04552d547ffc5f
983c67221ac7aa6d88265aea36e0731d962cf5c5
/lib/mnl/mcs.c
952a135cf29c57e2478a991d5c32ed82ab1d7ab0
[]
no_license
bigml/mbase
dadc0a9a4637489fe61460954bfcb0411bfe1725
1b6082f6f3fac4cbfb4e7d530e9034f8342b25d9
refs/heads/master
2023-07-07T22:18:54.693965
2023-06-28T09:29:15
2023-06-28T09:29:15
23,647,250
0
1
null
null
null
null
UTF-8
C
false
false
22,848
c
mcs.c
#include "mheads.h" void* hash_lookupf(HASH *table, char *fmt, ...) { char key[LEN_HASH_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return hash_lookup(table, key); } NEOERR* hash_insertf(HASH *table, void *data, char *fmt, ...) { char key[LEN_HASH_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return hash_insert(table, strdup(key), data); } NEOERR* mcs_outputcb(void *ctx, char *s) { printf ("%s", s); return STATUS_OK; } NEOERR* mcs_strcb(void *ctx, char *s) { STRING *str = (STRING*)ctx; NEOERR *err; err = nerr_pass(string_append(str, s)); return err; } NEOERR* mcs_str2file(STRING str, const char *file) { if (file == NULL) return nerr_raise(NERR_ASSERT, "paramter null"); FILE *fp = fopen(file, "w"); if (!fp) return nerr_raise(NERR_IO, "unable to open %s for write", file); size_t ret = fwrite(str.buf, str.len, 1, fp); if (ret < 0) { fclose(fp); return nerr_raise(NERR_IO, "write str.buf to %s error", file); } fclose(fp); return STATUS_OK; } static NEOERR* _builtin_bitop_and(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result) { NEOERR *err; long int n1 = 0; long int n2 = 0; result->op_type = CS_TYPE_NUM; result->n = 0; err = cs_arg_parse(parse, args, "ii", &n1, &n2); if (err) return nerr_pass(err); result->n = n1 & n2; return STATUS_OK; } static NEOERR* _builtin_bitop_or(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result) { NEOERR *err; long int n1 = 0; long int n2 = 0; result->op_type = CS_TYPE_NUM; result->n = 0; err = cs_arg_parse(parse, args, "ii", &n1, &n2); if (err) return nerr_pass(err); result->n = n1 | n2; return STATUS_OK; } static NEOERR* _builtin_bitop_xor(CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result) { NEOERR *err; long int n1 = 0; long int n2 = 0; result->op_type = CS_TYPE_NUM; result->n = 0; err = cs_arg_parse(parse, args, "ii", &n1, &n2); if (err) return nerr_pass(err); result->n = n1 & ~n2; return STATUS_OK; } /* * from csparse.c, most partly */ static NEOERR * _builtin_string_uslice (CSPARSE *parse, CS_FUNCTION *csf, CSARG *args, CSARG *result) { NEOERR *err; char *s = NULL, *appends = NULL; char *slice; long int b = 0; long int e = 0; size_t len, appendlen; result->op_type = CS_TYPE_STRING; result->s = ""; err = cs_arg_parse(parse, args, "siis", &s, &b, &e, &appends); if (err) return nerr_pass(err); /* If null, return empty string */ if (s == NULL) return STATUS_OK; len = mstr_ulen(s); if (b < 0 && e == 0) e = len; if (b < 0) b += len; if (b < 0) b = 0; if (b > len) b = len; if (e < 0) e += len; if (e < 0) e = 0; if (e > len) e = len; /* Its the whole string */ if (b == 0 && e == len) { result->s = s; result->alloc = 1; return STATUS_OK; } if (e < b) b = e; if (b == e) { /* If null, return empty string */ free(s); return STATUS_OK; } appendlen = (appends && e < len) ? strlen(appends) : 0; b = mstr_upos2len(s, b); e = mstr_upos2len(s, e); slice = (char *) malloc (sizeof(char) * (e-b+appendlen+1)); if (slice == NULL) return nerr_raise(NERR_NOMEM, "Unable to allocate memory for string slice"); strncpy(slice, s + b, e-b); free(s); if (appends) strncpy(slice+(e-b), appends, appendlen); slice[e-b+appendlen] = '\0'; result->s = slice; result->alloc = 1; return STATUS_OK; } NEOERR* mcs_register_bitop_functions(CSPARSE *cs) { NEOERR *err; err = cs_register_function(cs, "bitop.and", 2, _builtin_bitop_and); if (err != STATUS_OK) return nerr_pass(err); cs_register_function(cs, "bitop.or", 2, _builtin_bitop_or); if (err != STATUS_OK) return nerr_pass(err); cs_register_function(cs, "bitop.xor", 2, _builtin_bitop_xor); if (err != STATUS_OK) return nerr_pass(err); return STATUS_OK; } NEOERR* mcs_register_mkd_functions(CSPARSE *cs) { return nerr_pass(cs_register_esc_strfunc(cs, "mkd.escape", mkd_esc_str)); } NEOERR* mcs_register_string_uslice(CSPARSE *cs) { return nerr_pass(cs_register_function(cs, "string.uslice", 4, _builtin_string_uslice)); } NEOERR* mcs_register_upload_parse_cb(CGI *cgi, void *rock) { NEOERR *err; err = cgi_register_parse_cb(cgi, "POST", "application/x-www-form-urlencoded", rock, mhttp_upload_parse_cb); if (err != STATUS_OK) return nerr_pass(err); err = cgi_register_parse_cb(cgi, "POST", "multipart/form-data", rock, mhttp_upload_parse_cb); if (err != STATUS_OK) return nerr_pass(err); err = cgi_register_parse_cb(cgi, "PUT", "*", rock, mhttp_upload_parse_cb); return nerr_pass(err); } int mcs_get_child_num(HDF *hdf, char *name) { HDF *node; if (!hdf) return 0; int count = 0; node = hdf_get_child(hdf, name); while (node) { count++; node = hdf_obj_next(node); } return count; } HDF* mcs_obj_nth_child(HDF *hdf, int n) { HDF *node; if (!hdf || n < 0) return NULL; node = hdf_obj_child(hdf); while (node && --n > 0) { node = hdf_obj_next(node); } return node; } HDF* mcs_get_nth_child(HDF *hdf, char *name, int n) { HDF *node; if (!hdf || n <= 0) return NULL; node = hdf_get_child(hdf, name); while (node && --n > 0) { node = hdf_obj_next(node); } return node; } HDF* mcs_get_nth_childf(HDF *hdf, int n, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return mcs_get_nth_child(hdf, key, n); } int mcs_get_child_numf(HDF *hdf, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return mcs_get_child_num(hdf, key); } HDF* mcs_get_objf(HDF *hdf, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return hdf_get_obj(hdf, key); } NEOERR* mcs_get_nodef(HDF *hdf, HDF **rnode, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return hdf_get_node(hdf, key, rnode); } HDF* mcs_fetch_nodef(HDF *hdf, char *fmt, ...) { HDF *rnode = NULL; char key[LEN_HDF_KEY]; va_list ap; NEOERR *err; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); err = hdf_get_node(hdf, key, &rnode); TRACE_NOK(err); return rnode; } NEOERR* mcs_copyf(HDF *dst, HDF *src, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return nerr_pass(hdf_copy(dst, key, src)); } NEOERR* mcs_remove_treef(HDF *hdf, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return nerr_pass(hdf_remove_tree(hdf, key)); } unsigned int mcs_get_uint_value(HDF *hdf, char *name, unsigned int defval) { char *val, *n; unsigned int v; val = hdf_get_value(hdf, name, NULL); if (val) { v = strtoul(val, &n, 10); if (val == n) v = defval; return v; } return defval; } float mcs_get_float_value(HDF *hdf, char *name, float defval) { char *val, *n; float v; val = hdf_get_value(hdf, name, NULL); if (val) { v = strtof(val, &n); if (val == n) v = defval; return v; } return defval; } int mcs_get_int_valuef(HDF *hdf, int defval, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return hdf_get_int_value(hdf, key, defval); } int64_t mcs_get_int64_value(HDF *hdf, char *name, int64_t defval) { char *val, *n; int64_t v; val = hdf_get_value(hdf, name, NULL); if (val) { v = strtoll(val, &n, 10); if (val == n) v = defval; return v; } return defval; } NEOERR* mcs_set_int64_value(HDF *hdf, char *name, int64_t val) { char buf[256]; snprintf(buf, sizeof(buf), "%ld", val); return nerr_pass(hdf_set_value(hdf, name, buf)); } NEOERR* mcs_set_uint_value(HDF *hdf, char *name, unsigned int value) { char buf[256]; snprintf(buf, sizeof(buf), "%u", value); return nerr_pass(hdf_set_value(hdf, name, buf)); } NEOERR* mcs_set_float_value(HDF *hdf, char *name, float value) { char buf[256]; snprintf(buf, sizeof(buf), "%f", value); return nerr_pass(hdf_set_value(hdf, name, buf)); } NEOERR* mcs_set_value_with_type(HDF *hdf, char *name, char *value, CnodeType type) { NEOERR *err; err = hdf_set_value(hdf, name, value); if (err != STATUS_OK) return nerr_pass(err); return nerr_pass(mcs_set_int_attr(hdf, name, "type", type)); } NEOERR* mcs_set_int_value_with_type(HDF *hdf, char *name, int value, CnodeType type) { NEOERR *err; err = hdf_set_int_value(hdf, name, value); if (err != STATUS_OK) return nerr_pass(err); return nerr_pass(mcs_set_int_attr(hdf, name, "type", type)); } NEOERR* mcs_set_int64_value_with_type(HDF *hdf, char *name, int64_t value, CnodeType type) { NEOERR *err; err = mcs_set_int64_value(hdf, name, value); if (err != STATUS_OK) return nerr_pass(err); return nerr_pass(mcs_set_int_attr(hdf, name, "type", type)); } NEOERR* mcs_set_float_value_with_type(HDF *hdf, char *name, float value, CnodeType type) { NEOERR *err; err = mcs_set_float_value(hdf, name, value); if (err != STATUS_OK) return nerr_pass(err); return nerr_pass(mcs_set_int_attr(hdf, name, "type", type)); } NEOERR* mcs_set_valuef_with_type(HDF *hdf, CnodeType type, char *fmt, ...) { char *k, *v; va_list ap; NEOERR *err; va_start(ap, fmt); k = vsprintf_alloc(fmt, ap); if (!k) return nerr_raise(NERR_NOMEM, "alloc format string"); va_end(ap); v = strchr(k, '='); if (!v) return nerr_raise(NERR_ASSERT, "No equials found: %s", k); *v++ = '\0'; /* equal to *v = '\0'; v++; */ err = mcs_set_value_with_type(hdf, k, v, type); SAFE_FREE(k); return nerr_pass(err); } int mcs_add_int_value(HDF *node, char *key, int val) { if (!node || !key) return 0; int ov = hdf_get_int_value(node, key, 0); hdf_set_int_value(node, key, ov+val); return ov+val; } int mcs_add_int_valuef(HDF *node, int val, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return mcs_add_int_value(node, key, val); } int64_t mcs_add_int64_value(HDF *node, char *key, int64_t val) { if (!node || !key) return 0; int64_t ov = mcs_get_int64_value(node, key, 0); mcs_set_int64_value(node, key, ov+val); return ov+val; } int64_t mcs_add_int64_valuef(HDF *node, int64_t val, char *fmt, ...) { char key[LEN_HDF_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(key, sizeof(key), fmt, ap); va_end(ap); return mcs_add_int64_value(node, key, val); } char* mcs_append_string_value(HDF *node, char *key, char *str) { if (!node || !key) return NULL; char *ov = hdf_get_value(node, key, ""); hdf_set_valuef(node, "%s=%s%s", key, ov, str); return hdf_get_value(node, key, NULL); } char* mcs_append_string_valuef(HDF *node, char *key, char *sfmt, ...) { char *qa, *rs; va_list ap; va_start(ap, sfmt); qa = vsprintf_alloc(sfmt, ap); va_end(ap); if (!qa) return NULL; rs = mcs_append_string_value(node, key, qa); free(qa); return rs; } char* mcs_prepend_string_value(HDF *node, char *key, char *str) { if (!node || !key) return NULL; char *ov = hdf_get_value(node, key, ""); hdf_set_valuef(node, "%s=%s%s", key, str, ov); return hdf_get_value(node, key, NULL); } char* mcs_prepend_string_valuef(HDF *node, char *key, char *sfmt, ...) { char *qa, *rs; va_list ap; va_start(ap, sfmt); qa = vsprintf_alloc(sfmt, ap); va_end(ap); if (!qa) return NULL; rs = mcs_prepend_string_value(node, key, qa); free(qa); return rs; } void mcs_hdf_rep(HDF *data, HDF *dst) { char *srcstr, *repstr; if (!data || !dst) return; HDF *datarow = hdf_obj_child(data); while (datarow) { HDF *child = hdf_obj_child(dst); while (child) { if (hdf_obj_child(child)) { return mcs_hdf_rep(data, child); } srcstr = hdf_obj_value(child); repstr = mstr_repstr(1, srcstr, hdf_obj_name(datarow), hdf_obj_value(datarow)); hdf_set_value(child, NULL, repstr); free(repstr); child = hdf_obj_next(child); } datarow = hdf_obj_next(datarow); } } char* mcs_repvstr_byhdf(const char *src, const char *begin, const char *end, HDF *data) { char *p, *q, *value, *stmp; STRING str, stok; HDF *cnode; stmp = NULL; string_init(&str); string_init(&stok); if (!src) return NULL; if (!data) return strdup(src); cnode = hdf_obj_child(data); while (cnode) { string_appendf(&stok, "%s%s%s", begin, hdf_obj_name(cnode), end); value = hdf_obj_value(cnode); //mtc_dbg("replace %s", stok.buf); if (str.len == 0) { stmp = (char*)src; } else { /* already replaced key, so, refresh the src pointer */ stmp = strdup(str.buf); string_clear(&str); } p = q = stmp; q = strstr(p, stok.buf); while (q) { string_appendn(&str, p, q - p); if (value) string_append(&str, value); p = q + stok.len; if (p) q = strstr(p, stok.buf); else q = NULL; } if (p) string_append(&str, p); /* cleanup memory */ if (stmp != src) SAFE_FREE(stmp); string_clear(&stok); cnode = hdf_obj_next(cnode); } return str.buf; } NEOERR* mcs_data_rend(HDF *confignode, HDF *datanode, HDF *outnode, McsFlag flag) { HDF *childconfignode, *xnode, *ynode; char *keyp, *keyq; int cnum; bool singlechild; NEOERR *err; MCS_NOT_NULLB(confignode, outnode); childconfignode = hdf_obj_child(confignode); while (childconfignode) { char *name = hdf_obj_name(childconfignode); char *datakey = hdf_obj_value(childconfignode); if (!datakey) datakey = mcs_obj_attr(childconfignode, "value"); char *valuestr = hdf_get_value(datanode, datakey, NULL); HDF *valuenode = hdf_get_obj(datanode, datakey); char *require = mcs_obj_attr(childconfignode, "require"); char *defaultval = mcs_obj_attr(childconfignode, "default"); char *nodevalue = mcs_obj_attr(childconfignode, "valuenode"); int type = mcs_get_int_attr(childconfignode, NULL, "type", CNODE_TYPE_STRING); char *childtype = mcs_obj_attr(childconfignode, "childtype"); char tok[64]; singlechild = false; if (!datakey) { valuestr = NULL; valuenode = NULL; } else if (!strcmp(datakey, "__value__")) { valuestr = hdf_obj_value(datanode); valuenode = datanode; } else if (strstr(datakey, "__1stc__")) { /* * TODO __[n,x,z]stc__ support */ /* * eids.__1stc__.id * keyp = eids * keyq = id */ char *safekey = strdup(datakey); keyp = strstr(safekey, "__1stc__"); keyq = keyp + 8; if (*keyq && *(keyq) == '.') keyq = keyq + 1; if (keyp != safekey && *(keyp - 1) == '.') keyp = keyp - 1; *keyp = '\0'; keyp = safekey; valuestr = hdf_get_value(hdf_get_child(datanode, keyp), keyq, NULL); valuenode = hdf_get_obj(hdf_get_child(datanode, keyp), keyq); SAFE_FREE(safekey); } if (nodevalue && !strcmp(nodevalue, "true")) { valuestr = hdf_obj_value(childconfignode); valuenode = NULL; } if (childtype && !strcmp(childtype, "__single__")) singlechild = true; if (!strcmp(name, "__arraynode__")) name = NULL; else if (!strcmp(name, "__datanode__")) name = hdf_obj_name(datanode); switch (type) { case CNODE_TYPE_INT: case CNODE_TYPE_INT64: case CNODE_TYPE_DATETIME: case CNODE_TYPE_TIMESTAMP: if (!strcmp(datakey, "_NOW")) { snprintf(tok, sizeof(tok), "%ld", time(NULL)); valuestr = tok; } case CNODE_TYPE_STRING: case CNODE_TYPE_BOOL: case CNODE_TYPE_FLOAT: if (valuestr && *valuestr) { hdf_set_value(outnode, name, valuestr); } else if (require && !strcmp(require, "true")) { return nerr_raise(NERR_ASSERT, "need %s %d", name, type); } else { if (defaultval) { hdf_set_value(outnode, name, defaultval); } else if (!(flag & MCS_FLAG_REND_NO_EMPTY)) { hdf_set_value(outnode, name, ""); } } break; case CNODE_TYPE_OBJECT: if (hdf_obj_child(childconfignode)) { /* appoint object key from confignode */ err = mcs_data_rend(childconfignode, valuenode, mcs_fetch_nodef(outnode, name), flag); if (err != STATUS_OK) return nerr_pass(err); } else if (valuenode) { /* use object key from datanode */ hdf_copy(outnode, name, valuenode); } break; case CNODE_TYPE_ARRAY: if (hdf_obj_child(childconfignode)) { /* appoint array from confignode */ if (datakey && strstr(datakey, ".$.")) { /* * only support one $ * adgroups.$.spots * keyp = adgroups * keyq = spots */ char *safekey = strdup(datakey); keyp = strstr(safekey, ".$."); keyq = keyp + 3; *keyp = '\0'; keyp = safekey; cnum = 0; valuenode = hdf_get_obj(datanode, keyp); if (!valuenode) return nerr_raise(NERR_ASSERT, "%s don't exist", safekey); xnode = hdf_obj_child(valuenode); while (xnode) { ynode = hdf_get_child(xnode, keyq); while (ynode) { err = mcs_data_rend(childconfignode, ynode, mcs_fetch_nodef(outnode, "%s.%d", name, cnum++), flag); if (err != STATUS_OK) return nerr_pass(err); ynode = hdf_obj_next(ynode); } xnode = hdf_obj_next(xnode); } SAFE_FREE(safekey); } else { /* static array value from datanode */ if (singlechild) { err = mcs_data_rend(childconfignode, valuenode, mcs_fetch_nodef(outnode, "%s.0", name), flag); if (err != STATUS_OK) return nerr_pass(err); } else if (valuenode && hdf_obj_child(valuenode)) { cnum = 0; xnode = hdf_obj_child(valuenode); while (xnode) { err = mcs_data_rend(childconfignode, xnode, mcs_fetch_nodef(outnode, "%s.%d", name, cnum++), flag); if (err != STATUS_OK) return nerr_pass(err); xnode = hdf_obj_next(xnode); } } } } else if (valuenode) { /* use object key from datanode */ hdf_copy(outnode, name, valuenode); } break; default: break; } if (!(flag & MCS_FLAG_REND_NO_TYPE)) { err = mcs_set_int_attr(outnode, name, "type", type); if (err != STATUS_OK) nerr_ignore(&err); } childconfignode = hdf_obj_next(childconfignode); } return STATUS_OK; } char* mcs_hdf_attr(HDF *hdf, char *name, char*key) { if (hdf == NULL || key == NULL) return NULL; HDF_ATTR *attr = hdf_get_attr(hdf, name); while (attr != NULL) { if (!strcmp(attr->key, key)) { return attr->value; } attr = attr->next; } return NULL; } char* mcs_obj_attr(HDF *hdf, char*key) { if (hdf == NULL || key == NULL) return NULL; HDF_ATTR *attr = hdf_obj_attr(hdf); while (attr != NULL) { if (!strcmp(attr->key, key)) { return attr->value; } attr = attr->next; } return NULL; } NEOERR* mcs_set_int_attr(HDF *hdf, char *name, char *key, int val) { char tok[64] = {0}; snprintf(tok, sizeof(tok), "%d", val); return nerr_pass(hdf_set_attr(hdf, name, key, tok)); } NEOERR* mcs_set_int_attrf(HDF *hdf, char *key, int val, char *fmt, ...) { char name[LEN_HASH_KEY]; va_list ap; va_start(ap, fmt); vsnprintf(name, sizeof(name), fmt, ap); va_end(ap); return nerr_pass(mcs_set_int_attr(hdf, name, key, val)); } int mcs_get_int_attr(HDF *hdf, char *name, char *key, int defval) { char *s = mcs_hdf_attr(hdf, name, key); if (s) return atoi(s); else return defval; } NEOERR* mcs_err_valid(NEOERR *err) { NEOERR *r = err; if (err == STATUS_OK) return STATUS_OK; while (r && r != INTERNAL_ERR) { if (r->error != NERR_PASS) break; r = r->next; } if (!r) r = err; return r; }
b98abc10fcf948de54978a3e4f162b828865d1fd
73c086bd12377ca9f781e5a3578fe7ea82b08ca9
/lab1.c
16cd2710fac227c541bc7fc888aee81983d55ff2
[]
no_license
SuvonkarKundu/Problem-solving
61c6742fe8f5d68b81811093ecdb60666be07b01
2191ad1b93ce58bbab30e38345c4b3918d779d93
refs/heads/master
2022-01-25T01:04:07.930011
2022-01-11T18:16:04
2022-01-11T18:16:04
170,992,134
0
1
null
2022-01-11T18:16:05
2019-02-16T10:41:53
HTML
UTF-8
C
false
false
342
c
lab1.c
#include<stdio.h> main() { int a[100],q,i,r,e=0,j; scanf("%d",&q); for(i=0;i<q;i++) { scanf("%d",&a[i]); } scanf("%d",&r); for(j=0;j<q;j++) { if(a[j]==r) { printf("r is found"); e=1; } } if(e==0) printf("r is not found"); return 0; }
7f44093c9012196ce9f0c9028425b5671d59dae4
8ca3e84b4780a99609777267ba5fe23cc4136662
/pwd/pwd.c
61eb0fa06e524b181da050fb0d79a1597b3c638d
[]
no_license
jackandjoke/Understanding-unix-linux-programming
2aaf3f6139083fd28cee192ca5c4a89c92ef60f4
2a5f5b290c0c721960240718f61ec98973450a0f
refs/heads/master
2020-03-19T16:36:20.297405
2018-07-08T03:06:21
2018-07-08T03:06:21
136,721,397
0
0
null
null
null
null
UTF-8
C
false
false
1,344
c
pwd.c
#include<sys/types.h> #include<sys/stat.h> #include<unistd.h> #include<dirent.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX_SIZE 256 #define print_error(s,i) {perror(s);exit(i);} ino_t get_inode(const char *path){ struct stat buf; if( stat(path,&buf) != 0 ){ print_error("stat failed",1); } return buf.st_ino; } void inum_to_name(ino_t ino, char its_name[], DIR *dir){ struct dirent* direntp; int found = 0; while( (direntp = readdir(dir)) != NULL){ if(direntp -> d_ino == ino){ found = 1; break; } } if(!found){ print_error("current inode not found in parent directory",1); } strncpy(its_name,direntp->d_name,MAX_SIZE); its_name[MAX_SIZE-1] = '\0'; closedir(dir); } void printpathto(ino_t cur_ino){ ino_t p_ino = get_inode(".."); if(p_ino == cur_ino) {return;} DIR* dir; if( (dir = opendir("..")) == NULL){ print_error("readdir failed",1); } char its_name[MAX_SIZE]; inum_to_name(cur_ino,its_name,dir); chdir(".."); printpathto(p_ino); printf("/%s",its_name); } int main(){ ino_t cur_ino = get_inode("."); if(cur_ino == get_inode("/")){ printf("/"); }else{ printpathto(cur_ino); } printf("\n"); return 0; }
6700703183290bb388af8379016b8cb248220fe6
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/linux/drivers/iio/dac/extr_ad5696-i2c.c_ad5686_i2c_read.c
d71eeea0be8b3faf7cf384563baac6cb4b4b3606
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
1,732
c
extr_ad5696-i2c.c_ad5686_i2c_read.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ typedef struct TYPE_2__ TYPE_1__ ; /* Type definitions */ typedef int /*<<< orphan*/ u8 ; struct i2c_msg {int flags; int len; char* buf; int /*<<< orphan*/ addr; } ; struct i2c_client {int flags; int /*<<< orphan*/ adapter; int /*<<< orphan*/ addr; } ; struct ad5686_state {TYPE_1__* data; int /*<<< orphan*/ dev; } ; struct TYPE_2__ {char* d8; int /*<<< orphan*/ d16; int /*<<< orphan*/ d32; } ; /* Variables and functions */ int AD5686_ADDR (int /*<<< orphan*/ ) ; int AD5686_CMD (int /*<<< orphan*/ ) ; int /*<<< orphan*/ AD5686_CMD_NOOP ; int I2C_M_RD ; int be16_to_cpu (int /*<<< orphan*/ ) ; int /*<<< orphan*/ cpu_to_be32 (int) ; int i2c_transfer (int /*<<< orphan*/ ,struct i2c_msg*,int) ; struct i2c_client* to_i2c_client (int /*<<< orphan*/ ) ; __attribute__((used)) static int ad5686_i2c_read(struct ad5686_state *st, u8 addr) { struct i2c_client *i2c = to_i2c_client(st->dev); struct i2c_msg msg[2] = { { .addr = i2c->addr, .flags = i2c->flags, .len = 3, .buf = &st->data[0].d8[1], }, { .addr = i2c->addr, .flags = i2c->flags | I2C_M_RD, .len = 2, .buf = (char *)&st->data[0].d16, }, }; int ret; st->data[0].d32 = cpu_to_be32(AD5686_CMD(AD5686_CMD_NOOP) | AD5686_ADDR(addr) | 0x00); ret = i2c_transfer(i2c->adapter, msg, 2); if (ret < 0) return ret; return be16_to_cpu(st->data[0].d16); }
384f5ca7277aa33de8f8094ae7f0d664d2f8f1da
693c415c4b7458096f803ea90ce3f8e8c46dcd5d
/includes/libft/ft_putchar.c
58262051bb5788dca3c5c345e567de784d58ecc5
[]
no_license
daalexan/CoreWar
a759957c63b293d597287eba99781c84555ab517
90e9ad8f6c38cd70eaf63a4ec979b07c85159099
refs/heads/master
2020-04-05T01:06:48.974998
2018-11-10T17:24:01
2018-11-10T17:24:01
156,423,869
0
0
null
null
null
null
UTF-8
C
false
false
974
c
ft_putchar.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putchar.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: daalexan <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/11/01 18:37:42 by daalexan #+# #+# */ /* Updated: 2017/11/01 18:37:44 by daalexan ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" int ft_putchar(char c) { ft_putchar_fd(c, 1); return (1); }
d71988f01359d4e591bdd23a63202f2dbd3c3c05
c732666c24d86e0da4cd2c1ee12619e9c514e818
/beakjoon/hankyul/16/16-9.c
46ac09afb0a12a414ad5d0d5fbdcbc62356bab5c
[]
no_license
Algostu/boradori
032f71e9e58163d3e188856629a5de4afaa87b30
939d60e8652074e26ba08252217f7788cae9063c
refs/heads/master
2023-04-22T03:57:26.823917
2021-04-06T23:09:36
2021-04-06T23:09:36
263,754,451
0
0
null
null
null
null
UTF-8
C
false
false
1,339
c
16-9.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #include <time.h> #define _USE_MATH_DEFINES #define COMPARE(X, Y) (X) > (Y) ? (X) : ((X) == (Y) ? (X) : (Y)) #define SWAP(X, Y, T) T = (X); (X) = (Y); (Y) = T; #define MALLOC(X, Y) \ if(((X) = malloc((Y)))==NULL){\ fprintf(stderr, "mallc error"); exit(EXIT_FAILURE);\ } int stair_num(int i, int j, int n, int (*memo)[10]){ int s = 0, s_1 = 0, s_2 = 0; if(memo[j][i]!=-1) return memo[j][i]; if(j+1 >= n) return 1; if(i+1<10) s_1 = stair_num(i+1, j+1, n, memo); if(i-1>-1) s_2 = stair_num(i-1, j+1, n, memo); s = (s_1 % 1000000000 + s_2 % 1000000000) % 1000000000; memo[j][i] = s; return s; } void solve(int test_num){ int N, i, j, ans=0, memo[100][10]; scanf("%d", &N); for(i=0;i<N;i++){ for(j=0;j<10;j++){ memo[i][j] = -1; } } if(N==1) { printf("9\n"); return; } // else if(N==2) { printf("17\n"); return; } for(i=1;i<10;i++){ ans = (ans % 1000000000 + stair_num(i, 0, N, memo) % 1000000000) % 1000000000; } //debug // for(i=0;i<N;i++){ // for(j=0;j<10;j++){ // printf("%4d", memo[i][j]); // } // printf("\n"); // } printf("%d\n", ans); } int main(){ // int i, N; // scanf("%d", &N); // for(i=0;i<N;i++){ // solve(i+1); // } solve(0); return 0; }
6c934940aa539690ceab9dd5d8582e7637680e05
2d0ae087d4f78a1693585fef0bbfe89f0995ff5f
/src/test/testjoin.c
480a5f58757c1b3287151ca1d18305a061198fb6
[ "BSD-2-Clause" ]
permissive
mkushnir/mrkdht
98983cc6ae3a4266124c94f16f89a0c5e5107a6c
32db0d7daf49e4b7b2d5b171589d92798298f5a0
refs/heads/master
2021-01-18T21:18:54.506672
2019-02-25T15:57:13
2019-02-25T15:57:13
11,496,189
0
0
null
null
null
null
UTF-8
C
false
false
6,653
c
testjoin.c
#include <assert.h> #include <err.h> /* _POSIX_PATH_MAX */ #include <limits.h> #include <signal.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #include "unittest.h" #include "diag.h" #include <mrkcommon/dumpm.h> #include <mrkcommon/util.h> #include <mrkcommon/memdebug.h> MEMDEBUG_DECLARE(testjoin) #include <mrkthr.h> #include <mrkapp.h> #include <mrkdht.h> #ifndef NDEBUG const char *_malloc_options = "AJ"; #endif /* configuration */ static const char *myhost = NULL; static unsigned long myport; static mrkdht_nid_t mynid; static const char *joinhost = NULL; static unsigned long joinport; static mrkdht_nid_t joinnid; static int nojoin = 0; static int nowait = 0; static int nodaemon = 0; /* internal */ static int _shutdown = 0; static mrkthr_ctx_t *backdoor_thr; static void termhandler(UNUSED int sig) { mrkthr_set_interrupt(backdoor_thr); mrkdht_shutdown(); _shutdown = 1; } static void write_response(int fd, const char *resp) { size_t sz; char buf[1024]; sz = MIN(strlen(resp), countof(buf) - 1); strncpy(buf, resp, sz); buf[sz] = '\n'; if (mrkthr_write_all(fd, buf, sz + 1) != 0) { /* pass through */ ; } } static int backdoor(UNUSED int argc, void **argv) { int fd; void *udata; assert(argc == 2); fd = (int)(intptr_t)argv[0]; udata = argv[1]; while (!_shutdown) { char buf[1024], *pbuf; ssize_t nread; char cmd[32]; memset(buf, '\0', sizeof(buf)); if ((nread = mrkthr_read_allb(fd, buf, sizeof(buf))) <= 0) { break; } pbuf = buf; if (sscanf(pbuf, "%31s", cmd) <= 0) { break; } pbuf += strlen(cmd); //CTRACE("cmd=%s", cmd); if (strcmp(cmd, "help") == 0) { write_response(fd, "OK help kill tdump bdump fcn ln quit"); } else if (strcmp(cmd, "quit") == 0) { write_response(fd, "OK bye"); termhandler(0); break; } else if (strcmp(cmd, "kill") == 0) { write_response(fd, "OK killing"); mrkthr_shutdown(); break; } else if (strcmp(cmd, "tdump") == 0) { write_response(fd, "OK dumping threads"); mrkthr_dump_all_ctxes(); } else if (strcmp(cmd, "bdump") == 0) { write_response(fd, "OK dumping buckets"); mrkdht_buckets_dump(); } else if (strcmp(cmd, "fcn") == 0) { mrkdht_nid_t nid = 0; sscanf(pbuf, "%lx", &nid); CTRACE("nid=%016lx", nid); mrkdht_test_find_closest_nodes(nid, 3); write_response(fd, "OK"); } else if (strcmp(cmd, "ln") == 0) { mrkdht_nid_t nid = 0; mrkdht_node_t *nodes[MRKDHT_BUCKET_MAX]; size_t sz = MRKDHT_BUCKET_MAX; int res; size_t i; sscanf(pbuf, "%lx", &nid); CTRACE("nid=%016lx", nid); memset(nodes, '\0', sizeof(nodes)); res = mrkdht_lookup_nodes(nid, nodes, &sz); CTRACE("res=%d sz=%ld", res, sz); for (i = 0; i < sz; ++i) { mrkdht_dump_node(nodes[i]); } write_response(fd, "OK"); } else { write_response(fd, "ERR not supported, bye"); break; } } close(fd); return 0; } static int test1(UNUSED int argc, UNUSED void *argv[]) { int res; mrkdht_set_local_node(mynid, myhost, myport); mrkdht_set_refresh(15000); mrkdht_run(); if (!nojoin) { while (!_shutdown) { if ((res = mrkdht_join(joinnid, joinhost, joinport, 0)) != 0) { CTRACE("Failed to join, retrying ..."); mrkthr_sleep(2000); } else { break; } } } if (nowait) { killpg(0, SIGTERM); } return 0; } int main(int argc, char **argv) { struct sigaction sa; char ch; char bdpath[_POSIX_PATH_MAX]; char pidfile[_POSIX_PATH_MAX]; char outfile[_POSIX_PATH_MAX]; MEMDEBUG_REGISTER(testjoin); //#ifndef NDEBUG // MEMDEBUG_REGISTER(array); // MEMDEBUG_REGISTER(list); // MEMDEBUG_REGISTER(trie); //#endif while ((ch = getopt(argc, argv, "ch:H:nNp:P:")) != -1) { switch (ch) { case 'c': nodaemon = 1; break; case 'h': myhost = strdup(optarg); break; case 'H': joinhost = strdup(optarg); break; case 'n': nojoin = 1; break; case 'N': nowait = 1; break; case 'p': myport = strtol(optarg, NULL, 10); mynid = 0xdadadadadada0000 | myport; break; case 'P': joinport = strtol(optarg, NULL, 10); joinnid = 0xdadadadadada0000 | joinport; break; default: break; } } if (myhost == NULL) { errx(1, "Please supply my host via -h option."); } if (myport < 1024 || myport > 65535) { errx(1, "Please supply my port between 1024 and 65535 via -p option."); } if (!nojoin) { if (joinhost == NULL) { errx(1, "Please supply join host via -H option."); } if (joinport < 1024 || joinport > 65535) { errx(1, "Please supply join port between 1024 and 65535 " "via -P option."); } } if (myport == joinport) { errx(1, "My port and join port may not be the same."); } sa.sa_handler = termhandler; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); if (sigaction(SIGINT, &sa, NULL) != 0) { FAIL("sigaction"); } if (sigaction(SIGTERM, &sa, NULL) != 0) { FAIL("sigaction"); } if (!nodaemon) { snprintf(pidfile, sizeof(pidfile), "pid.%ld", myport); snprintf(outfile, sizeof(outfile), "out.%ld", myport); daemonize(pidfile, outfile, outfile); } mrkthr_init(); mrkdht_init(); mrkthr_spawn("test1", test1, 0); snprintf(bdpath, sizeof(bdpath), "/tmp/testjoin.%ld.sock", myport); backdoor_thr = mrkthr_spawn("backdoor", local_server, 4, 1, bdpath, backdoor, NULL); mrkthr_loop(); mrkdht_fini(); mrkthr_fini(); memdebug_print_stats(); return 0; }
39b71bff7d5cc880d492ce5d7e9f20bfeab3acf2
fcb8bfd28932532556abb2da115c029ca909d0ce
/libft/ft_itoa.c
5714a16a2ef02f9b9f5eb0a6ffcba1db6f031133
[]
no_license
YonValandil/lem-in
6c91045c874142a4567d44d9af54c2354929851c
bcf7c036d508f0aba7655aeaf530483746cad5d9
refs/heads/master
2020-03-14T16:27:25.016862
2018-06-03T23:06:56
2018-06-03T23:06:56
131,698,398
0
0
null
null
null
null
UTF-8
C
false
false
1,731
c
ft_itoa.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_itoa.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jjourne <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/25 17:30:43 by jjourne #+# #+# */ /* Updated: 2017/01/27 17:34:51 by jjourne ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" static long int ifneg(long int ln, int *f) { if (ln < 0) { *f = 1; ln = -ln; } else *f = 0; return (ln); } static char *sizemallocstr(char *s, long int ln, int f, int base) { while (ln >= 10) { ln /= 10; base++; } s = ft_strnew(base + f); if (s == NULL) return (NULL); return (s); } static char *conv(char *s, long int ln, int base, int i) { while (base > 0) { s[i] = ((ln / base) % 10) + '0'; base /= 10; i++; } s[i] = '\0'; return (s); } char *ft_itoa(int n) { char *s; int base; int i; int f; long int ln; i = 0; ln = n; base = 1; s = NULL; ln = ifneg(ln, &f); s = sizemallocstr(s, ln, f, base); if (s == NULL) return (NULL); if (f == 1) { s[i] = '-'; i++; } while ((ln / base) >= 10) base *= 10; s = conv(s, ln, base, i); return (s); }
d2fc29a634521d22112ec7d684a0f4baf7b5a505
83615a4d81339b33943a5baccfcc640e84869645
/ConfigReader/test/test.c
c817068ad49a6f5c80a5efbed847349a38237b54
[]
no_license
ljianhui/CDevToolKit
14f1382645d0ac098eb24819df3c4b1f50ce2fa6
d562dbf7114430d89142d032c18b70a77ae37434
refs/heads/master
2021-01-15T08:11:11.434271
2016-08-23T17:10:29
2016-08-23T17:10:29
65,671,341
2
0
null
null
null
null
UTF-8
C
false
false
984
c
test.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include "config_reader.h" int main(int argc, char *argv[]) { char configFile[256] = {'\0'}; char path[256] = {'\0'}; char *pc = strrchr(argv[0], '/'); memcpy(path, argv[0], pc - argv[0] + 1); path[pc - argv[0] + 1] = '\0'; snprintf(configFile, sizeof(configFile) - 1, "%s/test.ini", path); int errNo = 0; ConfigReader *reader = ConfigReaderCreate(configFile, &errNo); if (reader == NULL) { printf("config reader create failed, errNo[%d]\n", errNo); return 0; } ConfigReaderPrint(reader); printf("\nsection.key demo: \n"); printf("websize.baidu=%s\n", ConfigReaderGetValue(reader, "website", "baidu")); printf("network.protocol=%s\n", ConfigReaderGetValue(reader, "network", "protocol")); printf("ext.py=%s\n", ConfigReaderGetValue(reader, "ext", "py")); printf("ext.txt=%s\n", ConfigReaderGetValue(reader, "ext", "txt")); ConfigReaderDestory(reader); return 0; }
e713fb3dbf55e2110b58b10e10d39c8ee5a2a05c
6409376322c8cb807f2c1d1137affed097568842
/ITE_Castor3_SDK/project/MideaWBL_HSG/layer_auto.c
d98b92f934e250d7c1e9a14ffc5eb4701c853f57
[]
no_license
Music802/Midea_Hsg_SDK_V2281
141dd25eda566162eb95641c1f397cceb6ad12bf
0acf53d1d551d5092cf8e63e3a1ee7680c5edbd0
refs/heads/master
2021-08-22T21:21:29.821756
2017-12-01T09:49:34
2017-12-01T09:49:34
112,737,483
1
0
null
2017-12-01T12:28:13
2017-12-01T12:28:13
null
UTF-8
C
false
false
198
c
layer_auto.c
#include <assert.h> #include "scene.h" bool AutoButtonOnMouseDn(ITUWidget* widget, char* param) { return true; } bool AutoButtonOnMouseUp(ITUWidget* widget, char* param) { return true; }
e13402eab4b51cacc8b7632565b6e458e72b4b7c
d16a65e5b80240da6817b63e8f6187f0415460e8
/yzmc/model/swap/c/amp_classes.h
b1f580b75cf2f8d8838c44352014bcd2534777fb
[]
no_license
cortlandstarrett/graveyard
af841e6426466bf76fc342a7b9d6cdb1f6916ef9
a10972b1eca47741f424639c1a7af55dafab211f
refs/heads/master
2020-12-14T11:56:35.949085
2018-10-22T18:40:16
2018-10-22T18:40:16
60,371,947
0
0
null
2016-06-03T19:15:34
2016-06-03T19:15:26
Java
UTF-8
C
false
false
748
h
amp_classes.h
/*---------------------------------------------------------------------------- * File: amp_classes.h * * This file defines the object type identification numbers for all classes * in the component: amp * * your copyright statement can go here (from te_copyright.body) *--------------------------------------------------------------------------*/ #ifndef AMP_CLASSES_H #define AMP_CLASSES_H #ifdef __cplusplus extern "C" { #endif /* * Initialization services for component: amp */ void amp_execute_initialization( void ); /* * UML Domain Functions (Synchronous Services) */ void amp_init( void ); #include "LOG_bridge.h" #include "amp.h" #ifdef __cplusplus } #endif #endif /* AMP_CLASSES_H */
0032d6850bb92196187a6ad35cf9fa1dee210b47
afb7006e47e70c1deb2ddb205f06eaf67de3df72
/media/libwebp/src/dsp/alpha_processing_sse2.c
c16e4fc7566f065dc37950387a694bae3bdea868
[ "LicenseRef-scancode-unknown-license-reference", "BSD-3-Clause" ]
permissive
marco-c/gecko-dev-wordified
a66383f85db33911b6312dd094c36f88c55d2e2c
3509ec45ecc9e536d04a3f6a43a82ec09c08dff6
refs/heads/master
2023-08-10T16:37:56.660204
2023-08-01T00:39:54
2023-08-01T00:39:54
211,297,590
1
0
null
null
null
null
UTF-8
C
false
false
15,374
c
alpha_processing_sse2.c
/ / Copyright 2014 Google Inc . All Rights Reserved . / / / / Use of this source code is governed by a BSD - style license / / that can be found in the COPYING file in the root of the source / / tree . An additional intellectual property rights grant can be found / / in the file PATENTS . All contributing project authors may / / be found in the AUTHORS file in the root of the source tree . / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / / / Utilities for processing transparent channel . / / / / Author : Skal ( pascal . massimino gmail . com ) # include " src / dsp / dsp . h " # if defined ( WEBP_USE_SSE2 ) # include < emmintrin . h > / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - static int DispatchAlpha_SSE2 ( const uint8_t * WEBP_RESTRICT alpha int alpha_stride int width int height uint8_t * WEBP_RESTRICT dst int dst_stride ) { / / alpha_and stores an ' and ' operation of all the alpha [ ] values . The final / / value is not 0xff if any of the alpha [ ] is not equal to 0xff . uint32_t alpha_and = 0xff ; int i j ; const __m128i zero = _mm_setzero_si128 ( ) ; const __m128i rgb_mask = _mm_set1_epi32 ( ( int ) 0xffffff00 ) ; / / to preserve RGB const __m128i all_0xff = _mm_set_epi32 ( 0 0 ~ 0 ~ 0 ) ; __m128i all_alphas = all_0xff ; / / We must be able to access 3 extra bytes after the last written byte / / ' dst [ 4 * width - 4 ] ' because we don ' t know if alpha is the first or the / / last byte of the quadruplet . const int limit = ( width - 1 ) & ~ 7 ; for ( j = 0 ; j < height ; + + j ) { __m128i * out = ( __m128i * ) dst ; for ( i = 0 ; i < limit ; i + = 8 ) { / / load 8 alpha bytes const __m128i a0 = _mm_loadl_epi64 ( ( const __m128i * ) & alpha [ i ] ) ; const __m128i a1 = _mm_unpacklo_epi8 ( a0 zero ) ; const __m128i a2_lo = _mm_unpacklo_epi16 ( a1 zero ) ; const __m128i a2_hi = _mm_unpackhi_epi16 ( a1 zero ) ; / / load 8 dst pixels ( 32 bytes ) const __m128i b0_lo = _mm_loadu_si128 ( out + 0 ) ; const __m128i b0_hi = _mm_loadu_si128 ( out + 1 ) ; / / mask dst alpha values const __m128i b1_lo = _mm_and_si128 ( b0_lo rgb_mask ) ; const __m128i b1_hi = _mm_and_si128 ( b0_hi rgb_mask ) ; / / combine const __m128i b2_lo = _mm_or_si128 ( b1_lo a2_lo ) ; const __m128i b2_hi = _mm_or_si128 ( b1_hi a2_hi ) ; / / store _mm_storeu_si128 ( out + 0 b2_lo ) ; _mm_storeu_si128 ( out + 1 b2_hi ) ; / / accumulate eight alpha ' and ' in parallel all_alphas = _mm_and_si128 ( all_alphas a0 ) ; out + = 2 ; } for ( ; i < width ; + + i ) { const uint32_t alpha_value = alpha [ i ] ; dst [ 4 * i ] = alpha_value ; alpha_and & = alpha_value ; } alpha + = alpha_stride ; dst + = dst_stride ; } / / Combine the eight alpha ' and ' into a 8 - bit mask . alpha_and & = _mm_movemask_epi8 ( _mm_cmpeq_epi8 ( all_alphas all_0xff ) ) ; return ( alpha_and ! = 0xff ) ; } static void DispatchAlphaToGreen_SSE2 ( const uint8_t * WEBP_RESTRICT alpha int alpha_stride int width int height uint32_t * WEBP_RESTRICT dst int dst_stride ) { int i j ; const __m128i zero = _mm_setzero_si128 ( ) ; const int limit = width & ~ 15 ; for ( j = 0 ; j < height ; + + j ) { for ( i = 0 ; i < limit ; i + = 16 ) { / / process 16 alpha bytes const __m128i a0 = _mm_loadu_si128 ( ( const __m128i * ) & alpha [ i ] ) ; const __m128i a1 = _mm_unpacklo_epi8 ( zero a0 ) ; / / note the ' zero ' first ! const __m128i b1 = _mm_unpackhi_epi8 ( zero a0 ) ; const __m128i a2_lo = _mm_unpacklo_epi16 ( a1 zero ) ; const __m128i b2_lo = _mm_unpacklo_epi16 ( b1 zero ) ; const __m128i a2_hi = _mm_unpackhi_epi16 ( a1 zero ) ; const __m128i b2_hi = _mm_unpackhi_epi16 ( b1 zero ) ; _mm_storeu_si128 ( ( __m128i * ) & dst [ i + 0 ] a2_lo ) ; _mm_storeu_si128 ( ( __m128i * ) & dst [ i + 4 ] a2_hi ) ; _mm_storeu_si128 ( ( __m128i * ) & dst [ i + 8 ] b2_lo ) ; _mm_storeu_si128 ( ( __m128i * ) & dst [ i + 12 ] b2_hi ) ; } for ( ; i < width ; + + i ) dst [ i ] = alpha [ i ] < < 8 ; alpha + = alpha_stride ; dst + = dst_stride ; } } static int ExtractAlpha_SSE2 ( const uint8_t * WEBP_RESTRICT argb int argb_stride int width int height uint8_t * WEBP_RESTRICT alpha int alpha_stride ) { / / alpha_and stores an ' and ' operation of all the alpha [ ] values . The final / / value is not 0xff if any of the alpha [ ] is not equal to 0xff . uint32_t alpha_and = 0xff ; int i j ; const __m128i a_mask = _mm_set1_epi32 ( 0xff ) ; / / to preserve alpha const __m128i all_0xff = _mm_set_epi32 ( 0 0 ~ 0 ~ 0 ) ; __m128i all_alphas = all_0xff ; / / We must be able to access 3 extra bytes after the last written byte / / ' src [ 4 * width - 4 ] ' because we don ' t know if alpha is the first or the / / last byte of the quadruplet . const int limit = ( width - 1 ) & ~ 7 ; for ( j = 0 ; j < height ; + + j ) { const __m128i * src = ( const __m128i * ) argb ; for ( i = 0 ; i < limit ; i + = 8 ) { / / load 32 argb bytes const __m128i a0 = _mm_loadu_si128 ( src + 0 ) ; const __m128i a1 = _mm_loadu_si128 ( src + 1 ) ; const __m128i b0 = _mm_and_si128 ( a0 a_mask ) ; const __m128i b1 = _mm_and_si128 ( a1 a_mask ) ; const __m128i c0 = _mm_packs_epi32 ( b0 b1 ) ; const __m128i d0 = _mm_packus_epi16 ( c0 c0 ) ; / / store _mm_storel_epi64 ( ( __m128i * ) & alpha [ i ] d0 ) ; / / accumulate eight alpha ' and ' in parallel all_alphas = _mm_and_si128 ( all_alphas d0 ) ; src + = 2 ; } for ( ; i < width ; + + i ) { const uint32_t alpha_value = argb [ 4 * i ] ; alpha [ i ] = alpha_value ; alpha_and & = alpha_value ; } argb + = argb_stride ; alpha + = alpha_stride ; } / / Combine the eight alpha ' and ' into a 8 - bit mask . alpha_and & = _mm_movemask_epi8 ( _mm_cmpeq_epi8 ( all_alphas all_0xff ) ) ; return ( alpha_and = = 0xff ) ; } / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Non - dither premultiplied modes # define MULTIPLIER ( a ) ( ( a ) * 0x8081 ) # define PREMULTIPLY ( x m ) ( ( ( x ) * ( m ) ) > > 23 ) / / We can ' t use a ' const int ' for the SHUFFLE value because it has to be an / / immediate in the _mm_shufflexx_epi16 ( ) instruction . We really need a macro . / / We use : v / 255 = ( v * 0x8081 ) > > 23 where v = alpha * { r g b } is a 16bit / / value . # define APPLY_ALPHA ( RGBX SHUFFLE ) do { \ const __m128i argb0 = _mm_loadu_si128 ( ( const __m128i * ) & ( RGBX ) ) ; \ const __m128i argb1_lo = _mm_unpacklo_epi8 ( argb0 zero ) ; \ const __m128i argb1_hi = _mm_unpackhi_epi8 ( argb0 zero ) ; \ const __m128i alpha0_lo = _mm_or_si128 ( argb1_lo kMask ) ; \ const __m128i alpha0_hi = _mm_or_si128 ( argb1_hi kMask ) ; \ const __m128i alpha1_lo = _mm_shufflelo_epi16 ( alpha0_lo SHUFFLE ) ; \ const __m128i alpha1_hi = _mm_shufflelo_epi16 ( alpha0_hi SHUFFLE ) ; \ const __m128i alpha2_lo = _mm_shufflehi_epi16 ( alpha1_lo SHUFFLE ) ; \ const __m128i alpha2_hi = _mm_shufflehi_epi16 ( alpha1_hi SHUFFLE ) ; \ / * alpha2 = [ ff a0 a0 a0 ] [ ff a1 a1 a1 ] * / \ const __m128i A0_lo = _mm_mullo_epi16 ( alpha2_lo argb1_lo ) ; \ const __m128i A0_hi = _mm_mullo_epi16 ( alpha2_hi argb1_hi ) ; \ const __m128i A1_lo = _mm_mulhi_epu16 ( A0_lo kMult ) ; \ const __m128i A1_hi = _mm_mulhi_epu16 ( A0_hi kMult ) ; \ const __m128i A2_lo = _mm_srli_epi16 ( A1_lo 7 ) ; \ const __m128i A2_hi = _mm_srli_epi16 ( A1_hi 7 ) ; \ const __m128i A3 = _mm_packus_epi16 ( A2_lo A2_hi ) ; \ _mm_storeu_si128 ( ( __m128i * ) & ( RGBX ) A3 ) ; \ } while ( 0 ) static void ApplyAlphaMultiply_SSE2 ( uint8_t * rgba int alpha_first int w int h int stride ) { const __m128i zero = _mm_setzero_si128 ( ) ; const __m128i kMult = _mm_set1_epi16 ( ( short ) 0x8081 ) ; const __m128i kMask = _mm_set_epi16 ( 0 0xff 0xff 0 0 0xff 0xff 0 ) ; const int kSpan = 4 ; while ( h - - > 0 ) { uint32_t * const rgbx = ( uint32_t * ) rgba ; int i ; if ( ! alpha_first ) { for ( i = 0 ; i + kSpan < = w ; i + = kSpan ) { APPLY_ALPHA ( rgbx [ i ] _MM_SHUFFLE ( 2 3 3 3 ) ) ; } } else { for ( i = 0 ; i + kSpan < = w ; i + = kSpan ) { APPLY_ALPHA ( rgbx [ i ] _MM_SHUFFLE ( 0 0 0 1 ) ) ; } } / / Finish with left - overs . for ( ; i < w ; + + i ) { uint8_t * const rgb = rgba + ( alpha_first ? 1 : 0 ) ; const uint8_t * const alpha = rgba + ( alpha_first ? 0 : 3 ) ; const uint32_t a = alpha [ 4 * i ] ; if ( a ! = 0xff ) { const uint32_t mult = MULTIPLIER ( a ) ; rgb [ 4 * i + 0 ] = PREMULTIPLY ( rgb [ 4 * i + 0 ] mult ) ; rgb [ 4 * i + 1 ] = PREMULTIPLY ( rgb [ 4 * i + 1 ] mult ) ; rgb [ 4 * i + 2 ] = PREMULTIPLY ( rgb [ 4 * i + 2 ] mult ) ; } } rgba + = stride ; } } # undef MULTIPLIER # undef PREMULTIPLY / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Alpha detection static int HasAlpha8b_SSE2 ( const uint8_t * src int length ) { const __m128i all_0xff = _mm_set1_epi8 ( ( char ) 0xff ) ; int i = 0 ; for ( ; i + 16 < = length ; i + = 16 ) { const __m128i v = _mm_loadu_si128 ( ( const __m128i * ) ( src + i ) ) ; const __m128i bits = _mm_cmpeq_epi8 ( v all_0xff ) ; const int mask = _mm_movemask_epi8 ( bits ) ; if ( mask ! = 0xffff ) return 1 ; } for ( ; i < length ; + + i ) if ( src [ i ] ! = 0xff ) return 1 ; return 0 ; } static int HasAlpha32b_SSE2 ( const uint8_t * src int length ) { const __m128i alpha_mask = _mm_set1_epi32 ( 0xff ) ; const __m128i all_0xff = _mm_set1_epi8 ( ( char ) 0xff ) ; int i = 0 ; / / We don ' t know if we can access the last 3 bytes after the last alpha / / value ' src [ 4 * length - 4 ] ' ( because we don ' t know if alpha is the first / / or the last byte of the quadruplet ) . Hence the ' - 3 ' protection below . length = length * 4 - 3 ; / / size in bytes for ( ; i + 64 < = length ; i + = 64 ) { const __m128i a0 = _mm_loadu_si128 ( ( const __m128i * ) ( src + i + 0 ) ) ; const __m128i a1 = _mm_loadu_si128 ( ( const __m128i * ) ( src + i + 16 ) ) ; const __m128i a2 = _mm_loadu_si128 ( ( const __m128i * ) ( src + i + 32 ) ) ; const __m128i a3 = _mm_loadu_si128 ( ( const __m128i * ) ( src + i + 48 ) ) ; const __m128i b0 = _mm_and_si128 ( a0 alpha_mask ) ; const __m128i b1 = _mm_and_si128 ( a1 alpha_mask ) ; const __m128i b2 = _mm_and_si128 ( a2 alpha_mask ) ; const __m128i b3 = _mm_and_si128 ( a3 alpha_mask ) ; const __m128i c0 = _mm_packs_epi32 ( b0 b1 ) ; const __m128i c1 = _mm_packs_epi32 ( b2 b3 ) ; const __m128i d = _mm_packus_epi16 ( c0 c1 ) ; const __m128i bits = _mm_cmpeq_epi8 ( d all_0xff ) ; const int mask = _mm_movemask_epi8 ( bits ) ; if ( mask ! = 0xffff ) return 1 ; } for ( ; i + 32 < = length ; i + = 32 ) { const __m128i a0 = _mm_loadu_si128 ( ( const __m128i * ) ( src + i + 0 ) ) ; const __m128i a1 = _mm_loadu_si128 ( ( const __m128i * ) ( src + i + 16 ) ) ; const __m128i b0 = _mm_and_si128 ( a0 alpha_mask ) ; const __m128i b1 = _mm_and_si128 ( a1 alpha_mask ) ; const __m128i c = _mm_packs_epi32 ( b0 b1 ) ; const __m128i d = _mm_packus_epi16 ( c c ) ; const __m128i bits = _mm_cmpeq_epi8 ( d all_0xff ) ; const int mask = _mm_movemask_epi8 ( bits ) ; if ( mask ! = 0xffff ) return 1 ; } for ( ; i < = length ; i + = 4 ) if ( src [ i ] ! = 0xff ) return 1 ; return 0 ; } static void AlphaReplace_SSE2 ( uint32_t * src int length uint32_t color ) { const __m128i m_color = _mm_set1_epi32 ( ( int ) color ) ; const __m128i zero = _mm_setzero_si128 ( ) ; int i = 0 ; for ( ; i + 8 < = length ; i + = 8 ) { const __m128i a0 = _mm_loadu_si128 ( ( const __m128i * ) ( src + i + 0 ) ) ; const __m128i a1 = _mm_loadu_si128 ( ( const __m128i * ) ( src + i + 4 ) ) ; const __m128i b0 = _mm_srai_epi32 ( a0 24 ) ; const __m128i b1 = _mm_srai_epi32 ( a1 24 ) ; const __m128i c0 = _mm_cmpeq_epi32 ( b0 zero ) ; const __m128i c1 = _mm_cmpeq_epi32 ( b1 zero ) ; const __m128i d0 = _mm_and_si128 ( c0 m_color ) ; const __m128i d1 = _mm_and_si128 ( c1 m_color ) ; const __m128i e0 = _mm_andnot_si128 ( c0 a0 ) ; const __m128i e1 = _mm_andnot_si128 ( c1 a1 ) ; _mm_storeu_si128 ( ( __m128i * ) ( src + i + 0 ) _mm_or_si128 ( d0 e0 ) ) ; _mm_storeu_si128 ( ( __m128i * ) ( src + i + 4 ) _mm_or_si128 ( d1 e1 ) ) ; } for ( ; i < length ; + + i ) if ( ( src [ i ] > > 24 ) = = 0 ) src [ i ] = color ; } / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Apply alpha value to rows static void MultARGBRow_SSE2 ( uint32_t * const ptr int width int inverse ) { int x = 0 ; if ( ! inverse ) { const int kSpan = 2 ; const __m128i zero = _mm_setzero_si128 ( ) ; const __m128i k128 = _mm_set1_epi16 ( 128 ) ; const __m128i kMult = _mm_set1_epi16 ( 0x0101 ) ; const __m128i kMask = _mm_set_epi16 ( 0 0xff 0 0 0 0xff 0 0 ) ; for ( x = 0 ; x + kSpan < = width ; x + = kSpan ) { / / To compute ' result = ( int ) ( a * x / 255 . + . 5 ) ' we use : / / tmp = a * v + 128 result = ( tmp * 0x0101u ) > > 16 const __m128i A0 = _mm_loadl_epi64 ( ( const __m128i * ) & ptr [ x ] ) ; const __m128i A1 = _mm_unpacklo_epi8 ( A0 zero ) ; const __m128i A2 = _mm_or_si128 ( A1 kMask ) ; const __m128i A3 = _mm_shufflelo_epi16 ( A2 _MM_SHUFFLE ( 2 3 3 3 ) ) ; const __m128i A4 = _mm_shufflehi_epi16 ( A3 _MM_SHUFFLE ( 2 3 3 3 ) ) ; / / here A4 = [ ff a0 a0 a0 ] [ ff a1 a1 a1 ] const __m128i A5 = _mm_mullo_epi16 ( A4 A1 ) ; const __m128i A6 = _mm_add_epi16 ( A5 k128 ) ; const __m128i A7 = _mm_mulhi_epu16 ( A6 kMult ) ; const __m128i A10 = _mm_packus_epi16 ( A7 zero ) ; _mm_storel_epi64 ( ( __m128i * ) & ptr [ x ] A10 ) ; } } width - = x ; if ( width > 0 ) WebPMultARGBRow_C ( ptr + x width inverse ) ; } static void MultRow_SSE2 ( uint8_t * WEBP_RESTRICT const ptr const uint8_t * WEBP_RESTRICT const alpha int width int inverse ) { int x = 0 ; if ( ! inverse ) { const __m128i zero = _mm_setzero_si128 ( ) ; const __m128i k128 = _mm_set1_epi16 ( 128 ) ; const __m128i kMult = _mm_set1_epi16 ( 0x0101 ) ; for ( x = 0 ; x + 8 < = width ; x + = 8 ) { const __m128i v0 = _mm_loadl_epi64 ( ( __m128i * ) & ptr [ x ] ) ; const __m128i a0 = _mm_loadl_epi64 ( ( const __m128i * ) & alpha [ x ] ) ; const __m128i v1 = _mm_unpacklo_epi8 ( v0 zero ) ; const __m128i a1 = _mm_unpacklo_epi8 ( a0 zero ) ; const __m128i v2 = _mm_mullo_epi16 ( v1 a1 ) ; const __m128i v3 = _mm_add_epi16 ( v2 k128 ) ; const __m128i v4 = _mm_mulhi_epu16 ( v3 kMult ) ; const __m128i v5 = _mm_packus_epi16 ( v4 zero ) ; _mm_storel_epi64 ( ( __m128i * ) & ptr [ x ] v5 ) ; } } width - = x ; if ( width > 0 ) WebPMultRow_C ( ptr + x alpha + x width inverse ) ; } / / - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - / / Entry point extern void WebPInitAlphaProcessingSSE2 ( void ) ; WEBP_TSAN_IGNORE_FUNCTION void WebPInitAlphaProcessingSSE2 ( void ) { WebPMultARGBRow = MultARGBRow_SSE2 ; WebPMultRow = MultRow_SSE2 ; WebPApplyAlphaMultiply = ApplyAlphaMultiply_SSE2 ; WebPDispatchAlpha = DispatchAlpha_SSE2 ; WebPDispatchAlphaToGreen = DispatchAlphaToGreen_SSE2 ; WebPExtractAlpha = ExtractAlpha_SSE2 ; WebPHasAlpha8b = HasAlpha8b_SSE2 ; WebPHasAlpha32b = HasAlpha32b_SSE2 ; WebPAlphaReplace = AlphaReplace_SSE2 ; } # else / / ! WEBP_USE_SSE2 WEBP_DSP_INIT_STUB ( WebPInitAlphaProcessingSSE2 ) # endif / / WEBP_USE_SSE2
188c9266b0a9a33d374ad848605abc6656881861
1805b121e438a9d0cbb876afb9a9bf93f93388ec
/lib/my/my_find_prime_sup.c
7aa7dd0821e955e1d641f57217d1c3226d3e7026
[]
no_license
vitali-droujko/my_printf
309ab36bae48f7a3c8e06f1fb29d630aedfae80f
b7c72ef0006e3ef821b773b09fd4df735e7c208e
refs/heads/master
2023-02-20T17:31:49.128438
2021-01-23T13:44:33
2021-01-23T13:44:33
332,219,522
1
0
null
null
null
null
UTF-8
C
false
false
302
c
my_find_prime_sup.c
/* ** EPITECH PROJECT, 2020 ** myfindprimesup ** File description: ** disp fisrt nbp > parameter */ int my_is_prime(int nb); int my_find_prime_sup(int nb) { int l; l = my_is_prime(nb); if (l == 1) { return (nb); } else { return (my_find_prime_sup(nb + 1)); } }
ad7b2dce8678099c94a859885cc892dc1fe0d2a0
ac1069785adfece21fea89b943debbd0be7cae6d
/libft/ft_putstr.c
f9025bd1ad31bc9727258a1621ec824494bc3288
[]
no_license
Alienosaurus/fract_ol
a21d07b57297fab21db5da3181cdad9466da8419
0b78221427396a58f5ebae3ed5bdb450d38c9787
refs/heads/master
2021-01-19T16:10:39.873994
2017-04-14T09:18:36
2017-04-14T09:18:36
88,253,156
0
0
null
null
null
null
UTF-8
C
false
false
974
c
ft_putstr.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_putstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adenece <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/02/23 09:44:27 by adenece #+# #+# */ /* Updated: 2016/02/23 09:44:32 by adenece ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" void ft_putstr(char const *s) { write(1, s, ft_strlen(s)); }
ee4254957edfa4f4c0e866bee305082601c38008
fcab201b38eae05d35c2fcdb67142e2ef6226771
/src/ft_dblstnew.c
b6066dcbde8bf818bb61b5de56b5ca5fe1b0b55d
[]
no_license
BimManager/libft
97587c1027e038eaf65a677a264635a5ae609d50
8505c4e33e694ccd177374d033ee1177e06efbbc
refs/heads/master
2021-06-22T14:29:29.049096
2020-12-15T15:04:01
2020-12-15T15:04:01
158,298,031
0
0
null
null
null
null
UTF-8
C
false
false
1,042
c
ft_dblstnew.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_dblstnew.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kkozlov <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/13 14:56:49 by kkozlov #+# #+# */ /* Updated: 2020/01/17 11:43:29 by kkozlov ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" t_dblst *ft_dblstnew(void) { t_dblst *lst; lst = malloc(sizeof(t_dblst)); lst->head = NULL; lst->elems = 0; return (lst); }
f0ba80b03d244a28f0fdf69f913874083ff6dc06
0ec4035630f2f4b34662c978e6b8056edfa2b647
/ch6/ch6ex2.c
fd39de3360420c81c50fa76abb203adfe020e6a8
[]
no_license
pithecuse527/System-Programming
12f047619e5130adabcaf459e83266cc1f2ebd28
17924396d2a4c9619a11ca74d6b27315f692289f
refs/heads/main
2023-01-30T03:56:44.809455
2020-12-08T06:38:47
2020-12-08T06:38:47
301,731,445
0
0
null
null
null
null
UTF-8
C
false
false
695
c
ch6ex2.c
#include <stdio.h> #include <time.h> int main() { time_t t; char *ct, buf[80]; struct tm *lt; time(&t); printf("time:\n\t%ld\n", t); ct = ctime(&t); printf("ctime:\n\t%s", ct); lt = localtime(&t); printf("localtime:\n"); printf("\tyear\t:%d\n", lt->tm_year); printf("\tmon\t:%d\n", lt->tm_mon); printf("\tday\t:%d\n", lt->tm_mday); printf("\thour\t:%d\n", lt->tm_hour); printf("\tminute\t:%d\n", lt->tm_min); printf("\tsecond\t:%d\n", lt->tm_sec); printf("\tweekday\t:%d\n", lt->tm_wday); printf("\tyear day\t:%d\n", lt->tm_yday); strftime(buf, 80, "%A\t%B\t%c", lt); printf("strftime:\n\t%s\n", buf); }
a0c7c1cdf9fa27670b3fb0cab501230bb0f2e74e
eef28e9a779390d94818da0b7347b85901f27c02
/main.c
ef901d09cfda502a6554525e42413b39a2134d40
[]
no_license
AfikPeretz/myBank.c
64d9003fbfbd90ff5938183b63b06d3de50b1c72
926d135303150f05f85f868dba572f333bebb6d4
refs/heads/main
2023-01-29T05:14:59.661411
2020-12-06T17:10:30
2020-12-06T17:10:30
null
0
0
null
null
null
null
UTF-8
C
false
false
1,373
c
main.c
#include <stdio.h> #include "myBank.h" #include "myBank.c" char choose () { char code; printf("Please choose a transaction type:\n"); printf(" O - Open Account\n B - Balance Inquiry\n D - Deposit\n W - Withdrawal\n C - Close Account\n I - Interest\n P - Print\n E - Exit\n"); scanf("%c",&code); return code; } int main() { //char code; //printf("Please choose a transaction type:\n"); //printf(" O - Open Account\n B - Balance Inquiry\n D - Deposit\n W - Withdrawal\n C - Close Account\n I - Interest\n P - Print\n E - Exit\n"); //scanf("%c",&code); //fflush(stdin); char code = choose(); while( code != 'E') { //fflush(stdin); switch(code) { case 'O': O(); break; case 'B': B(); break; case 'D': D(); break; case 'W': W(); break; case 'C': C(); break; case 'I': I(); break; case 'P': P(); break; case 'E': E(); break; default: printf("Invalid transaction type\n"); } code = choose(); } }
36d486f0fca7fd53cb919d731851b7ef5f757b25
011c88bf8ba57b9a854776b32aac5807f7eca346
/01_lcd_show_char/02_LCD_show_char_freetype/show_free_type.c
106783e4fa21c22f3ac26e584f5e06f8ab7029ea
[ "MIT" ]
permissive
hanbo1990/linux_learning
83fa43bbb86c4c75b5eb64ffd45ff0c51afbcb53
2954271d5b3b2c2847f6e390b17c6f6fad11d948
refs/heads/main
2023-03-14T11:24:06.031947
2021-03-11T18:38:35
2021-03-11T18:38:35
312,201,469
1
0
null
null
null
null
UTF-8
C
false
false
3,738
c
show_free_type.c
#include <fcntl.h> #include <ft2build.h> #include FT_FREETYPE_H #include FT_GLYPH_H #include <linux/fb.h> #include <stddef.h> #include <stdio.h> #include <string.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include "utils/error_functions.h" static int fb_fd; static struct fb_var_screeninfo fb_var; static int line_width_byte, pixel_width, screen_size_byte; static unsigned char *fb_mmap; void lcd_put_pixel(int x, int y, unsigned int color) { unsigned char *pen_8 = fb_mmap + y * line_width_byte + x * pixel_width; unsigned int red, green, blue; unsigned short *pen_16; unsigned int *pen_32; pen_16 = (unsigned short *) pen_8; pen_32 = (unsigned int *) pen_8; switch (fb_var.bits_per_pixel) { case 8: { *pen_8 = color; break; } case 16: { /* 565 */ red = (color >> 16) & 0xff; green = (color >> 8) & 0xff; blue = (color >> 0) & 0xff; color = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3); *pen_16 = color; break; } case 32: { *pen_32 = color; break; } default: { printf("can't surport %dbpp\n", fb_var.bits_per_pixel); break; } } } void draw_bitmap(FT_Bitmap *bitmap, FT_Int x, FT_Int y) { FT_Int i, j, p, q; FT_Int x_max = x + bitmap->width; FT_Int y_max = y + bitmap->rows; for (i = x, p = 0; i < x_max; i++, p++) { for (j = y, q = 0; j < y_max; j++, q++) { if (i < 0 || j < 0 || i >= fb_var.xres || j >= fb_var.yres) continue; lcd_put_pixel(i, j, bitmap->buffer[q * bitmap->width + p]); } } } int main(void) { /* Step 1: open the LCD controller */ fb_fd = open("/dev/fb0", O_RDWR); if (-1 == fb_fd) { errExit("opening LCD device"); } /* Step 2: get the LCD configuration, resolution and BPP */ if (-1 == ioctl(fb_fd, FBIOGET_VSCREENINFO, &fb_var)) { (void) close(fb_fd); errExit("failed getting ctl for fb0"); } pixel_width = fb_var.bits_per_pixel / 8; line_width_byte = fb_var.xres * pixel_width; screen_size_byte = line_width_byte * fb_var.yres; /* Step 3: map the framebuffer and write data to frambuffer */ fb_mmap = (unsigned char *) mmap(NULL, screen_size_byte, PROT_READ | PROT_WRITE, MAP_SHARED, fb_fd, 0); if ((unsigned char *) -1 == fb_mmap) { (void) close(fb_fd); errExit("failed to memory map to fb0"); } memset(fb_mmap, 0, screen_size_byte); close(fb_fd); FT_Library library; FT_Error error; FT_Face face; FT_GlyphSlot slot; wchar_t *chinese_str = L"意"; // prepare /* init library */ error = FT_Init_FreeType(&library); /* error handling omitted */ /* Create new face which loads the font file */ error = FT_New_Face(library, "simsun.ttc", 0, &face); /* error handling omitted */ /* generated bitmap will be inside the slot */ slot = face->glyph; // Create bit map for the characters to show /* set font size */ error = FT_Set_Pixel_Sizes(face, 50, 0); /* error handling omitted */ /* 1. Get glyph index based on the encoding 2. Get glyph based on index 3. Render the bitmap --> after this function, slot->bitmap contains the rendered data */ error = FT_Load_Char(face, chinese_str[0], FT_LOAD_RENDER); /* error handling omitted */ /* you can create bitmap which contains more complex data. */ draw_bitmap(&slot->bitmap, fb_var.xres / 2, fb_var.yres / 2); munmap(fb_mmap, screen_size_byte); return 0; }
7e3991f65454bda64b64275906d234a76aaaee1c
be6b8bb6eaee52846445ad102580200a4fe6f379
/Assignment6/test2.c
1f779e9d5954aad863e396645e76656dcecbf2fa
[]
no_license
ParrotPotato/Tiny-C
0cf094d9d95ce24a40b49df546a627a653d57680
ee4bb2cdb43c40b64fe37b3782094512d14729e1
refs/heads/master
2020-04-24T20:22:17.767384
2019-02-23T17:14:12
2019-02-23T17:14:12
null
0
0
null
null
null
null
UTF-8
C
false
false
502
c
test2.c
void swap(int *a,int *b); int main() { int a; int b; int err; printStr("Enter the value of a:"); a = readi(&err); printStr("Enter the value of b:"); b = readi(&err); swap(&a,&b); printStr("Swapping the values of a and b by passing into a function as reference\n"); printStr("The value of a:"); printInt(a); printStr("\n"); printStr("The value of b:"); printInt(b); printStr("\n"); return 0; } void swap(int *a,int *b) { int temp; temp = *a; *a = *b; *b = temp; return; }
98590a60a59fae150e97dcc3ae853fba722d442f
a1446c3f95df2dfe097a9bd6b463767b00f18140
/regress/usr.bin/xlint/test-3.c
a9d63e2e4741d07256893fb23ec6cdc0be3317ea
[]
no_license
chrissicool/l4openbsd
e2fb756debc1c3bdc1c2da509fa228c25a3185e8
077177814444e08500e47bc2488502f11469bc60
refs/heads/master
2021-04-09T17:12:53.122136
2011-08-22T16:52:58
2011-08-22T16:52:58
1,706,491
18
4
null
2017-04-06T19:17:29
2011-05-05T14:08:03
C
UTF-8
C
false
false
348
c
test-3.c
/* $OpenBSD: test-3.c,v 1.1 2005/11/23 20:38:58 cloder Exp $ */ /* * Placed in the public domain by Chad Loder <cloder@openbsd.org>. * * Test parsing of "inline" keyword. */ static inline int foo(void); static inline int foo(void) { return 0; } /* ARGSUSED */ int main(int argc, char* argv[]) { int i; i = foo(); i++; return 0; }
b5164054096ed48617b6b62ffbf55c5b6d6a1288
803898f95f34521f4fc08ff42534888367ff4028
/extlibs/AODT/v72/odtmcidas/navcal/navcal/lwfile_.c
c61a493a71e07a6878bd669b69f74c362605fad8
[ "BSD-3-Clause" ]
permissive
Unidata/gempak
17057d45ad92512f56193155dd0d6ad0301965d8
f3997c88469be1c08cd265ef553c812a28778284
refs/heads/main
2023-07-13T19:39:57.114715
2023-06-23T10:11:23
2023-06-23T10:11:23
4,715,296
53
29
BSD-3-Clause
2023-06-23T10:11:24
2012-06-19T15:15:17
C
UTF-8
C
false
false
884
c
lwfile_.c
/* * Copyright(c) 1997, Space Science and Engineering Center, UW-Madison * Refer to "McIDAS Software Acquisition and Distribution Policies" * in the file mcidas/data/license.txt * *** $Id: lwfile_.c,v 1.2 2000/08/18 22:42:01 gad Exp $ *** */ /* GAD stub for windco cal routines 7/6/00 */ #include <stdio.h> #include "mcidas.h" /* *$ Name: *$ lwfile - Checks to see that a file exists. *$ *$ Interface: *$ integer function *$ lwfile(character*(*) c) *$ *$ Input: *$ c - Name of the file being investigated. *$ *$ Input and Output: *$ none *$ *$ Output: *$ none *$ *$ Return values: *$ 1 - The file exists. *$ 0 - The file does not exist. *$ *$ Remarks: *$ none *$ *$ Categories: *$ file */ Fint lwfile_(const char *file, FsLen i) { /* printf("\nCall to lwfile to check existence of %s",file); */ return 1; }
b591a7e542ac5c9a633d33b3da57a131f05cf4d4
f5012337084af8f3b4f80ae8284119a66c4844a8
/lab3/src/irq.c
1b0dddf57f44794d8b0994f75fa7fb6fdf94ea26
[ "MIT" ]
permissive
sajochiu/osdi2020
e58f5ba19f5a3b7e5b6d412162e4ea97d938579b
7ac8ae51e6fa1fe46534dcf707e79395a31abc6f
refs/heads/master
2021-03-06T07:30:15.005870
2020-05-16T12:39:28
2020-05-16T12:39:28
246,188,707
4
0
MIT
2020-03-10T02:23:14
2020-03-10T02:23:14
null
UTF-8
C
false
false
5,993
c
irq.c
#include "utils.h" #include "printf.h" #include "timer.h" #include "entry.h" #include "peripherals.h" #include "tools.h" #include "uart.h" #include "irq.h" const char *entry_error_messages[] = { "SYNC_INVALID_EL1t", "IRQ_INVALID_EL1t", "FIQ_INVALID_EL1t", "ERROR_INVALID_EL1T", "SYNC_INVALID_EL1h", "IRQ_INVALID_EL1h", "FIQ_INVALID_EL1h", "ERROR_INVALID_EL1h", "SYNC_INVALID_EL0_64", "IRQ_INVALID_EL0_64", "FIQ_INVALID_EL0_64", "ERROR_INVALID_EL0_64", "SYNC_INVALID_EL0_32", "IRQ_INVALID_EL0_32", "FIQ_INVALID_EL0_32", "ERROR_INVALID_EL0_32" }; // include/irq.h void enable_timer1_interrupt_controller(){ // set bit 1(system timer match 1) put32(ENABLE_IRQS_1, SYSTEM_TIMER_IRQ_1); } // src/entry.S : handle_invalid_entry_type void show_invalid_entry_message(int type, unsigned long esr, unsigned long address){ char buf_address[100]; char buf_ec[100]; char buf_iss[100]; itoa(address, buf_address, 10); uart_puts("Exception return address: 0x"); //uart_puts(buf_address); uart_hex(address); uart_puts("\n"); itoa((esr & 0xFC000000) >> 26, buf_ec, 10); uart_puts("Exception class (EC): 0x"); //uart_puts(buf_ec); uart_hex((esr & 0xFC000000) >> 26); uart_puts("\n"); itoa((esr & 0x01FFFFFF), buf_iss, 10); uart_puts("Instruction specific syndrome (ISS): 0x"); //uart_puts(buf_iss); uart_hex((esr & 0x01FFFFFF)); uart_puts("\n"); /* if(type == -1){ uart_puts("entry error message: "); uart_puts(entry_error_messages[type]); uart_puts("\n"); uart_puts("ESR: "); itoa(esr, buf_esr, 10); uart_puts(buf_esr); uart_puts("\n"); itoa(address, buf_address, 10); uart_puts("address: "); uart_puts(buf_address); uart_puts("\n"); } */ } void print_system_registers(){ unsigned int elr_el1, elr_el2, elr_el3; unsigned int esr_el1, esr_el2, esr_el3; unsigned int currentel, daif, nzcv, spsel; char buf[100]; asm volatile("mrs %0, elr_el1\n" : "=r"(elr_el1)); itoa(elr_el1, buf, 10); uart_puts("ELR_EL1: 0x"); //uart_puts(buf); uart_hex(elr_el1); uart_puts("\n"); /* asm volatile("mrs %0, elr_el2\n" : "=r"(elr_el2)); itoa(elr_el2, buf, 10); uart_puts("ELR_EL2: "); uart_puts(buf); uart_puts("\n"); asm volatile("mrs %0, elr_el3\n" : "=r"(elr_el3)); itoa(elr_el3, buf, 10); uart_puts("ELR_EL3: "); uart_puts(buf); uart_puts("\n"); */ asm volatile("mrs %0, esr_el1\n" : "=r"(esr_el1)); itoa(esr_el1, buf, 10); uart_puts("ESR_EL1: 0x"); //uart_puts(buf); uart_hex(esr_el1); uart_puts("\n"); /* asm volatile("mrs %0, esr_el2\n" : "=r"(esr_el2)); itoa(esr_el2, buf, 10); uart_puts("ESR_EL2: "); uart_puts(buf); uart_puts("\n"); asm volatile("mrs %0, esr_el3\n" : "=r"(esr_el3)); itoa(esr_el3, buf, 10); uart_puts("ESR_EL3: "); uart_puts(buf); uart_puts("\n"); */ asm volatile("mrs %0, CurrentEL\n" : "=r"(currentel)); currentel = currentel >> 2; itoa(currentel, buf, 10); uart_puts("CURRENT EXCEPTION LEVEL: "); uart_puts(buf); uart_puts("\n"); asm volatile("mrs %0, DAIF\n" : "=r"(daif)); itoa(daif, buf, 10); uart_puts("DAIF: "); uart_puts(buf); uart_puts("\n"); asm volatile("mrs %0, NZCV\n" : "=r"(nzcv)); itoa(nzcv, buf, 10); uart_puts("NZCV: "); uart_puts(buf); uart_puts("\n"); asm volatile("mrs %0, SPSel\n" : "=r"(spsel)); itoa(spsel, buf, 10); uart_puts("SPSEL: "); uart_puts(buf); uart_puts("\n"); } // src/entry.S : el1_irq void handle_irq(void){ unsigned int irq = get32(IRQ_PENDING_1); switch (irq) { case (SYSTEM_TIMER_IRQ_1): uart_puts("System timer 1\n"); break; default: uart_puts("Unknown pending irq: XXX\n"); //printf("Unknown pending irq: %x\r\n", irq); } } // src/entry.S vector void test_handler_sync_invalid_el0_64(void){ uart_puts("sync invalid el0 64\n"); } // src/entry.S vector void test_handler_irq_invalid_el0_64(void){ uart_puts("irq invalid el0 64\n"); } void system_call(unsigned int syscall_number){ if(syscall_number == 1){ // core timer enable core_timer_enable(); }else if(syscall_number == 2){ uart_puts("system call 2 test\n"); }else if(syscall_number == 3){ print_system_registers(); }else{ uart_puts("no such system call number!\n"); } return; } // src/entry.S vector entry 9th void sync_el0_64_handler(int x0, int x1, int x2, int x3, int x4, int x5){ unsigned int elr_el1; unsigned int esr_el1; unsigned int syscall_number; // read the system call number asm volatile("mrs %0, elr_el1\n" : "=r"(elr_el1)); // exception return address asm volatile("mrs %0, esr_el1\n" : "=r"(esr_el1)); // read the exception class asm volatile("mov %0, x8\n" : "=r"(syscall_number)); // system call number is saved in x8 register if(( (esr_el1 & 0xFC000000) >> 26) == 0x15){ // SVC instruction execution in AArch64 state //uart_puts("esr_el1: "); //uart_hex(esr_el1); //uart_puts("\n"); // svc #0: 0x56000000 // svc #1: 0x56000001 if((esr_el1 == 0x56000000)){ system_call(syscall_number); return; }else{ show_invalid_entry_message(-1, esr_el1, elr_el1); } }else{ // pass } } // src/entry.S vector entry 10th void irq_el0_64_handler(){ static unsigned long core_timer_number = 1; static unsigned long local_timer_number = 1; char buf_core_timer_number[1000]; char buf_local_timer_number[1000]; unsigned int IRQ_SOURCE = *((volatile unsigned int*)CORE0_IRQ_SOURCE); // bit 1: CNTPNSIRQ interrupt if(IRQ_SOURCE == 0x00000002){ // core timer IRQ_SOURCE: 2 core_timer_handler(); uart_puts("Core timer interrupt, jiffies "); itoa(core_timer_number, buf_core_timer_number, 10); uart_puts(buf_core_timer_number); uart_puts("\n"); core_timer_number++; return; } // bit 11: Local timer interrupt if(IRQ_SOURCE == 0x00000800){ // local timer IRQ_SOURCE: 2048 local_timer_handler(); uart_puts("Local timer interrupt, jiffies "); itoa(local_timer_number, buf_local_timer_number, 10); uart_puts(buf_local_timer_number); uart_puts("\n"); local_timer_number++; return; } }
8578639204713e70bbe9f304870c2524ceecbf1b
27678cf0f157b8fc2cc2c7e0602a8cda99812cbd
/gnl/libft/ft_strchr.c
04093eeb16aa390df4a8a53455e9e4998e1a5e58
[]
no_license
dashawebb/42
b3074c018ab366e7b181dac2cab0903388507609
a65fc1387ec2616a527deefd1ead43e0682333cf
refs/heads/master
2020-04-09T13:21:08.887018
2019-11-12T14:06:32
2019-11-12T14:06:32
160,370,425
0
1
null
null
null
null
UTF-8
C
false
false
1,137
c
ft_strchr.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strchr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: creek <creek@student.42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2018/12/01 19:18:05 by creek #+# #+# */ /* Updated: 2018/12/11 14:02:57 by creek ### ########.fr */ /* */ /* ************************************************************************** */ #include <string.h> char *ft_strchr(const char *s, int c) { char c1; char *s1; s1 = (char *)s; c1 = (char)c; if (*s1 == c1) return (s1); while (*s1++ != '\0') { if (*s1 == c1) { return (s1); break ; } } return (NULL); }
a9c68c9880be84054d9e7a60001c5556a0f668b8
0e21fd8d20fa2add8bf12a858479043cf4c5e3d2
/lab_7/2.c
4ef6cac950dd35e66206eaa6497bcd3e7ab52922
[]
no_license
sebalol1/C
75b2ab951e4d947807e44ce2bfd6c78828af2abc
29e25d85634df9ae8178fd93eb90979e1c63ea8c
refs/heads/master
2020-12-24T13:44:45.663687
2014-12-14T10:18:41
2014-12-14T10:18:41
null
0
0
null
null
null
null
UTF-8
C
false
false
185
c
2.c
#include <stdio.h> void zamien(int *x, int *y) { int tmp = *x; *x=*y; *y=tmp; } int main() { int a=5,b=1; zamien(&a,&b); printf("a=%d a b = %d \n", a,b); return 0; }
2be280efe50a3fe7af91ede7cf240c928f05fb05
f26ecbec1b129445a0fb233eecd872df5c522d04
/vrt_server_v2.c
486b1e43763c6750966e4e71b465ec1164e03ba8
[]
no_license
badril1978/vrt
1ecdd378ebadbd7fe8943016fed951ee1a3e7c54
81b6311a0900a1064ee41adba97a65a39e7c7540
refs/heads/master
2020-04-14T02:53:46.482971
2019-11-28T16:03:05
2019-11-28T16:03:05
163,594,862
0
0
null
2019-11-28T16:03:07
2018-12-30T14:51:09
null
UTF-8
C
false
false
9,137
c
vrt_server_v2.c
/* Last Update : 17Nov2017 Notes : vrt_server_manual.c (No sensor - dummy data) - has dual mode (auto/manual) - auto - server send CropCircle data to client - manual- client send data to set the calibrator - has interrupt handler (PAUSE/STOP/RESUME) - PAUSE - put server send() in halt - STOP - exit system - RESUME - continue - server shall receive continuous message from client using recvfrom() in the following format: "start(1/0),pause(1/0),gps-x(float),gps-y(float),manual(1/0),app-rate(int)". */ ////////////////////////////////////////////////////////////////////////////// #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> /*Unix Standard Definitions*/ #include <termios.h> /*Posix Terminal Control Definitions*/ #include <fcntl.h> /*File Control Definitions*/ #include <errno.h> /*Error Number Definitions*/ #include <arpa/inet.h> #include <sys/socket.h> #include <time.h> #include <stdbool.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/time.h> #define PORT_SENSOR "/dev/ttyS5" #define PORT_CALIBRATOR "/dev/ttyS7" #define PORT_UDP 4445 #define BUFLEN 512 #define Ntime 1 ////////////////////////////////////////////////////////////////////////////// int die (char *s) { perror(s); exit(-1); } ////////////////////////////////////////////////////////////////////////////// int port_sensor(void) { int port; port = open(PORT_SENSOR,O_RDWR | O_NOCTTY | O_NDELAY); if (port <1) die("Unable to open port_sensor\n "); else fcntl(port,F_SETFL,0); return (port); } int sensorPortsettings(int fsensor) { struct termios specs; /*Modify port settings*/ cfsetospeed(&specs,B38400); cfsetispeed(&specs,B38400); specs.c_cflag |= (CS8 | CREAD | CLOCAL |CRTSCTS); specs.c_cflag &= ~(PARENB | CSTOPB ); specs.c_lflag |= ICANON; specs.c_iflag |= (IGNPAR | ICRNL); specs.c_oflag = 0; specs.c_cc[VMIN] = 1; specs.c_cc[VTIME]= 0; /*Clear port line and set modified port settings*/ tcflush(fsensor, TCIOFLUSH); if (tcsetattr(fsensor,TCSANOW,&specs) != 0) die("tcsetattr:Unable to set sensorPortsettings"); } ////////////////////////////////////////////////////////////////////////////// int port_calibrator(void) { int port; port = open(PORT_CALIBRATOR,O_RDWR | O_NOCTTY | O_NDELAY); if (port <1) die("Unable to open port_calibrator port\n"); else fcntl(port,F_SETFL,0); return (port); } int calibratorPortsettings (int fcal) { struct termios specs; /*Modify port settings*/ cfsetospeed(&specs,B9600); cfsetispeed(&specs,B9600); specs.c_cflag |= (CS8 | CREAD | CLOCAL); specs.c_cflag &= ~(PARENB | CSTOPB | CRTSCTS); specs.c_iflag &= ~(ICANON | ECHO | ECHOE | ISIG); specs.c_oflag &= ~OPOST; specs.c_cc[VMIN] = 1; specs.c_cc[VTIME]= 0; //--Clear port line and set modified port settings tcflush(fcal, TCIFLUSH); if (tcsetattr(fcal,TCSANOW,&specs) != 0) die("tcsetattr:Unable to set calibratorPortsettings"); } ////////////////////////////////////////////////////////////////////////////// int csum(char *buff) { int len=strlen(buff); int i; if(buff[len-1]=='\n') buff[--len] = '\0'; int csum=0; for(i =0; i<len; i++){ csum=csum^buff[i];} return csum; } ////////////////////////////////////////////////////////////////////////////// int main(void) { /*UDP Socket Variables*/ struct sockaddr_in si_me, si_other; int udp_socket, slen=sizeof(si_other); int recv_len, n, start, pause, manual, app-rate; float gps-x, gps-y; char rbuf[BUFLEN], msg[BUFLEN]; struct timeval tv; tv.tv_sec = 0; tv.tv_usec = 10000; fd_set rset; /*----------------------------------------------------------------------*/ /*Establish Connection*/ /*----------------------------------------------------------------------*/ LOOP: if ((udp_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) die("Unable to create udp_socket\n"); memset((char *)&si_me,0,sizeof(si_me)); memset((char *)&si_other,0,sizeof(si_other)); si_me.sin_family = AF_INET; si_me.sin_port = htons(PORT_UDP); si_me.sin_addr.s_addr = htonl(INADDR_ANY); if ((bind(udp_socket,(struct sockaddr*)&si_me,sizeof(si_me))) == -1) die("Unable to bind udp_socket\n"); printf("Waiting for request..\n"); /*----------------------------------------------------------------------*/ /*Extract Client Info*/ /*----------------------------------------------------------------------*/ bool isExit; int stat; char status[8]; int mode; char modes[8]; //memset(msg,'\0',BUFLEN); //memset(rbuf,'\0',BUFLEN); //keep listening for data while(1) { fflush(stdout); FD_ZERO(&rset); FD_SET(udp_socket, &rset); n = select(udp_socket+1, &rset, 0, 0, &tv); // n = select(s+1, &rset, 0, 0, 0); if(n < 0) { perror("ERROR Server : select()\n"); close(udp_socket); exit(1); } if (FD_ISSET(udp_socket, &rset)) { printf("Server is ready to read\n"); //try to receive some data, this is a blocking call if ((recv_len = recvfrom(udp_socket, rbuf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen)) == -1) { die("recvfrom()"); } //print details of the client/peer and the data received printf("Received packet from %s:%d\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port)); printf("Data: %s\n" ,rbuf); //masukkan code utk start, pause, manual, gps untuk if-conditions di bawah. if(rbuf("start") == 1) //buat parsing ascii data macam baca dari sensor { start = 1; } else { start = 0; } if(rbuf("pause") == 1) //buat parsing ascii data macam baca dari sensor { pause = 1; } else { pause = 0; } if(rbuf(manual) == 1) //buat parsing ascii data macam baca dari sensor { manual = 1; //manual mode } else { manual = 0; //auto mode } gps-x = rbuf(gps-x); // buat parsing ascii data macam baca dari sensor gps-y = rbuf(gps-y); // buat parsing ascii data macam baca dari sensor app-rate = rbuf(app-rate); // buat parsing ascii data macam baca dari sensor FD_CLR(s, &rset); } else { START: if (start == 1) { //masukkan code utk hantar data sensor ke tab di sini. msg(plant-volume) = plant-volume; msg(plant-nitrogen) = plant-nitrogen; if(manual == 1) //manual mode { /*--------------------------------------------------------------*/ /* Manual mode*/ /*--------------------------------------------------------------*/ // set app-rate sebagai calibrator-val. calibrator-val = app-rate; //gunakan variable yg hantar ke calibrator dan tab msg(app-rate) = app-rate; // } else //automode { /*--------------------------------------------------------------*/ /* auto mode*/ /*--------------------------------------------------------------*/ //masukkan automode punye code calibrator-val = model-val; //calculate model value dan set sebagai calibrator value. msg(app-rate) = model-val; } } else //if start == 0 { // set 0 sebagai valuable calibrator. calibrator-val = 0; //gunakan variable yg hantar ke calibrator } if (start == 1 && pause ==0) //hanya hantar data ke client jika start dan bukan pause { if (sendto(udp_socket, msg, recv_len, 0, (struct sockaddr*) &si_other, slen) == -1) { die("sendto()"); } sleep(1); } } memset(&rbuf, 0, sizeof(rbuf)); bzero(rbuf, BUFLEN); memset(&msg, 0, sizeof(msg)); bzero(msg, BUFLEN); } /*----------------------------------------------------------------------*/ /*EXIT*/ /*----------------------------------------------------------------------*/ close(udp_socket); return 0; }
bc3f6041831dbe2dd795382faa7d2e31065d4ac2
3a77c766cf395592a14c1f76730054b0cecff9fb
/PP_bead/multipr/main.c
5d8f388bf1857672f144b09b6d40272100c97528
[]
no_license
domenyb/num
ea4d0f1c6d5d36892625dc24d56757f4f3c4ded8
eba6e44905517bdba2f2fa92c302ec8fe0b7eac6
refs/heads/master
2020-05-31T13:01:40.378902
2019-06-30T12:08:11
2019-06-30T12:08:11
190,294,480
0
0
null
null
null
null
UTF-8
C
false
false
1,166
c
main.c
#include<stdio.h> #include<stdlib.h> #include <math.h> #include <pthread.h> struct pass_param {int a,b; double result;}; void* bar(void* param){ struct pass_param* data = (struct pass_param*)param; int a=data->a; int b=data->b; double x,y,z; int count=0; double pi; for(int i = 0; i<a; i++) { unsigned int seed = time(NULL)+i*b; x=rand_r(&(seed))/(double)RAND_MAX; y=rand_r(&(seed))/(double)RAND_MAX; z=x*x + y*y; if (z<=1) { count++; } } pi=(double)count/a*4; data->result=pi; return 0; } int main(){ int n=1e6; int mid=n/2; struct pass_param data1,data2; data1.a=mid; data2.a=mid; data1.b=1; data2.b=2; pthread_t traad1, traad2; pthread_create(&traad1,NULL,bar,(void*)&data1); pthread_create(&traad2,NULL,bar,(void*)&data2); pthread_join(traad1,NULL); pthread_join(traad2,NULL); printf("my first processor used %d datapoints: %g\n",n/2,data1.result); printf("my second processor used %d datapoints: %g\n",n/2,data2.result); double together=(data1.result+data2.result)/2; printf("after %d datapoints pi is: %g\n",n,together); return 0; }
c40c3f232015e8b967808c78609f853d6671ff7b
e1736892d02704b73f3d227523ac2e246e9a2374
/source/Libraries/nitrofs.c
8e5846e550b7ba1b4ee161e498644a98538c1f6f
[ "BSD-2-Clause" ]
permissive
echojc/osu-ds
4d49130a007d6d67c36d9053b66bfd5ed092133d
f70525ca19fc511667d037db570f60006551bf45
refs/heads/master
2021-12-15T22:20:39.358732
2021-12-06T02:59:36
2021-12-06T02:59:36
20,091,430
30
4
BSD-2-Clause
2021-12-06T02:59:37
2014-05-23T07:56:36
C++
UTF-8
C
false
false
15,187
c
nitrofs.c
/* nitrofs.c - eris's wai ossum nitro filesystem device driver Based on information found at http://frangoassado.org/ds/rom_spec.txt and from the #dsdev ppls Kallisti (K) 2008-01-26 All rights reversed. 2008-05-19 v0.2 - New And Improved!! :DDD * fix'd the fseek SEEK_CUR issue (my fseek funct should not have returned a value :/) * also thx to wintermute's input realized: * if you dont give ndstool the -o wifilogo.bmp option it will run on emulators in gba mode * you then dont need the gba's LOADEROFFSET, so it was set to 0x000 2008-05-21 v0.3 - newer and more improved * fixed some issues with ftell() (again was fseek's fault u_u;;) * fixed possible error in detecting sc.gba files when using dldi * readded support for .gba files in addition to .nds emu * added stat() support for completedness :) 2008-05-22 v0.3.1 - slight update * again fixed fseek(), this time SEEK_END oddly i kinda forgot about it >_> sry * also went ahead and inlined the functions, makes slight proformance improvement 2008-05-26 v0.4 - added chdir * added proper chdir functionality 2008-05-30 v0.5.Turbo - major speed improvement * This version uses a single filehandle to access the .nds file when not in GBA mode improving the speed it takes to open a .nds file by around 106ms. This is great for situations requiring reading alot of seperate small files. However it does take a little bit longer when reading from multiple files simultainously (around 122ms over 10,327 0x100 byte reads between 2 files). 2008-06-09 * Fixed bug with SEEK_END where it wouldnt utilize the submitted position.. (now can fseek(f,-128,SEEK_END) to read from end of file :D) 2008-06-18 v0.6.Turbo - . and .. :D * Today i have added full "." and ".." support. dirnext() will return . and .. first, and all relevent operations will support . and .. in filenames. */ #include "nds.h" #include "nitrofs.h" #include <string.h> //Globals! u32 fntOffset; //offset to start of filename table u32 fatOffset; //offset to start of file alloc table bool hasLoader; u16 chdirpathid; //default dir path id... FILE *ndsFile; unsigned int ndsFileLastpos; //Used to determine need to fseek or not devoptab_t nitroFSdevoptab={ "nitro", // const char *name; sizeof(struct nitroFSStruct), // int structSize; &nitroFSOpen, // int (*open_r)(struct _reent *r, void *fileStruct, const char *path,int flags,int mode); &nitroFSClose, // int (*close_r)(struct _reent *r,int fd); NULL, // int (*write_r)(struct _reent *r,int fd,const char *ptr,int len); &nitroFSRead, // int (*read_r)(struct _reent *r,int fd,char *ptr,int len); &nitroFSSeek, // int (*seek_r)(struct _reent *r,int fd,int pos,int dir); &nitroFSFstat, // int (*fstat_r)(struct _reent *r,int fd,struct stat *st); &nitroFSstat, // int (*stat_r)(struct _reent *r,const char *file,struct stat *st); NULL, // int (*link_r)(struct _reent *r,const char *existing, const char *newLink); NULL, // int (*unlink_r)(struct _reent *r,const char *name); &nitroFSChdir, // int (*chdir_r)(struct _reent *r,const char *name); NULL, // int (*rename_r) (struct _reent *r, const char *oldName, const char *newName); NULL, // int (*mkdir_r) (struct _reent *r, const char *path, int mode); sizeof(struct nitroDIRStruct), // int dirStateSize; &nitroFSDirOpen,// DIR_ITER* (*diropen_r)(struct _reent *r, DIR_ITER *dirState, const char *path); &nitroDirReset, // int (*dirreset_r)(struct _reent *r, DIR_ITER *dirState); &nitroFSDirNext,// int (*dirnext_r)(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat); &nitroFSDirClose// int (*dirclose_r)(struct _reent *r, DIR_ITER *dirState); }; //K, i decided to inline these, improves speed slightly.. //these 2 'sub' functions deal with actually reading from either gba rom or .nds file :) //what i rly rly rly wanna know is how an actual nds cart reads from itself, but it seems no one can tell me ~_~ //so, instead we have this weird weird haxy try gbaslot then try dldi method. If i (or you!!) ever do figure out //how to read the proper way can replace these 4 functions and everything should work normally :) //reads from rom image either gba rom or dldi inline int nitroSubRead(unsigned int *npos, void *ptr, int len) { if(ndsFile!=NULL) { //read from ndsfile if(ndsFileLastpos!=*npos) fseek(ndsFile, *npos, SEEK_SET); //if we need to, move! (might want to verify this succeed) len=fread(ptr,1,len,ndsFile); } else { //reading from gbarom memcpy(ptr, *npos+(void*)GBAROM,len); //len isnt checked here because other checks exist in the callers (hopefully) } if(len > 0) *npos+=len; ndsFileLastpos=*npos; //save the current file nds pos return(len); } //seek around inline void nitroSubSeek(unsigned int *npos, int pos, int dir) { if((dir==SEEK_SET)||(dir==SEEK_END)) //otherwise just set the pos :) *npos=pos; else if(dir==SEEK_CUR) *npos+=pos; //see ez! } //Figure out if its gba or ds, setup stuff int nitroFSInit(const char *ndsfile) { unsigned int pos=0; char romstr[0x10]; chdirpathid=NITROROOT; ndsFileLastpos=0; ndsFile=NULL; REG_EXMEMCNT &= ~ARM7_OWNS_CARD; //give us gba slot ownership if(strncmp(((const char *)GBAROM)+LOADERSTROFFSET,LOADERSTR,strlen(LOADERSTR))==0) { // We has gba rahm if(strncmp(((const char *)GBAROM)+LOADERSTROFFSET+LOADEROFFSET,LOADERSTR,strlen(LOADERSTR))==0) { //Look for second magic string, if found its a sc.nds or nds.gba fntOffset=((u32)*(u32*)(((const char *)GBAROM)+FNTOFFSET+LOADEROFFSET))+LOADEROFFSET; fatOffset=((u32)*(u32*)(((const char *)GBAROM)+FATOFFSET+LOADEROFFSET))+LOADEROFFSET; hasLoader=true; AddDevice(&nitroFSdevoptab); return(1); } else { //Ok, its not a .gba build, so must be emulator fntOffset=((u32)*(u32*)(((const char *)GBAROM)+FNTOFFSET)); fatOffset=((u32)*(u32*)(((const char *)GBAROM)+FATOFFSET)); hasLoader=false; AddDevice(&nitroFSdevoptab); return(1); } } else { //okay then try something else ~_~ (like dldi) if((ndsFile=fopen(ndsfile,"rb"))) { nitroSubRead(&pos,romstr,strlen(LOADERSTR)); if(strncmp(romstr,LOADERSTR,strlen(LOADERSTR))==0) { nitroSubSeek(&pos,LOADEROFFSET+FNTOFFSET,SEEK_SET); nitroSubRead(&pos,&fntOffset,sizeof(fntOffset)); nitroSubSeek(&pos,LOADEROFFSET+FATOFFSET,SEEK_SET); nitroSubRead(&pos,&fatOffset,sizeof(fatOffset)); fatOffset+=LOADEROFFSET; fntOffset+=LOADEROFFSET; hasLoader=true; } else { nitroSubSeek(&pos,FNTOFFSET,SEEK_SET); nitroSubRead(&pos,&fntOffset,sizeof(fntOffset)); nitroSubSeek(&pos,FATOFFSET,SEEK_SET); nitroSubRead(&pos,&fatOffset,sizeof(fatOffset)); hasLoader=false; } setvbuf(ndsFile,NULL,_IONBF,0); //we dont need double buffs u_u AddDevice(&nitroFSdevoptab); return(1); } } return(0); } //Directory functs DIR_ITER* nitroFSDirOpen(struct _reent *r, DIR_ITER *dirState, const char *path) { struct nitroDIRStruct *dirStruct=(struct nitroDIRStruct*)dirState->dirStruct; //this makes it lots easier! struct stat st; char dirname[NITRONAMELENMAX]; char *cptr; char mydirpath[NITROMAXPATHLEN]; //to hold copy of path string char *dirpath=mydirpath; bool pathfound; if((cptr=strchr(path,':'))) path=cptr+1; //move path past any device names (if it was nixy style wouldnt need this step >_>) strncpy(dirpath,path,sizeof(mydirpath)-1); //copy the string (as im gonna mutalate it) dirStruct->pos=0; if(*dirpath=='/') //if first character is '/' use absolute root path plz dirStruct->cur_dir_id=NITROROOT; //first root dir else dirStruct->cur_dir_id=chdirpathid; //else use chdirpath nitroDirReset(r,dirState); //set dir to current path do { while((cptr=strchr(dirpath,'/'))==dirpath) { dirpath++; //move past any leading / or // together } if(cptr) *cptr=0; //erase / if(*dirpath==0) {//are we at the end of the path string?? if so there is nothing to search for we're already here ! pathfound=true; //mostly this handles searches for root or / or no path specified cases break; } pathfound=false; while(nitroFSDirNext(r,dirState,dirname,&st)==0) { if((st.st_mode==S_IFDIR) && !(strcmp(dirname,dirpath))) { //if its a directory and name matches dirpath dirStruct->cur_dir_id=dirStruct->dir_id; //move us to the next dir in tree nitroDirReset(r,dirState); //set dir to current path we just found... pathfound=true; break; } }; if(!pathfound) break; dirpath=cptr+1; //move to right after last / we found } while(cptr); // go till after the last / if(pathfound) { return(dirState); } else { return(NULL); } } int nitroFSDirClose(struct _reent *r, DIR_ITER *dirState) { return(0); } /*Consts containing relative system path strings*/ const char *syspaths[2]={ ".", ".." }; //reset dir to start of entry selected by dirStruct->cur_dir_id which should be set in dirOpen okai?! int nitroDirReset(struct _reent *r, DIR_ITER *dirState) { struct nitroDIRStruct *dirStruct=(struct nitroDIRStruct*)dirState->dirStruct; //this makes it lots easier! struct ROM_FNTDir dirsubtable; unsigned int *pos=&dirStruct->pos; nitroSubSeek(pos,fntOffset+((dirStruct->cur_dir_id&NITRODIRMASK)*sizeof(struct ROM_FNTDir)),SEEK_SET); nitroSubRead(pos, &dirsubtable, sizeof(dirsubtable)); dirStruct->namepos=dirsubtable.entry_start; //set namepos to first entry in this dir's table dirStruct->entry_id=dirsubtable.entry_file_id; //get number of first file ID in this branch dirStruct->parent_id=dirsubtable.parent_id; //save parent ID in case we wanna add ../ functionality dirStruct->spc=0; //system path counter, first two dirnext's deliver . and .. return(0); } int nitroFSDirNext(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *st) { unsigned char next; struct nitroDIRStruct *dirStruct=(struct nitroDIRStruct*)dirState->dirStruct; //this makes it lots easier! unsigned int *pos=&dirStruct->pos; if(dirStruct->spc<=1) { if(st) st->st_mode=S_IFDIR; if((dirStruct->spc==0)||(dirStruct->cur_dir_id==NITROROOT)) { // "." or its already root (no parent) dirStruct->dir_id=dirStruct->cur_dir_id; } else { // ".." dirStruct->dir_id=dirStruct->parent_id; } strcpy(filename,syspaths[dirStruct->spc++]); return(0); } nitroSubSeek(pos,fntOffset+dirStruct->namepos,SEEK_SET); nitroSubRead(pos, &next , sizeof(next)); // next: high bit 0x80 = entry isdir.. other 7 bits r size, the 16 bits following name are dir's entryid (starts with f000) // 00 = endoftable // if(next) { if(next&NITROISDIR) { if(st) st->st_mode=S_IFDIR; next&=NITROISDIR^0xff; //invert bits and mask off 0x80 nitroSubRead(pos,filename,next); nitroSubRead(&dirStruct->pos,&dirStruct->dir_id,sizeof(dirStruct->dir_id)); //read the dir_id //grr cant get the struct member size?, just wanna test it so moving on... // nitroSubRead(pos,&dirStruct->dir_id,sizeof(u16)); //read the dir_id dirStruct->namepos+=next+sizeof(u16)+1; //now we points to next one plus dir_id size:D } else { if(st) st->st_mode=0; nitroSubRead(pos,filename,next); dirStruct->namepos+=next+1; //now we points to next one :D //read file info to get filesize (and for fileopen) nitroSubSeek(pos,fatOffset+(dirStruct->entry_id*sizeof(struct ROM_FAT)),SEEK_SET); nitroSubRead(pos, &dirStruct->romfat, sizeof(dirStruct->romfat)); //retrieve romfat entry (contains filestart and end positions) dirStruct->entry_id++; //advance ROM_FNTStrFile ptr if(st) st->st_size=dirStruct->romfat.bottom-dirStruct->romfat.top; //calculate filesize } filename[(int)next]=0; //zero last char return(0); } else { return(-1); } } //fs functs int nitroFSOpen(struct _reent *r, void *fileStruct, const char *path,int flags,int mode) { struct nitroFSStruct *fatStruct=(struct nitroFSStruct *)fileStruct; struct nitroDIRStruct dirStruct; DIR_ITER dirState; dirState.dirStruct=&dirStruct; //create a temp dirstruct struct _reent dre; struct stat st; //all these are just used for reading the dir ~_~ char dirfilename[NITROMAXPATHLEN]; // to hold a full path (i tried to avoid using so much stack but blah :/) char *filename; // to hold filename char *cptr; //used to string searching and manipulation cptr=(char*)path+strlen(path); //find the end... filename=NULL; do { if((*cptr=='/') || (*cptr==':')) { // split at either / or : (whichever comes first form the end!) cptr++; strncpy(dirfilename,path,cptr-path); //copy string up till and including/ or : zero rest dirfilename[cptr-path]=0; //it seems strncpy doesnt always zero?! filename=cptr; //filename = now remainder of string break; } } while(cptr--!=path); //search till start if(!filename) { //we didnt find a / or : ? shouldnt realyl happen but if it does... filename=(char*)path; //filename = complete path dirfilename[0]=0; //make directory path "" } if(nitroFSDirOpen(&dre,&dirState,dirfilename)) { fatStruct->start=0; while(nitroFSDirNext(&dre,&dirState, dirfilename, &st)==0) { if(!(st.st_mode & S_IFDIR) && (strcmp(dirfilename,filename)==0)) { //Found the *file* youre looking for!! fatStruct->start=dirStruct.romfat.top; fatStruct->end=dirStruct.romfat.bottom; if(hasLoader) { fatStruct->start+=LOADEROFFSET; fatStruct->end+=LOADEROFFSET; } break; } } if(fatStruct->start) { nitroSubSeek(&fatStruct->pos,fatStruct->start,SEEK_SET); //seek to start of file return(0); //woot! } nitroFSDirClose(&dre,&dirState); } return(-1); //teh fail } int nitroFSClose(struct _reent *r,int fd) { return(0); } int nitroFSRead(struct _reent *r,int fd,char *ptr,int len) { struct nitroFSStruct *fatStruct=(struct nitroFSStruct *)fd; unsigned int *npos=&fatStruct->pos; if(*npos+len > fatStruct->end) len=fatStruct->end-*npos; //dont let us read past the end plz! if(*npos > fatStruct->end) return(0); //hit eof return(nitroSubRead(npos,ptr,len)); } int nitroFSSeek(struct _reent *r,int fd,int pos,int dir) { //need check for eof here... struct nitroFSStruct *fatStruct=(struct nitroFSStruct *)fd; unsigned int *npos=&fatStruct->pos; if(dir==SEEK_SET) pos+=fatStruct->start; //add start from .nds file offset else if(dir==SEEK_END) pos+=fatStruct->end; //set start to end of file (useless?) if(pos > fatStruct->end) return(-1); //dont let us read past the end plz! nitroSubSeek(npos,pos,dir); return(*npos-fatStruct->start); } int nitroFSFstat(struct _reent *r,int fd,struct stat *st) { struct nitroFSStruct *fatStruct=(struct nitroFSStruct *)fd; st->st_size=fatStruct->end-fatStruct->start; return(0); } int nitroFSstat(struct _reent *r,const char *file,struct stat *st) { struct nitroFSStruct fatStruct; if(nitroFSOpen(NULL, &fatStruct, file, 0, 0)>=0) { st->st_size=fatStruct.end-fatStruct.start; return(0); } return(-1); } int nitroFSChdir(struct _reent *r,const char *name) { struct nitroDIRStruct dirStruct; DIR_ITER dirState; dirState.dirStruct=&dirStruct; if((name!=NULL) && (nitroFSDirOpen(r, &dirState, name)!=NULL)) { chdirpathid=dirStruct.cur_dir_id; nitroFSDirClose(r, &dirState); return(0); } else { return(-1); } }
84797042a6538e7980d27bd919b74126fd12edf5
818e191b51017109feed5a562cdecc5e8931006a
/ping/ping-client.c
ed390fea0533052adff59693da7640879bf4a1c1
[ "MIT" ]
permissive
chamow97/Computer-Networks
7f55f9b787513f15fffed1f1c06e2497647ea28d
eea443d86c1fd68e3be28fb75e511b0ce6901000
refs/heads/master
2021-08-22T20:57:08.572463
2017-12-01T08:29:42
2017-12-01T08:29:42
108,554,278
1
0
null
null
null
null
UTF-8
C
false
false
1,773
c
ping-client.c
//ping //given a source and destination, find the minimum hop /*-------------------------------------------------------*/ #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<stdio.h> #include<stdlib.h> #include<string.h> #include<time.h> /*-------------------------------------------------------*/ int main(int argc, char **argv) { socklen_t len; struct sockaddr_in serverAddress, clientAddress; int length, sockFd, connFd; char buffer[1000]; char string[1000]; int ptr = 0; long double averageTime = 0.0; long double currentTime = 0.0; /*-------------------------------------------------------*/ printf("\n\n\n\t\t\t PING - CLIENT\n\t\t\t ---- -----"); sockFd = socket(AF_INET, SOCK_STREAM, 0); if(sockFd < 0) { perror("\n\n\t\t Socket Error!"); return 0; } bzero(&serverAddress, sizeof(serverAddress)); serverAddress.sin_family = AF_INET; serverAddress.sin_addr.s_addr = INADDR_ANY; serverAddress.sin_port = htons(5000); connect(sockFd, (struct sockaddr *)&serverAddress, sizeof(serverAddress)); struct timespec ts; strcpy(buffer, "\n\n\t\t Ping Messages! - "); while(ptr < 10) { ptr++; timespec_get(&ts, TIME_UTC); strftime(string, sizeof(string), "%D %T", gmtime(&ts.tv_sec)); currentTime = (ts.tv_nsec + ts.tv_sec * 1e9); write(sockFd, buffer, sizeof(buffer)); read(sockFd, buffer, sizeof(buffer)); timespec_get(&ts, TIME_UTC); strftime(string, sizeof(string), "%D %T", gmtime(&ts.tv_sec)); currentTime = -currentTime + ts.tv_nsec + ts.tv_sec * 1e9; averageTime = (averageTime + currentTime); printf("\n\t\t RTT for Packet: %d is: %.12Lf", ptr, currentTime); } averageTime /= 10; printf("\n\n\t\t Average RTT is: %.12Lf", averageTime); printf("\n\n"); close(sockFd); return 0; }
e501898aa6a0c1d0996fa17fef15c85c5c9fdff4
c4317fca0ce01074fcd66281c819fe7994bcd08b
/source/switchID.h
450f0f761050d71ee9625b1a2f4ec32a0dafe65e
[]
no_license
Sekilsgs2/SilverLite-FS-i6
e56a13c96571d6a397ec4fcb5e423d39e4189c9a
96624f6ef9fffc0a70753cc37ebca3706ccf25a0
refs/heads/master
2022-07-16T20:05:06.180789
2020-05-18T02:50:36
2020-05-18T02:50:36
null
0
0
null
null
null
null
UTF-8
C
false
false
429
h
switchID.h
#ifndef __SWITCHID_H__ #define __SWITCHID_H__ #include <stdint.h> enum ESwitchID { kSw_None, kSwA_1, kSwA_2, kSwB_1, kSwB_2, kSwC_1, kSwC_2, kSwC_3, kSwC_1_2, kSwC_2_3, kSwD_1, kSwD_2, _kSw_Max }; extern const char *gSwitchNames[_kSw_Max]; int switchIsActive(uint8_t id); // id should be a ESwitchID value #endif // __SWITCHID_H__
ba3f7e8bf84e03bb76ea48811eef0b13e96ccb66
0dc308a7ba47605b3cf25716140c61b1b4212360
/AVR_ATMEGA16/MICROCHIP_STUDIO_Codes/P10_IR_Sensor_DC_Motors/P10_IR_Sensor_DC_Motors/main.c
12e0fbe6ef92c6bab59fa5890f2e696f796a13e9
[]
no_license
joydipdutta001/AVR_ATmega16
555fec302e1b00b1807dfec4b9937ee9503778cb
37bb50f74396fa01fe2921143f6d80b1f2ba9440
refs/heads/master
2023-03-30T06:47:05.748513
2021-03-29T11:14:47
2021-03-29T11:14:47
352,595,425
0
0
null
null
null
null
UTF-8
C
false
false
1,404
c
main.c
/* * P11_IR_Sensor_DC_Motors.c * * Created: 26-03-2021 19:22:28 * Author : Jervis */ #define F_CPU 1000000UL #include <avr/io.h> #include <string.h> #include <util/delay.h> #define lcd PORTD lcd_init() { lcd_cmd(0x02); lcd_cmd(0x28); lcd_cmd(0x0c); } lcd_cmd(int x) { lcd=(x&0xf0)+0x04; _delay_ms(2); lcd=lcd-0x04; lcd=((x<<4)&0xf0)+0x04; _delay_ms(2); lcd=lcd-0x04; } lcd_data(int x) { lcd=(x&0xf0)+0x05; _delay_ms(2); lcd=lcd-0x04; lcd=((x<<4)&0xf0)+0x05; _delay_ms(2); lcd=lcd-0x04; } string_data(char *str){ int i = 0; for(i=0; i<=strlen(str) ; i++){ lcd_data(str[i]); _delay_ms(8); lcd_cmd(0x06); } } char arr[11] = "0123456789"; number_data(int number){ int i; if(number>0) { i=number%10; number=number/10; number_data(number); lcd_data(arr[i]); lcd_cmd(0x06); _delay_ms(10); } } int main(void) { DDRC = DDRD = 0xff; DDRA = 0xff; lcd_init(); while(1){ lcd_cmd(0x83); string_data("..Object.."); while(PINA == 0x01) { PORTC = 0x00; lcd_cmd(0x01); lcd_data(0xc0); string_data("Detected Stoping"); _delay_ms(100); PORTC = 0x06; lcd_cmd(0x01); lcd_data(0xc3); string_data(" Backward "); _delay_ms(1000); PORTC = 0x08; lcd_cmd(0x01); lcd_data(0xc3); string_data("Right"); _delay_ms(1000); lcd_cmd(0x01); _delay_ms(10); } PORTC = 0x09; lcd_cmd(0xc3); string_data(" Forward "); } }
417ed1c5725f9084544755b6d615fd0847a1c48f
dd2fc998eec856d064687d5a9f7dd2085fe29b51
/core/random.h
96e8a798399b2535c29b7bf972332e1d23281335
[]
no_license
tomazos/wt
89fc245b0c4e097409ca84998471143ceac28f5b
eb75fd7fbac39c8ae2b84f50a1d85cd585e3baaf
refs/heads/master
2021-05-31T00:57:26.400698
2016-02-06T17:27:22
2016-02-06T17:27:22
39,314,660
0
0
null
null
null
null
UTF-8
C
false
false
70
h
random.h
#pragma once float64 RandFloat(); int64 RandInt(int64 upper_limit);
b883f448ef2a12748dc45b695dce814c3169934d
71870a5795f5b6959f32c1da99efbb7b6a15dfb8
/Archive/node-demo-efm32/src/main.c
b19c37e598a20ac291f7b199bf2a50fbf65da70b
[]
no_license
samdbmg/sbc-wsn
c7bd2451ac376b0979cf1e7d453ad30d10a9cfdc
638c7d2cee005884a94fbb7e611bc8ea8b7f891f
refs/heads/master
2021-05-30T06:07:06.274431
2015-05-28T10:46:25
2015-05-28T10:46:25
29,143,631
1
0
null
null
null
null
UTF-8
C
false
false
3,185
c
main.c
/** * EFM32 Node power demo main file */ #include "em_device.h" #include "em_prs.h" #include "em_timer.h" #include "em_adc.h" #include "em_dma.h" #include "em_emu.h" #include "em_cmu.h" #include "em_chip.h" #include "em_rtc.h" #include "em_usart.h" #include "em_gpio.h" #include "adc_mode.h" #include "pin_mode.h" //#define ADC_MODE #define PINCHANGE_MODE #define WAKEUP_INTERVAL_MS 10000 // Calculate RTC wakeup timeout #define LFRCO_FREQ 32768 #define RTC_WAKEUP_TICKS (((LFRCO_FREQ * WAKEUP_INTERVAL_MS) / 1000) - 1) /** * Configure the RTC and start it, with interrupt enabled */ void rtc_init(void) { // Start the low frequency oscillator LFRCO CMU_OscillatorEnable(cmuOsc_LFRCO, true, true); // Enable the RTC clock supply CMU_ClockSelectSet(cmuClock_LFA, cmuSelect_LFRCO); CMU_ClockEnable(cmuClock_RTC, true); RTC_Init_TypeDef rtc_init_data; rtc_init_data.comp0Top = true; rtc_init_data.debugRun = false; rtc_init_data.enable = true; RTC_CompareSet(0, RTC_WAKEUP_TICKS); // Enable RTC interrupt and start it RTC_IntEnable(RTC_IF_COMP0); NVIC_EnableIRQ(RTC_IRQn); RTC_Init(&rtc_init_data); } /** * Handle an RTC wakeup by doing something with data */ void RTC_IRQHandler(void) { CMU_ClockEnable(cmuClock_USART1, true); rtc_handler(); CMU_ClockEnable(cmuClock_USART1, false); // Clear pending interrupt RTC_IntClear(RTC_IFC_COMP0); } void spi_init(void) { CMU_ClockEnable(cmuClock_USART1, true); // Pin config GPIO_PinModeSet(gpioPortD, 6, gpioModeInput, 0); // MISO GPIO_PinModeSet(gpioPortD, 7, gpioModePushPull, 0); // MOSI GPIO_PinModeSet(gpioPortC, 14, gpioModePushPull, 0); // CS GPIO_PinModeSet(gpioPortC, 15, gpioModePushPull, 0); // CLK USART_InitSync_TypeDef spi_init_data; spi_init_data.autoTx = false; spi_init_data.clockMode = usartClockMode0; spi_init_data.databits = usartDatabits8; spi_init_data.baudrate = 1000000; spi_init_data.enable = true; spi_init_data.master = true; spi_init_data.msbf = false; spi_init_data.prsRxEnable = false; spi_init_data.refFreq = 0; // Turn SPI on USART_InitSync(USART1, &spi_init_data); USART1->ROUTE = USART_ROUTE_TXPEN | USART_ROUTE_CLKPEN | USART_ROUTE_RXPEN | USART_ROUTE_CSPEN | USART_ROUTE_LOCATION_LOC3; USART1->CTRL |= USART_CTRL_AUTOCS; USART1->CMD |= USART_CMD_TXEN; CMU_ClockEnable(cmuClock_USART1, false); } /** * Main function. Initialises peripherals and lets interrupts do the work. */ int main(void) { CHIP_Init(); CMU_HFRCOBandSet(cmuHFRCOBand_21MHz); // Low energy module clock supply CMU_ClockEnable(cmuClock_CORELE, true); // GPIO pins clock supply CMU_ClockEnable(cmuClock_GPIO, true); // Start the RTC, we'll worry about time later rtc_init(); // Configure USART for PSI spi_init(); #ifdef ADC_MODE // Start up the ADC, timer and DMA adc_mode_init(); #elif defined(PINCHANGE_MODE) pin_mode_init(); #endif while (1) { #ifdef ADC_MODE EMU_EnterEM1(); #elif defined(PINCHANGE_MODE) sleep_handler(); #endif } }
e7531d85a5925fe15b7ad9b9c6dc13feccb5ed33
83e900d67ca534e77b587aa46d28e9052648c4b5
/Src/3-BSW/ComStack_cfg/CanIf_Lcfg.c
8db77013ca060ad4381a66963e6b896a17ffdde3
[]
no_license
EbrahimHamouda/SeatControl_SprintsTask
67d4a09d3e896b3ec0947d47fe58c9bfd7a3fc73
72c77f78ff4d3e1ae4c27aeac7a2f5f977393981
refs/heads/master
2022-12-04T22:46:14.112764
2020-08-21T17:04:06
2020-08-21T17:04:06
null
0
0
null
null
null
null
UTF-8
C
false
false
248
c
CanIf_Lcfg.c
/* * CAN_Lcfg.c * * Created: 6/15/2020 12:01:23 PM * Author: ebrah */ #include "CanIf_Pcfg.h" #include "Com_DataTypes.h" #include "Com.h" HOH_CfgType HOHs_2_PDUs_Arr[NUM_PDU] = { { 0, RX, 0xF0, 0xFF, Com_RxIndication } };
ebfff3278ccb260837161f63a5bca569a8f70ab1
d25460abc4c8c555af16b1acb35a3cb307c2dddf
/C_Codes/ListOfPrimes.c
630425007dd891c58e42bbdcd1f9e3b95d8c9710
[]
no_license
arponbasu/CS101_1stSem
3cb4cd7fb7e1ccf57feb396ad07ee27013cf8756
d591f8e4c51980a24c2c03b1f853f8ab4d0a6dfc
refs/heads/main
2023-06-25T08:13:53.254132
2021-07-21T10:43:44
2021-07-21T10:43:44
369,990,672
0
0
null
null
null
null
UTF-8
C
false
false
434
c
ListOfPrimes.c
/* * ListOfPrimes.c */ #include <stdio.h> #include "mathutils.h" #define MAXSIZE 2000 #define SEARCHLIMIT 17389 int ArrayOfPrimes[MAXSIZE]; int main(int argc, char **argv) { int index = 0; for (int i = 2; i <= SEARCHLIMIT; i++) { if (primechecker(i) == 1) { ArrayOfPrimes[index] = i; index++ ; } } printf("The hundredth prime is = %d\n",ArrayOfPrimes[1999]); return 0; }
816e0311f81d03365bf33adc74a314a933e719a3
976f5e0b583c3f3a87a142187b9a2b2a5ae9cf6f
/source/linux/drivers/net/ethernet/micrel/extr_ksz884x.c_netdev_get_eeprom.c
a5b5d7b9ad866329bf3571d073d0502d723421db
[]
no_license
isabella232/AnghaBench
7ba90823cf8c0dd25a803d1688500eec91d1cf4e
9a5f60cdc907a0475090eef45e5be43392c25132
refs/heads/master
2023-04-20T09:05:33.024569
2021-05-07T18:36:26
2021-05-07T18:36:26
null
0
0
null
null
null
null
UTF-8
C
false
false
1,401
c
extr_ksz884x.c_netdev_get_eeprom.c
#define NULL ((void*)0) typedef unsigned long size_t; // Customize by platform. typedef long intptr_t; typedef unsigned long uintptr_t; typedef long scalar_t__; // Either arithmetic or pointer type. /* By default, we understand bool (as a convenience). */ typedef int bool; #define false 0 #define true 1 /* Forward declarations */ /* Type definitions */ typedef int /*<<< orphan*/ u8 ; struct net_device {int dummy; } ; struct ethtool_eeprom {int offset; int len; int /*<<< orphan*/ magic; } ; struct dev_priv {struct dev_info* adapter; } ; struct dev_info {int /*<<< orphan*/ hw; } ; /* Variables and functions */ int /*<<< orphan*/ EEPROM_MAGIC ; int /*<<< orphan*/ * eeprom_data ; int /*<<< orphan*/ eeprom_read (int /*<<< orphan*/ *,int) ; int /*<<< orphan*/ memcpy (int /*<<< orphan*/ *,int /*<<< orphan*/ *,int) ; struct dev_priv* netdev_priv (struct net_device*) ; __attribute__((used)) static int netdev_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom, u8 *data) { struct dev_priv *priv = netdev_priv(dev); struct dev_info *hw_priv = priv->adapter; u8 *eeprom_byte = (u8 *) eeprom_data; int i; int len; len = (eeprom->offset + eeprom->len + 1) / 2; for (i = eeprom->offset / 2; i < len; i++) eeprom_data[i] = eeprom_read(&hw_priv->hw, i); eeprom->magic = EEPROM_MAGIC; memcpy(data, &eeprom_byte[eeprom->offset], eeprom->len); return 0; }
b5d6bad4242fa4fd23a55a9250ce90393af8abb0
a9007005b818852c70d1338a8751e425049f9883
/ToBeStructured_Branch_Arduino/stack/ec_cmd_brw.c
3a9e2e1fabde7ed242e57770b2b93f1165be1b79
[]
no_license
jaessy77/ecslave
fbd95c2625b783840687b61ab1b3f2aa9bb2963f
85e47eef6627b651a4a375325fe20173f3e22c29
refs/heads/master
2022-10-29T09:16:41.600290
2020-06-09T20:23:11
2020-06-09T20:23:11
265,329,481
2
0
null
null
null
null
UTF-8
C
false
false
671
c
ec_cmd_brw.c
#include "../include/xgeneral.h" #include "ethercattype.h" #include "fsm_slave.h" #include "ecs_slave.h" #include "ec_regs.h" /* Broadcat Read Write */ void ec_cmd_brw(ecat_slave * ecs,uint8_t *dgram_ec) { uint16_t ado; uint8_t *data = __ec_dgram_data(dgram_ec); uint16_t datalen = __ec_dgram_dlength(dgram_ec); uint8_t val[datalen]; ( (ec_dgram *) dgram_ec)->adp++; /* each slave ++ in APWR */ ado = __ec_dgram_ado(dgram_ec); ec_get_ado(ecs, ado, val, datalen); ec_set_ado(ecs, ado, data, datalen); memcpy(data, val, datalen); __ec_inc_wkc__(dgram_ec); __ec_inc_wkc__(dgram_ec); __ec_inc_wkc__(dgram_ec); __set_fsm_state(ecs, ecs_process_next_dgram); }
d5ef5866f452f622f1c8baa81c95fb5b00543778
46607867d79d85dacdd547bf119187722ad39863
/es-src/cli.c
bd01775367af244b2df857fcb7b84dac58eab958
[]
no_license
0xFF1E071F/TccPy
9a4255fa3643b85396255ef10745c49755775a83
a2131fd11e79b7ffb43d42fbccc3b94a1e5f620b
refs/heads/master
2021-07-22T10:29:27.892529
2017-11-02T03:30:41
2017-11-02T03:30:41
null
0
0
null
null
null
null
UTF-8
C
false
false
12,819
c
cli.c
// Everything IPC test // revision 2: // fixed command line interpreting '-' as a switch inside text. // revision 3: // convert unicode to same code page as console. // revision 4: // removed write console because it has no support for piping. // revision 5: // added ChangeWindowMessageFilterEx (if available) for admin/user support. // compiler options #pragma warning(disable : 4311) // type cast void * to unsigned int #pragma warning(disable : 4312) // type cast unsigned int to void * #pragma warning(disable : 4244) // warning C4244: 'argument' : conversion from 'LONG_PTR' to 'LONG', possible loss of data #pragma warning(disable : 4996) // deprecation #include <windows.h> #include <stdio.h> #include "everything_ipc.h" #define COPYDATA_IPCTEST_QUERYCOMPLETEW 0 #define MSGFLT_RESET 0 #define MSGFLT_ALLOW 1 #define MSGFLT_DISALLOW 2 #define COPYDATA_IPCTEST_QUERYCOMPLETEW 0 #define COPYDATA_IPCTEST_QUERYCOMPLETEA 1 #define farrStatus printf int gotData=0; int timeout=0; int isTutorial=0; int scoringType=0; int _EverythingSendQueryA(HWND hwnd, char *search_string, int flags) { EVERYTHING_IPC_QUERY *query; int len, size; HWND everything_hwnd; COPYDATASTRUCT cds; everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS, 0); if (everything_hwnd) { len = (int)strlen(search_string); size = sizeof(EVERYTHING_IPC_QUERY) - sizeof(CHAR) + len*sizeof(CHAR) + sizeof(CHAR); query = (EVERYTHING_IPC_QUERY *)HeapAlloc(GetProcessHeap(),0,size); if (query) { query->max_results = 50; query->offset = 0; query->reply_copydata_message = COPYDATA_IPCTEST_QUERYCOMPLETEA; query->search_flags = flags; query->reply_hwnd = hwnd; CopyMemory(query->search_string,search_string,(len+1)*sizeof(CHAR)); cds.cbData = size; cds.dwData = EVERYTHING_IPC_COPYDATAQUERY; cds.lpData = query; if (SendMessage(everything_hwnd,WM_COPYDATA,(WPARAM)hwnd,(LPARAM)&cds) == TRUE) { //debugmsg("Query sent.\n"); HeapFree(GetProcessHeap(),0,query); return 1; } else { farrStatus("Everything IPC service not running!"); isTutorial=1; } HeapFree(GetProcessHeap(),0,query); } else { farrStatus("Failed to allocate %d bytes for Everything IPC query.",size); return 0; } } else { farrStatus("Everything IPC service not found. Everything must be running."); isTutorial=1; } return 0; } int EverythingSendQuery(HWND windowHandle,char *searchString) { int ret, flags=0; MSG msg; timeout=30; gotData=0; if(searchString[0]=='$'&&strlen(searchString)>1) { flags|=EVERYTHING_IPC_REGEX; searchString++; } if(_EverythingSendQueryA(windowHandle, searchString, flags)==1) { //WaitMessage(); while(1) { timeout--; if(timeout<=0) { farrStatus("Timed out while waiting for blob from Everything!"); break; } WaitMessage(); while(PeekMessage(&msg, NULL, 0, 0, 0)) { ret = (int)GetMessage(&msg, 0, 0, 0); if (ret <=0) break; TranslateMessage(&msg); DispatchMessage(&msg); } if(gotData) break; } return 1; } return 0; } typedef struct tagCHANGEFILTERSTRUCT { DWORD cbSize; DWORD ExtStatus; } CHANGEFILTERSTRUCT, *PCHANGEFILTERSTRUCT; static void write(wchar_t *text); static void write_DWORD(DWORD value); static int wstring_to_int(const wchar_t *s); int sort = 0; EVERYTHING_IPC_LIST *sort_list; HMODULE user32_hdll = 0; BOOL (WINAPI *pChangeWindowMessageFilterEx)(HWND hWnd,UINT message,DWORD action,PCHANGEFILTERSTRUCT pChangeFilterStruct) = 0; int wstring_length(const wchar_t *s) { const wchar_t *p; p = s; while(*p) { p++; } return (int)(p - s); } // query everything with search string int sendquery(HWND hwnd,DWORD num,WCHAR *search_string,int regex,int match_case,int match_whole_word,int match_path) { EVERYTHING_IPC_QUERY *query; int len; int size; HWND everything_hwnd; COPYDATASTRUCT cds; everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS,0); if (everything_hwnd) { len = wstring_length(search_string); size = sizeof(EVERYTHING_IPC_QUERY) - sizeof(WCHAR) + len*sizeof(WCHAR) + sizeof(WCHAR); query = (EVERYTHING_IPC_QUERY *)HeapAlloc(GetProcessHeap(),0,size); if (query) { query->max_results = num; query->offset = 0; query->reply_copydata_message = COPYDATA_IPCTEST_QUERYCOMPLETEW; query->search_flags = (regex?EVERYTHING_IPC_REGEX:0) | (match_case?EVERYTHING_IPC_MATCHCASE:0) | (match_whole_word?EVERYTHING_IPC_MATCHWHOLEWORD:0) | (match_path?EVERYTHING_IPC_MATCHPATH:0); query->reply_hwnd = hwnd; CopyMemory(query->search_string,search_string,(len+1)*sizeof(WCHAR)); cds.cbData = size; cds.dwData = EVERYTHING_IPC_COPYDATAQUERY; cds.lpData = query; if (SendMessage(everything_hwnd,WM_COPYDATA,(WPARAM)hwnd,(LPARAM)&cds) == TRUE) { HeapFree(GetProcessHeap(),0,query); return 1; } else { write(L"Everything IPC service not running.\n"); } HeapFree(GetProcessHeap(),0,query); } else { write(L"failed to allocate "); write_DWORD(size); write(L" bytes for IPC query.\n"); } } else { // the everything window was not found. // we can optionally RegisterWindowMessage("EVERYTHING_IPC_CREATED") and // wait for Everything to post this message to all top level windows when its up and running. write(L"Everything IPC window not found, IPC unavailable.\n"); } return 0; } int compare_list_items(const void *a,const void *b) { int i; i = wcsicmp(EVERYTHING_IPC_ITEMPATH(sort_list,a),EVERYTHING_IPC_ITEMPATH(sort_list,b)); if (!i) { return wcsicmp(EVERYTHING_IPC_ITEMFILENAME(sort_list,a),EVERYTHING_IPC_ITEMFILENAME(sort_list,b)); } else if (i > 0) { return 1; } else { return -1; } } static void write(wchar_t *text) { DWORD mode; int wlen; DWORD numwritten; HANDLE output_handle; output_handle = GetStdHandle(STD_OUTPUT_HANDLE); wlen = wstring_length(text); if (GetConsoleMode(output_handle,&mode)) { WriteConsoleW(output_handle,text,wlen,&numwritten,0); } else { char *buf; int len; len = WideCharToMultiByte(GetConsoleCP(),0,text,wlen,0,0,0,0); if (len) { buf = HeapAlloc(GetProcessHeap(),0,len); if (buf) { WideCharToMultiByte(GetConsoleCP(),0,text,wlen,buf,len,0,0); WriteFile(output_handle,buf,len,&numwritten,0); HeapFree(GetProcessHeap(),0,buf); } } } } static void write_DWORD(DWORD value) { wchar_t buf[256]; wchar_t *d; d = buf + 256; *--d = 0; if (value) { DWORD i; i = value; while(i) { *--d = '0' + (i % 10); i /= 10; } } else { *--d = '0'; } write(d); } void listresultsW(EVERYTHING_IPC_LIST *list) { DWORD i; if (sort) { sort_list = list; qsort(list->items,list->numitems,sizeof(EVERYTHING_IPC_ITEM),compare_list_items); } for(i=0;i<list->numitems;i++) { if (list->items[i].flags & EVERYTHING_IPC_DRIVE) {MessageBoxA(0,"LPCSTR lpText","LPCSTR lpCaption",0); write(EVERYTHING_IPC_ITEMFILENAME(list,&list->items[i])); write(L"\r\n"); } else {MessageBoxA(0,"LPCSTR else","LPCSTR lpCaption",0); printf(EVERYTHING_IPC_ITEMPATH(list,&list->items[i])); write(L"\\"); printf(EVERYTHING_IPC_ITEMFILENAME(list,&list->items[i])); write(L"\r\n"); } } PostQuitMessage(0); } // custom window proc LRESULT __stdcall window_proc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { printf("proc[%d][%d]\n",msg,WM_COPYDATA); switch(msg) { case WM_COPYDATA: { COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lParam; printf("cds[%d][%d]\n",cds->dwData,COPYDATA_IPCTEST_QUERYCOMPLETEA); switch(cds->dwData) { case COPYDATA_IPCTEST_QUERYCOMPLETEA: listresultsW((EVERYTHING_IPC_LIST *)cds->lpData); gotData=1; return TRUE; } break; } } return DefWindowProc(hwnd,msg,wParam,lParam); } void help(void) { write(L"-r Search the database using a basic POSIX regular expression.\n"); write(L"-i Does a case sensitive search.\n"); write(L"-w Does a whole word search.\n"); write(L"-p Does a full path search.\n"); write(L"-h --help Display this help.\n"); write(L"-n <num> Limit the amount of results shown to <num>.\n"); write(L"-s Sort by full path.\n"); } // main entry int main(int argc,char **argv) { WNDCLASSEX wcex; HWND hwnd; MSG msg; int ret; int q; wchar_t *search; wchar_t *d; wchar_t *e; wchar_t *s; int match_whole_word = 0; int match_path = 0; int regex = 0; int match_case = 0; int wasexename = 0; int matchpath = 0; int i; int wargc; wchar_t **wargv; DWORD num = EVERYTHING_IPC_ALLRESULTS; ZeroMemory(&wcex,sizeof(wcex)); wcex.cbSize = sizeof(wcex); if (!GetClassInfoEx(GetModuleHandle(0),TEXT("IPCTEST"),&wcex)) { ZeroMemory(&wcex,sizeof(wcex)); wcex.cbSize = sizeof(wcex); wcex.hInstance = GetModuleHandle(0); wcex.lpfnWndProc = window_proc; wcex.lpszClassName = TEXT("IPCTEST"); if (!RegisterClassEx(&wcex)) { write(L"failed to register IPCTEST window class\n"); return 1; } } if (!(hwnd = CreateWindow( TEXT("IPCTEST"), TEXT(""), 0, 0,0,0,0, 0,0,GetModuleHandle(0),0))) { write(L"failed to create IPCTEST window\n"); return 1; } // windowHandle=hwnd; int ir=EverythingSendQuery(hwnd,"qgbcs"); printf("[%d]",ir); printf("[%d]",hwnd); return 23; // allow the everything window to send a reply. user32_hdll = LoadLibrary(L"user32.dll"); if (user32_hdll) { pChangeWindowMessageFilterEx = (BOOL (WINAPI *)(HWND hWnd,UINT message,DWORD action,PCHANGEFILTERSTRUCT pChangeFilterStruct))GetProcAddress(user32_hdll,"ChangeWindowMessageFilterEx"); if (pChangeWindowMessageFilterEx) { pChangeWindowMessageFilterEx(hwnd,WM_COPYDATA,MSGFLT_ALLOW,0); } } wargv = CommandLineToArgvW(GetCommandLineW(),&wargc); search = HeapAlloc(GetProcessHeap(),0,65536); if (!search) { write(L"failed to allocate "); write_DWORD(65536); write(L" bytes for search buffer.\n"); if (user32_hdll) { FreeLibrary(user32_hdll); } return 1; } d = search; // allow room for null terminator e = search + (65536 / sizeof(wchar_t)) - 1; wargc--; i = 0; for(;;) { if (i >= wargc) break; if (wcsicmp(wargv[i+1],L"-r") == 0) { regex = 1; } else if (wcsicmp(wargv[i+1],L"-i") == 0) { match_case = 1; } else if (wcsicmp(wargv[i+1],L"-w") == 0) { match_whole_word = 1; } else if (wcsicmp(wargv[i+1],L"-p") == 0) { match_path = 1; } else if (wcsicmp(wargv[i+1],L"-s") == 0) { sort = 1; } else if ((wcsicmp(wargv[i+1],L"-n") == 0) && (i + 1 < wargc)) { i++; num = wstring_to_int(wargv[i+1]); } else if (wargv[i+1][0] == '-') { // unknwon command help(); HeapFree(GetProcessHeap(),0,search); if (user32_hdll) { FreeLibrary(user32_hdll); } return 1; } else { // keep quotes ? q = 0; s = wargv[i+1]; while(*s) { if ((*s == ' ') || (*s == '\t') || (*s == '\r') || (*s == '\n')) { q = 1; break; } s++; } if ((d != search) && (d < e)) *d++ = ' '; if (q) { if (d < e) *d++ = '"'; } // copy append to search s = wargv[i+1]; while(*s) { if (d < e) *d++ = *s; s++; } if (q) { if (d < e) *d++ = '"'; } } i++; } // null terminate *d = 0; if (!sendquery(hwnd,num,search,regex,match_case,match_whole_word,match_path)) { // send query reports error HeapFree(GetProcessHeap(),0,search); if (user32_hdll) { FreeLibrary(user32_hdll); } return 1; } HeapFree(GetProcessHeap(),0,search); // message pump loop: // update windows if (PeekMessage(&msg,NULL,0,0,0)) { ret = (int)GetMessage(&msg,0,0,0); if (ret <= 0) goto exit; // let windows handle it. TranslateMessage(&msg); DispatchMessage(&msg); } else { WaitMessage(); } goto loop; exit: if (user32_hdll) { FreeLibrary(user32_hdll); } return 0; } static int wstring_to_int(const wchar_t *s) { const wchar_t *p; int value; p = s; value = 0; while(*p) { if (!((*p >= '0') && (*p <= '9'))) { break; } value *= 10; value += *p - '0'; p++; } return value; }