int main (int argc)
{
    char str01[32], str02[32];
    unsigned int  n1, n2 , result01, result02;
    int sock, port;
    port = argc;
    //sscanf(argv[1],"%d", &port);
    if(connectToServer(&sock, port)!=0) {
        sprintf(str01,"I couldn't connect to %s:%d\n",argv[1],port);
        perror(str01);
        return -1;
    }
    printf ("give me a natural number: ");
    fgets (str01,32,stdin);
    sscanf(str01,"%u",&n1);
    printf ("give me a natural number: ");
    fgets(str02,32,stdin);
    sscanf(str02,"%u",&n2);
    remoteGCD(sock, n1, n2, &result01);
    printf("gcd(%u,%u)=%u\n", n1, n2, result01);
    remoteLCM(sock,n1, n2, &result02);
    printf("lcm(%u,%u)=%u\n", n1, n2, result02);
    close(sock);
    return 0;
}
int main()
{
    // variables
    int		x1, y1;	/* point 1	*/
    int		x2, y2;	/* point 2	*/
    double	dx1, dy1;	/* point 1: double	*/
    double	dx2, dy2;	/* point 2: double	*/
    double	pow1, pow2; /* powers of x and y	*/
    double	dis_pow;	/* double before sqrt-ing	*/
    double	dis_sqrt;	/* double after sqrt-ing	*/
    long		dis;	/* distance	*/
    char	line[20];	/* line for input	*/

    // prompt input
    printf("Input point 1(x, y): ");
    fgets(line, sizeof(line), stdin);
    sscanf(line, "%d %d", &x1, &y1);
    printf("Input point 2(x, y): ");
    fgets(line, sizeof(line), stdin);
    sscanf(line, "%d %d", &x2, &y2);

    // prepare data
    dx1 = (double)x1;
    dx2 = (double)x2;
    dy1 = (double)y1;
    dy2 = (double)y2;
    pow1 = pow((dx2 - dx1), 2.0);
    pow2 = pow((dy2 - dy1), 2.0);
    dis_pow = pow1 + pow2;
    dis_sqrt = sqrt(dis_pow);

    // report
    printf("dis_pow=%f\n", dis_pow);
    printf("dis_sqrt=%f\n", dis_sqrt);

    /*	dis = sqrt(pow((dx2 - dx1), 2.0) +
    			pow((dy2 - dy1), 2.0));
    */
    // calculate
    //dis = sqrt((x2 - x1)^2 + (y2 - y1)^2);

    // show
    /*	printf("(dx2 - dx1)=%f\n", (dx2 - dx1));
    	printf("pow((dx2 - dx1), 2.0)=%f\n",
    				pow((dx2 - dx1), 2.0));
    	printf("pow((dx2 - dx1), 2.0) + "
    			"pow((dy2 - dy1), 2.0)=%f\n",
    			pow((dx2 - dx1), 2.0)
    			+ pow((dy2 - dy1), 2.0));
    	printf("dis=%f\n", dis);
    	*/
//	printf("(x2 - x1)^2=%d\n", (x2 - x1)^2);
//	printf("(double)x2=%f\n", (double)x2);


    return (0);
}//int main()
Example #3
0
File: main.c Project: karrika/cc65
static unsigned long CvtNumber (const char* Arg, const char* Number)
/* Convert a number from a string. Allow '$' and '0x' prefixes for hex
 * numbers.
 */
{
    unsigned long Val;
    int           Converted;
    char          BoundsCheck;

    /* Convert */
    if (*Number == '$') {
        ++Number;
        Converted = sscanf (Number, "%lx%c", &Val, &BoundsCheck);
    } else {
        Converted = sscanf (Number, "%li%c", (long*)&Val, &BoundsCheck);
    }

    /* Check if we do really have a number */
    if (Converted != 1) {
        Error ("Invalid number given in argument: %s\n", Arg);
    }

    /* Return the result */
    return Val;
}
Example #4
0
static void extract_caps_seccomp(pid_t pid) {
    // open stat file
    char *file;
    if (asprintf(&file, "/proc/%u/status", pid) == -1) {
        perror("asprintf");
        exit(1);
    }
    FILE *fp = fopen(file, "r");
    if (!fp) {
        free(file);
        fprintf(stderr, "Error: cannot open stat file for process %u\n", pid);
        exit(1);
    }

    char buf[BUFLEN];
    while (fgets(buf, BUFLEN - 1, fp)) {
        if (strncmp(buf, "Seccomp:", 8) == 0) {
            char *ptr = buf + 8;
            int val;
            sscanf(ptr, "%d", &val);
            if (val == 2)
                apply_seccomp = 1;
            break;
        }
        else if (strncmp(buf, "CapBnd:", 7) == 0) {
            char *ptr = buf + 8;
            unsigned long long val;
            sscanf(ptr, "%llx", &val);
            apply_caps = 1;
            caps = val;
        }
    }
    fclose(fp);
    free(file);
}
Example #5
0
bool
Reader::decodeDouble( Token &token )
{
    double value = 0;
    const int bufferSize = 32;
    int count;
    int length = int(token.end_ - token.start_);
    if ( length <= bufferSize )
    {
        Char buffer[bufferSize+1];
        memcpy( buffer, token.start_, length );
        buffer[length] = 0;
        count = sscanf( buffer, "%lf", &value );
    }
    else
    {
        std::string buffer( token.start_, token.end_ );
        count = sscanf( buffer.c_str(), "%lf", &value );
    }

    if ( count != 1 )
        return addError( "'" + std::string( token.start_, token.end_ ) + "' is not a number.", token );
    currentValue() = value;
    return true;
}
Example #6
0
bool CIPAddress::ParseStr(const char* address)
{
    u_int32_t a,b,c,d;
    char temp[10];
    char addrtmp[256];
    strcpy(addrtmp, address);

    char* q=addrtmp;
    char* p=strchr(q,'.');
    strncpy(temp,q,p-q);
    temp[p-q]='\0';
    sscanf(temp,"%d",&a);

    q=p+1;
    p=strchr(q,'.');
    strncpy(temp,q,p-q);
    temp[p-q]='\0';
    sscanf(temp,"%d",&b);

    q=p+1;
    p=strchr(q,'.');
    strncpy(temp,q,p-q);
    temp[p-q]='\0';
    sscanf(temp,"%d",&c);

    q=p+1;
    sscanf(q,"%d",&d);

    m_address=(a<<24)|(b<<16)|(c<<8)|d;

    return true;
}
JoystickAction::JoystickAction(std::string string)
{
    type = AXIS;
    number = 0;
    joy = 0;
    joyid = 0;
    try
    {
        const char* str = string.c_str();
        if (strstr(str, "button"))
        {
            type = BUTTON;
            if (sscanf(str, "joy_%d_button_%d", &joyid, &number) < 2)
                throw string;
        }
        else if (strstr(str, "axis"))
        {
            if (sscanf(str, "joy_%d_axis_%d", &joyid, &number) < 2)
                throw string;
        }

        joy = JoystickPool::getSingleton().getJoystick(joyid);
    }
    catch (std::string e)
    {
        std::cerr << "Parse error in joystick config: " << e << std::endl;
    }
}
Example #8
0
void FixFloats(idDict *dict) {
    int count = dict->GetNumKeyVals();
    for (int i = 0; i < count; i++) {
        const idKeyValue *kv = dict->GetKeyVal(i);
        for (int j = 0; j < FixupCount; j++) {
            if (kv->GetKey().Icmp(FloatFixups[j].name) == 0) {
                idStr val;
                if (FloatFixups[j].type == 1) {
                    idVec3 v;
                    sscanf(kv->GetValue().c_str(), "%f %f %f", &v.x, &v.y, &v.z);
                    sprintf(val, "%g %g %g", v.x, v.y, v.z);
                } else if (FloatFixups[j].type == 2) {
                    idMat3 mat;
                    sscanf(kv->GetValue().c_str(),	"%f %f %f %f %f %f %f %f %f ",&mat[0][0],&mat[0][1],&mat[0][2],&mat[1][0],&mat[1][1],&mat[1][2],&mat[2][0],&mat[2][1],&mat[2][2]);
                    sprintf(val, "%g %g %g %g %g %g %g %g %g",mat[0][0],mat[0][1],mat[0][2],mat[1][0],mat[1][1],mat[1][2],mat[2][0],mat[2][1],mat[2][2]);
                } else {
                    float f = atof(kv->GetValue().c_str());
                    sprintf(val, "%g", f);
                }
                dict->Set(kv->GetKey(), val);
                break;
            }
        }
    }
}
Example #9
0
/*
==============================
Dmc_SetKeyValue

Fill in key/values fro the teleporter
==============================
*/
void Dmc_SetKeyValue( dmc_tele_t *pTele, const char *key, const char *value )
{
    float x, y, z;

    if ( !stricmp( key, "classname" ) )
    {
        strcpy( pTele->classname, value );
    }
    else if ( !stricmp( key, "target" ) )
    {
        strcpy( pTele->target, value );
    }
    else if ( !stricmp( key, "targetname" ) )
    {
        strcpy( pTele->targetname, value );
    }
    else if ( !stricmp( key, "angles" ) )
    {
        if ( sscanf( value, "%f %f %f", &x, &y, &z ) == 3 )
        {
            pTele->angles[ 0 ] = x ;
            pTele->angles[ 1 ] = y;
            pTele->angles[ 2 ] = z;
        }
    }
    else if ( !stricmp( key, "origin" ) )
    {
        if ( sscanf( value, "%f %f %f", &x, &y, &z ) == 3 )
        {
            pTele->origin[ 0 ]  = x;
            pTele->origin[ 1 ]  = y;
            pTele->origin[ 2 ]  = z;
        }
    }
}
Example #10
0
/* getdoubles2ptf:
 * converts a graph attribute in inches to a pointf in points.
 * If only one number is given, it is used for both x and y.
 * Returns true if the attribute ends in '!'.
 */
