Exemplo n.º 1
0
static void
cb_grabber(void *data)
{
   if (opt.grabber)
      free(opt.grabber);
   opt.grabber = _Strdup((char *)data);
   return;
   data = NULL;
}
Exemplo n.º 2
0
static void
apply_config(void)
{
   /* Apply options from settings dialog */
   if (opt.new_url_command)
      free(opt.new_url_command);
   opt.new_url_command = _Strdup(Epplet_textbox_contents(txt_new_url_command));
   if (opt.url_save_file)
      free(opt.url_save_file);
   opt.url_save_file = _Strdup(Epplet_textbox_contents(txt_url_save_file));
   if (opt.url_file)
      free(opt.url_file);
   opt.url_file = _Strdup(Epplet_textbox_contents(txt_url_file));
   if (opt.www_command)
      free(opt.www_command);
   opt.www_command = _Strdup(Epplet_textbox_contents(txt_www_command));
   if (opt.ftp_command)
      free(opt.ftp_command);
   opt.ftp_command = _Strdup(Epplet_textbox_contents(txt_ftp_command));
   if (opt.get_command)
      free(opt.get_command);
   opt.get_command = _Strdup(Epplet_textbox_contents(txt_get_command));
   if (opt.check_url_file)
      Epplet_timer(check_url_file, NULL, 1, "URLCHECK_TIMER");

   return;
}
Exemplo n.º 3
0
/* Stick a string in the scrolly display */
static void
display_string(char *string)
{
   D(("In display_string: String -->%s<--\n", string));

   if (dtext.str)
      free(dtext.str);
   dtext.str = _Strdup(string);
   dtext.len = strlen(string);
   dtext.pos = 0;
   Epplet_timer(scroll_string, NULL, 0.1, "SCROLL_TIMER");
   Epplet_timer(reset_string, NULL, 20, "RESET_TIMER");
}
Exemplo n.º 4
0
/* Stick a new url in the list. Don't rebuild the popup yet though. */
static void
add_url_to_url_list(char *url)
{
   if (num_urls == 10)
      num_urls = 0;

   D(("In add_url_to_url_list: adding = -->%s<--\n", url));

   if (urllist[num_urls])
     {
	free(urllist[num_urls]);
	urllist[num_urls] = NULL;
     }

   urllist[num_urls] = _Strdup(url);

   num_urls++;
}
Exemplo n.º 5
0
static void
load_config(void)
{
   /* This reloads our config. */
   char               *home = getenv("HOME");
   char                buf[1024];

   opt.save_urls = atoi(Epplet_query_config_def("SAVE_URLS", "1"));
   opt.check_url_file = atoi(Epplet_query_config_def("CHECK_URL_FILE", "1"));
   opt.always_show_file_urls =
      atoi(Epplet_query_config_def("ALWAYS_SHOW_FILE_URLS", "0"));
   opt.do_new_url_command =
      atoi(Epplet_query_config_def("RUN_COMMAND_ON_NEW_URL", "1"));
   /* If reloading, free the old string before assigning a new one */
   if (opt.www_command)
      free(opt.www_command);
   opt.www_command =
      _Strdup(Epplet_query_config_def
	      ("WWW_COMMAND", "gnome-moz-remote --newwin \"%s\" &"));
   if (opt.ftp_command)
      free(opt.ftp_command);
   opt.ftp_command =
      _Strdup(Epplet_query_config_def
	      ("FTP_COMMAND", "gnome-moz-remote --newwin \"%s\" &"));
   if (opt.get_command)
      free(opt.get_command);
   opt.get_command =
      _Strdup(Epplet_query_config_def
	      ("GET_COMMAND", "Eterm -O -e wget \"%s\" &"));
   if (opt.url_save_file)
      free(opt.url_save_file);
   Esnprintf(buf, sizeof(buf), "%s/.Urls", home);
   opt.url_save_file = _Strdup(Epplet_query_config_def("URL_SAVE_FILE", buf));
   if (opt.url_file)
      free(opt.url_file);
   Esnprintf(buf, sizeof(buf), "%s/.te/.urls", home);
   opt.url_file = _Strdup(Epplet_query_config_def("URL_CHECK_FILE", buf));
   if (opt.new_url_command)
      free(opt.new_url_command);
   Esnprintf(buf, sizeof(buf), "esdplay %s/wooeep.wav &", Epplet_data_dir());
   opt.new_url_command =
      _Strdup(Epplet_query_config_def("NEW_URL_COMMAND", buf));
}
Exemplo n.º 6
0
static void
create_epplet_layout(void)
{
   Epplet_gadget_show(btn_close =
		      Epplet_create_button(NULL, NULL, 2, 2, 0, 0, "CLOSE", 0,
					   NULL, cb_close, NULL));
   Epplet_gadget_show(btn_help =
		      Epplet_create_button(NULL, NULL, 18, 2, 0, 0, "HELP", 0,
					   NULL, cb_help, NULL));
   Epplet_gadget_show(btn_shoot =
		      Epplet_create_button(NULL, "E-ScreenShoot_shoot.png",
					   23, 31, 22, 13, 0, 0, NULL,
					   cb_shoot, NULL));
   Epplet_gadget_show(tog_win =
		      Epplet_create_togglebutton(NULL, "E-ScreenShoot_win.png",
						 11, 17, 10, 13, &opt.win,
						 NULL, NULL));
   Epplet_gadget_show(sldr_qual =
		      Epplet_create_vslider(2, 17, 28, 0, 100, 1, 25,
					    &invquality, cb_quality, NULL));
   p = Epplet_create_popup();
   Epplet_add_popup_entry(p, "Don't Cloak", NULL, cb_dont_cloak, NULL);
   Epplet_add_popup_entry(p, "Blank Epplet", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[0])));
   Epplet_add_popup_entry(p, "RasterFire", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[1])));
   Epplet_add_popup_entry(p, "Radar", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[2])));
   Epplet_add_popup_entry(p, "AA Radar", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[3])));
   Epplet_add_popup_entry(p, "AA Triangle", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[4])));
   Epplet_add_popup_entry(p, "AA Star", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[5])));
   Epplet_add_popup_entry(p, "Starfield", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[6])));
   Epplet_add_popup_entry(p, "AA Starfield", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[7])));
   Epplet_add_popup_entry(p, "Mesh", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[8])));
   Epplet_add_popup_entry(p, "Funky Mesh", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[15])));
