home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2212 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  10.9 KB

  1. From: staceyc@sco.COM (Stacey Campbell)
  2. Newsgroups: comp.unix.sysv386,alt.sources
  3. Subject: Re: Screen packages in general (was Re: Vermont Views)
  4. Message-ID: <9090@scolex.sco.COM>
  5. Date: 5 Dec 90 19:13:38 GMT
  6.  
  7.  
  8. In article <1990Nov27.165132.1335@bkj386.uucp> anton@analsyn.UUCP writes:
  9. >Now CURSES may not be perfect.  it may be  bloated  and  only  do
  10. >80-90%  of  the  job, but it is there.  it is also a standard, as
  11. >far as the TERMCAP/TERMINFO side goes.
  12.  
  13. Agreed.  Even if curses doesn't directly support some feature it will
  14. just take a little work to add the required top layer, which can then
  15. be used for other applications' development.
  16.  
  17. >       SVR3.2.  They have colour capability in CURSES.  If SCO
  18. >       etc choose not to implement this for their own reasons
  19. >       that's their problem.   Go buy your UNIX from someone who
  20. >       adhere's to the standard.
  21.  
  22. Just so it is clear, SCO Unix V 3.2 (all versions) supports the
  23. stock AT&T System V 3.2 color curses.  Anton is almost certainly
  24. referring to SCO Xenix.  I've tossed in a fun little curses color
  25. demo at the bottom of this post, so anybody with any System V 3.2
  26. Development System can give it a spin.
  27.  
  28. >       The SCO TERMINFO lacks many features that
  29. >       were introduced in SVR2.0.  In fact most of the SCO XENIX 
  30. >       implemetation of TERMINFO & utilities is riddled with
  31. >       bugs.
  32.  
  33. SCO Xenix comes with System V 3.[01] curses, not Sys V 2 (the clue is
  34. ACS character defines in /usr/include/tinfo.h).  Historically SCO
  35. Xenix was based mostly around termcap curses simply because in
  36. the good old days BSD termcap curses was much more robust and useful
  37. than System V curses.  IMHO System V 3.2 curses, and even to a degree
  38. System V 3.1 curses, are far and away better than BSD curses.
  39.  
  40. >       But what about customers buying the package from sortes
  41. >       and other outlets?
  42. >
  43. >       To put this in persspective, would you consider buying,
  44. >       say, Norton Tools for DOS, if they were written so that
  45. >       they used the '286 & '386 extended instructions and the
  46. >       features of the VGA ?    I mean this in the sense that
  47. >       you HAVE to upgrade to use the program at all!
  48.  
  49. System V 3.2 curses applications execute correctly on Xenix machines,
  50. terminfo files are backward compatible, though it is much nicer to
  51. use Unix terminfo files when on Xenix.  There is no real system
  52. dependent issues when running a 386 Unix curses application on Xenix.
  53. The application only requires a working terminfo file.
  54.  
  55. >       We're also trying to produce a product which can be
  56. >       installed without being an expert in TERMCAP or TERMINFO
  57. >       and without having to RTFM.
  58.  
  59. The terminfo(4) man page is a bit daunting.  There is a reasonable
  60. Nutshell book that deals with both termcap and terminfo.
  61.  
  62. Here's the demo program;
  63.  
  64. #!/bin/sh
  65. # This is a shell archive (produced by shar 3.49)
  66. # To extract the files from this archive, save it to a file, remove
  67. # everything above the "!/bin/sh" line above, and type "sh file_name".
  68. #
  69. # existing files will NOT be overwritten unless -c is specified
  70. #
  71. # This shar contains:
  72. # length  mode       name
  73. # ------ ---------- ------------------------------------------
  74. #    212 -rw------- Makefile
  75. #   6631 -rw-rw-r-- fire.c
  76. #
  77. # ============= Makefile ==============
  78. if test -f 'Makefile' -a X"$1" != X"-c"; then
  79.     echo 'x - skipping Makefile (File already exists)'
  80. else
  81. echo 'x - extracting Makefile (Text)'
  82. sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
  83. CC= cc
  84. CFLAGS= -O -DM_TERMINFO -UM_TERMCAP
  85. LDFLAGS= -O
  86. OBJS= fire.o
  87. X
  88. #Unix
  89. LDLIBS= -lcurses -lm
  90. X
  91. #Xenix
  92. # LDLIBS= -ltinfo -lm
  93. X
  94. fire: $(OBJS)
  95. X    $(CC) $(LDFLAGS) fire.o -o fire $(LDLIBS)
  96. X
  97. clean:
  98. X    rm -f $(OBJS) fire
  99. SHAR_EOF
  100. chmod 0600 Makefile ||
  101. echo 'restore of Makefile failed'
  102. Wc_c="`wc -c < 'Makefile'`"
  103. test 212 -eq "$Wc_c" ||
  104.     echo 'Makefile: original size 212, current size' "$Wc_c"
  105. fi
  106. # ============= fire.c ==============
  107. if test -f 'fire.c' -a X"$1" != X"-c"; then
  108.     echo 'x - skipping fire.c (File already exists)'
  109. else
  110. echo 'x - extracting fire.c (Text)'
  111. sed 's/^X//' << 'SHAR_EOF' > 'fire.c' &&
  112. #include <sys/types.h>
  113. #include <math.h>
  114. #include <curses.h>
  115. #include <string.h>
  116. X
  117. #ifndef COLOR_BLACK
  118. #define start_color()
  119. #define COLOR_PAIR(a) 0
  120. #endif
  121. X
  122. extern double drand48();
  123. extern void srand48();
  124. extern long lrand48();
  125. extern time_t time();
  126. extern char *malloc();
  127. extern void free();
  128. extern unsigned int sleep();
  129. X
  130. #define PART_COUNT 10
  131. #define PART_VARIANCE 5
  132. #define SIN_TABLE_SIZE 350
  133. #define COLOR_MIXED -1
  134. #define TABLE_SCALE(val) ((int)(val / M_PI * SIN_TABLE_SIZE))
  135. #define BOUNDCHAR(win, y, x, char) \
  136. X    (((y) >= 0 && (y) < LINES && (x) >= 0 && (x) < COLS) ? \
  137. X        mvwaddch((win), (y), (x), (char)) : 0)
  138. #define PAT_RAND_SEQ    0x01
  139. X
  140. typedef struct particle_t {
  141. X    double y_scale;
  142. X    double x_scale;
  143. X    double x_inc;
  144. X    double x;
  145. X    int old_y, old_x;
  146. X    int direction;
  147. X    int color;
  148. X    int sequence;
  149. X    int pattern_inc;
  150. } particle_t;
  151. X
  152. typedef struct pattern_t {
  153. X    char *string;
  154. X    int mask;
  155. } pattern_t;
  156. X
  157. typedef struct object_t {
  158. X    int rel_y, rel_x;
  159. X    int part_count;
  160. X    pattern_t *pattern;
  161. X    int pat_cycle;
  162. X    int color;
  163. X    int done_count;
  164. X    int life;
  165. X    double y_mag, x_mag;
  166. X    particle_t *particles;
  167. } object_t;
  168. X
  169. typedef struct object_list_t {
  170. X    object_t *object;
  171. X    struct object_list_t *next;
  172. } object_list_t;
  173. X
  174. static pattern_t Patterns[] = {
  175. X    {"......+++++++******@@@@@@@", 0},
  176. X    {"|\\-/", PAT_RAND_SEQ},
  177. X    {".......ooooOOOOoooo", 0},
  178. X    {".........****.......", 0},
  179. X    {"*", 0}
  180. };
  181. X
  182. #define PATTERN_SIZE (sizeof(Patterns) / sizeof(Patterns[0]))
  183. X
  184. static int ColorId = 1;
  185. #define RAND_COLOR() (lrand48() % ColorId + 1)
  186. X
  187. static void DoSinTable();
  188. static void DisplayObject();
  189. static void BuildParticles();
  190. static object_t *BuildObject();
  191. static void InitColors();
  192. static void AddObject();
  193. static void DoObjectList();
  194. static void DeleteObject();
  195. static void FreeMemory();
  196. X
  197. int main(argc, argv)
  198. X
  199. int argc;
  200. char *argv[];
  201. X
  202. {
  203. X    double sin_table[SIN_TABLE_SIZE];
  204. X    object_list_t *top;
  205. X    time_t show_over;
  206. X
  207. X    nice(4);
  208. X    printf("wait.");
  209. X    fflush(stdout);
  210. X    DoSinTable(sin_table);
  211. X    srand48((long)time((time_t *)0));
  212. X    initscr();
  213. X    start_color();
  214. X    curs_set(FALSE);
  215. X    InitColors();
  216. X    top = (object_list_t *)malloc(sizeof(object_list_t));
  217. X    top->object = BuildObject();
  218. X    top->next = 0;
  219. X    show_over = time((time_t *)0) + 10000 * 60;
  220. X    while (time((time_t *)0) < show_over)
  221. X    {
  222. X        if (! (lrand48() % 20))
  223. X            AddObject(&top);
  224. X        else
  225. X            if (! top)
  226. X            {
  227. X                sleep(1);
  228. X                AddObject(&top);
  229. X            }
  230. X        DoObjectList(stdscr, sin_table, &top);
  231. X        wrefresh(stdscr);
  232. X    }
  233. X    endwin();
  234. X    return 0;
  235. }
  236. X
  237. static void DoObjectList(win, sin_table, top)
  238. X
  239. WINDOW *win;
  240. double *sin_table;
  241. object_list_t **top;
  242. X
  243. {
  244. X    object_list_t *now, *old;
  245. X
  246. X    now = *top;
  247. X    while (now)
  248. X    {
  249. X        DisplayObject(win, sin_table, now->object);
  250. X        old = now;
  251. X        now = now->next;
  252. X        if (old->object->done_count >= old->object->part_count ||
  253. X            old->object->life < 0)
  254. X            DeleteObject(old, top);
  255. X    }
  256. }
  257. X
  258. static void DeleteObject(zap, top)
  259. X
  260. object_list_t *zap;
  261. object_list_t **top;
  262. X
  263. {
  264. X    object_list_t *new, *last;
  265. X
  266. X    if (zap == *top)
  267. X    {
  268. X        new = zap->next;
  269. X        FreeMemory(zap);
  270. X        *top = new;
  271. X        return;
  272. X    }
  273. X    new = *top;
  274. X    while (new != zap)
  275. X    {
  276. X        last = new;
  277. X        new = new->next;
  278. X    }
  279. X    last->next = zap->next;
  280. X    FreeMemory(zap);
  281. }
  282. X
  283. static void FreeMemory(item)
  284. X
  285. object_list_t *item;
  286. X
  287. {
  288. X    free((char *)item->object->particles);
  289. X    free((char *)item->object);
  290. X    free((char *)item);
  291. }
  292. X
  293. static void AddObject(top)
  294. X
  295. object_list_t **top;
  296. X
  297. {
  298. X    object_list_t *new_top;
  299. X
  300. X    new_top = (object_list_t *)malloc(sizeof(object_list_t));
  301. X    new_top->object = BuildObject();
  302. X    new_top->next = *top;
  303. X    *top = new_top;
  304. }
  305. X
  306. static object_t *BuildObject()
  307. X
  308. {
  309. X    object_t *object;
  310. X
  311. X    object = (object_t *)malloc(sizeof(object_t));
  312. X    object->part_count = lrand48() % PART_VARIANCE + PART_COUNT;
  313. X    object->particles = (particle_t *)malloc(object->part_count *
  314. X        sizeof(particle_t));
  315. X    object->pattern = &Patterns[lrand48() % PATTERN_SIZE];
  316. X    object->pat_cycle = strlen(object->pattern->string);
  317. X    object->rel_y = LINES - lrand48() % 15;
  318. X    object->rel_x = lrand48() % (COLS / 4 * 3) + COLS / 4 * 1 / 2;
  319. X    object->color = lrand48() % 4 ? RAND_COLOR() : COLOR_MIXED;
  320. X    object->done_count = 0;
  321. X    object->y_mag = drand48() * 0.9 + 0.5;
  322. X    object->x_mag = drand48() * 0.9 + 0.5;
  323. X    object->life = lrand48() % 15 + 10;
  324. X    BuildParticles(object);
  325. X
  326. X    return object;
  327. }
  328. X
  329. static void DisplayObject(win, sin_table, object)
  330. X
  331. WINDOW *win;
  332. double *sin_table;
  333. object_t *object;
  334. X
  335. {
  336. X    int i;
  337. X    int draw_y, draw_x;
  338. X    particle_t *p;
  339. X    double y;
  340. X    int sym;
  341. X
  342. X    if (--object->life < 0)
  343. X    {
  344. X        for (i = 0; i < object->part_count; ++i)
  345. X        {
  346. X            p = &object->particles[i];
  347. X            BOUNDCHAR(win, p->old_y, p->old_x, ' ');
  348. X        }
  349. X        return;
  350. X    }
  351. X    for (i = 0; i < object->part_count; ++i)
  352. X    {
  353. X        p = &object->particles[i];
  354. X        if (p->x < M_PI)
  355. X        {
  356. X            BOUNDCHAR(win, p->old_y, p->old_x, ' ');
  357. X            y = sin_table[TABLE_SCALE(p->x)] * p->y_scale;
  358. X            draw_y = object->rel_y - y;
  359. X            draw_x = object->rel_x + p->direction * p->x *
  360. X                p->x_scale;
  361. X            p->sequence += p->pattern_inc;
  362. X            if (p->sequence < 0)
  363. X                p->sequence = object->pat_cycle - 1;
  364. X            else
  365. X                if (p->sequence >= object->pat_cycle)
  366. X                    p->sequence = 0;
  367. X            sym = object->pattern->string[p->sequence];
  368. X            BOUNDCHAR(win, draw_y, draw_x,
  369. X                sym | COLOR_PAIR(p->color));
  370. X            p->old_y = draw_y;
  371. X            p->old_x = draw_x;
  372. X            p->x += p->x_inc;
  373. X            if (p->x >= M_PI)
  374. X            {
  375. X                BOUNDCHAR(win, draw_y, draw_x, ' ');
  376. X                ++object->done_count;
  377. X            }
  378. X        }
  379. X    }
  380. }
  381. X
  382. static void DoSinTable(table)
  383. X
  384. double *table;
  385. X
  386. {
  387. X    int i;
  388. X    double inc;
  389. X    double current;
  390. X
  391. X    inc = M_PI / SIN_TABLE_SIZE;
  392. X    for (i = 0, current = 0.0; i < SIN_TABLE_SIZE; ++i, current += inc)
  393. X    {
  394. X        table[i] = sin(current);
  395. X        if (! (i % 66))
  396. X        {
  397. X            putchar('.');
  398. X            fflush(stdout);
  399. X        }
  400. X    }
  401. }
  402. X
  403. static void BuildParticles(object)
  404. X
  405. object_t *object;
  406. X
  407. {
  408. X    int i;
  409. X    particle_t *p;
  410. X
  411. X    for (i = 0; i < object->part_count; ++i)
  412. X    {
  413. X        p = &object->particles[i];
  414. X        p->y_scale = drand48() * (LINES - 1) * object->y_mag;
  415. X        p->x_scale = drand48() * COLS / 6.0 * object->x_mag;
  416. X        p->x_inc = drand48() * 0.05 + 0.1;
  417. X        p->x = 0.0;
  418. X        p->old_y = 0;
  419. X        p->old_x = 0;
  420. X        p->direction = lrand48() & 1 ? -1 : 1;
  421. X        if (object->pattern->mask & PAT_RAND_SEQ)
  422. X        {
  423. X            p->sequence = lrand48() % object->pat_cycle;
  424. X            p->pattern_inc = -p->direction;
  425. X        }
  426. X        else
  427. X        {
  428. X            p->sequence = 0;
  429. X            p->pattern_inc = 1;
  430. X        }
  431. X        if (object->color == COLOR_MIXED)
  432. X            p->color = RAND_COLOR();
  433. X        else
  434. X            p->color = object->color;
  435. X    }
  436. }
  437. X
  438. static void InitColors()
  439. X
  440. {
  441. #ifdef COLOR_BLACK
  442. X    init_pair(ColorId++, COLOR_RED, COLOR_BLACK);
  443. X    init_pair(ColorId++, COLOR_GREEN, COLOR_BLACK);
  444. X    init_pair(ColorId++, COLOR_YELLOW, COLOR_BLACK);
  445. X    init_pair(ColorId++, COLOR_BLUE, COLOR_BLACK);
  446. X    init_pair(ColorId++, COLOR_MAGENTA, COLOR_BLACK);
  447. X    init_pair(ColorId++, COLOR_CYAN, COLOR_BLACK);
  448. X    init_pair(ColorId, COLOR_WHITE, COLOR_BLACK);
  449. #endif
  450. }
  451. X
  452. SHAR_EOF
  453. chmod 0664 fire.c ||
  454. echo 'restore of fire.c failed'
  455. Wc_c="`wc -c < 'fire.c'`"
  456. test 6631 -eq "$Wc_c" ||
  457.     echo 'fire.c: original size 6631, current size' "$Wc_c"
  458. fi
  459. exit 0
  460. -- 
  461. Stacey Campbell       staceyc@sco.com
  462. {uunet,decwrl,ucscc,att,sq,altos,lotus,phoenix,sun,microsoft,xbs}!sco!staceyc
  463.