static boolean getdoubles2ptf(graph_t * g, char *name, pointf * result)
{
    char *p;
    int i;
    double xf, yf;
    char c = '\0';
    boolean rv = FALSE;

    if ((p = agget(g, name))) {
        i = sscanf(p, "%lf,%lf%c", &xf, &yf, &c);
        if ((i > 1) && (xf > 0) && (yf > 0)) {
            result->x = POINTS(xf);
            result->y = POINTS(yf);
            if (c == '!')
                rv = TRUE;
        }
        else {
            c = '\0';
            i = sscanf(p, "%lf%c", &xf, &c);
            if ((i > 0) && (xf > 0)) {
                result->y = result->x = POINTS(xf);
                if (c == '!') rv = TRUE;
            }
        }
    }
    return rv;
}
Example #11
0
/* set load address for elf image */
int
do_load_addr_option (skyeye_option_t * this_option, int num_params,
                     const char *params[])
{
    int i;
    char name[MAX_PARAM_NAME], value[MAX_PARAM_NAME];
    unsigned long load_base;
    unsigned long load_mask;
    for (i = 0; i < num_params; i++) {
        if (split_param (params[i], name, value) < 0)
            SKYEYE_ERR
            ("Error: sound has wrong parameter \"%s\".\n",
             name);
        if (!strncmp ("base", name, strlen (name))) {
            sscanf (value, "%x", &load_base);
        }
        else if (!strncmp ("mask", name, strlen (name))) {
            sscanf (value, "%x", &load_mask);
        }
        else
            SKYEYE_ERR ("Error: Unknown load_addr option  \"%s\"\n", params[i]);
    }
    sky_pref_t *pref;
    /* get the current preference for simulator */
    pref = get_skyeye_pref();
    pref->exec_load_base = load_base;
    pref->exec_load_mask = load_mask;
    /* FIXME, we should update load_base and load_mask to preference of SkyEye */
    fprintf(stderr, "%s not finished.\n", __FUNCTION__);
    //printf("Your elf file will be load to: base address=0x%x,mask=0x%x\n", load_base, load_mask);
    return 0;
}
Example #12
0
static int flsh_erase_cmd(int argc, char* argv[])
{
    unsigned int dst, len;
    int result;

    if (( argc == 0 )||( sscanf(argv[0],"%x", &dst )!=1) )
    {
        printf(" Invalid HEX: %s.\n", argv[0]);
        return -1 ;
    }

    if( argc > 1 )
    {
        if(sscanf( argv[1], "%x", &len )!=1)
        {
            printf(" Invalid HEX: %s.\n", argv[1]);
            return -1 ;
        }
    }
    else
        len = 0x10000 ;

    printf("flsh-earse %08x, len=%08x!",dst,len);
    result=flsh_erase( dst, len );
    printf("result=%08x\n",result);

    return result;
}
Example #13
0
static int flsh_write_cmd( int argc, char* argv[])
{
    unsigned int src, dst, len;
    int result;

    if (sscanf( argv[0],"%x", &dst )!=1)
    {
        printf(" Invalid Address(HEX) value.\n");
        return -1 ;
    }

    if (sscanf( argv[2],"%x", &src )!=1)
    {
        printf(" Invalid Address(HEX) value.\n");
        return -1 ;
    }

    if (sscanf( argv[1],"%x", &len )!=1)
    {
        printf(" Invalid len value.\n");
        return -1 ;
    }

    printf("flash-wr %08x, len=%08x,from=%08x!",dst,len,src);
    result=flsh_write(dst, src, len );
    printf("result=%08x\n",result);

    return result;
}
Example #14
0
struct w_clockspec *w_clockspec_parse(json_t *value)
{
    const char *str;
    uint64_t start_time;
    int pid;
    uint32_t root_number;
    uint32_t ticks;

