home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume4 / sim2 < prev    next >
Text File  |  1986-11-30  |  9KB  |  385 lines

  1. Subject: Re: Software similarity tester for C programs
  2. Newsgroups: mod.sources
  3. Approved: jpn@panda.UUCP
  4.  
  5. Mod.sources:  Volume 4, Issue 12
  6.  
  7. [ Contained here are two updates to "sim", the software similarity
  8.   tester that was submitted two weeks ago.  One provides for compiling
  9.   the program on a Gould, and the other provides more ambitious changes
  10.   including a new option to specify line width, as well as changes
  11.   specific to the HP-UX environment.
  12.  
  13.     - John P. Nelson, Moderator, mod.sources
  14. ]
  15.   
  16. -------------------------------------------------------------------
  17. Submitted by: tektronix!tekig4!georgew (George Walker)
  18.  
  19. This is a quick fix to allow sim to run on a Gould (which has 64K segment
  20. problems).  It prevents stack overflow.
  21.  
  22. Change is to hash.c (I have moved the declaration out of the function and made
  23. it a static):
  24.  
  25. 20a21,25
  26. > /*NOBASE*/                /* <- required by Gould compiler */
  27. > static unsigned int last[N_HASH];
  28. > /*    last[i] is the index of the latest char with hash_code i,
  29. >     or 0 if there is none.
  30. > */
  31. 27,30d31
  32. <     unsigned int last[N_HASH];
  33. <     /*    last[i] is the index of the latest char with hash_code i,
  34. <         or 0 if there is none.
  35. <     */
  36.  
  37. George Walker
  38.  
  39. (UUCP)       {ucbvax,decvax,chico,pur-ee,cbosg,ihnss}!tektronix!tekig4!georgew
  40. (CSNET)       tekig4!georgew@tek
  41. (ARPANET)  tekig4!georgew.tek@rand-relay
  42.  
  43.  
  44. -------------------------------------------------------------------
  45. Submitted by: hplabs!hp-lsd!paul (Paul Bame)
  46.  
  47.  
  48. Having a large-screen display, I decided to change sim(1) to accept a command 
  49. line argument allowing specification of line width.   The  following  patches
  50. (output  of  diff  -c)  patch  the  files  sim.c,  sim.1 (yea, even fixed the
  51. manual), pass3.c, and params.h to accommodate the  change.   I  attempted  to
  52. make the changes in the same style as the original software.  
  53.  
  54. Patches to Makefile and hash.c are suitable for HP-UX installations  and  may
  55. be  safely  removed  if you're not running HP-UX.  The local symbol space was
  56. too large in a function in hash.c so I moved the offending array outside  the
  57. function.  The MANDIR and BINDIR variables were changed in Makefile.  
  58.  
  59. Many thanks to Dick Grune for this software.
  60.  
  61.         --Paul Bame
  62.         UUCP: {hplabs,ihnp4!hpfcla}!hp-lsd!paul
  63.         CSNET: hp-lsd!paul@hp-labs
  64.         ARPA: hp-lsd!paul%hp-labs@csnet-relay.arpa
  65.  
  66.  
  67. *** /tmp/,RCSt1a03232    Thu Feb 20 13:53:49 1986
  68. --- Makefile    Thu Feb 20 13:52:04 1986
  69. ***************
  70. *** 2,9
  71.   #    Written by Dick Grune, Vrije Universiteit, Amsterdam.
  72.   #
  73.   
  74. ! BINDIR = /user1/dick/bin#        # where to put the binary (sim)
  75. ! MANDIR = /user1/dick/man#        # where to put the manual page (sim.1)
  76.   
  77.   #
  78.   #    Each module (set of programs that together perform some function)
  79.  
  80. --- 2,9 -----
  81.   #    Written by Dick Grune, Vrije Universiteit, Amsterdam.
  82.   #
  83.   
  84. ! BINDIR = /usr/local/bin#        # where to put the binary (sim)
  85. ! MANDIR = /usr/local/man/man1#        # where to put the manual page (sim.1)
  86.   
  87.   #
  88.   #    Each module (set of programs that together perform some function)
  89. *** /tmp/,RCSt1a03237    Thu Feb 20 13:53:56 1986
  90. --- hash.c    Thu Feb 20 13:52:12 1986
  91. ***************
  92. *** 23,28
  93.   static tally_right = 0, tally_wrong = 0;
  94.   static tally_hash(), print_tally();
  95.   
  96.   make_hash()    {
  97.       unsigned int last[N_HASH];
  98.       /*    last[i] is the index of the latest char with hash_code i,
  99.  
  100. --- 23,31 -----
  101.   static tally_right = 0, tally_wrong = 0;
  102.   static tally_hash(), print_tally();
  103.   
  104. + /* moved last[] out of make_hash() because too large local data area */
  105. + /* according to HPUX C compiler  - Paul Bame */
  106. + static unsigned int last[N_HASH];
  107.   make_hash()    {
  108.       /*    last[i] is the index of the latest char with hash_code i,
  109.           or 0 if there is none.
  110. ***************
  111. *** 24,30
  112.   static tally_hash(), print_tally();
  113.   
  114.   make_hash()    {
  115. -     unsigned int last[N_HASH];
  116.       /*    last[i] is the index of the latest char with hash_code i,
  117.           or 0 if there is none.
  118.       */
  119.  
  120. --- 27,32 -----
  121.   /* according to HPUX C compiler  - Paul Bame */
  122.   static unsigned int last[N_HASH];
  123.   make_hash()    {
  124.       /*    last[i] is the index of the latest char with hash_code i,
  125.           or 0 if there is none.
  126.       */
  127. *** /tmp/,RCSt1a03242    Thu Feb 20 13:54:02 1986
  128. --- params.h    Thu Feb 20 13:52:28 1986
  129. ***************
  130. *** 5,8
  131.   #define    MIN_RUN        24        /*    default minimum size
  132.                           of interesting run
  133.                       */
  134. ! #define    PAGE_WIDTH    80
  135.  
  136. --- 5,9 -----
  137.   #define    MIN_RUN        24        /*    default minimum size
  138.                           of interesting run
  139.                       */
  140. ! #define    DEFAULT_PAGE_WIDTH    80    /* default page width */
  141. ! #define    MAX_PAGE_WIDTH        160    /* maximum possible page width */
  142. *** /tmp/,RCSt1a03247    Thu Feb 20 13:54:08 1986
  143. --- pass3.c    Thu Feb 20 13:52:36 1986
  144. ***************
  145. *** 10,15
  146.   #include    "debug.h"
  147.   
  148.   extern char options[];
  149.   
  150.   static FILE *chunk_open();
  151.   static unsigned int fill_line();
  152.  
  153. --- 10,16 -----
  154.   #include    "debug.h"
  155.   
  156.   extern char options[];
  157. + extern int page_width;
  158.   
  159.   static FILE *chunk_open();
  160.   static unsigned int fill_line();
  161. ***************
  162. *** 14,19
  163.   static FILE *chunk_open();
  164.   static unsigned int fill_line();
  165.   static show_chunk(), show_line(), clear_line(), print_run();
  166.   
  167.   #define    MAXLINE        (PAGE_WIDTH/2-2)
  168.   
  169.  
  170. --- 15,21 -----
  171.   static FILE *chunk_open();
  172.   static unsigned int fill_line();
  173.   static show_chunk(), show_line(), clear_line(), print_run();
  174. + static int maxline;    /* Actual maxline */
  175.   
  176.   #define    MAXLINE        (MAX_PAGE_WIDTH/2-2)
  177.   
  178. ***************
  179. *** 15,21
  180.   static unsigned int fill_line();
  181.   static show_chunk(), show_line(), clear_line(), print_run();
  182.   
  183. ! #define    MAXLINE        (PAGE_WIDTH/2-2)
  184.   
  185.   pass3()    {
  186.       TopGen tp;
  187.  
  188. --- 17,23 -----
  189.   static show_chunk(), show_line(), clear_line(), print_run();
  190.   static int maxline;    /* Actual maxline */
  191.   
  192. ! #define    MAXLINE        (MAX_PAGE_WIDTH/2-2)
  193.   
  194.   pass3()    {
  195.       TopGen tp;
  196. ***************
  197. *** 21,26
  198.       TopGen tp;
  199.       struct run *run;
  200.   
  201.       OpenTop(&tp);
  202.       while ((run = NextTop(&tp)), run != NoObject)    {
  203.           print_run(run);
  204.  
  205. --- 23,30 -----
  206.       TopGen tp;
  207.       struct run *run;
  208.   
  209. +     maxline = page_width / 2 - 2;
  210.       OpenTop(&tp);
  211.       while ((run = NextTop(&tp)), run != NoObject)    {
  212.           print_run(run);
  213. ***************
  214. *** 164,170
  215.               indent++;
  216.           if (indent == 8)    {
  217.               /* every eight blanks give one blank */
  218. !             if (lpos < MAXLINE)
  219.                   ln[lpos++] = ' ';
  220.               indent = 0;
  221.           }
  222.  
  223. --- 168,174 -----
  224.               indent++;
  225.           if (indent == 8)    {
  226.               /* every eight blanks give one blank */
  227. !             if (lpos < maxline)
  228.                   ln[lpos++] = ' ';
  229.               indent = 0;
  230.           }
  231. ***************
  232. *** 174,180
  233.       while (ch >= 0 && ch != '\n')    {
  234.           if (ch == '\t')        /* replace tabs by blanks */
  235.               ch = ' ';
  236. !         if (lpos < MAXLINE)
  237.               ln[lpos++] = ch;
  238.           ch = getc(f);
  239.       }
  240.  
  241. --- 178,184 -----
  242.       while (ch >= 0 && ch != '\n')    {
  243.           if (ch == '\t')        /* replace tabs by blanks */
  244.               ch = ' ';
  245. !         if (lpos < maxline)
  246.               ln[lpos++] = ch;
  247.           ch = getc(f);
  248.       }
  249. ***************
  250. *** 195,201
  251.   {
  252.       int i;
  253.       
  254. !     for (i = 0; i < MAXLINE && ln0[i] != '\0'; i++)
  255.           putchar(ln0[i]);
  256.       for (; i < MAXLINE; i++)
  257.           putchar(' ');
  258.  
  259. --- 199,205 -----
  260.   {
  261.       int i;
  262.       
  263. !     for (i = 0; i < maxline && ln0[i] != '\0'; i++)
  264.           putchar(ln0[i]);
  265.       for (; i < maxline; i++)
  266.           putchar(' ');
  267. ***************
  268. *** 197,203
  269.       
  270.       for (i = 0; i < MAXLINE && ln0[i] != '\0'; i++)
  271.           putchar(ln0[i]);
  272. !     for (; i < MAXLINE; i++)
  273.           putchar(' ');
  274.       printf(" |");
  275.   
  276.  
  277. --- 201,207 -----
  278.       
  279.       for (i = 0; i < maxline && ln0[i] != '\0'; i++)
  280.           putchar(ln0[i]);
  281. !     for (; i < maxline; i++)
  282.           putchar(' ');
  283.       printf(" |");
  284.   
  285. ***************
  286. *** 201,207
  287.           putchar(' ');
  288.       printf(" |");
  289.   
  290. !     for (i = 0; i < MAXLINE && ln1[i] != '\0'; i++)
  291.               putchar(ln1[i]);
  292.       printf("\n");
  293.   }
  294.  
  295. --- 205,211 -----
  296.           putchar(' ');
  297.       printf(" |");
  298.   
  299. !     for (i = 0; i < maxline && ln1[i] != '\0'; i++)
  300.               putchar(ln1[i]);
  301.       printf("\n");
  302.   }
  303. *** /tmp/,RCSt1a03252    Thu Feb 20 13:54:16 1986
  304. --- sim.1    Thu Feb 20 13:52:40 1986
  305. ***************
  306. *** 9,14
  307.   [
  308.   .B \-[fns]
  309.   .BI \-r N
  310.   ]
  311.   file ...
  312.   .SH DESCRIPTION
  313.  
  314. --- 9,15 -----
  315.   [
  316.   .B \-[fns]
  317.   .BI \-r N
  318. + .BI \-w N
  319.   ]
  320.   file ...
  321.   .SH DESCRIPTION
  322. ***************
  323. *** 22,27
  324.   are found, they are reported on standard output; the default length
  325.   minimum is 24, but can be reset by the
  326.   .BR \-r -parameter.
  327.   .PP
  328.   The program can be used for finding copied pieces of code in
  329.   purportedly unrelated programs (with the
  330.  
  331. --- 23,33 -----
  332.   are found, they are reported on standard output; the default length
  333.   minimum is 24, but can be reset by the
  334.   .BR \-r -parameter.
  335. + .PP
  336. + The page width used may be changed from the default of 80 columns
  337. + with the
  338. + .BR \-w -parameter.
  339. + Maximum page width is 160 columns.
  340.   .PP
  341.   The program can be used for finding copied pieces of code in
  342.   purportedly unrelated programs (with the
  343. *** /tmp/,RCSt1a03257    Thu Feb 20 13:54:22 1986
  344. --- sim.c    Thu Feb 20 13:52:47 1986
  345. ***************
  346. *** 5,10
  347.   #include    "params.h"
  348.   
  349.   int min_run_size = MIN_RUN;
  350.   
  351.   char options[128];            /* for various, extensible flags */
  352.   
  353.  
  354. --- 5,11 -----
  355.   #include    "params.h"
  356.   
  357.   int min_run_size = MIN_RUN;
  358. + int page_width   = DEFAULT_PAGE_WIDTH;
  359.   
  360.   char options[128];            /* for various, extensible flags */
  361.   
  362. ***************
  363. *** 20,25
  364.               switch (*par)    {
  365.               case 'r':
  366.                   min_run_size = atoi(argv[1]);
  367.                   argc--, argv++;
  368.                   break;
  369.               default:
  370.  
  371. --- 21,30 -----
  372.               switch (*par)    {
  373.               case 'r':
  374.                   min_run_size = atoi(argv[1]);
  375. +                 argc--, argv++;
  376. +                 break;
  377. +             case 'w':
  378. +                 page_width = atoi(argv[1]);
  379.                   argc--, argv++;
  380.                   break;
  381.               default:
  382.  
  383.  
  384.