home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1992 June / SIMTEL_0692.cdr / msdos / gnuish / gptx01.arc / patches < prev    next >
Text File  |  1990-09-24  |  29KB  |  974 lines

  1. *** e:\tmp/RCSt1006052    Sat Sep 22 00:28:24 1990
  2. --- gptx.c    Sat Sep 22 00:20:50 1990
  3. ***************
  4. *** 2,8 ****
  5.      Copyright (C) 1990 Free Software Foundation, Inc.
  6.      Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  7.   
  8. !    $Id: gptx.c 0.1 90/08/11 09:18:50 tho Exp $
  9.   
  10.      This program is free software; you can redistribute it and/or modify
  11.      it under the terms of the GNU General Public License as published by
  12. --- 2,8 ----
  13.      Copyright (C) 1990 Free Software Foundation, Inc.
  14.      Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  15.   
  16. !    $Id: gptx.c 0.1.0.4 90/09/22 00:18:19 tho Exp $
  17.   
  18.      This program is free software; you can redistribute it and/or modify
  19.      it under the terms of the GNU General Public License as published by
  20. ***************
  21. *** 117,124 ****
  22.   
  23.   typedef struct
  24.     {
  25. !     char *start;        /* pointer to beginning of region */
  26. !     char *end;            /* pointer to end + 1 of region */
  27.     }
  28.   BLOCK;
  29.   
  30. --- 117,124 ----
  31.   
  32.   typedef struct
  33.     {
  34. !     char HUGE *start;        /* pointer to beginning of region */
  35. !     char HUGE *end;            /* pointer to end + 1 of region */
  36.     }
  37.   BLOCK;
  38.   
  39. ***************
  40. *** 186,192 ****
  41.   int *file_line_count;        /* array of `total_line_count' values at end */
  42.   
  43.   BLOCK text_buffer;        /* file to study */
  44. ! char *text_buffer_maxend;    /* allocated end of text_buffer */
  45.   
  46.   /* SKIP_NON_WHITE used only for getting or skipping the reference.  */
  47.   
  48. --- 186,192 ----
  49.   int *file_line_count;        /* array of `total_line_count' values at end */
  50.   
  51.   BLOCK text_buffer;        /* file to study */
  52. ! char HUGE *text_buffer_maxend;    /* allocated end of text_buffer */
  53.   
  54.   /* SKIP_NON_WHITE used only for getting or skipping the reference.  */
  55.   
  56. ***************
  57. *** 207,213 ****
  58.       if (word_regex_string)                        \
  59.         {                                    \
  60.       int count;                            \
  61. !     count = re_match (word_regex, cursor, limit - cursor, 0, NULL);    \
  62.       cursor += count <= 0 ? 1 : count;                \
  63.         }                                    \
  64.       else if (word_fastmap[(unsigned char) *cursor])            \
  65. --- 207,214 ----
  66.       if (word_regex_string)                        \
  67.         {                                    \
  68.       int count;                            \
  69. !     count = re_match (word_regex, cursor,                \
  70. !               L_PDIFF(limit, cursor), ZERO, NULL);        \
  71.       cursor += count <= 0 ? 1 : count;                \
  72.         }                                    \
  73.       else if (word_fastmap[(unsigned char) *cursor])            \
  74. ***************
  75. *** 368,374 ****
  76. --- 369,380 ----
  77.   
  78.     if (pattern->allocated > pattern->used)
  79.       {
  80. + #ifdef MSDOS
  81. +       pattern->buffer
  82. +     = (char *) xrealloc (pattern->buffer, (size_t) pattern->used);
  83. + #else /* not MSDOS */
  84.         pattern->buffer = (char *) xrealloc (pattern->buffer, pattern->used);
  85. + #endif /* not MSDOS */
  86.         pattern->allocated = pattern->used;
  87.       }
  88.   
  89. ***************
  90. *** 469,477 ****
  91.   {
  92.     int file_handle;        /* file descriptor number */
  93.     struct stat stat_block;    /* stat block for file */
  94. !   int allocated_length;        /* allocated length of memory buffer */
  95. !   int used_length;        /* used length in memory buffer */
  96. !   int read_length;        /* number of character gotten on last read */
  97.   
  98.     /* As special cases, a file name which is NULL or "-" indicates standard
  99.        input, which is already opened.  In all other cases, open the file from
  100. --- 475,483 ----
  101.   {
  102.     int file_handle;        /* file descriptor number */
  103.     struct stat stat_block;    /* stat block for file */
  104. !   LONG allocated_length;        /* allocated length of memory buffer */
  105. !   LONG used_length;        /* used length in memory buffer */
  106. !   LONG read_length;        /* number of character gotten on last read */
  107.   
  108.     /* As special cases, a file name which is NULL or "-" indicates standard
  109.        input, which is already opened.  In all other cases, open the file from
  110. ***************
  111. *** 493,498 ****
  112. --- 499,513 ----
  113.   
  114.     if ((stat_block.st_mode & S_IFMT) == S_IFREG)
  115.       {
  116. + #ifdef MSDOS
  117. +       block->start = (char HUGE *) xhalloc (stat_block.st_size);
  118. +       read_length = hread (file_handle, block->start, stat_block.st_size);
  119. +       if (read_length <= 0L)
  120. +     perror_and_exit (file_name);
  121. +       block->end = block->start + read_length;
  122. + #else /* not MSDOS */
  123.         block->start = (char *) xmalloc ((int) stat_block.st_size);
  124.   
  125.         if (read (file_handle, block->start, (int) stat_block.st_size)
  126. ***************
  127. *** 500,508 ****
  128. --- 515,533 ----
  129.       perror_and_exit (file_name);
  130.   
  131.         block->end = block->start + stat_block.st_size;
  132. + #endif /* not MSDOS */
  133.       }
  134.     else
  135.       {
  136. + #ifdef MSDOS
  137. +       block->start = (char HUGE *) xhalloc (1L << SWALLOW_REALLOC_LOG);
  138. +       used_length = 0;
  139. +       allocated_length = (1 << SWALLOW_REALLOC_LOG);
  140. +       while ((read_length = hread (file_handle,
  141. +                    block->start + used_length,
  142. +                    allocated_length - used_length)) > 0L)
  143. + #else /* not MSDOS */
  144.         block->start = (char *) xmalloc (1 << SWALLOW_REALLOC_LOG);
  145.         used_length = 0;
  146.         allocated_length = (1 << SWALLOW_REALLOC_LOG);
  147. ***************
  148. *** 510,522 ****
  149. --- 535,556 ----
  150.         while ((read_length = read (file_handle,
  151.                     block->start + used_length,
  152.                     allocated_length - used_length)) > 0)
  153. + #endif /* not MSDOS */
  154.       {
  155.         used_length += read_length;
  156.         if (used_length == allocated_length)
  157.           {
  158. + #ifdef MSDOS
  159. +           block->start
  160. +         = (char HUGE *) xhrealloc (block->start, allocated_length,
  161. +                        allocated_length
  162. +                        + (1L << SWALLOW_REALLOC_LOG));
  163. +           allocated_length += (1L << SWALLOW_REALLOC_LOG);
  164. + #else /* not MSDOS */
  165.             allocated_length += (1 << SWALLOW_REALLOC_LOG);
  166.             block->start
  167.           = (char *) xrealloc (block->start, allocated_length);
  168. + #endif /* not MSDOS */
  169.           }
  170.       }
  171.   
  172. ***************
  173. *** 594,600 ****
  174. --- 628,642 ----
  175.     int value;
  176.   
  177.     value = compare_words (&first->key, &second->key);
  178. + #ifdef MSDOS
  179. +   return
  180. +     value == 0
  181. +     ? (L_PDIFF (first->key.start, second->key.start) >= 0L ? 1 : -1)
  182. +     : value;
  183. + #else /* not MSDOS */
  184.     return value == 0 ? first->key.start - second->key.start : value;
  185. + #endif /* not MSDOS */
  186.   }
  187.   
  188.   
  189. ***************
  190. *** 645,650 ****
  191. --- 687,696 ----
  192.   
  193.     /* Only one language for the time being.  */
  194.   
  195. + #ifdef MSDOS
  196. +   assert ((long) number_of_occurs[0] * (long) sizeof_occurs < 0x10000L);
  197. + #endif
  198.     qsort (occurs_table[0], number_of_occurs[0],
  199.        sizeof_occurs, compare_occurs);
  200.   }
  201. ***************
  202. *** 734,740 ****
  203.       {
  204.         ALLOC_NEW_WORD (table);
  205.         table->start[table->length].start = word_start;
  206. !       table->start[table->length].size = cursor - word_start;
  207.         table->length++;
  208.       }
  209.   
  210. --- 780,786 ----
  211.       {
  212.         ALLOC_NEW_WORD (table);
  213.         table->start[table->length].start = word_start;
  214. !       table->start[table->length].size = I_PDIFF (cursor, word_start);
  215.         table->length++;
  216.       }
  217.   
  218. ***************
  219. *** 746,751 ****
  220. --- 792,801 ----
  221.   
  222.     /* Finally, sort all the words read.  */
  223.   
  224. + #ifdef MSDOS
  225. +   assert ((long) table->length * (long) sizeof (WORD) < 0x10000L);
  226. + #endif
  227.     qsort (table->start, table->length, sizeof (WORD), compare_words);
  228.   }
  229.   
  230. ***************
  231. *** 762,778 ****
  232.   find_occurs_in_text ()
  233.   #endif
  234.   {
  235. !   char *cursor;            /* for scanning the source text */
  236. !   char *scan;            /* for scanning the source text also */
  237. !   char *line_start;        /* start of the current input line */
  238. !   char *line_scan;        /* newlines scanned until this point */
  239.     int reference_length;        /* length of reference in input mode */
  240.     WORD possible_key;        /* possible key, to ease searches */
  241.     OCCURS *occurs_cursor;    /* current OCCURS under construction */
  242.   
  243. !   char *context_start;        /* start of left context */
  244. !   char *context_end;        /* end of right context */
  245. !   char *next_context_start;    /* next start of left context */
  246.   
  247.     /* Tracking where lines start is helpful for reference processing.  In
  248.        auto reference mode, this allows counting lines.  In input reference
  249. --- 812,828 ----
  250.   find_occurs_in_text ()
  251.   #endif
  252.   {
  253. !   char HUGE *cursor;        /* for scanning the source text */
  254. !   char HUGE *scan;        /* for scanning the source text also */
  255. !   char HUGE *line_start;    /* start of the current input line */
  256. !   char HUGE *line_scan;        /* newlines scanned until this point */
  257.     int reference_length;        /* length of reference in input mode */
  258.     WORD possible_key;        /* possible key, to ease searches */
  259.     OCCURS *occurs_cursor;    /* current OCCURS under construction */
  260.   
  261. !   char HUGE *context_start;    /* start of left context */
  262. !   char HUGE *context_end;    /* end of right context */
  263. !   char HUGE *next_context_start;/* next start of left context */
  264.   
  265.     /* Tracking where lines start is helpful for reference processing.  In
  266.        auto reference mode, this allows counting lines.  In input reference
  267. ***************
  268. *** 788,794 ****
  269.     if (input_reference)
  270.       {
  271.         SKIP_NON_WHITE (line_scan, text_buffer.end);
  272. !       reference_length = line_scan - line_start;
  273.         SKIP_WHITE (line_scan, text_buffer.end);
  274.       }
  275.   
  276. --- 838,844 ----
  277.     if (input_reference)
  278.       {
  279.         SKIP_NON_WHITE (line_scan, text_buffer.end);
  280. !       reference_length = I_PDIFF (line_scan, line_start);
  281.         SKIP_WHITE (line_scan, text_buffer.end);
  282.       }
  283.   
  284. ***************
  285. *** 814,821 ****
  286.        sentence at the end of the buffer.  */
  287.   
  288.         if (context_regex_string
  289. !       && (re_search (context_regex, cursor, text_buffer.end - cursor,
  290. !              0, text_buffer.end - cursor, &context_regs)
  291.             >= 0))
  292.       next_context_start = cursor + context_regs.end[0];
  293.   
  294. --- 864,872 ----
  295.        sentence at the end of the buffer.  */
  296.   
  297.         if (context_regex_string
  298. !       && (re_search (context_regex, cursor,
  299. !              L_PDIFF (text_buffer.end, cursor),
  300. !              ZERO, L_PDIFF (text_buffer.end, cursor), &context_regs)
  301.             >= 0))
  302.       next_context_start = cursor + context_regs.end[0];
  303.   
  304. ***************
  305. *** 841,848 ****
  306.              the loop.  */
  307.   
  308.           {
  309. !           if (re_search (word_regex, cursor, context_end - cursor,
  310. !                  0, context_end - cursor, &word_regs)
  311.             < 0)
  312.           break;
  313.           }
  314. --- 892,900 ----
  315.              the loop.  */
  316.   
  317.           {
  318. !           if (re_search (word_regex, cursor,
  319. !                  L_PDIFF (context_end, cursor),
  320. !                  ZERO, L_PDIFF (context_end, cursor), &word_regs)
  321.             < 0)
  322.           break;
  323.           }
  324. ***************
  325. *** 862,874 ****
  326.             if (scan == context_end)
  327.           break;
  328.   
  329. !           word_regs.start[0] = scan - cursor;
  330.   
  331.             while (scan < context_end
  332.                && word_fastmap[(unsigned char) *scan])
  333.           scan++;
  334.   
  335. !           word_regs.end[0] = scan - cursor;
  336.           }
  337.   
  338.         /* Skip right to the beginning of the found word.  */
  339. --- 914,926 ----
  340.             if (scan == context_end)
  341.           break;
  342.   
  343. !           word_regs.start[0] = I_PDIFF (scan, cursor);
  344.   
  345.             while (scan < context_end
  346.                && word_fastmap[(unsigned char) *scan])
  347.           scan++;
  348.   
  349. !           word_regs.end[0] = I_PDIFF (scan, cursor);
  350.           }
  351.   
  352.         /* Skip right to the beginning of the found word.  */
  353. ***************
  354. *** 912,918 ****
  355.               line_scan++;
  356.               line_start = line_scan;
  357.               SKIP_NON_WHITE (line_scan, text_buffer.end);
  358. !             reference_length = line_scan - line_start;
  359.             }
  360.           else
  361.             line_scan++;
  362. --- 964,971 ----
  363.               line_scan++;
  364.               line_start = line_scan;
  365.               SKIP_NON_WHITE (line_scan, text_buffer.end);
  366. !             reference_length = I_PDIFF (line_scan, line_start);
  367.             }
  368.           else
  369.             line_scan++;
  370. ***************
  371. *** 976,982 ****
  372.            value of `line_start'.  */
  373.   
  374.             occurs_cursor->reference
  375. !         = (DELTA) (line_start - possible_key.start);
  376.             if (reference_length > reference_max_width)
  377.           reference_max_width = reference_length;
  378.           }
  379. --- 1029,1035 ----
  380.            value of `line_start'.  */
  381.   
  382.             occurs_cursor->reference
  383. !         = (DELTA) I_PDIFF (line_start, possible_key.start);
  384.             if (reference_length > reference_max_width)
  385.           reference_max_width = reference_length;
  386.           }
  387. ***************
  388. *** 992,1000 ****
  389.         /* Completes the OCCURS structure.  */
  390.   
  391.         occurs_cursor->key = possible_key;
  392. !       occurs_cursor->left = context_start - possible_key.start;
  393. !       occurs_cursor->right = context_end - possible_key.start;
  394.   
  395.         number_of_occurs[0]++;
  396.       }
  397.       }
  398. --- 1045,1056 ----
  399.         /* Completes the OCCURS structure.  */
  400.   
  401.         occurs_cursor->key = possible_key;
  402. !       occurs_cursor->left = I_PDIFF (context_start, possible_key.start);
  403. !       occurs_cursor->right = I_PDIFF (context_end, possible_key.start);
  404.   
  405. + #ifdef MSDOS
  406. +       assert (number_of_occurs[0] < 32767);
  407. + #endif /* MSDOS */
  408.         number_of_occurs[0]++;
  409.       }
  410.       }
  411. ***************
  412. *** 1030,1036 ****
  413.        BLOCK field;
  414.   #endif
  415.   {
  416. !   char *cursor;            /* Cursor in field to print */
  417.     int character;        /* Current character */
  418.     int base;            /* Base character, without diacritic */
  419.     int diacritic;        /* Diacritic code for the character */
  420. --- 1086,1092 ----
  421.        BLOCK field;
  422.   #endif
  423.   {
  424. !   char HUGE *cursor;        /* Cursor in field to print */
  425.     int character;        /* Current character */
  426.     int base;            /* Base character, without diacritic */
  427.     int diacritic;        /* Diacritic code for the character */
  428. ***************
  429. *** 1356,1365 ****
  430.   {
  431.     int tail_max_width;        /* allowable width of tail field */
  432.     int head_max_width;        /* allowable width of head field */
  433. !   char *cursor;            /* running cursor in source text */
  434. !   char *left_context_start;    /* start of left context */
  435. !   char *right_context_end;    /* end of right context */
  436. !   char *left_field_start;    /* conservative start for `head'/`before' */
  437.     int file_index;        /* index in text input file arrays */
  438.     STRING *file_name;        /* file name for reference */
  439.     int line_ordinal;        /* line ordinal for reference */
  440. --- 1412,1421 ----
  441.   {
  442.     int tail_max_width;        /* allowable width of tail field */
  443.     int head_max_width;        /* allowable width of head field */
  444. !   char HUGE *cursor;        /* running cursor in source text */
  445. !   char HUGE *left_context_start;/* start of left context */
  446. !   char HUGE *right_context_end;    /* end of right context */
  447. !   char HUGE *left_field_start;    /* conservative start for `head'/`before' */
  448.     int file_index;        /* index in text input file arrays */
  449.     STRING *file_name;        /* file name for reference */
  450.     int line_ordinal;        /* line ordinal for reference */
  451. ***************
  452. *** 1442,1448 ****
  453.        has no suffixed spaces.  */
  454.   
  455.     tail_max_width
  456. !     = before_max_width - (before.end - before.start) - gap_size;
  457.   
  458.     if (tail_max_width > 0)
  459.       {
  460. --- 1498,1504 ----
  461.        has no suffixed spaces.  */
  462.   
  463.     tail_max_width
  464. !     = before_max_width - I_PDIFF (before.end, before.start) - gap_size;
  465.   
  466.     if (tail_max_width > 0)
  467.       {
  468. ***************
  469. *** 1488,1494 ****
  470.        contain only part of a word, and has no suffixed spaces.  */
  471.   
  472.     head_max_width
  473. !     = keyafter_max_width - (keyafter.end - keyafter.start) - gap_size;
  474.   
  475.     if (head_max_width > 0)
  476.       {
  477. --- 1544,1550 ----
  478.        contain only part of a word, and has no suffixed spaces.  */
  479.   
  480.     head_max_width
  481. !     = keyafter_max_width - I_PDIFF (keyafter.end, keyafter.start) - gap_size;
  482.   
  483.     if (head_max_width > 0)
  484.       {
  485. ***************
  486. *** 1624,1630 ****
  487.   {
  488.     BLOCK key;            /* key field, isolated */
  489.     BLOCK after;            /* after field, isolated */
  490. !   char *cursor;            /* running cursor in source text */
  491.   
  492.     printf ("\\xx ");
  493.     printf ("{");
  494. --- 1680,1686 ----
  495.   {
  496.     BLOCK key;            /* key field, isolated */
  497.     BLOCK after;            /* after field, isolated */
  498. !   char HUGE *cursor;        /* running cursor in source text */
  499.   
  500.     printf ("\\xx ");
  501.     printf ("{");
  502. ***************
  503. *** 1675,1681 ****
  504.       putchar (':');
  505.       print_spaces (reference_max_width
  506.                 + gap_size
  507. !               - (reference.end - reference.start)
  508.                 - 1);
  509.         }
  510.       else
  511. --- 1731,1737 ----
  512.       putchar (':');
  513.       print_spaces (reference_max_width
  514.                 + gap_size
  515. !               - I_PDIFF (reference.end, reference.start)
  516.                 - 1);
  517.         }
  518.       else
  519. ***************
  520. *** 1686,1692 ****
  521.       print_field (reference);
  522.       print_spaces (reference_max_width
  523.               + gap_size
  524. !             - (reference.end - reference.start));
  525.         }
  526.   
  527.     if (tail.start < tail.end)
  528. --- 1742,1748 ----
  529.       print_field (reference);
  530.       print_spaces (reference_max_width
  531.               + gap_size
  532. !             - I_PDIFF (reference.end, reference.start));
  533.         }
  534.   
  535.     if (tail.start < tail.end)
  536. ***************
  537. *** 1698,1711 ****
  538.       printf ("%s", truncation_string);
  539.   
  540.         print_spaces (half_line_width - gap_size
  541. !             - (before.end - before.start)
  542.               - (before_truncation ? truncation_string_length : 0)
  543. !             - (tail.end - tail.start)
  544.               - (tail_truncation ? truncation_string_length : 0));
  545.       }
  546.     else
  547.       print_spaces (half_line_width - gap_size
  548. !           - (before.end - before.start)
  549.             - (before_truncation ? truncation_string_length : 0));
  550.   
  551.     /* Output the `before' field.  */
  552. --- 1754,1767 ----
  553.       printf ("%s", truncation_string);
  554.   
  555.         print_spaces (half_line_width - gap_size
  556. !             - I_PDIFF (before.end, before.start)
  557.               - (before_truncation ? truncation_string_length : 0)
  558. !             - I_PDIFF (tail.end, tail.start)
  559.               - (tail_truncation ? truncation_string_length : 0));
  560.       }
  561.     else
  562.       print_spaces (half_line_width - gap_size
  563. !           - I_PDIFF (before.end, before.start)
  564.             - (before_truncation ? truncation_string_length : 0));
  565.   
  566.     /* Output the `before' field.  */
  567. ***************
  568. *** 1727,1735 ****
  569.         /* Output the `head' field.  */
  570.   
  571.         print_spaces (half_line_width
  572. !             - (keyafter.end - keyafter.start)
  573.               - (keyafter_truncation ? truncation_string_length : 0)
  574. !             - (head.end - head.start)
  575.               - (head_truncation ? truncation_string_length : 0));
  576.         if (head_truncation)
  577.       printf ("%s", truncation_string);
  578. --- 1783,1791 ----
  579.         /* Output the `head' field.  */
  580.   
  581.         print_spaces (half_line_width
  582. !             - I_PDIFF (keyafter.end, keyafter.start)
  583.               - (keyafter_truncation ? truncation_string_length : 0)
  584. !             - I_PDIFF (head.end, head.start)
  585.               - (head_truncation ? truncation_string_length : 0));
  586.         if (head_truncation)
  587.       printf ("%s", truncation_string);
  588. ***************
  589. *** 1739,1745 ****
  590.   
  591.       if ((auto_reference || input_reference) && right_reference)
  592.         print_spaces (half_line_width
  593. !             - (keyafter.end - keyafter.start)
  594.               - (keyafter_truncation ? truncation_string_length : 0));
  595.   
  596.     if ((auto_reference || input_reference) && right_reference)
  597. --- 1795,1801 ----
  598.   
  599.       if ((auto_reference || input_reference) && right_reference)
  600.         print_spaces (half_line_width
  601. !             - I_PDIFF (keyafter.end, keyafter.start)
  602.               - (keyafter_truncation ? truncation_string_length : 0));
  603.   
  604.     if ((auto_reference || input_reference) && right_reference)
  605. *** e:\tmp/RCSt1006052    Sat Sep 22 00:28:28 1990
  606. --- xmalloc.c    Fri Sep 21 23:39:02 1990
  607. ***************
  608. *** 2,8 ****
  609.      Copyright (C) 1990 Free Software Foundation, Inc.
  610.      Francois Pinard <pinard@iro.umontreal.ca>, September 1989.
  611.   
  612. !    $Id: xmalloc.c 0.1 90/08/11 09:18:57 tho Exp $
  613.   */
  614.   
  615.   #include <stdio.h>
  616. --- 2,8 ----
  617.      Copyright (C) 1990 Free Software Foundation, Inc.
  618.      Francois Pinard <pinard@iro.umontreal.ca>, September 1989.
  619.   
  620. !    $Id: xmalloc.c 0.1.0.1 90/08/12 00:53:35 tho Exp $
  621.   */
  622.   
  623.   #include <stdio.h>
  624. ***************
  625. *** 66,68 ****
  626. --- 66,163 ----
  627.       }
  628.     return result_pointer;
  629.   }
  630. + #ifdef MSDOS
  631. + #include <stdlib.h>
  632. + #include <string.h>
  633. + #include <io.h>
  634. + #if defined (_MSC_VER) && (_MSC_VER >= 600)
  635. + #define HUGE _huge
  636. + #else
  637. + #define HUGE huge
  638. + #endif
  639. + /* malloc a block of memory, with fatal error message if we can't do it. */
  640. + #include <malloc.h>
  641. + #include <dos.h>
  642. + void HUGE *
  643. + xhalloc (long size)
  644. + {
  645. +   void HUGE *value = (void HUGE *) halloc (size, (size_t)1 );
  646. +   if (!value)
  647. +     {
  648. +       fprintf (stderr, "Out of memory!\n");
  649. +       abort ();
  650. +     }
  651. +   return value;
  652. + }
  653. + /* Here we do a HUGE "realloc" by allocating a new block and
  654. +    moving the old block afterwards.  This is *slow*, but should
  655. +    be reliable.  */
  656. + void HUGE *
  657. + xhrealloc (void HUGE *ptr, long new_size, long old_size)
  658. + {
  659. +   void HUGE *value = (void HUGE *) halloc (new_size, (size_t)1 );
  660. +   if (!value)
  661. +     {
  662. +       fprintf (stderr, "Out of memory!\n");
  663. +       abort ();
  664. +     }
  665. +   else
  666. +     {
  667. +       char HUGE *dest = value;
  668. +       char HUGE *src = ptr;
  669. +       while (old_size > 0L)
  670. +     {
  671. +       unsigned int bytes = (unsigned int) min (0x8000L, old_size);
  672. +       memcpy (dest, src, bytes);
  673. +       old_size -= (long) bytes;
  674. +       dest += (long) bytes;
  675. +       src += (long) bytes;
  676. +     }
  677. +     }
  678. +   hfree (ptr);
  679. +   return value;
  680. + }
  681. + long
  682. + hread (int fd, void HUGE *buffer, long bytes)
  683. + {
  684. +   long bytes_read = 0L;
  685. +   while (1)
  686. +     {
  687. +       int n = read (fd, buffer, (unsigned int) min (0x4000L, bytes));
  688. +       if (n > 0)
  689. +     {
  690. +       bytes_read += (long) n;
  691. +       bytes -= (long) n;
  692. +       /* we can't say buffer += n here, because we have to make
  693. +          sure that the offset of BUFFER doesn't overflow during
  694. +          the read() system call.  Therefore we add what we read
  695. +          to the segment of BUFFER.  */
  696. +       FP_SEG(buffer) += (n >> 4);
  697. +       FP_OFF(buffer) += (n & 0x0F);
  698. +     }
  699. +       else if (n == 0)
  700. +     return bytes_read;    /* done */
  701. +       else
  702. +     {
  703. +       perror ("Out of memory");
  704. +       abort ();
  705. +     }
  706. +     }
  707. + }
  708. + #endif /* MSDOS */
  709. *** e:\tmp/RCSt1006052    Sat Sep 22 00:28:30 1990
  710. --- hregex.c    Sat Sep 22 00:25:50 1990
  711. ***************
  712. *** 0 ****
  713. --- 1,119 ----
  714. + /*  hregex.c - use re_search () and re_match () on huge buffers
  715. +     Copyright (C) 1990 Free Software Foundation, Inc.
  716. +     Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  717. +     Thorsten Ohl <td12@ddagsi3.bitnet>, 1990.
  718. +     This program is free software; you can redistribute it and/or modify
  719. +     it under the terms of the GNU General Public License as published by
  720. +     the Free Software Foundation; either version 1, or (at your option)
  721. +     any later version.
  722. +     This program is distributed in the hope that it will be useful,
  723. +     but WITHOUT ANY WARRANTY; without even the implied warranty of
  724. +     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  725. +     GNU General Public License for more details.
  726. +     You should have received a copy of the GNU General Public License
  727. +     along with this program; if not, write to the Free Software
  728. +     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  729. +     $Header: e:/gnu/gptx/RCS/hregex.c 0.1.0.1 90/09/22 00:23:03 tho Exp $
  730. +  */
  731. + #if defined (_MSC_VER) && (_MSC_VER >= 600)
  732. + #define HUGE _huge
  733. + #else
  734. + #define HUGE huge
  735. + #endif
  736. + #define LONG long
  737. + #define IMAX 0x7fffL
  738. + #include <stdio.h>
  739. + #include <stdlib.h>
  740. + #include <dos.h>
  741. + #include <regex.h>
  742. + extern char *program_name;
  743. + /* Normalize a "huge" ix86 pointer by moving part of the offset into
  744. +    the segment.  (We do it only if the offset is sufficiently large.)
  745. +    Note:  Don't do this with pointers to memory blocks owned by malloc,
  746. +       as a subsequent free () or realloc () will fail!  */
  747. + #define FP_NORM(fp)                \
  748. +   if (FP_OFF (fp) & 0xf000)            \
  749. +     {                        \
  750. +       FP_SEG (fp) += (FP_OFF(fp) >> 4);        \
  751. +       FP_OFF (fp) &= 0x0f;            \
  752. +     }
  753. + /* This is a kludge for using the GNU regex library on huge (>32k)
  754. +    buffers.  This "implementation" assumes that a match will be found in
  755. +    the first 32k and will simply abort with a diagnostic message if not.
  756. +    While this is certainly not a clean solution, it is appropriate in
  757. +    cases where a failure is extremely unlikely, since it avoids the
  758. +    enormous computational overhead of using huge pointers for regexp
  759. +    matching, which is furthermore very error-prone.
  760. +    Note: once these functions are real implementation, they should return
  761. +    a long, but for the moment ints are more convenient.  */
  762. + int
  763. + re_hsearch (struct re_pattern_buffer *pbufp, char HUGE *string, long size,
  764. +         long startpos, long range, struct re_registers *regs)
  765. + {
  766. +   int match;
  767. +   int isize = (int) min (size, IMAX);
  768. +   int istartpos = (int) min (startpos, IMAX);
  769. +   int irange = (int) min (range, IMAX);
  770. +   FP_NORM (string);
  771. +   match = re_search (pbufp, string, isize, istartpos, irange, regs);
  772. +   if (match == -1 && size > IMAX)
  773. +     {
  774. +       fprintf (stderr, "%s: re_search() failed in truncated buffer\n"
  775. +                "        buffer: `%.30s...'\n"
  776. +                "        length: %ld\n",
  777. +                program_name, string, size);
  778. +       abort ();
  779. +     }
  780. +   return match;
  781. + }
  782. + int
  783. + re_hmatch (struct re_pattern_buffer *pbufp, char HUGE *string, long size,
  784. +        long pos, struct re_registers *regs)
  785. + {
  786. +   int match;
  787. +   int isize = (int) min (size, IMAX);
  788. +   int ipos = (int) min (pos, IMAX);
  789. +   FP_NORM (string);
  790. +   match = re_match (pbufp, string, isize, ipos, regs);
  791. +   if (match == -1 && size > IMAX)
  792. +     {
  793. +       fprintf (stderr, "%s: re_match() failed against truncated buffer\n"
  794. +                "        buffer: `%.30s...'\n"
  795. +                "        length: %ld\n",
  796. +                program_name, string, size);
  797. +       abort ();
  798. +     }
  799. +   return match;
  800. + }
  801. + /*
  802. +    Local Variables:
  803. +    mode:C
  804. +    ChangeLog:ChangeLog
  805. +    compile-command:make
  806. +    End:
  807. +  */
  808. *** e:\tmp/RCSt1006052    Sat Sep 22 00:28:34 1990
  809. --- gptx.h    Sat Sep 22 00:23:24 1990
  810. ***************
  811. *** 2,8 ****
  812.      Copyright (C) 1990 Free Software Foundation, Inc.
  813.      Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  814.   
  815. !    $Id: gptx.h 0.1 90/08/11 09:18:59 tho Exp $
  816.   */
  817.   
  818.   
  819. --- 2,8 ----
  820.      Copyright (C) 1990 Free Software Foundation, Inc.
  821.      Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  822.   
  823. !    $Id: gptx.h 0.1.0.4 90/09/22 00:22:40 tho Exp $
  824.   */
  825.   
  826.   
  827. ***************
  828. *** 38,43 ****
  829. --- 38,53 ----
  830.   
  831.   #ifndef STDLIB_PROTO_ALREADY
  832.   
  833. + #include <assert.h>
  834. + #ifdef MSDOS
  835. + #include <stdlib.h>
  836. + #include <io.h>
  837. + int getopt (int, char **, const char *);
  838. + #else /* not MSDOS */
  839.   #ifdef BUFSIZ            /* stdio dependant -- how ugly! */
  840.   int        _filbuf PROTO ((FILE *));
  841.   int        _flsbuf PROTO ((unsigned char, FILE *));
  842. ***************
  843. *** 54,59 ****
  844. --- 64,71 ----
  845.   void        qsort PROTO ((void *, int, int, int ()));
  846.   int        read PROTO ((int, void *, unsigned));
  847.   
  848. + #endif /* not MSDOS */
  849.   #endif /* not STDLIB_PROTO_ALREADY */
  850.   
  851.   
  852. ***************
  853. *** 66,68 ****
  854. --- 78,143 ----
  855.   
  856.   void        print_copyright PROTO ((void));
  857.   void        print_version PROTO ((void));
  858. + /* Teach MS-DOS to handel long files */
  859. + #ifdef MSDOS
  860. + #if defined (_MSC_VER) && (_MSC_VER >= 600)
  861. + #define HUGE _huge
  862. + #else
  863. + #define HUGE huge
  864. + #endif
  865. + #define LONG long
  866. + void HUGE *xhalloc (long size);
  867. + void HUGE *xhrealloc (void HUGE *ptr, long new_size, long old_size);
  868. + long hread (int fd, void HUGE *buffer, long bytes);
  869. + #if defined (M_I86CM) || defined (M_I86LM)
  870. + #define L_PDIFF(ptr1,ptr2) \
  871. +   ((long)((char HUGE *)(ptr1) - (char HUGE *)(ptr2)))
  872. + #define I_PDIFF(ptr1,ptr2) \
  873. +   (assert ((long)((char HUGE *)(ptr1) - (char HUGE *)(ptr2)) < (1L << 15)), \
  874. +    ((int)(long)((char HUGE *)(ptr1) - (char HUGE *)(ptr2))))
  875. + extern int re_hsearch (struct re_pattern_buffer *pbufp, char HUGE *string,
  876. +                long size, long startpos, long range,
  877. +                struct re_registers *regs);
  878. + extern int re_hmatch (struct re_pattern_buffer *pbufp, char HUGE *string,
  879. +               long size, long pos, struct re_registers *regs);
  880. + /* We must mask re_search () and re_match () *after* the prototypes
  881. +    in regex.h!  */
  882. + #include <regex.h>
  883. + #define re_search re_hsearch
  884. + #define re_match re_hmatch
  885. + #define ZERO 0L
  886. + #else /* not M_I86CM and not M_I86LM */
  887. + #define L_PDIFF(ptr1,ptr2)    ((ptr1) - (ptr2))
  888. + #define I_PDIFF(ptr1,ptr2)    ((ptr1) - (ptr2))
  889. + #define ZERO 0
  890. + #endif /* not M_I86CM and not M_I86LM */
  891. + #else /* not MSDOS */
  892. + #define HUGE
  893. + #define LONG int
  894. + #define L_PDIFF(ptr1,ptr2)    ((ptr1) - (ptr2))
  895. + #define I_PDIFF(ptr1,ptr2)    ((ptr1) - (ptr2))
  896. + #define ZERO 0
  897. + #endif /* not MSDOS */
  898.