    struct w_clockspec *spec;

    spec = calloc(1, sizeof(*spec));
    if (!spec) {
        return NULL;
    }

    if (json_is_integer(value)) {
        spec->tag = w_cs_timestamp;
        spec->timestamp.tv_usec = 0;
        spec->timestamp.tv_sec = (time_t)json_integer_value(value);
        return spec;
    }

    str = json_string_value(value);
    if (!str) {
        free(spec);
        return NULL;
    }

    if (str[0] == 'n' && str[1] == ':') {
        spec->tag = w_cs_named_cursor;
        // spec owns the ref to the string
        spec->named_cursor.cursor = w_string_new(str);
        return spec;
    }

    if (sscanf(str, "c:%" PRIu64 ":%d:%" PRIu32 ":%" PRIu32,
               &start_time, &pid, &root_number, &ticks) == 4) {
        spec->tag = w_cs_clock;
        spec->clock.start_time = start_time;
        spec->clock.pid = pid;
        spec->clock.root_number = root_number;
        spec->clock.ticks = ticks;
        return spec;
    }

    if (sscanf(str, "c:%d:%" PRIu32, &pid, &ticks) == 2) {
        // old-style clock value (<= 2.8.2) -- by setting clock time and root number
        // to 0 we guarantee that this is treated as a fresh instance
        spec->tag = w_cs_clock;
        spec->clock.start_time = 0;
        spec->clock.pid = pid;
        spec->clock.root_number = root_number;
        spec->clock.ticks = ticks;
        return spec;
    }

