Exemple #1
0
void take_objects_from_cell(Labyrinth &map, Player &p) {
	int x = p.pos.x;
	int y = p.pos.y;
		
	p.bullets += map.cell[x][y].bullets;
	p.bombs += map.cell[x][y].bombs;
	p.treasures += map.cell[x][y].treasures;
	map.bombs_in_game += map.cell[x][y].bombs;
	map.bullets_in_game += map.cell[x][y].bullets;
	
	if (map.cell[x][y].treasures) {
		p.good_turns++;
		user_message(p.name + " found the treasure!");
	}
	
	if (map.cell[x][y].bullets == 1)
		user_message(p.name + " picked up one bullet");
	else if (map.cell[x][y].bullets > 1)
		user_message(p.name + " picked up " + to_string(map.cell[x][y].bullets) + " bullets");
	
	if (map.cell[x][y].bombs == 1)
		user_message(p.name + " picked up one bomb");
	else if (map.cell[x][y].bombs > 1)
		user_message(p.name + " picked up " + to_string(map.cell[x][y].bombs) + " bombs");
	
	map.cell[x][y].bullets = 0;
	map.cell[x][y].bombs = 0;
	map.cell[x][y].treasures = 0;
}
Exemple #2
0
void quan::report_errors()
{
   while ( ! error_fifo.is_empty()){
      error_info const & info = error_fifo.get();
      user_message("in fn ");
      user_message(get_function_name(info.function_id));
      user_message( " : ");
      user_message(get_error_string(info.error_id));
      user_message("\n");
   }
}
Exemple #3
0
bool turn(Labyrinth &map) {
	take_objects_from_cell(map, map.player[map.current_player]);
	if (DEBUG)
		print_debug(map);
	user_message(map.player[map.current_player].name + ", it's your turn");
	string message = map.player[map.current_player].name + ", enter what you want (go, bomb, shoot, knife, suicide, stay, leave";
	if (SERVER)
		message += ")";
	else
		message += ", save)";
	user_message(message);
	
	if (SERVER)
		server.clear_user_messages(map.current_player);
	string s = read_user_command(map.current_player);
	
	if (s == "leave")
		return leave_game(map, map.player[map.current_player]);
	if (s == "suicide")
		return suicide(map, map.player[map.current_player]);
	if (s == "knife")
		return use_knife(map, map.player[map.current_player]);
	if (s == "bomb")
		return bomb(map, map.player[map.current_player]);
	if (s == "go")
		return go(map, map.player[map.current_player]);
	if (s == "shoot")
		return shoot(map, map.player[map.current_player]);
	if (s == "stay")
		return stay(map.player[map.current_player]);
	if (s == "save" && !SERVER) {
		save_game(map);
		return false;
	}
	if (s == "winthemall") {
		if (is_developer(map.player[map.current_player])) {
			user_message("Okay, master");
			finish_game(map);
			return true;
		}
	}
	
	user_message(map.player[map.current_player].name + ", you entered incorrect command! Try again, if you can!");
	return false;
}
Exemple #4
0
bool use_bomb(Labyrinth &map, Player &p) {
	if (p.bombs == 0) {
		user_message(p.name + " is cheater! He tried to use bomb, but he hasn't got it!");
		return false;
	}
	p.bombs--;
	map.bombs_in_game--;
	return true;
}
Exemple #5
0
int get_direction(Player &p) {
	user_message(p.name + ", enter direction (u, d, l, r)");
	string dir = read_user_command(p.id);
	while (dir != "u" && dir != "d" && dir != "l" && dir != "r") {
		user_message(get_idiot_phraze(p) + " The direction is incorrect. Try again");
		dir = read_user_command(p.id);
		p.fails++;
	}
	int to;
	if (dir == "r")
		to = RIGHT;
	else if (dir == "l")
		to = LEFT;
	else if (dir == "u")
		to = UP;
	else if (dir == "d")
		to = DOWN;
	else
		assert(false);
	return to;
}
Exemple #6
0
void quan::user_error (char const * str) {
   user_message("error : ");
   user_message(str);
   user_message("\n");
}
Exemple #7
0
int main(int argc, char *argv[])
{
    struct user_list_t user_list={0, NULL,NULL};
    fd_set main_fds, read_fds;
    struct sockaddr_in cl_addr;
    char buf[MAXBUF];

    Init();
#ifdef DEBUG
    printf("Init() succesful!\n");
#endif

    FD_ZERO(&main_fds);
    FD_ZERO(&read_fds);

    /* add server to main_fds */
    FD_SET(server_fd, &main_fds);

    /* the highest file descriptor */
    int nfds = server_fd;

    while (1)
    {
#ifdef DEBUG
        printf("In the main loop!\n\n");
#endif

        read_fds = main_fds;
        if (select(nfds+1, &read_fds,  NULL, NULL, NULL)==-1)
        {
            perror("select");
            exit(1);
        }

#ifdef DEBUG
        printf("select() ... OK\n");
#endif

        /* going throug filedescriptors to read data*/
        for (int i=0; i<=nfds; i++)
        {
            /* */
            if (FD_ISSET(i, &read_fds))
            {

#ifdef DEBUG
                printf("connection from ... OK \n");
#endif

                /* NEW CONNECTION */
                if (i==server_fd)
                {
                    size_t addrlen = sizeof(cl_addr);
                    if ((new_fd = accept(server_fd, (struct sockaddr * )&cl_addr, &addrlen))==-1)
                    {
                        perror("accept()");
                    }
                    else
                    {
                        FD_SET(new_fd,&main_fds);
                        if (new_fd>nfds)
                        {
                            nfds=new_fd;
                        }
                        if (send(new_fd, q1, strlen(q1)+1, 0) == -1)
                                printf("send() error %d",new_fd);
                        printf("Client from %s on socket %d\n", inet_ntoa(cl_addr.sin_addr), new_fd);

                        user_add(&user_list, &cl_addr, new_fd);
                        user_print(&user_list, 1);

                    }
                }
                else
                /* Handling old Clients */
                {
                    int nbytes;
                    memset(buf, 0, sizeof buf);
                    if ((nbytes=recv(i, buf, sizeof buf, 0))<=0)
                    {
                        // Error
                        if (nbytes == 0)
                        {
                            printf("Client from socket %d is gone \n",i);
                            if (user_rem(&user_list, i)==-1)
                            {
                                perror("user_rem");
                            }
                        }
                        else
                        {
                            perror("recv()...");
                        }
                        close(i);
                        FD_CLR(i, &main_fds);
                    }
                    else
                    {
                        /* handling data from client */
                        /* who is writing */
                        #ifdef DEBUG
                            printf("data from client from socket %d \n",i);
                        #endif
                        struct user_t *p=user_find_sfd(&user_list, i);
                        /* is user authentificated? */
                        if (user_auth_true(p)==0)
                        {
                            /* Did he send username? */
                            if ((strlen(buf))<MAXNAME)
                            {
                                /* Make it a username */
                                if (buf[strlen(buf)-1]=='\n')
                                {
                                    buf[strlen(buf)-1]='\0';
                                    memset(p->name,0,sizeof(p->name));
                                    strcat (p->name, buf);
                                    p->auth=1;
                                    /* Welcome new user */
                                    memset(buf, 0, MAXBUF*(sizeof(char)));
                                    sprintf(buf, "Welcome %s!\n",p->name);
                                    if (send(i, buf, strlen(buf)+1, 0) == -1)
                                        printf("send() error %d",i);
                                }
                                else
                                {
                                    printf("Authorization of client on socket %d unsucesfull", i);
                                }
                            }
                        }
                        else
                        {
                            /* Client is authorized and he sended message */
                            user_message(&user_list, &main_fds, buf, server_fd, i, nfds);
                        }

                        #ifdef DEBUG
                            user_print(&user_list,1);
                        #endif
                    }
                }
            }
        }
    }
}
Exemple #8
0
/* flag_search_only:
 * 0 - Display & prompt for genres, exact match returns TRUE
 * 1 - Prompt, exact match returns TRUE
 * 2 - No prompt, show only sub string matches
 */
