~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/tools/winedump/misc.c

Version: ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  *  Misc functions
  3  *
  4  *  Copyright 2000 Jon Griffiths
  5  *
  6  * This library is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU Lesser General Public
  8  * License as published by the Free Software Foundation; either
  9  * version 2.1 of the License, or (at your option) any later version.
 10  *
 11  * This library is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  * Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public
 17  * License along with this library; if not, write to the Free Software
 18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include "config.h"
 22 #include "wine/port.h"
 23 
 24 #include "winedump.h"
 25 
 26 
 27 /*******************************************************************
 28  *         str_create
 29  *
 30  * Create a single string from many substrings
 31  */
 32 char *str_create(size_t num_str, ...)
 33 {
 34   va_list args;
 35   size_t len = 1, i = 0;
 36   char *tmp, *t;
 37 
 38   va_start (args, num_str);
 39   for (i = 0; i < num_str; i++)
 40     if ((t = va_arg(args, char *)))
 41       len += strlen (t);
 42   va_end (args);
 43 
 44   if (!(tmp = malloc (len)))
 45     fatal ("Out of memory");
 46 
 47   tmp[0] = '\0';
 48 
 49   va_start (args, num_str);
 50   for (i = 0; i < num_str; i++)
 51     if ((t = va_arg(args, char *)))
 52       strcat (tmp, t);
 53   va_end (args);
 54   return tmp;
 55 }
 56 
 57 
 58 /*******************************************************************
 59  *         str_create_num
 60  *
 61  * Create a single string from many substrings, terminating in a number
 62  */
 63 char *str_create_num(size_t num_str, int num, ...)
 64 {
 65   va_list args;
 66   size_t len = 8, i = 0;
 67   char *tmp, *t;
 68 
 69   va_start (args, num);
 70   for (i = 0; i < num_str; i++)
 71     if ((t = va_arg(args, char *)))
 72       len += strlen (t);
 73   va_end (args);
 74 
 75   if (!(tmp = malloc (len)))
 76     fatal ("Out of memory");
 77 
 78   tmp[0] = '\0';
 79 
 80   va_start (args, num);
 81   for (i = 0; i < num_str; i++)
 82     if ((t = va_arg(args, char *)))
 83       strcat (tmp, t);
 84   va_end (args);
 85   sprintf (tmp + len - 8, "%d", num);
 86   return tmp;
 87 }
 88 
 89 
 90 /*******************************************************************
 91  *         str_substring
 92  *
 93  * Create a new substring from a string
 94  */
 95 char *str_substring(const char *start, const char *end)
 96 {
 97   char *newstr;
 98 
 99   assert (start && end && end > start);
100 
101   if (!(newstr = malloc (end - start + 1)))
102     fatal ("Out of memory");
103 
104   memcpy (newstr, start, end - start);
105   newstr [end - start] = '\0';
106 
107   return newstr;
108 }
109 
110 
111 /*******************************************************************
112  *         str_replace
113  *
114  * Swap two strings in another string, in place
115  * Modified PD code from 'snippets'
116  */
117 char *str_replace (char *str, const char *oldstr, const char *newstr)
118 {
119   int oldlen, newlen;
120   char *p, *q;
121 
122   if (!(p = strstr(str, oldstr)))
123     return p;
124   oldlen = strlen (oldstr);
125   newlen = strlen (newstr);
126   memmove (q = p + newlen, p + oldlen, strlen (p + oldlen) + 1);
127   memcpy (p, newstr, newlen);
128   return q;
129 }
130 
131 
132 /*******************************************************************
133  *         str_match
134  *
135  * Locate one string in another, ignoring spaces
136  */
137 const char *str_match (const char *str, const char *match, int *found)
138 {
139   assert(str && match && found);
140 
141   while (*str == ' ') str++;
142   if (!strncmp (str, match, strlen (match)))
143   {
144     *found = 1;
145     str += strlen (match);
146     while (*str == ' ') str++;
147   }
148   else
149     *found = 0;
150   return str;
151 }
152 
153 
154 /*******************************************************************
155  *         str_find_set
156  *
157  * Locate the first occurrence of a set of characters in a string
158  */
159 const char *str_find_set (const char *str, const char *findset)
160 {
161   assert(str && findset);
162 
163   while (*str)
164   {
165     const char *p = findset;
166     while (*p)
167       if (*p++ == *str)
168         return str;
169     str++;
170   }
171   return NULL;
172 }
173 
174 
175 /*******************************************************************
176  *         str_toupper
177  *
178  * Uppercase a string
179  */
180 char *str_toupper (char *str)
181 {
182   char *save = str;
183   while (*str)
184   {
185     *str = toupper (*str);
186     str++;
187   }
188   return save;
189 }
190 
191 
192 /*******************************************************************
193  *         open_file
194  *
195  * Open a file returning only on success
196  */
197 FILE *open_file (const char *name, const char *ext, const char *mode)
198 {
199   char  fname[128];
200   FILE *fp;
201 
202   if (((unsigned)snprintf (fname, sizeof (fname), "%s%s%s",
203                  *mode == 'w' ? "./" : "", name, ext) > sizeof (fname)))
204     fatal ("File name too long");
205 
206   if (VERBOSE)
207     printf ("Open file %s\n", fname);
208 
209   fp = fopen (fname, mode);
210   if (!fp)
211     fatal ("Can't open file");
212   return fp;
213 }
214 
215 
216 /*******************************************************************
217  *         fatal
218  *
219  * Fatal error handling
220  */
221 void  fatal (const char *message)
222 {
223   if (errno)
224     perror (message);
225   else
226     puts (message);
227   exit(1);
228 }
229 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.