    free(spec);
    return NULL;
}
Example #15
0
// Read and dump initial values for memory
//
void initialize_memory(int argc, char *argv[], CPU *cpu) {
    FILE *datafile = get_datafile(argc, argv);
    printf("\nBefore While");
    // Buffer to read next line of text into
#define BUFFER_LEN 80
    char buffer[BUFFER_LEN];
    printf("\nBefore While");
    // Will read the next line (words_read = 1 if it started
    // with a memory value). Will set memory location loc to
    // value_read
    //
    int value_read, words_read, loc = 0, done = 0;

    char *read_success;    // NULL if reading in a line fails.
    read_success = fgets(buffer, BUFFER_LEN, datafile);
    int range = MEMLEN -1;

    while (read_success != NULL && !done) {
        // If the line of input begins with an integer, treat
        // it as the memory value to read in.  Ignore junk
        // after the number and ignore blank lines and lines
        // that don't begin with a number.
        //

        words_read = sscanf(buffer, "%d", &value_read);

        //printf("\nWords Read: %d",words_read);
        // *** STUB *** set memory value at current location to
        // value_read and increment location.  Exceptions: If
        // loc is out of range, complain and quit the loop. If
        // value_read is outside -9999...9999, then it's a
        // sentinel and we should say so and quit the loop.
        if(words_read == 1) {
            if(loc>range) {
                printf("\nERROR: Location %d is outside range",value_read);
                done = 1;
            } else if(value_read < -9999 || value_read > 9999) {
                printf("\nSentinel %d at location %d",value_read,loc);
                done = 1;
            } else {
                (*cpu).mem[loc] = value_read;
                loc++;
            }
        }

        // Get next line and continue the loop
        //
        // *** STUB ***
        words_read = sscanf(buffer,"%d",&value_read);
    }//end while

    // Initialize rest of memory
    //
    while (loc < MEMLEN) {
        cpu -> mem[loc++] = 0;
    }
    dump_memory(cpu);
}
Example #16
0
/**
 * used for db put/asc2g
 */
