Changeset 199 in kBuild
- Timestamp:
- Dec 17, 2004 4:51:58 AM (20 years ago)
- Location:
- trunk/src
- Files:
-
- 4 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kShell/kShell.c
r49 r199 158 158 * 159 159 * <b>Syntax: chdir <directory> </b> 160 *161 *162 *163 * @subsubsection mkdir164 * Create directory.165 *166 * <b>Syntax: mkdir <directory> </b>167 *168 * Specify one directory to create.169 160 * 170 161 * … … 311 302 int kshellError(const char *pszCmd, const char *pszMessage, ...); 312 303 304 int kshellCmd_echo(const char *pszCmd, PKSHELLWORDS pWords); 305 int kshellCmd_log(const char *pszCmd, PKSHELLWORDS pWords); 313 306 int kshellCmd_copy(const char *pszCmd, PKSHELLWORDS pWords); 314 307 int kshellCmd_copytree(const char *pszCmd, PKSHELLWORDS pWords); … … 324 317 int kshellCmd_pushenv(const char *pszCmd, PKSHELLWORDS pWords); 325 318 int kshellCmd_popenv(const char *pszCmd, PKSHELLWORDS pWords); 326 int kshellCmd_echo(const char *pszCmd, PKSHELLWORDS pWords);327 319 int kshellCmd_write(const char *pszCmd, PKSHELLWORDS pWords); 328 320 int kshellCmd_ExecuteProgram(const char *pszCmd, PKSHELLWORDS pWords); … … 410 402 } aCmds[] = 411 403 { 404 {"echo", MAX_WORDS, kshellCmd_echo}, 405 {"log", 2, kshellCmd_log}, 412 406 {"copy", MAX_WORDS, kshellCmd_copy}, 413 407 {"copytree", 3, kshellCmd_copytree}, … … 423 417 {"pushenv", MAX_WORDS, kshellCmd_pushenv}, 424 418 {"popenv", 1, kshellCmd_popenv}, 425 {"echo", 2, kshellCmd_echo},426 419 {"write", 2, kshellCmd_write}, 427 420 … … 698 691 699 692 693 700 694 /* 701 695 * … … 704 698 * 705 699 */ 700 701 702 /** @subsubsection echo 703 * Prints a message to stdout. 704 * 705 * <b>Syntax: echo <level> <message> 706 * 707 * The message is printed word for word normalize with a single space between 708 * the words. It's therefore a good thing to quote the message. 709 * 710 * The message can be empty. Then a blank line will be printed. 711 */ 712 int kshellCmd_echo(const char *pszCmd, PKSHELLWORDS pWords) 713 { 714 int i; 715 716 /* output all the words forcing one space separation */ 717 for (i = 2; i < pWords->cWords; i++) 718 { 719 if (i != 2) 720 fputc(' ', stdout); 721 fwrite(pWords->aWords[i].pszWord, pWords->aWords[i].cchWord, 1, stdout); 722 } 723 724 /* new line */ 725 fputc('\n', stdout); 726 fflush(stdout); 727 728 return 0; 729 } 730 731 732 /** @subsubsection log 733 * Prints a message to stdout. 734 * 735 * <b>Syntax: log <level> <message> 736 * 737 * Level is verbosity level of the message. This is compared with the 738 * KBUILD_MSG_LEVEL environment variable. The message is suppressed if the 739 * level is lower that KBUILD_MSG_LEVEL. 740 * 741 * The message is printed word for word normalize with a single space between 742 * the words. It's therefore a good thing to quote the message. 743 * 744 * The message can be empty. Then a blank line will be printed. 745 */ 746 int kshellCmd_log(const char *pszCmd, PKSHELLWORDS pWords) 747 { 748 int rc = KSHELL_ERROR_SYNTAX_ERROR; 749 750 /* 751 * Get the message level from the message. 752 */ 753 if (pWords->cWords >= 2) 754 { 755 unsigned uMsgLevel = kStrToUDef(pWords->aWords[1].pszWord, -2, 0); 756 if (uMsgLevel != -2) 757 { 758 if (uMsgLevel <= kEnvGetUDef("KBUILD_MSG_LEVEL", 0, 0)) 759 { 760 /* output all the words forcing one space separation */ 761 pWords = kshellWordsParse(pszCmd, -1, pWords); 762 if (pWords) 763 { 764 int i; 765 for (i = 2; i < pWords->cWords; i++) 766 { 767 if (i != 2) 768 fputc(' ', stdout); 769 fwrite(pWords->aWords[i].pszWord, pWords->aWords[i].cchWord, 1, stdout); 770 } 771 } 772 773 /* new line */ 774 fputc('\n', stdout); 775 fflush(stdout); 776 } 777 } 778 else 779 kshellSyntaxError("log", "invalid message level!"); 780 } 781 else 782 kshellSyntaxError("log", "requires at least one argument!"); 783 784 return -1; 785 } 786 706 787 707 788 … … 820 901 } 821 902 822 903 /** @subsubsection mkdir 904 * Create directory. 905 * 906 * <b>Syntax: mkdir <directory> [directory2[..]] </b> 907 * 908 * Specify zero or more directories to create. Necessary parent directories 909 * will be created. 910 * 911 * If the directory exist no error is reported. 912 * The command fails on the first failure, processing directories left to right. 913 * 914 * Mkdir is hence not suitable for making locks. Should such be needed a 915 * dedicated command should be created for that purpose. 916 * 917 */ 823 918 int kshellCmd_mkdir(const char *pszCmd, PKSHELLWORDS pWords) 824 919 { 825 return -1; 920 int rc = 0; 921 int i; 922 923 for (i = 1; i < pWords->cWords; i++) 924 { 925 /* 926 * Allocate a buffer for canonizing the directory name and work in. 927 */ 928 char *pszDir = kHeapAlloc(pWords->aWords[i].cchWord + KFILE_LENGTH); 929 if (pszDir) 930 { 931 /* 932 * Canonify the path to local default slash etc. 933 */ 934 rc = kPathCanonifyEx(pWords->aWords[i].pszWord, NULL, KSHELL_SLASH, 0, psz); 935 if (!rc) 936 { 937 kFileState 938 /* 939 * Now we will enumerate the path towards the root and 940 * find the first existing directory. We need the mode 941 * of that directory. 942 */ 943 944 char *psz = 945 } 946 } 947 948 rc = kDirCreate( 949 } 950 951 return rc; 826 952 } 827 953 … … 857 983 858 984 859 /** @subsubsection echo860 * Prints a message to stdout.861 *862 * <b>Syntax: echo <level> <message>863 *864 * Level is verbosity level of the message. This is compared with the865 * KBUILD_MSG_LEVEL environment variable. The message is suppressed if the866 * level is lower that KBUILD_MSG_LEVEL.867 *868 * The message is printed word for word normalize with a single space between869 * the words. It's therefore a good thing to quote the message.870 *871 * The message can be empty. Then a blank line will be printed.872 */873 int kshellCmd_echo(const char *pszCmd, PKSHELLWORDS pWords)874 {875 int rc = KSHELL_ERROR_SYNTAX_ERROR;876 877 /*878 * Get the message level from the message.879 */880 if (pWords->cWords >= 2)881 {882 unsigned uMsgLevel = kStrToUDef(pWords->aWords[1].pszWord, -2, 0);883 if (uMsgLevel != -2)884 {885 if (uMsgLevel <= kEnvGetUDef("KBUILD_MSG_LEVEL", 0, 0))886 {887 /* output all the words forcing one space separation */888 pWords = kshellWordsParse(pszCmd, -1, pWords);889 if (pWords)890 {891 int i;892 for (i = 2; i < pWords->cWords; i++)893 fwrite(pWords->aWords[i].pszWord, pWords->aWords[i].cchWord, 1, stdout);894 }895 896 /* new line */897 fputc('\n', stdout);898 fflush(stdout);899 }900 }901 else902 kshellSyntaxError("echo", "invalid message level!");903 }904 else905 kshellSyntaxError("echo", "requires at least one argument!");906 907 return -1;908 }909 985 910 986
Note:
See TracChangeset
for help on using the changeset viewer.