如何从源代码中获取PHP版本?(How to get the PHP version from the source code?)
我正在尝试创建一个bash脚本, 从Github (master分支) 下载最新版本的PHP并安装它。
我想用我正在下载的版本创建一个文件夹(例如/path/to/php/5.4.0),但我找不到源代码中的任何文件,说“嘿,我是PHP的XXX版本”。 看下面我的简单代码:
url="https://github.com/php/php-src/tarball/master" curl -L $url > php-temp.tar.gz tar -zxf php-temp.tar.gz cd php-php-src*
我想知道一些VERSION或README文件,但我找不到任何对PHP版本的引用。
有人知道哪里有这个信息的文件?
I'm trying to create a bash script which downloads the latest version of PHP from Github (master branch) and install it.
I would like to create a folder with the version I'm downloading (e. g. /path/to/php/5.4.0) but I cannot find any file among the source code saying "hey, I am the XXX version of PHP". Look below what my simple code does:
url="https://github.com/php/php-src/tarball/master" curl -L $url > php-temp.tar.gz tar -zxf php-temp.tar.gz cd php-php-src*
I was wondering to cat|grep some VERSION or README file but I could not find any references to PHP version among them.
Does someone knows where there is a file which this information?
原文:https://stackoverflow.com/questions/10264661
最满意答案
你肯定喜欢自己做事......你最大的四个问题是(1)没有将
mywords
的地址传递给add_words
, (2)没有在add_words
处理New / Empty列表的情况, (3)添加了新的节点到列表的头部,以及(4)每次调用add_word
时覆盖列表地址(例如mywords = add_words...
)修复每个问题并整理解析,您应该能够在列表中找到所有单词。 查看/测试以下内容:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> typedef struct s_words { char *str; //word int count; //number of times word occurs struct s_words *next; //pointer to next word } words; words *create_words (char *word) { //+allocate space for the structure printf ("%lu ", strlen (word)); words *newWord = malloc (sizeof (words)); if (NULL != newWord) { //+allocate space for storing the new word in "str" //+if str was array of fixed size, storage wud be wasted newWord->str = (char *) malloc ((strlen (word)) + 1); strcpy (newWord->str, word); //+copy “word” into newWord->str newWord->str[strlen (word)] = '\0'; printf (" Create: %s ", newWord->str); //+initialize count to 1; newWord->count = 1; //+initialize next; newWord->next = NULL; } return newWord; } words *add_word (words **wordList, char *word) { if (!*wordList) { /* handle EMPTY list */ printf ("NEW LIST\n"); return *wordList = create_words (word); } words *temp = *wordList; //+ search if word exists in the list; if so, make found=1 while (temp->next != NULL) { /* iterate while temp->next != NULL */ if (strcmp (temp->str, word) == 0) { //+use strcmp command temp->count = temp->count + 1; //+increment count; return *wordList; } else temp = temp->next; //+update temp } words *newWord = create_words (word); if (NULL != newWord) { /* insert at TAIL of list */ temp->next = newWord; printf (" NEW WORD: %s\n ", newWord->str); } return newWord; } int main (int argc, char *argv[]) { words *mywords; //+head of linked list containing words mywords = NULL; char *delim = ". ,:;\t\n"; FILE *myFile; FILE *myOutput; char *filename = argv[1]; char *outputfile = argv[2]; if (argc != 3) { fprintf (stderr, "error: insufficient input. usage: %s ifile ofile\n", argv[0]); return 1; } myFile = fopen (filename, "r"); //+first parameter is input file if (myFile == 0) { printf ("file not opened\n"); return 1; } else { printf ("file opened \n"); } //+start reading file character by character; //+when word has been detected; call the add_word function int ch = 0, word = 1, k = 0; char thisword[100]; while ((ch = fgetc (myFile)) != EOF) { /* for each char */ if (strchr (delim, ch)) { /* check if delim */ if (word == 1) { /* if so, terminate word, reset */ word = 0; thisword[k] = '\0'; printf ("\nadd_word (mywords, %s)\n", thisword); /* do NOT overwrite list address each time, * you must send ADDRESS of list to add_word * to handle EMPTY list case. */ if (add_word (&mywords, thisword)) printf (" added: %s\n", mywords->str); else fprintf (stderr, "error: add_word failed.\n"); k = 0; } } else { /* if not delim, add char to string, set word 1 */ word = 1; thisword[k++] = tolower (ch); /* make ch lowercase */ } } if (word == 1) { /* handle non-POSIX line-end */ thisword[k] = '\0'; //add thisword into the list printf ("\nadd_word (mywords, %s) (last)\n", thisword); if (add_word (&mywords, thisword)) /* same comment as above */ printf (" added: %s\n", mywords->str); else fprintf (stderr, "error: add_word failed.\n"); } words *currword; printf ("printing list\n"); //+Traverse list and print each word and its count to outputfile //+output file is second parameter being passed myOutput = fopen (outputfile, "w+"); //+first parameter is input file if (myOutput == 0) { printf ("output file not opened \n"); return 1; } else { printf ("output file opened \n"); } currword = mywords; while (currword != NULL) { /* just test currword here */ //add word name then word count to file, then move to next fprintf (myOutput, "%s %d \n", currword->str, currword->count); printf ("%s ", currword->str); currword = currword->next; } putchar ('\n'); return 0; }
输入文件
$ cat ../dat/captnjack.txt This is a tale Of Captain Jack Sparrow A Pirate So Brave On the Seven Seas.
测试使用
$ ./bin/llwordcount ../dat/captnjack.txt dat/llout.txt
输出文件
$ cat dat/llout.txt this 1 is 1 a 2 tale 1 of 1 captain 1 jack 1 sparrow 1 pirate 1 so 1 brave 1 on 1 the 1 seven 1 seas 1
注意:对于打印/输出,您只需要
while (currword != NULL)
遍历列表。现在说,您应该考虑使用面向行的输入(
fgets
或getline
)并将每行数据解析为单词,而不是逐个字符地读取并查找分隔符。 读取/解析一次一行更容易且更不容易出错。 由于面向行的输入是缓冲的,因此读取速度也快得多。 你可以一次读一个角色,它只是慢一点,沿途还有很多陷阱。消化更改(上面用
/* ... */
注释),如果您有任何疑问,请告诉我。You sure like making things hard on yourself... Your four biggest issues were (1) not passing the address of
mywords
toadd_words
, (2) failing to handle the New/Empty list case inadd_words
, (3) adding the new nodes to the head of the list, and (4) overwriting your list address every time you calledadd_word
(e.g.mywords = add_words...
)Fixing each of those problems and tidying up parsing a bit, you should be able to find all of your words in your list. Look over/test the following:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> typedef struct s_words { char *str; //word int count; //number of times word occurs struct s_words *next; //pointer to next word } words; words *create_words (char *word) { //+allocate space for the structure printf ("%lu ", strlen (word)); words *newWord = malloc (sizeof (words)); if (NULL != newWord) { //+allocate space for storing the new word in "str" //+if str was array of fixed size, storage wud be wasted newWord->str = (char *) malloc ((strlen (word)) + 1); strcpy (newWord->str, word); //+copy “word” into newWord->str newWord->str[strlen (word)] = '\0'; printf (" Create: %s ", newWord->str); //+initialize count to 1; newWord->count = 1; //+initialize next; newWord->next = NULL; } return newWord; } words *add_word (words **wordList, char *word) { if (!*wordList) { /* handle EMPTY list */ printf ("NEW LIST\n"); return *wordList = create_words (word); } words *temp = *wordList; //+ search if word exists in the list; if so, make found=1 while (temp->next != NULL) { /* iterate while temp->next != NULL */ if (strcmp (temp->str, word) == 0) { //+use strcmp command temp->count = temp->count + 1; //+increment count; return *wordList; } else temp = temp->next; //+update temp } words *newWord = create_words (word); if (NULL != newWord) { /* insert at TAIL of list */ temp->next = newWord; printf (" NEW WORD: %s\n ", newWord->str); } return newWord; } int main (int argc, char *argv[]) { words *mywords; //+head of linked list containing words mywords = NULL; char *delim = ". ,:;\t\n"; FILE *myFile; FILE *myOutput; char *filename = argv[1]; char *outputfile = argv[2]; if (argc != 3) { fprintf (stderr, "error: insufficient input. usage: %s ifile ofile\n", argv[0]); return 1; } myFile = fopen (filename, "r"); //+first parameter is input file if (myFile == 0) { printf ("file not opened\n"); return 1; } else { printf ("file opened \n"); } //+start reading file character by character; //+when word has been detected; call the add_word function int ch = 0, word = 1, k = 0; char thisword[100]; while ((ch = fgetc (myFile)) != EOF) { /* for each char */ if (strchr (delim, ch)) { /* check if delim */ if (word == 1) { /* if so, terminate word, reset */ word = 0; thisword[k] = '\0'; printf ("\nadd_word (mywords, %s)\n", thisword); /* do NOT overwrite list address each time, * you must send ADDRESS of list to add_word * to handle EMPTY list case. */ if (add_word (&mywords, thisword)) printf (" added: %s\n", mywords->str); else fprintf (stderr, "error: add_word failed.\n"); k = 0; } } else { /* if not delim, add char to string, set word 1 */ word = 1; thisword[k++] = tolower (ch); /* make ch lowercase */ } } if (word == 1) { /* handle non-POSIX line-end */ thisword[k] = '\0'; //add thisword into the list printf ("\nadd_word (mywords, %s) (last)\n", thisword); if (add_word (&mywords, thisword)) /* same comment as above */ printf (" added: %s\n", mywords->str); else fprintf (stderr, "error: add_word failed.\n"); } words *currword; printf ("printing list\n"); //+Traverse list and print each word and its count to outputfile //+output file is second parameter being passed myOutput = fopen (outputfile, "w+"); //+first parameter is input file if (myOutput == 0) { printf ("output file not opened \n"); return 1; } else { printf ("output file opened \n"); } currword = mywords; while (currword != NULL) { /* just test currword here */ //add word name then word count to file, then move to next fprintf (myOutput, "%s %d \n", currword->str, currword->count); printf ("%s ", currword->str); currword = currword->next; } putchar ('\n'); return 0; }
Input File
$ cat ../dat/captnjack.txt This is a tale Of Captain Jack Sparrow A Pirate So Brave On the Seven Seas.
Test Use
$ ./bin/llwordcount ../dat/captnjack.txt dat/llout.txt
Output File
$ cat dat/llout.txt this 1 is 1 a 2 tale 1 of 1 captain 1 jack 1 sparrow 1 pirate 1 so 1 brave 1 on 1 the 1 seven 1 seas 1
note: for printing/output, you simply want
while (currword != NULL)
to traverse the list.Now with that said, you should really consider using line-oriented input (
fgets
orgetline
) and parsing each line of data into words rather than reading character-by-character and looking for delimiters. It is much easier and less error prone to read/parse a line-at-a-time. Since line-oriented input is buffered, it is also a much faster read. You can read a character at a time, it is just slower and there are a lot more pitfalls along the way.Digest the changes (commented above with
/* ... */
) and let me know if you have any questions.
相关问答
更多-
尝试: temp->data = strdup(line); 复制(复制)什么行指向。 否则,每一行都指向buffer ,每个新行都会被覆盖。 Try: temp->data = strdup(line); to duplicate (make a copy of) what line points at. Otherwise every line points at the buffer which is getting overwritten with each new line.
-
使用FILE *参数在list_print函数中使用fprintf函数,如示例所示: void list_print(INTLIST* list, FILE *fp) { /* This function simply prints the linked list out */ INTLIST* temp=NULL; //temp pointer to head of list /* loops through each node of list printing its dat ...
-
C从文本文件中读取单词(C Reading words from text file)[2022-10-24]
你的word数组是一个指针数组,而不是一个字符数组。 你应该改变 char* word[200]; 至 char word[200]; 和 *word[i]; 至 word[i]; Your wordarray is a array of pointer, not a array of character. You should change char* word[200]; to char word[200]; and *word[i]; to word[i]; -
简单的uniq + sort + awk管道: uniq -c <(sort animal.txt) | awk '{print $2,$1}' 输出: bird 5 cat 2 dog 3 rabbit 2 我还建议你另一个名为GNU datamash的好工具: datamash -s -g1 count 1只有当您的文件不超过10行时,您的代码才能正常运行。 你可以用这种方式改变它 Imports System.IO .... Dim words = File.ReadLines("C:\Users\Me\Desktop\test.txt").ToList() For Each word in words Vlanbx1.Checklisbox.Items.Add(word) Vlanbx2.Checklisbox.Items.Add(word) Next 现在File.ReadLines ...
MIPS:计算纯文本文件中的唯一单词并查找其频率(MIPS: counting unique words in a plain text file and finding their Frequency)[2022-02-24]
对于像这样的所有复杂任务,您应该首先在C中编写和调试一个简单的解决方案,然后手动转换为汇编。 您可以使用C语言快速开发工作解决方案。然后,您需要做的就是验证是否已将其正确地转换为汇编并调试可能已在程序集中引入的任何错误。 考虑问题的解决方案并同时考虑在汇编程序中实现该解决方案太复杂了。 你会陷入困境,迷失方向。 这就是我在日常工作中用汇编写东西的方法。 解决这个问题的最简单方法是使一个数组包含到目前为止看到的所有单词,以及一个单独的数组,每个单词使用use-count,这样WORDS [0]的use-cou ...你肯定喜欢自己做事......你最大的四个问题是(1)没有将mywords的地址传递给add_words , (2)没有在add_words处理New / Empty列表的情况, (3)添加了新的节点到列表的头部,以及(4)每次调用add_word时覆盖列表地址(例如mywords = add_words... ) 修复每个问题并整理解析,您应该能够在列表中找到所有单词。 查看/测试以下内容: #include#include #include 无论你编写什么语言,如果你没有验证你的输入并且你的函数调用返回,你可以毫不自信地代码正在做任何事情,更重要的是,你将不知道你的代码在什么时候开始失败。 这是至关重要的。 我知道你正在学习,但从良好习惯开始验证所有输入和所有函数调用返回。 您作为程序员的生活将变得更加容易。 实现简单的验证将告诉您代码失败的位置以及它何时开始失败。 例如,每次你输入时,确认你实际上得到了你所期望的。 使用scanf系列函数,这意味着至少可以验证成功的转换次数。 如果您不清楚函数返回的内容,或者如何衡量成功/失败,请查看函数的手 ...C中的文件处理 - 从文本文件中的列表中删除特定单词(File Handling in C - Removing specific words from a list in text file)[2022-02-11]
你打开两个文件:你有一个(用于阅读)和一个新文件(用于写作)。 循环遍历第一个文件依次读取每一行。 您将每行的内容与您需要删除的单词进行比较。 如果该行与任何删除单词都不匹配,则将其写入新文件。 如果您需要进行的操作要复杂得多,那么您可以使用mmap()将其“读入内存”,但这是一种更高级的技术; 你需要将文件视为没有零终止符的字节数组,并且有很多方法可以搞砸了。 You open two files: the one you've got (for reading) and a new one (for w ...你想从文件中读取,可能会想到fgets() 。 你想通过分隔符(空格)分成标记,应该记住strtok() 。 所以,你可以这样做: #include#include int main(void) { FILE * pFile; char mystring [100]; char* pch; pFile = fopen ("text_newlines.txt" , "r"); if (pFile == NULL) perror (" ... 相关文章
更多- reading notes for solr source code
- Web scraper open source
- English,The Da Vinci Code,Chapter 1-3
- 微信会员注册开发【带源码】:网页授权,得到code后在当前页面获取openid,js+php实现跨域请求
- Solr PHP support
- PHP中的替代语法
- 关于如何参与到开源项目中《How To Succeed In Open Source ( In Ways You Haven't Considered Yet )》
- mac10.9+php5.5.15+brew0.9.5的安装
- Hibernate Search(基于version3.4)--第五章Querying
- 【转】php中escapeshellarg中文被过滤
最新问答
更多- h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
- 创建一个功能(Create a function)
- 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
- PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
- Qt冻结循环的原因?(Qt freezing cause of the loop?)
- TableView重复youtube-api结果(TableView Repeating youtube-api result)
- 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
- SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
- 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
- 以编程方式创建UITableView(Creating a UITableView Programmatically)
- 如何打破按钮上的生命周期循环(How to break do-while loop on button)
- C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
- 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
- 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
- Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
- 设置kotlin扩展名(Setting a kotlin extension)
- 如何并排放置两个元件?(How to position two elements side by side?)
- 如何在vim中启用python3?(How to enable python3 in vim?)
- 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
- 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
- Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
- dedecms如何安装?
- 在哪儿学计算机最好?
- 学php哪个的书 最好,本人菜鸟
- 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
- 如何覆盖错误堆栈getter(How to override Error stack getter)
- 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
- USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
- 电脑高中毕业学习去哪里培训
- 正则表达式验证SMTP响应(Regex to validate SMTP Responses)