int
rt_metaball_adjust(struct bu_vls *logstr, struct rt_db_internal *intern, int argc, const char **argv)
{
    struct rt_metaball_internal *mb;
    const char *pts;
    const char *pend;
    double thresh;

    if (argc != 3)  {
        bu_vls_printf(logstr, "Invalid number of arguments: %d\n", argc);
        return BRLCAD_ERROR;
    }

    RT_CK_DB_INTERNAL(intern);
    mb = (struct rt_metaball_internal *)intern->idb_ptr;
    RT_METABALL_CK_MAGIC(mb);

    if ( strlen(*argv) != 1 || (**argv < '0' || **argv > '2') ) {
        bu_vls_printf(logstr, "Invalid method type, must be one of 0, 1, or 2.");
        return BRLCAD_ERROR;
    }
    mb->method = *argv[0] - '0';
    sscanf(argv[1], "%lG", &thresh);
    mb->threshold = thresh;
    BU_LIST_INIT(&mb->metaball_ctrl_head);

    pts = argv[2];
    pend = pts + strlen(pts);

    while (1) {
        int len;
        double xyz[3];
        double fldstr, goo;
        point_t loc;
        const point_t *locp = (const point_t *)&loc;

        while ( pts < pend && *pts != '{' ) ++pts;
        if (pts >= pend) break;
        len = sscanf(pts, "{%lG %lG %lG %lG %lG}", &xyz[0], &xyz[1], &xyz[2], &fldstr, &goo);
        VMOVE(loc, xyz);

        if (len == EOF) break;
        if (len != 5) {
            bu_vls_printf(logstr, "Failed to parse point information: \"%s\"", pts);
            return BRLCAD_ERROR;
        }
        pts++;
        if (rt_metaball_add_point (mb, locp, fldstr, goo)) {
            bu_vls_printf(logstr, "Failure adding point: {%f %f %f %f %f}", V3ARGS(loc), fldstr, goo);
            return BRLCAD_ERROR;
        }
    }

    return BRLCAD_OK;
}
Example #17
0
static void
x264_parse_psy(const gchar *psy, gdouble *psy_rd, gdouble *psy_trell)
{
    *psy_rd = 0.;
    *psy_trell = 0.;
    if (psy == NULL) return;
    if (2 == sscanf(psy, "%lf|%lf", psy_rd, psy_trell) ||
            2 == sscanf(psy, "%lf,%lf", psy_rd, psy_trell))
    {
    }
}
Example #18
0
static void parse_args(int argc, char *argv[])
{
    int c;
    float input_outoff;

    for (;;) {
        c = getopt(argc, argv, "c:deg:hm:o:");
        if (c < 0)
            break;
        switch (c) {
        case 'c':
            channel_nr = atoi(optarg);
            if (!channel_nr) {
                fprintf(stderr, "Invalid channel_nr\n");
                exit(EXIT_FAILURE);
            }
            break;
        case 'd':
            out_enable = 0;
            break;
        case 'e':
            out_enable = 1;
            break;
        case 'g':
            if (!sscanf(optarg, "%i", &outgain)) {
                fprintf(stderr, "Invalid output gain\n");
                exit(EXIT_FAILURE);
            }
            set_outgain++;
            break;
        case 'h':
            usage_complete();
            exit(EXIT_SUCCESS);
        case 'm':
            module_nr = atoi(optarg);
            break;
        case 'o':
            if (!sscanf(optarg, "%g", &input_outoff)) {
                fprintf(stderr, "Invalid output offset\n");
                exit(EXIT_FAILURE);
            }
            if (input_outoff == 0)
                outoff = CVORG_OUT_OFFSET_0V;
            else if (input_outoff == 2.5)
                outoff = CVORG_OUT_OFFSET_2_5V;
            else {
                fprintf(stderr, "Invalid output offset\n");
                exit(EXIT_FAILURE);
            }
            break;
        }
    }
}
Example #19
0
static struct iio_context * iio_create_usb_context_from_string(const char *dev)
{
    unsigned short vid, pid;

    if ((sscanf(dev, "0x%04hx:0x%04hx", &vid, &pid) != 2) &&
            sscanf(dev, "%04hx:%04hx", &vid, &pid) != 2) {
        errno = EINVAL;
        return NULL;
    }

