home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume5 / dotplan < prev    next >
Internet Message Format  |  1989-02-03  |  16KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: rem@remsit.UUCP (Roger Murray)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i032: dotplan - Program to generate interesting .plan files
  5. Message-ID: <518@remsit.UUCP>
  6. Date: 6 Nov 88 20:17:11 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: rem@remsit.UUCP (Roger Murray)
  9. Organization: REM's IT, Santa Monica, CA
  10. Lines: 574
  11. Approved: allbery@ncoast.UUCP
  12.  
  13. Posting-number: Volume 5, Issue 32
  14. Submitted-by: "Roger Murray" <rem@remsit.UUCP>
  15. Archive-name: dotplan
  16.  
  17. [It works and seems to contain no system dependencies.  Except that it uses
  18. a few long identifiers (expand_* and bounce_*).  ++bsa]
  19.  
  20. #    This is a shell archive.
  21. #    Remove everything above and including the cut line.
  22. #    Then run the rest of the file through sh.
  23. #----cut here-----cut here-----cut here-----cut here----#
  24. #!/bin/sh
  25. # shar:    Shell Archiver
  26. #    Run the following text with /bin/sh to create:
  27. #    Makefile
  28. #    dotplan.1
  29. #    dotplan.c
  30. # This archive created: Fri Oct 28 22:42:37 1988
  31. # By:    Roger Murray (REM's IT)
  32. echo shar: extracting Makefile
  33. sed 's/^XX//' << \SHAR_EOF > Makefile
  34. XXBINDIR = /usr/local/bin
  35. XX
  36. XXdotplan: dotplan.c
  37. XX    cc -s -o dotplan dotplan.c
  38. XX
  39. XXinstall: dotplan
  40. XX    mv dotplan $(BINDIR)
  41. SHAR_EOF
  42. if test 112 -ne "`wc -c Makefile`"
  43. then
  44. echo shar: error transmitting Makefile '(should have been 112 characters)'
  45. fi
  46. echo shar: extracting dotplan.1
  47. sed 's/^XX//' << \SHAR_EOF > dotplan.1
  48. XX.TH DOTPLAN 1
  49. XX.SH NAME
  50. XXdotplan \- Generate interesting .plan files
  51. XX.SH SYNOPSIS
  52. XX.B dotplan
  53. XX[
  54. XX.I style
  55. XX| s | d ]
  56. XX.I text
  57. XX.SH DESCRIPTION
  58. XX.I dotplan
  59. XXtakes the supplied text (optionally between quotes to reduce the possibility
  60. XXof conflict with a shell metacharater) and displays it in one of many ways.
  61. XXThe results can be redirected (via '>') to the user's
  62. XX.I .plan
  63. XXfile.
  64. XX.PP
  65. XXThe meanings of the options are:
  66. XX.TP 6
  67. XX.B style
  68. XXtells
  69. XX.I dotplan
  70. XXto display the given text in one of its many styles.
  71. XX.TP 6
  72. XX.B s
  73. XXdisplays the list of styles, using each style on its description.  It's
  74. XXnice to be able to compare various styles and it helps when the user
  75. XXcan't think of anything to display.
  76. XX.TP 6
  77. XX.B d
  78. XXdisplays the given text in all styles, one at a time.
  79. XX.SH EXAMPLES
  80. XX.nf
  81. XXdotplan 3 This is sample text # Display string using style 3
  82. XXdotplan                       # Display usage information
  83. XXdotplan s                     # Display styles in all styles
  84. XXdotplay d This is more text   # Display string in all styles
  85. XX.fi
  86. XX.SH AUTHORS
  87. XX.nf
  88. XXRoger Murray <rem@remsit.UUCP>
  89. XXMarc Kriguer <kriguer@ernie.bekeley.edu>
  90. XX.fi
  91. XX.SH DIAGNOSTICS
  92. XX"Huh? (bad style number)" means the user has tried to select a style that
  93. XXdoesn't exist.  "Huh? (bad letter)" means the user has chosen an option
  94. XXthat doesn't exist.
  95. XX.SH BUGS
  96. XXThe resulting
  97. XX.I .plan
  98. XXfiles can look pretty nice.  However, people using high speed terminals
  99. XX(terminals on cluster lines, Xenix consoles, etc.) won't really get the full
  100. XXeffect when viewing them.  I suppose there are worse things in the world.
  101. XX.SH SEE ALSO
  102. XXfinger(1)
  103. XXrn(1)
  104. XXwarp(6)
  105. SHAR_EOF
  106. if test 1572 -ne "`wc -c dotplan.1`"
  107. then
  108. echo shar: error transmitting dotplan.1 '(should have been 1572 characters)'
  109. fi
  110. echo shar: extracting dotplan.c
  111. sed 's/^XX//' << \SHAR_EOF > dotplan.c
  112. XX/*
  113. XX * dotplan.c - Program to generate interesting .plan files
  114. XX *
  115. XX * By Roger Murray (ucla-an!remsit!rem@ee.ucla.edu) and
  116. XX *    Marc Kriguer (kriguer@ernie.berkeley.edu)
  117. XX *
  118. XX * Last Update: Mon Oct 17 13:55:14 PDT 1988
  119. XX *
  120. XX * If you'd like to add algorithms to this program, please follow the
  121. XX * following guidelines:
  122. XX *
  123. XX * 1) Write them as functions passed a (char *) and returning an int.
  124. XX * 2) Don't use backspaces.  Some fingers translate them.
  125. XX * 3) Be careful with malloc().  Make sure strings are NULL-terminated.
  126. XX *    free() what you malloc().
  127. XX * 4) Send the function, its long name (for list[]), and an address
  128. XX *    (to give credit where credit is due) to one of us.  "Anon" is fine.
  129. XX */
  130. XX
  131. XX#include <stdio.h>
  132. XX
  133. XX/* REM */
  134. XX
  135. XXint shift_right(string)
  136. XXchar *string;
  137. XX{
  138. XX   char *ptr;
  139. XX
  140. XX   ptr = &string[strlen(string)-1];
  141. XX   while(ptr >= string)
  142. XX      {
  143. XX         printf("%s\r", ptr);
  144. XX         ptr--;
  145. XX      }
  146. XX   putchar('\n');
  147. XX}
  148. XX
  149. XX/* REM */
  150. XX
  151. XXint shift_left(string)
  152. XXchar *string;
  153. XX{
  154. XX   int loop;
  155. XX
  156. XX   for(loop = strlen(string)-1; loop >= 1; loop--)
  157. XX      printf("%*s%.*s\r", loop, " ", strlen(string)-loop, string);
  158. XX   printf("%s\n", string);
  159. XX}
  160. XX
  161. XX/* MDK */
  162. XX
  163. XXint fill_right(string)
  164. XXchar *string;
  165. XX{
  166. XX   int i;
  167. XX
  168. XX   for (i = 1; i <= strlen(string); i++)
  169. XX      printf("%.*s\r", i, string);
  170. XX   putchar('\n');
  171. XX}
  172. XX
  173. XX/* MDK */
  174. XX
  175. XXint fill_left(string)
  176. XXchar *string;
  177. XX{
  178. XX   int i;
  179. XX
  180. XX   for (i = 1; i < strlen(string) - 1; i++)
  181. XX      printf("%*s%c\r", strlen(string)-i, " ", string[strlen(string)-i]);
  182. XX   printf("%s\n", string);
  183. XX}
  184. XX
  185. XX/* MDK */
  186. XX
  187. XXint ASCIIbet(string)
  188. XXchar *string;
  189. XX{
  190. XX   char *ptr;
  191. XX   int i, j, flag;
  192. XX
  193. XX   ptr = (char *) malloc(strlen(string)+1);
  194. XX   sprintf(ptr, "%*s", strlen(string), " ");
  195. XX
  196. XX   for (j = 1; j < 128; j++)
  197. XX   {
  198. XX      flag = 0;
  199. XX      for (i = 0; i < strlen(string) ; i++)
  200. XX         {
  201. XX        if (string[i] == j)
  202. XX        {
  203. XX           flag = 1;
  204. XX           ptr[i] = j;
  205. XX            }
  206. XX         }
  207. XX      if (flag)
  208. XX            printf("%s\r", ptr);
  209. XX   }
  210. XX   putchar('\n');
  211. XX   free(ptr);
  212. XX}
  213. XX
  214. XX/* MDK */
  215. XX
  216. XXint Robot_Attack(string)
  217. XXchar *string;
  218. XX{
  219. XX   char *ptr;
  220. XX   int i, j, flag=0;
  221. XX
  222. XX   ptr = (char *) malloc(strlen(string)+1);
  223. XX
  224. XX   for (i = 0; i < strlen(string); i++)
  225. XX   {
  226. XX      ptr[i] = ' ';
  227. XX      if (string[i] > flag)
  228. XX     flag = string[i];
  229. XX      if (string[i] < 'a')        /* only one pass for lower case letters;
  230. XX                            it took too long going from 32 to 127 */
  231. XX     ptr[i] = string[i];
  232. XX   }
  233. XX
  234. XX   ptr[strlen(string)] = '\0';
  235. XX
  236. XX   for (j = 'a'; j <= flag; j++)
  237. XX   {
  238. XX      for (i = 0; i < strlen(string) ; i++)
  239. XX         {
  240. XX        if (string[i] >= j)
  241. XX        {
  242. XX           ptr[i] = j;
  243. XX            }
  244. XX         }
  245. XX      printf("%s\r", ptr);
  246. XX   }
  247. XX   putchar('\n');
  248. XX   free(ptr);
  249. XX}
  250. XX
  251. XX/* REM */
  252. XX
  253. XXint expand_out(string)
  254. XXchar *string;
  255. XX{
  256. XX   char *ptr;
  257. XX   int loop, halfsize;
  258. XX
  259. XX   if(strlen(string) % 2)
  260. XX      {
  261. XX         ptr = (char *) malloc(strlen(string)+2);
  262. XX         sprintf(ptr, "%s ", string);
  263. XX      }
  264. XX   else
  265. XX      ptr = string;
  266. XX   for(loop = 1; loop <= (halfsize = strlen(ptr)/2)-1; loop++)
  267. XX      printf("%*s%.*s%s%*s\r", halfsize-loop, " ", loop, ptr,
  268. XX         &ptr[strlen(ptr)-1-loop], halfsize-loop, " ");
  269. XX   printf("%s\n", ptr);
  270. XX   if(ptr != string)
  271. XX      free(ptr);
  272. XX}
  273. XX
  274. XX/* REM */
  275. XX
  276. XXint expand_in(string)
  277. XXchar *string;
  278. XX{
  279. XX   char *ptr;
  280. XX   int loop, halfsize;
  281. XX
  282. XX   if(strlen(string) % 2)
  283. XX      {
  284. XX         ptr = (char *) malloc(strlen(string)+2);
  285. XX         sprintf(ptr, "%s ", string);
  286. XX      }
  287. XX   else
  288. XX      ptr = string;
  289. XX   for(loop = 1; loop <= (halfsize = strlen(ptr)/2)-1; loop++)
  290. XX      printf("%.*s%*s%.*s\r", loop, &ptr[halfsize-loop],
  291. XX         2 * (halfsize-loop), " ", loop, &ptr[halfsize]);
  292. XX   printf("%s\n", ptr);
  293. XX   if(ptr != string)
  294. XX      free(ptr);
  295. XX}
  296. XX
  297. XX/* MDK */
  298. XX
  299. XXint merge_one(string)
  300. XXchar *string;
  301. XX{
  302. XX   char *ptr, *model;
  303. XX   int loop, i, len=strlen(string);
  304. XX
  305. XX   if(len % 2)
  306. XX      {
  307. XX         ptr = (char *) malloc(++len +1);
  308. XX         sprintf(ptr, "%*s", len, " ");
  309. XX         model = (char *) malloc(len +1);
  310. XX         sprintf(model, "%s ", string);
  311. XX      }
  312. XX   else
  313. XX      {
  314. XX         ptr = (char *) malloc(len +1);
  315. XX         sprintf(ptr, "%*s", len, " ");
  316. XX         model = string;
  317. XX      }
  318. XX
  319. XX   for(loop = 0; loop < len/2; loop++)
  320. XX   {
  321. XX      for (i = 0; i <= loop; i++)
  322. XX      {
  323. XX         ptr[2*i] = model[len + 2*(i - loop -1)];
  324. XX         ptr[len-1 - 2*i] = model[2*(loop - i) + 1];
  325. XX      }
  326. XX      printf ("%s\r", ptr); 
  327. XX   }
  328. XX   putchar('\n');
  329. XX   free(ptr);
  330. XX   if(model != string)
  331. XX      free(model);
  332. XX}
  333. XX
  334. XX/* REM */
  335. XX
  336. XXint bounce_right(string)
  337. XXchar *string;
  338. XX{
  339. XX   char *ptr, *backward;
  340. XX   int loop, len = strlen(string);
  341. XX
  342. XX   backward = (char *) malloc(len+1);
  343. XX   for(loop = 0; loop < len; loop++)
  344. XX      backward[len-1-loop] = string[loop];
  345. XX   backward[len] = '\0';
  346. XX   ptr = &backward[len-1];
  347. XX   while(ptr >= backward)
  348. XX      {
  349. XX         printf("%s\r", ptr);
  350. XX         ptr--;
  351. XX      }
  352. XX   ptr = (char *) malloc(len+1);
  353. XX   for(loop = 1; loop < len; loop++)
  354. XX      {
  355. XX         sprintf(ptr, "%*s%.*s", loop, " ", len-loop, backward);
  356. XX         sprintf(&ptr[len-loop], "%.*s", loop, string);
  357. XX         printf("%s\r", ptr);
  358. XX      }
  359. XX   printf("%s\n", string);
  360. XX   free(ptr);
  361. XX   free(backward);
  362. XX}
  363. XX
  364. XX/* REM */
  365. XX
  366. XXint bounce_left(string)
  367. XXchar *string;
  368. XX{
  369. XX   char *ptr, *backward, *from, *to;
  370. XX   int loop, len = strlen(string);
  371. XX
  372. XX   backward = (char *) malloc(len+1);
  373. XX   for(loop = 0; loop < len; loop++)
  374. XX      backward[len-1-loop] = string[loop];
  375. XX   backward[len] = '\0';
  376. XX   for(loop = len-1; loop >= 1; loop--)
  377. XX      printf("%*s%.*s\r", loop, " ", len-loop, backward);
  378. XX   printf("%s\r", backward);
  379. XX   ptr = (char *) malloc(len+1);
  380. XX   for(loop = 1; loop < len; loop++)
  381. XX      {
  382. XX         sprintf(ptr, "%s%*s", &backward[loop], loop, " ");
  383. XX         from = &string[len-loop];
  384. XX         to = ptr;
  385. XX         while(*from != '\0')
  386. XX            *to++ = *from++;
  387. XX         printf("%s\r", ptr);
  388. XX      }
  389. XX   printf("%s\n", string);
  390. XX   free(ptr);
  391. XX   free(backward);
  392. XX}
  393. XX
  394. XX/* MDK */
  395. XX
  396. XX#define swap(A,B)  temp = (A); (A) = (B); (B) = temp
  397. XX
  398. XXint bubble(string)
  399. XXchar *string;
  400. XX{
  401. XX   char *ptr;
  402. XX   int   i, j, temp, 
  403. XX         swaps = 0,
  404. XX         len = strlen(string),
  405. XX         *indices = (int *) malloc(len * sizeof(int));
  406. XX
  407. XX   ptr = (char *) malloc(len + 1);
  408. XX   strcpy (ptr, string);
  409. XX
  410. XX   for (i = 0; i < len; i++)
  411. XX      indices[i] = i;
  412. XX
  413. XX   for (i = 0; i <= len-2; i++)            /* first, bubble sort the */
  414. XX      for (j = i+1; j <= len-1; j++)        /* string, to create an   */
  415. XX     if (ptr[i] > ptr[j])            /* array of indices that  */
  416. XX     {                    /* correspond to our      */
  417. XX            swap(ptr[i], ptr[j]);        /* characters. */
  418. XX        swap(indices[i], indices[j]);
  419. XX         }
  420. XX
  421. XX   for (i = 0; i <= len-2; i++)            /* Now, bubble sort the   */
  422. XX      for (j = i+1; j <= len-1; j++)        /* numbers back into      */
  423. XX     if (indices[i] > indices[j])        /* place to "unsort" the  */    
  424. XX     {                    /* sorted letters into    */
  425. XX        printf ("%s\r", ptr);        /* out desired string.    */
  426. XX            swap(ptr[i], ptr[j]);
  427. XX        swap(indices[i], indices[j]);
  428. XX         }
  429. XX
  430. XX   puts(ptr);
  431. XX   free(ptr);
  432. XX   free(indices);
  433. XX}
  434. XX
  435. XX/* REM */
  436. XX
  437. XXint insert(string)
  438. XXchar *string;
  439. XX{
  440. XX   char *ptr, *load;
  441. XX   int len = strlen(string),
  442. XX       loop, *iptr, min = 255, max = 0,
  443. XX       *pos = (int *) malloc(len * sizeof(int));
  444. XX
  445. XX   ptr = (char *) malloc(len+1);
  446. XX   for(loop = 0; loop < len; loop++)
  447. XX      {
  448. XX         pos[loop] = 0;
  449. XX         if(string[loop] < min)
  450. XX            min = string[loop];
  451. XX         else
  452. XX            if(string[loop] > max)
  453. XX               max = string[loop];
  454. XX      }
  455. XX   for(; min <= max; min++)
  456. XX      {
  457. XX         for(loop = 0; loop < len; loop++)
  458. XX            if(string[loop] == min)
  459. XX               {
  460. XX                  pos[loop] = 1;
  461. XX                  load = ptr;
  462. XX                  iptr = pos;
  463. XX                  while(iptr <= &pos[len-1])
  464. XX                     if (*iptr++)
  465. XX                        *load++ = string[(iptr-1)-pos];
  466. XX                  *load = '\0';
  467. XX                  printf("%s\r", ptr);
  468. XX               }
  469. XX      }
  470. XX   putchar('\n');
  471. XX   free(ptr);
  472. XX   free(pos);
  473. XX}
  474. XX
  475. XXtypedef struct array_elem {
  476. XX   char *name;
  477. XX   int (*function)();
  478. XX};
  479. XX
  480. XX/*
  481. XX * Nick:    Address:
  482. XX * REM      ucla-an!remsit!rem@ee.ucla.edu
  483. XX * MDK      kriguer@ernie.berkeley.edu
  484. XX */
  485. XX
  486. XXstruct array_elem list[] = {
  487. XX
  488. XX{ "Shift text to right", shift_right },     /* REM */
  489. XX{ "Shift text to left", shift_left},        /* REM */
  490. XX{ "Fill text to right", fill_right },       /* MDK */
  491. XX{ "Fill text to left", fill_left },         /* MDK */
  492. XX{ "Expand text outward", expand_out },      /* REM */
  493. XX{ "Expand text inward", expand_in },        /* REM */
  494. XX{ "Bounce text on right", bounce_right },   /* REM */
  495. XX{ "Bounce text on left", bounce_left },     /* REM */
  496. XX{ "Merge text inward", merge_one },         /* MDK */
  497. XX{ "Un-Bubble Sort text", bubble },          /* MDK */
  498. XX{ "Insertion Sort text", insert },          /* REM */
  499. XX{ "Fill text ASCIIbetically", ASCIIbet },   /* MDK */
  500. XX{ "Robot Attack technique", Robot_Attack }, /* MDK */
  501. XX
  502. XX};
  503. XX
  504. XX#define LISTSIZE sizeof(list) / sizeof(struct array_elem)
  505. XX
  506. XXchar *author[2] = { "Roger Murray (ucla-an!remsit!rem@ee.ucla.edu)",
  507. XX                    "Marc Kriguer (kriguer@ernie.berkeley.edu)", };
  508. XX
  509. XXmain(argc, argv)
  510. XXint argc;
  511. XXchar *argv[];
  512. XX{
  513. XX   int loop, style, arglen;
  514. XX   char temp_string[80];
  515. XX   char *textptr;
  516. XX
  517. XX   if(argc < 3 && !(argc == 2 && argv[1][0] == 's'))
  518. XX      {
  519. XX         printf("Usage: %s [style|s|d] \"Text to display\"\n\n", argv[0]);
  520. XX         printf("Styles:\n");
  521. XX         for(loop = 0; loop < LISTSIZE; loop++)
  522. XX            printf("   %2d. %s\n", loop+1, list[loop].name);
  523. XX         printf("\ns = help with styles  :-)\n");
  524. XX         printf("d = display in all styles\n");
  525. XX         printf("\nBy: %s and\n    %s\n", author[getpid() % 2],
  526. XX            author[!(getpid() % 2)]);
  527. XX         exit(0);
  528. XX      }
  529. XX   if((style = atoi(argv[1])) == 0)
  530. XX      switch(argv[1][0])
  531. XX         {
  532. XX            case 's': printf("Styles:\n");
  533. XX                      for(loop = 0; loop < LISTSIZE; loop++)
  534. XX                         {
  535. XX                            sprintf(temp_string, "   %2d. %s", loop+1, list[loop].name);
  536. XX                            (void) (*list[loop].function)(temp_string);
  537. XX                         }
  538. XX                      break;
  539. XX            case 'd': arglen = 0;
  540. XX                      for(loop = 2; loop < argc; loop++)
  541. XX                         arglen += strlen(argv[loop]) + 1;
  542. XX                      textptr = (char *) malloc(arglen);
  543. XX                      *textptr = '\0';
  544. XX                      for(loop = 2; loop < argc; loop++)
  545. XX                         {
  546. XX                            strcat(textptr, argv[loop]);
  547. XX                            if(loop != argc-1)
  548. XX                               strcat(textptr, " ");
  549. XX                         }
  550. XX                      for(loop = 0; loop < LISTSIZE; loop++)
  551. XX                         (void) (*list[loop].function)(textptr);
  552. XX                      break;
  553. XX            default: printf("Huh? (bad letter)\n");
  554. XX                     break;
  555. XX         }
  556. XX   else
  557. XX      if(style >= 1 && style <= LISTSIZE+1)
  558. XX         {
  559. XX            arglen = 0;
  560. XX            for(loop = 2; loop < argc; loop++)
  561. XX               arglen += strlen(argv[loop]) + 1;
  562. XX            textptr = (char *) malloc(arglen);
  563. XX            *textptr = '\0';
  564. XX            for(loop = 2; loop < argc; loop++)
  565. XX               {
  566. XX                  strcat(textptr, argv[loop]);
  567. XX                  if(loop != argc-1)
  568. XX                     strcat(textptr, " ");
  569. XX               }
  570. XX            (void) (*list[style-1].function)(textptr);
  571. XX         }
  572. XX      else
  573. XX         printf("Huh? (bad style number)\n");
  574. XX}
  575. SHAR_EOF
  576. if test 11316 -ne "`wc -c dotplan.c`"
  577. then
  578. echo shar: error transmitting dotplan.c '(should have been 11316 characters)'
  579. fi
  580. #    End of shell archive
  581. exit 0
  582. -- 
  583. Roger Murray
  584. "Look ma!  No ihnp4!"  :-)
  585. UUCP: ...!{randvax,sdcrdcf,ucbvax}!ucla-cs!cepu!ucla-an!remsit!rem
  586. ARPA: cepu!ucla-an!remsit!rem@CS.UCLA.EDU
  587.