home *** CD-ROM | disk | FTP | other *** search
- //================================================================
- //
- // Wide Area Information Servers (WAIS)
- // Windows Visual Basic Interface
- //
- //================================================================*/
-
- #include <windows.h>
- #include <dos.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <math.h>
-
- #undef TRUE
- #undef FALSE
- #undef IGNORE
-
- #include "cdialect.h"
- #include "wprot.h"
- #include "zutil.h"
- #include "ctype.h"
- #include "ui.h"
- #include "docid.h"
-
- #define FD_SETSIZE 2
- #include "sockets.h"
-
- #define MAX_DBNAME_LEN 50
- #define MAX_SERVER_LEN 30
- #define MAX_HEADLINE_LEN 100
- #define MAX_TYPE_LEN 100
- #define MAX_DOCID_LEN 600
-
- // STRUCTURE DEFINITIONS
-
- struct fdc
- {
- long length;
- int port;
- int score;
- int lines;
- int source;
- char *type;
- any *ID;
- char server[MAX_SERVER_LEN];
- char dbname[MAX_DBNAME_LEN];
- char headline[MAX_HEADLINE_LEN];
- };
-
- typedef struct
- {
- int score;
- int source;
- long length;
- char type[MAX_TYPE_LEN];
- char headline[MAX_HEADLINE_LEN];
- } DOC;
-
- typedef struct
- {
- long ch_start;
- long ch_end;
- long doc_size;
- char type[MAX_TYPE_LEN];
- char doc_bytes[MAX_DOCID_LEN];
- } REF;
-
- // FUNCTION PROTOTYPE DEFINITIONS
-
- int far pascal _export get_docid (int, REF*);
- int far pascal _export reference_titles (int, int, REF*);
- int far pascal _export query_titles (int, int, char*, char*, char*, long);
- int far pascal _export get_document (int, char*);
- int far pascal _export get_next_or_prev (char*, DOC*);
-
- int far pascal _export set_tcp_stack(int);
- int far pascal _export dos_driver_loaded(char*);
- int far pascal _export set_ip_suffix(char*);
- int far pascal _export set_maxdocs(int);
- int far pascal _export set_path(char*, char*);
- long far pascal _export get_alloc_mem(void);
- int far pascal _export coprocessor_status(void);
-
- // GLOBAL VARIABLES
-
- unsigned int vb_data = 0;
- long allocated_memory = 0;
-
- long host;
- int maxdocs;
-
- #define MAXDOCS_LIMIT 100
- #define CURRDOC MAXDOCS_LIMIT * 2
-
- struct fdc *srchinfo[MAXDOCS_LIMIT*2+1];
-
- DocObj **Doc;
-
- char far *inBuf;
- char far *outBuf;
-
- char db_path[255];
- char temp_path[255];
-
- char far *ip_suffix = "";
-
- int count=0;
- int lcount=0;
-
- SOCKET connection;
- int recv_bufsize;
- int send_bufsize;
-
- int cmp(a,b)
- struct fdc **a,**b;
- {
- return((*b)->score-(*a)->score);
- }
-
- //*********************************************************************
- // Return a DocID from a source description to be used in future
- // relevance feedback functions
- //*********************************************************************
-
- int far pascal _export
- get_docid(docno, ref_ptr)
- int docno;
- REF *ref_ptr;
- {
- if (lcount == 0)
- return (8); // No documents found
-
- if (docno > lcount - 1)
- return (7); // Invalid document number
-
- if (srchinfo[docno]->ID->size > MAX_DOCID_LEN)
- return(9); // Docid too long
-
- ref_ptr->doc_size = srchinfo[docno]->ID->size;
- memcpy(ref_ptr->doc_bytes, srchinfo[docno]->ID->bytes, ref_ptr->doc_size);
- strncpy(ref_ptr->type, srchinfo[docno]->type, MAX_TYPE_LEN);
-
- return(0);
- }
-
- //**********************************************************************
- // Build a list of documents to use for relevance feedback when
- // query_titles is called.
- //**********************************************************************
-
- int far pascal _export
- reference_titles (refno, tot_ref, ref_ptr)
- int refno;
- int tot_ref;
- REF *ref_ptr;
- {
- int i;
- any* DocAny;
-
- if (refno == 0)
- {
- if (Doc != NULL)
- {
- for (i = 0; Doc[i] != NULL; i++)
- {
- Doc[i]->DocumentID->bytes = NULL; // bytes/type passed by VB, so
- Doc[i]->Type = NULL; // don't free bytes; DO free the
- freeDocObj(Doc[i]); // any and docobj
- }
- s_free(Doc);
- }
- Doc = (DocObj**) s_malloc((long)((tot_ref+1) * sizeof(char*)));
- }
-
- DocAny = makeAny(ref_ptr->doc_size, ref_ptr->doc_bytes);
-
- if (ref_ptr->ch_start < 0)
- Doc[refno] = makeDocObjUsingWholeDocument(DocAny, ref_ptr->type);
- else
- Doc[refno] = makeDocObjUsingLines(DocAny,
- ref_ptr->type,
- ref_ptr->ch_start,
- ref_ptr->ch_end);
-
- Doc[refno + 1] = NULL;
- return(0);
- }
-
- //**********************************************************************
- // Use a server_name, database and port to query servers and store
- // returned titles.
- //**********************************************************************
-
- int far pascal _export
- query_titles(func, tot_ref, server_name, database, keywords, port)
- int func;
- int tot_ref;
- char *server_name;
- char *database;
- char *keywords;
- long port;
- {
- int i;
- long max_length, inBuf_length;
- static int source_id = -1;
-
- SearchResponseAPDU *query_response;
- WAISSearchResponse *query_info;
-
- if (func == 0)
- {
- source_id = -1;
- count = lcount = 0;
- }
-
- source_id++;
-
- if (0 == strcmp(keywords,""))
- keywords = NULL;
-
- if ((tot_ref == 0) && (Doc != NULL))
- {
- for (i = 0; Doc[i] != NULL; i++)
- {
- Doc[i]->DocumentID->bytes = NULL; // bytes/type passed by VB, so
- Doc[i]->Type = NULL; // don't free bytes, DO free the
- freeDocObj(Doc[i]); // any and docobj
- }
- s_free(Doc);
- Doc = NULL;
- }
-
- if (NULL == (connection = connect_to_server(server_name,port)))
- return(2); // Server connection failed
-
- if (0 > (max_length=init_connection(inBuf,outBuf,(long)MAX_MESSAGE_LEN,connection)))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return(2);
- }
-
- inBuf_length = max_length;
-
- if (NULL == generate_search_apdu((inBuf + HEADER_LENGTH),
- (long *)&inBuf_length,
- keywords,
- database,
- (long)Doc, // relevant documents
- (long)maxdocs))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return(3); // Request too large
- }
-
- if (0L == interpret_message(inBuf,
- (long)(max_length - inBuf_length),
- outBuf,
- (long)max_length,
- connection,
- false))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return (4); // Returned message too large
- }
-
- close_connection_to_server(connection);
- connection = NULL;
-
- readSearchResponseAPDU(&query_response, outBuf + HEADER_LENGTH);
-
- query_info = (WAISSearchResponse *)query_response->DatabaseDiagnosticRecords;
-
- if(query_info->Diagnostics!=NULL)
- return (5);
-
- if(query_response->NumberOfRecordsReturned > 0)
- copy_query(query_info, server_name, database, port, source_id);
-
- freeWAISSearchResponse(query_response->DatabaseDiagnosticRecords);
- freeSearchResponseAPDU(query_response);
-
- qsort(srchinfo, count, sizeof(struct fdc *), cmp);
-
- while (count > maxdocs)
- {
- if (srchinfo[count] != NULL)
- {
- if (srchinfo[count]->type != NULL)
- s_free(srchinfo[count]->type);
- if (srchinfo[count]->ID != NULL)
- freeAny(srchinfo[count]->ID);
- s_free(srchinfo[count]);
- srchinfo[count] = NULL;
- }
- count--;
- }
-
- if (func == 2)
- {
- lcount = count;
- count = 0;
- source_id = -1;
- }
-
- return (0);
- }
-
- //**********************************************************************
- // Get titles that were stored in response to query_titles()
- //**********************************************************************
-
- int far pascal _export
- get_titles(docno, doc_ptr)
- int docno;
- DOC *doc_ptr;
- {
- if (lcount == 0)
- return (8); // No documents found
-
- if (docno > lcount - 1)
- return (7); // Invalid document number
-
- doc_ptr->length = srchinfo[docno]->length;
- doc_ptr->source = srchinfo[docno]->source;
- doc_ptr->score = srchinfo[docno]->score;
- strncpy(doc_ptr->type, srchinfo[docno]->type, MAX_TYPE_LEN);
- strncpy(doc_ptr->headline, srchinfo[docno]->headline, MAX_HEADLINE_LEN);
-
- if (docno == (lcount-1))
- return(1); // Last document number
-
- return(0);
- }
-
- //**********************************************************************
- // Get a document using the supplied document number and type
- //**********************************************************************
-
- int far pascal _export
- get_document(docno, dtype)
- int docno;
- char *dtype;
- {
- FILE *fp;
- SearchResponseAPDU *retrieval_response;
- diagnosticRecord **diag;
- char server_name[MAX_SERVER_LEN];
- char database[MAX_DBNAME_LEN];
- long port;
- long inBuf_length, max_length;
- long len, tmplen, buf_pos;
- long a, b;
- long ch_start, ch_end;
- long entry_no;
- any* DocAny;
- char work_file[255];
-
- char *oldType = NULL;
- any *oldID = NULL;
-
- int retcode = 0;
-
- if ( docno > lcount-1 && docno != CURRDOC)
- return (7); // Invalid document number
-
- strncpy(server_name, srchinfo[docno]->server, MAX_SERVER_LEN);
- strncpy(database, srchinfo[docno]->dbname, MAX_DBNAME_LEN);
- port = srchinfo[docno]->port;
-
- if (NULL == (connection = connect_to_server(server_name, port)))
- return(2); // Server connection failed
-
- if (0 > (max_length = init_connection(inBuf,
- outBuf,
- (long)MAX_MESSAGE_LEN,
- connection)))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return(2);
- }
-
- inBuf_length = (long)max_length;
-
- strcpy(work_file, temp_path);
- strcat(work_file, "\\wais.$$$");
- fp=fopen(work_file, "wb");
-
- entry_no = 0;
-
- //tmplen = srchinfo[docno]->length;
- tmplen = CHARS_PER_PAGE;
-
- //for(buf_pos = 0L; buf_pos * CHARS_PER_PAGE < tmplen; buf_pos++)
- for(buf_pos = 0L ;; buf_pos++)
- {
- char *type;
-
- inBuf_length = (long)max_length;
- ch_start = (long)buf_pos * CHARS_PER_PAGE;
-
- //ch_end = MIN((buf_pos + 1) * CHARS_PER_PAGE, tmplen);
- ch_end = (long)(buf_pos + 1) * CHARS_PER_PAGE;
-
- DocAny = makeAny(srchinfo[docno]->ID->size,
- srchinfo[docno]->ID->bytes);
- if (0L == generate_retrieval_apdu(inBuf + HEADER_LENGTH,
- (long *)&inBuf_length,
- DocAny,
- (long)CT_byte,
- (long)ch_start,
- (long)ch_end,
- dtype,
- srchinfo[docno]->dbname))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return(3); // Request too large
- }
-
- s_free(DocAny);
-
- if (0L == (len = interpret_message(inBuf,
- (long)(max_length - inBuf_length),
- outBuf,
- (long)max_length,
- connection,
- false)))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return (4); // Returned message too large
- }
-
- readSearchResponseAPDU(&retrieval_response, outBuf + HEADER_LENGTH);
-
- if (NULL == ((WAISSearchResponse *)retrieval_response->
- DatabaseDiagnosticRecords)->
- Text)
- break;
-
- if(0 == strncmp(dtype,"TEXT",4) || 0 == strncmp(dtype,"WSRC",4))
- {
- save_text_record_completely(((WAISSearchResponse *)retrieval_response->
- DatabaseDiagnosticRecords)->Text[0],
- false,
- fp,
- entry_no++);
- }
- else
- {
- save_binary_record_completely(((WAISSearchResponse *)retrieval_response->
- DatabaseDiagnosticRecords)->Text[0],
- fp);
- }
-
- diag = ((WAISSearchResponse *)retrieval_response->
- DatabaseDiagnosticRecords)->Diagnostics;
-
- if (diag != NULL)
- {
- if (0 != strncmp(diag[0]->DIAG, "SF", 2))
- retcode = 5;
- break;
- }
-
- // if(len < CHARS_PER_PAGE)
- // break;
- }
-
- fclose(fp);
- freeWAISSearchResponse(retrieval_response->DatabaseDiagnosticRecords);
- freeSearchResponseAPDU(retrieval_response);
-
- close_connection_to_server(connection);
- connection = NULL;
-
- if(retcode == 0)
- {
- if(srchinfo[CURRDOC] == NULL)
- srchinfo[CURRDOC] = (struct fdc *)s_malloc((long)sizeof(struct fdc));
- else
- {
- oldID = srchinfo[CURRDOC]->ID;
- oldType = srchinfo[CURRDOC]->type;
- }
-
- srchinfo[CURRDOC]->ID = duplicateAny(srchinfo[docno]->ID);
- srchinfo[CURRDOC]->type = s_strdup(srchinfo[docno]->type);
- srchinfo[CURRDOC]->length = srchinfo[docno]->length;
- srchinfo[CURRDOC]->port = srchinfo[docno]->port;
- strncpy(srchinfo[CURRDOC]->server, srchinfo[docno]->server,
- MAX_SERVER_LEN);
- strncpy(srchinfo[CURRDOC]->dbname, srchinfo[docno]->dbname,
- MAX_DBNAME_LEN);
- srchinfo[CURRDOC]->score = srchinfo[docno]->score;
- srchinfo[CURRDOC]->source = srchinfo[docno]->source;
- strncpy(srchinfo[CURRDOC]->headline, srchinfo[docno]->headline,
- MAX_HEADLINE_LEN);
-
- if(oldID != NULL)
- freeAny(oldID);
- if(oldType != NULL)
- s_free(oldType);
- }
-
- return(retcode);
- }
-
- //**********************************************************************
- // Get next or previous
- //**********************************************************************
-
- int far pascal _export
- get_next_or_prev(dtype, doc_ptr)
- char *dtype;
- DOC *doc_ptr;
- {
- SearchResponseAPDU *query_response;
- WAISSearchResponse *query_info;
-
- char server_name[MAX_SERVER_LEN];
- char database[MAX_DBNAME_LEN];
- long port;
- long source;
-
- long inBuf_length, max_length;
- int save_count;
-
- static DocObj *thisDoc[2] = {NULL, NULL};
-
- if (thisDoc[0] != NULL)
- {
- thisDoc[0]->Type = NULL; // don't free, belongs to VB
- thisDoc[0]->DocumentID = NULL; // belongs to srchinfo[CURRDOC]
- freeDocObj(thisDoc[0]);
- }
-
- thisDoc[0] = makeDocObjUsingWholeDocument(srchinfo[CURRDOC]->ID, dtype);
-
- strncpy(server_name, srchinfo[CURRDOC]->server, MAX_SERVER_LEN);
- strncpy(database, srchinfo[CURRDOC]->dbname, MAX_DBNAME_LEN);
- port = srchinfo[CURRDOC]->port;
- source = srchinfo[CURRDOC]->source;
-
- if (NULL == (connection = connect_to_server(server_name, port)))
- return(2); // Server connection failed
-
- if (0 > (max_length = init_connection(inBuf,
- outBuf,
- (long)MAX_MESSAGE_LEN,
- connection)))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return(2);
- }
-
- inBuf_length = (long) max_length;
-
- if (0L == generate_search_apdu(inBuf + HEADER_LENGTH,
- (long *)&inBuf_length,
- "foo",
- database,
- thisDoc,
- 1L))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return(3); // Request too large
- }
-
- if (0L == interpret_message(inBuf,
- (long)(max_length - inBuf_length),
- outBuf,
- (long)max_length,
- connection,
- false))
- {
- close_connection_to_server(connection);
- connection = NULL;
- return (4); // Returned message too large
- }
-
- close_connection_to_server(connection);
- connection = NULL;
-
- readSearchResponseAPDU(&query_response, outBuf + HEADER_LENGTH);
-
- query_info = (WAISSearchResponse *)query_response->
- DatabaseDiagnosticRecords;
-
- if(query_info->Diagnostics != NULL)
- return(5);
-
- if(query_response->NumberOfRecordsReturned > 0)
- {
- save_count = count;
- count = CURRDOC;
- copy_query(query_info, server_name, database, port, source);
- count = save_count;
- }
-
- doc_ptr->length = srchinfo[CURRDOC]->length;
- doc_ptr->source = srchinfo[CURRDOC]->source;
- doc_ptr->score = srchinfo[CURRDOC]->score;
- strncpy(doc_ptr->type, srchinfo[CURRDOC]->type, MAX_TYPE_LEN);
- strncpy(doc_ptr->headline, srchinfo[CURRDOC]->headline, MAX_HEADLINE_LEN);
-
- freeWAISSearchResponse(query_response->DatabaseDiagnosticRecords);
- freeSearchResponseAPDU(query_response);
-
- return(0);
- }
-
- copy_query(query_info, server_name, database, port, source_id)
- WAISSearchResponse *query_info;
- char *server_name;
- char *database;
- long port;
- int source_id;
- {
- int tcnt;
- char multi_types[MAX_TYPE_LEN];
- int i=0;
-
- while(query_info->DocHeaders[i] != 0L)
- {
- if (query_info->DocHeaders[i]->DocumentLength != 0L)
- {
- if(srchinfo[count] ==NULL)
- srchinfo[count] = (struct fdc *)s_malloc((long)sizeof(struct fdc));
- else
- {
- if (srchinfo[count]->type != NULL)
- s_free(srchinfo[count]->type);
- if (srchinfo[count]->ID != NULL)
- freeAny(srchinfo[count]->ID);
- }
-
- srchinfo[count]->length = query_info->DocHeaders[i]->DocumentLength;
-
- if(srchinfo[count]->length != 0L)
- srchinfo[count]->ID = duplicateAny(query_info->DocHeaders[i]->DocumentID);
- strncpy(srchinfo[count]->dbname, database, MAX_DBNAME_LEN);
- strncpy(srchinfo[count]->server, server_name, MAX_SERVER_LEN);
- srchinfo[count]->port = port;
- strncpy(srchinfo[count]->headline, trim_junk(query_info->DocHeaders[i]->Headline),MAX_HEADLINE_LEN);
- srchinfo[count]->score = query_info->DocHeaders[i]->Score;
- srchinfo[count]->source = source_id;
-
- if(query_info->DocHeaders[i]->Types == NULL)
- srchinfo[count]->type = s_strdup("TEXT");
- else
- {
- multi_types[0] = '\0';
- for (tcnt = 0; query_info->DocHeaders[i]->Types[tcnt] != NULL; tcnt++)
- {
- strcat(multi_types, query_info->DocHeaders[i]->Types[tcnt]);
- strcat(multi_types, ",");
- }
- multi_types[strlen(multi_types)-1] = '\0';
- srchinfo[count]->type = s_strdup(multi_types);
- }
- ++count;
- if(count == 200)
- break;
- }
- ++i;
- }
- }
-
- void msgbox(msg)
- char* msg;
- {
- char buf[50];
-
- sprintf(buf, msg, WSAGetLastError());
- MessageBox(GetFocus(), buf, "WinSock Error", MB_OK);
- }
-
- int printf(ch, va_list)
- char *ch;
- {
- return(0);
- }
-
- int vprintf(fl, ch, va_list)
- FILE *fl;
- char *ch;
- {
- return(0);
- }
-
- //*******************************************************************
- //
- // MAP DRAWING ROUTINES
- //
- //*******************************************************************
-
- #define PI 3.1415926535898
- #define TWOPI 6.2831853071796
- #define DEG2RAD .01745329251994
- #define MIN2RAD DEG2RAD / 60
-
- typedef struct WDB
- {
- int rec_type;
- int lat;
- int lon;
- } WDB;
-
- int far pascal _export draw_map(int hDC, int globe, int grid,
- double ref_center_x, double ref_center_y,
- double ref_radius, double center_lon_rad,
- double sin_center_lat, double cos_center_lat);
-
- void do_grid (int hDC, double ref_center_x, double ref_center_y,
- double ref_radius, double center_lon_rad,
- double sin_center_lat, double cos_center_lat);
-
- int ortho (double inlat, double inlon, double* outx, double* outy,
- double ref_radius, double center_lon_rad,
- double sin_center_lat, double cos_center_lat);
-
- int far pascal _export draw_map(hDC, globe, grid, ref_center_x, ref_center_y, ref_radius, center_lon_rad, sin_center_lat, cos_center_lat)
- int hDC;
- int globe;
- int grid;
- double ref_center_x;
- double ref_center_y;
- double ref_radius;
- double center_lon_rad;
- double sin_center_lat;
- double cos_center_lat;
- {
- double atmp, outx, outy, inlat, inlon;
- int oldx, oldy, x, y;
- int i, first;
- FILE *wdbfile;
- WDB *wdb;
-
- // draw the outer circle for the globe into pixmap
-
- if (globe)
- {
- oldx = ref_center_x + ref_radius;
- oldy = ref_center_y;
-
- for (i = 3; i < 360; i += 3)
- {
- atmp = i * DEG2RAD;
- x = (cos(atmp) * ref_radius) + ref_center_x;
- y = (sin(atmp) * ref_radius) + ref_center_y;
-
- SetTextColor(hDC, 0x00c0c0c0);
- MoveTo(hDC, oldx, oldy);
- LineTo(hDC, x, y);
-
- oldx = x;
- oldy = y;
- }
- }
-
- // draw (10 degree) grid
-
- if (grid)
- do_grid (hDC, ref_center_x, ref_center_y, ref_radius, center_lon_rad, sin_center_lat, cos_center_lat);
-
- // open World Data Bank II reference file
-
- if (NULL == (wdbfile = fopen("WDBIIDOS", "rb")))
- return (1);
-
- wdb = s_malloc((long)sizeof(wdb));
-
- // draw World Data Bank II into pixmap
-
- first = TRUE;
-
- for (i = 0; i < 9182; i++)
- {
- fread (wdb, sizeof(int), 3, wdbfile);
-
- if (wdb->rec_type > 5)
- first = TRUE;
-
- inlat = wdb->lat * MIN2RAD;
- inlon = wdb->lon * MIN2RAD;
-
- if (0 == ortho(inlat, inlon, &outx, &outy,
- ref_radius, center_lon_rad,
- sin_center_lat, cos_center_lat))
- {
- x = outx + ref_center_x;
- y = ref_center_y - outy;
- if (first != TRUE)
- {
- SetTextColor(hDC, 0);
- MoveTo(hDC, oldx, oldy);
- LineTo(hDC, x, y);
- }
- first = FALSE;
- oldx = x;
- oldy = y;
- }
- else
- first = TRUE;
- }
-
- fclose(wdbfile);
- s_free(wdb);
-
- return(0);
- }
-
- void do_grid (hDC, ref_center_x, ref_center_y, ref_radius, center_lon_rad, sin_center_lat, cos_center_lat)
- int hDC;
- double ref_center_x;
- double ref_center_y;
- double ref_radius;
- double center_lon_rad;
- double sin_center_lat;
- double cos_center_lat;
- {
- double inlat, inlon, outx, outy;
- int oldx, oldy, x, y;
- int lat, longitude, pen_up;
-
- HPEN pen, old_pen;
-
- pen = CreatePen(PS_DOT, 1, 0x00c0c0c0);
- old_pen = SelectObject(hDC, pen);
- pen_up = TRUE;
-
- for (lat = 90; lat >= -90; lat -= 10)
- {
- inlat = lat * DEG2RAD;
- for (longitude = -180; longitude <= 180; longitude += 5)
- {
- inlon = longitude * DEG2RAD;
-
- if (0 == ortho(inlat, inlon, &outx, &outy,
- ref_radius, center_lon_rad,
- sin_center_lat, cos_center_lat))
- {
- x = outx + ref_center_x;
- y = ref_center_y - outy;
- if (!pen_up)
- {
- MoveTo(hDC, oldx, oldy);
- LineTo(hDC, x, y);
- }
- oldx = x;
- oldy = y;
- pen_up = FALSE;
- }
- else
- pen_up = TRUE;
- }
- pen_up = TRUE;
- }
-
- pen_up = TRUE;
-
- for (longitude = 180; longitude >= -180; longitude -= 10)
- {
- inlon = longitude * DEG2RAD;
- for (lat = -90; lat <= 90; lat++)
- {
- inlat = lat * DEG2RAD;
- if (0 == ortho(inlat, inlon, &outx, &outy,
- ref_radius, center_lon_rad,
- sin_center_lat, cos_center_lat))
- {
- x = outx + ref_center_x;
- y = ref_center_y - outy;
- if (!pen_up)
- {
- MoveTo(hDC, oldx, oldy);
- LineTo(hDC, x, y);
- }
- oldx = x;
- oldy = y;
- pen_up = FALSE;
- }
- else
- pen_up = TRUE;
- }
-
- pen_up = TRUE;
- }
- SelectObject(hDC, old_pen);
- DeleteObject(pen);
- }
-
- int ortho (inlat, inlon, outx, outy, ref_radius, center_lon_rad, sin_center_lat, cos_center_lat)
- double inlat;
- double inlon;
- double *outx;
- double *outy;
- double ref_radius;
- double center_lon_rad;
- double sin_center_lat;
- double cos_center_lat;
- {
-
- double delta, cosL, cosC, sin_inlat, cos_inlat;
-
- delta = inlon - center_lon_rad;
-
- if (delta < -PI)
- delta += TWOPI;
- else if (delta > PI)
- delta -= TWOPI;
-
- sin_inlat = sin(inlat);
- cos_inlat = cos(inlat);
-
- cosL = cos(delta) * cos_inlat;
- cosC = (sin_center_lat * sin_inlat) + (cos_center_lat * cosL);
-
- if (cosC >= 0)
- {
- *outx = cos_inlat * sin(delta) * ref_radius;
- *outy = ((cos_center_lat * sin_inlat) - (sin_center_lat * cosL)) * ref_radius;
- return(0);
- }
-
- return (-1);
- }
-
-
- //*******************************************************************
- //
- // MISCELLANEOUS SUPPORT ROUTINES
- //
- //*******************************************************************
-
- int far pascal _export set_maxdocs(int maximum)
- {
- if (maximum <= MAXDOCS_LIMIT)
- maxdocs = maximum;
- else
- maxdocs = MAXDOCS_LIMIT;
- return(0);
- }
-
- int far pascal _export set_path(path1, path2)
- char* path1;
- char* path2;
- {
- strncpy(db_path, path1, sizeof(db_path));
- strncpy(temp_path, path2, sizeof(temp_path));
- vb_data = FP_SEG(db_path);
- return(0);
- }
-
- long far pascal _export get_alloc_mem()
- {
- return(allocated_memory);
- }
-
- int far pascal _export coprocessor_status()
- {
- int stat;
-
- asm mov ax, 0e00h
- asm int 31h
- asm mov stat, ax
-
- return(stat & 4);
- }
-
- //*******************************************************************
- //
- // DLL ENTRY AND EXIT ROUTINES
- //
- //*******************************************************************
-
- int far pascal LibMain (Instance, DataSeg, HeapSize, CmdLine)
- HANDLE Instance;
- WORD DataSeg;
- WORD HeapSize;
- LPSTR CmdLine;
- {
- Doc = NULL;
-
- s_meminit(3);
- inBuf = s_malloc((long)MAX_MESSAGE_LEN);
- outBuf = s_malloc((long)MAX_MESSAGE_LEN);
-
- return(1);
- }
-
- int far pascal WEP (iParam)
- int iParam;
- {
- close_all_connections();
- s_free(inBuf);
- s_free(outBuf);
- s_memterm();
- return(1);
- }
-
-
-