Пример #1
0
int main()
{
    printf("%s\n", addStrings("8432708", "87372547"));

    printf("%s\n", addStrings("401716832807512840963",
                "167141802233061013023557397451289113296441069"));

    return 0;
}
Пример #2
0
//---------------------------------------------------------------------------
void JrkDialog::readErrors(bool occured)
{
    if(!jrk->isOpen()) {
        ui->textEdit->append("Error: Port is not open!");
        return;
    }

    QStringList sl;
    QString str;
    quint16 data2;

    if(occured) {
        data2 = jrk->readErrorOccurred();
        str.sprintf("Error Flags Occurred: 0x%04X", data2);
    }
    else {
        data2 = jrk->clearError();
        str.sprintf("Error Flags Halting: 0x%04X", data2);
    }

    ui->textEdit->append(str);

    jrk->errorStr(&sl, data2);
    addStrings(&sl);
    ui->textEdit->append("");
}
Пример #3
0
void AsciiSerializedRequest::prepareImpl(const McRequest& request,
                                         McOperation<mc_op_flushall>) {
  auto len = snprintf(printBuffer_, kMaxBufferLength, " %u\r\n",
                      request.number());
  addStrings("flush_all",
             folly::StringPiece(printBuffer_, static_cast<size_t>(len)));
}
Пример #4
0
void AsciiSerializedRequest::prepareImpl(const McRequest& request,
                                         McOperation<mc_op_delete>) {
  auto len = snprintf(printBuffer_, kMaxBufferLength, " %u\r\n",
                      request.exptime());
  assert(len > 0 && len < kMaxBufferLength);
  addStrings("delete ", request.fullKey(),
             folly::StringPiece(printBuffer_, static_cast<size_t>(len)));
}
Пример #5
0
int
main ()
{
  char num1[] = "1";
  char num2[] = "1";
  printf("%s\n", addStrings(num1, num2));
  return 0;
}
Пример #6
0
 void addStrings (String name, std::vector <std::string> const& strings)
 {
     StringArray stringArray;
     stringArray.ensureStorageAllocated (strings.size());
     for (std::size_t i = 0; i < strings.size(); ++i)
         stringArray.add (strings [i]);
     addStrings (name, stringArray);
 }
Пример #7
0
	ResolutionSelector() :
		ListSelectionScreen() {
		setProperty("title", "Resolution");
		Vector<String> resolutions;
		resolutions.add("low (8x8)");
		resolutions.add("medium (16x16)");
		resolutions.add("high (32x32)");
		addStrings(resolutions);
	}
