home *** CD-ROM | disk | FTP | other *** search
- /* cat > headers/myftp.h << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* myftp.h: header for myftp.c file */
- /* myftp.c creates ftp connection, get and put */
- /* files, and real time simulations of */
- /* computation runs. */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- #define myftp_h 1
-
- #include "all.h"
- #include "newext.h"
-
- static Panel_item inc_item, intv_item;
-
- static int ftp_connected, do_inc;
- static int inc_amt=1;
- static int intv_amt;
- static char remote_image[MAXNAMELEN];
-
- static Notify_value show_remote_image ();
- static void ftp_discon ();
- static void loop_start ();
- static int set_loop_option ();
- static int option_done ();
- static char *inc_fname ();
- static Frame option_box ();
- static void set_timer ();
- static void stop_timer ();
-
- /* EOF */
- /* cat > src+obj/myftp/create_ftp_menu.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* create_ftp_menu: create ftp menu */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- create_ftp_menu ()
- {
- ftp_menu = menu_create (
- MENU_FONT, font_menu,
- MENU_ACTION_ITEM, "Connect", ftp_connect,
- MENU_ACTION_ITEM, "Disconnect", ftp_discon,
- MENU_ACTION_ITEM, "Get loop", loop_start,
- MENU_ACTION_ITEM, "Stop", loop_stop,
- 0);
- }
- /* EOF */
- /* cat > src+obj/myftp/ftp_connect.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* ftp_connect: establish ftp connection */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- void
- ftp_connect (m, mi)
- Menu m;
- Menu_item mi;
- {
- int answer;
-
- static char host[MAXNAMELEN] = "";
-
- while (answer = mydialog ("Host name: ", NULL, host, 0, 20, 40))
- {
- if (strip_wspace (host) > 0)
- {
- if (word_count (host) != 1) /* must be one word */
- msg_write ("Error: Host name must be one word. Please retype or cancel.");
- else
- {
- sprintf (msgstr, "ftp %s\r", host);
- tty_write (msgstr);
- ftp_connected = 1;
- intv_amt = 15;
- return;
- }
- }
- else
- msg_write ("Error: No host name. Please type one in or cancel.");
- }
- ftp_connected = 0;
- return;
- }
- /* EOF */
- /* cat > src+obj/myftp/ftp_discon.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* ftp_discon: (static) disconnect ftp connection */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static void
- ftp_discon (m, mi)
- Menu m;
- Menu_item mi;
- {
- sprintf (msgstr, "quit\r");
- tty_write (msgstr);
- }
- /* EOF */
- /* cat > src+obj/myftp/ftp_handler.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* ftp_handler: handler for ftp */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- ftp_handler (item, event)
- Panel_item item;
- Event *event;
- {
- if (display_panel_menu (item, event, menu_panel, ftp_menu))
- ftp_connect (ftp_menu, menu_get (ftp_menu, MENU_NTH_ITEM, 1));
- }
- /* EOF */
- /* cat > src+obj/myftp/inc_fname.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* inc_fname: (static) file name increment */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static char *
- inc_fname (name)
- char *name;
- {
- char uc, lc, *s, str[MAXNAMELEN];
- int carry, atmp, stmp, nframe;
-
- if (name == NULL)
- return (NULL);
- if (inc_amt == 0)
- return (name);
-
- /* handle names ending in digits or letters separately */
- s = &name[strlen (name) - 1];
- if (isdigit (*s))
- {
- while (isdigit (*(s - 1)))
- s--;
- nframe = atoi (s) + inc_amt;
- *s = '\0';
- sprintf (str, "%s%.3d", name, nframe);
- strncpy (name, str, MAXNAMELEN - 1);
- }
- else if (isalpha (*s))
- {
- if (isupper (*s))
- {
- uc = 'Z';
- lc = 'A';
- }
- else
- {
- uc = 'z';
- lc = 'a';
- }
- atmp = inc_amt;
- carry = 0;
- do
- {
- stmp = (int) *s;
- stmp += atmp % 26 + carry;
- if (stmp > uc)
- {
- stmp = (stmp - uc - 1) + lc;
- carry = 1;
- }
- else
- carry = 0;
- *s = (char) (stmp & 0x7f);
- s--;
- } while ((atmp /= 26) > 0 || carry > 0);
- }
-
- return (name);
- }
- /* EOF */
- /* cat > src+obj/myftp/loop_start.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* loop_start: (static) routine to start get loop */
- /* dialog to get user input on options */
- /* start timer to signal loop operation */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static void
- loop_start (menu, item)
- Menu menu;
- Menu_item item;
- {
- Frame dialog;
- int answer;
- struct itimerval blink_timer;
-
- if (!ftp_connected)
- {
- msg_write ("Error: No ftp connection. Please connect first.");
- return;
- }
-
- /* get user input */
- dialog = option_box ();
- answer = (int) window_loop (dialog);
- window_set (dialog, FRAME_NO_CONFIRM, TRUE, 0);
- window_destroy (dialog);
- if (!answer)
- { /* cancel operation */
- loop_stop (NULL, NULL);
- return;
- }
-
- strcpy (remote_image, (char *) panel_get_value (image_board));
-
- /* set timer */
- set_timer (intv_amt, intv_amt);
-
- /* get first image - set binary mode first */
- sprintf (msgstr, "binary \r");
- tty_write (msgstr);
- sprintf (msgstr, "get %s\r", remote_image);
- tty_write (msgstr);
-
- getloop_go = 1;
- }
- /* EOF */
- /* cat > src+obj/myftp/loop_stop.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* loop_stop: loop termination */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- void
- loop_stop (menu, item)
- Menu menu;
- Menu_item item;
- {
- loop_zoomed = 0;
- getloop_go = 0;
-
- stop_timer();
-
- msg_write ("Note: Get loop stopped.");
- }
- /* EOF */
- /* cat > src+obj/myftp/option_box.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* option_box: (static) option box */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static Frame
- option_box ()
- {
- Frame dialog;
- Panel panel;
- char msg[MAXNAMELEN];
-
- dialog = window_create (NULL, FRAME, FRAME_SHOW_LABEL, FALSE, 0);
- panel = window_create (dialog, PANEL, 0);
-
- panel_create_item (panel, PANEL_MESSAGE,
- PANEL_ITEM_X, ATTR_COL (1),
- PANEL_ITEM_Y, ATTR_ROW (0),
- PANEL_LABEL_STRING, "Loop defaults: ",
- PANEL_LABEL_BOLD, TRUE,
- 0);
-
- sprintf (msg, "%d", inc_amt);
- inc_item = panel_create_item (panel, PANEL_TEXT,
- PANEL_ITEM_X, ATTR_COL (4),
- PANEL_ITEM_Y, ATTR_ROW (1),
- PANEL_LABEL_STRING, "Image name increment: ",
- PANEL_LABEL_BOLD, FALSE,
- PANEL_VALUE_STORED_LENGTH, 20,
- PANEL_VALUE_DISPLAY_LENGTH, 20,
- PANEL_VALUE, msg,
- 0);
-
- sprintf (msg, "%d", intv_amt);
- intv_item = panel_create_item (panel, PANEL_TEXT,
- PANEL_ITEM_X, ATTR_COL (4),
- PANEL_ITEM_Y, ATTR_ROW (2),
- PANEL_LABEL_STRING, "Interval (sec): ",
- PANEL_LABEL_BOLD, FALSE,
- PANEL_VALUE_STORED_LENGTH, 20,
- PANEL_VALUE_DISPLAY_LENGTH, 20,
- PANEL_VALUE, msg,
- 0);
-
- panel_create_item (panel, PANEL_CYCLE,
- PANEL_ITEM_X, ATTR_COL (4),
- PANEL_ITEM_Y, ATTR_ROW (3),
- PANEL_LABEL_STRING, "Zoomed image ",
- PANEL_LABEL_BOLD, FALSE,
- PANEL_CHOICE_STRINGS, "off", "on", 0,
- PANEL_VALUE, 0,
- PANEL_NOTIFY_PROC, set_loop_option,
- 0);
- panel_create_item (panel, PANEL_BUTTON,
- PANEL_ITEM_X, ATTR_COL (30),
- PANEL_ITEM_Y, ATTR_ROW (4),
- PANEL_LABEL_IMAGE, panel_button_image (panel, "Ok", 3, NULL),
- PANEL_CLIENT_DATA, 1,
- PANEL_NOTIFY_PROC, option_done,
- 0);
- panel_create_item (panel, PANEL_BUTTON,
- PANEL_ITEM_X, ATTR_COL (36),
- PANEL_ITEM_Y, ATTR_ROW (4),
- PANEL_LABEL_IMAGE, panel_button_image (panel, "Cancel", 7, NULL),
- PANEL_CLIENT_DATA, 0,
- PANEL_NOTIFY_PROC, option_done,
- 0);
- window_fit (panel);
- window_fit (dialog);
- /*
- init_same_colormap((Pixwin *)window_get(dialog,WIN_PIXWIN));
- init_same_colormap((Pixwin *)window_get(panel,WIN_PIXWIN));
- */
- return dialog;
- }
- /* EOF */
- /* cat > src+obj/myftp/option_done.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* option_done: (static) done with option */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static
- option_done (item, event)
- Panel_item item;
- Event *event;
- {
- char str[MAXNAMELEN];
-
- strcpy (str, (char *) panel_get_value (inc_item));
- inc_amt = atoi (str);
- strcpy (str, (char *) panel_get_value (intv_item));
- intv_amt = atoi (str);
- window_return ((int) panel_get (item, PANEL_CLIENT_DATA));
- }
- /* EOF */
- /* cat > src+obj/myftp/set_loop_option.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* set_loop_option: (static) set loop option */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static
- set_loop_option (item, value, event)
- Panel_item item;
- int value;
- Event *event;
- {
- loop_zoomed = value;
- }
- /* EOF */
- /* cat > src+obj/myftp/set_timer.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* set_timer: (static) start timer to signal loop */
- /* operation */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static void
- set_timer (start_time, interval_time)
- int start_time, interval_time;
- {
- struct itimerval blink_timer;
-
- /* set timer parameters and start timer */
- blink_timer.it_value.tv_sec = start_time;
- blink_timer.it_value.tv_usec = 0;
- blink_timer.it_interval.tv_sec = interval_time;
- blink_timer.it_interval.tv_usec = 0;
-
- (void) notify_set_itimer_func (ttysw, show_remote_image,
- ITIMER_REAL, &blink_timer, NULL);
- }
- /* EOF */
- /* cat > src+obj/myftp/show_remote_image.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* show_remote_image: (static) looping routine to get */
- /* image from network and display */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static Notify_value
- show_remote_image (client, itimer_type)
- Notify_client client;
- int itimer_type;
- {
- /* implementation note(s):
- 1. Attempt to display image.
- 2. If no error then build new image filename
- 3. Get the new image filename.
- */
- int index_type;
- enum desired_img_type in_type;
- enum img_type out_type;
- int err;
- char filename[MAXNAMELEN];
- int dim_x, dim_y;
- uint16 iref;
- bool load_pal, load_pal_old;
-
- /* show which image filename will be displayed */
- panel_set_value (image_board, remote_image);
-
- /* display image */
- index_type = (int) panel_get_value (load_toggle);
- in_type = index_type % 3;
- load_pal = (index_type < 2) ? TRUE : FALSE;
-
- switch ((err = check_imgfn (filename)))
- {
- case 0: /* no error */
- break;
- case 1:
- msg_write ("Error: Image file not found.");
- loop_stop (NULL, NULL);
- return;
- case 2:
- msg_write ("Error: Image file not a file.");
- loop_stop (NULL, NULL);
- return;
- case 3:
- msg_write ("Error: No image filename.");
- loop_stop (NULL, NULL);
- return;
- case 4:
- msg_write ("Error: More than one image file given.");
- loop_stop (NULL, NULL);
- return;
- case 5:
- msg_write ("Error: Wildcard matches more than one image file.");
- loop_stop (NULL, NULL);
- return;
- case 6:
- msg_write ("Error: Wildcard syntax.");
- loop_stop (NULL, NULL);
- return;
- default:
- sprintf (wkstr, "Internal error (%d): While checking image filename.", err);
- msg_write (wkstr);
- loop_stop (NULL, NULL);
- return;
- }
-
- load_pal_old = load_pal;
- switch ((err = check_image (in_type, filename, &out_type, &dim_x, &dim_y, &iref, &load_pal)))
- {
- case 0: /* no error */
- break;
- case 1:
- msg_write ("Error: Image file does not exist.");
- loop_stop (NULL, NULL);
- return;
- case 2:
- msg_write ("Error: Dimension(s) are bad.");
- loop_stop (NULL, NULL);
- return;
- case 3:
- msg_write ("Error: Size of image doesn't match dimensions.");
- loop_stop (NULL, NULL);
- return;
- case 4:
- msg_write ("Error: No 8-bit Raster Image Set found in image file.");
- loop_stop (NULL, NULL);
- return;
- case 5:
- msg_write ("Error: No 2D Scientific Data Set found in image file.");
- loop_stop (NULL, NULL);
- return;
- case 6:
- msg_write ("Error: No 8-bit Raster Image Set or 2D Scientific Data Set found in image file.");
- loop_stop (NULL, NULL);
- return;
- case 7:
- sprintf (wkstr, "Error: Image too big!. (x, y) size = (%d, %d) not in range (%d, %d)", dim_x, dim_y, XMAX_IMAGE, YMAX_IMAGE);
- msg_write (wkstr);
- loop_stop (NULL, NULL);
- return;
- default:
- sprintf (wkstr, "HDF file error (DFerror = %d): While checking image file.", err);
- msg_write (wkstr);
- loop_stop (NULL, NULL);
- return;
- }
- if (out_type == RIS8 && (load_pal != load_pal_old))
- msg_write ("Warning: No palette with 8-bit Raster Image Set in image file.");
- switch (out_type)
- {
- case RAWI:
- if (load_RAWI (filename, dim_x, dim_y, FTP_SEQUENCE))
- return;
- break;
- case RIS8:
- if (load_RIS8 (filename, dim_x, dim_y, iref, load_pal, FTP_SEQUENCE))
- return;
- break;
- case SDS2D:
- if (((int) panel_get_value (SDS_toggle)) == 0)
- { /* popup dialog box case */
- stop_timer ();
- if (load_SDS2D (filename, dim_x, dim_y, FTP_SEQUENCE))
- {
- loop_stop (NULL, NULL);
- return;
- }
- set_timer (intv_amt, intv_amt);
- }
- else
- {
- if (load_SDS2D (filename, dim_x, dim_y, FTP_SEQUENCE))
- {
- loop_stop (NULL, NULL);
- return;
- }
- }
- break;
- }
- /* increment filename */
- inc_fname (remote_image);
-
- /* get file */
- sprintf (msgstr, "get %s\r", remote_image);
- tty_write (msgstr);
-
- return (NOTIFY_DONE);
- }
- /* EOF */
- /* cat > src+obj/myftp/stop_timer.c << "EOF" */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* stop_timer: stop the looping timer */
- /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
- /* SCCS information: %W% %G% - NCSA */
-
- /* #include "myftp.h" */
-
- static void
- stop_timer ()
- {
- (void) notify_set_itimer_func (ttysw, show_remote_image,
- ITIMER_REAL, NULL, NULL);
- }
- /* EOF */
-