getargv.c.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. getargv.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='FragmentHeader.c.html' title=' FragmentHeader.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='gethwaddr.c.html' title=' gethwaddr.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2012 Qualcomm Atheros Inc.
  24. *
  25. * Permission to use, copy, modify, and/or distribute this software
  26. * for any purpose with or without fee is hereby granted, provided
  27. * that the above copyright notice and this permission notice appear
  28. * in all copies.
  29. *
  30. * THE SOFTWARE IS PROVIDED &quot;AS IS&quot; AND THE AUTHOR DISCLAIMS ALL
  31. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  32. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  33. * THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
  34. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  35. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  36. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  37. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  38. *
  39. *--------------------------------------------------------------------*/
  40. /*====================================================================*
  41. *
  42. * signed getargv (signed argc, char const * argv [])
  43. *
  44. * symbol.h
  45. *
  46. * read one line from stdin; fill argv [] with fields from that
  47. * line; return the number of fields found; ignore blank lines
  48. * and script style comment lines; this implementation inserts
  49. * a program name at argv [0] to emulate a true argv [];
  50. *
  51. *--------------------------------------------------------------------*/
  52. #ifndef GETARGV_SOURCE
  53. #define GETARGV_SOURCE
  54. #include &lt;stdio.h&gt;
  55. #include &lt;ctype.h&gt;
  56. #include &lt;memory.h&gt;
  57. #include &quot;../tools/symbol.h&quot;
  58. #include &quot;../tools/chars.h&quot;
  59. signed getargv (signed argc, char const * argv [])
  60. {
  61. extern char const * program_name;
  62. static char string [1024];
  63. char const ** argp = argv;
  64. char * sp = string;
  65. signed c = getc (stdin);
  66. memset (string, 0, sizeof (string));
  67. memset ((char **)(argv), 0, argc * sizeof (char const *));
  68. while (nobreak (c))
  69. {
  70. if (isspace (c))
  71. {
  72. do
  73. {
  74. c = getc (stdin);
  75. }
  76. while (isspace (c));
  77. }
  78. if (c == '#')
  79. {
  80. do
  81. {
  82. c = getc (stdin);
  83. }
  84. while (nobreak (c));
  85. c = getc (stdin);
  86. continue;
  87. }
  88. *argp++ = program_name;
  89. *argp++ = sp = string;
  90. while (nobreak (c))
  91. {
  92. if (c == '#')
  93. {
  94. do
  95. {
  96. c = getc (stdin);
  97. }
  98. while (nobreak (c));
  99. break;
  100. }
  101. if (isblank (c))
  102. {
  103. c = (char)(0);
  104. *argp = sp + 1;
  105. }
  106. else if (sp == *argp)
  107. {
  108. if ((signed)(argp - argv) &lt; argc)
  109. {
  110. argp++;
  111. }
  112. }
  113. *sp++ = (char)(c);
  114. c = getc (stdin);
  115. }
  116. *argp = (char const *)(0);
  117. *sp = (char)(0);
  118. }
  119. return ((unsigned)(argp - argv));
  120. }
  121. #endif
  122. </pre>
  123. <div class='footerlink'>
  124. [<a href='FragmentHeader.c.html' title=' FragmentHeader.c '>PREV</a>]
  125. [<a href='toolkit.html' title=' Index '>HOME</a>]
  126. [<a href='gethwaddr.c.html' title=' gethwaddr.c '>NEXT</a>]
  127. </div>
  128. </body>
  129. </html>