int
search_genre (int flag_search_only, int *dest, char *search_gen)
{
  int i;
  int digit;
  int substring_matches;
  char c = 'z';

  i = 0;

  while (i < strlen(search_gen) && isdigit(search_gen[i]))
    i++;

  if (i >= strlen(search_gen))
  {
    digit = (atoi(search_gen) - 1);

    if (digit >= 0 && digit < genre_count)
    {
      if (flag_search_only == 2)
        user_message(FALSE, "%s\n", genre_table[digit]);

      *dest = digit;
      return TRUE;
    }

    user_message(TRUE, "%s: search_genre: Invalid genre type: %d\n",
      program_name, digit);
    *dest = -1;
    return FALSE;
  }

  substring_matches = 0;

  for (i = 0; i < genre_count; i++)
  {
    if (flag_search_only != 2 &&
      strcasecmp(search_gen, genre_table[i]) == 0)
    {
      *dest = i;

      if (flag_search_only == 0 && flags.verbose)
        printf("Found exact genre match [%s]\n", genre_table[i]);

      return TRUE;
    }

    /* keep track of substring matches for later */

    if (strcase_search(genre_table[i], search_gen))
    {
      substring_matches++;

      if (flag_search_only == 0 && flags.verbose)
        printf("Found matching genre [%s]\n", genre_table[i]);

      if (flag_search_only == 2)
        printf("%3d: %s\n", substring_matches, genre_table[i]);
    }
  }

  if (substring_matches == 0)
  {
    user_message(FALSE, "Genre not found: %s\n", search_gen);
    *dest = -1;
    return FALSE;
  }

  if (flag_search_only == 2)
    return TRUE;

  /* HMMMM....didn't find an exact match, now search for sub strings */

  for (i = 0; i < genre_count && c != 'q'; i++)
  {
    if (strcase_search(genre_table[i], search_gen))
    {
      if (substring_matches == 1)
      {
        *dest = i;
        return TRUE;
      }

      do
      {
        printf("[%s] use this genre? (Y/n/q) ", genre_table[i]);
        c = tolower(getchar());

        if (c == '\n')
        {
          c = 'y';
        }
        else
        {
          while (getchar() != '\n') ;
        }
      } while (c != 'n' && c != 'y' && c != 'q');

      if (c == 'y')
      {
        *dest = i;
        return TRUE;
      }
    }
  }

  if (flag_search_only == 0)
    user_message(FALSE, "No genre selected...tough choice isn't it?\n");

  *dest = -1;
  return FALSE;
}
Exemple #9
0
int
tag_file (char *fn)
{
  FILE *fp;
  long sizelesstag;
  short found_tag;

  if (id3_open_file(&fp, fn, "rb") == FALSE)
    return FALSE;

  memset(ptrtag,0,sizeof(ID3_tag));

  if (id3_seek_header(fp, fn) == FALSE) return FALSE;
  sizelesstag = ftell(fp);

  if (!id3_read_file(ptrtag->tag, (sizeof(ptrtag->tag)-1), fp, fn))
    return FALSE;
/*
fread(&ptrtag->tag, (sizeof(ptrtag->tag)-1), 1, fp);
*/

  if (strcmp(ptrtag->tag, "TAG") != 0)
    found_tag = FALSE;
  else
   {found_tag = TRUE;
   }
    
  if (found_tag == FALSE)
  {
    id3_close_file(fp);

    user_message(FALSE, "*** No ID3 tag found in %s\n", fn);

    if (flags.strip_tag == TRUE)
      return TRUE;

    /* return FALSE so no renaming is performed on files without a tag */
    if (flags.no_tag_prompt == TRUE)
      return FALSE;

    printf("\n===> Entering new tag info for %s:\n", fn);
    if (ask_tag(fn) == FALSE)
      return FALSE;

    if(id3_write_tag(ptrtag,TRUE, fn) == FALSE)
      return FALSE;

    if (flags.tag_only == TRUE)
      return TRUE;

    if (id3_open_file(&fp, fn, "rb") == FALSE)
      return FALSE;

    if (id3_seek_header(fp, fn) == FALSE) return FALSE;

    if (!id3_read_file(ptrtag->tag, (sizeof(ptrtag->tag)-1), fp, fn))
      return FALSE;
  }  /*** Found a tag ****/
  else if (flags.force_tag == TRUE)    /* Always ask for a tag enabled? */
  {
    if (id3_read_tag(ptrtag,fp, fn) == FALSE)
      return FALSE;

    id3_close_file(fp);
    printf("\n===> Changing old tag info for %s:\n", fn);

    if (ask_tag(fn) == FALSE)
      return FALSE;

    if (id3_write_tag(ptrtag,FALSE, fn) == FALSE)
      return FALSE;

    if (flags.tag_only == TRUE)
      return TRUE;

    if (id3_open_file(&fp, fn, "rb") == FALSE)
      return FALSE;

    if (id3_seek_header(fp, fn) == FALSE) return FALSE;

    if (!id3_read_file(ptrtag->tag, (sizeof(ptrtag->tag)-1), fp, fn))
      return FALSE;
  }
  else if (flags.tag_only == TRUE)
  {
    id3_close_file(fp);
    user_message(FALSE, "===> Already has a tag: %s\n", fn);
    return TRUE;
  }
  else if (flags.strip_tag == TRUE)
  {
    id3_close_file(fp);
    if (id3_strip_tag(sizelesstag, fn) == FALSE)
      return FALSE;
    user_message(FALSE, "===> Removed ID3 tag from %s\n", fn);
    return TRUE;
  }

  if (id3_read_tag(ptrtag,fp, fn) == FALSE)
    return FALSE;

  resize_tag_field(ptrtag->songname);
  resize_tag_field(ptrtag->artist);
  resize_tag_field(ptrtag->album);
  resize_tag_field(ptrtag->year);
  resize_tag_field(ptrtag->u.v10.comment); // v1.1 tag handled
  id3_close_file(fp);
  return TRUE;
}
Exemple #10
0
int
ask_tag (char *fn)
{
  ID3_tag fntag; 
  char track[20],genre[20],*t,*w,*p,*f,*pfntmp,*ptagtmp;
  char tagtmp[256],fntmp[256];
  int length;

  /* If tag from file name, we grab the fields */
  memset(&fntag,0,sizeof(ID3_tag));
  if (flags.tag_ffn == TRUE)
  {
    strcpy(tagtmp,tag_template);p=ptagtmp=tagtmp;
    strcpy(fntmp,fn);pfntmp=fntmp;
    w=NULL;

    while(p!=NULL)
    {
      p=strchr(ptagtmp,IDENT_CHAR);    

      /* if it's the last char */
      if(p!=NULL)
      {
        *p=0;
        if(*(p+1)==0)break;
      }

      f=strstr(pfntmp,ptagtmp);
      if(f==NULL)break;

      if(w!=NULL)
      {
        switch(*w)
        {
          case 'a' : /* artist */
            length=MIN(f-pfntmp,sizeof(fntag.artist));
            strncpy(fntag.artist,pfntmp,length);
            break;
          case 'c' : /* comment */
            if(fntag.version==0)
             {length=MIN(f-pfntmp,sizeof(fntag.u.v10.comment));
              strncpy(fntag.u.v10.comment,pfntmp,length);
             }
            else
             {length=MIN(f-pfntmp,sizeof(fntag.u.v11.comment));
              strncpy(fntag.u.v11.comment,pfntmp,length);
             }
            break;
          case 's' : /* song */
            length=MIN(f-pfntmp,sizeof(fntag.songname));
            strncpy(fntag.songname,pfntmp,length);
            break;
          case 't' : /* title */
            length=MIN(f-pfntmp,sizeof(fntag.album));
            strncpy(fntag.album,pfntmp,length);
            break;
          case 'y' : /* year */
            length=MIN(f-pfntmp,sizeof(fntag.year));
            strncpy(fntag.year,pfntmp,length);
            break;
          case 'd' : /* dummy */
            break;
          case 'g' : /* Genre */
            memset(genre,0,sizeof(genre));
            length=MIN(f-pfntmp,sizeof(genre)-1);
            strncpy(genre,pfntmp,length);
            search_genre (2, &fntag.genre, genre);
            break;
          case 'n' : /* Track */
            memset(track,0,sizeof(track));
            length=MIN(f-pfntmp,sizeof(track)-1);
            strncpy(track,pfntmp,length);
            fntag.version=1;
            fntag.u.v11.track=0;
            t=track;
            while(*t!=0)
             {fntag.u.v11.track*=10;
              fntag.u.v11.track+=*t-'0';
              t++;
             }
            break;
        }
        w=NULL;
      }

      f+=strlen(ptagtmp);

      if(p!=NULL)
      {
        w=p+1;
        p+=2;

        ptagtmp=p;
        pfntmp=f;
      }
    }
  }  
   
  if (strcmp(fntag.songname,"")==0)
    get_tag_string(sizeof(ptrtag->songname), def_song, ptrtag->songname, "Song Name");
  else
    get_tag_string(sizeof(ptrtag->songname), fntag.songname, ptrtag->songname, "Song Name");
 
  if (strcmp(fntag.artist,"")==0)
    get_tag_string(sizeof(ptrtag->artist), def_artist, ptrtag->artist, "Artist Name");
  else
    get_tag_string(sizeof(ptrtag->artist), fntag.artist, ptrtag->artist, "Artist Name");

  if (flags.no_album == FALSE)
  {
    if (strcmp(fntag.album,"")==0)
      get_tag_string(sizeof(ptrtag->album), def_album, ptrtag->album, "Album Name");
    else
      get_tag_string(sizeof(ptrtag->album), fntag.album, ptrtag->album, "Album Name");
  }

  if (flags.no_year == FALSE)
  {
    if (strcmp(fntag.year,"")==0)
      get_tag_string(sizeof(ptrtag->year), def_year, ptrtag->year, "Year");
    else
      get_tag_string(sizeof(ptrtag->year), fntag.year, ptrtag->year, "Year");
  }
 
  if (flags.no_track == FALSE)
  {
    if (fntag.version==1&&fntag.u.v11.track!=0)
      get_tag_track(&ptrtag->u.v11.track, fntag.u.v11.track,&ptrtag->version);
    else
      get_tag_track(&ptrtag->u.v11.track, def_track,&ptrtag->version);
  }

  if (flags.no_comment == FALSE)
  {
   if (ptrtag->version==0)
    {
     if (strcmp(fntag.u.v10.comment,"")==0)
       get_tag_string(sizeof(ptrtag->u.v10.comment), def_comment, ptrtag->u.v10.comment, "Comment");
     else
       get_tag_string(sizeof(ptrtag->u.v10.comment), fntag.u.v10.comment, ptrtag->u.v10.comment, "Comment");
    }
   else
    {
     if (strcmp(fntag.u.v11.comment,"")==0)
       get_tag_string(sizeof(ptrtag->u.v11.comment), def_comment, ptrtag->u.v11.comment, "Comment");
     else
       get_tag_string(sizeof(ptrtag->u.v11.comment), fntag.u.v11.comment, ptrtag->u.v11.comment, "Comment");
    }
  }

  if (flags.no_genre == FALSE)
  {
    if (fntag.genre==0)
      get_tag_genre(&ptrtag->genre, def_genre);
    else
      get_tag_genre(&ptrtag->genre, fntag.genre);
  }

  if (strlen(ptrtag->songname) < 1 ) /*|| strlen(ptrtag->artist) < 1)*/
/*      || ptrtag->genre < 0 || ptrtag->genre >= genre_count) */
  {
    user_message(FALSE, "Not enough info entered to tag %s\n", fn);
    return FALSE;
  }

  return TRUE;
}
Exemple #11
0
HTStream *HTSaveToFile( HTPresentation *pres, HTParentAnchor *anchor, HTStream *sink )
{
  int eax;
  HTStream *ret_obj;
  char fnam[256];
  char *suffix;
  char *cp;
  int c = 0;
  BOOLEAN IsBinary = 1;
  ret_obj = calloc( 1, sizeof( HTStream ) );
  if ( ret_obj == 0 )
    outofmem( "./HTFWriter.c", "HTSaveToFile" );
  ret_obj->isa->name[0] = HTFWriter.name;
  *(int*)&ret_obj->remove_command = 0;
  *(int*)&ret_obj->end_command = 0;
  ret_obj->input_format = pres->rep->next;
  ret_obj->output_format = pres->rep_out;
  ret_obj->anchor = anchor;
  ret_obj->sink = sink;
  if ( dump_output_immediately )
  {
    ret_obj->fp = stdout;
    if ( HTOutputFormat != HTAtom_for( "www/download" ) )
      return ret_obj;
  }
  else
  {
    LYCancelDownload = 0;
    if ( HTOutputFormat != HTAtom_for( "www/download" ) )
    {
      if ( traversal || ( no_download && !override_no_download && no_disk_save ) )
      {
        if ( traversal == 0 )
        {
          HTAlert( gettext( "This file cannot be displayed on this terminal." ) );
        }
        LYCancelDownload = 1;
        if ( traversal )
          LYCancelledFetch = 1;
        if ( ret_obj )
        {
          free( ret_obj );
          ret_obj = 0;
        }
        return 0;
      }
      else
      {
        cp = strchr( (char*)pres->rep_out, ';' );
        if ( cp && strstr( &cp[1], "charset" ) )
        {
          mustshow = 1;
          user_message( gettext( "%s  D)ownload, or C)ancel" ), (char*)pres->rep_out );
          while ( 1 )
          {
            switch ( c )
            {
            case -1:
              if ( keymap[0] != 47 )
              {
                c = LYgetch_single( );
              }
              break;
            default:
              if ( c & 34816 )
              {
                if ( ( c & 255 ) != 47 )
                  continue;
              }
              else
              if ( keymap[ ( c & 2047 ) + 1 ] != 47 )
                continue;
              break;
            }
            switch ( c )
            {
            case -1:
              if ( keymap[0] == 47 )
              {
                mustshow = 1;
                statusline( gettext( "Cancelling file." ) );
                LYCancelDownload = 1;
                if ( ret_obj )
                {
                  free( ret_obj );
                  ret_obj = 0;
                }
                return 0;
              }
              break;
            default:
              if ( c & 34816 )
              {
                if ( ( c & 255 ) == 47 )
                  continue;
              }
              else
              if ( keymap[ ( c & 2047 ) + 1 ] == 47 )
                continue;
              break;
            }
          }
        }
        else
        if ( pres->rep_out->next )
        {
          mustshow = 1;
          user_message( gettext( "%s  D)ownload, or C)ancel" ), (char*)pres->rep_out );
        }
        else
        {
          mustshow = 1;
          statusline( gettext( "This file cannot be displayed on this terminal:  D)ownload, or C)ancel" ) );
        }
      }
    }
    if ( LYCachedTemp( fnam, &anchor->FileCache ) & 255 )
    {
      ret_obj->fp = LYOpenTempRewrite( fnam, ".bin", "wb" );
    }
    else
    {
      if ( strcasecomp( (char*)pres->rep_out, "text/html" ) == 0 )
        suffix = ".html";
      else
      {
        if ( strncasecomp( (char*)pres->rep_out, "text/", 5 ) == 0 )
          suffix = ".txt";
        else
        {
          if ( strncasecomp( (char*)pres->rep_out, "application/", 12 ) == 0 )
            suffix = ".bin";
          else
          {
            suffix = HTFileSuffix( &pres->rep->next, &anchor->content_encoding );
            if ( suffix == 0 || suffix[0] != '.' )
              suffix = ".html";
          }
        }
      }
      ret_obj->fp = LYOpenTemp( fnam, suffix, "wb" );
    }
    if ( ret_obj->fp == 0 )
    {
      HTAlert( gettext( "Can't open output file!  Cancelling!" ) );
      if ( ret_obj )
      {
        free( ret_obj );
        ret_obj = 0;
      }
      return 0;
    }
    else
    {
      if ( strncasecomp( (char*)pres->rep_out, "text/", 5 ) == 0 || strcasecomp( (char*)pres->rep_out, "application/postscript" ) == 0 || strcasecomp( (char*)pres->rep_out, "application/x-RUNOFF-MANUAL" ) == 0 )
        IsBinary = 0;
      HTInfoMsg2( gettext( "Content-type: %s" ), (char*)pres->rep_out );
      HTSACopy( &WWW_Download_File, fnam );
      *(int*)&ret_obj->remove_command = 0;
      HTAddParam( &ret_obj->remove_command, "%s", 1, fnam );
      HTEndParam( &ret_obj->remove_command, "%s", 1 );
      HTSACopy( &ret_obj->end_command, "SaveToFile" );
      mustshow = 1;
      statusline( gettext( "Retrieving file.  - PLEASE WAIT -" ) );
      HTSACopy( &anchor->FileCache, fnam );
    }
  }
  if ( LYPrependBaseToSource && strncasecomp( (char*)pres->rep_out, "text/html", 9 ) == 0 && anchor->content_encoding == 0 )
  {
    char *temp = 0;
    if ( anchor->content_base && anchor->content_base[0] )
      HTSACopy( &temp, &anchor->content_base );
    else
    if ( anchor->content_location && anchor->content_location[0] )
      HTSACopy( &temp, &anchor->content_location );
    if ( temp )
    {
      LYRemoveBlanks( temp );
      if ( !is_url( temp ) && temp )
      {
        free( temp );
        temp = 0;
      }
    }
    fprintf( &ret_obj->fp, "&lt;!-- X-URL: %s --&gt;\n", &anchor->address );
    if ( anchor->date && anchor->date[0] )
    {
      fprintf( &ret_obj->fp, "&lt;!-- Date: %s --&gt;\n", &anchor->date );
      if ( anchor->last_modified && anchor->last_modified[0] && strcmp( &anchor->last_modified, &anchor->date ) && strcmp( &anchor->last_modified, "Thu, 01 Jan 1970 00:00:01 GMT" ) )
        fprintf( &ret_obj->fp, "&lt;!-- Last-Modified: %s --&gt;\n", &anchor->last_modified );
    }
    fprintf( &ret_obj->fp, "&lt;BASE HREF=\"%s\"&gt;\n\n", temp ? temp : &anchor->address );
    if ( temp )
    {
      free( temp );
    }
  }
  if ( LYPrependCharsetToSource && strncasecomp( (char*)pres->rep_out, "text/html", 9 ) == 0 && anchor->content_encoding == 0 )
  {
    char *temp = 0;
    if ( anchor->charset && anchor->charset[0] )
    {
      HTSACopy( &temp, &anchor->charset );
      LYRemoveBlanks( temp );
      fprintf( &ret_obj->fp, "&lt;META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=%s\"&gt;\n\n", temp );
    }
    if ( temp )
    {
      free( temp );
    }
  }
  return ret_obj;
}
Exemple #12
0
      static bool text_to_type(quan::dynarray<char> const & text_in, void* value_out)
      {
         if ( !value_out){
#if defined QUAN_FLASH_DEBUG
    std::cout << "(1) unexpected nullptr\n";
#endif
            quan::error(fn_any, quan::detail::unexpected_nullptr);
            return false;
         }
         if ( text_in.get() == nullptr){
#if defined QUAN_FLASH_DEBUG
    std::cout << "(2) unexpected nullptr\n";
#endif
            quan::error(fn_any, quan::detail::unexpected_nullptr);
            return false;
         }
         size_t length = text_in.get_num_elements();
         if ((text_in.get_num_elements() < 7)  ) {
#if defined QUAN_FLASH_DEBUG
    std::cout << text_in.get_num_elements() << " : (3) too few elements\n";
#endif
            user_error(get_input_template());
            return false;
         }
         if ( *(text_in.get() + (length-1)) != '\0'){
#if defined QUAN_FLASH_DEBUG
    std::cout << "(4) unterminated string constant\n";
#endif
            quan::error(fn_any,quan::detail::unterminated_string_constant);
            return false;
         }

      // copy text_in 
         quan::dynarray<char> src {text_in.get_num_elements(),symbol_table::on_malloc_failed};
         if (! src.good()) {
            // should have reported
#if defined QUAN_FLASH_DEBUG
    std::cout << "(5) bad dynarray\n";
#endif
            return false;
         }
         memcpy (src.get(),text_in.get(),text_in.get_num_elements());

         const char* ptr = src.get();
         while ( isspace(*ptr) ){
            ++ptr;
         }
         if ( *ptr != '['){
#if defined QUAN_FLASH_DEBUG
    std::cout << "(6) expected [\n";
#endif
            user_error(get_input_template());
            return false;
         }
         const char delims[] = {',',',',']'};
         quan::three_d::vect<T> temp;
         for (size_t i = 0; i < 3; ++i) {
            if (*(++ptr) == '\0'){
#if defined QUAN_FLASH_DEBUG
    std::cout << "(7) unexpected end of input\n";
#endif
               user_error(get_input_template());
               return false;
            }
            quan::detail::converter<T, char*> conv;
            temp[i] = conv(ptr);
            if (conv.get_errno() == 0) {
               ptr += conv.get_parse_length();
               while ( isspace(*ptr)){
                  ++ptr;
               }
               if ( *ptr == delims[i] ){
                   continue;
               }else{
                  user_message("parse failed");
                  if (*ptr != '\0'){
                     user_message(" at \"");
                     user_error(ptr);
                     user_message("\"\n");
                  }else{
                     user_message("\n");
                  }
                  user_error(get_input_template());
                  return false;
               }
            }else{
               user_error("failed to parse values");
               return false;
            }
         }
         quan::three_d::vect<T>* typed_value_out = (quan::three_d::vect<T> *)value_out;
         *typed_value_out = temp;
         return true;
      }