Esempio n. 1
0
static void
add_sequence(char *rest, char *mapname)
{
	KeySym keysym;
	key_translation *tr, **prev_next;
	size_t chars;
	char keyname[KEYMAP_MAX_LINE_LENGTH];

	/* Skip over whitespace after the sequence keyword */
	chars = strspn(rest, " \t");
	rest += chars;

	/* Fetch the keysym name */
	chars = strcspn(rest, " \t\0");
	STRNCPY(keyname, rest, chars + 1);
	rest += chars;

	keysym = XStringToKeysym(keyname);
	if (keysym == NoSymbol)
	{
		DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname, mapname));
		return;
	}


	DEBUG_KBD(("Adding sequence for keysym (0x%lx, %s) -> ", keysym, keyname));

	free_key_translation(keymap[keysym & KEYMAP_MASK]);
	prev_next = &keymap[keysym & KEYMAP_MASK];

	while (*rest)
	{
		/* Skip whitespace */
		chars = strspn(rest, " \t");
		rest += chars;

		/* Fetch the keysym name */
		chars = strcspn(rest, " \t\0");
		STRNCPY(keyname, rest, chars + 1);
		rest += chars;

		keysym = XStringToKeysym(keyname);
		if (keysym == NoSymbol)
		{
			DEBUG_KBD(("Bad keysym \"%s\" in keymap %s (ignoring line)\n", keyname,
				   mapname));
			return;
		}

		/* Allocate space for key_translation structure */
		tr = (key_translation *) xmalloc(sizeof(key_translation));
		memset(tr, 0, sizeof(key_translation));
		*prev_next = tr;
		prev_next = &tr->next;
		tr->seq_keysym = keysym;

		DEBUG_KBD(("0x%x, ", (unsigned int) keysym));
	}
	DEBUG_KBD(("\n"));
}
Esempio n. 2
0
	void setupUserHomeDirectory()
	{
		STRNCPY(gameSavePath, "", sizeof(gameSavePath));
		STRNCPY(tempFile, "tmpsave", sizeof(tempFile));
		STRNCPY(saveFileIndex, "saveheader", sizeof(saveFileIndex));
		STRNCPY(continueFile, "continuesave", sizeof(continueFile));
	}
Esempio n. 3
0
int
        formatline(char *line)
{
  register int end;
  char   *temp;
  int     num = 0;

  if (!line)
    return 0;
  if (strlen(line) <= MAXMACRO)
    {
      STRNCPY(maclines[num], line, sizeof(maclines[0]));
      lineno++;
      return 1;
    }

  temp = line;
  while (1)
    {
      end = MAXMACRO - 1;
      if (end > strlen(temp))
  {
    lineno++;
    STRNCPY(maclines[num++], temp, sizeof(maclines[0]));
    return (num);
  }
      else
  for (; temp[end] != '%'; end--);

      lineno++;
      STRNCPY(maclines[num++], temp, end);

      temp = temp + end;
    }
}
bool DialogChangePassword::ResetUserPasswordStick10(void) {
  int ret;
  QByteArray PasswordString;
  unsigned char data[50 + 1];

  memset(data, 0, sizeof(data));

  // New User PIN
  PasswordString = ui->lineEdit_OldPW->text().toLatin1();
  STRNCPY((char *)data, 25, PasswordString.data(), 25);

  // Admin PIN
  PasswordString = ui->lineEdit_NewPW_1->text().toLatin1();
  STRNCPY((char *)&(data[25]), 25, PasswordString.data(), 25);

  ret = cryptostick->unlockUserPasswordStick10(data);

  bool success = ret == CMD_STATUS_OK;
  if (!success) {
    if (CMD_STATUS_WRONG_PASSWORD == ret) {
      csApplet->warningBox(tr("Wrong Admin PIN."));
    } else {
      csApplet->warningBox(tr("Couldn't unblock the user PIN. Error: %1").arg(ret));
    }
  } else {
    csApplet->messageBox(tr("User PIN successfully unblocked"));
  }
  return success;
}
Esempio n. 5
0
// Turns path into a full path:
//  - if not absolute, prepends gamedir
//  - calls realpath() to collapse ".." and such
//  - calls normalize_pathname() to fix backslashes, etc
//
// Much like realpath, buffer pointed to by fullpath is assumed to be 
// able to store a string of PATH_MAX length.
void sup_gamedir_path(const char *path, char *fullpath)
{
	char buf[PATH_MAX];
	
	// Build pathname from filename, plus gamedir if relative path.
	if(is_absolute_path(path))
		STRNCPY(buf, path, sizeof(buf));
	else
	{
		const char *plugpath = gpMetaUtilFuncs->pfnGetPluginPath(PLID);
		STRNCPY(buf, plugpath, sizeof(buf));
		for(int i = strlen(buf); i != -1; i--)
		{
			if(buf[i] == '/')
			{
				buf[i + 1] = '\0';
				break;
			}
		}
		strncat(buf, path, sizeof(buf));
	}

	normalize_path(buf);
	STRNCPY(fullpath, buf, sizeof(buf));
}
Esempio n. 6
0
SOAP_FMAC5 int SOAP_FMAC6 __tds__SetUser(struct soap* hSoap, struct _tds__SetUser *tds__SetUser, struct _tds__SetUserResponse *tds__SetUserResponse)
{
    NEW(User,USERS);
    ONVIF  *Onvif      = (ONVIF*)hSoap->hdOnvif;
	INT     i;
	NEWMIII(hSoap->fault ,struct SOAP_ENV__Fault,1);
	NEWMIII(hSoap->fault->SOAP_ENV__Code,struct SOAP_ENV__Code ,1);
	NEWMIII(hSoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode,struct SOAP_ENV__Code,1);
	NEWMIII(hSoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Subcode,struct SOAP_ENV__Code ,1);
		NEWMIII(hSoap->fault->SOAP_ENV__Reason,struct SOAP_ENV__Reason,1);
    if(NULL != tds__SetUser && NULL != tds__SetUser->User){
		for(i=0;i<tds__SetUser->__sizeUser&&i<OVFMAXCHANNEL;i++){
			STRNCPY(User->Users[i].UserName,tds__SetUser->User[i].Username,OVFCHARLENTH);;
			STRNCPY(User->Users[i].UserPwd ,tds__SetUser->User[i].Password,OVFCHARLENTH);;
			User->Users[i].UserLevel       =tds__SetUser->User[i].UserLevel;
		}
	}
    
    CHECK_CALLBACKFUC(Onvif->CallBackOvf,CallBackDevManage,SetUsers);
    if(FALSE==Onvif->CallBackOvf->CallBackDevManage->SetUsers( User)){

		hSoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Subcode->SOAP_ENV__Value ="ter:UsernameMissing" ;
		hSoap->fault->SOAP_ENV__Code->SOAP_ENV__Subcode->SOAP_ENV__Value ="ter:InvalidArgVal";
 		hSoap->fault->SOAP_ENV__Reason->SOAP_ENV__Text="The username Missing.";

		return SOAP_FAULT;
	}
   
    return SOAP_OK;
 }
