Example #1
1
int main( int argc , char *argv[])
{
    char hostname[100];

    if ( argc >= 3 ) sprintf(hostname,argv[2]);
    else
        sprintf(hostname,"www.microsoft.com");

    if ( argc >=5 ) timeout=atoi(argv[4]);

    if ( argc >=4 ) port=atoi(argv[3]);

    //Get the DNS servers from the resolv.conf file
    if ( argc == 1 )
        get_dns_servers();
    else
        strcpy(dns_servers[0] , argv[1]);

    //Get the hostname from the terminal
    //printf("Enter Hostname to Lookup : ");
    //scanf("%s" , hostname);
    //Now get the ip of this hostname , A record
    return ngethostbyname(hostname , T_A);

}
Example #2
1
int
main(int argc, char **argv)
{
    int		i, nthreads;
    pthread_t	tid[MAXNTHREADS];

    if (argc != 3)
        err_quit("usage: incr_rwlock1 <#loops> <#threads>");
    nloop = atoi(argv[1]);
    nthreads = min(atoi(argv[2]), MAXNTHREADS);

    /* 4obtain write lock */
    Pthread_rwlock_wrlock(&shared.rwlock);

    /* 4create all the threads */
    Set_concurrency(nthreads);
    for (i = 0; i < nthreads; i++) {
        Pthread_create(&tid[i], NULL, incr, NULL);
    }
    /* 4start the timer and release the write lock */
    Start_time();
    Pthread_rwlock_unlock(&shared.rwlock);

    /* 4wait for all the threads */
    for (i = 0; i < nthreads; i++) {
        Pthread_join(tid[i], NULL);
    }
    printf("microseconds: %.0f usec\n", Stop_time());
    if (shared.counter != nloop * nthreads)
        printf("error: counter = %ld\n", shared.counter);

    exit(0);
}
Example #3
1
bool GameClass::readEntityData(std::ifstream &stream) {
    std::string line, type;
    while (std::getline(stream, line)) {
        if (line == "") {
            break;
        }
        std::istringstream sStream(line);
        std::string key, value;
        std::getline(sStream, key, '=');
        std::getline(sStream, value);
        if (key == "type") {
            type = value;
        }
        else if (key == "location") {
            std::istringstream lineStream(value);
            std::string xPosition, yPosition;
            std::getline(lineStream, xPosition, ',');
            std::getline(lineStream, yPosition, ',');
            float placeX = atoi(xPosition.c_str()) / 16 * 0.08f + 0.08f;
            float placeY = atoi(yPosition.c_str()) / 16 * - 0.08f;
            placeEntity(type, placeX, placeY);
        }
    }
    return true;
}
Example #4
1
File: honey.c Project: pbos/kth
int main(int argc, char* argv[])
{
    int bees = 4;
    if(argc > 1)
        bees = atoi(argv[1]);
    if(argc > 2)
        portions = atoi(argv[2]);

    sem_init(&filled, 0, 0);
    sem_init(&empty, 0, portions);
    sem_init(&bee_mutex, 0, 1);
    sem_init(&bear_wait, 0, 0);

    printf("There are %d bees.\n", bees);

    pthread_t bee_threads[bees];

    int i;
    for(i = 0; i < bees; ++i)
    {
        pthread_create(&bee_threads[i], NULL, bee, (void *)(i+1));
    }

    pthread_t parent;
    pthread_create(&parent, NULL, bear, NULL);

    pthread_exit(NULL);
}
Example #5
1
void Map::readMapFromFile(std::string filePath)
{
    std::vector<std::vector<std::string>> info = FileUtils::readFile(filePath, '\t');
    std::vector<std::vector<std::string>>::iterator it;
    it = info.begin();
    std::vector<std::string> arr;

    //duyet nhung dong con lai
    while(it != info.end())
    {
        arr = *it++;
        int ID_Quadtree = atoi(arr.at(0).c_str());
        int ID = atoi(arr.at(1).c_str());

        //1 so doi tuong la bound cua scene
        if (ID < 50)
        {
            //add bound cho info scene
            MapLoader::getInstance()->getInfoSceneByKey(ID)->getBoundFromFile(arr);
        } else
        {
            this->listInfoOfObject[ID_Quadtree] = arr;
            this->ID_Max ++;
        }
    }
}
Example #6
1
int main(int argc, char *argv[]) {
    /* Loop counter */
    int i;

    /* Verify the correct number of arguments were passed in */
    if(argc != 4) {
        fprintf(stderr, "USAGE:./main.out <INT> <INT> <INT>\n");
    }

    int mainSleepTime = atoi(argv[1]); /* Time in seconds for main to sleep */
    int numProd = atoi(argv[2]); /* Number of producer threads */
    int numCons = atoi(argv[3]); /* Number of consumer threads */

    /* Initialize the app */
    initializeData();

    /* Create the producer threads */
    for(i = 0; i < numProd; i++) {
        /* Create the thread */
        pthread_create(&tid,&attr,producer,NULL);
    }

    /* Create the consumer threads */
    for(i = 0; i < numCons; i++) {
        /* Create the thread */
        pthread_create(&tid,&attr,consumer,NULL);
    }

    /* Sleep for the specified amount of time in milliseconds */
    sleep(mainSleepTime);

    /* Exit the program */
    printf("Exit the program\n");
    exit(0);
}
Example #7
1
int main(int argc, char *argv[]) {
    int s,n;
    unsigned int rcv;
    char *request;
    char recvbuf[256];
    banner();
    if( argc < 3)
        argv[2] = "80";
    else if ((atoi(argv[2]) < 1) || (atoi(argv[2]) > 65534))
        usage(argv[0]);
    if( (argc < 2) )
        usage(argv[0]);
    request = (char *) malloc(1024);
    printf("[+] Connecting to remote host\n");
    s = remote_connect(argv[1],atoi(argv[2]));
    sleep(1);
    printf("[+] Creating buffer\n");
    sprintf(request,BUGSTR,evilrequest);
    printf("[+] Sending %d bytes of painfull buffer\n",strlen(evilrequest));
    if ( send ( s, request, strlen (request), 0) <= 0 )
    {
        printf("[X] Failed to send buffer\n");
        close(s);
        exit(1);
    }
    sleep(1);
    printf("[+] Done, Packet Sent\n");
    close(s);
    free(request);
    request = NULL;
    return 0;
}
Example #8
0
int main(int argc, char **argv) {

    if (argc != 3) {
        std::cout << "%s <n> <input_type> <alg_type>" << std::endl;
        std::cout << "input_type 0: uniform random"  << std::endl;
        std::cout << "           1: already sorted" << std::endl;
        std::cout << "           2: almost sorted" << std::endl;
        std::cout << "           3: single unique value" << std::endl;
        std::cout << "           4: sorted in reverse" << std::endl;
        exit(1);
    }

    int n;

    n = atoi(argv[1]);

    assert(n > 0);
    assert(n <= 1000000000);

    float *A = new float[n];
    int input_type = atoi(argv[2]);
    assert(input_type >= 0);
    assert(input_type <= 4);

    gen_input(A, n, input_type);

    int num_iterations = 10;
    merge_sort_omp_parallel(A, n, num_iterations);

    delete [] A;

    return 0;
}
Example #9
0
int
atot(char *p, time_t *store)
{
    static struct tm *lt;
    char *t;
    const char **mp;
    time_t tval;
    int day, month, year;

    if (!*p) {
        *store = 0;
        return (0);
    }
    if (!lt) {
        unsetenv("TZ");
        time(&tval);
        lt = localtime(&tval);
    }
    if (!(t = strtok(p, " \t")))
        goto bad;
    if (isdigit(*t)) {
        month = atoi(t);
    } else {
        for (mp = months;; ++mp) {
            if (!*mp)
                goto bad;
            if (!strncasecmp(*mp, t, 3)) {
                month = mp - months + 1;
                break;
            }
        }
    }
    if (!(t = strtok(NULL, " \t,")) || !isdigit(*t))
        goto bad;
    day = atoi(t);
    if (!(t = strtok(NULL, " \t,")) || !isdigit(*t))
        goto bad;
    year = atoi(t);
    if (day < 1 || day > 31 || month < 1 || month > 12)
        goto bad;
    /* Allow two digit years 1969-2068 */
    if (year < 69)
        year += 2000;
    else if (year < 100)
        year += 1900;
    if (year < 1969)
bad:
        return (1);
    lt->tm_year = year - 1900;
    lt->tm_mon = month - 1;
    lt->tm_mday = day;
    lt->tm_hour = 0;
    lt->tm_min = 0;
    lt->tm_sec = 0;
    lt->tm_isdst = -1;
    if ((tval = mktime(lt)) < 0)
        return (1);
    *store = tval;
    return (0);
}
Example #10
0
int main(int argc, char *argv[])
{
    int port, srvport, retval;
    datagram_t datagram;

    // Check command line arguments
    if (argc != 3) {
        fprintf(stderr, "usage: %s <localport> <serverport>\n", argv[0]);
        exit(-1);
    }
    port = atoi(argv[1]);
    srvport = atoi(argv[2]);

    init_datagram_service(port, DEBUG_ALL);

    // Prepare datagram
    bzero(&datagram, sizeof(datagram));
    strcpy(datagram.srcaddr, "128.2.13.139"); // These should be command line inputs
    strcpy(datagram.dstaddr, "128.2.13.139"); // I am just being lazy here :-).
    // replace with your ip values before running
    datagram.srcport = port;
    datagram.dstport = srvport;
    strcpy(datagram.data, "Hello World!");
    datagram.size = 12;

    // Send datagram
    retval = send_datagram(&datagram);
    if (retval < 0) {
        perror("Send error");
    }
    printf("Sent %d bytes\n", retval);

    return 0;
}
bool CEditorAction::Valid(CApplication* pApp)
{
    // if the user removes an object sometimes the conditions / actions can still refer to the removed object
    // and this causes a headache

    // uberhack: set global filter removed
    if (oid == -1 && actID == 7)
        return false;

    CObjType* objecttype = pApp->FindObjTypeFromNumber(oid);
    if(objecttype )
    {
        if(mid < -1)
        {
            //check that the effect still exists
            if(!objecttype->GetEffect(mid * -1))
                return false;
        }
        if(mid > -1)
        {
            if(!objecttype->GetBehaviorByUniqueID(mid))
                return false;
        }

        // loop each param;
        for(int p = 0; p < params.size(); p++)
        {
            CEditorParam* param = params.at(p);
            if(param->m_type == 14) //variable
            {
                // lookup the variable
                if(!objecttype->GetPrivateVariable(atoi(param->CreateParamString(pApp))))
                    return false;
            }
            if(param->m_type == 13) //global
            {
                if(!pApp->GetGlobalVariable(atoi(param->CreateParamString(pApp))))
                    return false;
            }
            if(param->m_type == EDITORPARAM_OBJECT)
            {
                CString stparam = param->CreateParamString(pApp);
                int o = atoi(stparam);
                if(o == 0 && stparam != "0")
                    return true; //attribute

                if(!pApp->FindObjTypeFromNumber( o))
                    return false;

            }
            if(pApp)
                param->CreateParamString(pApp); //Calling this function updates valid...terrible design but meh
            if(param->valid == false)
                return false;
        }
        return true;

    }
    return false;
}
Example #12
0
int main(int argc, char ** argv) {
    FILE * file;
    char line[10];
    int x, y, n, i;
    file = fopen(argv[1], "r");
    while(fgets(line, sizeof(line), file)) {
        // assign vars
        x = atoi(strtok(line, " "));
        y = atoi(strtok(NULL, " "));
        n = atoi(strtok(NULL, " "));
        for(i = 1; i <= n; i++) {
            if(i % x == 0 && i % y == 0)
                printf("FB");
            else if(i % x == 0)
                printf("F");
            else if(i % y == 0)
                printf("B");
            else
                printf("%d", i);
            if(i != n)
                printf(" ");
        }
        printf("\n");
    }
    fclose(file);
    return 0;
}
Example #13
0
/** Parses an entry of a user in the config
 * @param doc the xml document
 * @param cur the current xml node
 * @return 0 on success, -1 on failure
 */
