vector<string> summaryRanges(vector<int>& nums) {
		vector<string> res;
		int p1, p2;
		p1 = p2 = 0;
		while (p1 < nums.size())
		{
			int start = p1;
			p2 = p1;
			int cnt = 0;
			while (p2 < nums.size() && nums[p2] == nums[p1] + cnt)
			{
				cnt++;
				p2++;
			}
			char start_str[32], end_str[32];
			sprintf(start_str, "%d", nums[start]);
			p2--;
			sprintf(end_str, "%d", nums[p2]);
			string start_part(start_str), end_part(end_str);//注意这里将数字转换为字符串的方法
			string tmp_res = "";
			if (cnt != 1)//has start and end
				tmp_res = start_part + "->" + end_part;
			else//only has start
				tmp_res = start_part;
			res.push_back(tmp_res);
			p1 = p2+1;//更新p1为上一个区间结束的下一个位置
		}
		return res;
	}
Example #2
0
int ls_func(pfactory pf,pnode pget)
{
	DIR *pdir;
	//printf("%s\n",pf->pth_pwd);
	pdir = opendir(pf->pth_pwd);
	printf("%s\n",pf->pth_pwd);
	if(pdir == NULL)
	{
		perror("opendir");
		return;
	}
	struct dirent *dirinfo;
	char buf[128] = {0};
	struct stat fsta;
	int ret;
	char ftype;
	data d;
	while((dirinfo = readdir(pdir))!= NULL)
	{
		sprintf(buf,"%s/%s",pf->pth_pwd,dirinfo->d_name);
		ret = stat(buf,&fsta);
		bzero(buf,sizeof(buf));
		if(!strcmp(dirinfo->d_name,".") || !strcmp(dirinfo->d_name,".."))
		{
		}else{
			sprintf(buf,"%-5s %-10s		%-10ld\n",dirinfo->d_type>4?"-":"d",dirinfo->d_name,fsta.st_size);
			send(pget->new_fd,buf,sizeof(buf),0);
//			printf("%s",buf);
			sleep(1);
		}
	}
	closedir(pdir);
	return 0;
}
Example #3
0
/* DDS3.2.6: Get Rotation */
void get_rotation(const struct electorate *elec)
{
	struct http_vars *reply;
	unsigned int i;
	char ecodestr[INT_CHARS];
	struct http_vars request[]
		= { { (char*)"ecode", ecodestr }, { NULL, NULL } };

	sprintf(ecodestr, "%u", elec->code);

	reply = http_exchange(SERVER_ADDRESS, SERVER_PORT, ROBSON_CGI,request);
	if (!reply)
		display_error(ERR_SERVER_UNREACHABLE);

	/* Some error occurred? */
	if (http_error(reply))
		display_error(http_error(reply));

	for (i = 0; i < elec->num_seats; i++) {
		char varname[strlen("rotation")
			    + sizeof(STRINGIZE(MAX_ELECTORATE_SEATS))];
		const char *val;

		sprintf(varname, "rotation%u", i);
		val = http_string(reply, varname);
		current_rotation.rotations[i] = atoi(val);
		assert(current_rotation.rotations[i] < elec->num_seats);
	}
	/* DDS3.2.6: Save Rotation */
	current_rotation.size = elec->num_seats;
	http_free(reply);
}
ostream &operator<<(ostream &f, AdaBoost2 &strong_classifier)
{
  f << strong_classifier.m_picked_classifiers.size() << endl;

  for (vector<tr1::shared_ptr<WeakClassifier> >::iterator it = strong_classifier.m_picked_classifiers.begin();
       it != strong_classifier.m_picked_classifiers.end();
       it++)
  {
    char buf[128];
    uint64 feature_type;
    double d;
    (*it)->feature_type(feature_type);
    sprintf(buf, "%lu", feature_type);
    f << string(buf) << "\t";

    (*it)->alpha(d);
    sprintf(buf, "%lf", d);
    f << string(buf) << endl;
    f << *(SgdSvm*)((*it).get());

    if ((it + 1) != strong_classifier.m_picked_classifiers.end())
    {
      f << endl;
    }
  }

  return f;
}
Example #5
0
static void *
tf (void *arg)
{
  int tmp = 0;
  char number[160];
  sprintf(number, "tf(%ld): begin", (long)arg);
  puts (number);
  
  tmp = sas_spin_trylock(&t_lock);
  if (tmp == 0)
  {
    sprintf(number, "tf(%ld): sas_spin_trylock", (long)arg);
    puts (number);
    
    sas_spin_unlock(&t_lock);

    sprintf(number, "tf(%ld): end", (long)arg);
    puts (number);
  } else {
    sas_spin_lock_with_yield(&t_lock);

    sprintf(number, "tf(%ld): sas_spin_lock_with_yield", (long)arg);
    puts (number);
  
    sas_spin_unlock(&t_lock);

    sprintf(number, "tf(%ld): end", (long)arg);
    puts (number);
  }
  return NULL;
}
void
MEStreetSegmentItemInfoWidget::activate(MEMapArea* mapArea,
                                        OldStreetSegmentItem* ssi)
{
    MEAbstractItemInfoWidget::activate(mapArea, ssi);

    char tmpstr[128];

    // Road class + cond
    sprintf(tmpstr, "%d", uint32(ssi->getRoadClass()));
    m_roadClassVal->set_text(tmpstr);
    sprintf(tmpstr, "%d", uint32(ssi->getRoadCondition()));
    m_roadConditionVal->set_text(tmpstr);

    // Housenumber
    m_houseNumberValLS->set_value(ssi->getLeftSideNbrStart());
    m_houseNumberValLE->set_value(ssi->getLeftSideNbrEnd());
    m_houseNumberValRS->set_value(ssi->getRightSideNbrStart());
    m_houseNumberValRE->set_value(ssi->getRightSideNbrEnd());
    sprintf(tmpstr, "%d", uint32(int(ssi->getStreetNumberType())));
    m_houseNumberTypeVal->set_text(tmpstr);

    // Ramp, roundabout(ish), multi.dig. and controlled access
    m_rampVal->set_active(ssi->isRamp());
    m_roundaboutVal->set_active(ssi->isRoundabout());
    m_roundaboutishVal->set_active(ssi->isRoundaboutish());
    m_multidigVal->set_active(ssi->isMultiDigitised());
    m_controlledAccessVal->set_active(ssi->isControlledAccess());

    show_all();
}
Example #7
0
static void get_flags_for_id(ID *id, char *buf) 
{
	int isfake= id->flag & LIB_FAKEUSER;
	int isnode=0;
		/* Writeout the flags for the entry, note there
		 * is a small hack that writes 5 spaces instead
		 * of 4 if no flags are displayed... this makes
		 * things usually line up ok - better would be
		 * to have that explicit, oh well - zr
		 */

	if(GS(id->name)==ID_MA)
		isnode= ((Material *)id)->use_nodes;
	if(GS(id->name)==ID_TE)
		isnode= ((Tex *)id)->use_nodes;
	
	if (id->us<0)
		sprintf(buf, "-1W ");
	else if (!id->lib && !isfake && id->us && !isnode)
		sprintf(buf, "     ");
	else if(isnode)
		sprintf(buf, "%c%cN%c ", id->lib?'L':' ', isfake?'F':' ', (id->us==0)?'O':' ');
	else
		sprintf(buf, "%c%c%c ", id->lib?'L':' ', isfake?'F':' ', (id->us==0)?'O':' ');
}
Example #8
0
static int proc_ide_read_identify
(char *page, char **start, off_t off, int count, int *eof, void *data)
{
    ide_drive_t	*drive = (ide_drive_t *)data;
    int		len = 0, i = 0;
    int		err = 0;

    len = sprintf(page, "\n");

    if (drive) {
        __le16 *val = (__le16 *)page;

        err = taskfile_lib_get_identify(drive, page);
        if (!err) {
            char *out = (char *)page + SECTOR_SIZE;

            page = out;
            do {
                out += sprintf(out, "%04x%c",
                               le16_to_cpup(val), (++i & 7) ? ' ' : '\n');
                val += 1;
            } while (i < SECTOR_SIZE / 2);
            len = out - page;
        }
    }
    PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
}
Example #9
0
static void save_gtk3_settings (void)
{
	char *user_config_file, *cstr;
	char cmdbuf[256];

	// construct the file path
	user_config_file = g_build_filename (g_get_home_dir (), ".config/gtk-3.0/gtk.css", NULL);

	// convert colour to string and use sed to write
	cstr = gdk_color_to_string (&theme_colour);
	sprintf (cmdbuf, "sed -i s/'theme_selected_bg_color #......'/'theme_selected_bg_color #%c%c%c%c%c%c'/g %s",
		cstr[1], cstr[2], cstr[5], cstr[6], cstr[9], cstr[10], user_config_file);
	system (cmdbuf);

	cstr = gdk_color_to_string (&themetext_colour);
	sprintf (cmdbuf, "sed -i s/'theme_selected_fg_color #......'/'theme_selected_fg_color #%c%c%c%c%c%c'/g %s",
		cstr[1], cstr[2], cstr[5], cstr[6], cstr[9], cstr[10], user_config_file);
	system (cmdbuf);

	// write the current font to the file
	sprintf (cmdbuf, "sed -i s/'font:[^;]*'/'font:\t%s'/g %s", desktop_font, user_config_file);
	system (cmdbuf);

	g_free (cstr);
	g_free (user_config_file);
}
Example #10
0
/**
 * Demonstrate sending a signed (HMAC) and then encrypted message to MQTT
 * @param tt just something that varies between messages, so we can see it when decrypted
 * @return
 */
