Пример #1
0
void Track_station_now(Widget w, XtPointer clientData, XtPointer callData) {
    char temp[MAX_CALLSIGN+1];
    char temp2[200];
    int found = 0;
    char *temp_ptr;


    temp_ptr = XmTextFieldGetString(track_station_data);
    xastir_snprintf(temp,
        sizeof(temp),
        "%s",
        temp_ptr);
    XtFree(temp_ptr);

    (void)remove_trailing_spaces(temp);
    (void)remove_trailing_dash_zero(temp);

    xastir_snprintf(tracking_station_call,
        sizeof(tracking_station_call),
        "%s",
        temp);
    track_case  = (int)XmToggleButtonGetState(track_case_data);
    track_match = (int)XmToggleButtonGetState(track_match_data);
    found = locate_station(da, temp, track_case, track_match, 0);

    if ( valid_object(tracking_station_call)    // Name of object is legal
            || valid_call(tracking_station_call)
            || valid_item(tracking_station_call ) ) {
        track_station_on = 1;   // Track it whether we've seen it yet or not
        if (!found) {
            xastir_snprintf(temp2, sizeof(temp2), langcode("POPEM00026"), temp);
            popup_message_always(langcode("POPEM00025"),temp2);
        }
        // Check for exact match, includes SSID
        if ( track_me & !is_my_call( tracking_station_call, 1) ) {
            XmToggleButtonSetState( trackme_button, FALSE, FALSE );
            track_me = 0;
        }
    } else {
        tracking_station_call[0] = '\0';    // Empty it out again
        track_station_on = 0;
        xastir_snprintf(temp2, sizeof(temp2), langcode("POPEM00002"), temp);
        popup_message_always(langcode("POPEM00003"),temp2);
    }

    track_station_destroy_shell(w, clientData, callData);
    display_zoom_status();
}
Пример #2
0
void Download_findu_trail( /*@unused@*/ Widget w, /*@unused@*/ XtPointer clientData, /*@unused@*/ XtPointer callData) {
    static Widget pane, my_form, button_ok, button_cancel, call, sep;
    Atom delw;
    XmString x_str;


    if (!download_findu_dialog) {

begin_critical_section(&download_findu_dialog_lock, "track_gui.c:Download_findu_trail" );

        download_findu_dialog = XtVaCreatePopupShell(langcode("WPUPTSP007"),
                xmDialogShellWidgetClass, appshell,
                XmNdeleteResponse,XmDESTROY,
                XmNdefaultPosition, FALSE,
                XmNfontList, fontlist1,
                NULL);

        pane = XtVaCreateWidget("Download_findu_trail pane",
                xmPanedWindowWidgetClass, 
                download_findu_dialog,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        my_form =  XtVaCreateWidget("Download_findu_trail my_form",
                xmFormWidgetClass, 
                pane,
                XmNfractionBase, 2,
                XmNautoUnmanage, FALSE,
                XmNshadowThickness, 1,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        call = XtVaCreateManagedWidget(langcode("WPUPTSP008"),
                xmLabelWidgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 10,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment, XmATTACH_NONE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        download_trail_station_data = XtVaCreateManagedWidget("download_trail_station_data", 
                xmTextFieldWidgetClass, 
                my_form,
                XmNeditable,   TRUE,
                XmNcursorPositionVisible, TRUE,
                XmNsensitive, TRUE,
                XmNshadowThickness,    1,
                XmNcolumns, 15,
                XmNwidth, ((15*7)+2),
                XmNmaxLength, 15,
                XmNbackground, colors[0x0f],
                XmNtopAttachment,XmATTACH_FORM,
                XmNtopOffset, 5,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, call,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                XmNfontList, fontlist1,
                NULL);

        x_str = XmStringCreateLocalized(langcode("WPUPTSP009"));
        posit_start_value = XtVaCreateManagedWidget("Start of Trail (hrs ago)", 
                xmScaleWidgetClass, 
                my_form,
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget, call,
                XmNtopOffset, 15,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                //XmNwidth, 190,
                XmNrightAttachment, XmATTACH_FORM,
                XmNrightOffset, 10,
                XmNsensitive, TRUE,
                XmNorientation, XmHORIZONTAL,
                XmNborderWidth, 1,
                XmNminimum, 1,
                XmNmaximum, MAX_FINDU_START_TIME,
                XmNshowValue, TRUE,
                XmNvalue, posit_start,
// Note:  Some versions of OpenMotif (distributed with Fedora,
// perhaps others) don't work properly with XtVaTypedArg() as used
// here, instead showing blank labels for the Scale widgets.
//                XtVaTypedArg, XmNtitleString, XmRString, langcode("WPUPTSP009"), 22,
                XmNtitleString, x_str,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);
        XmStringFree(x_str);

        x_str = XmStringCreateLocalized(langcode("WPUPTSP010"));
        posit_length_value = XtVaCreateManagedWidget("Length of trail (hrs)", 
                xmScaleWidgetClass, 
                my_form,
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget, posit_start_value,
                XmNtopOffset, 15,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                //XmNwidth, 190,
                XmNrightAttachment, XmATTACH_FORM,
                XmNrightOffset, 10,
                XmNsensitive, TRUE,
                XmNorientation, XmHORIZONTAL,
                XmNborderWidth, 1,
                XmNminimum, 1,
                XmNmaximum, MAX_FINDU_DURATION,
                XmNshowValue, TRUE,
                XmNvalue, posit_length,
// Note:  Some versions of OpenMotif (distributed with Fedora,
// perhaps others) don't work properly with XtVaTypedArg() as used
// here, instead showing blank labels for the Scale widgets.
//                XtVaTypedArg, XmNtitleString, XmRString, langcode("WPUPTSP010"), 19,
                XmNtitleString, x_str,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);
        XmStringFree(x_str);

        sep = XtVaCreateManagedWidget("Download_findu_trail sep", 
                xmSeparatorGadgetClass,
                my_form,
                XmNorientation, XmHORIZONTAL,
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget,posit_length_value,
                XmNtopOffset, 10,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNrightAttachment,XmATTACH_FORM,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_ok = XtVaCreateManagedWidget(langcode("WPUPTSP007"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 0,
                XmNleftOffset, 5,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 1,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);
        if (fetching_findu_trail_now)
            XtSetSensitive(button_ok, FALSE);

        button_cancel = XtVaCreateManagedWidget(langcode("UNIOP00002"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 1,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 2,
                XmNrightOffset, 5,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(button_ok, XmNactivateCallback, Download_trail_now, download_findu_dialog);
        XtAddCallback(button_cancel, XmNactivateCallback, Download_trail_destroy_shell, download_findu_dialog);
        XtAddCallback(posit_start_value, XmNvalueChangedCallback, Reset_posit_length_max, download_findu_dialog);

        pos_dialog(download_findu_dialog);

        delw = XmInternAtom(XtDisplay(download_findu_dialog),"WM_DELETE_WINDOW", FALSE);
        XmAddWMProtocolCallback(download_findu_dialog, delw, Download_trail_destroy_shell, (XtPointer)download_findu_dialog);

        XmTextFieldSetString(download_trail_station_data,download_trail_station_call);

        XtManageChild(my_form);
        XtManageChild(pane);

end_critical_section(&download_findu_dialog_lock, "track_gui.c:Download_trail" );

        XtPopup(download_findu_dialog,XtGrabNone);
        fix_dialog_size(download_findu_dialog);

        // Move focus to the Cancel button.  This appears to highlight the
        // button fine, but we're not able to hit the <Enter> key to
        // have that default function happen.  Note:  We _can_ hit the
        // <SPACE> key, and that activates the option.
//        XmUpdateDisplay(download_findu_dialog);
        XmProcessTraversal(button_cancel, XmTRAVERSE_CURRENT);

    } else
        (void)XRaiseWindow(XtDisplay(download_findu_dialog), XtWindow(download_findu_dialog));
}
Пример #3
0
void Download_trail_now(Widget w, XtPointer clientData, XtPointer callData) {
    char temp[MAX_CALLSIGN+1];
    static char fileimg[400];
    static char log_filename[200];
    char *temp_ptr;
    pthread_t download_trail_thread;
    static XtPointer download_client_data = NULL;

    char tmp_base_dir[MAX_VALUE];

    get_user_base_dir("tmp",tmp_base_dir, sizeof(tmp_base_dir));

    // If we're already fetching a trail, we shouldn't be calling
    // this callback function.  Get out.
    if (fetching_findu_trail_now)
        return;

    // Pass two parameters to findu_transfer_thread via a struct
    track_ptrs.download_client_ptrs[0] = log_filename;
    track_ptrs.download_client_ptrs[1] = fileimg;
    download_client_data = &track_ptrs;

    // Check whether it's ok to do a download currently.
    if (read_file) {
        // No, we're already in the middle of reading in some file.
        // Skip trying to download yet another file.

        fprintf(stderr,"Processing another file.  Wait a bit, then try again\n");

        popup_message_always(langcode("POPEM00035"),
            langcode("POPEM00041"));

        return;
    }
 
//    busy_cursor(appshell);

    xastir_snprintf(log_filename,
        sizeof(log_filename),
        "%s/map.log",
        tmp_base_dir);

    // Erase any previously existing local file by the same name.
    // This avoids the problem of having an old tracklog here and
    // the code trying to display it when the download fails.
    unlink( log_filename );


    XmScaleGetValue(posit_start_value , &posit_start);
    XmScaleGetValue(posit_length_value , &posit_length);

    temp_ptr = XmTextFieldGetString(download_trail_station_data);
    xastir_snprintf(temp,
        sizeof(temp),
        "%s",
        temp_ptr);
    XtFree(temp_ptr);

    (void)remove_trailing_spaces(temp);
    (void)remove_trailing_dash_zero(temp);
   
    xastir_snprintf(download_trail_station_call,
        sizeof(download_trail_station_call),
        "%s",
        temp);        
    //Download_trail_destroy_shell(w, clientData, callData);


// New URL's for findu.  The second one looks very promising.
//http://www.findu.com/cgi-bin/raw.cgi?call=k4hg-8&time=1
//http://www.findu.com/cgi-bin/rawposit.cgi?call=k4hg-8&time=1
//
// The last adds this to the beginning of the line:
//
//      "20030619235323,"
//
// which is a date/timestamp.  We'll need to do some extra stuff
// here in order to actually use that date/timestamp though.
// Setting the read_file_ptr to the downloaded file won't do it.



//        "http://www.findu.com/cgi-bin/rawposit.cgi?call=%s&start=%d&length=%d&time=1", // New, with timestamp
    xastir_snprintf(fileimg, sizeof(fileimg),
        //
        // Posits only:
        // "http://www.findu.com/cgi-bin/rawposit.cgi?call=%s&start=%d&length=%d",
        //
        // Posits plus timestamps (we can't handle timestamps yet):
        // "http://www.findu.com/cgi-bin/rawposit.cgi?call=%s&start=%d&length=%d&time=1", // New, with timestamp
        // 
        // Download all packets, not just posits:
        "http://www.findu.com/cgi-bin/raw.cgi?call=%s&start=%d&length=%d",
        //
        download_trail_station_call,posit_start,posit_length);

    if (debug_level & 1024) {
        fprintf(stderr, "%s\n", fileimg);
    }


//----- Start New Thread -----

    if (pthread_create(&download_trail_thread,
            NULL,
            findu_transfer_thread,
            download_client_data)) {

        fprintf(stderr,"Error creating findu transfer thread\n");
    }
    else {
        // We're off and running with the new thread!
    }

    display_zoom_status();

    Download_trail_destroy_shell(w, clientData, callData);
}
Пример #4
0
// This is the separate execution thread that fetches the track from
// findu.  The thread is started up by the Download_trail_now()
// function below.
//
static void* findu_transfer_thread(void *arg) {
    char *fileimg;
    char *log_filename;
//    char log_filename_tmp[210];
    char **ptrs;
    char sys_cmd[128];


    // Get fileimg and log_filename from parameters
    ptrs = arg;
    log_filename = ptrs[0];
    fileimg = ptrs[1];

    // Set global "busy" variable
    fetching_findu_trail_now = 1;
 
    if (fetch_remote_file(fileimg, log_filename)) {

        // Had trouble getting the file.  Abort.

// We may not be able to do any GUI stuff from multiple
// threads/processes at the same time.  If that is found to be the
// case we can write to STDERR instead.
 
        // Dump a message to STDERR
//        fprintf(stderr,
//            "%s  %s\n",
//            langcode("POPEM00035"),
//            langcode("POPEM00044"));

        // Fetch Findu Trail: Failed
        popup_message_always(langcode("POPEM00035"),
            langcode("POPEM00044"));

        // Reset global "busy" variable
        fetching_findu_trail_now = 0;

        // End the thread
        return(NULL);
    }

// We need to move this message up to the main thread if possible so
// that we don't have multiple threads writing to the GUI.  This
// sort of operation can cause segfaults.  In practice I haven't
// seen any segfaults due to this particular popup though.

    // Fetch Findu Trail: Complete
    popup_message_always(langcode("POPEM00036"),
        langcode("POPEM00045"));

    // Set permissions on the file so that any user can overwrite it.
    chmod(log_filename, 0666);

#if defined(HAVE_SED)
    // Add three spaces before each "<br>" and axe the "<br>".  This
    // is so that Base-91 compressed packets with no comment and no
    // speed/course/altitude will get decoded ok.  Otherwise the
    // spaces that are critical to the Base-91 packets won't be
    // there due to findu.com filtering them out.
    //
// "sed -i -e \"s/<br>/   <br>/\" %s",
    sprintf(sys_cmd,
        "%s -i -e \"s/<br>/   /\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);
//fprintf(stderr,"%s\n", sys_cmd);

// Greater-than symbol '>'
    sprintf(sys_cmd,
        "%s -i -e \"s/&gt;/>/\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);

// Less-than symbol '<'
    sprintf(sys_cmd,
        "%s -i -e \"s/&lt;/</\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);

// Ampersand '&' (A difficult character to escape from the shell!)
    sprintf(sys_cmd,
        "%s -i -e \"s/&amp;/\\&/\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);

// Double-quote symbol '"'
    sprintf(sys_cmd,
        "%s -i -e \"s/&quot;/""/\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);

// Remove whitespace at the start of a line
// sed 's/^[ \t]*//'
    sprintf(sys_cmd,
        "%s -i -e \"s/^[ \t]*//\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);

// Remove any lines that start with '<'
    sprintf(sys_cmd,
        "%s -i -e \"s/^<.*$//\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);

// Remove any lines that start with '"http'
    sprintf(sys_cmd,
        "%s -i -e \"/^\\\"http.*$/d\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);

// Remove any blank lines from the file
// sed '/^$/d'
    sprintf(sys_cmd,
        "%s -i -e \"/^$/d\" %s",
        SED_PATH,
        log_filename);
    system(sys_cmd);
#endif  // HAVE_SED

/*
#ifdef HAVE_HTML2TEXT
    // Create temp filename
    snprintf(log_filename_tmp, sizeof(log_filename_tmp), "%s%s",
        log_filename,
        ".tmp");
    // Create html2text command
    sprintf(sys_cmd,
        "%s -width 300 -o %s %s",
        HTML2TEXT_PATH,
        log_filename_tmp,
        log_filename);
    // Convert the newly-downloaded file from html to text format
    system(sys_cmd);
    // Rename the file so that we can keep the static char* name
    // pointing to it, needed for the read_file_ptr code in the main
    // thread.
#if defined(HAVE_MV)
    sprintf(sys_cmd,
        "%s %s %s",
        MV_PATH,
        log_filename_tmp,
        log_filename);
    system(sys_cmd);
#endif  // HAVE_MV
#endif  // HAVE_HTML2TEXT
*/

    // Here we do the findu stuff, if the findu_flag is set.  Else we do an imagemap.
    // We have the log data we're interested in within the log_filename file.
    // Cause that file to be read by the "File->Open Log File" routine.  HTML
    // tags will be ignored just fine.
    read_file_ptr = fopen(log_filename, "r");

    if (read_file_ptr != NULL) {
        read_file = 1;
    }
    else {
        fprintf(stderr,"Couldn't open file: %s\n", log_filename);
    }

    // Reset global "busy" variable
    fetching_findu_trail_now = 0;
 
    // End the thread
    return(NULL);
}
Пример #5
0
void Track_station( /*@unused@*/ Widget w, /*@unused@*/ XtPointer clientData, /*@unused@*/ XtPointer callData) {
    static Widget pane, my_form, button_ok, button_close, button_clear, call, sep;
    Atom delw;

    if (!track_station_dialog) {

begin_critical_section(&track_station_dialog_lock, "track_gui.c:Track_station" );

        track_station_dialog = XtVaCreatePopupShell(langcode("WPUPTSP001"),
                xmDialogShellWidgetClass, appshell,
                XmNdeleteResponse, XmDESTROY,
                XmNdefaultPosition, FALSE,
                XmNfontList, fontlist1,
                NULL);

        pane = XtVaCreateWidget("Track_station pane",
                xmPanedWindowWidgetClass, 
                track_station_dialog,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        my_form =  XtVaCreateWidget("Track_station my_form",
                xmFormWidgetClass, 
                pane,
                XmNfractionBase, 3,
                XmNautoUnmanage, FALSE,
                XmNshadowThickness, 1,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        call = XtVaCreateManagedWidget(langcode("WPUPTSP002"),
                xmLabelWidgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 10,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment, XmATTACH_NONE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        track_station_data = XtVaCreateManagedWidget("Track_station track locate data", 
                xmTextFieldWidgetClass, 
                my_form,
                XmNeditable,   TRUE,
                XmNcursorPositionVisible, TRUE,
                XmNsensitive, TRUE,
                XmNshadowThickness,    1,
                XmNcolumns, 15,
                XmNwidth, ((15*7)+2),
                XmNmaxLength, 15,
                XmNbackground, colors[0x0f],
                XmNtopAttachment,XmATTACH_FORM,
                XmNtopOffset, 5,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, call,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                XmNfontList, fontlist1,
                NULL);

        track_case_data  = XtVaCreateManagedWidget(langcode("WPUPTSP003"),
                xmToggleButtonWidgetClass,
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, call,
                XmNtopOffset, 20,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset ,10,
                XmNrightAttachment, XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        track_match_data  = XtVaCreateManagedWidget(langcode("WPUPTSP004"),
                xmToggleButtonWidgetClass,
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, call,
                XmNtopOffset, 20,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget,track_case_data,
                XmNrightOffset ,20,
                XmNrightAttachment, XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        sep = XtVaCreateManagedWidget("Track_station sep", 
                xmSeparatorGadgetClass,
                my_form,
                XmNorientation, XmHORIZONTAL,
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget,track_case_data,
                XmNtopOffset, 10,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNrightAttachment,XmATTACH_FORM,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_ok = XtVaCreateManagedWidget(langcode("WPUPTSP005"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 0,
                XmNleftOffset, 5,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 1,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_clear = XtVaCreateManagedWidget(langcode("WPUPTSP006"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 1,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 2,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_close = XtVaCreateManagedWidget(langcode("UNIOP00003"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, sep,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset, 5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 2,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 3,
                XmNrightOffset, 5,
                XmNnavigationType, XmTAB_GROUP,
                XmNtraversalOn, TRUE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(button_ok, XmNactivateCallback, Track_station_now, track_station_dialog);
        XtAddCallback(button_close, XmNactivateCallback, track_station_destroy_shell, track_station_dialog);
        XtAddCallback(button_clear, XmNactivateCallback, Track_station_clear, track_station_dialog);

        XmToggleButtonSetState(track_case_data,FALSE,FALSE);
        XmToggleButtonSetState(track_match_data,TRUE,FALSE);

        pos_dialog(track_station_dialog);

        delw = XmInternAtom(XtDisplay(track_station_dialog),"WM_DELETE_WINDOW", FALSE);
        XmAddWMProtocolCallback(track_station_dialog, delw, track_station_destroy_shell, (XtPointer)track_station_dialog);

//        if (track_station_on==1)
            XmTextFieldSetString(track_station_data,tracking_station_call);

        XtManageChild(my_form);
        XtManageChild(pane);

end_critical_section(&track_station_dialog_lock, "track_gui.c:Track_station" );

        XtPopup(track_station_dialog,XtGrabNone);
        fix_dialog_size(track_station_dialog);

        // Move focus to the Cancel button.  This appears to highlight the
        // button fine, but we're not able to hit the <Enter> key to
        // have that default function happen.  Note:  We _can_ hit the
        // <SPACE> key, and that activates the option.
//        XmUpdateDisplay(track_station_dialog);
        XmProcessTraversal(button_close, XmTRAVERSE_CURRENT);

    } else
        (void)XRaiseWindow(XtDisplay(track_station_dialog), XtWindow(track_station_dialog));
}
Пример #6
0
/* ******************************************************************** */
int search_rac_data(char *callsign, rac_record *data) {
    FILE *fdb;
    FILE *fndx;
    char *rc;
    long call_offset = 0l;
    char char_offset[16];
    char index[32];
    int found = 0;
    rac_record racdata;
    /*char        filler[8];*/
    char amacall_path[MAX_VALUE];

    get_user_base_dir("data/AMACALL.ndx", amacall_path, sizeof(amacall_path));


    xastir_snprintf(index, sizeof(index)," ");
    xastir_snprintf(racdata.callsign, sizeof(racdata.callsign)," ");

    /* ====================================================================    */
    /*    Search thru the index, get the RBA                */
    /*                                    */

    fndx = fopen(amacall_path, "r");
    if(fndx != NULL) {
        rc = fgets(index, (int)sizeof(index), fndx);
        xastir_snprintf(char_offset, sizeof(char_offset), "%s", &index[6]);
        while (!feof(fndx) && strncmp(callsign, index, 6) > 0) {
            xastir_snprintf(char_offset, sizeof(char_offset), "%s", &index[6]);
            rc = fgets(index, (int)sizeof(index), fndx);
        }
    } else {
        fprintf(stderr,
            "Search:Could not open RAC data base index: %s\n",
            amacall_path );

        return (0);
    }
    call_offset = atol(char_offset);
 
    (void)fclose(fndx);

    /* ====================================================================    */
    /*    Now we have our pointer into the main database (text) file.    */
    /*    Start from there and linear search the data.            */
    /*    This will take an avg of 1/2 of the # skipped making the index    */
    /*                                    */

    fdb = fopen(get_data_base_dir("fcc/AMACALL.LST"), "r");
    if (fdb != NULL) {
        (void)fseek(fdb, call_offset, SEEK_SET);
        if (callsign[5] == '-')
            (void)chomp(callsign,5);

        while (!feof(fdb) && strncmp((char *)&racdata, callsign, 6) < 0)

//WE7U
// Problem here:  We're sticking 8 bytes too many into racdata!
            rc = fgets((char *)&racdata, sizeof(racdata), fdb);

    } else
        fprintf(stderr,"Search:Could not open RAC data base: %s\n", get_data_base_dir("fcc/AMACALL.LST") );

    /*  || (callsign[5] == '-' && strncmp((char *)&racdata,callsign,5) < 0)) */
    (void)chomp(racdata.callsign, 6);

    if (!strncmp((char *)racdata.callsign, callsign, 6)) {
        found = 1;

// Some of these cause problems on 64-bit processors, so commented
// them out for now.
//        (void)chomp(racdata.first_name, 35);
//        (void)chomp(racdata.last_name, 35);
//        (void)chomp(racdata.address, 70);
//        (void)chomp(racdata.city, 35);
//        (void)chomp(racdata.province, 2);
//        (void)chomp(racdata.postal_code, 10);
//        (void)chomp(racdata.qual_a, 1);
//        (void)chomp(racdata.qual_b, 1);
//        (void)chomp(racdata.qual_c, 1);
//        (void)chomp(racdata.qual_d, 1);
//        (void)chomp(racdata.club_name, 141);
//        (void)chomp(racdata.club_address, 70);
//        (void)chomp(racdata.club_city, 35);
//        (void)chomp(racdata.club_province, 2);
//        (void)chomp(racdata.club_postal_code, 9);

        xastir_snprintf(data->callsign,
            sizeof(data->callsign),
            "%s",
            racdata.callsign);

        xastir_snprintf(data->first_name,
            sizeof(data->first_name),
            "%s",
            racdata.first_name);
 
        xastir_snprintf(data->last_name,
            sizeof(data->last_name),
            "%s",
            racdata.last_name);
 
        xastir_snprintf(data->address,
            sizeof(data->address),
            "%s",
            racdata.address);
 
        xastir_snprintf(data->city,
            sizeof(data->city),
            "%s",
            racdata.city);
 
        xastir_snprintf(data->province,
            sizeof(data->province),
            "%s",
            racdata.province);
 
        xastir_snprintf(data->postal_code,
            sizeof(data->postal_code),
            "%s",
            racdata.postal_code);
 
        xastir_snprintf(data->qual_a,
            sizeof(data->qual_a),
            "%s",
            racdata.qual_a);
 
        xastir_snprintf(data->qual_b,
            sizeof(data->qual_b),
            "%s",
            racdata.qual_b);
 
        xastir_snprintf(data->qual_c,
            sizeof(data->qual_c),
            "%s",
            racdata.qual_c);
 
        xastir_snprintf(data->qual_d,
            sizeof(data->qual_d),
            "%s",
            racdata.qual_d);
 
        xastir_snprintf(data->club_name,
            sizeof(data->club_name),
            "%s",
            racdata.club_name);
 
        xastir_snprintf(data->club_address,
            sizeof(data->club_address),
            "%s",
            racdata.club_address);
 
        xastir_snprintf(data->club_city,
            sizeof(data->club_city),
            "%s",
            racdata.club_city);
 
        xastir_snprintf(data->club_province,
            sizeof(data->club_province),
            "%s",
            racdata.club_province);
 
        xastir_snprintf(data->club_postal_code,
            sizeof(data->club_postal_code),
            "%s",
            racdata.club_postal_code);
 
    }
    (void)fclose(fdb);

    if (!found) {

        // "Callsign Search", "Callsign Not Found!"
        popup_message_always(langcode("STIFCC0101"),
            langcode("STIFCC0102") );
    }
 
    return(found);
}
Пример #7
0
/* ******************************************************************** */
int build_rac_index(void) {
    FILE *fdb;
    FILE *fndx;
    unsigned long call_offset = 0;
    unsigned long x = 0;
    char racdata[RAC_DATA_LEN+8];
    char amacall_path[MAX_VALUE];

    get_user_base_dir("data/AMACALL.ndx", amacall_path, sizeof(amacall_path));

    /* ====================================================================    */
    /*    If the index file is there, exit                */
    /*                                    */
    if (filethere(amacall_path)) {
        /* if file is there make sure the index date is newer */
      if(file_time(amacall_path)<=file_time(amacall_path)) {
            return(1);
        } else {

            // RAC index old, rebuilding
            statusline(langcode("STIFCC0103"), 1);

            fprintf(stderr,"RAC index is old.  Rebuilding index.\n");
//            XmTextFieldSetString(text,"RAC Index old rebuilding");
//            XtManageChild(text);
//            XmUpdateDisplay(XtParent(text));
        }
    }
    /* ====================================================================    */
    /*    Open the database and index file                */
    /*                                    */
    fdb=fopen(get_data_base_dir("fcc/AMACALL.LST"),"rb");
    if (fdb==NULL) {
        fprintf(stderr,"Build:Could not open RAC data base: %s\n", get_data_base_dir("fcc/AMACALL.LST") );
        return(0);
    }

    fndx=fopen(amacall_path,"w");
    if (fndx==NULL) {
        fprintf(stderr,"Build:Could not open/create RAC data base index: %s\n", amacall_path );
        (void)fclose(fdb);
        return(0);
    }
    /* ====================================================================    */
    /*    Skip past the header to the first callsign (VA2AA)        */
    /*                                    */
    memset(racdata, 0, sizeof(racdata));
    while (!feof(fdb) && strncmp(racdata,"VA",2)) {
        call_offset = (unsigned long)ftell(fdb);
        if (fgets(racdata, (int)sizeof(racdata), fdb)==NULL) {
            fprintf(stderr,"Build:header:Unable to read data base\n");
            (void)fclose(fdb);
            (void)fclose(fndx);
            fprintf(stderr,"rc=0\n");
            return (0);
        }
    }

    /* ====================================================================    */
    /*    write out the current callsign and RBA of the db file         */
    /*    skip 100 records and do it again until no more            */
    /*                                    */
    while (!feof(fdb)) {
        fprintf(fndx,"%6.6s%li\n",racdata,(long)call_offset);
        call_offset = (unsigned long)ftell(fdb);
        for (x=0;x<=100 && !feof(fdb);x++)
            if (fgets(racdata, (int)sizeof(racdata), fdb)==NULL)
                break;
    }
    (void)fclose(fdb);
    (void)fclose(fndx);

//    XmTextFieldSetString(text,"");
//    XtManageChild(text);

    return(1);
}
Пример #8
0
void Jump_location(/*@unused@*/ Widget w, /*@unused@*/ XtPointer clientData, /*@unused@*/ XtPointer callData) {
    static Widget  pane,form, button_ok, button_add, button_delete, button_cancel, locdata, location_name;
    int n;
    Arg al[50];           /* Arg List */
    unsigned int ac = 0;           /* Arg Count */
    Atom delw;
    char location_db_path[MAX_VALUE];

    get_user_base_dir("data/locations_db.dat", location_db_path, 
                      sizeof(location_db_path));

    if(!location_dialog) {

begin_critical_section(&location_dialog_lock, "location_gui.c:Jump_location" );

        location_dialog = XtVaCreatePopupShell(langcode("JMLPO00001"),
                xmDialogShellWidgetClass,
                appshell,
                XmNdeleteResponse,XmDESTROY,
                XmNdefaultPosition, FALSE,
                XmNresize, FALSE,
                XmNfontList, fontlist1,
                NULL);

        pane = XtVaCreateWidget("Jump_location pane",
                xmPanedWindowWidgetClass,
                location_dialog,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        form =  XtVaCreateWidget("Jump_location form",
                xmFormWidgetClass,
                pane,
                XmNfractionBase, 5,
                XmNautoUnmanage, FALSE,
                XmNshadowThickness, 1,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        /*set args for color */
        ac=0;
        XtSetArg(al[ac], XmNvisibleItemCount, 11); ac++;
        XtSetArg(al[ac], XmNtraversalOn, TRUE); ac++;
        XtSetArg(al[ac], XmNshadowThickness, 3); ac++;
        XtSetArg(al[ac], XmNbackground, colors[0x0ff]); ac++;
        XtSetArg(al[ac], XmNselectionPolicy, XmSINGLE_SELECT); ac++;
        XtSetArg(al[ac], XmNscrollBarPlacement, XmBOTTOM_RIGHT); ac++;
        XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
        XtSetArg(al[ac], XmNtopOffset, 5); ac++;
        XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
        XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
        XtSetArg(al[ac], XmNrightOffset, 5); ac++;
        XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
        XtSetArg(al[ac], XmNleftOffset, 5); ac++;
        XtSetArg(al[ac], XmNforeground, MY_FG_COLOR); ac++;
        XtSetArg(al[ac], XmNbackground, MY_BG_COLOR); ac++;
        XtSetArg(al[ac], XmNfontList, fontlist1); ac++;
 
        location_list = XmCreateScrolledList(form,
                "Jump_location list",
                al,
                ac);

        n=1;
        clear_sort_file(location_db_path);
        jump_sort();
        sort_list(location_db_path,200,location_list,&n);

        locdata = XtVaCreateManagedWidget(langcode("JMLPO00003"),
                xmLabelWidgetClass, 
                form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, XtParent(location_list),
                XmNtopOffset, 10,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 5,
                XmNrightAttachment, XmATTACH_NONE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        location_name = XtVaCreateManagedWidget("Jump_location Location_name", 
                xmTextFieldWidgetClass, 
                form,
                XmNeditable,   TRUE,
                XmNcursorPositionVisible, TRUE,
                XmNsensitive, TRUE,
                XmNshadowThickness,      1,
                XmNcolumns,21,
                XmNwidth,((21*7)+2),
                XmNbackground, colors[0x0f],
                XmNtopAttachment,XmATTACH_WIDGET,
                XmNtopWidget, XtParent(location_list),
                XmNtopOffset, 5,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget,locdata,
                XmNrightAttachment,XmATTACH_FORM,
                XmNrightOffset, 5,
                XmNfontList, fontlist1,
                NULL);

        button_ok = XtVaCreateManagedWidget(langcode("JMLPO00002"),
                xmPushButtonGadgetClass, 
                form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, locdata,
                XmNtopOffset,15,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset,5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 0,
                XmNleftOffset, 3,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 1,
                XmNnavigationType, XmTAB_GROUP,
                XmNfontList, fontlist1,
                NULL);

        button_add = XtVaCreateManagedWidget(langcode("UNIOP00007"),
                xmPushButtonGadgetClass, 
                form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, locdata,
                XmNtopOffset,15,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset,5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 1,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 2,
                XmNnavigationType, XmTAB_GROUP,
                XmNfontList, fontlist1,
                NULL);

        button_delete = XtVaCreateManagedWidget(langcode("UNIOP00008"),
                xmPushButtonGadgetClass, 
                form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, locdata,
                XmNtopOffset,15,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset,5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 2,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 3,
                XmNnavigationType, XmTAB_GROUP,
                XmNfontList, fontlist1,
                NULL);

        button_cancel = XtVaCreateManagedWidget(langcode("UNIOP00003"),
                xmPushButtonGadgetClass, 
                form,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, locdata,
                XmNtopOffset,15,
                XmNbottomAttachment, XmATTACH_FORM,
                XmNbottomOffset,5,
                XmNleftAttachment, XmATTACH_POSITION,
                XmNleftPosition, 4,
                XmNrightAttachment, XmATTACH_POSITION,
                XmNrightPosition, 5,
                XmNrightOffset, 3,
                XmNnavigationType, XmTAB_GROUP,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(button_cancel, XmNactivateCallback, location_destroy_shell, location_dialog);
        XtAddCallback(button_ok, XmNactivateCallback, location_view, NULL);
        XtAddCallback(button_add, XmNactivateCallback, location_add, location_name);
        XtAddCallback(button_delete, XmNactivateCallback, location_delete, NULL);

        pos_dialog(location_dialog);

        delw = XmInternAtom(XtDisplay(location_dialog),"WM_DELETE_WINDOW", FALSE);
        XmAddWMProtocolCallback(location_dialog, delw, location_destroy_shell, (XtPointer)location_dialog);

        XtManageChild(form);
        XtManageChild(location_list);
        XtVaSetValues(location_list, XmNbackground, colors[0x0f], NULL);
        XtManageChild(pane);

end_critical_section(&location_dialog_lock, "location_gui.c:location_destroy_shell" );

        XtPopup(location_dialog,XtGrabNone);
        fix_dialog_size(location_dialog);

        // Move focus to the Close button.  This appears to highlight the
        // button fine, but we're not able to hit the <Enter> key to
        // have that default function happen.  Note:  We _can_ hit the
        // <SPACE> key, and that activates the option.
//        XmUpdateDisplay(location_dialog);
        XmProcessTraversal(button_cancel, XmTRAVERSE_CURRENT);

    } else {
        XtPopup(location_dialog,XtGrabNone);
        (void)XRaiseWindow(XtDisplay(location_dialog), XtWindow(location_dialog));
    }
}
Пример #9
0
void draw_tiger_map (Widget w,
        char *filenm,
        int destination_pixmap,
        int nocache) {  // For future implementation of a "refresh cached map" option
    char file[MAX_FILENAME];        // Complete path/name of image file
    char short_filenm[MAX_FILENAME];
    FILE *f;                        // Filehandle of image file
    char fileimg[MAX_FILENAME];     // Ascii name of image file, read from GEO file
    char tigertmp[MAX_FILENAME*2];  // Used for putting together the tigermap query
    int width, height;
    tiepoint tp[2];                 // Calibration points for map, read in from .geo file
    register long map_c_T, map_c_L; // map delta NW edge coordinates, DNN: these should be signed
    register long tp_c_dx, tp_c_dy; // tiepoint coordinate differences
    unsigned long c_x_min,  c_y_min;// top left coordinates of map inside screen
    unsigned long c_y_max;          // bottom right coordinates of map inside screen
    double c_x;                     // Xastir coordinates 1/100 sec, 0 = 180°W
    double c_y;                     // Xastir coordinates 1/100 sec, 0 =  90°N

    long map_y_0;                   // map pixel pointer prior to TM adjustment
    register long map_x, map_y;     // map pixel pointers, DNN: this was a float, chg to long
    long map_x_min, map_x_max;      // map boundaries for in screen part of map
    long map_y_min, map_y_max;      //
    long map_x_ctr;                 // half map width in pixel
    long map_y_ctr;                 // half map height in pixel
    int map_seen = 0;
    int map_act;
    int map_done;

    long map_c_yc;                  // map center, vert coordinate
    long map_c_xc;                  // map center, hor  coordinate
    double map_c_dx, map_c_dy;      // map coordinates increment (pixel width)
    double c_dx;                    // adjusted map pixel width

    long scr_x,  scr_y;             // screen pixel plot positions
    long scr_xp, scr_yp;            // previous screen plot positions
    int  scr_dx, scr_dy;            // increments in screen plot positions
    long scr_x_mc;                  // map center in screen units

    long scr_c_xr;

    long scale_xa;                  // adjusted for topo maps
    double scale_x_nm;              // nm per Xastir coordinate unit
    long scale_x0;                  // at widest map area

    char local_filename[MAX_FILENAME];
    
    ExceptionInfo exception;
    Image *image;
    ImageInfo *image_info;
    PixelPacket *pixel_pack;
    PixelPacket temp_pack;
    IndexPacket *index_pack;
    int l;
    XColor my_colors[256];
    double left, right, top, bottom, map_width, map_height;
    double lat_center  = 0;
    double long_center = 0;

    char map_it[MAX_FILENAME];
    char tmpstr[100];
    int geo_image_width;        // Image width  from GEO file
    int geo_image_height;       // Image height from GEO file

    // initialize this
    local_filename[0]='\0';

    // Create a shorter filename for display (one that fits the
    // status line more closely).  Subtract the length of the
    // "Indexing " and/or "Loading " strings as well.
    if (strlen(filenm) > (41 - 9)) {
        int avail = 41 - 11;
        int new_len = strlen(filenm) - avail;

        xastir_snprintf(short_filenm,
            sizeof(short_filenm),
            "..%s",
            &filenm[new_len]);
    }
    else {
        xastir_snprintf(short_filenm,
            sizeof(short_filenm),
            "%s",
            filenm);
    }

    xastir_snprintf(map_it,
        sizeof(map_it),
        langcode ("BBARSTA028"),
        short_filenm);
    statusline(map_it,0);       // Loading ...


        
    // Check whether we're indexing or drawing the map
    if ( (destination_pixmap == INDEX_CHECK_TIMESTAMPS)
            || (destination_pixmap == INDEX_NO_TIMESTAMPS) ) {

        // We're indexing only.  Save the extents in the index.
        // Force the extents to the edges of the earth for the
        // index file.
        index_update_xastir(filenm, // Filename only
            64800000l,      // Bottom
            0l,             // Top
            0l,             // Left
            129600000l,     // Right
            0);             // Default Map Level

        // Update statusline
        xastir_snprintf(map_it,
            sizeof(map_it),
            langcode ("BBARSTA039"),
            short_filenm);
        statusline(map_it,0);       // Loading/Indexing ...

        return; // Done indexing this file
    }


    // Tiepoint for upper left screen corner
    //
    tp[0].img_x = 0;                // Pixel Coordinates
    tp[0].img_y = 0;                // Pixel Coordinates
    tp[0].x_long = NW_corner_longitude;   // Xastir Coordinates
    tp[0].y_lat  = NW_corner_latitude;    // Xastir Coordinates

    // Tiepoint for lower right screen corner
    //
    tp[1].img_x =  screen_width - 1; // Pixel Coordinates
    tp[1].img_y = screen_height - 1; // Pixel Coordinates 

    tp[1].x_long = SE_corner_longitude; // Xastir Coordinates
    tp[1].y_lat  =  SE_corner_latitude; // Xastir Coordinates

    left = (double)((NW_corner_longitude - 64800000l )/360000.0);   // Lat/long Coordinates
    top = (double)(-((NW_corner_latitude - 32400000l )/360000.0));  // Lat/long Coordinates
    right = (double)((SE_corner_longitude - 64800000l)/360000.0);//Lat/long Coordinates
    bottom = (double)(-((SE_corner_latitude - 32400000l)/360000.0));//Lat/long Coordinates

    map_width = right - left;   // Lat/long Coordinates
    map_height = top - bottom;  // Lat/long Coordinates

    geo_image_width  = screen_width;
    geo_image_height = screen_height;

    long_center = (left + right)/2.0l;
    lat_center  = (top + bottom)/2.0l;

//  Example query to the census map server....
/*        xastir_snprintf(fileimg, sizeof(fileimg), 
        "\'http://tiger.census.gov/cgi-bin/mapper/map.gif?on=CITIES&on=GRID&on=counties&on=majroads&on=places&&on=interstate&on=states&on=ushwy&on=statehwy&lat=%f\046lon=%f\046wid=%f\046ht=%f\046iwd=%i\046iht=%i\'",\
                   lat_center, long_center, map_width, map_height, tp[1].img_x + 1, tp[1].img_y + 1); */

    xastir_snprintf(tigertmp, sizeof(tigertmp), "http://tiger.census.gov/cgi-bin/mapper/map.gif?");

    if (tiger_show_grid)
        strncat(tigertmp, "&on=GRID", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=GRID", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_counties)
        strncat(tigertmp, "&on=counties", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=counties", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_cities)
        strncat(tigertmp, "&on=CITIES", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=CITIES", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_places)
        strncat(tigertmp, "&on=places", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=places", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_majroads)
        strncat(tigertmp, "&on=majroads", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=majroads", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_streets)
        strncat(tigertmp, "&on=streets", sizeof(tigertmp) - 1 - strlen(tigertmp));
    // Don't turn streets off since this will automagically show up as you zoom in.

    if (tiger_show_railroad)
        strncat(tigertmp, "&on=railroad", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=railroad", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_states)
        strncat(tigertmp, "&on=states", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=states", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_interstate)
        strncat(tigertmp, "&on=interstate", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=interstate", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_ushwy)
        strncat(tigertmp, "&on=ushwy", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=ushwy", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_statehwy)
        strncat(tigertmp, "&on=statehwy", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=statehwy", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_water)
        strncat(tigertmp, "&on=water", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=water", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_lakes)
        strncat(tigertmp, "&on=shorelin", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=shorelin", sizeof(tigertmp) - 1 - strlen(tigertmp));

    if (tiger_show_misc)
        strncat(tigertmp, "&on=miscell", sizeof(tigertmp) - 1 - strlen(tigertmp));
    else
        strncat(tigertmp, "&off=miscell", sizeof(tigertmp) - 1 - strlen(tigertmp));

    xastir_snprintf(tmpstr, sizeof(tmpstr), "&lat=%f\046lon=%f\046", lat_center, long_center);    
    strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp));
    xastir_snprintf(tmpstr, sizeof(tmpstr), "wid=%f\046ht=%f\046", map_width, map_height);
    strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp));
    xastir_snprintf(tmpstr, sizeof(tmpstr), "iwd=%i\046iht=%i", tp[1].img_x + 1, tp[1].img_y + 1);
    strncat (tigertmp, tmpstr, sizeof(tigertmp) - 1 - strlen(tigertmp));
    xastir_snprintf(fileimg, sizeof(fileimg), "%s", tigertmp);

    if (debug_level & 512) {
          fprintf(stderr,"left side is %f\n", left);
          fprintf(stderr,"right side is %f\n", right);
          fprintf(stderr,"top  is %f\n", top);
          fprintf(stderr,"bottom is %f\n", bottom);
          fprintf(stderr,"lat center is %f\n", lat_center);
          fprintf(stderr,"long center is %f\n", long_center);
          fprintf(stderr,"screen width is %li\n", screen_width);
          fprintf(stderr,"screen height is %li\n", screen_height);
          fprintf(stderr,"map width is %f\n", map_width);
          fprintf(stderr,"map height is %f\n", map_height);
          fprintf(stderr,"fileimg is %s\n", fileimg);
          fprintf(stderr,"ftp or http file: %s\n", fileimg);
    }


// Hopefully this will eventually allow us to get maps in the background
//    while (sometimeout !=0 && local_filename[0]==NULL){

    if  (local_filename[0]=='\0' ){

        if (debug_level & 512 ) { 
            fprintf(stderr,"tiger_local_file=<%s>\n",local_filename);
        }

        HandlePendingEvents(app_context);
        if (interrupt_drawing_now) {
            // Update to screen
            (void)XCopyArea(XtDisplay(da),
                pixmap,
                XtWindow(da),
                gc,
                0,
                0,
                (unsigned int)screen_width,
                (unsigned int)screen_height,
                0,
                0);
            return;
        }

        get_tiger_local_file(local_filename,fileimg); 

    }

// whackadoodle


    // Tell ImageMagick where to find it
    xastir_snprintf(file,
        sizeof(file),
        "%s",
        local_filename);

    GetExceptionInfo(&exception);

    image_info=CloneImageInfo((ImageInfo *) NULL);

    xastir_snprintf(image_info->filename,
        sizeof(image_info->filename),
        "%s",
        file);

    if (debug_level & 512) {
           fprintf(stderr,"Copied %s into image info.\n", file);
           fprintf(stderr,"image_info got: %s\n", image_info->filename);
           fprintf(stderr,"Entered ImageMagick code.\n");
           fprintf(stderr,"Attempting to open: %s\n", image_info->filename);
    }

    // We do a test read first to see if the file exists, so we
    // don't kill Xastir in the ReadImage routine.
    f = fopen (image_info->filename, "r");
    if (f == NULL) {
        if (debug_level & 512)
            fprintf(stderr,"File could not be read\n");

#ifdef USE_MAP_CACHE

        // clear from cache if bad    
        if (map_cache_del(fileimg)) {
            if (debug_level & 512) {
                fprintf(stderr,"Couldn't delete unreadable map from cache\n");
            }
        }
#endif
         
        if (image_info)
            DestroyImageInfo(image_info);
	DestroyExceptionInfo(&exception);
        return;
    }
    (void)fclose (f);


    image = ReadImage(image_info, &exception);

    if (image == (Image *) NULL) {
        MagickWarning(exception.severity, exception.reason, exception.description);
        //fprintf(stderr,"MagickWarning\n");

#ifdef USE_MAP_CACHE
        // clear from cache if bad    
        if (map_cache_del(fileimg)) {
            if (debug_level & 512) {
                fprintf(stderr,"Couldn't delete map from cache\n");
            }
        }
#endif

        if (image_info)
            DestroyImageInfo(image_info);
	DestroyExceptionInfo(&exception);
        return;
    }


    if (debug_level & 512)
        fprintf(stderr,"Color depth is %i \n", (int)image->depth);

    if (image->colorspace != RGBColorspace) {
        fprintf(stderr,"TBD: I don't think we can deal with colorspace != RGB");
        if (image)
            DestroyImage(image);
        if (image_info)
            DestroyImageInfo(image_info);
	DestroyExceptionInfo(&exception);
        return;
    }

    width = image->columns;
    height = image->rows;

    //  Code to mute the image so it's not as bright.
/*    if (raster_map_intensity < 1.0) {
        char tempstr[30];

        if (debug_level & 512)
            fprintf(stderr,"level=%s\n", tempstr);

        xastir_snprintf(tempstr,
            sizeof(tempstr),
            "%d, 100, 100",
            (int)(raster_map_intensity * 100.0));

        ModulateImage(image, tempstr);
    }
*/


    // If were are drawing to a low bpp display (typically < 8bpp)
    // try to reduce the number of colors in an image.
    // This may take some time, so it would be best to do ahead of
    // time if it is a static image.
#if (MagickLibVersion < 0x0540)
    if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL) > 128) {
#else   // MagickLib >= 540
    if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL, &exception) > 128) {
#endif  // MagickLib Version

        if (image->storage_class == PseudoClass) {
#if (MagickLibVersion < 0x0549)
            CompressColormap(image); // Remove duplicate colors
#else // MagickLib >= 0x0549
            CompressImageColormap(image); // Remove duplicate colors
#endif  // MagickLibVersion < 0x0549
        }

        // Quantize down to 128 will go here...
    }


    pixel_pack = GetImagePixels(image, 0, 0, image->columns, image->rows);
    if (!pixel_pack) {
        fprintf(stderr,"pixel_pack == NULL!!!");
        if (image)
            DestroyImage(image);
        if (image_info)
            DestroyImageInfo(image_info);
	DestroyExceptionInfo(&exception);
        return;
    }


    index_pack = GetIndexes(image);
    if (image->storage_class == PseudoClass && !index_pack) {
        fprintf(stderr,"PseudoClass && index_pack == NULL!!!");
        if (image)
            DestroyImage(image);
        if (image_info)
            DestroyImageInfo(image_info);
	DestroyExceptionInfo(&exception);
        return;
    }


    if (image->storage_class == PseudoClass && image->colors <= 256) {
        for (l = 0; l < (int)image->colors; l++) {
            // Need to check how to do this for ANY image, as ImageMagick can read in all sorts
            // of image files
            temp_pack = image->colormap[l];
            if (debug_level & 512)
                fprintf(stderr,"Colormap color is %i  %i  %i \n",
                       temp_pack.red, temp_pack.green, temp_pack.blue);

            // Here's a tricky bit:  PixelPacket entries are defined as Quantum's.  Quantum
            // is defined in /usr/include/magick/image.h as either an unsigned short or an
            // unsigned char, depending on what "configure" decided when ImageMagick was installed.
            // We can determine which by looking at MaxRGB or QuantumDepth.
            //
            if (QuantumDepth == 16) {   // Defined in /usr/include/magick/image.h
                if (debug_level & 512)
                    fprintf(stderr,"Color quantum is [0..65535]\n");
                my_colors[l].red   = temp_pack.red * raster_map_intensity;
                my_colors[l].green = temp_pack.green * raster_map_intensity;
                my_colors[l].blue  = temp_pack.blue * raster_map_intensity;
            }
            else {  // QuantumDepth = 8
                if (debug_level & 512)
                    fprintf(stderr,"Color quantum is [0..255]\n");
                my_colors[l].red   = (temp_pack.red << 8) * raster_map_intensity;
                my_colors[l].green = (temp_pack.green << 8) * raster_map_intensity;
                my_colors[l].blue  = (temp_pack.blue << 8) * raster_map_intensity;
            }

            // Get the color allocated on < 8bpp displays. pixel color is written to my_colors.pixel
            if (visual_type == NOT_TRUE_NOR_DIRECT) {
//                XFreeColors(XtDisplay(w), cmap, &(my_colors[l].pixel),1,0);
                XAllocColor(XtDisplay(w), cmap, &my_colors[l]);
            }
            else {
                pack_pixel_bits(my_colors[l].red, my_colors[l].green, my_colors[l].blue,
                                &my_colors[l].pixel);
            }

            if (debug_level & 512)
                fprintf(stderr,"Color allocated is %li  %i  %i  %i \n", my_colors[l].pixel,
                       my_colors[l].red, my_colors[l].blue, my_colors[l].green);
        }
    }



    /*
    * Here are the corners of our viewport, using the Xastir
    * coordinate system.  Notice that Y is upside down:
    *
    *   left edge of view = NW_corner_longitude
    *  right edge of view = SE_corner_longitude
    *    top edge of view =  NW_corner_latitude
    * bottom edge of view =  SE_corner_latitude
    *
    * The corners of our map will soon be (after translating the
    * tiepoints to the corners if they're not already there):
    *
    *   left edge of map = tp[0].x_long   in Xastir format
    *  right edge of map = tp[1].x_long
    *    top edge of map = tp[0].y_lat
    * bottom edge of map = tp[1].y_lat
    *
    */
    map_c_L = tp[0].x_long - NW_corner_longitude;     // map left coordinate
    map_c_T = tp[0].y_lat  - NW_corner_latitude;      // map top  coordinate

    tp_c_dx = (long)(tp[1].x_long - tp[0].x_long);//  Width between tiepoints
    tp_c_dy = (long)(tp[1].y_lat  - tp[0].y_lat); // Height between tiepoints


    // Check for tiepoints being in wrong relation to one another
    if (tp_c_dx < 0) 
        tp_c_dx = -tp_c_dx;       // New  width between tiepoints
    if (tp_c_dy < 0) 
        tp_c_dy = -tp_c_dy;       // New height between tiepoints

    // Calculate step size per pixel
    map_c_dx = ((double) tp_c_dx / abs(tp[1].img_x - tp[0].img_x));
    map_c_dy = ((double) tp_c_dy / abs(tp[1].img_y - tp[0].img_y));

    // Scaled screen step size for use with XFillRectangle below
    scr_dx = (int) (map_c_dx / scale_x) + 1;
    scr_dy = (int) (map_c_dy / scale_y) + 1;

    // calculate top left map corner from tiepoints
    if (tp[0].img_x != 0) {
        tp[0].x_long -= (tp[0].img_x * map_c_dx);   // map left edge longitude
        map_c_L = tp[0].x_long - NW_corner_longitude;     // delta ??
        tp[0].img_x = 0;
        if (debug_level & 512)
            fprintf(stderr,"Translated tiepoint_0 x: %d\t%lu\n", tp[0].img_x, tp[0].x_long);
    }
    if (tp[0].img_y != 0) {
        tp[0].y_lat -= (tp[0].img_y * map_c_dy);    // map top edge latitude
        map_c_T = tp[0].y_lat - NW_corner_latitude;
        tp[0].img_y = 0;
        if (debug_level & 512)
            fprintf(stderr,"Translated tiepoint_0 y: %d\t%lu\n", tp[0].img_y, tp[0].y_lat);
    }

    // calculate bottom right map corner from tiepoints
    // map size is geo_image_width / geo_image_height
    if (tp[1].img_x != (geo_image_width - 1) ) {
        tp[1].img_x = geo_image_width - 1;
        tp[1].x_long = tp[0].x_long + (tp[1].img_x * map_c_dx); // right
        if (debug_level & 512)
            fprintf(stderr,"Translated tiepoint_1 x: %d\t%lu\n", tp[1].img_x, tp[1].x_long);
    }
    if (tp[1].img_y != (geo_image_height - 1) ) {
        tp[1].img_y = geo_image_height - 1;
        tp[1].y_lat = tp[0].y_lat + (tp[1].img_y * map_c_dy);   // bottom
        if (debug_level & 512)
            fprintf(stderr,"Translated tiepoint_1 y: %d\t%lu\n", tp[1].img_y, tp[1].y_lat);
    }

    if (debug_level & 512) {
        fprintf(stderr,"X tiepoint width: %ld\n", tp_c_dx);
        fprintf(stderr,"Y tiepoint width: %ld\n", tp_c_dy);
        fprintf(stderr,"Loading imagemap: %s\n", file);
        fprintf(stderr,"\nImage: %s\n", file);
        fprintf(stderr,"Image size %d %d\n", geo_image_width, geo_image_height);
        fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n",
            map_c_L, map_c_T, map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y));
        fprintf(stderr,"Image size %d %d\n", width, height);
#if (MagickLibVersion < 0x0540)
        fprintf(stderr,"Unique colors = %d\n", GetNumberColors(image, NULL));
#else // MagickLib < 540
        fprintf(stderr,"Unique colors = %ld\n", GetNumberColors(image, NULL, &exception));
#endif // MagickLib < 540
        fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n", map_c_L, map_c_T,
            map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y));
        fprintf(stderr,"image matte is %i\n", image->matte);
    } // debug_level & 512

    // draw the image from the file out to the map screen

    // Get the border values for the X and Y for loops used
    // for the XFillRectangle call later.

    map_c_yc = (tp[0].y_lat + tp[1].y_lat) / 2;     // vert center of map as reference
    map_y_ctr = (long)(height / 2 +0.499);
    scale_x0 = get_x_scale(0,map_c_yc,scale_y);     // reference scaling at vert map center

    map_c_xc  = (tp[0].x_long + tp[1].x_long) / 2;  // hor center of map as reference
    map_x_ctr = (long)(width  / 2 +0.499);
    scr_x_mc  = (map_c_xc - NW_corner_longitude) / scale_x; // screen coordinates of map center

    // calculate map pixel range in y direction that falls into screen area
    c_y_max = 0ul;
    map_y_min = map_y_max = 0l;
    for (map_y_0 = 0, c_y = tp[0].y_lat; map_y_0 < (long)height; map_y_0++, c_y += map_c_dy) {
        scr_y = (c_y - NW_corner_latitude) / scale_y;   // current screen position
        if (scr_y > 0) {
            if (scr_y < screen_height) {
                map_y_max = map_y_0;          // update last map pixel in y
                c_y_max = (unsigned long)c_y;// bottom map inside screen coordinate
            } else
                break;                      // done, reached bottom screen border
        } else {                            // pixel is above screen
            map_y_min = map_y_0;              // update first map pixel in y
        }
    }
    c_y_min = (unsigned long)(tp[0].y_lat + map_y_min * map_c_dy);   // top map inside screen coordinate

        map_x_min = map_x_max = 0l;
        for (map_x = 0, c_x = tp[0].x_long; map_x < (long)width; map_x++, c_x += map_c_dx) {
            scr_x = (c_x - NW_corner_longitude)/ scale_x;  // current screen position
            if (scr_x > 0) {
                if (scr_x < screen_width)
                    map_x_max = map_x;          // update last map pixel in x
                else
                    break;                      // done, reached right screen border
            } else {                            // pixel is left from screen
                map_x_min = map_x;              // update first map pixel in x
            }
        }
        c_x_min = (unsigned long)(tp[0].x_long + map_x_min * map_c_dx);   // left map inside screen coordinate

    scr_yp = -1;
    scr_c_xr = SE_corner_longitude;
    c_dx = map_c_dx;                            // map pixel width
    scale_xa = scale_x0;                        // the compiler likes it ;-)

    map_done = 0;
    map_act  = 0;
    map_seen = 0;
    scr_y = screen_height - 1;


    // loop over map pixel rows
    for (map_y_0 = map_y_min, c_y = (double)c_y_min; (map_y_0 <= map_y_max); map_y_0++, c_y += map_c_dy) {

        HandlePendingEvents(app_context);
        if (interrupt_drawing_now) {
            if (image)
               DestroyImage(image);
            if (image_info)
               DestroyImageInfo(image_info);
            // Update to screen
            (void)XCopyArea(XtDisplay(da),
                pixmap,
                XtWindow(da),
                gc,
                0,
                0,
                (unsigned int)screen_width,
                (unsigned int)screen_height,
                0,
                0);
            DestroyExceptionInfo(&exception);
            return;
        }

        scr_y = (c_y - NW_corner_latitude) / scale_y;
        if (scr_y != scr_yp) {                  // don't do a row twice
            scr_yp = scr_y;                     // remember as previous y
            scr_xp = -1;
            // loop over map pixel columns
            map_act = 0;
            scale_x_nm = calc_dscale_x(0,(long)c_y) / 1852.0;  // nm per Xastir coordinate
            for (map_x = map_x_min, c_x = (double)c_x_min; map_x <= map_x_max; map_x++, c_x += c_dx) {
                scr_x = (c_x - NW_corner_longitude) / scale_x;
                if (scr_x != scr_xp) {      // don't do a pixel twice
                    scr_xp = scr_x;         // remember as previous x
                    map_y = map_y_0;

                    if (map_y >= 0 && map_y <= tp[1].img_y) { // check map boundaries in y direction
                        map_seen = 1;
                        map_act = 1;    // detects blank screen rows (end of map)

                        // now copy a pixel from the map image to the screen
                        l = map_x + map_y * image->columns;
                        if (image->storage_class == PseudoClass) {
                            XSetForeground(XtDisplay(w), gc, my_colors[index_pack[l]].pixel);
                        }
                        else {
                            // It is not safe to assume that the red/green/blue
                            // elements of pixel_pack of type Quantum are the
                            // same as the red/green/blue of an XColor!
                            if (QuantumDepth==16) {
                                my_colors[0].red=pixel_pack[l].red;
                                my_colors[0].green=pixel_pack[l].green;
                                my_colors[0].blue=pixel_pack[l].blue;
                            }
                            else { // QuantumDepth=8
                                // shift the bits of the 8-bit quantity so that
                                // they become the high bigs of my_colors.*
                                my_colors[0].red=pixel_pack[l].red<<8;
                                my_colors[0].green=pixel_pack[l].green<<8;
                                my_colors[0].blue=pixel_pack[l].blue<<8;
                            }
                            // NOW my_colors has the right r,g,b range for
                            // pack_pixel_bits
                            pack_pixel_bits(my_colors[0].red * raster_map_intensity,
                                            my_colors[0].green * raster_map_intensity,
                                            my_colors[0].blue * raster_map_intensity,
                                            &my_colors[0].pixel);
                            XSetForeground(XtDisplay(w), gc, my_colors[0].pixel);
                        }
                        (void)XFillRectangle (XtDisplay (w),pixmap,gc,scr_x,scr_y,scr_dx,scr_dy);
                    } // check map boundaries in y direction
                }
            } // loop over map pixel columns
            if (map_seen && !map_act)
                map_done = 1;
        }
    } // loop over map pixel rows

    if (image)
       DestroyImage(image);
    if (image_info)
       DestroyImageInfo(image_info);
    DestroyExceptionInfo(&exception);
}
Пример #10
0
void view_message_print_record(Message *m_fill) {
    int pos;
    char *temp;
    int i;
    int my_size = 200;
    char temp_my_course[10];
    XmTextPosition drop_ptr;
    int distance;


    // Make sure it's within our distance range we have set
    distance = (int)distance_from_my_station(m_fill->from_call_sign,temp_my_course);

    if (Read_messages_mine_only
            || (!Read_messages_mine_only
                && ( (vm_range == 0) || (distance <= vm_range) ) ) ) {
 
        // Check that it's coming from the correct type of interface
        // Compare Read_messages_packet_data_type against the port
        // type associated with data_port to determine whether or
        // not to display it.
        //
        // I = Internet
        // L = Local
        // T = TNC
        // F = File
        //
        switch (Read_messages_packet_data_type) {

            case 2:     // Display NET data only
                // if not network_interface, return
                if (m_fill->data_via != 'I')
                    return; // Don't display it
                break;

            case 1:     // Display TNC data only
                // if not local_tnc_interface, return
                if (m_fill->data_via != 'T')
                    return; // Don't display it
                break;

            case 0:     // Display both TNC and NET data
            default:
                break;
        }

        // Check for my stations only if set
        if (Read_messages_mine_only) {
            char short_call[MAX_CALLSIGN];
            char *p;

            xastir_snprintf(short_call,
                sizeof(short_call),
                "%s",
                my_callsign);
            if ( (p = index(short_call,'-')) ) {
                *p = '\0';  // Terminate it
            }

            if (!strstr(m_fill->call_sign, short_call)
                    && !strstr(m_fill->from_call_sign, short_call)) {
                return;
            }
        }

        if ((temp = malloc((size_t)my_size)) == NULL)
            return;

        sprintf(temp,"%-9s>%-9s %s:%5s %s:%c :%s\n",
            m_fill->from_call_sign,
            m_fill->call_sign,
            langcode("WPUPMSB013"),
            m_fill->seq,
            langcode("WPUPMSB014"),
            m_fill->type,
            m_fill->message_line);

        pos = (int)XmTextGetLastPosition(view_messages_text);


        XmTextInsert(view_messages_text, pos, temp);
        pos += strlen(temp);
        while (pos > view_message_limit) {
            for (drop_ptr = i = 0; i < 3; i++) {
                (void)XmTextFindString(view_messages_text, drop_ptr, "\n", XmTEXT_FORWARD, &drop_ptr);
                drop_ptr++;
            }
            XmTextReplace(view_messages_text, 0, drop_ptr, "");
            pos = (int)XmTextGetLastPosition(view_messages_text);
        }
        XtVaSetValues(view_messages_text, XmNcursorPosition, pos, NULL);

        free(temp);
    }
}
Пример #11
0
void location_add(/*@unused@*/ Widget w, XtPointer clientData, /*@unused@*/ XtPointer callData) {
    char name[100];
    char s_long[20];
    char s_lat[20];
    FILE *f, *fout;
    char temp[200];
    char *temp_ptr;
    Widget my_text = (Widget) clientData;
    int len,n,found;
    char location_file_path[MAX_VALUE];
    char location_db_path[MAX_VALUE];

    get_user_base_dir("config/locations.sys", location_file_path, 
                      sizeof(location_file_path));

    get_user_base_dir("data/locations_db.dat", location_db_path, 
                      sizeof(location_db_path));


    temp_ptr = XmTextFieldGetString(my_text);
    xastir_snprintf(name,
        sizeof(name),
        "%s",
        temp_ptr);
    XtFree(temp_ptr);

    (void)remove_trailing_spaces(name);
    XmTextFieldSetString(my_text,"");
    /* should check for name used already */
    found=0;
    f=fopen(location_file_path,"r");
    if (f!=NULL) {
        while (!feof(f) && !found) {
            (void)get_line(f,temp,200);
            if (!feof(f) && strlen(temp)>8) {
                temp_ptr=strtok(temp,"|");  /* get the name */
                if (temp_ptr!=NULL) {
                    if (strcmp(name,temp)==0)
                        found=1;
                }
            }
        }
        (void)fclose(f);
    }
    else
        fprintf(stderr,"Couldn't open file: %s\n", location_file_path );

    if (!found) {
        /* delete entire list available */
        XmListDeleteAllItems(location_list);
        len = (int)strlen(name);
        if (len>0 && len<100){
            fout = fopen(location_file_path,"a");
            if (fout!=NULL) {
                convert_lat_l2s(center_latitude, s_lat, sizeof(s_lat), CONVERT_HP_NOSP);
                convert_lon_l2s(center_longitude, s_long, sizeof(s_long), CONVERT_HP_NOSP);
                fprintf(fout,"%s|%s %s %ld\n",name,s_lat,s_long,scale_y);
                (void)fclose(fout);
            }
            else
                fprintf(stderr,"Couldn't open file: %s\n", location_file_path );
        } else
            popup_message_always(langcode("POPEM00022"),langcode("POPEM00023"));

        /* resort the list and put it back up */
        n=1;
        clear_sort_file(location_db_path);
        jump_sort();
        sort_list(location_db_path,200,location_list,&n);
    } else
        popup_message_always(langcode("POPEM00022"),langcode("POPEM00024")); /* dupe name */
}
Пример #12
0
void view_all_messages( /*@unused@*/ Widget w, /*@unused@*/ XtPointer clientData, /*@unused@*/ XtPointer callData) {
    Widget pane, my_form, button_close, dist, dist_units;
    Widget option_box, tnc_data, net_data, tnc_net_data,
        read_mine_only_button;
    unsigned int n;
#define NCNT 50
#define IncN(n) if (n< NCNT) n++; else fprintf(stderr, "Oops, too many arguments for array!\a")
    Arg args[NCNT];
    Atom delw;
    char temp[10];

    if (!All_messages_dialog) {

begin_critical_section(&All_messages_dialog_lock, "view_message_gui.c:view_all_messages" );

        All_messages_dialog = XtVaCreatePopupShell(langcode("AMTMW00001"),
                xmDialogShellWidgetClass, appshell,
                XmNdeleteResponse, XmDESTROY,
                XmNdefaultPosition, FALSE,
                XmNfontList, fontlist1,
                NULL);

        pane = XtVaCreateWidget("view_all_messages pane",
                xmPanedWindowWidgetClass, 
                All_messages_dialog,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        my_form =  XtVaCreateWidget("view_all_messages my_form",
                xmFormWidgetClass, 
                pane,
                XmNfractionBase, 5,
                XmNautoUnmanage, FALSE,
                XmNshadowThickness, 1,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                NULL);

        dist = XtVaCreateManagedWidget(langcode("AMTMW00002"),
                xmLabelWidgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 10,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_FORM,
                XmNleftOffset, 10,
                XmNrightAttachment, XmATTACH_NONE,
                XmNtraversalOn, FALSE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        vm_dist_data = XtVaCreateManagedWidget("view_all_messages dist_data", 
                xmTextFieldWidgetClass, 
                my_form,
                XmNeditable,   TRUE,
                XmNcursorPositionVisible, TRUE,
                XmNsensitive, TRUE,
                XmNshadowThickness,    1,
                XmNcolumns, 8,
                XmNwidth, ((8*7)+2),
                XmNmaxLength, 8,
                XmNbackground, colors[0x0f],
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 5,
                XmNbottomAttachment,XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, dist,
                XmNleftOffset, 10,
                XmNrightAttachment,XmATTACH_NONE,
                XmNfontList, fontlist1,
                NULL);

        dist_units = XtVaCreateManagedWidget((english_units?langcode("UNIOP00004"):langcode("UNIOP00005")),
                xmLabelWidgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 10,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, vm_dist_data,
                XmNleftOffset, 10,
                XmNrightAttachment, XmATTACH_NONE,
                XmNtraversalOn, FALSE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        button_range = XtVaCreateManagedWidget(langcode("BULMW00003"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, dist_units,
                XmNleftOffset, 10,
                XmNrightAttachment, XmATTACH_NONE,
                XmNnavigationType, XmTAB_GROUP,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(button_range, XmNactivateCallback, All_messages_change_range, All_messages_dialog);

        button_close = XtVaCreateManagedWidget(langcode("UNIOP00003"),
                xmPushButtonGadgetClass, 
                my_form,
                XmNtopAttachment, XmATTACH_FORM,
                XmNtopOffset, 5,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, button_range,
                XmNleftOffset, 10,
                XmNrightAttachment, XmATTACH_FORM,
                XmNnavigationType, XmTAB_GROUP,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(button_close, XmNactivateCallback, All_messages_destroy_shell, All_messages_dialog);

        n=0;
        XtSetArg(args[n],XmNforeground, MY_FG_COLOR); n++;
        XtSetArg(args[n],XmNbackground, MY_BG_COLOR); n++;
        XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
        XtSetArg(args[n], XmNtopWidget, dist); n++;
        XtSetArg(args[n], XmNtopOffset, 5); n++;
        XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
        XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
        XtSetArg(args[n], XmNleftOffset, 5); n++;
        XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
        XtSetArg(args[n], XmNfontList, fontlist1); n++;

        option_box = XmCreateRadioBox(my_form,
                "Vew Messages option box",
                args,
                n);

        XtVaSetValues(option_box,
                XmNpacking, XmPACK_TIGHT,
                XmNorientation, XmHORIZONTAL,
                NULL);

        tnc_data = XtVaCreateManagedWidget(langcode("WPUPDPD002"),
                xmToggleButtonGadgetClass,
                option_box,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(tnc_data,XmNvalueChangedCallback,Read_messages_packet_toggle,"1");

        net_data = XtVaCreateManagedWidget(langcode("WPUPDPD003"),
                xmToggleButtonGadgetClass,
                option_box,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(net_data,XmNvalueChangedCallback,Read_messages_packet_toggle,"2");

        tnc_net_data = XtVaCreateManagedWidget(langcode("WPUPDPD004"),
                xmToggleButtonGadgetClass,
                option_box,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);

        XtAddCallback(tnc_net_data,XmNvalueChangedCallback,Read_messages_packet_toggle,"0");

        read_mine_only_button = XtVaCreateManagedWidget(langcode("WPUPDPD008"),
                xmToggleButtonGadgetClass,
                my_form,
                XmNvisibleWhenOff, TRUE,
                XmNindicatorSize, 12,
                XmNtopAttachment, XmATTACH_WIDGET,
                XmNtopWidget, dist,
                XmNtopOffset, 10,
                XmNbottomAttachment, XmATTACH_NONE,
                XmNleftAttachment, XmATTACH_WIDGET,
                XmNleftWidget, option_box,
                XmNleftOffset, 20,
                XmNrightAttachment, XmATTACH_NONE,
                MY_FOREGROUND_COLOR,
                MY_BACKGROUND_COLOR,
                XmNfontList, fontlist1,
                NULL);
 
        XtAddCallback(read_mine_only_button,XmNvalueChangedCallback,Read_messages_mine_only_toggle,"1");

        n=0;
        XtSetArg(args[n], XmNrows, 15); IncN(n);
        XtSetArg(args[n], XmNcolumns, 85); IncN(n);
        XtSetArg(args[n], XmNeditable, FALSE); IncN(n);
        XtSetArg(args[n], XmNtraversalOn, TRUE); IncN(n);
        XtSetArg(args[n], XmNlistSizePolicy, XmVARIABLE); IncN(n);
        XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); IncN(n);
        XtSetArg(args[n], XmNwordWrap, TRUE); IncN(n);
        XtSetArg(args[n], XmNscrollHorizontal, TRUE); IncN(n);
        XtSetArg(args[n], XmNscrollVertical, TRUE); IncN(n);
//        XtSetArg(args[n], XmNscrollBarDisplayPolicy, XmSTATIC); IncN(n);
        XtSetArg(args[n], XmNselectionPolicy, XmMULTIPLE_SELECT); IncN(n);
        XtSetArg(args[n], XmNcursorPositionVisible, FALSE); IncN(n);
        XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); IncN(n);
        XtSetArg(args[n], XmNtopWidget, option_box); IncN(n);
        XtSetArg(args[n], XmNtopOffset, 5); IncN(n);
        XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); IncN(n);
        XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); IncN(n);
        XtSetArg(args[n], XmNleftOffset, 5); IncN(n);
        XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); IncN(n);
        XtSetArg(args[n], XmNrightOffset, 5); IncN(n);
        XtSetArg(args[n], XmNforeground, MY_FG_COLOR); IncN(n);
        XtSetArg(args[n], XmNbackground, MY_BG_COLOR); IncN(n);
        XtSetArg(args[n], XmNfontList, fontlist1); n++;
 
        view_messages_text = XmCreateScrolledText(my_form,
                "view_all_messages text",
                args,
                n);

// It's hard to get tab groups working with ScrolledText widgets.  Tab'ing in is
// fine, but then I'm stuck in insert mode and it absorbs the tabs and beeps.

        pos_dialog(All_messages_dialog);

        delw = XmInternAtom(XtDisplay(All_messages_dialog),"WM_DELETE_WINDOW", FALSE);
        XmAddWMProtocolCallback(All_messages_dialog, delw, All_messages_destroy_shell, (XtPointer)All_messages_dialog);

        sprintf(temp,"%d",vm_range);
        XmTextFieldSetString(vm_dist_data,temp);

        switch (Read_messages_packet_data_type) {
            case(0):
                XmToggleButtonSetState(tnc_net_data,TRUE,FALSE);
                break;

            case(1):
                XmToggleButtonSetState(tnc_data,TRUE,FALSE);
                break;

            case(2):
                XmToggleButtonSetState(net_data,TRUE,FALSE);
                break;

            default:
                XmToggleButtonSetState(tnc_net_data,TRUE,FALSE);
                break;
        }

        if (Read_messages_mine_only) {
            XmToggleButtonSetState(read_mine_only_button,TRUE,FALSE);
            XtSetSensitive(vm_dist_data, FALSE);
        }
        else {
            XmToggleButtonSetState(read_mine_only_button,FALSE,FALSE);
            XtSetSensitive(vm_dist_data, TRUE);
        }

        XtManageChild(option_box);
        XtManageChild(view_messages_text);
        XtVaSetValues(view_messages_text, XmNbackground, colors[0x0f], NULL);
        XtManageChild(my_form);
        XtManageChild(pane);

        redraw_on_new_packet_data=1;

        // Dump all currently active messages to the new window
        view_message_display_file('M');

end_critical_section(&All_messages_dialog_lock, "view_message_gui.c:view_all_messages" );

        XtPopup(All_messages_dialog,XtGrabNone);
//        fix_dialog_vsize(All_messages_dialog);

        // Move focus to the Close button.  This appears to highlight the
        // button fine, but we're not able to hit the <Enter> key to
        // have that default function happen.  Note:  We _can_ hit the
        // <SPACE> key, and that activates the option.
//        XmUpdateDisplay(All_messages_dialog);
        XmProcessTraversal(button_close, XmTRAVERSE_CURRENT); 


    }
    else {
        (void)XRaiseWindow(XtDisplay(All_messages_dialog), XtWindow(All_messages_dialog));
    }
}
Пример #13
0
void all_messages(char from, char *call_sign, char *from_call, char *message) {
    char temp_my_course[10];
    char *temp;
    char data1[97];
    char data2[97];
    int pos;
    int i;
    int my_size = 200;
    XmTextPosition drop_ptr;


    if (Read_messages_mine_only
            || (!Read_messages_mine_only
                && ((vm_range == 0)
                    || ((int)distance_from_my_station(call_sign,temp_my_course) <= vm_range)) ) ) {

        // Check that it's coming from the correct type of interface
        // Compare Read_messages_packet_data_type against the port
        // type associated with data_port to determine whether or
        // not to display it.
        //
        // I = Internet
        // L = Local
        // T = TNC
        // F = File
        //
        switch (Read_messages_packet_data_type) {

            case 2:     // Display NET data only
                // if not network_interface, return
                if (from != 'I')
                    return; // Don't display it
                break;

            case 1:     // Display TNC data only
                // if not local_tnc_interface, return
                if (from != 'T')
                    return; // Don't display it
                break;

            case 0:     // Display both TNC and NET data
            default:
                break;
        }

        // Check for my stations only if set
        if (Read_messages_mine_only) {
            char short_call[MAX_CALLSIGN];
            char *p;

            xastir_snprintf(short_call,
                sizeof(short_call),
                "%s",
                my_callsign);
            if ( (p = index(short_call,'-')) ) {
                *p = '\0';  // Terminate it
            }

            if (!strstr(call_sign, short_call)
                    && !strstr(from_call, short_call)) {
                return;
            }
        }

        if ((temp = malloc((size_t)my_size)) == NULL)
            return;

        if (strlen(message)>95) {
            xastir_snprintf(data1,
                sizeof(data1),
                "%s",
                message);
            data1[95]='\0';
            xastir_snprintf(data2,
                sizeof(data2),
                "\n\t%s",
                message+95);
        } else {
            xastir_snprintf(data1,
                sizeof(data1),
                "%s",
                message);
            data2[0] = '\0';
        }

        if (strncmp(call_sign, "java",4) == 0) {
            xastir_snprintf(call_sign,
                MAX_CALLSIGN+1,
                "%s", langcode("WPUPMSB015") );   // Broadcast
            xastir_snprintf(temp,
                my_size,
                "%s %s\t%s%s\n",
                from_call,
                call_sign,
                data1,
                data2);
        } else if (strncmp(call_sign, "USER", 4) == 0) {
            xastir_snprintf(call_sign,
                MAX_CALLSIGN+1,
                "%s", langcode("WPUPMSB015") );   // Broadcast
            xastir_snprintf(temp,
                my_size,
                "%s %s\t%s%s\n",
                from_call,
                call_sign,
                data1,
                data2);
        } else
            xastir_snprintf(temp,
                my_size,
                "%s to %s via:%c\t%s%s\n",
                from_call,
                call_sign,
                from,
                data1,
                data2);

        if ((All_messages_dialog != NULL)) {

begin_critical_section(&All_messages_dialog_lock, "view_message_gui.c:all_messages" );

            pos = (int)XmTextGetLastPosition(view_messages_text);
            XmTextInsert(view_messages_text, pos, temp);
            pos += strlen(temp);
            while (pos > view_message_limit) {
                for (drop_ptr = i = 0; i < 3; i++) {
                    (void)XmTextFindString(view_messages_text, drop_ptr, "\n", XmTEXT_FORWARD, &drop_ptr);
                    drop_ptr++;
                }
                XmTextReplace(view_messages_text, 0, drop_ptr, "");
                pos = (int)XmTextGetLastPosition(view_messages_text);
            }
            XtVaSetValues(view_messages_text, XmNcursorPosition, pos, NULL);
            XmTextShowPosition(view_messages_text, pos);

end_critical_section(&All_messages_dialog_lock, "view_message_gui.c:all_messages" );

        }
        free(temp);
    }
}
Пример #14
0
void popup_message_always(char *banner, char *message) {
    XmString msg_str;
    int j,i;
    Atom delw;


    if (disable_all_popups)
        return;

    if (banner == NULL || message == NULL)
        return;

    i=0;
    for (j=0; j<MAX_POPUPS; j++) {
        if (!pw[j].popup_message_dialog) {
            i=j;
            j=MAX_POPUPS+1;
        }
    }

    if(!pw[i].popup_message_dialog) {
        if (banner!=NULL && message!=NULL) {

begin_critical_section(&popup_message_dialog_lock, "popup_gui.c:popup_message" );

            pw[i].popup_message_dialog = XtVaCreatePopupShell(banner,
                xmDialogShellWidgetClass, appshell,
                XmNdeleteResponse, XmDESTROY,
                XmNdefaultPosition, FALSE,
                XmNtitleString,banner,
// An half-hearted attempt at fixing the problem where a popup
// comes up extremely small.  Setting a minimum size for the popup.
XmNminWidth, 220,
XmNminHeight, 80,
                XmNfontList, fontlist1,
                NULL);

            pw[i].pane = XtVaCreateWidget("popup_message pane",xmPanedWindowWidgetClass, pw[i].popup_message_dialog,
                          XmNbackground, colors[0xff],
                          NULL);

            pw[i].form =  XtVaCreateWidget("popup_message form",xmFormWidgetClass, pw[i].pane,
                            XmNfractionBase, 5,
                            XmNbackground, colors[0xff],
                            XmNautoUnmanage, FALSE,
                            XmNshadowThickness, 1,
                            NULL);

            pw[i].popup_message_data = XtVaCreateManagedWidget("popup_message message",xmLabelWidgetClass, pw[i].form,
                                      XmNtopAttachment, XmATTACH_FORM,
                                      XmNtopOffset, 10,
                                      XmNbottomAttachment, XmATTACH_NONE,
                                      XmNleftAttachment, XmATTACH_FORM,
                                      XmNleftOffset, 10,
                                      XmNrightAttachment, XmATTACH_FORM,
                                      XmNrightOffset, 10,
                                      XmNbackground, colors[0xff],
                                      XmNfontList, fontlist1,
                                      NULL);

            pw[i].button_close = XtVaCreateManagedWidget(langcode("UNIOP00003"),xmPushButtonGadgetClass, pw[i].form,
                                      XmNtopAttachment, XmATTACH_WIDGET,
                                      XmNtopWidget, pw[i].popup_message_data,
                                      XmNtopOffset, 10,
                                      XmNbottomAttachment, XmATTACH_FORM,
                                      XmNbottomOffset, 5,
                                      XmNleftAttachment, XmATTACH_POSITION,
                                      XmNleftPosition, 2,
                                      XmNrightAttachment, XmATTACH_POSITION,
                                      XmNrightPosition, 3,
                                      XmNbackground, colors[0xff],
                                      XmNfontList, fontlist1,
                                      NULL);

            sprintf(pw[i].name,"%d",i);

            msg_str=XmStringCreateLtoR(message,XmFONTLIST_DEFAULT_TAG);
            XtVaSetValues(pw[i].popup_message_data,XmNlabelString,msg_str,NULL);
            XmStringFree(msg_str);

            XtAddCallback(pw[i].button_close, XmNactivateCallback, popup_message_destroy_shell,(XtPointer)pw[i].name);

            delw = XmInternAtom(XtDisplay(pw[i].popup_message_dialog),"WM_DELETE_WINDOW", FALSE);

            XmAddWMProtocolCallback(pw[i].popup_message_dialog, delw, popup_message_destroy_shell, (XtPointer)pw[i].name);

            pos_dialog(pw[i].popup_message_dialog);

            XtManageChild(pw[i].form);
            XtManageChild(pw[i].pane);

end_critical_section(&popup_message_dialog_lock, "popup_gui.c:popup_message" );

            XtPopup(pw[i].popup_message_dialog,XtGrabNone);

// An half-hearted attempt at fixing the problem where a popup
// comes up extremely small.  Commenting out the below so we can
// change the size if necessary to read the message.
//            fix_dialog_size(pw[i].popup_message_dialog);

            pw[i].sec_opened=sec_now();
        }
    }
}
Пример #15
0
//
// Note that the length of "gps_line_data" can be up to
// MAX_DEVICE_BUFFER, which is currently set to 4096.
//
int gps_data_find(char *gps_line_data, int port) {

    char long_pos[20],lat_pos[20],aunit[2];
    time_t t;
    char temp_str[MAX_GPS_STRING+1];
    int have_valid_string = 0;
#ifndef __CYGWIN__
    struct timeval tv;
    struct timezone tz;
#endif  // __CYGWIN__
 


    if (strncmp(gps_line_data,"$GPRMC,",7)==0) {

        if (debug_level & 128) {
            char filtered_data[MAX_LINE_SIZE+1];

            xastir_snprintf(filtered_data,
                sizeof(filtered_data),
                "%s",
                gps_line_data);
            
            makePrintable(filtered_data);
            fprintf(stderr,"Got RMC %s\n", filtered_data);
        }

        if (debug_level & 128) {
            // Got GPS RMC String
            statusline(langcode("BBARSTA015"),0);
        }

        xastir_snprintf(gps_gprmc,
            sizeof(gps_gprmc),
            "%s",
            gps_line_data);

        xastir_snprintf(temp_str, sizeof(temp_str), "%s", gps_gprmc);
        // decode_gps_rmc is destructive to its first parameter
        if (decode_gps_rmc( temp_str,
                            long_pos,
                            sizeof(long_pos),
                            lat_pos,
                            sizeof(lat_pos),
                            gps_spd,
                            gps_sunit,
                            sizeof(gps_sunit),
                            gps_cse,
                            &t,
                            &gps_valid ) == 1) {    // mod station data
            // got GPS data
            have_valid_string++;
            if (debug_level & 128)
                fprintf(stderr,"RMC <%s> <%s><%s> %c <%s>\n",
                    long_pos,lat_pos,gps_spd,gps_sunit[0],gps_cse);

            if (debug_level & 128) {
                fprintf(stderr,"Checking for Time Set on %d (%d)\n",
                    port, devices[port].set_time);
            }

// Don't set the time if it's a Cygwin system.  Causes problems with
// date, plus time can be an hour off if daylight savings time is
// enabled on Windows.
//
#ifndef __CYGWIN__
            if (devices[port].set_time) {
                tv.tv_sec=t;
                tv.tv_usec=0;
                tz.tz_minuteswest=0;
                tz.tz_dsttime=0;

                if (debug_level & 128) {
                    fprintf(stderr,"Setting Time %ld EUID: %d, RUID: %d\n",
                        (long)t, (int)getuid(), (int)getuid());
                }

#ifdef HAVE_SETTIMEOFDAY

ENABLE_SETUID_PRIVILEGE;
                settimeofday(&tv, &tz);
DISABLE_SETUID_PRIVILEGE;

#endif  // HAVE_SETTIMEOFDAY

            }

#endif  // __CYGWIN__

        }
    }
    else {
        if (debug_level & 128) {
            int i;
            fprintf(stderr,"Not $GPRMC: ");
            for (i = 0; i<7; i++)
                fprintf(stderr,"%c", gps_line_data[i]);
            fprintf(stderr,"\n");
        }
    }

    if (strncmp(gps_line_data,"$GPGGA,",7)==0) {

        if (debug_level & 128) {
            char filtered_data[MAX_LINE_SIZE+1];

            xastir_snprintf(filtered_data,
                sizeof(filtered_data),
                "%s",
                gps_line_data);

            makePrintable(filtered_data);
            fprintf(stderr,"Got GGA %s\n", filtered_data);
        }

        if (debug_level & 128) {
            // Got GPS GGA String
            statusline(langcode("BBARSTA016"),0);
        }

        xastir_snprintf(gps_gpgga,
            sizeof(gps_gpgga),
            "%s",
            gps_line_data);

        xastir_snprintf(temp_str, sizeof(temp_str), "%s", gps_gpgga);

        // decode_gps_gga is destructive to its first parameter
        if ( decode_gps_gga( temp_str,
                             long_pos,
                             sizeof(long_pos),
                             lat_pos,
                             sizeof(lat_pos),
                             gps_sats,
                             gps_alt,
                             aunit,
                             &gps_valid ) == 1) { // mod station data
            // got GPS data
            have_valid_string++;
            if (debug_level & 128)
                fprintf(stderr,"GGA <%s> <%s> <%s> <%s> %c\n",
                    long_pos,lat_pos,gps_sats,gps_alt,aunit[0]);
        }
    }
    else {
        if (debug_level & 128) {
            int i;
            fprintf(stderr,"Not $GPGGA: ");
            for (i = 0; i<7; i++)
                fprintf(stderr,"%c",gps_line_data[i]);
            fprintf(stderr,"\n");
        }
    }


    if (have_valid_string) {

        if (debug_level & 128) {
            statusline(langcode("BBARSTA037"),0);
        }

        // Go update my screen position
        my_station_gps_change(long_pos,lat_pos,gps_cse,gps_spd,
            gps_sunit[0],gps_alt,gps_sats);

        // gps_stop_now is how we tell main.c that we've got a valid GPS string.
        // Only useful for HSP mode?
        if (!gps_stop_now)
            gps_stop_now=1;

        // If HSP port, shutdown gps for timed interval
        if (port_data[port].device_type == DEVICE_SERIAL_TNC_HSP_GPS) {
            // return dtr to normal
            port_dtr(port,0);
        }
    }
    return(have_valid_string);
}
Пример #16
0
void draw_WMS_map (Widget w,
        char *filenm,
        int destination_pixmap,
        char *URL,
        transparent_color_record *c_trans_color_head,
        int nocache) {  // If non-zero, don't use cached version


    char file[MAX_FILENAME];        // Complete path/name of image file
    char short_filenm[MAX_FILENAME];
    FILE *f;                        // Filehandle of image file
    char fileimg[MAX_FILENAME];     // Ascii name of image file, read from GEO file
    char WMStmp[MAX_FILENAME*2];  // Used for putting together the WMS map query
    int width, height;
    tiepoint tp[2];                 // Calibration points for map, read in from .geo file
    register long map_c_T, map_c_L; // map delta NW edge coordinates, DNN: these should be signed
    register long tp_c_dx, tp_c_dy; // tiepoint coordinate differences
    unsigned long c_x_min,  c_y_min;// top left coordinates of map inside screen
    unsigned long c_y_max;          // bottom right coordinates of map inside screen
    double c_x;                     // Xastir coordinates 1/100 sec, 0 = 180°W
    double c_y;                     // Xastir coordinates 1/100 sec, 0 =  90°N

    long map_y_0;                   // map pixel pointer prior to TM adjustment
    register long map_x, map_y;     // map pixel pointers, DNN: this was a float, chg to long
    long map_x_min, map_x_max;      // map boundaries for in screen part of map
    long map_y_min, map_y_max;      //
    long map_x_ctr;                 // half map width in pixel
    long map_y_ctr;                 // half map height in pixel
    int map_seen = 0;
    int map_act;
    int map_done;

    long map_c_yc;                  // map center, vert coordinate
    long map_c_xc;                  // map center, hor  coordinate
    double map_c_dx, map_c_dy;      // map coordinates increment (pixel width)
    double c_dx;                    // adjusted map pixel width

    long scr_x,  scr_y;             // screen pixel plot positions
    long scr_xp, scr_yp;            // previous screen plot positions
    int  scr_dx, scr_dy;            // increments in screen plot positions
    long scr_x_mc;                  // map center in screen units

    long scr_c_xr;

    long scale_xa;                  // adjusted for topo maps
    double scale_x_nm;              // nm per Xastir coordinate unit
    long scale_x0;                  // at widest map area

    char local_filename[MAX_FILENAME];
    ExceptionInfo exception;
    Image *image;
    ImageInfo *image_info;
    PixelPacket *pixel_pack;
    PixelPacket temp_pack;
    IndexPacket *index_pack;
    int l;
    XColor my_colors[256];
    int trans_skip = 0;             // skip transparent pixel
    double left, right, top, bottom, map_width, map_height;
    double lat_center  = 0;
    double long_center = 0;

    char map_it[MAX_FILENAME];
    char tmpstr[100];
    int geo_image_width;        // Image width  from GEO file
    int geo_image_height;       // Image height from GEO file

    time_t query_start_time, query_end_time; 

#ifdef USE_MAP_CACHE 
    int map_cache_return;
    char * cache_file_id;
#endif  // USE_MAP_CACHE

    char temp_file_path[MAX_VALUE];

    if (debug_level & 512) {
        if (nocache)
            fprintf(stderr,"draw_WMS_map: NOCACHE selected\n");
        else
            fprintf(stderr,"draw_WMS_map: CACHING if enabled\n");
    }

    // Create a shorter filename for display (one that fits the
    // status line more closely).  Subtract the length of the
    // "Indexing " and/or "Loading " strings as well.
    if (strlen(filenm) > (41 - 9)) {
        int avail = 41 - 11;
        int new_len = strlen(filenm) - avail;

        xastir_snprintf(short_filenm,
            sizeof(short_filenm),
            "..%s",
            &filenm[new_len]);
    }
    else {
        xastir_snprintf(short_filenm,
            sizeof(short_filenm),
            "%s",
            filenm);
    }

    xastir_snprintf(map_it,
        sizeof(map_it),
        langcode ("BBARSTA028"),
        short_filenm);
    statusline(map_it,0);       // Loading ...


        
    // Check whether we're indexing or drawing the map
    if ( (destination_pixmap == INDEX_CHECK_TIMESTAMPS)
            || (destination_pixmap == INDEX_NO_TIMESTAMPS) ) {

        // We're indexing only.  Save the extents in the index.
        // Force the extents to the edges of the earth for the
        // index file.
        index_update_xastir(filenm, // Filename only
            64800000l,      // Bottom
            0l,             // Top
            0l,             // Left
            129600000l,     // Right
            0);             // Default Map Level

        // Update statusline
        xastir_snprintf(map_it,
            sizeof(map_it),
            langcode ("BBARSTA039"),
            short_filenm);
        statusline(map_it,0);       // Loading/Indexing ...

        return; // Done indexing this file
    }


    // Tiepoint for upper left screen corner
    //
    tp[0].img_x = 0;                // Pixel Coordinates
    tp[0].img_y = 0;                // Pixel Coordinates
    tp[0].x_long = NW_corner_longitude;   // Xastir Coordinates
    tp[0].y_lat  = NW_corner_latitude;    // Xastir Coordinates


    // Tiepoint for lower right screen corner
    //
    // Here we must use scale_x for both directions because we have
    // square pixels returned by the WMS server.


// Really what we want to do here is to change our bounding box for
// our request to fit square pixels, using scale_x for both
// dimensions, and to change our tiepoints to match.  WMS servers
// currently feed us back square pixels but the spec says that the
// servers should be capable of sending back rectangular pixels, so
// the images we get back may change if we don't request square
// pixels each time.
//
// TODO:  Change our imagesize, bounding rectangle requested, and
// tiepoints to fit square pixels and to use scale_x for both
// dimensions.
//
// Actually, looking at the changes that were made, it looks like we
// _are_ using square pixels and requesting a bounding box based on
// scale_x for both dimensions, so we might be good to go as-is.


    //
    tp[1].img_x =  screen_width - 1; // Pixel Coordinates
    tp[1].img_y = screen_height - 1; // Pixel Coordinates 
    tp[1].x_long = SE_corner_longitude; // Xastir Coordinates

// Modified to use same scale (scale_x) for both dimensions, square
// pixels.  Don't use SE_corner_latitude here as it uses scale_y!
//    tp[1].y_lat  =  NW_corner_latitude + ((screen_height) * scale_y); // Xastir Coordinates
    tp[1].y_lat  =  NW_corner_latitude + ((screen_height) * scale_x); // Xastir Coordinates


    // Again, use scale_x for both directions due to the square
    // pixels returned from the WMS server.
    //
    left = (double)((NW_corner_longitude - 64800000l )/360000.0);   // Lat/long Coordinates
    top = (double)(-((NW_corner_latitude - 32400000l )/360000.0));  // Lat/long Coordinates
    right = (double)((SE_corner_longitude - 64800000l)/360000.0);//Lat/long Coordinates

// Modified to use same scale (scale_x) for both dimensions, square
// pixels.  Don't use SE_corner_latitude here as it uses scale_y!
//    bottom = (double)(-(((NW_corner_latitude + ((screen_height) * scale_y) ) - 32400000l)/360000.0));//Lat/long Coordinates
    bottom = (double)(-(((NW_corner_latitude + ((screen_height) * scale_x) ) - 32400000l)/360000.0));//Lat/long Coordinates


    map_width = right - left;   // Lat/long Coordinates
    map_height = top - bottom;  // Lat/long Coordinates

    geo_image_width  = screen_width;
    geo_image_height = screen_height;

    long_center = (left + right)/2.0l;
    lat_center  = (top + bottom)/2.0l;


//  Example query for a WMS map server....
//  xastir_snprintf(fileimg, sizeof(fileimg), 
//  "\'http://mesonet.tamu.edu/cgi-bin/p-warn?SERVICE=WMS&VERSION=1.1.1&REQUEST=getmap&layers=radar&BBOX=-129.000,52.500,-111.000,42.500&HEIGHT=1000&WIDTH=1800&FORMAT=image/png\'");


//    xastir_snprintf(WMStmp, sizeof(WMStmp),
//        "http://mesonet.tamu.edu/cgi-bin/p-warn?SERVICE=WMS&VERSION=1.1.1&REQUEST=getmap");


    xastir_snprintf(WMStmp, sizeof(WMStmp), "%s", URL);
    strncat(WMStmp, "&REQUEST=getmap", sizeof(WMStmp) - 1 - strlen(WMStmp));
    strncat(WMStmp, "&EXCEPTIONS=INIMAGE", sizeof(WMStmp) - 1 - strlen(WMStmp));

// This specifies a bounding box based on square pixels.
    xastir_snprintf(tmpstr, sizeof(tmpstr),
        "&BBOX=%8.5f,%7.5f,%8.5f,%7.5f",
        left,   // Lower left
        bottom, // Lower left
        right,  // Upper right
        top);   // Upper right
    strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp));

    xastir_snprintf(tmpstr, sizeof(tmpstr), "&HEIGHT=%d", geo_image_height);
    strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp));

    xastir_snprintf(tmpstr, sizeof(tmpstr), "&WIDTH=%d", geo_image_width);    
    strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp));


// These should be specified in the .geo file instead of hard-coded:
//
//    strncat(WMStmp, "&VERSION=1.0.0", sizeof(WMStmp) - 1 - strlen(WMStmp));
//    strncat(WMStmp, "&FORMAT=image/png", sizeof(WMStmp) - 1 - strlen(WMStmp));
//    strncat(WMStmp, "&TRANSPARENT=TRUE", sizeof(WMStmp) - 1 - strlen(WMStmp));
//    strncat(WMStmp, "&BGCOLOR=0xffffff", sizeof(WMStmp) - 1 - strlen(WMStmp));
//    strncat(WMStmp, "&BGCOLOR=0x000000", sizeof(WMStmp) - 1 - strlen(WMStmp));
//    strncat(WMStmp, "&CRS=CRS:84", sizeof(WMStmp) - 1 - strlen(WMStmp));





/*
    xastir_snprintf(WMStmp, sizeof(WMStmp), "http://tiger.census.gov/cgi-bin/mapper/map.png?");

    if (tiger_show_grid)
        strncat(WMStmp, "&on=GRID", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=GRID", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_counties)
        strncat(WMStmp, "&on=counties", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=counties", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_cities)
        strncat(WMStmp, "&on=CITIES", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=CITIES", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_places)
        strncat(WMStmp, "&on=places", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=places", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_majroads)
        strncat(WMStmp, "&on=majroads", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=majroads", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_streets)
        strncat(WMStmp, "&on=streets", sizeof(WMStmp) - 1 - strlen(WMStmp));
    // Don't turn streets off since this will automagically show up as you zoom in.

    if (tiger_show_railroad)
        strncat(WMStmp, "&on=railroad", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=railroad", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_states)
        strncat(WMStmp, "&on=states", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=states", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_interstate)
        strncat(WMStmp, "&on=interstate", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=interstate", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_ushwy)
        strncat(WMStmp, "&on=ushwy", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=ushwy", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_statehwy)
        strncat(WMStmp, "&on=statehwy", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=statehwy", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_water)
        strncat(WMStmp, "&on=water", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=water", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_lakes)
        strncat(WMStmp, "&on=shorelin", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=shorelin", sizeof(WMStmp) - 1 - strlen(WMStmp));

    if (tiger_show_misc)
        strncat(WMStmp, "&on=miscell", sizeof(WMStmp) - 1 - strlen(WMStmp));
    else
        strncat(WMStmp, "&off=miscell", sizeof(WMStmp) - 1 - strlen(WMStmp));

    xastir_snprintf(tmpstr, sizeof(tmpstr), "&lat=%f\046lon=%f\046", lat_center, long_center);    
    strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp));
    xastir_snprintf(tmpstr, sizeof(tmpstr), "wid=%f\046ht=%f\046", map_width, map_height);
    strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp));
    xastir_snprintf(tmpstr, sizeof(tmpstr), "iwd=%i\046iht=%i", tp[1].img_x + 1, tp[1].img_y + 1);
    strncat (WMStmp, tmpstr, sizeof(WMStmp) - 1 - strlen(WMStmp)); */


    xastir_snprintf(fileimg, sizeof(fileimg), "%s", WMStmp);

    if (debug_level & 512) {
          fprintf(stderr,"left side is %f\n", left);
          fprintf(stderr,"right side is %f\n", right);
          fprintf(stderr,"top  is %f\n", top);
          fprintf(stderr,"bottom is %f\n", bottom);
          fprintf(stderr,"lat center is %f\n", lat_center);
          fprintf(stderr,"long center is %f\n", long_center);
          fprintf(stderr,"screen width is %li\n", screen_width);
          fprintf(stderr,"screen height is %li\n", screen_height);
          fprintf(stderr,"map width is %f\n", map_width);
          fprintf(stderr,"map height is %f\n", map_height);
          fprintf(stderr,"fileimg is %s\n", fileimg);
          fprintf(stderr,"ftp or http file: %s\n", fileimg);
    }

    if (debug_level & 512) {
        query_start_time=time(&query_start_time); 
    }


#ifdef USE_MAP_CACHE 

    if (nocache || map_cache_fetch_disable) {

        // Delete old copy from the cache
        if (map_cache_fetch_disable && fileimg[0] != '\0') {
            if (map_cache_del(fileimg)) {
                if (debug_level & 512) {
                    fprintf(stderr,"Couldn't delete old map from cache\n");
                }
            }
        }

        // Simulate a cache miss
        map_cache_return = 1;
    }
    else {
        // Else look for the file in the cache
    	map_cache_return = map_cache_get(fileimg,local_filename); 
    }

	if (debug_level & 512) {
		fprintf(stderr,"map_cache_return: %d\n", map_cache_return);
	}
 

    // Don't use cached version if "nocache" is non-zero
    //	   
    if (nocache || map_cache_return != 0 ) {
        // Caching has not been requested or cached file not found.
        // We must snag the remote file via libcurl or wget.

        if (nocache) {
            xastir_snprintf(local_filename,
                sizeof(local_filename),
                "%s/map.%s",
                 get_user_base_dir("tmp", temp_file_path, sizeof(temp_file_path)),
                "png");
        }
        else {
            cache_file_id = map_cache_fileid();
            xastir_snprintf(local_filename,
                sizeof(local_filename),
                "%s/map_%s.%s",
                get_user_base_dir("map_cache", temp_file_path, sizeof(temp_file_path)),
                cache_file_id,
                "png");
            free(cache_file_id);
        }

#else   // USE_MAP_CACHE

    xastir_snprintf(local_filename,
        sizeof(local_filename),
        "%s/map.%s",
         get_user_base_dir("tmp", temp_file_path, sizeof(temp_file_path)),
        "png");

#endif  // USE_MAP_CACHE


    // Erase any previously existing local file by the same name.
    // This avoids the problem of having an old map image here and
    // the code trying to display it when the download fails.

    unlink( local_filename );

    HandlePendingEvents(app_context);
    if (interrupt_drawing_now) {
        // Update to screen
        (void)XCopyArea(XtDisplay(da),
            pixmap,
            XtWindow(da),
            gc,
            0,
            0,
            (unsigned int)screen_width,
            (unsigned int)screen_height,
            0,
            0);
        return;
    }

    if (fetch_remote_file(fileimg, local_filename)) {
        // Had trouble getting the file.  Abort.
        return;
    }

    // For debugging the MagickError/MagickWarning segfaults.
    //system("cat /dev/null >/var/tmp/xastir_hacker_map.png");

    
#ifdef USE_MAP_CACHE

    // Cache this map only if nocache is zero
    if (!nocache) {
        map_cache_put(fileimg,local_filename);
    }

        } // end if is cached  DHBROWN
#endif // USE_MAP_CACHE


    if (debug_level & 512) {
        fprintf (stderr, "Fetch or query took %d seconds\n", 
            (int) (time(&query_end_time) - query_start_time)); 
    }

    // Set permissions on the file so that any user can overwrite it.
    chmod(local_filename, 0666);

    // Tell ImageMagick where to find it
    xastir_snprintf(file,
        sizeof(file),
        "%s",
        local_filename);

    GetExceptionInfo(&exception);

    image_info=CloneImageInfo((ImageInfo *) NULL);

    xastir_snprintf(image_info->filename,
        sizeof(image_info->filename),
        "%s",
        file);

    if (debug_level & 512) {
           fprintf(stderr,"Copied %s into image info.\n", file);
           fprintf(stderr,"image_info got: %s\n", image_info->filename);
           fprintf(stderr,"Entered ImageMagick code.\n");
           fprintf(stderr,"Attempting to open: %s\n", image_info->filename);
    }

    // We do a test read first to see if the file exists, so we
    // don't kill Xastir in the ReadImage routine.
    f = fopen (image_info->filename, "r");
    if (f == NULL) {
        if (debug_level & 512)
            fprintf(stderr,"File could not be read\n");
        
#ifdef USE_MAP_CACHE
        // clear from cache if bad    
        if (map_cache_del(fileimg)) {
            if (debug_level & 512) {
                fprintf(stderr,"Couldn't delete map from cache\n");
            }
        }
#endif
         
        if (image_info)
            DestroyImageInfo(image_info);
	DestroyExceptionInfo(&exception);
        return;
    }
    (void)fclose (f);


    image = ReadImage(image_info, &exception);

    if (image == (Image *) NULL) {
        MagickWarning(exception.severity, exception.reason, exception.description);
        //fprintf(stderr,"MagickWarning\n");

#ifdef USE_MAP_CACHE
        // clear from cache if bad    
        if (map_cache_del(fileimg)) {
            if (debug_level & 512) {
                fprintf(stderr,"Couldn't delete map from cache\n");
            }
        }
#endif

        if (image_info)
            DestroyImageInfo(image_info);
	DestroyExceptionInfo(&exception);
        return;
    }


    if (debug_level & 512)
        fprintf(stderr,"Color depth is %i \n", (int)image->depth);

/*
    if (image->colorspace != RGBColorspace) {
        fprintf(stderr,"TBD: I don't think we can deal with colorspace != RGB");
        if (image)
            DestroyImage(image);
        if (image_info)
            DestroyImageInfo(image_info);
        DestroyExceptionInfo(&exception);
        return;
    }
*/

    width = image->columns;
    height = image->rows;

    //  Code to mute the image so it's not as bright.
/*    if (raster_map_intensity < 1.0) {
        char tempstr[30];

        if (debug_level & 512)
            fprintf(stderr,"level=%s\n", tempstr);

        xastir_snprintf(tempstr,
            sizeof(tempstr),
            "%d, 100, 100",
            (int)(raster_map_intensity * 100.0));

        ModulateImage(image, tempstr);
    }
*/


    // If were are drawing to a low bpp display (typically < 8bpp)
    // try to reduce the number of colors in an image.
    // This may take some time, so it would be best to do ahead of
    // time if it is a static image.
#if (MagickLibVersion < 0x0540)
    if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL) > 128) {
#else   // MagickLib >= 540
    if (visual_type == NOT_TRUE_NOR_DIRECT && GetNumberColors(image, NULL, &exception) > 128) {
#endif  // MagickLib Version

        if (image->storage_class == PseudoClass) {
#if (MagickLibVersion < 0x0549)
            CompressColormap(image); // Remove duplicate colors
#else // MagickLib >= 0x0549
            CompressImageColormap(image); // Remove duplicate colors
#endif  // MagickLibVersion < 0x0549
        }

        // Quantize down to 128 will go here...
    }


    pixel_pack = GetImagePixels(image, 0, 0, image->columns, image->rows);
    if (!pixel_pack) {
        fprintf(stderr,"pixel_pack == NULL!!!");
        if (image)
            DestroyImage(image);
        if (image_info)
            DestroyImageInfo(image_info);
        DestroyExceptionInfo(&exception);
        return;
    }


    index_pack = GetIndexes(image);
    if (image->storage_class == PseudoClass && !index_pack) {
        fprintf(stderr,"PseudoClass && index_pack == NULL!!!");
        if (image)
            DestroyImage(image);
        if (image_info)
            DestroyImageInfo(image_info);
        DestroyExceptionInfo(&exception);
        return;
    }


    if (image->storage_class == PseudoClass && image->colors <= 256) {
        for (l = 0; l < (int)image->colors; l++) {
            // Need to check how to do this for ANY image, as ImageMagick can read in all sorts
            // of image files
            temp_pack = image->colormap[l];
            if (debug_level & 512)
                fprintf(stderr,"Colormap color is %i  %i  %i \n",
                       temp_pack.red, temp_pack.green, temp_pack.blue);

            // Here's a tricky bit:  PixelPacket entries are defined as Quantum's.  Quantum
            // is defined in /usr/include/magick/image.h as either an unsigned short or an
            // unsigned char, depending on what "configure" decided when ImageMagick was installed.
            // We can determine which by looking at MaxRGB or QuantumDepth.
            //
            if (QuantumDepth == 16) {   // Defined in /usr/include/magick/image.h
                if (debug_level & 512)
                    fprintf(stderr,"Color quantum is [0..65535]\n");
                my_colors[l].red   = temp_pack.red * raster_map_intensity;
                my_colors[l].green = temp_pack.green * raster_map_intensity;
                my_colors[l].blue  = temp_pack.blue * raster_map_intensity;
            }
            else {  // QuantumDepth = 8
                if (debug_level & 512)
                    fprintf(stderr,"Color quantum is [0..255]\n");
                my_colors[l].red   = (temp_pack.red << 8) * raster_map_intensity;
                my_colors[l].green = (temp_pack.green << 8) * raster_map_intensity;
                my_colors[l].blue  = (temp_pack.blue << 8) * raster_map_intensity;
            }

            // Get the color allocated on < 8bpp displays. pixel color is written to my_colors.pixel
            if (visual_type == NOT_TRUE_NOR_DIRECT) {
//                XFreeColors(XtDisplay(w), cmap, &(my_colors[l].pixel),1,0);
                XAllocColor(XtDisplay(w), cmap, &my_colors[l]);
            }
            else {
                pack_pixel_bits(my_colors[l].red, my_colors[l].green, my_colors[l].blue,
                                &my_colors[l].pixel);
            }

            if (debug_level & 512)
                fprintf(stderr,"Color allocated is %li  %i  %i  %i \n", my_colors[l].pixel,
                       my_colors[l].red, my_colors[l].blue, my_colors[l].green);
        }
    }



    /*
    * Here are the corners of our viewport, using the Xastir
    * coordinate system.  Notice that Y is upside down:
    *
    *   left edge of view = NW_corner_longitude
    *  right edge of view = SE_corner_longitude
    *    top edge of view =  NW_corner_latitude
    * bottom edge of view =  SE_corner_latitude
    *
    * The corners of our map will soon be (after translating the
    * tiepoints to the corners if they're not already there):
    *
    *   left edge of map = tp[0].x_long   in Xastir format
    *  right edge of map = tp[1].x_long
    *    top edge of map = tp[0].y_lat
    * bottom edge of map = tp[1].y_lat
    *
    */
    map_c_L = tp[0].x_long - NW_corner_longitude;     // map left coordinate
    map_c_T = tp[0].y_lat  - NW_corner_latitude;      // map top  coordinate

    tp_c_dx = (long)(tp[1].x_long - tp[0].x_long);//  Width between tiepoints
    tp_c_dy = (long)(tp[1].y_lat  - tp[0].y_lat); // Height between tiepoints


    // Check for tiepoints being in wrong relation to one another
    if (tp_c_dx < 0) 
        tp_c_dx = -tp_c_dx;       // New  width between tiepoints
    if (tp_c_dy < 0) 
        tp_c_dy = -tp_c_dy;       // New height between tiepoints

    // Calculate step size per pixel
    map_c_dx = ((double) tp_c_dx / abs(tp[1].img_x - tp[0].img_x));
    map_c_dy = ((double) tp_c_dy / abs(tp[1].img_y - tp[0].img_y));

    // Scaled screen step size for use with XFillRectangle below
    scr_dx = (int) (map_c_dx / scale_x) + 1;
    scr_dy = (int) (map_c_dy / scale_y) + 1;

    // calculate top left map corner from tiepoints
    if (tp[0].img_x != 0) {
        tp[0].x_long -= (tp[0].img_x * map_c_dx);   // map left edge longitude
        map_c_L = tp[0].x_long - NW_corner_longitude;     // delta ??
        tp[0].img_x = 0;
        if (debug_level & 512)
            fprintf(stderr,"Translated tiepoint_0 x: %d\t%lu\n", tp[0].img_x, tp[0].x_long);
    }
    if (tp[0].img_y != 0) {
        tp[0].y_lat -= (tp[0].img_y * map_c_dy);    // map top edge latitude
        map_c_T = tp[0].y_lat - NW_corner_latitude;
        tp[0].img_y = 0;
        if (debug_level & 512)
            fprintf(stderr,"Translated tiepoint_0 y: %d\t%lu\n", tp[0].img_y, tp[0].y_lat);
    }

    // calculate bottom right map corner from tiepoints
    // map size is geo_image_width / geo_image_height
    if (tp[1].img_x != (geo_image_width - 1) ) {
        tp[1].img_x = geo_image_width - 1;
        tp[1].x_long = tp[0].x_long + (tp[1].img_x * map_c_dx); // right
        if (debug_level & 512)
            fprintf(stderr,"Translated tiepoint_1 x: %d\t%lu\n", tp[1].img_x, tp[1].x_long);
    }
    if (tp[1].img_y != (geo_image_height - 1) ) {
        tp[1].img_y = geo_image_height - 1;
        tp[1].y_lat = tp[0].y_lat + (tp[1].img_y * map_c_dy);   // bottom
        if (debug_level & 512)
            fprintf(stderr,"Translated tiepoint_1 y: %d\t%lu\n", tp[1].img_y, tp[1].y_lat);
    }

    if (debug_level & 512) {
        fprintf(stderr,"X tiepoint width: %ld\n", tp_c_dx);
        fprintf(stderr,"Y tiepoint width: %ld\n", tp_c_dy);
        fprintf(stderr,"Loading imagemap: %s\n", file);
        fprintf(stderr,"\nImage: %s\n", file);
        fprintf(stderr,"Image size %d %d\n", geo_image_width, geo_image_height);
        fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n",
            map_c_L, map_c_T, map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y));
        fprintf(stderr,"Image size %d %d\n", width, height);
#if (MagickLibVersion < 0x0540)
        fprintf(stderr,"Unique colors = %d\n", GetNumberColors(image, NULL));
#else // MagickLib < 540
        fprintf(stderr,"Unique colors = %ld\n", GetNumberColors(image, NULL, &exception));
#endif // MagickLib < 540
        fprintf(stderr,"XX: %ld YY:%ld Sx %f %d Sy %f %d\n", map_c_L, map_c_T,
            map_c_dx,(int) (map_c_dx / scale_x), map_c_dy, (int) (map_c_dy / scale_y));
        fprintf(stderr,"image matte is %i\n", image->matte);
    } // debug_level & 512

    // draw the image from the file out to the map screen

    // Get the border values for the X and Y for loops used
    // for the XFillRectangle call later.

    map_c_yc = (tp[0].y_lat + tp[1].y_lat) / 2;     // vert center of map as reference
    map_y_ctr = (long)(height / 2 +0.499);
    scale_x0 = get_x_scale(0,map_c_yc,scale_y);     // reference scaling at vert map center

    map_c_xc  = (tp[0].x_long + tp[1].x_long) / 2;  // hor center of map as reference
    map_x_ctr = (long)(width  / 2 +0.499);
    scr_x_mc  = (map_c_xc - NW_corner_longitude) / scale_x; // screen coordinates of map center

    // calculate map pixel range in y direction that falls into screen area
    c_y_max = 0ul;
    map_y_min = map_y_max = 0l;
    for (map_y_0 = 0, c_y = tp[0].y_lat; map_y_0 < (long)height; map_y_0++, c_y += map_c_dy) {
        scr_y = (c_y - NW_corner_latitude) / scale_y;   // current screen position
        if (scr_y > 0) {
            if (scr_y < screen_height) {
                map_y_max = map_y_0;          // update last map pixel in y
                c_y_max = (unsigned long)c_y;// bottom map inside screen coordinate
            } else
                break;                      // done, reached bottom screen border
        } else {                            // pixel is above screen
            map_y_min = map_y_0;              // update first map pixel in y
        }
    }
    c_y_min = (unsigned long)(tp[0].y_lat + map_y_min * map_c_dy);   // top map inside screen coordinate

        map_x_min = map_x_max = 0l;
        for (map_x = 0, c_x = tp[0].x_long; map_x < (long)width; map_x++, c_x += map_c_dx) {
            scr_x = (c_x - NW_corner_longitude)/ scale_x;  // current screen position
            if (scr_x > 0) {
                if (scr_x < screen_width)
                    map_x_max = map_x;          // update last map pixel in x
                else
                    break;                      // done, reached right screen border
            } else {                            // pixel is left from screen
                map_x_min = map_x;              // update first map pixel in x
            }
        }
        c_x_min = (unsigned long)(tp[0].x_long + map_x_min * map_c_dx);   // left map inside screen coordinate

    scr_yp = -1;
    scr_c_xr = SE_corner_longitude;
    c_dx = map_c_dx;                            // map pixel width
    scale_xa = scale_x0;                        // the compiler likes it ;-)

    map_done = 0;
    map_act  = 0;
    map_seen = 0;
    scr_y = screen_height - 1;


    // loop over map pixel rows
    for (map_y_0 = map_y_min, c_y = (double)c_y_min; (map_y_0 <= map_y_max); map_y_0++, c_y += map_c_dy) {

        HandlePendingEvents(app_context);
        if (interrupt_drawing_now) {
            if (image)
                DestroyImage(image);
            if (image_info)
                DestroyImageInfo(image_info);
            // Update to screen
            (void)XCopyArea(XtDisplay(da),
                pixmap,
                XtWindow(da),
                gc,
                0,
                0,
                (unsigned int)screen_width,
                (unsigned int)screen_height,
                0,
                0);
            return;
        }

        scr_y = (c_y - NW_corner_latitude) / scale_y;
        if (scr_y != scr_yp) {                  // don't do a row twice
            scr_yp = scr_y;                     // remember as previous y
            scr_xp = -1;
            // loop over map pixel columns
            map_act = 0;
            scale_x_nm = calc_dscale_x(0,(long)c_y) / 1852.0;  // nm per Xastir coordinate
            for (map_x = map_x_min, c_x = (double)c_x_min; map_x <= map_x_max; map_x++, c_x += c_dx) {
                scr_x = (c_x - NW_corner_longitude) / scale_x;
                if (scr_x != scr_xp) {      // don't do a pixel twice
                    scr_xp = scr_x;         // remember as previous x
                    map_y = map_y_0;

                    if (map_y >= 0 && map_y <= tp[1].img_y) { // check map boundaries in y direction
                        map_seen = 1;
                        map_act = 1;    // detects blank screen rows (end of map)

                        // now copy a pixel from the map image to the screen
                        l = map_x + map_y * image->columns;
                        trans_skip = 1; // possibly transparent
                        if (image->storage_class == PseudoClass) {
                            if ( c_trans_color_head &&
                                    check_trans(my_colors[index_pack[l]],c_trans_color_head)) {
                                trans_skip = 1; // skip it
                            }
                            else {
                                XSetForeground(XtDisplay(w), gc, my_colors[index_pack[l]].pixel);
                                trans_skip = 0; // draw it
                            }
                        }
                        else {
                            // It is not safe to assume that the red/green/blue
                            // elements of pixel_pack of type Quantum are the
                            // same as the red/green/blue of an XColor!
                            if (QuantumDepth==16) {
                                my_colors[0].red=pixel_pack[l].red;
                                my_colors[0].green=pixel_pack[l].green;
                                my_colors[0].blue=pixel_pack[l].blue;
                            }
                            else { // QuantumDepth=8
                                // shift the bits of the 8-bit quantity so that
                                // they become the high bigs of my_colors.*
                                my_colors[0].red=pixel_pack[l].red<<8;
                                my_colors[0].green=pixel_pack[l].green<<8;
                                my_colors[0].blue=pixel_pack[l].blue<<8;
                            }
                            // NOW my_colors has the right r,g,b range for
                            // pack_pixel_bits
                            pack_pixel_bits(my_colors[0].red * raster_map_intensity,
                                            my_colors[0].green * raster_map_intensity,
                                            my_colors[0].blue * raster_map_intensity,
                                            &my_colors[0].pixel);
                            if ( c_trans_color_head &&
                                    check_trans(my_colors[0],c_trans_color_head)) {
                                trans_skip = 1; // skip it
                            }
                            else {
                                XSetForeground(XtDisplay(w), gc, my_colors[0].pixel);
                                trans_skip = 0; // draw it
                            }
                        }

                        // Skip drawing if a transparent pixel
                        if (!trans_skip) {
                            (void)XFillRectangle (XtDisplay (w),pixmap,gc,scr_x,scr_y,scr_dx,scr_dy);
                        }

                    } // check map boundaries in y direction
                }
            } // loop over map pixel columns
            if (map_seen && !map_act)
                map_done = 1;
        }
    } // loop over map pixel rows

    if (image)
       DestroyImage(image);
    if (image_info)
       DestroyImageInfo(image_info);
    DestroyExceptionInfo(&exception);
}