Esempio n. 7
0
void	InetAddr::set(char	*straddr, int portnum)
{
	reset();	
	inet_addr_.sin_family = AF_INET;
	inet_addr_.sin_port = htons(portnum);
		
	if (straddr != NULL) {
		if (_isIPnumber(straddr)) {
			inet_addr_.sin_addr.s_addr	= inet_addr(straddr);
			STRNCPY(ipaddr, straddr, _LEN_INADDR);
		}
		else {
			STRNCPY(hostname, straddr, _LEN_HOSTNAME);
			struct hostent	*hent;
			hent = gethostbyname(straddr);
			if (hent==NULL) {
				inet_addr_.sin_addr.s_addr	= htonl(INADDR_ANY);
			}
			else {
				memcpy(& (inet_addr_.sin_addr.s_addr), hent->h_addr, hent->h_length);
				STRNCPY(ipaddr, inet_ntoa( *( (struct in_addr *) hent->h_addr ) ), _LEN_INADDR);
			}	
		}
	}
	else
		inet_addr_.sin_addr.s_addr	= htonl(INADDR_ANY);
}
Esempio n. 8
0
char   *
        format(char *buf, char *from, int width, int right_justify)
{
  int     len = strlen(from), i;

  if (len > width)
    len = width;

  buf[width] = '\0';

  if (right_justify)
    {
      STRNCPY(&(buf[width - len]), from, len);

      for (i = 0; i < (width - len); i++)
  buf[i] = ' ';
    }
  else
    {
      STRNCPY(buf, from, len);

      for (i = len; i < width; i++)
  buf[i] = ' ';
    }

  return (buf);
}
Esempio n. 9
0
//=============================================================================
// Return the length of the given track
//=============================================================================
int CCDAudio::GetTrackLength(const int nTrack)
{
	if(IsMediaInsert())
	{
		const int nBuffSize = 64;
		TCHAR szTrack[10];
		TCHAR szReqBuff[nBuffSize];
		TCHAR szBuff[nBuffSize];
		
		ITOA( nTrack, szTrack, 10 );
		lstrcpy( szReqBuff, _T("status cdaudio length track ") );
		lstrcat( szReqBuff, szTrack );

		m_nErrorCode = mciSendString( szReqBuff, szBuff, nBuffSize, NULL );    
		if( m_nErrorCode != 0 )
		{
			return 0;
		}

		TCHAR szMin[3], szSec[3];

		STRNCPY( szMin, szBuff, 2 );
		STRNCPY( szSec, (szBuff + 3), 2 );

		return ((ATOI(szMin) * 60) + ATOI(szSec));		
	}

	return 0;
}
bool DialogChangePassword::SendNewPassword(void) {
  bool communicationSuccess;
  QByteArray PasswordString;
  int password_length = STICK20_PASSOWRD_LEN;
  unsigned char Data[password_length + 2];

  // Set kind of password
  switch (PasswordKind) {
  case STICK20_PASSWORD_KIND_USER:
    Data[0] = 'P';
    break;
  case STICK20_PASSWORD_KIND_ADMIN:
    Data[0] = 'A';
    break;
  default:
    Data[0] = '?';
    break;
  }

  // Send old password
  PasswordString = ui->lineEdit_OldPW->text().toLatin1();

  STRNCPY((char *)&Data[1], STICK20_PASSOWRD_LEN - 1, PasswordString.data(), STICK20_PASSOWRD_LEN);
  Data[STICK20_PASSOWRD_LEN + 1] = 0;

  communicationSuccess = cryptostick->stick20SendPassword(Data);
  if (!communicationSuccess) {
    csApplet->warningBox(tr("There was a problem during communicating with device. Please retry."));
    return false;
  }

  bool isOldPasswordCorrect = CheckResponse(TRUE) == 1;
  if (!isOldPasswordCorrect) {
    csApplet->warningBox(tr("Current password is not correct. Please retry."));
    return false;
  }

  // Change password
  PasswordString = ui->lineEdit_NewPW_1->text().toLatin1();

  STRNCPY((char *)&Data[1], STICK20_PASSOWRD_LEN, PasswordString.data(), STICK20_PASSOWRD_LEN);
  Data[STICK20_PASSOWRD_LEN + 1] = 0;

  communicationSuccess = cryptostick->stick20SendNewPassword(Data);
  if (!communicationSuccess) {
    csApplet->warningBox(tr("There was a problem during communicating with device. Please retry."));
    return false;
  }

  bool isNewPasswordCorrect = CheckResponse(FALSE) == 1;
  if (!isNewPasswordCorrect) {
    csApplet->warningBox(tr("New password is not correct. Please retry."));
    return false;
  }
  csApplet->messageBox(tr("New password is set"));
  return true;
}
Esempio n. 11
0
static void loadWidgetSet(char *filename)
{
	cJSON *root, *node;
	char *text;
	Widget *w;
	
	SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);

	text = readFile(filename);
	root = cJSON_Parse(text);

	for (node = root->child ; node != NULL ; node = node->next)
	{
		w = malloc(sizeof(Widget));
		memset(w, 0, sizeof(Widget));
		
		w->type = lookup(cJSON_GetObjectItem(node, "type")->valuestring);
		STRNCPY(w->name, cJSON_GetObjectItem(node, "name")->valuestring, MAX_NAME_LENGTH);
		STRNCPY(w->group, cJSON_GetObjectItem(node, "group")->valuestring, MAX_NAME_LENGTH);
		w->rect.x = cJSON_GetObjectItem(node, "x")->valueint;
		w->rect.y = cJSON_GetObjectItem(node, "y")->valueint;
		w->rect.w = cJSON_GetObjectItem(node, "w")->valueint;
		w->rect.h = cJSON_GetObjectItem(node, "h")->valueint;
		w->enabled = 1;
		w->visible = 1;
		
		if (w->rect.x == -1)
		{
			w->rect.x = SCREEN_WIDTH / 2;
		}
		
		switch (w->type)
		{
			case WT_BUTTON:
				STRNCPY(w->text, cJSON_GetObjectItem(node, "text")->valuestring, MAX_NAME_LENGTH);
				w->rect.x -= w->rect.w / 2;
				w->rect.y -= (w->rect.h / 2) + 8;
				break;
				
			case WT_SELECT:
				STRNCPY(w->text, cJSON_GetObjectItem(node, "text")->valuestring, MAX_NAME_LENGTH);
				w->rect.x -= w->rect.w / 2;
				w->rect.y -= (w->rect.h / 2) + 8;
				createOptions(w, cJSON_GetObjectItem(node, "options")->valuestring);
				break;
		}
	
		tail->next = w;
		tail = w;
	}

	cJSON_Delete(root);
	free(text);
}
Esempio n. 12
0
/* INTPROTO */
static void
rxvt_update_lastlog(const char *fname, const char *pty, const char *host)
{
# ifdef HAVE_STRUCT_LASTLOGX
    struct lastlogx llx;
# endif
# ifdef HAVE_STRUCT_LASTLOG
    int             fd;
    struct lastlog  ll;
#  ifdef LASTLOG_IS_DIR
    char            lastlogfile[256];
#  endif
    struct passwd  *pwent;
# endif

# ifdef HAVE_STRUCT_LASTLOGX
    MEMSET(&llx, 0, sizeof(llx));
    llx.ll_tv.tv_sec = time(NULL);
    llx.ll_tv.tv_usec = 0;
    STRNCPY(llx.ll_line, pty, sizeof(llx.ll_line));
    STRNCPY(llx.ll_host, host, sizeof(llx.ll_host));
    updlastlogx(RXVT_LASTLOGX_FILE, getuid(), &llx);
# endif

# ifdef HAVE_STRUCT_LASTLOG
    pwent = getpwuid(getuid());
    if (!pwent) {
	rxvt_msg (DBG_ERROR, DBG_LOGGING, "no entry in password file");
	return;
    }
    MEMSET(&ll, 0, sizeof(ll));
    ll.ll_time = time(NULL);
    STRNCPY(ll.ll_line, pty, sizeof(ll.ll_line));
    STRNCPY(ll.ll_host, host, sizeof(ll.ll_host));
#  ifdef LASTLOG_IS_DIR
    sprintf(lastlogfile, "%.*s/%.*s",
        sizeof(lastlogfile) - sizeof(pwent->pw_name) - 2, fname,
        sizeof(pwent->pw_name),
        (!pwent->pw_name || pwent->pw_name[0] == '\0') ? "unknown"
			       : pwent->pw_name);
    if ((fd = open(lastlogfile, O_WRONLY | O_CREAT, 0644)) >= 0) {
	write(fd, &ll, sizeof(ll));
	close(fd);
    }
#  else
    if ((fd = open(fname, O_RDWR)) != -1) {
	if (lseek(fd, (off_t) ((long)pwent->pw_uid * sizeof(ll)),
	      SEEK_SET) != -1)
	    write(fd, &ll, sizeof(ll));
	close(fd);
    }
#  endif	    /* LASTLOG_IS_DIR */
# endif		    /* HAVE_STRUCT_LASTLOG */
}
Esempio n. 13
0
static void loadCapitalShipDef(char *filename)
{
	cJSON *root;
	char *text;
	Entity *e;

	SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);

	text = readFile(filename);

	root = cJSON_Parse(text);

	if (root)
	{
		e = malloc(sizeof(Entity));
		memset(e, 0, sizeof(Entity));
		defTail->next = e;
		defTail = e;

		e->type = ET_CAPITAL_SHIP;
		e->active = 1;

		STRNCPY(e->name, cJSON_GetObjectItem(root, "name")->valuestring, MAX_NAME_LENGTH);
		STRNCPY(e->defName, e->name, MAX_NAME_LENGTH);
		e->shield = e->maxShield = cJSON_GetObjectItem(root, "shield")->valueint;
		e->shieldRechargeRate = cJSON_GetObjectItem(root, "shieldRechargeRate")->valueint;
		e->texture = getTexture(cJSON_GetObjectItem(root, "texture")->valuestring);
		e->speed = 1;
		e->systemPower = 3;
		e->flags = EF_NO_HEALTH_BAR;

		e->action = think;
		e->die = die;

		SDL_QueryTexture(e->texture, NULL, NULL, &e->w, &e->h);

		e->separationRadius = MAX(e->w, e->h);

		loadComponents(e, cJSON_GetObjectItem(root, "components"));

		loadGuns(e, cJSON_GetObjectItem(root, "guns"));

		loadEngines(e, cJSON_GetObjectItem(root, "engines"));

		cJSON_Delete(root);
	}
	else
	{
		SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to load '%s'", filename);
	}

	free(text);
}
Esempio n. 14
0
/* Split input into lines, and call linehandler for each
   line. Incomplete lines are saved in the rest variable, which should
   initially point to NULL. When linehandler returns False, stop and
   return False. Otherwise, return True.  */