Пример #8
0
void AsciiSerializedRequest::keyValueRequestCommon(folly::StringPiece prefix,
                                                   const Request& request) {
  auto value = request.valueRangeSlow();
  auto len = snprintf(printBuffer_, kMaxBufferLength, " %lu %d %zd\r\n",
                      request.flags(), request.exptime(), value.size());
  assert(len > 0 && len < kMaxBufferLength);
  addStrings(prefix, request.fullKey(),
             folly::StringPiece(printBuffer_, static_cast<size_t>(len)),
             value, "\r\n");
}
Пример #9
0
int main(void)
{
	char s1[MAX_LEN], s2[MAX_LEN], r[MAX_LEN+1];
	/* Read first line */
	scanf("%s", s1);
	/* Read second line */
	scanf("%s", s2);

	addStrings(s1, s2, r);
	printf("%s\n", r);
}
Пример #10
0
void AsciiSerializedRequest::prepareImpl(const McRequest& request,
                                         McOperation<mc_op_cas>) {
  auto value = request.valueRangeSlow();
  auto len = snprintf(printBuffer_, kMaxBufferLength, " %lu %u %zd %lu\r\n",
                      request.flags(), request.exptime(), value.size(),
                      request.cas());
  assert(len > 0 && len < kMaxBufferLength);
  addStrings("cas ", request.fullKey(),
             folly::StringPiece(printBuffer_, static_cast<size_t>(len)), value,
             "\r\n");
}
Пример #11
0
void Strings::assign(const Strings& src)
{
	AutoUpdater autoUpdater(*this);
	clear();

	defined_ = src.defined_;
	delimiter_ = src.delimiter_;
	lineBreak_ = src.lineBreak_;
	quoteChar_ = src.quoteChar_;
	nameValueSeparator_ = src.nameValueSeparator_;

	addStrings(src);
}
Пример #12
0
char *
addStrings (char *num1, char *num2)
{
  int len1 = strlen (num1);
  int len2 = strlen (num2);
  if (len1 > len2)
    {
      return addStrings (num2, num1);
    }
  int j = len2;
  int i = len1;
  while (1)
    {
      if(i < 0) {
          break;
      }
      num2[j] += num1[i] - '0';
      j--;
      i--;
    }
  char tmp[5102];
  tmp[5101] = '\0';
  int up = 0;
  for (j = len2 - 1, i = 5100; j >= 0; j--, i--)
    {
        printf("%d\n", num2[j] + up - '0');
      if (num2[j] + up > '9')
	{
	  tmp[i] = num2[j] + up- 10;
	  up = 1;
	}
      else
	{
	  tmp[i] = num2[j] + up;
	  up = 0;
	}
    }
  if (up == 1)
    {
      tmp[i] = '1';
    }
  else
    {
      i++;
    }
  char *ret = (char *) malloc (sizeof (char) * 5101);
  bzero (ret, sizeof (char) * 5101);
  strncpy (ret, &tmp[i], sizeof (char) * 5101);
  return ret;
}
Пример #13
0
void main( int argc, char *argv[] ) {

    char                buffer[ BUFFER_SIZE ];
    owl_handle          owl;
    owl_file_handle     file;
    owl_string_table    *table;
    owl_client_funcs    funcs = { NULL, NULL, NULL, malloc, free };
    char                *t_buff;

    owl = OWLInit( &funcs, OWL_CPU_PPC );
    file = OWLFileInit( owl, "test", NULL, OWL_FORMAT_ELF, OWL_FILE_OBJECT );
    table = OWLStringInit( file );
    while( fgets( buffer, BUFFER_SIZE, stdin ) != NULL ) {
        addStrings( table, buffer );
        OWLStringDump( table );
    }
    t_buff = malloc( OWLStringTableSize( table ) + 1 );
    OWLStringEmit( table, t_buff );
    write( STDOUT_FILENO, t_buff, OWLStringTableSize( table ) );
    free( t_buff );
    OWLStringFini( table );
    OWLFileFini( file );
    OWLFini( owl );
}
Пример #14
0
void Logstalgia::logic(float t, float dt) {

    float sdt = dt * settings.simulation_speed;

    //increment clock
    elapsed_time += sdt;
    currtime = starttime + (long)(elapsed_time);
   
    if(settings.stop_time && currtime > settings.stop_time) {
        currtime = settings.stop_time;
    }
    
    if(mousehide_timeout>0.0f) {
        mousehide_timeout -= dt;
        if(mousehide_timeout<0.0f) {
            SDL_ShowCursor(false);
        }
    }

    infowindow.hide();

    if(end_reached && balls.empty()) {
        appFinished = true;
        return;
    }

    //if paused, dont move anything, only check what is under mouse
    if(paused) {

        for(auto& it: paddles) {
            Paddle* paddle = it.second;

            if(paddle->mouseOver(infowindow, mousepos)) {
                break;
            }
        }

        for(RequestBall* ball : balls) {
            if(ball->mouseOver(infowindow, mousepos)) {
                break;
            }
        }

        if(!ipSummarizer->mouseOver(infowindow,mousepos)) {
            for(Summarizer* s: summarizers) {
                if(s->mouseOver(infowindow, mousepos)) break;
            }
        }

        return;
    }

    //next will fast forward clock to the time of the next entry,
    //if the next entry is in the future
    if(next || (!settings.disable_auto_skip && balls.empty())) {
        if(!queued_entries.empty()) {
            LogEntry* le = queued_entries.front();

            long entrytime = le->timestamp;
            if(entrytime > currtime) {
                elapsed_time = entrytime - starttime;
                currtime = starttime + (long)(elapsed_time);
            }
        }
        next = false;
    }

    //recalc spawn speed each second by
    if(currtime != lasttime) {

        //dont bother reading the log if we dont need to
        if(queued_entries.empty() || queued_entries.back()->timestamp <= currtime) {
            readLog();
        }

        profile_start("determine new entries");

        int items_to_spawn=0;

        for(LogEntry* le : queued_entries) {

            if(le->timestamp > currtime) break;

            items_to_spawn++;

            addStrings(le);
        }

        profile_stop();

        //debugLog("items to spawn %d\n", items_to_spawn);

        if(items_to_spawn > 0) {

            profile_start("add new strings");

            //re-summarize
            ipSummarizer->summarize();

            for(Summarizer* s : summarizers) {
                s->summarize();
            }

            profile_stop();

            profile_start("add new entries");

            float item_offset = 1.0 / (float) (items_to_spawn);

            int item_no = 0;

            while(!queued_entries.empty()) {

                LogEntry* le = queued_entries.front();

                if(le->timestamp > currtime) break;

                float pos_offset   = item_offset * (float) item_no++;
                float start_offset = std::min(1.0f, pos_offset);

		addBall(le, start_offset);

                queued_entries.pop_front();
            }

        }

        //update date
        if(total_entries>0) {
            char datestr[256];
            char timestr[256];

            struct tm* timeinfo = localtime ( &currtime );
            strftime(datestr, 256, "%A, %B %d, %Y", timeinfo);
            strftime(timestr, 256, "%X", timeinfo);

            displaydate = datestr;
            displaytime = timestr;
        } else {
            displaydate = "";
            displaytime = "";
        }

        lasttime=currtime;

        profile_stop();
    } else {
        //do small reads per frame if we havent buffered the next second
        if(queued_entries.empty() || queued_entries.back()->timestamp <= currtime+1) {
            readLog(50);
        }
    }

    std::list<Paddle*> inactivePaddles;

    //update paddles
    for(auto& it: paddles) {

        std::string paddle_token = it.first;
        Paddle*           paddle = it.second;

        if(settings.paddle_mode > PADDLE_SINGLE && !paddle->moving() && !paddle->visible()) {

            bool token_match = false;

            //are there any requests that will match this paddle?
            for(RequestBall* ball : balls) {

                if(   (settings.paddle_mode == PADDLE_VHOST && ball->le->vhost == paddle_token)
                   || (settings.paddle_mode == PADDLE_PID   && ball->le->pid   == paddle_token)) {
                    token_match = true;
                    break;
                }
            }

            //mark this paddle for deletion, continue
            if(!token_match) {
                inactivePaddles.push_back(paddle);
                continue;
            }
        }

        // find nearest ball to this paddle
        if( (retarget || !paddle->getTarget())) {

            RequestBall* ball = findNearest(paddle, paddle_token);

            if(ball != 0) {
                paddle->setTarget(ball);
            } else if(!paddle->moving()) {
                paddle->setTarget(0);
            }
        }

        paddle->logic(sdt);
    }

    retarget = false;

    profile_start("check ball status");

    // NOTE: special handling for this iterator as items are being removed
    for(auto it = balls.begin(); it != balls.end();) {

        RequestBall* ball = *it;

        highscore += ball->logic(sdt);

        if(ball->isFinished()) {
            it = balls.erase(it);
            removeBall(ball);
        } else {
            it++;
        }
    }

    profile_stop();

    profile_start("ipSummarizer logic");
    ipSummarizer->logic(dt);
    profile_stop();

    profile_start("updateGroups logic");
    updateGroups(dt);
    profile_stop();


    screen_blank_elapsed += dt;

    if(screen_blank_elapsed-screen_blank_interval > screen_blank_period)
        screen_blank_elapsed = 0.0f;

    //update font alpha
    font_alpha = 1.0f;

    if(screen_blank_elapsed>screen_blank_interval) {
        font_alpha = std::min(1.0f, (float) fabs(1.0f - (screen_blank_elapsed-screen_blank_interval)/(screen_blank_period*0.5)));
        font_alpha *= font_alpha;
    }
}
/**
   @param argc how many arguments to add
   @param argv the strings to add
   @param position the position to add the string at, a position less
   than 0 means to add at the end, if this number is greater than how
   many positions exist then it will also be added at the end
**/
AREXPORT void ArArgumentBuilder::addStrings(char **argv, int argc,
					    int position)
{
  addStrings(argc, argv, position);
}
Пример #16
0
void AsciiSerializedRequest::prepareImpl(const McRequest& request,
                                         McOperation<mc_op_lease_get>) {
  addStrings("lease-get ", request.fullKey(), "\r\n");
}