int parseUser(xmlDoc *doc, xmlNode *cur)
{
    xmlChar *key;
    cur = cur->xmlChildrenNode;
    lp_user *user = g_new0(lp_user, 1);


    while (cur)
    {
        key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
        if ((!xmlStrcmp(cur->name, (const xmlChar *)"login")))
            user->login = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"pass")))
            user->pass = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"email")))
            user->email = strdup((char*)key);
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"right_db")))
        {
            if(atoi((char*)key))
                user->rights |= LP_RIGHT_DB;
        }
        else if ((!xmlStrcmp(cur->name, (const xmlChar *)"right_op")))
        {
            if(atoi((char*)key))
                user->rights |= LP_RIGHT_OP;
        }
        xmlFree(key);
        cur = cur->next;
    }
    config->users = g_list_append(config->users, user);
    return(0);
}
Example #14
0
void ObjReader::get_indices(char *word, int *vindex, int *tindex, int *nindex)
{
    char *null = " ";
    char *ptr;
    char *tp;
    char *np;

    /* by default, the texture and normal pointers are set to the null string */
    tp = null;
    np = null;

    /* replace slashes with null characters and cause tp and np to point */
    /* to character immediately following the first or second slash */

    for (ptr = word; *ptr != '\0'; ptr++) {
        if (*ptr == '/') {
            if (tp == null)
                tp = ptr + 1;
            else
                np = ptr + 1;

            *ptr = '\0';
        }
    }

    *vindex = atoi(word);
    *tindex = atoi(tp);
    *nindex = atoi(np);
}
Example #15
0
int main(int argc, string argv[])
{
    if(argc == 2) {
        if(atoi(argv[1])>0) {
            int shift = atoi(argv[1]);
            string text = GetString();
            for (int i = 0; i < strlen(text); i++) {
                if (text[i]>='A'&&text[i]<='z') {
                    bool cap = isupper(text[i]);
                    if (cap == 1) {
                        printf("%c",((text[i]-'A'+shift)%26+'A'));
                    }
                    else {
                        printf("%c",((text[i]-'a'+shift)%26+'a'));
                    }
                }
                else {
                    printf("%c",text[i]);
                }
            }
            printf("\n");
        }
        else {
            printf("Please run program again");
            return 1;
        }
    }
    else {
        printf("Please run program again");
        return 1;
    }
}
Example #16
0
/*----------------------------------------------------------------------*
 * Function: parse_parameter_section                                    *
 * Purpose:  Parse parameter section of log                             *
 * Params:   fp -> file handle                                          *
 *           cl -> CortexLog structure to populate                      *
 * Returns:  0 for no error, else error number                          *
 *----------------------------------------------------------------------*/