RD_BOOL
str_handle_lines(const char *input, char **rest, str_handle_lines_t linehandler, void *data)
{
	char *buf, *p;
	char *oldrest;
	size_t inputlen;
	size_t buflen;
	size_t restlen = 0;
	RD_BOOL ret = True;

	/* Copy data to buffer */
	inputlen = strlen(input);
	if (*rest)
		restlen = strlen(*rest);
	buflen = restlen + inputlen + 1;
	buf = (char *) xmalloc(buflen);
	buf[0] = '\0';
	if (*rest)
		STRNCPY(buf, *rest, buflen);
	strncat(buf, input, inputlen);
	p = buf;

	while (1)
	{
		char *newline = strchr(p, '\n');
		if (newline)
		{
			*newline = '\0';
			if (!linehandler(p, data))
			{
				p = newline + 1;
				ret = False;
				break;
			}
			p = newline + 1;
		}
		else
		{
			break;

		}
	}

	/* Save in rest */
	oldrest = *rest;
	restlen = buf + buflen - p;
	*rest = (char *) xmalloc(restlen);
	STRNCPY((*rest), p, restlen);
	xfree(oldrest);

	xfree(buf);
	return ret;
}
Esempio n. 15
0
File: open.c Progetto: GYGit/reactos
int
FTPInitConnectionInfo(const FTPLIPtr lip, const FTPCIPtr cip, size_t bufSize)
{
	size_t siz;

	if ((lip == NULL) || (cip == NULL) || (bufSize == 0))
		return (kErrBadParameter);

	siz = sizeof(FTPConnectionInfo);
	(void) memset(cip, 0, siz);

	if (strcmp(lip->magic, kLibraryMagic))
		return (kErrBadMagic);

	cip->buf = NULL;	/* denote that it needs to be allocated. */
	cip->bufSize = bufSize;
	cip->port = lip->defaultPort;
	cip->firewallPort = lip->defaultPort;
	cip->maxDials = kDefaultMaxDials;
	cip->redialDelay = kDefaultRedialDelay;
	cip->xferTimeout = kDefaultXferTimeout;
	cip->connTimeout = kDefaultConnTimeout;
	cip->ctrlTimeout = kDefaultCtrlTimeout;
	cip->abortTimeout = kDefaultAbortTimeout;
	cip->ctrlSocketR = kClosedFileDescriptor;
	cip->ctrlSocketW = kClosedFileDescriptor;
	cip->dataPortMode = kSendPortMode;
	cip->dataSocket = kClosedFileDescriptor;
	cip->lip = lip;
	cip->hasPASV = kCommandAvailabilityUnknown;
	cip->hasSIZE = kCommandAvailabilityUnknown;
	cip->hasMDTM = kCommandAvailabilityUnknown;
	cip->hasREST = kCommandAvailabilityUnknown;
	cip->hasNLST_d = kCommandAvailabilityUnknown;
	cip->hasUTIME = kCommandAvailabilityUnknown;
	cip->hasFEAT = kCommandAvailabilityUnknown;
	cip->hasMLSD = kCommandAvailabilityUnknown;
	cip->hasMLST = kCommandAvailabilityUnknown;
	cip->hasCLNT = kCommandAvailabilityUnknown;
	cip->hasRETRBUFSIZE = kCommandAvailabilityUnknown;
	cip->hasRBUFSIZ = kCommandAvailabilityUnknown;
	cip->hasRBUFSZ = kCommandAvailabilityUnknown;
	cip->hasSTORBUFSIZE = kCommandAvailabilityUnknown;
	cip->hasSBUFSIZ = kCommandAvailabilityUnknown;
	cip->hasSBUFSZ = kCommandAvailabilityUnknown;
	cip->STATfileParamWorks = kCommandAvailabilityUnknown;
	cip->NLSTfileParamWorks = kCommandAvailabilityUnknown;
	cip->firewallType = kFirewallNotInUse;
	cip->startingWorkingDirectory = NULL;
	(void) STRNCPY(cip->magic, kLibraryMagic);
	(void) STRNCPY(cip->user, "anonymous");
	return (kNoErr);
}	/* FTPInitConnectionInfo */
Esempio n. 16
0
File: Glob.c Progetto: aosm/ncftp
static
void RemoteGlobCollapse(char *pattern, LineListPtr fileList)
{
	LinePtr lp, nextLine;
	string patPrefix;
	string cur, prev;
	char *endp, *cp, *dp;
	char *pp;
	int wasGlobChar;
	size_t plen;

	/* Copy all characters before the first glob-char. */
	dp = patPrefix;
	endp = dp + sizeof(patPrefix) - 1;
	wasGlobChar = 0;
	for (cp = pattern; dp < endp; ) {
		for (pp=kGlobChars; *pp != '\0'; pp++) {
			if (*pp == *cp) {
				wasGlobChar = 1;
				break;
			}
		}
		if (wasGlobChar)
			break;
		*dp++ = *cp++;
	}
	*dp = '\0';
	plen = (size_t) (dp - patPrefix);

	*prev = '\0';
	for (lp=fileList->first; lp != NULL; lp = nextLine) {
		nextLine = lp->next;
		if (strncmp(lp->line, patPrefix, plen) == 0) {
			STRNCPY(cur, lp->line + plen);
			cp = strchr(cur, '/');
			if (cp != NULL)
				*cp = '\0';
			if (*prev && STREQ(cur, prev)) {
				nextLine = RemoveLine(fileList, lp);
			} else {
				STRNCPY(prev, cur);
				/* We are playing with a dynamically
				 * allocated string, but since the
				 * following expression is guaranteed
				 * to be the same or shorter, we won't
				 * overwrite the bounds.
				 */
				sprintf(lp->line, "%s%s", patPrefix, cur);
			}
		}
	}
}	/* RemoteGlobCollapse */
Esempio n. 17
0
File: sushi.c Progetto: ocxtal/sushi
/*
 * ゲーム関連
 * 寿司の位置を更新したり、ポイントを計算したりする
 */