    return usb_create_context(vid, pid);
}
Example #20
0
void show_trash(char * argv[], uint32_t tcpRef, void *bufRef) {
    char *pChar = uma_dbg_get_buffer();
    int limit;
    int ret;

    if (argv[1] == NULL) {
        export_rm_bins_stats(pChar);
        uma_dbg_send(tcpRef, bufRef, TRUE, uma_dbg_get_buffer());
        return;
    }

    if (strcmp(argv[1],"rate")==0) {

        if (argv[2] == NULL) {
            export_limit_rm_files = RM_FILES_MAX;
            sprintf(pChar," revert to default (%d) \n",RM_FILES_MAX);
            uma_dbg_send(tcpRef, bufRef, TRUE, uma_dbg_get_buffer());
            return;
        }

        ret = sscanf(argv[2], "%d", &limit);
        if (ret != 1) {
            show_trash_help(pChar);
            uma_dbg_send(tcpRef, bufRef, TRUE, uma_dbg_get_buffer());
            return;
        }
        export_limit_rm_files = limit;
        uma_dbg_send(tcpRef, bufRef, TRUE, "Done\n");
        return;
    }

    if (strcmp(argv[1],"limit")==0) {

        if (argv[2] == NULL) {
            show_trash_help(pChar);
            uma_dbg_send(tcpRef, bufRef, TRUE, uma_dbg_get_buffer());
            return;
        }

        ret = sscanf(argv[2], "%d", &limit);
        if (ret != 1) {
            show_trash_help(pChar);
            uma_dbg_send(tcpRef, bufRef, TRUE, uma_dbg_get_buffer());
            return;
        }
        export_rm_bins_threshold_high = limit;
        uma_dbg_send(tcpRef, bufRef, TRUE, "Done\n");
        return;
    }
    show_trash_help(pChar);
    uma_dbg_send(tcpRef, bufRef, TRUE,uma_dbg_get_buffer());
}
int main(void)
{
    int i, dev_cnt = 0, level, idx, ph;
    FILE *mdstat;
    char buf[256], status[16];

    struct raid_disk raid_ = {0};
    struct raid_disk *raid = &raid_;

    mdstat = fopen("file.proc_mdstat", "r");
    if (mdstat == 0) {
        perror("Cannot open 'file.proc_mdstat'\n");
        return -errno;
    }

    do {
        buf[0] = 0;
        while (buf[0] != 'm' || buf[1] != 'd')
            if (fgets(buf, sizeof(buf), mdstat) == 0) {
                fclose(mdstat);
                return 0;
            }
        i = sscanf(buf, "md%d : %s raid%d", &idx, status, &level);
        if (i != 3 || (level != 0 && level != 1 && level != 5) || strcmp(status, "active"))
            continue;
        ph = strstr(buf, "raid") - buf + sizeof("raid") + 1;
        raid->pdisk_cnt = 0;
        while (raid->pdisk_cnt < RAID_MAX_DISKS) {
            while (buf[ph] && isspace(buf[ph]) && ph < sizeof(buf))
                ph++;
            if (buf[ph] == 0 || ph >= sizeof(buf))
                break;
            i = sscanf(buf + ph, "%7[^[][%*d]",
                       raid->pdisk[raid->pdisk_cnt]);
            if (i != 1)
                break;
            raid->pdisk_cnt++;
            while (buf[ph] && !isspace(buf[ph]) && ph < sizeof(buf))
                ph++;
            if (buf[ph] == 0 || ph >= sizeof(buf))
                break;
        }
        if (raid->pdisk_cnt == 0)
            continue;
        raid->level = level;
        dev_cnt++;
    } while (dev_cnt < 1);

    fclose(mdstat);
    return 0;
}
Example #22
0
static unsigned long
find_cpu_speed(void)
{
    FILE *fp1;
    unsigned long f1 = 0, f2 = 0;
    char buffer[128], *p, *value;

    memset(buffer, 0, sizeof(buffer));

    fp1 = fopen("/proc/cpuinfo", "r");
    if (fp1 == NULL)
        return 0;

    for (;;) {
        buffer[0] = '\0';

        p  = fgets(buffer, 127, fp1);
        if (p == NULL)
            break;

        /* skip  blank lines */
        if (*p == '\n') continue;

        p = strchr(buffer, ':');
        if (p == NULL)
            break;

        /*
         * p+2: +1 = space, +2= firt character
         * strlen()-1 gets rid of \n
         */
        *p = '\0';
        value = p+2;

        value[strlen(value)-1] = '\0';

        if (!strncasecmp("cpu MHz", buffer, 7)) {
            float fl;
            sscanf(value, "%f", &fl);
            f1 = lroundf(fl);
            break;
        }
        if (!strncasecmp("BogoMIPS", buffer, 8)) {
            float fl;
            sscanf(value, "%f", &fl);
            f2 = lroundf(fl);
        }
    }
    fclose(fp1);
    return f1 == 0 ? f2 : f1;
}
Example #23
0
int main(int argc, char **argv) {
    if (nva_init()) {
        fprintf (stderr, "PCI init failure!\n");
        return 1;
    }
    int c;
    int cnum =0;
    while ((c = getopt (argc, argv, "c:")) != -1)
        switch (c) {
        case 'c':
            sscanf(optarg, "%d", &cnum);
            break;
        }
    if (cnum >= nva_cardsnum) {
        if (nva_cardsnum)
            fprintf (stderr, "No such card.\n");
        else
            fprintf (stderr, "No cards found.\n");
        return 1;
    }
    int32_t a, b = 1, i;
    if (optind >= argc) {
        fprintf (stderr, "No address specified.\n");
        return 1;
    }
    sscanf (argv[optind], "%x", &a);
    if (optind + 1 < argc)
        sscanf (argv[optind + 1], "%x", &b);
    int ls = 1;
    while (b > 0) {
        uint8_t z[16];
        int s = 0;
        for (i = 0; i < 16 && i < b; i++)
            if (z[i] = nva_rd8(cnum, a+i)) s = 1;
        if (s) {
            ls = 1;
            printf ("%08x:", a);
            for (i = 0; i < 16 && i < b; i++) {
                printf (" %02x", z[i]);
            }
            printf ("\n");
        } else  {
            if (ls) printf ("...\n"), ls = 0;
        }
        a+=16;
        b-=16;
    }
    return 0;
}
Example #24
0
/*
 * params - parameters in the following format
 *      "no_of_params\0param1\0param2\0param3\0...\0"
 *      for example, string for 2 parameters with value 10 and 21
 *      is specified as "2\010\021\0".
 */