int parse_parameter_section(FILE* fp, CortexLog* cl)
{
    char line[1024];
    long file_position = ftell(fp);

    while (get_next_line(line, 1024, fp) && (line[0] != '-')) {
        if (line_begins_with(line, "Max k:")) {
            cl->max_k = atoi(line + 6);
        } else if (line_begins_with(line, "Command:")) {
            if (!(cl->command_line = malloc(strlen(line)))) {
                return_error(ERROR_MEMORY);
            }
            strcpy(cl->command_line, line+9);
        } else if (line_begins_with(line, "Quality score offset:")) {
            cl->quality_score_offset = atoi(line + strlen("Quality score offset:"));
        } else if (line_begins_with(line, "Quality score threshold:")) {
            cl->quality_score_threshold = atoi(line + strlen("Quality score threshold:"));
        }

        file_position = ftell(fp);
    }

    fseek(fp, file_position, SEEK_SET);

    return 0;
}
Example #17
0
int CB_searchRequest_context_by_client_id(void *msg,
        char *id,
        char *description,
        char *client_id,
        char *network,
        char *netmask,
        char *serverCert,
        char *serverPrivkey,
        char *trustedCert)
{
    DNDSObject_t *objContext;
    DNDSObject_new(&objContext);
    DNDSObject_set_objectType(objContext, DNDSObject_PR_context);

    Context_set_id(objContext, atoi(id));
    Context_set_clientId(objContext, atoi(client_id));
    Context_set_description(objContext, description, strlen(description));
    Context_set_network(objContext, network);
    Context_set_netmask(objContext, netmask);

    Context_set_serverCert(objContext, serverCert, strlen(serverCert));
    Context_set_serverPrivkey(objContext, serverPrivkey, strlen(serverPrivkey));
    Context_set_trustedCert(objContext, trustedCert, strlen(trustedCert));

    SearchResponse_add_object(msg, objContext);

    return 0;
}
Example #18
0
int main(int argc, char* argv[]) {
    // set cross-over point - CHANGE AS NECESSARY
    int n0 = 65;

    // calculate and insert padding as necessary
    int num = (atoi(argv[2])+1)/n0;
    int k = 0;
    while(num >= 1) {
        k++;
        num = num/2;
    }
    int padded_n = pow(2,k) * n0;

    int** res = init_matrix(padded_n);
    int ***ms= filematrices(argv[3],atoi(argv[2]), padded_n);

    // timer
    // clock_t begin, end;
    // double time_spent;

    // begin = clock();
    strassens(ms[0], ms[1], res, padded_n, 0,0,0,0, n0);
    // end = clock();
    // time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
    // printf("n0=%i: Time taken: %f seconds\n", n0, time_spent);

    // prettyprinter(res, atoi(argv[2]));
    diagonal(res, atoi(argv[2]));

    free_matrix(res, padded_n);
    free_matrix(ms[0], padded_n);
    free_matrix(ms[1], padded_n);
}
void
createSCITransporter(void * _conf,
                     NodeId localNodeId,
                     NodeId remoteNodeId,
                     const char * localHostName,
                     const char * remoteHostName) {


    ndbout << "Creating SCI transporter from node "
           << localNodeId << "(" << localHostName << ") to "
           << remoteNodeId << "(" << remoteHostName << ")..." << endl;;


    SCI_TransporterConfiguration * conf = (SCI_TransporterConfiguration*)_conf;

    conf->remoteSciNodeId0= (Uint16)atoi(localHostName);
    conf->remoteSciNodeId1= (Uint16)atoi(remoteHostName);


    conf->localNodeId    = localNodeId;
    conf->remoteNodeId   = remoteNodeId;

    bool res = tReg->createTransporter(conf);
    if(res)
        ndbout << "... -- Success " << endl;
    else
        ndbout << "... -- Failure " << endl;
}
Example #20
0
int process_args(int argc, char ** argv) {
    int i = 6;

    /* The mandatory fields have not being specified. */
    if(argc < 6) {
        show_help();
        return -1;
    }

    ipcm = (ipcmid)atoi(argv[1]);
    ipcp = (ipcpid)atoi(argv[2]);

    name = argv[3];

    /* Ok, will run in server mode. */
    if(strcmp("--listen", argv[5]) == 0) {
        is_server = 1;
        qos = atoi(argv[4]);
    } else {
        qos = atoi(argv[4]);
        dest = argv[5];
    }

    /* Process the remaining flags. */
    for(i = 6; i < argc; i++) {
        if(strcmp("--duration", argv[i]) == 0 && (i + 1) < argc) {
            clt_duration = atoi(argv[i + 1]);
            i++;
        }
    }

    return 0;
}
Example #21
0
/*
 * Parse command line inputs.
 */