struct sushi_game *sushi_init_game(char const *sushi, char const *fish[], int len, double fish_per_call)
{
	int i;
	char const *eraser = " ";
	struct sushi_game *sg;

	sg = (struct sushi_game *)malloc(sizeof(struct sushi_game));
	if(sg == NULL) {
		return NULL;
	}
//#define STRNCPY 	mbstowcs
#define STRNCPY 	strncpy

	STRNCPY(sg->sushi, sushi, 10);
	STRNCPY(sg->eraser, eraser, 10);
	sg->fish_attr_cnt = 0;
	while(*fish != NULL && sg->fish_attr_cnt < 50) {
		STRNCPY(sg->fish[sg->fish_attr_cnt++], *fish++, 10);
	}
#undef STRNCPY
	sg->width = SUSHI_XWINDOW;			// 寿司1つで半角2文字分を消費するので、x座標は2文字ごとに1進める
	sg->height = SUSHI_YWINDOW;

	// 寿司の位置の初期化 (最初は(0, 0)に縮重している)
	sg->sushi_len = len;				// 最初の寿司の長さは1
	sg->dir = SUSHI_RIGHT;
	sg->sushi_max = 50 * (sg->width + sg->height);
	sg->sushi_pos = (struct sushi_pos *)malloc((sg->sushi_max + 1) * sizeof(struct sushi_pos));
	if(sg->sushi_pos == NULL) {
		free(sg);
		return NULL;
	}
	sg->sushi_pos[0].x = sg->sushi_pos[0].y = sg->sushi_pos[0].attr = 0;
	for(i = 1; i < sg->sushi_max; i++) {
		sg->sushi_pos[i].x = sg->sushi_pos[i].y = -1;
		sg->sushi_pos[i].attr = 0;
	}