static int clariion_set_params(struct scsi_device *sdev, const char *params)
{
    struct clariion_dh_data *csdev = sdev->handler_data;
    unsigned int hr = 0, st = 0, argc;
    const char *p = params;
    int result = SCSI_DH_OK;

    if ((sscanf(params, "%u", &argc) != 1) || (argc != 2))
        return -EINVAL;

    while (*p++)
        ;
    if ((sscanf(p, "%u", &st) != 1) || (st > 1))
        return -EINVAL;

    while (*p++)
        ;
    if ((sscanf(p, "%u", &hr) != 1) || (hr > 1))
        return -EINVAL;

    if (st)
        csdev->flags |= CLARIION_SHORT_TRESPASS;
    else
        csdev->flags &= ~CLARIION_SHORT_TRESPASS;

    if (hr)
        csdev->flags |= CLARIION_HONOR_RESERVATIONS;
    else
        csdev->flags &= ~CLARIION_HONOR_RESERVATIONS;

    /*
     * If this path is owned, we have to send a trespass command
     * with the new parameters. If not, simply return. Next trespass
     * command would use the parameters.
     */
    if (csdev->lun_state != CLARIION_LUN_OWNED)
        goto done;

    csdev->lun_state = CLARIION_LUN_UNINITIALIZED;
    result = send_trespass_cmd(sdev, csdev);
    if (result != SCSI_DH_OK)
        goto done;

    /* Update status */
    result = clariion_send_inquiry(sdev, csdev);

done:
    return result;
}
Example #25
0
static ssize_t fan_proc_write(struct file *file, const char __user *buf,
                              size_t count, loff_t *pos)
{
    struct toshiba_acpi_dev *dev = PDE(file->f_path.dentry->d_inode)->data;
    char cmd[42];
    size_t len;
    int value;
    u32 hci_result;

    len = min(count, sizeof(cmd) - 1);
    if (copy_from_user(cmd, buf, len))
        return -EFAULT;
    cmd[len] = '\0';

    if (sscanf(cmd, " force_on : %i", &value) == 1 &&
            value >= 0 && value <= 1) {
        hci_write1(dev, HCI_FAN, value, &hci_result);
        if (hci_result != HCI_SUCCESS)
            return -EIO;
        else
            dev->force_fan = value;
    } else {
        return -EINVAL;
    }

    return count;
}
Example #26
0
void executeCommand() {

    char buf[MAX_LEN];
    char event[MAX_EVENT_LEN];

    fgets(buf, MAX_LEN, stdin);
    sscanf(buf, "%s", event);

    int isSucceed = FALSE;

    if(strcmp(buf, "/time\n") == 0) {
        isSucceed = timeCommand();
        printCmdLog(auditfd, name, event, isSucceed, "client");
    } else if(strcmp(buf, "/help\n") == 0) {
        printUsage();
        isSucceed = TRUE;
        printCmdLog(auditfd, name, event, isSucceed, "client");
    } else if(strcmp(buf, "/logout\n") == 0) {
        isSucceed = logoutCommand();
        printCmdLog(auditfd, name, event, isSucceed, "client");
        printLogoutLog(auditfd, name, TRUE);
    } else if(strcmp(buf, "/listu\n") == 0) {
        isSucceed = listuCommand();
        printCmdLog(auditfd, name, event, isSucceed, "client");
    } else if(strncmp(buf, "/chat", 5) == 0) {
        isSucceed = chatCommand(buf);
        printCmdLog(auditfd, name, event, isSucceed, "client");
    } else if(strcmp(buf, "/audit\n") == 0) {
        isSucceed = auditCommand();
        printCmdLog(auditfd, name, event, isSucceed, "client");
    } else {
        printError("Command does not exist\n");
        printCmdLog(auditfd, name, event, isSucceed, "client");
    }
}
Example #27
0
int login() {
    char buf[MAX_LEN];
    char motd[MAX_LEN];

    int loginSucceed = FALSE;

    Send(clientfd, "WOLFIE \r\n\r\n", strlen("WOLFIE \r\n\r\n"), 0);
    Recv(clientfd, buf, MAX_LEN, 0);

    if(strcmp(buf, "EIFLOW \r\n\r\n") == 0) {
        if(authenticateUser() == TRUE) {
            if(promptPassword() == TRUE) {
                Recv(clientfd, buf, MAX_LEN, 0);

                if(strncmp(buf, "HI ", 3) == 0 && strcmp(&buf[strlen(buf)-5], " \r\n\r\n") == 0) {
                    Recv(clientfd, buf, MAX_LEN, 0);

                    if(strncmp(buf, "MOTD ", 5) == 0 && strcmp(&buf[strlen(buf)-5], " \r\n\r\n") == 0) {
                        sscanf(buf, "MOTD %s \r\n\r\n", motd);
                        sfwrite(&Q_lock, stdout, "%s\n", motd);

                        loginSucceed = TRUE;
                        printLoginLog(auditfd, name, hostname, port, TRUE, motd);
                    }
                }
            }
        }
    }

    return loginSucceed;
}
Example #28
0
/*
 * Set Mode
 */
