Changeset 1563


Ignore:
Timestamp:
Oct 10, 2004, 4:51:49 AM (21 years ago)
Author:
bird
Message:

Convert imports.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/src/emxomf/emxomf.c

    • Property cvs2svn:cvs-rev changed from 1.39 to 1.40
    r1562 r1563  
    917917
    918918
    919 /* Put the null-terminated string pszName into the current OMF record. 
     919/* Put the null-terminated string pszName into the current OMF record.
    920920   In the OMF record, the string is preceded by a length byte.  The
    921921   string length must not exceed 255; if it is too long, display a
     
    929929    if (cch > 255)
    930930    {
    931         /* Hash the symbol to help making it unique. 
     931        /* Hash the symbol to help making it unique.
    932932         * NOTE that the hash algorithm is not fixed, so is the !_%X marker too.
    933933         *      the weakld is parsing it!
     
    13031303            int cch = strlen(pszOrgName);
    13041304            int cch2;
    1305            
     1305
    13061306            /* Init the markers if not done already. */
    13071307            if (!weak_marker_simple[0])
     
    13301330                gettimeofday(&tv, NULL);
    13311331                memcpy(&weak_marker_ts[0], "$w$", 4);
    1332                 ltoa(tv.tv_sec, &weak_marker_ts[3], 36); 
     1332                ltoa(tv.tv_sec, &weak_marker_ts[3], 36);
    13331333                cch2 = 3 + strlen(&weak_marker_ts[3]);
    13341334                ltoa(tv.tv_usec, &weak_marker_ts[cch2], 36);
     
    13371337                if (tv_prev.tv_usec == tv.tv_usec && tv_prev.tv_sec == tv.tv_sec)
    13381338                {
    1339                     if (!iOpaque)   
     1339                    if (!iOpaque)
    13401340                    {
    13411341                        unsigned short seed[3];
     
    13631363            else if (cch + 24 < 255)
    13641364                snprintf(pachName, cchName, "%s%.16s", pszOrgName, weak_marker_ts);
    1365             else 
     1365            else
    13661366            {   /* too long. */
    13671367                int         cch3 = weak_marker_ts_size > 24 ? 24 : weak_marker_ts_size;
    13681368                char        szHash[16];
    13691369                const char *psz;
    1370                 unsigned    uHash;   
     1370                unsigned    uHash;
    13711371                for (psz = pszOrgName, uHash = 5381; *psz; psz++)   /* hash alg: original djb2. */
    13721372                    uHash += (uHash << 5) + *psz;
     
    27172717}
    27182718
     2719/* Convert import entries. */
     2720static void write_import_i2 (void)
     2721{
     2722  int i;
     2723  const char *name1, *name2;
     2724
     2725  /* Search the symbol table for N_IMP1 and N_IMP2 symbols.  These are
     2726     unique to import modules. */
     2727
     2728  name1 = NULL; name2 = NULL;
     2729  for (i = 0; i < sym_count; ++i)
     2730    {
     2731      switch (sym_ptr[i].n_type)
     2732        {
     2733        case N_IMP1|N_EXT:
     2734          name1 = str_ptr + sym_ptr[i].n_un.n_strx;
     2735          break;
     2736        case N_IMP2|N_EXT:
     2737          name2 = str_ptr + sym_ptr[i].n_un.n_strx;
     2738          break;
     2739        }
     2740      if (name1 && name2)
     2741        {
     2742          int len1, mod_len;
     2743          long ord;
     2744          const char *proc_name, *p;
     2745          char mod[256], *q;
     2746
     2747          /* Parse the special symbols into module name and ordinal number.
     2748             name2 should look like
     2749
     2750               SYMBOL=MODULE.ORDINAL
     2751
     2752             where SYMBOL is name1, MODULE is the module name and ORDINAL is
     2753             the ordinal number. */
     2754
     2755          len1 = strlen (name1);
     2756          if (memcmp (name1, name2, len1) != 0)
     2757            error ("Invalid import record: names don't match");
     2758          name2 += len1;
     2759          if (*name2 != '=')
     2760            error ("Invalid import record: missing `='");
     2761          ++name2;
     2762          p = strchr (name2, '.');
     2763          if (p == NULL)
     2764            error ("Invalid import record: missing `.'");
     2765          mod_len = p - name2;
     2766          memcpy (mod, name2, mod_len);
     2767          mod[mod_len] = '\0';
     2768          proc_name = NULL;
     2769          errno = 0;
     2770          ord = strtol (p + 1, &q, 10);
     2771          if (q != p + 1 && *q == 0 && errno == 0)
     2772            {
     2773              if (ord < 1 || ord > 65535)
     2774                error ("Invalid import record: invalid ordinal");
     2775            }
     2776          else
     2777            {
     2778              ord = -1;
     2779              proc_name = p + 1;
     2780              if (*proc_name == 0)
     2781                error ("Invalid import record: invalid name");
     2782            }
     2783
     2784          /* Write the import definition record. */
     2785
     2786          init_rec (COMENT);
     2787          put_8 (0x00);
     2788          put_8 (IMPDEF_CLASS);
     2789          put_8 (IMPDEF_SUBTYPE);
     2790          put_8 (proc_name == NULL ? 0x01 : 0x00); /* Import by ordinal or by name */
     2791          put_str (name1);                         /* Underscore already removed above */
     2792          put_str (mod);
     2793          if (proc_name == NULL)
     2794            put_16 (ord);
     2795          else if (strcmp (proc_name, name1) == 0)
     2796            put_8 (0);
     2797          else
     2798            put_str (proc_name);
     2799          write_rec ();
     2800
     2801          name1 = NULL;
     2802          name2 = NULL;
     2803        }
     2804    }
     2805}
     2806
    27192807
    27202808/* If the input file is an import module (method (I1) as created by
     
    36293717  write_set_pub ();
    36303718  write_alias ();
     3719  write_import_i2 ();
    36313720
    36323721  /* Write link pass separator. */
Note: See TracChangeset for help on using the changeset viewer.