int strerror_r (int errnum, char *buf, size_t buflen) #undef strerror_r { /* Filter this out now, so that rest of this replacement knows that there is room for a non-empty message and trailing NUL. */ if (buflen <= 1) { if (buflen) *buf = '\0'; return ERANGE; } *buf = '\0'; /* Check for gnulib overrides. */ { char const *msg = strerror_override (errnum); if (msg) return safe_copy (buf, buflen, msg); } { int ret; int saved_errno = errno; #if USE_XPG_STRERROR_R { ret = __xpg_strerror_r (errnum, buf, buflen); if (ret < 0) ret = errno; if (!*buf) { /* glibc 2.13 would not touch buf on err, so we have to fall back to GNU strerror_r which always returns a thread-safe untruncated string to (partially) copy into our buf. */ safe_copy (buf, buflen, strerror_r (errnum, buf, buflen)); } } #elif USE_SYSTEM_STRERROR_R if (buflen > INT_MAX) buflen = INT_MAX; # ifdef __hpux /* On HP-UX 11.31, strerror_r always fails when buflen < 80; it also fails to change buf on EINVAL. */ { char stackbuf[80]; if (buflen < sizeof stackbuf) { ret = strerror_r (errnum, stackbuf, sizeof stackbuf); if (ret == 0) ret = safe_copy (buf, buflen, stackbuf); } else ret = strerror_r (errnum, buf, buflen); } # else ret = strerror_r (errnum, buf, buflen); /* Some old implementations may return (-1, EINVAL) instead of EINVAL. But on Haiku, valid error numbers are negative. */ # if !defined __HAIKU__ if (ret < 0) ret = errno; # endif # endif # if defined _AIX || defined __HAIKU__ /* AIX and Haiku return 0 rather than ERANGE when truncating strings; try again until we are sure we got the entire string. */ if (!ret && strlen (buf) == buflen - 1) { char stackbuf[STACKBUF_LEN]; size_t len; strerror_r (errnum, stackbuf, sizeof stackbuf); len = strlen (stackbuf); /* STACKBUF_LEN should have been large enough. */ if (len + 1 == sizeof stackbuf) abort (); if (buflen <= len) ret = ERANGE; } # else /* Solaris 10 does not populate buf on ERANGE. OpenBSD 4.7 truncates early on ERANGE rather than return a partial integer. We prefer the maximal string. We set buf[0] earlier, and we know of no implementation that modifies buf to be an unterminated string, so this strlen should be portable in practice (rather than pulling in a safer strnlen). */ if (ret == ERANGE && strlen (buf) < buflen - 1) { char stackbuf[STACKBUF_LEN]; /* STACKBUF_LEN should have been large enough. */ if (strerror_r (errnum, stackbuf, sizeof stackbuf) == ERANGE) abort (); safe_copy (buf, buflen, stackbuf); } # endif #else /* USE_SYSTEM_STRERROR */ /* Try to do what strerror (errnum) does, but without clobbering the buffer used by strerror(). */ # if defined __NetBSD__ || defined __hpux || (defined _WIN32 && !defined __CYGWIN__) || defined __CYGWIN__ /* NetBSD, HP-UX, native Windows, Cygwin */ /* NetBSD: sys_nerr, sys_errlist are declared through _NETBSD_SOURCE and <errno.h> above. HP-UX: sys_nerr, sys_errlist are declared explicitly above. native Windows: sys_nerr, sys_errlist are declared in <stdlib.h>. Cygwin: sys_nerr, sys_errlist are declared in <errno.h>. */ if (errnum >= 0 && errnum < sys_nerr) { # if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux) # if defined __NetBSD__ nl_catd catd = catopen ("libc", NL_CAT_LOCALE); const char *errmsg = (catd != (nl_catd)-1 ? catgets (catd, 1, errnum, sys_errlist[errnum]) : sys_errlist[errnum]); # endif # if defined __hpux nl_catd catd = catopen ("perror", NL_CAT_LOCALE); const char *errmsg = (catd != (nl_catd)-1 ? catgets (catd, 1, 1 + errnum, sys_errlist[errnum]) : sys_errlist[errnum]); # endif # else const char *errmsg = sys_errlist[errnum]; # endif if (errmsg == NULL || *errmsg == '\0') ret = EINVAL; else ret = safe_copy (buf, buflen, errmsg); # if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux) if (catd != (nl_catd)-1) catclose (catd); # endif } else ret = EINVAL; # elif defined __sgi || (defined __sun && !defined _LP64) /* IRIX, Solaris <= 9 32-bit */ /* For a valid error number, the system's strerror() function returns a pointer to a not copied string, not to a buffer. */ if (errnum >= 0 && errnum < sys_nerr) { char *errmsg = strerror (errnum); if (errmsg == NULL || *errmsg == '\0') ret = EINVAL; else ret = safe_copy (buf, buflen, errmsg); } else ret = EINVAL; # else gl_lock_lock (strerror_lock); { char *errmsg = strerror (errnum); /* For invalid error numbers, strerror() on - IRIX 6.5 returns NULL, - HP-UX 11 returns an empty string. */ if (errmsg == NULL || *errmsg == '\0') ret = EINVAL; else ret = safe_copy (buf, buflen, errmsg); } gl_lock_unlock (strerror_lock); # endif #endif #if defined _WIN32 && !defined __CYGWIN__ /* MSVC 14 defines names for many error codes in the range 100..140, but _sys_errlist contains strings only for the error codes < _sys_nerr = 43. */ if (ret == EINVAL) { const char *errmsg; switch (errnum) { case 100 /* EADDRINUSE */: errmsg = "Address already in use"; break; case 101 /* EADDRNOTAVAIL */: errmsg = "Cannot assign requested address"; break; case 102 /* EAFNOSUPPORT */: errmsg = "Address family not supported by protocol"; break; case 103 /* EALREADY */: errmsg = "Operation already in progress"; break; case 105 /* ECANCELED */: errmsg = "Operation canceled"; break; case 106 /* ECONNABORTED */: errmsg = "Software caused connection abort"; break; case 107 /* ECONNREFUSED */: errmsg = "Connection refused"; break; case 108 /* ECONNRESET */: errmsg = "Connection reset by peer"; break; case 109 /* EDESTADDRREQ */: errmsg = "Destination address required"; break; case 110 /* EHOSTUNREACH */: errmsg = "No route to host"; break; case 112 /* EINPROGRESS */: errmsg = "Operation now in progress"; break; case 113 /* EISCONN */: errmsg = "Transport endpoint is already connected"; break; case 114 /* ELOOP */: errmsg = "Too many levels of symbolic links"; break; case 115 /* EMSGSIZE */: errmsg = "Message too long"; break; case 116 /* ENETDOWN */: errmsg = "Network is down"; break; case 117 /* ENETRESET */: errmsg = "Network dropped connection on reset"; break; case 118 /* ENETUNREACH */: errmsg = "Network is unreachable"; break; case 119 /* ENOBUFS */: errmsg = "No buffer space available"; break; case 123 /* ENOPROTOOPT */: errmsg = "Protocol not available"; break; case 126 /* ENOTCONN */: errmsg = "Transport endpoint is not connected"; break; case 128 /* ENOTSOCK */: errmsg = "Socket operation on non-socket"; break; case 129 /* ENOTSUP */: errmsg = "Not supported"; break; case 130 /* EOPNOTSUPP */: errmsg = "Operation not supported"; break; case 132 /* EOVERFLOW */: errmsg = "Value too large for defined data type"; break; case 133 /* EOWNERDEAD */: errmsg = "Owner died"; break; case 134 /* EPROTO */: errmsg = "Protocol error"; break; case 135 /* EPROTONOSUPPORT */: errmsg = "Protocol not supported"; break; case 136 /* EPROTOTYPE */: errmsg = "Protocol wrong type for socket"; break; case 138 /* ETIMEDOUT */: errmsg = "Connection timed out"; break; case 140 /* EWOULDBLOCK */: errmsg = "Operation would block"; break; default: errmsg = NULL; break; } if (errmsg != NULL) ret = safe_copy (buf, buflen, errmsg); } #endif if (ret == EINVAL && !*buf) { #if defined __HAIKU__ /* For consistency with perror(). */ snprintf (buf, buflen, "Unknown Application Error (%d)", errnum); #else snprintf (buf, buflen, "Unknown error %d", errnum); #endif } errno = saved_errno; return ret; } }
SOM_Scope void SOMLINK ShapePartCommonInit(ShapePart *somSelf, Environment *ev, ODPart* partWrapper) { ShapePartData *somThis = ShapePartGetData(somSelf); ShapePartMethodDebug("ShapePart","ShapePartCommonInit"); try { ShapePart_parent_SimplePart_CommonInit(somSelf, ev, partWrapper); somThis->fSession = somSelf->GetStorageUnit(ev)->GetSession(ev); somThis->fPartWrapper = partWrapper; ODMenuBar *menuBar = somSelf->GetMenuBar(ev); if (menuBar) { menuBar->Acquire(ev); // Add menu item for background color ODPlatformMenuItem *mi = new ODPlatformMenuItem; // clear the memory memset (mi, 0, sizeof(ODPlatformMenuItem)); mi->id = kShapePartBGColorMenuID; menuBar->AddMenuItemLast(ev, IDMS_EDIT, kODNULL, mi); #if defined(__IBMCPP__) || defined(_IBMR2) nl_catd msgCatalog; // NLS message catalog handle char *menuText; // pointer for NLS message setlocale(LC_MESSAGES, NULL); msgCatalog = catopen(SHAPE_MSG_CATALOG, 0); if(msgCatalog == CATD_ERR) { PRINT("Could not open message catalog %s\n", SHAPE_MSG_CATALOG); } #else char menuText[256]; #endif // Set text of Background Color menu item #if defined(__IBMCPP__) || defined(_IBMR2) menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_COLORMENU, SHAPE_DEFMSG_COLORMENU); #else strcpy(menuText, SHAPE_DEFMSG_COLORMENU); #endif menuBar->SetMenuItemText (ev, IDMS_EDIT, mi->id, menuText); //let's add help menu items ONLY if this is base container // and not its subclass if (!strcmp (somSelf->somGetClassName(), kShapeClassName)) { // we add the menu items that simple part did not add since // this is a subclass // add a menu separator line to the HELP menu mi->id = kSimplePartMenuSeparator; #if defined(_PLATFORM_WIN32_) mi->afAttribute=MF_SEPARATOR; #elif defined(_PLATFORM_OS2_) mi->afAttribute=CA_TITLESEPARATOR; #endif menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi); // add shape part help menu mi->afAttribute=0; mi->id = kSimplePartHelpMenu; menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi); #if defined(__IBMCPP__) || defined(_IBMR2) menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_HELPMENU, SHAPE_DEFMSG_HELPMENU); #else strcpy(menuText, SHAPE_DEFMSG_HELPMENU); #endif menuBar->SetMenuItemText(ev, IDMS_HELP, kSimplePartHelpMenu, menuText); // add shape part info menu mi->id = kSimplePartInfoMenu; menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi); #if defined(__IBMCPP__) || defined(_IBMR2) menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_INFOMENU, SHAPE_DEFMSG_INFOMENU); #else strcpy(menuText, SHAPE_DEFMSG_INFOMENU); #endif menuBar->SetMenuItemText(ev, IDMS_HELP, kSimplePartInfoMenu, menuText); } // end if the instance is of a subclass delete mi; menuBar->Release(ev); #if defined(__IBMCPP__) || defined(_IBMR2) catclose(msgCatalog); // close the message catalog #endif } // set default background color _fBackgroundColor = kShapePartDefaultColor; // check for read only drafts _fDraftReadOnly = (somSelf->GetStorageUnit(ev)->GetDraft(ev)->GetPermissions(ev) == kODDPReadOnly); } catch(...) { } }
/*-------------------------------------------------------------------------*/ int main(int argc, const char **argv) { int fileargc, switchargc; char *fileargv[255], *switchargv[255], env_prompt[MAXSWITCH], tmp_switch[MAXSWITCH] = "", src_pathname[MYMAXPATH] = "", src_filename[MAXFILE + MAXEXT] = "", dest_pathname[MYMAXPATH] = "", dest_filename[MAXFILE + MAXEXT] = "", *ptr, ch; int i, length; THEDATE dt; #ifdef __WATCOMC__ struct dostime_t tm; #else struct time tm; #endif cat = catopen ("xcopy", 0); /* initialize kitten */ classify_args(argc, argv, &fileargc, fileargv, &switchargc, switchargv); if (fileargc < 1 || switchargv[0] == "?") { print_help(); catclose(cat); exit(4); } if (fileargc > 2) { printf("%s\n",catgets(cat, 1, 1, "Invalid number of parameters")); catclose(cat); exit(4); } /* activate termination function */ /* (writes no. of copied files at exit) */ atexit(exit_fn); /* read environment variable COPYCMD to set confirmation switch */ strmcpy(env_prompt, getenv("COPYCMD"), sizeof(env_prompt)); if (env_prompt[0] != '\0') { strupr(env_prompt); if (strcmp(env_prompt, "/Y") == 0) /* overwrite existing file(s) */ switch_confirm = 0; else if (strcmp(env_prompt, "/N") == 0) /* skip existing file(s) */ switch_confirm = 1; else /* ask for confirmation */ switch_confirm = 2; } /* get switches */ for (i = 0; i < switchargc; i++) { strmcpy(tmp_switch, switchargv[i], sizeof(tmp_switch)); strupr(tmp_switch); if (strcmp(tmp_switch, "A") == 0) switch_archive = -1; else if (strcmp(tmp_switch, "C") == 0) switch_continue = -1; else if (strcmp(tmp_switch, "D") == 0) switch_date = -1; else if (strncmp(tmp_switch, "D:", 2) == 0) { if (strtodate(tmp_switch+2, &dt) != 0 || !datevalid(&dt)) { printf("%s\n",catgets(cat, 1, 2, "Invalid date")); catclose(cat); exit(4); } #ifdef __WATCOMC__ memset((void *)&tm, 0, sizeof(struct dostime_t)); /* tm.tm_hour = 0; tm.tm_min = 0; tm.tm_sec = 0; tm.tm_hund = 0; */ #else memset((void *)&tm, 0, sizeof(struct time)); /* tm.ti_hour = 0; tm.ti_min = 0; tm.ti_sec = 0; tm.ti_hund = 0; */ #endif switch_date = dostounix(&dt, &tm); } else if (strcmp(tmp_switch, "E") == 0) switch_emptydir = -1; else if (strcmp(tmp_switch, "F") == 0) switch_fullnames = -1; else if (strcmp(tmp_switch, "H") == 0) switch_hidden = -1; else if (strcmp(tmp_switch, "I") == 0) switch_intodir = -1; else if (strcmp(tmp_switch, "L") == 0) switch_listmode = -1; else if (strcmp(tmp_switch, "M") == 0) switch_archive_reset = -1; else if (strcmp(tmp_switch, "N") == 0) switch_confirm = 1; else if (strcmp(tmp_switch, "P") == 0) switch_prompt = -1; else if (strcmp(tmp_switch, "Q") == 0) switch_quiet = -1; else if (strcmp(tmp_switch, "R") == 0) switch_readonly = -1; else if (strcmp(tmp_switch, "S") == 0) switch_subdir = -1; else if (strcmp(tmp_switch, "T") == 0) switch_tree = -1; else if (strcmp(tmp_switch, "V") == 0) { switch_verify = -1; bak_verify = getverify(); setverify(1); } else if (strcmp(tmp_switch, "W") == 0) switch_wait = -1; else if (strcmp(tmp_switch, "Y") == 0) switch_confirm = 0; else if (strcmp(tmp_switch, "-Y") == 0) switch_confirm = 2; else { printf("%s - %s\n", catgets(cat, 1, 3, "Invalid switch"), switchargv[i]); catclose(cat); exit(4); } } /* get source pathname (with trailing backspace) and filename/-pattern */ length = strlen(fileargv[0]); if (length > (MAXPATH - 1)) { printf("%s\n", catgets(cat, 1, 4, "Source path too long")); catclose(cat); exit(4); } _fullpath(src_pathname, fileargv[0], MYMAXPATH); if (src_pathname[0] == '\0') { printf("%s\n", catgets(cat, 1, 5, "Invalid source drive specification")); catclose(cat); exit(4); } /* check source path */ if (!dir_exists(src_pathname)) { /* source path contains a filename/-pattern -> separate it */ ptr = strrchr(src_pathname, *DIR_SEPARATOR); ptr++; strmcpy(src_filename, ptr, sizeof(src_filename)); *ptr = '\0'; if (!dir_exists(src_pathname)) { printf("%s - %s\n", catgets(cat, 1, 6, "Source path not found"), src_pathname); catclose(cat); exit(4); } } else { /* source is a directory -> filepattern = "*.*" */ strmcpy(src_filename, "*.*", sizeof(src_filename)); } cat_separator(src_pathname); length = strlen(src_pathname); if (length > (MAXDRIVE - 1 + MAXDIR - 1)) { printf("%s\n", catgets(cat, 1, 7, "Source path too long")); catclose(cat); exit(4); } /* get destination pathname (with trailing backspace) and */ /* filename/-pattern */ if (fileargc < 2) { /* no destination path specified -> use current */ getcwd(dest_pathname, MAXPATH); strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } else { /* destination path specified */ length = strlen(fileargv[1]); if (length > (MAXPATH - 1)) { printf("%s\n", catgets(cat, 1, 8, "Destination path too long")); catclose(cat); exit(4); } _fullpath(dest_pathname, fileargv[1], MYMAXPATH); if (dest_pathname[0] == '\0') { printf("%s\n", catgets(cat, 1, 9, "Invalid destination drive specification")); catclose(cat); exit(4); } /* check destination path */ if (fileargv[1][length - 1] != *DIR_SEPARATOR && !dir_exists(dest_pathname)) { ptr = strrchr(dest_pathname, *DIR_SEPARATOR); ptr++; strmcpy(dest_filename, ptr, sizeof(dest_filename)); *ptr = '\0'; if ((ptr = strchr(dest_filename, '*')) == NULL && (ptr = strchr(dest_filename, '?')) == NULL) { /* last destination entry is not a filepattern -> does it specify */ /* a file or directory? */ if (((ptr = strchr(src_filename, '*')) == NULL && (ptr = strchr(src_filename, '?')) == NULL) || !switch_intodir) { /* source is a single file or switch /I was not specified -> ask */ /* user if destination should be a file or a directory */ printf("%s %s %s\n", catgets(cat, 1, 10, "Does"), dest_filename, catgets(cat, 1, 11, "specify a file name")); ch = confirm( catgets(cat, 1, 12, "or directory name on the target"), catgets(cat, 1, 13, "File"), catgets(cat, 1, 14, "Directory"), NULL, NULL); switch (ch) { case 1: /* 'F' */ /* file */ switch_file = -1; break; case 2: /* 'D' */ /* directory */ switch_intodir = -1; break; } } if (switch_intodir) { /* destination is a directory -> filepattern = "*.*" */ strmcat(dest_pathname, dest_filename, sizeof(dest_pathname)); strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } } } else { /* destination is a directory -> filepattern = "*.*" */ strmcpy(dest_filename, "*.*", sizeof(dest_filename)); } } cat_separator(dest_pathname); length = strlen(dest_pathname); if (length > (MAXDRIVE - 1 + MAXDIR - 1)) { printf("%s\n",catgets(cat, 1, 15, "Destination path too long")); catclose(cat); exit(4); } /* check for cyclic path */ if ((switch_emptydir || switch_subdir) && cyclic_path(src_pathname, dest_pathname)) { printf("%s\n",catgets(cat, 1, 16, "Cannot perform a cyclic copy")); catclose(cat); exit(4); } /* get destination drive (1 = A, 2 = B, 3 = C, ...) */ dest_drive = toupper(dest_pathname[0]) - 64; if (switch_wait) { printf("%s\n",catgets(cat, 1, 17, "Press enter to continue...")); (void)getchar(); /* getch(); would need conio.h */ fflush(stdin); } xcopy_files(src_pathname, src_filename, dest_pathname, dest_filename); if (!file_found) { printf("%s - %s\n",catgets(cat, 1, 18, "File not found"), src_filename); catclose(cat); exit(1); } catclose(cat); return 0; }
int strerror_r (int errnum, char *buf, size_t buflen) #undef strerror_r { /* Filter this out now, so that rest of this replacement knows that there is room for a non-empty message and trailing NUL. */ if (buflen <= 1) { if (buflen) *buf = '\0'; return ERANGE; } *buf = '\0'; /* Check for gnulib overrides. */ { char const *msg = strerror_override (errnum); if (msg) return safe_copy (buf, buflen, msg); } { int ret; int saved_errno = errno; #if USE_XPG_STRERROR_R { ret = __xpg_strerror_r (errnum, buf, buflen); if (ret < 0) ret = errno; if (!*buf) { /* glibc 2.13 would not touch buf on err, so we have to fall back to GNU strerror_r which always returns a thread-safe untruncated string to (partially) copy into our buf. */ safe_copy (buf, buflen, strerror_r (errnum, buf, buflen)); } } #elif USE_SYSTEM_STRERROR_R if (buflen > INT_MAX) buflen = INT_MAX; # ifdef __hpux /* On HP-UX 11.31, strerror_r always fails when buflen < 80; it also fails to change buf on EINVAL. */ { char stackbuf[80]; if (buflen < sizeof stackbuf) { ret = strerror_r (errnum, stackbuf, sizeof stackbuf); if (ret == 0) ret = safe_copy (buf, buflen, stackbuf); } else ret = strerror_r (errnum, buf, buflen); } # else ret = strerror_r (errnum, buf, buflen); /* Some old implementations may return (-1, EINVAL) instead of EINVAL. */ if (ret < 0) ret = errno; # endif # ifdef _AIX /* AIX returns 0 rather than ERANGE when truncating strings; try again until we are sure we got the entire string. */ if (!ret && strlen (buf) == buflen - 1) { char stackbuf[STACKBUF_LEN]; size_t len; strerror_r (errnum, stackbuf, sizeof stackbuf); len = strlen (stackbuf); /* STACKBUF_LEN should have been large enough. */ if (len + 1 == sizeof stackbuf) abort (); if (buflen <= len) ret = ERANGE; } # else /* Solaris 10 does not populate buf on ERANGE. OpenBSD 4.7 truncates early on ERANGE rather than return a partial integer. We prefer the maximal string. We set buf[0] earlier, and we know of no implementation that modifies buf to be an unterminated string, so this strlen should be portable in practice (rather than pulling in a safer strnlen). */ if (ret == ERANGE && strlen (buf) < buflen - 1) { char stackbuf[STACKBUF_LEN]; /* STACKBUF_LEN should have been large enough. */ if (strerror_r (errnum, stackbuf, sizeof stackbuf) == ERANGE) abort (); safe_copy (buf, buflen, stackbuf); } # endif #else /* USE_SYSTEM_STRERROR */ /* Try to do what strerror (errnum) does, but without clobbering the buffer used by strerror(). */ # if defined __NetBSD__ || defined __hpux || ((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) || defined __CYGWIN__ /* NetBSD, HP-UX, native Windows, Cygwin */ /* NetBSD: sys_nerr, sys_errlist are declared through _NETBSD_SOURCE and <errno.h> above. HP-UX: sys_nerr, sys_errlist are declared explicitly above. native Windows: sys_nerr, sys_errlist are declared in <stdlib.h>. Cygwin: sys_nerr, sys_errlist are declared in <errno.h>. */ if (errnum >= 0 && errnum < sys_nerr) { # if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux) # if defined __NetBSD__ nl_catd catd = catopen ("libc", NL_CAT_LOCALE); const char *errmsg = (catd != (nl_catd)-1 ? catgets (catd, 1, errnum, sys_errlist[errnum]) : sys_errlist[errnum]); # endif # if defined __hpux nl_catd catd = catopen ("perror", NL_CAT_LOCALE); const char *errmsg = (catd != (nl_catd)-1 ? catgets (catd, 1, 1 + errnum, sys_errlist[errnum]) : sys_errlist[errnum]); # endif # else const char *errmsg = sys_errlist[errnum]; # endif if (errmsg == NULL || *errmsg == '\0') ret = EINVAL; else ret = safe_copy (buf, buflen, errmsg); # if HAVE_CATGETS && (defined __NetBSD__ || defined __hpux) if (catd != (nl_catd)-1) catclose (catd); # endif } else ret = EINVAL; # elif defined __sgi || (defined __sun && !defined _LP64) /* IRIX, Solaris <= 9 32-bit */ /* For a valid error number, the system's strerror() function returns a pointer to a not copied string, not to a buffer. */ if (errnum >= 0 && errnum < sys_nerr) { char *errmsg = strerror (errnum); if (errmsg == NULL || *errmsg == '\0') ret = EINVAL; else ret = safe_copy (buf, buflen, errmsg); } else ret = EINVAL; # else gl_lock_lock (strerror_lock); { char *errmsg = strerror (errnum); /* For invalid error numbers, strerror() on - IRIX 6.5 returns NULL, - HP-UX 11 returns an empty string. */ if (errmsg == NULL || *errmsg == '\0') ret = EINVAL; else ret = safe_copy (buf, buflen, errmsg); } gl_lock_unlock (strerror_lock); # endif #endif if (ret == EINVAL && !*buf) snprintf (buf, buflen, "Unknown error %d", errnum); errno = saved_errno; return ret; } }
void Application::open_catalog() { // open message catalog file catd = catopen("MotifApp", NL_CAT_LOCALE); }
int main (int argc, char *argv[]) { FILE *instream; struct stat fstat_input; long bytes_in = 0L; int mychar; time_t now, start_stamp; setlocale (LC_ALL, ""); dtsearch_catd = catopen (FNAME_DTSRCAT, 0); printf (catgets(dtsearch_catd, MS_huff, 40, "HUFFCODE Version %s\n"), AUSAPI_VERSION); /* validate user's command line arguments */ user_args_processor (argc, argv); /* initialize tree table, using the table file if it exists */ init_treebase (); if (total_count == 0L) printf (catgets(dtsearch_catd, MS_huff, 41, "Huffman Code Tables will be newly created.\n")); else printf (catgets(dtsearch_catd, MS_huff, 42, "Table '%s' already contains %ld Kbytes from previous runs.\n"), filename_huf, total_count / 1000L); if (!input_file_specified && no_huffcode_file) { fprintf (stderr, catgets(dtsearch_catd, MS_huff, 43, "645 Input file not specified and '%s' table file\n" " doesn't exist--nothing to do!\n"), filename_huf); print_usage (); exit (2); } /* read the input file and count its bytes */ if (input_file_specified) { if ((instream = fopen (filename_input, "rb")) == NULL) { BAD_INPUT_FILE: fprintf (stderr, catgets(dtsearch_catd, MS_huff, 44, "Could not open input file '%s' or access status: %s\n"), filename_input, strerror (errno)); exit (2); } if (fstat (fileno (instream), &fstat_input) == -1) goto BAD_INPUT_FILE; printf (catgets(dtsearch_catd, MS_huff, 45, "Input file '%s' contains about %ld Kbytes.\n"), filename_input, fstat_input.st_size / 1000L); time (&start_stamp); while ((mychar = getc (instream)) != EOF) { hctree1[mychar].count++; total_count++; /* echo progress to user every so often */ if (!(++bytes_in % 10000L)) printf (catgets(dtsearch_catd, MS_huff, 46, "\r%ld%% done. %2ld Kbytes read. " "Estimate %3ld seconds to completion. "), (bytes_in * 100L) / fstat_input.st_size, bytes_in / 1000L, (fstat_input.st_size - bytes_in) * (time (NULL) - start_stamp) / bytes_in); } /* end read loop for each char in input file */ putchar ('\n'); fclose (instream); } /* endif that processes input file */ /* build huffman code tree, write out files */ time (&now); /* this will be the official tree id time * stamp */ printf (catgets(dtsearch_catd, MS_huff, 47, "Identifying timestamp will be '%ld'.\n" "%s Huffman Code Tables in '%s' and '%s'..."), now, (no_huffcode_file) ? catgets(dtsearch_catd, MS_huff, 48, "Creating") : catgets(dtsearch_catd, MS_huff, 49, "Rebuilding"), filename_huf, filename_huc); huffman_code (now); putchar ('\n'); return 0; } /* end of function main */
/** * Retrieve the message text for a give error code. * * @param code The Rexx error code * * @return The error message associated with that code. */ RexxString *SystemInterpreter::getMessageText(wholenumber_t code ) { #if defined( HAVE_NL_TYPES_H ) nl_catd catd; /* catalog descriptor from catopen() */ #endif int set_num = 1; /* message set 1 from catalog */ ERROR_MESSAGE *p; /* message table scan pointer */ int msgid; /* message number */ char DataArea[256]; /* buf to return message */ const char * message; /* loop through looking for the */ /* error code */ #if defined( HAVE_CATOPEN ) for (p = Message_table; p->code != 0; p++) { if (p->code == code) { /* found the target code? */ msgid = p->msgid; /* get msg number associated w/ error*/ /* open message catalog in NLSPATH */ if ((catd = catopen(REXXMESSAGEFILE, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) { sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE); if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) { sprintf(DataArea, "Cannot open REXX message catalog %s. Not in NLSPATH or %s.", REXXMESSAGEFILE, ORX_CATDIR); return new_string(DataArea); } } /* retrieve message from repository */ message = catgets(catd, set_num, msgid, NULL); if (!message) /* got a message ? */ { #if defined(OPSYS_LINUX) && !defined(OPSYS_SUN) sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE); if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) { sprintf(DataArea, "Cannot open REXX message catalog %s. Not in NLSPATH or %s.", REXXMESSAGEFILE, ORX_CATDIR); return new_string(DataArea); } else { message = catgets(catd, set_num, msgid, NULL); if (!message) /* got a message ? */ { strcpy(DataArea,"Error message not found!"); } else { strcpy(DataArea, message); } } #else strcpy(DataArea,"Error message not found!"); #endif } else { strcpy(DataArea, message); } catclose(catd); /* close the catalog */ /* convert and return the message */ return new_string(DataArea); } } return OREF_NULL; /* no message retrieved */ #else sprintf(DataArea,"Cannot get description for error %d",msgid); return new_string(&DataArea); #endif }
nl_catd_type _Locale_catopen(struct _Locale_messages *__loc, const char *__cat_name ) { return catopen( __cat_name, NL_CAT_LOCALE ); }
/* * XPG 1987, Vol. 3, Section 4.4 specifies the environment * variable NLSPATH (example: * NLSPATH=/nlslib/%L/%N.cat:/nlslib/%N/%L * where %L stands for the value of the environment variable LANG, * and %N stands for the `name' argument of catopen(). * The environ(5) page specifies more precisely that * LANG is of the form * LANG=language[_territory[.codeset]] * and adds %l, %t, %c for the three parts of LANG, without the * _ or . and are NULL when these parts are missing. * It also specifies %% for a single % sign. * A leading colon, or a pair of adjacent colons, in NLSPATH * specifies the current directory. (Meant is that "" stands for "%N".) * */ static nl_catd my_catopenpath(char *name, char *nlspath) { int fd; nl_catd cfd = (nl_catd) -1; char *path0, *path, *s, *file, *lang, *lang_l, *lang_t, *lang_c; int langsz, namesz, sz, lang_l_sz, lang_t_sz, lang_c_sz; namesz = strlen(name); lang = getenv("LANG"); if (!lang) lang = ""; langsz = strlen(lang); lang_l = lang; s = index(lang_l, '_'); if (!s) { lang_t = lang_c = ""; lang_l_sz = langsz; lang_t_sz = lang_c_sz = 0; } else { lang_l_sz = s - lang_l; lang_t = s+1; s = index(lang_t, '.'); if (!s) { lang_c = ""; lang_t_sz = langsz - lang_l_sz - 1; lang_c_sz = 0; } else { lang_t_sz = s - lang_t; lang_c = s+1; lang_c_sz = langsz - lang_l_sz - lang_t_sz - 2; } } /* figure out how much room we have to malloc() */ sz = 0; s = nlspath; while(*s) { if(*s == '%') { s++; switch(*s) { case '%': sz++; break; case 'N': sz += namesz; break; case 'L': sz += langsz; break; case 'l': sz += lang_l_sz; break; case 't': sz += lang_t_sz; break; case 'c': sz += lang_c_sz; break; default: /* unknown escape - ignore */ break; } } else if (*s == ':' && (s == nlspath || s[-1] == ':')) { sz += (namesz + 1); } else sz++; s++; } /* expand the %L and %N escapes */ path0 = my_malloc(sz + 1); path = path0; s = nlspath; while(*s) { if(*s == '%') { s++; switch(*s) { case '%': *path++ = '%'; break; case 'N': strncpy(path, name, namesz); path += namesz; break; case 'L': strncpy(path, lang, langsz); path += langsz; break; case 'l': strncpy(path, lang_l, lang_l_sz); path += lang_l_sz; break; case 't': strncpy(path, lang_t, lang_t_sz); path += lang_t_sz; break; case 'c': strncpy(path, lang_c, lang_c_sz); path += lang_c_sz; break; default: /* unknown escape - ignore */ break; } } else if (*s == ':' && (s == nlspath || s[-1] == ':')) { strncpy(path, name, namesz); path += namesz; *path++ = ':'; } else *path++ = *s; s++; } *path = 0; path = path0; while(path) { file = path; s = index(path, ':'); if (s) { *s = 0; path = s+1; } else path = 0; fd = open(file, O_RDONLY); if (fd != -1) { /* we found the right catalog - but we don't know the type of nl_catd, so close it again and ask libc */ close(fd); cfd = catopen(file, 0); break; } } free(path0); return cfd; }
/* XXX: negative 'num' ? (REGR) */ char * strsignal(int num) { char *ebuf; char tmp[20]; size_t n; int signum; char *t, *p; #if defined(NLS) int saved_errno = errno; nl_catd catd; catd = catopen("libc", NL_CAT_LOCALE); #endif ebuf = sig_tlsalloc(); if (num > 0 && num < sys_nsig) { n = strlcpy(ebuf, #if defined(NLS) catgets(catd, 2, num, sys_siglist[num]), #else sys_siglist[num], #endif sizeof(sig_ebuf)); } else { n = strlcpy(ebuf, #if defined(NLS) catgets(catd, 2, 0xffff, UPREFIX), #else UPREFIX, #endif sizeof(sig_ebuf)); signum = num; if (num < 0) signum = -signum; t = tmp; do { *t++ = "0123456789"[signum % 10]; } while (signum /= 10); if (num < 0) *t++ = '-'; p = (ebuf + n); *p++ = ':'; *p++ = ' '; for (;;) { *p++ = *--t; if (t <= tmp) break; } *p = '\0'; } #if defined(NLS) catclose(catd); errno = saved_errno; #endif return (ebuf); }
int main(int argc, char **argv) { int cnt; char *target = NULL, *date = NULL, *view = NULL, *uname, *loc; Props *p = NULL; CSA_session_handle c_handle; CSA_entry_handle *list; CSA_return_code stat; CSA_calendar_user csa_user; int version; #ifdef FNS char buf[256]; #endif init_time(); _DtEnvControl(DT_ENV_SET); /* set up environment variables */ setlocale(LC_ALL, ""); DT_catd = catopen(DTCM_CAT, NL_CAT_LOCALE); cm_tty_load_props(&p); cm_args(argc,argv); /* parse command line */ target = (cm_strlen(cm_target)) ? cm_target : cm_get_credentials(); #ifdef FNS dtfns_init(); if (cmfns_use_fns(p)) { cmfns_lookup_calendar(target, buf, sizeof(buf)); target = buf; } #endif uname = cm_target2name(target); loc = cm_target2location(target); csa_user.user_name = target; csa_user.user_type = 0; csa_user.calendar_user_extensions = NULL; csa_user.calendar_address = target; stat = csa_logon(NULL, &csa_user, NULL, NULL, NULL, &c_handle, NULL); if (stat != CSA_SUCCESS) { char *format = cm_strdup(catgets(DT_catd, 1, 208, "\nCould not open calendar \"%s\"\n")); fprintf(stderr, format, target ? target : catgets(DT_catd, 1, 209, "UNKNOWN")); free(format); free(uname); free(loc); exit(1); } version = get_data_version(c_handle); if (cm_strlen(cm_date)) date = cm_date; if (cm_strlen(cm_view)) view = cm_view; if ((cnt = cm_tty_lookup(DT_catd, c_handle, version, date, view, &list, p)) > 0) csa_free(list); csa_logoff(c_handle, NULL); props_clean_up(p); free(p); free(uname); free(loc); return 0; }
XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // Public Constructors and Destructor // --------------------------------------------------------------------------- MsgCatalogLoader::MsgCatalogLoader(const XMLCh* const msgDomain) :fCatalogHandle(0) ,fMsgSet(0) { if (!XMLString::equals(msgDomain, XMLUni::fgXMLErrDomain) && !XMLString::equals(msgDomain, XMLUni::fgExceptDomain) && !XMLString::equals(msgDomain, XMLUni::fgXMLDOMMsgDomain) && !XMLString::equals(msgDomain, XMLUni::fgValidityDomain)) { XMLPlatformUtils::panic(PanicHandler::Panic_UnknownMsgDomain); } // Prepare the path info char locationBuf[1024]; memset(locationBuf, 0, sizeof locationBuf); const char *nlsHome = XMLMsgLoader::getNLSHome(); if (nlsHome) { strcpy(locationBuf, nlsHome); strcat(locationBuf, "/"); } else { nlsHome = getenv("XERCESC_NLS_HOME"); if (nlsHome) { strcpy(locationBuf, nlsHome); strcat(locationBuf, "/"); } else { nlsHome = getenv("XERCESCROOT"); if (nlsHome) { strcpy(locationBuf, nlsHome); strcat(locationBuf, "/msg/"); } } } // Prepare user-specified locale specific cat file char catuser[1024]; memset(catuser, 0, sizeof catuser); strcpy(catuser, locationBuf); strcat(catuser, "XercesMessages_"); strcat(catuser, XMLMsgLoader::getLocale()); strcat(catuser, ".cat"); char catdefault[1024]; memset(catdefault, 0, sizeof catdefault); strcpy(catdefault, locationBuf); strcat(catdefault, "XercesMessages_en_US.cat"); /** * To open user-specified locale specific cat file * and default cat file if necessary */ if ( ((int)(fCatalogHandle=catopen(catuser, 0)) == -1) && ((int)(fCatalogHandle=catopen(catdefault, 0)) == -1) ) { // Probably have to call panic here printf("Could not open catalog:\n %s\n or %s\n", catuser, catdefault); XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain); } if (XMLString::equals(msgDomain, XMLUni::fgXMLErrDomain)) fMsgSet = CatId_XMLErrs; else if (XMLString::equals(msgDomain, XMLUni::fgExceptDomain)) fMsgSet = CatId_XMLExcepts; else if (XMLString::equals(msgDomain, XMLUni::fgValidityDomain)) fMsgSet = CatId_XMLValid; else if (XMLString::equals(msgDomain, XMLUni::fgXMLDOMMsgDomain)) fMsgSet = CatId_XMLDOMMsg; }
int _Locale_catopen(struct _Locale_messages*l, const char* cat_name) { return (int)catopen(cat_name, 0); /* JGS, don't know about the flag */ }
int main(int argc, char *argv[]) { char **aargv, **eargv, *eopts; char *ep; const char *pn; unsigned long long l; unsigned int aargc, eargc, i; int c, lastc, needpattern, newarg, prevoptind; setlocale(LC_ALL, ""); #ifndef WITHOUT_NLS catalog = catopen("grep", NL_CAT_LOCALE); #endif /* Check what is the program name of the binary. In this way we can have all the funcionalities in one binary without the need of scripting and using ugly hacks. */ pn = getprogname(); if (pn[0] == 'b' && pn[1] == 'z') { filebehave = FILE_BZIP; pn += 2; } else if (pn[0] == 'x' && pn[1] == 'z') { filebehave = FILE_XZ; pn += 2; } else if (pn[0] == 'l' && pn[1] == 'z') { filebehave = FILE_LZMA; pn += 2; } else if (pn[0] == 'z') { filebehave = FILE_GZIP; pn += 1; } switch (pn[0]) { case 'e': grepbehave = GREP_EXTENDED; break; case 'f': grepbehave = GREP_FIXED; break; } lastc = '\0'; newarg = 1; prevoptind = 1; needpattern = 1; eopts = getenv("GREP_OPTIONS"); /* support for extra arguments in GREP_OPTIONS */ eargc = 0; if (eopts != NULL && eopts[0] != '\0') { char *str; /* make an estimation of how many extra arguments we have */ for (unsigned int j = 0; j < strlen(eopts); j++) if (eopts[j] == ' ') eargc++; eargv = (char **)grep_malloc(sizeof(char *) * (eargc + 1)); eargc = 0; /* parse extra arguments */ while ((str = strsep(&eopts, " ")) != NULL) if (str[0] != '\0') eargv[eargc++] = grep_strdup(str); aargv = (char **)grep_calloc(eargc + argc + 1, sizeof(char *)); aargv[0] = argv[0]; for (i = 0; i < eargc; i++) aargv[i + 1] = eargv[i]; for (int j = 1; j < argc; j++, i++) aargv[i + 1] = argv[j]; aargc = eargc + argc; } else { aargv = argv; aargc = argc; } while (((c = getopt_long(aargc, aargv, optstr, long_options, NULL)) != -1)) { switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (newarg || !isdigit(lastc)) Aflag = 0; else if (Aflag > LLONG_MAX / 10) { errno = ERANGE; err(2, NULL); } Aflag = Bflag = (Aflag * 10) + (c - '0'); break; case 'C': if (optarg == NULL) { Aflag = Bflag = 2; break; } /* FALLTHROUGH */ case 'A': /* FALLTHROUGH */ case 'B': errno = 0; l = strtoull(optarg, &ep, 10); if (((errno == ERANGE) && (l == ULLONG_MAX)) || ((errno == EINVAL) && (l == 0))) err(2, NULL); else if (ep[0] != '\0') { errno = EINVAL; err(2, NULL); } if (c == 'A') Aflag = l; else if (c == 'B') Bflag = l; else Aflag = Bflag = l; break; case 'a': binbehave = BINFILE_TEXT; break; case 'b': bflag = true; break; case 'c': cflag = true; break; case 'D': if (strcasecmp(optarg, "skip") == 0) devbehave = DEV_SKIP; else if (strcasecmp(optarg, "read") == 0) devbehave = DEV_READ; else errx(2, getstr(3), "--devices"); break; case 'd': if (strcasecmp("recurse", optarg) == 0) { Hflag = true; dirbehave = DIR_RECURSE; } else if (strcasecmp("skip", optarg) == 0) dirbehave = DIR_SKIP; else if (strcasecmp("read", optarg) == 0) dirbehave = DIR_READ; else errx(2, getstr(3), "--directories"); break; case 'E': grepbehave = GREP_EXTENDED; break; case 'e': add_pattern(optarg, strlen(optarg)); needpattern = 0; break; case 'F': grepbehave = GREP_FIXED; break; case 'f': read_patterns(optarg); needpattern = 0; break; case 'G': grepbehave = GREP_BASIC; break; case 'H': Hflag = true; break; case 'h': Hflag = false; hflag = true; break; case 'I': binbehave = BINFILE_SKIP; break; case 'i': case 'y': iflag = true; cflags |= REG_ICASE; break; case 'J': #ifdef WITHOUT_BZIP2 errno = EOPNOTSUPP; err(2, "bzip2 support was disabled at compile-time"); #endif filebehave = FILE_BZIP; break; case 'L': lflag = false; Lflag = true; break; case 'l': Lflag = false; lflag = true; break; case 'm': mflag = true; errno = 0; mcount = strtoll(optarg, &ep, 10); if (((errno == ERANGE) && (mcount == LLONG_MAX)) || ((errno == EINVAL) && (mcount == 0))) err(2, NULL); else if (ep[0] != '\0') { errno = EINVAL; err(2, NULL); } break; case 'M': filebehave = FILE_LZMA; break; case 'n': nflag = true; break; case 'O': linkbehave = LINK_EXPLICIT; break; case 'o': oflag = true; cflags &= ~REG_NOSUB; break; case 'p': linkbehave = LINK_SKIP; break; case 'q': qflag = true; break; case 'S': linkbehave = LINK_READ; break; case 'R': case 'r': dirbehave = DIR_RECURSE; Hflag = true; break; case 's': sflag = true; break; case 'U': binbehave = BINFILE_BIN; break; case 'u': case MMAP_OPT: filebehave = FILE_MMAP; break; case 'V': printf(getstr(9), getprogname(), VERSION); exit(0); case 'v': vflag = true; break; case 'w': wflag = true; cflags &= ~REG_NOSUB; break; case 'x': xflag = true; cflags &= ~REG_NOSUB; break; case 'X': filebehave = FILE_XZ; break; case 'Z': filebehave = FILE_GZIP; break; case BIN_OPT: if (strcasecmp("binary", optarg) == 0) binbehave = BINFILE_BIN; else if (strcasecmp("without-match", optarg) == 0) binbehave = BINFILE_SKIP; else if (strcasecmp("text", optarg) == 0) binbehave = BINFILE_TEXT; else errx(2, getstr(3), "--binary-files"); break; case COLOR_OPT: color = NULL; if (optarg == NULL || strcasecmp("auto", optarg) == 0 || strcasecmp("tty", optarg) == 0 || strcasecmp("if-tty", optarg) == 0) { char *term; term = getenv("TERM"); if (isatty(STDOUT_FILENO) && term != NULL && strcasecmp(term, "dumb") != 0) color = init_color("01;31"); } else if (strcasecmp("always", optarg) == 0 || strcasecmp("yes", optarg) == 0 || strcasecmp("force", optarg) == 0) { color = init_color("01;31"); } else if (strcasecmp("never", optarg) != 0 && strcasecmp("none", optarg) != 0 && strcasecmp("no", optarg) != 0) errx(2, getstr(3), "--color"); cflags &= ~REG_NOSUB; break; case LABEL_OPT: label = optarg; break; case LINEBUF_OPT: lbflag = true; break; case NULL_OPT: nullflag = true; break; case R_INCLUDE_OPT: finclude = true; add_fpattern(optarg, INCL_PAT); break; case R_EXCLUDE_OPT: fexclude = true; add_fpattern(optarg, EXCL_PAT); break; case R_DINCLUDE_OPT: dinclude = true; add_dpattern(optarg, INCL_PAT); break; case R_DEXCLUDE_OPT: dexclude = true; add_dpattern(optarg, EXCL_PAT); break; case HELP_OPT: default: usage(); } lastc = c; newarg = optind != prevoptind; prevoptind = optind; } aargc -= optind; aargv += optind; /* Empty pattern file matches nothing */ if (!needpattern && (patterns == 0)) exit(1); /* Fail if we don't have any pattern */ if (aargc == 0 && needpattern) usage(); /* Process patterns from command line */ if (aargc != 0 && needpattern) { add_pattern(*aargv, strlen(*aargv)); --aargc; ++aargv; } switch (grepbehave) { case GREP_BASIC: break; case GREP_FIXED: /* XXX: header mess, REG_LITERAL not defined in gnu/regex.h */ cflags |= 0020; break; case GREP_EXTENDED: cflags |= REG_EXTENDED; break; default: /* NOTREACHED */ usage(); } fg_pattern = grep_calloc(patterns, sizeof(*fg_pattern)); r_pattern = grep_calloc(patterns, sizeof(*r_pattern)); /* Check if cheating is allowed (always is for fgrep). */ for (i = 0; i < patterns; ++i) { if (fastncomp(&fg_pattern[i], pattern[i].pat, pattern[i].len, cflags) != 0) { /* Fall back to full regex library */ c = regcomp(&r_pattern[i], pattern[i].pat, cflags); if (c != 0) { regerror(c, &r_pattern[i], re_error, RE_ERROR_BUF); errx(2, "%s", re_error); } } } if (lbflag) setlinebuf(stdout); if ((aargc == 0 || aargc == 1) && !Hflag) hflag = true; if (aargc == 0) exit(!procfile("-")); if (dirbehave == DIR_RECURSE) c = grep_tree(aargv); else for (c = 0; aargc--; ++aargv) { if ((finclude || fexclude) && !file_matching(*aargv)) continue; c+= procfile(*aargv); } #ifndef WITHOUT_NLS catclose(catalog); #endif /* Find out the correct return value according to the results and the command line option. */ exit(c ? (notfound ? (qflag ? 0 : 2) : 0) : (notfound ? 2 : 1)); }
/* 1. CREATE or find database dictionary (.dbd file). * 2. CREATE empty 'dtsearch' database files. * 3. OPEN 'dtsearch' database. * 4. INITIALIZE the database. * 5. WRITE dbrec after initializing it. * 6. RENAME each database file. * 7. UNLINK (delete) d9x files. */ int main (int argc, char *argv[]) { int i; char *ptr; FILE *f; struct or_miscrec miscrec; struct or_swordrec swordrec; struct or_lwordrec lwordrec; setlocale (LC_ALL, ""); dtsearch_catd = catopen (FNAME_DTSRCAT, 0); aa_argv0 = argv[0]; max_ormisc_size = sizeof (miscrec.or_misc); maxwidth_sword = sizeof (swordrec.or_swordkey) - 1; maxwidth_lword = sizeof (lwordrec.or_lwordkey) - 1; printf (catgets (dtsearch_catd, MS_misc, 4, "%s Version %s.\n"), aa_argv0, DtSrVERSION ); /* Handle cmd line args. Init global variables. */ user_args_processor (argc, argv); /* ------- copy model .dbd to new .dbd ------- */ /* CASE 1: If user specified -d special alternative * directory for model .dbd, it should be there. */ if (modelpath[0] != 0) { if (debug_mode) printf (PROGNAME"628 Try opening '%s' (-d dir).\n", modelpath); if ((f = fopen (modelpath, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"638 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } else { print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"302", modelpath, strerror(errno)); DtSearchExit (4); } } /* end CASE 1 */ /* CASE 2: If model .dbd is in current directory, use it. * If error is anything other than 'cant find file', quit now. */ if (debug_mode) printf (PROGNAME"649 Try opening '%s' (curr dir).\n", FNAME_MODEL); if ((f = fopen (FNAME_MODEL, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"660 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } else if (errno != ENOENT) { print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"655", FNAME_MODEL, strerror(errno)); DtSearchExit (4); } /* end else CASE 2 */ /* CASE 3: Last chance. Look for model .dbd in target directory. * At this point have to quit on any error. */ strcpy (modelpath, newpath); strcpy (modelpath + path_offset, FNAME_MODEL); if (debug_mode) printf (PROGNAME"672 Try opening '%s' (new dir).\n", modelpath); if ((f = fopen (modelpath, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"675 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } if (debug_mode) puts (PROGNAME"682 Never found it!"); print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"686", FNAME_MODEL, "Not found in either current or target directories. Use -d option\a"); DtSearchExit (4); DBD_OKAY: /* Open a new database */ *newextp = 0; /* use no extension when opening database */ if (debug_mode) printf ("040*** d_open newpath = '%s'.\n", newpath); d_open (newpath, "o"); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 230, PROGNAME "230 Could not open database '%s'.\n"), newpath); puts (vista_msg (PROGNAME "231")); DtSearchExit (3); } austext_exit_dbms = (void (*) (int)) d_close; /* emerg exit func */ /* initialize the 'dtsearch' database */ if (debug_mode) printf ("042*** d_initialize.\n"); d_initialize (0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 239, PROGNAME "239 Could not initialize database '%s'.\n"), newpath); puts (vista_msg (PROGNAME "240")); DtSearchExit (3); } /* Create and initialize dbrec database header record in first slot. * First fill entire record with binary zeros. * Then set specific values as specified by flavor on command line. * For now most values are hard-coded. */ if (debug_mode) printf ("050*** create dbrec.\n"); memset (&dbrec, 0, sizeof (dbrec)); /* Init fields that are completely independent */ dbrec.or_language = (DtSrINT16) language; dbrec.or_maxwordsz = (DtSrINT16) maxwordsz; dbrec.or_minwordsz = (DtSrINT16) minwordsz; dbrec.or_fzkeysz = (DtSrINT16) fzkeysz; dbrec.or_abstrsz = (DtSrINT16) abstrsz; dbrec.or_dbflags = ORD_NONOTES | ORD_NOMARKDEL | ORD_XWORDS; strncpy (dbrec.or_version, SCHEMA_VERSION, sizeof(dbrec.or_version)); dbrec.or_version [sizeof(dbrec.or_version) - 1] = 0; /* Load dbrec's recslots fields based on correct number * of misc recs required to hold user's abstract. * Round abstrsz upward if there is any space left on last misc rec. */ dbrec.or_recslots = 1; /* start with obj rec itself */ for (i = dbrec.or_fzkeysz + dbrec.or_abstrsz; i > 0; i -= max_ormisc_size) dbrec.or_recslots++; if (i < 0) { /* Add in difference to INCREASE abstrsz */ dbrec.or_abstrsz -= i; printf (catgets (dtsearch_catd, MS_misc, 433, "%1$sAdjusted maximum abstract size upward to %2$hd.\n"), PROGNAME "433 ", dbrec.or_abstrsz); } /* Init fields that are dependent on language */ switch (language) { case DtSrLaENG: case DtSrLaENG2: dbrec.or_dbflags |= ORD_XSTEMS; break; default: break; } /* Init fields that are dependent on flavor */ if (flavor == AUSTEXT_FLAVOR) { dbrec.or_dbaccess = ORA_BLOB; dbrec.or_compflags = ORC_COMPBLOB; dbrec.or_hufid = -1L; /* -1 = use huffman compression, but * hufid not yet known. */ dbrec.or_dbotype = DtSrObjTEXT; } else { /* default flavor == DTSEARCH_FLAVOR */ dbrec.or_dbaccess = ORA_NOTAVAIL; } if (!quiet_mode) { /******putchar ('\n');******/ print_dbrec (newpath, &dbrec); fflush (stdout); } swab_dbrec (&dbrec, HTON); if (debug_mode) printf ("060*** fillnew dbrec.\n"); d_fillnew (OR_DBREC, &dbrec, 0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 509, PROGNAME "509 Could not initialize database header record.\n")); puts (vista_msg (PROGNAME "510")); DtSearchExit (3); } /* Close the database */ d_close (); austext_exit_dbms = NULL; /* emerg exit no longer required */ /* Delete all nonvista (inverted index) database files (.d9x) */ remove_d9x_file (".d97"); remove_d9x_file (".d98"); remove_d9x_file (".d99"); *newextp = 0; /* no extension suffixes for next msgs */ printf (catgets (dtsearch_catd, MS_initausd, 24, PROGNAME " Successfully initialized database '%s'.\n"), newpath); return 0; } /* main() */