static int
set_mode_info(int		skfd,
              char *		ifname,
              char *		args[],		/* Command line args */
              int		count)		/* Args count */
{
    struct iwreq		wrq;
    unsigned int		k;		/* Must be unsigned */

    /* Avoid "Unused parameter" warning */
    count = count;

    /* Check if it is a uint, otherwise get is as a string */
    if(sscanf(args[0], "%i", &k) != 1)
    {
        k = 0;
        while((k < IW_NUM_OPER_MODE) &&
                strncasecmp(args[0], iw_operation_mode[k], 3))
            k++;
    }
    if(k >= IW_NUM_OPER_MODE)
    {
        errarg = 0;
        return(IWERR_ARG_TYPE);
    }

    wrq.u.mode = k;
    if(iw_set_ext(skfd, ifname, SIOCSIWMODE, &wrq) < 0)
        return(IWERR_SET_EXT);

    /* 1 arg */
    return(1);
}
Example #29
0
/** Called when asyn clients call pasynInt32->write().
  * This function converts the integer to a string and sends it to the echoServer.
  * It reads back the string response, converts it to a number, divides by 2 and calls
  * the callbacks with the new value.
  * For all parameters it sets the value in the parameter library and calls any registered callbacks..
  * \param[in] pasynUser pasynUser structure that encodes the reason and address.
  * \param[in] value Value to write. */
asynStatus asynPortTest::writeInt32(asynUser *pasynUser, epicsInt32 value)
{
    int function = pasynUser->reason;
    size_t nRead, nActual;
    int eomReason;
    int readValue;
    asynStatus status = asynSuccess;
    const char* functionName = "writeInt32";

    /* Set the parameter in the parameter library. */
    status = (asynStatus) setIntegerParam(function, value);

    if (function == Int32Data) {
        sprintf(writeBuffer, "%d", value);
        status = pasynOctetSyncIO->writeRead(pasynUserEcho, writeBuffer, strlen(writeBuffer), readBuffer,
                                             sizeof(readBuffer), TIMEOUT, &nActual, &nRead, &eomReason);
        sscanf(readBuffer, "%d", &readValue);
        readValue /= 2;
        setIntegerParam(Int32Data, readValue);
    }

    /* Do callbacks so higher layers see any changes */
    status = (asynStatus) callParamCallbacks();

    if (status)
        epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
                      "%s:%s: status=%d, function=%d, value=%d",
                      driverName, functionName, status, function, value);
    else
        asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
                  "%s:%s: function=%d, value=%d\n",
                  driverName, functionName, function, value);
    return status;
}
//*****************************************
uint8_t vobSubGetLanguage(const char *filename,vobSubLanguage *lingua)
{
    char str[1024];
    char s[16];
    uint32_t nb=0,index;
    FILE *fd=NULL;

    fd=fopen(filename,"rb");
    if(!fd) return 0;




    while(!feof(fd))
    {
        fgets(str,1023,fd);
        if(!strncmp(str,"id: ",3))
        {
            sscanf(str,"id: %s index: %d",s,&index);
            lingua->language[nb].name=new char[3];
            lingua->language[nb].name[0]=str[4];
            lingua->language[nb].name[1]=str[5];
            lingua->language[nb].name[2]=0;
            //
            lingua->language[nb].index=index;
            nb++;
        }
    }
    lingua->nbLanguage=nb;
    return 1;
}