/* break up an address to its component parts */ void dial_string_parse(char *str, DS *ds) { char *p, *p2; strncpy(ds->buf, str, sizeof(ds->buf)); ds->buf[sizeof(ds->buf)-1] = 0; p = strchr(ds->buf, '!'); if(p == 0) { ds->netdir = 0; ds->proto = "net"; ds->host = ds->buf; } else { if(*ds->buf != '/'){ ds->netdir = 0; ds->proto = ds->buf; } else { for(p2 = p; *p2 != '/'; p2--) ; *p2++ = 0; ds->netdir = ds->buf; ds->proto = p2; } *p = 0; ds->host = p + 1; } ds->service = strchr(ds->host, '!'); if(ds->service) *ds->service++ = 0; if(*ds->host == '$') expand_meta(ds); }
static void *thread(void *pArg) { struct ThreadInfo *threadInfo = (struct ThreadInfo *) pArg; // printf("Started thread %d\n", threadInfo->id); pthread_mutex_lock(&threadInfo->mutex); threadInfo->status = THREAD_FREE; pthread_mutex_unlock(&threadInfo->mutex); while(1) { pthread_mutex_lock(&threadInfo->mutex); if ((threadInfo->status == THREAD_FREE) && (threadInfo->isFinished == 1)) { pthread_mutex_unlock(&threadInfo->mutex); break; } if (threadInfo->status == THREAD_COMPUTE) { pthread_mutex_unlock(&threadInfo->mutex); expand_meta(threadInfo->path, threadInfo->store); pthread_mutex_lock(&threadInfo->mutex); threadInfo->status = THREAD_FREE; pthread_mutex_unlock(&threadInfo->mutex); } else { pthread_mutex_unlock(&threadInfo->mutex); usleep(THREAD_USLEEP); } } // printf("Finished thread %d\n", threadInfo->id); return NULL; }
static void read_psffm(char *file) { int fd; static char msgfile[MAXPATHLEN]; wchar_t *linebufptr, *p; char *bufptr = 0; int quotefound; /* double quote was seen */ int inmsgid = 0; /* indicates "msgid" was seen */ int inmsgstr = 0; /* indicates "msgstr" was seen */ int indomain = 0; /* indicates "domain" was seen */ wchar_t wc; char mb; int n; char token_found; /* Boolean value */ unsigned int bufptr_index = 0; /* current index of bufptr */ char *mbuf, *addr; size_t fsize, ln_size, ll; wchar_t *linebufhead = NULL; struct stat64 statbuf; char *filename; /* * For each po file to be read, * 1) set domain to default and * 2) set linenumer to 0. */ (void) strcpy(gcurrent_domain, DEFAULT_DOMAIN); linenum = 0; if (!inputdir) { filename = Xstrdup(file); } else { size_t dirlen, filelen, len; dirlen = strlen(inputdir); filelen = strlen(file); len = dirlen + 1 + filelen + 1; filename = (char *)Xmalloc(len); (void) memcpy(filename, inputdir, dirlen); *(filename + dirlen) = '/'; (void) memcpy(filename + dirlen + 1, file, filelen); *(filename + dirlen + 1 + filelen) = '\0'; } fd = open(filename, O_RDONLY); if (fd == -1) { error(gettext(ERR_OPEN_FAILED), filename); /* NOTREACHED */ } if (fstat64(fd, &statbuf) == -1) { error(gettext(ERR_STAT_FAILED), filename); /* NOTREACHED */ } fsize = (size_t)statbuf.st_size; if (fsize == 0) { /* * The size of the specified po file is 0. * In Solaris 8 and earlier, msgfmt was silent * for the null po file. So, just returns * without generating an error message. */ (void) close(fd); free(filename); return; } addr = mmap(NULL, fsize, PROT_READ, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { error(gettext(ERR_MMAP_FAILED), filename); /* NOTREACHED */ } (void) close(fd); if (!sun_p) check_gnu(addr, fsize); mbuf = addr; for (;;) { if (linebufhead) { free(linebufhead); linebufhead = NULL; } ln_size = _mbsntowcs(&linebufhead, &mbuf, &fsize); if (ln_size == (size_t)-1) { error(gettext(ERR_READ_FAILED), filename); /* NOTREACHED */ } else if (ln_size == 0) { break; /* End of File. */ } linenum++; linebufptr = linebufhead; quotefound = 0; switch (*linebufptr) { case L'#': /* comment */ case L'\n': /* empty line */ continue; case L'\"': /* multiple lines of msgid and msgstr */ quotefound = 1; break; } /* * Process MSGID Tokens. */ token_found = (wcsncmp(MSGID_TOKEN, linebufptr, MSGID_LEN) == 0) ? 1 : 0; if (token_found || (quotefound && inmsgid)) { if (token_found) { if (!CK_NXT_CH(linebufptr, MSGID_LEN+1)) { diag(gettext(ERR_NOSPC), linenum); error(gettext(ERR_EXITING)); /* NOTREACHED */ } } if (inmsgid && !quotefound) { warning(gettext(WARN_NO_MSGSTR), msgid_linenum); continue; } if (inmsgstr) { sortit(gmsgid, gmsgstr); (void) memset(gmsgid, 0, gmsgid_size); (void) memset(gmsgstr, 0, gmsgstr_size); } if (inmsgid) { /* multiple lines of msgid */ /* cancel the previous null termination */ bufptr_index--; } else { /* * The first line of msgid. * Save linenum of msgid to be used when * printing warning or error message. */ msgid_linenum = linenum; p = linebufptr; linebufptr = consume_whitespace( linebufptr + MSGID_LEN); ln_size -= linebufptr - p; bufptr = gmsgid; bufptr_index = 0; } inmsgid = 1; inmsgstr = 0; indomain = 0; goto load_buffer; } /* * Process MSGSTR Tokens. */ token_found = (wcsncmp(MSGSTR_TOKEN, linebufptr, MSGSTR_LEN) == 0) ? 1 : 0; if (token_found || (quotefound && inmsgstr)) { if (token_found) { if (!CK_NXT_CH(linebufptr, MSGSTR_LEN+1)) { diag(gettext(ERR_NOSPC), linenum); error(gettext(ERR_EXITING)); /* NOTREACHED */ } } if (inmsgstr && !quotefound) { warning(gettext(WARN_NO_MSGID), msgstr_linenum); continue; } if (inmsgstr) { /* multiple lines of msgstr */ /* cancel the previous null termination */ bufptr_index--; } else { /* * The first line of msgstr. * Save linenum of msgid to be used when * printing warning or error message. */ msgstr_linenum = linenum; p = linebufptr; linebufptr = consume_whitespace( linebufptr + MSGSTR_LEN); ln_size -= linebufptr - p; bufptr = gmsgstr; bufptr_index = 0; } inmsgstr = 1; inmsgid = 0; indomain = 0; goto load_buffer; } /* * Process DOMAIN Tokens. * Add message id and message string to sorted list * if msgstr was processed last time. */ token_found = (wcsncmp(DOMAIN_TOKEN, linebufptr, DOMAIN_LEN) == 0) ? 1 : 0; if ((token_found) || (quotefound && indomain)) { if (token_found) { if (!CK_NXT_CH(linebufptr, DOMAIN_LEN+1)) { diag(gettext(ERR_NOSPC), linenum); error(gettext(ERR_EXITING)); /* NOTREACHED */ } } /* * process msgid and msgstr pair for previous domain */ if (inmsgstr) { sortit(gmsgid, gmsgstr); } /* refresh msgid and msgstr buffer */ if (inmsgstr || inmsgid) { (void) memset(gmsgid, 0, gmsgid_size); (void) memset(gmsgstr, 0, gmsgstr_size); } if (indomain) { /* multiple lines of domain */ /* cancel the previous null termination */ bufptr_index--; } else { p = linebufptr; linebufptr = consume_whitespace( linebufptr + DOMAIN_LEN); (void) memset(gcurrent_domain, 0, sizeof (gcurrent_domain)); ln_size -= linebufptr - p; bufptr = gcurrent_domain; bufptr_index = 0; } indomain = 1; inmsgid = 0; inmsgstr = 0; } /* if */ load_buffer: /* * Now, fill up the buffer pointed by bufptr. * At this point bufptr should point to one of * msgid, msgptr, or current_domain. * Otherwise, the entire line is ignored. */ if (!bufptr) { warning(gettext(WARN_SYNTAX_ERR), linenum); continue; } if (*linebufptr++ != L'\"') { warning(gettext(WARN_MISSING_QUOTE), linenum); --linebufptr; } quotefound = 0; /* * If there is not enough space in the buffer, * increase buffer by ln_size by realloc. */ ll = ln_size * mbcurmax; if (bufptr == gmsgid) { if (gmsgid_size < (bufptr_index + ll)) { gmsgid = (char *)Xrealloc(gmsgid, bufptr_index + ll); bufptr = gmsgid; gmsgid_size = bufptr_index + ll; } } else if (bufptr == gmsgstr) { if (gmsgstr_size < (bufptr_index + ll)) { gmsgstr = (char *)Xrealloc(gmsgstr, bufptr_index + ll); bufptr = gmsgstr; gmsgstr_size = bufptr_index + ll; } } while (wc = *linebufptr++) { switch (wc) { case L'\n': if (!quotefound) { warning(gettext(WARN_MISSING_QUOTE_AT_EOL), linenum); } break; case L'\"': quotefound = 1; break; case L'\\': if ((mb = expand_meta(&linebufptr)) != NULL) bufptr[bufptr_index++] = mb; break; default: if ((n = wctomb(&bufptr[bufptr_index], wc)) > 0) bufptr_index += n; } /* switch */ if (quotefound) { /* * Check if any remaining characters * after closing quote. */ linebufptr = consume_whitespace(linebufptr); if (*linebufptr != L'\n') { warning(gettext(WARN_INVALID_STRING), linenum); } break; } } /* while */ bufptr[bufptr_index++] = '\0'; (void) strcpy(msgfile, gcurrent_domain); (void) strcat(msgfile, ".mo"); } /* for(;;) */ if (inmsgstr) { sortit(gmsgid, gmsgstr); } if (linebufhead) free(linebufhead); if (munmap(addr, statbuf.st_size) == -1) { error(gettext(ERR_MUNMAP_FAILED), filename); /* NOTREACHED */ } free(filename); return; } /* read_psffm */