int send_signed_message(time_t tt, char *shared_key) {

    // Make message...
    char data[200];
    sprintf(data, "Signed Message with sequence: %ld", tt);

    DLOG("pub SIGNED: %s\n", data);
    unsigned char* hmac;
    unsigned int result_len;

    // printf "%s" "message to be signed..." | openssl sha1 -hmac "karl_hmac_key"
    hmac = HMAC(EVP_sha1(), shared_key, strlen(shared_key), (unsigned char*)data, strlen(data), NULL, &result_len);
    if (hmac == NULL) {
        fatal("Couldn't sign the message: %s\n", ERR_error_string(ERR_get_error(), NULL));
    }

    // Add signature to message
    char topic[60];
    char *tmp = &topic[0];
    tmp += sprintf(topic, "demo/signed/");
    int i;
    for (i = 0; i < result_len; i++) {
        sprintf(tmp + (i*2), "%02x", hmac[i]);
    }
    i = mosquitto_publish(mosq, NULL, topic, strlen(data), (unsigned char*)data, 0, false);
    if (i != MOSQ_ERR_SUCCESS) {
        fatal("Failed to publish message: %d\n", i);
    }
    return 0;
}
Example #11
0
gmx_bool search_subdirs(const char *parent, char *libdir)
{
    char *ptr;
    gmx_bool found;

    /* Search a few common subdirectory names for the gromacs library dir */
    sprintf(libdir,"%s%cshare%ctop%cgurgle.dat",parent,
            DIR_SEPARATOR,DIR_SEPARATOR,DIR_SEPARATOR);
    found=gmx_fexist(libdir);
    if(!found) {
        sprintf(libdir,"%s%cshare%cgromacs%ctop%cgurgle.dat",parent,
                DIR_SEPARATOR,DIR_SEPARATOR,
                DIR_SEPARATOR,DIR_SEPARATOR);
        found=gmx_fexist(libdir);
    }    
    if(!found) {
        sprintf(libdir,"%s%cshare%cgromacs-%s%ctop%cgurgle.dat",parent,
                DIR_SEPARATOR,DIR_SEPARATOR,VERSION,
                DIR_SEPARATOR,DIR_SEPARATOR);
        found=gmx_fexist(libdir);
    }    
    if(!found) {
        sprintf(libdir,"%s%cshare%cgromacs%cgromacs-%s%ctop%cgurgle.dat",parent,
                DIR_SEPARATOR,DIR_SEPARATOR,DIR_SEPARATOR,
                VERSION,DIR_SEPARATOR,DIR_SEPARATOR);
        found=gmx_fexist(libdir);
    }    

    /* Remove the gurgle.dat part from libdir if we found something */
    if(found) {
        ptr=strrchr(libdir,DIR_SEPARATOR); /* slash or backslash always present, no check necessary */
        *ptr='\0';
    }
    return found;
}
Example #12
0
/* make the devices for a volume */
void
make_vol_dev(int volno, int recurse)
{
    dev_t voldev;
    char filename[PATH_MAX];				    /* for forming file names */
    int plexno;

    get_volume_info(&vol, volno);
    if (vol.state != volume_unallocated) {		    /* we could have holes in our lists */
	voldev = VINUMDEV(volno, 0, 0, VINUM_VOLUME_TYPE);  /* create a device number */

	/* Create /dev/vinum/<myvol> */
	sprintf(filename, VINUM_DIR "/%s", vol.name);
	if (mknod(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR, voldev) < 0)
	    fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));

	/* Create /dev/vinum/vol/<myvol> */
	sprintf(filename, VINUM_DIR "/vol/%s", vol.name);
	if (mknod(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR, voldev) < 0)
	    fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));

	if (vol.plexes > 0) {
	    /* Create /dev/vinum/vol/<myvol>.plex/ */
	    sprintf(filename, VINUM_DIR "/vol/%s.plex", vol.name);
	    if (mkdir(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IXOTH) < 0)
		fprintf(stderr, "Can't create %s: %s\n", filename, strerror(errno));
	}
	if (recurse)
	    for (plexno = 0; plexno < vol.plexes; plexno++)
		make_plex_dev(plex.plexno, recurse);
    }
}
Example #13
0
const char *vid_version(void)
{
    static char SDLVersion[80];
    SDL_version compiled, running;

#if SDL_MAJOR_VERSION == 1
    const SDL_version *ver = SDL_Linked_Version();
    running.major = ver->major;
    running.minor = ver->minor;
    running.patch = ver->patch;
#else
    SDL_GetVersion(&running);
#endif
    SDL_VERSION(&compiled);

    if ((compiled.major == running.major) &&
            (compiled.minor == running.minor) &&
            (compiled.patch == running.patch))
        sprintf(SDLVersion, "SDL Version %d.%d.%d",
                compiled.major, compiled.minor, compiled.patch);
    else
        sprintf(SDLVersion, "SDL Version (Compiled: %d.%d.%d, Runtime: %d.%d.%d)",
                compiled.major, compiled.minor, compiled.patch,
                running.major, running.minor, running.patch);
    return (const char *)SDLVersion;
}
Example #14
0
void printMatrixCSC(int* Ap, int* Ai, double* Ax, int n)
{
    int i, j, k, l;

    char buffer[400][4096] = {0};

    k = 0;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            if ((k < Ap[i + 1]) && (Ai[k] == j))
            {
                sprintf(buffer[j], "%s %5g ", buffer[j], Ax[k]);
                k++;
            }
            else
            {
                sprintf(buffer[j], "%s %5g ", buffer[j], 0.0);
            }
        }
    }
    for (l = 0; l < n; l++)
    {
        infoStreamPrint(LOG_LS_V, 0, "%s", buffer[l]);
    }

}
Example #15
0
static void
process_psqlrc_file(char *filename)
{
    char	   *psqlrc_minor, *psqlrc_major;

#if defined(WIN32) && (!defined(__MINGW32__))
#define R_OK 4
#endif

    psqlrc_minor = pg_malloc(strlen(filename) + 1 + strlen(PG_VERSION) + 1);
    sprintf(psqlrc_minor, "%s-%s", filename, PG_VERSION);
    psqlrc_major = pg_malloc(strlen(filename) + 1 + strlen(PG_MAJORVERSION) + 1);
    sprintf(psqlrc_major, "%s-%s", filename, PG_MAJORVERSION);

    /* check for minor version first, then major, then no version */
    if (access(psqlrc_minor, R_OK) == 0)
        (void) process_file(psqlrc_minor, false, false);
    else if (access(psqlrc_major, R_OK) == 0)
        (void) process_file(psqlrc_major, false, false);
    else if (access(filename, R_OK) == 0)
        (void) process_file(filename, false, false);

    free(psqlrc_minor);
    free(psqlrc_major);
}
Example #16
0
static void save_greeter_settings (void)
{
	char *str, *tfname;
	char buffer[256];
	GKeyFile *kf;
	gsize len;
	gint handle;

	// read in data from file to a key file
	kf = g_key_file_new ();
	if (!g_key_file_load_from_file (kf, GREETER_CONFIG_FILE, G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, NULL))
		return;

	// update changed values in the key file
	sprintf (buffer, "%s", gdk_color_to_string (&desktop_colour));
	g_key_file_set_string (kf, "greeter", "desktop_bg", buffer);
	g_key_file_set_string (kf, "greeter", "wallpaper", desktop_picture);
	g_key_file_set_string (kf, "greeter", "wallpaper_mode", desktop_mode);
	g_key_file_set_string (kf, "greeter", "gtk-font-name", desktop_font);
	g_key_file_set_string (kf, "greeter", "gtk-theme-name", "PiX");
	g_key_file_set_string (kf, "greeter", "gtk-icon-theme-name", "PiX");

	// write the modified key file out to a temp file
	str = g_key_file_to_data (kf, &len, NULL);
	handle = g_file_open_tmp ("XXXXXX", &tfname, NULL);
	write (handle, str, len);
	close (handle);
	g_free (str);

	// copy the temp file to the correct place with sudo
	sprintf (buffer, "sudo cp %s %s", tfname, GREETER_CONFIG_FILE);
	system (buffer);
}
Example #17
0
//int CSolver::GetActivityValue(char* colname, double& solutionvalue) {
//	int col = 0;
//	char buff[100];
//	if (m_ColMap.Lookup(colname, col) == false) {
//		sprintf(buff, "colname in: failed to find colname =%s\n",colname);
//		Message(buff);
//		return -1;
//	}
//	solutionvalue = m_x[col];
//	return 0;
//}
//*****************************************************************
int CSolver:: FindIndexes( char* colname,  char* rowname,
                          int& colndx,
                          int& rowndx ) {

    // Finds integer indexes for column and row names using Map.
    
    char buff[100];
    colndx = -1;
    rowndx = -1;
    int col, row;

    if ( m_RowMap.Lookup(rowname, row) == false ) {
  	     sprintf(buff, "rowname in: failed to find rowname = %s , colname in = %s",
		                rowname, colname);
         Message(buff);
         return -1;

    }
    if ( m_ColMap.Lookup(colname, col) == false ) {
         sprintf(buff, "colname in: failed to find colname =%s, rowname in = %s\n" ,
                        colname, rowname);
         Message(buff);
         return -1;
    }

    colndx = col;
    rowndx = row;

    return 0;
}
Example #18
0
//
//=========================================================================
//
// Write raw output to TCP clients
//
void modesSendRawOutput(struct modesMessage *mm) {
    char *p = &Modes.rawOut[Modes.rawOutUsed];
    int  msgLen = mm->msgbits / 8;
    int j;
    unsigned char * pTimeStamp;

    if (Modes.mlat && mm->timestampMsg) {
        *p++ = '@';
        pTimeStamp = (unsigned char *) &mm->timestampMsg;
        for (j = 5; j >= 0; j--) {
            sprintf(p, "%02X", pTimeStamp[j]);
            p += 2;
        }
        Modes.rawOutUsed += 12; // additional 12 characters for timestamp
    } else
        *p++ = '*';

    for (j = 0; j < msgLen; j++) {
        sprintf(p, "%02X", mm->msg[j]);
        p += 2;
    }

    *p++ = ';';
    *p++ = '\n';

    Modes.rawOutUsed += ((msgLen*2) + 3);
    if (Modes.rawOutUsed >= Modes.net_output_raw_size)
      {
      modesSendAllClients(Modes.ros, Modes.rawOut, Modes.rawOutUsed);
      Modes.rawOutUsed = 0;
      Modes.net_output_raw_rate_count = 0;
      }
}
Example #19
0
int name_by_ip (int conn_index, char * buf)
{
    struct addrinfo hints, *res;
    hints.ai_family = AF_INET6;
    hints.ai_socktype = 0;
    hints.ai_protocol = 0;
    hints.ai_flags = AI_CANONNAME| AI_V4MAPPED;
    static char out_buf[OUT_BUF_SIZE];

    if(getaddrinfo(&buf[sizeof(int)], "0", &hints, &res)){
    	//failed
    	sprintf(out_buf, "%s 0\n", &buf[sizeof(int)]);
    	DBG(("name_by_ip: malformed address request."));
    	OS_socket_write(all_conns[conn_index].fd, out_buf, strlen(out_buf));
    	return 0;
    }
    char tmpbuf[80], tmpp[80];
    int ret;
    if(ret = getnameinfo(res->ai_addr, res->ai_addrlen, tmpbuf, 79, tmpp, 79, NI_NAMEREQD|NI_NUMERICSERV)){
    	sprintf(out_buf, "%s 0\n", &buf[sizeof(int)]);
    	DBG(("%s", out_buf));
    	OS_socket_write(all_conns[conn_index].fd, out_buf, strlen(out_buf));
    	DBG(("name_by_ip: unable to resolve address."));
    	freeaddrinfo(res);
    	return 0;
    }
    sprintf(out_buf, "%s %s\n", &buf[sizeof(int)], tmpbuf);
    DBG(("%s", out_buf));
    OS_socket_write(all_conns[conn_index].fd, out_buf, strlen(out_buf));
    freeaddrinfo(res);
	return 1;
}
Example #20
0
static int
irc_decode_bitstring(const char **cpp, char *dn, const char *eom)
{
        const char *cp = *cpp;
        char *beg = dn, tc;
        int b, blen, plen;

        if ((blen = (*cp & 0xff)) == 0)
                blen = 256;
        plen = (blen + 3) / 4;
        plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1);
        if (dn + plen >= eom)
                return(-1);

        cp++;
        dn += sprintf(dn, "\\[x");
        for (b = blen; b > 7; b -= 8, cp++)
                dn += sprintf(dn, "%02x", *cp & 0xff);
        if (b > 4) {
                tc = *cp++;
                dn += sprintf(dn, "%02x", tc & (0xff << (8 - b)));
        } else if (b > 0) {
                tc = *cp++;
               dn += sprintf(dn, "%1x",
                               ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
        }
Example #21
0
void BlankGeom::LoadDrawObjs(vector< DrawObj* > & draw_obj_vec)
{
    char str[256];

    if ( m_Vehicle->IsGeomActive( m_ID ) )
    {
        sprintf(str,"%d",1);
        m_HighlightDrawObj.m_GeomID = m_ID+string(str);
        m_HighlightDrawObj.m_Visible = !m_GuiDraw.GetNoShowFlag();

        // Set Render Destination to Main VSP Window.
        m_HighlightDrawObj.m_Screen = DrawObj::VSP_MAIN_SCREEN;
        m_HighlightDrawObj.m_Type = DrawObj::VSP_POINTS;
        draw_obj_vec.push_back( &m_HighlightDrawObj) ;
    }

    if ( ( m_GuiDraw.GetDispFeatureFlag() && !m_GuiDraw.GetNoShowFlag() ) || m_Vehicle->IsGeomActive( m_ID ))
    {
        for ( int i = 0; i < m_FeatureDrawObj_vec.size(); i++ )
        {
            m_FeatureDrawObj_vec[i].m_Screen = DrawObj::VSP_MAIN_SCREEN;
            sprintf( str, "_%d", i );
            m_FeatureDrawObj_vec[i].m_GeomID = m_ID + "Feature_" + str;
            m_FeatureDrawObj_vec[i].m_LineWidth = 2.0;
            m_FeatureDrawObj_vec[i].m_LineColor = vec3d( 0.0, 0.0, 0.0 );
            m_FeatureDrawObj_vec[i].m_Type = DrawObj::VSP_LINE_STRIP;
            draw_obj_vec.push_back( &m_FeatureDrawObj_vec[i] );
        }
    }
}
Example #22
0
int EvalException(EXCEPTION_POINTERS *p)
{
    char pszError[256];
    if (p->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION)
    {
        if (p->ExceptionRecord->ExceptionInformation[0] == 1)
        {
            // write error
            sprintf(pszError, "EXCEPTION_ACCESS_VIOLATION: instruction address: 0x%p, invalid write to 0x%p",
                    p->ExceptionRecord->ExceptionAddress,
                    p->ExceptionRecord->ExceptionInformation[1]);
        }
        else
        {
            // read error
            sprintf(pszError, "EXCEPTION_ACCESS_VIOLATION: instruction address: 0x%p, invalid read from 0x%p",
                    p->ExceptionRecord->ExceptionAddress,
                    p->ExceptionRecord->ExceptionInformation[1]);
        }
        err_printf("%s\n", pszError);
        return EXCEPTION_CONTINUE_EXECUTION;
    }
    err_printf("exception %d caught in mpd", p->ExceptionRecord->ExceptionCode);
    return EXCEPTION_CONTINUE_SEARCH;
}
Example #23
0
bool ScreenMissionBriefing(const struct MissionOptions *m)
{
	const int w = gGraphicsDevice.cachedConfig.Res.x;
	const int h = gGraphicsDevice.cachedConfig.Res.y;
	const int y = h / 4;
	MissionBriefingData mData;
	memset(&mData, 0, sizeof mData);
	mData.IsOK = true;

	// Title
	CMALLOC(mData.Title, strlen(m->missionData->Title) + 32);
	sprintf(mData.Title, "Mission %d: %s",
		m->index + 1, m->missionData->Title);
	mData.TitleOpts = FontOptsNew();
	mData.TitleOpts.HAlign = ALIGN_CENTER;
	mData.TitleOpts.Area = gGraphicsDevice.cachedConfig.Res;
	mData.TitleOpts.Pad.y = y - 25;

	// Password
	if (m->index > 0)
	{
		sprintf(
			mData.Password, "Password: %s", gAutosave.LastMission.Password);
		mData.PasswordOpts = FontOptsNew();
		mData.PasswordOpts.HAlign = ALIGN_CENTER;
		mData.PasswordOpts.Area = gGraphicsDevice.cachedConfig.Res;
		mData.PasswordOpts.Pad.y = y - 15;
	}

	// Split the description, and prepare it for typewriter effect
	mData.TypewriterCount = 0;
	// allow some slack for newlines
	CMALLOC(mData.Description, strlen(m->missionData->Description) * 2 + 1);
	CCALLOC(mData.TypewriterBuf, strlen(m->missionData->Description) * 2 + 1);
	// Pad about 1/6th of the screen width total (1/12th left and right)
	FontSplitLines(m->missionData->Description, mData.Description, w * 5 / 6);
	mData.DescriptionPos = Vec2iNew(w / 12, y);

	// Objectives
	mData.ObjectiveDescPos =
		Vec2iNew(w / 6, y + FontStrH(mData.Description) + h / 10);
	mData.ObjectiveInfoPos =
		Vec2iNew(w - (w / 6), mData.ObjectiveDescPos.y + FontH());
	mData.ObjectiveHeight = h / 12;
	mData.MissionOptions = m;

	GameLoopData gData = GameLoopDataNew(
		&mData, MissionBriefingUpdate,
		&mData, MissionBriefingDraw);
	GameLoop(&gData);
	if (mData.IsOK)
	{
		SoundPlay(&gSoundDevice, StrSound("mg"));
	}

	CFREE(mData.Title);
	CFREE(mData.Description);
	CFREE(mData.TypewriterBuf);
	return mData.IsOK;
}
const char * Lwm2mCore_DebugPrintSockAddr(const struct sockaddr * sa)
{
    static char out[255];
    char buffer[64];
    const char* ip;
    int port;

    switch (sa->sa_family)
    {
        case AF_INET:
            ip = inet_ntop(AF_INET, &((struct sockaddr_in *)sa)->sin_addr, buffer, sizeof(buffer));
            port = ntohs(((struct sockaddr_in *)sa)->sin_port);
            sprintf(out, "%s:%d", ip, port);
            break;
        case AF_INET6:
            ip = inet_ntop(AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr, buffer, sizeof(buffer));
            port =  ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
            sprintf(out, "[%s]:%d", ip, port);
            break;
        default:
            Lwm2m_Error("Unsupported address family: %d\n", sa->sa_family);
            break;
    }
    return out;
}
Example #25
0
static void *
tf_for (void *arg)
{
  long cnt;
  char number[160];
  sprintf(number, "tf_for(%ld): begin", (long)arg);
  puts (number);
  
  sas_spin_lock_with_yield(&t_lock);
  sas_spin_unlock(&t_lock);
  
  for (cnt=sas_atomic_inc_long(&atomic_cnt); cnt<20; cnt=sas_atomic_inc_long(&atomic_cnt))
  {
    sprintf(number, "tf_for(%ld): sas_atomic_inc_long(%p)=%ld",
    		(long)arg, &atomic_cnt, cnt);
    puts (number);
  
    sleep(1);
  }

  sprintf(number, "tf_for(%ld): end", (long)arg);
  puts (number);
  
  return NULL;
}
Example #26
0
File: main.c Project: GPDP2/mupen64
__declspec(dllexport) void DllAbout ( HWND hParent )
{
#ifdef __WIN32__
    MessageBox(NULL, "Mupen64 HLE RSP plugin v0.2 with Azimers code by Hacktarux", "RSP HLE", MB_OK);
#else
#ifdef USE_GTK
    char tMsg[256];
    GtkWidget *dialog, *label, *okay_button;

    dialog = gtk_dialog_new();
    sprintf(tMsg,"Mupen64 HLE RSP plugin v0.2 with Azimers code by Hacktarux");
    label = gtk_label_new(tMsg);
    okay_button = gtk_button_new_with_label("OK");

    gtk_signal_connect_object(GTK_OBJECT(okay_button), "clicked",
                              GTK_SIGNAL_FUNC(gtk_widget_destroy),
                              GTK_OBJECT(dialog));
    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area),
                      okay_button);

    gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox),
                      label);
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
    gtk_widget_show_all(dialog);
