| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifdef TEXT_TEST |
| #define DECLARER |
| #endif |
|
|
| #include "config.h" |
| #include <stdlib.h> |
| #if (defined(_POSIX_)||!defined(WIN32)) |
| #include <unistd.h> |
| #include <sys/wait.h> |
| #endif |
| #include <stdio.h> |
| #include <limits.h> |
| #include <math.h> |
| #include <ctype.h> |
| #include <signal.h> |
| #include <string.h> |
| #include <errno.h> |
| #ifdef HP |
| #include <strings.h> |
| #endif |
| #if (defined(WIN32)&&!defined(_POSIX_)) |
| #include <process.h> |
| #pragma warning(disable:4201) |
| #pragma warning(disable:4214) |
| #pragma warning(disable:4514) |
| #define WIN32_LEAN_AND_MEAN |
| #define NOATOM |
| #define NOGDICAPMASKS |
| #define NOMETAFILE |
| #define NOMINMAX |
| #define NOMSG |
| #define NOOPENFILE |
| #define NORASTEROPS |
| #define NOSCROLL |
| #define NOSOUND |
| #define NOSYSMETRICS |
| #define NOTEXTMETRIC |
| #define NOWH |
| #define NOCOMM |
| #define NOKANJI |
| #define NOMCX |
| #include <windows.h> |
| #pragma warning(default:4201) |
| #pragma warning(default:4214) |
| #endif |
|
|
| #define TEXT_POOL_SIZE (300 * 1024 * 1024) |
|
|
| #include "dss.h" |
| #include "dsstypes.h" |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static int |
| txt_vp(char *dest, int sd) |
| { |
| char syntax[MAX_GRAMMAR_LEN + 1], |
| *cptr, |
| *parse_target; |
| distribution *src; |
| int i, |
| res = 0; |
|
|
| |
| pick_str(&vp, sd, &syntax[0]); |
| parse_target = syntax; |
| while ((cptr = strtok(parse_target, " ")) != NULL) |
| { |
| src = NULL; |
| switch(*cptr) |
| { |
| case 'D': |
| src = &adverbs; |
| break; |
| case 'V': |
| src = &verbs; |
| break; |
| case 'X': |
| src = &auxillaries; |
| break; |
| } |
| i = pick_str(src, sd, dest); |
| i = (int)strlen(DIST_MEMBER(src, i)); |
| dest += i; |
| res += i; |
| if (*(++cptr)) |
| { |
| dest += 1; |
| res += 1; |
| *dest = *cptr; |
| } |
| *dest = ' '; |
| dest++; |
| res++; |
| parse_target = NULL; |
| } |
|
|
| return(res); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static int |
| txt_np(char *dest, int sd) |
| { |
| char syntax[MAX_GRAMMAR_LEN + 1], |
| *cptr, |
| *parse_target; |
| distribution *src; |
| int i, |
| res = 0; |
|
|
| |
| pick_str(&np, sd, &syntax[0]); |
| parse_target = syntax; |
| while ((cptr = strtok(parse_target, " ")) != NULL) |
| { |
| src = NULL; |
| switch(*cptr) |
| { |
| case 'A': |
| src = &articles; |
| break; |
| case 'J': |
| src = &adjectives; |
| break; |
| case 'D': |
| src = &adverbs; |
| break; |
| case 'N': |
| src = &nouns; |
| break; |
| } |
| i = pick_str(src, sd, dest); |
| i = (int)strlen(DIST_MEMBER(src, i)); |
| dest += i; |
| res += i; |
| if (*(++cptr)) |
| { |
| *dest = *cptr; |
| dest += 1; |
| res += 1; |
| } |
| *dest = ' '; |
| dest++; |
| res++; |
| parse_target = NULL; |
| } |
|
|
| return(res); |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| static int |
| txt_sentence(char *dest, int sd) |
| { |
| char syntax[MAX_GRAMMAR_LEN + 1], |
| *cptr; |
| int i, |
| res = 0, |
| len = 0; |
|
|
| |
| pick_str(&grammar, sd, syntax); |
| cptr = syntax; |
|
|
| next_token: |
| while (*cptr && *cptr == ' ') |
| cptr++; |
| if (*cptr == '\0') |
| goto done; |
| switch(*cptr) |
| { |
| case 'V': |
| len = txt_vp(dest, sd); |
| break; |
| case 'N': |
| len = txt_np(dest, sd); |
| break; |
| case 'P': |
| i = pick_str(&prepositions, sd, dest); |
| len = (int)strlen(DIST_MEMBER(&prepositions, i)); |
| strcpy((dest + len), " the "); |
| len += 5; |
| len += txt_np(dest + len, sd); |
| break; |
| case 'T': |
| i = pick_str(&terminators, sd, --dest); |
| len = (int)strlen(DIST_MEMBER(&terminators, i)); |
| break; |
| } |
| dest += len; |
| res += len; |
| cptr++; |
| if (*cptr && *cptr != ' ') |
| { |
| dest += 1; |
| res += 1; |
| *dest = *cptr; |
| } |
| goto next_token; |
| done: |
| *dest = '\0'; |
| return(--res); |
| } |
|
|
| |
| |
| |
| |
| |
| void |
| dbg_text(char *tgt, int min, int max, int sd) |
| { |
| DSS_HUGE hgLength = 0, |
| hgOffset, |
| wordlen = 0, |
| s_len, |
| needed; |
| char sentence[MAX_SENT_LEN + 1], |
| *cp; |
| static char szTextPool[TEXT_POOL_SIZE + 1]; |
| static int bInit = 0; |
| int nLifeNoise = 0; |
| |
| if (!bInit) |
| { |
| cp = &szTextPool[0]; |
| if (verbose > 0) |
| fprintf(stderr, "\nPreloading text ... "); |
| |
| while (wordlen < TEXT_POOL_SIZE) |
| { |
| if ((verbose > 0) && (wordlen > nLifeNoise)) |
| { |
| nLifeNoise += 200000; |
| fprintf(stderr, "%3.0f%%\b\b\b\b", (100.0 * wordlen)/TEXT_POOL_SIZE); |
| } |
| |
| s_len = txt_sentence(sentence, 5); |
| if ( s_len < 0) |
| INTERNAL_ERROR("Bad sentence formation"); |
| needed = TEXT_POOL_SIZE - wordlen; |
| if (needed >= (s_len + 1)) |
| { |
| strcpy(cp, sentence); |
| cp += s_len; |
| wordlen += s_len + 1; |
| *(cp++) = ' '; |
| } |
| else |
| { |
| sentence[needed] = '\0'; |
| strcpy(cp, sentence); |
| wordlen += needed; |
| cp += needed; |
| } |
| } |
| *cp = '\0'; |
| bInit = 1; |
| if (verbose > 0) |
| fprintf(stderr, "\n"); |
| } |
|
|
| RANDOM(hgOffset, 0, TEXT_POOL_SIZE - max, sd); |
| RANDOM(hgLength, min, max, sd); |
| strncpy(&tgt[0], &szTextPool[hgOffset], (int)hgLength); |
| tgt[hgLength] = '\0'; |
|
|
| return; |
| } |
|
|
| #ifdef TEXT_TEST |
| tdef tdefs[1] = { NULL }; |
| distribution nouns, |
| verbs, |
| adjectives, |
| adverbs, |
| auxillaries, |
| terminators, |
| articles, |
| prepositions, |
| grammar, |
| np, |
| vp; |
|
|
| main() |
| { |
| char prattle[401]; |
| |
| verbose = 1; |
| |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "nouns", &nouns); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "verbs", &verbs); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "adjectives", &adjectives); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "adverbs", &adverbs); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "auxillaries", &auxillaries); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "terminators", &terminators); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "articles", &articles); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "prepositions", &prepositions); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "grammar", &grammar); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "np", &np); |
| read_dist (env_config (DIST_TAG, DIST_DFLT), "vp", &vp); |
|
|
| while (1) |
| { |
| dbg_text(&prattle[0], 300, 400, 0); |
| printf("<%s>\n", prattle); |
| } |
|
|
| return(0); |
| } |
| #endif |
|
|