示例#1
0
//-----------------------------------------------------------------
//  Import elevation file
//  Elevation are processed QGT per QGT
//  The array Spot is used to store for each detail tile the
//  spot elevation:
//  Type 0:   This is a unic elevation shared between sevral tiles
//  Type 1:   This is the unic center elevation for the detail tile
//  Type 2:   Elevation is an array of integers of dimension dim 
//-----------------------------------------------------------------
//  1) The elevations found in the database are loaded
//  2) The elevations from the BT file for this QGT are loaded
//     by => GetRegionElevation
//  3) New elevation overwrite those from the database =>Overwrite
//  4) Rectabgular region of same type are computed => CreateAreas
//-----------------------------------------------------------------
void CImport::ImportElevations(char *fn)
{ REGION_REC reg;
  reg.qgt = 0;
  CBtParser btp(fn);
  Dim = btp.Resolution();
  TRACE("=====BUILDING REGIONS ==========================");
  while (  btp.GetQgtKey(reg.qtx,reg.qtz))
  { reg.key = QGTKEY(reg.qtx,reg.qtz);
    TRACE("---QGT key=%010d",reg.key);
   //--- Load existing elevations from database ----
    globals->sqm->GetQgtElevation(reg,ELVtoSlots);
    btp.GetRegionElevation(reg);
    Overwrite(reg);
    //--- Create areas ----------------------------
    CreateAreas();
    area.qgt = 0;
    area.qtx = reg.qtx;
    area.qtz = reg.qtz;
    globals->sqm->DeleteElevation(reg.key);
    WriteRegions(1);
    //----Reset all resources ---------------------
    Reset();
    delete [] reg.data;
    reg.data = 0;
    btp.NextQgtKey();
  }
  return;
}
int CChars::PrivateReplaceWithLonger(const char* szFind, const char* szReplace, int iFindLen, int iDifference)
{
	int		iCount;
	int		iIndex;
	int		i;
	int		iTotalDifference;
	int		iOldIndex;

	iCount = Occurrences(szFind);
	if (iCount == 0)
	{
		return 0;
	}

	iTotalDifference = iDifference * iCount;
	mcText.AddNum(iTotalDifference);
	(*mcText.Tail()) = 0;

	iIndex = Length() - (iFindLen + iTotalDifference);
	for (i = iCount-1; i >= 0; i--)
	{
		iOldIndex = iIndex;
		iIndex = FindFromEnd(iIndex, szFind);
		memcpy(mcText.Get(iIndex + iFindLen + (iDifference * (i+1))), mcText.Get(iIndex + iFindLen), iOldIndex - iIndex);
		Overwrite(iIndex + (iDifference * i), szReplace);
		iIndex -= iFindLen;
	}
	return iCount;
}
示例#3
0
int
authenticate_user_password(int fd)
    /* authenticate user */
{
    char *password = NULL;
    char buf[USER_NAME_LEN + 16];
    int len = 0;
    fd_set read_set;            /* needed to use select to check if some data is waiting */
    struct timeval tv;

    snprintf(buf, sizeof(buf), "password for %s :", user_str);
    if ((password = read_string(CONV_ECHO_OFF, buf)) == NULL)
        return ERR;

    len = snprintf(buf, sizeof(buf), "%s", user_str) + 1;
    len += snprintf(buf + len, sizeof(buf) - len, "%s", password) + 1;
    send(fd, buf, len, 0);
    Overwrite(buf);
    Overwrite(password);
    Free_safe(password);

    tv.tv_sec = MAX_WAIT_TIME;
    tv.tv_usec = 0;
    FD_ZERO(&read_set);
    FD_SET(fd, &read_set);
    if (select(fd + 1, &read_set, NULL, NULL, &tv) <= 0) {
        error_e("Couldn't get data from socket during %d seconds.",
                MAX_WAIT_TIME);
        return ERR;
    }
    while (recv(fd, buf, sizeof(buf), 0) < 0 && errno == EINTR)
        if (errno == EINTR && debug_opt)
            fprintf(stderr, "Got EINTR ...");
    if (strncmp(buf, "1", sizeof("1")) != 0)
        return ERR;

    return OK;
}
int CChars::PrivateReplaceWithEqualLength(const char* szFind, const char* szReplace, int iFindLen, int iDifference)
{
	int		iCount;
	int		iIndex;

	iCount = 0;
	iIndex = Find(0, szFind);
	while (iIndex != -1)
	{
		Overwrite(iIndex, szReplace);
		iCount++;
		iIndex = Find(iIndex+iFindLen, szFind);
	}
	return iCount;}