#else
    char tMsg[256];
    sprintf(tMsg,"Mupen64 HLE RSP plugin v0.2 with Azimers code by Hacktarux");
    fprintf(stderr, "About\n%s\n", tMsg);
#endif
#endif
}
Example #27
0
/**
 * Test that sbuf_add_snum() successfully adds numbers.
 */
static void test_sbuf_add_snum(void)
{
	char nbuf[50];

	sbuf_reset(0);
	sprintf(nbuf, "%ld", LONG_MAX);
	CU_ASSERT_EQUAL(0, sbuf_add_snum(LONG_MAX, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, nbuf);
	CU_ASSERT_EQUAL(offset, strlen(nbuf));

	sbuf_reset(0);
	sprintf(nbuf, "%ld", -LONG_MAX);
	CU_ASSERT_EQUAL(0, sbuf_add_snum(-LONG_MAX, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, nbuf);
	CU_ASSERT_EQUAL(offset, strlen(nbuf));

	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_snum(-1, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, "-1");
	CU_ASSERT_EQUAL(offset, 2);

	sbuf_reset(0);
	CU_ASSERT_EQUAL(0, sbuf_add_snum(0, 0));
	CU_ASSERT_STRING_EQUAL(sbuf, "0");
	CU_ASSERT_EQUAL(offset, 1);
}
int
gweb_mysql_handle_login (j2c_map_t *j2cmap)
{
    struct j2c_login *jrecord = &j2cmap->login;

    MYSQL_RES *result;

    uint8_t qrybuf[MAX_MYSQL_QRYSZ];
    int len = 0, ret = -1;

    len += sprintf(qrybuf+len, "SELECT * FROM AppUsers WHERE ");
    len += sprintf(qrybuf+len, "Email='%s' AND Password='%s'",
		   jrecord->fields[0], jrecord->fields[1]);

    qrybuf[len] = '\0';

    if (mysql_query(g_mysql_ctx, qrybuf)) {
	report_mysql_error(g_mysql_ctx);
    }

    if ((result = mysql_store_result(g_mysql_ctx)) == NULL) {
	report_mysql_error(g_mysql_ctx);
    }

    if (mysql_num_rows(result) == 1) {
	ret = 0;
    }

    mysql_free_result(result);

    return (ret);
}
void FixDumpFileName (XnDevicePrivateData* pDevicePrivateData, XnChar* strFileName)
{
	XnChar strTempFileName[255];
	XnChar* nFind = 0;

	strcpy(strTempFileName, strFileName);

	nFind = strstr(strFileName, "SNSNSN");
	if (nFind != 0)
	{
		nFind[0] = 0;
		sprintf (strTempFileName, "%s%s%s", strFileName, pDevicePrivateData->pSensor->GetFixedParams()->GetSensorSerial(), nFind+6);

		strcpy(strFileName, strTempFileName);		
	}

	nFind = strstr(strFileName, "SETSET");
	if (nFind != 0)
	{
		XnInt32 nSet = 1;		
		XnBool bExists = TRUE;

		nFind[0] = 0;

		while (bExists == TRUE)
		{
			sprintf (strTempFileName, "%sSET%04d%s", strFileName, nSet, nFind+6);
			nSet++;

			xnOSDoesFileExist(strTempFileName, &bExists);
		}
			
		strcpy(strFileName, strTempFileName);		
	}
}
Example #30
0
static void
checkusers(void)
{
  int i;
  char statbuf[500];
  char idletime[500];
  struct timeval tstop;

  gettimeofday(&tstop, NULL);

  for (i = 0; i < num_users; ++i)
  {
    if (online[i].procid == 0)
      continue;

    /* Uploading */
    if ((!strncasecmp(online[i].status, "STOR", 4) ||
        !strncasecmp(online[i].status, "APPE", 4)) &&
        online[i].bytes_xfer != 0)
    {
      sprintf(statbuf, "Up:^%.1f", calc_time(i));
      idletime[0] = '\0';
    }
    /* Downloading */
    else if (!strncasecmp(online[i].status, "RETR", 4) && online[i].bytes_xfer != 0)
    {
      sprintf(statbuf, "Dn:^%.1f", calc_time(i));
      idletime[0] = '\0';
    }
    /* Idling */
    else if (time(NULL) - online[i].tstart.tv_sec > 5)
    {
      int32_t hours = 0;
      int32_t minutes = 0;
      int32_t seconds = tstop.tv_sec - online[i].tstart.tv_sec;
      while (seconds >= 3600)
      {
        ++hours;
        seconds -= 3600;
      }
      while (seconds >= 60)
      {
        ++minutes;
        seconds -= 60;
      }
      sprintf(statbuf, "Idle:");
      sprintf(idletime, "%02d:%02d:%02d", hours, minutes, seconds);
    }
    /* Doing something else... */
    else
    {
      sprintf(statbuf, "\"%s\"", online[i].status);
      trim(statbuf);
      idletime[0] = '\0';
    }

    printf("%-1s^%-1u^%-1.44s^%-1s^%-1s^%s\n",
           online[i].username, online[i].procid, statbuf, online[i].currentdir, get_g_name(online[i].groupid), idletime);
    }
}