void mereducemenucodes (bigstring bs, boolean *flenabled, boolean *flchecked) { /* 4.1b8 dmb: common code for mebuildmenu, memenuitemchanged, and mecheckformulas handles item disabling with '(', and checkmark with '!' 7.0b23 PBS: no longer static -- used in oppopup.c for right-click menus. */ *flenabled = (stringlength (bs) > 1) || (getstringcharacter (bs, 0) != '-'); // !equalstrings (bs, (ptrstring) "\p-"); /*all dotted lines are disabled*/ if (getstringcharacter (bs, 0) == '(' && lastchar (bs) != ')') { /*4.1b6 dmb*/ deletestring (bs, 1, 1); *flenabled = false; } *flchecked = false; if ((stringlength (bs) > 1) && (getstringcharacter (bs, 0) == '!')) { /*4.1b8 dmb*/ deletestring (bs, 1, 1); *flchecked = true; } } /*mereducemenucodes*/
int main() { char str1[] = {'s' , 'a' , 'b' , 'b' , 'u' , '\0'}; char str2[] = {'u' , 'd' , 'a' , 'y' , '\0'}; char str3[] = {'k' , 'u' , 'm' , 'a' , 'r' , '\0'}; printf("The lengths of strings are : %d\n%d\n%d\n", stringlength(str1) , stringlength(str2) , stringlength(str3)); return 0; }
// String comparsion bool stringcompare(char *str1, char *str2) { int i; int len = stringlength(str1); if (len != stringlength(str2)) return false; for (i = 0; i < len; i++) { if (str1[i] != str2[i]) return false; } return true; }
boolean getfsfile ( const ptrfilespec fs, bigstring bsfile ) { // // 2007-08-01 creedon: check FSRefGetNameStr255 return false if not true // // 2006-06-18 creedon: for Mac, FSRef-ized // #ifdef MACVERSION macgetfilespecnameasbigstring ( fs, bsfile ); if ( stringlength ( bsfile ) > 0 ) return ( true ); long vnum; getfsvolume ( fs, &vnum ); return ( filegetvolumename ( vnum, bsfile ) ); #endif #ifdef WIN95VERSION lastword ((ptrstring) fs -> fullSpecifier, '\\', bsfile); return (true); #endif } // getfsfile
void sendnlmsg(void) { struct sk_buff *skb_1; struct nlmsghdr *nlh; int len = NLMSG_SPACE(MAX_MSGSIZE); int slen = 0; char buffer[128]; const char *message="hello i am kernel"; if(!message || !nl_sk){ return ; } skb_1 = alloc_skb(len,GFP_KERNEL); if(!skb_1){ printk(KERN_ERR "my_net_link:alloc_skb_1 error\n"); } nlh = nlmsg_put(skb_1,0,0,0,MAX_MSGSIZE,0); //NETLINK_CB(skb_1).pid = 0; NETLINK_CB(skb_1).portid = 0; NETLINK_CB(skb_1).dst_group = 0; slen = stringlength(message); memset(buffer,0,sizeof(buffer)); memcpy(buffer,message,slen); memcpy(NLMSG_DATA(nlh),buffer,slen+1); printk("my_net_link:send message '%s'.\n",(char *)NLMSG_DATA(nlh)); netlink_unicast(nl_sk,skb_1,pid,MSG_DONTWAIT); }
boolean frontierversion (tyvaluerecord *v) { //6.1d1 AR: needed in langhtml.c if (stringlength (bsfrontierversion) == 0) filegetprogramversion (bsfrontierversion); return (setstringvalue (bsfrontierversion, v)); } /*frontierversion*/
boolean langisidentifier (bigstring bs) { /* called externally to determine when quoting in necessary in path construction 4.1b2 dmb: check the constants table too */ register short ct = stringlength (bs); register byte *s = bs; tyvaluerecord val; hdlhashnode hnode; if (ct == 0) /*empty string*/ return (false); if (!isfirstidentifierchar (*++s)) return (false); while (--ct > 0) if (!isidentifierchar (*++s)) return (false); if (hashtablelookup (hkeywordtable, bs, &val, &hnode)) /*it's a keyword*/ return (false); if (hashtablelookup (hconsttable, bs, &val, &hnode)) /*dmb 4.1b2 - it's a constant*/ return (false); return (true); } /*langisidentifier*/
boolean setRegKeyLong (Handle regkey, bigstring subkey, bigstring itemname, unsigned long val) { HKEY hkey; DWORD what; char key[256]; char item[256]; char * itemptr; if (subkey == NULL) return (false); if (stringlength (subkey) == 0) return (false); copyptocstring (subkey, key); if (itemname != NULL) { itemptr = item; copyptocstring (itemname, item); } else itemptr = NULL; if (RegCreateKeyEx ((HKEY) regkey, key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &what) == ERROR_SUCCESS) { RegSetValueEx (hkey, itemptr, 0, REG_DWORD_LITTLE_ENDIAN, (unsigned char *) &val, sizeof(long)); RegCloseKey (hkey); return (true); } return (false); } /*setRegKeyLong*/
int main() { char str[] = "'Master of Puppets!!'"; /* added single quotation marks to better separate the string from the rest of the output and created own string for easier identification*/ printf ("The lenght of the string %s is %d ", str, stringlength(str)); }
void appsetmessage (hdlappwindow appwindow, bigstring bs) { hdlappwindow ha = appwindow; if (ha == nil) return; if (app.hasmessagearea) { Handle htext; /*8/29/94 DW: don't do anything if the message hasn't changed*/ { bigstring bscurrentmessage; texthandletostring ((**ha).hmessage, bscurrentmessage); if (equalstrings (bscurrentmessage, bs)) /*nothing to do*/ return; } disposehandle ((**ha).hmessage); if (stringlength (bs) == 0) htext = nil; else newtexthandle (bs, &htext); (**ha).hmessage = htext; appdrawmessage (ha); } } /*appsetmessage*/
boolean setfilecomment (FSSpec *pfs, bigstring bscomment) { DTPBRec dt; clearbytes (&dt, longsizeof (dt)); if (!hasdesktopmanager ((*pfs).vRefNum)) return (false); dt.ioVRefNum = (*pfs).vRefNum; if (PBDTGetPath (&dt) != noErr) return (false); dt.ioNamePtr = (*pfs).name; dt.ioDirID = (*pfs).parID; dt.ioDTBuffer = (Ptr) bscomment + 1; dt.ioDTReqCount = stringlength (bscomment); if (PBDTSetCommentSync (&dt) != noErr) return (false); PBDTFlushSync (&dt); return (true); } /*setfilecomment*/
boolean debugnewtexthandle (char * filename, unsigned long linenumber, unsigned long threadid, const bigstring bs, Handle *htext) { /* create a new handle to hold the text of the string. if the string is "\pABC" -- you get a handle of size 3. */ register long len = stringlength (bs); register Handle h; h = debuggetnewhandle (filename, linenumber, threadid, len, false); if (h == nil) { memoryerror (); return (false); } if (len > 0) moveleft ((ptrstring) stringbaseaddress (bs), *h, len); *htext = h; /*pass handle back to caller*/ return (true); } /*newtexthandle*/
int main() { char str[]= "The quick brown fox"; printf ("The length of the string %s is %d\n", str, stringlength(str)); return(0); }
boolean setRegKeyString (Handle regkey, bigstring subkey, bigstring itemname, bigstring bsval) { HKEY hkey; DWORD what; char key[256]; char item[256]; char val[256]; char * itemptr; if ((subkey == NULL) || (bsval == NULL)) return (false); if (stringlength (subkey) == 0) return (false); copyptocstring (subkey, key); copyptocstring (bsval, val); if (itemname != NULL) { itemptr = item; copyptocstring (itemname, item); } else itemptr = NULL; if (RegCreateKeyEx ((HKEY) regkey, key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &what) == ERROR_SUCCESS) { RegSetValueEx (hkey, itemptr, 0, REG_SZ, val, strlen (val)+1); RegCloseKey (hkey); return (true); } return (false); } /*setRegKeyString*/
boolean registerFileType (bigstring extension, bigstring filetype, bigstring contenttype, bigstring filedescription, bigstring iconfile, short iconid, bigstring shellopen) { bigstring sval, skey; if ((extension == NULL) || (filetype == NULL)) return (false); if (stringlength (extension) < 2) return (false); if (stringlength (filetype) == 0) return (false); /* Register with the Registry */ setRegKeyValue (extension, NULL, filetype); if (contenttype != NULL) { setRegKeyValue (extension, BIGSTRING ("\x0c" "Content Type"), contenttype); } if (filedescription == NULL) return (true); /* nothing more to do */ setRegKeyValue (filetype, NULL, filedescription); if (iconfile != NULL) { copystring (iconfile, sval); pushchar (',', sval); pushint (iconid, sval); copystring (filetype, skey); pushstring (BIGSTRING ("\x0c" "\\DefaultIcon"), skey); setRegKeyValue (skey, NULL, sval); } if (shellopen != NULL) { copystring (filetype, skey); pushstring (BIGSTRING ("\x13" "\\shell\\open\\command"), skey); setRegKeyValue (skey, NULL, shellopen); } return (true); }
boolean pushtexthandle (const bigstring bs, Handle htext) { /* htext is a handle created with newtexthandle. increase the size of the handle so we can push the text of bs at the end of the handle (not including length byte). */ return (enlargehandle (htext, (long) stringlength (bs), (ptrvoid) stringbaseaddress (bs))); } /*pushtexthandle*/
char KthIndexFromEnd(char *str, int K) { int i; if (str == nullptr || stringlength(str) <= K || K < 0) return '\0'; for (i = 0; str[i] != '\0'; i++) { if (str[i] < 0 || str[i]>255) return '\0'; if (str[i + K + 1] == '\0') return str[i]; } }
static boolean midinsertchar (byte ch, bigstring bs, short ixinsert) { byte bs1 [4]; /*rab 3/21/97 was 2*/ if (ixinsert > lenbigstring) return (false); if (stringlength (bs) == lenbigstring) /*overflow -- push character off end*/ setstringlength (bs, lenbigstring - 1); setstringwithchar (ch, bs1); return (midinsertstring (bs1, bs, ixinsert)); /*should always be true*/ } /*midinsertchar*/
static void pushadjective (bigstring adjective, bigstring bs) { bigstring adj; copystring (adjective, adj); /*we might modify it*/ if (stringlength (bs) > 0) { pushstring (BIGSTRING ("\x01" " "), bs); alllower (adj); } pushstring (adj, bs); } /*pushadjective*/
void main() { clrscr(); char string[50]; cout<<"Enter a string: "; gets(string); int l=stringlength(string); cout<<"The length of the string is: "<<l ; cout<<endl<<endl; cout<<"The new string is: "; for(int i=0; i<=l;i++) up_low(string[i]); getch(); }
boolean getRegKeyLong (Handle regkey, bigstring subkey, bigstring itemname, unsigned long * val) { HKEY hkey; char key[256]; char item[256]; char * itemptr; DWORD regtype; long err; DWORD len; if ((subkey == NULL) || (val == NULL)) return (false); if (stringlength (subkey) == 0) return (false); copyptocstring (subkey, key); if (itemname != NULL) { itemptr = item; copyptocstring (itemname, item); } else itemptr = NULL; if (RegOpenKeyEx ((HKEY) regkey, key, 0, KEY_READ, &hkey) == ERROR_SUCCESS) { len = sizeof(long); err = RegQueryValueEx (hkey, itemptr, NULL, ®type, (unsigned char *) val, &len); RegCloseKey (hkey); if (err != ERROR_SUCCESS) return (false); if (regtype != REG_DWORD_LITTLE_ENDIAN) return (false); if (len != sizeof(long)) return (false); return (true); } return (false); } /*getRegKeyLong*/
boolean getRegKeyString (Handle regkey, bigstring subkey, bigstring itemname, bigstring bsval) { HKEY hkey; char key[256]; char item[256]; char * itemptr; DWORD regtype; long err; DWORD len; if ((subkey == NULL) || (bsval == NULL)) return (false); if (stringlength (subkey) == 0) return (false); copyptocstring (subkey, key); if (itemname != NULL) { itemptr = item; copyptocstring (itemname, item); } else itemptr = NULL; if (RegOpenKeyEx ((HKEY) regkey, key, 0, KEY_READ, &hkey) == ERROR_SUCCESS) { len = sizeof(bigstring) - 1; err = RegQueryValueEx (hkey, itemptr, NULL, ®type, stringbaseaddress(bsval), &len); RegCloseKey (hkey); if (err != ERROR_SUCCESS) return (false); if (regtype != REG_SZ) return (false); setstringlength (bsval, len - 1); return (true); } return (false); } /*getRegKeyString*/
static boolean winreggethandlevalue (Handle regkey, bigstring subkey, bigstring itemname, Handle hval, unsigned long *len, DWORD *regtype) { HKEY hkey; char key[256]; char item[256]; char * itemptr; long err; if ((subkey == NULL) || (hval == NULL) || (len == NULL)) return (false); if (stringlength (subkey) == 0) return (false); copyptocstring (subkey, key); if (itemname != NULL) { itemptr = item; copyptocstring (itemname, item); } else itemptr = NULL; if (RegOpenKeyEx ((HKEY) regkey, key, 0, KEY_READ, &hkey) == ERROR_SUCCESS) { lockhandle (hval); err = RegQueryValueEx (hkey, itemptr, NULL, regtype, *hval, len); unlockhandle (hval); RegCloseKey (hkey); if (err != ERROR_SUCCESS) return (false); return (true); } return (false); } /*winreggethandlevalue*/
boolean getRegKeyBinary (Handle regkey, bigstring subkey, bigstring itemname, unsigned char * val, unsigned long * len) { HKEY hkey; char key[256]; char item[256]; char * itemptr; DWORD regtype; long err; if ((subkey == NULL) || (val == NULL) || (len == NULL)) return (false); if (stringlength (subkey) == 0) return (false); copyptocstring (subkey, key); if (itemname != NULL) { itemptr = item; copyptocstring (itemname, item); } else itemptr = NULL; if (RegOpenKeyEx ((HKEY) regkey, key, 0, KEY_READ, &hkey) == ERROR_SUCCESS) { err = RegQueryValueEx (hkey, itemptr, NULL, ®type, val, len); RegCloseKey (hkey); if (err != ERROR_SUCCESS) return (false); if (regtype != REG_BINARY) return (false); return (true); } return (false); } /*getRegKeyBinary*/
/* Concat function */ char *string_nconcat(char *dest, const char *src, int n) { int lengthdestarray; int lengthdeststring; int positioninsrc; lengthdestarray = sizeof(dest) / sizeof(char) * 4; lengthdeststring = stringlength(dest); positioninsrc = 0; if ((lengthdeststring + n + 1) > lengthdestarray) return("There is no room at the inn"); while (positioninsrc < n) { dest[lengthdeststring] = src[positioninsrc]; lengthdeststring++; positioninsrc++; } dest[lengthdeststring] = '\0'; return (dest); }
void menufunction(int) { switch(stringmenu) { case 1: stringcopy(); break; case 2: stringcharcopy(); break; case 3: stringcompare(); break; case 4: stringcharcompare(); break; case 5: stringmerge(); break; case 6: stringcharmerge(); break; case 7: stringlength(); break; default: cout<<"This is not a valid option! \n"; cout<<"Choose again! \n"; break; } }
boolean getRegKeyInfo (Handle regkey, bigstring subkey, bigstring itemname, unsigned long *regType, unsigned long * len) { HKEY hkey; char key[256]; char item[256]; char * itemptr; long err; if ((subkey == NULL) || (regType == NULL) || (len == NULL)) return (false); if (stringlength (subkey) == 0) return (false); copyptocstring (subkey, key); if (itemname != NULL) { itemptr = item; copyptocstring (itemname, item); } else itemptr = NULL; if (RegOpenKeyEx ((HKEY) regkey, key, 0, KEY_READ, &hkey) == ERROR_SUCCESS) { *len = 0; err = RegQueryValueEx (hkey, itemptr, NULL, regType, NULL, len); RegCloseKey (hkey); if (err != ERROR_SUCCESS) return (false); return (true); } return (false); } /*getRegKeyInfo*/
void sendnlmsg(char *message) { struct sk_buff *skb; struct nlmsghdr *nlh; int len = NLMSG_SPACE(MAX_MSGSIZE); int slen = 0; if(!message ||!nl_sk) { return ; } // Allocate a new sk_buffer skb = alloc_skb(len,GFP_KERNEL); if(!skb){ printk(KERN_ERR"my netlink: alloc_skb Error.\n"); return ; } slen = stringlength(message); //Initiate the header of the netlink message nlh = nlmsg_put(skb,0,0,0,slen,0); NETLINK_CB(skb).pid = 0;//from kernel NETLINK_CB(skb).dst_group = 1; // multi_cast .0 is for unicast //message[slen] = '\0'; memcpy(NLMSG_DATA(nlh),message,slen); printk("my netlink:send message '%s'\n",(char *)NLMSG_DATA(nlh)); //send message by mutil cast netlink_broadcast(nl_sk,skb,0,1,GFP_KERNEL); return; }
static boolean setRegKeyValue (bigstring bskey, bigstring bsitem, bigstring bsval) { HKEY hkey; DWORD what; char key[256]; char item[256]; char val[256]; char * itemptr; if ((bskey == NULL) || (bsval == NULL)) return (false); if (stringlength (bskey) == 0) return (false); copyptocstring (bskey, key); copyptocstring (bsval, val); if (bsitem != NULL) { itemptr = item; copyptocstring (bsitem, item); } else itemptr = NULL; if (RegCreateKeyEx (HKEY_CLASSES_ROOT, key, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &what) == ERROR_SUCCESS) { RegSetValueEx (hkey, itemptr, 0, REG_SZ, val, strlen (val)+1); RegCloseKey (hkey); return (true); } return (false); }
pascal boolean landpushstringparam (hdlverbrecord hverb, bigstring bs, typaramkeyword key) { return (landpushparam (hverb, texttype, nil, bs + 1, stringlength (bs), key)); } /*landpushstringparam*/