/* 
 *   Epplet_add_popup_entry (p, "Bendy Mesh", NULL, cb_cloak_anim,
 * 			  (void *) (&(cloak_anims[16])));
 */
   Epplet_add_popup_entry(p, "Scanner", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[9])));
   Epplet_add_popup_entry(p, "ColorShift", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[10])));
   Epplet_add_popup_entry(p, "Bouncy Ball", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[11])));
   Epplet_add_popup_entry(p, "Atoms", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[12])));
   Epplet_add_popup_entry(p, "Banner", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[13])));
   Epplet_add_popup_entry(p, "SineWave", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[14])));
   Epplet_add_popup_entry(p, "Random", NULL, cb_cloak_anim,
			  (void *)(&(cloak_anims[25])));

   col_p = Epplet_create_popup();
   Epplet_add_popup_entry(col_p, "Flame Colors", NULL, NULL, NULL);
   Epplet_add_popup_entry(col_p, "Funky", NULL, cb_color,
			  (void *)(&(colors[0 * 9])));
   Epplet_add_popup_entry(col_p, "Turquoise", NULL, cb_color,
			  (void *)(&(colors[1 * 9])));
   Epplet_add_popup_entry(col_p, "Fire", NULL, cb_color,
			  (void *)(&(colors[2 * 9])));
   Epplet_add_popup_entry(col_p, "Copper", NULL, cb_color,
			  (void *)(&(colors[3 * 9])));
   Epplet_add_popup_entry(col_p, "Violet", NULL, cb_color,
			  (void *)(&(colors[4 * 9])));
   Epplet_add_popup_entry(col_p, "Night", NULL, cb_color,
			  (void *)(&(colors[5 * 9])));
   Epplet_add_popup_entry(col_p, "Sunrise", NULL, cb_color,
			  (void *)(&(colors[6 * 9])));
   Epplet_add_popup_entry(col_p, "Sunset", NULL, cb_color,
			  (void *)(&(colors[7 * 9])));

   ctimer_p = Epplet_create_popup();
   Epplet_add_popup_entry(ctimer_p, "Cloak Delay", NULL, NULL, NULL);
   Epplet_add_popup_entry(ctimer_p, "1 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[0])));
   Epplet_add_popup_entry(ctimer_p, "2 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[1])));
   Epplet_add_popup_entry(ctimer_p, "3 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[2])));
   Epplet_add_popup_entry(ctimer_p, "4 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[3])));
   Epplet_add_popup_entry(ctimer_p, "5 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[4])));
   Epplet_add_popup_entry(ctimer_p, "10 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[5])));
   Epplet_add_popup_entry(ctimer_p, "15 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[6])));
   Epplet_add_popup_entry(ctimer_p, "20 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[7])));
   Epplet_add_popup_entry(ctimer_p, "30 Sec", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[8])));
   Epplet_add_popup_entry(ctimer_p, "1 min", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[9])));
   Epplet_add_popup_entry(ctimer_p, "2 mins", NULL, cb_cloak_delay,
			  (void *)(&(cloak_delays[10])));

   stimer_p = Epplet_create_popup();
   Epplet_add_popup_entry(stimer_p, "Shot Delay", NULL, NULL, NULL);
   Epplet_add_popup_entry(stimer_p, "No Delay", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[0])));
   Epplet_add_popup_entry(stimer_p, "1 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[1])));
   Epplet_add_popup_entry(stimer_p, "2 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[2])));
   Epplet_add_popup_entry(stimer_p, "3 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[3])));
   Epplet_add_popup_entry(stimer_p, "4 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[4])));
   Epplet_add_popup_entry(stimer_p, "5 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[5])));
   Epplet_add_popup_entry(stimer_p, "10 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[6])));
   Epplet_add_popup_entry(stimer_p, "15 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[7])));
   Epplet_add_popup_entry(stimer_p, "20 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[8])));
   Epplet_add_popup_entry(stimer_p, "30 Sec", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[9])));
   Epplet_add_popup_entry(stimer_p, "1 min", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[10])));
   Epplet_add_popup_entry(stimer_p, "2 mins", NULL, cb_shot_delay,
			  (void *)(&(shot_delays[11])));

   grabber_p = Epplet_create_popup();
   Epplet_add_popup_entry(grabber_p, "import", NULL, cb_grabber,
			  _Strdup("import"));
   Epplet_add_popup_entry(grabber_p, "scrot", NULL, cb_grabber,
			  _Strdup("scrot"));

   Epplet_gadget_show(btn_conf =
		      Epplet_create_button(NULL, NULL, 34, 2, 12, 12,
					   "CONFIGURE", 0, NULL, cb_config,
					   NULL));

   Epplet_gadget_show(btn_col =
		      Epplet_create_popupbutton(NULL, "E-ScreenShoot_col.png",
						11, 31, 10, 13, NULL, col_p));
   Epplet_gadget_show(btn_ctimer =
		      Epplet_create_popupbutton(NULL,
						"E-ScreenShoot_minitime.png",
						23, 17, 10, 13, NULL,
						ctimer_p));

   Epplet_gadget_show(btn_stimer =
		      Epplet_create_popupbutton(NULL,
						"E-ScreenShoot_minitime2.png",
						35, 17, 10, 13, NULL,
						stimer_p));

   da = Epplet_create_drawingarea(2, 2, 44, 44);
   win = Epplet_get_drawingarea_window(da);
   buf = Epplet_make_rgb_buf(40, 40);

   cloaked = 0;
   set_flame_col(0);
   if (opt.do_cloak)
      Epplet_timer(cloak_epplet, NULL, opt.cloak_delay, "CLOAK_TIMER");

   Epplet_register_mouse_enter_handler(cb_in, (void *)win);
   Epplet_register_mouse_leave_handler(cb_out, NULL);
}
Exemplo n.º 7
0
/* Amongst all the fluff, this is the bit that does the actual work. */
static void
do_shot(void *data)
{
   char               *sys;
   char                qual_buf[5];
   char               *filename_buf;
   char                frame_buf[10];
   char                beep_buf[20];
   char                import_buf[50];
   char               *script_buf = NULL;
   char               *view_buf = NULL;
   char               *filename = NULL;

   Esnprintf(qual_buf, sizeof(qual_buf), "%d", opt.quality);

   filename =
      _Strjoin(NULL, opt.dir, opt.file_prefix, opt.file_stamp, ".",
	       opt.file_type, NULL);

   filename_buf = _Strjoin(NULL, "SCRTEMP=\"", filename, "\"", NULL);

   if (!strcmp(opt.grabber, "import"))
     {
	if ((opt.frame) && (opt.win))
	   Esnprintf(frame_buf, sizeof(frame_buf), "-frame");
	else
	   frame_buf[0] = '\0';

	if (opt.beep)
	   beep_buf[0] = '\0';
	else
	   Esnprintf(beep_buf, sizeof(beep_buf), "-silent");

	if (opt.win)
	   Esnprintf(import_buf, sizeof(import_buf), "import");
	else
	   Esnprintf(import_buf, sizeof(import_buf), "import -window root");

	if (opt.run_script)
	   script_buf = _Strjoin(" ", "&&", opt.script, "$SCRTEMP", NULL);
	else
	   script_buf = _Strdup(" ");

	if (opt.view_shot)
	   view_buf = _Strjoin(" ", "&&", opt.viewer, "$SCRTEMP", NULL);
	else
	   view_buf = _Strdup(" ");

	sys =
	   _Strjoin(" ", opt.do_ftp ? "" : "(", filename_buf, "&&", import_buf,
		    beep_buf, frame_buf, "-quality", qual_buf, "$SCRTEMP",
		    script_buf, view_buf, opt.do_ftp ? "" : ")&", NULL);
     }
   else if (!strcmp(opt.grabber, "scrot"))
     {
	char                delay_buf[20];

	if (opt.delay > 0)
	   Esnprintf(delay_buf, sizeof(delay_buf), "-d %.0f", opt.delay);
	else
	   delay_buf[0] = '\0';

	if ((opt.frame) && (opt.win))
	   Esnprintf(frame_buf, sizeof(frame_buf), "-b");
	else
	   frame_buf[0] = '\0';

	if (opt.win)
	   Esnprintf(import_buf, sizeof(import_buf), "scrot -s");
	else
	   Esnprintf(import_buf, sizeof(import_buf), "scrot");

	if (opt.run_script)
	   script_buf = _Strjoin(" ", "&&", opt.script, "$SCRTEMP", NULL);
	else
	   script_buf = _Strdup(" ");

	if (opt.view_shot)
	   view_buf = _Strjoin(" ", "&&", opt.viewer, "$SCRTEMP", NULL);
	else
	   view_buf = _Strdup(" ");

	sys =
	   _Strjoin(" ", opt.do_ftp ? "" : "(", filename_buf, "&&", import_buf,
		    delay_buf, frame_buf, "--quality", qual_buf, "$SCRTEMP",
		    script_buf, view_buf, opt.do_ftp ? "" : ")&", NULL);
     }
   else
     {
	printf("don't know how to handle grabber %s\n", opt.grabber);
	return;
     }

   system(sys);

   if (opt.do_ftp)
     {
	if (!ftp_connected)
	   ftp_connect(opt.ftp_host, opt.ftp_user, opt.ftp_pass, opt.ftp_dir);
	ftp_upload(filename, opt.ftp_file, opt.ftp_temp);
     }

   free(sys);
   free(script_buf);
   free(view_buf);
   free(filename_buf);
   free(filename);
   return;
   data = NULL;
}
Exemplo n.º 8
0
static void
apply_config(void)
{
   if (opt.file_prefix)
      free(opt.file_prefix);
   opt.file_prefix = _Strdup(Epplet_textbox_contents(txt_file_prefix));
   if (opt.file_stamp)
      free(opt.file_stamp);
   opt.file_stamp = _Strdup(Epplet_textbox_contents(txt_file_stamp));
   if (opt.file_type)
      free(opt.file_type);
   opt.file_type = _Strdup(Epplet_textbox_contents(txt_file_type));
   if (opt.viewer)
      free(opt.viewer);
   opt.viewer = _Strdup(Epplet_textbox_contents(txt_viewer));
   if (opt.script)
      free(opt.script);
   opt.script = _Strdup(Epplet_textbox_contents(txt_script));
   if (opt.dir)
      free(opt.dir);
   opt.dir = _Strdup(Epplet_textbox_contents(txt_dir));
   if (opt.ftp_user)
      free(opt.ftp_user);
   opt.ftp_user = _Strdup(Epplet_textbox_contents(txt_ftp_user));
   if (opt.ftp_pass)
      free(opt.ftp_pass);
   opt.ftp_pass = _Strdup(Epplet_textbox_contents(txt_ftp_pass));
   if (opt.ftp_host)
      free(opt.ftp_host);
   opt.ftp_host = _Strdup(Epplet_textbox_contents(txt_ftp_host));
   if (opt.ftp_dir)
      free(opt.ftp_dir);
   opt.ftp_dir = _Strdup(Epplet_textbox_contents(txt_ftp_dir));
   if (opt.ftp_file)
      free(opt.ftp_file);
   opt.ftp_file = _Strdup(Epplet_textbox_contents(txt_ftp_file));
   if (opt.ftp_temp)
      free(opt.ftp_temp);
   opt.ftp_temp = _Strdup(Epplet_textbox_contents(txt_ftp_temp));

   return;
}
Exemplo n.º 9
0
static void
load_config(void)
{
   opt.quality = atoi(Epplet_query_config_def("QUALITY", "75"));
   invquality = (100 - opt.quality);
   opt.win = atoi(Epplet_query_config_def("WIN_AREA", "0"));
   opt.do_ftp = atoi(Epplet_query_config_def("DO_FTP", "0"));
   opt.ftp_passive = atoi(Epplet_query_config_def("FTP_PASSIVE", "1"));
   opt.run_script = atoi(Epplet_query_config_def("RUN_SCRIPT", "0"));
   opt.view_shot = atoi(Epplet_query_config_def("VIEW_SHOT", "1"));
   opt.frame = atoi(Epplet_query_config_def("WM_FRAME", "1"));
   opt.do_cloak = atoi(Epplet_query_config_def("DO_CLOAK", "1"));
   opt.beep = atoi(Epplet_query_config_def("BEEP", "1"));
   opt.cloak_anim = atoi(Epplet_query_config_def("CLOAK_ANIM", "8"));
   if (opt.cloak_anim == 25)
     {
	opt.rand_cloak = 1;
	choose_random_cloak(NULL);
     }
   else
     {
	opt.rand_cloak = 0;
     }
   opt.delay = atof(Epplet_query_config_def("SHOT_DELAY", "0"));
   opt.cloak_delay = atof(Epplet_query_config_def("CLOAK_DELAY", "4"));
   opt.rand_delay = atof(Epplet_query_config_def("RAND_DELAY", "60"));
   opt.draw_interval = atof(Epplet_query_config_def("DRAW_INTERVAL", "0.1"));
   if (opt.dir)
      free(opt.dir);
   opt.dir = _Strdup(Epplet_query_config_def("DIRECTORY", "$HOME/"));
   if (opt.file_prefix)
      free(opt.file_prefix);
   opt.file_prefix = _Strdup(Epplet_query_config_def("FILE_PREFIX", "shot_"));
   if (opt.file_stamp)
      free(opt.file_stamp);
   opt.file_stamp =
      _Strdup(Epplet_query_config_def("FILE_STAMP", "`date +%d-%m-%y_%H%M%S`"));
   if (opt.file_type)
      free(opt.file_type);
   opt.file_type = _Strdup(Epplet_query_config_def("FILE_TYPE", "jpg"));
   if (opt.script)
      free(opt.script);
   opt.script =
      _Strdup(Epplet_query_config_def("SCRIPT_TO_RUN", "scrshot_script"));
   if (opt.viewer)
      free(opt.viewer);
   opt.viewer = _Strdup(Epplet_query_config_def("SHOT_VIEWER", "ee"));
   if (opt.ftp_user)
      free(opt.ftp_user);
   opt.ftp_user = _Strdup(Epplet_query_config_def("FTP_USER", "username"));
   if (opt.ftp_pass)
      free(opt.ftp_pass);
   opt.ftp_pass = _Strdup(Epplet_query_config_def("FTP_PASS", "password"));
   if (opt.ftp_host)
      free(opt.ftp_host);
   opt.ftp_host =
      _Strdup(Epplet_query_config_def("FTP_HOST", "ftp.myhost.com"));
   if (opt.ftp_dir)
      free(opt.ftp_dir);
   opt.ftp_dir = _Strdup(Epplet_query_config_def("FTP_DIR", "/images/"));
   if (opt.ftp_file)
      free(opt.ftp_file);
   opt.ftp_file = _Strdup(Epplet_query_config_def("FTP_FILE", "shot.jpg"));
   if (opt.ftp_temp)
      free(opt.ftp_temp);
   opt.ftp_temp = _Strdup(Epplet_query_config_def("FTP_TEMP", "uploading.jpg"));
   if (opt.grabber)
      free(opt.grabber);
   opt.grabber = _Strdup(Epplet_query_config_def("SHOT_GRABBER", "import"));
}
Exemplo n.º 10
0
// We've just seen a '<'.  Gather up stuff to closing '>' (if buffer
// ends before then, return -1).
// If it's a tag, look up the name, gather the attributes, and return
// the appropriate token.
// Else it's either just plain data or some kind of ignorable stuff:
// return Data or Comment as appropriate.
// If it's not a Comment, put it in a[*pai] and bump *pai.
static int
gettag(TokenSource* ts, int starti, Token* a, int* pai)
{
	int	rbra;
	int	ans;
	Attr*	al;
	int	nexti;
	int	c;
	int	ti;
	int	afnd;
	int	attid;
	int	quote;
	Rune*	val;
	int	nv;
	int	i;
	int	tag;
	Token*	tok;
	Rune	buf[BIGBUFSIZE];

	rbra = 0;
	nexti = ts->i;
	tok = &a[*pai];
	tok->tag = Notfound;
	tok->text = nil;
	tok->attr = nil;
	tok->starti = starti;
	c = getchar(ts);
	if(c == '/') {
		rbra = RBRA;
		c = getchar(ts);
	}
	if(c < 0)
		goto eob_done;
	if(c >= 256 || !isalpha(c)) {
		// not a tag
		if(c == '!') {
			ans = comment(ts);
			if(ans != -1)
				return ans;
			goto eob_done;
		}
		else {
			backup(ts, nexti);
			tok->tag = Data;
			tok->text = _Strdup(L"<");
			(*pai)++;
			return Data;
		}
	}
	// c starts a tagname
	buf[0] = c;
	i = 1;
	while(1) {
		c = getchar(ts);
		if(c < 0)
			goto eob_done;
		if(!ISNAMCHAR(c))
			break;
		// if name is bigger than buf it won't be found anyway...
		if(i < BIGBUFSIZE)
			buf[i++] = c;
	}
	if(_lookup(tagtable, Numtags, buf, i, &tag))
		tok->tag = tag + rbra;
	else
		tok->text = _Strndup(buf, i);	// for warning print, in build
	// attribute gathering loop
	al = nil;
	while(1) {
		// look for "ws name" or "ws name ws = ws val"  (ws=whitespace)
		// skip whitespace
attrloop_continue:
		while(c < 256 && isspace(c)) {
			c = getchar(ts);
			if(c < 0)
				goto eob_done;
		}
		if(c == '>')
			goto attrloop_done;
		if(c == '<') {
			if(warn)
				fprint(2, "warning: unclosed tag\n");
			ungetchar(ts, c);
			goto attrloop_done;
		}
		if(c >= 256 || !isalpha(c)) {
			if(warn)
				fprint(2, "warning: expected attribute name\n");
			// skipt to next attribute name
			while(1) {
				c = getchar(ts);
				if(c < 0)
					goto eob_done;
				if(c < 256 && isalpha(c))
					goto attrloop_continue;
				if(c == '<') {
					if(warn)
						fprint(2, "warning: unclosed tag\n");
					ungetchar(ts, 60);
					goto attrloop_done;
				}
				if(c == '>')
					goto attrloop_done;
			}
		}
		// gather attribute name
		buf[0] = c;
		i = 1;
		while(1) {
			c = getchar(ts);
			if(c < 0)
				goto eob_done;
			if(!ISNAMCHAR(c))
				break;
			if(i < BIGBUFSIZE-1)
				buf[i++] = c;
		}
		afnd = _lookup(attrtable, Numattrs, buf, i, &attid);
		if(warn && !afnd) {
			buf[i] = 0;
			fprint(2, "warning: unknown attribute name %S\n", buf);
		}
		// skip whitespace
		while(c < 256 && isspace(c)) {
			c = getchar(ts);
			if(c < 0)
				goto eob_done;
		}
		if(c != '=') {
			if(afnd)
				al = newattr(attid, nil, al);
			goto attrloop_continue;
		}
		//# c is '=' here;  skip whitespace
		while(1) {
			c = getchar(ts);
			if(c < 0)
				goto eob_done;
			if(c >= 256 || !isspace(c))
				break;
		}
		quote = 0;
		if(c == '\'' || c == '"') {
			quote = c;
			c = getchar(ts);
			if(c < 0)
				goto eob_done;
		}
		val = nil;
		nv = 0;
		while(1) {
valloop_continue:
			if(c < 0)
				goto eob_done;
			if(c == '>') {
				if(quote) {
					// c might be part of string (though not good style)
					// but if line ends before close quote, assume
					// there was an unmatched quote
					ti = ts->i;
					while(1) {
						c = getchar(ts);
						if(c < 0)
							goto eob_done;
						if(c == quote) {
							backup(ts, ti);
							buf[nv++] = '>';
							if(nv == BIGBUFSIZE-1) {
								val = buftostr(val, buf, nv);
								nv = 0;
							}
							c = getchar(ts);
							goto valloop_continue;
						}
						if(c == '\n') {
							if(warn)
								fprint(2, "warning: apparent unmatched quote\n");
							backup(ts, ti);
							c = '>';
							goto valloop_done;
						}
					}
				}
				else
					goto valloop_done;
			}
			if(quote) {
				if(c == quote) {
					c = getchar(ts);
					if(c < 0)
						goto eob_done;
					goto valloop_done;
				}
				if(c == '\r') {
					c = getchar(ts);
					goto valloop_continue;
				}
				if(c == '\t' || c == '\n')
					c = ' ';
			}
			else {
				if(c < 256 && isspace(c))
					goto valloop_done;
			}
			if(c == '&') {
				c = ampersand(ts);
				if(c == -1)
					goto eob_done;
			}
			buf[nv++] = c;
			if(nv == BIGBUFSIZE-1) {
				val = buftostr(val, buf, nv);
				nv = 0;
			}
			c = getchar(ts);
		}
valloop_done:
		if(afnd) {
			val = buftostr(val, buf, nv);
			al = newattr(attid, val, al);
		}
	}

attrloop_done:
	tok->attr = al;
	(*pai)++;
	return tok->tag;

eob_done:
	if(warn)
		fprint(2, "warning: incomplete tag at end of page\n");
	backup(ts, nexti);
	tok->tag = Data;
	tok->text = _Strdup(L"<");
	return Data;
}
Exemplo n.º 11
0
/* Search string for url. Fix up url if needed. */
static char        *
validate_url(char *url)
{
   char               *p;
   char               *ret = NULL;
   static char        *orig_ret = NULL;

   D(("In validate_url: url -->%s<--\n", url));

   if (!url)
      return NULL;

   if (orig_ret)
      free(orig_ret);

   ret = orig_ret = _Strdup(url);

   /* First, try searching for http://, in case there is a lot of text,
    * with an embedded url somewhere inside... */
   p = strstr(ret, "http://");
   if (p)
      ret = p;
   else
     {
	/* Ok. No "http://", maybe a "www." ? */
	p = strstr(ret, "http://");
	if (p)
	   ret = p;
     }

   /* Kill at end of line */
   p = strchr(ret, '\n');
   if (p)
      *p = '\0';

   /* Skip first spaces */
   p = ret;
   while (*p == ' ')
      p++;
   ret = p;

   /* Kill at next space */
   p = strchr(ret, ' ');
   if (p)
      *p = '\0';

   /* If just www.blah, add the http:// to avoid confusing nutscrape */
   if (*ret == 'w' && *(ret + 1) == 'w' && *(ret + 2) == 'w')
     {
	char               *temp = _Strjoin(NULL, "http://", ret, NULL);

	free(orig_ret);
	ret = _Strdup(temp);
	free(temp);
     }

   D(("In validate_url: ret -->%s<--\n", ret));

   /* Now some checks */
   if (strlen(ret) < 1)
      return 0;
   if (*ret == '-')
      return 0;

   return ret;
}