home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / layout / bullet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.4 KB  |  213 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "xp.h"
  20. #include "layout.h"
  21.  
  22. #ifdef PROFILE
  23. #pragma profile on
  24. #endif
  25.  
  26. PA_Block
  27. lo_ValueToAlpha(int32 value, Bool large, intn *len_ptr)
  28. {
  29.     int i;
  30.     char str[20];
  31.     char str2[22];
  32.     intn pos, cnt;
  33.     PA_Block buff;
  34.     char *bptr;
  35.     char base;
  36.  
  37.     *len_ptr = 0;
  38.  
  39.     if (large != FALSE)
  40.     {
  41.         base = 'A';
  42.     }
  43.     else
  44.     {
  45.         base = 'a';
  46.     }
  47.  
  48.     for (i=0; i<20; i++)
  49.     {
  50.         str[i] = (char)0;
  51.     }
  52.  
  53.     while (value > 26)
  54.     {
  55.         pos = 1;
  56.         str[pos] = (char)((int)str[pos] + 1);
  57.         cnt = (int)str[pos];
  58.         while ((cnt > 26)&&(pos < 19))
  59.         {
  60.             str[pos] = (char)0;
  61.             pos++;
  62.             str[pos] = (char)((int)str[pos] + 1);
  63.             cnt = (int)str[pos];
  64.         }
  65.         if ((pos == 20)&&(cnt > 26))
  66.         {
  67.             str[pos] = (char)0;
  68.         }
  69.         value -= 26;
  70.     }
  71.     str[0] = (char)value;
  72.  
  73.     pos = 0;
  74.     while ((int)str[pos] != 0)
  75.     {
  76.         pos++;
  77.     }
  78.  
  79.     if (pos == 0)
  80.     {
  81.         XP_STRCPY(str2, " .");
  82.     }
  83.     else
  84.     {
  85.         cnt = 0;
  86.         for (i=pos; i>0; i--)
  87.         {
  88.             str2[cnt] = (char)(base + (int)str[i - 1] - 1);
  89.             cnt++;
  90.         }
  91.         str2[cnt] = '.';
  92.         str2[cnt + 1] = '\0';
  93.     }
  94.  
  95.     *len_ptr = XP_STRLEN(str2);
  96.  
  97.     buff = PA_ALLOC(*len_ptr + 1);
  98.     if (buff != NULL)
  99.     {
  100.         PA_LOCK(bptr, char *, buff);
  101.         XP_STRCPY(bptr, str2);
  102.         PA_UNLOCK(buff);
  103.     }
  104.  
  105.     return(buff);
  106. }
  107.  
  108.  
  109. static char Fives[2][5] = {"vld ", "VLD "};
  110. static char Ones[2][5] = {"ixcm", "IXCM"};
  111.  
  112. PA_Block
  113. lo_ValueToRoman(int32 value, Bool large, intn *len_ptr)
  114. {
  115.     int i, j;
  116.     int indx[4];
  117.     char str[4][6];
  118.     char *fives;
  119.     char *ones;
  120.     char str2[22];
  121.     char *ptr;
  122.     PA_Block buff;
  123.     char *bptr;
  124.  
  125.     *len_ptr = 0;
  126.  
  127.     if (large != FALSE)
  128.     {
  129.         fives = Fives[1];
  130.         ones = Ones[1];
  131.     }
  132.     else
  133.     {
  134.         fives = Fives[0];
  135.         ones = Ones[0];
  136.     }
  137.  
  138.     if (value >= 4000)
  139.     {
  140.         value = value % 3999;
  141.         value++;
  142.     }
  143.  
  144.     for (i=0; i<4; i++)
  145.     {
  146.         indx[i] = (int) value % 10;
  147.         value  = value / 10;
  148.     }
  149.  
  150.     for (i=0; i<4; i++)
  151.     {
  152.         if (indx[i] >= 5)
  153.         {
  154.             indx[i] -= 5;
  155.             str[i][0] = fives[i];
  156.         }
  157.         else
  158.         {
  159.             str[i][0] = ' ';
  160.         }
  161.  
  162.         if (indx[i] == 4)
  163.         {
  164.             if (str[i][0] == ' ')
  165.             {
  166.                 str[i][1] = fives[i];
  167.             }
  168.             else
  169.             {
  170.                 str[i][1] = ones[i + 1];
  171.             }
  172.             str[i][0] = ones[i];
  173.             str[i][2] = '\0';
  174.         }
  175.         else
  176.         {
  177.             for (j=0; j<indx[i]; j++)
  178.             {
  179.                 str[i][j + 1] = ones[i];
  180.             }
  181.             str[i][indx[i] + 1] = '\0';
  182.         }
  183.     }
  184.  
  185.     XP_STRCPY(str2, "");
  186.     for (i=3; i>=0; i--)
  187.     {
  188.         ptr = str[i];
  189.         if (*ptr == ' ')
  190.         {
  191.             ptr++;
  192.         }
  193.         XP_STRCAT(str2, ptr);
  194.     }
  195.     XP_STRCAT(str2, ".");
  196.  
  197.     *len_ptr = XP_STRLEN(str2);
  198.  
  199.     buff = PA_ALLOC(*len_ptr + 1);
  200.     if (buff != NULL)
  201.     {
  202.         PA_LOCK(bptr, char *, buff);
  203.         XP_STRCPY(bptr, str2);
  204.         PA_UNLOCK(buff);
  205.     }
  206.  
  207.     return(buff);
  208. }
  209.  
  210. #ifdef PROFILE
  211. #pragma profile off
  212. #endif
  213.