	// 魚の位置の初期化 (最初は魚はいない)
	sg->fish_per_call = fish_per_call;
	sg->fish_cnt = 0;
	sg->fish_max = (sg->width * sg->height) / 100;
	sg->fish_pos = (struct sushi_pos *)malloc((sg->fish_max + 1) * sizeof(struct sushi_pos));
	if(sg->fish == NULL) {
		free(sg->sushi_pos);
		free(sg);
		return NULL;
	}
	memset(sg->fish_pos, 0, (sg->fish_max + 1) * sizeof(struct sushi_pos));

	return(sg);
}
Esempio n. 18
0
void
clip_mch_set_selection(VimClipboard *cbd)
{
    int type;
    long_u  len;
    char_u *text_clip, vim_clip[2], *str = NULL;
    PhClipHeader clip_header[2];

    /* Prevent recursion from clip_get_selection() */
    if (cbd->owned == TRUE)
	return;

    cbd->owned = TRUE;
    clip_get_selection(cbd);
    cbd->owned = FALSE;

    type = clip_convert_selection(&str, &len, cbd);
    if (type >= 0)
    {
	text_clip = lalloc(len + 1, TRUE); /* Normal text */

	if (text_clip && vim_clip)
	{
	    memset(clip_header, 0, sizeof(clip_header));

	    STRNCPY(clip_header[0].type, CLIP_TYPE_VIM, 8);
	    clip_header[0].length = sizeof(vim_clip);
	    clip_header[0].data   = vim_clip;

	    STRNCPY(clip_header[1].type, CLIP_TYPE_TEXT, 8);
	    clip_header[1].length = len + 1;
	    clip_header[1].data   = text_clip;

	    switch(type)
	    {
		default: /* fallthrough to MLINE */
		case MLINE:	*vim_clip = 'L'; break;
		case MCHAR:	*vim_clip = 'C'; break;
		case MBLOCK:	*vim_clip = 'B'; break;
	    }

	    vim_strncpy(text_clip, str, len);

	    vim_clip[ 1 ] = NUL;

	    PhClipboardCopy(PhInputGroup(NULL), 2, clip_header);
	}
	vim_free(text_clip);
    }
    vim_free(str);
}
Esempio n. 19
0
static void loadTrophyData(char *filename)
{
	cJSON *root, *node;
	char *text;
	Trophy *t, *tail;
	int count[TROPHY_MAX];

	SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", filename);

	text = readFile(filename);
	root = cJSON_Parse(text);

	tail = &game.trophyHead;
	
	memset(count, 0, sizeof(int) * TROPHY_MAX);

	for (node = root->child ; node != NULL ; node = node->next)
	{
		if (cJSON_GetObjectItem(node, "id")->valuestring[0] != '_')
		{
			t = malloc(sizeof(Trophy));
			memset(t, 0, sizeof(Trophy));

			STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH);
			STRNCPY(t->title, _(cJSON_GetObjectItem(node, "title")->valuestring), MAX_DESCRIPTION_LENGTH);
			STRNCPY(t->description, _(cJSON_GetObjectItem(node, "description")->valuestring), MAX_DESCRIPTION_LENGTH);
			t->value = lookup(cJSON_GetObjectItem(node, "value")->valuestring);
			t->hidden = getJSONValue(node, "hidden", 0);
			
			t->stat = -1;
			
			/* can't use the getJSONValue here, as it could lead to false positives */
			if (cJSON_GetObjectItem(node, "stat"))
			{
				t->stat = lookup(cJSON_GetObjectItem(node, "stat")->valuestring);
				t->statValue = cJSON_GetObjectItem(node, "statValue")->valueint;
			}
			
			count[t->value]++;
			count[TROPHY_UNEARNED]++;

			tail->next = t;
			tail = t;
		}
	}
	
	SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Trophies (%d) [Bronze=%d, Silver=%d, Gold=%d, Platinum=%d]", count[TROPHY_UNEARNED], count[TROPHY_BRONZE], count[TROPHY_SILVER], count[TROPHY_GOLD], count[TROPHY_PLATINUM]);

	cJSON_Delete(root);
	free(text);
}
Esempio n. 20
0
SOAP_FMAC5 int SOAP_FMAC6 __tds__SetRemoteUser(struct soap* hSoap, struct _tds__SetRemoteUser *tds__SetRemoteUser, struct _tds__SetRemoteUserResponse *tds__SetRemoteUserResponse)
{
  	NEW(lpRtUser,struct tt__RemoteUser);
    NEW(RtUser  ,REMOTEUSER);
    ONVIF  *Onvif      = (ONVIF*)hSoap->hdOnvif;
	
	STRNCPY(RtUser->UserName,lpRtUser->Username,OVFCHARLENTH);
	STRNCPY(RtUser->UserPwd ,lpRtUser->Password,OVFCHARLENTH);
	RtUser->UserUseDerivedPwd=lpRtUser->UseDerivedPassword;
    CHECK_CALLBACKFUC(Onvif->CallBackOvf,CallBackDevManage,SetRemoteUser);
    if(FALSE==Onvif->CallBackOvf->CallBackDevManage->SetRemoteUser( RtUser))return SOAP_FAULT;
    	
	return SOAP_OK;
}
Esempio n. 21
0
char *GetProgramName(char *programName, int size)
{
	char name[512];
	GetModuleFileName(GetModuleHandle(NULL), name, sizeof(name));
	char *p = strrchr(name, '\\');
	if (p)
	{
		STRNCPY(programName, p + 1, size);
	}
	else{
		STRNCPY(programName, name, size);
	}

	return programName;
}
Esempio n. 22
0
static void raiseDeadMoveToTopTarget()
{
	char c;
	int i, j;

	if (atTarget())
	{
		setEntityAnimation(self, "PHANTASMAL_BOLT_FIRE");

		self->thinkTime = 30;

		self->action = &raiseDead;

		self->mental = 2 + prand() % 4;

		STRNCPY(self->description, "123456", sizeof(self->description));

		for (i=0;i<6;i++)
		{
			j = prand() % 6;

			c = self->description[i];

			self->description[i] = self->description[j];

			self->description[j] = c;
		}
	}

	checkToMap(self);

	becomeTransparent();
}
Esempio n. 23
0
IOKitDevice& IOKitDevice::operator=(const IOKitDevice& clDevice_)
{
   if(this == &clDevice_)
      return *this;
      
   if (hSavedService)
   {
      IOObjectRelease(hSavedService);
      hSavedService = NULL;
   }   

   if (clDevice_.hSavedService)
   {
      IOObjectRetain(clDevice_.hSavedService);
      hSavedService = clDevice_.hSavedService;
   }

   usBusNumber = clDevice_.usBusNumber;
	usAddress = clDevice_.usAddress;
   usVid = clDevice_.usVid;
   usPid = clDevice_.usPid;
	usConfigurationNum = clDevice_.usConfigurationNum;
   ulSerialNumber = clDevice_.ulSerialNumber;
	ulLocation = clDevice_.ulLocation;
    
   STRNCPY(szProductDescription, clDevice_.szProductDescription, sizeof(szProductDescription));
   memcpy(szSerialString, clDevice_.szSerialString, sizeof(szSerialString));
   memcpy(&stDeviceDescriptor, &(clDevice_.stDeviceDescriptor), sizeof(clDevice_.stDeviceDescriptor));
   memcpy(szSystemPath, clDevice_.szSystemPath, sizeof(clDevice_.szSystemPath));

   return *this;
}
Esempio n. 24
0
IOKitDevice::IOKitDevice(const IOKitDevice& device)
:
   usBusNumber(device.usBusNumber),
	usAddress(device.usAddress),
   usVid(device.usVid),
   usPid(device.usPid),
	usConfigurationNum(device.usConfigurationNum),
   ulSerialNumber(device.ulSerialNumber),
	ulLocation(device.ulLocation),
   hSavedService(NULL)
{

   if (device.hSavedService)
   {
      IOObjectRetain(device.hSavedService);
      hSavedService = device.hSavedService;
   }

   STRNCPY(szProductDescription, device.szProductDescription, sizeof(szProductDescription));
   memcpy(szSerialString, device.szSerialString, sizeof(szSerialString));
   memcpy(&stDeviceDescriptor, &(device.stDeviceDescriptor), sizeof(device.stDeviceDescriptor));
   memcpy(szSystemPath, device.szSystemPath, sizeof(device.szSystemPath));

   return;
}
Esempio n. 25
0
// List the registered cvars for the given plugin id.
void DLLINTERNAL MRegCvarList::show(int plugin_id) {
	int i, n=0;
	MRegCvar *icvar;
	char bname[30+1], bval[15+1];	// +1 for term null
	
	/*
	// If OS doesn't support DLFNAME, then we can't know what the plugin's
	// registered cvars are.
	DLFNAME(NULL);
	if(meta_errno==ME_OSNOTSUP) {
		META_CONS("Registered cvars: unknown (can't get info under this OS)");
		return;
	}
	*/
	
	META_CONS("%-*s     %*s  %s", 
			sizeof(bname)-1, "Registered cvars:",
			sizeof(bval)-1, "float value",
			"string value");
	for(i=0; i < endlist; i++) {
		icvar = &vlist[i];
		if(icvar->plugid != plugin_id)
			continue;
		STRNCPY(bname, icvar->data->name, sizeof(bname));
		safevoid_snprintf(bval, sizeof(bval), "%f", icvar->data->value);
		META_CONS("   %-*s  %*s  %s", 
				sizeof(bname)-1, bname,
				sizeof(bval)-1, bval,
				icvar->data->string);
		n++;
	}
	META_CONS("%d cvars", n); 
}
Esempio n. 26
0
void TimeFmt::printHourMinSec(int sec, char *buf, int buflen, int hoursonlyifneeded) {
  int hours, minutes, seconds;
  int negative = sec < 0;

  sec = ABS(sec);
  if (buf == NULL) return;

  if (sec == -1) {
    *buf = 0;
    return;
  }

  hours = sec / 3600;
  sec -= hours * 3600;
  seconds = sec % 60;
  sec /= 60;
  minutes = sec;

  String sp;
  if (hoursonlyifneeded && hours == 0)
    sp = StringPrintf("%s%d:%02d", (minutes == 0 && negative) ? "-" : "", minutes, seconds);
  else
    sp = StringPrintf("%s%d:%02d:%02d", (minutes == 0 && negative) ? "-" : "", hours, minutes, seconds);

  STRNCPY(buf, sp, buflen);
}
Esempio n. 27
0
static void respawn()
{
	self->thinkTime--;

	if (self->thinkTime % 3 == 0)
	{
		self->flags ^= NO_DRAW;
	}

	if (self->thinkTime <= 0)
	{
		self->flags &= ~NO_DRAW;

		self->touch = &pushEntity;

		self->mental = 0;

		self->action = &horizontalGlassWait;

		self->thinkTime = self->maxThinkTime;

		self->active = FALSE;

		STRNCPY(self->requires, self->objectiveName, sizeof(self->requires));
	}
}
Esempio n. 28
0
char* CharArrayAddString(char* pHead, int maxbufsize, char* caBuf, const unsigned int code, const char* str)
{
   const int usedLen = caBuf - pHead;
   const int unusedLen = maxbufsize - usedLen;

   if(pHead == caBuf)
   {
      pHead[0] = CA_SETHEADER(0, code);
   }
   else
   {
      const unsigned int primeHeader = (unsigned int)pHead[0];
      unsigned int numParams = CA_GETNUMPARAMS(primeHeader);
      const unsigned int primeCode = CA_GETCODE(primeHeader);

      caBuf[0] = CA_SETHEADER(numParams, code);
      
      numParams++;
      pHead[0] = CA_SETHEADER(numParams, primeCode);
   }

   STRNCPY((caBuf + 1), (unusedLen - 1), str, (unusedLen - 1));
   
   return CharArrayAddEmptyString(caBuf + 1, unusedLen - 1);
}
Esempio n. 29
0
/*! 
*************************************************************************************
* \brief	reopen log file when finish setting current path
*
* \param	pCtx		context pCtx
* \param	pCurPath	current path string
*
* \return	NONE
*
* \note	N/A
*************************************************************************************
*/
void WelsReopenTraceFile( void *pCtx, str_t *pCurPath )
{
#ifdef ENABLE_TRACE_FILE
	sWelsEncCtx *pEncCtx	= (sWelsEncCtx *)pCtx;
	if (wlog == WelsLogDefault)
	{
		str_t strTraceFile[MAX_FNAME_LEN] = {0};
		int32_t len = 0;
		if (pEncCtx->pFileLog != NULL)
		{
			fclose(pEncCtx->pFileLog);
			pEncCtx->pFileLog = NULL;
		}
		pEncCtx->uiSizeLog	= 0;
		len = STRNLEN( pCurPath, MAX_FNAME_LEN-1 );	// confirmed_safe_unsafe_usage
		if (len >= MAX_FNAME_LEN)
			return;
		STRNCPY(strTraceFile, MAX_FNAME_LEN, pCurPath, len);	// confirmed_safe_unsafe_usage
#ifdef __GNUC__		
		STRCAT(strTraceFile, MAX_FNAME_LEN-len, "/wels_encoder_trace.txt");	// confirmed_safe_unsafe_usage
		pEncCtx->pFileLog	= FOPEN(strTraceFile, "wt+");	// confirmed_safe_unsafe_usage
#elif WIN32
		STRCAT(strTraceFile, MAX_FNAME_LEN-len, "\\wels_encoder_trace.txt");// confirmed_safe_unsafe_usage
#if _MSC_VER >= 1500
		FOPEN(&pEncCtx->pFileLog, strTraceFile, "wt+");	// confirmed_safe_unsafe_usage
#else
		pEncCtx->pFileLog	= FOPEN(strTraceFile, "wt+");	// confirmed_safe_unsafe_usage
#endif//_MSC_VER>=1500
#else		
#endif//__GNUC__
	}
#endif//ENABLE_TRACE_FILE
}
Esempio n. 30
0
File: fs.c Progetto: ashleyh/neovim
int os_get_absolute_path(char_u *fname, char_u *buf, int len, int force)
{
  char_u *p;
  *buf = NUL;

  char relative_directory[len];
  char *end_of_path = (char *) fname;

  // expand it if forced or not an absolute path
  if (force || !os_is_absolute_path(fname)) {
    if ((p = vim_strrchr(fname, '/')) != NULL) {
      STRNCPY(relative_directory, fname, p-fname);
      relative_directory[p-fname] = NUL;
      end_of_path = (char *) (p + 1);
    } else {
      relative_directory[0] = NUL;
      end_of_path = (char *) fname;
    }

    if (FAIL == os_full_dir_name(relative_directory, (char *) buf, len)) {
      return FAIL;
    }
  }
  return append_path((char *) buf, (char *) end_of_path, len);
}