void
parse_command_line(int argc, char *argv[], int *lwork,
                   float *u, yes_no_t *equil, trans_t *trans )
{
    int c;
    extern char *optarg;

    while ( (c = getopt(argc, argv, "hl:w:r:u:f:t:p:e:")) != EOF ) {
        switch (c) {
        case 'h':
            printf("Options:\n");
            printf("\t-l <int> - length of work[*] array\n");
            printf("\t-u <int> - pivoting threshold\n");
            printf("\t-e <0 or 1> - equilibrate or not\n");
            printf("\t-t <0 or 1> - solve transposed system or not\n");
            exit(1);
            break;
        case 'l':
            *lwork = atoi(optarg);
            break;
        case 'u':
            *u = atof(optarg);
            break;
        case 'e':
            *equil = atoi(optarg);
            break;
        case 't':
            *trans = atoi(optarg);
            break;
        }
    }
}
Example #22
0
void IN_KeyDown(kbutton_t* b) {
    int     k;
    char*    c;

    c = Cmd_Argv(1);
    if (c[0]) {
        k = atoi(c);
    } else {
        k = -1;     // typed manually at the console for continuous down
    }

    if (k == b->down[0] || k == b->down[1]) {
        return;     // repeating key
    }

    if (!b->down[0]) {
        b->down[0] = k;
    } else if (!b->down[1]) {
        b->down[1] = k;
    } else {
        Com_Printf("Three keys down for a button!\n");
        return;
    }

    if (b->active) {
        return;     // still down
    }

    // save timestamp for partial frame summing
    c = Cmd_Argv(2);
    b->downtime = atoi(c);

    b->active = qtrue;
    b->wasPressed = qtrue;
}
EdgeList generateEdgeList(int argc, char** argv, packed_edge** output){
    int log_numverts;
    int edge_factor = 16;
    int64_t nedges;
    packed_edge* result;
    log_numverts = 16; /* In base 2 */
    if (argc >= 2) log_numverts = atoi(argv[1]);
    if (argc >= 3) edge_factor = atoi(argv[2]);
    make_graph(log_numverts, edge_factor << log_numverts, 1, 2,
	       &nedges, &result);
    printf("nedges=%ld before\n",nedges);
    //remove loops:
#if rmdup
    tic();
    packed_edge* end=thrust::remove_if(result, result+nedges, is_loop());
    //sort packed_edge twice:
    thrust::sort(result,end,pe_less1());
    thrust::sort(result,end,pe_less2());
    //nedges=(end-result);
    //printf("nedges=%d after loop\n",nedges);
    //remove duplicates:
    end=thrust::unique(result,end);
    cudaDeviceSynchronize();
    elapsed_time+=toc();
    printf("remove dup took %f ms\n", elapsed_time);
    //TEMP: reset elapsed time:
    elapsed_time=0;
    nedges=(end-result);
    printf("nedges=%ld after dup\n",nedges);
    //
#endif
    uusi::EdgeList el=graph500ToEdgeList((const packed_edge*)result,nedges);
    *output=result;
    return el;
}
Example #24
0
/************************************************************************
 *                            msTileSetParams                           *
 ************************************************************************/