示例#5
0
VOID InsertFileName(UWORD namestart, struct InstData *data)
{
  struct ExAllData *ead1 = &data->FNCBuffer->buffer;
  struct ExAllData *ead2;
  struct FNCData *fncframe;
  struct FNCData *fncframe1 = data->FNCBuffer;
  UWORD entrynum;
  UWORD findnum = data->FileNumber;
  char tmpname[32];

  ENTER();

  do
  {
    entrynum = 0;
    fncframe = data->FNCBuffer;
    ead2 = &fncframe->buffer;
    while(ead2 != NULL)
    {
      //if(CmpStrings(ead1->ed_Name, ead2->ed_Name) > 0)
      if(strcmp((const char *)ead1->ed_Name, (const char *)ead2->ed_Name) > 0)
        entrynum++;

      ead2 = ead2->ed_Next;
      if(ead2 == NULL && fncframe->next != NULL)
      {
        fncframe = fncframe->next;
        ead2 = &fncframe->buffer;
      }
    }

    if(entrynum != findnum)
      ead1 = ead1->ed_Next;
    if(ead1 == NULL && fncframe1->next != NULL)
    {
      fncframe1 = fncframe1->next;
      ead1 = &fncframe1->buffer;
    }
  }
  while(entrynum != findnum);

  snprintf(tmpname, sizeof(tmpname), "%s%s", ead1->ed_Name, ead1->ed_Type == 2 ? "/" : " ");

  Overwrite(tmpname, namestart, data->BufferPos-namestart, data);

  LEAVE();
}
int CChars::PrivateReplaceWithShorter(const char* szFind, const char* szReplace, int iReplaceLen, int iFindLen, int iDifference)
{
	int		iCount;
	int		iIndex;
	int		iTotalDifference;
	int		iOldIndex;
	int		iDestPos;
	int		iSize;
	int		iEnd;

	//Remember that iDifference is NEGATIVE!
	iCount = 0;
	iIndex = Find(0, szFind);
	if (iIndex == -1)
	{
		return 0;
	}

	iOldIndex = 0;
	for (;;)
	{
		iSize = iIndex - iOldIndex + iDifference;

		if (iReplaceLen != 0)
		{
			if (iCount != 0)
			{
				memcpy(mcText.Get(iDestPos), mcText.Get(iOldIndex + iFindLen), iSize - 1);
			}
			Overwrite(iIndex + (iCount * iDifference), szReplace);
		}
		else
		{
			if (iCount != 0)
			{
				memcpy(mcText.Get(iDestPos), mcText.Get(iOldIndex + iFindLen), iSize);
			}
		}
		iCount++;
		iOldIndex = iIndex;
		iDestPos = iOldIndex + iReplaceLen + (iDifference * (iCount-1));
		iIndex = Find(iIndex + iFindLen, szFind);
		if (iIndex == -1)
		{
			iTotalDifference = iDifference * iCount;
			iEnd = Length() + iTotalDifference;
			iSize = Length() - iOldIndex + iDifference;
			if (iEnd != iDestPos)
			{
				if (iCount != 0)
				{
					memcpy(mcText.Get(iDestPos), mcText.Get(iOldIndex + iFindLen), iSize);
				}
			}
			break;
		}
	}
	mcText.AddNum(iTotalDifference);
	(*mcText.Tail()) = 0;
	return iCount;
}
示例#7
0
char *
read_string(int echo, const char *prompt)
    /* read a line of input string, giving prompt when appropriate */
{
    struct termios term_before, term_tmp;
    char line[PAM_MAX_MSG_SIZE];
    int nc, have_term = 0;

    debug("called with echo='%s', prompt='%s'.", echo ? "ON" : "OFF", prompt);

    if (isatty(STDIN_FILENO)) { /* terminal state */

        /* is a terminal so record settings and flush it */
        if (tcgetattr(STDIN_FILENO, &term_before) != 0) {
            debug("error: failed to get terminal settings");
            return NULL;
        }
        memcpy(&term_tmp, &term_before, sizeof(term_tmp));
        if (!echo)
            term_tmp.c_lflag &= ~(ECHO);
        have_term = 1;

    }
    else if (!echo)
        debug("warning: cannot turn echo off");

    /* reading the line */
    while (1) {

        fprintf(stderr, "%s", prompt);
        /* this may, or may not set echo off -- drop pending input */
        if (have_term)
            (void)tcsetattr(STDIN_FILENO, TCSAFLUSH, &term_tmp);

        nc = read(STDIN_FILENO, line, sizeof(line) - 1);
        if (have_term) {
            (void)tcsetattr(STDIN_FILENO, TCSADRAIN, &term_before);
            if (!echo)          /* do we need a newline? */
                fprintf(stderr, "\n");
        }
        if (nc > 0) {           /* we got some user input */
            char *input;

            if (nc > 0 && line[nc - 1] == '\n') {       /* <NUL> terminate */
                line[--nc] = '\0';
            }
            else {
                line[nc] = '\0';
            }
            input = strdup2(line);
            Overwrite(line);

            return input;       /* return malloc()ed string */
        }
        else if (nc == 0) {     /* Ctrl-D */
            debug("user did not want to type anything");
            fprintf(stderr, "\n");
            break;
        }
    }

    if (have_term)
        (void)tcsetattr(STDIN_FILENO, TCSADRAIN, &term_before);

    memset(line, 0, PAM_MAX_MSG_SIZE);  /* clean up */
    return NULL;
}
示例#8
0
int
conv_pam(int num_msg, const struct pam_message **msgm, struct pam_response **response,
	 void *appdata_ptr)
    /* text based conversation for pam. */
{
    int count = 0;
    struct pam_response *reply;

    if (num_msg <= 0 )
	return PAM_CONV_ERR;

    reply = (struct pam_response *) calloc(num_msg, sizeof(struct pam_response));
    if (reply == NULL) {
	debug("no memory for responses");
	return PAM_CONV_ERR;
    }

    for (count = 0; count < num_msg; ++count) {
	char *string = NULL;

	switch ( msgm[count]->msg_style ) {
	case PAM_PROMPT_ECHO_OFF:
	    string = read_string(CONV_ECHO_OFF,msgm[count]->msg);
	    if (string == NULL) {
		goto failed_conversation;
	    }
	    break;
	case PAM_PROMPT_ECHO_ON:
	    string = read_string(CONV_ECHO_ON,msgm[count]->msg);
	    if (string == NULL) {
		goto failed_conversation;
	    }
	    break;
	case PAM_ERROR_MSG:
	    if (fprintf(stderr,"%s\n",msgm[count]->msg) < 0) {
		goto failed_conversation;
	    }
	    break;
	case PAM_TEXT_INFO:
	    if (fprintf(stdout,"%s\n",msgm[count]->msg) < 0) {
		goto failed_conversation;
	    }
	    break;
	default:
	    fprintf(stderr, "erroneous conversation (%d)\n"
		    ,msgm[count]->msg_style);
	    goto failed_conversation;
	}

	if (string) {                         /* must add to reply array */
	    /* add string to list of responses */

	    reply[count].resp_retcode = 0;
	    reply[count].resp = string;
	    string = NULL;
	}
    }

    /* New (0.59+) behavior is to always have a reply - this is
       compatable with the X/Open (March 1997) spec. */
    *response = reply;
    reply = NULL;

    return PAM_SUCCESS;

failed_conversation:

    if (reply) {
	for (count=0; count<num_msg; ++count) {
	    if (reply[count].resp == NULL) {
		continue;
	    }
	    switch (msgm[count]->msg_style) {
	    case PAM_PROMPT_ECHO_ON:
	    case PAM_PROMPT_ECHO_OFF:
		Overwrite(reply[count].resp);
		free(reply[count].resp);
		break;
	    case PAM_ERROR_MSG:
	    case PAM_TEXT_INFO:
		/* should not actually be able to get here... */
		free(reply[count].resp);
	    }                                            
	    reply[count].resp = NULL;
	}
	/* forget reply too */
	free(reply);
	reply = NULL;
    }

    return PAM_CONV_ERR;
}