- 积分
- 10
- 注册时间
- 2007-10-5
- 仿真币
-
- 最后登录
- 1970-1-1
|
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_sf.h>
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))
static int report_error( char *file, int line, char *call, int irc)
{
if (irc)
{
char err[133],
msg[133];
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
irc, line, file);
UF_get_fail_message(irc, err);
/* NOTE: UF_print_syslog is new in V18 */
UF_print_syslog(msg, FALSE);
UF_print_syslog(err, FALSE);
UF_print_syslog("\n", FALSE);
UF_print_syslog(call, FALSE);
UF_print_syslog(";\n", FALSE);
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n");
}
}
return(irc);
}
static logical prompt_for_text(char *prompt, char *text)
{
int
n,
resp;
resp = uc1600(prompt, text, &n);
if (resp == 3 || resp == 5) return TRUE;
return FALSE;
}
static void do_it(void)
{
int
n,
ii;
tag_t
mat_tag = NULL_TAG;
char
msg[133],
mat_name[MAX_ENTITY_NAME_SIZE+1] = { "" },
**mat_names,
**mat_librefs,
**mat_types;
while ((prompt_for_text("Enter material name to search for: ", mat_name))
&& (strlen(mat_name) > 0))
{
/* make sure the name is all in upper case */
for (ii = 0; ii < strlen(mat_name); ii++)
mat_name[ii] = toupper(mat_name[ii]);
if (UF_SF_locate_named_material(mat_name, &mat_tag) ||
(mat_tag == NULL_TAG))
{
UF_CALL(UF_SF_ask_library_materials("*", "*", mat_name, &n,
&mat_librefs, &mat_names, &mat_types));
if (n > 0)
{
UF_CALL(UF_SF_retrieve_library_material(mat_librefs[0],
&mat_tag));
UF_free_string_array(n, mat_librefs);
UF_free_string_array(n, mat_names);
UF_free_string_array(n, mat_types);
}
}
sprintf(msg, "Tag for %s is %d", mat_name, mat_tag);
uc1601(msg, TRUE);
}
}
/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
if (UF_CALL(UF_initialize())) return;
do_it();
UF_terminate();
}
int ufusr_ask_unload(void)
{
return (UF_UNLOAD_IMMEDIATELY);
} |
|