static void msTileGetParams(mapObj *map, tileParams *params)
{

    const char *value = NULL;
    hashTableObj *meta = &(map->web.metadata);

    params->tile_size = SPHEREMERC_IMAGE_SIZE;

    /* Check for tile buffer, set to buffer==0 as default */
    if((value = msLookupHashTable(meta, "tile_map_edge_buffer")) != NULL) {
        params->map_edge_buffer = atoi(value);
        if(map->debug)
            msDebug("msTileSetParams(): tile_map_edge_buffer = %d\n", params->map_edge_buffer);
    } else
        params->map_edge_buffer = 0;

    /* Check for metatile size, set to tile==metatile as default */
    if((value = msLookupHashTable(meta, "tile_metatile_level")) != NULL) {
        params->metatile_level = atoi(value);
        /* Quietly force metatile_level to be sane */
        if( params->metatile_level < 0 )
            params->metatile_level = 0;
        if( params->metatile_level > 2 )
            params->metatile_level = 2;
        if(map->debug)
            msDebug("msTileSetParams(): tile_metatile_level = %d\n", params->metatile_level);
    } else
        params->metatile_level = 0;

}
Example #25
0
int main(int argc, char *argv[])
{
    unsigned char buf[BUF_SIZE];
    char device[80];
    int c, card_num,kilobytes=0,kb_out=0,n_opt=0;
    int actual_bytes;
    FILE *fo;

    card_num=default_card(FALSE);

    while((c=getopt(argc,argv,"lc:k:n"))!=-1) {
        switch(c) {
        case 'l':
            default_card(TRUE);
            exit(0);
        case 'c':
            card_num=atoi(optarg);
            break;
        case 'k':
            kilobytes=atoi(optarg)+1; // extra to account for the skipped bytes
            break;
        case 'n':
            n_opt=1;
            break;
        default:
            fprintf(stderr,"Usage: %s [-l] [-c card_num] [-k kilobytes]\n",argv[0]);
            exit(3);
        }
    }

    if(card_num<0) {
        fprintf(stderr,"%s: Valid REDOUBLER card_num neither found nor specified.\n",argv[0]);
        exit(9);
    }
    sprintf(device,"hw:%d",card_num);
    sound_set_device(device);
    sound_set_skip_bytes(960);
    sound_open();
    atexit(sound_close);

    fo=popen("cat | cat","w"); // quick-and-dirty double buffering, done before nice()
    if(n_opt) if(nice(-10)==-1) fprintf(stderr,"%s: Only root can increase priority.\n",argv[0]);
    if(fo == NULL) {
        fprintf(stderr,"%s: Could not open ouput buffering process.\n",argv[0]);
        exit(11);
    }
    sound_start();
    while((kilobytes <= 0) || (kb_out < kilobytes)) {
        actual_bytes=sound_read(buf,BUF_SIZE);
        if(actual_bytes==BUF_SIZE) {
            fwrite(buf,1,BUF_SIZE,fo);
            kb_out++;
        }
        else fprintf(stderr,"%s: Read glitch, actual_bytes = %d\n",argv[0],actual_bytes);
    }
    sound_stop();
    pclose(fo);

    exit(0); // shoud trigger atexit()
}
Example #26
0
/*****************************************************************************
 * mosaic_ParseSetOffsets:
 * parse the "--mosaic-offsets x1,y1,x2,y2,x3,y3" parameter
 * and set the corresponding struct filter_sys_t entries.
 *****************************************************************************/
static void mosaic_ParseSetOffsets( vlc_object_t *p_this,
                                    filter_sys_t *p_sys,
                                    char *psz_offsets )
{
    if( *psz_offsets )
    {
        char *psz_end = NULL;
        int i_index = 0;
        do
        {
            i_index++;

            p_sys->pi_x_offsets = xrealloc( p_sys->pi_x_offsets,
                                            i_index * sizeof(int) );
            p_sys->pi_x_offsets[i_index - 1] = atoi( psz_offsets );
            psz_end = strchr( psz_offsets, ',' );
            psz_offsets = psz_end + 1;

            p_sys->pi_y_offsets = xrealloc( p_sys->pi_y_offsets,
                                            i_index * sizeof(int) );
            p_sys->pi_y_offsets[i_index - 1] = atoi( psz_offsets );
            psz_end = strchr( psz_offsets, ',' );
            psz_offsets = psz_end + 1;

            msg_Dbg( p_this, CFG_PREFIX "offset: id %d, x=%d, y=%d",
                     i_index, p_sys->pi_x_offsets[i_index - 1],
                     p_sys->pi_y_offsets[i_index - 1]  );

        } while( psz_end );
        p_sys->i_offsets_length = i_index;
    }
}
Example #27
0
bool GameClass::readHeader(std::ifstream &stream) {
    string line;
    mapWidth = -1;
    mapHeight = -1;
    while
    (getline(stream, line)) {
        if (line == "") {
            break;
        }
        istringstream sStream(line);
        string key, value;
        getline(sStream, key, '=');
        getline(sStream, value);
        if (key == "width") {
            mapWidth = atoi(value.c_str());
        }
        else if (key == "height") {
            mapHeight = atoi(value.c_str());
        }
    }
    if
    (mapWidth == -1 || mapHeight == -1) {
        return false;
    }
    else { // allocate our map data
        levelData = new unsigned char*[mapHeight];
        for
        (int i =
                    0; i < mapHeight; ++i) {
            levelData[i] = new unsigned char[mapWidth];
        }
        return true;
    }
}
Example #28
0
File: main.c Project: phectori/RIOT
static int init_in(int argc, char **argv)
{
    int port, pin, pull;

    if (argc < 3) {
        printf("usage: %s <port> <pin> [pull_config]\n", argv[0]);
        puts("      pull_config: 0: no pull resistor (default)\n"
             "                   1: pull up\n"
             "                   2: pull down");
        return 1;
    }
    port = atoi(argv[1]);
    pin = atoi(argv[2]);
    if (argc >= 4) {
        pull = parse_pull(argv[3]);
        if (pull < 0) {
            return 1;
        }
    }
    else {
        pull = GPIO_NOPULL;
    }
    if (gpio_init(GPIO_PIN(port, pin), GPIO_DIR_IN, pull) < 0) {
        printf("Error while initializing  PORT_%i.%02i as input\n", port, pin);
        return 1;
    }
    printf("PORT_%i.%02i initialized successful as input\n", port, pin);

    return 0;
}
Example #29
0
/**
 * @brief This function does not add statistical values. Because there is no attacker.
 * The same counts for morale states - they are not affected.
 * @note: This is a debug function to let a whole team die
 */
static void G_KillTeam_f (void)
{
    /* default is to kill all teams */
    int teamToKill = -1;
    Edict *ent = nullptr;
    int amount = -1;

    /* with a parameter we will be able to kill a specific team */
    if (gi.Cmd_Argc() >= 2) {
        teamToKill = atoi(gi.Cmd_Argv(1));
        if (gi.Cmd_Argc() == 3)
            amount = atoi(gi.Cmd_Argv(2));
    }

    Com_DPrintf(DEBUG_GAME, "G_KillTeam: kill team %i\n", teamToKill);

    if (teamToKill >= 0) {
        while ((ent = G_EdictsGetNextLivingActorOfTeam(ent, teamToKill))) {
            if (amount == 0)
                break;
            /* die */
            ent->HP = 0;
            G_ActorDieOrStun(ent, nullptr);

            if (teamToKill == TEAM_ALIEN)
                level.num_kills[TEAM_PHALANX][TEAM_ALIEN]++;
            else
                level.num_kills[TEAM_ALIEN][teamToKill]++;
            amount--;
        }
    }

    /* check for win conditions */
    G_MatchEndCheck();
}
Example #30
0
int main (int argc, char **argv) {
    Display *display;
    int xpos = 0;
    int ypos = 0;
    char mydisp[256] = "";

    if (argc == 3) {
        xpos = atoi(argv[1]);
        ypos = atoi(argv[2]);
        strcpy(mydisp,getenv("DISPLAY"));
    } else {
        if (argc == 4) {
            xpos = atoi(argv[1]);
            ypos = atoi(argv[2]);
            strcpy(mydisp,argv[3]);
        } else {
            usage();
            exit(0);
        }
    }
    if (!(display = XOpenDisplay(mydisp))) {
        return fprintf(stderr, "unable to open display\n"), 11;
    }
    XWarpPointer (
        display,None,DefaultRootWindow(display),0,0,0,0,xpos,ypos
    );
    XFlush(display);
    return(0);
}